You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/12/14 03:05:42 UTC
[1/4] incubator-mynewt-core git commit: oic;
construct writes directly to mbuf.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop f23d9430e -> 1644f022a
oic; construct writes directly to mbuf.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1644f022
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1644f022
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1644f022
Branch: refs/heads/develop
Commit: 1644f022a59db89726b81a05d5e21f5170944247
Parents: 3ce9c6d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 19:03:25 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 19:04:25 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_rep.h | 3 +-
net/oic/include/oic/oc_ri.h | 3 +
net/oic/src/api/oc_client_api.c | 76 ++++++++++++-------------
net/oic/src/api/oc_core_res.c | 94 +++++++++++++++++--------------
net/oic/src/api/oc_rep.c | 14 ++---
net/oic/src/api/oc_ri.c | 42 +++++++++-----
net/oic/src/api/oc_server_api.c | 3 +-
net/oic/src/messaging/coap/coap.c | 23 ++++++--
net/oic/src/messaging/coap/coap.h | 3 +-
net/oic/src/messaging/coap/engine.c | 42 +++++---------
net/oic/src/messaging/coap/observe.c | 24 +++++---
net/oic/src/messaging/coap/oc_coap.h | 3 +-
12 files changed, 182 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/include/oic/oc_rep.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_rep.h b/net/oic/include/oic/oc_rep.h
index 72ae7fc..17983a4 100644
--- a/net/oic/include/oic/oc_rep.h
+++ b/net/oic/include/oic/oc_rep.h
@@ -31,7 +31,8 @@ extern "C" {
extern CborEncoder g_encoder, root_map, links_array;
extern CborError g_err;
-void oc_rep_new(uint8_t *payload, int size);
+struct os_mbuf;
+void oc_rep_new(struct os_mbuf *m);
void oc_rep_reset(void);
int oc_rep_finalize(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index 9f07d5f..9449685 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -149,6 +149,9 @@ int oc_ri_get_query_value(const char *query, int query_len, const char *key,
oc_interface_mask_t oc_ri_get_interface_mask(char *iface, int if_len);
+bool oc_ri_invoke_coap_entity_handler(void *request, void *response,
+ int32_t *offset, oc_endpoint_t *endpoint);
+
#ifdef __cplusplus
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/api/oc_client_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_client_api.c b/net/oic/src/api/oc_client_api.c
index c15e412..bc29fe1 100644
--- a/net/oic/src/api/oc_client_api.c
+++ b/net/oic/src/api/oc_client_api.c
@@ -22,43 +22,42 @@
#ifdef OC_CLIENT
#define OC_CLIENT_CB_TIMEOUT_SECS COAP_RESPONSE_TIMEOUT
-static struct os_mbuf *message;
-static oc_message_t *rsp;
-static coap_transaction_t *transaction;
-coap_packet_t request[1];
+static struct os_mbuf *oc_c_message;
+static struct os_mbuf *oc_c_rsp;
+static coap_transaction_t *oc_c_transaction;
+static coap_packet_t oc_c_request[1];
static bool
dispatch_coap_request(void)
{
int response_length = oc_rep_finalize();
- if (!transaction) {
- if (message) {
- if (response_length) {
- coap_set_payload(request, rsp->data, response_length);
- coap_set_header_content_format(request, APPLICATION_CBOR);
- }
- if (!coap_serialize_message(request, message)) {
- coap_send_message(message, 0);
+ if (response_length) {
+ oc_c_request->payload_m = oc_c_rsp;
+ oc_c_request->payload_len = response_length;
+ coap_set_header_content_format(oc_c_request, APPLICATION_CBOR);
+ } else {
+ os_mbuf_free_chain(oc_c_rsp);
+ }
+ oc_c_rsp = NULL;
+
+ if (!oc_c_transaction) {
+ if (oc_c_message) {
+ if (!coap_serialize_message(oc_c_request, oc_c_message)) {
+ coap_send_message(oc_c_message, 0);
} else {
- os_mbuf_free_chain(message);
+ os_mbuf_free_chain(oc_c_message);
}
- oc_message_unref(rsp);
- message = NULL;
+ oc_c_message = NULL;
return true;
}
} else {
- if (response_length) {
- coap_set_payload(request, transaction->m, response_length);
- coap_set_header_content_format(request, APPLICATION_CBOR);
- }
- if (!coap_serialize_message(request, transaction->m)) {
- coap_send_transaction(transaction);
+ if (!coap_serialize_message(oc_c_request, oc_c_transaction->m)) {
+ coap_send_transaction(oc_c_transaction);
} else {
- coap_clear_transaction(transaction);
+ coap_clear_transaction(oc_c_transaction);
}
- oc_message_unref(rsp);
- transaction = NULL;
+ oc_c_transaction = NULL;
return true;
}
return false;
@@ -69,33 +68,33 @@ prepare_coap_request(oc_client_cb_t *cb, oc_string_t *query)
{
coap_message_type_t type = COAP_TYPE_NON;
- rsp = oc_allocate_message();
- if (!rsp) {
+ oc_c_rsp = os_msys_get_pkthdr(0, 0);
+ if (!oc_c_rsp) {
return false;
}
if (cb->qos == HIGH_QOS) {
type = COAP_TYPE_CON;
- transaction = coap_new_transaction(cb->mid, &cb->server.endpoint);
- if (!transaction) {
+ oc_c_transaction = coap_new_transaction(cb->mid, &cb->server.endpoint);
+ if (!oc_c_transaction) {
goto free_rsp;
}
} else {
- message = oc_allocate_mbuf(&cb->server.endpoint);
- if (!message) {
+ oc_c_message = oc_allocate_mbuf(&cb->server.endpoint);
+ if (!oc_c_message) {
goto free_rsp;
}
}
- oc_rep_new(rsp->data, COAP_MAX_BLOCK_SIZE);
+ oc_rep_new(oc_c_rsp);
- coap_init_message(request, type, cb->method, cb->mid);
- coap_set_header_accept(request, APPLICATION_CBOR);
- coap_set_token(request, cb->token, cb->token_len);
- coap_set_header_uri_path(request, oc_string(cb->uri));
+ coap_init_message(oc_c_request, type, cb->method, cb->mid);
+ coap_set_header_accept(oc_c_request, APPLICATION_CBOR);
+ coap_set_token(oc_c_request, cb->token, cb->token_len);
+ coap_set_header_uri_path(oc_c_request, oc_string(cb->uri));
if (cb->observe_seq != -1) {
- coap_set_header_observe(request, cb->observe_seq);
+ coap_set_header_observe(oc_c_request, cb->observe_seq);
}
if (query && oc_string_len(*query)) {
- coap_set_header_uri_query(request, oc_string(*query));
+ coap_set_header_uri_query(oc_c_request, oc_string(*query));
}
if (cb->observe_seq == -1 && cb->qos == LOW_QOS) {
os_callout_reset(&cb->callout,
@@ -104,7 +103,8 @@ prepare_coap_request(oc_client_cb_t *cb, oc_string_t *query)
return true;
free_rsp:
- oc_message_unref(rsp);
+ os_mbuf_free_chain(oc_c_rsp);
+ oc_c_rsp = NULL;
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/api/oc_core_res.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_core_res.c b/net/oic/src/api/oc_core_res.c
index 0c4a919..ccb3896 100644
--- a/net/oic/src/api/oc_core_res.c
+++ b/net/oic/src/api/oc_core_res.c
@@ -14,10 +14,12 @@
// limitations under the License.
*/
-#include "oc_core_res.h"
+#include <os/os_mbuf.h>
+
+#include "oic/oc_core_res.h"
#include "messaging/coap/oc_coap.h"
-#include "oc_rep.h"
-#include "oc_ri.h"
+#include "oic/oc_rep.h"
+#include "oic/oc_ri.h"
#ifdef OC_SECURITY
#include "security/oc_pstat.h"
@@ -62,26 +64,26 @@ oc_core_encode_interfaces_mask(CborEncoder *parent,
static void
oc_core_device_handler(oc_request_t *req, oc_interface_mask_t interface)
{
- uint8_t *buffer = req->response->response_buffer->buffer;
- uint16_t buffer_size = req->response->response_buffer->buffer_size;
+ struct oc_response_buffer *rsp_buf;
+ struct os_mbuf *buffer;
int size;
+ char *str;
+ rsp_buf = req->response->response_buffer;
+ buffer = rsp_buf->buffer;
size = oc_string_len(oc_device_info[req->resource->device].payload);
-
- if (buffer_size < size) {
- req->response->response_buffer->response_length = 0;
- req->response->response_buffer->code =
- oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
- return;
- }
+ str = oc_string(oc_device_info[req->resource->device].payload);
switch (interface) {
case OC_IF_R:
case OC_IF_BASELINE:
- memcpy(buffer, oc_string(oc_device_info[req->resource->device].payload),
- size);
- req->response->response_buffer->response_length = size;
- req->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
+ if (os_mbuf_append(buffer, str, size)) {
+ rsp_buf->response_length = 0;
+ rsp_buf->code = oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
+ } else {
+ rsp_buf->response_length = size;
+ rsp_buf->code = oc_status_code(OC_STATUS_OK);
+ }
break;
default:
break;
@@ -95,7 +97,7 @@ oc_core_get_num_devices(void)
}
static int
-finalize_payload(oc_string_t *temp_buffer, oc_string_t *payload)
+finalize_payload(struct os_mbuf *m, oc_string_t *payload)
{
int size;
@@ -103,11 +105,11 @@ finalize_payload(oc_string_t *temp_buffer, oc_string_t *payload)
size = oc_rep_finalize();
if (size != -1) {
oc_alloc_string(payload, size + 1);
- memcpy(payload->os_str, temp_buffer->os_str, size);
- oc_free_string(temp_buffer);
+ os_mbuf_copydata(m, 0, size, payload->os_str);
+ os_mbuf_free_chain(m);
return 1;
}
- oc_free_string(temp_buffer);
+ os_mbuf_free_chain(m);
return -1;
}
@@ -116,12 +118,12 @@ oc_core_add_new_device(const char *uri, const char *rt, const char *name,
const char *spec_version, const char *data_model_version,
oc_core_add_device_cb_t add_device_cb, void *data)
{
- oc_string_t temp_buffer;
+ struct os_mbuf *tmp;
int ocf_d;
char uuid[37];
if (device_count == MAX_NUM_DEVICES) {
- return false;
+ return NULL;
}
/* Once provisioned, UUID is retrieved from the credential store.
@@ -146,8 +148,11 @@ oc_core_add_new_device(const char *uri, const char *rt, const char *name,
oc_core_device_handler, 0, 0, 0, device_count);
/* Encoding device resource payload */
- oc_alloc_string(&temp_buffer, MAX_DEVICE_PAYLOAD_SIZE);
- oc_rep_new(temp_buffer.os_str, MAX_DEVICE_PAYLOAD_SIZE);
+ tmp = os_msys_get_pkthdr(0, 0);
+ if (!tmp) {
+ return NULL;
+ }
+ oc_rep_new(tmp);
oc_rep_start_root_object();
@@ -165,7 +170,7 @@ oc_core_add_new_device(const char *uri, const char *rt, const char *name,
if (add_device_cb) {
add_device_cb(data);
}
- if (!finalize_payload(&temp_buffer, &oc_device_info[device_count].payload)){
+ if (!finalize_payload(tmp, &oc_device_info[device_count].payload)) {
return NULL;
}
@@ -173,27 +178,28 @@ oc_core_add_new_device(const char *uri, const char *rt, const char *name,
}
void
-oc_core_platform_handler(oc_request_t *request, oc_interface_mask_t interface)
+oc_core_platform_handler(oc_request_t *req, oc_interface_mask_t interface)
{
- uint8_t *buffer = request->response->response_buffer->buffer;
- uint16_t buffer_size = request->response->response_buffer->buffer_size;
+ struct oc_response_buffer *rsp_buf;
+ struct os_mbuf *buffer;
int size;
+ char *str;
+ rsp_buf = req->response->response_buffer;
+ buffer = rsp_buf->buffer;
size = oc_string_len(oc_platform_payload);
-
- if (buffer_size < size) {
- request->response->response_buffer->response_length = 0;
- request->response->response_buffer->code =
- oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
- return;
- }
+ str = oc_string(oc_platform_payload);
switch (interface) {
case OC_IF_R:
case OC_IF_BASELINE:
- memcpy(buffer, oc_string(oc_platform_payload), size);
- request->response->response_buffer->response_length = size;
- request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
+ if (os_mbuf_append(buffer, str, size)) {
+ rsp_buf->response_length = 0;
+ rsp_buf->code = oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
+ } else {
+ rsp_buf->response_length = size;
+ rsp_buf->code = oc_status_code(OC_STATUS_OK);
+ }
break;
default:
break;
@@ -204,7 +210,7 @@ oc_string_t *
oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb,
void *data)
{
- oc_string_t temp_buffer;
+ struct os_mbuf *tmp;
oc_uuid_t uuid; /*fix uniqueness of platform id?? */
char uuid_str[37];
@@ -218,11 +224,13 @@ oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb,
oc_core_platform_handler, 0, 0, 0, 0);
/* Encoding platform resource payload */
- oc_alloc_string(&temp_buffer, MAX_PLATFORM_PAYLOAD_SIZE);
- oc_rep_new(temp_buffer.os_str, MAX_PLATFORM_PAYLOAD_SIZE);
+ tmp = os_msys_get_pkthdr(0, 0);
+ if (!tmp) {
+ return NULL;
+ }
+ oc_rep_new(tmp);
oc_rep_start_root_object();
oc_rep_set_string_array(root, rt, core_resources[OCF_P].types);
-
oc_core_encode_interfaces_mask(oc_rep_object(root),
core_resources[OCF_P].interfaces);
oc_rep_set_uint(root, p, core_resources[OCF_P].properties & ~OC_PERIODIC);
@@ -237,7 +245,7 @@ oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb,
if (init_cb) {
init_cb(data);
}
- if (!finalize_payload(&temp_buffer, &oc_platform_payload)) {
+ if (!finalize_payload(tmp, &oc_platform_payload)) {
return NULL;
}
return &oc_platform_payload;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index 20a133a..2e70582 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -22,7 +22,7 @@
#include "config.h"
#include "port/oc_assert.h"
#include "api/oc_priv.h"
-#include <tinycbor/cbor_buf_writer.h>
+#include <tinycbor/cbor_mbuf_writer.h>
#include <tinycbor/cbor_buf_reader.h>
#ifdef OC_CLIENT
@@ -32,24 +32,24 @@ static uint8_t oc_rep_objects_area[OS_MEMPOOL_BYTES(EST_NUM_REP_OBJECTS,
#endif
static const CborEncoder g_empty;
-static uint8_t *g_buf;
+static struct os_mbuf *g_outm;
CborEncoder g_encoder, root_map, links_array;
CborError g_err;
-struct CborBufWriter g_buf_writer;
+struct CborMbufWriter g_buf_writer;
void
-oc_rep_new(uint8_t *out_payload, int size)
+oc_rep_new(struct os_mbuf *m)
{
g_err = CborNoError;
- g_buf = out_payload;
- cbor_buf_writer_init(&g_buf_writer, out_payload, size);
+ g_outm = m;
+ cbor_mbuf_writer_init(&g_buf_writer, m);
cbor_encoder_init(&g_encoder, &g_buf_writer.enc, 0);
}
int
oc_rep_finalize(void)
{
- int size = cbor_buf_writer_buffer_size(&g_buf_writer, g_buf);
+ int size = OS_MBUF_PKTLEN(g_outm);
oc_rep_reset();
if (g_err != CborNoError) {
return -1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 36d3cbb..3ff5040 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -357,9 +357,8 @@ does_interface_support_method(oc_resource_t *resource,
}
bool
-oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
- uint16_t buffer_size, int32_t *offset,
- oc_endpoint_t *endpoint)
+oc_ri_invoke_coap_entity_handler(void *request, void *response,
+ int32_t *offset, oc_endpoint_t *endpoint)
{
/* Flags that capture status along various stages of processing
* the request.
@@ -382,9 +381,9 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
oc_request_t request_obj;
oc_response_buffer_t response_buffer;
oc_response_t response_obj;
+ struct os_mbuf *m = NULL;
- response_buffer.buffer = buffer;
- response_buffer.buffer_size = buffer_size;
+ response_buffer.buffer = NULL;
response_buffer.block_offset = offset;
response_buffer.code = 0;
response_buffer.response_length = 0;
@@ -473,6 +472,12 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
bad_request = true;
}
+ m = os_msys_get_pkthdr(0, 0);
+ if (!m) {
+ bad_request = true;
+ }
+ response_buffer.buffer = m;
+
if (cur_resource && !bad_request) {
/* Process a request against a valid resource, request payload, and
* interface.
@@ -482,7 +487,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
* points to memory allocated in the messaging layer for the "CoAP
* Transaction" to service this request.
*/
- oc_rep_new(buffer, buffer_size);
+ oc_rep_new(m);
#ifdef OC_SECURITY
/* If cur_resource is a coaps:// resource, then query ACL to check if
@@ -514,9 +519,14 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
}
if (bad_request) {
- OC_LOG_ERROR("ocri: Bad request\n");
- /* Return a 4.00 response */
- response_buffer.code = oc_status_code(OC_STATUS_BAD_REQUEST);
+ if (!m) {
+ OC_LOG_ERROR("ocri: No bufs\n");
+ response_buffer.code = oc_status_code(OC_STATUS_SERVICE_UNAVAILABLE);
+ } else {
+ OC_LOG_ERROR("ocri: Bad request\n");
+ /* Return a 4.00 response */
+ response_buffer.code = oc_status_code(OC_STATUS_BAD_REQUEST);
+ }
success = false;
} else if (!cur_resource) {
OC_LOG_ERROR("ocri: Could not find resource\n");
@@ -627,19 +637,23 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
* of that resource with the change.
*/
if ((method == OC_PUT || method == OC_POST) &&
- response_buffer.code < oc_status_code(OC_STATUS_BAD_REQUEST))
- coap_notify_observers(cur_resource, NULL, NULL);
+ response_buffer.code < oc_status_code(OC_STATUS_BAD_REQUEST)) {
+ coap_notify_observers(cur_resource, NULL, NULL);
+ }
#endif
if (response_buffer.response_length) {
- coap_set_payload(response, response_buffer.buffer,
- response_buffer.response_length);
- coap_set_header_content_format(response, APPLICATION_CBOR);
+ coap_set_payload(response, response_buffer.buffer,
+ OS_MBUF_PKTLEN(response_buffer.buffer));
+ coap_set_header_content_format(response, APPLICATION_CBOR);
}
/* response_buffer.code at this point contains a valid CoAP status
* code.
*/
coap_set_status_code(response, response_buffer.code);
}
+ if (response_buffer.buffer) {
+ os_mbuf_free_chain(response_buffer.buffer);
+ }
return success;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/api/oc_server_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_server_api.c b/net/oic/src/api/oc_server_api.c
index 071bf40..f697f5c 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -216,6 +216,7 @@ oc_interate_query(oc_request_t *request, char **key, int *key_len, char **value,
return 1;
}
+#if 0 /* XXXX fix this */
void
oc_indicate_separate_response(oc_request_t *request,
oc_separate_response_t *response)
@@ -277,7 +278,7 @@ oc_send_separate_response(oc_separate_response_t *handle,
handle->active = 0;
}
}
-
+#endif
int
oc_notify_observers(oc_resource_t *resource)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index d4cb082..909e95f 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -446,16 +446,23 @@ coap_serialize_message(coap_packet_t *pkt, struct os_mbuf *m)
}
}
- if (os_mbuf_append(m, pkt->payload, pkt->payload_len)) {
- goto err_mem;
+ if (pkt->payload_m) {
+ assert(pkt->payload_len <= OS_MBUF_PKTLEN(pkt->payload_m));
+ if (pkt->payload_len < OS_MBUF_PKTLEN(pkt->payload_m)) {
+ os_mbuf_adj(pkt->payload_m,
+ OS_MBUF_PKTLEN(pkt->payload_m) - pkt->payload_len);
+ }
+ os_mbuf_concat(m, pkt->payload_m);
}
-
OC_LOG_DEBUG("coap_tx: serialized %u B (header len %u, payload len %u)\n",
OS_MBUF_PKTLEN(m), OS_MBUF_PKTLEN(m) - pkt->payload_len,
pkt->payload_len);
return 0;
err_mem:
+ if (pkt->payload_m) {
+ os_mbuf_free_chain(pkt->payload_m);
+ }
STATS_INC(coap_stats, oerr);
return -1;
}
@@ -1251,11 +1258,15 @@ coap_get_payload(coap_packet_t *pkt, const uint8_t **payload)
return 0;
}
}
+
int
-coap_set_payload(coap_packet_t *pkt, const void *payload, size_t length)
+coap_set_payload(coap_packet_t *pkt, struct os_mbuf *m, size_t length)
{
- pkt->payload = (uint8_t *)payload;
- pkt->payload_len = MIN(MAX_PAYLOAD_SIZE, length);
+ pkt->payload_m = os_mbuf_dup(m);
+ if (!pkt->payload_m) {
+ return -1;
+ }
+ pkt->payload_len = MIN(OS_MBUF_PKTLEN(m), length);
return pkt->payload_len;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 3dc0f49..c422a2f 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -158,6 +158,7 @@ typedef struct coap_packet {
uint16_t payload_len;
uint8_t *payload;
+ struct os_mbuf *payload_m;
} coap_packet_t;
/*
@@ -320,7 +321,7 @@ int coap_get_header_size1(coap_packet_t *, uint32_t *size);
int coap_set_header_size1(coap_packet_t *, uint32_t size);
int coap_get_payload(coap_packet_t *, const uint8_t **payload);
-int coap_set_payload(coap_packet_t *, const void *payload, size_t length);
+int coap_set_payload(coap_packet_t *, struct os_mbuf *m, size_t length);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index f06097b..13abeb1 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -44,12 +44,6 @@
#include "oc_client_state.h"
#endif
-extern bool oc_ri_invoke_coap_entity_handler(void *request, void *response,
- uint8_t *buffer,
- uint16_t buffer_size,
- int32_t *offset,
- oc_endpoint_t *endpoint);
-
/*---------------------------------------------------------------------------*/
/*- Internal API ------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
@@ -61,7 +55,7 @@ coap_receive(oc_message_t *msg)
static coap_packet_t message[1];
static coap_packet_t response[1];
static coap_transaction_t *transaction = NULL;
- static oc_message_t *rsp;
+ struct os_mbuf *rsp;
erbium_status_code = NO_ERROR;
@@ -150,13 +144,8 @@ coap_receive(oc_message_t *msg)
new_offset = block_offset;
}
- rsp = oc_allocate_message();
- if (!rsp) {
- erbium_status_code = SERVICE_UNAVAILABLE_5_03;
- coap_error_message = "NoFreeTraBuffer";
- } else if (oc_ri_invoke_coap_entity_handler(message, response,
- rsp->data, block_size, &new_offset,
- &msg->endpoint)) {
+ if (oc_ri_invoke_coap_entity_handler(message, response,
+ &new_offset, &msg->endpoint)) {
if (erbium_status_code == NO_ERROR) {
/*
* TODO coap_handle_blockwise(request, response,
@@ -184,17 +173,21 @@ coap_receive(oc_message_t *msg)
response->payload_len, block_size);
if (block_offset >= response->payload_len) {
response->code = BAD_OPTION_4_02;
- coap_set_payload(response, "BlockOutOfScope", 15);
+ rsp = os_msys_get_pkthdr(0, 0);
+ if (rsp) {
+ os_mbuf_copyinto(rsp, 0, "BlockOutOfScope", 15);
+ response->payload_m = rsp;
+ response->payload_len = 15;
+ }
/* a const char str[] and sizeof(str)
produces larger code size */
} else {
coap_set_header_block2(response, block_num,
response->payload_len - block_offset >
block_size, block_size);
- coap_set_payload(response,
- response->payload + block_offset,
- MIN(response->payload_len -
- block_offset, block_size));
+ response->payload_len = MIN(response->payload_len -
+ block_offset,
+ block_size);
} /* if(valid offset) */
/* resource provides chunk-wise data */
@@ -207,8 +200,7 @@ coap_receive(oc_message_t *msg)
block_size);
if (response->payload_len > block_size) {
- coap_set_payload(response, response->payload,
- block_size);
+ response->payload_len = block_size;
}
} /* if(resource aware of blockwise) */
@@ -219,9 +211,8 @@ coap_receive(oc_message_t *msg)
coap_set_header_block2(response, 0, new_offset != -1,
COAP_MAX_BLOCK_SIZE);
- coap_set_payload(response, response->payload,
- MIN(response->payload_len,
- COAP_MAX_BLOCK_SIZE));
+ response->payload_len = MIN(response->payload_len,
+ COAP_MAX_BLOCK_SIZE);
} /* blockwise transfer handling */
} /* no errors/hooks */
/* successful service callback */
@@ -233,9 +224,6 @@ coap_receive(oc_message_t *msg)
}
transaction->type = response->type;
}
- if (rsp) {
- oc_message_unref(rsp);
- }
} else { // Fix this
/* handle responses */
if (message->type == COAP_TYPE_CON) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 1b7404d..7bc8537 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -193,6 +193,11 @@ coap_notify_observers(oc_resource_t *resource,
oc_endpoint_t *endpoint)
{
int num_observers = 0;
+ oc_request_t request = {};
+ oc_response_t response = {};
+ oc_response_buffer_t response_buffer;
+ struct os_mbuf *m = NULL;
+
if (resource) {
if (!resource->num_observers) {
OC_LOG_DEBUG("coap_notify_observers: no observers left\n");
@@ -200,21 +205,21 @@ coap_notify_observers(oc_resource_t *resource,
}
num_observers = resource->num_observers;
}
- uint8_t buffer[COAP_MAX_BLOCK_SIZE];
- oc_request_t request = {};
- oc_response_t response = {};
response.separate_response = 0;
- oc_response_buffer_t response_buffer;
if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
OC_LOG_DEBUG("coap_notify_observers: Issue GET request to resource\n");
/* performing GET on the resource */
- response_buffer.buffer = buffer;
- response_buffer.buffer_size = COAP_MAX_BLOCK_SIZE;
+ m = os_msys_get_pkthdr(0, 0);
+ if (!m) {
+ /* XXX count */
+ return num_observers;
+ }
+ response_buffer.buffer = m;
response_buffer.block_offset = NULL;
response.response_buffer = &response_buffer;
request.resource = resource;
request.response = &response;
- oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
+ oc_rep_new(m);
resource->get_handler(&request, resource->default_interface);
response_buf = &response_buffer;
if (response_buf->code == OC_IGNORE) {
@@ -270,7 +275,7 @@ coap_notify_observers(oc_resource_t *resource,
notification->type = COAP_TYPE_CON;
}
coap_set_payload(notification, response_buf->buffer,
- response_buf->response_length);
+ OS_MBUF_PKTLEN(response_buf->buffer));
coap_set_status_code(notification, response_buf->code);
if (notification->code < BAD_REQUEST_4_00 &&
obs->resource->num_observers) {
@@ -290,6 +295,9 @@ coap_notify_observers(oc_resource_t *resource,
}
}
}
+ if (m) {
+ os_mbuf_free_chain(m);
+ }
return num_observers;
}
/*---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1644f022/net/oic/src/messaging/coap/oc_coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/oc_coap.h b/net/oic/src/messaging/coap/oc_coap.h
index dcc0352..2654d98 100644
--- a/net/oic/src/messaging/coap/oc_coap.h
+++ b/net/oic/src/messaging/coap/oc_coap.h
@@ -30,8 +30,7 @@ typedef struct oc_separate_response {
} oc_separate_response_t;
typedef struct oc_response_buffer {
- uint8_t *buffer;
- uint16_t buffer_size;
+ struct os_mbuf *buffer;
int32_t *block_offset;
uint16_t response_length;
int code;
[4/4] incubator-mynewt-core git commit: oic;
fix build warning when neither IP and BLE transport options were
compiled in.
Posted by ma...@apache.org.
oic; fix build warning when neither IP and BLE transport options
were compiled in.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4b6a012a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4b6a012a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4b6a012a
Branch: refs/heads/develop
Commit: 4b6a012aa0293da44bb0d6cfc878b4f41407c5c3
Parents: f23d943
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 11:48:51 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 19:04:25 2016 -0800
----------------------------------------------------------------------
net/oic/src/port/mynewt/log.c | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b6a012a/net/oic/src/port/mynewt/log.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c
index 9a877bf..85b80c6 100644
--- a/net/oic/src/port/mynewt/log.c
+++ b/net/oic/src/port/mynewt/log.c
@@ -32,6 +32,8 @@ oc_log_endpoint(uint16_t lvl, struct oc_endpoint *oe)
char *str;
char tmp[46 + 6];
+ (void)tmp;
+
switch (oe->flags) {
#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
case IP: {
[3/4] incubator-mynewt-core git commit: bootutil;
update signed_images.md with the new location of bootutil.
Posted by ma...@apache.org.
bootutil; update signed_images.md with the new location of bootutil.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3ce9c6d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3ce9c6d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3ce9c6d2
Branch: refs/heads/develop
Commit: 3ce9c6d2ee19021277d7cb332e8a02f6dbff6ab1
Parents: 8b2d941
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 17:15:24 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 19:04:25 2016 -0800
----------------------------------------------------------------------
boot/bootutil/signed_images.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ce9c6d2/boot/bootutil/signed_images.md
----------------------------------------------------------------------
diff --git a/boot/bootutil/signed_images.md b/boot/bootutil/signed_images.md
index 64869c1..e7cc2dd 100644
--- a/boot/bootutil/signed_images.md
+++ b/boot/bootutil/signed_images.md
@@ -65,7 +65,7 @@ This gets bootutil to turn on image signature validation.
pkg.name: libs/mykeys
pkg.deps:
- - libs/bootutil
+ - "@apache-mynewt-core/boot/bootutil"
## Sample source file
This exports the keys.
[2/4] incubator-mynewt-core git commit: oic;
don't automatically decode incoming payload to a tree of allocated
objects. Make handlers do the decoding, allowing them to use stack-only
construct.
Posted by ma...@apache.org.
oic; don't automatically decode incoming payload to a tree of
allocated objects. Make handlers do the decoding, allowing them
to use stack-only construct.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8b2d9412
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8b2d9412
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8b2d9412
Branch: refs/heads/develop
Commit: 8b2d9412b1b296ba5c783ebd640fca995f89ecab
Parents: 4b6a012
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 12:18:08 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 19:04:25 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_rep.h | 2 +
net/oic/include/oic/oc_ri.h | 4 +-
net/oic/src/api/oc_discovery.c | 66 +++++++++++++++----------------
net/oic/src/api/oc_rep.c | 4 ++
net/oic/src/api/oc_ri.c | 26 +-----------
net/oic/src/messaging/coap/observe.c | 1 -
6 files changed, 40 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/include/oic/oc_rep.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_rep.h b/net/oic/include/oic/oc_rep.h
index 4ccaa20..72ae7fc 100644
--- a/net/oic/include/oic/oc_rep.h
+++ b/net/oic/include/oic/oc_rep.h
@@ -190,6 +190,7 @@ int oc_rep_finalize(void);
g_err |= cbor_encoder_close_container(&object##_map, &key##_value_array); \
} while (0)
+#ifdef OC_CLIENT
typedef enum {
NIL = 0,
INT = 0x01,
@@ -229,6 +230,7 @@ uint16_t oc_parse_rep(const uint8_t *payload, uint16_t payload_size,
oc_rep_t **value_list);
void oc_free_rep(oc_rep_t *rep);
+#endif
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index c501f46..9f07d5f 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -97,13 +97,11 @@ typedef enum {
typedef struct oc_resource oc_resource_t;
-typedef struct
-{
+typedef struct {
oc_endpoint_t *origin;
oc_resource_t *resource;
const char *query;
int query_len;
- oc_rep_t *request_payload;
oc_response_t *response;
void *packet;
} oc_request_t;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/src/api/oc_discovery.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_discovery.c b/net/oic/src/api/oc_discovery.c
index 29311b7..be5be0c 100644
--- a/net/oic/src/api/oc_discovery.c
+++ b/net/oic/src/api/oc_discovery.c
@@ -127,45 +127,43 @@ process_device_object(CborEncoder *device, const char *uuid, const char *rt,
}
static void
-oc_core_discovery_handler(oc_request_t *request, oc_interface_mask_t interface)
+oc_core_discovery_handler(oc_request_t *req, oc_interface_mask_t interface)
{
- char *rt = NULL;
- int rt_len = 0, matches = 0;
- if (request->query_len) {
- rt_len =
- oc_ri_get_query_value(request->query, request->query_len, "rt", &rt);
- }
+ char *rt = NULL;
+ int rt_len = 0, matches = 0;
+ char uuid[37];
- char uuid[37];
- oc_uuid_to_str(oc_core_get_device_id(0), uuid, 37);
+ rt_len = oc_ri_get_query_value(req->query, req->query_len, "rt", &rt);
- switch (interface) {
- case OC_IF_LL: {
- oc_rep_start_links_array();
- matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
- oc_rep_end_links_array();
- } break;
- case OC_IF_BASELINE: {
- oc_rep_start_root_object();
- oc_process_baseline_interface(request->resource);
- oc_rep_set_array(root, links);
- matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
- oc_rep_close_array(root, links);
- oc_rep_end_root_object();
- } break;
- default:
- break;
- }
+ oc_uuid_to_str(oc_core_get_device_id(0), uuid, sizeof(uuid));
- int response_length = oc_rep_finalize();
+ switch (interface) {
+ case OC_IF_LL: {
+ oc_rep_start_links_array();
+ matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
+ oc_rep_end_links_array();
+ } break;
+ case OC_IF_BASELINE: {
+ oc_rep_start_root_object();
+ oc_process_baseline_interface(req->resource);
+ oc_rep_set_array(root, links);
+ matches = process_device_object(oc_rep_array(links), uuid, rt, rt_len);
+ oc_rep_close_array(root, links);
+ oc_rep_end_root_object();
+ } break;
+ default:
+ break;
+ }
- if (matches && response_length > 0) {
- request->response->response_buffer->response_length = response_length;
- request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
- } else {
- /* There were rt/if selections and there were no matches, so ignore */
- request->response->response_buffer->code = OC_IGNORE;
- }
+ int response_length = oc_rep_finalize();
+
+ if (matches && response_length > 0) {
+ req->response->response_buffer->response_length = response_length;
+ req->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
+ } else {
+ /* There were rt/if selections and there were no matches, so ignore */
+ req->response->response_buffer->code = OC_IGNORE;
+ }
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index 4ef7161..20a133a 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -25,9 +25,11 @@
#include <tinycbor/cbor_buf_writer.h>
#include <tinycbor/cbor_buf_reader.h>
+#ifdef OC_CLIENT
static struct os_mempool oc_rep_objects;
static uint8_t oc_rep_objects_area[OS_MEMPOOL_BYTES(EST_NUM_REP_OBJECTS,
sizeof(oc_rep_t))];
+#endif
static const CborEncoder g_empty;
static uint8_t *g_buf;
@@ -61,6 +63,7 @@ oc_rep_reset(void)
g_encoder = g_empty;
}
+#ifdef OC_CLIENT
static oc_rep_t *
_alloc_rep(void)
{
@@ -321,3 +324,4 @@ oc_rep_init(void)
os_mempool_init(&oc_rep_objects, EST_NUM_REP_OBJECTS,
sizeof(oc_rep_t), oc_rep_objects_area, "oc_rep_o");
}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index d240193..36d3cbb 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -229,8 +229,8 @@ oc_ri_init(void)
SLIST_INIT(&oc_client_cbs);
os_mempool_init(&oc_client_cb_pool, MAX_NUM_CONCURRENT_REQUESTS,
sizeof(oc_client_cb_t), oc_client_cb_area, "oc_cl_cbs");
-#endif
oc_rep_init();
+#endif
oc_buffer_init();
start_processes();
@@ -393,7 +393,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
response_obj.response_buffer = &response_buffer;
request_obj.response = &response_obj;
- request_obj.request_payload = 0;
request_obj.query_len = 0;
request_obj.resource = 0;
request_obj.origin = endpoint;
@@ -422,22 +421,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
}
}
- /* Obtain handle to buffer containing the serialized payload */
- const uint8_t *payload;
- int payload_len = coap_get_payload(request, &payload);
- if (payload_len) {
- /* Attempt to parse request payload using tinyCBOR via oc_rep helper
- * functions. The result of this parse is a tree of oc_rep_t structures
- * which will reflect the schema of the payload.
- * Any failures while parsing the payload is viewed as an erroneous
- * request and results in a 4.00 response being sent.
- */
- if (oc_parse_rep(payload, payload_len, &request_obj.request_payload) != 0) {
- OC_LOG_ERROR("ocri: error parsing request payload\n");
- bad_request = true;
- }
- }
-
oc_resource_t *resource, *cur_resource = NULL;
/* If there were no errors thus far, attempt to locate the specific
@@ -530,13 +513,6 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
}
}
- if (payload_len) {
- /* To the extent that the request payload was parsed, free the
- * payload structure (and return its memory to the pool).
- */
- oc_free_rep(request_obj.request_payload);
- }
-
if (bad_request) {
OC_LOG_ERROR("ocri: Bad request\n");
/* Return a 4.00 response */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b2d9412/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 73d70e8..1b7404d 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -214,7 +214,6 @@ coap_notify_observers(oc_resource_t *resource,
response.response_buffer = &response_buffer;
request.resource = resource;
request.response = &response;
- request.request_payload = NULL;
oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
resource->get_handler(&request, resource->default_interface);
response_buf = &response_buffer;