Repository: incubator-mynewt-larva Updated Branches: refs/heads/develop 1281bf352 -> 9e54d5f5e
Fix bug in PHY where it could overwrite the end of a mbuf. Remove global API to retrieve a ble mbuf 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/cf93bdc6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/cf93bdc6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/cf93bdc6 Branch: refs/heads/develop Commit: cf93bdc676779d5878248c53906e8f205e6639b5 Parents: 1281bf3 Author: wes3 <w...@micosa.io> Authored: Mon Feb 15 13:34:28 2016 -0800 Committer: wes3 <w...@micosa.io> Committed: Wed Feb 17 17:00:37 2016 -0800 ---------------------------------------------------------------------- net/nimble/controller/src/ble_ll_adv.c | 6 ++++-- net/nimble/controller/src/ble_ll_conn.c | 4 ++-- net/nimble/controller/src/ble_ll_scan.c | 3 ++- net/nimble/drivers/native/src/ble_phy.c | 2 +- net/nimble/drivers/nrf51/src/ble_phy.c | 2 +- net/nimble/drivers/nrf52/src/ble_phy.c | 7 ++++++- net/nimble/include/nimble/ble.h | 21 +++++---------------- project/bletest/src/main.c | 13 +++++++------ 8 files changed, 28 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/controller/src/ble_ll_adv.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c index 6c8c377..9ee2ffa 100644 --- a/net/nimble/controller/src/ble_ll_adv.c +++ b/net/nimble/controller/src/ble_ll_adv.c @@ -1321,11 +1321,13 @@ ble_ll_adv_init(void) advsm->adv_txdone_ev.ev_arg = advsm; /* Get an advertising mbuf (packet header) and attach to state machine */ - ble_get_packet(advsm->adv_pdu); + advsm->adv_pdu = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, + sizeof(struct ble_mbuf_hdr)); assert(advsm->adv_pdu != NULL); /* Get a scan response mbuf (packet header) and attach to state machine */ - ble_get_packet(advsm->scan_rsp_pdu); + advsm->scan_rsp_pdu = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, + sizeof(struct ble_mbuf_hdr)); assert(advsm->scan_rsp_pdu != NULL); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/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 aa47647..a1e2d03 100644 --- a/net/nimble/controller/src/ble_ll_conn.c +++ b/net/nimble/controller/src/ble_ll_conn.c @@ -100,7 +100,7 @@ extern int ble_hs_rx_data(struct os_mbuf *om); #define BLE_LL_CFG_CONN_TX_WIN_OFF (0) #define BLE_LL_CFG_CONN_MASTER_SCA (BLE_MASTER_SCA_51_75_PPM << 5) #define BLE_LL_CFG_CONN_OUR_SCA (60) /* in ppm */ -#define BLE_LL_CFG_CONN_INIT_SLOTS (4) +#define BLE_LL_CFG_CONN_INIT_SLOTS (2) /* We cannot have more than 254 connections given our current implementation */ #if (NIMBLE_OPT_MAX_CONNECTIONS >= 255) @@ -1889,7 +1889,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr) } if (acl_hdr == BLE_LL_LLID_CTRL) { - /* Process control frame! For now just free */ + /* Process control frame */ ++g_ble_ll_stats.rx_ctrl_pdus; ble_ll_ctrl_rx_pdu(connsm, rxpdu); } else { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/controller/src/ble_ll_scan.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c index ada4407..78320b8 100644 --- a/net/nimble/controller/src/ble_ll_scan.c +++ b/net/nimble/controller/src/ble_ll_scan.c @@ -1322,7 +1322,8 @@ ble_ll_scan_init(void) cputime_timer_init(&scansm->scan_timer, ble_ll_scan_timer_cb, scansm); /* Get a scan request mbuf (packet header) and attach to state machine */ - ble_get_packet(scansm->scan_req_pdu); + scansm->scan_req_pdu = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, + sizeof(struct ble_mbuf_hdr)); assert(scansm->scan_req_pdu != NULL); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/drivers/native/src/ble_phy.c ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/native/src/ble_phy.c b/net/nimble/drivers/native/src/ble_phy.c index f421a25..d96d5e2 100644 --- a/net/nimble/drivers/native/src/ble_phy.c +++ b/net/nimble/drivers/native/src/ble_phy.c @@ -107,7 +107,7 @@ ble_phy_rxpdu_get(void) m = g_ble_phy_data.rxpdu; if (m == NULL) { - ble_get_packet(m); + m = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, sizeof(struct ble_mbuf_hdr)); if (!m) { ++g_ble_phy_stats.no_bufs; } else { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/drivers/nrf51/src/ble_phy.c ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf51/src/ble_phy.c b/net/nimble/drivers/nrf51/src/ble_phy.c index dec1991..302bf5a 100644 --- a/net/nimble/drivers/nrf51/src/ble_phy.c +++ b/net/nimble/drivers/nrf51/src/ble_phy.c @@ -125,7 +125,7 @@ ble_phy_rxpdu_get(void) m = g_ble_phy_data.rxpdu; if (m == NULL) { - ble_get_packet(m); + m = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, sizeof(struct ble_mbuf_hdr)); if (!m) { ++g_ble_phy_stats.no_bufs; } else { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/drivers/nrf52/src/ble_phy.c ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c b/net/nimble/drivers/nrf52/src/ble_phy.c index 970dfb1..1f6e101 100644 --- a/net/nimble/drivers/nrf52/src/ble_phy.c +++ b/net/nimble/drivers/nrf52/src/ble_phy.c @@ -125,10 +125,15 @@ ble_phy_rxpdu_get(void) m = g_ble_phy_data.rxpdu; if (m == NULL) { - ble_get_packet(m); + m = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, sizeof(struct ble_mbuf_hdr)); if (!m) { ++g_ble_phy_stats.no_bufs; } else { + /* + * NOTE: we add two bytes to the data pointer as we will prepend + * two bytes if we hand this received pdu up to host. + */ + m->om_data += 2; g_ble_phy_data.rxpdu = m; } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/net/nimble/include/nimble/ble.h ---------------------------------------------------------------------- diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h index 25f9186..e9a1e93 100644 --- a/net/nimble/include/nimble/ble.h +++ b/net/nimble/include/nimble/ble.h @@ -71,8 +71,11 @@ struct ble_mbuf_hdr uint32_t end_cputime; }; -/* The payload size for BLE MBUFs. */ -#define BLE_MBUF_PAYLOAD_SIZE (256) +/* + * The payload size for BLE MBUFs. NOTE: this needs to accommodate a max size + * PHY pdu of 257 bytes. + */ +#define BLE_MBUF_PAYLOAD_SIZE (260) /* Flag definitions for rxinfo */ #define BLE_MBUF_HDR_F_CRC_OK (0x80) @@ -102,20 +105,6 @@ 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 - * leading space for ACL data header (4 bytes). - * - * - * @return struct os_mbuf * - */ -#define ble_get_packet(__om) do { \ - __om = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, sizeof(struct ble_mbuf_hdr)); \ - if (__om) { \ - __om->om_data += 4; \ - } \ -} while (0) - #define BLE_DEV_ADDR_LEN (6) extern uint8_t g_dev_addr[BLE_DEV_ADDR_LEN]; extern uint8_t g_random_addr[BLE_DEV_ADDR_LEN]; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/cf93bdc6/project/bletest/src/main.c ---------------------------------------------------------------------- diff --git a/project/bletest/src/main.c b/project/bletest/src/main.c index 1356878..6c24e64 100755 --- a/project/bletest/src/main.c +++ b/project/bletest/src/main.c @@ -93,8 +93,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) @@ -104,7 +104,7 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE]; #define BLETEST_CFG_SCAN_WINDOW (700000 / BLE_HCI_SCAN_ITVL) #define BLETEST_CFG_SCAN_TYPE (BLE_HCI_SCAN_TYPE_ACTIVE) #define BLETEST_CFG_SCAN_FILT_POLICY (BLE_HCI_SCAN_FILT_NO_WL) -#define BLETEST_CFG_CONN_ITVL (64) /* in 1.25 msec increments */ +#define BLETEST_CFG_CONN_ITVL (128) /* in 1.25 msec increments */ #define BLETEST_CFG_SLAVE_LATENCY (0) #define BLETEST_CFG_INIT_FILTER_POLICY (BLE_HCI_CONN_FILT_NO_WL) #define BLETEST_CFG_CONN_SPVN_TMO (1000) /* 20 seconds */ @@ -114,7 +114,7 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE]; /* BLETEST variables */ #undef BLETEST_ADV_PKT_NUM -#define BLETEST_PKT_SIZE (64) +#define BLETEST_PKT_SIZE (251) #define BLETEST_STACK_SIZE (256) uint32_t g_next_os_time; int g_bletest_state; @@ -445,7 +445,8 @@ bletest_get_packet(void) om = NULL; if (g_mbuf_pool.omp_pool->mp_num_free >= 5) { - ble_get_packet(om); + om = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, + sizeof(struct ble_mbuf_hdr)); } return om; } @@ -607,6 +608,7 @@ bletest_execute_advertiser(void) htole16(om->om_data + 4, pktlen); om->om_data[6] = 0; om->om_data[7] = 0; + om->om_len += 4; /* Fill with incrementing pattern (starting from 1) */ for (j = 0; j < pktlen; ++j) { @@ -614,7 +616,6 @@ bletest_execute_advertiser(void) } /* Add length */ - om->om_len += 4; OS_MBUF_PKTHDR(om)->omp_len = om->om_len; ble_hci_transport_host_acl_data_send(om);