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
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_gap_bt_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BT;
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);
}
/// Discoverability and Connectability mode
typedef enum {
- ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
- ESP_BT_SCAN_MODE_CONNECTABLE, /*!< Connectable but not discoverable */
- ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE /*!< both discoverable and connectable */
-} esp_bt_scan_mode_t;
+ ESP_BT_NON_CONNECTABLE, /*!< Non-connectable */
+ ESP_BT_CONNECTABLE, /*!< Connectable */
+} esp_bt_connection_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
typedef enum {
* @brief Set discoverability and connectability mode for legacy bluetooth. This function should
* 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
* - ESP_OK : Succeed
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - 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.
}
}
-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_CONN conn_mode;
- switch (mode) {
- case ESP_BT_SCAN_MODE_NONE:
- disc_mode = BTA_DM_NON_DISC;
+ switch (c_mode) {
+ case ESP_BT_NON_CONNECTABLE:
conn_mode = BTA_DM_NON_CONN;
break;
-
- case ESP_BT_SCAN_MODE_CONNECTABLE:
- disc_mode = BTA_DM_NON_DISC;
+ case ESP_BT_CONNECTABLE:
conn_mode = BTA_DM_CONN;
break;
+ default:
+ BTC_TRACE_WARNING("invalid connection mode (0x%x)", c_mode);
+ return;
+ }
- case ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+ 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;
- conn_mode = BTA_DM_CONN;
break;
-
default:
- BTC_TRACE_WARNING("invalid scan mode (0x%x)", mode);
+ BTC_TRACE_WARNING("invalid discovery mode (0x%x)", d_mode);
return;
}
BTC_TRACE_DEBUG("%s act %d\n", __func__, msg->act);
switch (msg->act) {
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;
}
case BTC_GAP_BT_ACT_START_DISCOVERY: {
typedef union {
// BTC_BT_GAP_ACT_SET_SCAN_MODE,
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;
// BTC_GAP_BT_ACT_START_DISCOVERY
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
/* 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;
}
default:
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]);
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){
- 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;
}
esp_avrc_ct_register_callback(bt_app_rc_ct_cb);
/* 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;
}
default:
esp_a2d_source_init();
/* 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 */
ESP_LOGI(BT_AV_TAG, "Starting device discovery...");
ESP_LOGI(BT_AV_TAG, "a2dp connected");
s_a2d_state = APP_AV_STATE_CONNECTED;
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) {
s_a2d_state = APP_AV_STATE_UNCONNECTED;
}
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
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;
}
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
ESP_LOGI(BT_AV_TAG, "a2dp disconnected");
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;
}
esp_bt_dev_set_device_name(dev_name);
/* 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 */
esp_bt_gap_register_callback(bt_app_gap_cb);
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
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);
break;
case ESP_SPP_DISCOVERY_COMP_EVT:
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
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);
break;
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
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);
break;
case ESP_SPP_DISCOVERY_COMP_EVT:
case ESP_SPP_INIT_EVT:
ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
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);
break;