}
/* mark bg conn record */
if (bta_gattc_mark_bg_conn(p_msg->api_listen.client_if,
- (BD_ADDR_PTR) p_msg->api_listen.remote_bda,
+ (BD_ADDR_PTR) NULL,
p_msg->api_listen.start,
true))
{
- if (!GATT_Listen(p_msg->api_listen.client_if,
- p_msg->api_listen.start,
- p_msg->api_listen.remote_bda))
- {
- APPL_TRACE_ERROR("Listen failure");
- (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
- }
- else
- {
- cb_data.status = BTA_GATT_OK;
-
- (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
-
- if (p_msg->api_listen.start)
- {
- /* if listen to a specific target */
- if (p_msg->api_listen.remote_bda != NULL)
- {
+ GATT_Listen(p_msg->api_listen.start);
+ cb_data.status = BTA_GATT_OK;
- /* if is a connected remote device */
- if (L2CA_GetBleConnRole(p_msg->api_listen.remote_bda) == HCI_ROLE_SLAVE &&
- bta_gattc_find_clcb_by_cif(p_msg->api_listen.client_if,
- p_msg->api_listen.remote_bda,
- BTA_GATT_TRANSPORT_LE) == NULL)
- {
+ (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
- bta_gattc_init_clcb_conn(p_msg->api_listen.client_if,
- p_msg->api_listen.remote_bda);
- }
- }
- /* if listen to all */
- else
- {
- LOG_DEBUG(LOG_TAG, "Listen For All now");
- /* go through all connected device and send
- callback for all connected slave connection */
- bta_gattc_process_listen_all(p_msg->api_listen.client_if);
- }
- }
+ if (p_msg->api_listen.start)
+ {
+ LOG_DEBUG(LOG_TAG, "Listen For All now");
+ /* go through all connected device and send
+ callback for all connected slave connection */
+ bta_gattc_process_listen_all(p_msg->api_listen.client_if);
}
}
}
**
** Parameters client_if: server interface.
** start: to start or stop listening for connection
-** remote_bda: remote device BD address, if listen to all device
-** use NULL.
**
** Returns void
**
*******************************************************************************/
-void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, bool start, BD_ADDR_PTR target_bda)
+void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, bool start)
{
tBTA_GATTC_API_LISTEN *p_buf =
(tBTA_GATTC_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN);
p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
p_buf->client_if = client_if;
p_buf->start = start;
- if (target_bda) {
- p_buf->remote_bda = (uint8_t*)(p_buf + 1);
- memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
- } else {
- p_buf->remote_bda = NULL;
- }
bta_sys_sendmsg(p_buf);
}
typedef struct
{
BT_HDR hdr;
- BD_ADDR_PTR remote_bda;
tBTA_GATTC_IF client_if;
bool start;
} tBTA_GATTC_API_LISTEN;
}
}
-/*******************************************************************************
-**
-** Function bta_gatts_listen
-**
-** Description Start or stop listening for LE connection on a GATT server
-**
-** Returns none.
-**
-*******************************************************************************/
-void bta_gatts_listen(UNUSED_ATTR tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
-{
- tBTA_GATTS_RCB *p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_listen.server_if);
- tBTA_GATTS cb_data;
-
- cb_data.reg_oper.status = BTA_GATT_OK;
- cb_data.reg_oper.server_if = p_msg->api_listen.server_if;
-
- if (p_rcb == NULL)
- {
- APPL_TRACE_ERROR("Unknown GATTS application");
- return;
- }
-
- if (!GATT_Listen(p_msg->api_listen.server_if,
- p_msg->api_listen.start,
- p_msg->api_listen.remote_bda))
- {
- cb_data.status = BTA_GATT_ERROR;
- APPL_TRACE_ERROR("bta_gatts_listen Listen failed");
- }
-
- if (p_rcb->p_cback)
- (*p_rcb->p_cback)(BTA_GATTS_LISTEN_EVT, &cb_data);
-}
/*******************************************************************************
**
bta_sys_sendmsg(p_buf);
}
-/*******************************************************************************
-**
-** Function BTA_GATTS_Listen
-**
-** Description Start advertisement to listen for connection request for a
-** GATT server
-**
-** Parameters server_if: server interface.
-** start: to start or stop listening for connection
-** remote_bda: remote device BD address, if listen to all device
-** use NULL.
-**
-** Returns void
-**
-*******************************************************************************/
-void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, bool start, BD_ADDR_PTR target_bda)
-{
- tBTA_GATTS_API_LISTEN *p_buf =
- (tBTA_GATTS_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN);
-
- p_buf->hdr.event = BTA_GATTS_API_LISTEN_EVT;
- p_buf->server_if = server_if;
- p_buf->start = start;
- if (target_bda) {
- p_buf->remote_bda = (uint8_t *)(p_buf + 1);
- memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
- } else {
- p_buf->remote_bda = NULL;
- }
-
- bta_sys_sendmsg(p_buf);
-}
-
#endif /* BTA_GATT_INCLUDED */
BTA_GATTS_API_OPEN_EVT,
BTA_GATTS_API_CANCEL_OPEN_EVT,
BTA_GATTS_API_CLOSE_EVT,
- BTA_GATTS_API_LISTEN_EVT,
BTA_GATTS_API_DISABLE_EVT
};
typedef uint16_t tBTA_GATTS_INT_EVT;
typedef tBTA_GATTS_API_OPEN tBTA_GATTS_API_CANCEL_OPEN;
-typedef struct
-{
- BT_HDR hdr;
- BD_ADDR_PTR remote_bda;
- tBTA_GATTS_IF server_if;
- bool start;
-} tBTA_GATTS_API_LISTEN;
-
typedef union
{
BT_HDR hdr;
tBTA_GATTS_API_CANCEL_OPEN api_cancel_open;
tBTA_GATTS_INT_START_IF int_start_if;
- /* if peripheral role is supported */
- tBTA_GATTS_API_LISTEN api_listen;
} tBTA_GATTS_DATA;
/* application registration control block */
extern void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
-extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern bool bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src);
extern tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if);
bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg);
break;
- case BTA_GATTS_API_LISTEN_EVT:
- bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg);
- break;
-
-
case BTA_GATTS_API_DEL_SRVC_EVT:
{
tBTA_GATTS_SRVC_CB *p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
**
** Parameters client_if: server interface.
** start: to start or stop listening for connection
-** remote_bda: remote device BD address, if listen to all device
-** use NULL.
**
** Returns void
**
*******************************************************************************/
-extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, bool start, BD_ADDR_PTR target_bda);
+extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, bool start);
/*******************************************************************************
**
*******************************************************************************/
extern void BTA_GATTS_Close(uint16_t conn_id);
-/*******************************************************************************
-**
-** Function BTA_GATTS_Listen
-**
-** Description Start advertisement to listen for connection request for a
-** GATT server
-**
-** Parameters server_if: server interface.
-** start: to start or stop listening for connection
-** remote_bda: remote device BD address, if listen to all device
-** use NULL.
-**
-** Returns void
-**
-*******************************************************************************/
-extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, bool start,
- BD_ADDR_PTR target_bda);
-
#endif /* BTA_GATT_API_H */
CHECK_BTGATT_INIT();
#if (defined(BLE_PERIPHERAL_MODE_SUPPORT) && \
(BLE_PERIPHERAL_MODE_SUPPORT == true))
- return do_in_jni_thread(Bind(&BTA_GATTC_Listen, client_if, start, nullptr));
+ return do_in_jni_thread(Bind(&BTA_GATTC_Listen, client_if, start));
#else
return do_in_jni_thread(Bind(&BTA_GATTC_Broadcast, client_if, start));
#endif
/*******************************************************************************
**
-** Function BTM_BleUpdateAdvWhitelist
-**
-** Description Add or remove device from advertising white list
-**
-** Returns void
-**
-*******************************************************************************/
-bool BTM_BleUpdateAdvWhitelist(UNUSED_ATTR bool add_remove,
- UNUSED_ATTR BD_ADDR remote_bda)
-{
- return false;
-}
-
-/*******************************************************************************
-**
** Function BTM_BleUpdateAdvFilterPolicy
**
** Description This function update the filter policy of advertiser.
gatt_deregister_bgdev_list(gatt_if);
/* update the listen mode */
#if (BLE_PERIPHERAL_MODE_SUPPORT == TRUE)
- GATT_Listen(gatt_if, false, NULL);
+ GATT_Listen(false);
#endif
memset (p_reg, 0, sizeof(tGATT_REG));
else
{
if (transport == BT_TRANSPORT_LE)
- status = gatt_update_auto_connect_dev(gatt_if,true, bd_addr, true);
+ status = gatt_update_auto_connect_dev(gatt_if,true, bd_addr);
else
{
GATT_TRACE_ERROR("Unsupported transport for background connection");
** Description This function start or stop LE advertisement and listen for
** connection.
**
-** Parameters gatt_if: applicaiton interface
-** p_bd_addr: listen for specific address connection, or NULL for
-** listen to all device connection.
-** start: start or stop listening.
-**
-** Returns true if advertisement is started; false if adv start failure.
+** Parameters start: start or stop listening.
**
*******************************************************************************/
-bool GATT_Listen (tGATT_IF gatt_if, bool start, BD_ADDR_PTR bd_addr)
+void GATT_Listen(bool start)
{
- tGATT_REG *p_reg;
-
- GATT_TRACE_API ("GATT_Listen gatt_if=%d", gatt_if);
-
- /* Make sure app is registered */
- if ((p_reg = gatt_get_regcb(gatt_if)) == NULL)
- {
- GATT_TRACE_ERROR("GATT_Listen - gatt_if =%d is not registered", gatt_if);
- return(false);
- }
-
- if (bd_addr != NULL)
- {
- gatt_update_auto_connect_dev(gatt_if,start, bd_addr, false);
- }
- else
- {
- p_reg->listening = start ? GATT_LISTEN_TO_ALL : GATT_LISTEN_TO_NONE;
- }
-
- return gatt_update_listen_mode();
+ GATT_TRACE_API("GATT_Listen start=%d", start);
+ gatt_update_listen_mode(start ? GATT_LISTEN_TO_ALL : GATT_LISTEN_TO_NONE);
}
#endif
typedef struct
{
tGATT_IF gatt_if[GATT_MAX_APPS];
- tGATT_IF listen_gif[GATT_MAX_APPS];
BD_ADDR remote_bda;
bool in_use;
}tGATT_BG_CONN_DEV;
extern void gatt_delete_dev_from_srv_chg_clt_list(BD_ADDR bd_addr);
extern tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind);
extern void gatt_free_srvc_db_buffer_app_id(tBT_UUID *p_app_id);
-extern bool gatt_update_listen_mode(void);
+extern void gatt_update_listen_mode(int listening);
extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb);
/* reserved handle list */
extern tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg);
/* for background connection */
-extern bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr, bool is_initiator);
+extern bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr);
extern bool gatt_is_bg_dev_for_app(tGATT_BG_CONN_DEV *p_dev, tGATT_IF gatt_if);
extern bool gatt_remove_bg_dev_for_app(tGATT_IF gatt_if, BD_ADDR bd_addr);
extern uint8_t gatt_get_num_apps_for_bg_dev(BD_ADDR bd_addr);
** Returns true if device added to the list; false failed
**
*******************************************************************************/
-bool gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr, bool is_initator)
+bool gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr)
{
tGATT_IF gatt_if = p_reg->gatt_if;
tGATT_BG_CONN_DEV *p_dev = NULL;
{
for (i = 0; i < GATT_MAX_APPS; i ++)
{
- if (is_initator)
+ if (p_dev->gatt_if[i] == gatt_if)
{
- if (p_dev->gatt_if[i] == gatt_if)
- {
- GATT_TRACE_ERROR("device already in iniator white list");
- return true;
- }
- else if (p_dev->gatt_if[i] == 0)
- {
- p_dev->gatt_if[i] = gatt_if;
- if (i == 0)
- ret = BTM_BleUpdateBgConnDev(true, bd_addr);
- else
- ret = true;
- break;
- }
+ GATT_TRACE_ERROR("device already in iniator white list");
+ return true;
}
- else
+ else if (p_dev->gatt_if[i] == 0)
{
- if (p_dev->listen_gif[i] == gatt_if)
- {
- GATT_TRACE_ERROR("device already in adv white list");
- return true;
- }
- else if (p_dev->listen_gif[i] == 0)
- {
- if (p_reg->listening == GATT_LISTEN_TO_ALL)
- p_reg->listening = GATT_LISTEN_TO_NONE;
-
- p_reg->listening ++;
- p_dev->listen_gif[i] = gatt_if;
-
- if (i == 0)
- ret = BTM_BleUpdateAdvWhitelist(true, bd_addr);
- else
- ret = true;
- break;
- }
+ p_dev->gatt_if[i] = gatt_if;
+ if (i == 0)
+ ret = BTM_BleUpdateBgConnDev(true, bd_addr);
+ else
+ ret = true;
+ break;
}
}
}
if (p_tcb)
gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false);
- status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr, true);
+ status = gatt_update_auto_connect_dev(gatt_if, false, bd_addr);
return status;
}
** Returns pointer to the device record
**
*******************************************************************************/
-bool gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr, bool is_initiator)
+bool gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr)
{
tGATT_IF gatt_if = p_reg->gatt_if;
tGATT_BG_CONN_DEV *p_dev = NULL;
return ret;
}
- for (i = 0; i < GATT_MAX_APPS && (p_dev->gatt_if[i] > 0 || p_dev->listen_gif[i]); i ++)
+ for (i = 0; i < GATT_MAX_APPS && (p_dev->gatt_if[i] > 0); i ++)
{
- if (is_initiator)
+ if (p_dev->gatt_if[i] == gatt_if)
{
- if (p_dev->gatt_if[i] == gatt_if)
- {
- p_dev->gatt_if[i] = 0;
- /* move all element behind one forward */
- for (j = i + 1; j < GATT_MAX_APPS; j ++)
- p_dev->gatt_if[j - 1] = p_dev->gatt_if[j];
+ p_dev->gatt_if[i] = 0;
+ /* move all element behind one forward */
+ for (j = i + 1; j < GATT_MAX_APPS; j ++)
+ p_dev->gatt_if[j - 1] = p_dev->gatt_if[j];
- if (p_dev->gatt_if[0] == 0)
- ret = BTM_BleUpdateBgConnDev(false, p_dev->remote_bda);
- else
- ret = true;
+ if (p_dev->gatt_if[0] == 0)
+ ret = BTM_BleUpdateBgConnDev(false, p_dev->remote_bda);
+ else
+ ret = true;
- break;
- }
- }
- else
- {
- if (p_dev->listen_gif[i] == gatt_if)
- {
- p_dev->listen_gif[i] = 0;
- p_reg->listening --;
- /* move all element behind one forward */
- for (j = i + 1; j < GATT_MAX_APPS; j ++)
- p_dev->listen_gif[j - 1] = p_dev->listen_gif[j];
-
- if (p_dev->listen_gif[0] == 0)
- ret = BTM_BleUpdateAdvWhitelist(false, p_dev->remote_bda);
- else
- ret = true;
- break;
- }
+ break;
}
}
- if (i != GATT_MAX_APPS && p_dev->gatt_if[0] == 0 && p_dev->listen_gif[0] == 0)
+ if (i != GATT_MAX_APPS && p_dev->gatt_if[0] == 0)
{
memset(p_dev, 0, sizeof(tGATT_BG_CONN_DEV));
}
{
tGATT_BG_CONN_DEV *p_dev_list = &gatt_cb.bgconn_dev[0];
uint8_t i , j, k;
- tGATT_REG *p_reg = gatt_get_regcb(gatt_if);
/* update the BG conn device list */
for (i = 0 ; i <GATT_MAX_BG_CONN_DEV; i ++, p_dev_list ++ )
{
for (j = 0; j < GATT_MAX_APPS; j ++)
{
- if (p_dev_list->gatt_if[j] == 0 && p_dev_list->listen_gif[j] == 0)
+ if (p_dev_list->gatt_if[j] == 0)
break;
if (p_dev_list->gatt_if[j] == gatt_if)
if (p_dev_list->gatt_if[0] == 0)
BTM_BleUpdateBgConnDev(false, p_dev_list->remote_bda);
}
-
- if (p_dev_list->listen_gif[j] == gatt_if)
- {
- p_dev_list->listen_gif[j] = 0;
-
- if (p_reg != NULL && p_reg->listening > 0)
- p_reg->listening --;
-
- /* move all element behind one forward */
- for (k = j + 1; k < GATT_MAX_APPS; k ++)
- p_dev_list->listen_gif[k - 1] = p_dev_list->listen_gif[k];
-
- if (p_dev_list->listen_gif[0] == 0)
- BTM_BleUpdateAdvWhitelist(false, p_dev_list->remote_bda);
- }
}
}
}
** Returns true if connection started; false if connection start failure.
**
*******************************************************************************/
-bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr, bool is_initator)
+bool gatt_update_auto_connect_dev (tGATT_IF gatt_if, bool add, BD_ADDR bd_addr)
{
bool ret = false;
tGATT_REG *p_reg;
if (add)
{
- ret = gatt_add_bg_dev_list(p_reg, bd_addr, is_initator);
+ ret = gatt_add_bg_dev_list(p_reg, bd_addr);
if (ret && p_tcb != NULL)
{
}
else
{
- ret = gatt_remove_bg_dev_from_list(p_reg, bd_addr, is_initator);
+ ret = gatt_remove_bg_dev_from_list(p_reg, bd_addr);
}
return ret;
}
** Returns Pointer to the new service start buffer, NULL no buffer available
**
*******************************************************************************/
-bool gatt_update_listen_mode(void)
+void gatt_update_listen_mode(int listening)
{
- uint8_t ii = 0;
- tGATT_REG *p_reg = &gatt_cb.cl_rcb[0];
- uint8_t listening = 0;
uint16_t connectability, window, interval;
- bool rt = true;
- for (; ii < GATT_MAX_APPS; ii ++, p_reg ++)
+ connectability = BTM_ReadConnectability(&window, &interval);
+
+ if (listening != GATT_LISTEN_TO_NONE)
{
- if ( p_reg->in_use && p_reg->listening > listening)
- {
- listening = p_reg->listening;
- }
+ connectability |= BTM_BLE_CONNECTABLE;
}
-
- if (listening == GATT_LISTEN_TO_ALL ||
- listening == GATT_LISTEN_TO_NONE)
- BTM_BleUpdateAdvFilterPolicy (AP_SCAN_CONN_ALL);
else
- BTM_BleUpdateAdvFilterPolicy (AP_SCAN_CONN_WL);
-
- if (rt)
{
- connectability = BTM_ReadConnectability (&window, &interval);
-
- if (listening != GATT_LISTEN_TO_NONE)
- {
- connectability |= BTM_BLE_CONNECTABLE;
- }
- else
- {
- if ((connectability & BTM_BLE_CONNECTABLE) == 0)
- connectability &= ~BTM_BLE_CONNECTABLE;
- }
- /* turning on the adv now */
- btm_ble_set_connectability(connectability);
+ if ((connectability & BTM_BLE_CONNECTABLE) == 0)
+ connectability &= ~BTM_BLE_CONNECTABLE;
}
-
- return rt;
-
+ /* turning on the adv now */
+ btm_ble_set_connectability(connectability);
}
#endif
/*******************************************************************************
**
-** Function BTM_BleUpdateAdvWhitelist
-**
-** Description Add or remove device from advertising white list
-**
-** Returns void
-**
-*******************************************************************************/
-extern bool BTM_BleUpdateAdvWhitelist(bool add_remove, BD_ADDR emote_bda);
-
-/*******************************************************************************
-**
** Function BTM_BleUpdateAdvFilterPolicy
**
** Description This function update the filter policy of advertiser.
** Description This function start or stop LE advertisement and listen for
** connection.
**
-** Parameters gatt_if: applicaiton interface
-** p_bd_addr: listen for specific address connection, or NULL for
-** listen to all device connection.
-** start: is a direct conenection or a background auto connection
+** Parameters start: is a direct conenection or a background auto connection
**
-** Returns true if advertisement is started; false if adv start failure.
**
*******************************************************************************/
-extern bool GATT_Listen (tGATT_IF gatt_if, bool start, BD_ADDR_PTR bd_addr);
+extern void GATT_Listen(bool start);
/*******************************************************************************
**