• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

修訂db6e80ee6fd6c7242be6d396aa1f848de2719650 (tree)
時間2013-08-14 17:15:37
作者Matthew Xie <mattx@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge "LE: Add peripheral role support (2/4)" into klp-dev

Change Summary

差異

--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -4960,6 +4960,37 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data)
49604960 BTM_BleObserve(FALSE, 0, NULL,NULL );
49614961 }
49624962 }
4963+/*******************************************************************************
4964+**
4965+** Function bta_dm_ble_set_scan_params
4966+**
4967+** Description This function set the adv parameters.
4968+**
4969+** Parameters:
4970+**
4971+*******************************************************************************/
4972+void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data)
4973+{
4974+ BTM_BleSetAdvParams(p_data->ble_set_adv_params.adv_int_min,
4975+ p_data->ble_set_adv_params.adv_int_max,
4976+ p_data->ble_set_adv_params.p_dir_bda,
4977+ BTA_DM_BLE_ADV_CHNL_MAP);
4978+}
4979+/*******************************************************************************
4980+**
4981+** Function bta_dm_ble_set_adv_config
4982+**
4983+** Description This function set the customized ADV data configuration
4984+**
4985+** Parameters:
4986+**
4987+*******************************************************************************/
4988+void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data)
4989+{
4990+ BTM_BleWriteAdvData(p_data->ble_set_adv_data.data_mask,
4991+ (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg);
4992+}
4993+
49634994
49644995 #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
49654996 #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -1447,6 +1447,72 @@ void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window )
14471447
14481448 /*******************************************************************************
14491449 **
1450+** Function BTA_DmSetBleAdvParams
1451+**
1452+** Description This function sets the advertising parameters BLE functionality.
1453+** It is to be called when device act in peripheral or broadcaster
1454+** role.
1455+**
1456+**
1457+** Returns void
1458+**
1459+*******************************************************************************/
1460+void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
1461+ tBLE_BD_ADDR *p_dir_bda)
1462+{
1463+#if BLE_INCLUDED == TRUE
1464+ tBTA_DM_API_BLE_ADV_PARAMS *p_msg;
1465+
1466+ APPL_TRACE_API2 ("BTA_DmSetBleAdvParam: %d, %d", adv_int_min, adv_int_max);
1467+
1468+ if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS))) != NULL)
1469+ {
1470+ memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS));
1471+
1472+ p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
1473+
1474+ p_msg->adv_int_min = adv_int_min;
1475+ p_msg->adv_int_max = adv_int_max;
1476+
1477+ if (p_dir_bda != NULL)
1478+ {
1479+ p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
1480+ memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
1481+ }
1482+
1483+ bta_sys_sendmsg(p_msg);
1484+ }
1485+#endif
1486+}
1487+
1488+#if BLE_INCLUDED == TRUE
1489+/*******************************************************************************
1490+**
1491+** Function BTA_DmBleSetAdvConfig
1492+**
1493+** Description This function is called to override the BTA default ADV parameters.
1494+**
1495+** Parameters Pointer to User defined ADV data structure
1496+**
1497+** Returns None
1498+**
1499+*******************************************************************************/
1500+void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg)
1501+{
1502+ tBTA_DM_API_SET_ADV_CONFIG *p_msg;
1503+
1504+ if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL)
1505+ {
1506+ p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
1507+ p_msg->data_mask = data_mask;
1508+ p_msg->p_adv_cfg = p_adv_cfg;
1509+
1510+ bta_sys_sendmsg(p_msg);
1511+ }
1512+}
1513+#endif
1514+/*******************************************************************************
1515+**
14501516 ** Function BTA_DmBleSetBgConnType
14511517 **
14521518 ** Description This function is called to set BLE connectable mode for a
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -99,6 +99,8 @@ enum
9999 BTA_DM_API_BLE_CONN_PARAM_EVT,
100100 BTA_DM_API_BLE_SCAN_PARAM_EVT,
101101 BTA_DM_API_BLE_OBSERVE_EVT,
102+ BTA_DM_API_BLE_ADV_PARAM_EVT,
103+ BTA_DM_API_BLE_SET_ADV_CONFIG_EVT,
102104 #endif
103105
104106 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
@@ -862,9 +864,6 @@ extern const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl[];
862864 extern const tBTA_DM_CFG bta_dm_cfg;
863865
864866
865-
866-#define BTA_ALL_APP_ID 0xff
867-
868867 typedef struct
869868 {
870869 UINT8 id;
@@ -995,6 +994,9 @@ extern void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data);
995994 extern void bta_dm_ble_set_scan_params (tBTA_DM_MSG *p_data);
996995 extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data);
997996 extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data);
997+extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data);
998+extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data);
999+
9981000 #endif
9991001 extern void bta_dm_set_encryption(tBTA_DM_MSG *p_data);
10001002 extern void bta_dm_confirm(tBTA_DM_MSG *p_data);
--- a/bta/dm/bta_dm_main.c
+++ b/bta/dm/bta_dm_main.c
@@ -96,6 +96,8 @@ const tBTA_DM_ACTION bta_dm_action[] =
9696 bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */
9797 bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
9898 bta_dm_ble_observe,
99+ bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
100+ bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */
99101 #endif
100102
101103 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -1948,6 +1948,99 @@ void bta_gattc_init_clcb_conn(UINT8 cif, BD_ADDR remote_bda)
19481948 APPL_TRACE_ERROR0("No resources");
19491949 }
19501950 }
1951+/*******************************************************************************
1952+**
1953+** Function bta_gattc_process_listen_all
1954+**
1955+** Description process listen all, send open callback to application for all
1956+** connected slave LE link.
1957+**
1958+** Returns void
1959+**
1960+********************************************************************************/
1961+void bta_gattc_process_listen_all(UINT8 cif)
1962+{
1963+ UINT8 i_conn = 0;
1964+ tBTA_GATTC_CONN *p_conn = &bta_gattc_cb.conn_track[0];
1965+
1966+ for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++)
1967+ {
1968+ if (p_conn->in_use )
1969+ {
1970+ if (bta_gattc_find_clcb_by_cif(cif, p_conn->remote_bda) == NULL)
1971+ {
1972+ bta_gattc_init_clcb_conn(cif, p_conn->remote_bda);
1973+ }
1974+ /* else already connected */
1975+ }
1976+ }
1977+}
1978+/*******************************************************************************
1979+**
1980+** Function bta_gattc_listen
1981+**
1982+** Description Start or stop a listen for connection
1983+**
1984+** Returns void
1985+**
1986+********************************************************************************/
1987+void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
1988+{
1989+ tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
1990+ tBTA_GATTC cb_data;
1991+ cb_data.reg_oper.status = BTA_GATT_ERROR;
1992+ cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
1993+
1994+ if (p_clreg == NULL)
1995+ {
1996+ APPL_TRACE_ERROR1("bta_gattc_listen failed, unknown client_if: %d",
1997+ p_msg->api_listen.client_if);
1998+ return;
1999+ }
2000+ /* mark bg conn record */
2001+ if (bta_gattc_mark_bg_conn(p_msg->api_listen.client_if,
2002+ (BD_ADDR_PTR) p_msg->api_listen.remote_bda,
2003+ p_msg->api_listen.start,
2004+ TRUE))
2005+ {
2006+ if (!GATT_Listen(p_msg->api_listen.client_if,
2007+ p_msg->api_listen.start,
2008+ p_msg->api_listen.remote_bda))
2009+ {
2010+ APPL_TRACE_ERROR0("Listen failure");
2011+ (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
2012+ }
2013+ else
2014+ {
2015+ cb_data.status = BTA_GATT_OK;
2016+
2017+ (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
2018+
2019+ if (p_msg->api_listen.start)
2020+ {
2021+ /* if listen to a specific target */
2022+ if (p_msg->api_listen.remote_bda != NULL)
2023+ {
19512024
1952-#endif /* #if BLE_INCLUDED == TRUE */
1953-#endif /* BTA_GATT_INCLUDED */
2025+ /* if is a connected remote device */
2026+ if (L2CA_GetBleConnRole(p_msg->api_listen.remote_bda) == HCI_ROLE_SLAVE &&
2027+ bta_gattc_find_clcb_by_cif(p_msg->api_listen.client_if, p_msg->api_listen.remote_bda) == NULL)
2028+ {
2029+
2030+ bta_gattc_init_clcb_conn(p_msg->api_listen.client_if,
2031+ p_msg->api_listen.remote_bda);
2032+ }
2033+ }
2034+ /* if listen to all */
2035+ else
2036+ {
2037+ APPL_TRACE_ERROR0("Listen For All now");
2038+ /* go through all connected device and send callback for all connected slave connection */
2039+ bta_gattc_process_listen_all(p_msg->api_listen.client_if);
2040+ }
2041+ }
2042+ }
2043+ }
2044+}
2045+#endif
2046+#endif
--- a/bta/gatt/bta_gattc_api.c
+++ b/bta/gatt/bta_gattc_api.c
@@ -1017,5 +1017,44 @@ void BTA_GATTC_Refresh(BD_ADDR remote_bda)
10171017 }
10181018 return;
10191019 }
1020+
1021+/*******************************************************************************
1022+**
1023+** Function BTA_GATTC_Listen
1024+**
1025+** Description Start advertisement to listen for connection request for a GATT
1026+** client application.
1027+**
1028+** Parameters client_if: server interface.
1029+** start: to start or stop listening for connection
1030+** remote_bda: remote device BD address, if listen to all device
1031+** use NULL.
1032+**
1033+** Returns void
1034+**
1035+*******************************************************************************/
1036+void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda)
1037+{
1038+ tBTA_GATTC_API_LISTEN *p_buf;
1039+
1040+ if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL)
1041+ {
1042+ p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
1043+
1044+ p_buf->client_if = client_if;
1045+ p_buf->start = start;
1046+ if (target_bda)
1047+ {
1048+ p_buf->remote_bda = (UINT8*)(p_buf + 1);
1049+ memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
1050+ }
1051+ else
1052+ p_buf->remote_bda = NULL;
1053+
1054+ bta_sys_sendmsg(p_buf);
1055+ }
1056+ return;
1057+}
1058+
10201059 #endif /* BTA_GATT_INCLUDED */
10211060
--- a/bta/gatt/bta_gattc_int.h
+++ b/bta/gatt/bta_gattc_int.h
@@ -68,8 +68,8 @@ enum
6868 BTA_GATTC_INT_START_IF_EVT,
6969 BTA_GATTC_API_REG_EVT,
7070 BTA_GATTC_API_DEREG_EVT,
71+ BTA_GATTC_API_LISTEN_EVT,
7172 BTA_GATTC_API_DISABLE_EVT
72-
7373 };
7474 typedef UINT16 tBTA_GATTC_INT_EVT;
7575
@@ -181,6 +181,14 @@ typedef struct
181181 typedef struct
182182 {
183183 BT_HDR hdr;
184+ BD_ADDR_PTR remote_bda;
185+ tBTA_GATTC_IF client_if;
186+ BOOLEAN start;
187+} tBTA_GATTC_API_LISTEN;
188+
189+typedef struct
190+{
191+ BT_HDR hdr;
184192 BD_ADDR remote_bda;
185193 tBTA_GATTC_IF client_if;
186194 UINT8 role;
@@ -208,6 +216,8 @@ typedef union
208216
209217 tBTA_GATTC_INT_START_IF int_start_if;
210218 tBTA_GATTC_INT_DEREG int_dereg;
219+ /* if peripheral role is supported */
220+ tBTA_GATTC_API_LISTEN api_listen;
211221
212222 } tBTA_GATTC_DATA;
213223
@@ -462,7 +472,9 @@ extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
462472 extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
463473 BD_ADDR remote_bda, UINT16 conn_id);
464474 extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
465-
475+#if BLE_INCLUDED == TRUE
476+extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
477+#endif
466478 /* utility functions */
467479 extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda);
468480 extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_conn_id (UINT16 conn_id);
--- a/bta/gatt/bta_gattc_main.c
+++ b/bta/gatt/bta_gattc_main.c
@@ -381,6 +381,11 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
381381 bta_gattc_process_api_refresh(p_cb, (tBTA_GATTC_DATA *) p_msg);
382382 break;
383383
384+#if BLE_INCLUDED == TRUE
385+ case BTA_GATTC_API_LISTEN_EVT:
386+ bta_gattc_listen(p_cb, (tBTA_GATTC_DATA *) p_msg);
387+ break;
388+#endif
384389 default:
385390 if (p_msg->event == BTA_GATTC_INT_CONN_EVT)
386391 p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg);
@@ -472,6 +477,8 @@ static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
472477 return "BTA_GATTC_API_DEREG_EVT";
473478 case BTA_GATTC_API_REFRESH_EVT:
474479 return "BTA_GATTC_API_REFRESH_EVT";
480+ case BTA_GATTC_API_LISTEN_EVT:
481+ return "BTA_GATTC_API_LISTEN_EVT";
475482 case BTA_GATTC_API_DISABLE_EVT:
476483 return "BTA_GATTC_API_DISABLE_EVT";
477484 default:
--- a/bta/gatt/bta_gatts_act.c
+++ b/bta/gatt/bta_gatts_act.c
@@ -781,6 +781,39 @@ void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
781781 }
782782
783783 }
784+/*******************************************************************************
785+**
786+** Function bta_gatts_listen
787+**
788+** Description Start or stop listening for LE connection on a GATT server
789+**
790+** Returns none.
791+**
792+*******************************************************************************/
793+void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
794+{
795+ tBTA_GATTS_RCB *p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_listen.server_if);
796+ tBTA_GATTS cb_data;
797+ cb_data.reg_oper.status = BTA_GATT_OK;
798+ cb_data.reg_oper.server_if = p_msg->api_listen.server_if;
799+
800+ if (p_rcb == NULL)
801+ {
802+ APPL_TRACE_ERROR0("Unknown GATTS application");
803+ return;
804+ }
805+
806+ if (!GATT_Listen(p_msg->api_listen.server_if,
807+ p_msg->api_listen.start,
808+ p_msg->api_listen.remote_bda))
809+ {
810+ cb_data.status = BTA_GATT_ERROR;
811+ APPL_TRACE_ERROR0("bta_gatts_listen Listen failed");
812+ }
813+
814+ if (p_rcb->p_cback)
815+ (*p_rcb->p_cback)(BTA_GATTS_LISTEN_EVT, &cb_data);
816+}
784817
785818 /*******************************************************************************
786819 **
--- a/bta/gatt/bta_gatts_api.c
+++ b/bta/gatt/bta_gatts_api.c
@@ -538,5 +538,43 @@ void BTA_GATTS_Close(UINT16 conn_id)
538538 return;
539539
540540 }
541+/*******************************************************************************
542+**
543+** Function BTA_GATTS_Listen
544+**
545+** Description Start advertisement to listen for connection request for a
546+** GATT server
547+**
548+** Parameters server_if: server interface.
549+** start: to start or stop listening for connection
550+** remote_bda: remote device BD address, if listen to all device
551+** use NULL.
552+**
553+** Returns void
554+**
555+*******************************************************************************/
556+void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, BD_ADDR_PTR target_bda)
557+{
558+ tBTA_GATTS_API_LISTEN *p_buf;
559+
560+ if ((p_buf = (tBTA_GATTS_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL)
561+ {
562+ p_buf->hdr.event = BTA_GATTS_API_LISTEN_EVT;
563+
564+ p_buf->server_if = server_if;
565+ p_buf->start = start;
566+
567+ if (target_bda)
568+ {
569+ p_buf->remote_bda = (UINT8*)(p_buf + 1);
570+ memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
571+ }
572+ else
573+ p_buf->remote_bda = NULL;
574+
575+ bta_sys_sendmsg(p_buf);
576+ }
577+ return;
578+}
541579
542580 #endif /* BTA_GATT_INCLUDED */
--- a/bta/gatt/bta_gatts_main.c
+++ b/bta/gatt/bta_gatts_main.c
@@ -107,6 +107,11 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
107107 bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg);
108108 break;
109109
110+ case BTA_GATTS_API_LISTEN_EVT:
111+ bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg);
112+ break;
113+
114+
110115 case BTA_GATTS_API_ADD_INCL_SRVC_EVT:
111116 case BTA_GATTS_API_ADD_CHAR_EVT:
112117 case BTA_GATTS_API_ADD_DESCR_EVT:
--- a/bta/include/bta_api.h
+++ b/bta/include/bta_api.h
@@ -1767,6 +1767,23 @@ BTA_API extern void BTA_DmSetBleConnScanParams(UINT16 scan_interval,
17671767
17681768 /*******************************************************************************
17691769 **
1770+** Function BTA_DmSetBleAdvParams
1771+**
1772+** Description This function sets the advertising parameters BLE functionality.
1773+** It is to be called when device act in peripheral or broadcaster
1774+** role.
1775+**
1776+** Parameters: adv_int_min - adv interval minimum
1777+** adv_int_max - adv interval max
1778+** p_dir_bda - directed adv initator address
1779+**
1780+** Returns void
1781+**
1782+*******************************************************************************/
1783+BTA_API extern void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
1784+ tBLE_BD_ADDR *p_dir_bda);
1785+/*******************************************************************************
1786+**
17701787 ** Function BTA_DmSearchExt
17711788 **
17721789 ** Description This function searches for peer Bluetooth devices. It performs
--- a/bta/include/bta_gatt_api.h
+++ b/bta/include/bta_gatt_api.h
@@ -114,6 +114,7 @@ typedef UINT8 tBTA_GATT_STATUS;
114114 #define BTA_GATTC_ACL_EVT 13 /* ACL up event */
115115 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
116116 #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */
117+#define BTA_GATTC_LISTEN_EVT 16 /* listen event */
117118
118119 typedef UINT8 tBTA_GATTC_EVT;
119120
@@ -392,6 +393,7 @@ typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
392393 #define BTA_GATTS_OPEN_EVT 16
393394 #define BTA_GATTS_CANCEL_OPEN_EVT 17
394395 #define BTA_GATTS_CLOSE_EVT 18
396+#define BTA_GATTS_LISTEN_EVT 19
395397
396398 typedef UINT8 tBTA_GATTS_EVT;
397399 typedef tGATT_IF tBTA_GATTS_IF;
@@ -1005,6 +1007,22 @@ BTA_API extern void BTA_GATTC_Refresh(BD_ADDR remote_bda);
10051007
10061008
10071009 /*******************************************************************************
1010+**
1011+** Function BTA_GATTC_Listen
1012+**
1013+** Description Start advertisement to listen for connection request.
1014+**
1015+** Parameters client_if: server interface.
1016+** start: to start or stop listening for connection
1017+** remote_bda: remote device BD address, if listen to all device
1018+** use NULL.
1019+**
1020+** Returns void
1021+**
1022+*******************************************************************************/
1023+BTA_API extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda);
1024+
1025+/*******************************************************************************
10081026 ** BTA GATT Server API
10091027 ********************************************************************************/
10101028
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -961,6 +961,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
961961 {
962962 bt_property_t properties[5];
963963 bt_device_type_t dev_type;
964+ UINT8 addr_type;
964965 uint32_t num_properties = 0;
965966 bt_status_t status;
966967
@@ -971,7 +972,8 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
971972 num_properties++;
972973 /* BD_NAME */
973974 /* Don't send BDNAME if it is empty */
974- if (bdname.name[0]) {
975+ if (bdname.name[0])
976+ {
975977 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
976978 BT_PROPERTY_BDNAME,
977979 strlen((char *)bdname.name), &bdname);
@@ -983,9 +985,10 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
983985 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
984986 num_properties++;
985987 /* DEV_TYPE */
986-#if (BLE_INCLUDED == TRUE)
988+#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
987989 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
988990 dev_type = p_search_data->inq_res.device_type;
991+ addr_type = p_search_data->inq_res.ble_addr_type;
989992 #else
990993 dev_type = BT_DEVICE_TYPE_BREDR;
991994 #endif
@@ -1000,7 +1003,10 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
10001003
10011004 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
10021005 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
1003-
1006+#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1007+ status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1008+ ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1009+#endif
10041010 /* Callback to notify upper layer of device */
10051011 HAL_CBACK(bt_hal_cbacks, device_found_cb,
10061012 num_properties, properties);
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -55,6 +55,8 @@
5555 ** Constants & Macros
5656 ********************************************************************************/
5757
58+#define ADV_FLAGS 0x02
59+
5860 #define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\
5961 {\
6062 ALOGW("%s: BTGATT not initialized", __FUNCTION__);\
@@ -86,7 +88,9 @@ typedef enum {
8688 BTIF_GATTC_REG_FOR_NOTIFICATION,
8789 BTIF_GATTC_DEREG_FOR_NOTIFICATION,
8890 BTIF_GATTC_REFRESH,
89- BTIF_GATTC_READ_RSSI
91+ BTIF_GATTC_READ_RSSI,
92+ BTIF_GATTC_LISTEN,
93+ BTIF_GATTC_SET_ADV_DATA
9094 } btif_gattc_event_t;
9195
9296 #define BTIF_GATT_MAX_OBSERVED_DEV 40
@@ -100,7 +104,14 @@ typedef enum {
100104
101105 typedef struct
102106 {
107+ tBTM_BLE_AD_MASK mask;
108+ tBTM_BLE_ADV_DATA data;
109+} btgatt_adv_data;
110+
111+typedef struct
112+{
103113 uint8_t value[BTGATT_MAX_ATTR_LEN];
114+ btgatt_adv_data adv_data;
104115 bt_bdaddr_t bd_addr;
105116 btgatt_srvc_id_t srvc_id;
106117 btgatt_srvc_id_t incl_srvc_id;
@@ -117,6 +128,7 @@ typedef struct
117128 uint8_t write_type;
118129 uint8_t status;
119130 uint8_t addr_type;
131+ uint8_t start;
120132 int8_t rssi;
121133 tBT_DEVICE_TYPE device_type;
122134 } __attribute__((packed)) btif_gattc_cb_t;
@@ -469,6 +481,14 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param)
469481 break;
470482 }
471483
484+ case BTA_GATTC_LISTEN_EVT:
485+ {
486+ HAL_CBACK(bt_gatt_callbacks, client->listen_cb
487+ , p_data->reg_oper.status
488+ , p_data->reg_oper.client_if
489+ );
490+ break;
491+ }
472492 default:
473493 ALOGE("%s: Unhandled event (%d)!", __FUNCTION__, event);
474494 break;
@@ -786,6 +806,21 @@ static void btgattc_handle_event(uint16_t event, char* p_param)
786806 BTM_ReadRSSI (p_cb->bd_addr.address, (tBTM_CMPL_CB *)btm_read_rssi_cb);
787807 break;
788808
809+ case BTIF_GATTC_LISTEN:
810+ BTA_GATTC_Listen(p_cb->client_if, p_cb->start, NULL);
811+ break;
812+
813+ case BTIF_GATTC_SET_ADV_DATA:
814+ {
815+ if (p_cb->start == 0)
816+ BTM_BleWriteAdvData(p_cb->adv_data.mask, &p_cb->adv_data.data);
817+ else
818+ BTM_BleWriteScanRsp(p_cb->adv_data.mask, &p_cb->adv_data.data);
819+ if (p_cb->adv_data.data.manu.p_val != NULL)
820+ GKI_freebuf(p_cb->adv_data.data.manu.p_val);
821+ break;
822+ }
823+
789824 default:
790825 ALOGE("%s: Unknown event (%d)!", __FUNCTION__, event);
791826 break;
@@ -845,6 +880,68 @@ static bt_status_t btif_gattc_close( int client_if, const bt_bdaddr_t *bd_addr,
845880 (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
846881 }
847882
883+static bt_status_t btif_gattc_listen(int client_if, bool start)
884+{
885+ CHECK_BTGATT_INIT();
886+ btif_gattc_cb_t btif_cb;
887+ btif_cb.client_if = (uint8_t) client_if;
888+ btif_cb.start = start ? 1 : 0;
889+ return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_LISTEN,
890+ (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
891+}
892+
893+static bt_status_t btif_gattc_set_adv_data(int client_if, bool set_scan_rsp, bool include_name,
894+ bool include_txpower, int min_interval, int max_interval, int appearance,
895+ uint16_t manufacturer_len, char* manufacturer_data)
896+{
897+ CHECK_BTGATT_INIT();
898+ btif_gattc_cb_t btif_cb;
899+ memset(&btif_cb, 0, sizeof(btif_gattc_cb_t));
900+ memset(&btif_cb.adv_data, 0, sizeof(btgatt_adv_data));
901+
902+ btif_cb.client_if = (uint8_t) client_if;
903+ btif_cb.start = set_scan_rsp ? 1 : 0;
904+
905+ if (!set_scan_rsp)
906+ {
907+ btif_cb.adv_data.mask = BTM_BLE_AD_BIT_FLAGS;
908+ btif_cb.adv_data.data.flag = ADV_FLAGS;
909+ }
910+
911+ if (include_name)
912+ btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_DEV_NAME;
913+
914+ if (include_txpower)
915+ btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_TX_PWR;
916+
917+ if (min_interval > 0 && max_interval > 0 && max_interval > min_interval)
918+ {
919+ btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_INT_RANGE;
920+ btif_cb.adv_data.data.int_range.low = min_interval;
921+ btif_cb.adv_data.data.int_range.hi = max_interval;
922+ }
923+
924+ if (appearance != 0)
925+ {
926+ btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_APPEARANCE;
927+ btif_cb.adv_data.data.appearance = appearance;
928+ }
929+
930+ if (manufacturer_len > 0 && manufacturer_data != NULL)
931+ {
932+ btif_cb.adv_data.data.manu.p_val = GKI_getbuf(manufacturer_len);
933+ if (btif_cb.adv_data.data.manu.p_val != NULL)
934+ {
935+ btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_MANU;
936+ btif_cb.adv_data.data.manu.len = manufacturer_len;
937+ memcpy(btif_cb.adv_data.data.manu.p_val, manufacturer_data, manufacturer_len);
938+ }
939+ }
940+
941+ return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_SET_ADV_DATA,
942+ (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
943+}
944+
848945 static bt_status_t btif_gattc_refresh( int client_if, const bt_bdaddr_t *bd_addr )
849946 {
850947 CHECK_BTGATT_INIT();
@@ -1060,6 +1157,7 @@ const btgatt_client_interface_t btgattClientInterface = {
10601157 btif_gattc_scan,
10611158 btif_gattc_open,
10621159 btif_gattc_close,
1160+ btif_gattc_listen,
10631161 btif_gattc_refresh,
10641162 btif_gattc_search_service,
10651163 btif_gattc_get_included_service,
@@ -1074,6 +1172,7 @@ const btgatt_client_interface_t btgattClientInterface = {
10741172 btif_gattc_dereg_for_notification,
10751173 btif_gattc_read_remote_rssi,
10761174 btif_gattc_get_device_type,
1175+ btif_gattc_set_adv_data,
10771176 btif_gattc_test_command
10781177 };
10791178