The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2008-2012 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 26 | #include "bt_utils.h" |
Myles Watson | d7ffd64 | 2016-10-27 10:27:36 -0700 | [diff] [blame] | 27 | #include "osi/include/osi.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 29 | #include <string.h> |
| 30 | #include "gatt_int.h" |
| 31 | #include "l2c_api.h" |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 32 | #include "l2c_int.h" |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 33 | #define GATT_MTU_REQ_MIN_LEN 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 34 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 35 | using base::StringPrintf; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 36 | using bluetooth::Uuid; |
| 37 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 39 | * |
| 40 | * Function gatt_sr_enqueue_cmd |
| 41 | * |
| 42 | * Description This function enqueue the request from client which needs a |
| 43 | * application response, and update the transaction ID. |
| 44 | * |
| 45 | * Returns void |
| 46 | * |
| 47 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 48 | uint32_t gatt_sr_enqueue_cmd(tGATT_TCB& tcb, uint8_t op_code, uint16_t handle) { |
| 49 | tGATT_SR_CMD* p_cmd = &tcb.sr_cmd; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 50 | uint32_t trans_id = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 51 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 52 | if ((p_cmd->op_code == 0) || |
| 53 | (op_code == GATT_HANDLE_VALUE_CONF)) /* no pending request */ |
| 54 | { |
| 55 | if (op_code == GATT_CMD_WRITE || op_code == GATT_SIGN_CMD_WRITE || |
| 56 | op_code == GATT_REQ_MTU || op_code == GATT_HANDLE_VALUE_CONF) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 57 | trans_id = ++tcb.trans_id; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 58 | } else { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 59 | p_cmd->trans_id = ++tcb.trans_id; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 60 | p_cmd->op_code = op_code; |
| 61 | p_cmd->handle = handle; |
| 62 | p_cmd->status = GATT_NOT_FOUND; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 63 | tcb.trans_id %= GATT_TRANS_ID_MAX; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 64 | trans_id = p_cmd->trans_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 65 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 66 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 67 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 68 | return trans_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 72 | * |
| 73 | * Function gatt_sr_cmd_empty |
| 74 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 75 | * Description This function checks if the server command queue is empty. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 76 | * |
| 77 | * Returns true if empty, false if there is pending command. |
| 78 | * |
| 79 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 80 | bool gatt_sr_cmd_empty(tGATT_TCB& tcb) { return (tcb.sr_cmd.op_code == 0); } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 81 | |
| 82 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 83 | * |
| 84 | * Function gatt_dequeue_sr_cmd |
| 85 | * |
| 86 | * Description This function dequeue the request from command queue. |
| 87 | * |
| 88 | * Returns void |
| 89 | * |
| 90 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 91 | void gatt_dequeue_sr_cmd(tGATT_TCB& tcb) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 92 | /* Double check in case any buffers are queued */ |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 93 | VLOG(1) << "gatt_dequeue_sr_cmd"; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 94 | if (tcb.sr_cmd.p_rsp_msg) |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 95 | LOG(ERROR) << "free tcb.sr_cmd.p_rsp_msg = " << tcb.sr_cmd.p_rsp_msg; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 96 | osi_free_and_reset((void**)&tcb.sr_cmd.p_rsp_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 97 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 98 | while (!fixed_queue_is_empty(tcb.sr_cmd.multi_rsp_q)) |
| 99 | osi_free(fixed_queue_try_dequeue(tcb.sr_cmd.multi_rsp_q)); |
| 100 | fixed_queue_free(tcb.sr_cmd.multi_rsp_q, NULL); |
| 101 | memset(&tcb.sr_cmd, 0, sizeof(tGATT_SR_CMD)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 105 | * |
| 106 | * Function process_read_multi_rsp |
| 107 | * |
| 108 | * Description This function check the read multiple response. |
| 109 | * |
| 110 | * Returns bool if all replies have been received |
| 111 | * |
| 112 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 113 | static bool process_read_multi_rsp(tGATT_SR_CMD* p_cmd, tGATT_STATUS status, |
| 114 | tGATTS_RSP* p_msg, uint16_t mtu) { |
| 115 | uint16_t ii, total_len, len; |
| 116 | uint8_t* p; |
| 117 | bool is_overflow = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 119 | VLOG(1) << StringPrintf("%s status=%d mtu=%d", __func__, status, mtu); |
Subramanian Srinivasan | 089cd11 | 2016-05-16 11:14:03 -0700 | [diff] [blame] | 120 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 121 | if (p_cmd->multi_rsp_q == NULL) |
| 122 | p_cmd->multi_rsp_q = fixed_queue_new(SIZE_MAX); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 124 | /* Enqueue the response */ |
| 125 | BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(tGATTS_RSP)); |
| 126 | memcpy((void*)p_buf, (const void*)p_msg, sizeof(tGATTS_RSP)); |
| 127 | fixed_queue_enqueue(p_cmd->multi_rsp_q, p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 129 | p_cmd->status = status; |
| 130 | if (status == GATT_SUCCESS) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 131 | VLOG(1) << "Multi read count=" << fixed_queue_length(p_cmd->multi_rsp_q) |
| 132 | << " num_hdls=" << p_cmd->multi_req.num_handles; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 133 | /* Wait till we get all the responses */ |
| 134 | if (fixed_queue_length(p_cmd->multi_rsp_q) == |
| 135 | p_cmd->multi_req.num_handles) { |
| 136 | len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu; |
| 137 | p_buf = (BT_HDR*)osi_calloc(len); |
| 138 | p_buf->offset = L2CAP_MIN_OFFSET; |
| 139 | p = (uint8_t*)(p_buf + 1) + p_buf->offset; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 140 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 141 | /* First byte in the response is the opcode */ |
| 142 | *p++ = GATT_RSP_READ_MULTI; |
| 143 | p_buf->len = 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 144 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 145 | /* Now walk through the buffers puting the data into the response in order |
| 146 | */ |
| 147 | list_t* list = NULL; |
| 148 | const list_node_t* node = NULL; |
| 149 | if (!fixed_queue_is_empty(p_cmd->multi_rsp_q)) |
| 150 | list = fixed_queue_get_list(p_cmd->multi_rsp_q); |
| 151 | for (ii = 0; ii < p_cmd->multi_req.num_handles; ii++) { |
| 152 | tGATTS_RSP* p_rsp = NULL; |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 153 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 154 | if (list != NULL) { |
| 155 | if (ii == 0) |
| 156 | node = list_begin(list); |
| 157 | else |
| 158 | node = list_next(node); |
| 159 | if (node != list_end(list)) p_rsp = (tGATTS_RSP*)list_node(node); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 160 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 161 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 162 | if (p_rsp != NULL) { |
| 163 | total_len = (p_buf->len + p_rsp->attr_value.len); |
| 164 | |
| 165 | if (total_len > mtu) { |
| 166 | /* just send the partial response for the overflow case */ |
| 167 | len = p_rsp->attr_value.len - (total_len - mtu); |
| 168 | is_overflow = true; |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 169 | VLOG(1) << StringPrintf( |
| 170 | "multi read overflow available len=%d val_len=%d", len, |
| 171 | p_rsp->attr_value.len); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 172 | } else { |
| 173 | len = p_rsp->attr_value.len; |
| 174 | } |
| 175 | |
| 176 | if (p_rsp->attr_value.handle == p_cmd->multi_req.handles[ii]) { |
| 177 | memcpy(p, p_rsp->attr_value.value, len); |
| 178 | if (!is_overflow) p += len; |
| 179 | p_buf->len += len; |
| 180 | } else { |
| 181 | p_cmd->status = GATT_NOT_FOUND; |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | if (is_overflow) break; |
| 186 | |
| 187 | } else { |
| 188 | p_cmd->status = GATT_NOT_FOUND; |
| 189 | break; |
| 190 | } |
| 191 | |
| 192 | } /* loop through all handles*/ |
| 193 | |
| 194 | /* Sanity check on the buffer length */ |
| 195 | if (p_buf->len == 0) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 196 | LOG(ERROR) << __func__ << " nothing found!!"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 197 | p_cmd->status = GATT_NOT_FOUND; |
| 198 | osi_free(p_buf); |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 199 | VLOG(1) << __func__ << "osi_free(p_buf)"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 200 | } else if (p_cmd->p_rsp_msg != NULL) { |
| 201 | osi_free(p_buf); |
| 202 | } else { |
| 203 | p_cmd->p_rsp_msg = p_buf; |
| 204 | } |
| 205 | |
| 206 | return (true); |
| 207 | } |
| 208 | } else /* any handle read exception occurs, return error */ |
| 209 | { |
| 210 | return (true); |
| 211 | } |
| 212 | |
| 213 | /* If here, still waiting */ |
| 214 | return (false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 218 | * |
| 219 | * Function gatt_sr_process_app_rsp |
| 220 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 221 | * Description This function checks whether the response message from |
| 222 | * application matches any pending request. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 223 | * |
| 224 | * Returns void |
| 225 | * |
| 226 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 227 | tGATT_STATUS gatt_sr_process_app_rsp(tGATT_TCB& tcb, tGATT_IF gatt_if, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 228 | UNUSED_ATTR uint32_t trans_id, |
| 229 | uint8_t op_code, tGATT_STATUS status, |
| 230 | tGATTS_RSP* p_msg) { |
| 231 | tGATT_STATUS ret_code = GATT_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 232 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 233 | VLOG(1) << __func__ << " gatt_if=" << +gatt_if; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 234 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 235 | gatt_sr_update_cback_cnt(tcb, gatt_if, false, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 237 | if (op_code == GATT_REQ_READ_MULTI) { |
| 238 | /* If no error and still waiting, just return */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 239 | if (!process_read_multi_rsp(&tcb.sr_cmd, status, p_msg, tcb.payload_size)) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 240 | return (GATT_SUCCESS); |
| 241 | } else { |
| 242 | if (op_code == GATT_REQ_PREPARE_WRITE && status == GATT_SUCCESS) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 243 | gatt_sr_update_prep_cnt(tcb, gatt_if, true, false); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 244 | |
| 245 | if (op_code == GATT_REQ_EXEC_WRITE && status != GATT_SUCCESS) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 246 | gatt_sr_reset_cback_cnt(tcb); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 247 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 248 | tcb.sr_cmd.status = status; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 249 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 250 | if (gatt_sr_is_cback_cnt_zero(tcb) && status == GATT_SUCCESS) { |
| 251 | if (tcb.sr_cmd.p_rsp_msg == NULL) { |
| 252 | tcb.sr_cmd.p_rsp_msg = attp_build_sr_msg(tcb, (uint8_t)(op_code + 1), |
| 253 | (tGATT_SR_MSG*)p_msg); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 254 | } else { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 255 | LOG(ERROR) << "Exception!!! already has respond message"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 256 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 257 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 258 | } |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 259 | if (gatt_sr_is_cback_cnt_zero(tcb)) { |
| 260 | if ((tcb.sr_cmd.status == GATT_SUCCESS) && (tcb.sr_cmd.p_rsp_msg)) { |
| 261 | ret_code = attp_send_sr_msg(tcb, tcb.sr_cmd.p_rsp_msg); |
| 262 | tcb.sr_cmd.p_rsp_msg = NULL; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 263 | } else { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 264 | ret_code = |
| 265 | gatt_send_error_rsp(tcb, status, op_code, tcb.sr_cmd.handle, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 268 | gatt_dequeue_sr_cmd(tcb); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 269 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 270 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 271 | VLOG(1) << __func__ << " ret_code=" << +ret_code; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 272 | |
| 273 | return ret_code; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 277 | * |
| 278 | * Function gatt_process_exec_write_req |
| 279 | * |
| 280 | * Description This function is called to process the execute write request |
| 281 | * from client. |
| 282 | * |
| 283 | * Returns void |
| 284 | * |
| 285 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 286 | void gatt_process_exec_write_req(tGATT_TCB& tcb, uint8_t op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 287 | UNUSED_ATTR uint16_t len, uint8_t* p_data) { |
| 288 | uint8_t *p = p_data, flag, i = 0; |
| 289 | uint32_t trans_id = 0; |
| 290 | tGATT_IF gatt_if; |
| 291 | uint16_t conn_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 292 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 293 | #if (GATT_CONFORMANCE_TESTING == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 294 | if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 295 | VLOG(1) |
| 296 | << "Conformance tst: forced err rspv for Execute Write: error status=" |
| 297 | << +gatt_cb.err_status; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 298 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 299 | gatt_send_error_rsp(tcb, gatt_cb.err_status, gatt_cb.req_op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 300 | gatt_cb.handle, false); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 301 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 302 | return; |
| 303 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 304 | #endif |
| 305 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 306 | STREAM_TO_UINT8(flag, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 307 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 308 | /* mask the flag */ |
| 309 | flag &= GATT_PREP_WRITE_EXEC; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 311 | /* no prep write is queued */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 312 | if (!gatt_sr_is_prep_cnt_zero(tcb)) { |
| 313 | trans_id = gatt_sr_enqueue_cmd(tcb, op_code, 0); |
| 314 | gatt_sr_copy_prep_cnt_to_cback_cnt(tcb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 315 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 316 | for (i = 0; i < GATT_MAX_APPS; i++) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 317 | if (tcb.prep_cnt[i]) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 318 | gatt_if = (tGATT_IF)(i + 1); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 319 | conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, gatt_if); |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 320 | tGATTS_DATA gatts_data; |
| 321 | gatts_data.exec_write = flag; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 322 | gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 323 | &gatts_data); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 324 | tcb.prep_cnt[i] = 0; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 325 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 326 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 327 | } else /* nothing needs to be executed , send response now */ |
| 328 | { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 329 | LOG(ERROR) << "gatt_process_exec_write_req: no prepare write pending"; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 330 | gatt_send_error_rsp(tcb, GATT_ERROR, GATT_REQ_EXEC_WRITE, 0, false); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 331 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 335 | * |
| 336 | * Function gatt_process_read_multi_req |
| 337 | * |
| 338 | * Description This function is called to process the read multiple request |
| 339 | * from client. |
| 340 | * |
| 341 | * Returns void |
| 342 | * |
| 343 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 344 | void gatt_process_read_multi_req(tGATT_TCB& tcb, uint8_t op_code, uint16_t len, |
| 345 | uint8_t* p_data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 346 | uint32_t trans_id; |
| 347 | uint16_t handle = 0, ll = len; |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 348 | uint8_t* p = p_data; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 349 | tGATT_STATUS err = GATT_SUCCESS; |
| 350 | uint8_t sec_flag, key_size; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 351 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 352 | VLOG(1) << __func__; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 353 | tcb.sr_cmd.multi_req.num_handles = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 354 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 355 | gatt_sr_get_sec_info(tcb.peer_bda, tcb.transport, &sec_flag, &key_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 357 | #if (GATT_CONFORMANCE_TESTING == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 358 | if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 359 | VLOG(1) << "Conformance tst: forced err rspvofr ReadMultiple: error status=" |
| 360 | << +gatt_cb.err_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 362 | STREAM_TO_UINT16(handle, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 364 | gatt_send_error_rsp(tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 365 | false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 367 | return; |
| 368 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 369 | #endif |
| 370 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 371 | while (ll >= 2 && |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 372 | tcb.sr_cmd.multi_req.num_handles < GATT_MAX_READ_MULTI_HANDLES) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 373 | STREAM_TO_UINT16(handle, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 374 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 375 | auto it = gatt_sr_find_i_rcb_by_handle(handle); |
| 376 | if (it != gatt_cb.srv_list_info->end()) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 377 | tcb.sr_cmd.multi_req.handles[tcb.sr_cmd.multi_req.num_handles++] = handle; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 378 | |
| 379 | /* check read permission */ |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 380 | err = gatts_read_attr_perm_check(it->p_db, false, handle, sec_flag, |
| 381 | key_size); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 382 | if (err != GATT_SUCCESS) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 383 | VLOG(1) << StringPrintf("read permission denied : 0x%02x", err); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | } else { |
| 387 | /* invalid handle */ |
| 388 | err = GATT_INVALID_HANDLE; |
| 389 | break; |
| 390 | } |
| 391 | ll -= 2; |
| 392 | } |
| 393 | |
| 394 | if (ll != 0) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 395 | LOG(ERROR) << "max attribute handle reached in ReadMultiple Request."; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 398 | if (tcb.sr_cmd.multi_req.num_handles == 0) err = GATT_INVALID_HANDLE; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 399 | |
| 400 | if (err == GATT_SUCCESS) { |
| 401 | trans_id = |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 402 | gatt_sr_enqueue_cmd(tcb, op_code, tcb.sr_cmd.multi_req.handles[0]); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 403 | if (trans_id != 0) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 404 | gatt_sr_reset_cback_cnt(tcb); /* read multiple use multi_rsp_q's count*/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 405 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 406 | for (ll = 0; ll < tcb.sr_cmd.multi_req.num_handles; ll++) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 407 | tGATTS_RSP* p_msg = (tGATTS_RSP*)osi_calloc(sizeof(tGATTS_RSP)); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 408 | handle = tcb.sr_cmd.multi_req.handles[ll]; |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 409 | auto it = gatt_sr_find_i_rcb_by_handle(handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 411 | p_msg->attr_value.handle = handle; |
| 412 | err = gatts_read_attr_value_by_handle( |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 413 | tcb, it->p_db, op_code, handle, 0, p_msg->attr_value.value, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 414 | &p_msg->attr_value.len, GATT_MAX_ATTR_LEN, sec_flag, key_size, |
| 415 | trans_id); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 416 | |
| 417 | if (err == GATT_SUCCESS) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 418 | gatt_sr_process_app_rsp(tcb, it->gatt_if, trans_id, op_code, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 419 | GATT_SUCCESS, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 420 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 421 | /* either not using or done using the buffer, release it now */ |
| 422 | osi_free(p_msg); |
| 423 | } |
| 424 | } else |
| 425 | err = GATT_NO_RESOURCES; |
| 426 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 427 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 428 | /* in theroy BUSY is not possible(should already been checked), protected |
| 429 | * check */ |
| 430 | if (err != GATT_SUCCESS && err != GATT_PENDING && err != GATT_BUSY) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 431 | gatt_send_error_rsp(tcb, err, op_code, handle, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 435 | * |
| 436 | * Function gatt_build_primary_service_rsp |
| 437 | * |
| 438 | * Description Primamry service request processed internally. Theretically |
| 439 | * only deal with ReadByTypeVAlue and ReadByGroupType. |
| 440 | * |
| 441 | * Returns void |
| 442 | * |
| 443 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 444 | static tGATT_STATUS gatt_build_primary_service_rsp( |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 445 | BT_HDR* p_msg, tGATT_TCB& tcb, uint8_t op_code, uint16_t s_hdl, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 446 | uint16_t e_hdl, UNUSED_ATTR uint8_t* p_data, const Uuid& value) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 447 | tGATT_STATUS status = GATT_NOT_FOUND; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 448 | uint8_t handle_len = 4; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 449 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 450 | uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 451 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 452 | for (tGATT_SRV_LIST_ELEM& el : *gatt_cb.srv_list_info) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 453 | if (el.s_hdl < s_hdl || el.s_hdl > e_hdl || |
| 454 | el.type != GATT_UUID_PRI_SERVICE) { |
| 455 | continue; |
| 456 | } |
Andre Eisenbach | ccf9c15 | 2013-10-02 15:37:21 -0700 | [diff] [blame] | 457 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 458 | Uuid* p_uuid = gatts_get_service_uuid(el.p_db); |
| 459 | if (!p_uuid) continue; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 460 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 461 | if (op_code == GATT_REQ_READ_BY_GRP_TYPE) |
| 462 | handle_len = 4 + p_uuid->GetShortestRepresentationSize(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 463 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 464 | /* get the length byte in the repsonse */ |
| 465 | if (p_msg->offset == 0) { |
| 466 | *p++ = op_code + 1; |
| 467 | p_msg->len++; |
| 468 | p_msg->offset = handle_len; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 469 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 470 | if (op_code == GATT_REQ_READ_BY_GRP_TYPE) { |
| 471 | *p++ = (uint8_t)p_msg->offset; /* length byte */ |
| 472 | p_msg->len++; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 473 | } |
| 474 | } |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 475 | |
| 476 | if (p_msg->len + p_msg->offset > tcb.payload_size || |
| 477 | handle_len != p_msg->offset) { |
| 478 | break; |
| 479 | } |
| 480 | |
| 481 | if (op_code == GATT_REQ_FIND_TYPE_VALUE && value != *p_uuid) continue; |
| 482 | |
| 483 | UINT16_TO_STREAM(p, el.s_hdl); |
| 484 | |
Jakub Pawlowski | 4c6007c | 2018-04-16 07:55:06 -0700 | [diff] [blame^] | 485 | if (gatt_cb.last_service_handle && |
| 486 | gatt_cb.last_service_handle == el.s_hdl) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 487 | VLOG(1) << "Use 0xFFFF for the last primary attribute"; |
| 488 | /* see GATT ERRATA 4065, 4063, ATT ERRATA 4062 */ |
| 489 | UINT16_TO_STREAM(p, 0xFFFF); |
| 490 | } else { |
| 491 | UINT16_TO_STREAM(p, el.e_hdl); |
| 492 | } |
| 493 | |
| 494 | if (op_code == GATT_REQ_READ_BY_GRP_TYPE) |
| 495 | gatt_build_uuid_to_stream(&p, *p_uuid); |
| 496 | |
| 497 | status = GATT_SUCCESS; |
| 498 | p_msg->len += p_msg->offset; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 499 | } |
| 500 | p_msg->offset = L2CAP_MIN_OFFSET; |
| 501 | |
| 502 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 505 | /** |
| 506 | * fill the find information response information in the given buffer. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 507 | * |
| 508 | * Returns true: if data filled sucessfully. |
| 509 | * false: packet full, or format mismatch. |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 510 | */ |
| 511 | static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SRV_LIST_ELEM& el, |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 512 | BT_HDR* p_msg, uint16_t& len, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 513 | uint16_t s_hdl, uint16_t e_hdl) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 514 | uint8_t info_pair_len[2] = {4, 18}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 515 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 516 | if (!el.p_db) return GATT_NOT_FOUND; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 517 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 518 | /* check the attribute database */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 519 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 520 | uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET + p_msg->len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 521 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 522 | for (auto& attr : el.p_db->attr_list) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 523 | if (attr.handle > e_hdl) break; |
| 524 | |
| 525 | if (attr.handle < s_hdl) continue; |
| 526 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 527 | uint8_t uuid_len = attr.uuid.GetShortestRepresentationSize(); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 528 | if (p_msg->offset == 0) |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 529 | p_msg->offset = (uuid_len == Uuid::kNumBytes16) ? GATT_INFO_TYPE_PAIR_16 |
| 530 | : GATT_INFO_TYPE_PAIR_128; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 531 | |
| 532 | if (len < info_pair_len[p_msg->offset - 1]) return GATT_NO_RESOURCES; |
| 533 | |
| 534 | if (p_msg->offset == GATT_INFO_TYPE_PAIR_16 && |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 535 | uuid_len == Uuid::kNumBytes16) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 536 | UINT16_TO_STREAM(p, attr.handle); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 537 | UINT16_TO_STREAM(p, attr.uuid.As16Bit()); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 538 | } else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 539 | uuid_len == Uuid::kNumBytes128) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 540 | UINT16_TO_STREAM(p, attr.handle); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 541 | ARRAY_TO_STREAM(p, attr.uuid.To128BitLE(), (int)Uuid::kNumBytes128); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 542 | } else if (p_msg->offset == GATT_INFO_TYPE_PAIR_128 && |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 543 | uuid_len == Uuid::kNumBytes32) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 544 | UINT16_TO_STREAM(p, attr.handle); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 545 | ARRAY_TO_STREAM(p, attr.uuid.To128BitLE(), (int)Uuid::kNumBytes128); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 546 | } else { |
| 547 | LOG(ERROR) << "format mismatch"; |
| 548 | return GATT_NO_RESOURCES; |
| 549 | /* format mismatch */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 550 | } |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 551 | p_msg->len += info_pair_len[p_msg->offset - 1]; |
| 552 | len -= info_pair_len[p_msg->offset - 1]; |
| 553 | return GATT_SUCCESS; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 556 | return GATT_NOT_FOUND; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 559 | static tGATT_STATUS read_handles(uint16_t& len, uint8_t*& p, uint16_t& s_hdl, |
| 560 | uint16_t& e_hdl) { |
| 561 | if (len < 4) return GATT_INVALID_PDU; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 562 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 563 | /* obtain starting handle, and ending handle */ |
| 564 | STREAM_TO_UINT16(s_hdl, p); |
| 565 | STREAM_TO_UINT16(e_hdl, p); |
| 566 | len -= 4; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 567 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 568 | if (s_hdl > e_hdl || !GATT_HANDLE_IS_VALID(s_hdl) || |
| 569 | !GATT_HANDLE_IS_VALID(e_hdl)) { |
| 570 | return GATT_INVALID_PDU; |
| 571 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 572 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 573 | return GATT_SUCCESS; |
| 574 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 575 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 576 | static tGATT_STATUS gatts_validate_packet_format(uint8_t op_code, uint16_t& len, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 577 | uint8_t*& p, Uuid* p_uuid, |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 578 | uint16_t& s_hdl, |
| 579 | uint16_t& e_hdl) { |
| 580 | tGATT_STATUS ret = read_handles(len, p, s_hdl, e_hdl); |
| 581 | if (ret != GATT_SUCCESS) return ret; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 582 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 583 | if (len < 2) return GATT_INVALID_PDU; |
| 584 | |
| 585 | /* parse uuid now */ |
| 586 | CHECK(p_uuid); |
| 587 | uint16_t uuid_len = (op_code == GATT_REQ_FIND_TYPE_VALUE) ? 2 : len; |
| 588 | if (!gatt_parse_uuid_from_cmd(p_uuid, uuid_len, &p)) { |
| 589 | VLOG(1) << "Bad UUID"; |
| 590 | return GATT_INVALID_PDU; |
| 591 | } |
| 592 | |
| 593 | len -= uuid_len; |
| 594 | return GATT_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 598 | * |
| 599 | * Function gatts_process_primary_service_req |
| 600 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 601 | * Description Process ReadByGroupType/ReadByTypeValue request, for |
| 602 | * discovering all primary services or discover primary service |
| 603 | * by UUID request. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 604 | * |
| 605 | * Returns void |
| 606 | * |
| 607 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 608 | void gatts_process_primary_service_req(tGATT_TCB& tcb, uint8_t op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 609 | uint16_t len, uint8_t* p_data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 610 | uint16_t s_hdl = 0, e_hdl = 0; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 611 | Uuid uuid = Uuid::kEmpty; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 612 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 613 | uint8_t reason = |
| 614 | gatts_validate_packet_format(op_code, len, p_data, &uuid, s_hdl, e_hdl); |
| 615 | if (reason != GATT_SUCCESS) { |
| 616 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
| 617 | return; |
| 618 | } |
| 619 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 620 | if (uuid != Uuid::From16Bit(GATT_UUID_PRI_SERVICE)) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 621 | if (op_code == GATT_REQ_READ_BY_GRP_TYPE) { |
| 622 | gatt_send_error_rsp(tcb, GATT_UNSUPPORT_GRP_TYPE, op_code, s_hdl, false); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 623 | VLOG(1) << StringPrintf("unexpected ReadByGrpType Group: %s", |
| 624 | uuid.ToString().c_str()); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 625 | return; |
| 626 | } |
| 627 | |
| 628 | // we do not support ReadByTypeValue with any non-primamry_service type |
| 629 | gatt_send_error_rsp(tcb, GATT_NOT_FOUND, op_code, s_hdl, false); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 630 | VLOG(1) << StringPrintf("unexpected ReadByTypeValue type: %s", |
| 631 | uuid.ToString().c_str()); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | |
| 635 | // TODO: we assume theh value is UUID, there is no such requirement in spec |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 636 | Uuid value = Uuid::kEmpty; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 637 | if (op_code == GATT_REQ_FIND_TYPE_VALUE) { |
Myles Watson | 5d5fcf2 | 2017-10-06 16:51:21 -0700 | [diff] [blame] | 638 | if (!gatt_parse_uuid_from_cmd(&value, len, &p_data)) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 639 | gatt_send_error_rsp(tcb, GATT_INVALID_PDU, op_code, s_hdl, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 640 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 641 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 642 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 643 | uint16_t msg_len = |
| 644 | (uint16_t)(sizeof(BT_HDR) + tcb.payload_size + L2CAP_MIN_OFFSET); |
| 645 | BT_HDR* p_msg = (BT_HDR*)osi_calloc(msg_len); |
| 646 | reason = gatt_build_primary_service_rsp(p_msg, tcb, op_code, s_hdl, e_hdl, |
| 647 | p_data, value); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 648 | if (reason != GATT_SUCCESS) { |
| 649 | osi_free(p_msg); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 650 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
Jack He | 882aec3 | 2017-08-14 23:02:16 -0700 | [diff] [blame] | 651 | return; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | attp_send_sr_msg(tcb, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 658 | * |
| 659 | * Function gatts_process_find_info |
| 660 | * |
| 661 | * Description process find information request, for discover character |
| 662 | * descriptors. |
| 663 | * |
| 664 | * Returns void |
| 665 | * |
| 666 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 667 | static void gatts_process_find_info(tGATT_TCB& tcb, uint8_t op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 668 | uint16_t len, uint8_t* p_data) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 669 | uint16_t s_hdl = 0, e_hdl = 0; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 670 | uint8_t reason = read_handles(len, p_data, s_hdl, e_hdl); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 671 | if (reason != GATT_SUCCESS) { |
| 672 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
| 673 | return; |
| 674 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 675 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 676 | uint16_t buf_len = |
| 677 | (uint16_t)(sizeof(BT_HDR) + tcb.payload_size + L2CAP_MIN_OFFSET); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 678 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 679 | BT_HDR* p_msg = (BT_HDR*)osi_calloc(buf_len); |
| 680 | reason = GATT_NOT_FOUND; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 681 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 682 | uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; |
| 683 | *p++ = op_code + 1; |
| 684 | p_msg->len = 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 685 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 686 | buf_len = tcb.payload_size - 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 687 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 688 | for (tGATT_SRV_LIST_ELEM& el : *gatt_cb.srv_list_info) { |
| 689 | if (el.s_hdl <= e_hdl && el.e_hdl >= s_hdl) { |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 690 | reason = gatt_build_find_info_rsp(el, p_msg, buf_len, s_hdl, e_hdl); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 691 | if (reason == GATT_NO_RESOURCES) { |
| 692 | reason = GATT_SUCCESS; |
| 693 | break; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 694 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 695 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 696 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 697 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 698 | *p = (uint8_t)p_msg->offset; |
| 699 | |
| 700 | p_msg->offset = L2CAP_MIN_OFFSET; |
| 701 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 702 | if (reason != GATT_SUCCESS) { |
| 703 | osi_free(p_msg); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 704 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 705 | } else |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 706 | attp_send_sr_msg(tcb, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 710 | * |
| 711 | * Function gatts_process_mtu_req |
| 712 | * |
| 713 | * Description This function is called to process excahnge MTU request. |
| 714 | * Only used on LE. |
| 715 | * |
| 716 | * Returns void |
| 717 | * |
| 718 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 719 | static void gatts_process_mtu_req(tGATT_TCB& tcb, uint16_t len, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 720 | uint8_t* p_data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 721 | /* BR/EDR conenction, send error response */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 722 | if (tcb.att_lcid != L2CAP_ATT_CID) { |
| 723 | gatt_send_error_rsp(tcb, GATT_REQ_NOT_SUPPORTED, GATT_REQ_MTU, 0, false); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | if (len < GATT_MTU_REQ_MIN_LEN) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 728 | LOG(ERROR) << "invalid MTU request PDU received."; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 729 | gatt_send_error_rsp(tcb, GATT_INVALID_PDU, GATT_REQ_MTU, 0, false); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 730 | return; |
| 731 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 732 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 733 | uint16_t mtu = 0; |
| 734 | uint8_t* p = p_data; |
| 735 | STREAM_TO_UINT16(mtu, p); |
| 736 | /* mtu must be greater than default MTU which is 23/48 */ |
| 737 | if (mtu < GATT_DEF_BLE_MTU_SIZE) |
| 738 | tcb.payload_size = GATT_DEF_BLE_MTU_SIZE; |
| 739 | else if (mtu > GATT_MAX_MTU_SIZE) |
| 740 | tcb.payload_size = GATT_MAX_MTU_SIZE; |
| 741 | else |
| 742 | tcb.payload_size = mtu; |
Zhihai Xu | 52c0ccb | 2014-03-20 17:50:12 -0700 | [diff] [blame] | 743 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 744 | LOG(ERROR) << "MTU request PDU with MTU size " << +tcb.payload_size; |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 745 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 746 | l2cble_set_fixed_channel_tx_data_length(tcb.peer_bda, L2CAP_ATT_CID, |
| 747 | tcb.payload_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 748 | |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 749 | tGATT_SR_MSG gatt_sr_msg; |
| 750 | gatt_sr_msg.mtu = tcb.payload_size; |
| 751 | BT_HDR* p_buf = attp_build_sr_msg(tcb, GATT_RSP_MTU, &gatt_sr_msg); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 752 | attp_send_sr_msg(tcb, p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 753 | |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 754 | tGATTS_DATA gatts_data; |
| 755 | gatts_data.mtu = tcb.payload_size; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 756 | /* Notify all registered applicaiton with new MTU size. Us a transaction ID */ |
| 757 | /* of 0, as no response is allowed from applcations */ |
| 758 | for (int i = 0; i < GATT_MAX_APPS; i++) { |
| 759 | if (gatt_cb.cl_rcb[i].in_use) { |
| 760 | uint16_t conn_id = |
| 761 | GATT_CREATE_CONN_ID(tcb.tcb_idx, gatt_cb.cl_rcb[i].gatt_if); |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 762 | gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 763 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 764 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 768 | * |
| 769 | * Function gatts_process_read_by_type_req |
| 770 | * |
| 771 | * Description process Read By type request. |
| 772 | * This PDU can be used to perform: |
| 773 | * - read characteristic value |
| 774 | * - read characteristic descriptor value |
| 775 | * - discover characteristic |
| 776 | * - discover characteristic by UUID |
| 777 | * - relationship discovery |
| 778 | * |
| 779 | * Returns void |
| 780 | * |
| 781 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 782 | void gatts_process_read_by_type_req(tGATT_TCB& tcb, uint8_t op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 783 | uint16_t len, uint8_t* p_data) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 784 | Uuid uuid = Uuid::kEmpty; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 785 | uint16_t s_hdl, e_hdl, err_hdl = 0; |
| 786 | tGATT_STATUS reason = |
| 787 | gatts_validate_packet_format(op_code, len, p_data, &uuid, s_hdl, e_hdl); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 788 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 789 | #if (GATT_CONFORMANCE_TESTING == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 790 | if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 791 | VLOG(1) << "Conformance tst: forced err rsp for ReadByType: error status=" |
| 792 | << +gatt_cb.err_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 793 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 794 | gatt_send_error_rsp(tcb, gatt_cb.err_status, gatt_cb.req_op_code, s_hdl, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 795 | false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 796 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 797 | return; |
| 798 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 799 | #endif |
| 800 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 801 | if (reason != GATT_SUCCESS) { |
| 802 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
| 803 | return; |
| 804 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 805 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 806 | size_t msg_len = sizeof(BT_HDR) + tcb.payload_size + L2CAP_MIN_OFFSET; |
| 807 | BT_HDR* p_msg = (BT_HDR*)osi_calloc(msg_len); |
| 808 | uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 809 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 810 | *p++ = op_code + 1; |
| 811 | /* reserve length byte */ |
| 812 | p_msg->len = 2; |
| 813 | uint16_t buf_len = tcb.payload_size - 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 814 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 815 | reason = GATT_NOT_FOUND; |
| 816 | for (tGATT_SRV_LIST_ELEM& el : *gatt_cb.srv_list_info) { |
| 817 | if (el.s_hdl <= e_hdl && el.e_hdl >= s_hdl) { |
| 818 | uint8_t sec_flag, key_size; |
| 819 | gatt_sr_get_sec_info(tcb.peer_bda, tcb.transport, &sec_flag, &key_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 820 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 821 | tGATT_STATUS ret = gatts_db_read_attr_value_by_type( |
| 822 | tcb, el.p_db, op_code, p_msg, s_hdl, e_hdl, uuid, &buf_len, sec_flag, |
| 823 | key_size, 0, &err_hdl); |
| 824 | if (ret != GATT_NOT_FOUND) { |
| 825 | reason = ret; |
| 826 | if (ret == GATT_NO_RESOURCES) reason = GATT_SUCCESS; |
| 827 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 828 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 829 | if (ret != GATT_SUCCESS && ret != GATT_NOT_FOUND) { |
| 830 | s_hdl = err_hdl; |
| 831 | break; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 832 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 833 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 834 | } |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 835 | *p = (uint8_t)p_msg->offset; |
| 836 | p_msg->offset = L2CAP_MIN_OFFSET; |
| 837 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 838 | if (reason != GATT_SUCCESS) { |
| 839 | osi_free(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 840 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 841 | /* in theroy BUSY is not possible(should already been checked), protected |
| 842 | * check */ |
| 843 | if (reason != GATT_PENDING && reason != GATT_BUSY) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 844 | gatt_send_error_rsp(tcb, reason, op_code, s_hdl, false); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 845 | |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | attp_send_sr_msg(tcb, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 852 | /** |
| 853 | * This function is called to process the write request from client. |
| 854 | */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 855 | void gatts_process_write_req(tGATT_TCB& tcb, tGATT_SRV_LIST_ELEM& el, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 856 | uint16_t handle, uint8_t op_code, uint16_t len, |
| 857 | uint8_t* p_data, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 858 | bt_gatt_db_attribute_type_t gatt_type) { |
| 859 | tGATTS_DATA sr_data; |
| 860 | uint32_t trans_id; |
| 861 | tGATT_STATUS status; |
| 862 | uint8_t sec_flag, key_size, *p = p_data; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 863 | uint16_t conn_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 864 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 865 | memset(&sr_data, 0, sizeof(tGATTS_DATA)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 866 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 867 | switch (op_code) { |
| 868 | case GATT_REQ_PREPARE_WRITE: |
| 869 | if (len < 2) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 870 | LOG(ERROR) << __func__ |
| 871 | << ": Prepare write request was invalid - missing offset, " |
| 872 | "sending error response"; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 873 | gatt_send_error_rsp(tcb, GATT_INVALID_PDU, op_code, handle, false); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 874 | return; |
| 875 | } |
| 876 | sr_data.write_req.is_prep = true; |
| 877 | STREAM_TO_UINT16(sr_data.write_req.offset, p); |
| 878 | len -= 2; |
| 879 | /* fall through */ |
| 880 | case GATT_SIGN_CMD_WRITE: |
| 881 | if (op_code == GATT_SIGN_CMD_WRITE) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 882 | VLOG(1) << "Write CMD with data sigining"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 883 | len -= GATT_AUTH_SIGN_LEN; |
| 884 | } |
| 885 | /* fall through */ |
| 886 | case GATT_CMD_WRITE: |
| 887 | case GATT_REQ_WRITE: |
| 888 | if (op_code == GATT_REQ_WRITE || op_code == GATT_REQ_PREPARE_WRITE) |
| 889 | sr_data.write_req.need_rsp = true; |
| 890 | sr_data.write_req.handle = handle; |
| 891 | sr_data.write_req.len = len; |
| 892 | if (len != 0 && p != NULL) { |
| 893 | memcpy(sr_data.write_req.value, p, len); |
| 894 | } |
| 895 | break; |
| 896 | } |
| 897 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 898 | gatt_sr_get_sec_info(tcb.peer_bda, tcb.transport, &sec_flag, &key_size); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 899 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 900 | status = gatts_write_attr_perm_check(el.p_db, op_code, handle, |
| 901 | sr_data.write_req.offset, p, len, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 902 | sec_flag, key_size); |
| 903 | |
| 904 | if (status == GATT_SUCCESS) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 905 | trans_id = gatt_sr_enqueue_cmd(tcb, op_code, handle); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 906 | if (trans_id != 0) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 907 | conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, el.gatt_if); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 908 | |
| 909 | uint8_t opcode = 0; |
| 910 | if (gatt_type == BTGATT_DB_DESCRIPTOR) { |
| 911 | opcode = GATTS_REQ_TYPE_WRITE_DESCRIPTOR; |
| 912 | } else if (gatt_type == BTGATT_DB_CHARACTERISTIC) { |
| 913 | opcode = GATTS_REQ_TYPE_WRITE_CHARACTERISTIC; |
| 914 | } else { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 915 | LOG(ERROR) << __func__ |
| 916 | << "%s: Attempt to write attribute that's not tied with" |
| 917 | " characteristic or descriptor value."; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 918 | status = GATT_ERROR; |
| 919 | } |
| 920 | |
| 921 | if (opcode) { |
| 922 | gatt_sr_send_req_callback(conn_id, trans_id, opcode, &sr_data); |
| 923 | status = GATT_PENDING; |
| 924 | } |
| 925 | } else { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 926 | LOG(ERROR) << "max pending command, send error"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 927 | status = GATT_BUSY; /* max pending command, application error */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 928 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 929 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 930 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 931 | /* in theroy BUSY is not possible(should already been checked), protected |
| 932 | * check */ |
| 933 | if (status != GATT_PENDING && status != GATT_BUSY && |
| 934 | (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_REQ_WRITE)) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 935 | gatt_send_error_rsp(tcb, status, op_code, handle, false); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 936 | } |
| 937 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 940 | /** |
| 941 | * This function is called to process the read request from client. |
| 942 | */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 943 | static void gatts_process_read_req(tGATT_TCB& tcb, tGATT_SRV_LIST_ELEM& el, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 944 | uint8_t op_code, uint16_t handle, |
| 945 | UNUSED_ATTR uint16_t len, uint8_t* p_data) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 946 | size_t buf_len = sizeof(BT_HDR) + tcb.payload_size + L2CAP_MIN_OFFSET; |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 947 | uint16_t offset = 0; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 948 | BT_HDR* p_msg = (BT_HDR*)osi_calloc(buf_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 949 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 950 | if (op_code == GATT_REQ_READ_BLOB) STREAM_TO_UINT16(offset, p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 951 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 952 | uint8_t* p = (uint8_t*)(p_msg + 1) + L2CAP_MIN_OFFSET; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 953 | *p++ = op_code + 1; |
| 954 | p_msg->len = 1; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 955 | buf_len = tcb.payload_size - 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 956 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 957 | uint8_t sec_flag, key_size; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 958 | gatt_sr_get_sec_info(tcb.peer_bda, tcb.transport, &sec_flag, &key_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 959 | |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 960 | uint16_t value_len = 0; |
| 961 | tGATT_STATUS reason = gatts_read_attr_value_by_handle( |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 962 | tcb, el.p_db, op_code, handle, offset, p, &value_len, (uint16_t)buf_len, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 963 | sec_flag, key_size, 0); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 964 | p_msg->len += value_len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 965 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 966 | if (reason != GATT_SUCCESS) { |
| 967 | osi_free(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 968 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 969 | /* in theroy BUSY is not possible(should already been checked), protected |
| 970 | * check */ |
| 971 | if (reason != GATT_PENDING && reason != GATT_BUSY) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 972 | gatt_send_error_rsp(tcb, reason, op_code, handle, false); |
Jakub Pawlowski | b4e4799 | 2017-07-11 15:36:48 -0700 | [diff] [blame] | 973 | |
| 974 | return; |
| 975 | } |
| 976 | |
| 977 | attp_send_sr_msg(tcb, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 981 | * |
| 982 | * Function gatts_process_attribute_req |
| 983 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 984 | * Description This function is called to process the per attribute handle |
| 985 | * request from client. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 986 | * |
| 987 | * Returns void |
| 988 | * |
| 989 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 990 | void gatts_process_attribute_req(tGATT_TCB& tcb, uint8_t op_code, uint16_t len, |
| 991 | uint8_t* p_data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 992 | uint16_t handle = 0; |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 993 | uint8_t* p = p_data; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 994 | tGATT_STATUS status = GATT_INVALID_HANDLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 995 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 996 | if (len < 2) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 997 | LOG(ERROR) << "Illegal PDU length, discard request"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 998 | status = GATT_INVALID_PDU; |
| 999 | } else { |
| 1000 | STREAM_TO_UINT16(handle, p); |
| 1001 | len -= 2; |
| 1002 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1003 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1004 | #if (GATT_CONFORMANCE_TESTING == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1005 | gatt_cb.handle = handle; |
| 1006 | if (gatt_cb.enable_err_rsp && gatt_cb.req_op_code == op_code) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1007 | VLOG(1) << "Conformance tst: forced err rsp: error status=" |
| 1008 | << +gatt_cb.err_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1009 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1010 | gatt_send_error_rsp(tcb, gatt_cb.err_status, gatt_cb.req_op_code, handle, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1011 | false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1012 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1013 | return; |
| 1014 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1015 | #endif |
| 1016 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1017 | if (GATT_HANDLE_IS_VALID(handle)) { |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 1018 | for (auto& el : *gatt_cb.srv_list_info) { |
| 1019 | if (el.s_hdl <= handle && el.e_hdl >= handle) { |
| 1020 | for (const auto& attr : el.p_db->attr_list) { |
| 1021 | if (attr.handle == handle) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1022 | switch (op_code) { |
| 1023 | case GATT_REQ_READ: /* read char/char descriptor value */ |
| 1024 | case GATT_REQ_READ_BLOB: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1025 | gatts_process_read_req(tcb, el, op_code, handle, len, p); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1026 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1027 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1028 | case GATT_REQ_WRITE: /* write char/char descriptor value */ |
| 1029 | case GATT_CMD_WRITE: |
| 1030 | case GATT_SIGN_CMD_WRITE: |
| 1031 | case GATT_REQ_PREPARE_WRITE: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1032 | gatts_process_write_req(tcb, el, handle, op_code, len, p, |
Jakub Pawlowski | 6395f15 | 2017-05-09 05:02:38 -0700 | [diff] [blame] | 1033 | attr.gatt_type); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1034 | break; |
| 1035 | default: |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1036 | break; |
| 1037 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1038 | status = GATT_SUCCESS; |
| 1039 | break; |
| 1040 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1041 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1042 | break; |
| 1043 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1044 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1045 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1046 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1047 | if (status != GATT_SUCCESS && op_code != GATT_CMD_WRITE && |
| 1048 | op_code != GATT_SIGN_CMD_WRITE) |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1049 | gatt_send_error_rsp(tcb, status, op_code, handle, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1053 | * |
| 1054 | * Function gatts_proc_srv_chg_ind_ack |
| 1055 | * |
| 1056 | * Description This function process the service changed indicaiton ACK |
| 1057 | * |
| 1058 | * Returns void |
| 1059 | * |
| 1060 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1061 | static void gatts_proc_srv_chg_ind_ack(tGATT_TCB tcb) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1062 | tGATTS_SRV_CHG_REQ req; |
| 1063 | tGATTS_SRV_CHG* p_buf = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1064 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1065 | VLOG(1) << __func__; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1066 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1067 | p_buf = gatt_is_bda_in_the_srv_chg_clt_list(tcb.peer_bda); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1068 | if (p_buf != NULL) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1069 | VLOG(1) << "NV update set srv chg = false"; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1070 | p_buf->srv_changed = false; |
| 1071 | memcpy(&req.srv_chg, p_buf, sizeof(tGATTS_SRV_CHG)); |
| 1072 | if (gatt_cb.cb_info.p_srv_chg_callback) |
| 1073 | (*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_UPDATE_CLIENT, |
| 1074 | &req, NULL); |
| 1075 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1079 | * |
| 1080 | * Function gatts_chk_pending_ind |
| 1081 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1082 | * Description This function check any pending indication needs to be sent |
| 1083 | * if there is a pending indication then sent the indication |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1084 | * |
| 1085 | * Returns void |
| 1086 | * |
| 1087 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1088 | static void gatts_chk_pending_ind(tGATT_TCB& tcb) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1089 | VLOG(1) << __func__; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1090 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1091 | tGATT_VALUE* p_buf = |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1092 | (tGATT_VALUE*)fixed_queue_try_peek_first(tcb.pending_ind_q); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1093 | if (p_buf != NULL) { |
| 1094 | GATTS_HandleValueIndication(p_buf->conn_id, p_buf->handle, p_buf->len, |
| 1095 | p_buf->value); |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1096 | osi_free(fixed_queue_try_remove_from_queue(tcb.pending_ind_q, p_buf)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1097 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1101 | * |
| 1102 | * Function gatts_proc_ind_ack |
| 1103 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1104 | * Description This function processes the Indication ack |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1105 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1106 | * Returns true continue to process the indication ack by the |
| 1107 | * application if the ACK is not a Service Changed Indication |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1108 | * |
| 1109 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1110 | static bool gatts_proc_ind_ack(tGATT_TCB& tcb, uint16_t ack_handle) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1111 | bool continue_processing = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1112 | |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1113 | VLOG(1) << __func__ << " ack handle=%d" << ack_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1114 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1115 | if (ack_handle == gatt_cb.handle_of_h_r) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1116 | gatts_proc_srv_chg_ind_ack(tcb); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1117 | /* there is no need to inform the application since srv chg is handled |
| 1118 | * internally by GATT */ |
| 1119 | continue_processing = false; |
| 1120 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1121 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1122 | gatts_chk_pending_ind(tcb); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1123 | return continue_processing; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1127 | * |
| 1128 | * Function gatts_process_value_conf |
| 1129 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1130 | * Description This function is called to process the handle value |
| 1131 | * confirmation. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1132 | * |
| 1133 | * Returns void |
| 1134 | * |
| 1135 | ******************************************************************************/ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1136 | void gatts_process_value_conf(tGATT_TCB& tcb, uint8_t op_code) { |
| 1137 | uint16_t handle = tcb.indicate_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1138 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1139 | alarm_cancel(tcb.conf_timer); |
| 1140 | if (!GATT_HANDLE_IS_VALID(handle)) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1141 | LOG(ERROR) << "unexpected handle value confirmation"; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1142 | return; |
| 1143 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1144 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1145 | tcb.indicate_handle = 0; |
| 1146 | bool continue_processing = gatts_proc_ind_ack(tcb, handle); |
| 1147 | |
| 1148 | if (continue_processing) { |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 1149 | tGATTS_DATA gatts_data; |
| 1150 | gatts_data.handle = handle; |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1151 | for (auto& el : *gatt_cb.srv_list_info) { |
| 1152 | if (el.s_hdl <= handle && el.e_hdl >= handle) { |
| 1153 | uint32_t trans_id = gatt_sr_enqueue_cmd(tcb, op_code, handle); |
| 1154 | uint16_t conn_id = GATT_CREATE_CONN_ID(tcb.tcb_idx, el.gatt_if); |
| 1155 | gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_CONF, |
Myles Watson | 8d74904 | 2017-09-19 10:01:28 -0700 | [diff] [blame] | 1156 | &gatts_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1157 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1158 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1159 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1162 | /** This function is called to handle the client requests to server */ |
| 1163 | void gatt_server_handle_client_req(tGATT_TCB& tcb, uint8_t op_code, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1164 | uint16_t len, uint8_t* p_data) { |
| 1165 | /* there is pending command, discard this one */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1166 | if (!gatt_sr_cmd_empty(tcb) && op_code != GATT_HANDLE_VALUE_CONF) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1167 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1168 | /* the size of the message may not be bigger than the local max PDU size*/ |
| 1169 | /* The message has to be smaller than the agreed MTU, len does not include op |
| 1170 | * code */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1171 | if (len >= tcb.payload_size) { |
Jakub Pawlowski | d8be0e5 | 2017-06-08 17:04:47 -0700 | [diff] [blame] | 1172 | LOG(ERROR) << StringPrintf("server receive invalid PDU size:%d pdu size:%d", |
| 1173 | len + 1, tcb.payload_size); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1174 | /* for invalid request expecting response, send it now */ |
| 1175 | if (op_code != GATT_CMD_WRITE && op_code != GATT_SIGN_CMD_WRITE && |
| 1176 | op_code != GATT_HANDLE_VALUE_CONF) { |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1177 | gatt_send_error_rsp(tcb, GATT_INVALID_PDU, op_code, 0, false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1178 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1179 | /* otherwise, ignore the pkt */ |
| 1180 | } else { |
| 1181 | switch (op_code) { |
| 1182 | case GATT_REQ_READ_BY_GRP_TYPE: /* discover primary services */ |
| 1183 | case GATT_REQ_FIND_TYPE_VALUE: /* discover service by UUID */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1184 | gatts_process_primary_service_req(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1185 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1186 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1187 | case GATT_REQ_FIND_INFO: /* discover char descrptor */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1188 | gatts_process_find_info(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1189 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1190 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1191 | case GATT_REQ_READ_BY_TYPE: /* read characteristic value, char descriptor |
| 1192 | value */ |
| 1193 | /* discover characteristic, discover char by UUID */ |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1194 | gatts_process_read_by_type_req(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1195 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1196 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1197 | case GATT_REQ_READ: /* read char/char descriptor value */ |
| 1198 | case GATT_REQ_READ_BLOB: |
| 1199 | case GATT_REQ_WRITE: /* write char/char descriptor value */ |
| 1200 | case GATT_CMD_WRITE: |
| 1201 | case GATT_SIGN_CMD_WRITE: |
| 1202 | case GATT_REQ_PREPARE_WRITE: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1203 | gatts_process_attribute_req(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1204 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1205 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1206 | case GATT_HANDLE_VALUE_CONF: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1207 | gatts_process_value_conf(tcb, op_code); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1208 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1209 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1210 | case GATT_REQ_MTU: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1211 | gatts_process_mtu_req(tcb, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1212 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1213 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1214 | case GATT_REQ_EXEC_WRITE: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1215 | gatt_process_exec_write_req(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1216 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1217 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1218 | case GATT_REQ_READ_MULTI: |
Jakub Pawlowski | f4c0292 | 2017-05-30 11:21:04 -0700 | [diff] [blame] | 1219 | gatt_process_read_multi_req(tcb, op_code, len, p_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1220 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1221 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1222 | default: |
| 1223 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1224 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1225 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1226 | } |