You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/12/15 00:47:24 UTC

[1/4] incubator-mynewt-core git commit: oic; ble, change reassembly take place in write callback from host. Only allocate oc_endpoint mbuf for the first fragment.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 6076575af -> f2ed5c979


oic; ble, change reassembly take place in write callback from host.
Only allocate oc_endpoint mbuf for the first fragment.


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

Branch: refs/heads/develop
Commit: f2ed5c9790ed458557d7fbe94dac5c270fc4af97
Parents: edbdda6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 14 16:43:22 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 14 16:45:51 2016 -0800

----------------------------------------------------------------------
 net/oic/src/port/mynewt/ble_adaptor.c | 196 ++++++++++-------------------
 1 file changed, 65 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f2ed5c97/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 14128f2..23742b9 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -75,8 +75,6 @@ STATS_NAME_START(oc_ble_stats)
     STATS_NAME(oc_ble_stats, oerr)
 STATS_NAME_END(oc_ble_stats)
 
-/* queue to hold mbufs until we get called from oic */
-static struct os_mqueue oc_ble_coap_mq;
 static STAILQ_HEAD(, os_mbuf_pkthdr) oc_ble_reass_q;
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
@@ -115,6 +113,70 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = { {
     },
 };
 
+int
+oc_ble_reass(struct os_mbuf *om1, uint16_t conn_handle)
+{
+    struct os_mbuf_pkthdr *pkt1;
+    struct oc_endpoint *oe;
+    struct os_mbuf *om2;
+    struct os_mbuf_pkthdr *pkt2;
+    uint8_t hdr[6]; /* sizeof(coap_tcp_hdr32) */
+
+    pkt1 = OS_MBUF_PKTHDR(om1);
+    assert(pkt1);
+
+    STATS_INC(oc_ble_stats, iseg);
+    STATS_INCN(oc_ble_stats, ibytes, pkt1->omp_len);
+
+    OC_LOG_DEBUG("oc_gatt rx seg %u-%x-%u\n", conn_handle,
+                 (unsigned)pkt1, pkt1->omp_len);
+
+    STAILQ_FOREACH(pkt2, &oc_ble_reass_q, omp_next) {
+        om2 = OS_MBUF_PKTHDR_TO_MBUF(pkt2);
+        oe = OC_MBUF_ENDPOINT(om2);
+        if (conn_handle == oe->bt_addr.conn_handle) {
+            /*
+             * Data from same connection. Append.
+             */
+            os_mbuf_concat(om2, om1);
+            os_mbuf_copydata(om2, 0, sizeof(hdr), hdr);
+
+            if (coap_tcp_msg_size(hdr, sizeof(hdr)) <= pkt2->omp_len) {
+                STAILQ_REMOVE(&oc_ble_reass_q, pkt2, os_mbuf_pkthdr, omp_next);
+                oc_recv_message(om2);
+            }
+            pkt1 = NULL;
+            break;
+        }
+    }
+    if (pkt1) {
+        /*
+         * New frame
+         */
+        om2 = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+        if (!om2) {
+            OC_LOG_ERROR("oc_gatt_rx: Could not allocate mbuf\n");
+            STATS_INC(oc_ble_stats, ierr);
+            return -1;
+        }
+        OS_MBUF_PKTHDR(om2)->omp_len = pkt1->omp_len;
+        SLIST_NEXT(om2, om_next) = om1;
+
+        oe = OC_MBUF_ENDPOINT(om2);
+        oe->flags = GATT;
+        oe->bt_addr.conn_handle = conn_handle;
+        pkt2 = OS_MBUF_PKTHDR(om2);
+
+        if (os_mbuf_copydata(om2, 0, sizeof(hdr), hdr) ||
+          coap_tcp_msg_size(hdr, sizeof(hdr)) > pkt2->omp_len) {
+            STAILQ_INSERT_TAIL(&oc_ble_reass_q, pkt2, omp_next);
+        } else {
+            oc_recv_message(om2);
+        }
+    }
+    return 0;
+}
+
 static int
 oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
                    struct ble_gatt_access_ctxt *ctxt, void *arg)
@@ -127,13 +189,7 @@ oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
     case BLE_GATT_ACCESS_OP_WRITE_CHR:
         m = ctxt->om;
 
-        /* stick the conn handle at the end of the frame -- we will
-         * pull it out later */
-        rc = os_mbuf_append(m, &conn_handle, sizeof(conn_handle));
-        if (rc) {
-            return BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-        rc = os_mqueue_put(&oc_ble_coap_mq, oc_evq_get(), m);
+        rc = oc_ble_reass(m, conn_handle);
         if (rc) {
             return BLE_ATT_ERR_INSUFFICIENT_RES;
         }
@@ -148,60 +204,6 @@ oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
     }
     return 0;
 }
-
-static struct os_mbuf *
-oc_attempt_rx_gatt(void)
-{
-    int rc;
-    struct os_mbuf *m;
-    struct os_mbuf *n;
-    struct os_mbuf_pkthdr *pkt;
-    struct oc_endpoint *oe;
-    uint16_t conn_handle;
-
-    /* get an mbuf from the queue */
-    n = os_mqueue_get(&oc_ble_coap_mq);
-    if (NULL == n) {
-        return NULL;
-    }
-
-    pkt = OS_MBUF_PKTHDR(n);
-
-    STATS_INC(oc_ble_stats, iseg);
-    STATS_INCN(oc_ble_stats, ibytes, pkt->omp_len);
-
-    /* get the conn handle from the end of the message */
-    rc = os_mbuf_copydata(n, pkt->omp_len - sizeof(conn_handle),
-                          sizeof(conn_handle), &conn_handle);
-    if (rc != 0) {
-        OC_LOG_ERROR("oc_gatt_rx: Failed to get conn_handle from mbuf\n");
-        goto rx_attempt_err;
-    }
-
-    /* trim conn_handle from the end */
-    os_mbuf_adj(n, - sizeof(conn_handle));
-
-    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
-    if (!m) {
-        OC_LOG_ERROR("oc_gatt_rx: Could not allocate mbuf\n");
-        goto rx_attempt_err;
-    }
-    OS_MBUF_PKTHDR(m)->omp_len = pkt->omp_len;
-    SLIST_NEXT(m, om_next) = n;
-
-    oe = OC_MBUF_ENDPOINT(m);
-
-    oe->flags = GATT;
-    oe->bt_addr.conn_handle = conn_handle;
-
-    return m;
-
-    /* add the addr info to the message */
-rx_attempt_err:
-    STATS_INC(oc_ble_stats, ierr);
-    os_mbuf_free_chain(n);
-    return NULL;
-}
 #endif
 
 int
@@ -227,60 +229,6 @@ oc_ble_coap_gatt_srv_init(void)
 }
 
 void
-oc_ble_reass(struct os_mbuf *om1)
-{
-    struct os_mbuf_pkthdr *pkt1;
-    struct oc_endpoint *oe1;
-    struct os_mbuf *om2;
-    struct os_mbuf_pkthdr *pkt2;
-    struct oc_endpoint *oe2;
-    int sr;
-    uint8_t hdr[6]; /* sizeof(coap_tcp_hdr32) */
-
-    pkt1 = OS_MBUF_PKTHDR(om1);
-    assert(pkt1);
-    oe1 = OC_MBUF_ENDPOINT(om1);
-
-    OC_LOG_DEBUG("oc_gatt rx seg %d-%x-%u\n", oe1->bt_addr.conn_handle,
-      (unsigned)pkt1, pkt1->omp_len);
-
-    OS_ENTER_CRITICAL(sr);
-    STAILQ_FOREACH(pkt2, &oc_ble_reass_q, omp_next) {
-        om2 = OS_MBUF_PKTHDR_TO_MBUF(pkt2);
-        oe2 = OC_MBUF_ENDPOINT(om2);
-        if (oe1->bt_addr.conn_handle == oe2->bt_addr.conn_handle) {
-            /*
-             * Data from same connection. Append.
-             */
-            os_mbuf_concat(om2, om1);
-            if (os_mbuf_copydata(om2, 0, sizeof(hdr), hdr)) {
-                pkt1 = NULL;
-                break;
-            }
-            if (coap_tcp_msg_size(hdr, sizeof(hdr)) <= pkt2->omp_len) {
-                STAILQ_REMOVE(&oc_ble_reass_q, pkt2, os_mbuf_pkthdr,
-                  omp_next);
-                oc_recv_message(om2);
-            }
-            pkt1 = NULL;
-            break;
-        }
-    }
-    if (pkt1) {
-        /*
-         *
-         */
-        if (os_mbuf_copydata(om1, 0, sizeof(hdr), hdr) ||
-          coap_tcp_msg_size(hdr, sizeof(hdr)) > pkt1->omp_len) {
-            STAILQ_INSERT_TAIL(&oc_ble_reass_q, pkt1, omp_next);
-        } else {
-            oc_recv_message(om1);
-        }
-    }
-    OS_EXIT_CRITICAL(sr);
-}
-
-void
 oc_ble_coap_conn_new(uint16_t conn_handle)
 {
     OC_LOG_DEBUG("oc_gatt newconn %x\n", conn_handle);
@@ -292,10 +240,8 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
     struct os_mbuf_pkthdr *pkt;
     struct os_mbuf *m;
     struct oc_endpoint *oe;
-    int sr;
 
     OC_LOG_DEBUG("oc_gatt endconn %x\n", conn_handle);
-    OS_ENTER_CRITICAL(sr);
     STAILQ_FOREACH(pkt, &oc_ble_reass_q, omp_next) {
         m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
         oe = OC_MBUF_ENDPOINT(m);
@@ -305,23 +251,11 @@ oc_ble_coap_conn_del(uint16_t conn_handle)
             break;
         }
     }
-    OS_EXIT_CRITICAL(sr);
-}
-
-static void
-oc_event_gatt(struct os_event *ev)
-{
-    struct os_mbuf *m;
-
-    while ((m = oc_attempt_rx_gatt()) != NULL) {
-        oc_ble_reass(m);
-    }
 }
 
 int
 oc_connectivity_init_gatt(void)
 {
-    os_mqueue_init(&oc_ble_coap_mq, oc_event_gatt, NULL);
     STAILQ_INIT(&oc_ble_reass_q);
     return 0;
 }


[2/4] incubator-mynewt-core git commit: oic; we don't actually keep track of mac address in oc_endpoint. So remove it.

Posted by ma...@apache.org.
oic; we don't actually keep track of mac address in oc_endpoint.
So remove it.


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

Branch: refs/heads/develop
Commit: 0ea2aca84e25e29c720de4c61dec4cd3fab8c777
Parents: 735fb8d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 14 16:17:01 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 14 16:45:51 2016 -0800

----------------------------------------------------------------------
 net/oic/src/port/mynewt/log.c      | 6 +-----
 net/oic/src/port/oc_connectivity.h | 2 --
 2 files changed, 1 insertion(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0ea2aca8/net/oic/src/port/mynewt/log.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c
index 85b80c6..b2f1b88 100644
--- a/net/oic/src/port/mynewt/log.c
+++ b/net/oic/src/port/mynewt/log.c
@@ -48,11 +48,7 @@ oc_log_endpoint(uint16_t lvl, struct oc_endpoint *oe)
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
     case GATT:
-        snprintf(tmp, sizeof(tmp), "%02x:%02x:%02x:%02x:%02x:%02x-%u\n",
-                 oe->bt_addr.address[0], oe->bt_addr.address[1],
-                 oe->bt_addr.address[2], oe->bt_addr.address[3],
-                 oe->bt_addr.address[4], oe->bt_addr.address[5],
-                 oe->bt_addr.conn_handle);
+        snprintf(tmp, sizeof(tmp), "%u\n", oe->bt_addr.conn_handle);
         str = tmp;
         break;
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0ea2aca8/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 807b0fb..ea44e3e 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -31,8 +31,6 @@ typedef struct {
 } oc_ipv6_addr_t;
 
 typedef struct {
-    uint8_t type;
-    uint8_t address[6];
     uint16_t conn_handle;
 } oc_le_addr_t;
 


[4/4] incubator-mynewt-core git commit: oic; fix debug log string in oc_buffer_tx().

Posted by ma...@apache.org.
oic; fix debug log string in oc_buffer_tx().


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

Branch: refs/heads/develop
Commit: 735fb8d4d6ea5718f75eee78f0db32d9cef15e6a
Parents: 6076575
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 14 16:15:26 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 14 16:45:51 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/735fb8d4/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 a2a00a8..7c3b477 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -115,7 +115,7 @@ oc_buffer_tx(struct os_event *ev)
     struct os_mbuf *m;
 
     while ((m = os_mqueue_get(&oc_outq)) != NULL) {
-        OC_LOG_DEBUG("oc_buffer_tx");
+        OC_LOG_DEBUG("oc_buffer_tx: ");
         OC_LOG_ENDPOINT(LOG_LEVEL_DEBUG, OC_MBUF_ENDPOINT(m));
 #ifdef OC_CLIENT
         if (OC_MBUF_ENDPOINT(m)->flags & MULTICAST) {


[3/4] incubator-mynewt-core git commit: bleprph_oic; add an example resource, which controls BSP's LED pin.

Posted by ma...@apache.org.
bleprph_oic; add an example resource, which controls BSP's LED pin.


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

Branch: refs/heads/develop
Commit: edbdda6f41a98ff07398c05ba6daf5503a766b44
Parents: 0ea2aca
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 14 16:18:30 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 14 16:45:51 2016 -0800

----------------------------------------------------------------------
 apps/bleprph_oic/src/main.c | 98 ++++++++++++++++++++++++++++++++++------
 1 file changed, 84 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/edbdda6f/apps/bleprph_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph_oic/src/main.c b/apps/bleprph_oic/src/main.c
index 203b1d4..22b4b81 100755
--- a/apps/bleprph_oic/src/main.c
+++ b/apps/bleprph_oic/src/main.c
@@ -21,26 +21,28 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
-#include "sysinit/sysinit.h"
-#include "bsp/bsp.h"
-#include "os/os.h"
-#include "bsp/bsp.h"
-#include "hal/hal_gpio.h"
-#include "console/console.h"
-#include "imgmgr/imgmgr.h"
-#include "mgmt/mgmt.h"
-#include "oic/oc_api.h"
+#include <sysinit/sysinit.h>
+#include <bsp/bsp.h>
+#include <os/os.h>
+#include <bsp/bsp.h>
+#include <hal/hal_gpio.h>
+#include <console/console.h>
+#include <imgmgr/imgmgr.h>
+#include <mgmt/mgmt.h>
+
+#include <oic/oc_api.h>
+#include <oic/oc_gatt.h>
+#include <oic/oc_log.h>
+#include <cborattr/cborattr.h>
 
 /* BLE */
-#include "nimble/ble.h"
-#include "host/ble_hs.h"
-#include "services/gap/ble_svc_gap.h"
+#include <nimble/ble.h>
+#include <host/ble_hs.h>
+#include <services/gap/ble_svc_gap.h>
 
 /* Application-specified header. */
 #include "bleprph.h"
 
-#include <oic/oc_gatt.h>
-#include <oic/oc_log.h>
 
 /** Log data. */
 struct log bleprph_log;
@@ -255,11 +257,76 @@ bleprph_on_sync(void)
 }
 
 static void
+app_get_light(oc_request_t *request, oc_interface_mask_t interface)
+{
+    bool state;
+
+    if (hal_gpio_read(LED_BLINK_PIN)) {
+        state = true;
+    } else {
+        state = false;
+    }
+    oc_rep_start_root_object();
+        switch (interface) {
+    case OC_IF_BASELINE:
+        oc_process_baseline_interface(request->resource);
+    case OC_IF_RW:
+        oc_rep_set_boolean(root, state, state);
+        break;
+    default:
+        break;
+    }
+    oc_rep_end_root_object();
+    oc_send_response(request, OC_STATUS_OK);
+}
+
+static void
+app_set_light(oc_request_t *request, oc_interface_mask_t interface)
+{
+    bool state;
+    int len;
+    const uint8_t *data;
+    struct cbor_attr_t attrs[] = {
+        [0] = {
+            .attribute = "state",
+            .type = CborAttrBooleanType,
+            .addr.boolean = &state,
+            .dflt.boolean = false
+        },
+        [1] = {
+        }
+    };
+
+    len = coap_get_payload(request->packet, &data);
+    if (cbor_read_flat_attrs(data, len, attrs)) {
+        oc_send_response(request, OC_STATUS_BAD_REQUEST);
+    } else {
+        hal_gpio_write(LED_BLINK_PIN, state == true);
+        oc_send_response(request, OC_STATUS_CHANGED);
+    }
+
+}
+
+static void
 omgr_app_init(void)
 {
+    oc_resource_t *res;
+
     oc_init_platform("MyNewt", NULL, NULL);
     oc_add_device("/oic/d", "oic.d.light", "MynewtLed", "1.0", "1.0", NULL,
                   NULL);
+
+    res = oc_new_resource("/light/1", 1, 0);
+    oc_resource_bind_resource_type(res, "oic.r.light");
+    oc_resource_bind_resource_interface(res, OC_IF_RW);
+    oc_resource_set_default_interface(res, OC_IF_RW);
+
+    oc_resource_set_discoverable(res);
+    oc_resource_set_periodic_observable(res, 1);
+    oc_resource_set_request_handler(res, OC_GET, app_get_light);
+    oc_resource_set_request_handler(res, OC_PUT, app_set_light);
+    oc_add_resource(res);
+
 }
 
 static const oc_handler_t omgr_oc_handler = {
@@ -333,6 +400,9 @@ main(void)
     rc = ble_svc_gap_device_name_set("pi");
     assert(rc == 0);
 
+    /* Our light resource */
+    hal_gpio_init_out(LED_BLINK_PIN, 1);
+
     /* Start the OS */
     os_start();