Blame view
net/nfc/digital_dep.c
34.8 KB
7d0911c02 NFC Digital: Add ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * NFC Digital Protocol stack * Copyright (c) 2013, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * */ |
c5da0e4a3 NFC: digital: Rem... |
15 |
#define pr_fmt(fmt) "digital: %s: " fmt, __func__ |
7d0911c02 NFC Digital: Add ... |
16 |
#include "digital.h" |
a80509c76 NFC: digital: Add... |
17 |
#define DIGITAL_NFC_DEP_N_RETRY_NACK 2 |
384ab1d17 NFC: digital: Add... |
18 |
#define DIGITAL_NFC_DEP_N_RETRY_ATN 2 |
a80509c76 NFC: digital: Add... |
19 |
|
7d0911c02 NFC Digital: Add ... |
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4 #define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5 #define DIGITAL_NFC_DEP_NFCA_SOD_SB 0xF0 #define DIGITAL_CMD_ATR_REQ 0x00 #define DIGITAL_CMD_ATR_RES 0x01 #define DIGITAL_CMD_PSL_REQ 0x04 #define DIGITAL_CMD_PSL_RES 0x05 #define DIGITAL_CMD_DEP_REQ 0x06 #define DIGITAL_CMD_DEP_RES 0x07 #define DIGITAL_ATR_REQ_MIN_SIZE 16 #define DIGITAL_ATR_REQ_MAX_SIZE 64 |
1a09c56f5 NFC: digital: Add... |
34 |
#define DIGITAL_ATR_RES_TO_WT(s) ((s) & 0xF) |
05afedcb8 NFC: digital: Add... |
35 |
#define DIGITAL_DID_MAX 14 |
b08147cbc NFC: digital: Imp... |
36 37 38 39 40 |
#define DIGITAL_PAYLOAD_SIZE_MAX 254 #define DIGITAL_PAYLOAD_BITS_TO_PP(s) (((s) & 0x3) << 4) #define DIGITAL_PAYLOAD_PP_TO_BITS(s) (((s) >> 4) & 0x3) #define DIGITAL_PAYLOAD_BITS_TO_FSL(s) ((s) & 0x3) #define DIGITAL_PAYLOAD_FSL_TO_BITS(s) ((s) & 0x3) |
7d0911c02 NFC Digital: Add ... |
41 |
#define DIGITAL_GB_BIT 0x02 |
3bd2a5bcc NFC: digital: Add... |
42 43 |
#define DIGITAL_NFC_DEP_REQ_RES_HEADROOM 2 /* SoD: [SB (NFC-A)] + LEN */ #define DIGITAL_NFC_DEP_REQ_RES_TAILROOM 2 /* EoD: 2-byte CRC */ |
7d0911c02 NFC Digital: Add ... |
44 45 46 |
#define DIGITAL_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0) #define DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT 0x10 |
3bd2a5bcc NFC: digital: Add... |
47 48 |
#define DIGITAL_NFC_DEP_PFB_MI_BIT 0x10 #define DIGITAL_NFC_DEP_PFB_NACK_BIT 0x10 |
05afedcb8 NFC: digital: Add... |
49 |
#define DIGITAL_NFC_DEP_PFB_DID_BIT 0x04 |
7d0911c02 NFC Digital: Add ... |
50 51 52 |
#define DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb) \ ((pfb) & DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT) |
3bd2a5bcc NFC: digital: Add... |
53 54 |
#define DIGITAL_NFC_DEP_MI_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_MI_BIT) #define DIGITAL_NFC_DEP_NACK_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_NACK_BIT) |
7d0911c02 NFC Digital: Add ... |
55 |
#define DIGITAL_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08) |
05afedcb8 NFC: digital: Add... |
56 |
#define DIGITAL_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_DID_BIT) |
7d0911c02 NFC Digital: Add ... |
57 |
#define DIGITAL_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03) |
d85a301c2 NFC: digital: Fix... |
58 59 |
#define DIGITAL_NFC_DEP_RTOX_VALUE(data) ((data) & 0x3F) #define DIGITAL_NFC_DEP_RTOX_MAX 59 |
7d0911c02 NFC Digital: Add ... |
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
#define DIGITAL_NFC_DEP_PFB_I_PDU 0x00 #define DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU 0x40 #define DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU 0x80 struct digital_atr_req { u8 dir; u8 cmd; u8 nfcid3[10]; u8 did; u8 bs; u8 br; u8 pp; u8 gb[0]; } __packed; struct digital_atr_res { u8 dir; u8 cmd; u8 nfcid3[10]; u8 did; u8 bs; u8 br; u8 to; u8 pp; u8 gb[0]; } __packed; struct digital_psl_req { u8 dir; u8 cmd; u8 did; u8 brs; u8 fsl; } __packed; struct digital_psl_res { u8 dir; u8 cmd; u8 did; } __packed; struct digital_dep_req_res { u8 dir; u8 cmd; u8 pfb; } __packed; static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp); |
c12715ab3 NFC: digital: Add... |
109 110 |
static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp); |
7d0911c02 NFC Digital: Add ... |
111 |
|
b08147cbc NFC: digital: Imp... |
112 113 114 115 116 117 |
static const u8 digital_payload_bits_map[4] = { [0] = 64, [1] = 128, [2] = 192, [3] = 254 }; |
1a09c56f5 NFC: digital: Add... |
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
/* Response Waiting Time for ATR_RES PDU in ms * * RWT(ATR_RES) = RWT(nfcdep,activation) + dRWT(nfcdep) + dT(nfcdep,initiator) * * with: * RWT(nfcdep,activation) = 4096 * 2^12 / f(c) s * dRWT(nfcdep) = 16 / f(c) s * dT(nfcdep,initiator) = 100 ms * f(c) = 13560000 Hz */ #define DIGITAL_ATR_RES_RWT 1337 /* Response Waiting Time for other DEP PDUs in ms * * max_rwt = rwt + dRWT(nfcdep) + dT(nfcdep,initiator) * * with: * rwt = (256 * 16 / f(c)) * 2^wt s * dRWT(nfcdep) = 16 / f(c) s * dT(nfcdep,initiator) = 100 ms * f(c) = 13560000 Hz * 0 <= wt <= 14 (given by the target by the TO field of ATR_RES response) */ #define DIGITAL_NFC_DEP_IN_MAX_WT 14 |
1b609e438 NFC: digital: NFC... |
142 |
#define DIGITAL_NFC_DEP_TG_MAX_WT 14 |
1a09c56f5 NFC: digital: Add... |
143 144 145 146 147 |
static const u16 digital_rwt_map[DIGITAL_NFC_DEP_IN_MAX_WT + 1] = { 100, 101, 101, 102, 105, 110, 119, 139, 177, 255, 409, 719, 1337, 2575, 5049, }; |
b08147cbc NFC: digital: Imp... |
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
static u8 digital_payload_bits_to_size(u8 payload_bits) { if (payload_bits >= ARRAY_SIZE(digital_payload_bits_map)) return 0; return digital_payload_bits_map[payload_bits]; } static u8 digital_payload_size_to_bits(u8 payload_size) { int i; for (i = 0; i < ARRAY_SIZE(digital_payload_bits_map); i++) if (digital_payload_bits_map[i] == payload_size) return i; return 0xff; } |
7d0911c02 NFC Digital: Add ... |
166 167 168 169 170 171 172 173 |
static void digital_skb_push_dep_sod(struct nfc_digital_dev *ddev, struct sk_buff *skb) { skb_push(skb, sizeof(u8)); skb->data[0] = skb->len; if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) |
d58ff3512 networking: make ... |
174 |
*(u8 *)skb_push(skb, sizeof(u8)) = DIGITAL_NFC_DEP_NFCA_SOD_SB; |
7d0911c02 NFC Digital: Add ... |
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
} static int digital_skb_pull_dep_sod(struct nfc_digital_dev *ddev, struct sk_buff *skb) { u8 size; if (skb->len < 2) return -EIO; if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) skb_pull(skb, sizeof(u8)); size = skb->data[0]; if (size != skb->len) return -EIO; skb_pull(skb, sizeof(u8)); return 0; } |
3bd2a5bcc NFC: digital: Add... |
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
static struct sk_buff * digital_send_dep_data_prep(struct nfc_digital_dev *ddev, struct sk_buff *skb, struct digital_dep_req_res *dep_req_res, struct digital_data_exch *data_exch) { struct sk_buff *new_skb; if (skb->len > ddev->remote_payload_max) { dep_req_res->pfb |= DIGITAL_NFC_DEP_PFB_MI_BIT; new_skb = digital_skb_alloc(ddev, ddev->remote_payload_max); if (!new_skb) { kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; return ERR_PTR(-ENOMEM); } |
59ae1d127 networking: intro... |
213 |
skb_put_data(new_skb, skb->data, ddev->remote_payload_max); |
3bd2a5bcc NFC: digital: Add... |
214 215 216 217 218 219 220 221 222 223 224 |
skb_pull(skb, ddev->remote_payload_max); ddev->chaining_skb = skb; ddev->data_exch = data_exch; } else { ddev->chaining_skb = NULL; new_skb = skb; } return new_skb; } |
c12715ab3 NFC: digital: Add... |
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
static struct sk_buff * digital_recv_dep_data_gather(struct nfc_digital_dev *ddev, u8 pfb, struct sk_buff *resp, int (*send_ack)(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch), struct digital_data_exch *data_exch) { struct sk_buff *new_skb; int rc; if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb) && (!ddev->chaining_skb)) { ddev->chaining_skb = nfc_alloc_recv_skb(8 * ddev->local_payload_max, GFP_KERNEL); if (!ddev->chaining_skb) { rc = -ENOMEM; goto error; } } if (ddev->chaining_skb) { if (resp->len > skb_tailroom(ddev->chaining_skb)) { new_skb = skb_copy_expand(ddev->chaining_skb, skb_headroom( ddev->chaining_skb), 8 * ddev->local_payload_max, GFP_KERNEL); if (!new_skb) { rc = -ENOMEM; goto error; } kfree_skb(ddev->chaining_skb); ddev->chaining_skb = new_skb; } |
59ae1d127 networking: intro... |
261 |
skb_put_data(ddev->chaining_skb, resp->data, resp->len); |
c12715ab3 NFC: digital: Add... |
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
kfree_skb(resp); resp = NULL; if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb)) { rc = send_ack(ddev, data_exch); if (rc) goto error; return NULL; } resp = ddev->chaining_skb; ddev->chaining_skb = NULL; } return resp; error: kfree_skb(resp); kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; return ERR_PTR(rc); } |
dddb3da04 NFC: digital: Add... |
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
static void digital_in_recv_psl_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { struct nfc_target *target = arg; struct digital_psl_res *psl_res; int rc; if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } psl_res = (struct digital_psl_res *)resp->data; if ((resp->len != sizeof(*psl_res)) || (psl_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN) || (psl_res->cmd != DIGITAL_CMD_PSL_RES)) { rc = -EIO; goto exit; } rc = digital_in_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, NFC_DIGITAL_RF_TECH_424F); if (rc) goto exit; rc = digital_in_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, NFC_DIGITAL_FRAMING_NFCF_NFC_DEP); if (rc) goto exit; if (!DIGITAL_DRV_CAPS_IN_CRC(ddev) && (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A)) { ddev->skb_add_crc = digital_skb_add_crc_f; ddev->skb_check_crc = digital_skb_check_crc_f; } ddev->curr_rf_tech = NFC_DIGITAL_RF_TECH_424F; nfc_dep_link_is_up(ddev->nfc_dev, target->idx, NFC_COMM_ACTIVE, NFC_RF_INITIATOR); ddev->curr_nfc_dep_pni = 0; exit: dev_kfree_skb(resp); if (rc) ddev->curr_protocol = 0; } static int digital_in_send_psl_req(struct nfc_digital_dev *ddev, struct nfc_target *target) { struct sk_buff *skb; struct digital_psl_req *psl_req; |
b15829ba5 NFC: digital: Fix... |
357 |
int rc; |
b08147cbc NFC: digital: Imp... |
358 |
u8 payload_size, payload_bits; |
dddb3da04 NFC: digital: Add... |
359 360 361 362 363 364 365 366 367 368 369 370 371 |
skb = digital_skb_alloc(ddev, sizeof(*psl_req)); if (!skb) return -ENOMEM; skb_put(skb, sizeof(*psl_req)); psl_req = (struct digital_psl_req *)skb->data; psl_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; psl_req->cmd = DIGITAL_CMD_PSL_REQ; psl_req->did = 0; psl_req->brs = (0x2 << 3) | 0x2; /* 424F both directions */ |
b08147cbc NFC: digital: Imp... |
372 373 374 375 376 377 378 |
payload_size = min(ddev->local_payload_max, ddev->remote_payload_max); payload_bits = digital_payload_size_to_bits(payload_size); psl_req->fsl = DIGITAL_PAYLOAD_BITS_TO_FSL(payload_bits); ddev->local_payload_max = payload_size; ddev->remote_payload_max = payload_size; |
dddb3da04 NFC: digital: Add... |
379 380 381 382 |
digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1a09c56f5 NFC: digital: Add... |
383 384 |
rc = digital_in_send_cmd(ddev, skb, ddev->dep_rwt, digital_in_recv_psl_res, target); |
b15829ba5 NFC: digital: Fix... |
385 386 387 388 |
if (rc) kfree_skb(skb); return rc; |
dddb3da04 NFC: digital: Add... |
389 |
} |
7d0911c02 NFC Digital: Add ... |
390 391 392 393 394 |
static void digital_in_recv_atr_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { struct nfc_target *target = arg; struct digital_atr_res *atr_res; |
b08147cbc NFC: digital: Imp... |
395 |
u8 gb_len, payload_bits; |
1a09c56f5 NFC: digital: Add... |
396 |
u8 wt; |
7d0911c02 NFC Digital: Add ... |
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
int rc; if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } if (resp->len < sizeof(struct digital_atr_res)) { rc = -EIO; goto exit; } gb_len = resp->len - sizeof(struct digital_atr_res); atr_res = (struct digital_atr_res *)resp->data; |
1a09c56f5 NFC: digital: Add... |
425 426 427 428 |
wt = DIGITAL_ATR_RES_TO_WT(atr_res->to); if (wt > DIGITAL_NFC_DEP_IN_MAX_WT) wt = DIGITAL_NFC_DEP_IN_MAX_WT; ddev->dep_rwt = digital_rwt_map[wt]; |
b08147cbc NFC: digital: Imp... |
429 430 431 432 433 434 435 |
payload_bits = DIGITAL_PAYLOAD_PP_TO_BITS(atr_res->pp); ddev->remote_payload_max = digital_payload_bits_to_size(payload_bits); if (!ddev->remote_payload_max) { rc = -EINVAL; goto exit; } |
7d0911c02 NFC Digital: Add ... |
436 437 438 |
rc = nfc_set_remote_general_bytes(ddev->nfc_dev, atr_res->gb, gb_len); if (rc) goto exit; |
dddb3da04 NFC: digital: Add... |
439 440 441 442 443 444 |
if ((ddev->protocols & NFC_PROTO_FELICA_MASK) && (ddev->curr_rf_tech != NFC_DIGITAL_RF_TECH_424F)) { rc = digital_in_send_psl_req(ddev, target); if (!rc) goto exit; } |
7d0911c02 NFC Digital: Add ... |
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
rc = nfc_dep_link_is_up(ddev->nfc_dev, target->idx, NFC_COMM_ACTIVE, NFC_RF_INITIATOR); ddev->curr_nfc_dep_pni = 0; exit: dev_kfree_skb(resp); if (rc) ddev->curr_protocol = 0; } int digital_in_send_atr_req(struct nfc_digital_dev *ddev, struct nfc_target *target, __u8 comm_mode, __u8 *gb, size_t gb_len) { struct sk_buff *skb; struct digital_atr_req *atr_req; uint size; |
b15829ba5 NFC: digital: Fix... |
464 |
int rc; |
b08147cbc NFC: digital: Imp... |
465 |
u8 payload_bits; |
7d0911c02 NFC Digital: Add ... |
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
size = DIGITAL_ATR_REQ_MIN_SIZE + gb_len; if (size > DIGITAL_ATR_REQ_MAX_SIZE) { PROTOCOL_ERR("14.6.1.1"); return -EINVAL; } skb = digital_skb_alloc(ddev, size); if (!skb) return -ENOMEM; skb_put(skb, sizeof(struct digital_atr_req)); atr_req = (struct digital_atr_req *)skb->data; memset(atr_req, 0, sizeof(struct digital_atr_req)); atr_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; atr_req->cmd = DIGITAL_CMD_ATR_REQ; if (target->nfcid2_len) |
4f319e325 NFC: digital: Use... |
486 |
memcpy(atr_req->nfcid3, target->nfcid2, NFC_NFCID2_MAXSIZE); |
7d0911c02 NFC Digital: Add ... |
487 |
else |
4f319e325 NFC: digital: Use... |
488 |
get_random_bytes(atr_req->nfcid3, NFC_NFCID3_MAXSIZE); |
7d0911c02 NFC Digital: Add ... |
489 490 491 492 |
atr_req->did = 0; atr_req->bs = 0; atr_req->br = 0; |
b08147cbc NFC: digital: Imp... |
493 494 495 |
ddev->local_payload_max = DIGITAL_PAYLOAD_SIZE_MAX; payload_bits = digital_payload_size_to_bits(ddev->local_payload_max); atr_req->pp = DIGITAL_PAYLOAD_BITS_TO_PP(payload_bits); |
7d0911c02 NFC Digital: Add ... |
496 497 498 |
if (gb_len) { atr_req->pp |= DIGITAL_GB_BIT; |
59ae1d127 networking: intro... |
499 |
skb_put_data(skb, gb, gb_len); |
7d0911c02 NFC Digital: Add ... |
500 501 502 503 504 |
} digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1a09c56f5 NFC: digital: Add... |
505 506 |
rc = digital_in_send_cmd(ddev, skb, DIGITAL_ATR_RES_RWT, digital_in_recv_atr_res, target); |
b15829ba5 NFC: digital: Fix... |
507 508 509 510 |
if (rc) kfree_skb(skb); return rc; |
7d0911c02 NFC Digital: Add ... |
511 |
} |
c12715ab3 NFC: digital: Add... |
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
static int digital_in_send_ack(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch) { struct digital_dep_req_res *dep_req; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; skb_push(skb, sizeof(struct digital_dep_req_res)); dep_req = (struct digital_dep_req_res *)skb->data; dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | ddev->curr_nfc_dep_pni; digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1d984c2e0 NFC: digital: Fix... |
535 |
ddev->saved_skb = pskb_copy(skb, GFP_KERNEL); |
384ab1d17 NFC: digital: Add... |
536 |
|
1a09c56f5 NFC: digital: Add... |
537 538 |
rc = digital_in_send_cmd(ddev, skb, ddev->dep_rwt, digital_in_recv_dep_res, data_exch); |
384ab1d17 NFC: digital: Add... |
539 |
if (rc) { |
c12715ab3 NFC: digital: Add... |
540 |
kfree_skb(skb); |
384ab1d17 NFC: digital: Add... |
541 542 543 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; } |
c12715ab3 NFC: digital: Add... |
544 545 546 |
return rc; } |
a80509c76 NFC: digital: Add... |
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
static int digital_in_send_nack(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch) { struct digital_dep_req_res *dep_req; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; skb_push(skb, sizeof(struct digital_dep_req_res)); dep_req = (struct digital_dep_req_res *)skb->data; dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | DIGITAL_NFC_DEP_PFB_NACK_BIT | ddev->curr_nfc_dep_pni; digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1a09c56f5 NFC: digital: Add... |
570 571 |
rc = digital_in_send_cmd(ddev, skb, ddev->dep_rwt, digital_in_recv_dep_res, data_exch); |
a80509c76 NFC: digital: Add... |
572 573 574 575 576 |
if (rc) kfree_skb(skb); return rc; } |
384ab1d17 NFC: digital: Add... |
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
static int digital_in_send_atn(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch) { struct digital_dep_req_res *dep_req; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; skb_push(skb, sizeof(struct digital_dep_req_res)); dep_req = (struct digital_dep_req_res *)skb->data; dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU; digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1a09c56f5 NFC: digital: Add... |
599 600 |
rc = digital_in_send_cmd(ddev, skb, ddev->dep_rwt, digital_in_recv_dep_res, data_exch); |
384ab1d17 NFC: digital: Add... |
601 602 603 604 605 |
if (rc) kfree_skb(skb); return rc; } |
7d0911c02 NFC Digital: Add ... |
606 607 608 609 610 611 |
static int digital_in_send_rtox(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch, u8 rtox) { struct digital_dep_req_res *dep_req; struct sk_buff *skb; int rc; |
d85a301c2 NFC: digital: Fix... |
612 613 614 615 616 |
u16 rwt_int; rwt_int = ddev->dep_rwt * rtox; if (rwt_int > digital_rwt_map[DIGITAL_NFC_DEP_IN_MAX_WT]) rwt_int = digital_rwt_map[DIGITAL_NFC_DEP_IN_MAX_WT]; |
7d0911c02 NFC Digital: Add ... |
617 618 619 620 |
skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; |
634fef610 networking: add a... |
621 |
skb_put_u8(skb, rtox); |
7d0911c02 NFC Digital: Add ... |
622 623 624 625 626 627 628 629 630 631 632 633 634 |
skb_push(skb, sizeof(struct digital_dep_req_res)); dep_req = (struct digital_dep_req_res *)skb->data; dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU | DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT; digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
d85a301c2 NFC: digital: Fix... |
635 |
rc = digital_in_send_cmd(ddev, skb, rwt_int, |
1a09c56f5 NFC: digital: Add... |
636 |
digital_in_recv_dep_res, data_exch); |
1d984c2e0 NFC: digital: Fix... |
637 |
if (rc) |
b15829ba5 NFC: digital: Fix... |
638 |
kfree_skb(skb); |
7d0911c02 NFC Digital: Add ... |
639 640 641 |
return rc; } |
384ab1d17 NFC: digital: Add... |
642 643 644 |
static int digital_in_send_saved_skb(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch) { |
1d984c2e0 NFC: digital: Fix... |
645 646 647 648 |
int rc; if (!ddev->saved_skb) return -EINVAL; |
384ab1d17 NFC: digital: Add... |
649 |
skb_get(ddev->saved_skb); |
384ab1d17 NFC: digital: Add... |
650 |
|
1a09c56f5 NFC: digital: Add... |
651 |
rc = digital_in_send_cmd(ddev, ddev->saved_skb, ddev->dep_rwt, |
1d984c2e0 NFC: digital: Fix... |
652 653 654 655 656 |
digital_in_recv_dep_res, data_exch); if (rc) kfree_skb(ddev->saved_skb); return rc; |
384ab1d17 NFC: digital: Add... |
657 |
} |
7d0911c02 NFC Digital: Add ... |
658 659 660 661 662 663 664 665 |
static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { struct digital_data_exch *data_exch = arg; struct digital_dep_req_res *dep_res; u8 pfb; uint size; int rc; |
d85a301c2 NFC: digital: Fix... |
666 |
u8 rtox; |
7d0911c02 NFC Digital: Add ... |
667 668 669 670 |
if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; |
a80509c76 NFC: digital: Add... |
671 |
|
3f89fea35 NFC: digital: Rew... |
672 |
if ((rc == -EIO || (rc == -ETIMEDOUT && ddev->nack_count)) && |
a80509c76 NFC: digital: Add... |
673 |
(ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) { |
384ab1d17 NFC: digital: Add... |
674 |
ddev->atn_count = 0; |
a80509c76 NFC: digital: Add... |
675 676 677 678 679 |
rc = digital_in_send_nack(ddev, data_exch); if (rc) goto error; return; |
384ab1d17 NFC: digital: Add... |
680 681 682 683 684 685 686 687 688 |
} else if ((rc == -ETIMEDOUT) && (ddev->atn_count++ < DIGITAL_NFC_DEP_N_RETRY_ATN)) { ddev->nack_count = 0; rc = digital_in_send_atn(ddev, data_exch); if (rc) goto error; return; |
a80509c76 NFC: digital: Add... |
689 690 691 692 693 694 695 696 |
} goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); |
7d0911c02 NFC Digital: Add ... |
697 698 699 700 701 |
goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { |
a80509c76 NFC: digital: Add... |
702 703 |
if ((resp->len >= 4) && (ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) { |
384ab1d17 NFC: digital: Add... |
704 |
ddev->atn_count = 0; |
a80509c76 NFC: digital: Add... |
705 706 707 708 709 710 711 712 |
rc = digital_in_send_nack(ddev, data_exch); if (rc) goto error; kfree_skb(resp); return; } |
7d0911c02 NFC Digital: Add ... |
713 714 715 |
PROTOCOL_ERR("14.4.1.6"); goto error; } |
384ab1d17 NFC: digital: Add... |
716 |
ddev->atn_count = 0; |
a80509c76 NFC: digital: Add... |
717 |
ddev->nack_count = 0; |
7d0911c02 NFC Digital: Add ... |
718 |
|
b08147cbc NFC: digital: Imp... |
719 720 721 722 |
if (resp->len > ddev->local_payload_max) { rc = -EMSGSIZE; goto exit; } |
6ce306682 NFC: digital: Rea... |
723 |
size = sizeof(struct digital_dep_req_res); |
7d0911c02 NFC Digital: Add ... |
724 |
dep_res = (struct digital_dep_req_res *)resp->data; |
6ce306682 NFC: digital: Rea... |
725 |
if (resp->len < size || dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN || |
7d0911c02 NFC Digital: Add ... |
726 727 728 729 730 731 |
dep_res->cmd != DIGITAL_CMD_DEP_RES) { rc = -EIO; goto error; } pfb = dep_res->pfb; |
3bc3f88af NFC: digital: Ens... |
732 733 734 735 736 |
if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) { PROTOCOL_ERR("14.8.2.1"); rc = -EIO; goto error; } |
6ce306682 NFC: digital: Rea... |
737 |
|
3e6b0de80 NFC: digital: Ens... |
738 739 740 741 |
if (DIGITAL_NFC_DEP_NAD_BIT_SET(pfb)) { rc = -EIO; goto exit; } |
6ce306682 NFC: digital: Rea... |
742 743 744 745 746 747 |
if (size > resp->len) { rc = -EIO; goto error; } skb_pull(resp, size); |
7d0911c02 NFC Digital: Add ... |
748 749 750 751 752 753 754 755 756 757 |
switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { case DIGITAL_NFC_DEP_PFB_I_PDU: if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { PROTOCOL_ERR("14.12.3.3"); rc = -EIO; goto error; } ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); |
c12715ab3 NFC: digital: Add... |
758 |
|
384ab1d17 NFC: digital: Add... |
759 760 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
c12715ab3 NFC: digital: Add... |
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
resp = digital_recv_dep_data_gather(ddev, pfb, resp, digital_in_send_ack, data_exch); if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto error; } /* If resp is NULL then we're still chaining so return and * wait for the next part of the PDU. Else, the PDU is * complete so pass it up. */ if (!resp) return; |
7d0911c02 NFC Digital: Add ... |
776 777 778 779 |
rc = 0; break; case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: |
e073eb679 NFC: digital: Rew... |
780 781 782 783 784 |
if (DIGITAL_NFC_DEP_NACK_BIT_SET(pfb)) { PROTOCOL_ERR("14.12.4.5"); rc = -EIO; goto exit; } |
485fdc9bb NFC: digital: Enf... |
785 786 787 788 789 790 791 792 |
if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { PROTOCOL_ERR("14.12.3.3"); rc = -EIO; goto exit; } ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); |
e073eb679 NFC: digital: Rew... |
793 794 795 796 797 |
if (!ddev->chaining_skb) { PROTOCOL_ERR("14.12.4.3"); rc = -EIO; goto exit; } |
384ab1d17 NFC: digital: Add... |
798 |
|
e073eb679 NFC: digital: Rew... |
799 800 801 802 803 |
/* The initiator has received a valid ACK. Free the last sent * PDU and keep on sending chained skb. */ kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
3bd2a5bcc NFC: digital: Add... |
804 |
|
e073eb679 NFC: digital: Rew... |
805 806 807 808 809 |
rc = digital_in_send_dep_req(ddev, NULL, ddev->chaining_skb, ddev->data_exch); if (rc) goto error; |
3bd2a5bcc NFC: digital: Add... |
810 |
|
e073eb679 NFC: digital: Rew... |
811 |
goto free_resp; |
7d0911c02 NFC Digital: Add ... |
812 813 |
case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: |
384ab1d17 NFC: digital: Add... |
814 815 |
if (!DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { /* ATN */ rc = digital_in_send_saved_skb(ddev, data_exch); |
1d984c2e0 NFC: digital: Fix... |
816 |
if (rc) |
384ab1d17 NFC: digital: Add... |
817 |
goto error; |
384ab1d17 NFC: digital: Add... |
818 |
|
e200f008a NFC: digital: Fre... |
819 |
goto free_resp; |
7d0911c02 NFC Digital: Add ... |
820 |
} |
d85a301c2 NFC: digital: Fix... |
821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
if (ddev->atn_count || ddev->nack_count) { PROTOCOL_ERR("14.12.4.4"); rc = -EIO; goto error; } rtox = DIGITAL_NFC_DEP_RTOX_VALUE(resp->data[0]); if (!rtox || rtox > DIGITAL_NFC_DEP_RTOX_MAX) { PROTOCOL_ERR("14.8.4.1"); rc = -EIO; goto error; } rc = digital_in_send_rtox(ddev, data_exch, rtox); |
7d0911c02 NFC Digital: Add ... |
835 836 |
if (rc) goto error; |
e200f008a NFC: digital: Fre... |
837 |
goto free_resp; |
7d0911c02 NFC Digital: Add ... |
838 |
} |
7d0911c02 NFC Digital: Add ... |
839 840 841 842 843 |
exit: data_exch->cb(data_exch->cb_context, resp, rc); error: kfree(data_exch); |
3bd2a5bcc NFC: digital: Add... |
844 845 |
kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; |
384ab1d17 NFC: digital: Add... |
846 847 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
7d0911c02 NFC Digital: Add ... |
848 849 |
if (rc) kfree_skb(resp); |
e073eb679 NFC: digital: Rew... |
850 851 852 853 854 |
return; free_resp: dev_kfree_skb(resp); |
7d0911c02 NFC Digital: Add ... |
855 856 857 858 859 860 861 |
} int digital_in_send_dep_req(struct nfc_digital_dev *ddev, struct nfc_target *target, struct sk_buff *skb, struct digital_data_exch *data_exch) { struct digital_dep_req_res *dep_req; |
3bd2a5bcc NFC: digital: Add... |
862 863 |
struct sk_buff *chaining_skb, *tmp_skb; int rc; |
7d0911c02 NFC Digital: Add ... |
864 865 866 867 |
skb_push(skb, sizeof(struct digital_dep_req_res)); dep_req = (struct digital_dep_req_res *)skb->data; |
3bd2a5bcc NFC: digital: Add... |
868 |
|
7d0911c02 NFC Digital: Add ... |
869 870 871 |
dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->pfb = ddev->curr_nfc_dep_pni; |
384ab1d17 NFC: digital: Add... |
872 |
ddev->atn_count = 0; |
a80509c76 NFC: digital: Add... |
873 |
ddev->nack_count = 0; |
3bd2a5bcc NFC: digital: Add... |
874 |
chaining_skb = ddev->chaining_skb; |
7d0911c02 NFC Digital: Add ... |
875 |
|
3bd2a5bcc NFC: digital: Add... |
876 877 878 |
tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_req, data_exch); if (IS_ERR(tmp_skb)) return PTR_ERR(tmp_skb); |
7d0911c02 NFC Digital: Add ... |
879 |
|
3bd2a5bcc NFC: digital: Add... |
880 881 882 |
digital_skb_push_dep_sod(ddev, tmp_skb); ddev->skb_add_crc(tmp_skb); |
1d984c2e0 NFC: digital: Fix... |
883 |
ddev->saved_skb = pskb_copy(tmp_skb, GFP_KERNEL); |
384ab1d17 NFC: digital: Add... |
884 |
|
1a09c56f5 NFC: digital: Add... |
885 886 |
rc = digital_in_send_cmd(ddev, tmp_skb, ddev->dep_rwt, digital_in_recv_dep_res, data_exch); |
3bd2a5bcc NFC: digital: Add... |
887 888 889 890 891 892 |
if (rc) { if (tmp_skb != skb) kfree_skb(tmp_skb); kfree_skb(chaining_skb); ddev->chaining_skb = NULL; |
384ab1d17 NFC: digital: Add... |
893 894 895 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
3bd2a5bcc NFC: digital: Add... |
896 897 898 |
} return rc; |
7d0911c02 NFC Digital: Add ... |
899 |
} |
1c7a4c24f NFC Digital: Add ... |
900 |
|
b711ad524 NFC: digital: Set... |
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
static void digital_tg_set_rf_tech(struct nfc_digital_dev *ddev, u8 rf_tech) { ddev->curr_rf_tech = rf_tech; ddev->skb_add_crc = digital_skb_add_crc_none; ddev->skb_check_crc = digital_skb_check_crc_none; if (DIGITAL_DRV_CAPS_TG_CRC(ddev)) return; switch (ddev->curr_rf_tech) { case NFC_DIGITAL_RF_TECH_106A: ddev->skb_add_crc = digital_skb_add_crc_a; ddev->skb_check_crc = digital_skb_check_crc_a; break; case NFC_DIGITAL_RF_TECH_212F: case NFC_DIGITAL_RF_TECH_424F: ddev->skb_add_crc = digital_skb_add_crc_f; ddev->skb_check_crc = digital_skb_check_crc_f; break; default: break; } } |
c12715ab3 NFC: digital: Add... |
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
static int digital_tg_send_ack(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch) { struct digital_dep_req_res *dep_res; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; skb_push(skb, sizeof(struct digital_dep_req_res)); dep_res = (struct digital_dep_req_res *)skb->data; dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; dep_res->cmd = DIGITAL_CMD_DEP_RES; dep_res->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | ddev->curr_nfc_dep_pni; if (ddev->did) { dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; |
59ae1d127 networking: intro... |
949 |
skb_put_data(skb, &ddev->did, sizeof(ddev->did)); |
c12715ab3 NFC: digital: Add... |
950 951 952 953 954 955 956 957 |
} ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
1d984c2e0 NFC: digital: Fix... |
958 |
ddev->saved_skb = pskb_copy(skb, GFP_KERNEL); |
49dbb14e3 NFC: digital: Add... |
959 |
|
c12715ab3 NFC: digital: Add... |
960 961 |
rc = digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, data_exch); |
49dbb14e3 NFC: digital: Add... |
962 |
if (rc) { |
c12715ab3 NFC: digital: Add... |
963 |
kfree_skb(skb); |
49dbb14e3 NFC: digital: Add... |
964 965 966 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; } |
c12715ab3 NFC: digital: Add... |
967 968 969 |
return rc; } |
9b5ec0fd5 NFC: digital: Add... |
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
static int digital_tg_send_atn(struct nfc_digital_dev *ddev) { struct digital_dep_req_res *dep_res; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, 1); if (!skb) return -ENOMEM; skb_push(skb, sizeof(struct digital_dep_req_res)); dep_res = (struct digital_dep_req_res *)skb->data; dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; dep_res->cmd = DIGITAL_CMD_DEP_RES; dep_res->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU; if (ddev->did) { dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; |
59ae1d127 networking: intro... |
990 |
skb_put_data(skb, &ddev->did, sizeof(ddev->did)); |
9b5ec0fd5 NFC: digital: Add... |
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
} digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); rc = digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, NULL); if (rc) kfree_skb(skb); return rc; } |
49dbb14e3 NFC: digital: Add... |
1004 1005 |
static int digital_tg_send_saved_skb(struct nfc_digital_dev *ddev) { |
1d984c2e0 NFC: digital: Fix... |
1006 1007 1008 1009 |
int rc; if (!ddev->saved_skb) return -EINVAL; |
49dbb14e3 NFC: digital: Add... |
1010 |
skb_get(ddev->saved_skb); |
49dbb14e3 NFC: digital: Add... |
1011 |
|
1d984c2e0 NFC: digital: Fix... |
1012 1013 1014 1015 1016 1017 |
rc = digital_tg_send_cmd(ddev, ddev->saved_skb, 1500, digital_tg_recv_dep_req, NULL); if (rc) kfree_skb(ddev->saved_skb); return rc; |
49dbb14e3 NFC: digital: Add... |
1018 |
} |
1c7a4c24f NFC Digital: Add ... |
1019 1020 1021 1022 1023 |
static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { int rc; struct digital_dep_req_res *dep_req; |
6ce306682 NFC: digital: Rea... |
1024 |
u8 pfb; |
1c7a4c24f NFC Digital: Add ... |
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
size_t size; if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } |
b08147cbc NFC: digital: Imp... |
1044 1045 1046 1047 |
if (resp->len > ddev->local_payload_max) { rc = -EMSGSIZE; goto exit; } |
1c7a4c24f NFC Digital: Add ... |
1048 1049 1050 1051 1052 1053 1054 1055 |
size = sizeof(struct digital_dep_req_res); dep_req = (struct digital_dep_req_res *)resp->data; if (resp->len < size || dep_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || dep_req->cmd != DIGITAL_CMD_DEP_REQ) { rc = -EIO; goto exit; } |
6ce306682 NFC: digital: Rea... |
1056 |
pfb = dep_req->pfb; |
05afedcb8 NFC: digital: Add... |
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) { if (ddev->did && (ddev->did == resp->data[3])) { size++; } else { rc = -EIO; goto exit; } } else if (ddev->did) { rc = -EIO; goto exit; } |
1c7a4c24f NFC Digital: Add ... |
1068 |
|
3e6b0de80 NFC: digital: Ens... |
1069 1070 1071 1072 |
if (DIGITAL_NFC_DEP_NAD_BIT_SET(pfb)) { rc = -EIO; goto exit; } |
6ce306682 NFC: digital: Rea... |
1073 |
if (size > resp->len) { |
1c7a4c24f NFC Digital: Add ... |
1074 1075 1076 |
rc = -EIO; goto exit; } |
6ce306682 NFC: digital: Rea... |
1077 1078 1079 |
skb_pull(resp, size); switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { |
1c7a4c24f NFC Digital: Add ... |
1080 |
case DIGITAL_NFC_DEP_PFB_I_PDU: |
260425308 NFC: digital: Add... |
1081 1082 |
pr_debug("DIGITAL_NFC_DEP_PFB_I_PDU "); |
485fdc9bb NFC: digital: Enf... |
1083 |
|
9b5ec0fd5 NFC: digital: Add... |
1084 |
if (ddev->atn_count) { |
f23a9868b NFC: digital: Fix... |
1085 1086 1087 |
/* The target has received (and replied to) at least one * ATN DEP_REQ. */ |
9b5ec0fd5 NFC: digital: Add... |
1088 |
ddev->atn_count = 0; |
f23a9868b NFC: digital: Fix... |
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
/* pni of resp PDU equal to the target current pni - 1 * means resp is the previous DEP_REQ PDU received from * the initiator so the target replies with saved_skb * which is the previous DEP_RES saved in * digital_tg_send_dep_res(). */ if (DIGITAL_NFC_DEP_PFB_PNI(pfb) == DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni - 1)) { rc = digital_tg_send_saved_skb(ddev); if (rc) goto exit; |
9b5ec0fd5 NFC: digital: Add... |
1100 |
|
f23a9868b NFC: digital: Fix... |
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
goto free_resp; } /* atn_count > 0 and PDU pni != curr_nfc_dep_pni - 1 * means the target probably did not received the last * DEP_REQ PDU sent by the initiator. The target * fallbacks to normal processing then. */ } if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { PROTOCOL_ERR("14.12.3.4"); rc = -EIO; goto exit; |
9b5ec0fd5 NFC: digital: Add... |
1115 |
} |
49dbb14e3 NFC: digital: Add... |
1116 1117 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
c12715ab3 NFC: digital: Add... |
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
resp = digital_recv_dep_data_gather(ddev, pfb, resp, digital_tg_send_ack, NULL); if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } /* If resp is NULL then we're still chaining so return and * wait for the next part of the PDU. Else, the PDU is * complete so pass it up. */ if (!resp) return; |
485fdc9bb NFC: digital: Enf... |
1132 |
rc = 0; |
1c7a4c24f NFC Digital: Add ... |
1133 1134 |
break; case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: |
482333b27 NFC: digital: Fix... |
1135 1136 1137 |
if (DIGITAL_NFC_DEP_NACK_BIT_SET(pfb)) { /* NACK */ if (DIGITAL_NFC_DEP_PFB_PNI(pfb + 1) != ddev->curr_nfc_dep_pni) { |
49dbb14e3 NFC: digital: Add... |
1138 1139 1140 |
rc = -EIO; goto exit; } |
482333b27 NFC: digital: Fix... |
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
ddev->atn_count = 0; rc = digital_tg_send_saved_skb(ddev); if (rc) goto exit; goto free_resp; } /* ACK */ if (ddev->atn_count) { /* The target has previously recevied one or more ATN * PDUs. */ ddev->atn_count = 0; |
9b5ec0fd5 NFC: digital: Add... |
1156 |
|
482333b27 NFC: digital: Fix... |
1157 1158 1159 1160 1161 1162 |
/* If the ACK PNI is equal to the target PNI - 1 means * that the initiator did not receive the previous PDU * sent by the target so re-send it. */ if (DIGITAL_NFC_DEP_PFB_PNI(pfb + 1) == ddev->curr_nfc_dep_pni) { |
9b5ec0fd5 NFC: digital: Add... |
1163 1164 1165 |
rc = digital_tg_send_saved_skb(ddev); if (rc) goto exit; |
482333b27 NFC: digital: Fix... |
1166 |
goto free_resp; |
9b5ec0fd5 NFC: digital: Add... |
1167 |
} |
482333b27 NFC: digital: Fix... |
1168 1169 1170 1171 1172 |
/* Otherwise, the target did not receive the previous * ACK PDU from the initiator. Fallback to normal * processing of chained PDU then. */ } |
485fdc9bb NFC: digital: Enf... |
1173 |
|
482333b27 NFC: digital: Fix... |
1174 1175 1176 1177 1178 1179 1180 |
/* Keep on sending chained PDU */ if (!ddev->chaining_skb || DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { rc = -EIO; goto exit; } |
3bd2a5bcc NFC: digital: Add... |
1181 |
|
482333b27 NFC: digital: Fix... |
1182 1183 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
9b5ec0fd5 NFC: digital: Add... |
1184 |
|
482333b27 NFC: digital: Fix... |
1185 1186 1187 |
rc = digital_tg_send_dep_res(ddev, ddev->chaining_skb); if (rc) goto exit; |
3bd2a5bcc NFC: digital: Add... |
1188 |
|
482333b27 NFC: digital: Fix... |
1189 |
goto free_resp; |
1c7a4c24f NFC Digital: Add ... |
1190 |
case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: |
9b5ec0fd5 NFC: digital: Add... |
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
if (DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { rc = -EINVAL; goto exit; } rc = digital_tg_send_atn(ddev); if (rc) goto exit; ddev->atn_count++; |
e200f008a NFC: digital: Fre... |
1201 |
goto free_resp; |
1c7a4c24f NFC Digital: Add ... |
1202 |
} |
1c7a4c24f NFC Digital: Add ... |
1203 1204 1205 |
rc = nfc_tm_data_received(ddev->nfc_dev, resp); exit: |
3bd2a5bcc NFC: digital: Add... |
1206 1207 |
kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; |
9b5ec0fd5 NFC: digital: Add... |
1208 |
ddev->atn_count = 0; |
49dbb14e3 NFC: digital: Add... |
1209 1210 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
1c7a4c24f NFC Digital: Add ... |
1211 1212 |
if (rc) kfree_skb(resp); |
f23a9868b NFC: digital: Fix... |
1213 1214 1215 1216 1217 |
return; free_resp: dev_kfree_skb(resp); |
1c7a4c24f NFC Digital: Add ... |
1218 1219 1220 1221 1222 |
} int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb) { struct digital_dep_req_res *dep_res; |
3bd2a5bcc NFC: digital: Add... |
1223 1224 |
struct sk_buff *chaining_skb, *tmp_skb; int rc; |
1c7a4c24f NFC Digital: Add ... |
1225 1226 |
skb_push(skb, sizeof(struct digital_dep_req_res)); |
b08147cbc NFC: digital: Imp... |
1227 |
|
1c7a4c24f NFC Digital: Add ... |
1228 1229 1230 1231 1232 |
dep_res = (struct digital_dep_req_res *)skb->data; dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; dep_res->cmd = DIGITAL_CMD_DEP_RES; dep_res->pfb = ddev->curr_nfc_dep_pni; |
05afedcb8 NFC: digital: Add... |
1233 1234 |
if (ddev->did) { dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; |
59ae1d127 networking: intro... |
1235 |
skb_put_data(skb, &ddev->did, sizeof(ddev->did)); |
05afedcb8 NFC: digital: Add... |
1236 |
} |
485fdc9bb NFC: digital: Enf... |
1237 1238 |
ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); |
3bd2a5bcc NFC: digital: Add... |
1239 |
chaining_skb = ddev->chaining_skb; |
1c7a4c24f NFC Digital: Add ... |
1240 |
|
3bd2a5bcc NFC: digital: Add... |
1241 1242 1243 1244 1245 1246 1247 |
tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_res, NULL); if (IS_ERR(tmp_skb)) return PTR_ERR(tmp_skb); digital_skb_push_dep_sod(ddev, tmp_skb); ddev->skb_add_crc(tmp_skb); |
1c7a4c24f NFC Digital: Add ... |
1248 |
|
1d984c2e0 NFC: digital: Fix... |
1249 |
ddev->saved_skb = pskb_copy(tmp_skb, GFP_KERNEL); |
49dbb14e3 NFC: digital: Add... |
1250 |
|
3bd2a5bcc NFC: digital: Add... |
1251 1252 1253 1254 1255 1256 1257 1258 |
rc = digital_tg_send_cmd(ddev, tmp_skb, 1500, digital_tg_recv_dep_req, NULL); if (rc) { if (tmp_skb != skb) kfree_skb(tmp_skb); kfree_skb(chaining_skb); ddev->chaining_skb = NULL; |
49dbb14e3 NFC: digital: Add... |
1259 1260 1261 |
kfree_skb(ddev->saved_skb); ddev->saved_skb = NULL; |
3bd2a5bcc NFC: digital: Add... |
1262 1263 1264 |
} return rc; |
1c7a4c24f NFC Digital: Add ... |
1265 1266 1267 1268 1269 |
} static void digital_tg_send_psl_res_complete(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { |
67af1d7a0 NFC: digital: Fix... |
1270 |
u8 rf_tech = (unsigned long)arg; |
1c7a4c24f NFC Digital: Add ... |
1271 1272 1273 |
if (IS_ERR(resp)) return; |
b711ad524 NFC: digital: Set... |
1274 |
digital_tg_set_rf_tech(ddev, rf_tech); |
1c7a4c24f NFC Digital: Add ... |
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, rf_tech); digital_tg_listen(ddev, 1500, digital_tg_recv_dep_req, NULL); dev_kfree_skb(resp); } static int digital_tg_send_psl_res(struct nfc_digital_dev *ddev, u8 did, u8 rf_tech) { struct digital_psl_res *psl_res; struct sk_buff *skb; int rc; skb = digital_skb_alloc(ddev, sizeof(struct digital_psl_res)); if (!skb) return -ENOMEM; skb_put(skb, sizeof(struct digital_psl_res)); psl_res = (struct digital_psl_res *)skb->data; psl_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; psl_res->cmd = DIGITAL_CMD_PSL_RES; psl_res->did = did; digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
485fdc9bb NFC: digital: Enf... |
1304 |
ddev->curr_nfc_dep_pni = 0; |
1c7a4c24f NFC Digital: Add ... |
1305 |
rc = digital_tg_send_cmd(ddev, skb, 0, digital_tg_send_psl_res_complete, |
67af1d7a0 NFC: digital: Fix... |
1306 |
(void *)(unsigned long)rf_tech); |
1c7a4c24f NFC Digital: Add ... |
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
if (rc) kfree_skb(skb); return rc; } static void digital_tg_recv_psl_req(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { int rc; struct digital_psl_req *psl_req; u8 rf_tech; |
b08147cbc NFC: digital: Imp... |
1319 |
u8 dsi, payload_size, payload_bits; |
1c7a4c24f NFC Digital: Add ... |
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } psl_req = (struct digital_psl_req *)resp->data; if (resp->len != sizeof(struct digital_psl_req) || psl_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || psl_req->cmd != DIGITAL_CMD_PSL_REQ) { rc = -EIO; goto exit; } dsi = (psl_req->brs >> 3) & 0x07; switch (dsi) { case 0: rf_tech = NFC_DIGITAL_RF_TECH_106A; break; case 1: rf_tech = NFC_DIGITAL_RF_TECH_212F; break; case 2: rf_tech = NFC_DIGITAL_RF_TECH_424F; break; default: |
77d84ff87 treewide: Fix typ... |
1360 1361 |
pr_err("Unsupported dsi value %d ", dsi); |
1c7a4c24f NFC Digital: Add ... |
1362 1363 |
goto exit; } |
b08147cbc NFC: digital: Imp... |
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 |
payload_bits = DIGITAL_PAYLOAD_FSL_TO_BITS(psl_req->fsl); payload_size = digital_payload_bits_to_size(payload_bits); if (!payload_size || (payload_size > min(ddev->local_payload_max, ddev->remote_payload_max))) { rc = -EINVAL; goto exit; } ddev->local_payload_max = payload_size; ddev->remote_payload_max = payload_size; |
1c7a4c24f NFC Digital: Add ... |
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
rc = digital_tg_send_psl_res(ddev, psl_req->did, rf_tech); exit: kfree_skb(resp); } static void digital_tg_send_atr_res_complete(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { int offset; if (IS_ERR(resp)) { digital_poll_next_tech(ddev); return; } offset = 2; if (resp->data[0] == DIGITAL_NFC_DEP_NFCA_SOD_SB) offset++; |
9b5ec0fd5 NFC: digital: Add... |
1394 |
ddev->atn_count = 0; |
1c7a4c24f NFC Digital: Add ... |
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 |
if (resp->data[offset] == DIGITAL_CMD_PSL_REQ) digital_tg_recv_psl_req(ddev, arg, resp); else digital_tg_recv_dep_req(ddev, arg, resp); } static int digital_tg_send_atr_res(struct nfc_digital_dev *ddev, struct digital_atr_req *atr_req) { struct digital_atr_res *atr_res; struct sk_buff *skb; |
b08147cbc NFC: digital: Imp... |
1406 |
u8 *gb, payload_bits; |
1c7a4c24f NFC Digital: Add ... |
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
size_t gb_len; int rc; gb = nfc_get_local_general_bytes(ddev->nfc_dev, &gb_len); if (!gb) gb_len = 0; skb = digital_skb_alloc(ddev, sizeof(struct digital_atr_res) + gb_len); if (!skb) return -ENOMEM; skb_put(skb, sizeof(struct digital_atr_res)); atr_res = (struct digital_atr_res *)skb->data; memset(atr_res, 0, sizeof(struct digital_atr_res)); atr_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; atr_res->cmd = DIGITAL_CMD_ATR_RES; memcpy(atr_res->nfcid3, atr_req->nfcid3, sizeof(atr_req->nfcid3)); |
1a09c56f5 NFC: digital: Add... |
1426 |
atr_res->to = DIGITAL_NFC_DEP_TG_MAX_WT; |
b08147cbc NFC: digital: Imp... |
1427 1428 1429 1430 |
ddev->local_payload_max = DIGITAL_PAYLOAD_SIZE_MAX; payload_bits = digital_payload_size_to_bits(ddev->local_payload_max); atr_res->pp = DIGITAL_PAYLOAD_BITS_TO_PP(payload_bits); |
1c7a4c24f NFC Digital: Add ... |
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 |
if (gb_len) { skb_put(skb, gb_len); atr_res->pp |= DIGITAL_GB_BIT; memcpy(atr_res->gb, gb, gb_len); } digital_skb_push_dep_sod(ddev, skb); ddev->skb_add_crc(skb); |
485fdc9bb NFC: digital: Enf... |
1441 |
ddev->curr_nfc_dep_pni = 0; |
1c7a4c24f NFC Digital: Add ... |
1442 1443 |
rc = digital_tg_send_cmd(ddev, skb, 999, digital_tg_send_atr_res_complete, NULL); |
b15829ba5 NFC: digital: Fix... |
1444 |
if (rc) |
1c7a4c24f NFC Digital: Add ... |
1445 |
kfree_skb(skb); |
1c7a4c24f NFC Digital: Add ... |
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 |
return rc; } void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { int rc; struct digital_atr_req *atr_req; size_t gb_len, min_size; |
b08147cbc NFC: digital: Imp... |
1456 |
u8 poll_tech_count, payload_bits; |
1c7a4c24f NFC Digital: Add ... |
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 |
if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } if (!resp->len) { rc = -EIO; goto exit; } if (resp->data[0] == DIGITAL_NFC_DEP_NFCA_SOD_SB) { min_size = DIGITAL_ATR_REQ_MIN_SIZE + 2; |
b711ad524 NFC: digital: Set... |
1471 |
digital_tg_set_rf_tech(ddev, NFC_DIGITAL_RF_TECH_106A); |
1c7a4c24f NFC Digital: Add ... |
1472 1473 |
} else { min_size = DIGITAL_ATR_REQ_MIN_SIZE + 1; |
b711ad524 NFC: digital: Set... |
1474 |
digital_tg_set_rf_tech(ddev, NFC_DIGITAL_RF_TECH_212F); |
1c7a4c24f NFC Digital: Add ... |
1475 1476 1477 1478 1479 1480 |
} if (resp->len < min_size) { rc = -EIO; goto exit; } |
48e104451 NFC: digital: Set... |
1481 |
ddev->curr_protocol = NFC_PROTO_NFC_DEP_MASK; |
1c7a4c24f NFC Digital: Add ... |
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 |
rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } atr_req = (struct digital_atr_req *)resp->data; if (atr_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || |
05afedcb8 NFC: digital: Add... |
1498 1499 |
atr_req->cmd != DIGITAL_CMD_ATR_REQ || atr_req->did > DIGITAL_DID_MAX) { |
1c7a4c24f NFC Digital: Add ... |
1500 1501 1502 |
rc = -EINVAL; goto exit; } |
b08147cbc NFC: digital: Imp... |
1503 1504 1505 1506 1507 1508 1509 |
payload_bits = DIGITAL_PAYLOAD_PP_TO_BITS(atr_req->pp); ddev->remote_payload_max = digital_payload_bits_to_size(payload_bits); if (!ddev->remote_payload_max) { rc = -EINVAL; goto exit; } |
05afedcb8 NFC: digital: Add... |
1510 |
ddev->did = atr_req->did; |
1c7a4c24f NFC Digital: Add ... |
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 |
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED); if (rc) goto exit; rc = digital_tg_send_atr_res(ddev, atr_req); if (rc) goto exit; gb_len = resp->len - sizeof(struct digital_atr_req); |
0529a7adf NFC: digital: Cle... |
1521 1522 1523 |
poll_tech_count = ddev->poll_tech_count; ddev->poll_tech_count = 0; |
1c7a4c24f NFC Digital: Add ... |
1524 1525 |
rc = nfc_tm_activated(ddev->nfc_dev, NFC_PROTO_NFC_DEP_MASK, NFC_COMM_PASSIVE, atr_req->gb, gb_len); |
0529a7adf NFC: digital: Cle... |
1526 1527 |
if (rc) { ddev->poll_tech_count = poll_tech_count; |
1c7a4c24f NFC Digital: Add ... |
1528 |
goto exit; |
0529a7adf NFC: digital: Cle... |
1529 |
} |
1c7a4c24f NFC Digital: Add ... |
1530 1531 1532 1533 1534 1535 1536 1537 |
rc = 0; exit: if (rc) digital_poll_next_tech(ddev); dev_kfree_skb(resp); } |