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 2017/03/07 00:04:56 UTC

[01/50] incubator-mynewt-core git commit: MYNEWT-630: Connection supervision timeout with high throughput

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/1_0_0_dev [created] cdcfc86fd


MYNEWT-630: Connection supervision timeout with high throughput

The issue was found to be an error in the os scheduler code.
If the PendSV handler was interrupted at a certain point when
we were checking to see if a context switch could occur, the
code is os_sched would think no context switch was necessary.

This is now fixed and the high throughput test has been running
for quite some time now with no disconnect.


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

Branch: refs/heads/1_0_0_dev
Commit: b6bee9ed12356aab34465cb03b490620ee062149
Parents: 4001f7a
Author: William San Filippo <wi...@runtime.io>
Authored: Fri Feb 24 20:19:42 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:47:21 2017 -0800

----------------------------------------------------------------------
 kernel/os/src/os_sched.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b6bee9ed/kernel/os/src/os_sched.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_sched.c b/kernel/os/src/os_sched.c
index 0cbe615..bb710ba 100644
--- a/kernel/os/src/os_sched.c
+++ b/kernel/os/src/os_sched.c
@@ -83,16 +83,11 @@ err:
 void
 os_sched_ctx_sw_hook(struct os_task *next_t)
 {
-    if (g_current_task == next_t) {
-        return;
-    }
-
     next_t->t_ctx_sw_cnt++;
     g_current_task->t_run_time += g_os_time - g_os_last_ctx_sw_time;
     g_os_last_ctx_sw_time = g_os_time;
 }
 
-
 /**
  * os sched get current task
  *
@@ -143,9 +138,7 @@ os_sched(struct os_task *next_t)
         next_t = os_sched_next_task();
     }
 
-    if (next_t != g_current_task) {
-        os_arch_ctx_sw(next_t);
-    }
+    os_arch_ctx_sw(next_t);
 
     OS_EXIT_CRITICAL(sr);
 }


[05/50] incubator-mynewt-core git commit: net/oic; notifications were not working. memset() in coap_receive_packet() was overwriting too many bytes, running into observer memory pool area.

Posted by ma...@apache.org.
net/oic; notifications were not working.
memset() in coap_receive_packet() was overwriting too many bytes,
running into observer memory pool area.


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

Branch: refs/heads/1_0_0_dev
Commit: 4f154cd3cc41ad2822c4cc3338f4575e4a6da7d3
Parents: 89731c6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Feb 27 14:24:48 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:02 2017 -0800

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


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f154cd3/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 17df8f8..30d72e5 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -555,7 +555,7 @@ coap_parse_message(struct coap_packet_rx *pkt, struct os_mbuf **mp)
 
     m = *mp;
     /* initialize packet */
-    memset(pkt, 0, sizeof(coap_packet_t));
+    memset(pkt, 0, sizeof(*pkt));
 
     STATS_INC(coap_stats, iframe);
 


[18/50] incubator-mynewt-core git commit: MYNEWT-652; net/oic - remove check of OC_PERIODIC when deciding whether to send notify or not.

Posted by ma...@apache.org.
MYNEWT-652; net/oic - remove check of OC_PERIODIC when deciding
whether to send notify or not.


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

Branch: refs/heads/1_0_0_dev
Commit: b48c0bcb513be06038c2f3b62800807f7131a5a2
Parents: 5ea6d72
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Mar 2 14:41:13 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:01 2017 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/observe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b48c0bcb/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 24ddd2a..ed88682 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -206,7 +206,7 @@ coap_notify_observers(oc_resource_t *resource,
         num_observers = resource->num_observers;
     }
     response.separate_response = 0;
-    if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
+    if (!response_buf && resource) {
         OC_LOG_DEBUG("coap_notify_observers: Issue GET request to resource\n");
         /* performing GET on the resource */
         m = os_msys_get_pkthdr(0, 0);


[11/50] incubator-mynewt-core git commit: MYNEWT-647 Changes to NMP over OIC scheme

Posted by ma...@apache.org.
MYNEWT-647 Changes to NMP over OIC scheme

This commit addresses the following three issues with NMP over OIC (OMP):

1. Parts of NMP header missing from OMP responses.  This causes problems
when multiplexing OMP among many target devices.

2. Parts of the NMP header are scattered in a few different places.
This works, but it makes it difficult to debug packet traces.

3. NMP errors get lost in translation.  Instead of an NMP message with
an error code, the OMP server sends back a generic "Bad Request" OIC
message.

***** Current Scheme

*** Requests

The NMP op is indicated by the OIC op:
NMP read <=> OIC get
NMP write <=> OIC put

The NMP group and ID are indicated as CoAP URI Query options:

    gr=<group>
    id=<id>

The remaining NMP header fields, seq and flags, are not present.

The NMP payload is the entire CoAP request body. This is identical to the body
of a plain NMP request.

*** Responses

The NMP header is not present. The NMP op is indicated in the payload (see
below), but other header fields cannot be inferred.

Payload consists of a single CBOR key-value pair. For read responses, the key
is "r"; for write responses, the key is "w". The value is a second CBOR map
containing the actual NMP response fields.

Errors encountered during processing of NMP requests are reported via OIC error
responses (bad request, internal server error).

***** Proposed Scheme

*** Requests

    * The OIC op is always the same: put.

    * No URI Query CoAP options.

    * The NMP header is included in the payload as a key-value pair (key="_h").
      This pair is in the root map of the request and is a sibling of the other
      request fields. The value of this pair is the big-endian eight-byte NMP
      header with a length field of 0.

*** Responses

    * As with requests, the NMP header is included in the payload as a
      key-value pair (key="_h").

    * No "r" or "w" field. The response fields are inserted into the root map
      as a sibling of the "_h" pair.

    * Errors encountered during processing of NMP requests are reported
      identically to other NMP responses (embedded NMP response).

*** Notes

    * Keys that start with an underscore are reserved to the OIC manager
      protocol (e.g., "_h"). NMP requests and responses must not name any of
      their fields with a leading underscore.


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

Branch: refs/heads/1_0_0_dev
Commit: 1209a410be00214e99604aef112aa4c7936213b9
Parents: 77b881d
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 17:41:21 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:56 2017 -0800

----------------------------------------------------------------------
 mgmt/mgmt/include/mgmt/mgmt.h          |  24 ++-
 mgmt/mgmt/src/mgmt.c                   |  22 ++-
 mgmt/newtmgr/include/newtmgr/newtmgr.h |  21 ---
 mgmt/oicmgr/src/oicmgr.c               | 238 ++++++++++++++++++----------
 4 files changed, 192 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1209a410/mgmt/mgmt/include/mgmt/mgmt.h
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/include/mgmt/mgmt.h b/mgmt/mgmt/include/mgmt/mgmt.h
index 9b79723..3c402f2 100644
--- a/mgmt/mgmt/include/mgmt/mgmt.h
+++ b/mgmt/mgmt/include/mgmt/mgmt.h
@@ -36,6 +36,10 @@ extern "C" {
 #define STR(x) #x
 #endif
 
+#define NMGR_OP_READ            (0)
+#define NMGR_OP_READ_RSP        (1)
+#define NMGR_OP_WRITE           (2)
+#define NMGR_OP_WRITE_RSP       (3)
 
 /* First 64 groups are reserved for system level newtmgr commands.
  * Per-user commands are then defined after group 64.
@@ -63,6 +67,24 @@ extern "C" {
 #define MGMT_ERR_EBADSTATE  (6)     /* Current state disallows command. */
 #define MGMT_ERR_EPERUSER   (256)
 
+#define NMGR_HDR_SIZE           (8)
+
+struct nmgr_hdr {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
+    uint8_t  _res1:5;
+#endif
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+    uint8_t  _res1:5;
+    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
+#endif
+    uint8_t  nh_flags;          /* XXX reserved for future flags */
+    uint16_t nh_len;            /* length of the payload */
+    uint16_t nh_group;          /* NMGR_GROUP_XXX */
+    uint8_t  nh_seq;            /* sequence number */
+    uint8_t  nh_id;             /* message ID within group */
+};
+
 struct mgmt_cbuf;
 
 typedef int (*mgmt_handler_func_t)(struct mgmt_cbuf *);
@@ -85,7 +107,7 @@ struct mgmt_group {
             sizeof(struct mgmt_handler));
 
 int mgmt_group_register(struct mgmt_group *group);
-void mgmt_cbuf_setoerr(struct mgmt_cbuf *njb, int errcode);
+int mgmt_cbuf_setoerr(struct mgmt_cbuf *njb, int errcode);
 const struct mgmt_handler *mgmt_find_handler(uint16_t group_id,
   uint16_t handler_id);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1209a410/mgmt/mgmt/src/mgmt.c
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/src/mgmt.c b/mgmt/mgmt/src/mgmt.c
index 4ac232a..c1a2a1e 100644
--- a/mgmt/mgmt/src/mgmt.c
+++ b/mgmt/mgmt/src/mgmt.c
@@ -137,14 +137,20 @@ err:
     return (NULL);
 }
 
-void
+int
 mgmt_cbuf_setoerr(struct mgmt_cbuf *cb, int errcode)
 {
-    CborEncoder *penc = &cb->encoder;
-    CborError g_err = CborNoError;
-    CborEncoder rsp;
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, errcode);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    int rc;
+
+    rc = cbor_encode_text_stringz(&cb->encoder, "rc");
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = cbor_encode_int(&cb->encoder, errcode);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1209a410/mgmt/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/include/newtmgr/newtmgr.h b/mgmt/newtmgr/include/newtmgr/newtmgr.h
index 50deb15..1cf314d 100644
--- a/mgmt/newtmgr/include/newtmgr/newtmgr.h
+++ b/mgmt/newtmgr/include/newtmgr/newtmgr.h
@@ -29,27 +29,6 @@
 extern "C" {
 #endif
 
-#define NMGR_OP_READ            (0)
-#define NMGR_OP_READ_RSP        (1)
-#define NMGR_OP_WRITE           (2)
-#define NMGR_OP_WRITE_RSP       (3)
-
-struct nmgr_hdr {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
-    uint8_t  _res1:5;
-#endif
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-    uint8_t  _res1:5;
-    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
-#endif
-    uint8_t  nh_flags;          /* XXX reserved for future flags */
-    uint16_t nh_len;            /* length of the payload */
-    uint16_t nh_group;          /* NMGR_GROUP_XXX */
-    uint8_t  nh_seq;            /* sequence number */
-    uint8_t  nh_id;             /* message ID within group */
-};
-
 struct nmgr_transport;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1209a410/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index d2110ef..d7d3591 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -22,6 +22,7 @@
 
 #include <os/os.h>
 #include <os/endian.h>
+#include <defs/error.h>
 
 #include <assert.h>
 #include <string.h>
@@ -52,9 +53,6 @@ static struct omgr_state omgr_state = {
     .os_event.ev_cb = omgr_event_start,
 };
 
-static void omgr_oic_get(oc_request_t *request, oc_interface_mask_t interface);
-static void omgr_oic_put(oc_request_t *request, oc_interface_mask_t interface);
-
 struct os_eventq *
 mgmt_evq_get(void)
 {
@@ -67,124 +65,199 @@ mgmt_evq_set(struct os_eventq *evq)
     os_eventq_designate(&omgr_state.os_evq, evq, &omgr_state.os_event);
 }
 
-static const struct mgmt_handler *
-omgr_find_handler(const char *q, int qlen)
+static int
+omgr_oic_read_hdr(struct CborValue *cv, struct nmgr_hdr *out_hdr)
 {
-    char id_str[8];
-    int grp = -1;
-    int id = -1;
-    char *str;
-    char *eptr;
-    int slen;
-
-    slen = oc_ri_get_query_value(q, qlen, "gr", &str);
-    if (slen > 0 && slen < sizeof(id_str) - 1) {
-        memcpy(id_str, str, slen);
-        id_str[slen] = '\0';
-        grp = strtoul(id_str, &eptr, 0);
-        if (*eptr != '\0') {
-            return NULL;
-        }
+    size_t hlen;
+    int rc;
+
+    struct cbor_attr_t attrs[] = {
+        [0] = {
+            .attribute = "_h",
+            .type = CborAttrByteStringType,
+            .addr.bytestring.data = (void *)out_hdr,
+            .addr.bytestring.len = &hlen,
+            .nodefault = 1,
+            .len = sizeof *out_hdr,
+        },
+        [1] = { 0 }
+    };
+
+    rc = cbor_read_object(cv, attrs);
+    if (rc != 0 || hlen != sizeof *out_hdr) {
+        return MGMT_ERR_EINVAL;
     }
-    slen = oc_ri_get_query_value(q, qlen, "id", &str);
-    if (slen > 0 && slen < sizeof(id_str) - 1) {
-        memcpy(id_str, str, slen);
-        id_str[slen] = '\0';
-        id = strtoul(id_str, &eptr, 0);
-        if (*eptr != '\0') {
-            return NULL;
-        }
+
+    out_hdr->nh_len = ntohs(out_hdr->nh_len);
+    out_hdr->nh_group = ntohs(out_hdr->nh_group);
+
+    return 0;
+}
+
+static int
+omgr_encode_nmp_hdr(struct CborEncoder *enc, struct nmgr_hdr hdr)
+{
+    int rc;
+
+    rc = cbor_encode_text_string(enc, "_h", 2);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    hdr.nh_len = htons(hdr.nh_len);
+    hdr.nh_group = htons(hdr.nh_group);
+
+    /* Encode the NMP header in the response. */
+    rc = cbor_encode_byte_string(enc, (void *)&hdr, sizeof hdr);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    return 0;
+}
+
+static int
+omgr_send_err_rsp(struct CborEncoder *enc, const struct nmgr_hdr *hdr,
+                  int nmp_status)
+{
+    int rc;
+
+    rc = omgr_encode_nmp_hdr(enc, *hdr);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = cbor_encode_text_stringz(enc, "rc");
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    rc = cbor_encode_int(enc, nmp_status);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
     }
-    return mgmt_find_handler(grp, id);
+
+    return 0;
 }
 
 static void
-omgr_oic_op(oc_request_t *req, oc_interface_mask_t mask, int isset)
+omgr_oic_put(oc_request_t *req, oc_interface_mask_t mask)
 {
     struct omgr_state *o = &omgr_state;
     const struct mgmt_handler *handler;
     uint16_t data_off;
     struct os_mbuf *m;
     int rc = 0;
-    extern CborEncoder g_encoder;
+    struct nmgr_hdr hdr;
+    int rsp_hdr_filled = 0;
 
-    if (!req->query_len) {
-        goto bad_req;
-    }
-
-    handler = omgr_find_handler(req->query, req->query_len);
-    if (!handler) {
-        goto bad_req;
-    }
+    coap_get_payload(req->packet, &m, &data_off);
 
-    rc = coap_get_payload(req->packet, &m, &data_off);
     cbor_mbuf_reader_init(&o->os_cbuf.ob_reader, m, data_off);
-
     cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser,
                      &o->os_cbuf.ob_mj.it);
 
-    /* start generating the CBOR OUTPUT */
-    /* this is worth a quick note.  We are encoding CBOR within CBOR, so we
-     * need to use the same encoder as ocf stack.  We are using their global
-     * encoder g_encoder which they intialized before this function is called.
-     * But we can't call their macros here as it won't use the right mape
-     * encoder (ob_mj) */
+    rc = omgr_oic_read_hdr(&o->os_cbuf.ob_mj.it, &hdr);
+    if (rc != 0) {
+        rc = MGMT_ERR_EINVAL;
+        goto done;
+    }
+
+    /* Convert request header to response header to be sent. */
+    switch (hdr.nh_op) {
+    case NMGR_OP_READ:
+        hdr.nh_op = NMGR_OP_READ_RSP;
+        break;
+
+    case NMGR_OP_WRITE:
+        hdr.nh_op = NMGR_OP_WRITE_RSP;
+        break;
+
+    default:
+        goto done;
+    }
+    rsp_hdr_filled = 1;
+
+    /* Begin root map in response. */
     cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder,
                             CborIndefiniteLength);
 
+    handler = mgmt_find_handler(hdr.nh_group, hdr.nh_id);
+    if (handler == NULL) {
+        rc = MGMT_ERR_ENOENT;
+        goto done;
+    }
+
+    cbor_mbuf_reader_init(&o->os_cbuf.ob_reader, m, data_off);
+    cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser,
+                     &o->os_cbuf.ob_mj.it);
+
     switch (mask) {
     case OC_IF_BASELINE:
         oc_process_baseline_interface(req->resource);
+        /* Fallthrough */
+
     case OC_IF_RW:
-        if (!isset) {
-            cbor_encode_text_string(&root_map, "r", 1);
-            if (handler->mh_read) {
-                rc = handler->mh_read(&o->os_cbuf.ob_mj);
+        switch (hdr.nh_op) {
+        case NMGR_OP_READ_RSP:
+            if (handler->mh_read == NULL) {
+                rc = MGMT_ERR_ENOENT;
             } else {
-                goto bad_req;
+                rc = handler->mh_read(&o->os_cbuf.ob_mj);
             }
-        } else {
-            cbor_encode_text_string(&root_map, "w", 1);
-            if (handler->mh_write) {
-                rc = handler->mh_write(&o->os_cbuf.ob_mj);
+            break;
+
+        case NMGR_OP_WRITE_RSP:
+            if (handler->mh_write == NULL) {
+                rc = MGMT_ERR_ENOENT;
             } else {
-                goto bad_req;
+                rc = handler->mh_write(&o->os_cbuf.ob_mj);
             }
+            break;
+
+        default:
+            rc = MGMT_ERR_EINVAL;
+            break;
         }
-        if (rc) {
-            goto bad_req;
+        if (rc != 0) {
+            goto done;
+        }
+
+        /* Encode the NMP header in the response. */
+        rc = omgr_encode_nmp_hdr(&o->os_cbuf.ob_mj.encoder, hdr);
+        if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
+            goto done;
         }
         break;
+
     default:
         break;
     }
 
-    cbor_encoder_close_container(&g_encoder, &o->os_cbuf.ob_mj.encoder);
-    oc_send_response(req, OC_STATUS_OK);
+    rc = 0;
 
-    return;
-bad_req:
-    /*
-     * XXXX might send partially constructed response as payload
-     */
-    if (rc == MGMT_ERR_ENOMEM) {
-        rc = OC_STATUS_INTERNAL_SERVER_ERROR;
-    } else {
-        rc = OC_STATUS_BAD_REQUEST;
-    }
-    oc_send_response(req, rc);
-}
+done:
+    if (rc != 0) {
+        if (rsp_hdr_filled) {
+            rc = omgr_send_err_rsp(&g_encoder, &hdr, rc);
+        }
+        switch (rc) {
+        case 0:
+            break;
 
-static void
-omgr_oic_get(oc_request_t *req, oc_interface_mask_t mask)
-{
-    omgr_oic_op(req, mask, 0);
-}
+        case MGMT_ERR_ENOMEM:
+            rc = OC_STATUS_INTERNAL_SERVER_ERROR;
+            break;
 
-static void
-omgr_oic_put(oc_request_t *req, oc_interface_mask_t mask)
-{
-    omgr_oic_op(req, mask, 1);
+        default:
+            rc = OC_STATUS_BAD_REQUEST;
+            break;
+        }
+    }
+
+    cbor_encoder_close_container(&g_encoder, &o->os_cbuf.ob_mj.encoder);
+    oc_send_response(req, rc);
 }
 
 static void
@@ -204,7 +277,6 @@ omgr_event_start(struct os_event *ev)
     oc_resource_bind_resource_interface(res, mode);
     oc_resource_set_default_interface(res, mode);
     oc_resource_set_discoverable(res);
-    oc_resource_set_request_handler(res, OC_GET, omgr_oic_get);
     oc_resource_set_request_handler(res, OC_PUT, omgr_oic_put);
     oc_add_resource(res);
 }


[04/50] incubator-mynewt-core git commit: net/oic; fix mbuf leak. Noticed in inspection.

Posted by ma...@apache.org.
net/oic; fix mbuf leak. Noticed in inspection.


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

Branch: refs/heads/1_0_0_dev
Commit: 89731c6eaa4ebb33779eaf4e8da9ce18a219706f
Parents: 8959ce9
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Feb 27 14:23:50 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:47:51 2017 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/observe.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/89731c6e/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 234b2da..24ddd2a 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -224,6 +224,7 @@ coap_notify_observers(oc_resource_t *resource,
         response_buf = &response_buffer;
         if (response_buf->code == OC_IGNORE) {
             OC_LOG_ERROR("coap_notify_observers: Resource ignored request\n");
+            os_mbuf_free_chain(m);
             return num_observers;
         }
     }


[27/50] incubator-mynewt-core git commit: nimble/l2cap: Fix L2CAP LE CoC disconnection handling

Posted by ma...@apache.org.
nimble/l2cap: Fix L2CAP LE CoC disconnection handling

This patch fixes mess around scid/dcid on L2CAP disconnection
request


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

Branch: refs/heads/1_0_0_dev
Commit: 1759bdfe9eef2770a9b60de3f1d1bc89d95312cc
Parents: 9597dc7
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:37:39 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:18 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1759bdfe/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index a1a3399..9292137 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -877,15 +877,21 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
 
     req = (struct ble_l2cap_sig_disc_req *) (*om)->om_data;
 
+    /* Let's find matching channel. Note that destination CID in the request
+     * is from peer perspective. It is source CID from nimble perspective 
+     */
     chan = ble_hs_conn_chan_find(conn, le16toh(req->dcid));
-    if (!chan || (le16toh(req->scid) != chan->scid)) {
+    if (!chan || (le16toh(req->scid) != chan->dcid)) {
         os_mbuf_free_chain(txom);
         ble_hs_unlock();
         return 0;
     }
 
-    rsp->dcid = htole16(chan->dcid);
-    rsp->scid = htole16(chan->scid);
+    /* Note that in the response destination CID is form peer perspective and
+     * it is source CID from nimble perspective.
+     */
+    rsp->dcid = htole16(chan->scid);
+    rsp->scid = htole16(chan->dcid);
 
     ble_l2cap_event_coc_disconnected(chan);
 


[08/50] incubator-mynewt-core git commit: MYNEWT-527; add wrapper for shell scripts when running on Windows.

Posted by ma...@apache.org.
MYNEWT-527; add wrapper for shell scripts when running on Windows.


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

Branch: refs/heads/1_0_0_dev
Commit: 9cd6ba521d330830fe59aae1cd9d2ef19e48e48e
Parents: b41f55d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Feb 27 20:59:50 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:28 2017 -0800

----------------------------------------------------------------------
 hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd           | 3 +++
 hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd        | 3 +++
 hw/bsp/ada_feather_nrf52/bsp.yml                               | 2 ++
 hw/bsp/arduino_primo_nrf52/bsp.yml                             | 2 ++
 hw/bsp/arduino_primo_nrf52/primo_debug.cmd                     | 3 +++
 hw/bsp/arduino_primo_nrf52/primo_download.cmd                  | 3 +++
 hw/bsp/bbc_microbit/bsp.yml                                    | 6 ++++--
 hw/bsp/bbc_microbit/microbit_debug.cmd                         | 3 +++
 hw/bsp/bbc_microbit/microbit_download.cmd                      | 3 +++
 hw/bsp/bmd200/bsp.yml                                          | 2 ++
 hw/bsp/bmd200/nrf51dk_debug.cmd                                | 3 +++
 hw/bsp/bmd200/nrf51dk_download.cmd                             | 3 +++
 hw/bsp/bmd300eval/bmd300eval_debug.cmd                         | 3 +++
 hw/bsp/bmd300eval/bmd300eval_download.cmd                      | 3 +++
 hw/bsp/bmd300eval/bsp.yml                                      | 2 ++
 hw/bsp/frdm-k64f/bsp.yml                                       | 2 ++
 hw/bsp/frdm-k64f/frdm-k64_debug.cmd                            | 3 +++
 hw/bsp/frdm-k64f/frdm-k64_download.cmd                         | 3 +++
 hw/bsp/nrf51-arduino_101/bsp.yml                               | 2 ++
 hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd             | 3 +++
 hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd          | 3 +++
 hw/bsp/nrf51dk-16kbram/bsp.yml                                 | 2 ++
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd               | 3 +++
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd            | 3 +++
 hw/bsp/nrf51dk/bsp.yml                                         | 2 ++
 hw/bsp/nrf51dk/nrf51dk_debug.cmd                               | 3 +++
 hw/bsp/nrf51dk/nrf51dk_download.cmd                            | 3 +++
 hw/bsp/nrf52840pdk/bsp.yml                                     | 2 ++
 hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd                       | 3 +++
 hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd                    | 3 +++
 hw/bsp/nrf52dk/bsp.yml                                         | 2 ++
 hw/bsp/nrf52dk/nrf52dk_debug.cmd                               | 3 +++
 hw/bsp/nrf52dk/nrf52dk_download.cmd                            | 3 +++
 hw/bsp/nucleo-f401re/bsp.yml                                   | 2 ++
 hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd                   | 3 +++
 hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd                | 3 +++
 hw/bsp/olimex_stm32-e407_devboard/bsp.yml                      | 2 ++
 .../olimex_stm32-e407_devboard_debug.cmd                       | 3 +++
 .../olimex_stm32-e407_devboard_download.cmd                    | 3 +++
 hw/bsp/rb-nano2/bsp.yml                                        | 2 ++
 hw/bsp/rb-nano2/rb-nano2_debug.cmd                             | 3 +++
 hw/bsp/rb-nano2/rb-nano2_download.cmd                          | 3 +++
 hw/bsp/stm32f4discovery/bsp.yml                                | 2 ++
 hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd             | 3 +++
 hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd          | 3 +++
 hw/bsp/usbmkw41z/bsp.yml                                       | 2 ++
 hw/bsp/usbmkw41z/usbkw41z_debug.cmd                            | 3 +++
 hw/bsp/usbmkw41z/usbkw41z_download.cmd                         | 3 +++
 48 files changed, 130 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/ada_feather_nrf52/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/bsp.yml b/hw/bsp/ada_feather_nrf52/bsp.yml
index 80c9a5d..3721c2b 100644
--- a/hw/bsp/ada_feather_nrf52/bsp.yml
+++ b/hw/bsp/ada_feather_nrf52/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld"
 bsp.downloadscript: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh"
 bsp.debugscript: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/arduino_primo_nrf52/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/bsp.yml b/hw/bsp/arduino_primo_nrf52/bsp.yml
index a24479b..15928c7 100644
--- a/hw/bsp/arduino_primo_nrf52/bsp.yml
+++ b/hw/bsp/arduino_primo_nrf52/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/arduino_primo_nrf52/split-primo.ld"
 bsp.downloadscript: "hw/bsp/arduino_primo_nrf52/primo_download.sh"
 bsp.debugscript: "hw/bsp/arduino_primo_nrf52/primo_debug.sh"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/arduino_primo_nrf52/primo_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/arduino_primo_nrf52/primo_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/arduino_primo_nrf52/primo_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/primo_debug.cmd b/hw/bsp/arduino_primo_nrf52/primo_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/arduino_primo_nrf52/primo_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/arduino_primo_nrf52/primo_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/primo_download.cmd b/hw/bsp/arduino_primo_nrf52/primo_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/arduino_primo_nrf52/primo_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bbc_microbit/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bbc_microbit/bsp.yml b/hw/bsp/bbc_microbit/bsp.yml
index ee9bdf1..c344752 100644
--- a/hw/bsp/bbc_microbit/bsp.yml
+++ b/hw/bsp/bbc_microbit/bsp.yml
@@ -26,8 +26,10 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/bsp/bbc_microbit/boot-nrf51xxac.ld"
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
 bsp.part2linkerscript: "hw/bsp/bbc_microbit/split-nrf51dk.ld"
-bsp.downloadscript: "hw/bsp/bbc_microbit/microbit_download.sh"
-bsp.debugscript: "hw/bsp/bbc_microbit/microbit_debug.sh"
+bsp.downloadscript: hw/bsp/bbc_microbit/microbit_download.sh
+bsp.debugscript: hw/bsp/bbc_microbit/microbit_debug.sh
+bsp.downloadscript.WINDOWS.OVERWRITE: hw/bsp/bbc_microbit/microbit_download.cmd
+bsp.debugscript.WINDOWS.OVERWRITE: hw/bsp/bbc_microbit/microbit_debug.cmd
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bbc_microbit/microbit_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bbc_microbit/microbit_debug.cmd b/hw/bsp/bbc_microbit/microbit_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bbc_microbit/microbit_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bbc_microbit/microbit_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bbc_microbit/microbit_download.cmd b/hw/bsp/bbc_microbit/microbit_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bbc_microbit/microbit_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd200/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd200/bsp.yml b/hw/bsp/bmd200/bsp.yml
index ed5b7b1..3fe1275 100644
--- a/hw/bsp/bmd200/bsp.yml
+++ b/hw/bsp/bmd200/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd200/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/bmd200/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/bmd200/nrf51dk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd200/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/bmd200/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd200/nrf51dk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd200/nrf51dk_debug.cmd b/hw/bsp/bmd200/nrf51dk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bmd200/nrf51dk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd200/nrf51dk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd200/nrf51dk_download.cmd b/hw/bsp/bmd200/nrf51dk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bmd200/nrf51dk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd300eval/bmd300eval_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bmd300eval_debug.cmd b/hw/bsp/bmd300eval/bmd300eval_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bmd300eval/bmd300eval_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd300eval/bmd300eval_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bmd300eval_download.cmd b/hw/bsp/bmd300eval/bmd300eval_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/bmd300eval/bmd300eval_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/bmd300eval/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bsp.yml b/hw/bsp/bmd300eval/bsp.yml
index 5f31de9..f3a9a5d 100644
--- a/hw/bsp/bmd300eval/bsp.yml
+++ b/hw/bsp/bmd300eval/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd300eval/split-bmd300eval.ld"
 bsp.downloadscript: "hw/bsp/bmd300eval/bmd300eval_download.sh"
 bsp.debugscript: "hw/bsp/bmd300eval/bmd300eval_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/frdm-k64f/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/frdm-k64f/bsp.yml b/hw/bsp/frdm-k64f/bsp.yml
index e1ef7d6..a771696 100644
--- a/hw/bsp/frdm-k64f/bsp.yml
+++ b/hw/bsp/frdm-k64f/bsp.yml
@@ -23,6 +23,8 @@ bsp.linkerscript: "hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld"
 bsp.linkerscript.BOOT_LOADER.OVERWRITE: "hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld"
 bsp.downloadscript: "hw/bsp/frdm-k64f/frdm-k64_download.sh"
 bsp.debugscript: "hw/bsp/frdm-k64f/frdm-k64_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/frdm-k64f/frdm-k64_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/frdm-k64f/frdm-k64_debug.cmd b/hw/bsp/frdm-k64f/frdm-k64_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/frdm-k64f/frdm-k64_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/frdm-k64f/frdm-k64_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/frdm-k64f/frdm-k64_download.cmd b/hw/bsp/frdm-k64f/frdm-k64_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/frdm-k64f/frdm-k64_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51-arduino_101/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/bsp.yml b/hw/bsp/nrf51-arduino_101/bsp.yml
index 00ecf5c..7a75151 100644
--- a/hw/bsp/nrf51-arduino_101/bsp.yml
+++ b/hw/bsp/nrf51-arduino_101/bsp.yml
@@ -27,6 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
 bsp.downloadscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd b/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd b/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk-16kbram/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/bsp.yml b/hw/bsp/nrf51dk-16kbram/bsp.yml
index 78ef8a7..94dd59f 100644
--- a/hw/bsp/nrf51dk-16kbram/bsp.yml
+++ b/hw/bsp/nrf51dk-16kbram/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk-16kbram/split-nrf51dk-16kbram.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/bsp.yml b/hw/bsp/nrf51dk/bsp.yml
index 5e78d60..247dc54 100644
--- a/hw/bsp/nrf51dk/bsp.yml
+++ b/hw/bsp/nrf51dk/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk/nrf51dk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk/nrf51dk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/nrf51dk_debug.cmd b/hw/bsp/nrf51dk/nrf51dk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51dk/nrf51dk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf51dk/nrf51dk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/nrf51dk_download.cmd b/hw/bsp/nrf51dk/nrf51dk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51dk/nrf51dk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52840pdk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/bsp.yml b/hw/bsp/nrf52840pdk/bsp.yml
index 16f878b..e168d57 100644
--- a/hw/bsp/nrf52840pdk/bsp.yml
+++ b/hw/bsp/nrf52840pdk/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52840pdk/split-nrf52840pdk.ld"
 bsp.downloadscript: "hw/bsp/nrf52840pdk/nrf52840pdk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd b/hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd b/hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/bsp.yml b/hw/bsp/nrf52dk/bsp.yml
index d0e5fc1..050c16a 100644
--- a/hw/bsp/nrf52dk/bsp.yml
+++ b/hw/bsp/nrf52dk/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52dk/split-nrf52dk.ld"
 bsp.downloadscript: "hw/bsp/nrf52dk/nrf52dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52dk/nrf52dk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52dk/nrf52dk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/nrf52dk_debug.cmd b/hw/bsp/nrf52dk/nrf52dk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf52dk/nrf52dk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nrf52dk/nrf52dk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/nrf52dk_download.cmd b/hw/bsp/nrf52dk/nrf52dk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf52dk/nrf52dk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nucleo-f401re/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/bsp.yml b/hw/bsp/nucleo-f401re/bsp.yml
index 73313b8..7610b47 100644
--- a/hw/bsp/nucleo-f401re/bsp.yml
+++ b/hw/bsp/nucleo-f401re/bsp.yml
@@ -27,6 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f401.ld"
 bsp.downloadscript: "hw/bsp/nucleo-f401re/nucleo-f401re_download.sh"
 bsp.debugscript: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd b/hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd b/hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
index 62a7899..478703b 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
+++ b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
@@ -27,6 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh"
 bsp.debugscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/rb-nano2/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/bsp.yml b/hw/bsp/rb-nano2/bsp.yml
index 4be5b52..c4fc926 100644
--- a/hw/bsp/rb-nano2/bsp.yml
+++ b/hw/bsp/rb-nano2/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/rb-nano2/split-rb-nano2.ld"
 bsp.downloadscript: "hw/bsp/rb-nano2/rb-nano2_download.sh"
 bsp.debugscript: "hw/bsp/rb-nano2/rb-nano2_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/rb-nano2/rb-nano2_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/rb-nano2_debug.cmd b/hw/bsp/rb-nano2/rb-nano2_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/rb-nano2/rb-nano2_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/rb-nano2/rb-nano2_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/rb-nano2_download.cmd b/hw/bsp/rb-nano2/rb-nano2_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/rb-nano2/rb-nano2_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/stm32f4discovery/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/bsp.yml b/hw/bsp/stm32f4discovery/bsp.yml
index 2e50d60..658cb21 100644
--- a/hw/bsp/stm32f4discovery/bsp.yml
+++ b/hw/bsp/stm32f4discovery/bsp.yml
@@ -27,6 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/stm32f4discovery/stm32f4discovery_download.sh"
 bsp.debugscript: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd b/hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/usbmkw41z/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/usbmkw41z/bsp.yml b/hw/bsp/usbmkw41z/bsp.yml
index 2084335..55e9ae7 100644
--- a/hw/bsp/usbmkw41z/bsp.yml
+++ b/hw/bsp/usbmkw41z/bsp.yml
@@ -26,6 +26,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/usbmkw41z/split-usbkw41z.ld"
 bsp.downloadscript: "hw/bsp/usbmkw41z/usbkw41z_download.sh"
 bsp.debugscript: "hw/bsp/usbmkw41z/usbkw41z_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/usbmkw41z/usbkw41z_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/usbmkw41z/usbkw41z_debug.cmd b/hw/bsp/usbmkw41z/usbkw41z_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/usbmkw41z/usbkw41z_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cd6ba52/hw/bsp/usbmkw41z/usbkw41z_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/usbmkw41z/usbkw41z_download.cmd b/hw/bsp/usbmkw41z/usbkw41z_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/usbmkw41z/usbkw41z_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"


[31/50] incubator-mynewt-core git commit: nimble/l2cap: Refactor handling L2CAP reject command

Posted by ma...@apache.org.
nimble/l2cap: Refactor handling L2CAP reject command

With this patch L2CAP reject command uses a new way of preparing
command and sending 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/79ed0c84
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/79ed0c84
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/79ed0c84

Branch: refs/heads/1_0_0_dev
Commit: 79ed0c8483eadc4cd429f6a51cbba48283a98284
Parents: 73705b0
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Feb 28 12:14:46 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:52 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c  | 40 +++++----------------------
 net/nimble/host/src/ble_l2cap_sig_priv.h |  1 +
 2 files changed, 8 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/79ed0c84/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index 189efd7..e6a7209 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -94,48 +94,22 @@ ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
     BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
     ble_l2cap_sig_hdr_swap(payload, src);
 }
-static void
-ble_l2cap_sig_reject_swap(struct ble_l2cap_sig_reject *dst,
-                          struct ble_l2cap_sig_reject *src)
-{
-    dst->reason = TOFROMLE16(src->reason);
-}
-
-static void
-ble_l2cap_sig_reject_write(void *payload, uint16_t len,
-                           struct ble_l2cap_sig_reject *src,
-                           void *data, int data_len)
-{
-    uint8_t *u8ptr;
-
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len);
-
-    ble_l2cap_sig_reject_swap(payload, src);
-
-    u8ptr = payload;
-    u8ptr += BLE_L2CAP_SIG_REJECT_MIN_SZ;
-    memcpy(u8ptr, data, data_len);
-}
 
 int
 ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason,
                         void *data, int data_len)
 {
-    struct ble_l2cap_sig_reject cmd;
+    struct ble_l2cap_sig_reject *cmd;
     struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_REJECT, id,
-                                BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
+    cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_REJECT, id,
+                           sizeof(*cmd) + data_len, &txom);
+    if (!cmd) {
+        return BLE_HS_ENOMEM;
     }
 
-    cmd.reason = reason;
-    ble_l2cap_sig_reject_write(payload_buf, txom->om_len, &cmd,
-                               data, data_len);
+    cmd->reason = htole16(reason);
+    memcpy(cmd->data, data, data_len);
 
     STATS_INC(ble_l2cap_stats, sig_rx);
     return ble_l2cap_sig_tx(conn_handle, txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/79ed0c84/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index f089dcb..ad3b846 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -39,6 +39,7 @@ struct ble_l2cap_sig_hdr {
 #define BLE_L2CAP_SIG_REJECT_MIN_SZ         2
 struct ble_l2cap_sig_reject {
     uint16_t reason;
+    uint8_t data[0];
 } __attribute__((packed));
 
 #define BLE_L2CAP_SIG_UPDATE_REQ_SZ         8


[49/50] incubator-mynewt-core git commit: microbit bsp: fix split linker script typo

Posted by ma...@apache.org.
microbit bsp: fix split linker script typo


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

Branch: refs/heads/1_0_0_dev
Commit: b490b7002e2657c3f92e010ffc31d77e431d1383
Parents: 6958839
Author: Jacob Rosenthal <ja...@gmail.com>
Authored: Sat Mar 4 13:59:24 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:54:35 2017 -0800

----------------------------------------------------------------------
 hw/bsp/bbc_microbit/bsp.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b490b700/hw/bsp/bbc_microbit/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bbc_microbit/bsp.yml b/hw/bsp/bbc_microbit/bsp.yml
index c344752..7a7063c 100644
--- a/hw/bsp/bbc_microbit/bsp.yml
+++ b/hw/bsp/bbc_microbit/bsp.yml
@@ -25,7 +25,7 @@ bsp.linkerscript:
 bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/bsp/bbc_microbit/boot-nrf51xxac.ld"
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
-bsp.part2linkerscript: "hw/bsp/bbc_microbit/split-nrf51dk.ld"
+bsp.part2linkerscript: "hw/bsp/bbc_microbit/split-microbit.ld"
 bsp.downloadscript: hw/bsp/bbc_microbit/microbit_download.sh
 bsp.debugscript: hw/bsp/bbc_microbit/microbit_debug.sh
 bsp.downloadscript.WINDOWS.OVERWRITE: hw/bsp/bbc_microbit/microbit_download.cmd


[22/50] incubator-mynewt-core git commit: bletiny: Add support to send data over L2CAP LE CoC

Posted by ma...@apache.org.
bletiny: Add support to send data over L2CAP LE CoC

With this patch user can send random data to specified CoC
channel with command:
 l2cap send conn=<conn_handle> idx=<coc idx> bytes=<num of bytes>


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

Branch: refs/heads/1_0_0_dev
Commit: c26d8c651f1a915be9dec0450f7d2040538115a4
Parents: 9bc81b1
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:07:58 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:37 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  1 +
 apps/bletiny/src/cmd.c     | 50 +++++++++++++++++++++++++++
 apps/bletiny/src/main.c    | 75 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c26d8c65/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 8d8ac64..cdaff14 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -193,6 +193,7 @@ int bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi);
 int bletiny_l2cap_create_srv(uint16_t psm);
 int bletiny_l2cap_connect(uint16_t conn, uint16_t psm);
 int bletiny_l2cap_disconnect(uint16_t conn, uint16_t idx);
+int bletiny_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
 #define BLETINY_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
 #define BLETINY_LOG(lvl, ...) \
     LOG_ ## lvl(&bletiny_log, BLETINY_LOG_MODULE, __VA_ARGS__)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c26d8c65/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 47ab379..45debc5 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1279,6 +1279,55 @@ cmd_l2cap_disconnect(int argc, char **argv)
     return bletiny_l2cap_disconnect(conn, idx);
 }
 
+static void
+bletiny_l2cap_send_help(void)
+{
+    console_printf("Available l2cap send commands: \n");
+    console_printf("\thelp\n");
+    console_printf("Available l2cap disconnect params: \n");
+    help_cmd_uint16("conn");
+    help_cmd_uint16("idx");
+    help_cmd_uint16("bytes");
+    console_printf("\n Use 'b show coc' to get conn and idx parameters.\n");
+    console_printf("bytes stands for number of bytes to send .\n");
+}
+
+static int
+cmd_l2cap_send(int argc, char **argv)
+{
+    uint16_t conn;
+    uint16_t idx;
+    uint16_t bytes;
+    int rc;
+
+    if (argc > 1 && strcmp(argv[1], "help") == 0) {
+        bletiny_l2cap_send_help();
+        return 0;
+    }
+    conn = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'conn' parameter\n");
+       help_cmd_uint16("conn");
+       return rc;
+    }
+
+    idx = parse_arg_uint16("idx", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'idx' parameter\n");
+       help_cmd_uint16("idx");
+       return rc;
+    }
+
+    bytes = parse_arg_uint16("bytes", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'bytes' parameter\n");
+       help_cmd_uint16("bytes");
+       return rc;
+    }
+
+    return bletiny_l2cap_send(conn, idx, bytes);
+}
+
 static const struct cmd_entry cmd_l2cap_entries[];
 
 static int
@@ -1298,6 +1347,7 @@ static const struct cmd_entry cmd_l2cap_entries[] = {
     { "create_srv", cmd_l2cap_create_srv },
     { "connect", cmd_l2cap_connect },
     { "disconnect", cmd_l2cap_disconnect },
+    { "send", cmd_l2cap_send },
     { "help", cmd_l2cap_help },
     { NULL, NULL }
 };

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c26d8c65/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 52cf7e6..b8f1e51 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1756,6 +1756,81 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
 #endif
 }
 
+int
+bletiny_l2cap_send(uint16_t conn_handle, uint16_t idx, uint16_t bytes)
+{
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
+    console_printf("BLE L2CAP LE COC not supported.");
+    console_printf(" Configure nimble host to enable it\n");
+    return 0;
+#else
+
+    struct bletiny_conn *conn;
+    struct bletiny_l2cap_coc *coc;
+    struct os_mbuf *sdu_tx;
+    uint8_t b[] = {0x00, 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, 0x99};
+    int i;
+    int rc;
+
+    console_printf("conn=%d, idx=%d, bytes=%d\n", conn_handle, idx, bytes);
+
+    conn = bletiny_conn_find(conn_handle);
+    if (conn == NULL) {
+        console_printf("conn=%d does not exist\n", conn_handle);
+        return 0;
+    }
+
+    i = 0;
+    SLIST_FOREACH(coc, &conn->coc_list, next) {
+        if (i == idx) {
+            break;
+        }
+        i++;
+    }
+    if (coc == NULL) {
+        console_printf("Are you sure your channel exist?\n");
+        return 0;
+    }
+
+    sdu_tx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
+    if (sdu_tx == NULL) {
+        console_printf("No memory in the test sdu pool\n");
+        return 0;
+    }
+
+    /* For the testing purpose we fill up buffer with known data, easy
+     * to validate on other side. In this loop we add as many full chunks as we
+     * can
+     */
+    for (i = 0; i < bytes / sizeof(b); i++) {
+        rc = os_mbuf_append(sdu_tx, b, sizeof(b));
+        if (rc) {
+            console_printf("Cannot append data %i !\n", i);
+            os_mbuf_free_chain(sdu_tx);
+            return rc;
+        }
+    }
+
+    /* Here we add the rest < sizeof(b) */
+    rc = os_mbuf_append(sdu_tx, b, bytes - (sizeof(b) * i));
+    if (rc) {
+        console_printf("Cannot append data %i !\n", i);
+        os_mbuf_free_chain(sdu_tx);
+        return rc;
+    }
+
+    rc = ble_l2cap_send(coc->chan, sdu_tx);
+    if (rc) {
+        console_printf("Could not send data rc=%d\n", rc);
+        if (rc == BLE_HS_EBUSY) {
+            os_mbuf_free_chain(sdu_tx);
+        }
+    }
+
+    return rc;
+
+#endif
+}
 /**
  * main
  *


[02/50] incubator-mynewt-core git commit: Initial cut at adafruit feather nrf52 bsp.

Posted by ma...@apache.org.
Initial cut at adafruit feather nrf52 bsp.


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

Branch: refs/heads/1_0_0_dev
Commit: 24956966c94fe01b4ddf0157d2440b77b3052329
Parents: b6bee9e
Author: William San Filippo <wi...@runtime.io>
Authored: Sun Feb 26 19:22:43 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:47:31 2017 -0800

----------------------------------------------------------------------
 .../ada_feather_nrf52_debug.sh                  |  46 +++
 .../ada_feather_nrf52_download.sh               |  40 +++
 .../ada_feather_nrf52_no_boot.ld                | 191 ++++++++++++
 hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld      |  25 ++
 hw/bsp/ada_feather_nrf52/bsp.yml                |  62 ++++
 hw/bsp/ada_feather_nrf52/include/bsp/bsp.h      |  64 ++++
 .../ada_feather_nrf52/include/bsp/cmsis_nvic.h  |  29 ++
 hw/bsp/ada_feather_nrf52/nrf52xxaa.ld           |  25 ++
 hw/bsp/ada_feather_nrf52/pkg.yml                |  96 ++++++
 .../split_ada_feather_nrf52.ld                  | 208 +++++++++++++
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      | 299 +++++++++++++++++++
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    | 163 ++++++++++
 hw/bsp/ada_feather_nrf52/src/hal_bsp.c          | 216 ++++++++++++++
 hw/bsp/ada_feather_nrf52/src/sbrk.c             |  59 ++++
 hw/bsp/ada_feather_nrf52/syscfg.yml             |  97 ++++++
 15 files changed, 1620 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh
new file mode 100755
index 0000000..17b980d
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Called with following variables set:
+#  - CORE_PATH is absolute path to @apache-mynewt-core
+#  - BSP_PATH is absolute path to hw/bsp/bsp_name
+#  - BIN_BASENAME is the path to prefix to target binary,
+#    .elf appended to name is the ELF file
+#  - FEATURES holds the target features string
+#  - EXTRA_JTAG_CMD holds extra parameters to pass to jtag software
+#  - RESET set if target should be reset when attaching
+#  - NO_GDB set if we should not start gdb to debug
+#
+
+. $CORE_PATH/hw/scripts/jlink.sh
+
+FILE_NAME=$BIN_BASENAME.elf
+
+if [ $# -gt 2 ]; then
+    SPLIT_ELF_NAME=$3.elf
+    # TODO -- this magic number 0x42000 is the location of the second image
+    # slot. we should either get this from a flash map file or somehow learn
+    # this from the image itself
+    EXTRA_GDB_CMDS="add-symbol-file $SPLIT_ELF_NAME 0x8000 -readnow"
+fi
+
+JLINK_DEV="nRF52"
+
+jlink_debug
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh
new file mode 100755
index 0000000..08d45b4
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Called with following variables set:
+#  - CORE_PATH is absolute path to @apache-mynewt-core
+#  - BSP_PATH is absolute path to hw/bsp/bsp_name
+#  - BIN_BASENAME is the path to prefix to target binary,
+#    .elf appended to name is the ELF file
+#  - IMAGE_SLOT is the image slot to download to (for non-mfg-image, non-boot)
+#  - FEATURES holds the target features string
+#  - EXTRA_JTAG_CMD holds extra parameters to pass to jtag software
+#  - MFG_IMAGE is "1" if this is a manufacturing image
+#  - FLASH_OFFSET contains the flash offset to download to
+#  - BOOT_LOADER is set if downloading a bootloader
+
+. $CORE_PATH/hw/scripts/jlink.sh
+
+if [ "$MFG_IMAGE" ]; then
+    FLASH_OFFSET=0x0
+fi
+
+JLINK_DEV="nRF52"
+
+common_file_to_load
+jlink_load

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_no_boot.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_no_boot.ld b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_no_boot.ld
new file mode 100755
index 0000000..e2fb5a8
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/ada_feather_nrf52_no_boot.ld
@@ -0,0 +1,191 @@
+/* Linker script for Nordic Semiconductor nRF5 devices
+ *
+ * Version: Sourcery G++ 4.5-1
+ * Support: https://support.codesourcery.com/GNUToolchain/
+ *
+ * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions.  No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
+
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ *
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __bssnz_start__
+ *   __bssnz_end__
+ */
+ENTRY(Reset_Handler)
+
+SECTIONS
+{
+    .text :
+    {
+        __isr_vector_start = .;
+        KEEP(*(.isr_vector))
+        __isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        *(.eh_frame*)
+        . = ALIGN(4);
+    } > FLASH
+
+
+    .ARM.extab :
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+        . = ALIGN(4);
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+        . = ALIGN(4);
+    } > FLASH
+    __exidx_end = .;
+
+    __etext = .;
+
+    .vector_relocation :
+    {
+        . = ALIGN(4);
+        __vector_tbl_reloc__ = .;
+        . = . + (__isr_vector_end - __isr_vector_start);
+        . = ALIGN(4);
+    } > RAM
+
+    .data : AT (__etext)
+    {
+        __data_start__ = .;
+        *(vtable)
+        *(.data*)
+
+        . = ALIGN(4);
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        *(.preinit_array)
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        *(SORT(.init_array.*))
+        *(.init_array)
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        *(SORT(.fini_array.*))
+        *(.fini_array)
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        *(.jcr)
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+    } > RAM
+
+    /* Non-zeroed BSS.  This section is similar to BSS, with the following
+     * caveat:
+     *    1. It does not get zeroed at init-time.
+     */
+    .bssnz :
+    {
+        . = ALIGN(4);
+        __bssnz_start__ = .;
+        *(.bss.core.nz*)
+        . = ALIGN(4);
+        __bssnz_end__ = .;
+    } > RAM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    /* Heap starts after BSS */
+    __HeapBase = .;
+
+    /* .stack_dummy section doesn't contains any symbols. It is only
+     * used for linker to calculate size of stack sections, and assign
+     * values to stack symbols later */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > RAM
+
+    /* Set stack top to end of RAM, and stack limit move down by
+     * size of stack_dummy section */
+    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = __StackLimit;
+
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld b/hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld
new file mode 100755
index 0000000..d1f1b99
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld
@@ -0,0 +1,25 @@
+/* Linker script for Nordic Semiconductor nRF5 devices
+ *
+ * Version: Sourcery G++ 4.5-1
+ * Support: https://support.codesourcery.com/GNUToolchain/
+ *
+ * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions.  No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x4000
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+}
+
+/* The bootloader does not contain an image header */
+_imghdr_size = 0x0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/bsp.yml b/hw/bsp/ada_feather_nrf52/bsp.yml
new file mode 100644
index 0000000..80c9a5d
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/bsp.yml
@@ -0,0 +1,62 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+bsp.arch: cortex_m4
+bsp.compiler: compiler/arm-none-eabi-m4
+bsp.linkerscript:
+    - "hw/bsp/ada_feather_nrf52/nrf52xxaa.ld"
+    - "hw/mcu/nordic/nrf52xxx/nrf52.ld"
+bsp.linkerscript.BOOT_LOADER.OVERWRITE:
+    - "hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld"
+    - "hw/mcu/nordic/nrf52xxx/nrf52.ld"
+bsp.part2linkerscript: "hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld"
+bsp.downloadscript: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_download.sh"
+bsp.debugscript: "hw/bsp/ada_feather_nrf52/ada_feather_nrf52_debug.sh"
+
+bsp.flash_map:
+    areas:
+        # System areas.
+        FLASH_AREA_BOOTLOADER:
+            device: 0
+            offset: 0x00000000
+            size: 16kB
+        FLASH_AREA_IMAGE_0:
+            device: 0
+            offset: 0x00008000
+            size: 232kB
+        FLASH_AREA_IMAGE_1:
+            device: 0
+            offset: 0x00042000
+            size: 232kB
+        FLASH_AREA_IMAGE_SCRATCH:
+            device: 0
+            offset: 0x0007c000
+            size: 4kB
+
+        # User areas.
+        FLASH_AREA_REBOOT_LOG:
+            user_id: 0
+            device: 0
+            offset: 0x00004000
+            size: 16kB
+        FLASH_AREA_NFFS:
+            user_id: 1
+            device: 0
+            offset: 0x0007d000
+            size: 12kB

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/include/bsp/bsp.h b/hw/bsp/ada_feather_nrf52/include/bsp/bsp.h
new file mode 100644
index 0000000..cb6ca46
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/include/bsp/bsp.h
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BSP_H
+#define H_BSP_H
+
+#include <inttypes.h>
+
+#include <syscfg/syscfg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Define special stackos sections */
+#define sec_data_core   __attribute__((section(".data.core")))
+#define sec_bss_core    __attribute__((section(".bss.core")))
+#define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
+
+/* More convenient section placement macros. */
+#define bssnz_t         sec_bss_nz_core
+
+extern uint8_t _ram_start;
+#define RAM_SIZE        0x10000
+
+/* LED pins */
+#define LED_BLINK_PIN   (17)
+#define LED_2           (19)
+
+/* UART info */
+#define CONSOLE_UART    "uart0"
+
+#if MYNEWT_VAL(BOOT_SERIAL)
+#define BOOT_SERIAL_DETECT_PIN          20 /* DFU SW2 */
+#define BOOT_SERIAL_DETECT_PIN_CFG      HAL_GPIO_PULL_UP
+#define BOOT_SERIAL_DETECT_PIN_VAL      0
+
+#define BOOT_SERIAL_REPORT_PIN          LED_BLINK_PIN
+#define BOOT_SERIAL_REPORT_FREQ         (MYNEWT_VAL(OS_CPUTIME_FREQ) / 4)
+#endif
+
+#define NFFS_AREA_MAX   (8)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* H_BSP_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/include/bsp/cmsis_nvic.h
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/include/bsp/cmsis_nvic.h b/hw/bsp/ada_feather_nrf52/include/bsp/cmsis_nvic.h
new file mode 100644
index 0000000..856f7d0
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/include/bsp/cmsis_nvic.h
@@ -0,0 +1,29 @@
+/* mbed Microcontroller Library - cmsis_nvic
+ * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
+ *
+ * CMSIS-style functionality to support dynamic vectors
+ */
+
+#ifndef MBED_CMSIS_NVIC_H
+#define MBED_CMSIS_NVIC_H
+
+#include <stdint.h>
+
+#define NVIC_NUM_VECTORS      (16 + 38)   // CORE + MCU Peripherals
+#define NVIC_USER_IRQ_OFFSET  16
+
+#include "nrf52.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void NVIC_Relocate(void);
+void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
+uint32_t NVIC_GetVector(IRQn_Type IRQn);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/nrf52xxaa.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/nrf52xxaa.ld b/hw/bsp/ada_feather_nrf52/nrf52xxaa.ld
new file mode 100755
index 0000000..9433e37
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/nrf52xxaa.ld
@@ -0,0 +1,25 @@
+/* Linker script for Nordic Semiconductor nRF5 devices
+ *
+ * Version: Sourcery G++ 4.5-1
+ * Support: https://support.codesourcery.com/GNUToolchain/
+ *
+ * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions.  No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+MEMORY
+{
+  FLASH (rx) : ORIGIN = 0x00008000, LENGTH = 0x3a000
+  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+}
+
+/* This linker script is used for images and thus contains an image header */
+_imghdr_size = 0x20;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/pkg.yml b/hw/bsp/ada_feather_nrf52/pkg.yml
new file mode 100644
index 0000000..7a4f1da
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/pkg.yml
@@ -0,0 +1,96 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/bsp/ada_feather_nrf52
+pkg.type: bsp
+pkg.description: BSP definition for the Adafruit nrf52 Feather.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - Adafruit
+    - Feather
+    - nrf52
+
+pkg.cflags:
+    # Nordic SDK files require these defines.
+    - '-DADC_ENABLED=0'
+    - '-DCLOCK_ENABLED=1'
+    - '-DCOMP_ENABLED=1'
+    - '-DEGU_ENABLED=0'
+    - '-DGPIOTE_ENABLED=1'
+    - '-DI2S_ENABLED=1'
+    - '-DLPCOMP_ENABLED=1'
+    - '-DNRF52'
+    - '-DPDM_ENABLED=0'
+    - '-DPERIPHERAL_RESOURCE_SHARING_ENABLED=1'
+    - '-DPWM0_ENABLED=1'
+    - '-DPWM1_ENABLED=0'
+    - '-DPWM2_ENABLED=0'
+    - '-DQDEC_ENABLED=1'
+    - '-DRNG_ENABLED=1'
+    - '-DRTC0_ENABLED=0'
+    - '-DRTC1_ENABLED=0'
+    - '-DRTC2_ENABLED=0'
+    - '-DSAADC_ENABLED=1'
+    - '-DSPI_MASTER_0_ENABLE=1'
+    - '-DSPI0_CONFIG_MISO_PIN=25'
+    - '-DSPI0_CONFIG_MOSI_PIN=24'
+    - '-DSPI0_CONFIG_SCK_PIN=23'
+    - '-DSPI0_ENABLED=1'
+    - '-DSPI0_USE_EASY_DMA=1'
+    - '-DSPI1_ENABLED=0'
+    - '-DSPI2_ENABLED=0'
+    - '-DSPIS0_CONFIG_MISO_PIN=25'
+    - '-DSPIS0_CONFIG_MOSI_PIN=24'
+    - '-DSPIS0_CONFIG_SCK_PIN=23'
+    - '-DSPIS0_ENABLED=1'
+    - '-DSPIS1_CONFIG_MISO_PIN=4'
+    - '-DSPIS1_CONFIG_MOSI_PIN=3'
+    - '-DSPIS1_CONFIG_SCK_PIN=2'
+    - '-DSPIS1_ENABLED=0'
+    - '-DSPIS2_ENABLED=0'
+    - '-DTIMER0_ENABLED=1'
+    - '-DTIMER1_ENABLED=0'
+    - '-DTIMER2_ENABLED=0'
+    - '-DTIMER3_ENABLED=0'
+    - '-DTIMER4_ENABLED=0'
+    - '-DTWI0_CONFIG_SCL=27'
+    - '-DTWI0_CONFIG_SDA=26'
+    - '-DTWI0_ENABLED=1'
+    - '-DTWI1_ENABLED=1'
+    - '-DTWIS0_ENABLED=1'
+    - '-DTWIS1_ENABLED=0'
+    - '-DUART0_ENABLED=1'
+    - '-DWDT_ENABLED=1'
+
+pkg.cflags.HARDFLOAT:
+    - -mfloat-abi=hard -mfpu=fpv4-sp-d16
+
+pkg.deps:
+    - hw/mcu/nordic/nrf52xxx
+    - libc/baselibc
+
+pkg.deps.BLE_DEVICE:
+    - hw/drivers/nimble/nrf52
+
+pkg.deps.UART_0:
+    - hw/drivers/uart/uart_hal
+
+pkg.deps.UART_1:
+    - hw/drivers/uart/uart_bitbang

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld b/hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld
new file mode 100755
index 0000000..f4ffe5a
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/split_ada_feather_nrf52.ld
@@ -0,0 +1,208 @@
+/* Linker script for Nordic Semiconductor nRF5 devices
+ *
+ * Version: Sourcery G++ 4.5-1
+ * Support: https://support.codesourcery.com/GNUToolchain/
+ *
+ * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions.  No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
+
+MEMORY
+{
+  FLASH (rx) : ORIGIN =  0x00042000, LENGTH = 0x3a000
+  RAM  (rwx) : ORIGIN =  0x20000000, LENGTH = 0x10000
+}
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ *
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __HeapBase
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __bssnz_start__
+ *   __bssnz_end__
+ */
+ENTRY(Reset_Handler_split)
+
+SECTIONS
+{
+    .imghdr (NOLOAD):
+    {
+        . = . + 0x20;
+    } > FLASH
+
+    .text :
+    {
+        __split_isr_vector_start = .;
+        KEEP(*(.isr_vector_split))
+        __split_isr_vector_end = .;
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        *(.rodata*)
+
+        *(.eh_frame*)
+        . = ALIGN(4);
+    } > FLASH
+
+
+    .ARM.extab : ALIGN(4)
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > FLASH
+
+    .ARM.extab :
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+        . = ALIGN(4);
+    } > FLASH
+
+    __exidx_start = .;
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+        . = ALIGN(4);
+    } > FLASH
+    __exidx_end = .;
+
+    __etext = .;
+
+    /* save RAM used by the split image. This assumes that 
+     * the loader uses all the RAM up to its HeapBase  */
+    .loader_ram_contents :
+    {
+        _loader_ram_start = .;
+
+ 	/* this symbol comes from the loader linker */
+	. = . + (ABSOLUTE(__HeapBase_loader) - _loader_ram_start);
+        _loader_ram_end = .;
+    } > RAM
+
+    .data :
+    {
+        __data_start__ = .;
+        *(.data*)
+
+        . = ALIGN(4);
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        *(.preinit_array)
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        *(SORT(.init_array.*))
+        *(.init_array)
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        *(SORT(.fini_array.*))
+        *(.fini_array)
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        *(.jcr)
+        . = ALIGN(4);
+        /* All data end */
+        __data_end__ = .;
+    } > RAM AT > FLASH
+
+    /* Non-zeroed BSS.  This section is similar to BSS, with the following two
+     * caveats:
+     *    1. It does not get zeroed at init-time.
+     *    2. You cannot use it as source memory for EasyDMA.
+     *
+     * This section exists because of a hardware defect; see errata 33 and 34
+     * in nrf52 errata sheet.
+     */
+    .bssnz :
+    {
+        . = ALIGN(4);
+        __bssnz_start__ = .;
+        *(.bss.core.nz*)
+        . = ALIGN(4);
+        __bssnz_end__ = .;
+    } > RAM
+
+    .bss :
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > RAM
+
+    /* Heap starts after BSS */
+    __HeapBase = .;
+
+    /* .stack_dummy section doesn't contains any symbols. It is only
+     * used for linker to calculate size of stack sections, and assign
+     * values to stack symbols later */
+    .stack_dummy (COPY):
+    {
+        *(.stack*)
+    } > RAM
+
+    _ram_start = ORIGIN(RAM);
+
+    /* Set stack top to end of RAM, and stack limit move down by
+     * size of stack_dummy section */
+    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = __StackLimit;
+
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52.s
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52.s b/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52.s
new file mode 100755
index 0000000..b45a73c
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52.s
@@ -0,0 +1,299 @@
+/*
+Copyright (c) 2015, Nordic Semiconductor ASA
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* 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.
+
+* Neither the name of Nordic Semiconductor ASA 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+*/
+
+/*
+NOTE: Template files (including this one) are application specific and therefore
+expected to be copied into the application project folder prior to its use!
+*/
+
+    .syntax unified
+    .arch armv7-m
+
+    .section .stack
+    .align 3
+    .equ    Stack_Size, 432
+    .globl    __StackTop
+    .globl    __StackLimit
+__StackLimit:
+    .space    Stack_Size
+    .size __StackLimit, . - __StackLimit
+__StackTop:
+    .size __StackTop, . - __StackTop
+
+    .section .heap
+    .align 3
+#ifdef __HEAP_SIZE
+    .equ    Heap_Size, __HEAP_SIZE
+#else
+    .equ    Heap_Size, 0
+#endif
+    .globl    __HeapBase
+    .globl    __HeapLimit
+__HeapBase:
+    .if    Heap_Size
+    .space    Heap_Size
+    .endif
+    .size __HeapBase, . - __HeapBase
+__HeapLimit:
+    .size __HeapLimit, . - __HeapLimit
+
+    .section .isr_vector
+    .align 2
+    .globl __isr_vector
+__isr_vector:
+    .long    __StackTop            /* Top of Stack */
+    .long   Reset_Handler               /* Reset Handler */
+    .long   NMI_Handler                 /* NMI Handler */
+    .long   HardFault_Handler           /* Hard Fault Handler */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   SVC_Handler                 /* SVCall Handler */
+    .long   0                           /* Reserved */
+    .long   0                           /* Reserved */
+    .long   PendSV_Handler              /* PendSV Handler */
+    .long   SysTick_Handler             /* SysTick Handler */
+
+  /* External Interrupts */
+    .long   POWER_CLOCK_IRQHandler
+    .long   RADIO_IRQHandler
+    .long   UARTE0_UART0_IRQHandler
+    .long   SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
+    .long   SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
+    .long   NFCT_IRQHandler
+    .long   GPIOTE_IRQHandler
+    .long   SAADC_IRQHandler
+    .long   TIMER0_IRQHandler
+    .long   TIMER1_IRQHandler
+    .long   TIMER2_IRQHandler
+    .long   RTC0_IRQHandler
+    .long   TEMP_IRQHandler
+    .long   RNG_IRQHandler
+    .long   ECB_IRQHandler
+    .long   CCM_AAR_IRQHandler
+    .long   WDT_IRQHandler
+    .long   RTC1_IRQHandler
+    .long   QDEC_IRQHandler
+    .long   COMP_LPCOMP_IRQHandler
+    .long   SWI0_EGU0_IRQHandler
+    .long   SWI1_EGU1_IRQHandler
+    .long   SWI2_EGU2_IRQHandler
+    .long   SWI3_EGU3_IRQHandler
+    .long   SWI4_EGU4_IRQHandler
+    .long   SWI5_EGU5_IRQHandler
+    .long   TIMER3_IRQHandler
+    .long   TIMER4_IRQHandler
+    .long   PWM0_IRQHandler
+    .long   PDM_IRQHandler
+    .long   0                         /*Reserved */
+    .long   0                         /*Reserved */
+    .long   MWU_IRQHandler
+    .long   PWM1_IRQHandler
+    .long   PWM2_IRQHandler
+    .long   SPIM2_SPIS2_SPI2_IRQHandler
+    .long   RTC2_IRQHandler
+    .long   I2S_IRQHandler
+
+    .size    __isr_vector, . - __isr_vector
+
+/* Reset Handler */
+
+    .text
+    .thumb
+    .thumb_func
+    .align 1
+    .globl    Reset_Handler
+    .type    Reset_Handler, %function
+Reset_Handler:
+    .fnstart
+
+    /* Clear BSS */
+    mov     r0, #0
+    ldr     r2, =__bss_start__
+    ldr     r3, =__bss_end__
+.bss_zero_loop:
+    cmp     r2, r3
+    itt     lt
+    strlt   r0, [r2], #4
+    blt    .bss_zero_loop
+
+
+/*     Loop to copy data from read only memory to RAM. The ranges
+ *      of copy from/to are specified by following symbols evaluated in
+ *      linker script.
+ *      __etext: End of code section, i.e., begin of data sections to copy from.
+ *      __data_start__/__data_end__: RAM address range that data should be
+ *      copied to. Both must be aligned to 4 bytes boundary.  */
+    ldr    r1, =__etext
+    ldr    r2, =__data_start__
+    ldr    r3, =__data_end__
+
+    subs    r3, r2
+    ble     .LC0
+
+.LC1:
+    subs    r3, 4
+    ldr    r0, [r1,r3]
+    str    r0, [r2,r3]
+    bgt    .LC1
+
+.LC0:
+
+    LDR     R0, =__HeapBase
+    LDR     R1, =__HeapLimit
+    BL      _sbrkInit
+
+    LDR     R0, =SystemInit
+    BLX     R0
+
+    LDR     R0, =_start
+    BX      R0
+
+    .pool
+    .cantunwind
+    .fnend
+    .size   Reset_Handler,.-Reset_Handler
+
+    .section ".text"
+
+
+/* Dummy Exception Handlers (infinite loops which can be modified) */
+
+    .weak   NMI_Handler
+    .type   NMI_Handler, %function
+NMI_Handler:
+    B       .
+    .size   NMI_Handler, . - NMI_Handler
+
+
+    .weak   HardFault_Handler
+    .type   HardFault_Handler, %function
+HardFault_Handler:
+    B       .
+    .size   HardFault_Handler, . - HardFault_Handler
+
+
+    .weak   MemoryManagement_Handler
+    .type   MemoryManagement_Handler, %function
+MemoryManagement_Handler:
+    B       .
+    .size   MemoryManagement_Handler, . - MemoryManagement_Handler
+
+
+    .weak   BusFault_Handler
+    .type   BusFault_Handler, %function
+BusFault_Handler:
+    B       .
+    .size   BusFault_Handler, . - BusFault_Handler
+
+
+    .weak   UsageFault_Handler
+    .type   UsageFault_Handler, %function
+UsageFault_Handler:
+    B       .
+    .size   UsageFault_Handler, . - UsageFault_Handler
+
+
+    .weak   SVC_Handler
+    .type   SVC_Handler, %function
+SVC_Handler:
+    B       .
+    .size   SVC_Handler, . - SVC_Handler
+
+
+    .weak   PendSV_Handler
+    .type   PendSV_Handler, %function
+PendSV_Handler:
+    B       .
+    .size   PendSV_Handler, . - PendSV_Handler
+
+
+    .weak   SysTick_Handler
+    .type   SysTick_Handler, %function
+SysTick_Handler:
+    B       .
+    .size   SysTick_Handler, . - SysTick_Handler
+
+
+/* IRQ Handlers */
+
+    .globl  Default_Handler
+    .type   Default_Handler, %function
+Default_Handler:
+    B       .
+    .size   Default_Handler, . - Default_Handler
+
+    .macro  IRQ handler
+    .weak   \handler
+    .set    \handler, Default_Handler
+    .endm
+
+    IRQ  POWER_CLOCK_IRQHandler
+    IRQ  RADIO_IRQHandler
+    IRQ  UARTE0_UART0_IRQHandler
+    IRQ  SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
+    IRQ  SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
+    IRQ  NFCT_IRQHandler
+    IRQ  GPIOTE_IRQHandler
+    IRQ  SAADC_IRQHandler
+    IRQ  TIMER0_IRQHandler
+    IRQ  TIMER1_IRQHandler
+    IRQ  TIMER2_IRQHandler
+    IRQ  RTC0_IRQHandler
+    IRQ  TEMP_IRQHandler
+    IRQ  RNG_IRQHandler
+    IRQ  ECB_IRQHandler
+    IRQ  CCM_AAR_IRQHandler
+    IRQ  WDT_IRQHandler
+    IRQ  RTC1_IRQHandler
+    IRQ  QDEC_IRQHandler
+    IRQ  COMP_LPCOMP_IRQHandler
+    IRQ  SWI0_EGU0_IRQHandler
+    IRQ  SWI1_EGU1_IRQHandler
+    IRQ  SWI2_EGU2_IRQHandler
+    IRQ  SWI3_EGU3_IRQHandler
+    IRQ  SWI4_EGU4_IRQHandler
+    IRQ  SWI5_EGU5_IRQHandler
+    IRQ  TIMER3_IRQHandler
+    IRQ  TIMER4_IRQHandler
+    IRQ  PWM0_IRQHandler
+    IRQ  PDM_IRQHandler
+    IRQ  MWU_IRQHandler
+    IRQ  PWM1_IRQHandler
+    IRQ  PWM2_IRQHandler
+    IRQ  SPIM2_SPIS2_SPI2_IRQHandler
+    IRQ  RTC2_IRQHandler
+    IRQ  I2S_IRQHandler
+
+  .end

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52_split.s
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52_split.s b/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52_split.s
new file mode 100755
index 0000000..de1ce6e
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/src/arch/cortex_m4/gcc_startup_nrf52_split.s
@@ -0,0 +1,163 @@
+/*
+Copyright (c) 2015, Nordic Semiconductor ASA
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* 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.
+
+* Neither the name of Nordic Semiconductor ASA 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+*/
+
+/*
+NOTE: Template files (including this one) are application specific and therefore
+expected to be copied into the application project folder prior to its use!
+*/
+
+    .syntax unified
+    .arch armv7-m
+    .section .stack
+    .align 3
+    .equ    Stack_Size, 432
+    .globl    __StackTop
+    .globl    __StackLimit
+__StackLimit:
+    .space    Stack_Size
+    .size __StackLimit, . - __StackLimit
+__StackTop:
+    .size __StackTop, . - __StackTop
+
+    .section .heap
+    .align 3
+#ifdef __HEAP_SIZE
+    .equ    Heap_Size, __HEAP_SIZE
+#else
+    .equ    Heap_Size, 0
+#endif
+    .globl    __HeapBase
+    .globl    __HeapLimit
+__HeapBase:
+    .if    Heap_Size
+    .space    Heap_Size
+    .endif
+    .size __HeapBase, . - __HeapBase
+__HeapLimit:
+    .size __HeapLimit, . - __HeapLimit
+
+    .section .isr_vector_split
+    .align 2
+    .globl __isr_vector_split
+__isr_vector_split:
+    .long    __StackTop            /* Top of Stack */
+    .long   Reset_Handler_split               /* Reset Handler */
+
+    .size    __isr_vector_split, . - __isr_vector_split
+
+/* Reset Handler */
+
+    .text
+    .thumb
+    .thumb_func
+    .align 1
+    .globl    Reset_Handler_split
+    .type    Reset_Handler_split, %function
+Reset_Handler_split:
+    .fnstart
+
+    /* Clear CPU state before proceeding */
+    mov     r0, #0
+    msr     control, r0
+    msr     primask, r0
+    /* Clear BSS */
+    ldr     r2, =__bss_start__
+    ldr     r3, =__bss_end__
+.bss_zero_loop:
+    cmp     r2, r3
+    itt     lt
+    strlt   r0, [r2], #4
+    blt    .bss_zero_loop
+
+
+/*     Loop to copy data from read only memory to RAM. The ranges
+ *      of copy from/to are specified by following symbols evaluated in
+ *      linker script.
+ *      __etext: End of code section, i.e., begin of data sections to copy from.
+ *      __data_start__/__data_end__: RAM address range that data should be
+ *      copied to. Both must be aligned to 4 bytes boundary.  */
+
+    ldr    r1, =__etext
+    ldr    r2, =__data_start__
+    ldr    r3, =__data_end__
+
+    subs    r3, r2
+    ble     .LC0
+
+.LC1:
+    subs    r3, 4
+    ldr    r0, [r1,r3]
+    str    r0, [r2,r3]
+    bgt    .LC1
+
+.LC0:
+    ldr    r1, =__etext_loader
+    ldr    r2, =__data_start___loader
+    ldr    r3, =__data_end___loader
+
+    subs    r3, r2
+    ble     .LC2
+
+.LC3:
+    subs    r3, 4
+    ldr    r0, [r1,r3]
+    str    r0, [r2,r3]
+    bgt    .LC3
+.LC2:
+
+    subs    r0, r0
+    ldr    r2, =__bss_start___loader
+    ldr    r3, =__bss_end___loader
+
+    subs    r3, r2
+    ble     .LC4
+
+.LC5:
+    subs    r3, 4
+    str    r0, [r2,r3]
+    bgt    .LC5
+.LC4:
+
+    LDR     R0, =__HeapBase
+    LDR     R1, =__HeapLimit
+    BL      _sbrkInit
+
+    LDR     R0, =SystemInit
+    BLX     R0
+    LDR     R0, =_start_split
+    BX      R0
+
+    .pool
+    .cantunwind
+    .fnend
+    .size   Reset_Handler_split,.-Reset_Handler_split
+
+    .section ".text"
+  .end

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/src/hal_bsp.c b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
new file mode 100644
index 0000000..178c76e
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <assert.h>
+#include <nrf52.h>
+#include "os/os_cputime.h"
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "flash_map/flash_map.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_flash.h"
+#include "hal/hal_spi.h"
+#include "hal/hal_watchdog.h"
+#include "hal/hal_i2c.h"
+#include "mcu/nrf52_hal.h"
+#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1)
+#include "uart/uart.h"
+#endif
+#if MYNEWT_VAL(UART_0)
+#include "uart_hal/uart_hal.h"
+#endif
+#if MYNEWT_VAL(UART_1)
+#include "uart_bitbang/uart_bitbang.h"
+#endif
+#include "os/os_dev.h"
+#include "bsp.h"
+
+#if MYNEWT_VAL(UART_0)
+static struct uart_dev os_bsp_uart0;
+static const struct nrf52_uart_cfg os_bsp_uart0_cfg = {
+    .suc_pin_tx = MYNEWT_VAL(UART_0_PIN_TX),
+    .suc_pin_rx = MYNEWT_VAL(UART_0_PIN_RX),
+    .suc_pin_rts = MYNEWT_VAL(UART_0_PIN_RTS),
+    .suc_pin_cts = MYNEWT_VAL(UART_0_PIN_CTS),
+};
+#endif
+
+#if MYNEWT_VAL(UART_1)
+static struct uart_dev os_bsp_bitbang_uart1;
+static const struct uart_bitbang_conf os_bsp_uart1_cfg = {
+    .ubc_txpin = MYNEWT_VAL(UART_1_PIN_TX),
+    .ubc_rxpin = MYNEWT_VAL(UART_1_PIN_RX),
+    .ubc_cputimer_freq = MYNEWT_VAL(OS_CPUTIME_FREQ),
+};
+#endif
+
+#if MYNEWT_VAL(SPI_0_MASTER)
+/*
+ * NOTE: Our HAL expects that the SS pin, if used, is treated as a gpio line
+ * and is handled outside the SPI routines.
+ */
+static const struct nrf52_hal_spi_cfg os_bsp_spi0m_cfg = {
+    .sck_pin      = 12,
+    .mosi_pin     = 13,
+    .miso_pin     = 14,
+};
+#endif
+
+#if MYNEWT_VAL(SPI_0_SLAVE)
+static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {
+    .sck_pin      = 12,
+    .mosi_pin     = 13,
+    .miso_pin     = 14,
+    .ss_pin       = 15,
+};
+#endif
+
+#if MYNEWT_VAL(I2C_0)
+static const struct nrf52_hal_i2c_cfg hal_i2c_cfg = {
+    .scl_pin = 26,
+    .sda_pin = 25,
+    .i2c_frequency = 100    /* 100 kHz */
+};
+#endif
+
+/*
+ * What memory to include in coredump.
+ */
+static const struct hal_bsp_mem_dump dump_cfg[] = {
+    [0] = {
+        .hbmd_start = &_ram_start,
+        .hbmd_size = RAM_SIZE
+    }
+};
+
+const struct hal_flash *
+hal_bsp_flash_dev(uint8_t id)
+{
+    /*
+     * Internal flash mapped to id 0.
+     */
+    if (id != 0) {
+        return NULL;
+    }
+    return &nrf52k_flash_dev;
+}
+
+const struct hal_bsp_mem_dump *
+hal_bsp_core_dump(int *area_cnt)
+{
+    *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
+    return dump_cfg;
+}
+
+int
+hal_bsp_power_state(int state)
+{
+    return (0);
+}
+
+/**
+ * Returns the configured priority for the given interrupt. If no priority
+ * configured, return the priority passed in
+ *
+ * @param irq_num
+ * @param pri
+ *
+ * @return uint32_t
+ */
+uint32_t
+hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
+{
+    uint32_t cfg_pri;
+
+    switch (irq_num) {
+    /* Radio gets highest priority */
+    case RADIO_IRQn:
+        cfg_pri = 0;
+        break;
+    default:
+        cfg_pri = pri;
+    }
+    return cfg_pri;
+}
+
+void
+hal_bsp_init(void)
+{
+    int rc;
+
+    (void)rc;
+#if MYNEWT_VAL(TIMER_0)
+    rc = hal_timer_init(0, NULL);
+    assert(rc == 0);
+#endif
+#if MYNEWT_VAL(TIMER_1)
+    rc = hal_timer_init(1, NULL);
+    assert(rc == 0);
+#endif
+#if MYNEWT_VAL(TIMER_2)
+    rc = hal_timer_init(2, NULL);
+    assert(rc == 0);
+#endif
+#if MYNEWT_VAL(TIMER_3)
+    rc = hal_timer_init(3, NULL);
+    assert(rc == 0);
+#endif
+#if MYNEWT_VAL(TIMER_4)
+    rc = hal_timer_init(4, NULL);
+    assert(rc == 0);
+#endif
+#if MYNEWT_VAL(TIMER_5)
+    rc = hal_timer_init(5, NULL);
+    assert(rc == 0);
+#endif
+
+#if (MYNEWT_VAL(OS_CPUTIME_TIMER_NUM) >= 0)
+    rc = os_cputime_init(MYNEWT_VAL(OS_CPUTIME_FREQ));
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(I2C_0)
+    rc = hal_i2c_init(0, (void *)&hal_i2c_cfg);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(SPI_0_MASTER)
+    rc = hal_spi_init(0, (void *)&os_bsp_spi0m_cfg, HAL_SPI_TYPE_MASTER);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(SPI_0_SLAVE)
+    rc = hal_spi_init(0, (void *)&os_bsp_spi0s_cfg, HAL_SPI_TYPE_SLAVE);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(UART_0)
+    rc = os_dev_create((struct os_dev *) &os_bsp_uart0, "uart0",
+      OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&os_bsp_uart0_cfg);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(UART_1)
+    rc = os_dev_create((struct os_dev *) &os_bsp_bitbang_uart1, "uart1",
+      OS_DEV_INIT_PRIMARY, 0, uart_bitbang_init, (void *)&os_bsp_uart1_cfg);
+    assert(rc == 0);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/src/sbrk.c b/hw/bsp/ada_feather_nrf52/src/sbrk.c
new file mode 100644
index 0000000..5df43c9
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/src/sbrk.c
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <hal/hal_bsp.h>
+
+/* put these in the data section so they are not cleared by _start */
+static char *sbrkBase __attribute__ ((section (".data")));
+static char *sbrkLimit __attribute__ ((section (".data")));
+static char *brk __attribute__ ((section (".data")));
+
+void
+_sbrkInit(char *base, char *limit) {
+    sbrkBase = base;
+    sbrkLimit = limit;
+    brk = base;
+}
+
+void *
+_sbrk(int incr)
+{
+    void *prev_brk;
+
+    if (incr < 0) {
+        /* Returning memory to the heap. */
+        incr = -incr;
+        if (brk - incr < sbrkBase) {
+            prev_brk = (void *)-1;
+        } else {
+            prev_brk = brk;
+            brk -= incr;
+        }
+    } else {
+        /* Allocating memory from the heap. */
+        if (sbrkLimit - brk >= incr) {
+            prev_brk = brk;
+            brk += incr;
+        } else {
+            prev_brk = (void *)-1;
+        }
+    }
+
+    return prev_brk;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24956966/hw/bsp/ada_feather_nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/syscfg.yml b/hw/bsp/ada_feather_nrf52/syscfg.yml
new file mode 100644
index 0000000..e56991e
--- /dev/null
+++ b/hw/bsp/ada_feather_nrf52/syscfg.yml
@@ -0,0 +1,97 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/ada_feather_nrf52
+
+syscfg.defs:
+    BSP_NRF52:
+        description: 'Set to indicate that BSP has NRF52'
+        value: 1
+
+    XTAL_32768:
+        description: 'External 32k oscillator available.'
+        value: 1
+
+    UART_0:
+        description: 'Whether to enable UART0'
+        value:  1
+    UART_0_PIN_TX:
+        description: 'TX pin for UART0'
+        value:  6
+    UART_0_PIN_RX:
+        description: 'RX pin for UART0'
+        value:  8
+    UART_0_PIN_RTS:
+        description: 'RTS pin for UART0'
+        value:  5
+    UART_0_PIN_CTS:
+        description: 'CTS pin for UART0'
+        value:  7
+
+    UART_1:
+        description: 'Whether to enable bitbanger UART1'
+        value:  0
+    UART_1_PIN_TX:
+        description: 'TX pin for UART1'
+        value:  -1
+    UART_1_PIN_RX:
+        description: 'RX pin for UART1'
+        value:  -1
+
+    SPI_0_MASTER:
+        description: 'SPI 0 master'
+        value:  0
+        restrictions:
+            - "!SPI_0_SLAVE"
+    SPI_0_MASTER_SS_PIN:
+        description: 'SPI 0 (master) SS pin number.'
+        value:  15
+    SPI_0_SLAVE:
+        description: 'SPI 0 slave'
+        value:  0
+        restrictions:
+            - "!SPI_0_MASTER"
+
+    TIMER_0:
+        description: 'NRF52 Timer 0'
+        value:  1
+    TIMER_1:
+        description: 'NRF52 Timer 1'
+        value:  0
+    TIMER_2:
+        description: 'NRF52 Timer 2'
+        value:  0
+    TIMER_3:
+        description: 'NRF52 Timer 3'
+        value:  0
+    TIMER_4:
+        description: 'NRF52 Timer 4'
+        value:  0
+    TIMER_5:
+        description: 'NRF52 RTC 0'
+        value:  0
+
+    I2C_0:
+        description: 'NRF52 I2C (TWI) interface 0'
+        value:  '0'
+
+syscfg.vals:
+    CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS
+    REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
+    NFFS_FLASH_AREA: FLASH_AREA_NFFS
+    COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1


[26/50] incubator-mynewt-core git commit: nimble/l2cap: Memset response in L2CAP LE CoC connect request

Posted by ma...@apache.org.
nimble/l2cap: Memset response in L2CAP LE CoC connect request

This is in order to not send trash in case of error response.


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

Branch: refs/heads/1_0_0_dev
Commit: 9597dc7bc8c5fe43c5fa193ce72c3a44ae82e475
Parents: 357d8bd
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:15:35 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:10 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9597dc7b/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 94bb271..a1a3399 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -631,6 +631,8 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         return 0;
     }
 
+    memset(rsp, 0, sizeof(*rsp));
+
     req = (struct ble_l2cap_sig_le_con_req *)(*om)->om_data;
 
     ble_hs_lock();


[36/50] incubator-mynewt-core git commit: nimble/l2cap: Add handling receiving SDU over L2CAP LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add handling receiving SDU over L2CAP LE CoC

With this patch nimble can receive full SDU from remote device.
Once it is done, callback with SDU is called to application.


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

Branch: refs/heads/1_0_0_dev
Commit: 7870412b4eb22a337c03ace234e63de81d117d3e
Parents: 2ce91be
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:20:50 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:35 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |   2 +-
 net/nimble/host/src/ble_l2cap_coc.c      | 136 ++++++++++++++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |   4 +
 3 files changed, 141 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7870412b/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index e048ce9..b0ab23d 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -166,7 +166,7 @@ ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 void
 ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
 {
-    /*TODO In here we going to update sdu_rx buffer */
+    ble_l2cap_coc_recv_ready(chan, sdu_rx);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7870412b/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 8d5f71f..b549ba7 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -28,6 +28,8 @@
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 
+#define BLE_L2CAP_SDU_SIZE              2
+
 STAILQ_HEAD(ble_l2cap_coc_srv_list, ble_l2cap_coc_srv);
 
 static struct ble_l2cap_coc_srv_list ble_l2cap_coc_srvs;
@@ -116,9 +118,115 @@ ble_l2cap_coc_srv_find(uint16_t psm)
     return srv;
 }
 
+static void
+ble_l2cap_event_coc_received_data(struct ble_l2cap_chan *chan,
+                                  struct os_mbuf *om)
+{
+    struct ble_l2cap_event event;
+
+    event.type = BLE_L2CAP_EVENT_COC_DATA_RECEIVED;
+    event.receive.chan = chan;
+    event.receive.sdu_rx = om;
+
+    chan->cb(&event, chan->cb_arg);
+}
+
 static int
 ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan)
 {
+    int rc;
+    struct os_mbuf **om;
+    struct ble_l2cap_coc_endpoint *rx;
+    uint16_t om_total;
+
+    /* Create a shortcut to rx_buf */
+    om = &chan->rx_buf;
+    BLE_HS_DBG_ASSERT(*om != NULL);
+
+    /* Create a shortcut to rx endpoint */
+    rx = &chan->coc_rx;
+
+    om_total = OS_MBUF_PKTLEN(*om);
+    rc = ble_hs_mbuf_pullup_base(om, om_total);
+    if (rc != 0) {
+        return rc;
+    }
+
+    /* Fist LE frame */
+    if (OS_MBUF_PKTLEN(rx->sdu) == 0) {
+        uint16_t sdu_len;
+
+        sdu_len = get_le16((*om)->om_data);
+        if (sdu_len > rx->mtu) {
+            /* TODO Disconnect?*/
+            BLE_HS_LOG(INFO, "error: sdu_len > rx->mtu (%d>%d)\n",
+                       sdu_len, rx->mtu);
+            return BLE_HS_EBADDATA;
+        }
+
+        BLE_HS_LOG(DEBUG, "sdu_len=%d, received LE frame=%d, credits=%d\n",
+                   sdu_len, om_total, rx->credits);
+
+        os_mbuf_adj(*om , BLE_L2CAP_SDU_SIZE);
+
+        rc = os_mbuf_appendfrom(rx->sdu, *om, 0, om_total - BLE_L2CAP_SDU_SIZE);
+        if (rc != 0) {
+            /* FIXME: User shall give us big enough buffer.
+             * need to handle it better
+             */
+            BLE_HS_LOG(INFO, "Could not append data rc=%d\n", rc);
+            assert(0);
+        }
+
+        /* In RX case data_offset keeps incoming SDU len */
+        rx->data_offset = sdu_len;
+
+    } else {
+        BLE_HS_LOG(DEBUG, "Continuation...received %d\n", (*om)->om_len);
+
+        rc  = os_mbuf_appendfrom(rx->sdu, *om, 0, om_total);
+        if (rc != 0) {
+            /* FIXME: need to handle it better */
+            BLE_HS_LOG(DEBUG, "Could not append data rc=%d\n", rc);
+            assert(0);
+        }
+    }
+
+    rx->credits--;
+
+    if (OS_MBUF_PKTLEN(rx->sdu) == rx->data_offset) {
+        struct os_mbuf *sdu_rx = rx->sdu;
+
+        /* Lets get back control to os_mbuf to application.
+         * Since it this callback application might want to set new sdu
+         * we need to prepare space for this. Therefore we need sdu_rx
+         */
+
+        rx->sdu = NULL;
+        rx->data_offset = 0;
+
+        ble_l2cap_event_coc_received_data(chan, sdu_rx);
+
+        goto done;
+    }
+
+    /* If we did not received full SDU and credits are 0 it means
+     * that remote was sending us not fully filled up LE frames.
+     * However, we still have buffer to for next LE Frame so lets give one more
+     * credit to peer so it can send us full SDU
+     */
+    if (rx->credits == 0 && rx->sdu) {
+        /* Remote did not send full SDU. Lets give him one more credits to do
+         * so since we have still buffer to handle it
+         */
+        rx->credits = 1;
+        ble_l2cap_sig_le_credits(chan, rx->credits);
+    }
+
+done:
+    BLE_HS_LOG(DEBUG, "Received sdu_len=%d, credits left=%d\n",
+               OS_MBUF_PKTLEN(rx->sdu), rx->credits);
+
     return 0;
 }
 
@@ -200,6 +308,34 @@ ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
     ble_hs_unlock();
 }
 
+void
+ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
+{
+    struct ble_hs_conn *conn;
+    struct ble_l2cap_chan *c;
+
+    chan->coc_rx.sdu = sdu_rx;
+
+    ble_hs_lock();
+    conn = ble_hs_conn_find_assert(chan->conn_handle);
+    c = ble_hs_conn_chan_find_by_scid(conn, chan->scid);
+    if (!c) {
+        ble_hs_unlock();
+        return;
+    }
+
+    /* FIXME 10 is hardcoded - make it better.
+     * We want to back only that much credits which remote side is missing
+     * to be able to send complete SDU.
+     */
+    if (chan->coc_rx.credits < 10) {
+        ble_l2cap_sig_le_credits(chan, 10 - chan->coc_rx.credits);
+        chan->coc_rx.credits = 10;
+    }
+
+    ble_hs_unlock();
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7870412b/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 21f9ec2..88380ea 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -39,6 +39,7 @@ struct ble_l2cap_chan;
 struct ble_l2cap_coc_endpoint {
     uint16_t mtu;
     uint16_t credits;
+    uint16_t data_offset;
     struct os_mbuf *sdu;
 };
 
@@ -63,9 +64,12 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  void *cb_arg);
 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
+void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
+                              struct os_mbuf *sdu_rx);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
+#define ble_l2cap_coc_recv_ready(chan, sdu_rx)
 #endif
 
 #ifdef __cplusplus


[35/50] incubator-mynewt-core git commit: nimble/l2cap: Add LE credits update handling

Posted by ma...@apache.org.
nimble/l2cap: Add LE credits update handling

This patch add support to send singaling request to update LE creadits
as well as handle remote device sending us LE credits update.

Note, that this patch introduces also helper function to find channel
by scid and dcid


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

Branch: refs/heads/1_0_0_dev
Commit: 2ce91beac58db779ddb6ffcf4132f456e0860ebe
Parents: bf24437
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:30:21 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:26 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c               |  2 +-
 net/nimble/host/src/ble_hs_conn.c           | 23 ++++++++++-
 net/nimble/host/src/ble_hs_conn_priv.h      |  4 +-
 net/nimble/host/src/ble_hs_misc.c           |  2 +-
 net/nimble/host/src/ble_l2cap.c             |  2 +-
 net/nimble/host/src/ble_l2cap_coc.c         | 32 +++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h    |  2 +
 net/nimble/host/src/ble_l2cap_sig.c         | 50 +++++++++++++++++++++++-
 net/nimble/host/src/ble_l2cap_sig_priv.h    |  6 +++
 net/nimble/host/test/src/ble_hs_conn_test.c |  6 +--
 10 files changed, 119 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 7fe095b..0eaed34 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -545,7 +545,7 @@ ble_att_set_preferred_mtu(uint16_t mtu)
 
     i = 0;
     while ((conn = ble_hs_conn_find_by_idx(i)) != NULL) {
-        chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+        chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
         BLE_HS_DBG_ASSERT(chan != NULL);
 
         if (!(chan->flags & BLE_L2CAP_CHAN_F_TXED_MTU)) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index a371ace..cef0e3a 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -50,7 +50,7 @@ ble_hs_conn_can_alloc(void)
 }
 
 struct ble_l2cap_chan *
-ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
+ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn, uint16_t cid)
 {
 #if !NIMBLE_BLE_CONNECT
     return NULL;
@@ -70,6 +70,27 @@ ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
     return NULL;
 }
 
+struct ble_l2cap_chan *
+ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn, uint16_t cid)
+{
+#if !NIMBLE_BLE_CONNECT
+    return NULL;
+#endif
+
+    struct ble_l2cap_chan *chan;
+
+    SLIST_FOREACH(chan, &conn->bhc_channels, next) {
+        if (chan->dcid == cid) {
+            return chan;
+        }
+        if (chan->dcid > cid) {
+            return NULL;
+        }
+    }
+
+    return NULL;
+}
+
 int
 ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 24e2e48..4c51646 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -84,7 +84,9 @@ struct ble_hs_conn *ble_hs_conn_find_by_addr(const ble_addr_t *addr);
 struct ble_hs_conn *ble_hs_conn_find_by_idx(int idx);
 int ble_hs_conn_exists(uint16_t conn_handle);
 struct ble_hs_conn *ble_hs_conn_first(void);
-struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
+struct ble_l2cap_chan *ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn,
+                                             uint16_t cid);
+struct ble_l2cap_chan *ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn,
                                              uint16_t cid);
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 578c7e4..f06bfae 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -39,7 +39,7 @@ ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
         chan = NULL;
         rc = BLE_HS_ENOTCONN;
     } else {
-        chan = ble_hs_conn_chan_find(conn, cid);
+        chan = ble_hs_conn_chan_find_by_scid(conn, cid);
         if (chan == NULL) {
             rc = BLE_HS_ENOTCONN;
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 306eac1..e048ce9 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -320,7 +320,7 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
         /* Strip L2CAP header from the front of the mbuf. */
         os_mbuf_adj(om, BLE_L2CAP_HDR_SZ);
 
-        chan = ble_hs_conn_chan_find(conn, l2cap_hdr.cid);
+        chan = ble_hs_conn_chan_find_by_scid(conn, l2cap_hdr.cid);
         if (chan == NULL) {
             rc = BLE_HS_ENOENT;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index ac1b6fa..8d5f71f 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -168,6 +168,38 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
     return 0;
 }
 
+void
+ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
+                                uint16_t credits)
+{
+    struct ble_hs_conn *conn;
+    struct ble_l2cap_chan *chan;
+
+    /* remote updated its credits */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(conn_handle);
+    if (!conn) {
+        ble_hs_unlock();
+        return;
+    }
+
+    chan = ble_hs_conn_chan_find_by_dcid(conn, dcid);
+    if (!chan) {
+        ble_hs_unlock();
+        return;
+    }
+
+    if (chan->coc_tx.credits + credits > 0xFFFF) {
+        BLE_HS_LOG(INFO, "LE CoC credits overflow...disconnecting\n");
+        ble_l2cap_sig_disconnect(chan);
+        ble_hs_unlock();
+        return;
+    }
+
+    chan->coc_tx.credits += credits;
+    ble_hs_unlock();
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 63c593e..21f9ec2 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -61,6 +61,8 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  struct os_mbuf *sdu_rx,
                                                  ble_l2cap_event_fn *cb,
                                                  void *cb_arg);
+void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
+                                    uint16_t credits);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index abc00ae..8da2dad 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -98,11 +98,13 @@ static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_req_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_rsp_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_disc_rsp_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_disc_req_rx;
+static ble_l2cap_sig_rx_fn ble_l2cap_sig_le_credits_rx;
 #else
 #define ble_l2cap_sig_coc_req_rx    ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_coc_rsp_rx    ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_disc_rsp_rx   ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_disc_req_rx   ble_l2cap_sig_rx_noop
+#define ble_l2cap_sig_le_credits_rx   ble_l2cap_sig_rx_noop
 #endif
 
 static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
@@ -120,7 +122,7 @@ static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
     [BLE_L2CAP_SIG_OP_UPDATE_RSP]           = ble_l2cap_sig_update_rsp_rx,
     [BLE_L2CAP_SIG_OP_CREDIT_CONNECT_REQ]   = ble_l2cap_sig_coc_req_rx,
     [BLE_L2CAP_SIG_OP_CREDIT_CONNECT_RSP]   = ble_l2cap_sig_coc_rsp_rx,
-    [BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT]     = ble_l2cap_sig_rx_noop,
+    [BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT]     = ble_l2cap_sig_le_credits_rx,
 };
 
 static uint8_t ble_l2cap_sig_cur_id;
@@ -876,7 +878,7 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     /* Let's find matching channel. Note that destination CID in the request
      * is from peer perspective. It is source CID from nimble perspective 
      */
-    chan = ble_hs_conn_chan_find(conn, le16toh(req->dcid));
+    chan = ble_hs_conn_chan_find_by_scid(conn, le16toh(req->dcid));
     if (!chan || (le16toh(req->scid) != chan->dcid)) {
         os_mbuf_free_chain(txom);
         ble_hs_unlock();
@@ -1006,6 +1008,50 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
 
     return rc;
 }
+
+static int
+ble_l2cap_sig_le_credits_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
+                            struct os_mbuf **om)
+{
+    struct ble_l2cap_sig_le_credits *req;
+    int rc;
+
+    rc = ble_hs_mbuf_pullup_base(om, sizeof(*req));
+    if (rc != 0) {
+        return 0;
+    }
+
+    req = (struct ble_l2cap_sig_le_credits *) (*om)->om_data;
+
+    /* Ignore when peer sends zero credits */
+    if (req->credits == 0) {
+            return 0;
+    }
+
+    ble_l2cap_coc_le_credits_update(conn_handle, le16toh(req->scid),
+                                    le16toh(req->credits));
+
+    return 0;
+}
+
+int
+ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits)
+{
+    struct ble_l2cap_sig_le_credits *cmd;
+    struct os_mbuf *txom;
+
+    cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT,
+                                ble_l2cap_sig_next_id(), sizeof(*cmd), &txom);
+
+    if (!cmd) {
+        return BLE_HS_ENOMEM;
+    }
+
+    cmd->scid = htole16(chan->scid);
+    cmd->credits = htole16(credits);
+
+    return ble_l2cap_sig_tx(chan->conn_handle, txom);
+}
 #endif
 /*****************************************************************************
  * $misc                                                                     *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 0677405..49d096c 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -84,6 +84,11 @@ struct ble_l2cap_sig_disc_rsp {
     uint16_t scid;
 } __attribute__((packed));
 
+struct ble_l2cap_sig_le_credits {
+    uint16_t scid;
+    uint16_t credits;
+} __attribute__((packed));
+
 int ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
                            struct os_mbuf **out_om, void **out_payload_buf);
 void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
@@ -103,6 +108,7 @@ int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
                               struct os_mbuf *sdu_rx,
                               ble_l2cap_event_fn *cb, void *cb_arg);
 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
+int ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits);
 #else
 #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \
                                                                 BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2ce91bea/net/nimble/host/test/src/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_conn_test.c b/net/nimble/host/test/src/ble_hs_conn_test.c
index 8ae4971..87f9b46 100644
--- a/net/nimble/host/test/src/ble_hs_conn_test.c
+++ b/net/nimble/host/test/src/ble_hs_conn_test.c
@@ -77,7 +77,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);
@@ -131,7 +131,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);
@@ -192,7 +192,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);


[15/50] incubator-mynewt-core git commit: MYNEWT-492 - Remove unused obsolete settings.

Posted by ma...@apache.org.
MYNEWT-492 - Remove unused obsolete settings.


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

Branch: refs/heads/1_0_0_dev
Commit: fdc8e21b0b8789dbbb85fb022f8c2ee2b0ecca2f
Parents: dffe450
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 17:03:21 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:33 2017 -0800

----------------------------------------------------------------------
 mgmt/newtmgr/syscfg.yml      | 24 ------------------------
 net/nimble/host/src/ble_hs.c |  3 ---
 net/nimble/host/syscfg.yml   |  5 -----
 3 files changed, 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fdc8e21b/mgmt/newtmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/syscfg.yml b/mgmt/newtmgr/syscfg.yml
deleted file mode 100644
index 6b5da78..0000000
--- a/mgmt/newtmgr/syscfg.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#  http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-# Package: mgmt/newtmgr
-
-syscfg.defs:
-    NEWTMGR_BLE_HOST:
-        description: 'TBD'
-        value: 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fdc8e21b/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index ae7b4f5..9fb5702 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -61,9 +61,6 @@ static struct os_event ble_hs_ev_start = {
 uint8_t ble_hs_sync_state;
 static int ble_hs_reset_reason;
 
-#define BLE_HS_HEARTBEAT_OS_TICKS       \
-    (MYNEWT_VAL(BLE_HS_HEARTBEAT_FREQ) * OS_TICKS_PER_SEC / 1000)
-
 #define BLE_HS_SYNC_RETRY_RATE          (OS_TICKS_PER_SEC / 10)
 
 static struct os_task *ble_hs_parent_task;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fdc8e21b/net/nimble/host/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/syscfg.yml b/net/nimble/host/syscfg.yml
index be9d953..6a52b82 100644
--- a/net/nimble/host/syscfg.yml
+++ b/net/nimble/host/syscfg.yml
@@ -34,11 +34,6 @@ syscfg.defs:
         description: 'TBD'
         value: 1
 
-    # Misc settings.
-    BLE_HS_HEARTBEAT_FREQ:
-        description: 'Milliseconds.'
-        value: 1000
-
     # L2CAP settings.
     BLE_L2CAP_MAX_CHANS:
         description: 'TBD'


[40/50] incubator-mynewt-core git commit: nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req

Posted by ma...@apache.org.
nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req

With this patch, if legacy device response with REJECT CMD on
LE Create Base Connection request, application will be corretly
notified.


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

Branch: refs/heads/1_0_0_dev
Commit: f6b3b2223e79aa1607c40abeb1b1d4389f8be557
Parents: 61a0e85
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 21:49:47 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:09 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c |  5 ++++
 net/nimble/host/src/ble_l2cap_sig.c | 39 +++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b3b222/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index ec01fec..f7ecef4 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -281,6 +281,11 @@ ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
 {
     struct ble_l2cap_event event = { };
 
+    /* FIXME */
+    if (!chan->cb) {
+        return;
+    }
+
     event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
     event.disconnect.conn_handle = chan->conn_handle;
     event.disconnect.chan = chan;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b3b222/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index b77fa3b..a33ddef 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -92,6 +92,7 @@ typedef int ble_l2cap_sig_rx_fn(uint16_t conn_handle,
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_noop;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_req_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_rsp_rx;
+static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_reject;
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_req_rx;
@@ -108,7 +109,7 @@ static ble_l2cap_sig_rx_fn ble_l2cap_sig_le_credits_rx;
 #endif
 
 static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
-    [BLE_L2CAP_SIG_OP_REJECT]               = ble_l2cap_sig_rx_noop,
+    [BLE_L2CAP_SIG_OP_REJECT]               = ble_l2cap_sig_rx_reject,
     [BLE_L2CAP_SIG_OP_CONNECT_RSP]          = ble_l2cap_sig_rx_noop,
     [BLE_L2CAP_SIG_OP_CONFIG_RSP]           = ble_l2cap_sig_rx_noop,
     [BLE_L2CAP_SIG_OP_DISCONN_REQ]          = ble_l2cap_sig_disc_req_rx,
@@ -613,6 +614,15 @@ ble_l2cap_sig_coc_connect_cb(struct ble_l2cap_sig_proc *proc, int status)
     }
 
     ble_l2cap_event_coc_connected(chan, status);
+
+    if (status) {
+        /* Normally in channel free we send disconnected event to application.
+         * However in case on error during creation connection we send connected
+         * event with error status. To avoid additional disconnected event lets
+         * clear callbacks since we don't needed it anymore.*/
+        chan->cb = NULL;
+        ble_l2cap_chan_free(chan);
+    }
 }
 
 static int
@@ -1037,6 +1047,33 @@ ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits)
     return ble_l2cap_sig_tx(chan->conn_handle, txom);
 }
 #endif
+
+static int
+ble_l2cap_sig_rx_reject(uint16_t conn_handle,
+                        struct ble_l2cap_sig_hdr *hdr,
+                        struct os_mbuf **om)
+{
+    struct ble_l2cap_sig_proc *proc;
+    proc = ble_l2cap_sig_proc_extract(conn_handle,
+                                         BLE_L2CAP_SIG_PROC_OP_CONNECT,
+                                         hdr->identifier);
+   if (!proc) {
+       return 0;
+   }
+
+   switch (proc->id) {
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
+       case BLE_L2CAP_SIG_PROC_OP_CONNECT:
+           ble_l2cap_sig_coc_connect_cb(proc, BLE_HS_EREJECT);
+           break;
+#endif
+       default:
+           break;
+   }
+
+   ble_l2cap_sig_proc_free(proc);
+   return 0;
+}
 /*****************************************************************************
  * $misc                                                                     *
  *****************************************************************************/


[17/50] incubator-mynewt-core git commit: net/oic; support IPv4.

Posted by ma...@apache.org.
net/oic; support IPv4.


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

Branch: refs/heads/1_0_0_dev
Commit: 5ea6d720e7177a8f0a342d8e129c307f9338db0f
Parents: c664f02
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Feb 21 10:09:25 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:52 2017 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_client_api.c       |  61 ++++-
 net/oic/src/port/mynewt/adaptor.c     |  32 ++-
 net/oic/src/port/mynewt/adaptor.h     |  16 +-
 net/oic/src/port/mynewt/ip4_adaptor.c | 354 +++++++++++++++++++++++++++++
 net/oic/src/port/mynewt/ip_adaptor.c  |  96 ++++----
 net/oic/src/port/oc_connectivity.h    |  15 +-
 net/oic/syscfg.yml                    |   6 +
 net/oic/test/syscfg.yml               |   2 +
 8 files changed, 512 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/net/oic/src/api/oc_client_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_client_api.c b/net/oic/src/api/oc_client_api.c
index 692e0f6..d87683c 100644
--- a/net/oic/src/api/oc_client_api.c
+++ b/net/oic/src/api/oc_client_api.c
@@ -263,22 +263,16 @@ oc_stop_observe(const char *uri, oc_server_handle_t *server)
     return status;
 }
 
-bool
-oc_do_ip_discovery(const char *rt, oc_discovery_cb_t handler)
+#if MYNEWT_VAL(OC_TRANSPORT_IP)
+static bool
+oc_send_ip_discovery(oc_server_handle_t *handle, const char *rt,
+                     oc_discovery_cb_t handler)
 {
-    oc_server_handle_t handle;
     oc_client_cb_t *cb;
     bool status = false;
     oc_string_t query;
 
-    oc_make_ip_endpoint(mcast, IP | MULTICAST, 5683,
-                       0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xfd);
-    mcast.oe_ip.v6.scope = 0;
-
-    memcpy(&handle.endpoint, &mcast, sizeof(oc_endpoint_t));
-
-    cb = oc_ri_alloc_client_cb("/oic/res", &handle, OC_GET, handler, LOW_QOS);
-
+    cb = oc_ri_alloc_client_cb("/oic/res", handle, OC_GET, handler, LOW_QOS);
     if (!cb) {
         return false;
     }
@@ -297,4 +291,49 @@ oc_do_ip_discovery(const char *rt, oc_discovery_cb_t handler)
     }
     return status;
 }
+
+#if MYNEWT_VAL(OC_TRANSPORT_IPV6)
+bool
+oc_do_ip6_discovery(const char *rt, oc_discovery_cb_t handler)
+{
+    oc_server_handle_t handle;
+
+    oc_make_ip_endpoint(mcast, IP | MULTICAST, 5683,
+                       0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xfd);
+    mcast.oe_ip.v6.scope = 0;
+    memcpy(&handle.endpoint, &mcast, sizeof(oc_endpoint_t));
+
+    return oc_send_ip_discovery(&handle, rt, handler);
+
+}
+#endif
+
+#if MYNEWT_VAL(OC_TRANSPORT_IPV4)
+bool
+oc_do_ip4_discovery(const char *rt, oc_discovery_cb_t handler)
+{
+    oc_server_handle_t handle;
+
+    oc_make_ip4_endpoint(mcast, IP4 | MULTICAST, 5683, 0xe0, 0, 0x01, 0xbb);
+    memcpy(&handle.endpoint, &mcast, sizeof(oc_endpoint_t));
+
+    return oc_send_ip_discovery(&handle, rt, handler);
+}
+#endif
+
+bool
+oc_do_ip_discovery(const char *rt, oc_discovery_cb_t handler)
+{
+    bool status = false;
+
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
+    status = oc_do_ip6_discovery(rt, handler);
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+    status = oc_do_ip4_discovery(rt, handler);
+#endif
+    return status;
+}
+#endif
+
 #endif /* OC_CLIENT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/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 0212592..dd6b986 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -51,9 +51,14 @@ oc_send_buffer(struct os_mbuf *m)
     oe = OC_MBUF_ENDPOINT(m);
 
     switch (oe->oe.flags) {
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
     case IP:
-        oc_send_buffer_ip(m);
+        oc_send_buffer_ip6(m);
+        break;
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+    case IP4:
+        oc_send_buffer_ip4(m);
         break;
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
@@ -79,8 +84,11 @@ oc_send_multicast_message(struct os_mbuf *m)
      * Send on all the transports.
      */
     void (*funcs[])(struct os_mbuf *) = {
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-        oc_send_buffer_ip_mcast,
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
+        oc_send_buffer_ip6_mcast,
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+        oc_send_buffer_ip4_mcast,
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
         /* no multicast for GATT, just send unicast */
@@ -108,8 +116,11 @@ oc_send_multicast_message(struct os_mbuf *m)
 void
 oc_connectivity_shutdown(void)
 {
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-    oc_connectivity_shutdown_ip();
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
+    oc_connectivity_shutdown_ip6();
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+    oc_connectivity_shutdown_ip4();
 #endif
 #if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
     oc_connectivity_shutdown_serial();
@@ -124,8 +135,13 @@ oc_connectivity_init(void)
 {
     int rc = -1;
 
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-    if (oc_connectivity_init_ip() == 0) {
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
+    if (oc_connectivity_init_ip6() == 0) {
+        rc = 0;
+    }
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+    if (oc_connectivity_init_ip4() == 0) {
         rc = 0;
     }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/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 7ea0c4d..ba13e90 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -26,11 +26,17 @@ extern "C" {
 
 struct os_eventq *oc_evq_get(void);
 
-#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 os_mbuf *);
-void oc_send_buffer_ip_mcast(struct os_mbuf *);
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
+int oc_connectivity_init_ip6(void);
+void oc_connectivity_shutdown_ip6(void);
+void oc_send_buffer_ip6(struct os_mbuf *);
+void oc_send_buffer_ip6_mcast(struct os_mbuf *);
+#endif
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+int oc_connectivity_init_ip4(void);
+void oc_connectivity_shutdown_ip4(void);
+void oc_send_buffer_ip4(struct os_mbuf *);
+void oc_send_buffer_ip4_mcast(struct os_mbuf *);
 #endif
 
 #if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/net/oic/src/port/mynewt/ip4_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip4_adaptor.c b/net/oic/src/port/mynewt/ip4_adaptor.c
new file mode 100644
index 0000000..9757fdd
--- /dev/null
+++ b/net/oic/src/port/mynewt/ip4_adaptor.c
@@ -0,0 +1,354 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <syscfg/syscfg.h>
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV4) == 1)
+#include <assert.h>
+#include <string.h>
+
+#include <os/os.h>
+#include <os/endian.h>
+
+#include <log/log.h>
+#include <mn_socket/mn_socket.h>
+#include <stats/stats.h>
+
+#include "port/oc_connectivity.h"
+#include "oic/oc_log.h"
+#include "api/oc_buffer.h"
+#include "adaptor.h"
+
+static void oc_event_ip4(struct os_event *ev);
+
+static struct os_event oc_sock4_read_event = {
+    .ev_cb = oc_event_ip4,
+};
+
+#ifdef OC_SECURITY
+#error This implementation does not yet support security
+#endif
+
+#define COAP_PORT_UNSECURED (5683)
+
+/* 224.0.1.187 */
+static const struct mn_in_addr coap_all_nodes_v4 = {
+    .s_addr = htonl(0xe00001bb)
+};
+
+STATS_SECT_START(oc_ip4_stats)
+    STATS_SECT_ENTRY(iframe)
+    STATS_SECT_ENTRY(ibytes)
+    STATS_SECT_ENTRY(ierr)
+    STATS_SECT_ENTRY(oucast)
+    STATS_SECT_ENTRY(omcast)
+    STATS_SECT_ENTRY(obytes)
+    STATS_SECT_ENTRY(oerr)
+STATS_SECT_END
+STATS_SECT_DECL(oc_ip4_stats) oc_ip4_stats;
+STATS_NAME_START(oc_ip4_stats)
+    STATS_NAME(oc_ip4_stats, iframe)
+    STATS_NAME(oc_ip4_stats, ibytes)
+    STATS_NAME(oc_ip4_stats, ierr)
+    STATS_NAME(oc_ip4_stats, oucast)
+    STATS_NAME(oc_ip4_stats, omcast)
+    STATS_NAME(oc_ip4_stats, obytes)
+    STATS_NAME(oc_ip4_stats, oerr)
+STATS_NAME_END(oc_ip4_stats)
+
+/* sockets to use for coap unicast and multicast */
+static struct mn_socket *oc_ucast4;
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+static struct mn_socket *oc_mcast4;
+#endif
+
+static void
+oc_send_buffer_ip4_int(struct os_mbuf *m, int is_mcast)
+{
+    struct mn_sockaddr_in to;
+    struct oc_endpoint *oe;
+    struct mn_itf itf;
+    uint32_t if2_idx;
+    struct os_mbuf *n;
+    int rc;
+
+    assert(OS_MBUF_USRHDR_LEN(m) >= sizeof(struct oc_endpoint_ip));
+    oe = OC_MBUF_ENDPOINT(m);
+    if ((oe->oe_ip.flags & IP4) == 0) {
+        os_mbuf_free_chain(m);
+        return;
+    }
+    to.msin_len = sizeof(to);
+    to.msin_family = MN_AF_INET;
+    to.msin_port = htons(oe->oe_ip.v4.port);
+    memcpy(&to.msin_addr, oe->oe_ip.v4.address, sizeof(to.msin_addr));
+
+    STATS_INCN(oc_ip4_stats, obytes, OS_MBUF_PKTLEN(m));
+    if (is_mcast) {
+        memset(&itf, 0, sizeof(itf));
+        if2_idx = 0;
+
+        while (1) {
+            rc = mn_itf_getnext(&itf);
+            if (rc) {
+                break;
+            }
+
+            if ((itf.mif_flags & (MN_ITF_F_UP | MN_ITF_F_MULTICAST)) !=
+              (MN_ITF_F_UP | MN_ITF_F_MULTICAST)) {
+                continue;
+            }
+
+            if (!if2_idx) {
+                if2_idx = itf.mif_idx;
+                continue;
+            }
+
+            rc = mn_setsockopt(oc_ucast4, MN_SO_LEVEL, MN_MCAST_IF, &if2_idx);
+            if (rc) {
+                STATS_INC(oc_ip4_stats, oerr);
+                continue;
+            }
+            n = os_mbuf_dup(m);
+            if (!n) {
+                STATS_INC(oc_ip4_stats, oerr);
+                break;
+            }
+            rc = mn_sendto(oc_ucast4, n, (struct mn_sockaddr *)&to);
+            if (rc != 0) {
+                OC_LOG_ERROR("Failed to send buffer %u on %x\n",
+                             OS_MBUF_PKTHDR(m)->omp_len, if2_idx);
+                STATS_INC(oc_ip4_stats, oerr);
+                os_mbuf_free_chain(n);
+            }
+            if2_idx = itf.mif_idx;
+        }
+        if (if2_idx) {
+            rc = mn_setsockopt(oc_ucast4, MN_SO_LEVEL, MN_MCAST_IF, &if2_idx);
+            if (rc) {
+                STATS_INC(oc_ip4_stats, oerr);
+                os_mbuf_free_chain(m);
+            } else {
+                rc = mn_sendto(oc_ucast4, m, (struct mn_sockaddr *) &to);
+                if (rc != 0) {
+                    OC_LOG_ERROR("Failed sending buffer %u on itf %x\n",
+                                 OS_MBUF_PKTHDR(m)->omp_len, if2_idx);
+                    STATS_INC(oc_ip4_stats, oerr);
+                    os_mbuf_free_chain(m);
+                }
+            }
+        } else {
+            os_mbuf_free_chain(m);
+        }
+    } else {
+        rc = mn_sendto(oc_ucast4, m, (struct mn_sockaddr *) &to);
+        if (rc != 0) {
+            OC_LOG_ERROR("Failed to send buffer %u ucast\n",
+                         OS_MBUF_PKTHDR(m)->omp_len);
+            STATS_INC(oc_ip4_stats, oerr);
+            os_mbuf_free_chain(m);
+        }
+    }
+}
+
+void
+oc_send_buffer_ip4(struct os_mbuf *m)
+{
+    STATS_INC(oc_ip4_stats, oucast);
+    oc_send_buffer_ip4_int(m, 0);
+}
+void
+oc_send_buffer_ip4_mcast(struct os_mbuf *m)
+{
+    STATS_INC(oc_ip4_stats, omcast);
+    oc_send_buffer_ip4_int(m, 1);
+}
+
+static struct os_mbuf *
+oc_attempt_rx_ip4_sock(struct mn_socket *rxsock)
+{
+    int rc;
+    struct os_mbuf *m;
+    struct os_mbuf *n;
+    struct oc_endpoint *oe;
+    struct mn_sockaddr_in from;
+
+    rc = mn_recvfrom(rxsock, &n, (struct mn_sockaddr *) &from);
+    if (rc != 0) {
+        return NULL;
+    }
+    assert(OS_MBUF_IS_PKTHDR(n));
+
+    STATS_INC(oc_ip4_stats, iframe);
+    STATS_INCN(oc_ip4_stats, ibytes, OS_MBUF_PKTLEN(n));
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint_ip));
+    if (!m) {
+        OC_LOG_ERROR("Could not allocate RX buffer\n");
+        goto rx_attempt_err;
+    }
+    OS_MBUF_PKTHDR(m)->omp_len = OS_MBUF_PKTHDR(n)->omp_len;
+    SLIST_NEXT(m, om_next) = n;
+
+    oe = OC_MBUF_ENDPOINT(m);
+
+    oe->oe_ip.flags = IP4;
+    memcpy(&oe->oe_ip.v4.address, &from.msin_addr,
+           sizeof(oe->oe_ip.v4.address));
+    oe->oe_ip.v4.port = ntohs(from.msin_port);
+
+    return m;
+
+    /* add the addr info to the message */
+rx_attempt_err:
+    STATS_INC(oc_ip4_stats, ierr);
+    os_mbuf_free_chain(n);
+    return NULL;
+}
+
+static struct os_mbuf *
+oc_attempt_rx_ip4(void)
+{
+    struct os_mbuf *m;
+
+    m = oc_attempt_rx_ip4_sock(oc_ucast4);
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    if (m == NULL) {
+        m = oc_attempt_rx_ip4_sock(oc_mcast4);
+    }
+#endif
+    return m;
+}
+
+static void oc_socks4_readable(void *cb_arg, int err);
+
+union mn_socket_cb oc_sock4_cbs = {
+    .socket.readable = oc_socks4_readable,
+    .socket.writable = NULL
+};
+
+void
+oc_socks4_readable(void *cb_arg, int err)
+{
+    os_eventq_put(oc_evq_get(), &oc_sock4_read_event);
+}
+
+void
+oc_connectivity_shutdown_ip4(void)
+{
+    if (oc_ucast4) {
+        mn_close(oc_ucast4);
+    }
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    if (oc_mcast4) {
+        mn_close(oc_mcast4);
+    }
+#endif
+}
+
+static void
+oc_event_ip4(struct os_event *ev)
+{
+    struct os_mbuf *m;
+
+    while ((m = oc_attempt_rx_ip4()) != NULL) {
+        oc_recv_message(m);
+    }
+}
+
+int
+oc_connectivity_init_ip4(void)
+{
+    int rc;
+    struct mn_sockaddr_in sin;
+    struct mn_itf itf;
+
+    memset(&itf, 0, sizeof(itf));
+
+    rc = mn_socket(&oc_ucast4, MN_PF_INET, MN_SOCK_DGRAM, 0);
+    if (rc != 0 || !oc_ucast4) {
+        OC_LOG_ERROR("Could not create oc unicast v4 socket\n");
+        return rc;
+    }
+    mn_socket_set_cbs(oc_ucast4, oc_ucast4, &oc_sock4_cbs);
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    rc = mn_socket(&oc_mcast4, MN_PF_INET, MN_SOCK_DGRAM, 0);
+    if (rc != 0 || !oc_mcast4) {
+        mn_close(oc_ucast4);
+        OC_LOG_ERROR("Could not create oc multicast v4 socket\n");
+        return rc;
+    }
+    mn_socket_set_cbs(oc_mcast4, oc_mcast4, &oc_sock4_cbs);
+#endif
+
+    sin.msin_len = sizeof(sin);
+    sin.msin_family = MN_AF_INET;
+    sin.msin_port = 11111;
+    memset(&sin.msin_addr, 0, sizeof(sin.msin_addr));
+
+    rc = mn_bind(oc_ucast4, (struct mn_sockaddr *)&sin);
+    if (rc != 0) {
+        OC_LOG_ERROR("Could not bind oc unicast v4 socket\n");
+        goto oc_connectivity_init_err;
+    }
+
+#if (MYNEWT_VAL(OC_SERVER) == 1)
+    /* Set socket option to join multicast group on all valid interfaces */
+    while (1) {
+        struct mn_mreq join;
+
+        rc = mn_itf_getnext(&itf);
+        if (rc) {
+            break;
+        }
+
+        if ((itf.mif_flags & (MN_ITF_F_UP | MN_ITF_F_MULTICAST)) !=
+          (MN_ITF_F_UP | MN_ITF_F_MULTICAST)) {
+            continue;
+        }
+
+        memcpy(&join.mm_addr.v4, &coap_all_nodes_v4, sizeof(coap_all_nodes_v4));
+        join.mm_idx = itf.mif_idx;
+        join.mm_family = MN_AF_INET;
+
+        rc = mn_setsockopt(oc_mcast4, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
+        if (rc != 0) {
+            continue;
+        }
+
+        OC_LOG_DEBUG("Joined Coap v4 mcast group on %s\n", itf.mif_name);
+    }
+
+    sin.msin_port = htons(COAP_PORT_UNSECURED);
+    rc = mn_bind(oc_mcast4, (struct mn_sockaddr *)&sin);
+    if (rc != 0) {
+        OC_LOG_ERROR("Could not bind oc v4 multicast socket\n");
+        goto oc_connectivity_init_err;
+    }
+#endif
+
+    return 0;
+
+oc_connectivity_init_err:
+    oc_connectivity_shutdown();
+    return rc;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/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 d933b2a..9dcbeb9 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -18,7 +18,7 @@
  */
 
 #include <syscfg/syscfg.h>
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
+#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1) && (MYNEWT_VAL(OC_TRANSPORT_IPV6) == 1)
 #include <assert.h>
 #include <string.h>
 
@@ -34,10 +34,10 @@
 #include "api/oc_buffer.h"
 #include "adaptor.h"
 
-static void oc_event_ip(struct os_event *ev);
+static void oc_event_ip6(struct os_event *ev);
 
-static struct os_event oc_sock_read_event = {
-    .ev_cb = oc_event_ip,
+static struct os_event oc_sock6_read_event = {
+    .ev_cb = oc_event_ip6,
 };
 
 #ifdef OC_SECURITY
@@ -46,10 +46,13 @@ static struct os_event oc_sock_read_event = {
 
 
 #define COAP_PORT_UNSECURED (5683)
-/* TODO use inet_pton when its available */
+
+/* link-local scoped address ff02::fd */
 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}
+    .s_addr = {
+        0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD
+    }
 };
 
 STATS_SECT_START(oc_ip_stats)
@@ -73,14 +76,14 @@ STATS_NAME_START(oc_ip_stats)
 STATS_NAME_END(oc_ip_stats)
 
 /* sockets to use for coap unicast and multicast */
-static struct mn_socket *oc_ucast;
+static struct mn_socket *oc_ucast6;
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-static struct mn_socket *oc_mcast;
+static struct mn_socket *oc_mcast6;
 #endif
 
 static void
-oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
+oc_send_buffer_ip6_int(struct os_mbuf *m, int is_mcast)
 {
     struct mn_sockaddr_in6 to;
     struct oc_endpoint *oe;
@@ -91,7 +94,10 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
 
     assert(OS_MBUF_USRHDR_LEN(m) >= sizeof(struct oc_endpoint_ip));
     oe = OC_MBUF_ENDPOINT(m);
-
+    if ((oe->oe_ip.flags & IP) == 0) {
+        os_mbuf_free_chain(m);
+        return;
+    }
     to.msin6_len = sizeof(to);
     to.msin6_family = MN_AF_INET6;
     to.msin6_port = htons(oe->oe_ip.v6.port);
@@ -126,7 +132,7 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
                 break;
             }
             to.msin6_scope_id = itf2.mif_idx;
-            rc = mn_sendto(oc_ucast, n, (struct mn_sockaddr *) &to);
+            rc = mn_sendto(oc_ucast6, n, (struct mn_sockaddr *) &to);
             if (rc != 0) {
                 OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
                              OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
@@ -137,7 +143,7 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
         }
         if (itf2.mif_idx) {
             to.msin6_scope_id = itf2.mif_idx;
-            rc = mn_sendto(oc_ucast, m, (struct mn_sockaddr *) &to);
+            rc = mn_sendto(oc_ucast6, m, (struct mn_sockaddr *) &to);
             if (rc != 0) {
                 OC_LOG_ERROR("Failed sending buffer %u on itf %d\n",
                              OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
@@ -148,7 +154,7 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
             os_mbuf_free_chain(m);
         }
     } else {
-        rc = mn_sendto(oc_ucast, m, (struct mn_sockaddr *) &to);
+        rc = mn_sendto(oc_ucast6, m, (struct mn_sockaddr *) &to);
         if (rc != 0) {
             OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
                          OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
@@ -159,20 +165,20 @@ oc_send_buffer_ip_int(struct os_mbuf *m, int is_mcast)
 }
 
 void
-oc_send_buffer_ip(struct os_mbuf *m)
+oc_send_buffer_ip6(struct os_mbuf *m)
 {
     STATS_INC(oc_ip_stats, oucast);
-    oc_send_buffer_ip_int(m, 0);
+    oc_send_buffer_ip6_int(m, 0);
 }
 void
-oc_send_buffer_ip_mcast(struct os_mbuf *m)
+oc_send_buffer_ip6_mcast(struct os_mbuf *m)
 {
     STATS_INC(oc_ip_stats, omcast);
-    oc_send_buffer_ip_int(m, 1);
+    oc_send_buffer_ip6_int(m, 1);
 }
 
 static struct os_mbuf *
-oc_attempt_rx_ip_sock(struct mn_socket *rxsock)
+oc_attempt_rx_ip6_sock(struct mn_socket *rxsock)
 {
     int rc;
     struct os_mbuf *m;
@@ -214,59 +220,59 @@ rx_attempt_err:
 }
 
 static struct os_mbuf *
-oc_attempt_rx_ip(void)
+oc_attempt_rx_ip6(void)
 {
     struct os_mbuf *m;
 
-    m = oc_attempt_rx_ip_sock(oc_ucast);
+    m = oc_attempt_rx_ip6_sock(oc_ucast6);
 #if (MYNEWT_VAL(OC_SERVER) == 1)
     if (m == NULL) {
-        m = oc_attempt_rx_ip_sock(oc_mcast);
+        m = oc_attempt_rx_ip6_sock(oc_mcast6);
     }
 #endif
     return m;
 }
 
-static void oc_socks_readable(void *cb_arg, int err);
+static void oc_socks6_readable(void *cb_arg, int err);
 
-union mn_socket_cb oc_sock_cbs = {
-    .socket.readable = oc_socks_readable,
+union mn_socket_cb oc_sock6_cbs = {
+    .socket.readable = oc_socks6_readable,
     .socket.writable = NULL
 };
 
 void
-oc_socks_readable(void *cb_arg, int err)
+oc_socks6_readable(void *cb_arg, int err)
 {
-    os_eventq_put(oc_evq_get(), &oc_sock_read_event);
+    os_eventq_put(oc_evq_get(), &oc_sock6_read_event);
 }
 
 void
-oc_connectivity_shutdown_ip(void)
+oc_connectivity_shutdown_ip6(void)
 {
-    if (oc_ucast) {
-        mn_close(oc_ucast);
+    if (oc_ucast6) {
+        mn_close(oc_ucast6);
     }
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    if (oc_mcast) {
-        mn_close(oc_mcast);
+    if (oc_mcast6) {
+        mn_close(oc_mcast6);
     }
 #endif
 
 }
 
 static void
-oc_event_ip(struct os_event *ev)
+oc_event_ip6(struct os_event *ev)
 {
     struct os_mbuf *m;
 
-    while ((m = oc_attempt_rx_ip()) != NULL) {
+    while ((m = oc_attempt_rx_ip6()) != NULL) {
         oc_recv_message(m);
     }
 }
 
 int
-oc_connectivity_init_ip(void)
+oc_connectivity_init_ip6(void)
 {
     int rc;
     struct mn_sockaddr_in6 sin;
@@ -274,21 +280,21 @@ oc_connectivity_init_ip(void)
 
     memset(&itf, 0, sizeof(itf));
 
-    rc = mn_socket(&oc_ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    if (rc != 0 || !oc_ucast) {
+    rc = mn_socket(&oc_ucast6, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    if (rc != 0 || !oc_ucast6) {
         OC_LOG_ERROR("Could not create oc unicast socket\n");
         return rc;
     }
-    mn_socket_set_cbs(oc_ucast, oc_ucast, &oc_sock_cbs);
+    mn_socket_set_cbs(oc_ucast6, oc_ucast6, &oc_sock6_cbs);
 
 #if (MYNEWT_VAL(OC_SERVER) == 1)
-    rc = mn_socket(&oc_mcast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    if (rc != 0 || !oc_mcast) {
-        mn_close(oc_ucast);
+    rc = mn_socket(&oc_mcast6, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    if (rc != 0 || !oc_mcast6) {
+        mn_close(oc_ucast6);
         OC_LOG_ERROR("Could not create oc multicast socket\n");
         return rc;
     }
-    mn_socket_set_cbs(oc_mcast, oc_mcast, &oc_sock_cbs);
+    mn_socket_set_cbs(oc_mcast6, oc_mcast6, &oc_sock6_cbs);
 #endif
 
     sin.msin6_len = sizeof(sin);
@@ -298,7 +304,7 @@ oc_connectivity_init_ip(void)
     sin.msin6_scope_id = 0;
     memcpy(&sin.msin6_addr, nm_in6addr_any, sizeof(sin.msin6_addr));
 
-    rc = mn_bind(oc_ucast, (struct mn_sockaddr *)&sin);
+    rc = mn_bind(oc_ucast6, (struct mn_sockaddr *)&sin);
     if (rc != 0) {
         OC_LOG_ERROR("Could not bind oc unicast socket\n");
         goto oc_connectivity_init_err;
@@ -323,7 +329,7 @@ oc_connectivity_init_ip(void)
         join.mm_idx = itf.mif_idx;
         join.mm_family = MN_AF_INET6;
 
-        rc = mn_setsockopt(oc_mcast, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
+        rc = mn_setsockopt(oc_mcast6, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &join);
         if (rc != 0) {
             continue;
         }
@@ -332,7 +338,7 @@ oc_connectivity_init_ip(void)
     }
 
     sin.msin6_port = htons(COAP_PORT_UNSECURED);
-    rc = mn_bind(oc_mcast, (struct mn_sockaddr *)&sin);
+    rc = mn_bind(oc_mcast6, (struct mn_sockaddr *)&sin);
     if (rc != 0) {
         OC_LOG_ERROR("Could not bind oc multicast socket\n");
         goto oc_connectivity_init_err;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/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 c4d205c..a7cce39 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -30,6 +30,11 @@ typedef struct {
     uint8_t scope;
 } oc_ipv6_addr_t;
 
+typedef struct {
+    uint16_t port;
+    uint8_t address[4];
+} oc_ipv4_addr_t;
+
 enum oc_transport_flags {
     IP = 1 << 0,
     GATT = 1 << 1,
@@ -37,6 +42,7 @@ enum oc_transport_flags {
     MULTICAST = 1 << 3,
     SECURED = 1 << 4,
     SERIAL = 1 << 5,
+    IP4 = 1 << 6,
 };
 
 /*
@@ -48,7 +54,10 @@ enum oc_transport_flags {
  */
 struct oc_endpoint_ip {
     enum oc_transport_flags flags;
-    oc_ipv6_addr_t v6;
+    union {
+        oc_ipv6_addr_t v6;
+        oc_ipv4_addr_t v4;
+    };
 };
 
 /*
@@ -83,6 +92,10 @@ typedef struct oc_endpoint {
     oc_endpoint_t __name__ = {.oe_ip = {.flags = __flags__,             \
                                         .v6 = {.port = __port__,        \
                                                .address = { __VA_ARGS__ } } } }
+#define oc_make_ip4_endpoint(__name__, __flags__, __port__, ...)        \
+    oc_endpoint_t __name__ = {.oe_ip = {.flags = __flags__,             \
+                                        .v4 = {.port = __port__,        \
+                                               .address = { __VA_ARGS__ } } } }
 
 #ifdef OC_SECURITY
 uint16_t oc_connectivity_get_dtls_port(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/net/oic/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/oic/syscfg.yml b/net/oic/syscfg.yml
index 3b7460a..51d86e2 100644
--- a/net/oic/syscfg.yml
+++ b/net/oic/syscfg.yml
@@ -29,6 +29,12 @@ syscfg.defs:
     OC_TRANSPORT_IP:
         description: 'Enables OIC transport over IP UDP'
         value: '0'
+    OC_TRANSPORT_IPV6:
+        description: 'Support IPv6'
+        value: '1'
+    OC_TRANSPORT_IPV4:
+        description: 'Support IPv4'
+        value: '0'
     OC_CLIENT:
         description: 'Enables OIC client support'
         value: '0'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea6d720/net/oic/test/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/oic/test/syscfg.yml b/net/oic/test/syscfg.yml
index 47ceb25..a8ed09e 100644
--- a/net/oic/test/syscfg.yml
+++ b/net/oic/test/syscfg.yml
@@ -20,5 +20,7 @@
 
 syscfg.vals:
   OC_TRANSPORT_IP: 1
+  OC_TRANSPORT_IPV6: 1
+  OC_TRANSPORT_IPV4: 0
   OC_SERVER: 1
   OC_CLIENT: 1


[47/50] incubator-mynewt-core git commit: MYNEWT-654 datetime command may crash device

Posted by ma...@apache.org.
MYNEWT-654 datetime command may crash device

There are two issues here:

1. newtmgr tool always includes an extraneous rc:0 key-value pair in its
   outgoing datetime commands.
2. Server-side, the firmware parses the "rc" value and writes the result
   to null.

This commit addresses the second issue as follows: Don't attempt to
parse the rc entry in incoming requests.


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

Branch: refs/heads/1_0_0_dev
Commit: 0dc1c2b85664cdde99c48f8628cacdc0c52e4852
Parents: e85707d
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Mar 4 14:24:38 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:54:14 2017 -0800

----------------------------------------------------------------------
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0dc1c2b8/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index 2a75d47..b69766e 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -271,17 +271,13 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
     struct os_timezone tz;
     char buf[DATETIME_BUFSIZE];
     int rc = 0;
-    const struct cbor_attr_t datetime_write_attr[3] = {
+    const struct cbor_attr_t datetime_write_attr[] = {
         [0] = {
             .attribute = "datetime",
             .type = CborAttrTextStringType,
             .addr.string = buf,
             .len = sizeof(buf),
         },
-        [1] = {
-            .attribute = "rc",
-            .type = CborAttrIntegerType,
-        },
         { 0 },
     };
 


[32/50] incubator-mynewt-core git commit: nimble/l2cap: Remove not needed function ble_l2cap_sig_init_cmd

Posted by ma...@apache.org.
nimble/l2cap: Remove not needed function ble_l2cap_sig_init_cmd

After refactor this function is not needed anymore in the host code.
The only user of it is unitest and this patch fixes that.


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

Branch: refs/heads/1_0_0_dev
Commit: d116c904a9cea94ac008dc179b59b1ccb353c89c
Parents: 79ed0c8
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Feb 28 13:23:41 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:00 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c     | 34 ----------------------
 net/nimble/host/test/src/ble_hs_test_util.c | 22 ++++-----------
 net/nimble/host/test/src/ble_l2cap_test.c   | 36 ++++++------------------
 3 files changed, 13 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d116c904/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index e6a7209..4381be5 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -21,40 +21,6 @@
 #include "ble_hs_priv.h"
 
 int
-ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
-                       struct os_mbuf **out_om, void **out_payload_buf)
-{
-    struct ble_l2cap_sig_hdr hdr;
-    struct os_mbuf *txom;
-    void *v;
-
-    *out_om = NULL;
-    *out_payload_buf = NULL;
-
-    txom = ble_hs_mbuf_l2cap_pkt();
-    if (txom == NULL) {
-        return BLE_HS_ENOMEM;
-    }
-
-    v = os_mbuf_extend(txom, BLE_L2CAP_SIG_HDR_SZ + payload_len);
-    if (v == NULL) {
-        os_mbuf_free(txom);
-        return BLE_HS_ENOMEM;
-    }
-
-    hdr.op = op;
-    hdr.identifier = id;
-    hdr.length = TOFROMLE16(payload_len);
-
-    ble_l2cap_sig_hdr_write(v, BLE_L2CAP_SIG_HDR_SZ, &hdr);
-
-    *out_om = txom;
-    *out_payload_buf = (uint8_t *)v + BLE_L2CAP_SIG_HDR_SZ;
-
-    return 0;
-}
-
-int
 ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
 {
     struct ble_l2cap_chan *chan;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d116c904/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index ceabd1c..0dc1b18 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1820,36 +1820,24 @@ ble_l2cap_sig_update_rsp_parse(void *payload, int len,
     dst->result = le16toh(src->result);
 }
 
-static void
-ble_l2cap_test_update_rsp_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *src)
-{
-    struct ble_l2cap_sig_update_rsp *dst = payload;
-
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    dst->result = htole16(src->result);
-}
-
 int
 ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
                                      uint8_t id, uint16_t result)
 {
-    struct ble_l2cap_sig_update_rsp rsp;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct hci_data_hdr hci_hdr;
     struct os_mbuf *om;
-    void *v;
     int rc;
 
     hci_hdr = BLE_HS_TEST_UTIL_L2CAP_HCI_HDR(
         2, BLE_HCI_PB_FIRST_FLUSH,
         BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ);
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
-                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &om, &v);
-    TEST_ASSERT_FATAL(rc == 0);
+    rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
+                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &om);
+    TEST_ASSERT_FATAL(rsp != NULL);
 
-    rsp.result = result;
-    ble_l2cap_test_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
+    rsp->result = htole16(result);
 
     rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
                                               &hci_hdr, om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d116c904/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index 2958a6c..9c11607 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -44,46 +44,26 @@ ble_l2cap_test_util_init(void)
 }
 
 static void
-ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
-                              struct ble_l2cap_sig_update_req *src)
-{
-    dst->itvl_min = le16toh(src->itvl_min);
-    dst->itvl_max = le16toh(src->itvl_max);
-    dst->slave_latency = le16toh(src->slave_latency);
-    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
-}
-
-static void
-ble_l2cap_test_update_req_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_test_update_req_swap(payload, src);
-}
-
-static void
 ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
                                   struct ble_l2cap_sig_update_params *params)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct ble_l2cap_sig_update_req *req;
     struct hci_data_hdr hci_hdr;
     struct os_mbuf *om;
-    void *v;
     int rc;
 
     hci_hdr = BLE_HS_TEST_UTIL_L2CAP_HCI_HDR(
         2, BLE_HCI_PB_FIRST_FLUSH,
         BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ);
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
-                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &om, &v);
-    TEST_ASSERT_FATAL(rc == 0);
+    req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
+                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &om);
+    TEST_ASSERT_FATAL(req != NULL);
 
-    req.itvl_min = params->itvl_min;
-    req.itvl_max = params->itvl_max;
-    req.slave_latency = params->slave_latency;
-    req.timeout_multiplier = params->timeout_multiplier;
-    ble_l2cap_test_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
+    req->itvl_min = htole16(params->itvl_min);
+    req->itvl_max = htole16(params->itvl_max);
+    req->slave_latency = htole16(params->slave_latency);
+    req->timeout_multiplier = htole16(params->timeout_multiplier);
 
     ble_hs_test_util_set_ack(
         ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,


[07/50] incubator-mynewt-core git commit: MYNEWT-642 Eddystone buf: one byte too large.

Posted by ma...@apache.org.
MYNEWT-642 Eddystone buf: one byte too large.


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

Branch: refs/heads/1_0_0_dev
Commit: b41f55db3c44d544366887a2a0155a52d71434d3
Parents: 0c354af
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Feb 27 20:31:12 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:21 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_eddystone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b41f55db/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index 6132b78..f19191d 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -22,7 +22,7 @@
 #include "host/ble_hs_adv.h"
 #include "ble_hs_priv.h"
 
-#define BLE_EDDYSTONE_MAX_SVC_DATA_LEN  23
+#define BLE_EDDYSTONE_MAX_SVC_DATA_LEN  22
 #define BLE_EDDYSTONE_SVC_DATA_BASE_SZ  3
 
 #define BLE_EDDYSTONE_SERVICE_UUID      0xfeaa


[09/50] incubator-mynewt-core git commit: Expose os_dev_loookup()

Posted by ma...@apache.org.
Expose os_dev_loookup()

This enables users who want to share a OS device during init to
access it using the device name.  This should not be called at
runtime.


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

Branch: refs/heads/1_0_0_dev
Commit: 9ca5d71ca2813ef79693bfa873a736383f71ad84
Parents: 9cd6ba5
Author: Sterling Hughes <st...@runtime.io>
Authored: Tue Feb 21 16:39:03 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:36 2017 -0800

----------------------------------------------------------------------
 kernel/os/include/os/os_dev.h | 1 +
 kernel/os/src/os_dev.c        | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ca5d71c/kernel/os/include/os/os_dev.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_dev.h b/kernel/os/include/os/os_dev.h
index 5af06b2..ed65a08 100644
--- a/kernel/os/include/os/os_dev.h
+++ b/kernel/os/include/os/os_dev.h
@@ -108,6 +108,7 @@ os_dev_resume(struct os_dev *dev)
 
 int os_dev_create(struct os_dev *dev, char *name, uint8_t stage,
         uint8_t priority, os_dev_init_func_t od_init, void *arg);
+struct os_dev *os_dev_lookup(char *name);
 int os_dev_initialize_all(uint8_t stage);
 int os_dev_suspend_all(os_time_t, uint8_t);
 int os_dev_resume_all(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ca5d71c/kernel/os/src/os_dev.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_dev.c b/kernel/os/src/os_dev.c
index 139fe13..07b1c54 100644
--- a/kernel/os/src/os_dev.c
+++ b/kernel/os/src/os_dev.c
@@ -232,13 +232,16 @@ err:
 }
 
 /**
- * Lookup a device by name, internal function only.
+ * Lookup a device by name.
+ *
+ * WARNING: This should be called before any locking on the device is done, or
+ * the device list itself is modified in any context.  There is no locking.
  *
  * @param name The name of the device to look up.
  *
  * @return A pointer to the device corresponding to name, or NULL if not found.
  */
-static struct os_dev *
+struct os_dev *
 os_dev_lookup(char *name)
 {
     struct os_dev *dev;


[45/50] incubator-mynewt-core git commit: MYNEWT-527; nrf51-blenano fix typo in bsp.yml.

Posted by ma...@apache.org.
MYNEWT-527; nrf51-blenano fix typo in bsp.yml.


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

Branch: refs/heads/1_0_0_dev
Commit: 933f658e9c41bdb745c594c5b3a85d2a5fd48673
Parents: 9ee8e85
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 22:00:00 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:56 2017 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51-blenano/bsp.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/933f658e/hw/bsp/nrf51-blenano/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/bsp.yml b/hw/bsp/nrf51-blenano/bsp.yml
index ee95b51..c72efec 100644
--- a/hw/bsp/nrf51-blenano/bsp.yml
+++ b/hw/bsp/nrf51-blenano/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51-blenano/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51-blenano/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-blenano/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:


[10/50] incubator-mynewt-core git commit: MYNEWT-650 fs/fs/test build errors for non-native

Posted by ma...@apache.org.
MYNEWT-650 fs/fs/test build errors for non-native

The problem is that the fixed-size integer types map to different
"natural" integer types, depending on the target platform.
Unfortunately, the PRIxxx macros in inttypes.h don't work here, since
gcc assumes no cross compile when it generates the warning. The next
best solution is to cast everything to uintmax_t and apply the j format
specifier.


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

Branch: refs/heads/1_0_0_dev
Commit: 77b881d67efd57fb3f2e414213e71969fbe288a2
Parents: 9ca5d71
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 16:50:17 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:48 2017 -0800

----------------------------------------------------------------------
 fs/nffs/test/src/nffs_test_debug.c | 274 ++++++++++++++++++++------------
 1 file changed, 168 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/77b881d6/fs/nffs/test/src/nffs_test_debug.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_debug.c b/fs/nffs/test/src/nffs_test_debug.c
index 0d01fcf..f59fa42 100644
--- a/fs/nffs/test/src/nffs_test_debug.c
+++ b/fs/nffs/test/src/nffs_test_debug.c
@@ -64,8 +64,9 @@ print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
 
     name[inode.ni_filename_len] = '\0';
 
-    printf("%*s%s %d %x\n", indent, "", name[0] == '\0' ? "/" : name,
-           inode.ni_seq, inode.ni_inode_entry->nie_flags);
+    printf("%*s%s %ju %jx\n", indent, "", name[0] == '\0' ? "/" : name,
+           (uintmax_t) inode.ni_seq,
+           (uintmax_t) inode.ni_inode_entry->nie_flags);
 }
 
 void
@@ -99,16 +100,17 @@ print_nffs_flash_inode(struct nffs_area *area, uint32_t off)
     rc = hal_flash_read(area->na_flash_id, area->na_offset + off + sizeof(ndi),
                          filename, len);
 
-    printf("  off %x %s id %x flen %d seq %d last %x prnt %x flgs %x %s\n",
-           off,
+    printf("  off %jx %s id %jx flen %ju seq %ju last %jx prnt %jx "
+           "flgs %jx %s\n",
+           (uintmax_t) off,
            (nffs_hash_id_is_file(ndi.ndi_id) ? "File" :
             (nffs_hash_id_is_dir(ndi.ndi_id) ? "Dir" : "???")),
-           ndi.ndi_id,
-           ndi.ndi_filename_len,
-           ndi.ndi_seq,
-           ndi.ndi_lastblock_id,
-           ndi.ndi_parent_id,
-           ndi.ndi_flags,
+           (uintmax_t) ndi.ndi_id,
+           (uintmax_t) ndi.ndi_filename_len,
+           (uintmax_t) ndi.ndi_seq,
+           (uintmax_t) ndi.ndi_lastblock_id,
+           (uintmax_t) ndi.ndi_parent_id,
+           (uintmax_t) ndi.ndi_flags,
            filename);
     return sizeof(ndi) + ndi.ndi_filename_len;
 }
@@ -123,13 +125,13 @@ print_nffs_flash_block(struct nffs_area *area, uint32_t off)
                         &ndb, sizeof(ndb));
     assert(rc == 0);
 
-    printf("  off %x Block id %x len %d seq %d prev %x own ino %x\n",
-           off,
-           ndb.ndb_id,
-           ndb.ndb_data_len,
-           ndb.ndb_seq,
-           ndb.ndb_prev_id,
-           ndb.ndb_inode_id);
+    printf("  off %jx Block id %jx len %ju seq %ju prev %jx own ino %jx\n",
+           (uintmax_t) off,
+           (uintmax_t) ndb.ndb_id,
+           (uintmax_t) ndb.ndb_data_len,
+           (uintmax_t) ndb.ndb_seq,
+           (uintmax_t) ndb.ndb_prev_id,
+           (uintmax_t) ndb.ndb_inode_id);
     return sizeof(ndb) + ndb.ndb_data_len;
 }
 
@@ -176,9 +178,16 @@ print_nffs_flash_areas(int verbose)
         if (!nffs_area_magic_is_set(&darea)) {
             printf("Area header corrupt!\n");
         }
-        printf("area %d: id %d %x-%x cur %x len %d flashid %x gc-seq %d %s%s\n",
-               i, area.na_id, area.na_offset, area.na_offset + area.na_length,
-               area.na_cur, area.na_length, area.na_flash_id, darea.nda_gc_seq,
+        printf("area %d: id %ju %jx-%jx cur %jx len %ju flashid %jx "
+               "gc-seq %jd %s%s\n",
+               i,
+               (uintmax_t)area.na_id,
+               (uintmax_t)area.na_offset,
+               (uintmax_t)area.na_offset + area.na_length,
+               (uintmax_t)area.na_cur,
+               (uintmax_t)area.na_length,
+               (uintmax_t)area.na_flash_id,
+               (uintmax_t)darea.nda_gc_seq,
                nffs_scratch_area_idx == i ? "(scratch)" : "",
                !nffs_area_magic_is_set(&darea) ? "corrupt" : "");
         if (verbose < 2) {
@@ -204,11 +213,12 @@ print_hashlist(struct nffs_hash_entry *he)
     list = nffs_hash + idx;
 
     SLIST_FOREACH(he, list, nhe_next) {
-        printf("hash_entry %s 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+        printf("hash_entry %s %p: id 0x%jx flash_loc 0x%jx next %p\n",
                    nffs_hash_id_is_inode(he->nhe_id) ? "inode" : "block",
-                   (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
    }
 }
 
@@ -228,10 +238,13 @@ print_hash(void)
 
     NFFS_HASH_FOREACH(he, i, next) {
         if (nffs_hash_id_is_inode(he->nhe_id)) {
-            printf("hash_entry inode %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry inode %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
             if (he->nhe_id == NFFS_ID_ROOT_DIR) {
                 continue;
             }
@@ -239,56 +252,66 @@ print_hash(void)
                                   &area_idx, &area_offset);
             rc = nffs_inode_read_disk(area_idx, area_offset, &di);
             if (rc) {
-                printf("%d: fail inode read id 0x%x rc %d\n",
-                       i, he->nhe_id, rc);
+                printf("%d: fail inode read id 0x%jx rc %d\n",
+                       i, (uintmax_t)he->nhe_id, rc);
             }
-            printf("    Disk inode: id %x seq %d parent %x last %x flgs %x\n",
-                   di.ndi_id,
-                   di.ndi_seq,
-                   di.ndi_parent_id,
-                   di.ndi_lastblock_id,
-                   di.ndi_flags);
+            printf("    Disk inode: id %jx seq %ju parent %jx last %jx "
+                   "flgs %jx\n",
+                   (uintmax_t)di.ndi_id,
+                   (uintmax_t)di.ndi_seq,
+                   (uintmax_t)di.ndi_parent_id,
+                   (uintmax_t)di.ndi_lastblock_id,
+                   (uintmax_t)di.ndi_flags);
             ni.ni_inode_entry = (struct nffs_inode_entry *)he;
             ni.ni_seq = di.ndi_seq; 
             ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
-            printf("    RAM inode: entry 0x%x seq %d parent %x filename %s\n",
-                   (unsigned int)ni.ni_inode_entry,
-                   ni.ni_seq,
-                   (unsigned int)ni.ni_parent,
+            printf("    RAM inode: entry %p seq %ju parent %p "
+                   "filename %s\n",
+                   ni.ni_inode_entry,
+                   (uintmax_t)ni.ni_seq,
+                   ni.ni_parent,
                    ni.ni_filename);
 
         } else if (nffs_hash_id_is_block(he->nhe_id)) {
-            printf("hash_entry block %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry block %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
             rc = nffs_block_from_hash_entry(&nb, he);
             if (rc) {
-                printf("%d: fail block read id 0x%x rc %d\n",
-                       i, he->nhe_id, rc);
+                printf("%d: fail block read id 0x%jx rc %d\n",
+                       i, (uintmax_t)he->nhe_id, rc);
             }
-            printf("    block: id %x seq %d inode %x prev %x\n",
-                   nb.nb_hash_entry->nhe_id, nb.nb_seq, 
-                   nb.nb_inode_entry->nie_hash_entry.nhe_id, 
-                   nb.nb_prev->nhe_id);
+            printf("    block: id %jx seq %ju inode %jx prev %jx\n",
+                   (uintmax_t)nb.nb_hash_entry->nhe_id,
+                   (uintmax_t)nb.nb_seq, 
+                   (uintmax_t)nb.nb_inode_entry->nie_hash_entry.nhe_id, 
+                   (uintmax_t)nb.nb_prev->nhe_id);
             nffs_flash_loc_expand(nb.nb_hash_entry->nhe_flash_loc,
                                   &area_idx, &area_offset);
             rc = nffs_block_read_disk(area_idx, area_offset, &db);
             if (rc) {
-                printf("%d: fail disk block read id 0x%x rc %d\n",
-                       i, nb.nb_hash_entry->nhe_id, rc);
+                printf("%d: fail disk block read id 0x%jx rc %d\n",
+                       i, (uintmax_t)nb.nb_hash_entry->nhe_id, rc);
             }
-            printf("    disk block: id %x seq %d inode %x prev %x len %d\n",
-                   db.ndb_id,
-                   db.ndb_seq,
-                   db.ndb_inode_id,
-                   db.ndb_prev_id,
-                   db.ndb_data_len);
+            printf("    disk block: id %jx seq %ju inode %jx prev %jx "
+                   "len %ju\n",
+                   (uintmax_t)db.ndb_id,
+                   (uintmax_t)db.ndb_seq,
+                   (uintmax_t)db.ndb_inode_id,
+                   (uintmax_t)db.ndb_prev_id,
+                   (uintmax_t)db.ndb_data_len);
         } else {
-            printf("hash_entry UNKNONN %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry UNKNONN %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
         }
     }
 
@@ -301,27 +324,32 @@ nffs_print_object(struct nffs_disk_object *dobj)
     struct nffs_disk_block *db = &dobj->ndo_disk_block;
 
     if (dobj->ndo_type == NFFS_OBJECT_TYPE_INODE) {
-        printf("    %s id %x seq %d prnt %x last %x\n",
+        printf("    %s id %jx seq %ju prnt %jx last %jx\n",
                nffs_hash_id_is_file(di->ndi_id) ? "File" :
                 nffs_hash_id_is_dir(di->ndi_id) ? "Dir" : "???",
-               di->ndi_id, di->ndi_seq, di->ndi_parent_id,
-               di->ndi_lastblock_id);
+               (uintmax_t)di->ndi_id,
+               (uintmax_t)di->ndi_seq,
+               (uintmax_t)di->ndi_parent_id,
+               (uintmax_t)di->ndi_lastblock_id);
     } else if (dobj->ndo_type != NFFS_OBJECT_TYPE_BLOCK) {
-        printf("    %s: id %x seq %d ino %x prev %x len %d\n",
+        printf("    %s: id %jx seq %ju ino %jx prev %jx len %ju\n",
                nffs_hash_id_is_block(db->ndb_id) ? "Block" : "Block?",
-               db->ndb_id, db->ndb_seq, db->ndb_inode_id,
-               db->ndb_prev_id, db->ndb_data_len);
+               (uintmax_t)db->ndb_id,
+               (uintmax_t)db->ndb_seq,
+               (uintmax_t)db->ndb_inode_id,
+               (uintmax_t)db->ndb_prev_id,
+               (uintmax_t)db->ndb_data_len);
     }
 }
 
 void
 print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
 {
-    struct nffs_block nb;
+    struct nffs_block nb = { 0 };
     struct nffs_disk_block db;
     uint32_t area_offset;
     uint8_t area_idx;
-    int rc;
+    int rc = 0;
 
     if (he == NULL) {
         return;
@@ -331,8 +359,8 @@ print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
                               &area_idx, &area_offset);
         rc = nffs_block_read_disk(area_idx, area_offset, &db);
         if (rc) {
-            printf("%p: fail block read id 0x%x rc %d\n",
-                   he, he->nhe_id, rc);
+            printf("%p: fail block read id 0x%jx rc %d\n",
+                   he, (uintmax_t)he->nhe_id, rc);
         }
         nb.nb_hash_entry = he;
         nb.nb_seq = db.ndb_seq;
@@ -352,28 +380,43 @@ print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
         db.ndb_id = 0;
     }
     if (!verbose) {
-        printf("%s%s id %x idx/off %d/%x seq %d ino %x prev %x len %d\n",
+        printf("%s%s id %jx idx/off %ju/%jx seq %ju ino %jx prev %jx "
+               "len %ju\n",
                nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
                nffs_hash_id_is_block(he->nhe_id) ? "Block" : "Unknown",
-               he->nhe_id, area_idx, area_offset, nb.nb_seq,
-               nb.nb_inode_entry->nie_hash_entry.nhe_id,
-               (unsigned int)db.ndb_prev_id, db.ndb_data_len);
+               (uintmax_t)he->nhe_id,
+               (uintmax_t)area_idx,
+               (uintmax_t)area_offset,
+               (uintmax_t)nb.nb_seq,
+               (uintmax_t)nb.nb_inode_entry->nie_hash_entry.nhe_id,
+               (uintmax_t)db.ndb_prev_id,
+               (uintmax_t)db.ndb_data_len);
         return;
     }
-    printf("%s%s id %x loc %x/%x %x ent %p\n",
+    printf("%s%s id %jx loc %jx/%jx %jx ent %p\n",
            nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
            nffs_hash_id_is_block(he->nhe_id) ? "Block:" : "Unknown:",
-           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+           (uintmax_t)he->nhe_id,
+           (uintmax_t)area_idx,
+           (uintmax_t)area_offset,
+           (uintmax_t)he->nhe_flash_loc,
+           he);
     if (nb.nb_inode_entry) {
-        printf("  Ram: ent %p seq %d ino %p prev %p len %d\n",
-               nb.nb_hash_entry, nb.nb_seq,
-               nb.nb_inode_entry, nb.nb_prev, nb.nb_data_len);
+        printf("  Ram: ent %p seq %ju ino %p prev %p len %ju\n",
+               nb.nb_hash_entry,
+               (uintmax_t)nb.nb_seq,
+               nb.nb_inode_entry,
+               nb.nb_prev,
+               (uintmax_t)nb.nb_data_len);
     }
     if (db.ndb_id) {
-        printf("  Disk %s id %x seq %d ino %x prev %x len %d\n",
+        printf("  Disk %s id %jx seq %ju ino %jx prev %jx len %ju\n",
                nffs_hash_id_is_block(db.ndb_id) ? "Block:" : "???:",
-               db.ndb_id, db.ndb_seq, db.ndb_inode_id,
-               db.ndb_prev_id, db.ndb_data_len);
+               (uintmax_t)db.ndb_id,
+               (uintmax_t)db.ndb_seq,
+               (uintmax_t)db.ndb_inode_id,
+               (uintmax_t)db.ndb_prev_id,
+               (uintmax_t)db.ndb_data_len);
     }
 }
 
@@ -386,7 +429,7 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
     int cached_name_len;
     uint32_t area_offset;
     uint8_t area_idx;
-    int rc;
+    int rc = 0;
 
     if (he == NULL) {
         return;
@@ -396,8 +439,8 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
                               &area_idx, &area_offset);
         rc = nffs_inode_read_disk(area_idx, area_offset, &di);
         if (rc) {
-            printf("Entry %p: fail inode read id 0x%x rc %d\n",
-                   he, he->nhe_id, rc);
+            printf("Entry %p: fail inode read id 0x%jx rc %d\n",
+                   he, (uintmax_t)he->nhe_id, rc);
         }
         ni.ni_inode_entry = (struct nffs_inode_entry *)he;
         ni.ni_seq = di.ndi_seq; 
@@ -415,8 +458,8 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
             rc = nffs_flash_read(area_idx, area_offset + sizeof di,
                          ni.ni_filename, cached_name_len);
             if (rc != 0) {
-                printf("entry %p: fail filename read id 0x%x rc %d\n",
-                       he, he->nhe_id, rc);
+                printf("entry %p: fail filename read id 0x%jx rc %d\n",
+                       he, (uintmax_t)he->nhe_id, rc);
                 return;
             }
         }
@@ -425,41 +468,56 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
         di.ndi_id = 0;
     }
     if (!verbose) {
-        printf("%s%s id %x idx/off %x/%x seq %d prnt %x last %x flags %x",
+        printf("%s%s id %jx idx/off %jx/%jx seq %ju prnt %jx last %jx "
+               "flags %jx",
                nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
-
                nffs_hash_id_is_file(he->nhe_id) ? "File" :
                 he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir" : 
                 nffs_hash_id_is_dir(he->nhe_id) ? "Dir" : "Inode",
 
-               he->nhe_id, area_idx, area_offset, ni.ni_seq, di.ndi_parent_id,
-               di.ndi_lastblock_id, nie->nie_flags);
+               (uintmax_t)he->nhe_id,
+               (uintmax_t)area_idx,
+               (uintmax_t)area_offset,
+               (uintmax_t)ni.ni_seq,
+               (uintmax_t)di.ndi_parent_id,
+               (uintmax_t)di.ndi_lastblock_id,
+               (uintmax_t)nie->nie_flags);
         if (ni.ni_inode_entry) {
-            printf(" ref %d\n", ni.ni_inode_entry->nie_refcnt);
+            printf(" ref %ju\n", (uintmax_t)ni.ni_inode_entry->nie_refcnt);
         } else {
             printf("\n");
         }
         return;
     }
-    printf("%s%s id %x loc %x/%x %x entry %p\n",
+    printf("%s%s id %jx loc %jx/%jx %jx entry %p\n",
            nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
            nffs_hash_id_is_file(he->nhe_id) ? "File:" :
             he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir:" : 
             nffs_hash_id_is_dir(he->nhe_id) ? "Dir:" : "Inode:",
-           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+           (uintmax_t)he->nhe_id,
+           (uintmax_t)area_idx,
+           (uintmax_t)area_offset,
+           (uintmax_t)he->nhe_flash_loc,
+           he);
     if (ni.ni_inode_entry) {
-        printf("  ram: ent %p seq %d prnt %p lst %p ref %d flgs %x nm %s\n",
-               ni.ni_inode_entry, ni.ni_seq, ni.ni_parent,
+        printf("  ram: ent %p seq %ju prnt %p lst %p ref %ju flgs %jx nm %s\n",
+               ni.ni_inode_entry,
+               (uintmax_t)ni.ni_seq,
+               ni.ni_parent,
                ni.ni_inode_entry->nie_last_block_entry,
-               ni.ni_inode_entry->nie_refcnt, ni.ni_inode_entry->nie_flags,
+               (uintmax_t)ni.ni_inode_entry->nie_refcnt,
+               (uintmax_t)ni.ni_inode_entry->nie_flags,
                ni.ni_filename);
     }
     if (rc == 0) {
-        printf("  Disk %s: id %x seq %d prnt %x lst %x flgs %x\n",
+        printf("  Disk %s: id %jx seq %ju prnt %jx lst %jx flgs %jx\n",
                nffs_hash_id_is_file(di.ndi_id) ? "File" :
                 nffs_hash_id_is_dir(di.ndi_id) ? "Dir" : "???",
-               di.ndi_id, di.ndi_seq, di.ndi_parent_id,
-               di.ndi_lastblock_id, di.ndi_flags);
+               (uintmax_t)di.ndi_id,
+               (uintmax_t)di.ndi_seq,
+               (uintmax_t)di.ndi_parent_id,
+               (uintmax_t)di.ndi_lastblock_id,
+               (uintmax_t)di.ndi_flags);
     }
 }
 
@@ -480,8 +538,10 @@ print_hash_entries(int verbose)
             } else if (nffs_hash_id_is_block(he->nhe_id)) {
                 print_nffs_hash_block(he, verbose);
             } else {
-                printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
-                       i, he->nhe_id, he->nhe_flash_loc);
+                printf("UNKNOWN type hash entry %d: id 0x%jx loc 0x%jx\n",
+                       i,
+                       (uintmax_t)he->nhe_id,
+                       (uintmax_t)he->nhe_flash_loc);
             }
             he = next;
         }
@@ -501,8 +561,10 @@ print_nffs_hashlist(int verbose)
         } else if (nffs_hash_id_is_block(he->nhe_id)) {
             print_nffs_hash_block(he, verbose);
         } else {
-            printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
-                   i, he->nhe_id, he->nhe_flash_loc);
+            printf("UNKNOWN type hash entry %d: id 0x%jx loc 0x%jx\n",
+                   i,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc);
         }
     }
 }


[16/50] incubator-mynewt-core git commit: MYNEWT-492 Add missing syscfg setting descriptions

Posted by ma...@apache.org.
MYNEWT-492 Add missing syscfg setting descriptions


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

Branch: refs/heads/1_0_0_dev
Commit: c664f02a82418627968de5aefb9514610154c832
Parents: fdc8e21
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 17:41:40 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:42 2017 -0800

----------------------------------------------------------------------
 hw/bsp/ci40/syscfg.yml                      |   2 +-
 net/nimble/host/services/bleuart/syscfg.yml |   4 +-
 net/nimble/host/syscfg.yml                  | 179 ++++++++++++++++-------
 net/nimble/syscfg.yml                       |  18 ++-
 4 files changed, 142 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c664f02a/hw/bsp/ci40/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ci40/syscfg.yml b/hw/bsp/ci40/syscfg.yml
index ddcf459..09b7da4 100644
--- a/hw/bsp/ci40/syscfg.yml
+++ b/hw/bsp/ci40/syscfg.yml
@@ -21,7 +21,7 @@
 
 syscfg.defs:
     CLOCK_FREQ:
-        description: 'TBD'
+        description: 'Clock frequency (hertz).'
         value:  546000000ul
 
     UART_0:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c664f02a/net/nimble/host/services/bleuart/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/bleuart/syscfg.yml b/net/nimble/host/services/bleuart/syscfg.yml
index 328838d..8ce3e63 100644
--- a/net/nimble/host/services/bleuart/syscfg.yml
+++ b/net/nimble/host/services/bleuart/syscfg.yml
@@ -20,5 +20,7 @@
 
 syscfg.defs:
     BLEUART_MAX_INPUT:
-        description: 'TBD'
+        description: >
+            The size of the largest line that can be received over the UART
+            service.
         value: 120

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c664f02a/net/nimble/host/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/syscfg.yml b/net/nimble/host/syscfg.yml
index 6a52b82..d7ffddb 100644
--- a/net/nimble/host/syscfg.yml
+++ b/net/nimble/host/syscfg.yml
@@ -25,21 +25,30 @@ syscfg.defs:
 
     # Debug settings.
     BLE_HS_DEBUG:
-        description: 'TBD'
+        description: 'Enables extra runtime assertions.'
         value: 0
     BLE_HS_PHONY_HCI_ACKS:
-        description: 'TBD'
+        description: >
+            Rather than wait for HCI acknowledgements from a controller, the
+            host simulates incoming acks.  Only recommended for test code
+            running in the simulator.
         value: 0
     BLE_HS_REQUIRE_OS:
-        description: 'TBD'
+        description: >
+            Specifies whether the host can depend on the kernel being present.
+            This should only be disabled for unit tests running in the
+            simulator.
         value: 1
 
     # L2CAP settings.
     BLE_L2CAP_MAX_CHANS:
-        description: 'TBD'
+        description: >
+            The number of L2CAP channels to allocate.  The default value allows
+            for the signal, ATT, and SM channels for each connection.
         value: '3*MYNEWT_VAL_BLE_MAX_CONNECTIONS'
     BLE_L2CAP_SIG_MAX_PROCS:
-        description: 'TBD'
+        description: >
+            The maximum number of concurrent L2CAP signal procedures.
         value: 1
     BLE_L2CAP_JOIN_RX_FRAGS:
         description: >
@@ -69,147 +78,213 @@ syscfg.defs:
         value: 0
 
     BLE_SM_MAX_PROCS:
-        description: 'TBD'
+        description: >
+            The maximum number of concurrent security manager procedures.
         value: 1
     BLE_SM_IO_CAP:
-        description: 'TBD'
+        description: >
+            The IO capabilities to report during pairing.  Valid values are:
+                BLE_HS_IO_DISPLAY_ONLY
+                BLE_HS_IO_DISPLAY_YESNO
+                BLE_HS_IO_KEYBOARD_ONLY
+                BLE_HS_IO_NO_INPUT_OUTPUT
+                BLE_HS_IO_KEYBOARD_DISPLAY
         value: 'BLE_HS_IO_NO_INPUT_OUTPUT'
     BLE_SM_OOB_DATA_FLAG:
-        description: 'TBD'
+        description: >
+            Whether the out-of-band pairing algorithm is advertised. (0/1)
         value: 0
     BLE_SM_BONDING:
-        description: 'TBD'
+        description: >
+            Enables bonding (persistence and restoration of secure links). (0/1)
         value: 0
     BLE_SM_MITM:
-        description: 'TBD'
+        description: >
+            Whether man-in-the-middle protection is advertised during
+            pairing. (0/1)
         value: 0
     BLE_SM_KEYPRESS:
-        description: 'TBD'
+        description: >
+            Whether keypress support is advertised during pairing. (0/1)
         value: 0
     BLE_SM_OUR_KEY_DIST:
-        description: 'TBD'
+        description: >
+            A bitmap indicating which keys to distribute during pairing.  The
+            bits are defined as follows:
+                0x01: BLE_SM_PAIR_KEY_DIST_ENC
+                0x02: BLE_SM_PAIR_KEY_DIST_ID
+                0x04: BLE_SM_PAIR_KEY_DIST_SIGN
+                0x08: BLE_SM_PAIR_KEY_DIST_LINK
         value: 0
     BLE_SM_THEIR_KEY_DIST:
-        description: 'TBD'
+        description: >
+            A bitmap indicating which keys to accept during pairing.  The
+            bits are defined as follows:
+                0x01: BLE_SM_PAIR_KEY_DIST_ENC
+                0x02: BLE_SM_PAIR_KEY_DIST_ID
+                0x04: BLE_SM_PAIR_KEY_DIST_SIGN
+                0x08: BLE_SM_PAIR_KEY_DIST_LINK
         value: 0
 
     # Supported GATT procedures.  By default:
     #     o Notify and indicate are enabled;
     #     o All other procedures are enabled for centrals.
     BLE_GATT_DISC_ALL_SVCS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Primary Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_SVC_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Discover Primary Services by Service UUID GATT
+            procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_FIND_INC_SVCS:
-        description: 'TBD'
+        description: >
+            Enables the Find Included Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_ALL_CHRS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Characteristics of a Service GATT
+            procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_CHR_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Discover Characteristics by UUID GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_ALL_DSCS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Primary Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ:
-        description: 'TBD'
+        description: >
+            Enables the Read Characteristic Value GATT procedure. (0/1)
+            (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Read Using Characteristic UUID GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_LONG:
-        description: 'TBD'
+        description: >
+            Enables the Read Long Characteristic Values GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_MULT:
-        description: 'TBD'
+        description: >
+            Enables the Read Multiple Characteristic Values GATT procedure.
+            (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_NO_RSP:
-        description: 'TBD'
+        description: >
+            Enables the Write Without Response GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_SIGNED_WRITE:
-        description: 'TBD'
+        description: >
+            Enables the Signed Write Without Response GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE:
-        description: 'TBD'
+        description: >
+            Enables the Write Characteristic Value GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_LONG:
-        description: 'TBD'
+        description: >
+            Enables the Write Long Characteristic Values GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_RELIABLE:
-        description: 'TBD'
+        description: >
+            Enables the Reliable Writes GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_NOTIFY:
-        description: 'TBD'
+        description: >
+            Enables sending and receiving of GATT notifications. (0/1)
         value: 1
     BLE_GATT_INDICATE:
-        description: 'TBD'
+        description: >
+            Enables sending and receiving of GATT indications. (0/1)
         value: 1
 
     # GATT options.
     BLE_GATT_READ_MAX_ATTRS:
         description: >
             The maximum number of attributes that can be read with a single
-            GATT Read Multiple Characteristic Values procedure.
+            GATT Read Multiple Characteristic Values procedure. (0/1)
         value: 8
     BLE_GATT_WRITE_MAX_ATTRS:
         description: >
             The maximum number of attributes that can be written with a single
-            GATT Reliable Write procedure.
+            GATT Reliable Write procedure. (0/1)
         value: 4
     BLE_GATT_MAX_PROCS:
         description: >
-            The maximum number of concurrent client GATT procedures.
+            The maximum number of concurrent client GATT procedures. (0/1)
         value: 4
     BLE_GATT_RESUME_RATE:
         description: >
             The rate to periodically resume GATT procedures that have stalled
-            due to memory exhaustion.  Units are milliseconds.
+            due to memory exhaustion. (0/1)  Units are milliseconds. (0/1)
         value: 1000
 
-    # Supported server ATT commands.
+    # Supported server ATT commands. (0/1)
     BLE_ATT_SVR_FIND_INFO:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Find Information Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_FIND_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Find By Type Value Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_READ_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read By Type Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_READ_BLOB:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Blob Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ_MULT:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Multiple Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ_GROUP_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read by Group Type Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_WRITE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Write Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_WRITE_NO_RSP:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Write Command ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_SIGNED_WRITE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Signed Write Command ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_QUEUED_WRITE:
         description: >
-            Whether the device can receive ATT queued writes (prepare write
-            and execute write requests).
+            Enables processing of incoming Prepare Write Request and Execute
+            Write Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_NOTIFY:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Handle Value Notification ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_INDICATE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Handle Value Indication ATT
+            commands.  (0/1)
         value: 1
 
     # ATT options.
@@ -230,10 +305,12 @@ syscfg.defs:
 
     # Privacy options.
     BLE_RPA_TIMEOUT:
-        description: 'TBD'
+        description: >
+            The rate that new random addresses should be generated (seconds).
         value: 300
 
     # Miscellaneous features.
     BLE_EDDYSTONE:
-        description: 'TBD'
+        description: >
+            Enables advertising of Eddystone beacons.
         value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c664f02a/net/nimble/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/syscfg.yml b/net/nimble/syscfg.yml
index f44da01..7f348b8 100644
--- a/net/nimble/syscfg.yml
+++ b/net/nimble/syscfg.yml
@@ -21,23 +21,25 @@
 syscfg.defs:
     # Supported GAP roles.  By default, all four roles are enabled.
     BLE_ROLE_CENTRAL:
-        description: 'TBD'
+        description: 'Enables the Central bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_PERIPHERAL:
-        description: 'TBD'
+        description: 'Enables the Peripheral bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_BROADCASTER:
-        description: 'TBD'
+        description: 'Enables the Broadcaster bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_OBSERVER:
-        description: 'TBD'
+        description: 'Enables the Observer bluetooth role. (0/1)'
         value: 1
 
     BLE_MAX_CONNECTIONS:
         description: 'The maximum number of concurrent connections.'
         value: 1
     BLE_WHITELIST:
-        description: 'TBD'
+        description: >
+            Enables the BLE whitelist for controlling who to connect to or
+            accept a connection from. (0/1)
         value: 1
     BLE_MULTI_ADV_SUPPORT:
         description: 'Support for multi-advertisers'
@@ -45,7 +47,7 @@ syscfg.defs:
     BLE_MULTI_ADV_INSTANCES:
         description: >
             This is the number of multi-advertising instances. This is NOT the
-            total number of advertising instances. The total number of advertising
-            instances is this number plus 1 (assuming the device supports
-            advertising).
+            total number of advertising instances. The total number of
+            advertising instances is this number plus 1 (assuming the device
+            supports advertising).
         value: 0


[41/50] incubator-mynewt-core git commit: nimble/l2cap: Fix for possible memory leak

Posted by ma...@apache.org.
nimble/l2cap: Fix for possible memory leak

With this patch we remove allocated memory for proc in case we could
not allocate signaling request later on.


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

Branch: refs/heads/1_0_0_dev
Commit: 45c365cff9bd4b14371707320fdc784b293576a5
Parents: f6b3b22
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 09:24:35 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:18 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/45c365cf/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index a33ddef..444a8f6 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -990,7 +990,8 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
     req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_DISCONN_REQ, proc->id,
                                 sizeof(*req), &txom);
     if (!req) {
-        return BLE_HS_ENOMEM;
+        rc = BLE_HS_ENOMEM;
+        goto done;
     }
 
     req->dcid = htole16(chan->dcid);
@@ -998,6 +999,7 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
 
     rc = ble_l2cap_sig_tx(proc->conn_handle, txom);
 
+done:
     ble_l2cap_sig_process_status(proc, rc);
 
     return rc;


[48/50] incubator-mynewt-core git commit: Fix invalid memory accesses in ble_uuid_cmp

Posted by ma...@apache.org.
Fix invalid memory accesses in ble_uuid_cmp

When the two uuid values differ in type, one of two things can happen:

1. Access to unallocated or uninitialised memory
2. Unaligned access to 16/32-bit values

Both of these cause crashes, so always make sure we are comparing like types.


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

Branch: refs/heads/1_0_0_dev
Commit: 69588392a5d86b41c47bb0e863138feb1c14fe76
Parents: 0dc1c2b
Author: Simon Ratner <si...@probablyprime.net>
Authored: Sat Mar 4 12:02:40 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:54:25 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_uuid.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/69588392/net/nimble/host/src/ble_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid.c b/net/nimble/host/src/ble_uuid.c
index 028e227..f9ccc6d 100644
--- a/net/nimble/host/src/ble_uuid.c
+++ b/net/nimble/host/src/ble_uuid.c
@@ -76,6 +76,10 @@ ble_uuid_cmp(const ble_uuid_t *uuid1, const ble_uuid_t *uuid2)
     BLE_HS_DBG_ASSERT(verify_uuid(uuid1) == 0);
     BLE_HS_DBG_ASSERT(verify_uuid(uuid2) == 0);
 
+    if (uuid1->type != uuid2->type) {
+      return uuid1->type - uuid2->type;
+    }
+
     switch (uuid1->type) {
     case BLE_UUID_TYPE_16:
         return (int) BLE_UUID16(uuid1)->value - (int) BLE_UUID16(uuid2)->value;


[14/50] incubator-mynewt-core git commit: MYNEWT-509 - Specify min-write-sz per MCU.

Posted by ma...@apache.org.
MYNEWT-509 - Specify min-write-sz per MCU.


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

Branch: refs/heads/1_0_0_dev
Commit: dffe45054f04cb5ec816c1752959008ee73cac46
Parents: 58ea0a5
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 16:37:51 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:23 2017 -0800

----------------------------------------------------------------------
 hw/mcu/mips/danube/syscfg.yml     | 26 ++++++++++++++++++++++++++
 hw/mcu/native/syscfg.yml          | 26 ++++++++++++++++++++++++++
 hw/mcu/nordic/nrf51xxx/syscfg.yml | 26 ++++++++++++++++++++++++++
 hw/mcu/nordic/nrf52xxx/syscfg.yml | 26 ++++++++++++++++++++++++++
 hw/mcu/nxp/MK64F12/syscfg.yml     | 26 ++++++++++++++++++++++++++
 hw/mcu/stm/stm32f4xx/syscfg.yml   | 26 ++++++++++++++++++++++++++
 6 files changed, 156 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/mips/danube/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/mips/danube/syscfg.yml b/hw/mcu/mips/danube/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/mips/danube/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/native/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/native/syscfg.yml b/hw/mcu/native/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/native/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/nordic/nrf51xxx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/syscfg.yml b/hw/mcu/nordic/nrf51xxx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/nordic/nrf51xxx/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/nordic/nrf52xxx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/syscfg.yml b/hw/mcu/nordic/nrf52xxx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/nordic/nrf52xxx/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/nxp/MK64F12/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nxp/MK64F12/syscfg.yml b/hw/mcu/nxp/MK64F12/syscfg.yml
new file mode 100644
index 0000000..824f039
--- /dev/null
+++ b/hw/mcu/nxp/MK64F12/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 8

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dffe4505/hw/mcu/stm/stm32f4xx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/syscfg.yml b/hw/mcu/stm/stm32f4xx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/stm/stm32f4xx/syscfg.yml
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1


[44/50] incubator-mynewt-core git commit: nimble/l2cap: Add initial credits calculations

Posted by ma...@apache.org.
nimble/l2cap: Add initial credits calculations

With this patch we calculate initial credits in that way that
peer device is able to send full SDU by fill up fully LE frames.

If it happens that peer is not filling up LE Frames, there is mechanism
to handling it already in receiving function


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

Branch: refs/heads/1_0_0_dev
Commit: 9ee8e85e296d9e49aaedff9998074a01364e3b69
Parents: 687403e
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Fri Mar 3 11:30:45 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:47 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c  | 16 ++++++++++------
 net/nimble/host/src/ble_l2cap_priv.h |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ee8e85e/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index f7ecef4..fbfbf31 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -249,9 +249,14 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
     chan->my_mtu = BLE_L2CAP_COC_MTU;
     chan->rx_fn = ble_l2cap_coc_rx_fn;
     chan->coc_rx.mtu = mtu;
-    chan->coc_rx.credits = 10; /* FIXME Calculate it */
     chan->coc_rx.sdu = sdu_rx;
 
+    /* Number of credits should allow to send full SDU with on given
+     * L2CAP MTU
+     */
+    chan->coc_rx.credits = (mtu + (chan->my_mtu - 1) / 2) / chan->my_mtu;
+
+    chan->initial_credits = chan->coc_rx.credits;
     return chan;
 }
 
@@ -459,13 +464,12 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
         return;
     }
 
-    /* FIXME 10 is hardcoded - make it better.
-     * We want to back only that much credits which remote side is missing
+    /* We want to back only that much credits which remote side is missing
      * to be able to send complete SDU.
      */
-    if (chan->coc_rx.credits < 10) {
-        ble_l2cap_sig_le_credits(chan, 10 - chan->coc_rx.credits);
-        chan->coc_rx.credits = 10;
+    if (chan->coc_rx.credits < c->initial_credits) {
+        ble_l2cap_sig_le_credits(chan, c->initial_credits - chan->coc_rx.credits);
+        chan->coc_rx.credits = c->initial_credits;
     }
 
     ble_hs_unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ee8e85e/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 5db63c3..1d035e8 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -82,6 +82,7 @@ struct ble_l2cap_chan {
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;
+    uint16_t initial_credits;
     ble_l2cap_event_fn *cb;
     void *cb_arg;
 #endif


[34/50] incubator-mynewt-core git commit: nimble/l2cap: Remove not needed **om from ble_l2cap_rx_fn

Posted by ma...@apache.org.
nimble/l2cap: Remove not needed **om from ble_l2cap_rx_fn

Since this callback function has ble_l2cap_chan as a parameter,
we don't need to provide there os_mbuf with data as this is already
in chan->rx_buf


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

Branch: refs/heads/1_0_0_dev
Commit: bf2443799b36ea1202e200bee9d911fe99e56466
Parents: 505cea6
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 15:00:25 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:16 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c               |  6 +++++-
 net/nimble/host/src/ble_hs_hci_evt.c        |  7 ++-----
 net/nimble/host/src/ble_l2cap.c             |  7 +++----
 net/nimble/host/src/ble_l2cap_coc.c         |  2 +-
 net/nimble/host/src/ble_l2cap_priv.h        |  3 +--
 net/nimble/host/src/ble_l2cap_sig.c         |  8 ++++++--
 net/nimble/host/src/ble_sm.c                | 14 +++++++++-----
 net/nimble/host/test/src/ble_hs_test_util.c |  7 ++-----
 net/nimble/host/test/src/ble_l2cap_test.c   |  2 +-
 9 files changed, 30 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 7876e0d..7fe095b 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -461,11 +461,12 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan)
 }
 
 static int
-ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_att_rx(struct ble_l2cap_chan *chan)
 {
     const struct ble_att_rx_dispatch_entry *entry;
     uint8_t op;
     uint16_t conn_handle;
+    struct os_mbuf **om;
     int rc;
 
     conn_handle = ble_l2cap_get_conn_handle(chan);
@@ -473,6 +474,9 @@ ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
         return BLE_HS_ENOTCONN;
     }
 
+    om = &chan->rx_buf;
+    BLE_HS_DBG_ASSERT(*om != NULL);
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EMSGSIZE;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
index 7f868a6..cd98f7f 100644
--- a/net/nimble/host/src/ble_hs_hci_evt.c
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -612,7 +612,6 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
     struct hci_data_hdr hci_hdr;
     struct ble_hs_conn *conn;
     ble_l2cap_rx_fn *rx_cb;
-    struct os_mbuf *rx_buf;
     uint16_t conn_handle;
     int reject_cid;
     int rc;
@@ -648,7 +647,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
         reject_cid = -1;
     } else {
         /* Forward ACL data to L2CAP. */
-        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf, &reject_cid);
+        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &reject_cid);
         om = NULL;
     }
 
@@ -658,10 +657,8 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
     case 0:
         /* Final fragment received. */
         BLE_HS_DBG_ASSERT(rx_cb != NULL);
-        BLE_HS_DBG_ASSERT(rx_buf != NULL);
-        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan);
         ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
-        os_mbuf_free_chain(rx_buf);
         break;
 
     case BLE_HS_EAGAIN:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index d909b78..306eac1 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -173,6 +173,7 @@ void
 ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {
     conn->bhc_rx_chan = NULL;
+    os_mbuf_free_chain(chan->rx_buf);
     chan->rx_buf = NULL;
     chan->rx_len = 0;
 }
@@ -209,7 +210,7 @@ ble_l2cap_append_rx(struct ble_l2cap_chan *chan, struct os_mbuf *frag)
 static int
 ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                      struct os_mbuf *om,
-                     ble_l2cap_rx_fn **out_rx_cb, struct os_mbuf **out_rx_buf)
+                     ble_l2cap_rx_fn **out_rx_cb)
 {
     int len_diff;
     int rc;
@@ -231,7 +232,6 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
     } else if (len_diff == 0) {
         /* All fragments received. */
         *out_rx_cb = chan->rx_fn;
-        *out_rx_buf = chan->rx_buf;
         rc = 0;
     } else {
         /* More fragments remain. */
@@ -299,7 +299,6 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
              struct hci_data_hdr *hci_hdr,
              struct os_mbuf *om,
              ble_l2cap_rx_fn **out_rx_cb,
-             struct os_mbuf **out_rx_buf,
              int *out_reject_cid)
 {
     struct ble_l2cap_chan *chan;
@@ -367,7 +366,7 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
         goto err;
     }
 
-    rc = ble_l2cap_rx_payload(conn, chan, om, out_rx_cb, out_rx_buf);
+    rc = ble_l2cap_rx_payload(conn, chan, om, out_rx_cb);
     om = NULL;
     if (rc != 0) {
         goto err;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 178370d..ac1b6fa 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -117,7 +117,7 @@ ble_l2cap_coc_srv_find(uint16_t psm)
 }
 
 static int
-ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom)
+ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan)
 {
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 64ffa22..5db63c3 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -62,7 +62,7 @@ extern struct os_mempool ble_l2cap_chan_pool;
 
 typedef uint8_t ble_l2cap_chan_flags;
 
-typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom);
+typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
@@ -113,7 +113,6 @@ int ble_l2cap_rx(struct ble_hs_conn *conn,
                  struct hci_data_hdr *hci_hdr,
                  struct os_mbuf *om,
                  ble_l2cap_rx_fn **out_rx_cb,
-                 struct os_mbuf **out_rx_buf,
                  int *out_reject_cid);
 int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                  struct os_mbuf *txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 93d73ed..abc00ae 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1012,13 +1012,17 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
  *****************************************************************************/
 
 static int
-ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_l2cap_sig_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_l2cap_sig_hdr hdr;
     ble_l2cap_sig_rx_fn *rx_cb;
-    uint16_t conn_handle = chan->conn_handle;
+    uint16_t conn_handle;
+    struct os_mbuf **om;
     int rc;
 
+    conn_handle = chan->conn_handle;
+    om = &chan->rx_buf;
+
     STATS_INC(ble_l2cap_stats, sig_rx);
     BLE_HS_LOG(DEBUG, "L2CAP - rxed signalling msg: ");
     ble_hs_log_mbuf(*om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 603d99c..ef2f41b 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2326,12 +2326,13 @@ ble_sm_unbond(uint8_t peer_id_addr_type, const uint8_t *peer_id_addr)
 }
 
 static int
-ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_sm_result res;
     ble_sm_rx_fn *rx_cb;
     uint8_t op;
     uint16_t conn_handle;
+    struct os_mbuf *om;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sm_rx);
@@ -2341,19 +2342,22 @@ ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
         return BLE_HS_ENOTCONN;
     }
 
-    rc = os_mbuf_copydata(*om, 0, 1, &op);
+    om = chan->rx_buf;
+    BLE_HS_DBG_ASSERT(om != NULL);
+
+    rc = os_mbuf_copydata(om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EBADDATA;
     }
 
     /* Strip L2CAP SM header from the front of the mbuf. */
-    os_mbuf_adj(*om, 1);
+    os_mbuf_adj(om, 1);
 
     rx_cb = ble_sm_dispatch_get(op);
     if (rx_cb != NULL) {
         memset(&res, 0, sizeof res);
 
-        rx_cb(conn_handle, om, &res);
+        rx_cb(conn_handle, &om, &res);
         ble_sm_process_result(conn_handle, &res);
         rc = res.app_status;
     } else {
@@ -2491,7 +2495,7 @@ ble_sm_init(void)
  * simple
  */
 static int
-ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_sm_pair_fail *cmd;
     struct os_mbuf *txom;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 9fa2d3d..d084c39 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -934,7 +934,6 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
 {
     struct ble_hs_conn *conn;
     ble_l2cap_rx_fn *rx_cb;
-    struct os_mbuf *rx_buf;
     int reject_cid;
     int rc;
 
@@ -942,7 +941,7 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
 
     conn = ble_hs_conn_find(conn_handle);
     if (conn != NULL) {
-        rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &rx_buf, &reject_cid);
+        rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &reject_cid);
     } else {
         os_mbuf_free_chain(om);
     }
@@ -953,10 +952,8 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
         rc = BLE_HS_ENOTCONN;
     } else if (rc == 0) {
         TEST_ASSERT_FATAL(rx_cb != NULL);
-        TEST_ASSERT_FATAL(rx_buf != NULL);
-        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan);
         ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
-        os_mbuf_free_chain(rx_buf);
     } else if (rc == BLE_HS_EAGAIN) {
         /* More fragments on the way. */
         rc = 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bf244379/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index e68971d..3fc7876 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -94,7 +94,7 @@ ble_l2cap_test_util_verify_tx_update_conn(
 }
 
 static int
-ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan)
 {
     return 0;
 }


[24/50] incubator-mynewt-core git commit: bletiny: Add error print when L2CAP LE CoC disconnect fails

Posted by ma...@apache.org.
bletiny: Add error print when L2CAP LE CoC disconnect fails


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

Branch: refs/heads/1_0_0_dev
Commit: 07b86ffe1cdea5cc8474d9c8f4e4f9c6294a02af
Parents: 0aef480
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 11:16:15 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:54 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/07b86ffe/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 442a264..c0177c0 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1740,6 +1740,7 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
     struct bletiny_conn *conn;
     struct bletiny_l2cap_coc *coc;
     int i;
+    int rc = 0;
 
     conn = bletiny_conn_find(conn_handle);
     assert(conn != NULL);
@@ -1753,9 +1754,12 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
     }
     assert(coc != NULL);
 
-    ble_l2cap_disconnect(coc->chan);
+    rc = ble_l2cap_disconnect(coc->chan);
+    if (rc) {
+        console_printf("Could not disconnect channel rc=%d\n", rc);
+    }
 
-    return 0;
+    return rc;
 #endif
 }
 


[28/50] incubator-mynewt-core git commit: nimble/l2cap: Refactor update parameters handling

Posted by ma...@apache.org.
nimble/l2cap: Refactor update parameters handling

With this patch l2cap update parameters is handled in similar way as
other signaling commands.


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

Branch: refs/heads/1_0_0_dev
Commit: 7f09f382687436e4a7dfda0a83354967028f7bfa
Parents: 1759bdf
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 10:21:57 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:26 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c         | 55 +++++++++-----
 net/nimble/host/src/ble_l2cap_sig_cmd.c     | 94 ------------------------
 net/nimble/host/src/ble_l2cap_sig_priv.h    | 17 +----
 net/nimble/host/test/src/ble_hs_test_util.c | 42 ++++++++++-
 net/nimble/host/test/src/ble_l2cap_test.c   | 20 ++++-
 5 files changed, 98 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f09f382/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 9292137..7919a89 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -336,7 +336,9 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
                             struct ble_l2cap_sig_hdr *hdr,
                             struct os_mbuf **om)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct ble_l2cap_sig_update_req *req;
+    struct os_mbuf *txom;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct ble_gap_upd_params params;
     ble_hs_conn_flags_t conn_flags;
     uint16_t l2cap_result;
@@ -361,12 +363,12 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
         return BLE_HS_EREJECT;
     }
 
-    ble_l2cap_sig_update_req_parse((*om)->om_data, (*om)->om_len, &req);
+    req = (struct ble_l2cap_sig_update_req *)(*om)->om_data;
 
-    params.itvl_min = req.itvl_min;
-    params.itvl_max = req.itvl_max;
-    params.latency = req.slave_latency;
-    params.supervision_timeout = req.timeout_multiplier;
+    params.itvl_min = le16toh(req->itvl_min);
+    params.itvl_max = le16toh(req->itvl_max);
+    params.latency = le16toh(req->slave_latency);
+    params.supervision_timeout = le16toh(req->timeout_multiplier);
     params.min_ce_len = BLE_GAP_INITIAL_CONN_MIN_CE_LEN;
     params.max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN;
 
@@ -383,11 +385,19 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
         l2cap_result = BLE_L2CAP_SIG_UPDATE_RSP_RESULT_REJECT;
     }
 
+    rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_RSP, hdr->identifier,
+                                sizeof(*rsp), &txom);
+    if (!rsp) {
+        /* No memory for response, lest allow to timeout on remote side */
+        return 0;
+    }
+
+    rsp->result = htole16(l2cap_result);
+
     /* Send L2CAP response. */
-    rc = ble_l2cap_sig_update_rsp_tx(conn_handle, hdr->identifier,
-                                         l2cap_result);
+    ble_l2cap_sig_tx(conn_handle, txom);
 
-    return rc;
+    return 0;
 }
 
 static int
@@ -395,7 +405,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
                             struct ble_l2cap_sig_hdr *hdr,
                             struct os_mbuf **om)
 {
-    struct ble_l2cap_sig_update_rsp rsp;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct ble_l2cap_sig_proc *proc;
     int cb_status;
     int rc;
@@ -413,9 +423,9 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
         goto done;
     }
 
-    ble_l2cap_sig_update_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+    rsp = (struct ble_l2cap_sig_update_rsp *)(*om)->om_data;
 
-    switch (rsp.result) {
+    switch (le16toh(rsp->result)) {
     case BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT:
         cb_status = 0;
         rc = 0;
@@ -443,7 +453,8 @@ ble_l2cap_sig_update(uint16_t conn_handle,
                      struct ble_l2cap_sig_update_params *params,
                      ble_l2cap_sig_update_fn *cb, void *cb_arg)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct os_mbuf *txom;
+    struct ble_l2cap_sig_update_req *req;
     struct ble_l2cap_sig_proc *proc;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
@@ -481,12 +492,20 @@ ble_l2cap_sig_update(uint16_t conn_handle,
     proc->update.cb = cb;
     proc->update.cb_arg = cb_arg;
 
-    req.itvl_min = params->itvl_min;
-    req.itvl_max = params->itvl_max;
-    req.slave_latency = params->slave_latency;
-    req.timeout_multiplier = params->timeout_multiplier;
+    req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_REQ, proc->id,
+                                sizeof(*req), &txom);
+    if (!req) {
+        STATS_INC(ble_l2cap_stats, update_fail);
+        rc = BLE_HS_ENOMEM;
+        goto done;
+    }
 
-    rc = ble_l2cap_sig_update_req_tx(conn_handle, proc->id, &req);
+    req->itvl_min = htole16(params->itvl_min);
+    req->itvl_max = htole16(params->itvl_max);
+    req->slave_latency = htole16(params->slave_latency);
+    req->timeout_multiplier = htole16(params->timeout_multiplier);
+
+    rc = ble_l2cap_sig_tx(conn_handle, txom);
 
 done:
     ble_l2cap_sig_process_status(proc, rc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f09f382/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index f7e68c8..189efd7 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -158,99 +158,6 @@ ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
                                  &data, sizeof data);
 }
 
-static void
-ble_l2cap_sig_update_req_swap(struct ble_l2cap_sig_update_req *dst,
-                              struct ble_l2cap_sig_update_req *src)
-{
-    dst->itvl_min = TOFROMLE16(src->itvl_min);
-    dst->itvl_max = TOFROMLE16(src->itvl_max);
-    dst->slave_latency = TOFROMLE16(src->slave_latency);
-    dst->timeout_multiplier = TOFROMLE16(src->timeout_multiplier);
-}
-
-void
-ble_l2cap_sig_update_req_parse(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *dst)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_sig_update_req_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_req_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_sig_update_req_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
-                            struct ble_l2cap_sig_update_req *req)
-{
-    struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
-
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
-                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    ble_l2cap_sig_update_req_write(payload_buf, BLE_L2CAP_SIG_UPDATE_REQ_SZ,
-                                   req);
-
-    return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-static void
-ble_l2cap_sig_update_rsp_swap(struct ble_l2cap_sig_update_rsp *dst,
-                              struct ble_l2cap_sig_update_rsp *src)
-{
-    dst->result = TOFROMLE16(src->result);
-}
-
-void
-ble_l2cap_sig_update_rsp_parse(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *dst)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    ble_l2cap_sig_update_rsp_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_rsp_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    ble_l2cap_sig_update_rsp_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id, uint16_t result)
-{
-    struct ble_l2cap_sig_update_rsp rsp;
-    struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
-
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
-                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rsp.result = result;
-    ble_l2cap_sig_update_rsp_write(payload_buf, BLE_L2CAP_SIG_UPDATE_RSP_SZ,
-                                   &rsp);
-
-    return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 void *
 ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
                       struct os_mbuf **txom)
@@ -275,4 +182,3 @@ ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
 
     return hdr->data;
 }
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f09f382/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 48bff7e..f089dcb 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -92,28 +92,15 @@ void ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
 int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
                             uint8_t id, uint16_t reason,
                             void *data, int data_len);
-void ble_l2cap_sig_update_req_parse(void *payload, int len,
-                                    struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_req_write(void *payload, int len,
-                                    struct ble_l2cap_sig_update_req *src);
-int ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
-                                struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_rsp_parse(void *payload, int len,
-                                    struct ble_l2cap_sig_update_rsp *cmd);
-void ble_l2cap_sig_update_rsp_write(void *payload, int len,
-                                    struct ble_l2cap_sig_update_rsp *src);
-int ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id,
-                                uint16_t result);
 int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
                                         uint16_t src_cid, uint16_t dst_cid);
 int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom);
+void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
+                            struct os_mbuf **txom);
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
                               struct os_mbuf *sdu_rx,
                               ble_l2cap_event_fn *cb, void *cb_arg);
-void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
-                            struct os_mbuf **txom);
-
 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
 #else
 #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f09f382/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index cd9e1b2..ceabd1c 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1764,6 +1764,24 @@ ble_hs_test_util_verify_tx_l2cap_sig_hdr(uint8_t op, uint8_t id,
     return om;
 }
 
+static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+                               struct ble_l2cap_sig_update_req *src)
+{
+    dst->itvl_min = le16toh(src->itvl_min);
+    dst->itvl_max = le16toh(src->itvl_max);
+    dst->slave_latency = le16toh(src->slave_latency);
+    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_parse(void *payload, int len,
+                               struct ble_l2cap_sig_update_req *dst)
+{
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+    ble_l2cap_test_update_req_swap(dst, payload);
+}
+
 /**
  * @return                      The L2CAP sig identifier in the request.
  */
@@ -1783,7 +1801,7 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
                                                   &hdr);
 
     /* Verify payload. */
-    ble_l2cap_sig_update_req_parse(om->om_data, om->om_len, &req);
+    ble_l2cap_test_update_req_parse(om->om_data, om->om_len, &req);
     TEST_ASSERT(req.itvl_min == params->itvl_min);
     TEST_ASSERT(req.itvl_max == params->itvl_max);
     TEST_ASSERT(req.slave_latency == params->slave_latency);
@@ -1792,6 +1810,26 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
     return hdr.identifier;
 }
 
+static void
+ble_l2cap_sig_update_rsp_parse(void *payload, int len,
+                               struct ble_l2cap_sig_update_rsp *dst)
+{
+    struct ble_l2cap_sig_update_rsp *src = payload;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+    dst->result = le16toh(src->result);
+}
+
+static void
+ble_l2cap_test_update_rsp_write(void *payload, int len,
+                               struct ble_l2cap_sig_update_rsp *src)
+{
+    struct ble_l2cap_sig_update_rsp *dst = payload;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+    dst->result = htole16(src->result);
+}
+
 int
 ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
                                      uint8_t id, uint16_t result)
@@ -1811,7 +1849,7 @@ ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
     TEST_ASSERT_FATAL(rc == 0);
 
     rsp.result = result;
-    ble_l2cap_sig_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
+    ble_l2cap_test_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
 
     rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
                                               &hci_hdr, om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f09f382/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index f4f16bc..2958a6c 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -44,6 +44,24 @@ ble_l2cap_test_util_init(void)
 }
 
 static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+                              struct ble_l2cap_sig_update_req *src)
+{
+    dst->itvl_min = le16toh(src->itvl_min);
+    dst->itvl_max = le16toh(src->itvl_max);
+    dst->slave_latency = le16toh(src->slave_latency);
+    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_write(void *payload, int len,
+                               struct ble_l2cap_sig_update_req *src)
+{
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+    ble_l2cap_test_update_req_swap(payload, src);
+}
+
+static void
 ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
                                   struct ble_l2cap_sig_update_params *params)
 {
@@ -65,7 +83,7 @@ ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
     req.itvl_max = params->itvl_max;
     req.slave_latency = params->slave_latency;
     req.timeout_multiplier = params->timeout_multiplier;
-    ble_l2cap_sig_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
+    ble_l2cap_test_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
 
     ble_hs_test_util_set_ack(
         ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,


[37/50] incubator-mynewt-core git commit: nimble/l2cap: Add helper to clean L2CAP LE CoC channel

Posted by ma...@apache.org.
nimble/l2cap: Add helper to clean L2CAP LE CoC channel

With this patch we make sure that when CoC is used, outstanding
os_mbufs are freed when channel is closing


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

Branch: refs/heads/1_0_0_dev
Commit: 25e85d3d96ee2dbb8015d9e65a018514616ef9b3
Parents: 7870412
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:23:09 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:43 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |  1 +
 net/nimble/host/src/ble_l2cap_coc.c      | 12 ++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |  2 ++
 3 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25e85d3d/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index b0ab23d..046a136 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -79,6 +79,7 @@ ble_l2cap_chan_free(struct ble_l2cap_chan *chan)
     }
 
     os_mbuf_free_chain(chan->rx_buf);
+    ble_l2cap_coc_cleanup_chan(chan);
 
     rc = os_memblock_put(&ble_l2cap_chan_pool, chan);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25e85d3d/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index b549ba7..9794a00 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -277,6 +277,18 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
 }
 
 void
+ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
+{
+    /* PSM 0 is used for fixed channels. */
+    if (chan->psm == 0) {
+            return;
+    }
+
+    os_mbuf_free_chain(chan->coc_rx.sdu);
+    os_mbuf_free_chain(chan->coc_tx.sdu);
+}
+
+void
 ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                 uint16_t credits)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25e85d3d/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 88380ea..36ab4dc 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -62,6 +62,7 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  struct os_mbuf *sdu_rx,
                                                  ble_l2cap_event_fn *cb,
                                                  void *cb_arg);
+void ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan);
 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
 void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
@@ -70,6 +71,7 @@ void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
 #define ble_l2cap_coc_recv_ready(chan, sdu_rx)
+#define ble_l2cap_coc_cleanup_chan(chan)
 #endif
 
 #ifdef __cplusplus


[12/50] incubator-mynewt-core git commit: MYNEWT-647 Changes to NMP over OIC scheme

Posted by ma...@apache.org.
MYNEWT-647 Changes to NMP over OIC scheme

Update NMP handlers to account for new scheme.  Now the top-level
handler creates and closes the response root map rather than each
handler.


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

Branch: refs/heads/1_0_0_dev
Commit: 5f24475b194abf8869c47bc750cb3b8d0c409154
Parents: 1209a41
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 17:48:55 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:04 2017 -0800

----------------------------------------------------------------------
 fs/fs/src/fs_nmgr.c                   |  63 +++++---------
 mgmt/imgmgr/src/imgmgr.c              |  38 +++------
 mgmt/imgmgr/src/imgmgr_coredump.c     |  70 ++++++++-------
 mgmt/imgmgr/src/imgmgr_state.c        |  41 ++++-----
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c | 132 ++++++++++++++---------------
 mgmt/newtmgr/src/newtmgr.c            |  54 ++++++++++--
 sys/config/src/config_nmgr.c          |   8 +-
 sys/log/full/src/log_nmgr.c           |  81 ++++++++----------
 sys/stats/full/src/stats_nmgr.c       |  51 +++++------
 test/crash_test/src/crash_nmgr.c      |  23 +++--
 test/runtest/src/runtest_nmgr.c       |  21 ++---
 11 files changed, 274 insertions(+), 308 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/fs/fs/src/fs_nmgr.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_nmgr.c b/fs/fs/src/fs_nmgr.c
index d04d768..bd87697 100644
--- a/fs/fs/src/fs_nmgr.c
+++ b/fs/fs/src/fs_nmgr.c
@@ -90,19 +90,15 @@ fs_nmgr_file_download(struct mgmt_cbuf *cb)
     uint32_t out_len;
     struct fs_file *file;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
 
     rc = cbor_read_object(&cb->it, dload_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = fs_open(tmp_str, FS_ACCESS_READ, &file);
     if (rc || !file) {
-        rc = MGMT_ERR_ENOMEM;
-        goto err;
+        return MGMT_ERR_ENOMEM;
     }
 
     rc = fs_seek(file, off);
@@ -116,34 +112,30 @@ fs_nmgr_file_download(struct mgmt_cbuf *cb)
         goto err_close;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_uint(&rsp, off);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_uint(&cb->encoder, off);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "data");
-    g_err |= cbor_encode_byte_string(&rsp, img_data, out_len);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "data");
+    g_err |= cbor_encode_byte_string(&cb->encoder, img_data, out_len);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
     if (off == 0) {
         rc = fs_filelen(file, &out_len);
-        g_err |= cbor_encode_text_stringz(&rsp, "len");
-        g_err |= cbor_encode_uint(&rsp, out_len);
+        g_err |= cbor_encode_text_stringz(&cb->encoder, "len");
+        g_err |= cbor_encode_uint(&cb->encoder, out_len);
     }
-    g_err |= cbor_encoder_close_container(penc, &rsp);
 
     fs_close(file);
     if (g_err) {
-          return MGMT_ERR_ENOMEM;
+        return MGMT_ERR_ENOMEM;
     }
+
     return 0;
 
 err_close:
     fs_close(file);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 static int
@@ -183,14 +175,11 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         [4] = { 0 },
     };
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     int rc;
 
     rc = cbor_read_object(&cb->it, off_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (off == 0) {
@@ -201,8 +190,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         fs_nmgr_state.upload.size = size;
 
         if (!strlen(file_name)) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
         if (fs_nmgr_state.upload.file) {
             fs_close(fs_nmgr_state.upload.file);
@@ -211,8 +199,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         rc = fs_open(file_name, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
           &fs_nmgr_state.upload.file);
         if (rc) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
     } else if (off != fs_nmgr_state.upload.off) {
         /*
@@ -223,8 +210,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
     }
 
     if (!fs_nmgr_state.upload.file) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
     if (img_len) {
         rc = fs_write(fs_nmgr_state.upload.file, img_data, img_len);
@@ -239,13 +225,12 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
             fs_nmgr_state.upload.file = NULL;
         }
     }
+
 out:
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_uint(&rsp, fs_nmgr_state.upload.off);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_uint(&cb->encoder, fs_nmgr_state.upload.off);
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }
@@ -254,9 +239,7 @@ out:
 err_close:
     fs_close(fs_nmgr_state.upload.file);
     fs_nmgr_state.upload.file = NULL;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/mgmt/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index 32744e2..7b4431e 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -257,14 +257,11 @@ imgr_upload(struct mgmt_cbuf *cb)
     int best;
     int rc;
     int i;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     CborError g_err = CborNoError;
 
     rc = cbor_read_object(&cb->it, off_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (off == 0) {
@@ -272,13 +269,11 @@ imgr_upload(struct mgmt_cbuf *cb)
             /*
              * Image header is the first thing in the image.
              */
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
         hdr = (struct image_header *)img_data;
         if (hdr->ih_magic != IMAGE_MAGIC) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
 
         /*
@@ -318,12 +313,10 @@ imgr_upload(struct mgmt_cbuf *cb)
             }
             rc = flash_area_open(area_id, &imgr_state.upload.fa);
             if (rc) {
-                rc = MGMT_ERR_EINVAL;
-                goto err;
+                return MGMT_ERR_EINVAL;
             }
             if (IMAGE_SIZE(hdr) > imgr_state.upload.fa->fa_size) {
-                rc = MGMT_ERR_EINVAL;
-                goto err;
+                return MGMT_ERR_EINVAL;
             }
             /*
              * XXX only erase if needed.
@@ -334,8 +327,7 @@ imgr_upload(struct mgmt_cbuf *cb)
             /*
              * No slot where to upload!
              */
-            rc = MGMT_ERR_ENOMEM;
-            goto err;
+            return MGMT_ERR_ENOMEM;
         }
     } else if (off != imgr_state.upload.off) {
         /*
@@ -346,8 +338,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     }
 
     if (!imgr_state.upload.fa) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
     if (data_len) {
         rc = flash_area_write(imgr_state.upload.fa, imgr_state.upload.off,
@@ -363,13 +354,12 @@ imgr_upload(struct mgmt_cbuf *cb)
             imgr_state.upload.fa = NULL;
         }
     }
+
 out:
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_int(&rsp, imgr_state.upload.off);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_int(&cb->encoder, imgr_state.upload.off);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -378,9 +368,7 @@ out:
 err_close:
     flash_area_close(imgr_state.upload.fa);
     imgr_state.upload.fa = NULL;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/mgmt/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_coredump.c b/mgmt/imgmgr/src/imgmgr_coredump.c
index df3e321..48058c9 100644
--- a/mgmt/imgmgr/src/imgmgr_coredump.c
+++ b/mgmt/imgmgr/src/imgmgr_coredump.c
@@ -40,20 +40,24 @@ imgr_core_list(struct mgmt_cbuf *cb)
     int rc;
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    } else {
-        rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
-        if (rc != 0) {
-            rc = MGMT_ERR_EINVAL;
-        } else if (hdr.ch_magic != COREDUMP_MAGIC) {
-            rc = MGMT_ERR_ENOENT;
-        } else {
-            rc = 0;
-        }
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    if (hdr.ch_magic != COREDUMP_MAGIC) {
+        return MGMT_ERR_ENOENT;
+    }
+
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
     }
 
-    mgmt_cbuf_setoerr(cb, rc);
     return 0;
 }
 
@@ -75,21 +79,17 @@ imgr_core_load(struct mgmt_cbuf *cb)
     uint8_t data[IMGMGR_NMGR_MAX_MSG];
     struct coredump_header *hdr;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
 
     hdr = (struct coredump_header *)data;
 
     rc = cbor_read_object(&cb->it, dload_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
     if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_read(fa, 0, hdr, sizeof(*hdr));
@@ -115,14 +115,12 @@ imgr_core_load(struct mgmt_cbuf *cb)
         goto err_close;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_int(&rsp, off);
-    g_err |= cbor_encode_text_stringz(&rsp, "data");
-    g_err |= cbor_encode_byte_string(&rsp, data, sz);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_int(&cb->encoder, off);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "data");
+    g_err |= cbor_encode_byte_string(&cb->encoder, data, sz);
 
     flash_area_close(fa);
     if (g_err) {
@@ -132,8 +130,6 @@ imgr_core_load(struct mgmt_cbuf *cb)
 
 err_close:
     flash_area_close(fa);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
     return rc;
 }
 
@@ -148,24 +144,26 @@ imgr_core_erase(struct mgmt_cbuf *cb)
     int rc;
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
     if (rc == 0 &&
       (hdr.ch_magic == COREDUMP_MAGIC || hdr.ch_magic == 0xffffffff)) {
         rc = flash_area_erase(fa, 0, fa->fa_size);
-        if (rc) {
-            rc = MGMT_ERR_EINVAL;
+        if (rc != 0) {
+            return MGMT_ERR_EINVAL;
         }
     }
-    rc = 0;
 
     flash_area_close(fa);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
+
+    rc = mgmt_cbuf_setoerr(cb, rc);
+    if (rc != 0) {
+        return rc;
+    }
+
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/mgmt/imgmgr/src/imgmgr_state.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_state.c b/mgmt/imgmgr/src/imgmgr_state.c
index ee7d76c..610b57f 100644
--- a/mgmt/imgmgr/src/imgmgr_state.c
+++ b/mgmt/imgmgr/src/imgmgr_state.c
@@ -240,15 +240,15 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
     int split_status;
     uint8_t state_flags;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, images, image;
+    CborEncoder images;
+    CborEncoder image;
 
     any_non_bootable = 0;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "images");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "images");
 
-    g_err |= cbor_encoder_create_array(&rsp, &images, CborIndefiniteLength);
+    g_err |= cbor_encoder_create_array(&cb->encoder, &images,
+                                       CborIndefiniteLength);
     for (i = 0; i < 2; i++) {
         rc = imgr_read_info(i, &ver, hash, &flags);
         if (rc != 0) {
@@ -261,7 +261,8 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
 
         state_flags = imgmgr_state_flags(i);
 
-        g_err |= cbor_encoder_create_map(&images, &image, CborIndefiniteLength);
+        g_err |= cbor_encoder_create_map(&images, &image,
+                                         CborIndefiniteLength);
         g_err |= cbor_encode_text_stringz(&image, "slot");
         g_err |= cbor_encode_int(&image, i);
 
@@ -294,7 +295,7 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
         g_err |= cbor_encoder_close_container(&images, &image);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &images);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &images);
 
     if (any_non_bootable) {
         split_status = split_check_status();
@@ -302,10 +303,8 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
         split_status = SPLIT_STATUS_INVALID;
     }
 
-    g_err |= cbor_encode_text_stringz(&rsp, "splitStatus");
-    g_err |= cbor_encode_int(&rsp, split_status);
-
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "splitStatus");
+    g_err |= cbor_encode_int(&cb->encoder, split_status);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -341,45 +340,37 @@ imgmgr_state_write(struct mgmt_cbuf *cb)
 
     rc = cbor_read_object(&cb->it, write_attr);
     if (rc != 0) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     /* Validate arguments. */
     if ((hash_len == 0) && !confirm) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (hash_len != 0) {
         slot = imgr_find_by_hash(hash, NULL);
         if (slot < 0) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
 
         rc = imgmgr_state_set_pending(slot, confirm);
         if (rc != 0) {
-            goto err;
+            return rc;
         }
     } else {
         /* Confirm current setup. */
         rc = imgmgr_state_confirm();
         if (rc != 0) {
-            goto err;
+            return rc;
         }
     }
 
     /* Send the current image state in the response. */
     rc = imgmgr_state_read(cb);
     if (rc != 0) {
-        goto err;
+        return rc;
     }
 
     return 0;
-
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-
-    return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index c3e38d6..2a75d47 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -84,9 +84,8 @@ static int
 nmgr_def_echo(struct mgmt_cbuf *cb)
 {
     char echo_buf[128] = {'\0'};
-    CborEncoder *penc = &cb->encoder;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
+
     struct cbor_attr_t attrs[2] = {
         [0] = {
             .attribute = "d",
@@ -100,11 +99,9 @@ nmgr_def_echo(struct mgmt_cbuf *cb)
         }
     };
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "r");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "r");
     g_err |= cbor_read_object(&cb->it, attrs);
-    g_err |= cbor_encode_text_string(&rsp, echo_buf, strlen(echo_buf));
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_string(&cb->encoder, echo_buf, strlen(echo_buf));
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -145,19 +142,18 @@ nmgr_def_taskstat_read(struct mgmt_cbuf *cb)
 {
     struct os_task *prev_task;
     struct os_task_info oti;
-
     CborError g_err = CborNoError;
-    CborEncoder rsp, tasks, task;
+    CborEncoder tasks;
+    CborEncoder task;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "tasks");
-    g_err |= cbor_encoder_create_map(&rsp, &tasks, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "tasks");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &tasks,
+                                     CborIndefiniteLength);
 
     prev_task = NULL;
     while (1) {
-
         prev_task = os_task_info_get_next(prev_task, &oti);
         if (prev_task == NULL) {
             break;
@@ -165,28 +161,27 @@ nmgr_def_taskstat_read(struct mgmt_cbuf *cb)
 
         g_err |= cbor_encode_text_stringz(&tasks, oti.oti_name);
         g_err |= cbor_encoder_create_map(&tasks, &task, CborIndefiniteLength);
-        g_err |= cbor_encode_text_stringz(&rsp, "prio");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_prio);
-        g_err |= cbor_encode_text_stringz(&rsp, "tid");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_taskid);
-        g_err |= cbor_encode_text_stringz(&rsp, "state");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_state);
-        g_err |= cbor_encode_text_stringz(&rsp, "stkuse");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_stkusage);
-        g_err |= cbor_encode_text_stringz(&rsp, "stksiz");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_stksize);
-        g_err |= cbor_encode_text_stringz(&rsp, "cswcnt");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_cswcnt);
-        g_err |= cbor_encode_text_stringz(&rsp, "runtime");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_runtime);
-        g_err |= cbor_encode_text_stringz(&rsp, "last_checkin");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_last_checkin);
-        g_err |= cbor_encode_text_stringz(&rsp, "next_checkin");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_next_checkin);
+        g_err |= cbor_encode_text_stringz(&task, "prio");
+        g_err |= cbor_encode_uint(&task, oti.oti_prio);
+        g_err |= cbor_encode_text_stringz(&task, "tid");
+        g_err |= cbor_encode_uint(&task, oti.oti_taskid);
+        g_err |= cbor_encode_text_stringz(&task, "state");
+        g_err |= cbor_encode_uint(&task, oti.oti_state);
+        g_err |= cbor_encode_text_stringz(&task, "stkuse");
+        g_err |= cbor_encode_uint(&task, oti.oti_stkusage);
+        g_err |= cbor_encode_text_stringz(&task, "stksiz");
+        g_err |= cbor_encode_uint(&task, oti.oti_stksize);
+        g_err |= cbor_encode_text_stringz(&task, "cswcnt");
+        g_err |= cbor_encode_uint(&task, oti.oti_cswcnt);
+        g_err |= cbor_encode_text_stringz(&task, "runtime");
+        g_err |= cbor_encode_uint(&task, oti.oti_runtime);
+        g_err |= cbor_encode_text_stringz(&task, "last_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_last_checkin);
+        g_err |= cbor_encode_text_stringz(&task, "next_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_next_checkin);
         g_err |= cbor_encoder_close_container(&tasks, &task);
     }
-    g_err |= cbor_encoder_close_container(&rsp, &tasks);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &tasks);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -200,13 +195,14 @@ nmgr_def_mpstat_read(struct mgmt_cbuf *cb)
     struct os_mempool *prev_mp;
     struct os_mempool_info omi;
     CborError g_err = CborNoError;
-    CborEncoder rsp, pools, pool;
+    CborEncoder pools;
+    CborEncoder pool;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "mpools");
-    g_err |= cbor_encoder_create_map(&rsp, &pools, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "mpools");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &pools,
+                                     CborIndefiniteLength);
 
     prev_mp = NULL;
     while (1) {
@@ -217,19 +213,18 @@ nmgr_def_mpstat_read(struct mgmt_cbuf *cb)
 
         g_err |= cbor_encode_text_stringz(&pools, omi.omi_name);
         g_err |= cbor_encoder_create_map(&pools, &pool, CborIndefiniteLength);
-        g_err |= cbor_encode_text_stringz(&rsp, "blksiz");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_block_size);
-        g_err |= cbor_encode_text_stringz(&rsp, "nblks");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_num_blocks);
-        g_err |= cbor_encode_text_stringz(&rsp, "nfree");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_num_free);
-        g_err |= cbor_encode_text_stringz(&rsp, "min");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_min_free);
+        g_err |= cbor_encode_text_stringz(&pool, "blksiz");
+        g_err |= cbor_encode_uint(&pool, omi.omi_block_size);
+        g_err |= cbor_encode_text_stringz(&pool, "nblks");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_blocks);
+        g_err |= cbor_encode_text_stringz(&pool, "nfree");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_free);
+        g_err |= cbor_encode_text_stringz(&pool, "min");
+        g_err |= cbor_encode_uint(&pool, omi.omi_min_free);
         g_err |= cbor_encoder_close_container(&pools, &pool);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &pools);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &pools);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -245,11 +240,9 @@ nmgr_datetime_get(struct mgmt_cbuf *cb)
     char buf[DATETIME_BUFSIZE];
     int rc;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
     /* Display the current datetime */
     rc = os_gettimeofday(&tv, &tz);
@@ -259,9 +252,8 @@ nmgr_datetime_get(struct mgmt_cbuf *cb)
         rc = MGMT_ERR_EINVAL;
         goto err;
     }
-    g_err |= cbor_encode_text_stringz(&rsp, "datetime");
-    g_err |= cbor_encode_text_stringz(&rsp, buf);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "datetime");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, buf);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -295,8 +287,7 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
 
     rc = cbor_read_object(&cb->it, datetime_write_attr);
     if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto out;
+        return MGMT_ERR_EINVAL;
     }
 
     /* Set the current datetime */
@@ -304,18 +295,18 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
     if (!rc) {
         rc = os_settimeofday(&tv, &tz);
         if (rc) {
-          rc = MGMT_ERR_EINVAL;
-          goto out;
+          return MGMT_ERR_EINVAL;
         }
     } else {
-        rc = MGMT_ERR_EINVAL;
-        goto out;
+        return MGMT_ERR_EINVAL;
     }
 
-    rc = 0;
-out:
-    mgmt_cbuf_setoerr(cb, rc);
-    return rc;
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
 }
 
 static void
@@ -327,6 +318,8 @@ nmgr_reset_tmo(struct os_event *ev)
 static int
 nmgr_reset(struct mgmt_cbuf *cb)
 {
+    int rc;
+
     os_callout_init(&nmgr_reset_callout, mgmt_evq_get(), nmgr_reset_tmo, NULL);
 
 #if MYNEWT_VAL(LOG_SOFT_RESET)
@@ -334,7 +327,10 @@ nmgr_reset(struct mgmt_cbuf *cb)
 #endif
     os_callout_reset(&nmgr_reset_callout, OS_TICKS_PER_SEC / 4);
 
-    mgmt_cbuf_setoerr(cb, OS_OK);
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/mgmt/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/src/newtmgr.c b/mgmt/newtmgr/src/newtmgr.c
index 5d37021..043cef6 100644
--- a/mgmt/newtmgr/src/newtmgr.c
+++ b/mgmt/newtmgr/src/newtmgr.c
@@ -95,20 +95,36 @@ nmgr_init_rsp(struct os_mbuf *m, struct nmgr_hdr *src)
 
 static void
 nmgr_send_err_rsp(struct nmgr_transport *nt, struct os_mbuf *m,
-  struct nmgr_hdr *hdr, int rc)
+                  struct nmgr_hdr *hdr, int status)
 {
+    struct CborEncoder map;
+    int rc;
+
     hdr = nmgr_init_rsp(m, hdr);
     if (!hdr) {
         os_mbuf_free_chain(m);
         return;
     }
 
-    mgmt_cbuf_setoerr(&nmgr_task_cbuf.n_b, rc);
-    hdr->nh_len +=
-        cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
+    rc = cbor_encoder_create_map(&nmgr_task_cbuf.n_b.encoder, &map,
+                                 CborIndefiniteLength);
+    if (rc != 0) {
+        return;
+    }
+
+    rc = mgmt_cbuf_setoerr(&nmgr_task_cbuf.n_b, status);
+    if (rc != 0) {
+        return;
+    }
+
+    rc = cbor_encoder_close_container(&nmgr_task_cbuf.n_b.encoder, &map);
+    if (rc != 0) {
+        return;
+    }
+
+    hdr->nh_len =
+        htons(cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder));
 
-    hdr->nh_len = htons(hdr->nh_len);
-    hdr->nh_flags = 0;
     nt->nt_output(nt, nmgr_task_cbuf.n_out_m);
 }
 
@@ -172,6 +188,7 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
 {
     struct os_mbuf *rsp;
     const struct mgmt_handler *handler;
+    CborEncoder payload_enc;
     struct nmgr_hdr *rsp_hdr;
     struct nmgr_hdr hdr;
     int off;
@@ -194,7 +211,7 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
 
     mtu = nt->nt_get_mtu(req);
 
-    /* Copy the request packet header into the response. */
+    /* Copy the request user header into the response. */
     memcpy(OS_MBUF_USRHDR(rsp), OS_MBUF_USRHDR(req), OS_MBUF_USRHDR_LEN(req));
 
     off = 0;
@@ -228,6 +245,16 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         cbor_parser_init(&nmgr_task_cbuf.reader.r, 0,
                          &nmgr_task_cbuf.n_b.parser, &nmgr_task_cbuf.n_b.it);
 
+        /* Begin response payload.  Response fields are inserted into the root
+         * map as key value pairs.
+         */
+        rc = cbor_encoder_create_map(&nmgr_task_cbuf.n_b.encoder, &payload_enc,
+                                     CborIndefiniteLength);
+        if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
+            goto err;
+        }
+
         if (hdr.nh_op == NMGR_OP_READ) {
             if (handler->mh_read) {
                 rc = handler->mh_read(&nmgr_task_cbuf.n_b);
@@ -243,8 +270,15 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         } else {
             rc = MGMT_ERR_EINVAL;
         }
+        if (rc != 0) {
+            goto err;
+        }
 
+        /* End response payload. */
+        rc = cbor_encoder_close_container(&nmgr_task_cbuf.n_b.encoder,
+                                          &payload_enc);
         if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
             goto err;
         }
 
@@ -270,11 +304,15 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
     os_mbuf_free_chain(rsp);
     os_mbuf_free_chain(req);
     return;
+
 err:
-    OS_MBUF_PKTHDR(rsp)->omp_len = rsp->om_len = 0;
+    /* Clear partially written response. */
+    os_mbuf_adj(rsp, OS_MBUF_PKTLEN(rsp));
+
     nmgr_send_err_rsp(nt, rsp, &hdr, rc);
     os_mbuf_free_chain(req);
     return;
+
 err_norsp:
     os_mbuf_free_chain(rsp);
     os_mbuf_free_chain(req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/sys/config/src/config_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_nmgr.c b/sys/config/src/config_nmgr.c
index 24c7080..0b42bc6 100644
--- a/sys/config/src/config_nmgr.c
+++ b/sys/config/src/config_nmgr.c
@@ -49,7 +49,6 @@ conf_nmgr_read(struct mgmt_cbuf *cb)
     char val_str[CONF_MAX_VAL_LEN];
     char *val;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
 
     const struct cbor_attr_t attr[2] = {
         [0] = {
@@ -73,10 +72,9 @@ conf_nmgr_read(struct mgmt_cbuf *cb)
         return MGMT_ERR_EINVAL;
     }
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "val");
-    g_err |= cbor_encode_text_stringz(&rsp, val);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "val");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, val);
+
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/sys/log/full/src/log_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/log/full/src/log_nmgr.c b/sys/log/full/src/log_nmgr.c
index 6d51cb6..00beeba 100644
--- a/sys/log/full/src/log_nmgr.c
+++ b/sys/log/full/src/log_nmgr.c
@@ -250,8 +250,7 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     int64_t ts;
     uint64_t index;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, logs;
+    CborEncoder logs;
 
     const struct cbor_attr_t attr[4] = {
         [0] = {
@@ -281,10 +280,9 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     }
 
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "logs");
-
-    g_err |= cbor_encoder_create_array(&rsp, &logs, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "logs");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &logs,
+                                       CborIndefiniteLength);
 
     name_len = strlen(name);
     log = NULL;
@@ -321,10 +319,9 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     }
 
 err:
-    g_err |= cbor_encoder_close_container(&rsp, &logs);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, rc);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &logs);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, rc);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -344,15 +341,14 @@ log_nmgr_module_list(struct mgmt_cbuf *cb)
     int module;
     char *str;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, modules;
+    CborEncoder modules;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "module_map");
-    g_err |= cbor_encoder_create_map(&rsp, &modules, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "module_map");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &modules,
+                                     CborIndefiniteLength);
 
     module = LOG_MODULE_DEFAULT;
     while (module < LOG_MODULE_MAX) {
@@ -367,8 +363,7 @@ log_nmgr_module_list(struct mgmt_cbuf *cb)
         module++;
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &modules);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &modules);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -385,16 +380,15 @@ static int
 log_nmgr_logs_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, log_list;
+    CborEncoder log_list;
     struct log *log;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "log_list");
-    g_err |= cbor_encoder_create_array(&rsp, &log_list, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "log_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &log_list,
+                                       CborIndefiniteLength);
 
     log = NULL;
     while (1) {
@@ -410,8 +404,7 @@ log_nmgr_logs_list(struct mgmt_cbuf *cb)
         g_err |= cbor_encode_text_stringz(&log_list, log->l_name);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &log_list);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &log_list);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -428,17 +421,16 @@ static int
 log_nmgr_level_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, level_map;
+    CborEncoder level_map;
     int level;
     char *str;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "level_map");
-    g_err |= cbor_encoder_create_map(&rsp, &level_map, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "level_map");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &level_map,
+                                     CborIndefiniteLength);
 
     level = LOG_LEVEL_DEBUG;
     while (level < LOG_LEVEL_MAX) {
@@ -453,8 +445,7 @@ log_nmgr_level_list(struct mgmt_cbuf *cb)
         level++;
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &level_map);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &level_map);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -470,9 +461,6 @@ log_nmgr_level_list(struct mgmt_cbuf *cb)
 static int
 log_nmgr_clear(struct mgmt_cbuf *cb)
 {
-    CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     struct log *log;
     int rc;
 
@@ -489,19 +477,16 @@ log_nmgr_clear(struct mgmt_cbuf *cb)
 
         rc = log_flush(log);
         if (rc) {
-            goto err;
+            return rc;
         }
     }
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
 
-    if (g_err) {
-        return MGMT_ERR_ENOMEM;
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
     }
+
     return 0;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return (rc);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/sys/stats/full/src/stats_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/stats/full/src/stats_nmgr.c b/sys/stats/full/src/stats_nmgr.c
index 5df6e7c..0b28b25 100644
--- a/sys/stats/full/src/stats_nmgr.c
+++ b/sys/stats/full/src/stats_nmgr.c
@@ -95,46 +95,39 @@ stats_nmgr_read(struct mgmt_cbuf *cb)
         { NULL },
     };
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, stats;
+    CborEncoder stats;
 
     g_err = cbor_read_object(&cb->it, attrs);
     if (g_err != 0) {
-        g_err = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     hdr = stats_group_find(stats_name);
     if (!hdr) {
-        g_err = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "name");
-    g_err |= cbor_encode_text_stringz(&rsp, stats_name);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "name");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, stats_name);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "group");
-    g_err |= cbor_encode_text_string(&rsp, "sys", sizeof("sys")-1);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "group");
+    g_err |= cbor_encode_text_string(&cb->encoder, "sys", sizeof("sys")-1);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "fields");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "fields");
 
-    g_err |= cbor_encoder_create_map(&rsp, &stats, CborIndefiniteLength);
+    g_err |= cbor_encoder_create_map(&cb->encoder, &stats,
+                                     CborIndefiniteLength);
 
     stats_walk(hdr, stats_nmgr_walk_func, &stats);
 
-    g_err |= cbor_encoder_close_container(&rsp, &stats);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &stats);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }
-    return (0);
-err:
-    mgmt_cbuf_setoerr(cb, g_err);
 
     return (0);
 }
@@ -143,17 +136,15 @@ static int
 stats_nmgr_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, stats;
-
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "stat_list");
-    g_err |= cbor_encoder_create_array(&rsp, &stats, CborIndefiniteLength);
+    CborEncoder stats;
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "stat_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &stats,
+                                       CborIndefiniteLength);
     stats_group_walk(stats_nmgr_encode_name, &stats);
-    g_err |= cbor_encoder_close_container(&rsp, &stats);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &stats);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/test/crash_test/src/crash_nmgr.c
----------------------------------------------------------------------
diff --git a/test/crash_test/src/crash_nmgr.c b/test/crash_test/src/crash_nmgr.c
index 7ffd969..b1b8eaa 100644
--- a/test/crash_test/src/crash_nmgr.c
+++ b/test/crash_test/src/crash_nmgr.c
@@ -33,7 +33,7 @@
 static int crash_test_nmgr_write(struct mgmt_cbuf *);
 
 static const struct mgmt_handler crash_test_nmgr_handler[] = {
-    [0] = { crash_test_nmgr_write, crash_test_nmgr_write }
+    [0] = { NULL, crash_test_nmgr_write }
 };
 
 struct mgmt_group crash_test_nmgr_group = {
@@ -60,15 +60,20 @@ crash_test_nmgr_write(struct mgmt_cbuf *cb)
     int rc;
 
     rc = cbor_read_object(&cb->it, attr);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    } else {
-        rc = crash_device(tmp_str);
-        if (rc) {
-            rc = MGMT_ERR_EINVAL;
-        }
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    rc = crash_device(tmp_str);
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
     }
-    mgmt_cbuf_setoerr(cb, rc);
+
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f24475b/test/runtest/src/runtest_nmgr.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest_nmgr.c b/test/runtest/src/runtest_nmgr.c
index 3c02ee3..ce282ce 100644
--- a/test/runtest/src/runtest_nmgr.c
+++ b/test/runtest/src/runtest_nmgr.c
@@ -105,11 +105,6 @@ run_nmgr_test(struct mgmt_cbuf *cb)
 
     os_eventq_put(run_evq_get(), &run_test_event);
             
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    }
-
-    mgmt_cbuf_setoerr(cb, rc);
     return 0;
 }
 
@@ -120,23 +115,21 @@ static int
 run_nmgr_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, run_list;
+    CborEncoder run_list;
     struct ts_suite *ts;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "run_list");
-    g_err |= cbor_encoder_create_array(&rsp, &run_list, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "run_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &run_list,
+                                       CborIndefiniteLength);
 
     SLIST_FOREACH(ts, &g_ts_suites, ts_next) {
         g_err |= cbor_encode_text_stringz(&run_list, ts->ts_name);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &run_list);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &run_list);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;



[30/50] incubator-mynewt-core git commit: nimble/l2cap: Fix handling bad data in L2CAP update parameters response

Posted by ma...@apache.org.
nimble/l2cap: Fix handling bad data in L2CAP update parameters response

Returning error will cause sending L2CAP REJECT on that response and
this is incorrect. This patch fixes that.


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

Branch: refs/heads/1_0_0_dev
Commit: 73705b0855a8e53ed59ce3b6064a75a5b80f8f26
Parents: e9d7750
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 11:32:25 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:42 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/73705b08/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index d6219d3..560311d 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -438,7 +438,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
 
     default:
         cb_status = BLE_HS_EBADDATA;
-        rc = BLE_HS_EBADDATA;
+        rc = 0;
         break;
     }
 


[03/50] incubator-mynewt-core git commit: Update adafruit nrf52 feather bsp with correct crystal SCA.

Posted by ma...@apache.org.
Update adafruit nrf52 feather bsp with correct crystal SCA.


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

Branch: refs/heads/1_0_0_dev
Commit: 8959ce9e49a63ec031cd1f341e7749d9016d2dc4
Parents: 2495696
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Feb 27 10:53:55 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:47:40 2017 -0800

----------------------------------------------------------------------
 hw/bsp/ada_feather_nrf52/syscfg.yml | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8959ce9e/hw/bsp/ada_feather_nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ada_feather_nrf52/syscfg.yml b/hw/bsp/ada_feather_nrf52/syscfg.yml
index e56991e..fdb43b9 100644
--- a/hw/bsp/ada_feather_nrf52/syscfg.yml
+++ b/hw/bsp/ada_feather_nrf52/syscfg.yml
@@ -95,3 +95,7 @@ syscfg.vals:
     REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
     NFFS_FLASH_AREA: FLASH_AREA_NFFS
     COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
+
+# The module on the board has +/- 40 ppm crystal. A value of 5 is
+# for crystals in the range of 31 to 50 ppm.
+    BLE_LL_MASTER_SCA: 5


[39/50] incubator-mynewt-core git commit: nibmle/l2cap: Clear LE CoC channel on ACL drop

Posted by ma...@apache.org.
nibmle/l2cap: Clear LE CoC channel on ACL drop

When ACL is disconnected before L2CAP is disconnected we need to
make sure proper cleaning is done and application is notified
about channel disconnection.

Therefore with this patch sending DISCONNECTED EVENT is moved to
function doing free of COC specific data in the channel


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

Branch: refs/heads/1_0_0_dev
Commit: 61a0e851ef6ca8aed601192a54a07668c7f42291
Parents: 5199caf
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 21:45:29 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:01 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c | 14 ++++++++++++++
 net/nimble/host/src/ble_l2cap_sig.c | 16 ----------------
 2 files changed, 14 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/61a0e851/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 12d79d6..ec01fec 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -276,6 +276,18 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
     return 0;
 }
 
+static void
+ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
+{
+    struct ble_l2cap_event event = { };
+
+    event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
+    event.disconnect.conn_handle = chan->conn_handle;
+    event.disconnect.chan = chan;
+
+    chan->cb(&event, chan->cb_arg);
+}
+
 void
 ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
 {
@@ -284,6 +296,8 @@ ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
             return;
     }
 
+    ble_l2cap_event_coc_disconnected(chan);
+
     os_mbuf_free_chain(chan->coc_rx.sdu);
     os_mbuf_free_chain(chan->coc_tx.sdu);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/61a0e851/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 8da2dad..b77fa3b 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -585,18 +585,6 @@ ble_l2cap_event_coc_connected(struct ble_l2cap_chan *chan, uint16_t status)
     chan->cb(&event, chan->cb_arg);
 }
 
-static void
-ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
-{
-    struct ble_l2cap_event event = { };
-
-    event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
-    event.disconnect.conn_handle = chan->conn_handle;
-    event.disconnect.chan = chan;
-
-    chan->cb(&event, chan->cb_arg);
-}
-
 static int
 ble_l2cap_event_coc_accept(struct ble_l2cap_chan *chan, uint16_t peer_sdu_size)
 {
@@ -891,8 +879,6 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     rsp->dcid = htole16(chan->scid);
     rsp->scid = htole16(chan->dcid);
 
-    ble_l2cap_event_coc_disconnected(chan);
-
     ble_hs_conn_delete_chan(conn, chan);
     ble_hs_unlock();
 
@@ -922,8 +908,6 @@ ble_l2cap_sig_coc_disconnect_cb(struct ble_l2cap_sig_proc *proc, int status)
         goto done;
     }
 
-    ble_l2cap_event_coc_disconnected(chan);
-
 done:
     ble_hs_lock();
     conn = ble_hs_conn_find(chan->conn_handle);


[13/50] incubator-mynewt-core git commit: blecent: Fix not setting initial BLE address

Posted by ma...@apache.org.
blecent: Fix not setting initial BLE address

Application needs to set correct public address if it want to use it.

MYNEWT-634


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

Branch: refs/heads/1_0_0_dev
Commit: 58ea0a58c6b51e032440959221ad3f4cead87fa3
Parents: 5f24475
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue Feb 28 12:39:17 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:49:13 2017 -0800

----------------------------------------------------------------------
 apps/blecent/src/main.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58ea0a58/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 4c271ca..a1dfa62 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -465,6 +465,9 @@ main(void)
 {
     int rc;
 
+    /* Set initial BLE device address. */
+    memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
+
     /* Initialize OS */
     sysinit();
 


[38/50] incubator-mynewt-core git commit: nimble/l2cap: Add suppport to send data over L2CAP LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add suppport to send data over L2CAP LE CoC


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

Branch: refs/heads/1_0_0_dev
Commit: 5199caf473273685e06a47df4506283b3b454274
Parents: 25e85d3
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:26:25 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:52 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |   3 +-
 net/nimble/host/src/ble_l2cap_coc.c      | 124 ++++++++++++++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |   2 +
 3 files changed, 127 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5199caf4/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 046a136..b19a348 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -160,8 +160,7 @@ int ble_l2cap_disconnect(struct ble_l2cap_chan *chan)
 int
 ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 {
-    /*TODO Implement */
-    return BLE_HS_ENOTSUP;
+    return ble_l2cap_coc_send(chan, sdu);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5199caf4/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 9794a00..12d79d6 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -288,6 +288,108 @@ ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
     os_mbuf_free_chain(chan->coc_tx.sdu);
 }
 
+static int
+ble_l2cap_coc_continue_tx(struct ble_l2cap_chan *chan)
+{
+    struct ble_l2cap_coc_endpoint *tx;
+    uint16_t len;
+    uint16_t left_to_send;
+    struct os_mbuf *txom;
+    struct ble_hs_conn *conn;
+    uint16_t sdu_size_offset;
+    int rc;
+
+    /* If there is no data to send, just return success */
+    tx = &chan->coc_tx;
+    if (!tx->sdu) {
+        return 0;
+    }
+
+    while (tx->credits) {
+        sdu_size_offset = 0;
+
+        BLE_HS_LOG(DEBUG, "Available credits %d\n", tx->credits);
+
+        /* lets calculate data we are going to send */
+        left_to_send = OS_MBUF_PKTLEN(tx->sdu) - tx->data_offset;
+
+        if (tx->data_offset == 0) {
+            sdu_size_offset = BLE_L2CAP_SDU_SIZE;
+            left_to_send += sdu_size_offset;
+        }
+
+        /* Take into account peer MTU */
+        len = min(left_to_send, chan->peer_mtu);
+
+        /* Prepare packet */
+        txom = ble_hs_mbuf_l2cap_pkt();
+        if (!txom) {
+            BLE_HS_LOG(DEBUG, "Could not prepare l2cap packet len %d, err=%d",
+                                                                   len, rc);
+
+            rc = BLE_HS_ENOMEM;
+            goto failed;
+        }
+
+        if (tx->data_offset == 0) {
+            /* First packet needs SDU len first. Left to send */
+            uint16_t l = htole16(OS_MBUF_PKTLEN(tx->sdu));
+
+            BLE_HS_LOG(DEBUG, "Sending SDU len=%d\n", OS_MBUF_PKTLEN(tx->sdu));
+            rc = os_mbuf_append(txom, &l, sizeof(uint16_t));
+            if (rc) {
+                BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
+                goto failed;
+            }
+        }
+
+        /* In data_offset we keep track on what we already sent. Need to remember
+         * that for first packet we need to decrease data size by 2 bytes for sdu
+         * size
+         */
+        rc = os_mbuf_appendfrom(txom, tx->sdu, tx->data_offset,
+                                len - sdu_size_offset);
+        if (rc) {
+            BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
+           goto failed;
+        }
+
+        ble_hs_lock();
+        conn = ble_hs_conn_find_assert(chan->conn_handle);
+        rc = ble_l2cap_tx(conn, chan, txom);
+        ble_hs_unlock();
+
+        if (rc) {
+          /* txom is consumed by l2cap */
+          txom = NULL;
+          goto failed;
+        } else {
+            tx->credits --;
+            tx->data_offset += len - sdu_size_offset;
+        }
+
+        BLE_HS_LOG(DEBUG, "Sent %d bytes, credits=%d, to send %d bytes \n",
+                  len, tx->credits, OS_MBUF_PKTLEN(tx->sdu)- tx->data_offset );
+
+        if (tx->data_offset == OS_MBUF_PKTLEN(tx->sdu)) {
+                BLE_HS_LOG(DEBUG, "Complete package sent");
+                os_mbuf_free_chain(tx->sdu);
+                tx->sdu = 0;
+                tx->data_offset = 0;
+                break;
+        }
+    }
+
+    return 0;
+
+failed:
+    os_mbuf_free_chain(tx->sdu);
+    tx->sdu = NULL;
+    os_mbuf_free_chain(txom);
+
+    return rc;
+}
+
 void
 ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                 uint16_t credits)
@@ -317,6 +419,8 @@ ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
     }
 
     chan->coc_tx.credits += credits;
+    ble_l2cap_coc_continue_tx(chan);
+
     ble_hs_unlock();
 }
 
@@ -349,6 +453,26 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
 }
 
 int
+ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx)
+{
+    struct ble_l2cap_coc_endpoint *tx;
+
+    tx = &chan->coc_tx;
+
+    if (tx->sdu) {
+        return BLE_HS_EBUSY;
+    }
+
+    tx->sdu = sdu_tx;
+
+    if (OS_MBUF_PKTLEN(sdu_tx) > tx->mtu) {
+        return BLE_HS_EBADDATA;
+    }
+
+    return ble_l2cap_coc_continue_tx(chan);
+}
+
+int
 ble_l2cap_coc_init(void)
 {
     STAILQ_INIT(&ble_l2cap_coc_srvs);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5199caf4/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 36ab4dc..4fe75e9 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -67,11 +67,13 @@ void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
 void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
                               struct os_mbuf *sdu_rx);
+int ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
 #define ble_l2cap_coc_recv_ready(chan, sdu_rx)
 #define ble_l2cap_coc_cleanup_chan(chan)
+#define ble_l2cap_coc_send(chan, sdu_tx)                        BLE_HS_ENOTSUP
 #endif
 
 #ifdef __cplusplus


[21/50] incubator-mynewt-core git commit: bletiny: Refactor buffer handling in the application

Posted by ma...@apache.org.
bletiny: Refactor buffer handling in the application

With this patch we prepare os_mbuf_pool which is used later by application
to get sdu buffer


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

Branch: refs/heads/1_0_0_dev
Commit: 9bc81b106fb11a14bf7eb973f1e10adbc0cd697a
Parents: 143f6f5
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:06:53 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:28 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9bc81b10/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c468666..52cf7e6 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -73,6 +73,8 @@
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
 #define BLETINY_COC_MTU               (256)
+/* We use same pool for incoming and outgoing sdu */
+#define BLETINY_COC_BUF_COUNT         (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
 #endif
 
 struct log bletiny_log;
@@ -94,7 +96,8 @@ static void *bletiny_coc_conn_mem;
 static struct os_mempool bletiny_coc_conn_pool;
 
 static void *bletiny_sdu_coc_mem;
-static struct os_mempool bletiny_sdu_coc_pool;
+struct os_mbuf_pool sdu_os_mbuf_pool;
+static struct os_mempool sdu_coc_mbuf_mempool;
 #endif
 
 static struct os_callout bletiny_tx_timer;
@@ -1624,7 +1627,14 @@ bletiny_l2cap_coc_remove(uint16_t conn_handle, struct ble_l2cap_chan *chan)
 static void
 bletiny_l2cap_coc_recv(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 {
-    console_printf("LE CoC SDU received, chan: 0x%08lx\n", (uint32_t) chan);
+    console_printf("LE CoC SDU received, chan: 0x%08lx, data len %d\n",
+                   (uint32_t) chan, OS_MBUF_PKTLEN(sdu));
+
+    os_mbuf_free_chain(sdu);
+    sdu = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
+    assert(sdu != NULL);
+
+    ble_l2cap_recv_ready(chan, sdu);
 }
 
 static int
@@ -1633,9 +1643,9 @@ bletiny_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
 {
     struct os_mbuf *sdu_rx;
 
-    sdu_rx = os_memblock_get(&bletiny_sdu_coc_pool);
+    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     if (!sdu_rx) {
-            return BLE_HS_ENOMEM;
+        return BLE_HS_ENOMEM;
     }
 
     ble_l2cap_recv_ready(chan, sdu_rx);
@@ -1707,7 +1717,7 @@ bletiny_l2cap_connect(uint16_t conn_handle, uint16_t psm)
 
     struct os_mbuf *sdu_rx;
 
-    sdu_rx = os_memblock_get(&bletiny_sdu_coc_pool);
+    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     assert(sdu_rx != NULL);
 
     return ble_l2cap_connect(conn_handle, psm, BLETINY_COC_MTU, sdu_rx,
@@ -1793,16 +1803,18 @@ main(void)
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
     /* For testing we want to support all the available channels */
     bletiny_sdu_coc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_COC_MTU * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct os_mbuf)));
+        OS_MEMPOOL_BYTES(BLETINY_COC_BUF_COUNT, BLETINY_COC_MTU));
     assert(bletiny_sdu_coc_mem != NULL);
 
-    rc = os_mempool_init(&bletiny_sdu_coc_pool,
-                         BLETINY_COC_MTU * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct os_mbuf), bletiny_sdu_coc_mem,
+    rc = os_mempool_init(&sdu_coc_mbuf_mempool, BLETINY_COC_BUF_COUNT,
+                         BLETINY_COC_MTU, bletiny_sdu_coc_mem,
                          "bletiny_coc_sdu_pool");
     assert(rc == 0);
 
+    rc = os_mbuf_pool_init(&sdu_os_mbuf_pool, &sdu_coc_mbuf_mempool,
+                           BLETINY_COC_MTU, BLETINY_COC_BUF_COUNT);
+    assert(rc == 0);
+
     bletiny_coc_conn_mem = malloc(
         OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
                          sizeof (struct bletiny_l2cap_coc)));


[42/50] incubator-mynewt-core git commit: nimble/l2cap: Fix hanlding broken ACL during L2CAP procedure

Posted by ma...@apache.org.
nimble/l2cap: Fix hanlding broken ACL during L2CAP procedure

With this patch we make sure that all processing procedures are
free and user is notified about broken link


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

Branch: refs/heads/1_0_0_dev
Commit: 01835da6cd8265ba011ed01cb74fe277acc10fc0
Parents: 45c365c
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 09:26:17 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:28 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/01835da6/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 444a8f6..439acfe 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1200,17 +1200,26 @@ ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason)
 {
     struct ble_l2cap_sig_proc *proc;
 
-    /* If there was a connection update in progress, indicate to the
-     * application that it did not complete.
-     */
-
-    proc = ble_l2cap_sig_proc_extract(conn_handle,
-                                      BLE_L2CAP_SIG_PROC_OP_UPDATE, 0);
+    /* Report a failure for each timed out procedure. */
+    while ((proc = STAILQ_FIRST(&ble_l2cap_sig_procs)) != NULL) {
+        switch(proc->op) {
+            case BLE_L2CAP_SIG_PROC_OP_UPDATE:
+                ble_l2cap_sig_update_call_cb(proc, reason);
+                break;
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
+            case BLE_L2CAP_SIG_PROC_OP_CONNECT:
+                ble_l2cap_sig_coc_connect_cb(proc, reason);
+            break;
+            case BLE_L2CAP_SIG_PROC_OP_DISCONNECT:
+                ble_l2cap_sig_coc_disconnect_cb(proc, reason);
+            break;
+#endif
+            }
 
-    if (proc != NULL) {
-        ble_l2cap_sig_update_call_cb(proc, reason);
-        ble_l2cap_sig_proc_free(proc);
+            STAILQ_REMOVE_HEAD(&ble_l2cap_sig_procs, next);
+            ble_l2cap_sig_proc_free(proc);
     }
+
 }
 
 /**


[50/50] incubator-mynewt-core git commit: MYNEWT-527; fix OVERRIDE -> OVERWRITE

Posted by ma...@apache.org.
MYNEWT-527; fix OVERRIDE -> OVERWRITE


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

Branch: refs/heads/1_0_0_dev
Commit: cdcfc86fd6da032894074a49ff41c5c37853b4e2
Parents: b490b70
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Sat Mar 4 19:20:35 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:54:44 2017 -0800

----------------------------------------------------------------------
 hw/bsp/bmd200/bsp.yml                     | 2 +-
 hw/bsp/bmd300eval/bsp.yml                 | 4 ++--
 hw/bsp/frdm-k64f/bsp.yml                  | 4 ++--
 hw/bsp/nrf51-arduino_101/bsp.yml          | 4 ++--
 hw/bsp/nrf51dk-16kbram/bsp.yml            | 4 ++--
 hw/bsp/nrf51dk/bsp.yml                    | 4 ++--
 hw/bsp/nrf52840pdk/bsp.yml                | 4 ++--
 hw/bsp/nrf52dk/bsp.yml                    | 4 ++--
 hw/bsp/nucleo-f401re/bsp.yml              | 4 ++--
 hw/bsp/olimex_stm32-e407_devboard/bsp.yml | 4 ++--
 hw/bsp/rb-nano2/bsp.yml                   | 4 ++--
 hw/bsp/stm32f4discovery/bsp.yml           | 4 ++--
 hw/bsp/usbmkw41z/bsp.yml                  | 4 ++--
 13 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/bmd200/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd200/bsp.yml b/hw/bsp/bmd200/bsp.yml
index 3fe1275..388966d 100644
--- a/hw/bsp/bmd200/bsp.yml
+++ b/hw/bsp/bmd200/bsp.yml
@@ -28,7 +28,7 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd200/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/bmd200/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/bmd200/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd200/nrf51dk_download.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/bmd200/nrf51dk_download.cmd"
 bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/bmd200/nrf51dk_debug.cmd"
 
 bsp.flash_map:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/bmd300eval/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bsp.yml b/hw/bsp/bmd300eval/bsp.yml
index f3a9a5d..68920b3 100644
--- a/hw/bsp/bmd300eval/bsp.yml
+++ b/hw/bsp/bmd300eval/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd300eval/split-bmd300eval.ld"
 bsp.downloadscript: "hw/bsp/bmd300eval/bmd300eval_download.sh"
 bsp.debugscript: "hw/bsp/bmd300eval/bmd300eval_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/bmd300eval/bmd300eval_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/bmd300eval/bmd300eval_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/frdm-k64f/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/frdm-k64f/bsp.yml b/hw/bsp/frdm-k64f/bsp.yml
index a771696..0da1a9a 100644
--- a/hw/bsp/frdm-k64f/bsp.yml
+++ b/hw/bsp/frdm-k64f/bsp.yml
@@ -23,8 +23,8 @@ bsp.linkerscript: "hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld"
 bsp.linkerscript.BOOT_LOADER.OVERWRITE: "hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld"
 bsp.downloadscript: "hw/bsp/frdm-k64f/frdm-k64_download.sh"
 bsp.debugscript: "hw/bsp/frdm-k64f/frdm-k64_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/frdm-k64f/frdm-k64_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/frdm-k64f/frdm-k64_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nrf51-arduino_101/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/bsp.yml b/hw/bsp/nrf51-arduino_101/bsp.yml
index 7a75151..1b2cf94 100644
--- a/hw/bsp/nrf51-arduino_101/bsp.yml
+++ b/hw/bsp/nrf51-arduino_101/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
 bsp.downloadscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nrf51dk-16kbram/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/bsp.yml b/hw/bsp/nrf51dk-16kbram/bsp.yml
index 94dd59f..6aaaee4 100644
--- a/hw/bsp/nrf51dk-16kbram/bsp.yml
+++ b/hw/bsp/nrf51dk-16kbram/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk-16kbram/split-nrf51dk-16kbram.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nrf51dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/bsp.yml b/hw/bsp/nrf51dk/bsp.yml
index 247dc54..9382824 100644
--- a/hw/bsp/nrf51dk/bsp.yml
+++ b/hw/bsp/nrf51dk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nrf52840pdk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/bsp.yml b/hw/bsp/nrf52840pdk/bsp.yml
index e168d57..950c399 100644
--- a/hw/bsp/nrf52840pdk/bsp.yml
+++ b/hw/bsp/nrf52840pdk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52840pdk/split-nrf52840pdk.ld"
 bsp.downloadscript: "hw/bsp/nrf52840pdk/nrf52840pdk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nrf52dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/bsp.yml b/hw/bsp/nrf52dk/bsp.yml
index 050c16a..76e154d 100644
--- a/hw/bsp/nrf52dk/bsp.yml
+++ b/hw/bsp/nrf52dk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52dk/split-nrf52dk.ld"
 bsp.downloadscript: "hw/bsp/nrf52dk/nrf52dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52dk/nrf52dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52dk/nrf52dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52dk/nrf52dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/nucleo-f401re/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/bsp.yml b/hw/bsp/nucleo-f401re/bsp.yml
index 7610b47..4fdd6ce 100644
--- a/hw/bsp/nucleo-f401re/bsp.yml
+++ b/hw/bsp/nucleo-f401re/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f401.ld"
 bsp.downloadscript: "hw/bsp/nucleo-f401re/nucleo-f401re_download.sh"
 bsp.debugscript: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
index 478703b..fdddd4b 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
+++ b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh"
 bsp.debugscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/rb-nano2/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/bsp.yml b/hw/bsp/rb-nano2/bsp.yml
index c4fc926..7e04c46 100644
--- a/hw/bsp/rb-nano2/bsp.yml
+++ b/hw/bsp/rb-nano2/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/rb-nano2/split-rb-nano2.ld"
 bsp.downloadscript: "hw/bsp/rb-nano2/rb-nano2_download.sh"
 bsp.debugscript: "hw/bsp/rb-nano2/rb-nano2_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/rb-nano2/rb-nano2_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/rb-nano2/rb-nano2_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/stm32f4discovery/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/bsp.yml b/hw/bsp/stm32f4discovery/bsp.yml
index 658cb21..6c4a1a5 100644
--- a/hw/bsp/stm32f4discovery/bsp.yml
+++ b/hw/bsp/stm32f4discovery/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/stm32f4discovery/stm32f4discovery_download.sh"
 bsp.debugscript: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cdcfc86f/hw/bsp/usbmkw41z/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/usbmkw41z/bsp.yml b/hw/bsp/usbmkw41z/bsp.yml
index 55e9ae7..eff217c 100644
--- a/hw/bsp/usbmkw41z/bsp.yml
+++ b/hw/bsp/usbmkw41z/bsp.yml
@@ -26,8 +26,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/usbmkw41z/split-usbkw41z.ld"
 bsp.downloadscript: "hw/bsp/usbmkw41z/usbkw41z_download.sh"
 bsp.debugscript: "hw/bsp/usbmkw41z/usbkw41z_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/usbmkw41z/usbkw41z_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/usbmkw41z/usbkw41z_debug.cmd"
 
 bsp.flash_map:
     areas:


[19/50] incubator-mynewt-core git commit: MYNEWT-527; add Windows wrapper script to nrf51-blenano.

Posted by ma...@apache.org.
MYNEWT-527; add Windows wrapper script to nrf51-blenano.


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

Branch: refs/heads/1_0_0_dev
Commit: 9c7db2d4a493c6b5307916b98d36ad19bb632545
Parents: b48c0bc
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 08:10:38 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:11 2017 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51-blenano/bsp.yml              | 2 ++
 hw/bsp/nrf51-blenano/nrf51dk_debug.cmd    | 3 +++
 hw/bsp/nrf51-blenano/nrf51dk_download.cmd | 3 +++
 3 files changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9c7db2d4/hw/bsp/nrf51-blenano/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/bsp.yml b/hw/bsp/nrf51-blenano/bsp.yml
index c174892..ee95b51 100644
--- a/hw/bsp/nrf51-blenano/bsp.yml
+++ b/hw/bsp/nrf51-blenano/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51-blenano/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51-blenano/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-blenano/nrf51dk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9c7db2d4/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd b/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9c7db2d4/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/nrf51dk_download.cmd b/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"


[23/50] incubator-mynewt-core git commit: bletiny: Add debug log for CoC accept

Posted by ma...@apache.org.
bletiny: Add debug log for CoC accept


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

Branch: refs/heads/1_0_0_dev
Commit: 0aef4806e0ca0d20a7cf91d2de31a2760bca55a6
Parents: c26d8c6
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 16 06:29:56 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:46 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0aef4806/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index b8f1e51..442a264 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1643,6 +1643,9 @@ bletiny_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
 {
     struct os_mbuf *sdu_rx;
 
+    console_printf("LE CoC accepting, chan: 0x%08lx, peer_mtu %d\n",
+                       (uint32_t) chan, peer_mtu);
+
     sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     if (!sdu_rx) {
         return BLE_HS_ENOMEM;


[43/50] incubator-mynewt-core git commit: nimble/l2cap: Improve L2CAP LE CoC connection handling

Posted by ma...@apache.org.
nimble/l2cap: Improve L2CAP LE CoC connection handling

With this patch we make sure remote does not use already used CID


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

Branch: refs/heads/1_0_0_dev
Commit: 687403eb222dc00e72e82345c62228fc9ab42048
Parents: 01835da
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 11:42:43 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:53:37 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/687403eb/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 439acfe..1840b0a 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -658,14 +658,19 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     ble_hs_lock();
     conn = ble_hs_conn_find_assert(conn_handle);
 
-    /* Verify CID */
+    /* Verify CID. Note, scid in the request is dcid for out local channel */
     scid = le16toh(req->scid);
     if (scid < BLE_L2CAP_COC_CID_START || scid > BLE_L2CAP_COC_CID_END) {
-        /*FIXME: Check if SCID is not already used */
         rsp->result = htole16(BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID);
         goto failed;
     }
 
+    chan = ble_hs_conn_chan_find_by_dcid(conn, scid);
+    if (chan) {
+        rsp->result = htole16(BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED);
+        goto failed;
+    }
+
     rc = ble_l2cap_coc_create_srv_chan(conn_handle, le16toh(req->psm), &chan);
     if (rc != 0) {
         uint16_t coc_err = ble_l2cap_sig_ble_hs_err2coc_err(rc);


[06/50] incubator-mynewt-core git commit: MYNEWT-642 Eddystone UID format is incorrect

Posted by ma...@apache.org.
MYNEWT-642 Eddystone UID format is incorrect

The tx power and reserved bytes were missing.


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

Branch: refs/heads/1_0_0_dev
Commit: 0c354af2d39efa652e8c4211e65968d15b35ac9d
Parents: 4f154cd
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Feb 27 20:25:53 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:48:13 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_eddystone.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0c354af2/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index e6e15c3..6132b78 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -127,12 +127,28 @@ ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields, void *uid)
     return BLE_HS_ENOTSUP;
 #endif
 
-    void *svc_data;
+    uint8_t *svc_data;
+    int8_t tx_pwr;
     int rc;
 
+    /* Eddystone UUID and frame type (0). */
     svc_data = ble_eddystone_set_svc_data_base(BLE_EDDYSTONE_FRAME_TYPE_UID);
-    memcpy(svc_data, uid, 16);
-    rc = ble_eddystone_set_adv_data_gen(adv_fields, 16);
+
+    /* Ranging data (Calibrated tx power at 0 meters). */
+    rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
+    if (rc != 0) {
+        return rc;
+    }
+    svc_data[0] = tx_pwr;
+
+    /* UID. */
+    memcpy(svc_data + 1, uid, 16);
+
+    /* Reserved. */
+    svc_data[17] = 0x00;
+    svc_data[18] = 0x00;
+
+    rc = ble_eddystone_set_adv_data_gen(adv_fields, 19);
     if (rc != 0) {
         return rc;
     }


[29/50] incubator-mynewt-core git commit: nimble/l2cap: Add helper to create L2CAP channel for LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add helper to create L2CAP channel for LE CoC

With this patch, creating L2CAP channel for LE CoC purposes is moved
to ble_l2cap_coc.c. It is because in that file we want to have
all the logic related to CoC e.g. credits, available servers, data handling


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

Branch: refs/heads/1_0_0_dev
Commit: e9d7750ab36ca434d3f76408787cf9d7f76feee1
Parents: 7f09f38
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 11:27:14 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:34 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c      | 57 ++++++++++++++++++++++++++-
 net/nimble/host/src/ble_l2cap_coc_priv.h | 11 ++++--
 net/nimble/host/src/ble_l2cap_sig.c      | 43 +++++---------------
 3 files changed, 73 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e9d7750a/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 6286d43..46b903b 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -87,7 +87,7 @@ ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
     return 0;
 }
 
-uint16_t
+static uint16_t
 ble_l2cap_coc_get_cid(void)
 {
     static uint16_t next_cid = BLE_L2CAP_COC_CID_START;
@@ -100,7 +100,7 @@ ble_l2cap_coc_get_cid(void)
     return next_cid++;
 }
 
-struct ble_l2cap_coc_srv *
+static struct ble_l2cap_coc_srv *
 ble_l2cap_coc_srv_find(uint16_t psm)
 {
     struct ble_l2cap_coc_srv *cur, *srv;
@@ -116,6 +116,59 @@ ble_l2cap_coc_srv_find(uint16_t psm)
     return srv;
 }
 
+static int
+ble_l2cap_coc_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom)
+{
+    return 0;
+}
+
+struct ble_l2cap_chan *
+ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
+                         struct os_mbuf *sdu_rx, ble_l2cap_event_fn *cb,
+                         void *cb_arg)
+{
+    struct ble_l2cap_chan *chan;
+
+    chan = ble_l2cap_chan_alloc();
+    if (!chan) {
+        return NULL;
+    }
+
+    chan->conn_handle = conn_handle;
+    chan->psm = psm;
+    chan->cb = cb;
+    chan->cb_arg = cb_arg;
+    chan->scid = ble_l2cap_coc_get_cid();
+    chan->my_mtu = BLE_L2CAP_COC_MTU;
+    chan->rx_fn = ble_l2cap_coc_rx_fn;
+    chan->coc_rx.mtu = mtu;
+    chan->coc_rx.credits = 10; /* FIXME Calculate it */
+    chan->coc_rx.sdu = sdu_rx;
+
+    return chan;
+}
+
+int
+ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
+                              struct ble_l2cap_chan **chan)
+{
+    struct ble_l2cap_coc_srv *srv;
+
+    /* Check if there is server registered on this PSM */
+    srv = ble_l2cap_coc_srv_find(psm);
+    if (!srv) {
+        return BLE_HS_ENOTSUP;
+    }
+
+    *chan = ble_l2cap_coc_chan_alloc(conn_handle, psm, srv->mtu, NULL, srv->cb,
+                                     srv->cb_arg);
+    if (!*chan) {
+        return BLE_HS_ENOMEM;
+    }
+
+    return 0;
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e9d7750a/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 31e81e7..63c593e 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -23,9 +23,9 @@
 #include <inttypes.h>
 #include "syscfg/syscfg.h"
 #include "os/queue.h"
+#include "os/os_mbuf.h"
 #include "host/ble_l2cap.h"
 #include "ble_l2cap_sig_priv.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -52,10 +52,15 @@ struct ble_l2cap_coc_srv {
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 int ble_l2cap_coc_init(void);
-uint16_t ble_l2cap_coc_get_cid(void);
 int ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
                                 ble_l2cap_event_fn *cb, void *cb_arg);
-struct ble_l2cap_coc_srv * ble_l2cap_coc_srv_find(uint16_t psm);
+int ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
+                                  struct ble_l2cap_chan **chan);
+struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
+                                                 uint16_t psm, uint16_t mtu,
+                                                 struct os_mbuf *sdu_rx,
+                                                 ble_l2cap_event_fn *cb,
+                                                 void *cb_arg);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e9d7750a/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 7919a89..d6219d3 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -551,6 +551,8 @@ static int
 ble_l2cap_sig_ble_hs_err2coc_err(uint16_t ble_hs_err)
 {
     switch (ble_hs_err) {
+    case BLE_HS_ENOTSUP:
+        return BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM;
     case BLE_HS_ENOMEM:
         return BLE_L2CAP_COC_ERR_NO_RESOURCES;
     case BLE_HS_EAUTHEN:
@@ -631,8 +633,7 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     struct ble_l2cap_sig_le_con_req *req;
     struct os_mbuf *txom;
     struct ble_l2cap_sig_le_con_rsp *rsp;
-    struct ble_l2cap_coc_srv *srv;
-    struct ble_l2cap_chan *chan;
+    struct ble_l2cap_chan *chan = NULL;
     struct ble_hs_conn *conn;
     uint16_t scid;
 
@@ -657,13 +658,6 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     ble_hs_lock();
     conn = ble_hs_conn_find_assert(conn_handle);
 
-    /* Check if there is server registered on this PSM */
-    srv = ble_l2cap_coc_srv_find(le16toh(req->psm));
-    if (!srv) {
-        rsp->result = htole16(BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM);
-        goto failed;
-    }
-
     /* Verify CID */
     scid = le16toh(req->scid);
     if (scid < BLE_L2CAP_COC_CID_START || scid > BLE_L2CAP_COC_CID_END) {
@@ -672,19 +666,15 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         goto failed;
     }
 
-    chan = ble_l2cap_chan_alloc();
-    if (!chan) {
-        rsp->result = htole16(BLE_L2CAP_COC_ERR_NO_RESOURCES);
+    rc = ble_l2cap_coc_create_srv_chan(conn_handle, le16toh(req->psm), &chan);
+    if (rc != 0) {
+        uint16_t coc_err = ble_l2cap_sig_ble_hs_err2coc_err(rc);
+        rsp->result = htole16(coc_err);
         goto failed;
     }
 
-    chan->cb = srv->cb;
-    chan->cb_arg = srv->cb_arg;
-    chan->conn_handle = conn_handle;
-    chan->dcid = scid;
-    chan->my_mtu = BLE_L2CAP_COC_MTU;
-
     /* Fill up remote configuration. Note MPS is the L2CAP MTU*/
+    chan->dcid = scid;
     chan->peer_mtu = le16toh(req->mps);
     chan->coc_tx.credits = le16toh(req->credits);
     chan->coc_tx.mtu = le16toh(req->mtu);
@@ -697,10 +687,6 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         goto failed;
     }
 
-    chan->scid = ble_l2cap_coc_get_cid();
-    chan->coc_rx.mtu = srv->mtu;
-    chan->coc_rx.credits = 10; //FIXME Calculate it
-
     rsp->dcid = htole16(chan->scid);
     rsp->credits = htole16(chan->coc_rx.credits);
     rsp->mps = htole16(chan->my_mtu);
@@ -795,7 +781,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
     struct ble_l2cap_sig_proc *proc;
     struct os_mbuf *txom;
     struct ble_l2cap_sig_le_con_req *req;
-    struct ble_l2cap_chan *chan;
+    struct ble_l2cap_chan *chan = NULL;
     int rc;
 
     if (!sdu_rx || !cb) {
@@ -810,7 +796,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
         return BLE_HS_ENOTCONN;
     }
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_coc_chan_alloc(conn_handle, psm, mtu, sdu_rx, cb, cb_arg);
     if (!chan) {
         ble_hs_unlock();
         return BLE_HS_ENOMEM;
@@ -823,15 +809,6 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
         return BLE_HS_ENOMEM;
     }
 
-    chan->scid = ble_l2cap_coc_get_cid();
-    chan->my_mtu = BLE_L2CAP_COC_MTU;
-    chan->coc_rx.credits = 10;
-    chan->coc_rx.mtu = mtu;
-    chan->coc_rx.sdu = sdu_rx;
-    chan->cb = cb;
-    chan->cb_arg = cb_arg;
-    chan->conn_handle = conn_handle;
-
     proc->op = BLE_L2CAP_SIG_PROC_OP_CONNECT;
     proc->id = ble_l2cap_sig_next_id();
     proc->conn_handle = conn_handle;


[20/50] incubator-mynewt-core git commit: bletiny: Add missing returns in L2CAP connect/disconnect

Posted by ma...@apache.org.
bletiny: Add missing returns in L2CAP connect/disconnect

Fix missing error returns.


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

Branch: refs/heads/1_0_0_dev
Commit: 143f6f53dd6a1cc44e507214dac8b6b641747572
Parents: 9c7db2d
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:04:10 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:50:20 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/143f6f53/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 8904ea2..47ab379 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1226,6 +1226,7 @@ cmd_l2cap_connect(int argc, char **argv)
     if (rc != 0) {
         console_printf("invalid 'conn' parameter\n");
         help_cmd_uint16("conn");
+        return rc;
     }
 
     psm = parse_arg_uint16("psm", &rc);
@@ -1265,13 +1266,14 @@ cmd_l2cap_disconnect(int argc, char **argv)
     if (rc != 0) {
         console_printf("invalid 'conn' parameter\n");
         help_cmd_uint16("conn");
+        return rc;
     }
 
     idx = parse_arg_uint16("idx", &rc);
     if (rc != 0) {
         console_printf("invalid 'idx' parameter\n");
         help_cmd_uint16("idx");
-        return 0;
+        return rc;
     }
 
     return bletiny_l2cap_disconnect(conn, idx);


[46/50] incubator-mynewt-core git commit: don't crash when dumping logs from shell. Dump full logs.

Posted by ma...@apache.org.
don't crash when dumping logs from shell.   Dump full logs.


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

Branch: refs/heads/1_0_0_dev
Commit: e85707dad58de5b3ca8789961775a8daa938627f
Parents: 933f658
Author: Sterling Hughes <st...@runtime.io>
Authored: Sat Mar 4 10:09:18 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:54:05 2017 -0800

----------------------------------------------------------------------
 sys/log/full/src/log_shell.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e85707da/sys/log/full/src/log_shell.c
----------------------------------------------------------------------
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index e0f6d71..ae1fd3d 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -71,6 +71,7 @@ int
 shell_log_dump_all_cmd(int argc, char **argv)
 {
     struct log *log;
+    struct log_offset log_offset;
     int rc;
 
     log = NULL;
@@ -86,7 +87,12 @@ shell_log_dump_all_cmd(int argc, char **argv)
 
         console_printf("Dumping log %s\n", log->l_name);
 
-        rc = log_walk(log, shell_log_dump_entry, NULL);
+        log_offset.lo_arg = NULL;
+        log_offset.lo_ts = 0;
+        log_offset.lo_index = 0;
+        log_offset.lo_data_len = 0;
+
+        rc = log_walk(log, shell_log_dump_entry, &log_offset);
         if (rc != 0) {
             goto err;
         }


[25/50] incubator-mynewt-core git commit: nimble/l2cap: Fix handling scid/dcid in the channel.

Posted by ma...@apache.org.
nimble/l2cap: Fix handling scid/dcid in the channel.

This patch makes sure that each l2cap channel has corretly
set scid and dcid. In the same time dcid is use when sending
data.


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

Branch: refs/heads/1_0_0_dev
Commit: 357d8bd17c5055d5df8e2521d072f286c8658912
Parents: 07b86ff
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 16 06:31:43 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:51:02 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c        | 1 +
 net/nimble/host/src/ble_l2cap.c      | 2 +-
 net/nimble/host/src/ble_l2cap_priv.h | 2 +-
 net/nimble/host/src/ble_l2cap_sig.c  | 1 +
 net/nimble/host/src/ble_sm.c         | 1 +
 5 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/357d8bd1/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index ff1eebf..329fcec 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -561,6 +561,7 @@ ble_att_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_ATT;
+    chan->dcid = BLE_L2CAP_CID_ATT;
     chan->my_mtu = ble_att_preferred_mtu_val;
     chan->rx_fn = ble_att_rx;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/357d8bd1/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index e94a234..09ca9dc 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -385,7 +385,7 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
 {
     int rc;
 
-    txom = ble_l2cap_prepend_hdr(txom, chan->scid, OS_MBUF_PKTLEN(txom));
+    txom = ble_l2cap_prepend_hdr(txom, chan->dcid, OS_MBUF_PKTLEN(txom));
     if (txom == NULL) {
         return BLE_HS_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/357d8bd1/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index cc4e0ed..81e350d 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -66,6 +66,7 @@ typedef int ble_l2cap_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
+    uint16_t dcid;
     uint16_t scid;
     uint16_t my_mtu;
     uint16_t peer_mtu;      /* 0 if not exchanged. */
@@ -78,7 +79,6 @@ struct ble_l2cap_chan {
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
     uint16_t conn_handle;
-    uint16_t dcid;
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/357d8bd1/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 40cda11..94bb271 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1060,6 +1060,7 @@ ble_l2cap_sig_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_SIG;
+    chan->dcid = BLE_L2CAP_CID_SIG;
     chan->my_mtu = BLE_L2CAP_SIG_MTU;
     chan->rx_fn = ble_l2cap_sig_rx;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/357d8bd1/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index bb2c1aa..2a880dc 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2512,6 +2512,7 @@ ble_sm_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_SM;
+    chan->dcid = BLE_L2CAP_CID_SM;
     chan->my_mtu = BLE_SM_MTU;
     chan->rx_fn = ble_sm_rx;
 


[33/50] incubator-mynewt-core git commit: nimble/l2cap: Make ble_l2cap_chan available in ble_l2cap_rx_fn

Posted by ma...@apache.org.
nimble/l2cap: Make ble_l2cap_chan available in ble_l2cap_rx_fn

Each L2CAP channel has its data handler function. Till now we had
function per CID. In order to handle COC we need to have possibility
to handle more channels in same data handler function. For this reason
we need to have pointer to ble_l2cap_chan to which data are comming.

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

Branch: refs/heads/1_0_0_dev
Commit: 505cea6dd8811be3115d63735afbe4282daae96d
Parents: d116c90
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 14:44:47 2017 +0100
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 15:52:08 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_l2cap.h    |  1 +
 net/nimble/host/src/ble_att.c               | 12 +++++++++---
 net/nimble/host/src/ble_att_priv.h          |  2 +-
 net/nimble/host/src/ble_gap.c               |  3 +--
 net/nimble/host/src/ble_hs_conn.c           |  9 +++++----
 net/nimble/host/src/ble_hs_conn_priv.h      |  2 +-
 net/nimble/host/src/ble_hs_hci_evt.c        |  3 ++-
 net/nimble/host/src/ble_l2cap.c             | 16 +++++++++++++---
 net/nimble/host/src/ble_l2cap_coc.c         |  5 ++---
 net/nimble/host/src/ble_l2cap_priv.h        |  7 ++++---
 net/nimble/host/src/ble_l2cap_sig.c         |  7 ++++---
 net/nimble/host/src/ble_l2cap_sig_priv.h    |  2 +-
 net/nimble/host/src/ble_sm.c                | 20 ++++++++++++++++----
 net/nimble/host/src/ble_sm_priv.h           |  2 +-
 net/nimble/host/test/src/ble_hs_test_util.c |  3 ++-
 net/nimble/host/test/src/ble_l2cap_test.c   |  4 ++--
 16 files changed, 65 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/include/host/ble_l2cap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_l2cap.h b/net/nimble/host/include/host/ble_l2cap.h
index 604d080..b3b03b9 100644
--- a/net/nimble/host/include/host/ble_l2cap.h
+++ b/net/nimble/host/include/host/ble_l2cap.h
@@ -174,6 +174,7 @@ struct ble_l2cap_event {
 
 typedef int ble_l2cap_event_fn(struct ble_l2cap_event *event, void *arg);
 
+uint16_t ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan);
 int ble_l2cap_create_server(uint16_t psm, uint16_t mtu,
                             ble_l2cap_event_fn *cb, void *cb_arg);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 329fcec..7876e0d 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -461,12 +461,18 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan)
 }
 
 static int
-ble_att_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     const struct ble_att_rx_dispatch_entry *entry;
     uint8_t op;
+    uint16_t conn_handle;
     int rc;
 
+    conn_handle = ble_l2cap_get_conn_handle(chan);
+    if (!conn_handle) {
+        return BLE_HS_ENOTCONN;
+    }
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EMSGSIZE;
@@ -551,11 +557,11 @@ ble_att_set_preferred_mtu(uint16_t mtu)
 }
 
 struct ble_l2cap_chan *
-ble_att_create_chan(void)
+ble_att_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 22ed62e..af05684 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -159,7 +159,7 @@ SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
 
 /*** @gen */
 
-struct ble_l2cap_chan *ble_att_create_chan(void);
+struct ble_l2cap_chan *ble_att_create_chan(uint16_t conn_handle);
 void ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
                             struct ble_l2cap_chan **out_chan);
 void ble_att_inc_tx_stat(uint8_t att_op);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 92c3d12..0a09d4c 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1151,10 +1151,9 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     }
 
     /* We verified that there is a free connection when the procedure began. */
-    conn = ble_hs_conn_alloc();
+    conn = ble_hs_conn_alloc(evt->connection_handle);
     BLE_HS_DBG_ASSERT(conn != NULL);
 
-    conn->bhc_handle = evt->connection_handle;
     conn->bhc_itvl = evt->conn_itvl;
     conn->bhc_latency = evt->conn_latency;
     conn->bhc_supervision_timeout = evt->supervision_timeout;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 02676fa..a371ace 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -102,7 +102,7 @@ ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 }
 
 struct ble_hs_conn *
-ble_hs_conn_alloc(void)
+ble_hs_conn_alloc(uint16_t conn_handle)
 {
 #if !NIMBLE_BLE_CONNECT
     return NULL;
@@ -117,10 +117,11 @@ ble_hs_conn_alloc(void)
         goto err;
     }
     memset(conn, 0, sizeof *conn);
+    conn->bhc_handle = conn_handle;
 
     SLIST_INIT(&conn->bhc_channels);
 
-    chan = ble_att_create_chan();
+    chan = ble_att_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }
@@ -129,7 +130,7 @@ ble_hs_conn_alloc(void)
         goto err;
     }
 
-    chan = ble_l2cap_sig_create_chan();
+    chan = ble_l2cap_sig_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }
@@ -141,7 +142,7 @@ ble_hs_conn_alloc(void)
     /* Create the SM channel even if not configured. We need it to reject SM
      * messages.
      */
-    chan = ble_sm_create_chan();
+    chan = ble_sm_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index b58a0df..24e2e48 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -74,7 +74,7 @@ struct ble_hs_conn_addrs {
 };
 
 int ble_hs_conn_can_alloc(void);
-struct ble_hs_conn *ble_hs_conn_alloc(void);
+struct ble_hs_conn *ble_hs_conn_alloc(uint16_t conn_handle);
 void ble_hs_conn_free(struct ble_hs_conn *conn);
 void ble_hs_conn_insert(struct ble_hs_conn *conn);
 void ble_hs_conn_remove(struct ble_hs_conn *conn);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
index a2d7a52..7f868a6 100644
--- a/net/nimble/host/src/ble_hs_hci_evt.c
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -659,7 +659,8 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
         /* Final fragment received. */
         BLE_HS_DBG_ASSERT(rx_cb != NULL);
         BLE_HS_DBG_ASSERT(rx_buf != NULL);
-        rc = rx_cb(conn_handle, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
         os_mbuf_free_chain(rx_buf);
         break;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 09ca9dc..d909b78 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -52,7 +52,7 @@ STATS_NAME_START(ble_l2cap_stats)
 STATS_NAME_END(ble_l2cap_stats)
 
 struct ble_l2cap_chan *
-ble_l2cap_chan_alloc(void)
+ble_l2cap_chan_alloc(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
@@ -62,6 +62,7 @@ ble_l2cap_chan_alloc(void)
     }
 
     memset(chan, 0, sizeof *chan);
+    chan->conn_handle = conn_handle;
 
     STATS_INC(ble_l2cap_stats, chan_create);
 
@@ -126,6 +127,16 @@ ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid, uint16_t len)
     return om;
 }
 
+uint16_t
+ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan)
+{
+    if (!chan) {
+        return 0;
+    }
+
+    return chan->conn_handle;
+}
+
 int
 ble_l2cap_create_server(uint16_t psm, uint16_t mtu,
                         ble_l2cap_event_fn *cb, void *cb_arg)
@@ -158,7 +169,7 @@ ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
     /*TODO In here we going to update sdu_rx buffer */
 }
 
-static void
+void
 ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {
     conn->bhc_rx_chan = NULL;
@@ -221,7 +232,6 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
         /* All fragments received. */
         *out_rx_cb = chan->rx_fn;
         *out_rx_buf = chan->rx_buf;
-        ble_l2cap_forget_rx(conn, chan);
         rc = 0;
     } else {
         /* More fragments remain. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 46b903b..178370d 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -117,7 +117,7 @@ ble_l2cap_coc_srv_find(uint16_t psm)
 }
 
 static int
-ble_l2cap_coc_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom)
+ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom)
 {
     return 0;
 }
@@ -129,12 +129,11 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (!chan) {
         return NULL;
     }
 
-    chan->conn_handle = conn_handle;
     chan->psm = psm;
     chan->cb = cb;
     chan->cb_arg = cb_arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 81e350d..64ffa22 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -62,10 +62,11 @@ extern struct os_mempool ble_l2cap_chan_pool;
 
 typedef uint8_t ble_l2cap_chan_flags;
 
-typedef int ble_l2cap_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom);
+typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
+    uint16_t conn_handle;
     uint16_t dcid;
     uint16_t scid;
     uint16_t my_mtu;
@@ -78,7 +79,6 @@ struct ble_l2cap_chan {
     ble_l2cap_rx_fn *rx_fn;
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
-    uint16_t conn_handle;
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;
@@ -104,7 +104,7 @@ int ble_l2cap_parse_hdr(struct os_mbuf *om, int off,
 struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid,
                                       uint16_t len);
 
-struct ble_l2cap_chan *ble_l2cap_chan_alloc(void);
+struct ble_l2cap_chan *ble_l2cap_chan_alloc(uint16_t conn_handle);
 void ble_l2cap_chan_free(struct ble_l2cap_chan *chan);
 
 bool ble_l2cap_is_mtu_req_sent(const struct ble_l2cap_chan *chan);
@@ -118,6 +118,7 @@ int ble_l2cap_rx(struct ble_hs_conn *conn,
 int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                  struct os_mbuf *txom);
 
+void ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
 int ble_l2cap_init(void);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 560311d..93d73ed 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1012,10 +1012,11 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
  *****************************************************************************/
 
 static int
-ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_l2cap_sig_hdr hdr;
     ble_l2cap_sig_rx_fn *rx_cb;
+    uint16_t conn_handle = chan->conn_handle;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sig_rx);
@@ -1054,11 +1055,11 @@ ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
 }
 
 struct ble_l2cap_chan *
-ble_l2cap_sig_create_chan(void)
+ble_l2cap_sig_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index ad3b846..0677405 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -111,7 +111,7 @@ int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
 
 void ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason);
 int32_t ble_l2cap_sig_timer(void);
-struct ble_l2cap_chan *ble_l2cap_sig_create_chan(void);
+struct ble_l2cap_chan *ble_l2cap_sig_create_chan(uint16_t conn_handle);
 int ble_l2cap_sig_init(void);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 2a880dc..603d99c 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2326,15 +2326,21 @@ ble_sm_unbond(uint8_t peer_id_addr_type, const uint8_t *peer_id_addr)
 }
 
 static int
-ble_sm_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_sm_result res;
     ble_sm_rx_fn *rx_cb;
     uint8_t op;
+    uint16_t conn_handle;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sm_rx);
 
+    conn_handle = ble_l2cap_get_conn_handle(chan);
+    if (!conn_handle) {
+        return BLE_HS_ENOTCONN;
+    }
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EBADDATA;
@@ -2485,10 +2491,16 @@ ble_sm_init(void)
  * simple
  */
 static int
-ble_sm_rx(uint16_t handle, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_sm_pair_fail *cmd;
     struct os_mbuf *txom;
+    uint16_t handle;
+
+    handle = ble_l2cap_get_conn_handle(chan);
+    if (!handle) {
+        return BLE_HS_ENOTCONN;
+    }
 
     cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_FAIL, sizeof(*cmd), &txom);
     if (cmd == NULL) {
@@ -2502,11 +2514,11 @@ ble_sm_rx(uint16_t handle, struct os_mbuf **om)
 #endif
 
 struct ble_l2cap_chan *
-ble_sm_create_chan(void)
+ble_sm_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index eb4f2da..86c31da 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -419,7 +419,7 @@ int ble_sm_init(void);
 
 #endif
 
-struct ble_l2cap_chan *ble_sm_create_chan(void);
+struct ble_l2cap_chan *ble_sm_create_chan(uint16_t handle);
 void *ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
 int ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 0dc1b18..9fa2d3d 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -954,7 +954,8 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
     } else if (rc == 0) {
         TEST_ASSERT_FATAL(rx_cb != NULL);
         TEST_ASSERT_FATAL(rx_buf != NULL);
-        rc = rx_cb(conn_handle, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
         os_mbuf_free_chain(rx_buf);
     } else if (rc == BLE_HS_EAGAIN) {
         /* More fragments on the way. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/505cea6d/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index 9c11607..e68971d 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -94,7 +94,7 @@ ble_l2cap_test_util_verify_tx_update_conn(
 }
 
 static int
-ble_l2cap_test_util_dummy_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     return 0;
 }
@@ -113,7 +113,7 @@ ble_l2cap_test_util_create_conn(uint16_t conn_handle, uint8_t *addr,
     conn = ble_hs_conn_find(conn_handle);
     TEST_ASSERT_FATAL(conn != NULL);
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     TEST_ASSERT_FATAL(chan != NULL);
 
     chan->scid = BLE_L2CAP_TEST_CID;