Merge branch 'feature/btdm_legacy_paring' into 'master'

component/bt: Add Legacy Pairing

See merge request idf/esp-idf!3057
This commit is contained in:
Jiang Jiang Jian 2018-09-07 10:15:52 +08:00
commit 8484b9cfd3
18 changed files with 498 additions and 166 deletions

View file

@ -253,11 +253,6 @@ config CLASSIC_BT_ENABLED
help help
For now this option needs "SMP_ENABLE" to be set to yes 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 config A2DP_ENABLE
bool "A2DP" bool "A2DP"
depends on CLASSIC_BT_ENABLED depends on CLASSIC_BT_ENABLED

View file

@ -240,6 +240,52 @@ esp_err_t esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list)
return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); 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) #if (BT_SSP_INCLUDED == TRUE)
esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type, esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type,
void *value, uint8_t len) void *value, uint8_t len)

View file

@ -102,6 +102,13 @@ typedef enum {
ESP_BT_COD_SRVC_INFORMATION = 0x400, /*!< Information, e.g., WEB-server, WAP-server */ ESP_BT_COD_SRVC_INFORMATION = 0x400, /*!< Information, e.g., WEB-server, WAP-server */
} esp_bt_cod_srvc_t; } 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 { typedef enum {
ESP_BT_SP_IOCAP_MODE = 0, /*!< Set IO mode */ ESP_BT_SP_IOCAP_MODE = 0, /*!< Set IO mode */
@ -162,6 +169,7 @@ typedef enum {
ESP_BT_GAP_RMT_SRVCS_EVT, /*!< get remote services event */ 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_RMT_SRVC_REC_EVT, /*!< get remote service record event */
ESP_BT_GAP_AUTH_CMPL_EVT, /*!< AUTH complete 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_CFM_REQ_EVT, /*!< Simple Pairing User Confirmation request. */
ESP_BT_GAP_KEY_NOTIF_EVT, /*!< Simple Pairing Passkey Notification */ ESP_BT_GAP_KEY_NOTIF_EVT, /*!< Simple Pairing Passkey Notification */
ESP_BT_GAP_KEY_REQ_EVT, /*!< Simple Pairing Passkey request */ ESP_BT_GAP_KEY_REQ_EVT, /*!< Simple Pairing Passkey request */
@ -233,6 +241,14 @@ typedef union {
uint8_t device_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; /*!< device name */ uint8_t device_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1]; /*!< device name */
} auth_cmpl; /*!< authentication complete parameter struct */ } 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 * @brief ESP_BT_GAP_CFM_REQ_EVT
*/ */
@ -486,6 +502,38 @@ int esp_bt_gap_get_bond_device_num(void);
*/ */
esp_err_t esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list); 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) #if (BT_SSP_INCLUDED == TRUE)
/** /**
* @brief Set a GAP security parameter value. Overrides the default value. * @brief Set a GAP security parameter value. Overrides the default value.

View file

@ -974,6 +974,21 @@ void bta_dm_bond_cancel (tBTA_DM_MSG *p_data)
} }
/*******************************************************************************
**
** 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_dm_pin_reply

View file

@ -436,6 +436,29 @@ void BTA_DmBondCancel(BD_ADDR bd_addr)
} }
/*******************************************************************************
**
** 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 ** Function BTA_DmPinReply
@ -448,7 +471,6 @@ void BTA_DmBondCancel(BD_ADDR bd_addr)
** **
*******************************************************************************/ *******************************************************************************/
void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin) void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin)
{ {
tBTA_DM_API_PIN_REPLY *p_msg; tBTA_DM_API_PIN_REPLY *p_msg;

View file

@ -53,45 +53,46 @@ typedef void (*tBTA_DM_ACTION)(tBTA_DM_MSG *p_data);
const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
/* device manager local device API events */ /* device manager local device API events */
bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */ bta_dm_enable, /* BTA_DM_API_ENABLE_EVT */
bta_dm_disable, /* 1 BTA_DM_API_DISABLE_EVT */ bta_dm_disable, /* BTA_DM_API_DISABLE_EVT */
bta_dm_set_dev_name, /* 2 BTA_DM_API_SET_NAME_EVT */ bta_dm_set_dev_name, /* BTA_DM_API_SET_NAME_EVT */
bta_dm_set_visibility, /* 3 BTA_DM_API_SET_VISIBILITY_EVT */ bta_dm_set_visibility, /* BTA_DM_API_SET_VISIBILITY_EVT */
bta_dm_acl_change, /* 8 BTA_DM_ACL_CHANGE_EVT */ bta_dm_acl_change, /* BTA_DM_ACL_CHANGE_EVT */
bta_dm_add_device, /* 9 BTA_DM_API_ADD_DEVICE_EVT */ bta_dm_add_device, /* BTA_DM_API_ADD_DEVICE_EVT */
bta_dm_close_acl, /* 10 BTA_DM_API_REMOVE_ACL_EVT */ bta_dm_close_acl, /* BTA_DM_API_REMOVE_ACL_EVT */
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
/* security API events */ /* security API events */
bta_dm_bond, /* 11 BTA_DM_API_BOND_EVT */ bta_dm_bond, /* BTA_DM_API_BOND_EVT */
bta_dm_bond_cancel, /* 12 BTA_DM_API_BOND_CANCEL_EVT */ bta_dm_bond_cancel, /* BTA_DM_API_BOND_CANCEL_EVT */
bta_dm_pin_reply, /* 13 BTA_DM_API_PIN_REPLY_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 #endif ///SMP_INCLUDED == TRUE
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
/* power manger events */ /* power manger events */
bta_dm_pm_btm_status, /* 16 BTA_DM_PM_BTM_STATUS_EVT */ bta_dm_pm_btm_status, /* BTA_DM_PM_BTM_STATUS_EVT */
bta_dm_pm_timer, /* 17 BTA_DM_PM_TIMER_EVT*/ bta_dm_pm_timer, /* BTA_DM_PM_TIMER_EVT */
#endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */ #endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */
/* simple pairing events */ /* simple pairing events */
#if (SMP_INCLUDED == TRUE) #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) #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 #endif ///BT_SSP_INCLUDED == TRUE
bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */ bta_dm_set_encryption, /* BTA_DM_API_SET_ENCRYPTION_EVT */
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
#if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE) #if (BTM_OOB_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
bta_dm_loc_oob, /* 21 BTA_DM_API_LOC_OOB_EVT */ bta_dm_loc_oob, /* BTA_DM_API_LOC_OOB_EVT */
bta_dm_ci_io_req_act, /* 22 BTA_DM_CI_IO_REQ_EVT */ bta_dm_ci_io_req_act, /* BTA_DM_CI_IO_REQ_EVT */
bta_dm_ci_rmt_oob_act, /* 23 BTA_DM_CI_RMT_OOB_EVT */ bta_dm_ci_rmt_oob_act, /* BTA_DM_CI_RMT_OOB_EVT */
#endif /* BTM_OOB_INCLUDED */ #endif /* BTM_OOB_INCLUDED */
#if BLE_INCLUDED == TRUE #if BLE_INCLUDED == TRUE
#if SMP_INCLUDED == TRUE #if SMP_INCLUDED == TRUE
bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */ bta_dm_add_blekey, /* BTA_DM_API_ADD_BLEKEY_EVT */
bta_dm_add_ble_device, /* BTA_DM_API_ADD_BLEDEVICE_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_passkey_reply, /* BTA_DM_API_BLE_PASSKEY_REPLY_EVT */
bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */ bta_dm_ble_confirm_reply, /* BTA_DM_API_BLE_CONFIRM_REPLY_EVT */
bta_dm_security_grant, bta_dm_security_grant,
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
bta_dm_ble_set_bg_conn_type, bta_dm_ble_set_bg_conn_type,
@ -99,18 +100,18 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */ 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_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_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_scan, /* BTA_DM_API_BLE_SCAN_EVT */
bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */ bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */
/* This handler function added by /* This handler function added by
Yulong at 2016/9/9 to support the Yulong at 2016/9/9 to support the
random address setting for the APP */ 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 /* This handler function added by
Yulong at 2016/10/19 to support Yulong at 2016/10/19 to support
stop the ble advertising setting stop the ble advertising setting
by the APP */ 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 #if BLE_PRIVACY_SPT == TRUE
bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */
#endif #endif
@ -132,10 +133,10 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */ 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 */ bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */
#endif #endif
bta_dm_ble_multi_adv_enb, /* BTA_DM_API_BLE_MULTI_ADV_ENB_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_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 */ 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 */ 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_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_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_disable_batch_scan, /* BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT */
@ -145,9 +146,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_ble_disconnect, /* BTA_DM_API_BLE_DISCONNECT_EVT */ bta_dm_ble_disconnect, /* BTA_DM_API_BLE_DISCONNECT_EVT */
#endif #endif
bta_dm_enable_test_mode, /* BTA_DM_API_ENABLE_TEST_MODE_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_disable_test_mode, /* BTA_DM_API_DISABLE_TEST_MODE_EVT */
bta_dm_execute_callback, /* BTA_DM_API_EXECUTE_CBACK_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_all_acl, /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */ bta_dm_remove_device, /* BTA_DM_API_REMOVE_DEVICE_EVT */

View file

@ -61,6 +61,7 @@ enum {
/* security API events */ /* security API events */
BTA_DM_API_BOND_EVT, BTA_DM_API_BOND_EVT,
BTA_DM_API_BOND_CANCEL_EVT, BTA_DM_API_BOND_CANCEL_EVT,
BTA_DM_API_SET_PIN_TYPE_EVT,
BTA_DM_API_PIN_REPLY_EVT, BTA_DM_API_PIN_REPLY_EVT,
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
@ -273,6 +274,14 @@ typedef struct {
tBTA_TRANSPORT transport; tBTA_TRANSPORT transport;
} tBTA_DM_API_BOND_CANCEL; } 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 */ /* data type for BTA_DM_API_PIN_REPLY_EVT */
typedef struct { typedef struct {
BT_HDR hdr; BT_HDR hdr;
@ -754,6 +763,7 @@ typedef union {
tBTA_DM_API_BOND_CANCEL bond_cancel; 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_PIN_REPLY pin_reply;
tBTA_DM_API_LOC_OOB loc_oob; tBTA_DM_API_LOC_OOB loc_oob;
@ -1177,6 +1187,7 @@ extern void bta_dm_set_scan_config(tBTA_DM_MSG *p_data);
extern void bta_dm_vendor_spec_command(tBTA_DM_MSG *p_data); 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 (tBTA_DM_MSG *p_data);
extern void bta_dm_bond_cancel (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_pin_reply (tBTA_DM_MSG *p_data);
extern void bta_dm_acl_change(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_dm_add_device (tBTA_DM_MSG *p_data);

View file

@ -1570,6 +1570,18 @@ extern void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport);
*******************************************************************************/ *******************************************************************************/
extern void BTA_DmBondCancel(BD_ADDR bd_addr); 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 ** Function BTA_DmPinReply

View file

@ -182,7 +182,7 @@ static void btc_dm_remove_ble_bonding_keys(void)
static void btc_dm_save_ble_bonding_keys(void) 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)) { pairing_cb.ble.is_lenc_key_rcvd || pairing_cb.ble.is_lcsrk_key_rcvd || pairing_cb.ble.is_lidk_key_rcvd)) {
return ; return ;
} }
@ -357,7 +357,7 @@ static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
status = BT_STATUS_FAIL; 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; esp_bt_gap_cb_param_t param;
bt_status_t ret; bt_status_t ret;
btc_msg_t msg; btc_msg_t msg;
@ -375,13 +375,35 @@ static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); 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; (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, &param,
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) #if (BT_SSP_INCLUDED == TRUE)
static void btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_cfm_req) 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) { if (p_cfm_req->just_works) {
// just work, not show to users. // just work, not show to users.
BTA_DmConfirm(p_cfm_req->bd_addr, true); BTA_DmConfirm(p_cfm_req->bd_addr, true);
@ -403,11 +425,12 @@ static void btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_cfm_req)
if (ret != BT_STATUS_SUCCESS) { if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); 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) 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; esp_bt_gap_cb_param_t param;
bt_status_t ret; bt_status_t ret;
btc_msg_t msg; btc_msg_t msg;
@ -423,11 +446,12 @@ static void btc_dm_sp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_key_notif)
if (ret != BT_STATUS_SUCCESS) { if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); 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) 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; esp_bt_gap_cb_param_t param;
bt_status_t ret; bt_status_t ret;
btc_msg_t msg; btc_msg_t msg;
@ -442,9 +466,9 @@ static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req)
if (ret != BT_STATUS_SUCCESS) { if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); 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) tBTA_SERVICE_MASK btc_get_enabled_services_mask(void)
{ {
@ -556,6 +580,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
} }
case BTA_DM_PIN_REQ_EVT: case BTA_DM_PIN_REQ_EVT:
BTC_TRACE_DEBUG("BTA_DM_PIN_REQ_EVT"); BTC_TRACE_DEBUG("BTA_DM_PIN_REQ_EVT");
btc_dm_pin_req_evt(&p_data->pin_req);
break; break;
case BTA_DM_AUTH_CMPL_EVT: case BTA_DM_AUTH_CMPL_EVT:
btc_dm_auth_cmpl_evt(&p_data->auth_cmpl); btc_dm_auth_cmpl_evt(&p_data->auth_cmpl);

View file

@ -646,6 +646,14 @@ static esp_err_t btc_gap_bt_remove_bond_device(btc_gap_bt_args_t *arg)
return ESP_BT_STATUS_FAIL; 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) #if (BT_SSP_INCLUDED == TRUE)
static esp_err_t btc_gap_bt_set_security_param(btc_gap_bt_args_t *arg) static esp_err_t btc_gap_bt_set_security_param(btc_gap_bt_args_t *arg)
{ {
@ -689,6 +697,8 @@ void btc_gap_bt_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
case BTC_GAP_BT_ACT_SET_COD: case BTC_GAP_BT_ACT_SET_COD:
case BTC_GAP_BT_ACT_READ_RSSI_DELTA: case BTC_GAP_BT_ACT_READ_RSSI_DELTA:
case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE: case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE:
case BTC_GAP_BT_ACT_PIN_REPLY:
case BTC_GAP_BT_ACT_SET_PIN_TYPE:
break; break;
#if (BT_SSP_INCLUDED == TRUE) #if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY: case BTC_GAP_BT_ACT_PASSKEY_REPLY:
@ -728,6 +738,8 @@ void btc_gap_bt_arg_deep_free(btc_msg_t *msg)
case BTC_GAP_BT_ACT_SET_COD: case BTC_GAP_BT_ACT_SET_COD:
case BTC_GAP_BT_ACT_READ_RSSI_DELTA: case BTC_GAP_BT_ACT_READ_RSSI_DELTA:
case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE: case BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE:
case BTC_GAP_BT_ACT_PIN_REPLY:
case BTC_GAP_BT_ACT_SET_PIN_TYPE:
break; break;
#if (BT_SSP_INCLUDED == TRUE) #if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_PASSKEY_REPLY: case BTC_GAP_BT_ACT_PASSKEY_REPLY:
@ -780,6 +792,14 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
btc_gap_bt_remove_bond_device(msg->arg); btc_gap_bt_remove_bond_device(msg->arg);
break; 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) #if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_ACT_SET_SECURITY_PARAM:{ case BTC_GAP_BT_ACT_SET_SECURITY_PARAM:{
btc_gap_bt_set_security_param(arg); btc_gap_bt_set_security_param(arg);
@ -827,8 +847,9 @@ void btc_gap_bt_cb_deep_free(btc_msg_t *msg)
osi_free(((tBTA_DM_SEARCH_PARAM *) (msg->arg)) ->p_data); osi_free(((tBTA_DM_SEARCH_PARAM *) (msg->arg)) ->p_data);
break; break;
case BTC_GAP_BT_READ_RSSI_DELTA_EVT: case BTC_GAP_BT_READ_RSSI_DELTA_EVT:
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_AUTH_CMPL_EVT: 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_CFM_REQ_EVT:
case BTC_GAP_BT_KEY_NOTIF_EVT: case BTC_GAP_BT_KEY_NOTIF_EVT:
case BTC_GAP_BT_KEY_REQ_EVT: case BTC_GAP_BT_KEY_REQ_EVT:
@ -859,11 +880,15 @@ void btc_gap_bt_cb_handler(btc_msg_t *msg)
btc_gap_bt_cb_to_app(ESP_BT_GAP_READ_RSSI_DELTA_EVT, (esp_bt_gap_cb_param_t *)msg->arg); btc_gap_bt_cb_to_app(ESP_BT_GAP_READ_RSSI_DELTA_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break; break;
} }
#if (BT_SSP_INCLUDED == TRUE)
case BTC_GAP_BT_AUTH_CMPL_EVT:{ 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); btc_gap_bt_cb_to_app(ESP_BT_GAP_AUTH_CMPL_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break; 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:{ 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); btc_gap_bt_cb_to_app(ESP_BT_GAP_CFM_REQ_EVT, (esp_bt_gap_cb_param_t *)msg->arg);
break; break;

View file

@ -27,6 +27,7 @@ typedef enum {
BTC_GAP_BT_SEARCH_SERVICES_EVT, BTC_GAP_BT_SEARCH_SERVICES_EVT,
BTC_GAP_BT_SEARCH_SERVICE_RECORD_EVT, BTC_GAP_BT_SEARCH_SERVICE_RECORD_EVT,
BTC_GAP_BT_AUTH_CMPL_EVT, BTC_GAP_BT_AUTH_CMPL_EVT,
BTC_GAP_BT_PIN_REQ_EVT,
BTC_GAP_BT_CFM_REQ_EVT, BTC_GAP_BT_CFM_REQ_EVT,
BTC_GAP_BT_KEY_NOTIF_EVT, BTC_GAP_BT_KEY_NOTIF_EVT,
BTC_GAP_BT_KEY_REQ_EVT, BTC_GAP_BT_KEY_REQ_EVT,
@ -42,6 +43,8 @@ typedef enum {
BTC_GAP_BT_ACT_SET_COD, BTC_GAP_BT_ACT_SET_COD,
BTC_GAP_BT_ACT_READ_RSSI_DELTA, BTC_GAP_BT_ACT_READ_RSSI_DELTA,
BTC_GAP_BT_ACT_REMOVE_BOND_DEVICE, 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_SET_SECURITY_PARAM,
BTC_GAP_BT_ACT_PASSKEY_REPLY, BTC_GAP_BT_ACT_PASSKEY_REPLY,
BTC_GAP_BT_ACT_CONFIRM_REPLY, BTC_GAP_BT_ACT_CONFIRM_REPLY,
@ -86,6 +89,21 @@ typedef union {
bt_bdaddr_t bda; bt_bdaddr_t bda;
} rm_bond_device; } 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 // BTC_GAP_BT_ACT_SET_SECURITY_PARAM
struct set_sec_param_args { struct set_sec_param_args {
esp_bt_sp_param_t param_type; esp_bt_sp_param_t param_type;

View file

@ -52,6 +52,7 @@
#define BTA_SDP_INCLUDED TRUE #define BTA_SDP_INCLUDED TRUE
#define BTA_DM_PM_INCLUDED TRUE #define BTA_DM_PM_INCLUDED TRUE
#define SDP_INCLUDED TRUE #define SDP_INCLUDED TRUE
#define BT_SSP_INCLUDED TRUE
#if CONFIG_A2DP_ENABLE #if CONFIG_A2DP_ENABLE
#define BTA_AR_INCLUDED TRUE #define BTA_AR_INCLUDED TRUE
@ -129,12 +130,6 @@
#define BLE_PRIVACY_SPT FALSE #define BLE_PRIVACY_SPT FALSE
#endif /* CONFIG_SMP_ENABLE */ #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) #if (CONFIG_BT_ACL_CONNECTIONS)
#define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS #define MAX_ACL_CONNECTIONS CONFIG_BT_ACL_CONNECTIONS
#define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS #define GATT_MAX_PHY_CHANNEL CONFIG_BT_ACL_CONNECTIONS

View file

@ -113,18 +113,28 @@ void app_main()
/* Bluetooth device name, connection mode and profile set up */ /* 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); 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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) void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{ {
switch (event) { 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) { if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(BT_AV_TAG, "authentication success: %s", param->auth_cmpl.device_name); 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); esp_log_buffer_hex(BT_AV_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
@ -143,7 +153,6 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE
default: { default: {
ESP_LOGI(BT_AV_TAG, "event: %d", event); ESP_LOGI(BT_AV_TAG, "event: %d", event);
break; break;

View file

@ -134,11 +134,18 @@ void app_main()
/* Bluetooth device name, connection mode and profile set up */ /* 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); 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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) static bool get_name_from_eir(uint8_t *eir, uint8_t *bdname, uint8_t *bdname_len)
@ -251,7 +258,6 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
case ESP_BT_GAP_RMT_SRVCS_EVT: case ESP_BT_GAP_RMT_SRVCS_EVT:
case ESP_BT_GAP_RMT_SRVC_REC_EVT: case ESP_BT_GAP_RMT_SRVC_REC_EVT:
break; break;
#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) { if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(BT_AV_TAG, "authentication success: %s", param->auth_cmpl.device_name); ESP_LOGI(BT_AV_TAG, "authentication success: %s", param->auth_cmpl.device_name);
@ -261,6 +267,23 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
} }
break; 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: 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_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); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
@ -271,7 +294,6 @@ void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE
default: { default: {
ESP_LOGI(BT_AV_TAG, "event: %d", event); ESP_LOGI(BT_AV_TAG, "event: %d", event);
break; break;

View file

@ -106,7 +106,6 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{ {
switch (event) { 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) { if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name); ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
@ -116,6 +115,23 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
} }
break; 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: 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_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); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
@ -126,7 +142,6 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE
default: { default: {
ESP_LOGI(SPP_TAG, "event: %d", event); ESP_LOGI(SPP_TAG, "event: %d", event);
break; break;
@ -181,10 +196,17 @@ void app_main()
return; 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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);
} }

View file

@ -165,54 +165,69 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{ {
switch(event){ switch(event){
case ESP_BT_GAP_DISC_RES_EVT: case ESP_BT_GAP_DISC_RES_EVT:
ESP_LOGI(SPP_TAG, "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); 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++){ for (int i = 0; i < param->disc_res.num_prop; i++){
if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR 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)){ && 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); esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
if (strlen(remote_device_name) == peer_bdname_len if (strlen(remote_device_name) == peer_bdname_len
&& strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) { && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
esp_spp_start_discovery(peer_bd_addr); esp_spp_start_discovery(peer_bd_addr);
esp_bt_gap_cancel_discovery(); 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: break;
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val); case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
break; break;
case ESP_BT_GAP_KEY_NOTIF_EVT: case ESP_BT_GAP_RMT_SRVCS_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
break; break;
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_RMT_SRVC_REC_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE case ESP_BT_GAP_AUTH_CMPL_EVT:{
default: if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
break; 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;
} }
} }
@ -266,10 +281,17 @@ void app_main()
return; 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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);
} }

View file

@ -111,7 +111,6 @@ static void esp_spp_stack_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{ {
switch (event) { 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) { if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name); ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
@ -121,6 +120,23 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
} }
break; 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: 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_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); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
@ -131,7 +147,6 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE
default: { default: {
ESP_LOGI(SPP_TAG, "event: %d", event); ESP_LOGI(SPP_TAG, "event: %d", event);
break; break;
@ -187,10 +202,17 @@ void app_main()
return; 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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);
} }

View file

@ -148,54 +148,69 @@ static void esp_spp_cb(uint16_t e, void *p)
static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{ {
switch(event){ switch(event){
case ESP_BT_GAP_DISC_RES_EVT: case ESP_BT_GAP_DISC_RES_EVT:
ESP_LOGI(SPP_TAG, "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); 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++){ for (int i = 0; i < param->disc_res.num_prop; i++){
if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR 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)){ && 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); esp_log_buffer_char(SPP_TAG, peer_bdname, peer_bdname_len);
if (strlen(remote_device_name) == peer_bdname_len if (strlen(remote_device_name) == peer_bdname_len
&& strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) { && strncmp(peer_bdname, remote_device_name, peer_bdname_len) == 0) {
memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN); memcpy(peer_bd_addr, param->disc_res.bda, ESP_BD_ADDR_LEN);
esp_spp_start_discovery(peer_bd_addr); esp_spp_start_discovery(peer_bd_addr);
esp_bt_gap_cancel_discovery(); 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: break;
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val); case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
break; break;
case ESP_BT_GAP_KEY_NOTIF_EVT: case ESP_BT_GAP_RMT_SRVCS_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVCS_EVT");
break; break;
case ESP_BT_GAP_KEY_REQ_EVT: case ESP_BT_GAP_RMT_SRVC_REC_EVT:
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!"); ESP_LOGI(SPP_TAG, "ESP_BT_GAP_RMT_SRVC_REC_EVT");
break; break;
#endif ///CONFIG_BT_SSP_ENABLE case ESP_BT_GAP_AUTH_CMPL_EVT:{
default: if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
break; 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;
} }
} }
@ -255,10 +270,17 @@ void app_main()
return; 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_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); 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);
} }