default 2
range 1 7
help
- BR/EDR ACL maximum connections of bluetooth controller.
+ BR/EDR ACL maximum connections of bluetooth controller.
Each connection uses 1.2KB static DRAM whenever the BT controller is enabled.
config BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN
help
For now this option needs "SMP_ENABLE" to be set to yes
-config BT_SSP_ENABLE
- bool "Enable Secure Simple Pairing"
- depends on CLASSIC_BT_ENABLED
- default CLASSIC_BT_ENABLED
-
config A2DP_ENABLE
bool "A2DP"
depends on CLASSIC_BT_ENABLED
depends on BLUEDROID_ENABLED
default n
help
- When scanning and scan duplicate is not enabled, if there are a lot of adv packets around or application layer
- handling adv packets is slow, it will cause the controller memory to run out. if enabled, adv packets will be
+ When scanning and scan duplicate is not enabled, if there are a lot of adv packets around or application layer
+ handling adv packets is slow, it will cause the controller memory to run out. if enabled, adv packets will be
lost when host queue is congested.
config SMP_ENABLE
return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
+esp_err_t esp_bt_gap_set_pin(esp_bt_pin_type_t pin_type, uint8_t pin_code_len, esp_bt_pin_code_t pin_code)
+{
+ btc_msg_t msg;
+ btc_gap_bt_args_t arg;
+
+ if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_GAP_BT;
+ msg.act = BTC_GAP_BT_ACT_SET_PIN_TYPE;
+ arg.set_pin_type.pin_type = pin_type;
+ if (pin_type == ESP_BT_PIN_TYPE_FIXED){
+ arg.set_pin_type.pin_code_len = pin_code_len;
+ memcpy(arg.set_pin_type.pin_code, pin_code, pin_code_len);
+ } else {
+ arg.set_pin_type.pin_code_len = 0;
+ memset(arg.set_pin_type.pin_code, 0, ESP_BT_PIN_CODE_LEN);
+ }
+
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), btc_gap_bt_arg_deep_copy)
+ == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
+esp_err_t esp_bt_gap_pin_reply(esp_bd_addr_t bd_addr, bool accept, uint8_t pin_code_len, esp_bt_pin_code_t pin_code)
+{
+ btc_msg_t msg;
+ btc_gap_bt_args_t arg;
+
+ if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
+ return ESP_ERR_INVALID_STATE;
+ }
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_GAP_BT;
+ msg.act = BTC_GAP_BT_ACT_PIN_REPLY;
+ arg.pin_reply.accept = accept;
+ arg.pin_reply.pin_code_len = pin_code_len;
+ memcpy(arg.pin_reply.bda.address, bd_addr, sizeof(esp_bd_addr_t));
+ memcpy(arg.pin_reply.pin_code, pin_code, pin_code_len);
+
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), btc_gap_bt_arg_deep_copy)
+ == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
#if (BT_SSP_INCLUDED == TRUE)
esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type,
void *value, uint8_t len)
ESP_BT_COD_SRVC_INFORMATION = 0x400, /*!< Information, e.g., WEB-server, WAP-server */
} esp_bt_cod_srvc_t;
+typedef enum{
+ ESP_BT_PIN_TYPE_VARIABLE = 0, /*!< Refer to BTM_PIN_TYPE_VARIABLE */
+ ESP_BT_PIN_TYPE_FIXED = 1, /*!< Refer to BTM_PIN_TYPE_FIXED */
+} esp_bt_pin_type_t;
+
+#define ESP_BT_PIN_CODE_LEN 16 /*!< Max pin code length */
+typedef uint8_t esp_bt_pin_code_t[ESP_BT_PIN_CODE_LEN]; /*!< Pin Code (upto 128 bits) MSB is 0 */
typedef enum {
ESP_BT_SP_IOCAP_MODE = 0, /*!< Set IO mode */
ESP_BT_GAP_RMT_SRVCS_EVT, /*!< get remote services event */
ESP_BT_GAP_RMT_SRVC_REC_EVT, /*!< get remote service record event */
ESP_BT_GAP_AUTH_CMPL_EVT, /*!< AUTH complete event */
+ ESP_BT_GAP_PIN_REQ_EVT, /*!< Legacy Pairing Pin code request */
ESP_BT_GAP_CFM_REQ_EVT, /*!< Simple Pairing User Confirmation request. */
ESP_BT_GAP_KEY_NOTIF_EVT, /*!< Simple Pairing Passkey Notification */
ESP_BT_GAP_KEY_REQ_EVT, /*!< Simple Pairing Passkey request */
uint8_t device_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; /*!< device name */
} auth_cmpl; /*!< authentication complete parameter struct */
+ /**
+ * @brief ESP_BT_GAP_PIN_REQ_EVT
+ */
+ struct pin_req_param {
+ esp_bd_addr_t bda; /*!< remote bluetooth device address*/
+ bool min_16_digit; /*!< TRUE if the pin returned must be at least 16 digits */
+ } pin_req; /*!< pin request parameter struct */
+
/**
* @brief ESP_BT_GAP_CFM_REQ_EVT
*/
*/
esp_err_t esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list);
+/**
+* @brief Set pin type and default pin code for legacy pairing.
+*
+* @param[in] pin_type: Use variable or fixed pin.
+* If pin_type is ESP_BT_PIN_TYPE_VARIABLE, pin_code and pin_code_len
+* will be ignored, and ESP_BT_GAP_PIN_REQ_EVT will come when control
+* requests for pin code.
+* Else, will use fixed pin code and not callback to users.
+* @param[in] pin_code_len: Length of pin_code
+* @param[in] pin_code: Pin_code
+*
+* @return - ESP_OK : success
+* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
+* - other : failed
+*/
+esp_err_t esp_bt_gap_set_pin(esp_bt_pin_type_t pin_type, uint8_t pin_code_len, esp_bt_pin_code_t pin_code);
+
+/**
+* @brief Reply the pin_code to the peer device for legacy pairing
+* when ESP_BT_GAP_PIN_REQ_EVT is coming.
+*
+* @param[in] bd_addr: BD address of the peer
+* @param[in] accept: Pin_code reply successful or declined.
+* @param[in] pin_code_len: Length of pin_code
+* @param[in] pin_code: Pin_code
+*
+* @return - ESP_OK : success
+* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
+* - other : failed
+*/
+esp_err_t esp_bt_gap_pin_reply(esp_bd_addr_t bd_addr, bool accept, uint8_t pin_code_len, esp_bt_pin_code_t pin_code);
+
#if (BT_SSP_INCLUDED == TRUE)
/**
* @brief Set a GAP security parameter value. Overrides the default value.
}
+/*******************************************************************************
+**
+** Function bta_dm_set_pin_type
+**
+** Description Set the pin type and fixed pin
+**
+**
+** Returns void
+**
+*******************************************************************************/
+void bta_dm_set_pin_type (tBTA_DM_MSG *p_data)
+{
+ BTM_SetPinType (p_data->set_pin_type.pin_type, p_data->set_pin_type.p_pin, p_data->set_pin_type.pin_len);
+}
+
/*******************************************************************************
**
** Function bta_dm_pin_reply
}
+/*******************************************************************************
+**
+** Function BTA_DMSetPinType
+**
+** Description This function set pin type as BTM_PIN_TYPE_FIXED or BTM_PIN_TYPE_VARIABLE
+**
+**
+** Returns void
+**
+*******************************************************************************/
+void BTA_DMSetPinType (UINT8 pin_type, UINT8 *pin_code, UINT8 pin_code_len)
+{
+ tBTA_DM_API_SET_PIN_TYPE *p_msg;
+
+ if ((p_msg = (tBTA_DM_API_SET_PIN_TYPE *) osi_malloc(sizeof(tBTA_DM_API_SET_PIN_TYPE))) != NULL) {
+ p_msg->hdr.event = BTA_DM_API_SET_PIN_TYPE_EVT;
+ p_msg->pin_type = pin_type;
+ p_msg->pin_len = pin_code_len;
+ memcpy(p_msg->p_pin, pin_code, pin_code_len);
+ bta_sys_sendmsg(p_msg);
+ }
+}
+
/*******************************************************************************
**
** Function BTA_DmPinReply
**
*******************************************************************************/
void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
-
{
tBTA_DM_API_PIN_REPLY *p_msg;
const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
/* device manager local device API events */
- bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */
- bta_dm_disable, /* 1 BTA_DM_API_DISABLE_EVT */
- bta_dm_set_dev_name, /* 2 BTA_DM_API_SET_NAME_EVT */
- bta_dm_set_visibility, /* 3 BTA_DM_API_SET_VISIBILITY_EVT */
- bta_dm_acl_change, /* 8 BTA_DM_ACL_CHANGE_EVT */
- bta_dm_add_device, /* 9 BTA_DM_API_ADD_DEVICE_EVT */
- bta_dm_close_acl, /* 10 BTA_DM_API_REMOVE_ACL_EVT */
+ bta_dm_enable, /* BTA_DM_API_ENABLE_EVT */
+ bta_dm_disable, /* BTA_DM_API_DISABLE_EVT */
+ bta_dm_set_dev_name, /* BTA_DM_API_SET_NAME_EVT */
+ bta_dm_set_visibility, /* BTA_DM_API_SET_VISIBILITY_EVT */
+ bta_dm_acl_change, /* BTA_DM_ACL_CHANGE_EVT */
+ bta_dm_add_device, /* BTA_DM_API_ADD_DEVICE_EVT */
+ bta_dm_close_acl, /* BTA_DM_API_REMOVE_ACL_EVT */
#if (SMP_INCLUDED == TRUE)
/* security API events */
- bta_dm_bond, /* 11 BTA_DM_API_BOND_EVT */
- bta_dm_bond_cancel, /* 12 BTA_DM_API_BOND_CANCEL_EVT */
- bta_dm_pin_reply, /* 13 BTA_DM_API_PIN_REPLY_EVT */
+ bta_dm_bond, /* BTA_DM_API_BOND_EVT */
+ bta_dm_bond_cancel, /* BTA_DM_API_BOND_CANCEL_EVT */
+ bta_dm_set_pin_type, /* BTA_DM_API_SET_PIN_TYPE_EVT */
+ bta_dm_pin_reply, /* BTA_DM_API_PIN_REPLY_EVT */
#endif ///SMP_INCLUDED == TRUE
#if (BTA_DM_PM_INCLUDED == TRUE)
/* power manger events */
- bta_dm_pm_btm_status, /* 16 BTA_DM_PM_BTM_STATUS_EVT */
- bta_dm_pm_timer, /* 17 BTA_DM_PM_TIMER_EVT*/
+ bta_dm_pm_btm_status, /* BTA_DM_PM_BTM_STATUS_EVT */
+ bta_dm_pm_timer, /* BTA_DM_PM_TIMER_EVT */
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
/* simple pairing events */
#if (SMP_INCLUDED == TRUE)
- bta_dm_confirm, /* 18 BTA_DM_API_CONFIRM_EVT */
+ bta_dm_confirm, /* BTA_DM_API_CONFIRM_EVT */
#if (BT_SSP_INCLUDED == TRUE)
- bta_dm_key_req, /* 19 BTA_DM_API_KEY_REQ_EVT */
+ bta_dm_key_req, /* BTA_DM_API_KEY_REQ_EVT */
#endif ///BT_SSP_INCLUDED == TRUE
bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */
#endif ///SMP_INCLUDED == TRUE
#if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
- bta_dm_loc_oob, /* 21 BTA_DM_API_LOC_OOB_EVT */
- bta_dm_ci_io_req_act, /* 22 BTA_DM_CI_IO_REQ_EVT */
- bta_dm_ci_rmt_oob_act, /* 23 BTA_DM_CI_RMT_OOB_EVT */
+ bta_dm_loc_oob, /* BTA_DM_API_LOC_OOB_EVT */
+ bta_dm_ci_io_req_act, /* BTA_DM_CI_IO_REQ_EVT */
+ bta_dm_ci_rmt_oob_act, /* BTA_DM_CI_RMT_OOB_EVT */
#endif /* BTM_OOB_INCLUDED */
#if BLE_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE
- bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
- bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
- bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
- bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
+ bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
+ bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_EVT */
+ bta_dm_ble_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
+ bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
bta_dm_security_grant,
#endif ///SMP_INCLUDED == TRUE
bta_dm_ble_set_bg_conn_type,
bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */
- bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/
+ bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT */
bta_dm_ble_scan, /* BTA_DM_API_BLE_SCAN_EVT */
bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
/* This handler function added by
Yulong at 2016/9/9 to support the
random address setting for the APP */
- bta_dm_ble_set_rand_address, /* BTA_DM_API_SET_RAND_ADDR_EVT*/
+ bta_dm_ble_set_rand_address, /* BTA_DM_API_SET_RAND_ADDR_EVT */
/* This handler function added by
Yulong at 2016/10/19 to support
stop the ble advertising setting
by the APP */
- bta_dm_ble_stop_advertising, /* BTA_DM_API_BLE_STOP_ADV_EVT*/
+ bta_dm_ble_stop_advertising, /* BTA_DM_API_BLE_STOP_ADV_EVT */
#if BLE_PRIVACY_SPT == TRUE
bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
#endif
bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */
bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */
#endif
- bta_dm_ble_multi_adv_enb, /* BTA_DM_API_BLE_MULTI_ADV_ENB_EVT*/
- bta_dm_ble_multi_adv_upd_param, /* BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT */
- bta_dm_ble_multi_adv_data, /* BTA_DM_API_BLE_MULTI_ADV_DATA_EVT */
- btm_dm_ble_multi_adv_disable, /* BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT */
+ bta_dm_ble_multi_adv_enb, /* BTA_DM_API_BLE_MULTI_ADV_ENB_EVT */
+ bta_dm_ble_multi_adv_upd_param, /* BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT */
+ bta_dm_ble_multi_adv_data, /* BTA_DM_API_BLE_MULTI_ADV_DATA_EVT */
+ btm_dm_ble_multi_adv_disable, /* BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT */
bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */
bta_dm_ble_enable_batch_scan, /* BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT */
bta_dm_ble_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */
bta_dm_ble_disconnect, /* BTA_DM_API_BLE_DISCONNECT_EVT */
#endif
- bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
- bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
- bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
+ bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_EVT */
+ bta_dm_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
+ bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_EVT */
bta_dm_remove_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */
/* security API events */
BTA_DM_API_BOND_EVT,
BTA_DM_API_BOND_CANCEL_EVT,
+ BTA_DM_API_SET_PIN_TYPE_EVT,
BTA_DM_API_PIN_REPLY_EVT,
#endif ///SMP_INCLUDED == TRUE
#if (BTA_DM_PM_INCLUDED == TRUE)
tBTA_TRANSPORT transport;
} tBTA_DM_API_BOND_CANCEL;
+/* data type for BTA_DM_API_SET_PIN_TYPE_EVT */
+typedef struct {
+ BT_HDR hdr;
+ UINT8 pin_type;
+ UINT8 pin_len;
+ UINT8 p_pin[PIN_CODE_LEN];
+} tBTA_DM_API_SET_PIN_TYPE;
+
/* data type for BTA_DM_API_PIN_REPLY_EVT */
typedef struct {
BT_HDR hdr;
tBTA_DM_API_BOND_CANCEL bond_cancel;
+ tBTA_DM_API_SET_PIN_TYPE set_pin_type;
tBTA_DM_API_PIN_REPLY pin_reply;
tBTA_DM_API_LOC_OOB loc_oob;
extern void bta_dm_vendor_spec_command(tBTA_DM_MSG *p_data);
extern void bta_dm_bond (tBTA_DM_MSG *p_data);
extern void bta_dm_bond_cancel (tBTA_DM_MSG *p_data);
+extern void bta_dm_set_pin_type (tBTA_DM_MSG *p_data);
extern void bta_dm_pin_reply (tBTA_DM_MSG *p_data);
extern void bta_dm_acl_change(tBTA_DM_MSG *p_data);
extern void bta_dm_add_device (tBTA_DM_MSG *p_data);
*******************************************************************************/
extern void BTA_DmBondCancel(BD_ADDR bd_addr);
+/*******************************************************************************
+**
+** Function BTA_DMSetPinType
+**
+** Description This function sets pin type as BTM_PIN_TYPE_FIXED or BTM_PIN_TYPE_VARIABLE
+**
+**
+** Returns void
+**
+*******************************************************************************/
+extern void BTA_DMSetPinType (UINT8 pin_type, UINT8 *pin_code, UINT8 pin_code_len);
+
/*******************************************************************************
**
** Function BTA_DmPinReply
static void btc_dm_save_ble_bonding_keys(void)
{
- if(!(pairing_cb.ble.is_penc_key_rcvd || pairing_cb.ble.is_pid_key_rcvd || pairing_cb.ble.is_pcsrk_key_rcvd ||
+ if (!(pairing_cb.ble.is_penc_key_rcvd || pairing_cb.ble.is_pid_key_rcvd || pairing_cb.ble.is_pcsrk_key_rcvd ||
pairing_cb.ble.is_lenc_key_rcvd || pairing_cb.ble.is_lcsrk_key_rcvd || pairing_cb.ble.is_lidk_key_rcvd)) {
return ;
}
status = BT_STATUS_FAIL;
}
}
-#if (BTC_GAP_BT_INCLUDED == TRUE && BT_SSP_INCLUDED == TRUE)
+#if (BTC_GAP_BT_INCLUDED == TRUE)
esp_bt_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
-#endif /// BTC_GAP_BT_INCLUDED == TRUE && BT_SSP_INCLUDED == TRUE
+#endif /// BTC_GAP_BT_INCLUDED == TRUE
(void) status;
}
+static void btc_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
+{
+#if (BTC_GAP_BT_INCLUDED == TRUE)
+ esp_bt_gap_cb_param_t param;
+ bt_status_t ret;
+ btc_msg_t msg;
+ msg.sig = BTC_SIG_API_CB;
+ msg.pid = BTC_PID_GAP_BT;
+ msg.act = BTC_GAP_BT_PIN_REQ_EVT;
+ param.pin_req.min_16_digit = p_pin_req->min_16_digit;
+ memcpy(param.pin_req.bda, p_pin_req->bd_addr, ESP_BD_ADDR_LEN);
+
+ ret = btc_transfer_context(&msg, ¶m,
+ sizeof(esp_bt_gap_cb_param_t), NULL);
+
+ if (ret != BT_STATUS_SUCCESS) {
+ BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
+ }
+#endif /// BTC_GAP_BT_INCLUDED == TRUE
+}
+
#if (BT_SSP_INCLUDED == TRUE)
static void btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_cfm_req)
{
+#if (BTC_GAP_BT_INCLUDED == TRUE)
if (p_cfm_req->just_works) {
// just work, not show to users.
BTA_DmConfirm(p_cfm_req->bd_addr, true);
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
-
+#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
static void btc_dm_sp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_key_notif)
{
+#if (BTC_GAP_BT_INCLUDED == TRUE)
esp_bt_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
-
+#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req)
{
+#if (BTC_GAP_BT_INCLUDED == TRUE)
esp_bt_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
}
+#endif /// BTC_GAP_BT_INCLUDED == TRUE
}
-#endif ///BT_SSP_INCLUDED == TRUE
-
+#endif /// BT_SSP_INCLUDED == TRUE
tBTA_SERVICE_MASK btc_get_enabled_services_mask(void)
{
}
case BTA_DM_PIN_REQ_EVT:
BTC_TRACE_DEBUG("BTA_DM_PIN_REQ_EVT");
+ btc_dm_pin_req_evt(&p_data->pin_req);
break;
case BTA_DM_AUTH_CMPL_EVT:
btc_dm_auth_cmpl_evt(&p_data->auth_cmpl);
return ESP_BT_STATUS_FAIL;
}
+static void btc_gap_bt_set_pin_type(btc_gap_bt_args_t *arg){
+ BTA_DMSetPinType (arg->set_pin_type.pin_type, arg->set_pin_type.pin_code, arg->set_pin_type.pin_code_len);
+}
+
+static void btc_gap_bt_pin_reply(btc_gap_bt_args_t *arg){
+ BTA_DmPinReply(arg->pin_reply.bda.address, arg->pin_reply.accept, arg->pin_reply.pin_code_len, arg->pin_reply.pin_code);
+}
+
#if (BT_SSP_INCLUDED == TRUE)
static esp_err_t btc_gap_bt_set_security_param(btc_gap_bt_args_t *arg)
{
case BTC_GAP_BT_ACT_SET_COD:
case BTC_GAP_BT_ACT_READ_RSSI_DELTA:
case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE:
+ case BTC_GAP_BT_ACT_PIN_REPLY:
+ case BTC_GAP_BT_ACT_SET_PIN_TYPE:
break;
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
case BTC_GAP_BT_ACT_SET_COD:
case BTC_GAP_BT_ACT_READ_RSSI_DELTA:
case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE:
+ case BTC_GAP_BT_ACT_PIN_REPLY:
+ case BTC_GAP_BT_ACT_SET_PIN_TYPE:
break;
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY:
btc_gap_bt_remove_bond_device(msg->arg);
break;
}
+ case BTC_GAP_BT_ACT_SET_PIN_TYPE:{
+ btc_gap_bt_set_pin_type(arg);
+ break;
+ }
+ case BTC_GAP_BT_ACT_PIN_REPLY: {
+ btc_gap_bt_pin_reply(arg);
+ break;
+ }
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_SET_SECURITY_PARAM:{
btc_gap_bt_set_security_param(arg);
osi_free(((tBTA_DM_SEARCH_PARAM *) (msg->arg)) ->p_data);
break;
case BTC_GAP_BT_READ_RSSI_DELTA_EVT:
-#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_AUTH_CMPL_EVT:
+ case BTC_GAP_BT_PIN_REQ_EVT:
+#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_CFM_REQ_EVT:
case BTC_GAP_BT_KEY_NOTIF_EVT:
case BTC_GAP_BT_KEY_REQ_EVT:
btc_gap_bt_cb_to_app(ESP_BT_GAP_READ_RSSI_DELTA_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
}
-#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_AUTH_CMPL_EVT:{
btc_gap_bt_cb_to_app(ESP_BT_GAP_AUTH_CMPL_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
}
+ case BTC_GAP_BT_PIN_REQ_EVT:{
+ btc_gap_bt_cb_to_app(ESP_BT_GAP_PIN_REQ_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
+ break;
+ }
+#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_CFM_REQ_EVT:{
btc_gap_bt_cb_to_app(ESP_BT_GAP_CFM_REQ_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break;
BTC_GAP_BT_SEARCH_SERVICES_EVT,
BTC_GAP_BT_SEARCH_SERVICE_RECORD_EVT,
BTC_GAP_BT_AUTH_CMPL_EVT,
+ BTC_GAP_BT_PIN_REQ_EVT,
BTC_GAP_BT_CFM_REQ_EVT,
BTC_GAP_BT_KEY_NOTIF_EVT,
BTC_GAP_BT_KEY_REQ_EVT,
BTC_GAP_BT_ACT_SET_COD,
BTC_GAP_BT_ACT_READ_RSSI_DELTA,
BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE,
+ BTC_GAP_BT_ACT_SET_PIN_TYPE,
+ BTC_GAP_BT_ACT_PIN_REPLY,
BTC_GAP_BT_ACT_SET_SECURITY_PARAM,
BTC_GAP_BT_ACT_PASSKEY_REPLY,
BTC_GAP_BT_ACT_CONFIRM_REPLY,
bt_bdaddr_t bda;
} rm_bond_device;
+ // BTC_GAP_BT_ACT_SET_PIN_TYPE
+ struct set_pin_type_args {
+ esp_bt_pin_type_t pin_type;
+ uint8_t pin_code_len;
+ esp_bt_pin_code_t pin_code;
+ } set_pin_type;
+
+ // BTC_GAP_BT_ACT_PIN_REPLY
+ struct pin_reply_args {
+ bt_bdaddr_t bda;
+ bool accept;
+ uint8_t pin_code_len;
+ esp_bt_pin_code_t pin_code;
+ } pin_reply;
+
// BTC_GAP_BT_ACT_SET_SECURITY_PARAM
struct set_sec_param_args {
esp_bt_sp_param_t param_type;
#define BTA_SDP_INCLUDED TRUE
#define BTA_DM_PM_INCLUDED TRUE
#define SDP_INCLUDED TRUE
+#define BT_SSP_INCLUDED TRUE
#if CONFIG_A2DP_ENABLE
#define BTA_AR_INCLUDED TRUE
#define BLE_PRIVACY_SPT FALSE
#endif /* CONFIG_SMP_ENABLE */
-#if (CONFIG_BT_SSP_ENABLE)
-#define BT_SSP_INCLUDED TRUE
-#else
-#define BT_SSP_INCLUDED FALSE
-#endif /* CONFIG_BT_SSP_ENABLE */
-
#if (CONFIG_BT_ACL_CONNECTIONS)
#define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS
#define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS
/* Bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use fixed pin code
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_set_pin(pin_type, 4, pin_code);
}
void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event) {
-#ifdef CONFIG_BT_SSP_ENABLE
- case ESP_BT_GAP_AUTH_CMPL_EVT:{
+ case ESP_BT_GAP_AUTH_CMPL_EVT: {
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(BT_AV_TAG, "authentication success: %s", param->auth_cmpl.device_name);
esp_log_buffer_hex(BT_AV_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break;
-#endif ///CONFIG_BT_SSP_ENABLE
default: {
ESP_LOGI(BT_AV_TAG, "event: %d", event);
break;
/* Bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use variable pin, input pin code when pairing
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
+ esp_bt_pin_code_t pin_code;
+ esp_bt_gap_set_pin(pin_type, 0, pin_code);
}
static bool get_name_from_eir(uint8_t *eir, uint8_t *bdname, uint8_t *bdname_len)
case ESP_BT_GAP_RMT_SRVCS_EVT:
case ESP_BT_GAP_RMT_SRVC_REC_EVT:
break;
-#ifdef CONFIG_BT_SSP_ENABLE
case ESP_BT_GAP_AUTH_CMPL_EVT: {
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(BT_AV_TAG, "authentication success: %s", param->auth_cmpl.device_name);
}
break;
}
+ case ESP_BT_GAP_PIN_REQ_EVT: {
+ ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
+ if (param->pin_req.min_16_digit) {
+ ESP_LOGI(BT_AV_TAG, "Input pin code: 0000 0000 0000 0000");
+ esp_bt_pin_code_t pin_code = {0};
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
+ } else {
+ ESP_LOGI(BT_AV_TAG, "Input pin code: 1234");
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
+ }
+ break;
+ }
case ESP_BT_GAP_CFM_REQ_EVT:
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break;
-#endif ///CONFIG_BT_SSP_ENABLE
default: {
ESP_LOGI(BT_AV_TAG, "event: %d", event);
break;
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event) {
-#ifdef CONFIG_BT_SSP_ENABLE
case ESP_BT_GAP_AUTH_CMPL_EVT:{
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
}
break;
}
+ case ESP_BT_GAP_PIN_REQ_EVT:{
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
+ if (param->pin_req.min_16_digit) {
+ ESP_LOGI(SPP_TAG, "Input pin code: 0000 0000 0000 0000");
+ esp_bt_pin_code_t pin_code = {0};
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
+ } else {
+ ESP_LOGI(SPP_TAG, "Input pin code: 1234");
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
+ }
+ break;
+ }
case ESP_BT_GAP_CFM_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break;
-#endif ///CONFIG_BT_SSP_ENABLE
default: {
ESP_LOGI(SPP_TAG, "event: %d", event);
break;
return;
}
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use variable pin, input pin code when pairing
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
+ esp_bt_pin_code_t pin_code;
+ esp_bt_gap_set_pin(pin_type, 0, pin_code);
}
static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch(event){
- case ESP_BT_GAP_DISC_RES_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_RES_EVT");
- esp_log_buffer_hex(SPP_TAG, param->disc_res.bda, ESP_BD_ADDR_LEN);
- for (int i = 0; i < param->disc_res.num_prop; i++){
- if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR
- && get_name_from_eir(param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)){
- esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
- if (strlen(remote_device_name) == peer_bdname_len
- && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
- memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
- esp_spp_start_discovery(peer_bd_addr);
- esp_bt_gap_cancel_discovery();
- }
+ case ESP_BT_GAP_DISC_RES_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_RES_EVT");
+ esp_log_buffer_hex(SPP_TAG, param->disc_res.bda, ESP_BD_ADDR_LEN);
+ for (int i = 0; i < param->disc_res.num_prop; i++){
+ if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR
+ && get_name_from_eir(param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)){
+ esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
+ if (strlen(remote_device_name) == peer_bdname_len
+ && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
+ memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
+ esp_spp_start_discovery(peer_bd_addr);
+ esp_bt_gap_cancel_discovery();
}
}
- break;
- case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
- break;
- case ESP_BT_GAP_RMT_SRVCS_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
- break;
- case ESP_BT_GAP_RMT_SRVC_REC_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
- break;
-#ifdef CONFIG_BT_SSP_ENABLE
- case ESP_BT_GAP_AUTH_CMPL_EVT:{
- if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
- ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
- esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
- } else {
- ESP_LOGE(SPP_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
- }
- break;
}
- case ESP_BT_GAP_CFM_REQ_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
- esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
- break;
- case ESP_BT_GAP_KEY_NOTIF_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
- break;
- case ESP_BT_GAP_KEY_REQ_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
- break;
-#endif ///CONFIG_BT_SSP_ENABLE
- default:
- break;
+ break;
+ case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
+ break;
+ case ESP_BT_GAP_RMT_SRVCS_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
+ break;
+ case ESP_BT_GAP_RMT_SRVC_REC_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
+ break;
+ case ESP_BT_GAP_AUTH_CMPL_EVT:{
+ if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
+ ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
+ esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
+ } else {
+ ESP_LOGE(SPP_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
+ }
+ break;
+ }
+ case ESP_BT_GAP_PIN_REQ_EVT:{
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
+ if (param->pin_req.min_16_digit) {
+ ESP_LOGI(SPP_TAG, "Input pin code: 0000 0000 0000 0000");
+ esp_bt_pin_code_t pin_code = {0};
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
+ } else {
+ ESP_LOGI(SPP_TAG, "Input pin code: 1234");
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
+ }
+ break;
+ }
+ case ESP_BT_GAP_CFM_REQ_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
+ esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
+ break;
+ case ESP_BT_GAP_KEY_NOTIF_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
+ break;
+ case ESP_BT_GAP_KEY_REQ_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
+ break;
+ default:
+ break;
}
}
return;
}
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use variable pin, input pin code when pairing
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
+ esp_bt_pin_code_t pin_code;
+ esp_bt_gap_set_pin(pin_type, 0, pin_code);
}
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event) {
-#ifdef CONFIG_BT_SSP_ENABLE
case ESP_BT_GAP_AUTH_CMPL_EVT:{
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
}
break;
}
+ case ESP_BT_GAP_PIN_REQ_EVT:{
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
+ if (param->pin_req.min_16_digit) {
+ ESP_LOGI(SPP_TAG, "Input pin code: 0000 0000 0000 0000");
+ esp_bt_pin_code_t pin_code = {0};
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
+ } else {
+ ESP_LOGI(SPP_TAG, "Input pin code: 1234");
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
+ }
+ break;
+ }
case ESP_BT_GAP_CFM_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break;
-#endif ///CONFIG_BT_SSP_ENABLE
default: {
ESP_LOGI(SPP_TAG, "event: %d", event);
break;
return;
}
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use variable pin, input pin code when pairing
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
+ esp_bt_pin_code_t pin_code;
+ esp_bt_gap_set_pin(pin_type, 0, pin_code);
}
static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch(event){
- case ESP_BT_GAP_DISC_RES_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_RES_EVT");
- esp_log_buffer_hex(SPP_TAG, param->disc_res.bda, ESP_BD_ADDR_LEN);
- for (int i = 0; i < param->disc_res.num_prop; i++){
- if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR
- && get_name_from_eir(param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)){
- esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
- if (strlen(remote_device_name) == peer_bdname_len
- && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
- memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
- esp_spp_start_discovery(peer_bd_addr);
- esp_bt_gap_cancel_discovery();
- }
+ case ESP_BT_GAP_DISC_RES_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_RES_EVT");
+ esp_log_buffer_hex(SPP_TAG, param->disc_res.bda, ESP_BD_ADDR_LEN);
+ for (int i = 0; i < param->disc_res.num_prop; i++){
+ if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR
+ && get_name_from_eir(param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)){
+ esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
+ if (strlen(remote_device_name) == peer_bdname_len
+ && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
+ memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
+ esp_spp_start_discovery(peer_bd_addr);
+ esp_bt_gap_cancel_discovery();
}
}
- break;
- case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
- break;
- case ESP_BT_GAP_RMT_SRVCS_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
- break;
- case ESP_BT_GAP_RMT_SRVC_REC_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
- break;
-#ifdef CONFIG_BT_SSP_ENABLE
- case ESP_BT_GAP_AUTH_CMPL_EVT:{
- if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
- ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
- esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
- } else {
- ESP_LOGE(SPP_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
- }
- break;
}
- case ESP_BT_GAP_CFM_REQ_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
- esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
- break;
- case ESP_BT_GAP_KEY_NOTIF_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
- break;
- case ESP_BT_GAP_KEY_REQ_EVT:
- ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
- break;
-#endif ///CONFIG_BT_SSP_ENABLE
- default:
- break;
+ break;
+ case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
+ break;
+ case ESP_BT_GAP_RMT_SRVCS_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
+ break;
+ case ESP_BT_GAP_RMT_SRVC_REC_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
+ break;
+ case ESP_BT_GAP_AUTH_CMPL_EVT:{
+ if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
+ ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
+ esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
+ } else {
+ ESP_LOGE(SPP_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
+ }
+ break;
+ }
+ case ESP_BT_GAP_PIN_REQ_EVT:{
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
+ if (param->pin_req.min_16_digit) {
+ ESP_LOGI(SPP_TAG, "Input pin code: 0000 0000 0000 0000");
+ esp_bt_pin_code_t pin_code = {0};
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
+ } else {
+ ESP_LOGI(SPP_TAG, "Input pin code: 1234");
+ esp_bt_pin_code_t pin_code;
+ pin_code[0] = '1';
+ pin_code[1] = '2';
+ pin_code[2] = '3';
+ pin_code[3] = '4';
+ esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
+ }
+ break;
+ }
+ case ESP_BT_GAP_CFM_REQ_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
+ esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
+ break;
+ case ESP_BT_GAP_KEY_NOTIF_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
+ break;
+ case ESP_BT_GAP_KEY_REQ_EVT:
+ ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
+ break;
+ default:
+ break;
}
}
return;
}
-#ifdef CONFIG_BT_SSP_ENABLE
+ /* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
-#endif ///CONFIG_BT_SSP_ENABLE
+
+ /*
+ * Set default parameters for Legacy Pairing
+ * Use variable pin, input pin code when pairing
+ */
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE;
+ esp_bt_pin_code_t pin_code;
+ esp_bt_gap_set_pin(pin_type, 0, pin_code);
}