system/bt
修订版 | db6e80ee6fd6c7242be6d396aa1f848de2719650 (tree) |
---|---|
时间 | 2013-08-14 17:15:37 |
作者 | Matthew Xie <mattx@goog...> |
Commiter | Android (Google) Code Review |
Merge "LE: Add peripheral role support (2/4)" into klp-dev
@@ -4960,6 +4960,37 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data) | ||
4960 | 4960 | BTM_BleObserve(FALSE, 0, NULL,NULL ); |
4961 | 4961 | } |
4962 | 4962 | } |
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 | + | |
4963 | 4994 | |
4964 | 4995 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
4965 | 4996 | #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT |
@@ -1447,6 +1447,72 @@ void BTA_DmSetBleConnScanParams(UINT16 scan_interval, UINT16 scan_window ) | ||
1447 | 1447 | |
1448 | 1448 | /******************************************************************************* |
1449 | 1449 | ** |
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 | +** | |
1450 | 1516 | ** Function BTA_DmBleSetBgConnType |
1451 | 1517 | ** |
1452 | 1518 | ** Description This function is called to set BLE connectable mode for a |
@@ -99,6 +99,8 @@ enum | ||
99 | 99 | BTA_DM_API_BLE_CONN_PARAM_EVT, |
100 | 100 | BTA_DM_API_BLE_SCAN_PARAM_EVT, |
101 | 101 | BTA_DM_API_BLE_OBSERVE_EVT, |
102 | + BTA_DM_API_BLE_ADV_PARAM_EVT, | |
103 | + BTA_DM_API_BLE_SET_ADV_CONFIG_EVT, | |
102 | 104 | #endif |
103 | 105 | |
104 | 106 | #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[]; | ||
862 | 864 | extern const tBTA_DM_CFG bta_dm_cfg; |
863 | 865 | |
864 | 866 | |
865 | - | |
866 | -#define BTA_ALL_APP_ID 0xff | |
867 | - | |
868 | 867 | typedef struct |
869 | 868 | { |
870 | 869 | UINT8 id; |
@@ -995,6 +994,9 @@ extern void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data); | ||
995 | 994 | extern void bta_dm_ble_set_scan_params (tBTA_DM_MSG *p_data); |
996 | 995 | extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data); |
997 | 996 | 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 | + | |
998 | 1000 | #endif |
999 | 1001 | extern void bta_dm_set_encryption(tBTA_DM_MSG *p_data); |
1000 | 1002 | extern void bta_dm_confirm(tBTA_DM_MSG *p_data); |
@@ -96,6 +96,8 @@ const tBTA_DM_ACTION bta_dm_action[] = | ||
96 | 96 | bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */ |
97 | 97 | bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */ |
98 | 98 | 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 */ | |
99 | 101 | #endif |
100 | 102 | |
101 | 103 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
@@ -1948,6 +1948,99 @@ void bta_gattc_init_clcb_conn(UINT8 cif, BD_ADDR remote_bda) | ||
1948 | 1948 | APPL_TRACE_ERROR0("No resources"); |
1949 | 1949 | } |
1950 | 1950 | } |
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 | + { | |
1951 | 2024 | |
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 |
@@ -1017,5 +1017,44 @@ void BTA_GATTC_Refresh(BD_ADDR remote_bda) | ||
1017 | 1017 | } |
1018 | 1018 | return; |
1019 | 1019 | } |
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 | + | |
1020 | 1059 | #endif /* BTA_GATT_INCLUDED */ |
1021 | 1060 |
@@ -68,8 +68,8 @@ enum | ||
68 | 68 | BTA_GATTC_INT_START_IF_EVT, |
69 | 69 | BTA_GATTC_API_REG_EVT, |
70 | 70 | BTA_GATTC_API_DEREG_EVT, |
71 | + BTA_GATTC_API_LISTEN_EVT, | |
71 | 72 | BTA_GATTC_API_DISABLE_EVT |
72 | - | |
73 | 73 | }; |
74 | 74 | typedef UINT16 tBTA_GATTC_INT_EVT; |
75 | 75 |
@@ -181,6 +181,14 @@ typedef struct | ||
181 | 181 | typedef struct |
182 | 182 | { |
183 | 183 | 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; | |
184 | 192 | BD_ADDR remote_bda; |
185 | 193 | tBTA_GATTC_IF client_if; |
186 | 194 | UINT8 role; |
@@ -208,6 +216,8 @@ typedef union | ||
208 | 216 | |
209 | 217 | tBTA_GATTC_INT_START_IF int_start_if; |
210 | 218 | tBTA_GATTC_INT_DEREG int_dereg; |
219 | + /* if peripheral role is supported */ | |
220 | + tBTA_GATTC_API_LISTEN api_listen; | |
211 | 221 | |
212 | 222 | } tBTA_GATTC_DATA; |
213 | 223 |
@@ -462,7 +472,9 @@ extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data); | ||
462 | 472 | extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status, |
463 | 473 | BD_ADDR remote_bda, UINT16 conn_id); |
464 | 474 | 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 | |
466 | 478 | /* utility functions */ |
467 | 479 | extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda); |
468 | 480 | extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_conn_id (UINT16 conn_id); |
@@ -381,6 +381,11 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) | ||
381 | 381 | bta_gattc_process_api_refresh(p_cb, (tBTA_GATTC_DATA *) p_msg); |
382 | 382 | break; |
383 | 383 | |
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 | |
384 | 389 | default: |
385 | 390 | if (p_msg->event == BTA_GATTC_INT_CONN_EVT) |
386 | 391 | 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) | ||
472 | 477 | return "BTA_GATTC_API_DEREG_EVT"; |
473 | 478 | case BTA_GATTC_API_REFRESH_EVT: |
474 | 479 | return "BTA_GATTC_API_REFRESH_EVT"; |
480 | + case BTA_GATTC_API_LISTEN_EVT: | |
481 | + return "BTA_GATTC_API_LISTEN_EVT"; | |
475 | 482 | case BTA_GATTC_API_DISABLE_EVT: |
476 | 483 | return "BTA_GATTC_API_DISABLE_EVT"; |
477 | 484 | default: |
@@ -781,6 +781,39 @@ void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) | ||
781 | 781 | } |
782 | 782 | |
783 | 783 | } |
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 | +} | |
784 | 817 | |
785 | 818 | /******************************************************************************* |
786 | 819 | ** |
@@ -538,5 +538,43 @@ void BTA_GATTS_Close(UINT16 conn_id) | ||
538 | 538 | return; |
539 | 539 | |
540 | 540 | } |
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 | +} | |
541 | 579 | |
542 | 580 | #endif /* BTA_GATT_INCLUDED */ |
@@ -107,6 +107,11 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg) | ||
107 | 107 | bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg); |
108 | 108 | break; |
109 | 109 | |
110 | + case BTA_GATTS_API_LISTEN_EVT: | |
111 | + bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg); | |
112 | + break; | |
113 | + | |
114 | + | |
110 | 115 | case BTA_GATTS_API_ADD_INCL_SRVC_EVT: |
111 | 116 | case BTA_GATTS_API_ADD_CHAR_EVT: |
112 | 117 | case BTA_GATTS_API_ADD_DESCR_EVT: |
@@ -1767,6 +1767,23 @@ BTA_API extern void BTA_DmSetBleConnScanParams(UINT16 scan_interval, | ||
1767 | 1767 | |
1768 | 1768 | /******************************************************************************* |
1769 | 1769 | ** |
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 | +** | |
1770 | 1787 | ** Function BTA_DmSearchExt |
1771 | 1788 | ** |
1772 | 1789 | ** Description This function searches for peer Bluetooth devices. It performs |
@@ -114,6 +114,7 @@ typedef UINT8 tBTA_GATT_STATUS; | ||
114 | 114 | #define BTA_GATTC_ACL_EVT 13 /* ACL up event */ |
115 | 115 | #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ |
116 | 116 | #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */ |
117 | +#define BTA_GATTC_LISTEN_EVT 16 /* listen event */ | |
117 | 118 | |
118 | 119 | typedef UINT8 tBTA_GATTC_EVT; |
119 | 120 |
@@ -392,6 +393,7 @@ typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); | ||
392 | 393 | #define BTA_GATTS_OPEN_EVT 16 |
393 | 394 | #define BTA_GATTS_CANCEL_OPEN_EVT 17 |
394 | 395 | #define BTA_GATTS_CLOSE_EVT 18 |
396 | +#define BTA_GATTS_LISTEN_EVT 19 | |
395 | 397 | |
396 | 398 | typedef UINT8 tBTA_GATTS_EVT; |
397 | 399 | typedef tGATT_IF tBTA_GATTS_IF; |
@@ -1005,6 +1007,22 @@ BTA_API extern void BTA_GATTC_Refresh(BD_ADDR remote_bda); | ||
1005 | 1007 | |
1006 | 1008 | |
1007 | 1009 | /******************************************************************************* |
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 | +/******************************************************************************* | |
1008 | 1026 | ** BTA GATT Server API |
1009 | 1027 | ********************************************************************************/ |
1010 | 1028 |
@@ -961,6 +961,7 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
961 | 961 | { |
962 | 962 | bt_property_t properties[5]; |
963 | 963 | bt_device_type_t dev_type; |
964 | + UINT8 addr_type; | |
964 | 965 | uint32_t num_properties = 0; |
965 | 966 | bt_status_t status; |
966 | 967 |
@@ -971,7 +972,8 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
971 | 972 | num_properties++; |
972 | 973 | /* BD_NAME */ |
973 | 974 | /* Don't send BDNAME if it is empty */ |
974 | - if (bdname.name[0]) { | |
975 | + if (bdname.name[0]) | |
976 | + { | |
975 | 977 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
976 | 978 | BT_PROPERTY_BDNAME, |
977 | 979 | strlen((char *)bdname.name), &bdname); |
@@ -983,9 +985,10 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
983 | 985 | BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); |
984 | 986 | num_properties++; |
985 | 987 | /* DEV_TYPE */ |
986 | -#if (BLE_INCLUDED == TRUE) | |
988 | +#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) | |
987 | 989 | /* FixMe: Assumption is that bluetooth.h and BTE enums match */ |
988 | 990 | dev_type = p_search_data->inq_res.device_type; |
991 | + addr_type = p_search_data->inq_res.ble_addr_type; | |
989 | 992 | #else |
990 | 993 | dev_type = BT_DEVICE_TYPE_BREDR; |
991 | 994 | #endif |
@@ -1000,7 +1003,10 @@ static void btif_dm_search_devices_evt (UINT16 event, char *p_param) | ||
1000 | 1003 | |
1001 | 1004 | status = btif_storage_add_remote_device(&bdaddr, num_properties, properties); |
1002 | 1005 | 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 | |
1004 | 1010 | /* Callback to notify upper layer of device */ |
1005 | 1011 | HAL_CBACK(bt_hal_cbacks, device_found_cb, |
1006 | 1012 | num_properties, properties); |
@@ -55,6 +55,8 @@ | ||
55 | 55 | ** Constants & Macros |
56 | 56 | ********************************************************************************/ |
57 | 57 | |
58 | +#define ADV_FLAGS 0x02 | |
59 | + | |
58 | 60 | #define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\ |
59 | 61 | {\ |
60 | 62 | ALOGW("%s: BTGATT not initialized", __FUNCTION__);\ |
@@ -86,7 +88,9 @@ typedef enum { | ||
86 | 88 | BTIF_GATTC_REG_FOR_NOTIFICATION, |
87 | 89 | BTIF_GATTC_DEREG_FOR_NOTIFICATION, |
88 | 90 | BTIF_GATTC_REFRESH, |
89 | - BTIF_GATTC_READ_RSSI | |
91 | + BTIF_GATTC_READ_RSSI, | |
92 | + BTIF_GATTC_LISTEN, | |
93 | + BTIF_GATTC_SET_ADV_DATA | |
90 | 94 | } btif_gattc_event_t; |
91 | 95 | |
92 | 96 | #define BTIF_GATT_MAX_OBSERVED_DEV 40 |
@@ -100,7 +104,14 @@ typedef enum { | ||
100 | 104 | |
101 | 105 | typedef struct |
102 | 106 | { |
107 | + tBTM_BLE_AD_MASK mask; | |
108 | + tBTM_BLE_ADV_DATA data; | |
109 | +} btgatt_adv_data; | |
110 | + | |
111 | +typedef struct | |
112 | +{ | |
103 | 113 | uint8_t value[BTGATT_MAX_ATTR_LEN]; |
114 | + btgatt_adv_data adv_data; | |
104 | 115 | bt_bdaddr_t bd_addr; |
105 | 116 | btgatt_srvc_id_t srvc_id; |
106 | 117 | btgatt_srvc_id_t incl_srvc_id; |
@@ -117,6 +128,7 @@ typedef struct | ||
117 | 128 | uint8_t write_type; |
118 | 129 | uint8_t status; |
119 | 130 | uint8_t addr_type; |
131 | + uint8_t start; | |
120 | 132 | int8_t rssi; |
121 | 133 | tBT_DEVICE_TYPE device_type; |
122 | 134 | } __attribute__((packed)) btif_gattc_cb_t; |
@@ -469,6 +481,14 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) | ||
469 | 481 | break; |
470 | 482 | } |
471 | 483 | |
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 | + } | |
472 | 492 | default: |
473 | 493 | ALOGE("%s: Unhandled event (%d)!", __FUNCTION__, event); |
474 | 494 | break; |
@@ -786,6 +806,21 @@ static void btgattc_handle_event(uint16_t event, char* p_param) | ||
786 | 806 | BTM_ReadRSSI (p_cb->bd_addr.address, (tBTM_CMPL_CB *)btm_read_rssi_cb); |
787 | 807 | break; |
788 | 808 | |
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 | + | |
789 | 824 | default: |
790 | 825 | ALOGE("%s: Unknown event (%d)!", __FUNCTION__, event); |
791 | 826 | break; |
@@ -845,6 +880,68 @@ static bt_status_t btif_gattc_close( int client_if, const bt_bdaddr_t *bd_addr, | ||
845 | 880 | (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); |
846 | 881 | } |
847 | 882 | |
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 | + | |
848 | 945 | static bt_status_t btif_gattc_refresh( int client_if, const bt_bdaddr_t *bd_addr ) |
849 | 946 | { |
850 | 947 | CHECK_BTGATT_INIT(); |
@@ -1060,6 +1157,7 @@ const btgatt_client_interface_t btgattClientInterface = { | ||
1060 | 1157 | btif_gattc_scan, |
1061 | 1158 | btif_gattc_open, |
1062 | 1159 | btif_gattc_close, |
1160 | + btif_gattc_listen, | |
1063 | 1161 | btif_gattc_refresh, |
1064 | 1162 | btif_gattc_search_service, |
1065 | 1163 | btif_gattc_get_included_service, |
@@ -1074,6 +1172,7 @@ const btgatt_client_interface_t btgattClientInterface = { | ||
1074 | 1172 | btif_gattc_dereg_for_notification, |
1075 | 1173 | btif_gattc_read_remote_rssi, |
1076 | 1174 | btif_gattc_get_device_type, |
1175 | + btif_gattc_set_adv_data, | |
1077 | 1176 | btif_gattc_test_command |
1078 | 1177 | }; |
1079 | 1178 |