Repository: incubator-mynewt-core Updated Branches: refs/heads/develop c4023a2f8 -> 0fc206fb9
MYNEWT-564 BLE Host - Allow byte buf for adv 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/0fc206fb Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0fc206fb Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0fc206fb Branch: refs/heads/develop Commit: 0fc206fb9d22dd7eb706b4ef0daeaf7f6823c494 Parents: c4023a2 Author: Christopher Collins <[email protected]> Authored: Wed Jan 25 19:05:08 2017 -0800 Committer: Christopher Collins <[email protected]> Committed: Wed Jan 25 19:05:08 2017 -0800 ---------------------------------------------------------------------- apps/blecent/src/misc.c | 4 +- apps/bleprph/src/main.c | 11 +- apps/bleprph_oic/src/main.c | 11 +- apps/blesplit/src/main.c | 11 +- apps/bletiny/src/cmd.c | 1 - apps/bletiny/src/main.c | 2 +- apps/bleuart/src/main.c | 11 +- apps/ocf_sample/src/ocf_ble.c | 11 +- net/nimble/host/include/host/ble_gap.h | 4 +- net/nimble/host/include/host/ble_hs_adv.h | 8 +- net/nimble/host/src/ble_gap.c | 249 +++++------- net/nimble/host/src/ble_gap_priv.h | 8 +- net/nimble/host/src/ble_hs_adv.c | 18 +- net/nimble/host/src/ble_hs_adv_priv.h | 2 - net/nimble/host/test/src/ble_gap_test.c | 55 +-- net/nimble/host/test/src/ble_hs_adv_test.c | 484 ++++++++++------------- net/nimble/host/test/src/ble_hs_conn_test.c | 2 +- net/nimble/host/test/src/ble_hs_test_util.c | 83 +++- net/nimble/host/test/src/ble_hs_test_util.h | 7 +- 19 files changed, 439 insertions(+), 543 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/blecent/src/misc.c ---------------------------------------------------------------------- diff --git a/apps/blecent/src/misc.c b/apps/blecent/src/misc.c index 18f723b..81abcae 100644 --- a/apps/blecent/src/misc.c +++ b/apps/blecent/src/misc.c @@ -103,12 +103,12 @@ print_conn_desc(const struct ble_gap_conn_desc *desc) void print_adv_fields(const struct ble_hs_adv_fields *fields) { - char s[BLE_HCI_MAX_ADV_DATA_LEN]; + char s[BLE_HS_ADV_MAX_SZ]; const uint8_t *u8p; ble_uuid_any_t uuid; int i; - if (fields->flags_is_present) { + if (fields->flags != 0) { BLECENT_LOG(DEBUG, " flags=0x%02x\n", fields->flags); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/bleprph/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c index 0153d36..962a345 100755 --- a/apps/bleprph/src/main.c +++ b/apps/bleprph/src/main.c @@ -94,14 +94,15 @@ bleprph_advertise(void) memset(&fields, 0, sizeof fields); - /* Indicate that the flags field should be included; specify a value of 0 - * to instruct the stack to fill the value in for us. + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). */ - fields.flags_is_present = 1; - fields.flags = 0; + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; /* Indicate that the TX power level field should be included; have the - * stack fill this one automatically as well. This is done by assiging the + * stack fill this value automatically. This is done by assiging the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. */ fields.tx_pwr_lvl_is_present = 1; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/bleprph_oic/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleprph_oic/src/main.c b/apps/bleprph_oic/src/main.c index 514584f..513c875 100755 --- a/apps/bleprph_oic/src/main.c +++ b/apps/bleprph_oic/src/main.c @@ -98,14 +98,15 @@ bleprph_advertise(void) memset(&fields, 0, sizeof fields); - /* Indicate that the flags field should be included; specify a value of 0 - * to instruct the stack to fill the value in for us. + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). */ - fields.flags_is_present = 1; - fields.flags = 0; + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; /* Indicate that the TX power level field should be included; have the - * stack fill this one automatically as well. This is done by assiging the + * stack fill this value automatically. This is done by assiging the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. */ fields.tx_pwr_lvl_is_present = 1; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/blesplit/src/main.c ---------------------------------------------------------------------- diff --git a/apps/blesplit/src/main.c b/apps/blesplit/src/main.c index 92a7cb8..4643e1c 100755 --- a/apps/blesplit/src/main.c +++ b/apps/blesplit/src/main.c @@ -94,14 +94,15 @@ blesplit_advertise(void) memset(&fields, 0, sizeof fields); - /* Indicate that the flags field should be included; specify a value of 0 - * to instruct the stack to fill the value in for us. + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). */ - fields.flags_is_present = 1; - fields.flags = 0; + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; /* Indicate that the TX power level field should be included; have the - * stack fill this one automatically as well. This is done by assiging the + * stack fill this value automatically. This is done by assiging the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. */ fields.tx_pwr_lvl_is_present = 1; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/bletiny/src/cmd.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c index 533d163..13eae4d 100644 --- a/apps/bletiny/src/cmd.c +++ b/apps/bletiny/src/cmd.c @@ -1927,7 +1927,6 @@ cmd_set_adv_data(void) tmp = parse_arg_long_bounds("flags", 0, UINT8_MAX, &rc); if (rc == 0) { adv_fields.flags = tmp; - adv_fields.flags_is_present = 1; } else if (rc != ENOENT) { console_printf("invalid 'flags' parameter\n"); help_cmd_long_bounds("flags", 0, UINT8_MAX); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/bletiny/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c index 9403bfd..b0ed15d 100755 --- a/apps/bletiny/src/main.c +++ b/apps/bletiny/src/main.c @@ -124,7 +124,7 @@ bletiny_print_adv_fields(const struct ble_hs_adv_fields *fields) ble_uuid_any_t uuid; int i; - if (fields->flags_is_present) { + if (fields->flags != 0) { console_printf(" flags=0x%02x:\n", fields->flags); if (!(fields->flags & BLE_HS_ADV_F_DISC_LTD) && http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/bleuart/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c index 6147fcd..270bb70 100755 --- a/apps/bleuart/src/main.c +++ b/apps/bleuart/src/main.c @@ -75,14 +75,15 @@ bleuart_advertise(void) memset(&fields, 0, sizeof fields); - /* Indicate that the flags field should be included; specify a value of 0 - * to instruct the stack to fill the value in for us. + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). */ - fields.flags_is_present = 1; - fields.flags = 0; + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; /* Indicate that the TX power level field should be included; have the - * stack fill this one automatically as well. This is done by assiging the + * stack fill this value automatically. This is done by assiging the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. */ fields.tx_pwr_lvl_is_present = 1; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/apps/ocf_sample/src/ocf_ble.c ---------------------------------------------------------------------- diff --git a/apps/ocf_sample/src/ocf_ble.c b/apps/ocf_sample/src/ocf_ble.c index 6ae636b..21e015a 100644 --- a/apps/ocf_sample/src/ocf_ble.c +++ b/apps/ocf_sample/src/ocf_ble.c @@ -116,14 +116,15 @@ ocf_ble_advertise(void) memset(&fields, 0, sizeof fields); - /* Indicate that the flags field should be included; specify a value of 0 - * to instruct the stack to fill the value in for us. + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). */ - fields.flags_is_present = 1; - fields.flags = 0; + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; /* Indicate that the TX power level field should be included; have the - * stack fill this one automatically as well. This is done by assiging the + * stack fill this value automatically. This is done by assiging the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. */ fields.tx_pwr_lvl_is_present = 1; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/include/host/ble_gap.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h index e960975..f24c4e0 100644 --- a/net/nimble/host/include/host/ble_gap.h +++ b/net/nimble/host/include/host/ble_gap.h @@ -543,7 +543,9 @@ int ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type, ble_gap_event_fn *cb, void *cb_arg); int ble_gap_adv_stop(void); int ble_gap_adv_active(void); -int ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields); +int ble_gap_adv_set_data(const uint8_t *data, int data_len); +int ble_gap_adv_rsp_set_data(const uint8_t *data, int data_len); +int ble_gap_adv_set_fields(const struct ble_hs_adv_fields *rsp_fields); int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields); int ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms, const struct ble_gap_disc_params *disc_params, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/include/host/ble_hs_adv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_hs_adv.h b/net/nimble/host/include/host/ble_hs_adv.h index 024e708..3ea9a19 100644 --- a/net/nimble/host/include/host/ble_hs_adv.h +++ b/net/nimble/host/include/host/ble_hs_adv.h @@ -26,13 +26,14 @@ extern "C" { #endif +#define BLE_HS_ADV_MAX_SZ BLE_HCI_MAX_ADV_DATA_LEN + /** Max field payload size (account for 2-byte header). */ -#define BLE_HS_ADV_MAX_FIELD_SZ (BLE_HCI_MAX_ADV_DATA_LEN - 2) +#define BLE_HS_ADV_MAX_FIELD_SZ (BLE_HS_ADV_MAX_SZ - 2) struct ble_hs_adv_fields { /*** 0x01 - Flags. */ uint8_t flags; - unsigned flags_is_present:1; /*** 0x02,0x03 - 16-bit service class UUIDs. */ uint16_t *uuids16; @@ -178,6 +179,9 @@ struct ble_hs_adv_fields { #define BLE_HS_ADV_SVC_DATA_UUID128_MIN_LEN 16 +int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, + uint8_t *dst, uint8_t *dst_len, uint8_t max_len); + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/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 f36656a..8d46aa4 100644 --- a/net/nimble/host/src/ble_gap.c +++ b/net/nimble/host/src/ble_gap.c @@ -73,14 +73,6 @@ #define BLE_GAP_UPDATE_TIMEOUT (30 * OS_TICKS_PER_SEC) -/** - * The maximum amount of user data that can be put into the advertising data. - * The stack will automatically insert the flags field on its own if requested - * by the application, limiting the maximum amount of user data. - */ -#define BLE_GAP_ADV_DATA_LIMIT_FLAGS (BLE_HCI_MAX_ADV_DATA_LEN - 3) -#define BLE_GAP_ADV_DATA_LIMIT_NO_FLAGS BLE_HCI_MAX_ADV_DATA_LEN - #define BLE_GAP_MAX_UPDATE_ENTRIES 1 static const struct ble_gap_conn_params ble_gap_conn_params_dflt = { @@ -142,8 +134,6 @@ static bssnz_t struct { uint8_t rsp_data[BLE_HCI_MAX_ADV_DATA_LEN]; uint8_t adv_data_len; uint8_t rsp_data_len; - - unsigned adv_auto_flags:1; } ble_gap_slave; struct ble_gap_update_entry { @@ -185,10 +175,10 @@ STATS_NAME_START(ble_gap_stats) STATS_NAME(ble_gap_stats, adv_stop_fail) STATS_NAME(ble_gap_stats, adv_start) STATS_NAME(ble_gap_stats, adv_start_fail) - STATS_NAME(ble_gap_stats, adv_set_fields) - STATS_NAME(ble_gap_stats, adv_set_fields_fail) - STATS_NAME(ble_gap_stats, adv_rsp_set_fields) - STATS_NAME(ble_gap_stats, adv_rsp_set_fields_fail) + STATS_NAME(ble_gap_stats, adv_set_data) + STATS_NAME(ble_gap_stats, adv_set_data_fail) + STATS_NAME(ble_gap_stats, adv_rsp_set_data) + STATS_NAME(ble_gap_stats, adv_rsp_set_data_fail) STATS_NAME(ble_gap_stats, discover) STATS_NAME(ble_gap_stats, discover_fail) STATS_NAME(ble_gap_stats, initiate) @@ -1592,7 +1582,7 @@ done: ble_hs_unlock(); if (rc != 0) { - STATS_INC(ble_gap_stats, adv_set_fields_fail); + STATS_INC(ble_gap_stats, adv_set_data_fail); } return rc; @@ -1603,93 +1593,6 @@ done: *****************************************************************************/ static int -ble_gap_adv_rsp_data_tx(void) -{ - uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN]; - int rc; - - rc = ble_hs_hci_cmd_build_le_set_scan_rsp_data(ble_gap_slave.rsp_data, - ble_gap_slave.rsp_data_len, - buf, sizeof buf); - if (rc != 0) { - return rc; - } - - rc = ble_hs_hci_cmd_tx_empty_ack(buf); - if (rc != 0) { - return rc; - } - - return 0; -} - -static void -ble_gap_adv_data_set_flags(void) -{ - uint8_t flags; - int rc; - - /* Calculate the value of the flags field from the discoverable mode. */ - flags = 0; - switch (ble_gap_slave.disc_mode) { - case BLE_GAP_DISC_MODE_NON: - break; - - case BLE_GAP_DISC_MODE_LTD: - flags |= BLE_HS_ADV_F_DISC_LTD; - break; - - case BLE_GAP_DISC_MODE_GEN: - flags |= BLE_HS_ADV_F_DISC_GEN; - break; - - default: - BLE_HS_DBG_ASSERT(0); - break; - } - - flags |= BLE_HS_ADV_F_BREDR_UNSUP; - - if (flags != 0) { - rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &flags, - ble_gap_slave.adv_data, - &ble_gap_slave.adv_data_len, - BLE_HCI_MAX_ADV_DATA_LEN); - BLE_HS_DBG_ASSERT_EVAL(rc == 0); - } -} - -static int -ble_gap_adv_data_tx(void) -{ - uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN]; - int rc; - - /* Calculate the flags AD field if requested by application. Clear the - * auto flag after encoding the flags so that we don't get repeated flags - * fields on subsequent advertising procedures. - */ - if (ble_gap_slave.adv_auto_flags) { - ble_gap_adv_data_set_flags(); - ble_gap_slave.adv_auto_flags = 0; - } - - rc = ble_hs_hci_cmd_build_le_set_adv_data(ble_gap_slave.adv_data, - ble_gap_slave.adv_data_len, - buf, sizeof buf); - if (rc != 0) { - return rc; - } - - rc = ble_hs_hci_cmd_tx_empty_ack(buf); - if (rc != 0) { - return rc; - } - - return 0; -} - -static int ble_gap_adv_type(const struct ble_gap_adv_params *adv_params) { switch (adv_params->conn_mode) { @@ -1953,18 +1856,6 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type, goto done; } - if (adv_params->conn_mode != BLE_GAP_CONN_MODE_DIR) { - rc = ble_gap_adv_data_tx(); - if (rc != 0) { - goto done; - } - - rc = ble_gap_adv_rsp_data_tx(); - if (rc != 0) { - goto done; - } - } - ble_gap_slave.op = BLE_GAP_OP_S_ADV; rc = ble_gap_adv_enable_tx(1); @@ -1991,25 +1882,20 @@ done: /** * Configures the data to include in subsequent advertisements. * - * @param adv_fields Specifies the advertisement data. + * @param data Buffer containing the advertising data. + * @param data_len The size of the advertising data, in bytes. * * @return 0 on success; * BLE_HS_EBUSY if advertising is in progress; - * BLE_HS_EMSGSIZE if the specified data is too - * large to fit in an advertisement; * Other nonzero on failure. */ int -ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields) +ble_gap_adv_set_data(const uint8_t *data, int data_len) { -#if !NIMBLE_BLE_ADVERTISE - return BLE_HS_ENOTSUP; -#endif - - int max_sz; + uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN]; int rc; - STATS_INC(ble_gap_stats, adv_set_fields); + STATS_INC(ble_gap_stats, adv_set_data); ble_hs_lock(); @@ -2019,76 +1905,125 @@ ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields) goto done; } - /* If application has requested the stack to calculate the flags field - * automatically (flags == 0), there is less room for user data. - */ - if (adv_fields->flags_is_present && adv_fields->flags == 0) { - max_sz = BLE_GAP_ADV_DATA_LIMIT_FLAGS; - ble_gap_slave.adv_auto_flags = 1; - } else { - max_sz = BLE_GAP_ADV_DATA_LIMIT_NO_FLAGS; - ble_gap_slave.adv_auto_flags = 0; + rc = ble_hs_hci_cmd_build_le_set_adv_data(data, data_len, buf, sizeof buf); + if (rc != 0) { + return BLE_HS_HCI_ERR(rc); } - rc = ble_hs_adv_set_fields(adv_fields, ble_gap_slave.adv_data, - &ble_gap_slave.adv_data_len, max_sz); + rc = ble_hs_hci_cmd_tx_empty_ack(buf); if (rc != 0) { - goto done; + return rc; } + rc = 0; + done: ble_hs_unlock(); - - if (rc != 0) { - STATS_INC(ble_gap_stats, adv_set_fields_fail); - } return rc; } /** * Configures the data to include in subsequent scan responses. * - * @param adv_fields Specifies the scan response data. + * @param data Buffer containing the scan response data. + * @param data_len The size of the response data, in bytes. * * @return 0 on success; * BLE_HS_EBUSY if advertising is in progress; - * BLE_HS_EMSGSIZE if the specified data is too - * large to fit in an advertisement; * Other nonzero on failure. */ int -ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields) +ble_gap_adv_rsp_set_data(const uint8_t *data, int data_len) { -#if !NIMBLE_BLE_ADVERTISE - return BLE_HS_ENOTSUP; -#endif - + uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN]; int rc; - STATS_INC(ble_gap_stats, adv_rsp_set_fields); - ble_hs_lock(); - /* Don't allow response fields to be set while advertising is active. */ + /* Don't allow advertising fields to be set while advertising is active. */ if (ble_gap_slave.op != BLE_GAP_OP_NULL) { rc = BLE_HS_EBUSY; goto done; } - rc = ble_hs_adv_set_fields(rsp_fields, ble_gap_slave.rsp_data, - &ble_gap_slave.rsp_data_len, - BLE_HCI_MAX_ADV_DATA_LEN); + rc = ble_hs_hci_cmd_build_le_set_scan_rsp_data(data, data_len, + buf, sizeof buf); if (rc != 0) { - goto done; + return BLE_HS_HCI_ERR(rc); + } + + rc = ble_hs_hci_cmd_tx_empty_ack(buf); + if (rc != 0) { + return rc; } + rc = 0; + done: ble_hs_unlock(); + return rc; +} +/** + * Configures the fields to include in subsequent advertisements. This is a + * higher-level version of ble_gap_adv_set_data(). + * + * @param adv_fields Specifies the advertisement data. + * + * @return 0 on success; + * BLE_HS_EBUSY if advertising is in progress; + * BLE_HS_EMSGSIZE if the specified data is too + * large to fit in an advertisement; + * Other nonzero on failure. + */ +int +ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields) +{ + uint8_t buf[BLE_HS_ADV_MAX_SZ]; + uint8_t buf_sz; + int rc; + + rc = ble_hs_adv_set_fields(adv_fields, buf, &buf_sz, sizeof buf); if (rc != 0) { - STATS_INC(ble_gap_stats, adv_rsp_set_fields_fail); + return rc; } - return rc; + + rc = ble_gap_adv_set_data(buf, buf_sz); + if (rc != 0) { + return rc; + } + + return 0; +} + +/** + * Configures the fields to include in subsequent scan responses. This is a + * higher-level version of ble_gap_adv_rsp_set_data(). + * + * @param adv_fields Specifies the scan response data. + * + * @return 0 on success; + * BLE_HS_EBUSY if advertising is in progress; + * Other nonzero on failure. + */ +int +ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields) +{ + uint8_t buf[BLE_HS_ADV_MAX_SZ]; + uint8_t buf_sz; + int rc; + + rc = ble_hs_adv_set_fields(rsp_fields, buf, &buf_sz, sizeof buf); + if (rc != 0) { + return rc; + } + + rc = ble_gap_adv_rsp_set_data(buf, buf_sz); + if (rc != 0) { + return rc; + } + + return 0; } /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/src/ble_gap_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h index a1f7429..c67efe4 100644 --- a/net/nimble/host/src/ble_gap_priv.h +++ b/net/nimble/host/src/ble_gap_priv.h @@ -42,10 +42,10 @@ STATS_SECT_START(ble_gap_stats) STATS_SECT_ENTRY(adv_stop_fail) STATS_SECT_ENTRY(adv_start) STATS_SECT_ENTRY(adv_start_fail) - STATS_SECT_ENTRY(adv_set_fields) - STATS_SECT_ENTRY(adv_set_fields_fail) - STATS_SECT_ENTRY(adv_rsp_set_fields) - STATS_SECT_ENTRY(adv_rsp_set_fields_fail) + STATS_SECT_ENTRY(adv_set_data) + STATS_SECT_ENTRY(adv_set_data_fail) + STATS_SECT_ENTRY(adv_rsp_set_data) + STATS_SECT_ENTRY(adv_rsp_set_data_fail) STATS_SECT_ENTRY(discover) STATS_SECT_ENTRY(discover_fail) STATS_SECT_ENTRY(initiate) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/src/ble_hs_adv.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c index 729887f..09d4c53 100644 --- a/net/nimble/host/src/ble_hs_adv.c +++ b/net/nimble/host/src/ble_hs_adv.c @@ -108,7 +108,7 @@ ble_hs_adv_set_array32(uint8_t type, uint8_t num_elems, const uint32_t *elems, } /** - * Sets the significant part of the data in outgoing advertisements. + * Converts a high-level set of fields to a byte buffer. * * @return 0 on success; nonzero on failure. */ @@ -127,19 +127,14 @@ ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, *dst_len = 0; /*** 0x01 - Flags. */ - /* The application has three options concerning the flags field: - * 1. Don't include it in advertisements (!flags_is_present). - * 2. Explicitly specify the value (flags_is_present && flags != 0). - * 3. Let stack calculate the value (flags_is_present && flags == 0). - * - * For option 3, the calculation is delayed until advertising is enabled. - * The delay is necessary because the flags value depends on the type of - * advertising being performed which is not known at this time. + /* The application has two options concerning the flags field: + * 1. Don't include it in advertisements (flags == 0). + * 2. Explicitly specify the value (flags != 0). * * Note: The CSS prohibits advertising a flags value of 0, so this method - * of specifying option 2 vs. 3 is sound. + * of specifying option 1 vs. 2 is sound. */ - if (adv_fields->flags_is_present && adv_fields->flags != 0) { + if (adv_fields->flags != 0) { rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &adv_fields->flags, dst, dst_len, max_len); } @@ -432,7 +427,6 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields, return BLE_HS_EBADDATA; } adv_fields->flags = *data; - adv_fields->flags_is_present = 1; break; case BLE_HS_ADV_TYPE_INCOMP_UUIDS16: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/src/ble_hs_adv_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_adv_priv.h b/net/nimble/host/src/ble_hs_adv_priv.h index 052d20c..f913b09 100644 --- a/net/nimble/host/src/ble_hs_adv_priv.h +++ b/net/nimble/host/src/ble_hs_adv_priv.h @@ -26,8 +26,6 @@ extern "C" { int ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data, uint8_t *dst, uint8_t *dst_len, uint8_t max_len); -int ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, - uint8_t *dst, uint8_t *dst_len, uint8_t max_len); int ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields, uint8_t *src, uint8_t src_len); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/test/src/ble_gap_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_gap_test.c b/net/nimble/host/test/src/ble_gap_test.c index 7b3dd54..7aaebee 100644 --- a/net/nimble/host/test/src/ble_gap_test.c +++ b/net/nimble/host/test/src/ble_gap_test.c @@ -251,6 +251,7 @@ ble_gap_test_util_verify_tx_adv_data(void) /* Note: Content of message verified in ble_hs_adv_test.c. */ } +#if 0 static void ble_gap_test_util_verify_tx_rsp_data(void) { @@ -262,6 +263,7 @@ ble_gap_test_util_verify_tx_rsp_data(void) ¶m_len); (void)param; /* XXX: Verify other fields. */ } +#endif static void ble_gap_test_util_verify_tx_adv_enable(int enabled) @@ -631,7 +633,7 @@ TEST_CASE(ble_gap_test_case_disc_ltd_mismatch) .length_data = 0, .rssi = 0, .addr = { 1, 2, 3, 4, 5, 6 }, - .data = (uint8_t[BLE_HCI_MAX_ADV_DATA_LEN]){ + .data = (uint8_t[BLE_HS_ADV_MAX_SZ]){ 2, BLE_HS_ADV_TYPE_FLAGS, BLE_HS_ADV_F_DISC_GEN, @@ -1362,21 +1364,22 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type, cmd_idx = 0; - if (conn_mode != BLE_GAP_CONN_MODE_DIR) { - memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.tx_pwr_lvl_is_present = 1; - adv_fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; + memset(&adv_fields, 0, sizeof adv_fields); + adv_fields.tx_pwr_lvl_is_present = 1; + adv_fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; - hci_status = ble_hs_test_util_exp_hci_status(cmd_idx, cmd_fail_idx, - fail_status); - rc = ble_hs_test_util_adv_set_fields(&adv_fields, hci_status); - - if (adv_fields.tx_pwr_lvl_is_present && - adv_fields.tx_pwr_lvl == BLE_HS_ADV_TX_PWR_LVL_AUTO) { + rc = ble_hs_test_util_adv_set_fields(&adv_fields, cmd_fail_idx, + fail_status); + if (cmd_fail_idx < 2) { + hci_status = fail_status; + } else { + hci_status = 0; + } + TEST_ASSERT_FATAL(rc == BLE_HS_HCI_ERR(hci_status)); + cmd_idx += 2; - TEST_ASSERT_FATAL(rc == BLE_HS_HCI_ERR(hci_status)); - cmd_idx++; - } + if (rc == 0) { + ble_gap_test_util_verify_tx_adv_data(); } if (fail_status == 0 || cmd_fail_idx >= cmd_idx) { @@ -1386,6 +1389,7 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type, cmd_fail_idx - cmd_idx, fail_status); TEST_ASSERT(rc == BLE_HS_HCI_ERR(fail_status)); + cmd_idx++; } if (fail_status == 0 || cmd_fail_idx >= cmd_idx) { @@ -1394,20 +1398,6 @@ ble_gap_test_util_adv(uint8_t own_addr_type, uint8_t peer_addr_type, } cmd_idx++; - if (conn_mode != BLE_GAP_CONN_MODE_DIR) { - if (fail_status == 0 || cmd_fail_idx >= cmd_idx) { - /* Verify tx of set advertise data command. */ - ble_gap_test_util_verify_tx_adv_data(); - } - cmd_idx++; - - if (fail_status == 0 || cmd_fail_idx >= cmd_idx) { - /* Verify tx of set scan response data command. */ - ble_gap_test_util_verify_tx_rsp_data(); - } - cmd_idx++; - } - if (fail_status == 0 || cmd_fail_idx >= cmd_idx) { /* Verify tx of set advertise enable command. */ ble_gap_test_util_verify_tx_adv_enable(1); @@ -1625,20 +1615,13 @@ TEST_CASE(ble_gap_test_case_adv_ctlr_fail) TEST_CASE(ble_gap_test_case_adv_hci_fail) { uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 }; - int num_hci_cmds; int fail_idx; int d; int c; for (c = BLE_GAP_CONN_MODE_NON; c < BLE_GAP_CONN_MODE_MAX; c++) { - if (c == BLE_GAP_CONN_MODE_DIR) { - num_hci_cmds = 2; - } else { - num_hci_cmds = 5; - } - for (d = BLE_GAP_DISC_MODE_NON; d < BLE_GAP_DISC_MODE_MAX; d++) { - for (fail_idx = 0; fail_idx < num_hci_cmds; fail_idx++) { + for (fail_idx = 0; fail_idx < 4; fail_idx++) { ble_gap_test_util_adv(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC, peer_addr, c, d, 0, fail_idx, BLE_ERR_UNSUPPORTED); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/test/src/ble_hs_adv_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_hs_adv_test.c b/net/nimble/host/test/src/ble_hs_adv_test.c index 0a06374..b21f4b3 100644 --- a/net/nimble/host/test/src/ble_hs_adv_test.c +++ b/net/nimble/host/test/src/ble_hs_adv_test.c @@ -148,11 +148,15 @@ ble_hs_adv_test_misc_tx_and_verify_data( adv_params = ble_hs_test_util_adv_params; adv_params.disc_mode = disc_mode; - rc = ble_hs_test_util_adv_set_fields(adv_fields, 0); + rc = ble_hs_test_util_adv_set_fields(adv_fields, 0, 0); TEST_ASSERT_FATAL(rc == 0); + ble_hs_adv_test_misc_verify_tx_adv_data(test_adv_fields); - rc = ble_gap_adv_rsp_set_fields(rsp_fields); - TEST_ASSERT_FATAL(rc == 0); + if (test_rsp_fields != NULL) { + rc = ble_hs_test_util_adv_rsp_set_fields(rsp_fields, 0, 0); + TEST_ASSERT_FATAL(rc == 0); + ble_hs_adv_test_misc_verify_tx_rsp_data(test_rsp_fields); + } rc = ble_hs_test_util_adv_start(BLE_ADDR_TYPE_PUBLIC, 0, NULL, &adv_params, BLE_HS_FOREVER, NULL, NULL, 0, 0); @@ -161,9 +165,6 @@ ble_hs_adv_test_misc_tx_and_verify_data( /* Discard the adv-enable command. */ ble_hs_test_util_get_last_hci_tx(); - ble_hs_adv_test_misc_verify_tx_rsp_data(test_rsp_fields); - ble_hs_adv_test_misc_verify_tx_adv_data(test_adv_fields); - /* Ensure the same data gets sent on repeated advertise procedures. */ rc = ble_hs_test_util_adv_stop(0); TEST_ASSERT_FATAL(rc == 0); @@ -174,74 +175,6 @@ ble_hs_adv_test_misc_tx_and_verify_data( /* Discard the adv-enable command. */ ble_hs_test_util_get_last_hci_tx(); - - ble_hs_adv_test_misc_verify_tx_rsp_data(test_rsp_fields); - ble_hs_adv_test_misc_verify_tx_adv_data(test_adv_fields); -} - -TEST_CASE(ble_hs_adv_test_case_flags) -{ - struct ble_hs_adv_fields adv_fields; - struct ble_hs_adv_fields rsp_fields; - - memset(&adv_fields, 0, sizeof adv_fields); - memset(&rsp_fields, 0, sizeof rsp_fields); - - /* Default flags. */ - adv_fields.flags_is_present = 1; - adv_fields.tx_pwr_lvl_is_present = 1; - adv_fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; - ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, - &adv_fields, - (struct ble_hs_adv_test_field[]) { - { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, - .val_len = 1, - }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, - { 0 }, - }, &rsp_fields, NULL); - - /* Flags |= limited discoverable. */ - ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_LTD, &adv_fields, - (struct ble_hs_adv_test_field[]) { - { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, - .val_len = 1, - }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]) { - BLE_HS_ADV_F_DISC_LTD | BLE_HS_ADV_F_BREDR_UNSUP - }, - .val_len = 1, - }, - { 0 }, - }, &rsp_fields, NULL); - - /* Flags = general discoverable. */ - ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_GEN, &adv_fields, - (struct ble_hs_adv_test_field[]) { - { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, - .val_len = 1, - }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]) { - BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP - }, - .val_len = 1, - }, - { 0 }, - }, &rsp_fields, NULL); } TEST_CASE(ble_hs_adv_test_case_user) @@ -253,7 +186,7 @@ TEST_CASE(ble_hs_adv_test_case_user) /*** Complete 16-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; adv_fields.uuids16 = (uint16_t[]) { 0x0001, 0x1234, 0x54ab }; @@ -263,6 +196,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_COMP_UUIDS16, .val = (uint8_t[]) { 0x01, 0x00, 0x34, 0x12, 0xab, 0x54 }, .val_len = 6, @@ -272,17 +210,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Incomplete 16-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uuids16 = (uint16_t[]) { 0x0001, 0x1234, 0x54ab }; adv_fields.num_uuids16 = 3; @@ -291,6 +224,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_INCOMP_UUIDS16, .val = (uint8_t[]) { 0x01, 0x00, 0x34, 0x12, 0xab, 0x54 }, .val_len = 6, @@ -300,17 +238,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Complete 32-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uuids32 = (uint32_t[]) { 0x12345678, 0xabacadae }; adv_fields.num_uuids32 = 2; @@ -319,6 +252,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_COMP_UUIDS32, .val = (uint8_t[]) { 0x78,0x56,0x34,0x12,0xae,0xad,0xac,0xab }, .val_len = 8, @@ -328,17 +266,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Incomplete 32-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uuids32 = (uint32_t[]) { 0x12345678, 0xabacadae }; adv_fields.num_uuids32 = 2; @@ -347,6 +280,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_INCOMP_UUIDS32, .val = (uint8_t[]) { 0x78,0x56,0x34,0x12,0xae,0xad,0xac,0xab }, .val_len = 8, @@ -356,17 +294,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Complete 128-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uuids128 = (uint8_t[]) { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -378,6 +311,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_COMP_UUIDS128, .val = (uint8_t[]) { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -390,17 +328,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Incomplete 128-bit service class UUIDs. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uuids128 = (uint8_t[]) { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -412,6 +345,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_INCOMP_UUIDS128, .val = (uint8_t[]) { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -424,17 +362,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Complete name. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.name = (uint8_t *)"myname"; adv_fields.name_len = 6; @@ -443,6 +376,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_COMP_NAME, .val = (uint8_t*)"myname", .val_len = 6, @@ -452,17 +390,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Incomplete name. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.name = (uint8_t *)"myname"; adv_fields.name_len = 6; @@ -471,6 +404,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_INCOMP_NAME, .val = (uint8_t*)"myname", .val_len = 6, @@ -480,23 +418,23 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0 }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Class of device. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -506,23 +444,23 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3 }, .val_len = BLE_HS_ADV_DEVICE_CLASS_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** Slave interval range. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -532,17 +470,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4 }, .val_len = BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x16 - Service data - 16-bit UUID. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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; @@ -550,6 +483,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -559,17 +497,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4 }, .val_len = 4, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x17 - Public target address. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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; @@ -577,6 +510,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -586,17 +524,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 1,2,3,4,5,6, 6,5,4,3,2,1 }, .val_len = 2 * BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x19 - Appearance. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.appearance = 0x1234; adv_fields.appearance_is_present = 1; @@ -604,6 +537,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -613,17 +551,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0x34, 0x12 }, .val_len = BLE_HS_ADV_APPEARANCE_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x1a - Advertising interval. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.adv_itvl = 0x1234; adv_fields.adv_itvl_is_present = 1; @@ -631,6 +564,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -640,23 +578,23 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]){ 0x34, 0x12 }, .val_len = BLE_HS_ADV_ADV_ITVL_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x1b - LE bluetooth device address. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -666,17 +604,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4,5,6,7 }, .val_len = BLE_HS_ADV_LE_ADDR_LEN, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x1c - LE role. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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; @@ -684,6 +617,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -693,17 +631,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { BLE_HS_ADV_LE_ROLE_BOTH_PERIPH_PREF }, .val_len = 1, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x20 - Service data - 32-bit UUID. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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; @@ -711,6 +644,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -720,17 +658,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4,5 }, .val_len = 5, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x21 - Service data - 128-bit UUID. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; 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 }; @@ -739,6 +672,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -749,17 +687,12 @@ TEST_CASE(ble_hs_adv_test_case_user) 11,12,13,14,15,16,17,18 }, .val_len = 18, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0x24 - URI. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.uri = (uint8_t[]){ 1,2,3,4 }; adv_fields.uri_len = 4; @@ -767,6 +700,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -776,17 +714,12 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4 }, .val_len = 4, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); /*** 0xff - Manufacturer specific data. */ memset(&adv_fields, 0, sizeof adv_fields); - adv_fields.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; adv_fields.mfg_data = (uint8_t[]){ 1,2,3,4 }; adv_fields.mfg_data_len = 4; @@ -794,6 +727,11 @@ TEST_CASE(ble_hs_adv_test_case_user) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .val_len = 1, + }, + { .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, .val = (uint8_t[]){ 0 }, .val_len = 1, @@ -803,11 +741,6 @@ TEST_CASE(ble_hs_adv_test_case_user) .val = (uint8_t[]) { 1,2,3,4 }, .val_len = 4, }, - { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, - .val_len = 1, - }, { 0 }, }, &rsp_fields, NULL); } @@ -818,7 +751,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.flags_is_present = 1; + adv_fields.flags = BLE_HS_ADV_F_BREDR_UNSUP; adv_fields.tx_pwr_lvl_is_present = 1; /*** Complete 16-bit service class UUIDs. */ @@ -830,13 +763,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -860,13 +793,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -890,13 +823,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -920,13 +853,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -953,13 +886,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -989,13 +922,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1022,13 +955,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1052,13 +985,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1080,13 +1013,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1108,13 +1041,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1137,13 +1070,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1166,13 +1099,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1195,13 +1128,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1224,13 +1157,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1252,13 +1185,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1281,13 +1214,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1310,13 +1243,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1340,13 +1273,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1370,13 +1303,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1399,13 +1332,13 @@ TEST_CASE(ble_hs_adv_test_case_user_rsp) ble_hs_adv_test_misc_tx_and_verify_data(BLE_GAP_DISC_MODE_NON, &adv_fields, (struct ble_hs_adv_test_field[]) { { - .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, - .val = (uint8_t[]){ 0 }, + .type = BLE_HS_ADV_TYPE_FLAGS, + .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, .val_len = 1, }, { - .type = BLE_HS_ADV_TYPE_FLAGS, - .val = (uint8_t[]){ BLE_HS_ADV_F_BREDR_UNSUP }, + .type = BLE_HS_ADV_TYPE_TX_PWR_LVL, + .val = (uint8_t[]){ 0 }, .val_len = 1, }, { 0 }, @@ -1470,7 +1403,6 @@ TEST_SUITE(ble_hs_adv_test_suite) { tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL); - ble_hs_adv_test_case_flags(); ble_hs_adv_test_case_user(); ble_hs_adv_test_case_user_rsp(); ble_hs_adv_test_case_user_full_payload(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/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 a5fdba7..5563dde 100644 --- a/net/nimble/host/test/src/ble_hs_conn_test.c +++ b/net/nimble/host/test/src/ble_hs_conn_test.c @@ -162,7 +162,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success) /* Initiate advertising. */ memset(&adv_fields, 0, sizeof adv_fields); adv_fields.tx_pwr_lvl_is_present = 1; - rc = ble_gap_adv_set_fields(&adv_fields); + rc = ble_hs_test_util_adv_set_fields(&adv_fields, 0, 0); TEST_ASSERT_FATAL(rc == 0); adv_params = ble_hs_test_util_adv_params; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/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 919ec9b..2e8ecbc 100644 --- a/net/nimble/host/test/src/ble_hs_test_util.c +++ b/net/nimble/host/test/src/ble_hs_test_util.c @@ -689,23 +689,37 @@ ble_hs_test_util_verify_tx_rd_pwr(void) } int -ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields, - uint8_t hci_status) +ble_hs_test_util_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, + int cmd_fail_idx, uint8_t hci_status) { + struct ble_hs_test_util_phony_ack acks[3]; int auto_pwr; int rc; + int i; auto_pwr = adv_fields->tx_pwr_lvl_is_present && adv_fields->tx_pwr_lvl == BLE_HS_ADV_TX_PWR_LVL_AUTO; + i = 0; if (auto_pwr) { - ble_hs_test_util_set_ack_params( - ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, - BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), - hci_status, - ((uint8_t[1]){0}), 1); + acks[i] = (struct ble_hs_test_util_phony_ack) { + BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), + ble_hs_test_util_exp_hci_status(i, cmd_fail_idx, hci_status), + {0}, + 1, + }; + i++; } + acks[i] = (struct ble_hs_test_util_phony_ack) { + BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADV_DATA), + ble_hs_test_util_exp_hci_status(i, cmd_fail_idx, hci_status), + }; + i++; + + memset(acks + i, 0, sizeof acks[i]); + ble_hs_test_util_set_ack_seq(acks); + rc = ble_gap_adv_set_fields(adv_fields); if (rc == 0 && auto_pwr) { /* Verify tx of set advertising params command. */ @@ -716,6 +730,47 @@ ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields, } int +ble_hs_test_util_adv_rsp_set_fields(const struct ble_hs_adv_fields *adv_fields, + int cmd_fail_idx, uint8_t hci_status) +{ + struct ble_hs_test_util_phony_ack acks[3]; + int auto_pwr; + int rc; + int i; + + auto_pwr = adv_fields->tx_pwr_lvl_is_present && + adv_fields->tx_pwr_lvl == BLE_HS_ADV_TX_PWR_LVL_AUTO; + + i = 0; + if (auto_pwr) { + acks[i] = (struct ble_hs_test_util_phony_ack) { + BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), + ble_hs_test_util_exp_hci_status(i, cmd_fail_idx, hci_status), + {0}, + 1, + }; + i++; + } + + acks[i] = (struct ble_hs_test_util_phony_ack) { + BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA), + ble_hs_test_util_exp_hci_status(i, cmd_fail_idx, hci_status), + }; + i++; + + memset(acks + i, 0, sizeof acks[i]); + ble_hs_test_util_set_ack_seq(acks); + + rc = ble_gap_adv_rsp_set_fields(adv_fields); + if (rc == 0 && auto_pwr) { + /* Verify tx of set advertising params command. */ + ble_hs_test_util_verify_tx_rd_pwr(); + } + + return rc; +} + +int ble_hs_test_util_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type, const uint8_t *peer_addr, const struct ble_gap_adv_params *adv_params, @@ -735,20 +790,6 @@ ble_hs_test_util_adv_start(uint8_t own_addr_type, }; i++; - if (adv_params->conn_mode != BLE_GAP_CONN_MODE_DIR) { - acks[i] = (struct ble_hs_test_util_phony_ack) { - BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADV_DATA), - ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status), - }; - i++; - - acks[i] = (struct ble_hs_test_util_phony_ack) { - BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA), - ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status), - }; - i++; - } - acks[i] = (struct ble_hs_test_util_phony_ack) { BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADV_ENABLE), ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status), http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fc206fb/net/nimble/host/test/src/ble_hs_test_util.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_hs_test_util.h b/net/nimble/host/test/src/ble_hs_test_util.h index 8f3d94e..041bb4d 100644 --- a/net/nimble/host/test/src/ble_hs_test_util.h +++ b/net/nimble/host/test/src/ble_hs_test_util.h @@ -122,8 +122,11 @@ int ble_hs_test_util_disc(uint8_t own_addr_type, int32_t duration_ms, int ble_hs_test_util_disc_cancel(uint8_t ack_status); void ble_hs_test_util_verify_tx_disconnect(uint16_t handle, uint8_t reason); void ble_hs_test_util_verify_tx_create_conn(const struct hci_create_conn *exp); -int ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields, - uint8_t hci_status); +int ble_hs_test_util_adv_set_fields(const struct ble_hs_adv_fields *adv_fields, + int cmd_fail_idx, uint8_t hci_status); +int ble_hs_test_util_adv_rsp_set_fields( + const struct ble_hs_adv_fields *adv_fields, + int cmd_fail_idx, uint8_t hci_status); int ble_hs_test_util_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type, const uint8_t *peer_addr,
