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