Bluetooth: host: Add support for multiple advertising set

Add support for multiple advertising set. Move the advertising state
flags to be per advertising set and loop over advertising sets instead
of looking up legacy advertiser set or handle 0.

Since it is not certain that the advertising set terminated event can
arrive directly after the connection complete event there is currently
a limitation that there can only be one local identity used by
connectable advertisers at a time. This guarantees that we know
the local identity being used in the connection complete event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-04-18 18:30:12 +02:00 committed by Johan Hedberg
commit d4f22a8216
7 changed files with 403 additions and 317 deletions

View file

@ -434,7 +434,16 @@ enum {
/** LE Advertising Parameters. */ /** LE Advertising Parameters. */
struct bt_le_adv_param { struct bt_le_adv_param {
/** Local identity */ /** Local identity.
*
* @note When extended advertising :option:`CONFIG_BT_EXT_ADV` is not
* enabled or not supported by the controller it is not possible
* to scan and advertise simultaneously using two different
* random addresses.
*
* @note It is not possible to have multiple connectable advertising
* sets advertising simultaneously using different identities.
*/
u8_t id; u8_t id;
/** Advertising Set Identifier, valid range 0x00 - 0x0f. /** Advertising Set Identifier, valid range 0x00 - 0x0f.
@ -1038,7 +1047,7 @@ struct bt_le_oob {
* cases: * cases:
* - Creating a connection in progress, wait for the connected callback. * - Creating a connection in progress, wait for the connected callback.
* In addition when extended advertising :option:`CONFIG_BT_EXT_ADV` is * In addition when extended advertising :option:`CONFIG_BT_EXT_ADV` is
* not enabled or supported by the controller: * not enabled or not supported by the controller:
* - Advertiser is enabled using a Random Static Identity Address for a * - Advertiser is enabled using a Random Static Identity Address for a
* different local identity. * different local identity.
* - The local identity conflicts with the local identity used by other * - The local identity conflicts with the local identity used by other

View file

@ -622,8 +622,8 @@ struct bt_conn_cb {
* @ref bt_conn_le_create_param timeout parameter, which defaults to * @ref bt_conn_le_create_param timeout parameter, which defaults to
* :option:`CONFIG_BT_CREATE_CONN_TIMEOUT` seconds. * :option:`CONFIG_BT_CREATE_CONN_TIMEOUT` seconds.
* - @p BT_HCI_ERR_ADV_TIMEOUT High duty cycle directed connectable * - @p BT_HCI_ERR_ADV_TIMEOUT High duty cycle directed connectable
* advertiser started by @ref bt_le_adv_start or bt_le_ext_adv_start * advertiser started by @ref bt_le_adv_start failed to be connected
* failed to be connected within the timeout. * within the timeout.
*/ */
void (*connected)(struct bt_conn *conn, u8_t err); void (*connected)(struct bt_conn *conn, u8_t err);

View file

@ -126,7 +126,7 @@ config BT_EXT_ADV_LEGACY_SUPPORT
config BT_EXT_ADV_MAX_ADV_SET config BT_EXT_ADV_MAX_ADV_SET
int "Maximum number of simultaneous advertising sets" int "Maximum number of simultaneous advertising sets"
range 1 1 range 1 64
default 1 default 1
help help
Maximum number of simultaneous Bluetooth advertising sets Maximum number of simultaneous Bluetooth advertising sets

View file

@ -340,9 +340,7 @@ static void conn_update_timeout(struct k_work *work)
/* A new reference likely to have been released here, /* A new reference likely to have been released here,
* Resume advertising. * Resume advertising.
*/ */
if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) {
atomic_test_bit(bt_dev.flags, BT_DEV_KEEP_ADVERTISING) &&
!atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) {
bt_le_adv_resume(); bt_le_adv_resume();
} }
@ -1639,7 +1637,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
BT_DBG("%s -> %s", state2str(conn->state), state2str(state)); BT_DBG("%s -> %s", state2str(conn->state), state2str(state));
if (conn->state == state) { if (conn->state == state) {
BT_WARN("no transition"); BT_WARN("no transition %s", state2str(state));
return; return;
} }

File diff suppressed because it is too large Load diff

View file

@ -33,11 +33,6 @@ enum {
BT_DEV_HAS_PUB_KEY, BT_DEV_HAS_PUB_KEY,
BT_DEV_PUB_KEY_BUSY, BT_DEV_PUB_KEY_BUSY,
BT_DEV_ADVERTISING,
BT_DEV_ADVERTISING_NAME,
BT_DEV_ADVERTISING_CONNECTABLE,
BT_DEV_ADVERTISING_IDENTITY,
BT_DEV_KEEP_ADVERTISING,
BT_DEV_SCANNING, BT_DEV_SCANNING,
BT_DEV_EXPLICIT_SCAN, BT_DEV_EXPLICIT_SCAN,
BT_DEV_ACTIVE_SCAN, BT_DEV_ACTIVE_SCAN,
@ -84,6 +79,22 @@ enum {
* events, or both. * events, or both.
*/ */
BT_ADV_LIMITED, BT_ADV_LIMITED,
/* Advertiser set is currently advertising in the controller. */
BT_ADV_ENABLED,
/* Advertiser should include name in advertising data */
BT_ADV_INCLUDE_NAME,
/* Advertiser set is connectable */
BT_ADV_CONNECTABLE,
/* Advertiser set has disabled the use of private addresses and is using
* the identity address instead.
*/
BT_ADV_USE_IDENTITY,
/* Advertiser has been configured to keep advertising after a connection
* has been established as long as there are connections available.
*/
BT_ADV_PERSIST,
/* Advertiser has been temporarily disabled. */
BT_ADV_PAUSED,
BT_ADV_NUM_FLAGS, BT_ADV_NUM_FLAGS,
}; };
@ -167,6 +178,7 @@ struct bt_dev {
#endif #endif
/* Current local Random Address */ /* Current local Random Address */
bt_addr_le_t random_addr; bt_addr_le_t random_addr;
u8_t adv_conn_id;
/* Controller version & manufacturer information */ /* Controller version & manufacturer information */
u8_t hci_version; u8_t hci_version;

View file

@ -1045,6 +1045,7 @@ static int cmd_adv_start(const struct shell *shell, size_t argc, char *argv[])
int err; int err;
if (!adv) { if (!adv) {
shell_print(shell, "Advertiser[%d] not created", selected_adv);
return -EINVAL; return -EINVAL;
} }
@ -1091,6 +1092,7 @@ static int cmd_adv_stop(const struct shell *shell, size_t argc, char *argv[])
int err; int err;
if (!adv) { if (!adv) {
shell_print(shell, "Advertiser[%d] not created", selected_adv);
return -EINVAL; return -EINVAL;
} }
@ -1110,6 +1112,7 @@ static int cmd_adv_delete(const struct shell *shell, size_t argc, char *argv[])
int err; int err;
if (!adv) { if (!adv) {
shell_print(shell, "Advertiser[%d] not created", selected_adv);
return -EINVAL; return -EINVAL;
} }
@ -2296,7 +2299,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
"<type: discov, name, hex>", cmd_adv_data, "<type: discov, name, hex>", cmd_adv_data,
1, 16), 1, 16),
SHELL_CMD_ARG(adv-start, NULL, "[timeout] [num_events]", cmd_adv_start, SHELL_CMD_ARG(adv-start, NULL, "[timeout] [num_events]", cmd_adv_start,
1, 2), 1, 4),
SHELL_CMD_ARG(adv-stop, NULL, "", cmd_adv_stop, 1, 0), SHELL_CMD_ARG(adv-stop, NULL, "", cmd_adv_stop, 1, 0),
SHELL_CMD_ARG(adv-delete, NULL, "", cmd_adv_delete, 1, 0), SHELL_CMD_ARG(adv-delete, NULL, "", cmd_adv_delete, 1, 0),
SHELL_CMD_ARG(adv-select, NULL, "[adv]", cmd_adv_select, 1, 1), SHELL_CMD_ARG(adv-select, NULL, "[adv]", cmd_adv_select, 1, 1),