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/11/30 16:57:49 UTC

[01/16] incubator-mynewt-core git commit: oic; use malloc() instead of os_mmem.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 425e06fa9 -> 5f7ad8cb0


oic; use malloc() instead of os_mmem.


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/0526e079
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0526e079
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0526e079

Branch: refs/heads/develop
Commit: 0526e07932dc5ef87a658d07279efe1dfae1dbfa
Parents: 566da38
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 08:07:52 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_helpers.h |  89 +++++----
 net/oic/include/oic/oc_rep.h     |   1 +
 net/oic/src/api/oc_core_res.c    | 359 ++++++++++++++++++----------------
 net/oic/src/api/oc_discovery.c   |  13 +-
 net/oic/src/api/oc_helpers.c     | 180 +++++++----------
 net/oic/src/api/oc_rep.c         |   8 +-
 6 files changed, 322 insertions(+), 328 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/net/oic/include/oic/oc_helpers.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_helpers.h b/net/oic/include/oic/oc_helpers.h
index 7520c7b..4855f94 100644
--- a/net/oic/include/oic/oc_helpers.h
+++ b/net/oic/include/oic/oc_helpers.h
@@ -28,56 +28,71 @@
 extern "C" {
 #endif
 
-typedef struct oc_mmem oc_handle_t, oc_string_t, oc_array_t, oc_string_array_t;
+#define STRING_ARRAY_ITEM_MAX_LEN 24
+
+typedef struct oc_string {
+    uint16_t os_sz;
+    uint8_t *os_str;
+} oc_string_t;
+
+typedef struct oc_array {
+    uint16_t oa_sz;
+    union {
+        bool *b;
+        int64_t *i;
+        double *d;
+        char *s;
+    } oa_arr;
+} oc_array_t;
 
-#define oc_cast(block, type) ((type *)(OC_MMEM_PTR(&(block))))
-#define oc_string(ocstring) (oc_cast(ocstring, char))
+typedef struct oc_array oc_string_array_t;
+
+#define oc_string(ocstring) ((char *)(ocstring).os_str)
 
 void oc_new_string(oc_string_t *ocstring, const char str[]);
 void oc_alloc_string(oc_string_t *ocstring, int size);
 void oc_free_string(oc_string_t *ocstring);
-void oc_concat_strings(oc_string_t *concat, const char *str1, const char *str2);
-#define oc_string_len(ocstring) ((ocstring).size ? (ocstring).size - 1 : 0)
+void oc_concat_strings(oc_string_t *concat, const char *, const char *);
+#define oc_string_len(ocstring) ((ocstring).os_sz ? (ocstring).os_sz - 1 : 0)
+
+void _oc_new_array(oc_array_t *ocarray, uint8_t size, uint8_t elem_sz);
+void _oc_free_array(oc_array_t *ocarray);
 
-void _oc_new_array(oc_array_t *ocarray, uint8_t size, pool type);
-void _oc_free_array(oc_array_t *ocarray, pool type);
-#define oc_new_int_array(ocarray, size) (_oc_new_array(ocarray, size, INT_POOL))
-#define oc_new_bool_array(ocarray, size)                                       \
-  (_oc_new_array(ocarray, size, BYTE_POOL))
-#define oc_new_double_array(ocarray, size)                                     \
-  (_oc_new_array(ocarray, size, DOUBLE_POOL))
-#define oc_free_int_array(ocarray) (_oc_free_array(ocarray, INT_POOL))
-#define oc_free_bool_array(ocarray) (_oc_free_array(ocarray, BYTE_POOL))
-#define oc_free_double_array(ocarray) (_oc_free_array(ocarray, DOUBLE_POOL))
-#define oc_int_array_size(ocintarray) ((ocintarray).size / sizeof(int64_t))
-#define oc_bool_array_size(ocboolarray) ((ocboolarray).size / sizeof(bool))
+#define oc_new_int_array(ocarray, size)                                 \
+    _oc_new_array(ocarray, size, sizeof(uint64_t))
+#define oc_new_bool_array(ocarray, size)                                \
+    _oc_new_array(ocarray, size, sizeof(bool))
+#define oc_new_double_array(ocarray, size)                              \
+    _oc_new_array(ocarray, size, sizeof(double))
+#define oc_free_int_array(ocarray) _oc_free_array(ocarray)
+#define oc_free_bool_array(ocarray) _oc_free_array(ocarray)
+#define oc_free_double_array(ocarray) _oc_free_array(ocarray)
+#define oc_int_array_size(ocintarray) ((ocintarray).oa_sz / sizeof(int64_t))
+#define oc_bool_array_size(ocboolarray) ((ocboolarray).oa_sz / sizeof(bool))
 #define oc_double_array_size(ocdoublearray)                                    \
-  ((ocdoublearray).size / sizeof(double))
-#define oc_int_array(ocintarray) (oc_cast(ocintarray, int64_t))
-#define oc_bool_array(ocboolarray) (oc_cast(ocboolarray, bool))
-#define oc_double_array(ocdoublearray) (oc_cast(ocdoublearray, double))
+  ((ocdoublearray).oa_sz / sizeof(double))
+#define oc_int_array(ocintarray) (ocintarray.oa_arr.i)
+#define oc_bool_array(ocboolarray) (ocboolarray.oa_arr.b)
+#define oc_double_array(ocdoublearray) (ocdoublearray.oa_arr.d)
 
-#define STRING_ARRAY_ITEM_MAX_LEN 24
 void _oc_alloc_string_array(oc_string_array_t *ocstringarray, uint8_t size);
 bool _oc_copy_string_to_string_array(oc_string_array_t *ocstringarray,
                                      const char str[], uint8_t index);
 bool _oc_string_array_add_item(oc_string_array_t *ocstringarray,
                                const char str[]);
-void oc_join_string_array(oc_string_array_t *ocstringarray,
-                          oc_string_t *ocstring);
-#define oc_new_string_array(ocstringarray, size)                               \
-  (_oc_alloc_string_array(ocstringarray, size))
-#define oc_free_string_array(ocstringarray) (oc_free_string(ocstringarray))
-#define oc_string_array_add_item(ocstringarray, str)                           \
-  (_oc_string_array_add_item(&(ocstringarray), str))
-#define oc_string_array_get_item(ocstringarray, index)                         \
-  (oc_string(ocstringarray) + index * STRING_ARRAY_ITEM_MAX_LEN)
-#define oc_string_array_set_item(ocstringarray, str, index)                    \
-  (_oc_copy_string_to_string_array(&(ocstringarray), str, index))
-#define oc_string_array_get_item_size(ocstringarray, index)                    \
-  (strlen((const char *)oc_string_array_get_item(ocstringarray, index)))
-#define oc_string_array_get_allocated_size(ocstringarray)                      \
-  ((ocstringarray).size / STRING_ARRAY_ITEM_MAX_LEN)
+#define oc_new_string_array(ocstringarray, size)                        \
+    (_oc_alloc_string_array(ocstringarray, size))
+#define oc_free_string_array(ocs) (_oc_free_array(ocs))
+#define oc_string_array_add_item(ocstringarray, str)                    \
+    (_oc_string_array_add_item(&(ocstringarray), str))
+#define oc_string_array_get_item(ocstringarray, index)                  \
+    (&(ocstringarray.oa_arr.s[index * STRING_ARRAY_ITEM_MAX_LEN]))
+#define oc_string_array_set_item(ocstringarray, str, index)             \
+    (_oc_copy_string_to_string_array(&(ocstringarray), str, index))
+#define oc_string_array_get_item_size(ocstringarray, index)             \
+    (strlen(oc_string_array_get_item(ocstringarray, index)))
+#define oc_string_array_get_allocated_size(ocstringarray)               \
+    (ocstringarray.oa_sz / STRING_ARRAY_ITEM_MAX_LEN)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/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 f0f80a6..4ccaa20 100644
--- a/net/oic/include/oic/oc_rep.h
+++ b/net/oic/include/oic/oc_rep.h
@@ -219,6 +219,7 @@ typedef struct oc_rep_s
     double value_double;
     oc_string_t value_string;
     oc_array_t value_array;
+    oc_string_array_t value_string_array;
     struct oc_rep_s *value_object;
     struct oc_rep_s *value_object_array;
   };

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/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 ced0f88..c3f4e66 100644
--- a/net/oic/src/api/oc_core_res.c
+++ b/net/oic/src/api/oc_core_res.c
@@ -24,10 +24,9 @@
 #endif /* OC_SECURITY */
 
 static oc_resource_t core_resources[NUM_OC_CORE_RESOURCES];
-struct oc_device_info_t
-{
-  oc_uuid_t uuid;
-  oc_string_t payload;
+static struct oc_device_info {
+    oc_uuid_t uuid;
+    oc_string_t payload;
 } oc_device_info[MAX_NUM_DEVICES];
 static int device_count;
 static oc_string_t oc_platform_payload;
@@ -36,78 +35,80 @@ void
 oc_core_encode_interfaces_mask(CborEncoder *parent,
                                oc_interface_mask_t interface)
 {
-  oc_rep_set_key((*parent), "if");
-  oc_rep_start_array((*parent), if);
-  if (interface & OC_IF_LL) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_LL);
-  }
-  if (interface & OC_IF_B) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_B);
-  }
-  if (interface & OC_IF_R) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_R);
-  }
-  if (interface & OC_IF_RW) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_RW);
-  }
-  if (interface & OC_IF_A) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_A);
-  }
-  if (interface & OC_IF_S) {
-    oc_rep_add_text_string(if, OC_RSRVD_IF_S);
-  }
-  oc_rep_add_text_string(if, OC_RSRVD_IF_BASELINE);
-  oc_rep_end_array((*parent), if);
+    oc_rep_set_key((*parent), "if");
+    oc_rep_start_array((*parent), if);
+    if (interface & OC_IF_LL) {
+        oc_rep_add_text_string(if, OC_RSRVD_IF_LL);
+    }
+    if (interface & OC_IF_B) {
+        oc_rep_add_text_string(if, OC_RSRVD_IF_B);
+    }
+    if (interface & OC_IF_R) {
+        oc_rep_add_text_string(if, OC_RSRVD_IF_R);
+    }
+    if (interface & OC_IF_RW) {
+        oc_rep_add_text_string(if, OC_RSRVD_IF_RW);
+    }
+    if (interface & OC_IF_A) {
+      oc_rep_add_text_string(if, OC_RSRVD_IF_A);
+    }
+    if (interface & OC_IF_S) {
+        oc_rep_add_text_string(if, OC_RSRVD_IF_S);
+    }
+    oc_rep_add_text_string(if, OC_RSRVD_IF_BASELINE);
+    oc_rep_end_array((*parent), if);
 }
 
 static void
-oc_core_device_handler(oc_request_t *request, oc_interface_mask_t interface)
+oc_core_device_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;
-  int payload_size = oc_device_info[request->resource->device].payload.size;
-
-  if (buffer_size < payload_size) {
-    request->response->response_buffer->response_length = 0;
-    request->response->response_buffer->code =
-      oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
-    return;
-  }
-
-  switch (interface) {
-  case OC_IF_R:
-  case OC_IF_BASELINE:
-    memcpy(buffer,
-           oc_cast(oc_device_info[request->resource->device].payload, uint8_t),
-           payload_size);
-    request->response->response_buffer->response_length = payload_size;
-    request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
-    break;
-  default:
-    break;
-  }
+    uint8_t *buffer = req->response->response_buffer->buffer;
+    uint16_t buffer_size = req->response->response_buffer->buffer_size;
+    int size;
+
+    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;
+    }
+
+    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);
+        break;
+    default:
+        break;
+    }
 }
 
 int
 oc_core_get_num_devices(void)
 {
-  return device_count;
+    return device_count;
 }
 
 static int
 finalize_payload(oc_string_t *temp_buffer, oc_string_t *payload)
 {
-  oc_rep_end_root_object();
-  int size = oc_rep_finalize();
-  if (size != -1) {
-    oc_alloc_string(payload, size);
-    memcpy(oc_cast(*payload, uint8_t), oc_cast(*temp_buffer, uint8_t), size);
+    int size;
+
+    oc_rep_end_root_object();
+    size = oc_rep_finalize();
+    if (size != -1) {
+        oc_alloc_string(payload, size);
+        memcpy(payload->os_str, temp_buffer->os_str, size);
+        oc_free_string(temp_buffer);
+        return 1;
+    }
     oc_free_string(temp_buffer);
-    return 1;
-  }
-
-  oc_free_string(temp_buffer);
-  return -1;
+    return -1;
 }
 
 oc_string_t *
@@ -115,121 +116,130 @@ 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)
 {
-  if (device_count == MAX_NUM_DEVICES)
-    return false;
-
-  oc_string_t temp_buffer;
-/* Once provisioned, UUID is retrieved from the credential store.
-   If not yet provisioned, a default is generated in the security
-   layer.
-*/
+    oc_string_t temp_buffer;
+    int ocf_d;
+    char uuid[37];
+
+    if (device_count == MAX_NUM_DEVICES) {
+        return false;
+    }
+
+    /* Once provisioned, UUID is retrieved from the credential store.
+       If not yet provisioned, a default is generated in the security
+       layer.
+    */
 #ifdef OC_SECURITY /*fix if add new devices after provisioning, need to reset  \
                       or it will generate non-standard uuid */
-  /* where are secondary device ids persisted? */
-  if (!oc_sec_provisioned() && device_count > 0)
-    oc_gen_uuid(&oc_device_info[device_count].uuid);
+    /* where are secondary device ids persisted? */
+    if (!oc_sec_provisioned() && device_count > 0) {
+        oc_gen_uuid(&oc_device_info[device_count].uuid);
+    }
 #else
-  oc_gen_uuid(&oc_device_info[device_count].uuid);
+    oc_gen_uuid(&oc_device_info[device_count].uuid);
 #endif
 
-  int ocf_d = NUM_OC_CORE_RESOURCES - 1 - device_count;
+    ocf_d = NUM_OC_CORE_RESOURCES - 1 - device_count;
 
-  /* Construct device resource */
-  oc_core_populate_resource(ocf_d, uri, rt, OC_IF_R | OC_IF_BASELINE,
-                            OC_IF_BASELINE, OC_ACTIVE | OC_DISCOVERABLE,
-                            oc_core_device_handler, 0, 0, 0, device_count);
+    /* Construct device resource */
+    oc_core_populate_resource(ocf_d, uri, rt, OC_IF_R | OC_IF_BASELINE,
+                              OC_IF_BASELINE, OC_ACTIVE | OC_DISCOVERABLE,
+                              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(oc_cast(temp_buffer, uint8_t), MAX_DEVICE_PAYLOAD_SIZE);
+    /* Encoding device resource payload */
+    oc_alloc_string(&temp_buffer, MAX_DEVICE_PAYLOAD_SIZE);
+    oc_rep_new(temp_buffer.os_str, MAX_DEVICE_PAYLOAD_SIZE);
 
-  oc_rep_start_root_object();
+    oc_rep_start_root_object();
 
-  oc_rep_set_string_array(root, rt, core_resources[ocf_d].types);
-  oc_core_encode_interfaces_mask(oc_rep_object(root),
-                                 core_resources[ocf_d].interfaces);
-  oc_rep_set_uint(root, p, core_resources[ocf_d].properties);
+    oc_rep_set_string_array(root, rt, core_resources[ocf_d].types);
+    oc_core_encode_interfaces_mask(oc_rep_object(root),
+                                   core_resources[ocf_d].interfaces);
+    oc_rep_set_uint(root, p, core_resources[ocf_d].properties);
 
-  char uuid[37];
-  oc_uuid_to_str(&oc_device_info[device_count].uuid, uuid, 37);
-  oc_rep_set_text_string(root, di, uuid);
-  oc_rep_set_text_string(root, n, name);
-  oc_rep_set_text_string(root, icv, spec_version);
-  oc_rep_set_text_string(root, dmv, data_model_version);
+    oc_uuid_to_str(&oc_device_info[device_count].uuid, uuid, 37);
+    oc_rep_set_text_string(root, di, uuid);
+    oc_rep_set_text_string(root, n, name);
+    oc_rep_set_text_string(root, icv, spec_version);
+    oc_rep_set_text_string(root, dmv, data_model_version);
 
-  if (add_device_cb)
-    add_device_cb(data);
-  if (!finalize_payload(&temp_buffer, &oc_device_info[device_count].payload))
-    return NULL;
+    if (add_device_cb) {
+        add_device_cb(data);
+    }
+    if (!finalize_payload(&temp_buffer, &oc_device_info[device_count].payload)){
+        return NULL;
+    }
 
-  return &oc_device_info[device_count++].payload;
+    return &oc_device_info[device_count++].payload;
 }
 
 void
 oc_core_platform_handler(oc_request_t *request, oc_interface_mask_t interface)
 {
-  uint8_t *buffer = request->response->response_buffer->buffer;
-  uint16_t buffer_size = request->response->response_buffer->buffer_size;
-  int payload_size = oc_platform_payload.size;
-
-  if (buffer_size < payload_size) {
-    request->response->response_buffer->response_length = 0;
-    request->response->response_buffer->code =
-      oc_status_code(OC_STATUS_INTERNAL_SERVER_ERROR);
-    return;
-  }
-
-  switch (interface) {
-  case OC_IF_R:
-  case OC_IF_BASELINE:
-    memcpy(buffer, oc_cast(oc_platform_payload, uint8_t), payload_size);
-    request->response->response_buffer->response_length = payload_size;
-    request->response->response_buffer->code = oc_status_code(OC_STATUS_OK);
-    break;
-  default:
-    break;
-  }
+    uint8_t *buffer = request->response->response_buffer->buffer;
+    uint16_t buffer_size = request->response->response_buffer->buffer_size;
+    int size;
+
+    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;
+    }
+
+    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);
+        break;
+    default:
+        break;
+    }
 }
 
 oc_string_t *
 oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb,
                       void *data)
 {
-  if (oc_platform_payload.size > 0)
-    return NULL;
-
-  oc_string_t temp_buffer;
-  /* Populating resource obuject */
-  oc_core_populate_resource(OCF_P, OC_RSRVD_PLATFORM_URI, "oic.wk.p",
-                            OC_IF_R | OC_IF_BASELINE, OC_IF_BASELINE,
-                            OC_ACTIVE | OC_DISCOVERABLE,
-                            oc_core_platform_handler, 0, 0, 0, 0);
-
-  /* Encoding platform resource payload */
-  oc_alloc_string(&temp_buffer, MAX_PLATFORM_PAYLOAD_SIZE);
-  oc_rep_new(oc_cast(temp_buffer, uint8_t), MAX_PLATFORM_PAYLOAD_SIZE);
-  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);
-
-  oc_uuid_t uuid; /*fix uniqueness of platform id?? */
-  oc_gen_uuid(&uuid);
-  char uuid_str[37];
-
-  oc_uuid_to_str(&uuid, uuid_str, 37);
-  oc_rep_set_text_string(root, pi, uuid_str);
-  oc_rep_set_text_string(root, mnmn, mfg_name);
-
-  if (init_cb)
-    init_cb(data);
-
-  if (!finalize_payload(&temp_buffer, &oc_platform_payload))
-    return NULL;
-
-  return &oc_platform_payload;
+    oc_string_t temp_buffer;
+    oc_uuid_t uuid; /*fix uniqueness of platform id?? */
+    char uuid_str[37];
+
+    if (oc_string_len(oc_platform_payload) > 0) {
+        return NULL;
+    }
+    /* Populating resource obuject */
+    oc_core_populate_resource(OCF_P, OC_RSRVD_PLATFORM_URI, "oic.wk.p",
+                              OC_IF_R | OC_IF_BASELINE, OC_IF_BASELINE,
+                              OC_ACTIVE | OC_DISCOVERABLE,
+                              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);
+    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);
+
+    oc_gen_uuid(&uuid);
+
+    oc_uuid_to_str(&uuid, uuid_str, 37);
+    oc_rep_set_text_string(root, pi, uuid_str);
+    oc_rep_set_text_string(root, mnmn, mfg_name);
+
+    if (init_cb) {
+        init_cb(data);
+    }
+    if (!finalize_payload(&temp_buffer, &oc_platform_payload)) {
+        return NULL;
+    }
+    return &oc_platform_payload;
 }
 
 void
@@ -241,40 +251,41 @@ oc_core_populate_resource(int type, const char *uri, const char *rt,
                           oc_request_handler_t post,
                           oc_request_handler_t delete, int device)
 {
-  oc_resource_t *r = &core_resources[type];
-  r->device = device;
-  oc_new_string(&r->uri, uri);
-  r->properties = properties;
-  oc_new_string_array(&r->types, 1);
-  oc_string_array_add_item(r->types, rt);
-  r->interfaces = interfaces;
-  r->default_interface = default_interface;
-  r->get_handler = get;
-  r->put_handler = put;
-  r->post_handler = post;
-  r->delete_handler = delete;
+    oc_resource_t *r = &core_resources[type];
+    r->device = device;
+    oc_new_string(&r->uri, uri);
+    r->properties = properties;
+    oc_new_string_array(&r->types, 1);
+    oc_string_array_add_item(r->types, rt);
+    r->interfaces = interfaces;
+    r->default_interface = default_interface;
+    r->get_handler = get;
+    r->put_handler = put;
+    r->post_handler = post;
+    r->delete_handler = delete;
 }
 
 oc_uuid_t *
 oc_core_get_device_id(int device)
 {
-  return &oc_device_info[device].uuid;
+    return &oc_device_info[device].uuid;
 }
 
 oc_resource_t *
 oc_core_get_resource_by_index(int type)
 {
-  return &core_resources[type];
+    return &core_resources[type];
 }
 
 oc_resource_t *
 oc_core_get_resource_by_uri(const char *uri)
 {
-  int i;
-  for (i = 0; i < NUM_OC_CORE_RESOURCES; i++) {
-    if (oc_string_len(core_resources[i].uri) == strlen(uri) &&
-        strncmp(uri, oc_string(core_resources[i].uri), strlen(uri)) == 0)
-      return &core_resources[i];
-  }
-  return NULL;
+    int i;
+
+    for (i = 0; i < NUM_OC_CORE_RESOURCES; i++) {
+        if (oc_string_len(core_resources[i].uri) == strlen(uri) &&
+          strncmp(uri, oc_string(core_resources[i].uri), strlen(uri)) == 0)
+            return &core_resources[i];
+    }
+    return NULL;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/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 ea6de37..29311b7 100644
--- a/net/oic/src/api/oc_discovery.c
+++ b/net/oic/src/api/oc_discovery.c
@@ -183,15 +183,20 @@ oc_ri_process_discovery_payload(uint8_t *payload, int len,
                                 oc_endpoint_t *endpoint)
 {
   oc_discovery_flags_t ret = OC_CONTINUE_DISCOVERY;
-  oc_string_t uri;
-  uri.ptr = 0;
-  oc_string_t di;
-  di.ptr = 0;
+  oc_string_t uri = {
+      .os_sz = 0,
+      .os_str = NULL
+  };
+  oc_string_t di = {
+      .os_sz = 0,
+      .os_str = NULL
+  };
   bool secure = false;
   uint16_t dtls_port = 0, default_port = endpoint->ipv6_addr.port;
   oc_string_array_t types = {};
   oc_interface_mask_t interfaces = 0;
   oc_server_handle_t handle;
+
   memcpy(&handle.endpoint, endpoint, sizeof(oc_endpoint_t));
 
   oc_rep_t *array = 0, *rep;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/net/oic/src/api/oc_helpers.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_helpers.c b/net/oic/src/api/oc_helpers.c
index 4af8eeb..af4743c 100644
--- a/net/oic/src/api/oc_helpers.c
+++ b/net/oic/src/api/oc_helpers.c
@@ -14,151 +14,113 @@
 // limitations under the License.
 */
 
-#include "oc_helpers.h"
-#include "port/oc_assert.h"
-#include "port/oc_log.h"
 #include <stdbool.h>
-
-static bool mmem_initialized = false;
-
-static void
-oc_malloc(oc_handle_t *block, uint16_t num_bytes, pool pool_type)
-{
-  if (!mmem_initialized) {
-    oc_mmem_init();
-    mmem_initialized = true;
-  }
-  oc_assert(oc_mmem_alloc(block, num_bytes, pool_type) > 0);
-}
-
-static void
-oc_free(oc_handle_t *block, pool pool_type)
-{
-  oc_mmem_free(block, pool_type);
-  block->next = 0;
-  block->ptr = 0;
-  block->size = 0;
-}
+#include <stdlib.h>
+#include "oc_helpers.h"
 
 void
-oc_new_string(oc_string_t *ocstring, const char str[])
+oc_new_string(oc_string_t *os, const char str[])
 {
-  oc_malloc(ocstring, strlen(str) + 1, BYTE_POOL);
-  memcpy(oc_string(*ocstring), (const uint8_t *)str, strlen(str));
-  memcpy(oc_string(*ocstring) + strlen(str), (const uint8_t *)"", 1);
+    int len = strlen(str);
+
+    os->os_str = malloc(len + 1);
+    if (os->os_str) {
+        os->os_sz = len + 1;
+        memcpy(os->os_str, str, len);
+        os->os_str[len] = '\0';
+    }
 }
 
 void
-oc_alloc_string(oc_string_t *ocstring, int size)
+oc_alloc_string(oc_string_t *os, int size)
 {
-  oc_malloc(ocstring, size, BYTE_POOL);
+    os->os_str = malloc(size);
+    if (os->os_str) {
+        os->os_sz = size;
+    }
 }
 
 void
-oc_free_string(oc_string_t *ocstring)
+oc_free_string(oc_string_t *os)
 {
-  oc_free(ocstring, BYTE_POOL);
+    free(os->os_str);
+    os->os_sz = 0;
 }
 
 void
 oc_concat_strings(oc_string_t *concat, const char *str1, const char *str2)
 {
-  size_t len1 = strlen(str1), len2 = strlen(str2);
-  oc_alloc_string(concat, len1 + len2 + 1);
-  memcpy(oc_string(*concat), str1, len1);
-  memcpy(oc_string(*concat) + len1, str2, len2);
-  memcpy(oc_string(*concat) + len1 + len2, (const char *)"", 1);
+    size_t len1 = strlen(str1), len2 = strlen(str2);
+
+    oc_alloc_string(concat, len1 + len2 + 1);
+    memcpy(concat->os_str, str1, len1);
+    memcpy(&concat->os_str[len1], str2, len2);
+    concat->os_str[len1 + len2] = '\0';
 }
 
 void
-_oc_new_array(oc_array_t *ocarray, uint8_t size, pool type)
+_oc_new_array(oc_array_t *oa, uint8_t size, uint8_t elem_size)
 {
-  switch (type) {
-  case INT_POOL:
-    oc_malloc(ocarray, size * sizeof(int64_t), INT_POOL);
-    break;
-  case BYTE_POOL:
-    oc_malloc(ocarray, size * sizeof(bool), BYTE_POOL);
-    break;
-  case DOUBLE_POOL:
-    oc_malloc(ocarray, size * sizeof(double), DOUBLE_POOL);
-    break;
-  default:
-    break;
-  }
+    oa->oa_arr.b = malloc(size * elem_size);
+    if (oa->oa_arr.b) {
+        oa->oa_sz = size * elem_size;
+    }
 }
 
-void
-_oc_free_array(oc_array_t *ocarray, pool type)
+void _oc_free_array(oc_array_t *oa)
 {
-  oc_free(ocarray, type);
+    free(oa->oa_arr.b);
+    oa->oa_sz = 0;
 }
 
 void
-_oc_alloc_string_array(oc_string_array_t *ocstringarray, uint8_t size)
+_oc_alloc_string_array(oc_string_array_t *osa, uint8_t size)
 {
-  oc_alloc_string(ocstringarray, size * STRING_ARRAY_ITEM_MAX_LEN);
-  int i, pos;
-  for (i = 0; i < size; i++) {
-    pos = i * STRING_ARRAY_ITEM_MAX_LEN;
-    memcpy((char *)oc_string(*ocstringarray) + pos, (const char *)"", 1);
-  }
-}
+    int i;
+    int pos;
 
-bool
-_oc_copy_string_to_string_array(oc_string_array_t *ocstringarray,
-                                const char str[], uint8_t index)
-{
-  if (strlen(str) >= STRING_ARRAY_ITEM_MAX_LEN) {
-    return false;
-  }
-  uint8_t pos = index * STRING_ARRAY_ITEM_MAX_LEN;
-  memcpy(oc_string(*ocstringarray) + pos, (const uint8_t *)str, strlen(str));
-  memcpy(oc_string(*ocstringarray) + pos + strlen(str), (const uint8_t *)"", 1);
-  return true;
+    _oc_new_array(osa, size, STRING_ARRAY_ITEM_MAX_LEN);
+    if (osa->oa_arr.s) {
+        for (i = 0; i < size; i++) {
+            pos = i * STRING_ARRAY_ITEM_MAX_LEN;
+            osa->oa_arr.s[pos] = '\0';
+        }
+    }
 }
 
 bool
-_oc_string_array_add_item(oc_string_array_t *ocstringarray, const char str[])
+_oc_copy_string_to_string_array(oc_string_array_t *osa,
+                                const char str[], uint8_t idx)
 {
-  bool success = false;
-  int i;
-  for (i = 0; i < oc_string_array_get_allocated_size(*ocstringarray); i++) {
-    if (strlen((const char *)oc_string_array_get_item(*ocstringarray, i)) ==
-        0) {
-      success = oc_string_array_set_item(*ocstringarray, str, i);
-      break;
+    int len;
+    int pos;
+
+    len = strlen(str);
+    pos = idx * STRING_ARRAY_ITEM_MAX_LEN;
+
+    if (len >= STRING_ARRAY_ITEM_MAX_LEN ||
+        pos + STRING_ARRAY_ITEM_MAX_LEN > osa->oa_sz) {
+        return false;
     }
-  }
-  return success;
+    memcpy(&osa->oa_arr.s[pos], str, len);
+    osa->oa_arr.s[pos + len] = '\0';
+    return true;
 }
 
-void
-oc_join_string_array(oc_string_array_t *ocstringarray, oc_string_t *ocstring)
+bool
+_oc_string_array_add_item(oc_string_array_t *osa, const char str[])
 {
-  size_t len = 0;
-  uint8_t i;
-  for (i = 0; i < oc_string_array_get_allocated_size(*ocstringarray); i++) {
-    const char *item =
-      (const char *)oc_string_array_get_item(*ocstringarray, i);
-    if (strlen(item)) {
-      len += strlen(item);
-      len++;
-    }
-  }
-  oc_alloc_string(ocstring, len);
-  len = 0;
-  for (i = 0; i < oc_string_array_get_allocated_size(*ocstringarray); i++) {
-    const char *item =
-      (const char *)oc_string_array_get_item(*ocstringarray, i);
-    if (strlen(item)) {
-      if (len > 0) {
-        oc_string(*ocstring)[len] = ' ';
-        len++;
-      }
-      strncpy((char *)oc_string(*ocstring) + len, item, strlen(item));
-      len += strlen(item);
+    int i;
+    int sz;
+    int pos;
+
+    sz = osa->oa_sz / STRING_ARRAY_ITEM_MAX_LEN;
+    for (i = 0; i < sz; i++) {
+        pos = i * STRING_ARRAY_ITEM_MAX_LEN;
+        if (osa->oa_arr.s[pos] == '\0') {
+            _oc_copy_string_to_string_array(osa, str, i);
+            return true;
+        }
     }
-  }
-  strcpy((char *)oc_string(*ocstring) + len, "");
+    return false;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0526e079/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 3465775..08ec29b 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -142,8 +142,7 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
   *err |= cbor_value_calculate_string_length(value, &len);
   len++;
   oc_alloc_string(&cur->name, len);
-  *err |= cbor_value_copy_text_string(value, (char *)oc_string(cur->name), &len,
-                                      NULL);
+  *err |= cbor_value_copy_text_string(value, oc_string(cur->name), &len, NULL);
   *err |= cbor_value_advance(value);
   /* value */
   switch (value->type) {
@@ -163,8 +162,9 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
     *err |= cbor_value_calculate_string_length(value, &len);
     len++;
     oc_alloc_string(&cur->value_string, len);
-    *err |= cbor_value_copy_byte_string(
-      value, oc_cast(cur->value_string, uint8_t), &len, NULL);
+    *err |= cbor_value_copy_byte_string(value,
+                                        (uint8_t *)oc_string(cur->value_string),
+                                        &len, NULL);
     cur->type = BYTE_STRING;
     break;
   case CborTextStringType:


[15/16] incubator-mynewt-core git commit: oic; change to use os_mbufs from oc_buffer_tx to transport.

Posted by ma...@apache.org.
oic; change to use os_mbufs from oc_buffer_tx to transport.


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/84997a94
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/84997a94
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/84997a94

Branch: refs/heads/develop
Commit: 84997a94853faf183c427f33ff724b0250fa1e33
Parents: 6cdcc7e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 10:40:15 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:54:52 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_buffer.c              | 43 ++++++++++----
 net/oic/src/port/mynewt/adaptor.c        | 59 ++++++++++--------
 net/oic/src/port/mynewt/adaptor.h        |  9 ++-
 net/oic/src/port/mynewt/ble_adaptor.c    | 30 ++--------
 net/oic/src/port/mynewt/ip_adaptor.c     | 86 ++++++++++++++++-----------
 net/oic/src/port/mynewt/serial_adaptor.c | 36 ++---------
 net/oic/src/port/oc_connectivity.h       |  6 +-
 7 files changed, 136 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index b92ac8f..6a38301 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -113,35 +113,58 @@ oc_send_message(oc_message_t *message)
 }
 
 static void
-oc_buffer_tx(struct oc_message *message)
+oc_buffer_tx(struct oc_message *msg)
 {
+    struct os_mbuf *m;
+    struct oc_endpoint *oe;
+    int rc;
+
+    /* get a packet header */
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
+        ERROR("oc_buffer_tx: failed to alloc mbuf\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    /* add this data to the mbuf */
+    rc = os_mbuf_append(m, msg->data, msg->length);
+    if (rc != 0) {
+        ERROR("oc_buffer_tx: could not append data\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    oe = OC_MBUF_ENDPOINT(m);
+    memcpy(oe, &msg->endpoint, sizeof(msg->endpoint));
+
+    oc_message_unref(msg);
+
 #ifdef OC_CLIENT
-    if (message->endpoint.flags & MULTICAST) {
+    if (oe->flags & MULTICAST) {
         LOG("Outbound network event: multicast request\n");
-        oc_send_multicast_message(message);
-        oc_message_unref(message);
+        oc_send_multicast_message(m);
     } else {
 #endif
 #ifdef OC_SECURITY
         /* XXX convert this */
-        if (message->endpoint.flags & SECURED) {
+        if (oe->flags & SECURED) {
             LOG("Outbound network event: forwarding to DTLS\n");
 
-            if (!oc_sec_dtls_connected(&message->endpoint)) {
+            if (!oc_sec_dtls_connected(oe)) {
                 LOG("Posting INIT_DTLS_CONN_EVENT\n");
                 oc_process_post(&oc_dtls_handler,
-                  oc_events[INIT_DTLS_CONN_EVENT], msg);
+                  oc_events[INIT_DTLS_CONN_EVENT], m);
             } else {
                 LOG("Posting RI_TO_DTLS_EVENT\n");
                 oc_process_post(&oc_dtls_handler,
-                  oc_events[RI_TO_DTLS_EVENT], msg);
+                  oc_events[RI_TO_DTLS_EVENT], m);
             }
         } else
 #endif
         {
             LOG("Outbound network event: unicast message\n");
-            oc_send_buffer(message);
-            oc_message_unref(message);
+            oc_send_buffer(m);
         }
 #ifdef OC_CLIENT
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index 40785c2..cdd31f5 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -68,54 +68,65 @@ oc_network_event_handler_mutex_unlock(void)
 }
 
 void
-oc_send_buffer(oc_message_t *message)
+oc_send_buffer(struct os_mbuf *m)
 {
-    switch (message->endpoint.flags) {
+    struct oc_endpoint *oe;
+
+    oe = OC_MBUF_ENDPOINT(m);
+
+    switch (oe->flags) {
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     case IP:
-        oc_send_buffer_ip(message);
+        oc_send_buffer_ip(m);
         break;
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     case GATT:
-        oc_send_buffer_gatt(message);
+        oc_send_buffer_gatt(m);
         break;
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
     case SERIAL:
-        oc_send_buffer_serial(message);
+        oc_send_buffer_serial(m);
         break;
 #endif
     default:
-        ERROR("Unknown transport option %u\n", message->endpoint.flags);
-        oc_message_unref(message);
+        ERROR("Unknown transport option %u\n", oe->flags);
+        os_mbuf_free_chain(m);
     }
 }
 
-void oc_send_multicast_message(oc_message_t *message)
+void
+oc_send_multicast_message(struct os_mbuf *m)
 {
-    oc_message_add_ref(message);
-
-    /* send on all the transports.  Don't forget to reference the message
-     * so it doesn't get deleted  */
-
+    /*
+     * Send on all the transports.
+     */
+    void (*funcs[])(struct os_mbuf *) = {
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-    oc_send_buffer_ip_mcast(message);
+        oc_send_buffer_ip_mcast,
 #endif
-
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
-    /* no multicast for GATT, just send unicast */
-    oc_message_add_ref(message);
-    oc_send_buffer_gatt(message);
+        /* no multicast for GATT, just send unicast */
+        oc_send_buffer_gatt,
 #endif
-
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
-    /* no multi-cast for serial.  just send unicast */
-    oc_message_add_ref(message);
-    oc_send_buffer_serial(message);
+        /* no multi-cast for serial.  just send unicast */
+        oc_send_buffer_serial,
 #endif
-
-    oc_message_unref(message);
+    };
+    struct os_mbuf *n;
+    int i;
+
+    for (i = 0; i < (sizeof(funcs) / sizeof(funcs[0])) - 1; i++) {
+        n = os_mbuf_dup(m);
+        funcs[i](m);
+        if (!n) {
+            return;
+        }
+        m = n;
+    }
+    funcs[(sizeof(funcs) / sizeof(funcs[0])) - 1](m);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index c6ea8bb..025efd6 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -32,21 +32,20 @@ struct oc_message;
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
-void oc_send_buffer_ip(struct oc_message *message);
-void oc_send_buffer_ip_mcast(struct oc_message *message);
+void oc_send_buffer_ip(struct os_mbuf *);
+void oc_send_buffer_ip_mcast(struct os_mbuf *);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
 int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
-void oc_send_buffer_gatt(struct oc_message *message);
-void oc_send_buffer_gatt_mcast(struct oc_message *message);
+void oc_send_buffer_gatt(struct os_mbuf *);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
-void oc_send_buffer_serial(struct oc_message *message);
+void oc_send_buffer_serial(struct os_mbuf *);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 0c3363f..81f2d2c 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -208,41 +208,19 @@ oc_connectivity_shutdown_gatt(void)
 }
 
 void
-oc_send_buffer_gatt(oc_message_t *message)
+oc_send_buffer_gatt(struct os_mbuf *m)
 {
-    struct os_mbuf *m = NULL;
-    int rc;
-
-    /* get a packet header */
-    m = os_msys_get_pkthdr(0, 0);
-    if (m == NULL) {
-        ERROR("oc_transport_gatt: No mbuf available\n");
-        goto err;
-    }
+    struct oc_endpoint *oe;
 
-    /* add this data to the mbuf */
-    rc = os_mbuf_append(m, message->data, message->length);
-    if (rc != 0) {
-        ERROR("oc_transport_gatt: could not append data \n");
-        goto err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
 
 #if (MYNEWT_VAL(OC_CLIENT) == 1)
     ERROR("send not supported on client");
 #endif
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
-                            g_ble_coap_attr_handle, m);
-    m = NULL;
+    ble_gattc_notify_custom(oe->bt_addr.conn_handle, g_ble_coap_attr_handle, m);
 #endif
-
-err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-    oc_message_unref(message);
-    return;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 181bc68..90edd42 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -35,7 +35,7 @@
 
 static void oc_event_ip(struct os_event *ev);
 
-struct os_event oc_sock_read_event = {
+static struct os_event oc_sock_read_event = {
     .ev_cb = oc_event_ip,
 };
 
@@ -46,45 +46,43 @@ struct os_event oc_sock_read_event = {
 
 #define COAP_PORT_UNSECURED (5683)
 /* TODO use inet_pton when its available */
-const struct mn_in6_addr coap_all_nodes_v6 = {
+static const struct mn_in6_addr coap_all_nodes_v6 = {
     .s_addr = {0xFF,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFD}
 };
 
 
 /* sockets to use for coap unicast and multicast */
-struct mn_socket *ucast;
+static struct mn_socket *ucast;
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-struct mn_socket *mcast;
+static struct mn_socket *mcast;
 #endif
 
 static void
-oc_send_buffer_ip_int(oc_message_t *message, int mcast)
+oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
 {
     struct mn_sockaddr_in6 to;
-    struct os_mbuf m;
+    struct oc_endpoint *oe;
+    struct mn_itf itf;
+    struct mn_itf itf2;
+    struct os_mbuf *n;
     int rc;
 
-    LOG("oc_transport_ip attempt send buffer %lu\n",
-        (unsigned long)message->length);
+    LOG("oc_transport_ip attempt send buffer %u\n",
+      OS_MBUF_PKTHDR(m)->omp_len);
+
+    oe = OC_MBUF_ENDPOINT(m);
 
     to.msin6_len = sizeof(to);
     to.msin6_family = MN_AF_INET6;
+    to.msin6_port = htons(oe->ipv6_addr.port);
+    to.msin6_scope_id = oe->ipv6_addr.scope;
+    memcpy(&to.msin6_addr, oe->ipv6_addr.address, sizeof(to.msin6_addr));
 
-    to.msin6_port = htons(message->endpoint.ipv6_addr.port);
-    memcpy(&to.msin6_addr, message->endpoint.ipv6_addr.address,
-           sizeof(to.msin6_addr));
-
-    /* put on an mbuf header to make the socket happy */
-    memset(&m, 0, sizeof(m));
-    m.om_data = message->data;
-    m.om_len = message->length;
-    to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
-
-    if (mcast) {
-        struct mn_itf itf;
+    if (is_mcast) {
         memset(&itf, 0, sizeof(itf));
+        memset(&itf2, 0, sizeof(itf2));
 
         while (1) {
             rc = mn_itf_getnext(&itf);
@@ -96,37 +94,57 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
                 continue;
             }
 
-            to.msin6_scope_id = itf.mif_idx;
-
-            rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+            if (!itf2.mif_idx) {
+                memcpy(&itf2, &itf, sizeof(itf));
+                continue;
+            }
+            n = os_mbuf_dup(m);
+            if (!n) {
+                break;
+            }
+            to.msin6_scope_id = itf2.mif_idx;
+            rc = mn_sendto(ucast, n, (struct mn_sockaddr *) &to);
             if (rc != 0) {
-                ERROR("Failed sending buffer %lu on itf %d\n",
-                      (unsigned long)message->length, to.msin6_scope_id);
+                ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                os_mbuf_free_chain(n);
+            }
+        }
+        if (itf2.mif_idx) {
+            to.msin6_scope_id = itf2.mif_idx;
+            rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
+            if (rc != 0) {
+                ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                os_mbuf_free_chain(m);
             }
         }
     } else {
-        rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+        rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
         if (rc != 0) {
-            ERROR("Failed sending buffer %lu on itf %d\n",
-                  (unsigned long)message->length, to.msin6_scope_id);
+            ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+            os_mbuf_free_chain(m);
         }
     }
-    oc_message_unref(message);
+    if (rc) {
+        os_mbuf_free_chain(m);
+    }
 }
 
 void
-oc_send_buffer_ip(oc_message_t *message)
+oc_send_buffer_ip(struct os_mbuf *m)
 {
-    oc_send_buffer_ip_int(message, 0);
+    oc_send_buffer_ip_int(m, 0);
 }
 void
-oc_send_buffer_ip_mcast(oc_message_t *message)
+oc_send_buffer_ip_mcast(struct os_mbuf *m)
 {
-    oc_send_buffer_ip_int(message, 1);
+    oc_send_buffer_ip_int(m, 1);
 }
 
 static struct os_mbuf *
-oc_attempt_rx_ip_sock(struct mn_socket * rxsock)
+oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
 {
     int rc;
     struct os_mbuf *m;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index 209a9c7..59342a9 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -58,7 +58,8 @@ oc_event_serial(struct os_event *ev)
 }
 
 int
-oc_connectivity_init_serial(void) {
+oc_connectivity_init_serial(void)
+{
     int rc;
 
     rc = shell_nlip_input_register(oc_serial_in, NULL);
@@ -80,39 +81,14 @@ err:
 
 
 void
-oc_send_buffer_serial(oc_message_t *message)
+oc_send_buffer_serial(struct os_mbuf *m)
 {
-    int rc;
-    struct os_mbuf *m;
-
-    /* get a packet header */
-    m = os_msys_get_pkthdr(0, 0);
-    if (m == NULL) {
-        ERROR("oc_transport_serial: No mbuf available\n");
-        goto err;
-    }
-
-    /* add this data to the mbuf */
-    rc = os_mbuf_append(m, message->data, message->length);
-    if (rc != 0) {
-
-        ERROR("oc_transport_serial: could not append data \n");
-        goto err;
-    }
+    LOG("oc_transport_serial: send buffer %u\n", OS_MBUF_PKTHDR(m)->omp_len);
 
     /* send over the shell output */
-    rc = shell_nlip_output(m);
-    if (rc != 0) {
-        ERROR("oc_transport_serial: nlip output failed \n");
-        goto err;
+    if (shell_nlip_output(m)) {
+        ERROR("oc_transport_serial: nlip output failed\n");
     }
-
-    LOG("oc_transport_serial: send buffer %zu\n", message->length);
-
-err:
-    oc_message_unref(message);
-    return;
-
 }
 
 static struct os_mbuf *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84997a94/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 493b30e..123db7c 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -66,17 +66,15 @@ typedef struct oc_message {
     uint8_t data[MAX_PAYLOAD_SIZE];
 } oc_message_t;
 
-void oc_send_buffer(oc_message_t *message);
-
 #ifdef OC_SECURITY
 uint16_t oc_connectivity_get_dtls_port(void);
 #endif /* OC_SECURITY */
 
 int oc_connectivity_init(void);
-
 void oc_connectivity_shutdown(void);
 
-void oc_send_multicast_message(oc_message_t *message);
+void oc_send_buffer(struct os_mbuf *);
+void oc_send_multicast_message(struct os_mbuf *);
 
 #ifdef __cplusplus
 }


[06/16] incubator-mynewt-core git commit: stm32f4 lwip eth driver; get it to compile, if not operate.

Posted by ma...@apache.org.
stm32f4 lwip eth driver; get it to compile, if not operate.


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/566da38a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/566da38a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/566da38a

Branch: refs/heads/develop
Commit: 566da38aee6302b2548a34cb51f1e7ed24536199
Parents: d541740
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 29 12:39:18 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/566da38a/hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c b/hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c
index 54c15d3..0660a19 100755
--- a/hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c
+++ b/hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c
@@ -44,22 +44,22 @@
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-  #pragma data_alignment=4   
+  #pragma data_alignment=4
 #endif
 __ALIGN_BEGIN ETH_DMADescTypeDef  DMARxDscrTab[ETH_RXBUFNB] __ALIGN_END;/* Ethernet Rx MA Descriptor */
 
 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-  #pragma data_alignment=4   
+  #pragma data_alignment=4
 #endif
 __ALIGN_BEGIN ETH_DMADescTypeDef  DMATxDscrTab[ETH_TXBUFNB] __ALIGN_END;/* Ethernet Tx DMA Descriptor */
 
 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-  #pragma data_alignment=4   
+  #pragma data_alignment=4
 #endif
 __ALIGN_BEGIN uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE] __ALIGN_END; /* Ethernet Receive Buffer */
 
 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
-  #pragma data_alignment=4   
+  #pragma data_alignment=4
 #endif
 __ALIGN_BEGIN uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __ALIGN_END; /* Ethernet Transmit Buffer */
 
@@ -654,7 +654,9 @@ stm32f4_output(struct netif *nif, struct pbuf *p)
 static void
 stm32f4_eth_isr(void)
 {
+#if 0
     HAL_ETH_IRQHandler(&stmref4_eth_State.st_eth);
+#endif
 }
 
 static err_t
@@ -697,7 +699,9 @@ stm32f4_lwip_init(struct netif *nif)
             if ((cfg->sec_port_mask[i] & (1 << j)) == 0) {
                 continue;
             }
+#if 0
             hal_gpio_init_af(i * 16 + j, GPIO_AF11_ETH, GPIO_NOPULL);
+#endif
         }
     }
 
@@ -706,8 +710,10 @@ stm32f4_lwip_init(struct netif *nif)
     __HAL_RCC_ETH_CLK_ENABLE();
 
     ses->st_eth.Instance = ETH;
-    ses->st_eth.Init.MACAddr = { 0, 1, 2, 3, 4, 5 };
+    ses->st_eth.Init.MACAddr[1] = 2;
+#if 0
     ses->st_eth.Init.Autonegotiation = ETH_AUTONEGOTIATION_ENABLE;
+#endif
     ses->st_eth.Init.Speed = ETH_SPEED_100M;
     ses->st_eth.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
     ses->st_eth.Init.PhyAddress = 0;


[12/16] incubator-mynewt-core git commit: mn_socket; add comment saying interface index cannot be 0.

Posted by ma...@apache.org.
mn_socket; add comment saying interface index cannot be 0.


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/6cdcc7ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6cdcc7ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6cdcc7ea

Branch: refs/heads/develop
Commit: 6cdcc7ea11bbee2607f52db822cf1b29a12d95ea
Parents: 969df79
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 10:39:03 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:54:51 2016 -0800

----------------------------------------------------------------------
 net/ip/mn_socket/include/mn_socket/mn_socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6cdcc7ea/net/ip/mn_socket/include/mn_socket/mn_socket.h
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/include/mn_socket/mn_socket.h b/net/ip/mn_socket/include/mn_socket/mn_socket.h
index 9d0ac42..b21bc33 100644
--- a/net/ip/mn_socket/include/mn_socket/mn_socket.h
+++ b/net/ip/mn_socket/include/mn_socket/mn_socket.h
@@ -126,7 +126,7 @@ extern const uint32_t nm_in6addr_any[4];
  * Structure for multicast join/leave
  */
 struct mn_mreq {
-    uint8_t mm_idx;			/* interface index */
+    uint8_t mm_idx;			/* interface index; must not be 0 */
     uint8_t mm_family;			/* address family */
     union {
         struct mn_in_addr v4;


[08/16] incubator-mynewt-core git commit: oic coap; don't use void * where coap_packet_t * should be used.

Posted by ma...@apache.org.
oic coap; don't use void * where coap_packet_t * should be used.


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/670a6577
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/670a6577
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/670a6577

Branch: refs/heads/develop
Commit: 670a657709a2ab6b45787c7721f6bf3e56e93884
Parents: d2321da
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 16:24:40 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/separate.c | 7 +++----
 net/oic/src/messaging/coap/separate.h | 9 +++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/670a6577/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index 2aad061..b542586 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -64,15 +64,14 @@ static uint8_t coap_separate_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS,
  * then retry later.
  */
 int
-coap_separate_accept(void *request, oc_separate_response_t *separate_response,
+coap_separate_accept(coap_packet_t *coap_req,
+                     oc_separate_response_t *separate_response,
                      oc_endpoint_t *endpoint, int observe)
 {
     if (separate_response->active == 0) {
         OC_LIST_STRUCT_INIT(separate_response, requests);
     }
 
-    coap_packet_t *const coap_req = (coap_packet_t *)request;
-
     for (coap_separate_t *item = oc_list_head(separate_response->requests);
          item != NULL; item = oc_list_item_next(separate_response->requests)) {
         if (item->token_len == coap_req->token_len &&
@@ -133,7 +132,7 @@ coap_separate_accept(void *request, oc_separate_response_t *separate_response,
 }
 /*----------------------------------------------------------------------------*/
 void
-coap_separate_resume(void *response, coap_separate_t *separate_store,
+coap_separate_resume(coap_packet_t *response, coap_separate_t *separate_store,
                      uint8_t code, uint16_t mid)
 {
     coap_init_message(response, separate_store->type, code, mid);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/670a6577/net/oic/src/messaging/coap/separate.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.h b/net/oic/src/messaging/coap/separate.h
index 9b3379e..c39d532 100644
--- a/net/oic/src/messaging/coap/separate.h
+++ b/net/oic/src/messaging/coap/separate.h
@@ -45,8 +45,7 @@ extern "C" {
 #include "oc_coap.h"
 #include "oic/oc_ri.h"
 
-typedef struct coap_separate
-{
+typedef struct coap_separate {
   struct coap_separate *next;
   coap_message_type_t type;
 
@@ -64,10 +63,12 @@ typedef struct coap_separate
   oc_endpoint_t endpoint;
 } coap_separate_t;
 
-int coap_separate_accept(void *request,
+typedef struct coap_packet coap_packet_t;
+int coap_separate_accept(coap_packet_t *request,
                          oc_separate_response_t *separate_response,
                          oc_endpoint_t *endpoint, int observe);
-void coap_separate_resume(void *response, coap_separate_t *separate_store,
+void coap_separate_resume(coap_packet_t *response,
+                          coap_separate_t *separate_store,
                           uint8_t code, uint16_t mid);
 void coap_separate_clear(oc_separate_response_t *separate_response,
                          coap_separate_t *separate_store);


[03/16] incubator-mynewt-core git commit: mn_socket; add comment saying interface index cannot be 0.

Posted by ma...@apache.org.
mn_socket; add comment saying interface index cannot be 0.


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/ae888434
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ae888434
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ae888434

Branch: refs/heads/develop
Commit: ae8884340dae247005bae98359816bf01efc39f5
Parents: 51dfe83
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 10:39:03 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/ip/mn_socket/include/mn_socket/mn_socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae888434/net/ip/mn_socket/include/mn_socket/mn_socket.h
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/include/mn_socket/mn_socket.h b/net/ip/mn_socket/include/mn_socket/mn_socket.h
index 9d0ac42..b21bc33 100644
--- a/net/ip/mn_socket/include/mn_socket/mn_socket.h
+++ b/net/ip/mn_socket/include/mn_socket/mn_socket.h
@@ -126,7 +126,7 @@ extern const uint32_t nm_in6addr_any[4];
  * Structure for multicast join/leave
  */
 struct mn_mreq {
-    uint8_t mm_idx;			/* interface index */
+    uint8_t mm_idx;			/* interface index; must not be 0 */
     uint8_t mm_family;			/* address family */
     union {
         struct mn_in_addr v4;


[09/16] incubator-mynewt-core git commit: oic; in preparation to moving to os_mbufs.

Posted by ma...@apache.org.
oic; in preparation to moving to os_mbufs.


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/26a8f8ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/26a8f8ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/26a8f8ce

Branch: refs/heads/develop
Commit: 26a8f8ce027bde3e70f9e8bfc1ed22cc90b28671
Parents: 425e06f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 22 16:03:47 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_buffer.h         | 12 +++---
 net/oic/include/oic/oc_network_events.h |  4 +-
 net/oic/src/api/oc_buffer.c             | 16 +++----
 net/oic/src/api/oc_network_events.c     |  2 +-
 net/oic/src/port/mynewt/adaptor.h       | 18 ++++----
 net/oic/src/port/oc_connectivity.h      | 62 +++++++++++++---------------
 6 files changed, 54 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 852e427..7dab610 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -21,13 +21,13 @@
 extern "C" {
 #endif
 
-struct oc_message_s;
-struct oc_message_s *oc_allocate_message(void);
-void oc_message_add_ref(struct oc_message_s *message);
-void oc_message_unref(struct oc_message_s *message);
+struct oc_message;
+struct oc_message *oc_allocate_message(void);
+void oc_message_add_ref(struct oc_message *message);
+void oc_message_unref(struct oc_message *message);
 
-void oc_recv_message(struct oc_message_s *message);
-void oc_send_message(struct oc_message_s *message);
+void oc_recv_message(struct oc_message *message);
+void oc_send_message(struct oc_message *message);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
index 61a274c..f786390 100644
--- a/net/oic/include/oic/oc_network_events.h
+++ b/net/oic/include/oic/oc_network_events.h
@@ -21,9 +21,9 @@
 extern "C" {
 #endif
 
-typedef struct oc_message_s oc_message_t;
+struct oc_message;
 
-void oc_network_event(oc_message_t *message);
+void oc_network_event(struct oc_message *message);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index b7201d7..bd3bbd1 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -37,8 +37,8 @@ static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
 
 static void oc_buffer_handler(struct os_event *);
 
-static struct oc_message_s *oc_buffer_inq;
-static struct oc_message_s *oc_buffer_outq;
+static struct oc_message *oc_buffer_inq;
+static struct oc_message *oc_buffer_outq;
 static struct os_event oc_buffer_ev = {
     .ev_cb = oc_buffer_handler
 };
@@ -89,11 +89,11 @@ oc_message_unref(oc_message_t *message)
 }
 
 static void
-oc_queue_msg(struct oc_message_s **head, struct oc_message_s *msg)
+oc_queue_msg(struct oc_message **head, struct oc_message *msg)
 {
-    struct oc_message_s *tmp;
+    struct oc_message *tmp;
 
-    msg->next = NULL; /* oc_message_s has been oc_list once, clear next */
+    msg->next = NULL; /* oc_message has been oc_list once, clear next */
     if (!*head) {
         *head = msg;
     } else {
@@ -117,7 +117,7 @@ oc_send_message(oc_message_t *message)
 }
 
 static void
-oc_buffer_tx(struct oc_message_s *message)
+oc_buffer_tx(struct oc_message *message)
 {
 #ifdef OC_CLIENT
     if (message->endpoint.flags & MULTICAST) {
@@ -153,7 +153,7 @@ oc_buffer_tx(struct oc_message_s *message)
 }
 
 static void
-oc_buffer_rx(struct oc_message_s *msg)
+oc_buffer_rx(struct oc_message *msg)
 {
 #ifdef OC_SECURITY
     uint8_t b = (uint8_t)(msg->data[0];
@@ -175,7 +175,7 @@ oc_buffer_rx(struct oc_message_s *msg)
 static void
 oc_buffer_handler(struct os_event *ev)
 {
-    struct oc_message_s *msg;
+    struct oc_message *msg;
 
     while (oc_buffer_outq || oc_buffer_inq) {
         msg = oc_buffer_outq;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index fd5ba38..6f33189 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -33,7 +33,7 @@ static struct os_event oc_network_ev = {
 static void
 oc_network_ev_process(struct os_event *ev)
 {
-    struct oc_message_s *head;
+    struct oc_message *head;
 
     oc_network_event_handler_mutex_lock();
     while (1) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index e9062e0..a40d2e8 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -27,29 +27,29 @@ extern "C" {
 struct os_eventq *oc_evq_get(void);
 void oc_evq_set(struct os_eventq *evq);
 
-struct oc_message_s;
+struct oc_message;
 
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
-void oc_send_buffer_ip(struct oc_message_s *message);
-void oc_send_buffer_ip_mcast(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_ip(void);
+void oc_send_buffer_ip(struct oc_message *message);
+void oc_send_buffer_ip_mcast(struct oc_message *message);
+struct oc_message *oc_attempt_rx_ip(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
 int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
-void oc_send_buffer_gatt(struct oc_message_s *message);
-void oc_send_buffer_gatt_mcast(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_gatt(void);
+void oc_send_buffer_gatt(struct oc_message *message);
+void oc_send_buffer_gatt_mcast(struct oc_message *message);
+struct oc_message *oc_attempt_rx_gatt(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
-void oc_send_buffer_serial(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_serial(void);
+void oc_send_buffer_serial(struct oc_message *message);
+struct oc_message *oc_attempt_rx_serial(void);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/26a8f8ce/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 1380442..3f84541 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -26,37 +26,32 @@
 extern "C" {
 #endif
 
-typedef struct
-{
-  uint16_t port;
-  uint8_t address[16];
-  uint8_t scope;
+typedef struct {
+    uint16_t port;
+    uint8_t address[16];
+    uint8_t scope;
 } oc_ipv6_addr_t;
 
-typedef struct
-{
-  uint8_t type;
-  uint8_t address[6];
-  uint16_t conn_handle;
+typedef struct {
+    uint8_t type;
+    uint8_t address[6];
+    uint16_t conn_handle;
 } oc_le_addr_t;
 
-typedef struct
-{
-  enum transport_flags
-  {
-    IP = 1 << 0,
-    GATT = 1 << 1,
-    IPSP = 1 << 2,
-    MULTICAST = 1 << 3,
-    SECURED = 1 << 4,
-    SERIAL = 1 <<5,
-  } flags;
-
-  union
-  {
-    oc_ipv6_addr_t ipv6_addr;
-    oc_le_addr_t bt_addr;
-  };
+typedef struct oc_endpoint {
+    enum transport_flags {
+        IP = 1 << 0,
+        GATT = 1 << 1,
+        IPSP = 1 << 2,
+        MULTICAST = 1 << 3,
+        SECURED = 1 << 4,
+        SERIAL = 1 <<5,
+    } flags;
+
+    union {
+        oc_ipv6_addr_t ipv6_addr;
+        oc_le_addr_t bt_addr;
+    };
 } oc_endpoint_t;
 
 #define oc_make_ip_endpoint(__name__, __flags__, __port__, ...)                \
@@ -64,13 +59,12 @@ typedef struct
                             .ipv6_addr = {.port = __port__,                    \
                                           .address = { __VA_ARGS__ } } }
 
-typedef struct oc_message_s
-{
-  struct oc_message_s *next;
-  oc_endpoint_t endpoint;
-  size_t length;
-  uint8_t ref_count;
-  uint8_t data[MAX_PAYLOAD_SIZE];
+typedef struct oc_message {
+    struct oc_message *next;
+    oc_endpoint_t endpoint;
+    size_t length;
+    uint8_t ref_count;
+    uint8_t data[MAX_PAYLOAD_SIZE];
 } oc_message_t;
 
 void oc_send_buffer(oc_message_t *message);


[04/16] incubator-mynewt-core git commit: oic; change to use os_mbuf from transport to oc_recv_message(). Call oc_recv_message() directly, instead of going through oc_network_events.

Posted by ma...@apache.org.
oic; change to use os_mbuf from transport to oc_recv_message().
Call oc_recv_message() directly, instead of going through oc_network_events.


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/51dfe836
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/51dfe836
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/51dfe836

Branch: refs/heads/develop
Commit: 51dfe836a231832b2a31aedf727a3e83a0b5d99a
Parents: 26a8f8c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 23 16:19:41 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 kernel/os/include/os/os_mbuf.h           |   2 +-
 net/oic/include/oic/oc_buffer.h          |   7 +-
 net/oic/include/oic/oc_network_events.h  |  32 --------
 net/oic/src/api/oc_buffer.c              |  86 ++++++++++++++-------
 net/oic/src/api/oc_network_events.c      |  57 --------------
 net/oic/src/api/oc_ri.c                  |   1 -
 net/oic/src/port/mynewt/adaptor.h        |   3 -
 net/oic/src/port/mynewt/ble_adaptor.c    |  71 +++++++-----------
 net/oic/src/port/mynewt/ip_adaptor.c     | 104 +++++++++++---------------
 net/oic/src/port/mynewt/serial_adaptor.c |  79 +++++++------------
 net/oic/src/port/oc_connectivity.h       |   1 -
 11 files changed, 163 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/kernel/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_mbuf.h b/kernel/os/include/os/os_mbuf.h
index 0b56962..495f4b4 100644
--- a/kernel/os/include/os/os_mbuf.h
+++ b/kernel/os/include/os/os_mbuf.h
@@ -61,7 +61,7 @@ struct os_mbuf_pool {
  */
 struct os_mbuf_pkthdr {
     /**
-     * Overall length of the packet. 
+     * Overall length of the packet.
      */
     uint16_t omp_len;
     /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 7dab610..2d67109 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -21,12 +21,17 @@
 extern "C" {
 #endif
 
+#define OC_MBUF_ENDPOINT(m)                                             \
+    (struct oc_endpoint *)((uint8_t *)m + sizeof(struct os_mbuf) +     \
+                                          sizeof(struct os_mbuf_pkthdr))
+
 struct oc_message;
+struct os_mbuf;
 struct oc_message *oc_allocate_message(void);
 void oc_message_add_ref(struct oc_message *message);
 void oc_message_unref(struct oc_message *message);
 
-void oc_recv_message(struct oc_message *message);
+void oc_recv_message(struct os_mbuf *m);
 void oc_send_message(struct oc_message *message);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
deleted file mode 100644
index f786390..0000000
--- a/net/oic/include/oic/oc_network_events.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-// Copyright (c) 2016 Intel Corporation
-//
-// Licensed 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 OC_NETWORK_EVENTS_H
-#define OC_NETWORK_EVENTS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct oc_message;
-
-void oc_network_event(struct oc_message *message);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_NETWORK_EVENTS_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index bd3bbd1..b92ac8f 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -18,6 +18,7 @@
 
 #include <os/os_eventq.h>
 #include <os/os_mempool.h>
+#include <os/os_mbuf.h>
 
 #include "messaging/coap/engine.h"
 #include "port/oc_signal_main_loop.h"
@@ -37,19 +38,12 @@ static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
 
 static void oc_buffer_handler(struct os_event *);
 
-static struct oc_message *oc_buffer_inq;
+static struct os_mqueue oc_inq;
 static struct oc_message *oc_buffer_outq;
 static struct os_event oc_buffer_ev = {
     .ev_cb = oc_buffer_handler
 };
 
-void
-oc_buffer_init(void)
-{
-    os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
-      sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
-}
-
 oc_message_t *
 oc_allocate_message(void)
 {
@@ -103,10 +97,12 @@ oc_queue_msg(struct oc_message **head, struct oc_message *msg)
 }
 
 void
-oc_recv_message(oc_message_t *message)
+oc_recv_message(struct os_mbuf *m)
 {
-    oc_queue_msg(&oc_buffer_inq, message);
-    os_eventq_put(oc_evq_get(), &oc_buffer_ev);
+    int rc;
+
+    rc = os_mqueue_put(&oc_inq, oc_evq_get(), m);
+    assert(rc == 0);
 }
 
 void
@@ -153,23 +149,52 @@ oc_buffer_tx(struct oc_message *message)
 }
 
 static void
-oc_buffer_rx(struct oc_message *msg)
+oc_buffer_rx(struct os_event *ev)
 {
+    struct oc_message *msg;
+    struct os_mbuf *m;
+#if defined(OC_SECURITY)
+    uint8_t b;
+#endif
+
+    while ((m = os_mqueue_get(&oc_inq)) != NULL) {
+        msg = oc_allocate_message();
+        if (!msg) {
+            ERROR("Could not allocate OC message buffer\n");
+            goto free_msg;
+        }
+        if (OS_MBUF_PKTHDR(m)->omp_len > MAX_PAYLOAD_SIZE) {
+            ERROR("Message to large for OC message buffer\n");
+            goto free_msg;
+        }
+        if (os_mbuf_copydata(m, 0, OS_MBUF_PKTHDR(m)->omp_len, msg->data)) {
+            ERROR("Failed to copy message from mbuf to OC message buffer \n");
+            goto free_msg;
+        }
+        memcpy(&msg->endpoint, OC_MBUF_ENDPOINT(m), sizeof(msg->endpoint));
+        msg->length = OS_MBUF_PKTHDR(m)->omp_len;
+
 #ifdef OC_SECURITY
-    uint8_t b = (uint8_t)(msg->data[0];
-    if (b > 19 && b < 64) {
-        LOG("Inbound network event: encrypted request\n");
-        oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], msg);
-    } else {
+        b = m->om_data[0];
+        if (b > 19 && b < 64) {
+            LOG("Inbound network event: encrypted request\n");
+            oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], m);
+        } else {
+            LOG("Inbound network event: decrypted request\n");
+            coap_receive(msg);
+            oc_message_unref(msg);
+        }
+#else
         LOG("Inbound network event: decrypted request\n");
         coap_receive(msg);
         oc_message_unref(msg);
-    }
-#else
-    LOG("Inbound network event: decrypted request\n");
-    coap_receive(msg);
-    oc_message_unref(msg);
 #endif
+free_msg:
+        os_mbuf_free_chain(m);
+        if (msg) {
+            oc_message_unref(msg);
+        }
+    }
 }
 
 static void
@@ -177,18 +202,21 @@ oc_buffer_handler(struct os_event *ev)
 {
     struct oc_message *msg;
 
-    while (oc_buffer_outq || oc_buffer_inq) {
+    while (oc_buffer_outq) {
         msg = oc_buffer_outq;
         if (msg) {
             oc_buffer_outq = msg->next;
             msg->next = NULL;
             oc_buffer_tx(msg);
         }
-        msg = oc_buffer_inq;
-        if (msg) {
-            oc_buffer_inq = msg->next;
-            msg->next = NULL;
-            oc_buffer_rx(msg);
-        }
     }
 }
+
+void
+oc_buffer_init(void)
+{
+    os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
+      sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
+    os_mqueue_init(&oc_inq, oc_buffer_rx, NULL);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
deleted file mode 100644
index 6f33189..0000000
--- a/net/oic/src/api/oc_network_events.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-// Copyright (c) 2016 Intel Corporation
-//
-// Licensed 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 <os/os_eventq.h>
-
-#include "oc_network_events.h"
-#include "oc_buffer.h"
-#include "port/oc_connectivity.h"
-#include "port/oc_signal_main_loop.h"
-#include "port/oc_network_events_mutex.h"
-#include "port/mynewt/adaptor.h"
-#include "util/oc_list.h"
-
-OC_LIST(network_events);
-static void oc_network_ev_process(struct os_event *ev);
-static struct os_event oc_network_ev = {
-    .ev_cb = oc_network_ev_process
-};
-
-static void
-oc_network_ev_process(struct os_event *ev)
-{
-    struct oc_message *head;
-
-    oc_network_event_handler_mutex_lock();
-    while (1) {
-        head = oc_list_pop(network_events);
-        if (!head) {
-            break;
-        }
-        oc_recv_message(head);
-    }
-    oc_network_event_handler_mutex_unlock();
-}
-
-void
-oc_network_event(oc_message_t *message)
-{
-    oc_network_event_handler_mutex_lock();
-    oc_list_add(network_events, message);
-    oc_network_event_handler_mutex_unlock();
-
-    os_eventq_put(oc_evq_get(), &oc_network_ev);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/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 9219f7b..8221ea5 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -34,7 +34,6 @@
 #include "oc_buffer.h"
 #include "oc_core_res.h"
 #include "oc_discovery.h"
-#include "oc_network_events.h"
 #include "oc_ri.h"
 #include "oc_uuid.h"
 #include "oc_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index a40d2e8..c6ea8bb 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -34,7 +34,6 @@ int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
 void oc_send_buffer_ip(struct oc_message *message);
 void oc_send_buffer_ip_mcast(struct oc_message *message);
-struct oc_message *oc_attempt_rx_ip(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
@@ -42,14 +41,12 @@ int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
 void oc_send_buffer_gatt(struct oc_message *message);
 void oc_send_buffer_gatt_mcast(struct oc_message *message);
-struct oc_message *oc_attempt_rx_gatt(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
 void oc_send_buffer_serial(struct oc_message *message);
-struct oc_message *oc_attempt_rx_serial(void);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 18ff7ad..0c3363f 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -109,75 +109,58 @@ gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
     return 0;
 }
 
-oc_message_t *
+static struct os_mbuf *
 oc_attempt_rx_gatt(void)
 {
     int rc;
-    struct os_mbuf *m = NULL;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
     struct os_mbuf_pkthdr *pkt;
+    struct oc_endpoint *oe;
     uint16_t conn_handle;
-    oc_message_t *message = NULL;
 
     LOG("oc_transport_gatt attempt rx\n");
 
     /* get an mbuf from the queue */
-    m = os_mqueue_get(&ble_coap_mq);
-    if (NULL == m) {
-        ERROR("oc_transport_gatt: Woke for for receive but found no mbufs\n");
-        goto rx_attempt_err;
-    }
-
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        ERROR("oc_transport_gatt: received mbuf that wasn't a packet header\n");
-        goto rx_attempt_err;
+    n = os_mqueue_get(&ble_coap_mq);
+    if (NULL == n) {
+        ERROR("oc_transport_gatt: Woke for receive but found no mbufs\n");
+        return NULL;
     }
 
-    pkt = OS_MBUF_PKTHDR(m);
+    pkt = OS_MBUF_PKTHDR(n);
 
-    LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
     /* get the conn handle from the end of the message */
-    rc = os_mbuf_copydata(m, pkt->omp_len - sizeof(conn_handle),
+    rc = os_mbuf_copydata(n, pkt->omp_len - sizeof(conn_handle),
                           sizeof(conn_handle), &conn_handle);
     if (rc != 0) {
-        ERROR("Failed to retrieve conn_handle from mbuf \n");
+        ERROR("Failed to retrieve conn_handle from mbuf\n");
         goto rx_attempt_err;
     }
 
     /* trim conn_handle from the end */
-    os_mbuf_adj(m, - sizeof(conn_handle));
+    os_mbuf_adj(n, - sizeof(conn_handle));
 
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = pkt->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
+
+    oe->flags = GATT;
+    oe->bt_addr.conn_handle = conn_handle;
+
+    LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
 
-    os_mbuf_free_chain(m);
-    message->endpoint.flags = GATT;
-    message->endpoint.bt_addr.conn_handle = conn_handle;
-    message->length = pkt->omp_len;
-    LOG("Successfully rx length %lu\n", (unsigned long)message->length);
-    return message;
+    return m;
 
     /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-    if (message) {
-        oc_message_unref(message);
-    }
+    os_mbuf_free_chain(n);
     return NULL;
 }
 #endif
@@ -204,10 +187,10 @@ ble_coap_gatt_srv_init(void)
 static void
 oc_event_gatt(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_gatt()) != NULL) {
+        oc_recv_message(m);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 646a5b0..181bc68 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -20,9 +20,11 @@
 #include <syscfg/syscfg.h>
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 #include <assert.h>
+#include <string.h>
+
 #include <os/os.h>
 #include <os/endian.h>
-#include <string.h>
+
 #include <log/log.h>
 #include <mn_socket/mn_socket.h>
 
@@ -75,7 +77,7 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
            sizeof(to.msin6_addr));
 
     /* put on an mbuf header to make the socket happy */
-    memset(&m,0, sizeof(m));
+    memset(&m, 0, sizeof(m));
     m.om_data = message->data;
     m.om_len = message->length;
     to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
@@ -113,91 +115,73 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
 }
 
 void
-oc_send_buffer_ip(oc_message_t *message) {
+oc_send_buffer_ip(oc_message_t *message)
+{
     oc_send_buffer_ip_int(message, 0);
 }
 void
-oc_send_buffer_ip_mcast(oc_message_t *message) {
+oc_send_buffer_ip_mcast(oc_message_t *message)
+{
     oc_send_buffer_ip_int(message, 1);
 }
 
-oc_message_t *
-oc_attempt_rx_ip_sock(struct mn_socket * rxsock) {
+static struct os_mbuf *
+oc_attempt_rx_ip_sock(struct mn_socket * rxsock)
+{
     int rc;
-    struct os_mbuf *m = NULL;
-    struct os_mbuf_pkthdr *pkt;
-    oc_message_t *message = NULL;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct oc_endpoint *oe;
     struct mn_sockaddr_in6 from;
 
     LOG("oc_transport_ip attempt rx from %p\n", rxsock);
 
-    rc= mn_recvfrom(rxsock, &m, (struct mn_sockaddr *) &from);
-
-    if ( rc != 0) {
+    rc = mn_recvfrom(rxsock, &n, (struct mn_sockaddr *) &from);
+    if (rc != 0) {
         return NULL;
     }
+    assert(OS_MBUF_IS_PKTHDR(n));
 
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        goto rx_attempt_err;
-    }
-
-    pkt = OS_MBUF_PKTHDR(m);
-
-    LOG("rx from %p %p-%u\n", rxsock, pkt, pkt->omp_len);
-
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
 
-    os_mbuf_free_chain(m);
+    LOG("rx from %p %p-%u\n", rxsock, m, OS_MBUF_PKTHDR(m)->omp_len);
 
-    message->endpoint.flags = IP;
-    message->length = pkt->omp_len;
-    memcpy(&message->endpoint.ipv6_addr.address, &from.msin6_addr,
-             sizeof(message->endpoint.ipv6_addr.address));
-    message->endpoint.ipv6_addr.scope = from.msin6_scope_id;
-    message->endpoint.ipv6_addr.port = ntohs(from.msin6_port);
+    oe->flags = IP;
+    memcpy(&oe->ipv6_addr.address, &from.msin6_addr,
+             sizeof(oe->ipv6_addr.address));
+    oe->ipv6_addr.scope = from.msin6_scope_id;
+    oe->ipv6_addr.port = ntohs(from.msin6_port);
 
-    LOG("Successfully rx from %p len %lu\n", rxsock,
-        (unsigned long)message->length);
-    return message;
+    LOG("Successfully rx from %p\n", rxsock);
+
+    return m;
 
     /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-
-    if (message) {
-        oc_message_unref(message);
-    }
-
+    os_mbuf_free_chain(n);
     return NULL;
 }
 
-oc_message_t *
-oc_attempt_rx_ip(void) {
-    oc_message_t *pmsg;
-    pmsg = oc_attempt_rx_ip_sock(ucast);
+static struct os_mbuf *
+oc_attempt_rx_ip(void)
+{
+    struct os_mbuf *m;
+
+    m = oc_attempt_rx_ip_sock(ucast);
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    if (pmsg == NULL ) {
-        pmsg = oc_attempt_rx_ip_sock(mcast);
+    if (m == NULL ) {
+        m = oc_attempt_rx_ip_sock(mcast);
     }
 #endif
-    return pmsg;
+    return m;
 }
 
 static void oc_socks_readable(void *cb_arg, int err);
@@ -233,10 +217,10 @@ oc_connectivity_shutdown_ip(void)
 static void
 oc_event_ip(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_ip()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_ip()) != NULL) {
+        oc_recv_message(m);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index be807d3..209a9c7 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -21,16 +21,20 @@
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 
 #include <assert.h>
+
 #include <os/os.h>
+
 #include <shell/shell.h>
+
 #include "oc_buffer.h"
 #include "port/oc_connectivity.h"
 #include "../oc_log.h"
 #include "adaptor.h"
 
-
 struct os_mqueue oc_serial_mqueue;
 
+static struct os_mbuf *oc_attempt_rx_serial(void);
+
 static int
 oc_serial_in(struct os_mbuf *m, void *arg)
 {
@@ -38,17 +42,18 @@ oc_serial_in(struct os_mbuf *m, void *arg)
 }
 
 void
-oc_connectivity_shutdown_serial(void) {
+oc_connectivity_shutdown_serial(void)
+{
     shell_nlip_input_register(NULL, NULL);
 }
 
 static void
 oc_event_serial(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_serial()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_serial()) != NULL) {
+        oc_recv_message(m);
     }
 }
 
@@ -110,67 +115,39 @@ err:
 
 }
 
-oc_message_t *
-oc_attempt_rx_serial(void) {
-    int rc;
-    struct os_mbuf *m = NULL;
-    struct os_mbuf_pkthdr *pkt;
-    oc_message_t *message = NULL;
+static struct os_mbuf *
+oc_attempt_rx_serial(void)
+{
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct oc_endpoint *oe;
 
     LOG("oc_transport_serial attempt rx\n");
 
     /* get an mbuf from the queue */
-    m = os_mqueue_get(&oc_serial_mqueue);
-    if (NULL == m) {
+    n = os_mqueue_get(&oc_serial_mqueue);
+    if (NULL == n) {
         ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n");
-        goto rx_attempt_err;
-    }
-
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        ERROR("oc_transport_serial: received mbuf that wasn't a packet header\n");
-        goto rx_attempt_err;
+        return NULL;
     }
 
-    pkt = OS_MBUF_PKTHDR(m);
-
-    LOG("oc_transport_serial rx %p-%u\n", pkt, pkt->omp_len);
-
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
+    oe->flags = SERIAL;
 
-    os_mbuf_free_chain(m);
+    LOG("oc_transport_serial rx %p-%u\n", n, OS_MBUF_PKTHDR(n)->omp_len);
 
-    message->endpoint.flags = SERIAL;
-    message->length = pkt->omp_len;
+    return m;
 
-    LOG("Successfully rx length %zu\n", message->length);
-    return message;
-
-    /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-
-    if (message) {
-        oc_message_unref(message);
-    }
-
+    os_mbuf_free_chain(n);
     return NULL;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/51dfe836/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 3f84541..493b30e 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -18,7 +18,6 @@
 #define OC_CONNECTIVITY_H
 
 #include "mynewt/config.h"
-#include "oic/oc_network_events.h"
 #include "oc_log.h"
 #include <stdint.h>
 


[07/16] incubator-mynewt-core git commit: oic; remove most of the oc_list users.

Posted by ma...@apache.org.
oic; remove most of the oc_list users.


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/d541740a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d541740a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d541740a

Branch: refs/heads/develop
Commit: d541740a900874c1357da5a99580005e7c1d4cac
Parents: 670a657
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 29 12:38:52 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_client_state.h     |   4 +-
 net/oic/include/oic/oc_ri.h               |  11 ++-
 net/oic/src/api/oc_discovery.c            |  19 +++--
 net/oic/src/api/oc_ri.c                   | 107 ++++++++++++-------------
 net/oic/src/api/oc_server_api.c           |  73 ++++++++---------
 net/oic/src/messaging/coap/observe.c      |  50 +++++++-----
 net/oic/src/messaging/coap/observe.h      |   5 +-
 net/oic/src/messaging/coap/oc_coap.h      |  22 +++--
 net/oic/src/messaging/coap/separate.c     |  17 ++--
 net/oic/src/messaging/coap/separate.h     |  20 ++---
 net/oic/src/messaging/coap/transactions.c |  22 +++--
 net/oic/src/messaging/coap/transactions.h |   2 +-
 12 files changed, 179 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/include/oic/oc_client_state.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_client_state.h b/net/oic/include/oic/oc_client_state.h
index e844276..dd6308d 100644
--- a/net/oic/include/oic/oc_client_state.h
+++ b/net/oic/include/oic/oc_client_state.h
@@ -51,8 +51,8 @@ typedef oc_discovery_flags_t(oc_discovery_cb_t)(const char *, const char *,
 
 typedef void (*oc_response_handler_t)(oc_client_response_t *);
 
-typedef struct oc_client_cb_s {
-    struct oc_client_cb_s *next;
+typedef struct oc_client_cb {
+    SLIST_ENTRY(oc_client_cb) next;
     struct os_callout callout;
     oc_string_t uri;
     uint8_t token[COAP_TOKEN_LEN];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 79e57e6..c501f46 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -61,9 +61,9 @@ typedef enum {
   OC_IGNORE
 } oc_status_t;
 
-typedef struct oc_separate_response_s oc_separate_response_t;
+typedef struct oc_separate_response oc_separate_response_t;
 
-typedef struct oc_response_buffer_s oc_response_buffer_t;
+typedef struct oc_response_buffer oc_response_buffer_t;
 
 typedef struct
 {
@@ -95,7 +95,7 @@ typedef enum {
 
 #define NUM_OC_CORE_RESOURCES (__NUM_OC_CORE_RESOURCES__ + MAX_NUM_DEVICES)
 
-typedef struct oc_resource_s oc_resource_t;
+typedef struct oc_resource oc_resource_t;
 
 typedef struct
 {
@@ -110,9 +110,8 @@ typedef struct
 
 typedef void (*oc_request_handler_t)(oc_request_t *, oc_interface_mask_t);
 
-typedef struct oc_resource_s
-{
-  struct oc_resource_s *next;
+typedef struct oc_resource {
+  SLIST_ENTRY(oc_resource) next;
   int device;
   oc_string_t uri;
   oc_string_array_t types;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 e8ca760..ea6de37 100644
--- a/net/oic/src/api/oc_discovery.c
+++ b/net/oic/src/api/oc_discovery.c
@@ -84,6 +84,9 @@ process_device_object(CborEncoder *device, const char *uuid, const char *rt,
                       int rt_len)
 {
   int dev, matches = 0;
+#ifdef OC_SERVER
+  oc_resource_t *resource;
+#endif
   oc_rep_start_object(*device, links);
   oc_rep_set_text_string(links, di, uuid);
   oc_rep_set_array(links, links);
@@ -100,14 +103,14 @@ process_device_object(CborEncoder *device, const char *uuid, const char *rt,
   }
 
 #ifdef OC_SERVER
-  oc_resource_t *resource = oc_ri_get_app_resources();
-  for (; resource; resource = resource->next) {
-
-    if (!(resource->properties & OC_DISCOVERABLE))
-      continue;
-
-    if (filter_resource(resource, rt, rt_len, oc_rep_array(links)))
-      matches++;
+  for (resource = oc_ri_get_app_resources(); resource;
+       resource = SLIST_NEXT(resource, next)) {
+      if (!(resource->properties & OC_DISCOVERABLE)) {
+          continue;
+      }
+      if (filter_resource(resource, rt, rt_len, oc_rep_array(links))) {
+          matches++;
+      }
   }
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 8221ea5..da89d11 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -20,8 +20,7 @@
 
 #include <os/os_callout.h>
 #include <os/os_mempool.h>
-
-#include "util/oc_list.h"
+#include <os/queue.h>
 
 #include "messaging/coap/constants.h"
 #include "messaging/coap/engine.h"
@@ -44,9 +43,8 @@
 #endif /* OC_SECURITY */
 
 #ifdef OC_SERVER
-OC_LIST(app_resources);
-OC_LIST(observe_callbacks);
-static struct os_mempool oc_resources;
+static SLIST_HEAD(, oc_resource) oc_app_resources;
+static struct os_mempool oc_resource_pool;
 static uint8_t oc_resource_area[OS_MEMPOOL_BYTES(MAX_APP_RESOURCES,
       sizeof(oc_resource_t))];
 
@@ -55,8 +53,8 @@ static void periodic_observe_handler(struct os_event *ev);
 
 #ifdef OC_CLIENT
 #include "oc_client_state.h"
-OC_LIST(client_cbs);
-static struct os_mempool oc_client_cbs;
+static SLIST_HEAD(, oc_client_cb) oc_client_cbs;
+static struct os_mempool oc_client_cb_pool;
 static uint8_t oc_client_cb_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS,
       sizeof(oc_client_cb_t))];
 #endif /* OC_CLIENT */
@@ -120,7 +118,7 @@ set_mpro_status_codes(void)
 oc_resource_t *
 oc_ri_get_app_resources(void)
 {
-  return oc_list_head(app_resources);
+    return SLIST_FIRST(&oc_app_resources);
 }
 #endif
 
@@ -203,14 +201,15 @@ stop_processes(void)
 oc_resource_t *
 oc_ri_get_app_resource_by_uri(const char *uri)
 {
-  oc_resource_t *res = oc_ri_get_app_resources();
-  while (res != NULL) {
-    if (oc_string_len(res->uri) == strlen(uri) &&
-        strncmp(uri, oc_string(res->uri), strlen(uri)) == 0)
-      return res;
-    res = res->next;
-  }
-  return res;
+    oc_resource_t *res;
+
+    SLIST_FOREACH(res, &oc_app_resources, next) {
+        if (oc_string_len(res->uri) == strlen(uri) &&
+          strncmp(uri, oc_string(res->uri), strlen(uri)) == 0)
+            return res;
+    }
+
+    return NULL;
 }
 #endif
 
@@ -221,15 +220,14 @@ oc_ri_init(void)
   set_mpro_status_codes();
 
 #ifdef OC_SERVER
-  oc_list_init(app_resources);
-  os_mempool_init(&oc_resources, MAX_APP_RESOURCES, sizeof(oc_resource_t),
+  SLIST_INIT(&oc_app_resources);
+  os_mempool_init(&oc_resource_pool, MAX_APP_RESOURCES, sizeof(oc_resource_t),
     oc_resource_area, "oc_res");
-  oc_list_init(observe_callbacks);
 #endif
 
 #ifdef OC_CLIENT
-  oc_list_init(client_cbs);
-  os_mempool_init(&oc_client_cbs, MAX_NUM_CONCURRENT_REQUESTS,
+  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();
@@ -250,9 +248,9 @@ oc_ri_shutdown(void)
 oc_resource_t *
 oc_ri_alloc_resource(void)
 {
-    struct oc_resource_s *resource;
+    struct oc_resource *resource;
 
-    resource = os_memblock_get(&oc_resources);
+    resource = os_memblock_get(&oc_resource_pool);
     if (resource) {
         os_callout_init(&resource->callout, oc_evq_get(),
           periodic_observe_handler, resource);
@@ -263,7 +261,7 @@ oc_ri_alloc_resource(void)
 void
 oc_ri_delete_resource(oc_resource_t *resource)
 {
-    os_memblock_put(&oc_resources, resource);
+    os_memblock_put(&oc_resource_pool, resource);
 }
 
 bool
@@ -280,7 +278,7 @@ oc_ri_add_resource(oc_resource_t *resource)
         valid = false;
     }
     if (valid) {
-        oc_list_add(app_resources, resource);
+        SLIST_INSERT_HEAD(&oc_app_resources, resource, next);
     }
 
     return valid;
@@ -292,7 +290,7 @@ oc_ri_add_resource(oc_resource_t *resource)
 static void
 periodic_observe_handler(struct os_event *ev)
 {
-    struct oc_resource_s *resource;
+    struct oc_resource *resource;
 
     resource = ev->ev_arg;
 
@@ -464,15 +462,14 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
   /* Check against list of declared application resources.
    */
   if (!cur_resource && !bad_request) {
-    for (resource = oc_ri_get_app_resources(); resource;
-         resource = resource->next) {
-      if (oc_string_len(resource->uri) == (uri_path_len + 1) &&
-          strncmp((const char *)oc_string(resource->uri) + 1, uri_path,
-                  uri_path_len) == 0) {
-        request_obj.resource = cur_resource = resource;
-        break;
+      SLIST_FOREACH(resource, &oc_app_resources, next) {
+          if (oc_string_len(resource->uri) == (uri_path_len + 1) &&
+            strncmp((const char *)oc_string(resource->uri) + 1, uri_path,
+              uri_path_len) == 0) {
+              request_obj.resource = cur_resource = resource;
+              break;
+          }
       }
-    }
   }
 #endif
 
@@ -676,21 +673,23 @@ free_client_cb(oc_client_cb_t *cb)
 {
     os_callout_stop(&cb->callout);
     oc_free_string(&cb->uri);
-    oc_list_remove(client_cbs, cb);
-    os_memblock_put(&oc_client_cbs, cb);
+    SLIST_REMOVE(&oc_client_cbs, cb, oc_client_cb, next);
+    os_memblock_put(&oc_client_cb_pool, cb);
 }
 
 void
 oc_ri_remove_client_cb_by_mid(uint16_t mid)
 {
-  oc_client_cb_t *cb = (oc_client_cb_t *)oc_list_head(client_cbs);
-  while (cb != NULL) {
-    if (cb->mid == mid)
-      break;
-    cb = cb->next;
-  }
-  if (cb)
-    free_client_cb(cb);
+    oc_client_cb_t *cb;
+
+    SLIST_FOREACH(cb, &oc_client_cbs, next) {
+        if (cb->mid == mid) {
+            break;
+        }
+    }
+    if (cb) {
+        free_client_cb(cb);
+    }
 }
 
 bool
@@ -716,7 +715,7 @@ oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint)
   uint8_t *payload;
   int payload_len;
   coap_packet_t *const pkt = (coap_packet_t *)response;
-  oc_client_cb_t *cb = oc_list_head(client_cbs);
+  oc_client_cb_t *cb, *tmp;
   int i;
   /*
     if con then send ack and process as above
@@ -731,7 +730,9 @@ oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint)
   unsigned int content_format = APPLICATION_CBOR;
   coap_get_header_content_format(pkt, &content_format);
 
+  cb = SLIST_FIRST(&oc_client_cbs);
   while (cb != NULL) {
+    tmp = SLIST_NEXT(cb, next);
     if (cb->token_len == pkt->token_len &&
         memcmp(cb->token, pkt->token, pkt->token_len) == 0) {
 
@@ -803,7 +804,7 @@ oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint)
 
       break;
     }
-    cb = cb->next;
+    cb = tmp;
   }
 
   return true;
@@ -813,9 +814,9 @@ oc_client_cb_t *
 oc_ri_get_client_cb(const char *uri, oc_server_handle_t *server,
                     oc_method_t method)
 {
-    oc_client_cb_t *cb = (oc_client_cb_t *)oc_list_head(client_cbs);
+    oc_client_cb_t *cb;
 
-    while (cb != NULL) {
+    SLIST_FOREACH(cb, &oc_client_cbs, next) {
         if (oc_string_len(cb->uri) == strlen(uri) &&
           strncmp(oc_string(cb->uri), uri, strlen(uri)) == 0 &&
           memcmp(&cb->server.endpoint, &server->endpoint,
@@ -823,17 +824,15 @@ oc_ri_get_client_cb(const char *uri, oc_server_handle_t *server,
           cb->method == method) {
             return cb;
         }
-
-        cb = cb->next;
     }
 
-    return cb;
+    return NULL;
 }
 
 static void
 oc_ri_remove_cb(struct os_event *ev)
 {
-    struct oc_client_cb_s *cb;
+    struct oc_client_cb *cb;
 
     cb = ev->ev_arg;
 
@@ -846,7 +845,7 @@ oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
 {
     oc_client_cb_t *cb;
 
-    cb = os_memblock_get(&oc_client_cbs);
+    cb = os_memblock_get(&oc_client_cb_pool);
     if (!cb) {
         return NULL;
     }
@@ -870,7 +869,7 @@ oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
 
     os_callout_init(&cb->callout, oc_evq_get(), oc_ri_remove_cb, cb);
 
-    oc_list_add(client_cbs, cb);
+    SLIST_INSERT_HEAD(&oc_client_cbs, cb, next);
     return cb;
 }
 #endif /* OC_CLIENT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 48fb680..344d29f 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -234,44 +234,45 @@ void
 oc_send_separate_response(oc_separate_response_t *handle,
                           oc_status_t response_code)
 {
-  oc_response_buffer_t response_buffer;
-  response_buffer.buffer = handle->buffer;
-  response_buffer.response_length = response_length();
-  response_buffer.code = oc_status_code(response_code);
-
-  coap_separate_t *cur = oc_list_head(handle->requests), *next = NULL;
-  coap_packet_t response[1];
-
-  while (cur != NULL) {
-    next = cur->next;
-    if (cur->observe > 0) {
-      coap_transaction_t *t =
-        coap_new_transaction(coap_get_mid(), &cur->endpoint);
-      if (t) {
-        coap_separate_resume(response, cur, oc_status_code(response_code),
-                             t->mid);
-        coap_set_header_content_format(response, APPLICATION_CBOR);
-        if (cur->observe == 1) {
-          coap_set_header_observe(response, 1);
+    oc_response_buffer_t response_buffer;
+    coap_separate_t *cur, *next = NULL;
+    coap_packet_t response[1];
+    coap_transaction_t *t;
+
+    response_buffer.buffer = handle->buffer;
+    response_buffer.response_length = response_length();
+    response_buffer.code = oc_status_code(response_code);
+
+    for (cur = SLIST_FIRST(&handle->requests); cur; cur = next) {
+        next = SLIST_NEXT(cur, next);
+        if (cur->observe > 0) {
+            t = coap_new_transaction(coap_get_mid(), &cur->endpoint);
+            if (t) {
+                coap_separate_resume(response, cur,
+                  oc_status_code(response_code), t->mid);
+                coap_set_header_content_format(response, APPLICATION_CBOR);
+                if (cur->observe == 1) {
+                    coap_set_header_observe(response, 1);
+                }
+                if (response_buffer.response_length > 0) {
+                    coap_set_payload(response, handle->buffer,
+                      response_buffer.response_length);
+                }
+                t->message->length = coap_serialize_message(response,
+                  t->message->data);
+                coap_send_transaction(t);
+            }
+            coap_separate_clear(handle, cur);
+        } else {
+            if (coap_notify_observers(NULL, &response_buffer,
+                &cur->endpoint) == 0) {
+                coap_separate_clear(handle, cur);
+            }
         }
-        if (response_buffer.response_length > 0) {
-          coap_set_payload(response, handle->buffer,
-                           response_buffer.response_length);
-        }
-        t->message->length = coap_serialize_message(response, t->message->data);
-        coap_send_transaction(t);
-      }
-      coap_separate_clear(handle, cur);
-    } else {
-      if (coap_notify_observers(NULL, &response_buffer, &cur->endpoint) == 0) {
-        coap_separate_clear(handle, cur);
-      }
     }
-    cur = next;
-  }
-  if (oc_list_length(handle->requests) == 0) {
-    handle->active = 0;
-  }
+    if (SLIST_FIRST(&handle->requests) == NULL) {
+        handle->active = 0;
+    }
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 c67c0a7..711cfff 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -39,6 +39,7 @@
 #include <string.h>
 
 #include <os/os_mempool.h>
+#include <os/queue.h>
 
 #include "observe.h"
 
@@ -48,9 +49,9 @@
 /*-------------------*/
 uint64_t observe_counter = 3;
 /*---------------------------------------------------------------------------*/
-OC_LIST(observers_list);
+static SLIST_HEAD(, coap_observer) oc_observers;
 
-static struct os_mempool coap_observers;
+static struct os_mempool coap_observer_pool;
 static uint8_t coap_observer_area[OS_MEMPOOL_BYTES(COAP_MAX_OBSERVERS,
       sizeof(coap_observer_t))];
 
@@ -65,7 +66,7 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
     /* Remove existing observe relationship, if any. */
     int dup = coap_remove_observer_by_uri(endpoint, uri);
 
-    coap_observer_t *o = os_memblock_get(&coap_observers);
+    coap_observer_t *o = os_memblock_get(&coap_observer_pool);
 
     if (o) {
         int max = sizeof(o->url) - 1;
@@ -82,9 +83,9 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
         o->resource = resource;
         resource->num_observers++;
         LOG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
-          oc_list_length(observers_list) + 1, COAP_MAX_OBSERVERS, o->url,
-          o->token[0], o->token[1]);
-        oc_list_add(observers_list, o);
+          coap_observer_pool.mp_num_blocks - coap_observer_pool.mp_num_free,
+          coap_observer_pool.mp_num_blocks, o->url, o->token[0], o->token[1]);
+        SLIST_INSERT_HEAD(&oc_observers, o, next);
         return dup;
     }
     return -1;
@@ -97,22 +98,22 @@ coap_remove_observer(coap_observer_t *o)
 {
     LOG("Removing observer for /%s [0x%02X%02X]\n", o->url, o->token[0],
       o->token[1]);
-    oc_list_remove(observers_list, o);
-    os_memblock_put(&coap_observers, o);
+    SLIST_REMOVE(&oc_observers, o, coap_observer, next);
+    os_memblock_put(&coap_observer_pool, o);
 }
 /*---------------------------------------------------------------------------*/
 int
 coap_remove_observer_by_client(oc_endpoint_t *endpoint)
 {
     int removed = 0;
-    coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list),
-      *next;
+    coap_observer_t *obs, *next;
 
     LOG("Unregistering observers for client at: ");
     LOGipaddr(*endpoint);
 
+    obs = SLIST_FIRST(&oc_observers);
     while (obs) {
-        next = obs->next;
+        next = SLIST_NEXT(obs, next);
         if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0) {
             obs->resource->num_observers--;
             coap_remove_observer(obs);
@@ -129,10 +130,13 @@ coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
                               size_t token_len)
 {
     int removed = 0;
-    coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list);
+    coap_observer_t *obs, *next;
     LOG("Unregistering observers for request token 0x%02X%02X\n", token[0],
       token[1]);
+
+    obs = SLIST_FIRST(&oc_observers);
     while (obs) {
+        next = SLIST_NEXT(obs, next);
         if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0 &&
           obs->token_len == token_len &&
           memcmp(obs->token, token, token_len) == 0) {
@@ -141,7 +145,7 @@ coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
             removed++;
             break;
         }
-        obs = obs->next;
+        obs = next;
     }
     LOG("Removed %d observers\n", removed);
     return removed;
@@ -152,11 +156,11 @@ coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
 {
     LOG("Unregistering observers for resource uri /%s", uri);
     int removed = 0;
-    coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list),
-      *next;
+    coap_observer_t *obs, *next;
 
+    obs = SLIST_FIRST(&oc_observers);
     while (obs) {
-        next = obs->next;
+        next = SLIST_NEXT(obs, next);
         if (((memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0)) &&
           (obs->url == uri || memcmp(obs->url, uri, strlen(obs->url)) == 0)) {
             obs->resource->num_observers--;
@@ -173,11 +177,12 @@ int
 coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
 {
     int removed = 0;
-    coap_observer_t *obs = NULL;
+    coap_observer_t *obs, *next;
     LOG("Unregistering observers for request MID %u\n", mid);
 
-    for (obs = (coap_observer_t *)oc_list_head(observers_list); obs != NULL;
-         obs = obs->next) {
+    obs = SLIST_FIRST(&oc_observers);
+    while (obs) {
+        next = SLIST_NEXT(obs, next);
         if (memcmp(&obs->endpoint, endpoint, sizeof(*endpoint)) == 0 &&
           obs->last_mid == mid) {
             obs->resource->num_observers--;
@@ -185,6 +190,7 @@ coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
             removed++;
             break;
         }
+        obs = next;
     }
     LOG("Removed %d observers\n", removed);
     return removed;
@@ -231,11 +237,11 @@ coap_notify_observers(oc_resource_t *resource,
 
     coap_observer_t *obs = NULL;
     /* iterate over observers */
-    for (obs = (coap_observer_t *)oc_list_head(observers_list);
+    for (obs = SLIST_FIRST(&oc_observers);
          obs && ((resource && obs->resource == resource) ||
            (endpoint &&
              memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0));
-         obs = obs->next) {
+         obs = SLIST_NEXT(obs, next)) {
         num_observers = obs->resource->num_observers;
         if (response.separate_response != NULL &&
           response_buf->code == oc_status_code(OC_STATUS_OK)) {
@@ -329,7 +335,7 @@ coap_observe_handler(void *request, void *response, oc_resource_t *resource,
 void
 coap_observe_init(void)
 {
-    os_mempool_init(&coap_observers, COAP_MAX_OBSERVERS,
+    os_mempool_init(&coap_observer_pool, COAP_MAX_OBSERVERS,
       sizeof(coap_observer_t), coap_observer_area, "coap_obs");
 }
 #endif /* OC_SERVER */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.h b/net/oic/src/messaging/coap/observe.h
index 095f21e..a913745 100644
--- a/net/oic/src/messaging/coap/observe.h
+++ b/net/oic/src/messaging/coap/observe.h
@@ -47,9 +47,8 @@ extern "C" {
 
 #define COAP_OBSERVER_URL_LEN 20
 
-typedef struct coap_observer
-{
-  struct coap_observer *next; /* for LIST */
+typedef struct coap_observer {
+  SLIST_ENTRY(coap_observer) next;
 
   oc_resource_t *resource;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/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 a94b926..cddf46f 100644
--- a/net/oic/src/messaging/coap/oc_coap.h
+++ b/net/oic/src/messaging/coap/oc_coap.h
@@ -24,20 +24,18 @@
 extern "C" {
 #endif
 
-typedef struct oc_separate_response_s
-{
-  OC_LIST_STRUCT(requests);
-  int active;
-  uint8_t buffer[COAP_MAX_BLOCK_SIZE];
+typedef struct oc_separate_response {
+    SLIST_HEAD(, coap_separate) requests;
+    int active;
+    uint8_t buffer[COAP_MAX_BLOCK_SIZE];
 } oc_separate_response_t;
 
-typedef struct oc_response_buffer_s
-{
-  uint8_t *buffer;
-  uint16_t buffer_size;
-  int32_t *block_offset;
-  uint16_t response_length;
-  int code;
+typedef struct oc_response_buffer {
+    uint8_t *buffer;
+    uint16_t buffer_size;
+    int32_t *block_offset;
+    uint16_t response_length;
+    int code;
 } oc_response_buffer_t;
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index b542586..015aa2d 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -51,7 +51,7 @@ static uint8_t coap_separate_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS,
 /*---------------------------------------------------------------------------*/
 /*- Separate Response API ---------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
-/*----------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
 /**
  * \brief Initiate a separate response with an empty ACK
  * \param request The request to accept
@@ -68,25 +68,27 @@ coap_separate_accept(coap_packet_t *coap_req,
                      oc_separate_response_t *separate_response,
                      oc_endpoint_t *endpoint, int observe)
 {
+    coap_separate_t *item;
+    coap_separate_t *separate_store;
+
     if (separate_response->active == 0) {
-        OC_LIST_STRUCT_INIT(separate_response, requests);
+        SLIST_INIT(&separate_response->requests);
     }
 
-    for (coap_separate_t *item = oc_list_head(separate_response->requests);
-         item != NULL; item = oc_list_item_next(separate_response->requests)) {
+    SLIST_FOREACH(item, &separate_response->requests, next) {
         if (item->token_len == coap_req->token_len &&
           memcmp(item->token, coap_req->token, item->token_len) == 0) {
             return 0;
         }
     }
 
-    coap_separate_t *separate_store = os_memblock_get(&coap_separate_pool);
+    separate_store = os_memblock_get(&coap_separate_pool);
 
     if (!separate_store) {
         return 0;
     }
 
-    oc_list_add(separate_response->requests, separate_store);
+    SLIST_INSERT_HEAD(&separate_response->requests, separate_store, next);
 
     erbium_status_code = CLEAR_TRANSACTION;
     /* send separate ACK for CON */
@@ -150,7 +152,8 @@ void
 coap_separate_clear(oc_separate_response_t *separate_response,
                     coap_separate_t *separate_store)
 {
-    oc_list_remove(separate_response->requests, separate_store);
+    SLIST_REMOVE(&separate_response->requests, separate_store, coap_separate,
+      next);
     os_memblock_put(&coap_separate_pool, separate_store);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/src/messaging/coap/separate.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.h b/net/oic/src/messaging/coap/separate.h
index c39d532..71ee3be 100644
--- a/net/oic/src/messaging/coap/separate.h
+++ b/net/oic/src/messaging/coap/separate.h
@@ -46,21 +46,21 @@ extern "C" {
 #include "oic/oc_ri.h"
 
 typedef struct coap_separate {
-  struct coap_separate *next;
-  coap_message_type_t type;
+    SLIST_ENTRY(coap_separate) next;
+    coap_message_type_t type;
 
-  uint8_t token_len;
-  uint8_t token[COAP_TOKEN_LEN];
+    uint8_t token_len;
+    uint8_t token[COAP_TOKEN_LEN];
 
-  uint32_t block1_num;
-  uint16_t block1_size;
+    uint32_t block1_num;
+    uint16_t block1_size;
 
-  uint32_t block2_num;
-  uint16_t block2_size;
+    uint32_t block2_num;
+    uint16_t block2_size;
 
-  int32_t observe;
+    int32_t observe;
 
-  oc_endpoint_t endpoint;
+    oc_endpoint_t endpoint;
 } coap_separate_t;
 
 typedef struct coap_packet coap_packet_t;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index c05ba63..662ca22 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -54,8 +54,7 @@
 static struct os_mempool oc_transaction_memb;
 static uint8_t oc_transaction_area[OS_MEMPOOL_BYTES(COAP_MAX_OPEN_TRANSACTIONS,
       sizeof(coap_transaction_t))];
-
-OC_LIST(transactions_list);
+static SLIST_HEAD(, coap_transaction) oc_transaction_list;
 
 static void coap_transaction_retrans(struct os_event *ev);
 
@@ -87,7 +86,7 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
             os_callout_init(&t->retrans_timer, oc_evq_get(),
               coap_transaction_retrans, t);
             /* list itself makes sure same element is not added twice */
-            oc_list_add(transactions_list, t);
+            SLIST_INSERT_HEAD(&oc_transaction_list, t, next);
         } else {
             os_memblock_put(&oc_transaction_memb, t);
             t = NULL;
@@ -171,7 +170,7 @@ coap_clear_transaction(coap_transaction_t *t)
 
         os_callout_stop(&t->retrans_timer);
         oc_message_unref(t->message);
-        oc_list_remove(transactions_list, t);
+        SLIST_REMOVE(&oc_transaction_list, t, coap_transaction, next);
         os_memblock_put(&oc_transaction_memb, t);
   }
 }
@@ -179,16 +178,15 @@ coap_clear_transaction(coap_transaction_t *t)
 coap_transaction_t *
 coap_get_transaction_by_mid(uint16_t mid)
 {
-  coap_transaction_t *t = NULL;
+    coap_transaction_t *t;
 
-  for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
-       t = t->next) {
-    if (t->mid == mid) {
-      LOG("Found transaction for MID %u: %p\n", t->mid, t);
-      return t;
+    SLIST_FOREACH(t, &oc_transaction_list, next) {
+        if (t->mid == mid) {
+            LOG("Found transaction for MID %u: %p\n", t->mid, t);
+            return t;
+        }
     }
-  }
-  return NULL;
+    return NULL;
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d541740a/net/oic/src/messaging/coap/transactions.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.h b/net/oic/src/messaging/coap/transactions.h
index 266f2fd..794b189 100644
--- a/net/oic/src/messaging/coap/transactions.h
+++ b/net/oic/src/messaging/coap/transactions.h
@@ -56,7 +56,7 @@ extern "C" {
 /* container for transactions with message buffer and retransmission info */
 typedef struct coap_transaction
 {
-  struct coap_transaction *next; /* for LIST */
+  SLIST_ENTRY(coap_transaction) next;
 
   uint16_t mid;
   uint8_t retrans_counter;


[02/16] incubator-mynewt-core git commit: oic/coap; don't use void * where coap_packet_t * should be used.

Posted by ma...@apache.org.
oic/coap; don't use void * where coap_packet_t * should be used.


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/d2321dab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d2321dab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d2321dab

Branch: refs/heads/develop
Commit: d2321dab5acd1c3183fc63b03dfe29bbefd81127
Parents: 4487aa6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 15:58:23 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/coap.c | 698 ++++++++++++++++-----------------
 net/oic/src/messaging/coap/coap.h | 108 +++--
 2 files changed, 379 insertions(+), 427 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d2321dab/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 d77fbbb..6412c71 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -260,36 +260,33 @@ coap_get_variable(const char *buffer, size_t length, const char *name,
 /*- Internal API ------------------------------------------------------------*/
 /*---------------------------------------------------------------------------*/
 void
-coap_init_connection()
+coap_init_connection(void)
 {
-  /* initialize transaction ID */
-  current_mid = oc_random_rand();
+    /* initialize transaction ID */
+    current_mid = oc_random_rand();
 }
 /*---------------------------------------------------------------------------*/
 uint16_t
-coap_get_mid()
+coap_get_mid(void)
 {
-  return ++current_mid;
+    return ++current_mid;
 }
 /*---------------------------------------------------------------------------*/
 void
-coap_init_message(void *packet, coap_message_type_t type, uint8_t code,
-                  uint16_t mid)
+coap_init_message(coap_packet_t *coap_pkt, coap_message_type_t type,
+                  uint8_t code, uint16_t mid)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
+    /* Important thing */
+    memset(coap_pkt, 0, sizeof(coap_packet_t));
 
-  /* Important thing */
-  memset(coap_pkt, 0, sizeof(coap_packet_t));
-
-  coap_pkt->type = type;
-  coap_pkt->code = code;
-  coap_pkt->mid = mid;
+    coap_pkt->type = type;
+    coap_pkt->code = code;
+    coap_pkt->mid = mid;
 }
 /*---------------------------------------------------------------------------*/
 size_t
-coap_serialize_message(void *packet, uint8_t *buffer)
+coap_serialize_message(coap_packet_t *coap_pkt, uint8_t *buffer)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
   uint8_t *option;
   unsigned int current_number = 0;
 
@@ -411,9 +408,8 @@ coap_send_message(oc_message_t *message)
 }
 /*---------------------------------------------------------------------------*/
 coap_status_t
-coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
+coap_parse_message(coap_packet_t *coap_pkt, uint8_t *data, uint16_t data_len)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
   /* initialize packet */
   memset(coap_pkt, 0, sizeof(coap_packet_t));
   /* pointer to packet bytes */
@@ -677,510 +673,472 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
 }
 #if 0
 int
-coap_get_query_variable(void *packet, const char *name, const char **output)
+coap_get_query_variable(coap_packet_t *const coap_pkt, const char *name,
+  const char **output)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if(IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
-    return coap_get_variable(coap_pkt->uri_query, coap_pkt->uri_query_len,
-			     name, output);
-  }
-  return 0;
+    if (IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
+        return coap_get_variable(coap_pkt->uri_query, coap_pkt->uri_query_len,
+                                 name, output);
+    }
+    return 0;
 }
 int
-coap_get_post_variable(void *packet, const char *name, const char **output)
+coap_get_post_variable(coap_packet_t *coap_pkt, const char *name,
+                       const char **output)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if(coap_pkt->payload_len) {
-    return coap_get_variable((const char *)coap_pkt->payload,
-			     coap_pkt->payload_len, name, output);
-  }
-  return 0;
+    if (coap_pkt->payload_len) {
+        return coap_get_variable(coap_pkt->payload, coap_pkt->payload_len,
+                                 name, output);
+    }
+    return 0;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_set_status_code(void *packet, unsigned int code)
+coap_set_status_code(coap_packet_t *const packet, unsigned int code)
 {
-  if (code <= 0xFF) {
-    ((coap_packet_t *)packet)->code = (uint8_t)code;
-    return 1;
-  } else {
-    return 0;
-  }
+    if (code <= 0xFF) {
+        packet->code = (uint8_t)code;
+        return 1;
+    } else {
+        return 0;
+    }
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_set_token(void *packet, const uint8_t *token, size_t token_len)
+coap_set_token(coap_packet_t *coap_pkt, const uint8_t *token, size_t token_len)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->token_len = MIN(COAP_TOKEN_LEN, token_len);
-  memcpy(coap_pkt->token, token, coap_pkt->token_len);
+    coap_pkt->token_len = MIN(COAP_TOKEN_LEN, token_len);
+    memcpy(coap_pkt->token, token, coap_pkt->token_len);
 
-  return coap_pkt->token_len;
+    return coap_pkt->token_len;
 }
 #ifdef OC_CLIENT
 int
-coap_get_header_content_format(void *packet, unsigned int *format)
+coap_get_header_content_format(coap_packet_t *coap_pkt, unsigned int *format)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) {
-    return 0;
-  }
-  *format = coap_pkt->content_format;
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT)) {
+        return 0;
+    }
+    *format = coap_pkt->content_format;
+    return 1;
 }
 #endif
 int
-coap_set_header_content_format(void *packet, unsigned int format)
+coap_set_header_content_format(coap_packet_t *coap_pkt, unsigned int format)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->content_format = format;
-  SET_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT);
-  return 1;
+    coap_pkt->content_format = format;
+    SET_OPTION(coap_pkt, COAP_OPTION_CONTENT_FORMAT);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_accept(void *packet, unsigned int *accept)
+int
+coap_get_header_accept(coap_packet_t *coap_pkt, unsigned int *accept)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) {
-    return 0;
-  }
-  *accept = coap_pkt->accept;
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_ACCEPT)) {
+        return 0;
+    }
+    *accept = coap_pkt->accept;
+    return 1;
 }
 #endif
+
 #ifdef OC_CLIENT
 int
-coap_set_header_accept(void *packet, unsigned int accept)
+coap_set_header_accept(coap_packet_t *coap_pkt, unsigned int accept)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->accept = accept;
-  SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
-  return 1;
+    coap_pkt->accept = accept;
+    SET_OPTION(coap_pkt, COAP_OPTION_ACCEPT);
+    return 1;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_max_age(void *packet, uint32_t *age)
+int
+coap_get_header_max_age(coap_packet_t *coap_pkt, uint32_t *age)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_MAX_AGE)) {
-    *age = COAP_DEFAULT_MAX_AGE;
-  } else {
-    *age = coap_pkt->max_age;
-  }
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_MAX_AGE)) {
+        *age = COAP_DEFAULT_MAX_AGE;
+    } else {
+        *age = coap_pkt->max_age;
+    }
+    return 1;
 }
 #endif
 int
-coap_set_header_max_age(void *packet, uint32_t age)
+coap_set_header_max_age(coap_packet_t *coap_pkt, uint32_t age)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->max_age = age;
-  SET_OPTION(coap_pkt, COAP_OPTION_MAX_AGE);
-  return 1;
+    coap_pkt->max_age = age;
+    SET_OPTION(coap_pkt, COAP_OPTION_MAX_AGE);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_etag(void *packet, const uint8_t **etag)
+int
+coap_get_header_etag(coap_packet_t *coap_pkt, const uint8_t **etag)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) {
-    return 0;
-  }
-  *etag = coap_pkt->etag;
-  return coap_pkt->etag_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_ETAG)) {
+        return 0;
+    }
+    *etag = coap_pkt->etag;
+    return coap_pkt->etag_len;
 }
-int coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
 
-  coap_pkt->etag_len = MIN(COAP_ETAG_LEN, etag_len);
-  memcpy(coap_pkt->etag, etag, coap_pkt->etag_len);
+int
+coap_set_header_etag(coap_packet_t *coap_pkt, const uint8_t *etag,
+  size_t etag_len)
+{
+    coap_pkt->etag_len = MIN(COAP_ETAG_LEN, etag_len);
+    memcpy(coap_pkt->etag, etag, coap_pkt->etag_len);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_ETAG);
-  return coap_pkt->etag_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_ETAG);
+    return coap_pkt->etag_len;
 }
 /*---------------------------------------------------------------------------*/
 /*FIXME support multiple ETags */
-int coap_get_header_if_match(void *packet, const uint8_t **etag)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
 
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) {
-    return 0;
-  }
-  *etag = coap_pkt->if_match;
-  return coap_pkt->if_match_len;
-}
-int coap_set_header_if_match(void *packet, const uint8_t *etag, size_t etag_len)
+int
+coap_get_header_if_match(coap_packet_t *coap_pkt, const uint8_t **etag)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_IF_MATCH)) {
+        return 0;
+    }
+    *etag = coap_pkt->if_match;
+    return coap_pkt->if_match_len;
+}
 
-  coap_pkt->if_match_len = MIN(COAP_ETAG_LEN, etag_len);
-  memcpy(coap_pkt->if_match, etag, coap_pkt->if_match_len);
+int
+coap_set_header_if_match(coap_packet_t *coap_pkt, const uint8_t *etag,
+  size_t etag_len)
+{
+    coap_pkt->if_match_len = MIN(COAP_ETAG_LEN, etag_len);
+    memcpy(coap_pkt->if_match, etag, coap_pkt->if_match_len);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_IF_MATCH);
-  return coap_pkt->if_match_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_IF_MATCH);
+    return coap_pkt->if_match_len;
 }
+
 /*---------------------------------------------------------------------------*/
-int coap_get_header_if_none_match(void *packet)
+int
+coap_get_header_if_none_match(coap_packet_t *coap_pkt)
 {
-  return IS_OPTION((coap_packet_t *)packet,
-		   COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
+    return IS_OPTION(coap_pkt, COAP_OPTION_IF_NONE_MATCH) ? 1 : 0;
 }
-int coap_set_header_if_none_match(void *packet)
+
+int
+coap_set_header_if_none_match(coap_packet_t *coap_pkt)
 {
-  SET_OPTION((coap_packet_t * )packet, COAP_OPTION_IF_NONE_MATCH);
-  return 1;
+    SET_OPTION(coap_pkt, COAP_OPTION_IF_NONE_MATCH);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
-int coap_get_header_proxy_uri(void *packet, const char **uri)
+int
+coap_get_header_proxy_uri(coap_packet_t *coap_pkt, const char **uri)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) {
-    return 0;
-  }
-  *uri = coap_pkt->proxy_uri;
-  return coap_pkt->proxy_uri_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_PROXY_URI)) {
+        return 0;
+    }
+    *uri = coap_pkt->proxy_uri;
+    return coap_pkt->proxy_uri_len;
 }
-int coap_set_header_proxy_uri(void *packet, const char *uri)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
 
-  /*TODO Provide alternative that sets Proxy-Scheme and Uri-* options and provide er-coap-conf define */
+int
+coap_set_header_proxy_uri(coap_packet_t *coap_pkt, const char *uri)
+{
+    /*TODO Provide alternative that sets Proxy-Scheme and Uri-* options and provide er-coap-conf define */
 
-  coap_pkt->proxy_uri = uri;
-  coap_pkt->proxy_uri_len = strlen(uri);
+    coap_pkt->proxy_uri = uri;
+    coap_pkt->proxy_uri_len = strlen(uri);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_PROXY_URI);
-  return coap_pkt->proxy_uri_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_PROXY_URI);
+    return coap_pkt->proxy_uri_len;
 }
 /*---------------------------------------------------------------------------*/
-int coap_get_header_uri_host(void *packet, const char **host)
+int
+coap_get_header_uri_host(coap_packet_t *coap_pkt, const char **host)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) {
-    return 0;
-  }
-  *host = coap_pkt->uri_host;
-  return coap_pkt->uri_host_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_HOST)) {
+        return 0;
+    }
+    *host = coap_pkt->uri_host;
+    return coap_pkt->uri_host_len;
 }
-int coap_set_header_uri_host(void *packet, const char *host)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
 
-  coap_pkt->uri_host = host;
-  coap_pkt->uri_host_len = strlen(host);
+int
+coap_set_header_uri_host(coap_packet_t *coap_pkt, const char *host)
+{
+    coap_pkt->uri_host = host;
+    coap_pkt->uri_host_len = strlen(host);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_URI_HOST);
-  return coap_pkt->uri_host_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_URI_HOST);
+    return coap_pkt->uri_host_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_uri_path(void *packet, const char **path)
+coap_get_header_uri_path(coap_packet_t *coap_pkt, const char **path)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) {
-    return 0;
-  }
-  *path = coap_pkt->uri_path;
-  return coap_pkt->uri_path_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_PATH)) {
+        return 0;
+    }
+    *path = coap_pkt->uri_path;
+    return coap_pkt->uri_path_len;
 }
 #ifdef OC_CLIENT
 int
-coap_set_header_uri_path(void *packet, const char *path)
+coap_set_header_uri_path(coap_packet_t *coap_pkt, const char *path)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  while (path[0] == '/')
-    ++path;
-
-  coap_pkt->uri_path = path;
-  coap_pkt->uri_path_len = strlen(path);
+    while (path[0] == '/') {
+        ++path;
+    }
+    coap_pkt->uri_path = path;
+    coap_pkt->uri_path_len = strlen(path);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_URI_PATH);
-  return coap_pkt->uri_path_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_URI_PATH);
+    return coap_pkt->uri_path_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_uri_query(void *packet, const char **query)
+coap_get_header_uri_query(coap_packet_t *coap_pkt, const char **query)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
-    return 0;
-  }
-  *query = coap_pkt->uri_query;
-  return coap_pkt->uri_query_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_URI_QUERY)) {
+        return 0;
+    }
+    *query = coap_pkt->uri_query;
+    return coap_pkt->uri_query_len;
 }
 #ifdef OC_CLIENT
 int
-coap_set_header_uri_query(void *packet, const char *query)
+coap_set_header_uri_query(coap_packet_t *coap_pkt, const char *query)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  while (query[0] == '?')
-    ++query;
-
-  coap_pkt->uri_query = query;
-  coap_pkt->uri_query_len = strlen(query);
+    while (query[0] == '?') {
+        ++query;
+    }
+    coap_pkt->uri_query = query;
+    coap_pkt->uri_query_len = strlen(query);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_URI_QUERY);
-  return coap_pkt->uri_query_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_URI_QUERY);
+    return coap_pkt->uri_query_len;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_location_path(void *packet, const char **path)
+int
+coap_get_header_location_path(coap_packet_t *coap_pkt, const char **path)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) {
-    return 0;
-  }
-  *path = coap_pkt->location_path;
-  return coap_pkt->location_path_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH)) {
+        return 0;
+    }
+    *path = coap_pkt->location_path;
+    return coap_pkt->location_path_len;
 }
-int coap_set_header_location_path(void *packet, const char *path)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  char *query;
 
-  while(path[0] == '/')
-    ++path;
+int
+coap_set_header_location_path(coap_packet_t *coap_pkt, const char *path)
+{
+    char *query;
 
-  if((query = strchr(path, '?'))) {
-    coap_set_header_location_query(packet, query + 1);
-    coap_pkt->location_path_len = query - path;
-  } else {
-    coap_pkt->location_path_len = strlen(path);
-  }
-  coap_pkt->location_path = path;
+    while(path[0] == '/') {
+        ++path;
+    }
+    if ((query = strchr(path, '?'))) {
+        coap_set_header_location_query(packet, query + 1);
+        coap_pkt->location_path_len = query - path;
+    } else {
+        coap_pkt->location_path_len = strlen(path);
+    }
+    coap_pkt->location_path = path;
 
-  if(coap_pkt->location_path_len > 0) {
-    SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH);
-  }
-  return coap_pkt->location_path_len;
+    if (coap_pkt->location_path_len > 0) {
+        SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_PATH);
+    }
+    return coap_pkt->location_path_len;
 }
 /*---------------------------------------------------------------------------*/
-int coap_get_header_location_query(void *packet, const char **query)
+int
+coap_get_header_location_query(coap_packet_t *coap_pkt, const char **query)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) {
-    return 0;
-  }
-  *query = coap_pkt->location_query;
-  return coap_pkt->location_query_len;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY)) {
+        return 0;
+    }
+    *query = coap_pkt->location_query;
+    return coap_pkt->location_query_len;
 }
 #endif
 int
-coap_set_header_location_query(void *packet, const char *query)
+coap_set_header_location_query(coap_packet_t *coap_pkt, const char *query)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  while (query[0] == '?')
-    ++query;
-
-  coap_pkt->location_query = query;
-  coap_pkt->location_query_len = strlen(query);
+    while (query[0] == '?') {
+        ++query;
+    }
+    coap_pkt->location_query = query;
+    coap_pkt->location_query_len = strlen(query);
 
-  SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY);
-  return coap_pkt->location_query_len;
+    SET_OPTION(coap_pkt, COAP_OPTION_LOCATION_QUERY);
+    return coap_pkt->location_query_len;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_observe(void *packet, uint32_t *observe)
+coap_get_header_observe(coap_packet_t *coap_pkt, uint32_t *observe)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) {
-    return 0;
-  }
-  *observe = coap_pkt->observe;
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_OBSERVE)) {
+        return 0;
+    }
+    *observe = coap_pkt->observe;
+    return 1;
 }
+
 int
-coap_set_header_observe(void *packet, uint32_t observe)
+coap_set_header_observe(coap_packet_t *coap_pkt, uint32_t observe)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->observe = observe;
-  SET_OPTION(coap_pkt, COAP_OPTION_OBSERVE);
-  return 1;
+    coap_pkt->observe = observe;
+    SET_OPTION(coap_pkt, COAP_OPTION_OBSERVE);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_block2(void *packet, uint32_t *num, uint8_t *more,
-                       uint16_t *size, uint32_t *offset)
+coap_get_header_block2(coap_packet_t *coap_pkt, uint32_t *num,
+                       uint8_t *more, uint16_t *size, uint32_t *offset)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) {
-    return 0;
-  }
-  /* pointers may be NULL to get only specific block parameters */
-  if (num != NULL) {
-    *num = coap_pkt->block2_num;
-  }
-  if (more != NULL) {
-    *more = coap_pkt->block2_more;
-  }
-  if (size != NULL) {
-    *size = coap_pkt->block2_size;
-  }
-  if (offset != NULL) {
-    *offset = coap_pkt->block2_offset;
-  }
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK2)) {
+        return 0;
+    }
+    /* pointers may be NULL to get only specific block parameters */
+    if (num != NULL) {
+        *num = coap_pkt->block2_num;
+    }
+    if (more != NULL) {
+        *more = coap_pkt->block2_more;
+    }
+    if (size != NULL) {
+        *size = coap_pkt->block2_size;
+    }
+    if (offset != NULL) {
+        *offset = coap_pkt->block2_offset;
+    }
+    return 1;
 }
+
 int
-coap_set_header_block2(void *packet, uint32_t num, uint8_t more, uint16_t size)
+coap_set_header_block2(coap_packet_t *coap_pkt, uint32_t num,
+                       uint8_t more, uint16_t size)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (size < 16) {
-    return 0;
-  }
-  if (size > 2048) {
-    return 0;
-  }
-  if (num > 0x0FFFFF) {
-    return 0;
-  }
-  coap_pkt->block2_num = num;
-  coap_pkt->block2_more = more ? 1 : 0;
-  coap_pkt->block2_size = size;
+    if (size < 16) {
+        return 0;
+    }
+    if (size > 2048) {
+        return 0;
+    }
+    if (num > 0x0FFFFF) {
+        return 0;
+    }
+    coap_pkt->block2_num = num;
+    coap_pkt->block2_more = more ? 1 : 0;
+    coap_pkt->block2_size = size;
 
-  SET_OPTION(coap_pkt, COAP_OPTION_BLOCK2);
-  return 1;
+    SET_OPTION(coap_pkt, COAP_OPTION_BLOCK2);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
 int
-coap_get_header_block1(void *packet, uint32_t *num, uint8_t *more,
+coap_get_header_block1(coap_packet_t *coap_pkt, uint32_t *num, uint8_t *more,
                        uint16_t *size, uint32_t *offset)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) {
-    return 0;
-  }
-  /* pointers may be NULL to get only specific block parameters */
-  if (num != NULL) {
-    *num = coap_pkt->block1_num;
-  }
-  if (more != NULL) {
-    *more = coap_pkt->block1_more;
-  }
-  if (size != NULL) {
-    *size = coap_pkt->block1_size;
-  }
-  if (offset != NULL) {
-    *offset = coap_pkt->block1_offset;
-  }
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_BLOCK1)) {
+        return 0;
+    }
+    /* pointers may be NULL to get only specific block parameters */
+    if (num != NULL) {
+        *num = coap_pkt->block1_num;
+    }
+    if (more != NULL) {
+        *more = coap_pkt->block1_more;
+    }
+    if (size != NULL) {
+        *size = coap_pkt->block1_size;
+    }
+    if (offset != NULL) {
+        *offset = coap_pkt->block1_offset;
+    }
+    return 1;
 }
+
 int
-coap_set_header_block1(void *packet, uint32_t num, uint8_t more, uint16_t size)
+coap_set_header_block1(coap_packet_t *coap_pkt, uint32_t num, uint8_t more,
+                       uint16_t size)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (size < 16) {
-    return 0;
-  }
-  if (size > 2048) {
-    return 0;
-  }
-  if (num > 0x0FFFFF) {
-    return 0;
-  }
-  coap_pkt->block1_num = num;
-  coap_pkt->block1_more = more;
-  coap_pkt->block1_size = size;
+    if (size < 16) {
+        return 0;
+    }
+    if (size > 2048) {
+        return 0;
+    }
+    if (num > 0x0FFFFF) {
+        return 0;
+    }
+    coap_pkt->block1_num = num;
+    coap_pkt->block1_more = more;
+    coap_pkt->block1_size = size;
 
-  SET_OPTION(coap_pkt, COAP_OPTION_BLOCK1);
-  return 1;
+    SET_OPTION(coap_pkt, COAP_OPTION_BLOCK1);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
 #if 0
-int coap_get_header_size2(void *packet, uint32_t *size)
+int coap_get_header_size2(coap_packet_t * const coap_pkt, uint32_t *size)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) {
-    return 0;
-  }
-  *size = coap_pkt->size2;
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_SIZE2)) {
+        return 0;
+    }
+    *size = coap_pkt->size2;
+    return 1;
 }
-int coap_set_header_size2(void *packet, uint32_t size)
-{
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
 
-  coap_pkt->size2 = size;
-  SET_OPTION(coap_pkt, COAP_OPTION_SIZE2);
-  return 1;
+int
+coap_set_header_size2(coap_packet_t *coap_pkt, uint32_t size)
+{
+    coap_pkt->size2 = size;
+    SET_OPTION(coap_pkt, COAP_OPTION_SIZE2);
+    return 1;
 }
 /*---------------------------------------------------------------------------*/
-int coap_get_header_size1(void *packet, uint32_t *size)
+int
+coap_get_header_size1(coap_packet_t *coap_pkt, uint32_t *size)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  if(!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) {
-    return 0;
-  }
-  *size = coap_pkt->size1;
-  return 1;
+    if (!IS_OPTION(coap_pkt, COAP_OPTION_SIZE1)) {
+        return 0;
+    }
+    *size = coap_pkt->size1;
+    return 1;
 }
-int coap_set_header_size1(void *packet, uint32_t size)
+int
+coap_set_header_size1(coap_packet_t *coap_pkt, uint32_t size)
 {
-  coap_packet_t * const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->size1 = size;
-  SET_OPTION(coap_pkt, COAP_OPTION_SIZE1);
-  return 1;
+    coap_pkt->size1 = size;
+    SET_OPTION(coap_pkt, COAP_OPTION_SIZE1);
+    return 1;
 }
 #endif
 /*---------------------------------------------------------------------------*/
 int
-coap_get_payload(void *packet, const uint8_t **payload)
+coap_get_payload(coap_packet_t *coap_pkt, const uint8_t **payload)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  if (coap_pkt->payload) {
-    *payload = coap_pkt->payload;
-    return coap_pkt->payload_len;
-  } else {
-    *payload = NULL;
-    return 0;
-  }
+    if (coap_pkt->payload) {
+        *payload = coap_pkt->payload;
+        return coap_pkt->payload_len;
+    } else {
+        *payload = NULL;
+        return 0;
+    }
 }
 int
-coap_set_payload(void *packet, const void *payload, size_t length)
+coap_set_payload(coap_packet_t *coap_pkt, const void *payload, size_t length)
 {
-  coap_packet_t *const coap_pkt = (coap_packet_t *)packet;
-
-  coap_pkt->payload = (uint8_t *)payload;
-  coap_pkt->payload_len = MIN(MAX_PAYLOAD_SIZE, length);
+    coap_pkt->payload = (uint8_t *)payload;
+    coap_pkt->payload_len = MIN(MAX_PAYLOAD_SIZE, length);
 
-  return coap_pkt->payload_len;
+    return coap_pkt->payload_len;
 }
 /*---------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d2321dab/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 9834d31..672320d 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -34,11 +34,12 @@
 #ifndef COAP_H
 #define COAP_H
 
-#include "conf.h"
-#include "constants.h"
 #include <stddef.h> /* for size_t */
 #include <stdint.h>
 
+#include "conf.h"
+#include "constants.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -95,8 +96,7 @@ enum
   ((packet)->options[opt / OPTION_MAP_SIZE] & (1 << (opt % OPTION_MAP_SIZE)))
 
 /* parsed message struct */
-typedef struct
-{
+typedef struct coap_packet {
   uint8_t *buffer; /* pointer to CoAP header / incoming packet buffer / memory
                       to serialize packet */
 
@@ -201,102 +201,96 @@ extern char *coap_error_message;
 void coap_init_connection(void);
 uint16_t coap_get_mid(void);
 
-void coap_init_message(void *packet, coap_message_type_t type, uint8_t code,
-                       uint16_t mid);
-size_t coap_serialize_message(void *packet, uint8_t *buffer);
+void coap_init_message(coap_packet_t *, coap_message_type_t type,
+                       uint8_t code, uint16_t mid);
+size_t coap_serialize_message(coap_packet_t *, uint8_t *buffer);
 void coap_send_message(oc_message_t *message);
-coap_status_t coap_parse_message(void *request, uint8_t *data,
+coap_status_t coap_parse_message(coap_packet_t *request, uint8_t *data,
                                  uint16_t data_len);
 
-int coap_get_query_variable(void *packet, const char *name,
+int coap_get_query_variable(coap_packet_t *, const char *name,
                             const char **output);
-int coap_get_post_variable(void *packet, const char *name, const char **output);
+int coap_get_post_variable(coap_packet_t *, const char *name,
+                           const char **output);
 
 /*---------------------------------------------------------------------------*/
 
-int coap_set_status_code(void *packet, unsigned int code);
+int coap_set_status_code(coap_packet_t *, unsigned int code);
 
-int coap_set_token(void *packet, const uint8_t *token, size_t token_len);
+int coap_set_token(coap_packet_t *, const uint8_t *token, size_t token_len);
 
-int coap_get_header_content_format(void *packet, unsigned int *format);
-int coap_set_header_content_format(void *packet, unsigned int format);
+int coap_get_header_content_format(coap_packet_t *, unsigned int *format);
+int coap_set_header_content_format(coap_packet_t *, unsigned int format);
 
-int coap_get_header_accept(void *packet, unsigned int *accept);
-int coap_set_header_accept(void *packet, unsigned int accept);
+int coap_get_header_accept(coap_packet_t *, unsigned int *accept);
+int coap_set_header_accept(coap_packet_t *, unsigned int accept);
 
-int coap_get_header_max_age(void *packet, uint32_t *age);
-int coap_set_header_max_age(void *packet, uint32_t age);
+int coap_get_header_max_age(coap_packet_t *, uint32_t *age);
+int coap_set_header_max_age(coap_packet_t *, uint32_t age);
 
-int coap_get_header_etag(void *packet, const uint8_t **etag);
-int coap_set_header_etag(void *packet, const uint8_t *etag, size_t etag_len);
+int coap_get_header_etag(coap_packet_t *, const uint8_t **etag);
+int coap_set_header_etag(coap_packet_t *, const uint8_t *etag, size_t etag_len);
 
-int coap_get_header_if_match(void *packet, const uint8_t **etag);
-int coap_set_header_if_match(void *packet, const uint8_t *etag,
+int coap_get_header_if_match(coap_packet_t *, const uint8_t **etag);
+int coap_set_header_if_match(coap_packet_t *, const uint8_t *etag,
                              size_t etag_len);
 
-int coap_get_header_if_none_match(void *packet);
-int coap_set_header_if_none_match(void *packet);
+int coap_get_header_if_none_match(coap_packet_t *);
+int coap_set_header_if_none_match(coap_packet_t *);
 
-int coap_get_header_proxy_uri(
-  void *packet,
+int coap_get_header_proxy_uri(coap_packet_t *,
   const char **uri); /* in-place string might not be 0-terminated. */
-int coap_set_header_proxy_uri(void *packet, const char *uri);
+int coap_set_header_proxy_uri(coap_packet_t *, const char *uri);
 
-int coap_get_header_proxy_scheme(
-  void *packet,
+int coap_get_header_proxy_scheme(coap_packet_t *,
   const char **scheme); /* in-place string might not be 0-terminated. */
-int coap_set_header_proxy_scheme(void *packet, const char *scheme);
+int coap_set_header_proxy_scheme(coap_packet_t *, const char *scheme);
 
-int coap_get_header_uri_host(
-  void *packet,
+int coap_get_header_uri_host(coap_packet_t *,
   const char **host); /* in-place string might not be 0-terminated. */
-int coap_set_header_uri_host(void *packet, const char *host);
+int coap_set_header_uri_host(coap_packet_t *, const char *host);
 
-int coap_get_header_uri_path(
-  void *packet,
+int coap_get_header_uri_path(coap_packet_t *,
   const char **path); /* in-place string might not be 0-terminated. */
-int coap_set_header_uri_path(void *packet, const char *path);
+int coap_set_header_uri_path(coap_packet_t *, const char *path);
 
-int coap_get_header_uri_query(
-  void *packet,
+int coap_get_header_uri_query(coap_packet_t *,
   const char **query); /* in-place string might not be 0-terminated. */
-int coap_set_header_uri_query(void *packet, const char *query);
+int coap_set_header_uri_query(coap_packet_t *, const char *query);
 
-int coap_get_header_location_path(
-  void *packet,
+int coap_get_header_location_path(coap_packet_t *,
   const char **path); /* in-place string might not be 0-terminated. */
-int coap_set_header_location_path(void *packet,
+int coap_set_header_location_path(coap_packet_t *,
                                   const char *path); /* also splits optional
                                                         query into
                                                         Location-Query option.
                                                         */
 
-int coap_get_header_location_query(
-  void *packet,
+int coap_get_header_location_query(coap_packet_t *,
   const char **query); /* in-place string might not be 0-terminated. */
-int coap_set_header_location_query(void *packet, const char *query);
+int coap_set_header_location_query(coap_packet_t *, const char *query);
 
-int coap_get_header_observe(void *packet, uint32_t *observe);
-int coap_set_header_observe(void *packet, uint32_t observe);
+int coap_get_header_observe(coap_packet_t *, uint32_t *observe);
+int coap_set_header_observe(coap_packet_t *, uint32_t observe);
 
-int coap_get_header_block2(void *packet, uint32_t *num, uint8_t *more,
+int coap_get_header_block2(coap_packet_t *, uint32_t *num, uint8_t *more,
                            uint16_t *size, uint32_t *offset);
-int coap_set_header_block2(void *packet, uint32_t num, uint8_t more,
+int coap_set_header_block2(coap_packet_t *, uint32_t num, uint8_t more,
                            uint16_t size);
 
-int coap_get_header_block1(void *packet, uint32_t *num, uint8_t *more,
+int coap_get_header_block1(coap_packet_t *, uint32_t *num, uint8_t *more,
                            uint16_t *size, uint32_t *offset);
-int coap_set_header_block1(void *packet, uint32_t num, uint8_t more,
+int coap_set_header_block1(coap_packet_t *, uint32_t num, uint8_t more,
                            uint16_t size);
 
-int coap_get_header_size2(void *packet, uint32_t *size);
-int coap_set_header_size2(void *packet, uint32_t size);
+int coap_get_header_size2(coap_packet_t *, uint32_t *size);
+int coap_set_header_size2(coap_packet_t *, uint32_t size);
 
-int coap_get_header_size1(void *packet, uint32_t *size);
-int coap_set_header_size1(void *packet, uint32_t size);
+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(void *packet, const uint8_t **payload);
-int coap_set_payload(void *packet, const void *payload, size_t length);
+int coap_get_payload(coap_packet_t *, const uint8_t **payload);
+int coap_set_payload(coap_packet_t *, const void *payload, size_t length);
 
 #ifdef __cplusplus
 }


[05/16] incubator-mynewt-core git commit: oic; change to use os_mbufs from oc_buffer_tx to transport.

Posted by ma...@apache.org.
oic; change to use os_mbufs from oc_buffer_tx to transport.


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/4487aa69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4487aa69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4487aa69

Branch: refs/heads/develop
Commit: 4487aa69f4f1bfe98c9b79e753a68328226bc9d0
Parents: ae88843
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 28 10:40:15 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:23 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_buffer.c              | 43 ++++++++++----
 net/oic/src/port/mynewt/adaptor.c        | 59 ++++++++++--------
 net/oic/src/port/mynewt/adaptor.h        |  9 ++-
 net/oic/src/port/mynewt/ble_adaptor.c    | 30 ++--------
 net/oic/src/port/mynewt/ip_adaptor.c     | 86 ++++++++++++++++-----------
 net/oic/src/port/mynewt/serial_adaptor.c | 36 ++---------
 net/oic/src/port/oc_connectivity.h       |  6 +-
 7 files changed, 136 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index b92ac8f..6a38301 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -113,35 +113,58 @@ oc_send_message(oc_message_t *message)
 }
 
 static void
-oc_buffer_tx(struct oc_message *message)
+oc_buffer_tx(struct oc_message *msg)
 {
+    struct os_mbuf *m;
+    struct oc_endpoint *oe;
+    int rc;
+
+    /* get a packet header */
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
+        ERROR("oc_buffer_tx: failed to alloc mbuf\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    /* add this data to the mbuf */
+    rc = os_mbuf_append(m, msg->data, msg->length);
+    if (rc != 0) {
+        ERROR("oc_buffer_tx: could not append data\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    oe = OC_MBUF_ENDPOINT(m);
+    memcpy(oe, &msg->endpoint, sizeof(msg->endpoint));
+
+    oc_message_unref(msg);
+
 #ifdef OC_CLIENT
-    if (message->endpoint.flags & MULTICAST) {
+    if (oe->flags & MULTICAST) {
         LOG("Outbound network event: multicast request\n");
-        oc_send_multicast_message(message);
-        oc_message_unref(message);
+        oc_send_multicast_message(m);
     } else {
 #endif
 #ifdef OC_SECURITY
         /* XXX convert this */
-        if (message->endpoint.flags & SECURED) {
+        if (oe->flags & SECURED) {
             LOG("Outbound network event: forwarding to DTLS\n");
 
-            if (!oc_sec_dtls_connected(&message->endpoint)) {
+            if (!oc_sec_dtls_connected(oe)) {
                 LOG("Posting INIT_DTLS_CONN_EVENT\n");
                 oc_process_post(&oc_dtls_handler,
-                  oc_events[INIT_DTLS_CONN_EVENT], msg);
+                  oc_events[INIT_DTLS_CONN_EVENT], m);
             } else {
                 LOG("Posting RI_TO_DTLS_EVENT\n");
                 oc_process_post(&oc_dtls_handler,
-                  oc_events[RI_TO_DTLS_EVENT], msg);
+                  oc_events[RI_TO_DTLS_EVENT], m);
             }
         } else
 #endif
         {
             LOG("Outbound network event: unicast message\n");
-            oc_send_buffer(message);
-            oc_message_unref(message);
+            oc_send_buffer(m);
         }
 #ifdef OC_CLIENT
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index 40785c2..cdd31f5 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -68,54 +68,65 @@ oc_network_event_handler_mutex_unlock(void)
 }
 
 void
-oc_send_buffer(oc_message_t *message)
+oc_send_buffer(struct os_mbuf *m)
 {
-    switch (message->endpoint.flags) {
+    struct oc_endpoint *oe;
+
+    oe = OC_MBUF_ENDPOINT(m);
+
+    switch (oe->flags) {
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
     case IP:
-        oc_send_buffer_ip(message);
+        oc_send_buffer_ip(m);
         break;
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     case GATT:
-        oc_send_buffer_gatt(message);
+        oc_send_buffer_gatt(m);
         break;
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
     case SERIAL:
-        oc_send_buffer_serial(message);
+        oc_send_buffer_serial(m);
         break;
 #endif
     default:
-        ERROR("Unknown transport option %u\n", message->endpoint.flags);
-        oc_message_unref(message);
+        ERROR("Unknown transport option %u\n", oe->flags);
+        os_mbuf_free_chain(m);
     }
 }
 
-void oc_send_multicast_message(oc_message_t *message)
+void
+oc_send_multicast_message(struct os_mbuf *m)
 {
-    oc_message_add_ref(message);
-
-    /* send on all the transports.  Don't forget to reference the message
-     * so it doesn't get deleted  */
-
+    /*
+     * Send on all the transports.
+     */
+    void (*funcs[])(struct os_mbuf *) = {
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-    oc_send_buffer_ip_mcast(message);
+        oc_send_buffer_ip_mcast,
 #endif
-
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
-    /* no multicast for GATT, just send unicast */
-    oc_message_add_ref(message);
-    oc_send_buffer_gatt(message);
+        /* no multicast for GATT, just send unicast */
+        oc_send_buffer_gatt,
 #endif
-
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
-    /* no multi-cast for serial.  just send unicast */
-    oc_message_add_ref(message);
-    oc_send_buffer_serial(message);
+        /* no multi-cast for serial.  just send unicast */
+        oc_send_buffer_serial,
 #endif
-
-    oc_message_unref(message);
+    };
+    struct os_mbuf *n;
+    int i;
+
+    for (i = 0; i < (sizeof(funcs) / sizeof(funcs[0])) - 1; i++) {
+        n = os_mbuf_dup(m);
+        funcs[i](m);
+        if (!n) {
+            return;
+        }
+        m = n;
+    }
+    funcs[(sizeof(funcs) / sizeof(funcs[0])) - 1](m);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index c6ea8bb..025efd6 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -32,21 +32,20 @@ struct oc_message;
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
-void oc_send_buffer_ip(struct oc_message *message);
-void oc_send_buffer_ip_mcast(struct oc_message *message);
+void oc_send_buffer_ip(struct os_mbuf *);
+void oc_send_buffer_ip_mcast(struct os_mbuf *);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
 int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
-void oc_send_buffer_gatt(struct oc_message *message);
-void oc_send_buffer_gatt_mcast(struct oc_message *message);
+void oc_send_buffer_gatt(struct os_mbuf *);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
-void oc_send_buffer_serial(struct oc_message *message);
+void oc_send_buffer_serial(struct os_mbuf *);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 0c3363f..81f2d2c 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -208,41 +208,19 @@ oc_connectivity_shutdown_gatt(void)
 }
 
 void
-oc_send_buffer_gatt(oc_message_t *message)
+oc_send_buffer_gatt(struct os_mbuf *m)
 {
-    struct os_mbuf *m = NULL;
-    int rc;
-
-    /* get a packet header */
-    m = os_msys_get_pkthdr(0, 0);
-    if (m == NULL) {
-        ERROR("oc_transport_gatt: No mbuf available\n");
-        goto err;
-    }
+    struct oc_endpoint *oe;
 
-    /* add this data to the mbuf */
-    rc = os_mbuf_append(m, message->data, message->length);
-    if (rc != 0) {
-        ERROR("oc_transport_gatt: could not append data \n");
-        goto err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
 
 #if (MYNEWT_VAL(OC_CLIENT) == 1)
     ERROR("send not supported on client");
 #endif
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    ble_gattc_notify_custom(message->endpoint.bt_addr.conn_handle,
-                            g_ble_coap_attr_handle, m);
-    m = NULL;
+    ble_gattc_notify_custom(oe->bt_addr.conn_handle, g_ble_coap_attr_handle, m);
 #endif
-
-err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-    oc_message_unref(message);
-    return;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 181bc68..90edd42 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -35,7 +35,7 @@
 
 static void oc_event_ip(struct os_event *ev);
 
-struct os_event oc_sock_read_event = {
+static struct os_event oc_sock_read_event = {
     .ev_cb = oc_event_ip,
 };
 
@@ -46,45 +46,43 @@ struct os_event oc_sock_read_event = {
 
 #define COAP_PORT_UNSECURED (5683)
 /* TODO use inet_pton when its available */
-const struct mn_in6_addr coap_all_nodes_v6 = {
+static const struct mn_in6_addr coap_all_nodes_v6 = {
     .s_addr = {0xFF,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFD}
 };
 
 
 /* sockets to use for coap unicast and multicast */
-struct mn_socket *ucast;
+static struct mn_socket *ucast;
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-struct mn_socket *mcast;
+static struct mn_socket *mcast;
 #endif
 
 static void
-oc_send_buffer_ip_int(oc_message_t *message, int mcast)
+oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
 {
     struct mn_sockaddr_in6 to;
-    struct os_mbuf m;
+    struct oc_endpoint *oe;
+    struct mn_itf itf;
+    struct mn_itf itf2;
+    struct os_mbuf *n;
     int rc;
 
-    LOG("oc_transport_ip attempt send buffer %lu\n",
-        (unsigned long)message->length);
+    LOG("oc_transport_ip attempt send buffer %u\n",
+      OS_MBUF_PKTHDR(m)->omp_len);
+
+    oe = OC_MBUF_ENDPOINT(m);
 
     to.msin6_len = sizeof(to);
     to.msin6_family = MN_AF_INET6;
+    to.msin6_port = htons(oe->ipv6_addr.port);
+    to.msin6_scope_id = oe->ipv6_addr.scope;
+    memcpy(&to.msin6_addr, oe->ipv6_addr.address, sizeof(to.msin6_addr));
 
-    to.msin6_port = htons(message->endpoint.ipv6_addr.port);
-    memcpy(&to.msin6_addr, message->endpoint.ipv6_addr.address,
-           sizeof(to.msin6_addr));
-
-    /* put on an mbuf header to make the socket happy */
-    memset(&m, 0, sizeof(m));
-    m.om_data = message->data;
-    m.om_len = message->length;
-    to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
-
-    if (mcast) {
-        struct mn_itf itf;
+    if (is_mcast) {
         memset(&itf, 0, sizeof(itf));
+        memset(&itf2, 0, sizeof(itf2));
 
         while (1) {
             rc = mn_itf_getnext(&itf);
@@ -96,37 +94,57 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
                 continue;
             }
 
-            to.msin6_scope_id = itf.mif_idx;
-
-            rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+            if (!itf2.mif_idx) {
+                memcpy(&itf2, &itf, sizeof(itf));
+                continue;
+            }
+            n = os_mbuf_dup(m);
+            if (!n) {
+                break;
+            }
+            to.msin6_scope_id = itf2.mif_idx;
+            rc = mn_sendto(ucast, n, (struct mn_sockaddr *) &to);
             if (rc != 0) {
-                ERROR("Failed sending buffer %lu on itf %d\n",
-                      (unsigned long)message->length, to.msin6_scope_id);
+                ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                os_mbuf_free_chain(n);
+            }
+        }
+        if (itf2.mif_idx) {
+            to.msin6_scope_id = itf2.mif_idx;
+            rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
+            if (rc != 0) {
+                ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+                os_mbuf_free_chain(m);
             }
         }
     } else {
-        rc = mn_sendto(ucast, &m, (struct mn_sockaddr *) &to);
+        rc = mn_sendto(ucast, m, (struct mn_sockaddr *) &to);
         if (rc != 0) {
-            ERROR("Failed sending buffer %lu on itf %d\n",
-                  (unsigned long)message->length, to.msin6_scope_id);
+            ERROR("Failed sending buffer %u on itf %d\n",
+                  OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
+            os_mbuf_free_chain(m);
         }
     }
-    oc_message_unref(message);
+    if (rc) {
+        os_mbuf_free_chain(m);
+    }
 }
 
 void
-oc_send_buffer_ip(oc_message_t *message)
+oc_send_buffer_ip(struct os_mbuf *m)
 {
-    oc_send_buffer_ip_int(message, 0);
+    oc_send_buffer_ip_int(m, 0);
 }
 void
-oc_send_buffer_ip_mcast(oc_message_t *message)
+oc_send_buffer_ip_mcast(struct os_mbuf *m)
 {
-    oc_send_buffer_ip_int(message, 1);
+    oc_send_buffer_ip_int(m, 1);
 }
 
 static struct os_mbuf *
-oc_attempt_rx_ip_sock(struct mn_socket * rxsock)
+oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
 {
     int rc;
     struct os_mbuf *m;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index 209a9c7..59342a9 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -58,7 +58,8 @@ oc_event_serial(struct os_event *ev)
 }
 
 int
-oc_connectivity_init_serial(void) {
+oc_connectivity_init_serial(void)
+{
     int rc;
 
     rc = shell_nlip_input_register(oc_serial_in, NULL);
@@ -80,39 +81,14 @@ err:
 
 
 void
-oc_send_buffer_serial(oc_message_t *message)
+oc_send_buffer_serial(struct os_mbuf *m)
 {
-    int rc;
-    struct os_mbuf *m;
-
-    /* get a packet header */
-    m = os_msys_get_pkthdr(0, 0);
-    if (m == NULL) {
-        ERROR("oc_transport_serial: No mbuf available\n");
-        goto err;
-    }
-
-    /* add this data to the mbuf */
-    rc = os_mbuf_append(m, message->data, message->length);
-    if (rc != 0) {
-
-        ERROR("oc_transport_serial: could not append data \n");
-        goto err;
-    }
+    LOG("oc_transport_serial: send buffer %u\n", OS_MBUF_PKTHDR(m)->omp_len);
 
     /* send over the shell output */
-    rc = shell_nlip_output(m);
-    if (rc != 0) {
-        ERROR("oc_transport_serial: nlip output failed \n");
-        goto err;
+    if (shell_nlip_output(m)) {
+        ERROR("oc_transport_serial: nlip output failed\n");
     }
-
-    LOG("oc_transport_serial: send buffer %zu\n", message->length);
-
-err:
-    oc_message_unref(message);
-    return;
-
 }
 
 static struct os_mbuf *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4487aa69/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 493b30e..123db7c 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -66,17 +66,15 @@ typedef struct oc_message {
     uint8_t data[MAX_PAYLOAD_SIZE];
 } oc_message_t;
 
-void oc_send_buffer(oc_message_t *message);
-
 #ifdef OC_SECURITY
 uint16_t oc_connectivity_get_dtls_port(void);
 #endif /* OC_SECURITY */
 
 int oc_connectivity_init(void);
-
 void oc_connectivity_shutdown(void);
 
-void oc_send_multicast_message(oc_message_t *message);
+void oc_send_buffer(struct os_mbuf *);
+void oc_send_multicast_message(struct os_mbuf *);
 
 #ifdef __cplusplus
 }


[14/16] incubator-mynewt-core git commit: oic; change to use os_mbuf from transport to oc_recv_message(). Call oc_recv_message() directly, instead of going through oc_network_events.

Posted by ma...@apache.org.
oic; change to use os_mbuf from transport to oc_recv_message().
Call oc_recv_message() directly, instead of going through oc_network_events.


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/969df792
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/969df792
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/969df792

Branch: refs/heads/develop
Commit: 969df7925f9984bcdf3a01e4dfa1f4201b0d09e5
Parents: 5c7b885
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 23 16:19:41 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:54:51 2016 -0800

----------------------------------------------------------------------
 kernel/os/include/os/os_mbuf.h           |   2 +-
 net/oic/include/oic/oc_buffer.h          |   7 +-
 net/oic/include/oic/oc_network_events.h  |  32 --------
 net/oic/src/api/oc_buffer.c              |  86 ++++++++++++++-------
 net/oic/src/api/oc_network_events.c      |  57 --------------
 net/oic/src/api/oc_ri.c                  |   1 -
 net/oic/src/port/mynewt/adaptor.h        |   3 -
 net/oic/src/port/mynewt/ble_adaptor.c    |  71 +++++++-----------
 net/oic/src/port/mynewt/ip_adaptor.c     | 104 +++++++++++---------------
 net/oic/src/port/mynewt/serial_adaptor.c |  79 +++++++------------
 net/oic/src/port/oc_connectivity.h       |   1 -
 11 files changed, 163 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/kernel/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_mbuf.h b/kernel/os/include/os/os_mbuf.h
index 0b56962..495f4b4 100644
--- a/kernel/os/include/os/os_mbuf.h
+++ b/kernel/os/include/os/os_mbuf.h
@@ -61,7 +61,7 @@ struct os_mbuf_pool {
  */
 struct os_mbuf_pkthdr {
     /**
-     * Overall length of the packet. 
+     * Overall length of the packet.
      */
     uint16_t omp_len;
     /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 7dab610..2d67109 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -21,12 +21,17 @@
 extern "C" {
 #endif
 
+#define OC_MBUF_ENDPOINT(m)                                             \
+    (struct oc_endpoint *)((uint8_t *)m + sizeof(struct os_mbuf) +     \
+                                          sizeof(struct os_mbuf_pkthdr))
+
 struct oc_message;
+struct os_mbuf;
 struct oc_message *oc_allocate_message(void);
 void oc_message_add_ref(struct oc_message *message);
 void oc_message_unref(struct oc_message *message);
 
-void oc_recv_message(struct oc_message *message);
+void oc_recv_message(struct os_mbuf *m);
 void oc_send_message(struct oc_message *message);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
deleted file mode 100644
index f786390..0000000
--- a/net/oic/include/oic/oc_network_events.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-// Copyright (c) 2016 Intel Corporation
-//
-// Licensed 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 OC_NETWORK_EVENTS_H
-#define OC_NETWORK_EVENTS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct oc_message;
-
-void oc_network_event(struct oc_message *message);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_NETWORK_EVENTS_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index bd3bbd1..b92ac8f 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -18,6 +18,7 @@
 
 #include <os/os_eventq.h>
 #include <os/os_mempool.h>
+#include <os/os_mbuf.h>
 
 #include "messaging/coap/engine.h"
 #include "port/oc_signal_main_loop.h"
@@ -37,19 +38,12 @@ static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
 
 static void oc_buffer_handler(struct os_event *);
 
-static struct oc_message *oc_buffer_inq;
+static struct os_mqueue oc_inq;
 static struct oc_message *oc_buffer_outq;
 static struct os_event oc_buffer_ev = {
     .ev_cb = oc_buffer_handler
 };
 
-void
-oc_buffer_init(void)
-{
-    os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
-      sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
-}
-
 oc_message_t *
 oc_allocate_message(void)
 {
@@ -103,10 +97,12 @@ oc_queue_msg(struct oc_message **head, struct oc_message *msg)
 }
 
 void
-oc_recv_message(oc_message_t *message)
+oc_recv_message(struct os_mbuf *m)
 {
-    oc_queue_msg(&oc_buffer_inq, message);
-    os_eventq_put(oc_evq_get(), &oc_buffer_ev);
+    int rc;
+
+    rc = os_mqueue_put(&oc_inq, oc_evq_get(), m);
+    assert(rc == 0);
 }
 
 void
@@ -153,23 +149,52 @@ oc_buffer_tx(struct oc_message *message)
 }
 
 static void
-oc_buffer_rx(struct oc_message *msg)
+oc_buffer_rx(struct os_event *ev)
 {
+    struct oc_message *msg;
+    struct os_mbuf *m;
+#if defined(OC_SECURITY)
+    uint8_t b;
+#endif
+
+    while ((m = os_mqueue_get(&oc_inq)) != NULL) {
+        msg = oc_allocate_message();
+        if (!msg) {
+            ERROR("Could not allocate OC message buffer\n");
+            goto free_msg;
+        }
+        if (OS_MBUF_PKTHDR(m)->omp_len > MAX_PAYLOAD_SIZE) {
+            ERROR("Message to large for OC message buffer\n");
+            goto free_msg;
+        }
+        if (os_mbuf_copydata(m, 0, OS_MBUF_PKTHDR(m)->omp_len, msg->data)) {
+            ERROR("Failed to copy message from mbuf to OC message buffer \n");
+            goto free_msg;
+        }
+        memcpy(&msg->endpoint, OC_MBUF_ENDPOINT(m), sizeof(msg->endpoint));
+        msg->length = OS_MBUF_PKTHDR(m)->omp_len;
+
 #ifdef OC_SECURITY
-    uint8_t b = (uint8_t)(msg->data[0];
-    if (b > 19 && b < 64) {
-        LOG("Inbound network event: encrypted request\n");
-        oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], msg);
-    } else {
+        b = m->om_data[0];
+        if (b > 19 && b < 64) {
+            LOG("Inbound network event: encrypted request\n");
+            oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], m);
+        } else {
+            LOG("Inbound network event: decrypted request\n");
+            coap_receive(msg);
+            oc_message_unref(msg);
+        }
+#else
         LOG("Inbound network event: decrypted request\n");
         coap_receive(msg);
         oc_message_unref(msg);
-    }
-#else
-    LOG("Inbound network event: decrypted request\n");
-    coap_receive(msg);
-    oc_message_unref(msg);
 #endif
+free_msg:
+        os_mbuf_free_chain(m);
+        if (msg) {
+            oc_message_unref(msg);
+        }
+    }
 }
 
 static void
@@ -177,18 +202,21 @@ oc_buffer_handler(struct os_event *ev)
 {
     struct oc_message *msg;
 
-    while (oc_buffer_outq || oc_buffer_inq) {
+    while (oc_buffer_outq) {
         msg = oc_buffer_outq;
         if (msg) {
             oc_buffer_outq = msg->next;
             msg->next = NULL;
             oc_buffer_tx(msg);
         }
-        msg = oc_buffer_inq;
-        if (msg) {
-            oc_buffer_inq = msg->next;
-            msg->next = NULL;
-            oc_buffer_rx(msg);
-        }
     }
 }
+
+void
+oc_buffer_init(void)
+{
+    os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
+      sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
+    os_mqueue_init(&oc_inq, oc_buffer_rx, NULL);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
deleted file mode 100644
index 6f33189..0000000
--- a/net/oic/src/api/oc_network_events.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-// Copyright (c) 2016 Intel Corporation
-//
-// Licensed 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 <os/os_eventq.h>
-
-#include "oc_network_events.h"
-#include "oc_buffer.h"
-#include "port/oc_connectivity.h"
-#include "port/oc_signal_main_loop.h"
-#include "port/oc_network_events_mutex.h"
-#include "port/mynewt/adaptor.h"
-#include "util/oc_list.h"
-
-OC_LIST(network_events);
-static void oc_network_ev_process(struct os_event *ev);
-static struct os_event oc_network_ev = {
-    .ev_cb = oc_network_ev_process
-};
-
-static void
-oc_network_ev_process(struct os_event *ev)
-{
-    struct oc_message *head;
-
-    oc_network_event_handler_mutex_lock();
-    while (1) {
-        head = oc_list_pop(network_events);
-        if (!head) {
-            break;
-        }
-        oc_recv_message(head);
-    }
-    oc_network_event_handler_mutex_unlock();
-}
-
-void
-oc_network_event(oc_message_t *message)
-{
-    oc_network_event_handler_mutex_lock();
-    oc_list_add(network_events, message);
-    oc_network_event_handler_mutex_unlock();
-
-    os_eventq_put(oc_evq_get(), &oc_network_ev);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/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 9219f7b..8221ea5 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -34,7 +34,6 @@
 #include "oc_buffer.h"
 #include "oc_core_res.h"
 #include "oc_discovery.h"
-#include "oc_network_events.h"
 #include "oc_ri.h"
 #include "oc_uuid.h"
 #include "oc_priv.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index a40d2e8..c6ea8bb 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -34,7 +34,6 @@ int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
 void oc_send_buffer_ip(struct oc_message *message);
 void oc_send_buffer_ip_mcast(struct oc_message *message);
-struct oc_message *oc_attempt_rx_ip(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
@@ -42,14 +41,12 @@ int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
 void oc_send_buffer_gatt(struct oc_message *message);
 void oc_send_buffer_gatt_mcast(struct oc_message *message);
-struct oc_message *oc_attempt_rx_gatt(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
 void oc_send_buffer_serial(struct oc_message *message);
-struct oc_message *oc_attempt_rx_serial(void);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 18ff7ad..0c3363f 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -109,75 +109,58 @@ gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
     return 0;
 }
 
-oc_message_t *
+static struct os_mbuf *
 oc_attempt_rx_gatt(void)
 {
     int rc;
-    struct os_mbuf *m = NULL;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
     struct os_mbuf_pkthdr *pkt;
+    struct oc_endpoint *oe;
     uint16_t conn_handle;
-    oc_message_t *message = NULL;
 
     LOG("oc_transport_gatt attempt rx\n");
 
     /* get an mbuf from the queue */
-    m = os_mqueue_get(&ble_coap_mq);
-    if (NULL == m) {
-        ERROR("oc_transport_gatt: Woke for for receive but found no mbufs\n");
-        goto rx_attempt_err;
-    }
-
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        ERROR("oc_transport_gatt: received mbuf that wasn't a packet header\n");
-        goto rx_attempt_err;
+    n = os_mqueue_get(&ble_coap_mq);
+    if (NULL == n) {
+        ERROR("oc_transport_gatt: Woke for receive but found no mbufs\n");
+        return NULL;
     }
 
-    pkt = OS_MBUF_PKTHDR(m);
+    pkt = OS_MBUF_PKTHDR(n);
 
-    LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
     /* get the conn handle from the end of the message */
-    rc = os_mbuf_copydata(m, pkt->omp_len - sizeof(conn_handle),
+    rc = os_mbuf_copydata(n, pkt->omp_len - sizeof(conn_handle),
                           sizeof(conn_handle), &conn_handle);
     if (rc != 0) {
-        ERROR("Failed to retrieve conn_handle from mbuf \n");
+        ERROR("Failed to retrieve conn_handle from mbuf\n");
         goto rx_attempt_err;
     }
 
     /* trim conn_handle from the end */
-    os_mbuf_adj(m, - sizeof(conn_handle));
+    os_mbuf_adj(n, - sizeof(conn_handle));
 
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = pkt->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
+
+    oe->flags = GATT;
+    oe->bt_addr.conn_handle = conn_handle;
+
+    LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
 
-    os_mbuf_free_chain(m);
-    message->endpoint.flags = GATT;
-    message->endpoint.bt_addr.conn_handle = conn_handle;
-    message->length = pkt->omp_len;
-    LOG("Successfully rx length %lu\n", (unsigned long)message->length);
-    return message;
+    return m;
 
     /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-    if (message) {
-        oc_message_unref(message);
-    }
+    os_mbuf_free_chain(n);
     return NULL;
 }
 #endif
@@ -204,10 +187,10 @@ ble_coap_gatt_srv_init(void)
 static void
 oc_event_gatt(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_gatt()) != NULL) {
+        oc_recv_message(m);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 646a5b0..181bc68 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -20,9 +20,11 @@
 #include <syscfg/syscfg.h>
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 #include <assert.h>
+#include <string.h>
+
 #include <os/os.h>
 #include <os/endian.h>
-#include <string.h>
+
 #include <log/log.h>
 #include <mn_socket/mn_socket.h>
 
@@ -75,7 +77,7 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
            sizeof(to.msin6_addr));
 
     /* put on an mbuf header to make the socket happy */
-    memset(&m,0, sizeof(m));
+    memset(&m, 0, sizeof(m));
     m.om_data = message->data;
     m.om_len = message->length;
     to.msin6_scope_id = message->endpoint.ipv6_addr.scope;
@@ -113,91 +115,73 @@ oc_send_buffer_ip_int(oc_message_t *message, int mcast)
 }
 
 void
-oc_send_buffer_ip(oc_message_t *message) {
+oc_send_buffer_ip(oc_message_t *message)
+{
     oc_send_buffer_ip_int(message, 0);
 }
 void
-oc_send_buffer_ip_mcast(oc_message_t *message) {
+oc_send_buffer_ip_mcast(oc_message_t *message)
+{
     oc_send_buffer_ip_int(message, 1);
 }
 
-oc_message_t *
-oc_attempt_rx_ip_sock(struct mn_socket * rxsock) {
+static struct os_mbuf *
+oc_attempt_rx_ip_sock(struct mn_socket * rxsock)
+{
     int rc;
-    struct os_mbuf *m = NULL;
-    struct os_mbuf_pkthdr *pkt;
-    oc_message_t *message = NULL;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct oc_endpoint *oe;
     struct mn_sockaddr_in6 from;
 
     LOG("oc_transport_ip attempt rx from %p\n", rxsock);
 
-    rc= mn_recvfrom(rxsock, &m, (struct mn_sockaddr *) &from);
-
-    if ( rc != 0) {
+    rc = mn_recvfrom(rxsock, &n, (struct mn_sockaddr *) &from);
+    if (rc != 0) {
         return NULL;
     }
+    assert(OS_MBUF_IS_PKTHDR(n));
 
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        goto rx_attempt_err;
-    }
-
-    pkt = OS_MBUF_PKTHDR(m);
-
-    LOG("rx from %p %p-%u\n", rxsock, pkt, pkt->omp_len);
-
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
 
-    os_mbuf_free_chain(m);
+    LOG("rx from %p %p-%u\n", rxsock, m, OS_MBUF_PKTHDR(m)->omp_len);
 
-    message->endpoint.flags = IP;
-    message->length = pkt->omp_len;
-    memcpy(&message->endpoint.ipv6_addr.address, &from.msin6_addr,
-             sizeof(message->endpoint.ipv6_addr.address));
-    message->endpoint.ipv6_addr.scope = from.msin6_scope_id;
-    message->endpoint.ipv6_addr.port = ntohs(from.msin6_port);
+    oe->flags = IP;
+    memcpy(&oe->ipv6_addr.address, &from.msin6_addr,
+             sizeof(oe->ipv6_addr.address));
+    oe->ipv6_addr.scope = from.msin6_scope_id;
+    oe->ipv6_addr.port = ntohs(from.msin6_port);
 
-    LOG("Successfully rx from %p len %lu\n", rxsock,
-        (unsigned long)message->length);
-    return message;
+    LOG("Successfully rx from %p\n", rxsock);
+
+    return m;
 
     /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-
-    if (message) {
-        oc_message_unref(message);
-    }
-
+    os_mbuf_free_chain(n);
     return NULL;
 }
 
-oc_message_t *
-oc_attempt_rx_ip(void) {
-    oc_message_t *pmsg;
-    pmsg = oc_attempt_rx_ip_sock(ucast);
+static struct os_mbuf *
+oc_attempt_rx_ip(void)
+{
+    struct os_mbuf *m;
+
+    m = oc_attempt_rx_ip_sock(ucast);
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    if (pmsg == NULL ) {
-        pmsg = oc_attempt_rx_ip_sock(mcast);
+    if (m == NULL ) {
+        m = oc_attempt_rx_ip_sock(mcast);
     }
 #endif
-    return pmsg;
+    return m;
 }
 
 static void oc_socks_readable(void *cb_arg, int err);
@@ -233,10 +217,10 @@ oc_connectivity_shutdown_ip(void)
 static void
 oc_event_ip(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_ip()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_ip()) != NULL) {
+        oc_recv_message(m);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index be807d3..209a9c7 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -21,16 +21,20 @@
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 
 #include <assert.h>
+
 #include <os/os.h>
+
 #include <shell/shell.h>
+
 #include "oc_buffer.h"
 #include "port/oc_connectivity.h"
 #include "../oc_log.h"
 #include "adaptor.h"
 
-
 struct os_mqueue oc_serial_mqueue;
 
+static struct os_mbuf *oc_attempt_rx_serial(void);
+
 static int
 oc_serial_in(struct os_mbuf *m, void *arg)
 {
@@ -38,17 +42,18 @@ oc_serial_in(struct os_mbuf *m, void *arg)
 }
 
 void
-oc_connectivity_shutdown_serial(void) {
+oc_connectivity_shutdown_serial(void)
+{
     shell_nlip_input_register(NULL, NULL);
 }
 
 static void
 oc_event_serial(struct os_event *ev)
 {
-    oc_message_t *pmsg;
+    struct os_mbuf *m;
 
-    while ((pmsg = oc_attempt_rx_serial()) != NULL) {
-        oc_network_event(pmsg);
+    while ((m = oc_attempt_rx_serial()) != NULL) {
+        oc_recv_message(m);
     }
 }
 
@@ -110,67 +115,39 @@ err:
 
 }
 
-oc_message_t *
-oc_attempt_rx_serial(void) {
-    int rc;
-    struct os_mbuf *m = NULL;
-    struct os_mbuf_pkthdr *pkt;
-    oc_message_t *message = NULL;
+static struct os_mbuf *
+oc_attempt_rx_serial(void)
+{
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct oc_endpoint *oe;
 
     LOG("oc_transport_serial attempt rx\n");
 
     /* get an mbuf from the queue */
-    m = os_mqueue_get(&oc_serial_mqueue);
-    if (NULL == m) {
+    n = os_mqueue_get(&oc_serial_mqueue);
+    if (NULL == n) {
         ERROR("oc_transport_serial: Woke for for receive but found no mbufs\n");
-        goto rx_attempt_err;
-    }
-
-    if (!OS_MBUF_IS_PKTHDR(m)) {
-        ERROR("oc_transport_serial: received mbuf that wasn't a packet header\n");
-        goto rx_attempt_err;
+        return NULL;
     }
 
-    pkt = OS_MBUF_PKTHDR(m);
-
-    LOG("oc_transport_serial rx %p-%u\n", pkt, pkt->omp_len);
-
-    message = oc_allocate_message();
-    if (NULL == message) {
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
         ERROR("Could not allocate OC message buffer\n");
         goto rx_attempt_err;
     }
+    OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
+    SLIST_NEXT(m, om_next) = n;
 
-    if (pkt->omp_len > MAX_PAYLOAD_SIZE) {
-        ERROR("Message to large for OC message buffer\n");
-        goto rx_attempt_err;
-    }
-    /* copy to message from mbuf chain */
-    rc = os_mbuf_copydata(m, 0, pkt->omp_len, message->data);
-    if (rc != 0) {
-        ERROR("Failed to copy message from mbuf to OC message buffer \n");
-        goto rx_attempt_err;
-    }
+    oe = OC_MBUF_ENDPOINT(m);
+    oe->flags = SERIAL;
 
-    os_mbuf_free_chain(m);
+    LOG("oc_transport_serial rx %p-%u\n", n, OS_MBUF_PKTHDR(n)->omp_len);
 
-    message->endpoint.flags = SERIAL;
-    message->length = pkt->omp_len;
+    return m;
 
-    LOG("Successfully rx length %zu\n", message->length);
-    return message;
-
-    /* add the addr info to the message */
 rx_attempt_err:
-    if (m) {
-        os_mbuf_free_chain(m);
-    }
-
-    if (message) {
-        oc_message_unref(message);
-    }
-
+    os_mbuf_free_chain(n);
     return NULL;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/969df792/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 3f84541..493b30e 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -18,7 +18,6 @@
 #define OC_CONNECTIVITY_H
 
 #include "mynewt/config.h"
-#include "oic/oc_network_events.h"
 #include "oc_log.h"
 #include <stdint.h>
 


[11/16] incubator-mynewt-core git commit: oic; allow only one request in at a time.

Posted by ma...@apache.org.
oic; allow only one request in at a time.


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/6979f45e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6979f45e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6979f45e

Branch: refs/heads/develop
Commit: 6979f45e63091bd44dd091f332232821471ee1a8
Parents: 049222d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 08:19:56 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:24 2016 -0800

----------------------------------------------------------------------
 net/oic/syscfg.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6979f45e/net/oic/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/oic/syscfg.yml b/net/oic/syscfg.yml
index 47e9802..a9734ab 100644
--- a/net/oic/syscfg.yml
+++ b/net/oic/syscfg.yml
@@ -44,7 +44,7 @@ syscfg.defs:
 
     OC_CONCURRENT_REQUESTS:
         description: 'Maximum number of concurrent requests'
-        value: 2
+        value: 1
 
     OC_MAX_PAYLOAD_SIZE:
         description: 'Maximum size of request/response PDUs'


[10/16] incubator-mynewt-core git commit: oic; remove oc_list, oc_mmem.

Posted by ma...@apache.org.
oic; remove oc_list, oc_mmem.


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/049222d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/049222d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/049222d3

Branch: refs/heads/develop
Commit: 049222d3f1330fe9386f7829e61ee73cf167a6c6
Parents: 0526e07
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 08:18:12 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:45:24 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_helpers.h          |   2 -
 net/oic/src/messaging/coap/observe.h      |   2 -
 net/oic/src/messaging/coap/oc_coap.h      |   1 -
 net/oic/src/messaging/coap/transactions.c |   1 -
 net/oic/src/port/mynewt/config.h          |   5 -
 net/oic/src/util/oc_list.c                | 317 -------------------------
 net/oic/src/util/oc_list.h                | 152 ------------
 net/oic/src/util/oc_mmem.c                | 154 ------------
 net/oic/src/util/oc_mmem.h                |  61 -----
 9 files changed, 695 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/include/oic/oc_helpers.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_helpers.h b/net/oic/include/oic/oc_helpers.h
index 4855f94..24c5f0c 100644
--- a/net/oic/include/oic/oc_helpers.h
+++ b/net/oic/include/oic/oc_helpers.h
@@ -17,8 +17,6 @@
 #ifndef OC_HELPERS_H
 #define OC_HELPERS_H
 
-#include "../../src/util/oc_list.h"
-#include "../../src/util/oc_mmem.h"
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.h b/net/oic/src/messaging/coap/observe.h
index a913745..ae63bf1 100644
--- a/net/oic/src/messaging/coap/observe.h
+++ b/net/oic/src/messaging/coap/observe.h
@@ -36,7 +36,6 @@
 
 #include "coap.h"
 #include "transactions.h"
-#include "../../util/oc_list.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -63,7 +62,6 @@ typedef struct coap_observer {
   uint8_t retrans_counter;
 } coap_observer_t;
 
-oc_list_t coap_get_observers(void);
 void coap_remove_observer(coap_observer_t *o);
 int coap_remove_observer_by_client(oc_endpoint_t *endpoint);
 int coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/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 cddf46f..dcc0352 100644
--- a/net/oic/src/messaging/coap/oc_coap.h
+++ b/net/oic/src/messaging/coap/oc_coap.h
@@ -18,7 +18,6 @@
 #define OC_COAP_H
 
 #include "separate.h"
-#include "../../util/oc_list.h"
 
 #ifdef __cplusplus
 extern "C" {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index 662ca22..42ca498 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -39,7 +39,6 @@
 #include "transactions.h"
 #include "observe.h"
 #include "oc_buffer.h"
-#include "util/oc_list.h"
 
 #ifdef OC_CLIENT
 #include "oc_client_state.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/port/mynewt/config.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/config.h b/net/oic/src/port/mynewt/config.h
index 171625f..c8fdb06 100644
--- a/net/oic/src/port/mynewt/config.h
+++ b/net/oic/src/port/mynewt/config.h
@@ -36,11 +36,6 @@ typedef os_time_t oc_clock_time_t;
 #define OC_CLK_FMT  "%lu"
 #endif
 
-/* Memory pool sizes */
-#define OC_BYTES_POOL_SIZE (2048)
-#define OC_INTS_POOL_SIZE (16)
-#define OC_DOUBLES_POOL_SIZE (16)
-
 /* Server-side parameters */
 /* Maximum number of server resources */
 #define MAX_APP_RESOURCES MYNEWT_VAL(OC_APP_RESOURCES)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/util/oc_list.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_list.c b/net/oic/src/util/oc_list.c
deleted file mode 100644
index 429f411..0000000
--- a/net/oic/src/util/oc_list.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-#include "oc_list.h"
-
-#define NULL 0
-
-struct list
-{
-  struct list *next;
-};
-
-/*---------------------------------------------------------------------------*/
-/**
- * Initialize a list.
- *
- * This function initalizes a list. The list will be empty after this
- * function has been called.
- *
- * \param list The list to be initialized.
- */
-void
-oc_list_init(oc_list_t list)
-{
-  *list = NULL;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Get a pointer to the first element of a list.
- *
- * This function returns a pointer to the first element of the
- * list. The element will \b not be removed from the list.
- *
- * \param list The list.
- * \return A pointer to the first element on the list.
- *
- * \sa oc_list_tail()
- */
-void *
-oc_list_head(oc_list_t list)
-{
-  return *list;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Duplicate a list.
- *
- * This function duplicates a list by copying the list reference, but
- * not the elements.
- *
- * \note This function does \b not copy the elements of the list, but
- * merely duplicates the pointer to the first element of the list.
- *
- * \param dest The destination list.
- * \param src The source list.
- */
-void
-oc_list_copy(oc_list_t dest, oc_list_t src)
-{
-  *dest = *src;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Get the tail of a list.
- *
- * This function returns a pointer to the elements following the first
- * element of a list. No elements are removed by this function.
- *
- * \param list The list
- * \return A pointer to the element after the first element on the list.
- *
- * \sa oc_list_head()
- */
-void *
-oc_list_tail(oc_list_t list)
-{
-  struct list *l;
-
-  if (*list == NULL) {
-    return NULL;
-  }
-
-  for (l = *list; l->next != NULL; l = l->next)
-    ;
-
-  return l;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Add an item at the end of a list.
- *
- * This function adds an item to the end of the list.
- *
- * \param list The list.
- * \param item A pointer to the item to be added.
- *
- * \sa oc_list_push()
- *
- */
-void
-oc_list_add(oc_list_t list, void *item)
-{
-  struct list *l;
-
-  /* Make sure not to add the same element twice */
-  oc_list_remove(list, item);
-
-  ((struct list *)item)->next = NULL;
-
-  l = oc_list_tail(list);
-
-  if (l == NULL) {
-    *list = item;
-  } else {
-    l->next = item;
-  }
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Add an item to the start of the list.
- */
-void
-oc_list_push(oc_list_t list, void *item)
-{
-  /* Make sure not to add the same element twice */
-  oc_list_remove(list, item);
-
-  ((struct list *)item)->next = *list;
-  *list = item;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Remove the last object on the list.
- *
- * This function removes the last object on the list and returns it.
- *
- * \param list The list
- * \return The removed object
- *
- */
-void *
-oc_list_chop(oc_list_t list)
-{
-  struct list *l, *r;
-
-  if (*list == NULL) {
-    return NULL;
-  }
-  if (((struct list *)*list)->next == NULL) {
-    l = *list;
-    *list = NULL;
-    return l;
-  }
-
-  for (l = *list; l->next->next != NULL; l = l->next)
-    ;
-
-  r = l->next;
-  l->next = NULL;
-
-  return r;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Remove the first object on a list.
- *
- * This function removes the first object on the list and returns a
- * pointer to it.
- *
- * \param list The list.
- * \return Pointer to the removed element of list.
- */
-/*---------------------------------------------------------------------------*/
-void *
-oc_list_pop(oc_list_t list)
-{
-  struct list *l;
-  l = *list;
-  if (*list != NULL) {
-    *list = ((struct list *)*list)->next;
-  }
-
-  return l;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Remove a specific element from a list.
- *
- * This function removes a specified element from the list.
- *
- * \param list The list.
- * \param item The item that is to be removed from the list.
- *
- */
-/*---------------------------------------------------------------------------*/
-void
-oc_list_remove(oc_list_t list, void *item)
-{
-  struct list *l, *r;
-
-  if (*list == NULL) {
-    return;
-  }
-
-  r = NULL;
-  for (l = *list; l != NULL; l = l->next) {
-    if (l == item) {
-      if (r == NULL) {
-        /* First on list */
-        *list = l->next;
-      } else {
-        /* Not first on list */
-        r->next = l->next;
-      }
-      l->next = NULL;
-      return;
-    }
-    r = l;
-  }
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Get the length of a list.
- *
- * This function counts the number of elements on a specified list.
- *
- * \param list The list.
- * \return The length of the list.
- */
-/*---------------------------------------------------------------------------*/
-int
-oc_list_length(oc_list_t list)
-{
-  struct list *l;
-  int n = 0;
-
-  for (l = *list; l != NULL; l = l->next) {
-    ++n;
-  }
-
-  return n;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * \brief      Insert an item after a specified item on the list
- * \param list The list
- * \param previtem The item after which the new item should be inserted
- * \param newitem  The new item that is to be inserted
- * \author     Adam Dunkels
- *
- *             This function inserts an item right after a specified
- *             item on the list. This function is useful when using
- *             the list module to ordered lists.
- *
- *             If previtem is NULL, the new item is placed at the
- *             start of the list.
- *
- */
-void
-oc_list_insert(oc_list_t list, void *previtem, void *newitem)
-{
-  if (previtem == NULL) {
-    oc_list_push(list, newitem);
-  } else {
-
-    ((struct list *)newitem)->next = ((struct list *)previtem)->next;
-    ((struct list *)previtem)->next = newitem;
-  }
-}
-/*---------------------------------------------------------------------------*/
-/**
- * \brief      Get the next item following this item
- * \param item A list item
- * \returns    A next item on the list
- *
- *             This function takes a list item and returns the next
- *             item on the list, or NULL if there are no more items on
- *             the list. This function is used when iterating through
- *             lists.
- */
-void *
-oc_list_item_next(void *item)
-{
-  return item == NULL ? NULL : ((struct list *)item)->next;
-}
-/*---------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/util/oc_list.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_list.h b/net/oic/src/util/oc_list.h
deleted file mode 100644
index c0f5db8..0000000
--- a/net/oic/src/util/oc_list.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \defgroup list Linked list library
- *
- * The linked list library provides a set of functions for
- * manipulating linked lists.
- *
- * A linked list is made up of elements where the first element \b
- * must be a pointer. This pointer is used by the linked list library
- * to form lists of the elements.
- *
- * Lists are declared with the LIST() macro. The declaration specifies
- * the name of the list that later is used with all list functions.
- *
- * Lists can be manipulated by inserting or removing elements from
- * either sides of the list (list_push(), list_add(), list_pop(),
- * list_chop()). A specified element can also be removed from inside a
- * list with list_remove(). The head and tail of a list can be
- * extracted using list_head() and list_tail(), respectively.
- *
- */
-
-#ifndef OC_LIST_H
-#define OC_LIST_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define OC_LIST_CONCAT2(s1, s2) s1##s2
-#define OC_LIST_CONCAT(s1, s2) OC_LIST_CONCAT2(s1, s2)
-
-/**
- * Declare a linked list.
- *
- * This macro declares a linked list with the specified \c type. The
- * type \b must be a structure (\c struct) with its first element
- * being a pointer. This pointer is used by the linked list library to
- * form the linked lists.
- *
- * The list variable is declared as static to make it easy to use in a
- * single C module without unnecessarily exporting the name to other
- * modules.
- *
- * \param name The name of the list.
- */
-#define OC_LIST(name)                                                          \
-  static void *OC_LIST_CONCAT(name, _list) = NULL;                             \
-  static oc_list_t name = (oc_list_t)&OC_LIST_CONCAT(name, _list)
-
-/**
- * Declare a linked list inside a structure declaraction.
- *
- * This macro declares a linked list with the specified \c type. The
- * type \b must be a structure (\c struct) with its first element
- * being a pointer. This pointer is used by the linked list library to
- * form the linked lists.
- *
- * Internally, the list is defined as two items: the list itself and a
- * pointer to the list. The pointer has the name of the parameter to
- * the macro and the name of the list is a concatenation of the name
- * and the suffix "_list". The pointer must point to the list for the
- * list to work. Thus the list must be initialized before using.
- *
- * The list is initialized with the LIST_STRUCT_INIT() macro.
- *
- * \param name The name of the list.
- */
-#define OC_LIST_STRUCT(name)                                                   \
-  void *OC_LIST_CONCAT(name, _list);                                           \
-  oc_list_t name
-
-/**
- * Initialize a linked list that is part of a structure.
- *
- * This macro sets up the internal pointers in a list that has been
- * defined as part of a struct. This macro must be called before using
- * the list.
- *
- * \param struct_ptr A pointer to the struct
- * \param name The name of the list.
- */
-#define OC_LIST_STRUCT_INIT(struct_ptr, name)                                  \
-  do {                                                                         \
-    (struct_ptr)->name = &((struct_ptr)->OC_LIST_CONCAT(name, _list));         \
-    (struct_ptr)->OC_LIST_CONCAT(name, _list) = NULL;                          \
-    oc_list_init((struct_ptr)->name);                                          \
-  } while (0)
-
-/**
- * The linked list type.
- *
- */
-typedef void **oc_list_t;
-
-void oc_list_init(oc_list_t list);
-void *oc_list_head(oc_list_t list);
-void *oc_list_tail(oc_list_t list);
-void *oc_list_pop(oc_list_t list);
-void oc_list_push(oc_list_t list, void *item);
-
-void *oc_list_chop(oc_list_t list);
-
-void oc_list_add(oc_list_t list, void *item);
-void oc_list_remove(oc_list_t list, void *item);
-
-int oc_list_length(oc_list_t list);
-
-void oc_list_copy(oc_list_t dest, oc_list_t src);
-
-void oc_list_insert(oc_list_t list, void *previtem, void *newitem);
-
-void *oc_list_item_next(void *item);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_LIST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/util/oc_mmem.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_mmem.c b/net/oic/src/util/oc_mmem.c
deleted file mode 100644
index 8a129c6..0000000
--- a/net/oic/src/util/oc_mmem.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2005, Swedish Institute of Computer Science
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- */
-
-#include "oc_mmem.h"
-#include "config.h"
-#include "oc_list.h"
-#include "port/oc_log.h"
-#include <stdint.h>
-#include <string.h>
-
-#if !defined(OC_BYTES_POOL_SIZE) || !defined(OC_INTS_POOL_SIZE) ||             \
-  !defined(OC_DOUBLES_POOL_SIZE)
-#error "Please define byte, int, double pool sizes in config.h"
-#endif /* ...POOL_SIZE */
-
-static double doubles[OC_DOUBLES_POOL_SIZE];
-static int64_t ints[OC_INTS_POOL_SIZE];
-static unsigned char bytes[OC_BYTES_POOL_SIZE];
-static unsigned int avail_bytes, avail_ints, avail_doubles;
-
-OC_LIST(bytes_list);
-OC_LIST(ints_list);
-OC_LIST(doubles_list);
-
-/*---------------------------------------------------------------------------*/
-int
-oc_mmem_alloc(struct oc_mmem *m, unsigned int size, pool pool_type)
-{
-  switch (pool_type) {
-  case BYTE_POOL:
-    if (avail_bytes < size) {
-      return 0;
-    }
-    oc_list_add(bytes_list, m);
-    m->ptr = &bytes[OC_BYTES_POOL_SIZE - avail_bytes];
-    m->size = size;
-    avail_bytes -= size;
-    break;
-  case INT_POOL:
-    if (avail_ints < size) {
-      return 0;
-    }
-    oc_list_add(ints_list, m);
-    m->ptr = &ints[OC_INTS_POOL_SIZE - avail_ints];
-    m->size = size;
-    avail_ints -= size;
-    break;
-  case DOUBLE_POOL:
-    if (avail_doubles < size) {
-      return 0;
-    }
-    oc_list_add(doubles_list, m);
-    m->ptr = &doubles[OC_DOUBLES_POOL_SIZE - avail_doubles];
-    m->size = size;
-    avail_doubles -= size;
-    break;
-  default:
-    break;
-  }
-  return 1;
-}
-
-void
-oc_mmem_free(struct oc_mmem *m, pool pool_type)
-{
-  struct oc_mmem *n;
-
-  if (m->next != NULL) {
-    switch (pool_type) {
-    case BYTE_POOL:
-      memmove(m->ptr, m->next->ptr, &bytes[OC_BYTES_POOL_SIZE - avail_bytes] -
-                                      (unsigned char *)m->next->ptr);
-      break;
-    case INT_POOL:
-      memmove(m->ptr, m->next->ptr,
-              &ints[OC_INTS_POOL_SIZE - avail_ints] - (int64_t *)m->next->ptr);
-      break;
-    case DOUBLE_POOL:
-      memmove(m->ptr, m->next->ptr,
-              &doubles[OC_DOUBLES_POOL_SIZE - avail_doubles] -
-                (double *)m->next->ptr);
-      break;
-    default:
-      return;
-      break;
-    }
-    for (n = m->next; n != NULL; n = n->next) {
-      n->ptr = (void *)((char *)n->ptr - m->size);
-    }
-  }
-
-  switch (pool_type) {
-  case BYTE_POOL:
-    avail_bytes += m->size;
-    oc_list_remove(bytes_list, m);
-    break;
-  case INT_POOL:
-    avail_ints += m->size;
-    oc_list_remove(ints_list, m);
-    break;
-  case DOUBLE_POOL:
-    avail_doubles += m->size;
-    oc_list_remove(doubles_list, m);
-    break;
-  }
-}
-
-void
-oc_mmem_init(void)
-{
-  static int inited = 0;
-  if (inited) {
-    return;
-  }
-  oc_list_init(bytes_list);
-  oc_list_init(ints_list);
-  oc_list_init(doubles_list);
-  avail_bytes = OC_BYTES_POOL_SIZE;
-  avail_ints = OC_INTS_POOL_SIZE;
-  avail_doubles = OC_DOUBLES_POOL_SIZE;
-  inited = 1;
-}
-/*---------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/049222d3/net/oic/src/util/oc_mmem.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_mmem.h b/net/oic/src/util/oc_mmem.h
deleted file mode 100644
index bcd170f..0000000
--- a/net/oic/src/util/oc_mmem.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2005, Swedish Institute of Computer Science
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- */
-
-#ifndef OC_MMEM_H
-#define OC_MMEM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define OC_MMEM_PTR(m) (struct oc_mmem *)(m)->ptr
-
-struct oc_mmem
-{
-  struct oc_mmem *next;
-  unsigned int size;
-  void *ptr;
-};
-
-typedef enum { BYTE_POOL, INT_POOL, DOUBLE_POOL } pool;
-
-int oc_mmem_alloc(struct oc_mmem *m, unsigned int size, pool pool_type);
-void oc_mmem_free(struct oc_mmem *, pool pool_type);
-void oc_mmem_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_MMEM_H */


[16/16] incubator-mynewt-core git commit: Merge branch 'coap' into develop

Posted by ma...@apache.org.
Merge branch 'coap' into develop


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/5f7ad8cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5f7ad8cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5f7ad8cb

Branch: refs/heads/develop
Commit: 5f7ad8cb0d189dac73b45e1cf928b92be3056cdd
Parents: 84997a9 6979f45
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 30 08:56:36 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:56:36 2016 -0800

----------------------------------------------------------------------
 hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c |  16 +-
 net/oic/include/oic/oc_client_state.h         |   4 +-
 net/oic/include/oic/oc_helpers.h              |  91 +--
 net/oic/include/oic/oc_rep.h                  |   1 +
 net/oic/include/oic/oc_ri.h                   |  11 +-
 net/oic/src/api/oc_core_res.c                 | 359 ++++++-----
 net/oic/src/api/oc_discovery.c                |  32 +-
 net/oic/src/api/oc_helpers.c                  | 180 +++---
 net/oic/src/api/oc_rep.c                      |   8 +-
 net/oic/src/api/oc_ri.c                       | 107 ++--
 net/oic/src/api/oc_server_api.c               |  73 +--
 net/oic/src/messaging/coap/coap.c             | 698 ++++++++++-----------
 net/oic/src/messaging/coap/coap.h             | 108 ++--
 net/oic/src/messaging/coap/observe.c          |  50 +-
 net/oic/src/messaging/coap/observe.h          |   7 +-
 net/oic/src/messaging/coap/oc_coap.h          |  23 +-
 net/oic/src/messaging/coap/separate.c         |  24 +-
 net/oic/src/messaging/coap/separate.h         |  29 +-
 net/oic/src/messaging/coap/transactions.c     |  23 +-
 net/oic/src/messaging/coap/transactions.h     |   2 +-
 net/oic/src/port/mynewt/config.h              |   5 -
 net/oic/src/util/oc_list.c                    | 317 ----------
 net/oic/src/util/oc_list.h                    | 152 -----
 net/oic/src/util/oc_mmem.c                    | 154 -----
 net/oic/src/util/oc_mmem.h                    |  61 --
 net/oic/syscfg.yml                            |   2 +-
 26 files changed, 900 insertions(+), 1637 deletions(-)
----------------------------------------------------------------------



[13/16] incubator-mynewt-core git commit: oic; in preparation to moving to os_mbufs.

Posted by ma...@apache.org.
oic; in preparation to moving to os_mbufs.


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/5c7b8859
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5c7b8859
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5c7b8859

Branch: refs/heads/develop
Commit: 5c7b8859e1a85a8238ea4fbb0296a4a317200a38
Parents: 425e06f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 22 16:03:47 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 30 08:54:51 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_buffer.h         | 12 +++---
 net/oic/include/oic/oc_network_events.h |  4 +-
 net/oic/src/api/oc_buffer.c             | 16 +++----
 net/oic/src/api/oc_network_events.c     |  2 +-
 net/oic/src/port/mynewt/adaptor.h       | 18 ++++----
 net/oic/src/port/oc_connectivity.h      | 62 +++++++++++++---------------
 6 files changed, 54 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 852e427..7dab610 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -21,13 +21,13 @@
 extern "C" {
 #endif
 
-struct oc_message_s;
-struct oc_message_s *oc_allocate_message(void);
-void oc_message_add_ref(struct oc_message_s *message);
-void oc_message_unref(struct oc_message_s *message);
+struct oc_message;
+struct oc_message *oc_allocate_message(void);
+void oc_message_add_ref(struct oc_message *message);
+void oc_message_unref(struct oc_message *message);
 
-void oc_recv_message(struct oc_message_s *message);
-void oc_send_message(struct oc_message_s *message);
+void oc_recv_message(struct oc_message *message);
+void oc_send_message(struct oc_message *message);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
index 61a274c..f786390 100644
--- a/net/oic/include/oic/oc_network_events.h
+++ b/net/oic/include/oic/oc_network_events.h
@@ -21,9 +21,9 @@
 extern "C" {
 #endif
 
-typedef struct oc_message_s oc_message_t;
+struct oc_message;
 
-void oc_network_event(oc_message_t *message);
+void oc_network_event(struct oc_message *message);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index b7201d7..bd3bbd1 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -37,8 +37,8 @@ static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
 
 static void oc_buffer_handler(struct os_event *);
 
-static struct oc_message_s *oc_buffer_inq;
-static struct oc_message_s *oc_buffer_outq;
+static struct oc_message *oc_buffer_inq;
+static struct oc_message *oc_buffer_outq;
 static struct os_event oc_buffer_ev = {
     .ev_cb = oc_buffer_handler
 };
@@ -89,11 +89,11 @@ oc_message_unref(oc_message_t *message)
 }
 
 static void
-oc_queue_msg(struct oc_message_s **head, struct oc_message_s *msg)
+oc_queue_msg(struct oc_message **head, struct oc_message *msg)
 {
-    struct oc_message_s *tmp;
+    struct oc_message *tmp;
 
-    msg->next = NULL; /* oc_message_s has been oc_list once, clear next */
+    msg->next = NULL; /* oc_message has been oc_list once, clear next */
     if (!*head) {
         *head = msg;
     } else {
@@ -117,7 +117,7 @@ oc_send_message(oc_message_t *message)
 }
 
 static void
-oc_buffer_tx(struct oc_message_s *message)
+oc_buffer_tx(struct oc_message *message)
 {
 #ifdef OC_CLIENT
     if (message->endpoint.flags & MULTICAST) {
@@ -153,7 +153,7 @@ oc_buffer_tx(struct oc_message_s *message)
 }
 
 static void
-oc_buffer_rx(struct oc_message_s *msg)
+oc_buffer_rx(struct oc_message *msg)
 {
 #ifdef OC_SECURITY
     uint8_t b = (uint8_t)(msg->data[0];
@@ -175,7 +175,7 @@ oc_buffer_rx(struct oc_message_s *msg)
 static void
 oc_buffer_handler(struct os_event *ev)
 {
-    struct oc_message_s *msg;
+    struct oc_message *msg;
 
     while (oc_buffer_outq || oc_buffer_inq) {
         msg = oc_buffer_outq;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index fd5ba38..6f33189 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -33,7 +33,7 @@ static struct os_event oc_network_ev = {
 static void
 oc_network_ev_process(struct os_event *ev)
 {
-    struct oc_message_s *head;
+    struct oc_message *head;
 
     oc_network_event_handler_mutex_lock();
     while (1) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index e9062e0..a40d2e8 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -27,29 +27,29 @@ extern "C" {
 struct os_eventq *oc_evq_get(void);
 void oc_evq_set(struct os_eventq *evq);
 
-struct oc_message_s;
+struct oc_message;
 
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
 int oc_connectivity_init_ip(void);
 void oc_connectivity_shutdown_ip(void);
-void oc_send_buffer_ip(struct oc_message_s *message);
-void oc_send_buffer_ip_mcast(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_ip(void);
+void oc_send_buffer_ip(struct oc_message *message);
+void oc_send_buffer_ip_mcast(struct oc_message *message);
+struct oc_message *oc_attempt_rx_ip(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
 int oc_connectivity_init_gatt(void);
 void oc_connectivity_shutdown_gatt(void);
-void oc_send_buffer_gatt(struct oc_message_s *message);
-void oc_send_buffer_gatt_mcast(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_gatt(void);
+void oc_send_buffer_gatt(struct oc_message *message);
+void oc_send_buffer_gatt_mcast(struct oc_message *message);
+struct oc_message *oc_attempt_rx_gatt(void);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
 int oc_connectivity_init_serial(void);
 void oc_connectivity_shutdown_serial(void);
-void oc_send_buffer_serial(struct oc_message_s *message);
-struct oc_message_s *oc_attempt_rx_serial(void);
+void oc_send_buffer_serial(struct oc_message *message);
+struct oc_message *oc_attempt_rx_serial(void);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c7b8859/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 1380442..3f84541 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -26,37 +26,32 @@
 extern "C" {
 #endif
 
-typedef struct
-{
-  uint16_t port;
-  uint8_t address[16];
-  uint8_t scope;
+typedef struct {
+    uint16_t port;
+    uint8_t address[16];
+    uint8_t scope;
 } oc_ipv6_addr_t;
 
-typedef struct
-{
-  uint8_t type;
-  uint8_t address[6];
-  uint16_t conn_handle;
+typedef struct {
+    uint8_t type;
+    uint8_t address[6];
+    uint16_t conn_handle;
 } oc_le_addr_t;
 
-typedef struct
-{
-  enum transport_flags
-  {
-    IP = 1 << 0,
-    GATT = 1 << 1,
-    IPSP = 1 << 2,
-    MULTICAST = 1 << 3,
-    SECURED = 1 << 4,
-    SERIAL = 1 <<5,
-  } flags;
-
-  union
-  {
-    oc_ipv6_addr_t ipv6_addr;
-    oc_le_addr_t bt_addr;
-  };
+typedef struct oc_endpoint {
+    enum transport_flags {
+        IP = 1 << 0,
+        GATT = 1 << 1,
+        IPSP = 1 << 2,
+        MULTICAST = 1 << 3,
+        SECURED = 1 << 4,
+        SERIAL = 1 <<5,
+    } flags;
+
+    union {
+        oc_ipv6_addr_t ipv6_addr;
+        oc_le_addr_t bt_addr;
+    };
 } oc_endpoint_t;
 
 #define oc_make_ip_endpoint(__name__, __flags__, __port__, ...)                \
@@ -64,13 +59,12 @@ typedef struct
                             .ipv6_addr = {.port = __port__,                    \
                                           .address = { __VA_ARGS__ } } }
 
-typedef struct oc_message_s
-{
-  struct oc_message_s *next;
-  oc_endpoint_t endpoint;
-  size_t length;
-  uint8_t ref_count;
-  uint8_t data[MAX_PAYLOAD_SIZE];
+typedef struct oc_message {
+    struct oc_message *next;
+    oc_endpoint_t endpoint;
+    size_t length;
+    uint8_t ref_count;
+    uint8_t data[MAX_PAYLOAD_SIZE];
 } oc_message_t;
 
 void oc_send_buffer(oc_message_t *message);