Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-2013 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 18 | #include "bt_target.h" |
| 19 | |
| 20 | #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) |
| 21 | |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 22 | #include "bt_utils.h" |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 23 | #include <string.h> |
| 24 | #include "gap_int.h" |
| 25 | #include "gap_api.h" |
| 26 | #include "gattdefs.h" |
| 27 | #include "gatt_api.h" |
| 28 | #include "gatt_int.h" |
| 29 | #include "btm_int.h" |
| 30 | #include "hcimsgs.h" |
| 31 | |
| 32 | #define GAP_CHAR_ICON_SIZE 2 |
| 33 | #define GAP_CHAR_DEV_NAME_SIZE 248 |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 34 | #define GAP_MAX_NUM_INC_SVR 0 |
| 35 | #define GAP_MAX_ATTR_NUM (2 * GAP_MAX_CHAR_NUM + GAP_MAX_NUM_INC_SVR + 1) |
| 36 | #define GAP_MAX_CHAR_VALUE_SIZE (30 + GAP_CHAR_DEV_NAME_SIZE) |
| 37 | |
| 38 | |
| 39 | #ifndef GAP_ATTR_DB_SIZE |
| 40 | #define GAP_ATTR_DB_SIZE GATT_DB_MEM_SIZE(GAP_MAX_NUM_INC_SVR, GAP_MAX_CHAR_NUM, GAP_MAX_CHAR_VALUE_SIZE) |
| 41 | #endif |
| 42 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 43 | static void gap_ble_s_attr_request_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE op_code, tGATTS_DATA *p_data); |
| 44 | |
| 45 | /* client connection callback */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 46 | static void gap_ble_c_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected, |
| 47 | tGATT_DISCONN_REASON reason, tGATT_TRANSPORT transport); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 48 | static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data); |
| 49 | |
| 50 | static tGATT_CBACK gap_cback = |
| 51 | { |
| 52 | gap_ble_c_connect_cback, |
| 53 | gap_ble_c_cmpl_cback, |
| 54 | NULL, |
| 55 | NULL, |
Zhihai Xu | 7051db3 | 2013-11-12 20:18:37 -0800 | [diff] [blame] | 56 | gap_ble_s_attr_request_cback, |
Andre Eisenbach | 17b04bd | 2014-03-28 14:54:22 -0700 | [diff] [blame] | 57 | NULL, |
Zhihai Xu | 7051db3 | 2013-11-12 20:18:37 -0800 | [diff] [blame] | 58 | NULL |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | |
| 62 | |
| 63 | /******************************************************************************* |
| 64 | ** |
| 65 | ** Function gap_find_clcb_by_bd_addr |
| 66 | ** |
| 67 | ** Description The function searches all LCB with macthing bd address |
| 68 | ** |
| 69 | ** Returns total number of clcb found. |
| 70 | ** |
| 71 | *******************************************************************************/ |
| 72 | tGAP_CLCB *gap_find_clcb_by_bd_addr(BD_ADDR bda) |
| 73 | { |
| 74 | UINT8 i_clcb; |
| 75 | tGAP_CLCB *p_clcb = NULL; |
| 76 | |
| 77 | for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) |
| 78 | { |
| 79 | if (p_clcb->in_use && !memcmp(p_clcb->bda, bda, BD_ADDR_LEN)) |
| 80 | { |
| 81 | return p_clcb; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | ** |
| 90 | ** Function gap_ble_find_clcb_by_conn_id |
| 91 | ** |
| 92 | ** Description The function searches all LCB with macthing connection ID |
| 93 | ** |
| 94 | ** Returns total number of clcb found. |
| 95 | ** |
| 96 | *******************************************************************************/ |
| 97 | tGAP_CLCB *gap_ble_find_clcb_by_conn_id(UINT16 conn_id) |
| 98 | { |
| 99 | UINT8 i_clcb; |
| 100 | tGAP_CLCB *p_clcb = NULL; |
| 101 | |
| 102 | for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) |
| 103 | { |
| 104 | if (p_clcb->in_use && p_clcb->connected && p_clcb->conn_id == conn_id) |
| 105 | { |
| 106 | return p_clcb; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return p_clcb; |
| 111 | } |
| 112 | |
| 113 | /******************************************************************************* |
| 114 | ** |
| 115 | ** Function gap_clcb_alloc |
| 116 | ** |
| 117 | ** Description The function allocates a GAP connection link control block |
| 118 | ** |
| 119 | ** Returns NULL if not found. Otherwise pointer to the connection link block. |
| 120 | ** |
| 121 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 122 | tGAP_CLCB *gap_clcb_alloc (BD_ADDR bda) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 123 | { |
| 124 | UINT8 i_clcb = 0; |
| 125 | tGAP_CLCB *p_clcb = NULL; |
| 126 | |
| 127 | for (i_clcb = 0, p_clcb= gap_cb.clcb; i_clcb < GAP_MAX_CL; i_clcb++, p_clcb++) |
| 128 | { |
| 129 | if (!p_clcb->in_use) |
| 130 | { |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 131 | fixed_queue_free(p_clcb->pending_req_q, NULL); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 132 | memset(p_clcb, 0, sizeof(tGAP_CLCB)); |
| 133 | p_clcb->in_use = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 134 | memcpy (p_clcb->bda, bda, BD_ADDR_LEN); |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 135 | p_clcb->pending_req_q = fixed_queue_new(SIZE_MAX); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 136 | break; |
| 137 | } |
| 138 | } |
| 139 | return p_clcb; |
| 140 | } |
| 141 | |
| 142 | /******************************************************************************* |
| 143 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 144 | ** Function gap_ble_dealloc_clcb |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 145 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 146 | ** Description The function clean up the pending request queue in GAP |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 147 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 148 | ** Returns none |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 149 | ** |
| 150 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 151 | void gap_ble_dealloc_clcb(tGAP_CLCB *p_clcb) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 152 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 153 | tGAP_BLE_REQ *p_q; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 154 | |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 155 | while ((p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q)) != NULL) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 156 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 157 | /* send callback to all pending requests if being removed*/ |
| 158 | if (p_q->p_cback != NULL) |
| 159 | (*p_q->p_cback)(FALSE, p_clcb->bda, 0, NULL); |
| 160 | |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame^] | 161 | osi_freebuf (p_q); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 162 | } |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 163 | fixed_queue_free(p_clcb->pending_req_q, NULL); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 164 | |
| 165 | memset(p_clcb, 0, sizeof(tGAP_CLCB)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /******************************************************************************* |
| 169 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 170 | ** Function gap_ble_enqueue_request |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 171 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 172 | ** Description The function enqueue a GAP client request |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 173 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 174 | ** Returns TRUE is successul; FALSE otherwise |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 175 | ** |
| 176 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 177 | BOOLEAN gap_ble_enqueue_request (tGAP_CLCB *p_clcb, UINT16 uuid, tGAP_BLE_CMPL_CBACK *p_cback) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 178 | { |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame^] | 179 | tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)osi_getbuf(sizeof(tGAP_BLE_REQ)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 180 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 181 | if (p_q != NULL) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 182 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 183 | p_q->p_cback = p_cback; |
| 184 | p_q->uuid = uuid; |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 185 | fixed_queue_enqueue(p_clcb->pending_req_q, p_q); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 186 | return TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 189 | return FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 190 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 191 | /******************************************************************************* |
| 192 | ** |
| 193 | ** Function gap_ble_dequeue_request |
| 194 | ** |
| 195 | ** Description The function dequeue a GAP client request if any |
| 196 | ** |
| 197 | ** Returns TRUE is successul; FALSE otherwise |
| 198 | ** |
| 199 | *******************************************************************************/ |
| 200 | BOOLEAN gap_ble_dequeue_request (tGAP_CLCB *p_clcb, UINT16 * p_uuid, tGAP_BLE_CMPL_CBACK **p_cback) |
| 201 | { |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 202 | tGAP_BLE_REQ *p_q = (tGAP_BLE_REQ *)fixed_queue_try_dequeue(p_clcb->pending_req_q);; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 203 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 204 | if (p_q != NULL) |
| 205 | { |
| 206 | *p_cback = p_q->p_cback; |
| 207 | *p_uuid = p_q->uuid; |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame^] | 208 | osi_freebuf((void *)p_q); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 209 | return TRUE; |
| 210 | } |
| 211 | |
| 212 | return FALSE; |
| 213 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 214 | |
| 215 | /******************************************************************************* |
| 216 | ** GAP Attributes Database Request callback |
| 217 | *******************************************************************************/ |
| 218 | tGATT_STATUS gap_read_attr_value (UINT16 handle, tGATT_VALUE *p_value, BOOLEAN is_long) |
| 219 | { |
| 220 | tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; |
| 221 | UINT8 *p = p_value->value, i; |
| 222 | UINT16 offset = p_value->offset; |
| 223 | UINT8 *p_dev_name = NULL; |
| 224 | |
| 225 | for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) |
| 226 | { |
| 227 | if (handle == p_db_attr->handle) |
| 228 | { |
| 229 | if (p_db_attr->uuid != GATT_UUID_GAP_DEVICE_NAME && |
| 230 | is_long == TRUE) |
| 231 | return GATT_NOT_LONG; |
| 232 | |
| 233 | switch (p_db_attr->uuid) |
| 234 | { |
| 235 | case GATT_UUID_GAP_DEVICE_NAME: |
| 236 | BTM_ReadLocalDeviceName((char **)&p_dev_name); |
| 237 | if (strlen ((char *)p_dev_name) > GATT_MAX_ATTR_LEN) |
| 238 | p_value->len = GATT_MAX_ATTR_LEN; |
| 239 | else |
| 240 | p_value->len = (UINT16)strlen ((char *)p_dev_name); |
| 241 | |
| 242 | if (offset > p_value->len) |
| 243 | return GATT_INVALID_OFFSET; |
| 244 | else |
| 245 | { |
| 246 | p_value->len -= offset; |
| 247 | p_dev_name += offset; |
| 248 | ARRAY_TO_STREAM(p, p_dev_name, p_value->len); |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 249 | GAP_TRACE_EVENT("GATT_UUID_GAP_DEVICE_NAME len=0x%04x", p_value->len); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 250 | } |
| 251 | break; |
| 252 | |
| 253 | case GATT_UUID_GAP_ICON: |
| 254 | UINT16_TO_STREAM(p, p_db_attr->attr_value.icon); |
| 255 | p_value->len = 2; |
| 256 | break; |
| 257 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 258 | case GATT_UUID_GAP_PREF_CONN_PARAM: |
| 259 | UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.int_min); /* int_min */ |
| 260 | UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.int_max); /* int_max */ |
| 261 | UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.latency); /* latency */ |
| 262 | UINT16_TO_STREAM(p, p_db_attr->attr_value.conn_param.sp_tout); /* sp_tout */ |
| 263 | p_value->len =8; |
| 264 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 265 | |
| 266 | /* address resolution */ |
| 267 | case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: |
| 268 | UINT8_TO_STREAM(p, p_db_attr->attr_value.addr_resolution); |
| 269 | p_value->len =1; |
| 270 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 271 | } |
| 272 | return GATT_SUCCESS; |
| 273 | } |
| 274 | } |
| 275 | return GATT_NOT_FOUND; |
| 276 | } |
| 277 | |
| 278 | /******************************************************************************* |
| 279 | ** GAP Attributes Database Read/Read Blob Request process |
| 280 | *******************************************************************************/ |
| 281 | tGATT_STATUS gap_proc_read (tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, tGATTS_RSP *p_rsp) |
| 282 | { |
| 283 | tGATT_STATUS status = GATT_NO_RESOURCES; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 284 | UNUSED(type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 285 | |
| 286 | if (p_data->is_long) |
| 287 | p_rsp->attr_value.offset = p_data->offset; |
| 288 | |
| 289 | p_rsp->attr_value.handle = p_data->handle; |
| 290 | |
| 291 | status = gap_read_attr_value(p_data->handle, &p_rsp->attr_value, p_data->is_long); |
| 292 | |
| 293 | return status; |
| 294 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 295 | |
| 296 | /****************************************************************************** |
| 297 | ** |
| 298 | ** Function gap_proc_write_req |
| 299 | ** |
| 300 | ** Description GAP ATT server process a write request. |
| 301 | ** |
| 302 | ** Returns void. |
| 303 | ** |
| 304 | *******************************************************************************/ |
| 305 | UINT8 gap_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data) |
| 306 | { |
| 307 | tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; |
| 308 | UINT8 i; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 309 | UNUSED(type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 310 | |
| 311 | for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) |
| 312 | { |
| 313 | if (p_data-> handle == p_db_attr->handle) |
| 314 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 315 | return GATT_WRITE_NOT_PERMIT; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | return GATT_NOT_FOUND; |
| 319 | |
| 320 | } |
| 321 | |
| 322 | /****************************************************************************** |
| 323 | ** |
| 324 | ** Function gap_ble_s_attr_request_cback |
| 325 | ** |
| 326 | ** Description GAP ATT server attribute access request callback. |
| 327 | ** |
| 328 | ** Returns void. |
| 329 | ** |
| 330 | *******************************************************************************/ |
| 331 | void gap_ble_s_attr_request_cback (UINT16 conn_id, UINT32 trans_id, |
| 332 | tGATTS_REQ_TYPE type, tGATTS_DATA *p_data) |
| 333 | { |
| 334 | UINT8 status = GATT_INVALID_PDU; |
| 335 | tGATTS_RSP rsp_msg; |
| 336 | BOOLEAN ignore = FALSE; |
| 337 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 338 | GAP_TRACE_EVENT("gap_ble_s_attr_request_cback : recv type (0x%02x)", type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 339 | |
| 340 | memset(&rsp_msg, 0, sizeof(tGATTS_RSP)); |
| 341 | |
| 342 | switch (type) |
| 343 | { |
| 344 | case GATTS_REQ_TYPE_READ: |
| 345 | status = gap_proc_read(type, &p_data->read_req, &rsp_msg); |
| 346 | break; |
| 347 | |
| 348 | case GATTS_REQ_TYPE_WRITE: |
| 349 | if (!p_data->write_req.need_rsp) |
| 350 | ignore = TRUE; |
| 351 | |
| 352 | status = gap_proc_write_req(type, &p_data->write_req); |
| 353 | break; |
| 354 | |
| 355 | case GATTS_REQ_TYPE_WRITE_EXEC: |
| 356 | ignore = TRUE; |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 357 | GAP_TRACE_EVENT("Ignore GATTS_REQ_TYPE_WRITE_EXEC" ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 358 | break; |
| 359 | |
| 360 | case GATTS_REQ_TYPE_MTU: |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 361 | GAP_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 362 | ignore = TRUE; |
| 363 | break; |
| 364 | |
| 365 | default: |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 366 | GAP_TRACE_EVENT("Unknown/unexpected LE GAP ATT request: 0x%02x", type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 367 | break; |
| 368 | } |
| 369 | |
| 370 | if (!ignore) |
| 371 | GATTS_SendRsp (conn_id, trans_id, status, &rsp_msg); |
| 372 | } |
| 373 | |
| 374 | /******************************************************************************* |
| 375 | ** |
| 376 | ** Function btm_ble_att_db_init |
| 377 | ** |
| 378 | ** Description GAP ATT database initalization. |
| 379 | ** |
| 380 | ** Returns void. |
| 381 | ** |
| 382 | *******************************************************************************/ |
| 383 | void gap_attr_db_init(void) |
| 384 | { |
| 385 | tBT_UUID app_uuid = {LEN_UUID_128,{0}}; |
| 386 | tBT_UUID uuid = {LEN_UUID_16,{UUID_SERVCLASS_GAP_SERVER}}; |
| 387 | UINT16 service_handle; |
| 388 | tGAP_ATTR *p_db_attr = &gap_cb.gatt_attr[0]; |
| 389 | tGATT_STATUS status; |
| 390 | |
| 391 | /* Fill our internal UUID with a fixed pattern 0x82 */ |
| 392 | memset (&app_uuid.uu.uuid128, 0x82, LEN_UUID_128); |
| 393 | memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM); |
| 394 | |
| 395 | gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback); |
| 396 | |
| 397 | GATT_StartIf(gap_cb.gatt_if); |
| 398 | |
| 399 | /* Create a GAP service */ |
| 400 | service_handle = GATTS_CreateService (gap_cb.gatt_if, &uuid, 0, GAP_MAX_ATTR_NUM, TRUE); |
| 401 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 402 | GAP_TRACE_EVENT ("gap_attr_db_init service_handle = %d", service_handle); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 403 | |
| 404 | /* add Device Name Characteristic |
| 405 | */ |
| 406 | uuid.len = LEN_UUID_16; |
| 407 | uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_DEVICE_NAME; |
| 408 | p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); |
| 409 | p_db_attr ++; |
| 410 | |
| 411 | /* add Icon characteristic |
| 412 | */ |
| 413 | uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_ICON; |
| 414 | p_db_attr->handle = GATTS_AddCharacteristic(service_handle, |
| 415 | &uuid, |
| 416 | GATT_PERM_READ, |
| 417 | GATT_CHAR_PROP_BIT_READ); |
| 418 | p_db_attr ++; |
| 419 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 420 | #if BTM_PERIPHERAL_ENABLED == TRUE /* Only needed for peripheral testing */ |
| 421 | /* add preferred connection parameter characteristic |
| 422 | */ |
| 423 | uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_PREF_CONN_PARAM; |
| 424 | p_db_attr->attr_value.conn_param.int_max = GAP_PREFER_CONN_INT_MAX; /* 6 */ |
| 425 | p_db_attr->attr_value.conn_param.int_min = GAP_PREFER_CONN_INT_MIN; /* 0 */ |
| 426 | p_db_attr->attr_value.conn_param.latency = GAP_PREFER_CONN_LATENCY; /* 0 */ |
| 427 | p_db_attr->attr_value.conn_param.sp_tout = GAP_PREFER_CONN_SP_TOUT; /* 2000 */ |
| 428 | p_db_attr->handle = GATTS_AddCharacteristic(service_handle, |
| 429 | &uuid, |
| 430 | GATT_PERM_READ, |
| 431 | GATT_CHAR_PROP_BIT_READ); |
| 432 | p_db_attr ++; |
| 433 | #endif |
| 434 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 435 | /* add Central address resolution Characteristic */ |
| 436 | uuid.len = LEN_UUID_16; |
| 437 | uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_CENTRAL_ADDR_RESOL; |
| 438 | p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, |
| 439 | GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); |
| 440 | p_db_attr->attr_value.addr_resolution = 0; |
| 441 | p_db_attr++; |
| 442 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 443 | /* start service now */ |
| 444 | memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128); |
| 445 | |
| 446 | status = GATTS_StartService(gap_cb.gatt_if, service_handle, GAP_TRANSPORT_SUPPORTED ); |
| 447 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 448 | GAP_TRACE_EVENT ("GAP App gatt_if: %d s_hdl = %d start_status=%d", |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 449 | gap_cb.gatt_if, service_handle, status); |
| 450 | |
| 451 | |
| 452 | |
| 453 | } |
| 454 | |
| 455 | /******************************************************************************* |
| 456 | ** |
| 457 | ** Function GAP_BleAttrDBUpdate |
| 458 | ** |
| 459 | ** Description GAP ATT database update. |
| 460 | ** |
| 461 | ** Returns void. |
| 462 | ** |
| 463 | *******************************************************************************/ |
| 464 | void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) |
| 465 | { |
| 466 | tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; |
| 467 | UINT8 i = 0; |
| 468 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 469 | GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x", attr_uuid); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 470 | |
| 471 | for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) |
| 472 | { |
| 473 | if (p_db_attr->uuid == attr_uuid) |
| 474 | { |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 475 | GAP_TRACE_EVENT("Found attr_uuid=0x%04x", attr_uuid); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 476 | |
| 477 | switch (attr_uuid) |
| 478 | { |
| 479 | case GATT_UUID_GAP_ICON: |
| 480 | p_db_attr->attr_value.icon = p_value->icon; |
| 481 | break; |
| 482 | |
| 483 | case GATT_UUID_GAP_PREF_CONN_PARAM: |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 484 | memcpy((void *)&p_db_attr->attr_value.conn_param, |
| 485 | (const void *)&p_value->conn_param, sizeof(tGAP_BLE_PREF_PARAM)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 486 | break; |
| 487 | |
| 488 | case GATT_UUID_GAP_DEVICE_NAME: |
| 489 | BTM_SetLocalDeviceName((char *)p_value->p_dev_name); |
| 490 | break; |
| 491 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 492 | case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: |
| 493 | p_db_attr->attr_value.addr_resolution = p_value->addr_resolution; |
| 494 | break; |
| 495 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 496 | } |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | /******************************************************************************* |
| 505 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 506 | ** Function gap_ble_send_cl_read_request |
| 507 | ** |
| 508 | ** Description utility function to send a read request for a GAP charactersitic |
| 509 | ** |
| 510 | ** Returns TRUE if read started, else FALSE if GAP is busy |
| 511 | ** |
| 512 | *******************************************************************************/ |
| 513 | BOOLEAN gap_ble_send_cl_read_request(tGAP_CLCB *p_clcb) |
| 514 | { |
| 515 | tGATT_READ_PARAM param; |
| 516 | UINT16 uuid = 0; |
| 517 | BOOLEAN started = FALSE; |
| 518 | |
| 519 | if (gap_ble_dequeue_request(p_clcb, &uuid, &p_clcb->p_cback)) |
| 520 | { |
| 521 | memset(¶m, 0, sizeof(tGATT_READ_PARAM)); |
| 522 | |
| 523 | param.service.uuid.len = LEN_UUID_16; |
| 524 | param.service.uuid.uu.uuid16 = uuid; |
| 525 | param.service.s_handle = 1; |
| 526 | param.service.e_handle = 0xFFFF; |
| 527 | param.service.auth_req = 0; |
| 528 | |
| 529 | if (GATTC_Read(p_clcb->conn_id, GATT_READ_BY_TYPE, ¶m) == GATT_SUCCESS) |
| 530 | { |
| 531 | p_clcb->cl_op_uuid = uuid; |
| 532 | started = TRUE; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | return started; |
| 537 | } |
| 538 | |
| 539 | /******************************************************************************* |
| 540 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 541 | ** Function gap_ble_cl_op_cmpl |
| 542 | ** |
| 543 | ** Description GAP client operation complete callback |
| 544 | ** |
| 545 | ** Returns void |
| 546 | ** |
| 547 | *******************************************************************************/ |
| 548 | void gap_ble_cl_op_cmpl(tGAP_CLCB *p_clcb, BOOLEAN status, UINT16 len, UINT8 *p_name) |
| 549 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 550 | tGAP_BLE_CMPL_CBACK *p_cback = p_clcb->p_cback; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 551 | UINT16 op = p_clcb->cl_op_uuid; |
| 552 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 553 | GAP_TRACE_EVENT("gap_ble_cl_op_cmpl status: %d", status); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 554 | |
| 555 | p_clcb->cl_op_uuid = 0; |
| 556 | p_clcb->p_cback=NULL; |
| 557 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 558 | if (p_cback && op) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 559 | { |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 560 | GAP_TRACE_EVENT("calling gap_ble_cl_op_cmpl"); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 561 | (* p_cback)(status, p_clcb->bda, len, (char *)p_name); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 564 | /* if no further activity is requested in callback, drop the link */ |
| 565 | if (p_clcb->connected) |
| 566 | { |
| 567 | if (!gap_ble_send_cl_read_request(p_clcb)) |
| 568 | { |
| 569 | GATT_Disconnect(p_clcb->conn_id); |
| 570 | gap_ble_dealloc_clcb(p_clcb); |
| 571 | } |
| 572 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /******************************************************************************* |
| 576 | ** |
| 577 | ** Function gap_ble_c_connect_cback |
| 578 | ** |
| 579 | ** Description Client connection callback. |
| 580 | ** |
| 581 | ** Returns void |
| 582 | ** |
| 583 | *******************************************************************************/ |
| 584 | static void gap_ble_c_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 585 | BOOLEAN connected, tGATT_DISCONN_REASON reason, |
| 586 | tGATT_TRANSPORT transport) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 587 | { |
| 588 | tGAP_CLCB *p_clcb = gap_find_clcb_by_bd_addr (bda); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 589 | |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 590 | UNUSED(gatt_if); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 591 | UNUSED(transport); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 592 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 593 | if (p_clcb != NULL) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 594 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 595 | if (connected) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 596 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 597 | p_clcb->conn_id = conn_id; |
| 598 | p_clcb->connected = TRUE; |
| 599 | /* start operation is pending */ |
| 600 | gap_ble_send_cl_read_request(p_clcb); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 601 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 602 | else |
| 603 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 604 | p_clcb->connected = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 605 | gap_ble_cl_op_cmpl(p_clcb, FALSE, 0, NULL); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 606 | /* clean up clcb */ |
| 607 | gap_ble_dealloc_clcb(p_clcb); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /******************************************************************************* |
| 613 | ** |
| 614 | ** Function gap_ble_c_cmpl_cback |
| 615 | ** |
| 616 | ** Description Client operation complete callback. |
| 617 | ** |
| 618 | ** Returns void |
| 619 | ** |
| 620 | *******************************************************************************/ |
| 621 | static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) |
| 622 | |
| 623 | { |
| 624 | tGAP_CLCB *p_clcb = gap_ble_find_clcb_by_conn_id(conn_id); |
| 625 | UINT16 op_type; |
| 626 | UINT16 min, max, latency, tout; |
| 627 | UINT16 len; |
| 628 | UINT8 *pp; |
| 629 | |
| 630 | if (p_clcb == NULL) |
| 631 | return; |
| 632 | |
| 633 | op_type = p_clcb->cl_op_uuid; |
| 634 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 635 | GAP_TRACE_EVENT ("gap_ble_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x read_type: 0x%04x", op, status, op_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 636 | /* Currently we only issue read commands */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 637 | if (op != GATTC_OPTYPE_READ) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 638 | return; |
| 639 | |
| 640 | if (status != GATT_SUCCESS) |
| 641 | { |
| 642 | gap_ble_cl_op_cmpl(p_clcb, FALSE, 0, NULL); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | pp = p_data->att_value.value; |
| 647 | |
| 648 | switch (op_type) |
| 649 | { |
| 650 | case GATT_UUID_GAP_PREF_CONN_PARAM: |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 651 | GAP_TRACE_EVENT ("GATT_UUID_GAP_PREF_CONN_PARAM"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 652 | /* Extract the peripheral preferred connection parameters and save them */ |
| 653 | |
| 654 | STREAM_TO_UINT16 (min, pp); |
| 655 | STREAM_TO_UINT16 (max, pp); |
| 656 | STREAM_TO_UINT16 (latency, pp); |
| 657 | STREAM_TO_UINT16 (tout, pp); |
| 658 | |
| 659 | BTM_BleSetPrefConnParams (p_clcb->bda, min, max, latency, tout); |
| 660 | /* release the connection here */ |
| 661 | gap_ble_cl_op_cmpl(p_clcb, TRUE, 0, NULL); |
| 662 | break; |
| 663 | |
| 664 | case GATT_UUID_GAP_DEVICE_NAME: |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 665 | GAP_TRACE_EVENT ("GATT_UUID_GAP_DEVICE_NAME"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 666 | len = (UINT16)strlen((char *)pp); |
| 667 | if (len > GAP_CHAR_DEV_NAME_SIZE) |
| 668 | len = GAP_CHAR_DEV_NAME_SIZE; |
| 669 | gap_ble_cl_op_cmpl(p_clcb, TRUE, len, pp); |
| 670 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 671 | |
| 672 | case GATT_UUID_GAP_CENTRAL_ADDR_RESOL: |
| 673 | gap_ble_cl_op_cmpl(p_clcb, TRUE, 1, pp); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 674 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 678 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 679 | /******************************************************************************* |
| 680 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 681 | ** Function gap_ble_accept_cl_operation |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 682 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 683 | ** Description Start a process to read peer address resolution capability |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 684 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 685 | ** Returns TRUE if request accepted |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 686 | ** |
| 687 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 688 | BOOLEAN gap_ble_accept_cl_operation(BD_ADDR peer_bda, UINT16 uuid, tGAP_BLE_CMPL_CBACK *p_cback) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 689 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 690 | tGAP_CLCB *p_clcb; |
| 691 | BOOLEAN started = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 692 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 693 | if (p_cback == NULL && uuid != GATT_UUID_GAP_PREF_CONN_PARAM) |
| 694 | return(started); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 695 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 696 | if ((p_clcb = gap_find_clcb_by_bd_addr (peer_bda)) == NULL) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 697 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 698 | if ((p_clcb = gap_clcb_alloc(peer_bda)) == NULL) |
| 699 | { |
| 700 | GAP_TRACE_ERROR("gap_ble_accept_cl_operation max connection reached"); |
| 701 | return started; |
| 702 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 705 | GAP_TRACE_EVENT ("%s() - BDA: %08x%04x cl_op_uuid: 0x%04x", |
| 706 | __FUNCTION__, |
| 707 | (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], |
| 708 | (peer_bda[4]<<8)+peer_bda[5], uuid); |
| 709 | |
| 710 | if (GATT_GetConnIdIfConnected(gap_cb.gatt_if, peer_bda, &p_clcb->conn_id, BT_TRANSPORT_LE)) |
| 711 | p_clcb->connected = TRUE; |
| 712 | |
| 713 | /* hold the link here */ |
| 714 | if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, TRUE, BT_TRANSPORT_LE)) |
| 715 | return started; |
| 716 | |
| 717 | /* enqueue the request */ |
| 718 | gap_ble_enqueue_request(p_clcb, uuid, p_cback); |
| 719 | |
| 720 | if (p_clcb->connected && p_clcb->cl_op_uuid == 0) |
| 721 | started = gap_ble_send_cl_read_request(p_clcb); |
| 722 | else /* wait for connection up or pending operation to finish */ |
| 723 | started = TRUE; |
| 724 | |
| 725 | return started; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 726 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 727 | /******************************************************************************* |
| 728 | ** |
| 729 | ** Function GAP_BleReadPeerPrefConnParams |
| 730 | ** |
| 731 | ** Description Start a process to read a connected peripheral's preferred |
| 732 | ** connection parameters |
| 733 | ** |
| 734 | ** Returns TRUE if read started, else FALSE if GAP is busy |
| 735 | ** |
| 736 | *******************************************************************************/ |
| 737 | BOOLEAN GAP_BleReadPeerPrefConnParams (BD_ADDR peer_bda) |
| 738 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 739 | return gap_ble_accept_cl_operation (peer_bda, GATT_UUID_GAP_PREF_CONN_PARAM, NULL); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /******************************************************************************* |
| 743 | ** |
| 744 | ** Function GAP_BleReadPeerDevName |
| 745 | ** |
| 746 | ** Description Start a process to read a connected peripheral's device name. |
| 747 | ** |
| 748 | ** Returns TRUE if request accepted |
| 749 | ** |
| 750 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 751 | BOOLEAN GAP_BleReadPeerDevName (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 752 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 753 | return gap_ble_accept_cl_operation (peer_bda, GATT_UUID_GAP_DEVICE_NAME, p_cback); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 754 | } |
| 755 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 756 | /******************************************************************************* |
| 757 | ** |
| 758 | ** Function GAP_BleReadPeerAddressResolutionCap |
| 759 | ** |
| 760 | ** Description Start a process to read peer address resolution capability |
| 761 | ** |
| 762 | ** Returns TRUE if request accepted |
| 763 | ** |
| 764 | *******************************************************************************/ |
| 765 | BOOLEAN GAP_BleReadPeerAddressResolutionCap (BD_ADDR peer_bda, tGAP_BLE_CMPL_CBACK *p_cback) |
| 766 | { |
| 767 | return gap_ble_accept_cl_operation(peer_bda, GATT_UUID_GAP_CENTRAL_ADDR_RESOL, p_cback); |
| 768 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 769 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 770 | /******************************************************************************* |
| 771 | ** |
| 772 | ** Function GAP_BleCancelReadPeerDevName |
| 773 | ** |
| 774 | ** Description Cancel reading a peripheral's device name. |
| 775 | ** |
| 776 | ** Returns TRUE if request accepted |
| 777 | ** |
| 778 | *******************************************************************************/ |
| 779 | BOOLEAN GAP_BleCancelReadPeerDevName (BD_ADDR peer_bda) |
| 780 | { |
| 781 | tGAP_CLCB *p_clcb = gap_find_clcb_by_bd_addr (peer_bda); |
| 782 | |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 783 | GAP_TRACE_EVENT ("GAP_BleCancelReadPeerDevName() - BDA: %08x%04x cl_op_uuid: 0x%04x", |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 784 | (peer_bda[0]<<24)+(peer_bda[1]<<16)+(peer_bda[2]<<8)+peer_bda[3], |
| 785 | (peer_bda[4]<<8)+peer_bda[5], (p_clcb == NULL)? 0 : p_clcb->cl_op_uuid); |
| 786 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 787 | if (p_clcb == NULL) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 788 | { |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 789 | GAP_TRACE_ERROR ("Cannot cancel current op is not get dev name"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 790 | return FALSE; |
| 791 | } |
| 792 | |
| 793 | if (!p_clcb->connected) |
| 794 | { |
| 795 | if (!GATT_CancelConnect(gap_cb.gatt_if, peer_bda, TRUE)) |
| 796 | { |
Sharvil Nanavati | d5bba90 | 2014-05-04 01:33:15 -0700 | [diff] [blame] | 797 | GAP_TRACE_ERROR ("Cannot cancel where No connection id"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 798 | return FALSE; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | gap_ble_cl_op_cmpl(p_clcb, FALSE, 0, NULL); |
| 803 | |
| 804 | return(TRUE); |
| 805 | } |
| 806 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 807 | #endif /* BLE_INCLUDED */ |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |