forked from apache/mynewt-mcumgr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#3 from mlaz/mynewt_mcumgr
oicmgr + omp_streamer
- Loading branch information
Showing
9 changed files
with
487 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief OMP - OIC Management Protocol. | ||
* | ||
* OMP is an OIC implementation of SMP, a basic protocol that sits on top of | ||
* the mgmt layer. SMP requests and responses have the following format: | ||
* | ||
* [Offset 0]: Mgmt header | ||
* [Offset 8]: CBOR map of command-specific key-value pairs. | ||
* | ||
* SMP request packets may contain multiple concatenated requests. Each | ||
* request must start at an offset that is a multiple of 4, so padding should | ||
* be inserted between requests as necessary. Requests are processed | ||
* sequentially from the start of the packet to the end. Each response is sent | ||
* individually in its own packet. If a request elicits an error response, | ||
* processing of the packet is aborted. | ||
*/ | ||
|
||
#ifndef H_OMP_ | ||
#define H_OMP_ | ||
|
||
#include "mgmt/mgmt.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct omp_streamer; | ||
struct mgmt_hdr; | ||
|
||
/** | ||
* @brief Transmits an OMP response. | ||
* | ||
* @param stmr The OMP Streamer struct. | ||
* @param retval The return value for the request. | ||
* @param arg Optional streamer argument. | ||
*/ | ||
typedef void omp_tx_rsp_fn(struct omp_streamer *stmr, int retval, void* arg); | ||
|
||
/** | ||
* @brief Decodes, encodes, and transmits OMP requests and responses. | ||
* Holds the callback pointer and the response CBOR encoder provided by | ||
* underlying OIC implementation. | ||
*/ | ||
struct omp_streamer { | ||
struct mgmt_streamer mgmt_stmr; | ||
struct CborEncoder *rsp_encoder; | ||
omp_tx_rsp_fn *tx_rsp_cb; | ||
}; | ||
|
||
/** | ||
* @brief Stores the streamer, management context and request. | ||
*/ | ||
struct omp_state { | ||
struct omp_streamer omp_stmr; | ||
struct mgmt_ctxt *m_ctxt; | ||
void *request; | ||
}; | ||
|
||
|
||
/** | ||
* @brief Processes a single OMP request packet and sends all corresponding | ||
* responses. | ||
* | ||
* Processes all OMP requests in an incoming packet. Requests are processed | ||
* sequentially from the start of the packet to the end. Each response is sent | ||
* individually in its own packet. If a request elicits an error response, | ||
* processing of the packet is aborted. This function consumes the supplied | ||
* request buffer regardless of the outcome.//encoder | ||
* | ||
* @param omgr_st The OMP State struct | ||
* @param req The request packet to process. | ||
* | ||
* @return 0 on success, MGMT_ERR_[...] code on failure. | ||
*/ | ||
int omp_impl_process_request_packet(struct omp_state *omgr_st, void *req); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* H_OMP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef H_OMP_PRIV | ||
#define H_OMP_PRIV | ||
|
||
#include "mgmt/mgmt.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
int omp_encode_mgmt_hdr(struct CborEncoder *enc, struct mgmt_hdr hdr); | ||
int omp_send_err_rsp(struct CborEncoder *enc, | ||
const struct mgmt_hdr *hdr, | ||
int mgmt_status); | ||
int omp_read_hdr(struct CborValue *cv, struct mgmt_hdr *out_hdr); | ||
int omp_process_mgmt_hdr(struct mgmt_hdr *req_hdr, | ||
struct mgmt_hdr *rsp_hdr, | ||
struct mgmt_ctxt *ctxt); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* H_OMP_IMPL */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
pkg.name: omp | ||
pkg.description: Server-side SMP functionality for OIC | ||
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>" | ||
pkg.homepage: "http://mynewt.apache.org/" | ||
pkg.keywords: | ||
- omp | ||
- oicmgr | ||
- mgmt | ||
|
||
pkg.deps: | ||
- "@apache-mynewt-core/kernel/os" | ||
|
||
- "@apache-mynewt-mcumgr/mgmt" | ||
pkg.apis: | ||
- smp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
pkg.name: omp/port/mynewt | ||
pkg.description: 'OIC Management Protocol.' | ||
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>" | ||
pkg.homepage: "http://mynewt.apache.org/" | ||
pkg.keywords: | ||
|
||
pkg.deps: | ||
- '@apache-mynewt-mcumgr/omp' | ||
- '@apache-mynewt-mcumgr/mgmt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <string.h> | ||
|
||
#include "os/mynewt.h" | ||
|
||
#include <mgmt/mgmt.h> | ||
#include <cborattr/cborattr.h> | ||
#include <tinycbor/cbor.h> | ||
|
||
#include "omp/omp.h" | ||
#include "omp/omp_priv.h" | ||
|
||
int | ||
omp_impl_process_request_packet(struct omp_state *omgr_st, void *req_buf) | ||
{ | ||
struct mgmt_ctxt ctxt; | ||
struct omp_streamer *streamer; | ||
struct mgmt_hdr req_hdr, rsp_hdr; | ||
struct os_mbuf *req_m; | ||
int rc = 0; | ||
|
||
assert(omgr_st); | ||
assert(req_buf); | ||
|
||
streamer = &omgr_st->omp_stmr; | ||
omgr_st->m_ctxt = &ctxt; | ||
|
||
req_m = (struct os_mbuf *) req_buf; | ||
|
||
rc = mgmt_streamer_init_reader(&streamer->mgmt_stmr, req_m); | ||
if (rc != 0) { | ||
rc = MGMT_ERR_EINVAL; | ||
return rc; | ||
|
||
} | ||
|
||
rc = omp_read_hdr(&ctxt.it, &req_hdr); | ||
if (rc != 0) { | ||
rc = MGMT_ERR_EINVAL; | ||
return rc; | ||
|
||
} | ||
|
||
memcpy(&rsp_hdr, &req_hdr, sizeof(struct mgmt_hdr)); | ||
|
||
rc = mgmt_streamer_init_reader(&streamer->mgmt_stmr, req_m); | ||
if (rc != 0) { | ||
rc = MGMT_ERR_EINVAL; | ||
return rc; | ||
|
||
} | ||
|
||
rc = cbor_encoder_create_map(streamer->rsp_encoder, | ||
&ctxt.encoder, | ||
CborIndefiniteLength); | ||
if (rc != 0) { | ||
rc = MGMT_ERR_EINVAL; | ||
return rc; | ||
} | ||
|
||
rc = omp_process_mgmt_hdr(&req_hdr, &rsp_hdr, &ctxt); | ||
/* if (err != 0) { */ | ||
/* rc = MGMT_ERR_EINVAL; */ | ||
/* } */ | ||
|
||
cbor_encoder_close_container(streamer->rsp_encoder, &ctxt.encoder); | ||
if (rc != 0) { | ||
rc = MGMT_ERR_EINVAL; | ||
return rc; | ||
|
||
} | ||
|
||
streamer->tx_rsp_cb(streamer, rc, NULL); | ||
return 0; | ||
} |
Oops, something went wrong.