| .. | .. |
|---|
| 15 | 15 | #include "nfc.h" |
|---|
| 16 | 16 | #include "llcp.h" |
|---|
| 17 | 17 | |
|---|
| 18 | | -static u8 llcp_tlv_length[LLCP_TLV_MAX] = { |
|---|
| 18 | +static const u8 llcp_tlv_length[LLCP_TLV_MAX] = { |
|---|
| 19 | 19 | 0, |
|---|
| 20 | 20 | 1, /* VERSION */ |
|---|
| 21 | 21 | 2, /* MIUX */ |
|---|
| .. | .. |
|---|
| 29 | 29 | |
|---|
| 30 | 30 | }; |
|---|
| 31 | 31 | |
|---|
| 32 | | -static u8 llcp_tlv8(u8 *tlv, u8 type) |
|---|
| 32 | +static u8 llcp_tlv8(const u8 *tlv, u8 type) |
|---|
| 33 | 33 | { |
|---|
| 34 | 34 | if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]]) |
|---|
| 35 | 35 | return 0; |
|---|
| .. | .. |
|---|
| 37 | 37 | return tlv[2]; |
|---|
| 38 | 38 | } |
|---|
| 39 | 39 | |
|---|
| 40 | | -static u16 llcp_tlv16(u8 *tlv, u8 type) |
|---|
| 40 | +static u16 llcp_tlv16(const u8 *tlv, u8 type) |
|---|
| 41 | 41 | { |
|---|
| 42 | 42 | if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]]) |
|---|
| 43 | 43 | return 0; |
|---|
| .. | .. |
|---|
| 46 | 46 | } |
|---|
| 47 | 47 | |
|---|
| 48 | 48 | |
|---|
| 49 | | -static u8 llcp_tlv_version(u8 *tlv) |
|---|
| 49 | +static u8 llcp_tlv_version(const u8 *tlv) |
|---|
| 50 | 50 | { |
|---|
| 51 | 51 | return llcp_tlv8(tlv, LLCP_TLV_VERSION); |
|---|
| 52 | 52 | } |
|---|
| 53 | 53 | |
|---|
| 54 | | -static u16 llcp_tlv_miux(u8 *tlv) |
|---|
| 54 | +static u16 llcp_tlv_miux(const u8 *tlv) |
|---|
| 55 | 55 | { |
|---|
| 56 | 56 | return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7ff; |
|---|
| 57 | 57 | } |
|---|
| 58 | 58 | |
|---|
| 59 | | -static u16 llcp_tlv_wks(u8 *tlv) |
|---|
| 59 | +static u16 llcp_tlv_wks(const u8 *tlv) |
|---|
| 60 | 60 | { |
|---|
| 61 | 61 | return llcp_tlv16(tlv, LLCP_TLV_WKS); |
|---|
| 62 | 62 | } |
|---|
| 63 | 63 | |
|---|
| 64 | | -static u16 llcp_tlv_lto(u8 *tlv) |
|---|
| 64 | +static u16 llcp_tlv_lto(const u8 *tlv) |
|---|
| 65 | 65 | { |
|---|
| 66 | 66 | return llcp_tlv8(tlv, LLCP_TLV_LTO); |
|---|
| 67 | 67 | } |
|---|
| 68 | 68 | |
|---|
| 69 | | -static u8 llcp_tlv_opt(u8 *tlv) |
|---|
| 69 | +static u8 llcp_tlv_opt(const u8 *tlv) |
|---|
| 70 | 70 | { |
|---|
| 71 | 71 | return llcp_tlv8(tlv, LLCP_TLV_OPT); |
|---|
| 72 | 72 | } |
|---|
| 73 | 73 | |
|---|
| 74 | | -static u8 llcp_tlv_rw(u8 *tlv) |
|---|
| 74 | +static u8 llcp_tlv_rw(const u8 *tlv) |
|---|
| 75 | 75 | { |
|---|
| 76 | 76 | return llcp_tlv8(tlv, LLCP_TLV_RW) & 0xf; |
|---|
| 77 | 77 | } |
|---|
| 78 | 78 | |
|---|
| 79 | | -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) |
|---|
| 80 | 80 | { |
|---|
| 81 | 81 | u8 *tlv, length; |
|---|
| 82 | 82 | |
|---|
| .. | .. |
|---|
| 130 | 130 | return sdres; |
|---|
| 131 | 131 | } |
|---|
| 132 | 132 | |
|---|
| 133 | | -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, |
|---|
| 134 | 134 | size_t uri_len) |
|---|
| 135 | 135 | { |
|---|
| 136 | 136 | struct nfc_llcp_sdp_tlv *sdreq; |
|---|
| .. | .. |
|---|
| 190 | 190 | } |
|---|
| 191 | 191 | |
|---|
| 192 | 192 | int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local, |
|---|
| 193 | | - u8 *tlv_array, u16 tlv_array_len) |
|---|
| 193 | + const u8 *tlv_array, u16 tlv_array_len) |
|---|
| 194 | 194 | { |
|---|
| 195 | | - u8 *tlv = tlv_array, type, length, offset = 0; |
|---|
| 195 | + const u8 *tlv = tlv_array; |
|---|
| 196 | + u8 type, length, offset = 0; |
|---|
| 196 | 197 | |
|---|
| 197 | 198 | pr_debug("TLV array length %d\n", tlv_array_len); |
|---|
| 198 | 199 | |
|---|
| .. | .. |
|---|
| 239 | 240 | } |
|---|
| 240 | 241 | |
|---|
| 241 | 242 | int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock, |
|---|
| 242 | | - u8 *tlv_array, u16 tlv_array_len) |
|---|
| 243 | + const u8 *tlv_array, u16 tlv_array_len) |
|---|
| 243 | 244 | { |
|---|
| 244 | | - u8 *tlv = tlv_array, type, length, offset = 0; |
|---|
| 245 | + const u8 *tlv = tlv_array; |
|---|
| 246 | + u8 type, length, offset = 0; |
|---|
| 245 | 247 | |
|---|
| 246 | 248 | pr_debug("TLV array length %d\n", tlv_array_len); |
|---|
| 247 | 249 | |
|---|
| .. | .. |
|---|
| 295 | 297 | return pdu; |
|---|
| 296 | 298 | } |
|---|
| 297 | 299 | |
|---|
| 298 | | -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, |
|---|
| 299 | 301 | u8 tlv_length) |
|---|
| 300 | 302 | { |
|---|
| 301 | 303 | /* XXX Add an skb length check */ |
|---|
| .. | .. |
|---|
| 359 | 361 | struct sk_buff *skb; |
|---|
| 360 | 362 | struct nfc_llcp_local *local; |
|---|
| 361 | 363 | u16 size = 0; |
|---|
| 364 | + int err; |
|---|
| 362 | 365 | |
|---|
| 363 | 366 | pr_debug("Sending SYMM\n"); |
|---|
| 364 | 367 | |
|---|
| .. | .. |
|---|
| 370 | 373 | size += dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE; |
|---|
| 371 | 374 | |
|---|
| 372 | 375 | skb = alloc_skb(size, GFP_KERNEL); |
|---|
| 373 | | - if (skb == NULL) |
|---|
| 374 | | - return -ENOMEM; |
|---|
| 376 | + if (skb == NULL) { |
|---|
| 377 | + err = -ENOMEM; |
|---|
| 378 | + goto out; |
|---|
| 379 | + } |
|---|
| 375 | 380 | |
|---|
| 376 | 381 | skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); |
|---|
| 377 | 382 | |
|---|
| .. | .. |
|---|
| 381 | 386 | |
|---|
| 382 | 387 | nfc_llcp_send_to_raw_sock(local, skb, NFC_DIRECTION_TX); |
|---|
| 383 | 388 | |
|---|
| 384 | | - return nfc_data_exchange(dev, local->target_idx, skb, |
|---|
| 389 | + err = nfc_data_exchange(dev, local->target_idx, skb, |
|---|
| 385 | 390 | nfc_llcp_recv, local); |
|---|
| 391 | +out: |
|---|
| 392 | + nfc_llcp_local_put(local); |
|---|
| 393 | + return err; |
|---|
| 386 | 394 | } |
|---|
| 387 | 395 | |
|---|
| 388 | 396 | int nfc_llcp_send_connect(struct nfc_llcp_sock *sock) |
|---|
| 389 | 397 | { |
|---|
| 390 | 398 | struct nfc_llcp_local *local; |
|---|
| 391 | 399 | struct sk_buff *skb; |
|---|
| 392 | | - u8 *service_name_tlv = NULL, service_name_tlv_length; |
|---|
| 393 | | - u8 *miux_tlv = NULL, miux_tlv_length; |
|---|
| 394 | | - 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; |
|---|
| 395 | 405 | int err; |
|---|
| 396 | 406 | u16 size = 0; |
|---|
| 397 | 407 | __be16 miux; |
|---|
| .. | .. |
|---|
| 465 | 475 | { |
|---|
| 466 | 476 | struct nfc_llcp_local *local; |
|---|
| 467 | 477 | struct sk_buff *skb; |
|---|
| 468 | | - u8 *miux_tlv = NULL, miux_tlv_length; |
|---|
| 469 | | - 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; |
|---|
| 470 | 481 | int err; |
|---|
| 471 | 482 | u16 size = 0; |
|---|
| 472 | 483 | __be16 miux; |
|---|