Skip to content

Commit

Permalink
feat(bt/gap): Add new apis for bluetooth to set and get page timeout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ESP-YTGerd committed Aug 29, 2023
1 parent 3632aa5 commit ff353be
Show file tree
Hide file tree
Showing 17 changed files with 446 additions and 10 deletions.
37 changes: 36 additions & 1 deletion components/bt/host/bluedroid/api/esp_gap_bt_api.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -420,4 +420,39 @@ esp_err_t esp_bt_gap_set_qos(esp_bd_addr_t remote_bda, uint32_t t_poll)
arg.set_qos.t_poll = t_poll;
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_bt_gap_set_page_timeout(uint16_t page_to)
{
btc_msg_t msg;
btc_gap_bt_args_t arg;

if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (page_to < HCI_MIN_PAGE_TOUT) {
return ESP_ERR_INVALID_ARG;
}

msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_ACT_SET_PAGE_TIMEOUT;

arg.set_page_to.page_to = page_to;
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

esp_err_t esp_bt_gap_get_page_timeout(void)
{
btc_msg_t msg;

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_GET_PAGE_TIMEOUT;

return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* #if BTC_GAP_BT_INCLUDED == TRUE */
48 changes: 47 additions & 1 deletion components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -218,6 +218,8 @@ typedef enum {
ESP_BT_GAP_QOS_CMPL_EVT, /*!< QOS complete event */
ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT, /*!< ACL connection complete status event */
ESP_BT_GAP_ACL_DISCONN_CMPL_STAT_EVT, /*!< ACL disconnection complete status event */
ESP_BT_GAP_SET_PAGE_TO_EVT, /*!< Set page timeout event */
ESP_BT_GAP_GET_PAGE_TO_EVT, /*!< Get page timeout event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;

Expand Down Expand Up @@ -372,6 +374,21 @@ typedef union {
logical transport. unit is 0.625ms. */
} qos_cmpl; /*!< QoS complete parameter struct */

/**
* @brief ESP_BT_GAP_SET_PAGE_TO_EVT
*/
struct page_to_set_param {
esp_bt_status_t stat; /*!< set page timeout status*/
} set_page_timeout; /*!< set page timeout parameter struct */

/**
* @brief ESP_BT_GAP_GET_PAGE_TO_EVT
*/
struct page_to_get_param {
esp_bt_status_t stat; /*!< get page timeout status*/
uint16_t page_to; /*!< page_timeout value to be set, unit is 0.625ms. */
} get_page_timeout; /*!< get page timeout parameter struct */

/**
* @brief ESP_BT_GAP_ACL_CONN_CMPL_STAT_EVT
*/
Expand Down Expand Up @@ -786,6 +803,35 @@ esp_err_t esp_bt_gap_read_remote_name(esp_bd_addr_t remote_bda);
*/
esp_err_t esp_bt_gap_set_qos(esp_bd_addr_t remote_bda, uint32_t t_poll);

/**
* @brief Set the page timeout
* esp_bt_gap_cb_t will be called with ESP_BT_GAP_SET_PAGE_TO_EVT
* after set page timeout ends. The value to be set will not be effective util the
* next page procedure, it's suggested to set the page timeout before initiating
* a connection.
*
* @param[in] page_to: Page timeout, the maximum time the master will wait for a
Base-band page response from the remote device at a locally
initiated connection attempt. The valid range is 0x0016 ~ 0xffff,
the default value is 0x2000, unit is 0.625ms.
*
* @return - ESP_OK: success
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - other: failed
*/
esp_err_t esp_bt_gap_set_page_timeout(uint16_t page_to);

/**
* @brief Get the page timeout
* esp_bt_gap_cb_t will be called with ESP_BT_GAP_GET_PAGE_TO_EVT
* after get page timeout ends
*
* @return - ESP_OK: success
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - other: failed
*/
esp_err_t esp_bt_gap_get_page_timeout(void);

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 31 additions & 1 deletion components/bt/host/bluedroid/bta/dm/bta_dm_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status )
#endif ///SMP_INCLUDED == TRUE
BTM_SetDefaultLinkSuperTout(p_bta_dm_cfg->link_timeout);
#if CLASSIC_BT_INCLUDED
BTM_WritePageTimeout(p_bta_dm_cfg->page_timeout);
BTM_WritePageTimeout(p_bta_dm_cfg->page_timeout, NULL);
bta_dm_cb.cur_policy = p_bta_dm_cfg->policy_settings;
BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy);
#endif
Expand Down Expand Up @@ -825,6 +825,36 @@ void bta_dm_config_eir (tBTA_DM_MSG *p_data)

bta_dm_set_eir(NULL);
}

/*******************************************************************************
**
** Function bta_dm_set_page_timeout
**
** Description Sets page timeout
**
**
** Returns void
**
*******************************************************************************/
void bta_dm_set_page_timeout (tBTA_DM_MSG *p_data)
{
BTM_WritePageTimeout(p_data->set_page_timeout.page_to, p_data->set_page_timeout.set_page_to_cb);
}

/*******************************************************************************
**
** Function bta_dm_get_page_timeout
**
** Description Gets page timeout
**
**
** Returns void
**
*******************************************************************************/
void bta_dm_get_page_timeout (tBTA_DM_MSG *p_data)
{
BTM_ReadPageTimeout(p_data->get_page_timeout.get_page_to_cb);
}
#endif
/*******************************************************************************
**
Expand Down
45 changes: 45 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,51 @@ void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB *set_afh_cb)
bta_sys_sendmsg(p_msg);
}
}

/*******************************************************************************
**
** Function BTA_DmSetPageTimeout
**
** Description This function sets the Bluetooth page timeout.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmSetPageTimeout(UINT16 page_to, tBTM_CMPL_CB *p_cb)
{
tBTA_DM_API_PAGE_TO_SET *p_msg;

if ((p_msg = (tBTA_DM_API_PAGE_TO_SET *) osi_malloc(sizeof(tBTA_DM_API_PAGE_TO_SET))) != NULL) {
p_msg->hdr.event = BTA_DM_API_PAGE_TO_SET_EVT;
p_msg->page_to = page_to;
p_msg->set_page_to_cb = p_cb;

bta_sys_sendmsg(p_msg);
}
}

/*******************************************************************************
**
** Function BTA_DmGetPageTimeout
**
** Description This function gets the Bluetooth page timeout.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmGetPageTimeout(tBTM_CMPL_CB *p_cb)
{
tBTA_DM_API_PAGE_TO_GET *p_msg;

if ((p_msg = (tBTA_DM_API_PAGE_TO_GET *) osi_malloc(sizeof(tBTA_DM_API_PAGE_TO_GET))) != NULL) {
p_msg->hdr.event = BTA_DM_API_PAGE_TO_GET_EVT;
p_msg->get_page_to_cb = p_cb;

bta_sys_sendmsg(p_msg);
}
}
#endif /// CLASSIC_BT_INCLUDED == TRUE

#if (SDP_INCLUDED == TRUE)
Expand Down
2 changes: 2 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
bta_dm_get_dev_name, /* BTA_DM_API_GET_NAME_EVT */
#if (CLASSIC_BT_INCLUDED == TRUE)
bta_dm_config_eir, /* BTA_DM_API_CONFIG_EIR_EVT */
bta_dm_set_page_timeout, /* BTA_DM_API_PAGE_TO_SET_EVT */
bta_dm_get_page_timeout, /* BTA_DM_API_PAGE_TO_GET_EVT */
#endif
bta_dm_set_afh_channels, /* BTA_DM_API_SET_AFH_CHANNELS_EVT */
#if (SDP_INCLUDED == TRUE)
Expand Down
19 changes: 19 additions & 0 deletions components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enum {
BTA_DM_API_GET_NAME_EVT,
#if (CLASSIC_BT_INCLUDED == TRUE)
BTA_DM_API_CONFIG_EIR_EVT,
BTA_DM_API_PAGE_TO_SET_EVT,
BTA_DM_API_PAGE_TO_GET_EVT,
#endif
BTA_DM_API_SET_AFH_CHANNELS_EVT,
#if (SDP_INCLUDED == TRUE)
Expand Down Expand Up @@ -264,6 +266,19 @@ typedef struct {
tBTA_CMPL_CB *set_afh_cb;
}tBTA_DM_API_SET_AFH_CHANNELS;

/* data type for BTA_DM_API_PAGE_TO_SET_EVT */
typedef struct {
BT_HDR hdr;
UINT16 page_to;
tBTM_CMPL_CB *set_page_to_cb;
} tBTA_DM_API_PAGE_TO_SET;

/* data type for BTA_DM_API_PAGE_TO_GET_EVT */
typedef struct {
BT_HDR hdr;
tBTM_CMPL_CB *get_page_to_cb;
} tBTA_DM_API_PAGE_TO_GET;

/* data type for BTA_DM_API_GET_REMOTE_NAME_EVT */
typedef struct {
BT_HDR hdr;
Expand Down Expand Up @@ -1077,6 +1092,8 @@ typedef union {
tBTA_DM_API_CONFIG_EIR config_eir;

tBTA_DM_API_SET_AFH_CHANNELS set_afh_channels;
tBTA_DM_API_PAGE_TO_SET set_page_timeout;
tBTA_DM_API_PAGE_TO_GET get_page_timeout;
#if (SDP_INCLUDED == TRUE)
tBTA_DM_API_GET_REMOTE_NAME get_rmt_name;
#endif
Expand Down Expand Up @@ -1577,6 +1594,8 @@ extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data);
extern void bta_dm_get_dev_name (tBTA_DM_MSG *p_data);
#if (CLASSIC_BT_INCLUDED == TRUE)
extern void bta_dm_config_eir (tBTA_DM_MSG *p_data);
extern void bta_dm_set_page_timeout (tBTA_DM_MSG *p_data);
extern void bta_dm_get_page_timeout (tBTA_DM_MSG *p_data);
#endif
extern void bta_dm_set_afh_channels (tBTA_DM_MSG *p_data);
extern void bta_dm_read_rmt_name(tBTA_DM_MSG *p_data);
Expand Down
26 changes: 26 additions & 0 deletions components/bt/host/bluedroid/bta/include/bta/bta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ typedef tBTM_RSSI_RESULTS tBTA_RSSI_RESULTS;
typedef tBTM_SET_AFH_CHANNELS_RESULTS tBTA_SET_AFH_CHANNELS_RESULTS;
typedef tBTM_BLE_SET_CHANNELS_RESULTS tBTA_BLE_SET_CHANNELS_RESULTS;

typedef tBTM_SET_PAGE_TIMEOUT_RESULTS tBTA_SET_PAGE_TIMEOUT_RESULTS;
typedef tBTM_GET_PAGE_TIMEOUT_RESULTS tBTA_GET_PAGE_TIMEOUT_RESULTS;

typedef tBTM_REMOTE_DEV_NAME tBTA_REMOTE_DEV_NAME;

/* advertising channel map */
Expand Down Expand Up @@ -1760,6 +1763,29 @@ void BTA_DmSetAfhChannels(const uint8_t *channels, tBTA_CMPL_CB *set_afh_cb);
void BTA_DmSetQos(BD_ADDR bd_addr, UINT32 t_poll, tBTM_CMPL_CB *p_cb);
#endif /// (BTA_DM_QOS_INCLUDED == TRUE)

/*******************************************************************************
**
** Function BTA_DmSetPageTimeout
**
** Description This function sets the Bluetooth page timeout.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmSetPageTimeout(UINT16 page_to, tBTM_CMPL_CB *p_cb);
/*******************************************************************************
**
** Function BTA_DmGetPageTimeout
**
** Description This function gets the Bluetooth page timeout.
**
**
** Returns void
**
*******************************************************************************/
void BTA_DmGetPageTimeout(tBTM_CMPL_CB *p_cb);

#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**
Expand Down
Loading

0 comments on commit ff353be

Please sign in to comment.