/从机端*********/
从机的配对机制
#if 0
// 配置为绑定时需要PIN码
gap_security_param_t param =
{
.mitm = true, // use PIN code during bonding
.ble_secure_conn = true, //not enable security encryption
.io_cap = GAP_IO_CAP_DISPLAY_ONLY, //ble device has output ability, will show pin code.
.pair_init_mode = GAP_PAIRING_MODE_WAIT_FOR_REQ,//need bond
.bond_auth = true, //need bond auth
.password = 12345, //set PIN code, it is a dec num between 100000 ~ 999999
};
#endif
#if 1
//配置为不需要PIN码
gap_security_param_t param =
{
.mitm = false, // use PIN code during bonding
.ble_secure_conn = false, //not enable security encryption
.io_cap = GAP_IO_CAP_DISPLAY_ONLY, //ble device has output ability, will show pin code.
.pair_init_mode = GAP_PAIRING_MODE_WAIT_FOR_REQ, //need bond
.bond_auth = true, //need bond auth
.password = 0, //set PIN code, it is a dec num between 100000 ~ 999999
};
#endif
//initialize bonding configuration
gap_security_param_init(¶m);
//*****************************************************//
/主机端*********/
需要在 app_gap_evt_cb(gap_event_t *p_event)里面
加入
case GAP_SEC_EVT_BOND_FAIL: //!< Link bond is failed
co_printf("GAP_SEC_EVT_BOND_FAIL:0x%02x\r\n",GAP_SEC_EVT_BOND_FAIL);
break;
case GAP_SEC_EVT_BOND_SUCCESS: //!< Link bond is successful
co_printf("GAP_SEC_EVT_BOND_SUCCESS:0x%02x\r\n",GAP_SEC_EVT_BOND_SUCCESS);
break;
case GAP_SEC_EVT_PIN_CODE_REQ: //!< Link bond request pin code inpu
gap_security_send_pairing_password(0,12345);
co_printf("GAP_SEC_EVT_PIN_CODE_REQ:0x%02x\r\n",GAP_SEC_EVT_PIN_CODE_REQ);
break;