You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/02/05 22:35:47 UTC

[1/2] incubator-mynewt-larva git commit: Fix os_msys_get_pkthdr bug where the size of the os mbuf pkthdr was not taken into account. Also, we now use the term 'user header' instead of 'extra packet header'

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master f52685853 -> 4989659ff


Fix os_msys_get_pkthdr bug where the size of the os mbuf pkthdr was not taken into account. Also, we now use the term 'user header' instead of 'extra packet header'


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/c216090c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/c216090c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/c216090c

Branch: refs/heads/master
Commit: c216090cb252e63031c1d31d2ea488f58cf39c05
Parents: f526858
Author: wes3 <wi...@micosa.io>
Authored: Fri Feb 5 13:11:05 2016 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Fri Feb 5 13:25:40 2016 -0800

----------------------------------------------------------------------
 libs/os/include/os/os_mbuf.h |  3 +--
 libs/os/src/os_mbuf.c        | 14 ++++++++------
 2 files changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c216090c/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index 09d13fb..16180a2 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -237,8 +237,7 @@ int os_msys_register(struct os_mbuf_pool *);
 struct os_mbuf *os_msys_get(uint16_t dsize, uint16_t leadingspace);
 
 /* Return a packet header mbuf from the system pool */
-struct os_mbuf *os_msys_get_pkthdr(uint16_t dsize, uint16_t pkthdr_len);
-
+struct os_mbuf *os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len);
 
 /* Initialize a mbuf pool */
 int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp, 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/c216090c/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 844af80..bb6d458 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -185,17 +185,19 @@ err:
 
 
 struct os_mbuf *
-os_msys_get_pkthdr(uint16_t dsize, uint16_t pkthdr_len)
+os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len)
 {
+    uint16_t total_pkthdr_len;
     struct os_mbuf *m;
     struct os_mbuf_pool *pool;
 
-    pool = _os_msys_find_pool(dsize + pkthdr_len);
+    total_pkthdr_len =  user_hdr_len + sizeof(struct os_mbuf_pkthdr);
+    pool = _os_msys_find_pool(dsize + total_pkthdr_len);
     if (!pool) {
         goto err;
     }
     
-    m = os_mbuf_get_pkthdr(pool, pkthdr_len);
+    m = os_mbuf_get_pkthdr(pool, user_hdr_len);
     return (m);
 err:
     return (NULL);
@@ -257,15 +259,15 @@ err:
 
 /* Allocate a new packet header mbuf out of the os_mbuf_pool */ 
 struct os_mbuf *
-os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, uint8_t extra_pkthdr_len)
+os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, uint8_t user_pkthdr_len)
 {
     struct os_mbuf_pkthdr *pkthdr;
     struct os_mbuf *om;
 
     om = os_mbuf_get(omp, 0);
     if (om) {
-        om->om_pkthdr_len = extra_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
-        om->om_data += extra_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
+        om->om_pkthdr_len = user_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
+        om->om_data += user_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
 
         pkthdr = OS_MBUF_PKTHDR(om);
         pkthdr->omp_len = 0;


[2/2] incubator-mynewt-larva git commit: Modify code to use msys as opposed to mbuf. For now, we define the size of the msys buffer pool in ble.h and that is used by the project to allocate the memory blocks for the block

Posted by we...@apache.org.
Modify code to use msys as opposed to mbuf. For now, we define the size of the msys buffer pool in ble.h and that is used by the project to allocate the memory blocks for the block


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/4989659f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4989659f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4989659f

Branch: refs/heads/master
Commit: 4989659ff03f7548f6264259cfb0052c2c23e37a
Parents: c216090
Author: wes3 <wi...@micosa.io>
Authored: Fri Feb 5 13:25:29 2016 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Fri Feb 5 13:35:34 2016 -0800

----------------------------------------------------------------------
 net/nimble/controller/include/controller/ble_ll.h   |  4 +++-
 .../controller/include/controller/ble_ll_conn.h     |  2 +-
 .../controller/include/controller/ble_ll_ctrl.h     |  1 +
 net/nimble/controller/src/ble_ll_conn.c             |  2 +-
 net/nimble/controller/src/ble_ll_conn_hci.c         |  3 ++-
 net/nimble/controller/src/ble_ll_ctrl.c             |  5 +++--
 net/nimble/include/nimble/ble.h                     | 16 +++++++++++-----
 project/bletest/src/main.c                          | 10 ++++------
 8 files changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index d76dccb..a83f817 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -202,7 +202,7 @@ struct ble_dev_addr
  *      -> LSB contains pdu type, txadd and rxadd bits.
  *      -> MSB contains length (6 bits). Length is length of payload. Does
  *         not include the header length itself. 
- * -> Payload
+ * -> Payload (max 37 bytes)
  */
 #define BLE_ADV_PDU_HDR_TYPE_MASK           (0x0F)
 #define BLE_ADV_PDU_HDR_TXADD_MASK          (0x40)
@@ -225,6 +225,8 @@ struct ble_dev_addr
 #define BLE_ADV_PDU_HDR_TXADD_RAND          (0x40)
 #define BLE_ADV_PDU_HDR_RXADD_RAND          (0x80)
 
+/* Max length */
+#define BLE_LL_MAX_ADV_PYLD                 (37)
 /*
  * Data Channel format
  * 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index 9de8d32..07fa01a 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -53,7 +53,7 @@
  * and we always want to have one available. The empty pdu length is of
  * type uint32_t so we have 4 byte alignment.
  */ 
-#define BLE_LL_EMPTY_PDU_MBUF_SIZE  (BLE_MBUF_PKT_OVERHEAD / 4)
+#define BLE_LL_EMPTY_PDU_MBUF_SIZE  (BLE_MBUF_MEMBLOCK_OVERHEAD / 4)
 
 /* Connection state machine flags. */
 union ble_ll_conn_sm_flags {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/include/controller/ble_ll_ctrl.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_ctrl.h b/net/nimble/controller/include/controller/ble_ll_ctrl.h
index ecd1541..5b149f6 100644
--- a/net/nimble/controller/include/controller/ble_ll_ctrl.h
+++ b/net/nimble/controller/include/controller/ble_ll_ctrl.h
@@ -76,6 +76,7 @@ extern const uint8_t g_ble_ll_ctrl_pkt_lengths[BLE_LL_CTRL_OPCODES];
 
 /* Maximum # of payload bytes in a LL control PDU */
 #define BLE_LL_CTRL_MAX_PAYLOAD         (26)
+#define BLE_LL_CTRL_MAX_PDU_LEN         (27)
 
 /* LL control connection update request */
 struct ble_ll_conn_upd_req

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 788d8d5..65f6037 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2402,7 +2402,7 @@ ble_ll_conn_module_init(void)
         /* Initialize empty pdu */
         m = (struct os_mbuf *)&connsm->conn_empty_pdu;
         m->om_data = (uint8_t *)&connsm->conn_empty_pdu[0];
-        m->om_data += BLE_MBUF_PKT_OVERHEAD;
+        m->om_data += BLE_MBUF_MEMBLOCK_OVERHEAD;
         m->om_pkthdr_len = sizeof(struct ble_mbuf_hdr) + 
             sizeof(struct os_mbuf_pkthdr);
         m->om_omp = NULL;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index 5f7e802..038dac3 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -584,7 +584,8 @@ ble_ll_conn_hci_param_reply(uint8_t *cmdbuf, int positive_reply)
     if (connsm->csmflags.cfbit.awaiting_host_reply) {
         /* Get a control packet buffer */
         if (positive_reply && (rc == BLE_ERR_SUCCESS)) {
-            om = os_mbuf_get_pkthdr(&g_mbuf_pool, sizeof(struct ble_mbuf_hdr));
+            om = os_msys_get_pkthdr(BLE_LL_CTRL_MAX_PAYLOAD + 1, 
+                                    sizeof(struct ble_mbuf_hdr));
             if (om) {
                 dptr = om->om_data;
                 rsp_opcode = ble_ll_ctrl_conn_param_reply(connsm, dptr, 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index 43238d4..099c6c3 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -750,7 +750,7 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc)
     struct os_mbuf *om;
 
     /* Get an mbuf for the control pdu */
-    om = os_mbuf_get_pkthdr(&g_mbuf_pool, sizeof(struct ble_mbuf_hdr));
+    om = os_msys_get_pkthdr(BLE_LL_CTRL_MAX_PDU_LEN, sizeof(struct ble_mbuf_hdr));
 
     if (om) {
         dptr = om->om_data;
@@ -1203,7 +1203,8 @@ ble_ll_ctrl_reject_ind_ext_send(struct ble_ll_conn_sm *connsm,
     uint8_t *rspbuf;
     struct os_mbuf *om;
 
-    om = os_mbuf_get_pkthdr(&g_mbuf_pool, sizeof(struct ble_mbuf_hdr));
+    om = os_msys_get_pkthdr(BLE_LL_CTRL_MAX_PDU_LEN,
+                            sizeof(struct ble_mbuf_hdr));
     if (om) {
         rspbuf = om->om_data;
         rspbuf[0] = BLE_LL_CTRL_REJECT_IND_EXT;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index bcb9ff5..9895672 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -30,9 +30,10 @@ extern struct os_mempool g_hci_os_event_pool;
  * 
  * The BLE mbuf structure is as follows. Note that this structure applies to
  * the packet header mbuf (not mbufs that are part of a "packet chain"):
- *      struct os_mbuf          (12)
+ *      struct os_mbuf          (16)
  *      struct os_mbuf_pkthdr   (8)
- *      struct ble_mbuf_hdr     (4)
+ *      struct ble_mbuf_hdr     (8)
+ *      Data buffer             (BLE_MBUF_PAYLOAD_SIZE)
  * 
  * The BLE mbuf header contains the following:
  *  flags: bitfield with the following values
@@ -68,6 +69,9 @@ struct ble_mbuf_hdr
     uint32_t end_cputime;
 };
 
+/* The payload size for BLE MBUFs. */
+#define BLE_MBUF_PAYLOAD_SIZE           (256)
+
 /* Flag definitions for rxinfo  */
 #define BLE_MBUF_HDR_F_CRC_OK           (0x80)
 #define BLE_MBUF_HDR_F_DEVMATCH         (0x40)
@@ -90,9 +94,11 @@ struct ble_mbuf_hdr
                             sizeof(struct os_mbuf_pkthdr))
 
 /* BLE mbuf overhead per packet header mbuf */
-#define BLE_MBUF_PKT_OVERHEAD   (sizeof(struct os_mbuf) +           \
-                                 sizeof(struct os_mbuf_pkthdr) +    \
-                                 sizeof(struct ble_mbuf_hdr))
+#define BLE_MBUF_PKTHDR_OVERHEAD    \
+    (sizeof(struct os_mbuf_pkthdr) + sizeof(struct ble_mbuf_hdr))
+
+#define BLE_MBUF_MEMBLOCK_OVERHEAD  \
+    (sizeof(struct os_mbuf) + BLE_MBUF_PKTHDR_OVERHEAD)
 
 /**
  * Get a BLE packet. A packet is a BLE packet header mbuf with enough 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4989659f/project/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/project/bletest/src/main.c b/project/bletest/src/main.c
index 3b90791..b294669 100755
--- a/project/bletest/src/main.c
+++ b/project/bletest/src/main.c
@@ -75,10 +75,8 @@ uint8_t g_host_adv_len;
 
 /* Create a mbuf pool of BLE mbufs */
 #define MBUF_NUM_MBUFS      (8)
-#define MBUF_BUF_SIZE       \
-    ((BLE_LL_CFG_ACL_DATA_PKT_LEN + sizeof(struct hci_data_hdr) + 3) & 0xFFFC)
-#define MBUF_MEMBLOCK_SIZE  (MBUF_BUF_SIZE + BLE_MBUF_PKT_OVERHEAD)
-
+#define MBUF_BUF_SIZE       OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#define MBUF_MEMBLOCK_SIZE  (MBUF_BUF_SIZE + BLE_MBUF_MEMBLOCK_OVERHEAD)
 #define MBUF_MEMPOOL_SIZE   OS_MEMPOOL_SIZE(MBUF_NUM_MBUFS, MBUF_MEMBLOCK_SIZE)
 
 struct os_mbuf_pool g_mbuf_pool; 
@@ -89,8 +87,8 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 #define BLETEST_ROLE_ADVERTISER         (0)
 #define BLETEST_ROLE_SCANNER            (1)
 #define BLETEST_ROLE_INITIATOR          (2)
-#define BLETEST_CFG_ROLE                (BLETEST_ROLE_INITIATOR)
-//#define BLETEST_CFG_ROLE                (BLETEST_ROLE_ADVERTISER)
+//#define BLETEST_CFG_ROLE                (BLETEST_ROLE_INITIATOR)
+#define BLETEST_CFG_ROLE                (BLETEST_ROLE_ADVERTISER)
 //#define BLETEST_CFG_ROLE                (BLETEST_ROLE_SCANNER)
 #define BLETEST_CFG_FILT_DUP_ADV        (0)
 #define BLETEST_CFG_ADV_ITVL            (60000 / BLE_HCI_ADV_ITVL)