feat(bt/gap): Add new apis for bluetooth to set and get page timeout
1: add two new apis for classic bluetooth, esp_bt_gap_set_page_timeout(page_to) and esp_bt_gap_get_page_timeout(), which can get and set the value of page timeout.
This commit is contained in:
@@ -162,6 +162,7 @@ static void reset_complete(void)
|
||||
btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW;
|
||||
btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL;
|
||||
btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
|
||||
btm_cb.btm_inq_vars.page_timeout = HCI_DEFAULT_PAGE_TOUT;
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
|
||||
@@ -197,6 +198,9 @@ static void reset_complete(void)
|
||||
#if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
|
||||
BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len);
|
||||
#endif ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
|
||||
#if (CLASSIC_BT_INCLUDED == TRUE)
|
||||
BTM_WritePageTimeout(btm_cb.btm_inq_vars.page_timeout, NULL);
|
||||
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
||||
for (int i = 0; i <= controller->get_last_features_classic_index(); i++) {
|
||||
btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array);
|
||||
}
|
||||
@@ -817,7 +821,7 @@ void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
|
||||
BTM_TRACE_DEBUG ("BTM Event: Vendor Specific event from controller");
|
||||
}
|
||||
|
||||
|
||||
#if (CLASSIC_BT_INCLUDED == TRUE)
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_WritePageTimeout
|
||||
@@ -830,12 +834,115 @@ void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
|
||||
tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout, tBTM_CMPL_CB *p_cb)
|
||||
{
|
||||
BTM_TRACE_EVENT ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout);
|
||||
|
||||
if (timeout >= HCI_MIN_PAGE_TOUT) {
|
||||
btm_cb.btm_inq_vars.page_timeout = timeout;
|
||||
}
|
||||
btm_cb.devcb.p_page_to_set_cmpl_cb = p_cb;
|
||||
|
||||
/* Send the HCI command */
|
||||
if (btsnd_hcic_write_page_tout (timeout)) {
|
||||
if (!btsnd_hcic_write_page_tout (timeout)) {
|
||||
return (BTM_NO_RESOURCES);
|
||||
}
|
||||
|
||||
if (p_cb) {
|
||||
btu_start_timer(&btm_cb.devcb.page_timeout_set_timer, BTU_TTYPE_BTM_SET_PAGE_TO, BTM_DEV_REPLY_TIMEOUT);
|
||||
}
|
||||
|
||||
return (BTM_CMD_STARTED);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_set_page_timeout_complete
|
||||
**
|
||||
** Description This function is called when setting page timeout complete.
|
||||
** message is received from the HCI.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void btm_set_page_timeout_complete (const UINT8 *p)
|
||||
{
|
||||
tBTM_SET_PAGE_TIMEOUT_RESULTS results;
|
||||
|
||||
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_page_to_set_cmpl_cb;
|
||||
btm_cb.devcb.p_page_to_set_cmpl_cb = NULL;
|
||||
btu_free_timer (&btm_cb.devcb.page_timeout_set_timer);
|
||||
|
||||
/* If there is a callback address for setting page timeout, call it */
|
||||
if (p_cb) {
|
||||
if (p) {
|
||||
STREAM_TO_UINT8 (results.hci_status, p);
|
||||
switch (results.hci_status) {
|
||||
case HCI_SUCCESS:
|
||||
results.status = BTM_SUCCESS;
|
||||
break;
|
||||
case HCI_ERR_UNSUPPORTED_VALUE:
|
||||
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
|
||||
results.status = BTM_ILLEGAL_VALUE;
|
||||
break;
|
||||
default:
|
||||
results.status = BTM_NO_RESOURCES;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
results.hci_status = HCI_ERR_HOST_TIMEOUT;
|
||||
results.status = BTM_DEVICE_TIMEOUT;
|
||||
}
|
||||
(*p_cb)(&results);
|
||||
}
|
||||
}
|
||||
#endif /// CLASSIC_BT_INCLUDED == TRUE
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_page_to_setup_timeout
|
||||
**
|
||||
** Description This function processes a timeout.
|
||||
** Currently, we just report an error log
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void btm_page_to_setup_timeout (void *p_tle)
|
||||
{
|
||||
UNUSED(p_tle);
|
||||
BTM_TRACE_DEBUG ("%s\n", __func__);
|
||||
|
||||
#if (CLASSIC_BT_INCLUDED == TRUE)
|
||||
btm_set_page_timeout_complete (NULL);
|
||||
#endif /// CLASSIC_BT_INCLUDED == TRUE
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_ReadPageTimeout
|
||||
**
|
||||
** Description Send HCI Read Page Timeout.
|
||||
**
|
||||
** Returns
|
||||
** BTM_SUCCESS Command sent.
|
||||
** BTM_NO_RESOURCES If out of resources to send the command.
|
||||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
tBTM_STATUS BTM_ReadPageTimeout(tBTM_CMPL_CB *p_cb)
|
||||
{
|
||||
BTM_TRACE_EVENT ("BTM: BTM_ReadPageTimeout");
|
||||
|
||||
/* Get the page timeout */
|
||||
tBTM_GET_PAGE_TIMEOUT_RESULTS results;
|
||||
|
||||
if (p_cb) {
|
||||
results.hci_status = HCI_SUCCESS;
|
||||
results.status = BTM_SUCCESS;
|
||||
results.page_to = btm_cb.btm_inq_vars.page_timeout;
|
||||
|
||||
(*p_cb)(&results);
|
||||
return (BTM_SUCCESS);
|
||||
} else {
|
||||
return (BTM_NO_RESOURCES);
|
||||
|
||||
@@ -214,6 +214,10 @@ tBTM_CMPL_CB *p_tx_power_cmpl_cb;/* Callback function to be called
|
||||
TIMER_LIST_ENT afh_channels_timer;
|
||||
tBTM_CMPL_CB *p_afh_channels_cmpl_cb; /* Callback function to be called When */
|
||||
/* set AFH channels is completed */
|
||||
|
||||
TIMER_LIST_ENT page_timeout_set_timer;
|
||||
tBTM_CMPL_CB *p_page_to_set_cmpl_cb; /* Callback function to be called when */
|
||||
/* set page timeout is completed */
|
||||
#endif
|
||||
|
||||
DEV_CLASS dev_class; /* Local device class */
|
||||
@@ -315,6 +319,7 @@ typedef struct {
|
||||
UINT16 inq_scan_type;
|
||||
UINT16 page_scan_type; /* current page scan type */
|
||||
tBTM_INQ_TYPE scan_type;
|
||||
UINT16 page_timeout;
|
||||
|
||||
BD_ADDR remname_bda; /* Name of bd addr for active remote name request */
|
||||
#define BTM_RMT_NAME_INACTIVE 0
|
||||
@@ -1135,6 +1140,8 @@ 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);
|
||||
void btm_set_page_timeout_complete (const UINT8 *p);
|
||||
void btm_page_to_setup_timeout (void *p_tle);
|
||||
|
||||
/* Internal functions provided by btm_dev.c
|
||||
**********************************************
|
||||
|
||||
@@ -996,6 +996,9 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l
|
||||
case HCI_SET_AFH_CHANNELS:
|
||||
btm_set_afh_channels_complete(p);
|
||||
break;
|
||||
case HCI_WRITE_PAGE_TOUT:
|
||||
btm_set_page_timeout_complete(p);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
|
||||
@@ -401,6 +401,9 @@ static void btu_general_alarm_process(void *param)
|
||||
case BTU_TTYPE_BTM_QOS:
|
||||
btm_qos_setup_timeout(p_tle);
|
||||
break;
|
||||
case BTU_TTYPE_BTM_SET_PAGE_TO:
|
||||
btm_page_to_setup_timeout(p_tle);
|
||||
break;
|
||||
default:
|
||||
for (int i = 0; i < BTU_MAX_REG_TIMER; i++) {
|
||||
if (btu_cb.timer_reg[i].timer_cb == NULL) {
|
||||
|
||||
@@ -810,6 +810,23 @@ typedef struct {
|
||||
UINT8 hci_status;
|
||||
} tBTM_SET_AFH_CHANNELS_RESULTS;
|
||||
|
||||
/* Structure returned with set page timeout event (in tBTM_CMPL_CB callback function)
|
||||
** in response to BTM_WritePageTimeout call.
|
||||
*/
|
||||
typedef struct {
|
||||
tBTM_STATUS status;
|
||||
UINT8 hci_status;
|
||||
} tBTM_SET_PAGE_TIMEOUT_RESULTS;
|
||||
|
||||
/* Structure returned with get page timeout event (in tBTM_CMPL_CB callback function)
|
||||
** in response to BTM_ReadPageTimeout call.
|
||||
*/
|
||||
typedef struct {
|
||||
tBTM_STATUS status;
|
||||
UINT8 hci_status;
|
||||
UINT16 page_to;
|
||||
} tBTM_GET_PAGE_TIMEOUT_RESULTS;
|
||||
|
||||
/* Structure returned with set BLE channels event (in tBTM_CMPL_CB callback function)
|
||||
** in response to BTM_BleSetChannels call.
|
||||
*/
|
||||
@@ -2192,7 +2209,21 @@ UINT8 BTM_SetTraceLevel (UINT8 new_level);
|
||||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout);
|
||||
tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout, tBTM_CMPL_CB *p_cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTM_ReadPageTimeout
|
||||
**
|
||||
** Description Send HCI Read Page Timeout.
|
||||
**
|
||||
** Returns
|
||||
** BTM_SUCCESS Command sent.
|
||||
** BTM_NO_RESOURCES If out of resources to send the command.
|
||||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
tBTM_STATUS BTM_ReadPageTimeout(tBTM_CMPL_CB *p_cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
||||
@@ -166,6 +166,9 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
|
||||
/* BTU internal timer for QOS */
|
||||
#define BTU_TTYPE_BTM_QOS 110
|
||||
|
||||
/* BTU internal timer for set page timeout*/
|
||||
#define BTU_TTYPE_BTM_SET_PAGE_TO 111
|
||||
|
||||
/* BTU Task Signal */
|
||||
typedef enum {
|
||||
SIG_BTU_START_UP = 0,
|
||||
|
||||
@@ -1285,6 +1285,7 @@ typedef UINT8 tHCI_STATUS;
|
||||
|
||||
/* Page timeout is used in LC only and LC is counting down slots not using OS */
|
||||
#define HCI_DEFAULT_PAGE_TOUT 0x2000 /* 5.12 sec (in slots) */
|
||||
#define HCI_MIN_PAGE_TOUT 0x0016 /* 13.75 ms (in slots) */
|
||||
|
||||
/* Scan enable flags */
|
||||
#define HCI_NO_SCAN_ENABLED 0x00
|
||||
|
||||
@@ -586,7 +586,7 @@ BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels);
|
||||
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 */
|
||||
BOOLEAN btsnd_hcic_write_page_tout(UINT16 timeout); /* Write Page Timout */
|
||||
BOOLEAN btsnd_hcic_write_page_tout(UINT16 timeout); /* Write Page Timeout */
|
||||
BOOLEAN btsnd_hcic_write_scan_enable(UINT8 flag); /* Write Scan Enable */
|
||||
BOOLEAN btsnd_hcic_write_pagescan_cfg(UINT16 interval,
|
||||
UINT16 window); /* Write Page Scan Activity */
|
||||
|
||||
Reference in New Issue
Block a user