mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
feat(bt/bluedroid): added a VSC to set minimal encryption key size
This commit is contained in:
@@ -877,6 +877,42 @@ tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout, tBTM_CMPL_CB *p_cb)
|
||||
return (BTM_CMD_STARTED);
|
||||
}
|
||||
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE != ENC_KEY_SIZE_CTRL_MODE_NONE)
|
||||
void btm_set_min_enc_key_size_complete(const UINT8 *p)
|
||||
{
|
||||
tBTM_SET_MIN_ENC_KEY_SIZE_RESULTS results;
|
||||
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_set_min_enc_key_size_cmpl_cb;
|
||||
|
||||
STREAM_TO_UINT8(results.hci_status, p);
|
||||
|
||||
if (p_cb) {
|
||||
btm_cb.devcb.p_set_min_enc_key_size_cmpl_cb = NULL;
|
||||
(*p_cb)(&results);
|
||||
}
|
||||
}
|
||||
|
||||
tBTM_STATUS BTM_SetMinEncKeySize(UINT8 key_size, tBTM_CMPL_CB *p_cb)
|
||||
{
|
||||
BTM_TRACE_EVENT ("BTM: BTM_SetMinEncKeySize: key_size: %d.", key_size);
|
||||
|
||||
btm_cb.devcb.p_set_min_enc_key_size_cmpl_cb = p_cb;
|
||||
tBTM_STATUS status = BTM_NO_RESOURCES;
|
||||
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE == ENC_KEY_SIZE_CTRL_MODE_VSC)
|
||||
/* Send the HCI command */
|
||||
UINT8 param[1];
|
||||
UINT8 *p = (UINT8 *)param;
|
||||
UINT8_TO_STREAM(p, key_size);
|
||||
status = BTM_VendorSpecificCommand(HCI_VENDOR_BT_SET_MIN_ENC_KEY_SIZE, 1, param, NULL);
|
||||
#else
|
||||
if (btsnd_hcic_set_min_enc_key_size(key_size)) {
|
||||
status = BTM_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_set_page_timeout_complete
|
||||
|
@@ -221,6 +221,8 @@ tBTM_CMPL_CB *p_page_to_set_cmpl_cb; /* Callback function to be called w
|
||||
TIMER_LIST_ENT set_acl_pkt_types_timer;
|
||||
tBTM_CMPL_CB *p_set_acl_pkt_types_cmpl_cb; /* Callback function to be called when */
|
||||
/* set ACL packet types is completed */
|
||||
tBTM_CMPL_CB *p_set_min_enc_key_size_cmpl_cb; /* Callback function to be called when */
|
||||
/* set min encryption key size is completed */
|
||||
#endif
|
||||
|
||||
DEV_CLASS dev_class; /* Local device class */
|
||||
@@ -1148,6 +1150,9 @@ void btm_delete_stored_link_key_complete (UINT8 *p);
|
||||
void btm_report_device_status (tBTM_DEV_STATUS status);
|
||||
void btm_set_afh_channels_complete (UINT8 *p);
|
||||
void btm_ble_set_channels_complete (UINT8 *p);
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE != ENC_KEY_SIZE_CTRL_MODE_NONE)
|
||||
void btm_set_min_enc_key_size_complete(const UINT8 *p);
|
||||
#endif
|
||||
void btm_set_page_timeout_complete (const UINT8 *p);
|
||||
void btm_page_to_setup_timeout (void *p_tle);
|
||||
|
||||
|
@@ -998,6 +998,16 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l
|
||||
case HCI_WRITE_PAGE_TOUT:
|
||||
btm_set_page_timeout_complete(p);
|
||||
break;
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE == ENC_KEY_SIZE_CTRL_MODE_STD)
|
||||
case HCI_SET_MIN_ENC_KEY_SIZE:
|
||||
btm_set_min_enc_key_size_complete(p);
|
||||
break;
|
||||
#endif
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE == ENC_KEY_SIZE_CTRL_MODE_VSC)
|
||||
case HCI_VENDOR_BT_SET_MIN_ENC_KEY_SIZE:
|
||||
btm_set_min_enc_key_size_complete(p);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
|
@@ -1910,4 +1910,30 @@ BOOLEAN btsnd_hcic_set_afh_channels (AFH_CHANNELS channels)
|
||||
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE == ENC_KEY_SIZE_CTRL_MODE_STD)
|
||||
BOOLEAN btsnd_hcic_set_min_enc_key_size (UINT8 size)
|
||||
{
|
||||
BT_HDR *p;
|
||||
UINT8 *pp;
|
||||
|
||||
if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_MIN_ENC_KEY_SIZE)) == NULL) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
pp = (UINT8 *)(p + 1);
|
||||
|
||||
p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_MIN_ENC_KEY_SIZE;
|
||||
p->offset = 0;
|
||||
|
||||
UINT16_TO_STREAM (pp, HCI_SET_MIN_ENC_KEY_SIZE);
|
||||
UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_SET_MIN_ENC_KEY_SIZE);
|
||||
|
||||
UINT8_TO_STREAM (pp, size);
|
||||
|
||||
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
|
||||
return (TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /// CLASSIC_BT_INCLUDED == TRUE
|
||||
|
@@ -860,6 +860,15 @@ typedef struct {
|
||||
UINT16 pkt_types;
|
||||
} tBTM_SET_ACL_PKT_TYPES_RESULTS;
|
||||
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE != ENC_KEY_SIZE_CTRL_MODE_NONE)
|
||||
/* Structure returned with set minimal encryption key size event (in tBTM_CMPL_CB callback function)
|
||||
** in response to BTM_SetMinEncKeySize call.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 hci_status;
|
||||
} tBTM_SET_MIN_ENC_KEY_SIZE_RESULTS;
|
||||
#endif
|
||||
|
||||
/* Structure returned with set BLE channels event (in tBTM_CMPL_CB callback function)
|
||||
** in response to BTM_BleSetChannels call.
|
||||
*/
|
||||
@@ -2305,6 +2314,22 @@ tBTM_STATUS BTM_ReadPageTimeout(tBTM_CMPL_CB *p_cb);
|
||||
//extern
|
||||
tBTM_STATUS BTM_SetAclPktTypes(BD_ADDR remote_bda, UINT16 pkt_types, tBTM_CMPL_CB *p_cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_SetMinEncKeySize
|
||||
**
|
||||
** Description Send HCI Set Minimum Encryption Key Size
|
||||
**
|
||||
** Returns
|
||||
** BTM_SUCCESS Command sent.
|
||||
** BTM_NO_RESOURCES If out of resources to send the command.
|
||||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
#if (ENC_KEY_SIZE_CTRL_MODE != ENC_KEY_SIZE_CTRL_MODE_NONE)
|
||||
tBTM_STATUS BTM_SetMinEncKeySize(UINT8 key_size, tBTM_CMPL_CB *p_cb);
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_WriteVoiceSettings
|
||||
|
@@ -212,6 +212,7 @@
|
||||
#define HCI_WRITE_ERRONEOUS_DATA_RPT (0x005B | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
|
||||
#define HCI_ENHANCED_FLUSH (0x005F | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
|
||||
#define HCI_SEND_KEYPRESS_NOTIF (0x0060 | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
|
||||
#define HCI_SET_MIN_ENC_KEY_SIZE (0x0084 | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
|
||||
|
||||
|
||||
/* AMP HCI */
|
||||
@@ -424,8 +425,9 @@
|
||||
#define HCI_SUBCODE_BLE_MAX 0x7F
|
||||
|
||||
//ESP BT subcode define
|
||||
#define HCI_SUBCODE_BT_INIT 0x00
|
||||
#define HCI_SUBCODE_BT_MAX 0x7F
|
||||
#define HCI_SUBCODE_BT_INIT 0x00
|
||||
#define HCI_SUBCODE_BT_SET_MIN_ENC_KEY_SIZE 0x02
|
||||
#define HCI_SUBCODE_BT_MAX 0x7F
|
||||
|
||||
#define HCI_ESP_VENDOR_OPCODE_BUILD(ogf, group, subcode) ((ogf << 10) | (group <<7) | (subcode << 0))
|
||||
/*
|
||||
@@ -467,6 +469,7 @@
|
||||
/* BLE clear legacy advertising */
|
||||
#define HCI_VENDOR_BLE_CLEAR_ADV HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BLE, HCI_SUBCODE_BLE_CLEAR_ADV)
|
||||
//ESP BT HCI CMD
|
||||
#define HCI_VENDOR_BT_SET_MIN_ENC_KEY_SIZE HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BT, HCI_SUBCODE_BT_SET_MIN_ENC_KEY_SIZE)
|
||||
|
||||
/* subcode for multi adv feature */
|
||||
#define BTM_BLE_MULTI_ADV_SET_PARAM 0x01
|
||||
|
@@ -583,6 +583,10 @@ BOOLEAN btsnd_hcic_set_afh_channels (AFH_CHANNELS channels);
|
||||
BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels);
|
||||
#define HCIC_PARAM_SIZE_BLE_SET_CHANNELS 5
|
||||
|
||||
/* set minimum encryption key size */
|
||||
BOOLEAN btsnd_hcic_set_min_enc_key_size (UINT8 size);
|
||||
#define HCIC_PARAM_SIZE_SET_MIN_ENC_KEY_SIZE 1
|
||||
|
||||
BOOLEAN btsnd_hcic_write_pin_type(UINT8 type); /* Write PIN Type */
|
||||
BOOLEAN btsnd_hcic_write_auto_accept(UINT8 flag); /* Write Auto Accept */
|
||||
BOOLEAN btsnd_hcic_read_name (void); /* Read Local Name */
|
||||
|
Reference in New Issue
Block a user