You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/07 01:52:07 UTC
[2/4] incubator-mynewt-core git commit: MYNEWT-265 BLE - advertise
iBeacon
MYNEWT-265 BLE - advertise iBeacon
Only include AD tx-pwr field if requested. The iBeacon advertisement
format requires that undirected advertisements not include the
tx-power-level AD field. Prior to this change, this field was always
inserted into an undirected advertisement.
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/13747ab3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/13747ab3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/13747ab3
Branch: refs/heads/develop
Commit: 13747ab33342e7ccf050c1bff24703e1d653240f
Parents: 738c6e7
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Apr 5 20:31:02 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 6 16:50:17 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_gap.c | 39 ++++++++++++++++++-------
net/nimble/host/src/test/ble_hs_adv_test.c | 22 ++++++++++++++
2 files changed, 50 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13747ab3/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 4342103..750c1aa 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -75,10 +75,15 @@
/**
* The maximum amount of user data that can be put into the advertising data.
- * Six bytes are reserved at the end for the flags field and the transmit power
- * field.
+ * The stack may automatically insert some fields on its own, limiting the
+ * maximum amount of user data. The following fields are automatically
+ * inserted:
+ * o Flags (3 bytes)
+ * o Tx-power-level (3 bytes) - Only if the application specified a
+ * tx_pwr_llvl_present value of 1 in a call to ble_gap_set_adv_data().
*/
-#define BLE_GAP_ADV_DATA_LIMIT (BLE_HCI_MAX_ADV_DATA_LEN - 6)
+#define BLE_GAP_ADV_DATA_LIMIT_PWR (BLE_HCI_MAX_ADV_DATA_LEN - 6)
+#define BLE_GAP_ADV_DATA_LIMIT_NO_PWR (BLE_HCI_MAX_ADV_DATA_LEN - 3)
static const struct ble_gap_crt_params ble_gap_params_dflt = {
.scan_itvl = 0x0010,
@@ -154,6 +159,8 @@ static bssnz_t struct {
uint8_t adv_data_len;
uint8_t rsp_data_len;
int8_t tx_pwr_lvl;
+
+ unsigned adv_pwr_lvl:1;
} ble_gap_slave;
static bssnz_t struct {
@@ -1892,11 +1899,13 @@ ble_gap_adv_data_tx(void *arg)
}
/* Encode the transmit power AD field. */
- rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_TX_PWR_LVL, 1,
- &ble_gap_slave.tx_pwr_lvl,
- ble_gap_slave.adv_data,
- &adv_data_len, BLE_HCI_MAX_ADV_DATA_LEN);
- BLE_HS_DBG_ASSERT(rc == 0);
+ if (ble_gap_slave.adv_pwr_lvl) {
+ rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_TX_PWR_LVL, 1,
+ &ble_gap_slave.tx_pwr_lvl,
+ ble_gap_slave.adv_data,
+ &adv_data_len, BLE_HCI_MAX_ADV_DATA_LEN);
+ BLE_HS_DBG_ASSERT(rc == 0);
+ }
ble_hci_sched_set_ack_cb(ble_gap_adv_ack, NULL);
rc = host_hci_cmd_le_set_adv_data(ble_gap_slave.adv_data,
@@ -2156,14 +2165,22 @@ ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields)
return BLE_HS_ENOTSUP;
#endif
+ int max_sz;
int rc;
STATS_INC(ble_gap_stats, adv_set_fields);
+ if (adv_fields->tx_pwr_lvl_is_present) {
+ max_sz = BLE_GAP_ADV_DATA_LIMIT_PWR;
+ } else {
+ max_sz = BLE_GAP_ADV_DATA_LIMIT_NO_PWR;
+ }
+
rc = ble_hs_adv_set_fields(adv_fields, ble_gap_slave.adv_data,
- &ble_gap_slave.adv_data_len,
- BLE_GAP_ADV_DATA_LIMIT);
- if (rc != 0) {
+ &ble_gap_slave.adv_data_len, max_sz);
+ if (rc == 0) {
+ ble_gap_slave.adv_pwr_lvl = adv_fields->tx_pwr_lvl_is_present;
+ } else {
STATS_INC(ble_gap_stats, adv_set_fields_fail);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13747ab3/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 477afd6..b465fdf 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -176,6 +176,7 @@ TEST_CASE(ble_hs_adv_test_case_flags)
memset(&rsp_fields, 0, sizeof rsp_fields);
/* Default flags. */
+ adv_fields.tx_pwr_lvl_is_present = 1;
ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON,
&adv_fields,
(struct ble_hs_adv_test_field[]) {
@@ -236,6 +237,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Complete 16-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids16 = (uint16_t[]) { 0x0001, 0x1234, 0x54ab };
adv_fields.num_uuids16 = 3;
adv_fields.uuids16_is_complete = 1;
@@ -262,6 +264,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Incomplete 16-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids16 = (uint16_t[]) { 0x0001, 0x1234, 0x54ab };
adv_fields.num_uuids16 = 3;
adv_fields.uuids16_is_complete = 0;
@@ -288,6 +291,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Complete 32-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids32 = (uint32_t[]) { 0x12345678, 0xabacadae };
adv_fields.num_uuids32 = 2;
adv_fields.uuids32_is_complete = 1;
@@ -314,6 +318,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Incomplete 32-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids32 = (uint32_t[]) { 0x12345678, 0xabacadae };
adv_fields.num_uuids32 = 2;
adv_fields.uuids32_is_complete = 0;
@@ -340,6 +345,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Complete 128-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids128 = (uint8_t[]) {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
@@ -372,6 +378,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Incomplete 128-bit service class UUIDs. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uuids128 = (uint8_t[]) {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
@@ -404,6 +411,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Complete name. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.name = (uint8_t *)"myname";
adv_fields.name_len = 6;
adv_fields.name_is_complete = 1;
@@ -430,6 +438,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Incomplete name. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.name = (uint8_t *)"myname";
adv_fields.name_len = 6;
adv_fields.name_is_complete = 0;
@@ -456,6 +465,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Class of device. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.device_class = (uint8_t[]){ 1,2,3 };
ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields,
@@ -480,6 +490,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** Slave interval range. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.slave_itvl_range = (uint8_t[]){ 1,2,3,4 };
ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields,
@@ -504,6 +515,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x16 - Service data - 16-bit UUID. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.svc_data_uuid16 = (uint8_t[]){ 1,2,3,4 };
adv_fields.svc_data_uuid16_len = 4;
@@ -529,6 +541,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x17 - Public target address. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.public_tgt_addr = (uint8_t[]){ 1,2,3,4,5,6, 6,5,4,3,2,1 };
adv_fields.num_public_tgt_addrs = 2;
@@ -554,6 +567,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x19 - Appearance. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.appearance = 0x1234;
adv_fields.appearance_is_present = 1;
@@ -579,6 +593,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x1a - Advertising interval. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.adv_itvl = 0x1234;
adv_fields.adv_itvl_is_present = 1;
@@ -604,6 +619,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x1b - LE bluetooth device address. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.le_addr = (uint8_t[]){ 1,2,3,4,5,6,7 };
ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields,
@@ -628,6 +644,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x1c - LE role. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.le_role = BLE_HS_ADV_LE_ROLE_BOTH_PERIPH_PREF;
adv_fields.le_role_is_present = 1;
@@ -653,6 +670,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x20 - Service data - 32-bit UUID. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.svc_data_uuid32 = (uint8_t[]){ 1,2,3,4,5 };
adv_fields.svc_data_uuid32_len = 5;
@@ -678,6 +696,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x21 - Service data - 128-bit UUID. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.svc_data_uuid128 =
(uint8_t[]){ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 };
adv_fields.svc_data_uuid128_len = 18;
@@ -705,6 +724,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0x24 - URI. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.uri = (uint8_t[]){ 1,2,3,4 };
adv_fields.uri_len = 4;
@@ -730,6 +750,7 @@ TEST_CASE(ble_hs_adv_test_case_user)
/*** 0xff - Manufacturer specific data. */
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
adv_fields.mfg_data = (uint8_t[]){ 1,2,3,4 };
adv_fields.mfg_data_len = 4;
@@ -760,6 +781,7 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp)
struct ble_hs_adv_fields adv_fields;
memset(&adv_fields, 0, sizeof adv_fields);
+ adv_fields.tx_pwr_lvl_is_present = 1;
/*** Complete 16-bit service class UUIDs. */
memset(&rsp_fields, 0, sizeof rsp_fields);