blob: 58d28b7f4dfced6f429ed97104de6ae5945b9a20 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2008-2012 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 ******************************************************************************/
18
19/******************************************************************************
20 *
21 * this file contains the GATT server functions
22 *
23 ******************************************************************************/
24
25#include "bt_target.h"
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080026#include "bt_utils.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080027
28#if BLE_INCLUDED == TRUE
29#include <string.h>
30#include "gatt_int.h"
31#include "l2c_api.h"
Priti Aghera636d6712014-12-18 13:55:48 -080032#include "l2c_int.h"
Andre Eisenbachccf9c152013-10-02 15:37:21 -070033#define GATT_MTU_REQ_MIN_LEN 2
34
The Android Open Source Project5738f832012-12-12 16:00:35 -080035
36/*******************************************************************************
37**
38** Function gatt_sr_enqueue_cmd
39**
40** Description This function enqueue the request from client which needs a
41** application response, and update the transaction ID.
42**
43** Returns void
44**
45*******************************************************************************/
46UINT32 gatt_sr_enqueue_cmd (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 handle)
47{
48 tGATT_SR_CMD *p_cmd = &p_tcb->sr_cmd;
49 UINT32 trans_id = 0;
50
51 if ( (p_cmd->op_code == 0) ||
52 (op_code == GATT_HANDLE_VALUE_CONF)) /* no pending request */
53 {
54 if (op_code == GATT_CMD_WRITE ||
55 op_code == GATT_SIGN_CMD_WRITE ||
56 op_code == GATT_REQ_MTU ||
57 op_code == GATT_HANDLE_VALUE_CONF)
58 {
59 trans_id = ++p_tcb->trans_id;
60 }
61 else
62 {
63 p_cmd->trans_id = ++p_tcb->trans_id;
64 p_cmd->op_code = op_code;
65 p_cmd->handle = handle;
66 p_cmd->status = GATT_NOT_FOUND;
67 p_tcb->trans_id %= GATT_TRANS_ID_MAX;
68 trans_id = p_cmd->trans_id;
69 }
70 }
71
72 return trans_id;
73}
74
75/*******************************************************************************
76**
77** Function gatt_sr_cmd_empty
78**
79** Description This function check the server command queue is empty or not.
80**
81** Returns TRUE if empty, FALSE if there is pending command.
82**
83*******************************************************************************/
84BOOLEAN gatt_sr_cmd_empty (tGATT_TCB *p_tcb)
85{
86 return(p_tcb->sr_cmd.op_code == 0);
87}
88
89/*******************************************************************************
90**
91** Function gatt_dequeue_sr_cmd
92**
93** Description This function dequeue the request from command queue.
94**
95** Returns void
96**
97*******************************************************************************/
98void gatt_dequeue_sr_cmd (tGATT_TCB *p_tcb)
99{
100 /* Double check in case any buffers are queued */
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700101 GATT_TRACE_DEBUG("gatt_dequeue_sr_cmd" );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800102 if (p_tcb->sr_cmd.p_rsp_msg)
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700103 GATT_TRACE_ERROR("free p_tcb->sr_cmd.p_rsp_msg = %d", p_tcb->sr_cmd.p_rsp_msg);
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800104 osi_free_and_reset((void **)&p_tcb->sr_cmd.p_rsp_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800105
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700106 while (!fixed_queue_is_empty(p_tcb->sr_cmd.multi_rsp_q))
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800107 osi_free(fixed_queue_try_dequeue(p_tcb->sr_cmd.multi_rsp_q));
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700108 fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800109 memset( &p_tcb->sr_cmd, 0, sizeof(tGATT_SR_CMD));
110}
111
112/*******************************************************************************
113**
114** Function process_read_multi_rsp
115**
116** Description This function check the read multiple response.
117**
118** Returns BOOLEAN if all replies have been received
119**
120*******************************************************************************/
121static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
122 tGATTS_RSP *p_msg, UINT16 mtu)
123{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800124 UINT16 ii, total_len, len;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800125 UINT8 *p;
126 BOOLEAN is_overflow = FALSE;
127
Subramanian Srinivasan089cd112016-05-16 11:14:03 -0700128 GATT_TRACE_DEBUG ("%s status=%d mtu=%d", __func__, status, mtu);
129
130 if (p_cmd->multi_rsp_q == NULL)
131 p_cmd->multi_rsp_q = fixed_queue_new(SIZE_MAX);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800132
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133 /* Enqueue the response */
Subramanian Srinivasan089cd112016-05-16 11:14:03 -0700134 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(tGATTS_RSP));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800135 memcpy((void *)p_buf, (const void *)p_msg, sizeof(tGATTS_RSP));
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700136 fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800137
138 p_cmd->status = status;
139 if (status == GATT_SUCCESS)
140 {
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700141 GATT_TRACE_DEBUG("Multi read count=%d num_hdls=%d",
Pavlin Radoslavov43947202016-02-13 08:47:19 -0800142 fixed_queue_length(p_cmd->multi_rsp_q),
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700143 p_cmd->multi_req.num_handles);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800144 /* Wait till we get all the responses */
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700145 if (fixed_queue_length(p_cmd->multi_rsp_q) == p_cmd->multi_req.num_handles)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800146 {
147 len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800148 p_buf = (BT_HDR *)osi_calloc(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800149 p_buf->offset = L2CAP_MIN_OFFSET;
150 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
151
152 /* First byte in the response is the opcode */
153 *p++ = GATT_RSP_READ_MULTI;
154 p_buf->len = 1;
155
156 /* Now walk through the buffers puting the data into the response in order */
Pavlin Radoslavov577862e2015-10-07 18:07:48 -0700157 list_t *list = NULL;
158 const list_node_t *node = NULL;
159 if (! fixed_queue_is_empty(p_cmd->multi_rsp_q))
160 list = fixed_queue_get_list(p_cmd->multi_rsp_q);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161 for (ii = 0; ii < p_cmd->multi_req.num_handles; ii++)
162 {
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -0700163 tGATTS_RSP *p_rsp = NULL;
164
Pavlin Radoslavov577862e2015-10-07 18:07:48 -0700165 if (list != NULL) {
166 if (ii == 0)
167 node = list_begin(list);
168 else
169 node = list_next(node);
170 if (node != list_end(list))
171 p_rsp = (tGATTS_RSP *)list_node(node);
172 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173
174 if (p_rsp != NULL)
175 {
176
177 total_len = (p_buf->len + p_rsp->attr_value.len);
178
179 if (total_len > mtu)
180 {
181 /* just send the partial response for the overflow case */
182 len = p_rsp->attr_value.len - (total_len - mtu);
183 is_overflow = TRUE;
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700184 GATT_TRACE_DEBUG ("multi read overflow available len=%d val_len=%d", len, p_rsp->attr_value.len );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800185 }
186 else
187 {
188 len = p_rsp->attr_value.len;
189 }
190
191 if (p_rsp->attr_value.handle == p_cmd->multi_req.handles[ii])
192 {
193 memcpy (p, p_rsp->attr_value.value, len);
194 if (!is_overflow)
195 p += len;
196 p_buf->len += len;
197 }
198 else
199 {
200 p_cmd->status = GATT_NOT_FOUND;
201 break;
202 }
203
204 if (is_overflow)
205 break;
206
207 }
208 else
209 {
210 p_cmd->status = GATT_NOT_FOUND;
211 break;
212 }
213
214 } /* loop through all handles*/
215
216
217 /* Sanity check on the buffer length */
218 if (p_buf->len == 0)
219 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700220 GATT_TRACE_ERROR("process_read_multi_rsp - nothing found!!");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800221 p_cmd->status = GATT_NOT_FOUND;
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800222 osi_free(p_buf);
223 GATT_TRACE_DEBUG("osi_free(p_buf)");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800224 }
225 else if (p_cmd->p_rsp_msg != NULL)
226 {
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800227 osi_free(p_buf);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800228 }
229 else
230 {
231 p_cmd->p_rsp_msg = p_buf;
232 }
233
234 return(TRUE);
235 }
236 }
237 else /* any handle read exception occurs, return error */
238 {
239 return(TRUE);
240 }
241
242 /* If here, still waiting */
243 return(FALSE);
244}
245
246/*******************************************************************************
247**
248** Function gatt_sr_process_app_rsp
249**
250** Description This function checks whether the response message from application
251** match any pending request or not.
252**
253** Returns void
254**
255*******************************************************************************/
256tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if,
257 UINT32 trans_id, UINT8 op_code,
258 tGATT_STATUS status, tGATTS_RSP *p_msg)
259{
260 tGATT_STATUS ret_code = GATT_SUCCESS;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800261 UNUSED(trans_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800262
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700263 GATT_TRACE_DEBUG("gatt_sr_process_app_rsp gatt_if=%d", gatt_if);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800264
265 gatt_sr_update_cback_cnt(p_tcb, gatt_if, FALSE, FALSE);
266
267 if (op_code == GATT_REQ_READ_MULTI)
268 {
269 /* If no error and still waiting, just return */
270 if (!process_read_multi_rsp (&p_tcb->sr_cmd, status, p_msg, p_tcb->payload_size))
271 return(GATT_SUCCESS);
272 }
273 else
274 {
275 if (op_code == GATT_REQ_PREPARE_WRITE && status == GATT_SUCCESS)
276 gatt_sr_update_prep_cnt(p_tcb, gatt_if, TRUE, FALSE);
277
278 if (op_code == GATT_REQ_EXEC_WRITE && status != GATT_SUCCESS)
279 gatt_sr_reset_cback_cnt(p_tcb);
280
281 p_tcb->sr_cmd.status = status;
282
283 if (gatt_sr_is_cback_cnt_zero(p_tcb)
284 && status == GATT_SUCCESS)
285 {
286 if (p_tcb->sr_cmd.p_rsp_msg == NULL)
287 {
288 p_tcb->sr_cmd.p_rsp_msg = attp_build_sr_msg (p_tcb, (UINT8)(op_code + 1), (tGATT_SR_MSG *)p_msg);
289 }
290 else
291 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700292 GATT_TRACE_ERROR("Exception!!! already has respond message");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293 }
294 }
295 }
296 if (gatt_sr_is_cback_cnt_zero(p_tcb))
297 {
298 if ( (p_tcb->sr_cmd.status == GATT_SUCCESS) && (p_tcb->sr_cmd.p_rsp_msg) )
299 {
300 ret_code = attp_send_sr_msg (p_tcb, p_tcb->sr_cmd.p_rsp_msg);
301 p_tcb->sr_cmd.p_rsp_msg = NULL;
302 }
303 else
304 {
305 ret_code = gatt_send_error_rsp (p_tcb, status, op_code, p_tcb->sr_cmd.handle, FALSE);
306 }
307
308 gatt_dequeue_sr_cmd(p_tcb);
309 }
310
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700311 GATT_TRACE_DEBUG("gatt_sr_process_app_rsp ret_code=%d", ret_code);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800312
313 return ret_code;
314}
315
316/*******************************************************************************
317**
318** Function gatt_process_exec_write_req
319**
320** Description This function is called to process the execute write request
321** from client.
322**
323** Returns void
324**
325*******************************************************************************/
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700326void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800327{
328 UINT8 *p = p_data, flag, i = 0;
329 UINT32 trans_id = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800330 tGATT_IF gatt_if;
331 UINT16 conn_id;
332
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700333 UNUSED(len);
334
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800335#if GATT_CONFORMANCE_TESTING == TRUE
336 if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code)
337 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700338 GATT_TRACE_DEBUG("Conformance tst: forced err rspv for Execute Write: error status=%d",
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700339 gatt_cb.err_status);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800340
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700341 gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, gatt_cb.handle, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800342
343 return;
344 }
345#endif
346
The Android Open Source Project5738f832012-12-12 16:00:35 -0800347 STREAM_TO_UINT8(flag, p);
348
349 /* mask the flag */
350 flag &= GATT_PREP_WRITE_EXEC;
351
352
353 /* no prep write is queued */
354 if (!gatt_sr_is_prep_cnt_zero(p_tcb))
355 {
356 trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, 0);
357 gatt_sr_copy_prep_cnt_to_cback_cnt(p_tcb);
358
359 for (i=0; i<GATT_MAX_APPS; i++)
360 {
361 if (p_tcb->prep_cnt[i])
362 {
363 gatt_if = (tGATT_IF) (i+1);
364 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_if);
365 gatt_sr_send_req_callback(conn_id,
366 trans_id,
367 GATTS_REQ_TYPE_WRITE_EXEC,
368 (tGATTS_DATA *)&flag);
369 p_tcb->prep_cnt[i]= 0;
370 }
371 }
372 }
373 else /* nothing needs to be executed , send response now */
374 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700375 GATT_TRACE_ERROR("gatt_process_exec_write_req: no prepare write pending");
Mudumba Ananthcf310332014-07-04 03:45:11 -0700376 gatt_send_error_rsp(p_tcb, GATT_ERROR, GATT_REQ_EXEC_WRITE, 0, FALSE);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800377 }
378}
379
380/*******************************************************************************
381**
382** Function gatt_process_read_multi_req
383**
384** Description This function is called to process the read multiple request
385** from client.
386**
387** Returns void
388**
389*******************************************************************************/
390void gatt_process_read_multi_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
391{
392 UINT32 trans_id;
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700393 UINT16 handle = 0, ll = len;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800394 UINT8 *p = p_data, i_rcb;
395 tGATT_STATUS err = GATT_SUCCESS;
396 UINT8 sec_flag, key_size;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800397
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700398 GATT_TRACE_DEBUG("gatt_process_read_multi_req" );
The Android Open Source Project5738f832012-12-12 16:00:35 -0800399 p_tcb->sr_cmd.multi_req.num_handles = 0;
400
401 gatt_sr_get_sec_info(p_tcb->peer_bda,
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700402 p_tcb->transport,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800403 &sec_flag,
404 &key_size);
405
406#if GATT_CONFORMANCE_TESTING == TRUE
407 if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code)
408 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700409 GATT_TRACE_DEBUG("Conformance tst: forced err rspvofr ReadMultiple: error status=%d", gatt_cb.err_status);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800410
411 STREAM_TO_UINT16(handle, p);
412
413 gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, FALSE);
414
415 return;
416 }
417#endif
418
419 while (ll >= 2 && p_tcb->sr_cmd.multi_req.num_handles < GATT_MAX_READ_MULTI_HANDLES)
420 {
421 STREAM_TO_UINT16(handle, p);
422
423 if ((i_rcb = gatt_sr_find_i_rcb_by_handle(handle)) < GATT_MAX_SR_PROFILES)
424 {
425 p_tcb->sr_cmd.multi_req.handles[p_tcb->sr_cmd.multi_req.num_handles++] = handle;
426
427 /* check read permission */
428 if ((err = gatts_read_attr_perm_check( gatt_cb.sr_reg[i_rcb].p_db,
429 FALSE,
430 handle,
431 sec_flag,
432 key_size))
433 != GATT_SUCCESS)
434 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700435 GATT_TRACE_DEBUG("read permission denied : 0x%02x", err);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800436 break;
437 }
438 }
439 else
440 {
441 /* invalid handle */
442 err = GATT_INVALID_HANDLE;
443 break;
444 }
445 ll -= 2;
446 }
447
448 if (ll != 0)
449 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700450 GATT_TRACE_ERROR("max attribute handle reached in ReadMultiple Request.");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800451 }
452
453 if (p_tcb->sr_cmd.multi_req.num_handles == 0)
454 err = GATT_INVALID_HANDLE;
455
456 if (err == GATT_SUCCESS)
457 {
458 if ((trans_id = gatt_sr_enqueue_cmd (p_tcb, op_code, p_tcb->sr_cmd.multi_req.handles[0])) != 0)
459 {
460 gatt_sr_reset_cback_cnt(p_tcb); /* read multiple use multi_rsp_q's count*/
461
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800462 for (ll = 0; ll < p_tcb->sr_cmd.multi_req.num_handles; ll ++) {
463 tGATTS_RSP *p_msg = (tGATTS_RSP *)osi_calloc(sizeof(tGATTS_RSP));
464 handle = p_tcb->sr_cmd.multi_req.handles[ll];
465 i_rcb = gatt_sr_find_i_rcb_by_handle(handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800466
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800467 p_msg->attr_value.handle = handle;
468 err = gatts_read_attr_value_by_handle(p_tcb,
469 gatt_cb.sr_reg[i_rcb].p_db,
470 op_code,
471 handle,
472 0,
473 p_msg->attr_value.value,
474 &p_msg->attr_value.len,
475 GATT_MAX_ATTR_LEN,
476 sec_flag,
477 key_size,
478 trans_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800479
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800480 if (err == GATT_SUCCESS) {
481 gatt_sr_process_app_rsp(p_tcb, gatt_cb.sr_reg[i_rcb].gatt_if ,trans_id, op_code, GATT_SUCCESS, p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800482 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800483 /* either not using or done using the buffer, release it now */
484 osi_free(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800485 }
486 }
487 else
488 err = GATT_NO_RESOURCES;
489 }
490
491 /* in theroy BUSY is not possible(should already been checked), protected check */
492 if (err != GATT_SUCCESS && err != GATT_PENDING && err != GATT_BUSY)
493 gatt_send_error_rsp(p_tcb, err, op_code, handle, FALSE);
494}
495
496/*******************************************************************************
497**
498** Function gatt_build_primary_service_rsp
499**
500** Description Primamry service request processed internally. Theretically
501** only deal with ReadByTypeVAlue and ReadByGroupType.
502**
503** Returns void
504**
505*******************************************************************************/
506static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_tcb,
507 UINT8 op_code, UINT16 s_hdl,
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700508 UINT16 e_hdl, UINT8 *p_data, tBT_UUID value)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800509{
510 tGATT_STATUS status = GATT_NOT_FOUND;
511 UINT8 handle_len =4, *p ;
512 tGATT_SR_REG *p_rcb;
513 tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info;
514 tGATT_SRV_LIST_ELEM *p_srv=NULL;
515 tBT_UUID *p_uuid;
516
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700517 UNUSED(p_data);
518
The Android Open Source Project5738f832012-12-12 16:00:35 -0800519 p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
520
521 p_srv = p_list->p_first;
522
523 while (p_srv)
524 {
525 p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg);
526
527 if (p_rcb->in_use &&
528 p_rcb->s_hdl >= s_hdl &&
529 p_rcb->s_hdl <= e_hdl &&
530 p_rcb->type == GATT_UUID_PRI_SERVICE)
531 {
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700532 if ((p_uuid = gatts_get_service_uuid (p_rcb->p_db)) != NULL)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800533 {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800534 if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700535 handle_len = 4 + p_uuid->len;
536
537 /* get the length byte in the repsonse */
538 if (p_msg->offset ==0)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800539 {
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700540 *p ++ = op_code + 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800541 p_msg->len ++;
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700542 p_msg->offset = handle_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800543
544 if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700545 {
546 *p ++ = (UINT8)p_msg->offset; /* length byte */
547 p_msg->len ++;
548 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800549 }
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700550
551 if (p_msg->len + p_msg->offset <= p_tcb->payload_size &&
552 handle_len == p_msg->offset)
553 {
554 if (op_code != GATT_REQ_FIND_TYPE_VALUE ||
555 gatt_uuid_compare(value, *p_uuid))
556 {
557 UINT16_TO_STREAM(p, p_rcb->s_hdl);
558
559 if (p_list->p_last_primary == p_srv &&
560 p_list->p_last_primary == p_list->p_last)
561 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700562 GATT_TRACE_DEBUG("Use 0xFFFF for the last primary attribute");
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700563 UINT16_TO_STREAM(p, 0xFFFF); /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */
564 }
565 else
566 {
567 UINT16_TO_STREAM(p, p_rcb->e_hdl);
568 }
569
570 if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
571 gatt_build_uuid_to_stream(&p, *p_uuid);
572
573 status = GATT_SUCCESS;
574 p_msg->len += p_msg->offset;
575 }
576 }
577 else
578 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800580 }
581 p_srv = p_srv->p_next;
582 }
583 p_msg->offset = L2CAP_MIN_OFFSET;
584
585 return status;
586}
587
588/*******************************************************************************
589**
590** Function gatt_build_find_info_rsp
591**
592** Description fill the find information response information in the given
593** buffer.
594**
595** Returns TRUE: if data filled sucessfully.
596** FALSE: packet full, or format mismatch.
597**
598*******************************************************************************/
599static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, UINT16 *p_len,
600 UINT16 s_hdl, UINT16 e_hdl)
601{
602 tGATT_STATUS status = GATT_NOT_FOUND;
603 UINT8 *p;
604 UINT16 len = *p_len;
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700605 tGATT_ATTR *p_attr = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800606 UINT8 info_pair_len[2] = {4, 18};
607
608 if (!p_rcb->p_db || !p_rcb->p_db->p_attr_list)
609 return status;
610
611 /* check the attribute database */
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700612 p_attr = (tGATT_ATTR *) p_rcb->p_db->p_attr_list;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800613
614 p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET + p_msg->len;
615
616 while (p_attr)
617 {
618 if (p_attr->handle > e_hdl)
619 {
620 break;
621 }
622
623 if (p_attr->handle >= s_hdl)
624 {
625 if (p_msg->offset == 0)
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700626 p_msg->offset = (p_attr->uuid.len == LEN_UUID_16) ? GATT_INFO_TYPE_PAIR_16 : GATT_INFO_TYPE_PAIR_128;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800627
628 if (len >= info_pair_len[p_msg->offset - 1])
629 {
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700630 if (p_msg->offset == GATT_INFO_TYPE_PAIR_16 && p_attr->uuid.len == LEN_UUID_16)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800631 {
632 UINT16_TO_STREAM(p, p_attr->handle);
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700633 UINT16_TO_STREAM(p, p_attr->uuid.uu.uuid16);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800634 }
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700635 else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && p_attr->uuid.len == LEN_UUID_128 )
The Android Open Source Project5738f832012-12-12 16:00:35 -0800636 {
637 UINT16_TO_STREAM(p, p_attr->handle);
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700638 ARRAY_TO_STREAM (p, p_attr->uuid.uu.uuid128, LEN_UUID_128);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800639 }
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700640 else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && p_attr->uuid.len == LEN_UUID_32)
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700641 {
642 UINT16_TO_STREAM(p, p_attr->handle);
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700643 gatt_convert_uuid32_to_uuid128(p, p_attr->uuid.uu.uuid32);
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700644 p += LEN_UUID_128;
645 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800646 else
647 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700648 GATT_TRACE_ERROR("format mismatch");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800649 status = GATT_NO_RESOURCES;
650 break;
651 /* format mismatch */
652 }
653 p_msg->len += info_pair_len[p_msg->offset - 1];
654 len -= info_pair_len[p_msg->offset - 1];
655 status = GATT_SUCCESS;
656
657 }
658 else
659 {
660 status = GATT_NO_RESOURCES;
661 break;
662 }
663 }
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -0700664 p_attr = (tGATT_ATTR *)p_attr->p_next;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800665 }
666
667 *p_len = len;
668 return status;
669}
670
671/*******************************************************************************
672**
673** Function gatts_internal_read_by_type_req
674**
675** Description check to see if the ReadByType request can be handled internally.
676**
677** Returns void
678**
679*******************************************************************************/
680static tGATT_STATUS gatts_validate_packet_format(UINT8 op_code, UINT16 *p_len,
681 UINT8 **p_data, tBT_UUID *p_uuid_filter,
682 UINT16 *p_s_hdl, UINT16 *p_e_hdl)
683{
684 tGATT_STATUS reason = GATT_SUCCESS;
685 UINT16 uuid_len, s_hdl = 0, e_hdl = 0;
686 UINT16 len = *p_len;
687 UINT8 *p = *p_data;
688
689 if (len >= 4)
690 {
691 /* obtain starting handle, and ending handle */
692 STREAM_TO_UINT16(s_hdl, p);
693 STREAM_TO_UINT16(e_hdl, p);
694 len -= 4;
695
696 if (s_hdl > e_hdl || !GATT_HANDLE_IS_VALID(s_hdl) || !GATT_HANDLE_IS_VALID(e_hdl))
697 {
698 reason = GATT_INVALID_HANDLE;
699 }
700 /* for these PDUs, uuid filter must present */
701 else if (op_code == GATT_REQ_READ_BY_GRP_TYPE ||
702 op_code == GATT_REQ_FIND_TYPE_VALUE ||
703 op_code == GATT_REQ_READ_BY_TYPE)
704 {
705 if (len >= 2 && p_uuid_filter != NULL)
706 {
707 uuid_len = (op_code == GATT_REQ_FIND_TYPE_VALUE) ? 2 : len;
708
709 /* parse uuid now */
710 if (gatt_parse_uuid_from_cmd (p_uuid_filter, uuid_len, &p) == FALSE ||
711 p_uuid_filter->len == 0)
712 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700713 GATT_TRACE_DEBUG("UUID filter does not exsit");
The Android Open Source Project5738f832012-12-12 16:00:35 -0800714 reason = GATT_INVALID_PDU;
715 }
716 else
717 len -= p_uuid_filter->len;
718 }
719 else
720 reason = GATT_INVALID_PDU;
721 }
722 }
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700723 else
724 reason = GATT_INVALID_PDU;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800725
726 *p_data = p;
727 *p_len = len;
728 *p_s_hdl = s_hdl;
729 *p_e_hdl = e_hdl;
730
731 return reason;
732}
733
734/*******************************************************************************
735**
736** Function gatts_process_primary_service_req
737**
738** Description process ReadByGroupType/ReadByTypeValue request, for discover
739** all primary services or discover primary service by UUID request.
740**
741** Returns void
742**
743*******************************************************************************/
744void gatts_process_primary_service_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
745{
746 UINT8 reason = GATT_INVALID_PDU;
747 UINT16 s_hdl = 0, e_hdl = 0;
748 tBT_UUID uuid, value, primary_service = {LEN_UUID_16, {GATT_UUID_PRI_SERVICE}};
749 BT_HDR *p_msg = NULL;
750 UINT16 msg_len = (UINT16)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET);
751
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700752 memset (&value, 0, sizeof(tBT_UUID));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800753 reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, &e_hdl);
754
755 if (reason == GATT_SUCCESS)
756 {
757 if (gatt_uuid_compare(uuid, primary_service))
758 {
759 if (op_code == GATT_REQ_FIND_TYPE_VALUE)
760 {
761 if (gatt_parse_uuid_from_cmd(&value, len, &p_data) == FALSE)
762 reason = GATT_INVALID_PDU;
763 }
764
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800765 if (reason == GATT_SUCCESS) {
766 p_msg = (BT_HDR *)osi_calloc(msg_len);
767 reason = gatt_build_primary_service_rsp (p_msg, p_tcb, op_code,
768 s_hdl, e_hdl, p_data,
769 value);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800770 }
771 }
772 else
773 {
774 if (op_code == GATT_REQ_READ_BY_GRP_TYPE)
775 {
776 reason = GATT_UNSUPPORT_GRP_TYPE;
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700777 GATT_TRACE_DEBUG("unexpected ReadByGrpType Group: 0x%04x", uuid.uu.uuid16);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800778 }
779 else
780 {
781 /* we do not support ReadByTypeValue with any non-primamry_service type */
782 reason = GATT_NOT_FOUND;
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700783 GATT_TRACE_DEBUG("unexpected ReadByTypeValue type: 0x%04x", uuid.uu.uuid16);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800784 }
785 }
786 }
787
788 if (reason != GATT_SUCCESS)
789 {
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800790 osi_free(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800791 gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, FALSE);
792 }
793 else
794 attp_send_sr_msg(p_tcb, p_msg);
795
796}
797
798/*******************************************************************************
799**
800** Function gatts_process_find_info
801**
802** Description process find information request, for discover character
803** descriptors.
804**
805** Returns void
806**
807*******************************************************************************/
808static void gatts_process_find_info(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
809{
810 UINT8 reason = GATT_INVALID_PDU, *p;
811 UINT16 s_hdl = 0, e_hdl = 0, buf_len;
812 BT_HDR *p_msg = NULL;
813 tGATT_SR_REG *p_rcb;
814 tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info;
815 tGATT_SRV_LIST_ELEM *p_srv=NULL;
816
817 reason = gatts_validate_packet_format(op_code, &len, &p_data, NULL, &s_hdl, &e_hdl);
818
819 if (reason == GATT_SUCCESS)
820 {
821 buf_len = (UINT16)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET);
822
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800823 p_msg = (BT_HDR *)osi_calloc(buf_len);
824 reason = GATT_NOT_FOUND;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800825
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800826 p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
827 *p ++ = op_code + 1;
828 p_msg->len = 2;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800829
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800830 buf_len = p_tcb->payload_size - 2;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800831
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800832 p_srv = p_list->p_first;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800833
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800834 while (p_srv) {
835 p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800836
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800837 if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl ||
838 p_rcb->e_hdl < s_hdl)) {
839 reason = gatt_build_find_info_rsp(p_rcb, p_msg, &buf_len,
840 s_hdl, e_hdl);
841 if (reason == GATT_NO_RESOURCES) {
842 reason = GATT_SUCCESS;
843 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800844 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800845 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800846 p_srv = p_srv->p_next;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800847 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800848 *p = (UINT8)p_msg->offset;
849
850 p_msg->offset = L2CAP_MIN_OFFSET;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800851 }
852
853 if (reason != GATT_SUCCESS)
854 {
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800855 osi_free(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800856 gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, FALSE);
857 }
858 else
859 attp_send_sr_msg(p_tcb, p_msg);
860
861}
862
863/*******************************************************************************
864**
865** Function gatts_process_mtu_req
866**
867** Description This function is called to process excahnge MTU request.
868** Only used on LE.
869**
870** Returns void
871**
872*******************************************************************************/
873static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data)
874{
875 UINT16 mtu = 0;
876 UINT8 *p = p_data, i;
877 BT_HDR *p_buf;
878 UINT16 conn_id;
879
The Android Open Source Project5738f832012-12-12 16:00:35 -0800880 /* BR/EDR conenction, send error response */
881 if (p_tcb->att_lcid != L2CAP_ATT_CID)
882 {
883 gatt_send_error_rsp (p_tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, FALSE);
884 }
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700885 else if (len < GATT_MTU_REQ_MIN_LEN)
886 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700887 GATT_TRACE_ERROR("invalid MTU request PDU received.");
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700888 gatt_send_error_rsp (p_tcb, GATT_INVALID_PDU, GATT_REQ_MTU, 0, FALSE);
889 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800890 else
891 {
Andre Eisenbachccf9c152013-10-02 15:37:21 -0700892 STREAM_TO_UINT16 (mtu, p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800893 /* mtu must be greater than default MTU which is 23/48 */
Andre Eisenbach4b638692013-06-14 13:22:25 -0700894 if (mtu < GATT_DEF_BLE_MTU_SIZE)
895 p_tcb->payload_size = GATT_DEF_BLE_MTU_SIZE;
896 else if (mtu > GATT_MAX_MTU_SIZE)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800897 p_tcb->payload_size = GATT_MAX_MTU_SIZE;
Andre Eisenbach4b638692013-06-14 13:22:25 -0700898 else
899 p_tcb->payload_size = mtu;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800900
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700901 GATT_TRACE_ERROR("MTU request PDU with MTU size %d", p_tcb->payload_size);
Zhihai Xu52c0ccb2014-03-20 17:50:12 -0700902
Priti Aghera636d6712014-12-18 13:55:48 -0800903 l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
904
The Android Open Source Project5738f832012-12-12 16:00:35 -0800905 if ((p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, (tGATT_SR_MSG *) &p_tcb->payload_size)) != NULL)
906 {
907 attp_send_sr_msg (p_tcb, p_buf);
908
909 /* Notify all registered applicaiton with new MTU size. Us a transaction ID */
910 /* of 0, as no response is allowed from applcations */
911
912 for (i = 0; i < GATT_MAX_APPS; i ++)
913 {
914 if (gatt_cb.cl_rcb[i].in_use )
915 {
916 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, gatt_cb.cl_rcb[i].gatt_if);
917 gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU,
918 (tGATTS_DATA *)&p_tcb->payload_size);
919 }
920 }
921
922 }
923 }
924}
925
926/*******************************************************************************
927**
928** Function gatts_process_read_by_type_req
929**
930** Description process Read By type request.
931** This PDU can be used to perform:
932** - read characteristic value
933** - read characteristic descriptor value
934** - discover characteristic
935** - discover characteristic by UUID
936** - relationship discovery
937**
938** Returns void
939**
940*******************************************************************************/
941void gatts_process_read_by_type_req(tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
942{
943 tBT_UUID uuid;
944 tGATT_SR_REG *p_rcb;
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -0800945 size_t msg_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET;
946 UINT16 buf_len, s_hdl, e_hdl, err_hdl = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800947 BT_HDR *p_msg = NULL;
948 tGATT_STATUS reason, ret;
949 UINT8 *p;
950 UINT8 sec_flag, key_size;
951 tGATT_SRV_LIST_INFO *p_list= &gatt_cb.srv_list_info;
952 tGATT_SRV_LIST_ELEM *p_srv=NULL;
953
954 reason = gatts_validate_packet_format(op_code, &len, &p_data, &uuid, &s_hdl, &e_hdl);
955
956#if GATT_CONFORMANCE_TESTING == TRUE
957 if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code)
958 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -0700959 GATT_TRACE_DEBUG("Conformance tst: forced err rsp for ReadByType: error status=%d", gatt_cb.err_status);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800960
961 gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, s_hdl, FALSE);
962
963 return;
964 }
965#endif
966
967 if (reason == GATT_SUCCESS)
968 {
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800969 p_msg = (BT_HDR *)osi_calloc(msg_len);
970 p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800971
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800972 *p ++ = op_code + 1;
973 /* reserve length byte */
974 p_msg->len = 2;
975 buf_len = p_tcb->payload_size - 2;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800976
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800977 reason = GATT_NOT_FOUND;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800978
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800979 p_srv = p_list->p_first;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800980
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800981 while (p_srv) {
982 p_rcb = GATT_GET_SR_REG_PTR(p_srv->i_sreg);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800983
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800984 if (p_rcb->in_use && !(p_rcb->s_hdl > e_hdl ||
985 p_rcb->e_hdl < s_hdl)) {
986 gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport,
987 &sec_flag, &key_size);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800988
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -0800989 ret = gatts_db_read_attr_value_by_type(p_tcb,
990 p_rcb->p_db,
991 op_code,
992 p_msg,
993 s_hdl,
994 e_hdl,
995 uuid,
996 &buf_len,
997 sec_flag,
998 key_size,
999 0,
1000 &err_hdl);
1001 if (ret != GATT_NOT_FOUND) {
1002 reason = ret;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001003
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001004 if (ret == GATT_NO_RESOURCES)
1005 reason = GATT_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001006 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001007 if (ret != GATT_SUCCESS && ret != GATT_NOT_FOUND) {
1008 s_hdl = err_hdl;
1009 break;
1010 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001011 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001012 p_srv = p_srv->p_next;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001013 }
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001014 *p = (UINT8)p_msg->offset;
1015 p_msg->offset = L2CAP_MIN_OFFSET;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001016 }
1017 if (reason != GATT_SUCCESS)
1018 {
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -08001019 osi_free(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001020
1021 /* in theroy BUSY is not possible(should already been checked), protected check */
1022 if (reason != GATT_PENDING && reason != GATT_BUSY)
1023 gatt_send_error_rsp (p_tcb, reason, op_code, s_hdl, FALSE);
1024 }
1025 else
1026 attp_send_sr_msg(p_tcb, p_msg);
1027
1028}
1029
1030/*******************************************************************************
1031**
1032** Function gatts_process_write_req
1033**
1034** Description This function is called to process the write request
1035** from client.
1036**
1037** Returns void
1038**
1039*******************************************************************************/
1040void gatts_process_write_req (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 handle,
Jakub Pawlowskia641b6f2016-03-26 00:47:23 -07001041 UINT8 op_code, UINT16 len, UINT8 *p_data,
1042 bt_gatt_db_attribute_type_t gatt_type)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001043{
1044 tGATTS_DATA sr_data;
1045 UINT32 trans_id;
1046 tGATT_STATUS status;
1047 UINT8 sec_flag, key_size, *p = p_data;
1048 tGATT_SR_REG *p_sreg;
1049 UINT16 conn_id;
1050
1051 memset(&sr_data, 0, sizeof(tGATTS_DATA));
1052
1053 switch (op_code)
1054 {
1055 case GATT_REQ_PREPARE_WRITE:
Subramanian Srinivasan0acfd132016-02-01 16:21:10 -08001056 if (len < 2) {
1057 GATT_TRACE_ERROR("%s: Prepare write request was invalid - missing offset, sending error response", __func__);
1058 gatt_send_error_rsp(p_tcb, GATT_INVALID_PDU, op_code, handle, FALSE);
1059 return;
1060 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001061 sr_data.write_req.is_prep = TRUE;
1062 STREAM_TO_UINT16(sr_data.write_req.offset, p);
1063 len -= 2;
1064 /* fall through */
1065 case GATT_SIGN_CMD_WRITE:
1066 if (op_code == GATT_SIGN_CMD_WRITE)
1067 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001068 GATT_TRACE_DEBUG("Write CMD with data sigining" );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001069 len -= GATT_AUTH_SIGN_LEN;
1070 }
1071 /* fall through */
1072 case GATT_CMD_WRITE:
1073 case GATT_REQ_WRITE:
1074 if (op_code == GATT_REQ_WRITE || op_code == GATT_REQ_PREPARE_WRITE)
1075 sr_data.write_req.need_rsp = TRUE;
1076 sr_data.write_req.handle = handle;
1077 sr_data.write_req.len = len;
Satya Calloji444a8da2015-03-06 10:38:22 -08001078 if (len != 0 && p != NULL)
1079 {
1080 memcpy (sr_data.write_req.value, p, len);
1081 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001082 break;
1083 }
1084
1085 gatt_sr_get_sec_info(p_tcb->peer_bda,
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001086 p_tcb->transport,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001087 &sec_flag,
1088 &key_size);
1089
1090 status = gatts_write_attr_perm_check (gatt_cb.sr_reg[i_rcb].p_db,
1091 op_code,
1092 handle,
1093 sr_data.write_req.offset,
1094 p,
1095 len,
1096 sec_flag,
1097 key_size);
1098
1099 if (status == GATT_SUCCESS)
1100 {
1101 if ((trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle)) != 0)
1102 {
1103 p_sreg = &gatt_cb.sr_reg[i_rcb];
1104 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_sreg->gatt_if);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001105
Jakub Pawlowskia641b6f2016-03-26 00:47:23 -07001106 UINT8 opcode = 0;
1107 if (gatt_type == BTGATT_DB_DESCRIPTOR) {
1108 opcode = GATTS_REQ_TYPE_WRITE_DESCRIPTOR;
1109 } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) {
1110 opcode = GATTS_REQ_TYPE_WRITE_CHARACTERISTIC;
1111 } else {
1112 GATT_TRACE_ERROR("%s: Attempt to write attribute that's not tied with"
1113 " characteristic or descriptor value.", __func__);
1114 status = GATT_ERROR;
1115 }
1116
1117 if (opcode) {
1118 gatt_sr_send_req_callback(conn_id, trans_id, opcode, &sr_data);
1119 status = GATT_PENDING;
1120 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001121 }
1122 else
1123 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001124 GATT_TRACE_ERROR("max pending command, send error");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001125 status = GATT_BUSY; /* max pending command, application error */
1126 }
1127 }
1128
1129 /* in theroy BUSY is not possible(should already been checked), protected check */
1130 if (status != GATT_PENDING && status != GATT_BUSY &&
1131 (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_REQ_WRITE))
1132 {
1133 gatt_send_error_rsp (p_tcb, status, op_code, handle, FALSE);
1134 }
1135 return;
1136}
1137
1138/*******************************************************************************
1139**
1140** Function gatts_process_read_req
1141**
1142** Description This function is called to process the read request
1143** from client.
1144**
1145** Returns void
1146**
1147*******************************************************************************/
1148static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8 op_code,
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001149 UINT16 handle, UINT16 len, UINT8 *p_data)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001150{
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -08001151 size_t buf_len = sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001152 tGATT_STATUS reason;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001153 UINT8 sec_flag, key_size, *p;
1154 UINT16 offset = 0, value_len = 0;
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001155 BT_HDR *p_msg = (BT_HDR *)osi_calloc(buf_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001156
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001157 UNUSED(len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001158
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001159 if (op_code == GATT_REQ_READ_BLOB)
1160 STREAM_TO_UINT16(offset, p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001161
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001162 p = (UINT8 *)(p_msg + 1) + L2CAP_MIN_OFFSET;
1163 *p ++ = op_code + 1;
1164 p_msg->len = 1;
1165 buf_len = p_tcb->payload_size - 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001166
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001167 gatt_sr_get_sec_info(p_tcb->peer_bda, p_tcb->transport, &sec_flag,
1168 &key_size);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001169
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001170 reason = gatts_read_attr_value_by_handle(p_tcb,
1171 p_rcb->p_db,
1172 op_code,
1173 handle,
1174 offset,
1175 p,
1176 &value_len,
1177 (uint16_t)buf_len,
1178 sec_flag,
1179 key_size,
1180 0);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001181
Pavlin Radoslavov717a4a92016-02-06 08:36:06 -08001182 p_msg->len += value_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001183
1184 if (reason != GATT_SUCCESS)
1185 {
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -08001186 osi_free(p_msg);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001187
1188 /* in theroy BUSY is not possible(should already been checked), protected check */
1189 if (reason != GATT_PENDING && reason != GATT_BUSY)
1190 gatt_send_error_rsp (p_tcb, reason, op_code, handle, FALSE);
1191 }
1192 else
1193 attp_send_sr_msg(p_tcb, p_msg);
1194
1195}
1196
1197/*******************************************************************************
1198**
1199** Function gatts_process_attribute_req
1200**
1201** Description This function is called to process the per attribute handle request
1202** from client.
1203**
1204** Returns void
1205**
1206*******************************************************************************/
1207void gatts_process_attribute_req (tGATT_TCB *p_tcb, UINT8 op_code,
1208 UINT16 len, UINT8 *p_data)
1209{
Andre Eisenbachccf9c152013-10-02 15:37:21 -07001210 UINT16 handle = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001211 UINT8 *p = p_data, i;
1212 tGATT_SR_REG *p_rcb = gatt_cb.sr_reg;
1213 tGATT_STATUS status = GATT_INVALID_HANDLE;
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -07001214 tGATT_ATTR *p_attr;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001215
Andre Eisenbachccf9c152013-10-02 15:37:21 -07001216 if (len < 2)
1217 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001218 GATT_TRACE_ERROR("Illegal PDU length, discard request");
Andre Eisenbachccf9c152013-10-02 15:37:21 -07001219 status = GATT_INVALID_PDU;
1220 }
1221 else
1222 {
1223 STREAM_TO_UINT16(handle, p);
1224 len -= 2;
1225 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001226
1227#if GATT_CONFORMANCE_TESTING == TRUE
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07001228 gatt_cb.handle = handle;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001229 if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code)
1230 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001231 GATT_TRACE_DEBUG("Conformance tst: forced err rsp: error status=%d", gatt_cb.err_status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001232
1233 gatt_send_error_rsp (p_tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, FALSE);
1234
1235 return;
1236 }
1237#endif
1238
1239 if (GATT_HANDLE_IS_VALID(handle))
1240 {
1241 for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_rcb ++)
1242 {
1243 if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle)
1244 {
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -07001245 p_attr = (tGATT_ATTR *)p_rcb->p_db->p_attr_list;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001246
1247 while (p_attr)
1248 {
1249 if (p_attr->handle == handle)
1250 {
1251 switch (op_code)
1252 {
1253 case GATT_REQ_READ: /* read char/char descriptor value */
1254 case GATT_REQ_READ_BLOB:
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001255 gatts_process_read_req(p_tcb, p_rcb, op_code, handle, len, p);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001256 break;
1257
1258 case GATT_REQ_WRITE: /* write char/char descriptor value */
1259 case GATT_CMD_WRITE:
1260 case GATT_SIGN_CMD_WRITE:
1261 case GATT_REQ_PREPARE_WRITE:
Jakub Pawlowskia641b6f2016-03-26 00:47:23 -07001262 gatts_process_write_req(p_tcb, i, handle, op_code, len, p,
1263 p_attr->gatt_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001264 break;
1265 default:
1266 break;
1267 }
1268 status = GATT_SUCCESS;
1269 break;
1270 }
Jakub Pawlowskic88b20a2016-06-21 16:16:09 -07001271 p_attr = (tGATT_ATTR *)p_attr->p_next;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001272 }
1273 break;
1274 }
1275 }
1276 }
1277
1278 if (status != GATT_SUCCESS && op_code != GATT_CMD_WRITE && op_code != GATT_SIGN_CMD_WRITE)
1279 gatt_send_error_rsp (p_tcb, status, op_code, handle, FALSE);
1280}
1281
1282/*******************************************************************************
1283**
1284** Function gatts_proc_srv_chg_ind_ack
1285**
1286** Description This function process the service changed indicaiton ACK
1287**
1288** Returns void
1289**
1290*******************************************************************************/
1291static void gatts_proc_srv_chg_ind_ack(tGATT_TCB *p_tcb )
1292{
1293 tGATTS_SRV_CHG_REQ req;
1294 tGATTS_SRV_CHG *p_buf = NULL;
1295
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001296 GATT_TRACE_DEBUG("gatts_proc_srv_chg_ind_ack");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001297
1298 if ((p_buf = gatt_is_bda_in_the_srv_chg_clt_list(p_tcb->peer_bda)) != NULL)
1299 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001300 GATT_TRACE_DEBUG("NV update set srv chg = FALSE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001301 p_buf->srv_changed = FALSE;
1302 memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG));
1303 if (gatt_cb.cb_info.p_srv_chg_callback)
1304 (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT,&req, NULL);
1305 }
1306}
1307
1308/*******************************************************************************
1309**
1310** Function gatts_chk_pending_ind
1311**
1312** Description This function check any pending indication needs to be sent if
1313** there is a pending indication then sent the indication
1314**
1315** Returns void
1316**
1317*******************************************************************************/
1318static void gatts_chk_pending_ind(tGATT_TCB *p_tcb )
1319{
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -07001320 GATT_TRACE_DEBUG("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001321
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -07001322 tGATT_VALUE *p_buf = (tGATT_VALUE *)fixed_queue_try_peek_first(p_tcb->pending_ind_q);
1323 if (p_buf != NULL)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001324 {
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -07001325 GATTS_HandleValueIndication(p_buf->conn_id,
1326 p_buf->handle,
1327 p_buf->len,
1328 p_buf->value);
Pavlin Radoslavovcceb4302016-02-05 13:54:43 -08001329 osi_free(fixed_queue_try_remove_from_queue(p_tcb->pending_ind_q,
Pavlin Radoslavov1a3844f2015-09-25 11:21:15 -07001330 p_buf));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001331 }
1332}
1333
1334/*******************************************************************************
1335**
1336** Function gatts_proc_ind_ack
1337**
1338** Description This function process the Indication ack
1339**
1340** Returns TRUE continue to process the indication ack by the aaplication
1341** if the ACk is not a Service Changed Indication Ack
1342**
1343*******************************************************************************/
1344static BOOLEAN gatts_proc_ind_ack(tGATT_TCB *p_tcb, UINT16 ack_handle)
1345{
1346 BOOLEAN continue_processing = TRUE;
1347
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001348 GATT_TRACE_DEBUG ("gatts_proc_ind_ack ack handle=%d", ack_handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001349
1350 if (ack_handle == gatt_cb.handle_of_h_r)
1351 {
1352 gatts_proc_srv_chg_ind_ack(p_tcb);
1353 /* there is no need to inform the application since srv chg is handled internally by GATT */
1354 continue_processing = FALSE;
1355 }
1356
1357 gatts_chk_pending_ind(p_tcb);
1358 return continue_processing;
1359}
1360
1361/*******************************************************************************
1362**
1363** Function gatts_process_value_conf
1364**
1365** Description This function is called to process the handle value confirmation.
1366**
1367** Returns void
1368**
1369*******************************************************************************/
1370void gatts_process_value_conf(tGATT_TCB *p_tcb, UINT8 op_code)
1371{
1372 UINT16 handle = p_tcb->indicate_handle;
1373 UINT32 trans_id;
1374 UINT8 i;
1375 tGATT_SR_REG *p_rcb = gatt_cb.sr_reg;
1376 BOOLEAN continue_processing;
1377 UINT16 conn_id;
1378
Pavlin Radoslavov78bcff72015-12-04 17:36:34 -08001379 alarm_cancel(p_tcb->conf_timer);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001380 if (GATT_HANDLE_IS_VALID(handle))
1381 {
1382 p_tcb->indicate_handle = 0;
1383 continue_processing = gatts_proc_ind_ack(p_tcb, handle);
1384
1385 if (continue_processing)
1386 {
1387 for (i = 0; i < GATT_MAX_SR_PROFILES; i ++, p_rcb ++)
1388 {
1389 if (p_rcb->in_use && p_rcb->s_hdl <= handle && p_rcb->e_hdl >= handle)
1390 {
1391 trans_id = gatt_sr_enqueue_cmd(p_tcb, op_code, handle);
1392 conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_rcb->gatt_if);
1393 gatt_sr_send_req_callback(conn_id,
1394 trans_id, GATTS_REQ_TYPE_CONF, (tGATTS_DATA *)&handle);
1395 }
1396 }
1397 }
1398 }
1399 else
1400 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001401 GATT_TRACE_ERROR("unexpected handle value confirmation");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001402 }
1403}
1404
1405/*******************************************************************************
1406**
1407** Function gatt_server_handle_client_req
1408**
1409** Description This function is called to handle the client requests to
1410** server.
1411**
1412**
1413** Returns void
1414**
1415*******************************************************************************/
1416void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code,
1417 UINT16 len, UINT8 *p_data)
1418{
1419 /* there is pending command, discard this one */
1420 if (!gatt_sr_cmd_empty(p_tcb) && op_code != GATT_HANDLE_VALUE_CONF)
1421 return;
1422
1423 /* the size of the message may not be bigger than the local max PDU size*/
1424 /* The message has to be smaller than the agreed MTU, len does not include op code */
1425 if (len >= p_tcb->payload_size)
1426 {
Sharvil Nanavatib44cc592014-05-04 10:03:35 -07001427 GATT_TRACE_ERROR("server receive invalid PDU size:%d pdu size:%d", len + 1, p_tcb->payload_size );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001428 /* for invalid request expecting response, send it now */
1429 if (op_code != GATT_CMD_WRITE &&
1430 op_code != GATT_SIGN_CMD_WRITE &&
1431 op_code != GATT_HANDLE_VALUE_CONF)
1432 {
1433 gatt_send_error_rsp (p_tcb, GATT_INVALID_PDU, op_code, 0, FALSE);
1434 }
1435 /* otherwise, ignore the pkt */
1436 }
1437 else
1438 {
1439 switch (op_code)
1440 {
1441 case GATT_REQ_READ_BY_GRP_TYPE: /* discover primary services */
1442 case GATT_REQ_FIND_TYPE_VALUE: /* discover service by UUID */
1443 gatts_process_primary_service_req (p_tcb, op_code, len, p_data);
1444 break;
1445
1446 case GATT_REQ_FIND_INFO:/* discover char descrptor */
1447 gatts_process_find_info(p_tcb, op_code, len, p_data);
1448 break;
1449
1450 case GATT_REQ_READ_BY_TYPE: /* read characteristic value, char descriptor value */
1451 /* discover characteristic, discover char by UUID */
1452 gatts_process_read_by_type_req(p_tcb, op_code, len, p_data);
1453 break;
1454
1455
1456 case GATT_REQ_READ: /* read char/char descriptor value */
1457 case GATT_REQ_READ_BLOB:
1458 case GATT_REQ_WRITE: /* write char/char descriptor value */
1459 case GATT_CMD_WRITE:
1460 case GATT_SIGN_CMD_WRITE:
1461 case GATT_REQ_PREPARE_WRITE:
1462 gatts_process_attribute_req (p_tcb, op_code, len, p_data);
1463 break;
1464
1465 case GATT_HANDLE_VALUE_CONF:
1466 gatts_process_value_conf (p_tcb, op_code);
1467 break;
1468
1469 case GATT_REQ_MTU:
1470 gatts_process_mtu_req (p_tcb, len, p_data);
1471 break;
1472
1473 case GATT_REQ_EXEC_WRITE:
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001474 gatt_process_exec_write_req (p_tcb, op_code, len, p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001475 break;
1476
1477 case GATT_REQ_READ_MULTI:
1478 gatt_process_read_multi_req (p_tcb, op_code, len, p_data);
1479 break;
1480
1481 default:
1482 break;
1483 }
1484 }
1485}
1486
1487#endif /* BLE_INCLUDED */