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