mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Modify esp_bt_gap_set_scan_mode() to be able to set connection modes as well as discoverable modes
The current API is insufficient to allow the users to set different combinations of connection and discoverable mode Users should be able to choose the device modes independently: 1. Connectable- i. Non-connectable mode ii. Connectable mode 2. Discoverable- i. Non-discoverable mode ii. Limited discoverable mode iii. General discoverable mode
This commit is contained in:
parent
fa5bc5d58b
commit
d9ce0bb705
@ -37,7 +37,7 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
|
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode)
|
||||||
{
|
{
|
||||||
btc_msg_t msg;
|
btc_msg_t msg;
|
||||||
btc_gap_bt_args_t arg;
|
btc_gap_bt_args_t arg;
|
||||||
@ -49,7 +49,8 @@ esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
|
|||||||
msg.sig = BTC_SIG_API_CALL;
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
msg.pid = BTC_PID_GAP_BT;
|
msg.pid = BTC_PID_GAP_BT;
|
||||||
msg.act = BTC_GAP_BT_ACT_SET_SCAN_MODE;
|
msg.act = BTC_GAP_BT_ACT_SET_SCAN_MODE;
|
||||||
arg.set_scan_mode.mode = mode;
|
arg.set_scan_mode.c_mode = c_mode;
|
||||||
|
arg.set_scan_mode.d_mode = d_mode;
|
||||||
|
|
||||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,15 @@ typedef enum {
|
|||||||
|
|
||||||
/// Discoverability and Connectability mode
|
/// Discoverability and Connectability mode
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
|
ESP_BT_NON_CONNECTABLE, /*!< Non-connectable */
|
||||||
ESP_BT_SCAN_MODE_CONNECTABLE, /*!< Connectable but not discoverable */
|
ESP_BT_CONNECTABLE, /*!< Connectable */
|
||||||
ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE /*!< both discoverable and connectable */
|
} esp_bt_connection_mode_t;
|
||||||
} esp_bt_scan_mode_t;
|
|
||||||
|
typedef enum {
|
||||||
|
ESP_BT_NON_DISCOVERABLE, /*!< Non-discoverable */
|
||||||
|
ESP_BT_LIMITED_DISCOVERABLE, /*!< Limited Discoverable */
|
||||||
|
ESP_BT_GENERAL_DISCOVERABLE, /*!< General Discoverable */
|
||||||
|
} esp_bt_discovery_mode_t;
|
||||||
|
|
||||||
/// Bluetooth Device Property type
|
/// Bluetooth Device Property type
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -350,7 +355,8 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback);
|
|||||||
* @brief Set discoverability and connectability mode for legacy bluetooth. This function should
|
* @brief Set discoverability and connectability mode for legacy bluetooth. This function should
|
||||||
* be called after esp_bluedroid_enable() completes successfully
|
* be called after esp_bluedroid_enable() completes successfully
|
||||||
*
|
*
|
||||||
* @param[in] mode : one of the enums of bt_scan_mode_t
|
* @param[in] c_mode : one of the enums of esp_bt_connection_mode_t
|
||||||
|
* @param[in] d_mode : one of the enums of esp_bt_discovery_mode_t
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* - ESP_OK : Succeed
|
* - ESP_OK : Succeed
|
||||||
@ -358,7 +364,7 @@ esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback);
|
|||||||
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
|
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
|
||||||
* - ESP_FAIL: others
|
* - ESP_FAIL: others
|
||||||
*/
|
*/
|
||||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
|
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start device discovery. This function should be called after esp_bluedroid_enable() completes successfully.
|
* @brief Start device discovery. This function should be called after esp_bluedroid_enable() completes successfully.
|
||||||
|
@ -48,29 +48,35 @@ static inline void btc_gap_bt_cb_to_app(esp_bt_gap_cb_event_t event, esp_bt_gap_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btc_bt_set_scan_mode(esp_bt_scan_mode_t mode)
|
static void btc_bt_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode)
|
||||||
{
|
{
|
||||||
tBTA_DM_DISC disc_mode;
|
tBTA_DM_DISC disc_mode;
|
||||||
tBTA_DM_CONN conn_mode;
|
tBTA_DM_CONN conn_mode;
|
||||||
|
|
||||||
switch (mode) {
|
switch (c_mode) {
|
||||||
case ESP_BT_SCAN_MODE_NONE:
|
case ESP_BT_NON_CONNECTABLE:
|
||||||
disc_mode = BTA_DM_NON_DISC;
|
|
||||||
conn_mode = BTA_DM_NON_CONN;
|
conn_mode = BTA_DM_NON_CONN;
|
||||||
break;
|
break;
|
||||||
|
case ESP_BT_CONNECTABLE:
|
||||||
case ESP_BT_SCAN_MODE_CONNECTABLE:
|
|
||||||
disc_mode = BTA_DM_NON_DISC;
|
|
||||||
conn_mode = BTA_DM_CONN;
|
conn_mode = BTA_DM_CONN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
|
||||||
disc_mode = BTA_DM_GENERAL_DISC;
|
|
||||||
conn_mode = BTA_DM_CONN;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BTC_TRACE_WARNING("invalid scan mode (0x%x)", mode);
|
BTC_TRACE_WARNING("invalid connection mode (0x%x)", c_mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (d_mode) {
|
||||||
|
case ESP_BT_NON_DISCOVERABLE:
|
||||||
|
disc_mode = BTA_DM_NON_DISC;
|
||||||
|
break;
|
||||||
|
case ESP_BT_LIMITED_DISCOVERABLE:
|
||||||
|
disc_mode = BTA_DM_LIMITED_DISC;
|
||||||
|
break;
|
||||||
|
case ESP_BT_GENERAL_DISCOVERABLE:
|
||||||
|
disc_mode = BTA_DM_GENERAL_DISC;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BTC_TRACE_WARNING("invalid discovery mode (0x%x)", d_mode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,7 +767,7 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
|
|||||||
BTC_TRACE_DEBUG("%s act %d\n", __func__, msg->act);
|
BTC_TRACE_DEBUG("%s act %d\n", __func__, msg->act);
|
||||||
switch (msg->act) {
|
switch (msg->act) {
|
||||||
case BTC_GAP_BT_ACT_SET_SCAN_MODE: {
|
case BTC_GAP_BT_ACT_SET_SCAN_MODE: {
|
||||||
btc_bt_set_scan_mode(arg->set_scan_mode.mode);
|
btc_bt_set_scan_mode(arg->set_scan_mode.c_mode, arg->set_scan_mode.d_mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BTC_GAP_BT_ACT_START_DISCOVERY: {
|
case BTC_GAP_BT_ACT_START_DISCOVERY: {
|
||||||
|
@ -54,7 +54,8 @@ typedef enum {
|
|||||||
typedef union {
|
typedef union {
|
||||||
// BTC_BT_GAP_ACT_SET_SCAN_MODE,
|
// BTC_BT_GAP_ACT_SET_SCAN_MODE,
|
||||||
struct set_bt_scan_mode_args {
|
struct set_bt_scan_mode_args {
|
||||||
esp_bt_scan_mode_t mode;
|
esp_bt_connection_mode_t c_mode;
|
||||||
|
esp_bt_discovery_mode_t d_mode;
|
||||||
} set_scan_mode;
|
} set_scan_mode;
|
||||||
|
|
||||||
// BTC_GAP_BT_ACT_START_DISCOVERY
|
// BTC_GAP_BT_ACT_START_DISCOVERY
|
||||||
|
@ -618,7 +618,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
|||||||
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
||||||
|
|
||||||
/* set discoverable and connectable mode, wait to be connected */
|
/* set discoverable and connectable mode, wait to be connected */
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -100,9 +100,9 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
|
|||||||
ESP_LOGI(BT_AV_TAG, "A2DP connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
|
ESP_LOGI(BT_AV_TAG, "A2DP connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
|
||||||
s_a2d_conn_state_str[a2d->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
|
s_a2d_conn_state_str[a2d->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
|
||||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED){
|
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED){
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_NONE);
|
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
|||||||
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
|
||||||
|
|
||||||
/* set discoverable and connectable mode, wait to be connected */
|
/* set discoverable and connectable mode, wait to be connected */
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -328,7 +328,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
|||||||
esp_a2d_source_init();
|
esp_a2d_source_init();
|
||||||
|
|
||||||
/* set discoverable and connectable mode */
|
/* set discoverable and connectable mode */
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
|
||||||
/* start device discovery */
|
/* start device discovery */
|
||||||
ESP_LOGI(BT_AV_TAG, "Starting device discovery...");
|
ESP_LOGI(BT_AV_TAG, "Starting device discovery...");
|
||||||
@ -434,7 +434,7 @@ static void bt_app_av_state_connecting(uint16_t event, void *param)
|
|||||||
ESP_LOGI(BT_AV_TAG, "a2dp connected");
|
ESP_LOGI(BT_AV_TAG, "a2dp connected");
|
||||||
s_a2d_state = APP_AV_STATE_CONNECTED;
|
s_a2d_state = APP_AV_STATE_CONNECTED;
|
||||||
s_media_state = APP_AV_MEDIA_STATE_IDLE;
|
s_media_state = APP_AV_MEDIA_STATE_IDLE;
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_NONE);
|
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
|
||||||
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||||
}
|
}
|
||||||
@ -530,7 +530,7 @@ static void bt_app_av_state_connected(uint16_t event, void *param)
|
|||||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||||
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
||||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -564,7 +564,7 @@ static void bt_app_av_state_disconnecting(uint16_t event, void *param)
|
|||||||
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
|
||||||
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
|
||||||
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
s_a2d_state = APP_AV_STATE_UNCONNECTED;
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ void bt_app_gap_start_up(void)
|
|||||||
esp_bt_dev_set_device_name(dev_name);
|
esp_bt_dev_set_device_name(dev_name);
|
||||||
|
|
||||||
/* set discoverable and connectable mode, wait to be connected */
|
/* set discoverable and connectable mode, wait to be connected */
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
|
|
||||||
/* register GAP callback function */
|
/* register GAP callback function */
|
||||||
esp_bt_gap_register_callback(bt_app_gap_cb);
|
esp_bt_gap_register_callback(bt_app_gap_cb);
|
||||||
|
@ -57,7 +57,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
case ESP_SPP_INIT_EVT:
|
case ESP_SPP_INIT_EVT:
|
||||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
||||||
break;
|
break;
|
||||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||||
|
@ -104,7 +104,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
|||||||
case ESP_SPP_INIT_EVT:
|
case ESP_SPP_INIT_EVT:
|
||||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -76,7 +76,7 @@ static void esp_spp_cb(uint16_t e, void *p)
|
|||||||
case ESP_SPP_INIT_EVT:
|
case ESP_SPP_INIT_EVT:
|
||||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
esp_spp_start_srv(sec_mask,role_slave, 0, SPP_SERVER_NAME);
|
||||||
break;
|
break;
|
||||||
case ESP_SPP_DISCOVERY_COMP_EVT:
|
case ESP_SPP_DISCOVERY_COMP_EVT:
|
||||||
|
@ -114,7 +114,7 @@ static void esp_spp_cb(uint16_t e, void *p)
|
|||||||
case ESP_SPP_INIT_EVT:
|
case ESP_SPP_INIT_EVT:
|
||||||
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
|
||||||
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
|
||||||
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||||
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user