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:52 UTC

[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.

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>