| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2011 Intel Corporation. All rights reserved. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 6 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | | - * (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License |
|---|
| 15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 4 | */ |
|---|
| 17 | 5 | |
|---|
| 18 | 6 | #define pr_fmt(fmt) "llcp: %s: " fmt, __func__ |
|---|
| .. | .. |
|---|
| 27 | 15 | #include "nfc.h" |
|---|
| 28 | 16 | #include "llcp.h" |
|---|
| 29 | 17 | |
|---|
| 30 | | -static u8 llcp_tlv_length[LLCP_TLV_MAX] = { |
|---|
| 18 | +static const u8 llcp_tlv_length[LLCP_TLV_MAX] = { |
|---|
| 31 | 19 | 0, |
|---|
| 32 | 20 | 1, /* VERSION */ |
|---|
| 33 | 21 | 2, /* MIUX */ |
|---|
| .. | .. |
|---|
| 41 | 29 | |
|---|
| 42 | 30 | }; |
|---|
| 43 | 31 | |
|---|
| 44 | | -static u8 llcp_tlv8(u8 *tlv, u8 type) |
|---|
| 32 | +static u8 llcp_tlv8(const u8 *tlv, u8 type) |
|---|
| 45 | 33 | { |
|---|
| 46 | 34 | if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]]) |
|---|
| 47 | 35 | return 0; |
|---|
| .. | .. |
|---|
| 49 | 37 | return tlv[2]; |
|---|
| 50 | 38 | } |
|---|
| 51 | 39 | |
|---|
| 52 | | -static u16 llcp_tlv16(u8 *tlv, u8 type) |
|---|
| 40 | +static u16 llcp_tlv16(const u8 *tlv, u8 type) |
|---|
| 53 | 41 | { |
|---|
| 54 | 42 | if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]]) |
|---|
| 55 | 43 | return 0; |
|---|
| .. | .. |
|---|
| 58 | 46 | } |
|---|
| 59 | 47 | |
|---|
| 60 | 48 | |
|---|
| 61 | | -static u8 llcp_tlv_version(u8 *tlv) |
|---|
| 49 | +static u8 llcp_tlv_version(const u8 *tlv) |
|---|
| 62 | 50 | { |
|---|
| 63 | 51 | return llcp_tlv8(tlv, LLCP_TLV_VERSION); |
|---|
| 64 | 52 | } |
|---|
| 65 | 53 | |
|---|
| 66 | | -static u16 llcp_tlv_miux(u8 *tlv) |
|---|
| 54 | +static u16 llcp_tlv_miux(const u8 *tlv) |
|---|
| 67 | 55 | { |
|---|
| 68 | 56 | return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7ff; |
|---|
| 69 | 57 | } |
|---|
| 70 | 58 | |
|---|
| 71 | | -static u16 llcp_tlv_wks(u8 *tlv) |
|---|
| 59 | +static u16 llcp_tlv_wks(const u8 *tlv) |
|---|
| 72 | 60 | { |
|---|
| 73 | 61 | return llcp_tlv16(tlv, LLCP_TLV_WKS); |
|---|
| 74 | 62 | } |
|---|
| 75 | 63 | |
|---|
| 76 | | -static u16 llcp_tlv_lto(u8 *tlv) |
|---|
| 64 | +static u16 llcp_tlv_lto(const u8 *tlv) |
|---|
| 77 | 65 | { |
|---|
| 78 | 66 | return llcp_tlv8(tlv, LLCP_TLV_LTO); |
|---|
| 79 | 67 | } |
|---|
| 80 | 68 | |
|---|
| 81 | | -static u8 llcp_tlv_opt(u8 *tlv) |
|---|
| 69 | +static u8 llcp_tlv_opt(const u8 *tlv) |
|---|
| 82 | 70 | { |
|---|
| 83 | 71 | return llcp_tlv8(tlv, LLCP_TLV_OPT); |
|---|
| 84 | 72 | } |
|---|
| 85 | 73 | |
|---|
| 86 | | -static u8 llcp_tlv_rw(u8 *tlv) |
|---|
| 74 | +static u8 llcp_tlv_rw(const u8 *tlv) |
|---|
| 87 | 75 | { |
|---|
| 88 | 76 | return llcp_tlv8(tlv, LLCP_TLV_RW) & 0xf; |
|---|
| 89 | 77 | } |
|---|
| 90 | 78 | |
|---|
| 91 | | -u8 *nfc_llcp_build_tlv(u8 type, u8 *value, u8 value_length, u8 *tlv_length) |
|---|
| 79 | +u8 *nfc_llcp_build_tlv(u8 type, const u8 *value, u8 value_length, u8 *tlv_length) |
|---|
| 92 | 80 | { |
|---|
| 93 | 81 | u8 *tlv, length; |
|---|
| 94 | 82 | |
|---|
| .. | .. |
|---|
| 142 | 130 | return sdres; |
|---|
| 143 | 131 | } |
|---|
| 144 | 132 | |
|---|
| 145 | | -struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, char *uri, |
|---|
| 133 | +struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri, |
|---|
| 146 | 134 | size_t uri_len) |
|---|
| 147 | 135 | { |
|---|
| 148 | 136 | struct nfc_llcp_sdp_tlv *sdreq; |
|---|
| .. | .. |
|---|
| 202 | 190 | } |
|---|
| 203 | 191 | |
|---|
| 204 | 192 | int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local, |
|---|
| 205 | | - u8 *tlv_array, u16 tlv_array_len) |
|---|
| 193 | + const u8 *tlv_array, u16 tlv_array_len) |
|---|
| 206 | 194 | { |
|---|
| 207 | | - u8 *tlv = tlv_array, type, length, offset = 0; |
|---|
| 195 | + const u8 *tlv = tlv_array; |
|---|
| 196 | + u8 type, length, offset = 0; |
|---|
| 208 | 197 | |
|---|
| 209 | 198 | pr_debug("TLV array length %d\n", tlv_array_len); |
|---|
| 210 | 199 | |
|---|
| .. | .. |
|---|
| 251 | 240 | } |
|---|
| 252 | 241 | |
|---|
| 253 | 242 | int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock, |
|---|
| 254 | | - u8 *tlv_array, u16 tlv_array_len) |
|---|
| 243 | + const u8 *tlv_array, u16 tlv_array_len) |
|---|
| 255 | 244 | { |
|---|
| 256 | | - u8 *tlv = tlv_array, type, length, offset = 0; |
|---|
| 245 | + const u8 *tlv = tlv_array; |
|---|
| 246 | + u8 type, length, offset = 0; |
|---|
| 257 | 247 | |
|---|
| 258 | 248 | pr_debug("TLV array length %d\n", tlv_array_len); |
|---|
| 259 | 249 | |
|---|
| .. | .. |
|---|
| 307 | 297 | return pdu; |
|---|
| 308 | 298 | } |
|---|
| 309 | 299 | |
|---|
| 310 | | -static struct sk_buff *llcp_add_tlv(struct sk_buff *pdu, u8 *tlv, |
|---|
| 300 | +static struct sk_buff *llcp_add_tlv(struct sk_buff *pdu, const u8 *tlv, |
|---|
| 311 | 301 | u8 tlv_length) |
|---|
| 312 | 302 | { |
|---|
| 313 | 303 | /* XXX Add an skb length check */ |
|---|
| .. | .. |
|---|
| 371 | 361 | struct sk_buff *skb; |
|---|
| 372 | 362 | struct nfc_llcp_local *local; |
|---|
| 373 | 363 | u16 size = 0; |
|---|
| 364 | + int err; |
|---|
| 374 | 365 | |
|---|
| 375 | 366 | pr_debug("Sending SYMM\n"); |
|---|
| 376 | 367 | |
|---|
| .. | .. |
|---|
| 382 | 373 | size += dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE; |
|---|
| 383 | 374 | |
|---|
| 384 | 375 | skb = alloc_skb(size, GFP_KERNEL); |
|---|
| 385 | | - if (skb == NULL) |
|---|
| 386 | | - return -ENOMEM; |
|---|
| 376 | + if (skb == NULL) { |
|---|
| 377 | + err = -ENOMEM; |
|---|
| 378 | + goto out; |
|---|
| 379 | + } |
|---|
| 387 | 380 | |
|---|
| 388 | 381 | skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); |
|---|
| 389 | 382 | |
|---|
| .. | .. |
|---|
| 393 | 386 | |
|---|
| 394 | 387 | nfc_llcp_send_to_raw_sock(local, skb, NFC_DIRECTION_TX); |
|---|
| 395 | 388 | |
|---|
| 396 | | - return nfc_data_exchange(dev, local->target_idx, skb, |
|---|
| 389 | + err = nfc_data_exchange(dev, local->target_idx, skb, |
|---|
| 397 | 390 | nfc_llcp_recv, local); |
|---|
| 391 | +out: |
|---|
| 392 | + nfc_llcp_local_put(local); |
|---|
| 393 | + return err; |
|---|
| 398 | 394 | } |
|---|
| 399 | 395 | |
|---|
| 400 | 396 | int nfc_llcp_send_connect(struct nfc_llcp_sock *sock) |
|---|
| 401 | 397 | { |
|---|
| 402 | 398 | struct nfc_llcp_local *local; |
|---|
| 403 | 399 | struct sk_buff *skb; |
|---|
| 404 | | - u8 *service_name_tlv = NULL, service_name_tlv_length; |
|---|
| 405 | | - u8 *miux_tlv = NULL, miux_tlv_length; |
|---|
| 406 | | - u8 *rw_tlv = NULL, rw_tlv_length, rw; |
|---|
| 400 | + const u8 *service_name_tlv = NULL; |
|---|
| 401 | + const u8 *miux_tlv = NULL; |
|---|
| 402 | + const u8 *rw_tlv = NULL; |
|---|
| 403 | + u8 service_name_tlv_length = 0; |
|---|
| 404 | + u8 miux_tlv_length, rw_tlv_length, rw; |
|---|
| 407 | 405 | int err; |
|---|
| 408 | 406 | u16 size = 0; |
|---|
| 409 | 407 | __be16 miux; |
|---|
| .. | .. |
|---|
| 477 | 475 | { |
|---|
| 478 | 476 | struct nfc_llcp_local *local; |
|---|
| 479 | 477 | struct sk_buff *skb; |
|---|
| 480 | | - u8 *miux_tlv = NULL, miux_tlv_length; |
|---|
| 481 | | - u8 *rw_tlv = NULL, rw_tlv_length, rw; |
|---|
| 478 | + const u8 *miux_tlv = NULL; |
|---|
| 479 | + const u8 *rw_tlv = NULL; |
|---|
| 480 | + u8 miux_tlv_length, rw_tlv_length, rw; |
|---|
| 482 | 481 | int err; |
|---|
| 483 | 482 | u16 size = 0; |
|---|
| 484 | 483 | __be16 miux; |
|---|