1 /* 2 * NFC Digital Protocol stack 3 * Copyright (c) 2013, Intel Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 */ 15 16 #define pr_fmt(fmt) "digital: %s: " fmt, __func__ 17 18 #include "digital.h" 19 20 #define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4 21 #define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5 22 23 #define DIGITAL_NFC_DEP_NFCA_SOD_SB 0xF0 24 25 #define DIGITAL_CMD_ATR_REQ 0x00 26 #define DIGITAL_CMD_ATR_RES 0x01 27 #define DIGITAL_CMD_PSL_REQ 0x04 28 #define DIGITAL_CMD_PSL_RES 0x05 29 #define DIGITAL_CMD_DEP_REQ 0x06 30 #define DIGITAL_CMD_DEP_RES 0x07 31 32 #define DIGITAL_ATR_REQ_MIN_SIZE 16 33 #define DIGITAL_ATR_REQ_MAX_SIZE 64 34 35 #define DIGITAL_LR_BITS_PAYLOAD_SIZE_254B 0x30 36 #define DIGITAL_GB_BIT 0x02 37 38 #define DIGITAL_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0) 39 40 #define DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT 0x10 41 42 #define DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb) \ 43 ((pfb) & DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT) 44 #define DIGITAL_NFC_DEP_MI_BIT_SET(pfb) ((pfb) & 0x10) 45 #define DIGITAL_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08) 46 #define DIGITAL_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & 0x04) 47 #define DIGITAL_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03) 48 49 #define DIGITAL_NFC_DEP_PFB_I_PDU 0x00 50 #define DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU 0x40 51 #define DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU 0x80 52 53 struct digital_atr_req { 54 u8 dir; 55 u8 cmd; 56 u8 nfcid3[10]; 57 u8 did; 58 u8 bs; 59 u8 br; 60 u8 pp; 61 u8 gb[0]; 62 } __packed; 63 64 struct digital_atr_res { 65 u8 dir; 66 u8 cmd; 67 u8 nfcid3[10]; 68 u8 did; 69 u8 bs; 70 u8 br; 71 u8 to; 72 u8 pp; 73 u8 gb[0]; 74 } __packed; 75 76 struct digital_psl_req { 77 u8 dir; 78 u8 cmd; 79 u8 did; 80 u8 brs; 81 u8 fsl; 82 } __packed; 83 84 struct digital_psl_res { 85 u8 dir; 86 u8 cmd; 87 u8 did; 88 } __packed; 89 90 struct digital_dep_req_res { 91 u8 dir; 92 u8 cmd; 93 u8 pfb; 94 } __packed; 95 96 static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, 97 struct sk_buff *resp); 98 99 static void digital_skb_push_dep_sod(struct nfc_digital_dev *ddev, 100 struct sk_buff *skb) 101 { 102 skb_push(skb, sizeof(u8)); 103 104 skb->data[0] = skb->len; 105 106 if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) 107 *skb_push(skb, sizeof(u8)) = DIGITAL_NFC_DEP_NFCA_SOD_SB; 108 } 109 110 static int digital_skb_pull_dep_sod(struct nfc_digital_dev *ddev, 111 struct sk_buff *skb) 112 { 113 u8 size; 114 115 if (skb->len < 2) 116 return -EIO; 117 118 if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) 119 skb_pull(skb, sizeof(u8)); 120 121 size = skb->data[0]; 122 if (size != skb->len) 123 return -EIO; 124 125 skb_pull(skb, sizeof(u8)); 126 127 return 0; 128 } 129 130 static void digital_in_recv_atr_res(struct nfc_digital_dev *ddev, void *arg, 131 struct sk_buff *resp) 132 { 133 struct nfc_target *target = arg; 134 struct digital_atr_res *atr_res; 135 u8 gb_len; 136 int rc; 137 138 if (IS_ERR(resp)) { 139 rc = PTR_ERR(resp); 140 resp = NULL; 141 goto exit; 142 } 143 144 rc = ddev->skb_check_crc(resp); 145 if (rc) { 146 PROTOCOL_ERR("14.4.1.6"); 147 goto exit; 148 } 149 150 rc = digital_skb_pull_dep_sod(ddev, resp); 151 if (rc) { 152 PROTOCOL_ERR("14.4.1.2"); 153 goto exit; 154 } 155 156 if (resp->len < sizeof(struct digital_atr_res)) { 157 rc = -EIO; 158 goto exit; 159 } 160 161 gb_len = resp->len - sizeof(struct digital_atr_res); 162 163 atr_res = (struct digital_atr_res *)resp->data; 164 165 rc = nfc_set_remote_general_bytes(ddev->nfc_dev, atr_res->gb, gb_len); 166 if (rc) 167 goto exit; 168 169 rc = nfc_dep_link_is_up(ddev->nfc_dev, target->idx, NFC_COMM_ACTIVE, 170 NFC_RF_INITIATOR); 171 172 ddev->curr_nfc_dep_pni = 0; 173 174 exit: 175 dev_kfree_skb(resp); 176 177 if (rc) 178 ddev->curr_protocol = 0; 179 } 180 181 int digital_in_send_atr_req(struct nfc_digital_dev *ddev, 182 struct nfc_target *target, __u8 comm_mode, __u8 *gb, 183 size_t gb_len) 184 { 185 struct sk_buff *skb; 186 struct digital_atr_req *atr_req; 187 uint size; 188 189 size = DIGITAL_ATR_REQ_MIN_SIZE + gb_len; 190 191 if (size > DIGITAL_ATR_REQ_MAX_SIZE) { 192 PROTOCOL_ERR("14.6.1.1"); 193 return -EINVAL; 194 } 195 196 skb = digital_skb_alloc(ddev, size); 197 if (!skb) 198 return -ENOMEM; 199 200 skb_put(skb, sizeof(struct digital_atr_req)); 201 202 atr_req = (struct digital_atr_req *)skb->data; 203 memset(atr_req, 0, sizeof(struct digital_atr_req)); 204 205 atr_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; 206 atr_req->cmd = DIGITAL_CMD_ATR_REQ; 207 if (target->nfcid2_len) 208 memcpy(atr_req->nfcid3, target->nfcid2, NFC_NFCID2_MAXSIZE); 209 else 210 get_random_bytes(atr_req->nfcid3, NFC_NFCID3_MAXSIZE); 211 212 atr_req->did = 0; 213 atr_req->bs = 0; 214 atr_req->br = 0; 215 216 atr_req->pp = DIGITAL_LR_BITS_PAYLOAD_SIZE_254B; 217 218 if (gb_len) { 219 atr_req->pp |= DIGITAL_GB_BIT; 220 memcpy(skb_put(skb, gb_len), gb, gb_len); 221 } 222 223 digital_skb_push_dep_sod(ddev, skb); 224 225 ddev->skb_add_crc(skb); 226 227 return digital_in_send_cmd(ddev, skb, 500, digital_in_recv_atr_res, 228 target); 229 } 230 231 static int digital_in_send_rtox(struct nfc_digital_dev *ddev, 232 struct digital_data_exch *data_exch, u8 rtox) 233 { 234 struct digital_dep_req_res *dep_req; 235 struct sk_buff *skb; 236 int rc; 237 238 skb = digital_skb_alloc(ddev, 1); 239 if (!skb) 240 return -ENOMEM; 241 242 *skb_put(skb, 1) = rtox; 243 244 skb_push(skb, sizeof(struct digital_dep_req_res)); 245 246 dep_req = (struct digital_dep_req_res *)skb->data; 247 248 dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; 249 dep_req->cmd = DIGITAL_CMD_DEP_REQ; 250 dep_req->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU | 251 DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT; 252 253 digital_skb_push_dep_sod(ddev, skb); 254 255 ddev->skb_add_crc(skb); 256 257 rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, 258 data_exch); 259 260 return rc; 261 } 262 263 static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, 264 struct sk_buff *resp) 265 { 266 struct digital_data_exch *data_exch = arg; 267 struct digital_dep_req_res *dep_res; 268 u8 pfb; 269 uint size; 270 int rc; 271 272 if (IS_ERR(resp)) { 273 rc = PTR_ERR(resp); 274 resp = NULL; 275 goto exit; 276 } 277 278 rc = ddev->skb_check_crc(resp); 279 if (rc) { 280 PROTOCOL_ERR("14.4.1.6"); 281 goto error; 282 } 283 284 rc = digital_skb_pull_dep_sod(ddev, resp); 285 if (rc) { 286 PROTOCOL_ERR("14.4.1.2"); 287 goto exit; 288 } 289 290 dep_res = (struct digital_dep_req_res *)resp->data; 291 292 if (resp->len < sizeof(struct digital_dep_req_res) || 293 dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN || 294 dep_res->cmd != DIGITAL_CMD_DEP_RES) { 295 rc = -EIO; 296 goto error; 297 } 298 299 pfb = dep_res->pfb; 300 301 switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { 302 case DIGITAL_NFC_DEP_PFB_I_PDU: 303 if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { 304 PROTOCOL_ERR("14.12.3.3"); 305 rc = -EIO; 306 goto error; 307 } 308 309 ddev->curr_nfc_dep_pni = 310 DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); 311 rc = 0; 312 break; 313 314 case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: 315 pr_err("Received a ACK/NACK PDU\n"); 316 rc = -EIO; 317 goto error; 318 319 case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: 320 if (!DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { 321 rc = -EINVAL; 322 goto error; 323 } 324 325 rc = digital_in_send_rtox(ddev, data_exch, resp->data[3]); 326 if (rc) 327 goto error; 328 329 kfree_skb(resp); 330 return; 331 } 332 333 if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb)) { 334 pr_err("MI bit set. Chained PDU not supported\n"); 335 rc = -EIO; 336 goto error; 337 } 338 339 size = sizeof(struct digital_dep_req_res); 340 341 if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) 342 size++; 343 344 if (size > resp->len) { 345 rc = -EIO; 346 goto error; 347 } 348 349 skb_pull(resp, size); 350 351 exit: 352 data_exch->cb(data_exch->cb_context, resp, rc); 353 354 error: 355 kfree(data_exch); 356 357 if (rc) 358 kfree_skb(resp); 359 } 360 361 int digital_in_send_dep_req(struct nfc_digital_dev *ddev, 362 struct nfc_target *target, struct sk_buff *skb, 363 struct digital_data_exch *data_exch) 364 { 365 struct digital_dep_req_res *dep_req; 366 367 skb_push(skb, sizeof(struct digital_dep_req_res)); 368 369 dep_req = (struct digital_dep_req_res *)skb->data; 370 dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; 371 dep_req->cmd = DIGITAL_CMD_DEP_REQ; 372 dep_req->pfb = ddev->curr_nfc_dep_pni; 373 374 digital_skb_push_dep_sod(ddev, skb); 375 376 ddev->skb_add_crc(skb); 377 378 return digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, 379 data_exch); 380 } 381 382 static void digital_tg_set_rf_tech(struct nfc_digital_dev *ddev, u8 rf_tech) 383 { 384 ddev->curr_rf_tech = rf_tech; 385 386 ddev->skb_add_crc = digital_skb_add_crc_none; 387 ddev->skb_check_crc = digital_skb_check_crc_none; 388 389 if (DIGITAL_DRV_CAPS_TG_CRC(ddev)) 390 return; 391 392 switch (ddev->curr_rf_tech) { 393 case NFC_DIGITAL_RF_TECH_106A: 394 ddev->skb_add_crc = digital_skb_add_crc_a; 395 ddev->skb_check_crc = digital_skb_check_crc_a; 396 break; 397 398 case NFC_DIGITAL_RF_TECH_212F: 399 case NFC_DIGITAL_RF_TECH_424F: 400 ddev->skb_add_crc = digital_skb_add_crc_f; 401 ddev->skb_check_crc = digital_skb_check_crc_f; 402 break; 403 404 default: 405 break; 406 } 407 } 408 409 static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, 410 struct sk_buff *resp) 411 { 412 int rc; 413 struct digital_dep_req_res *dep_req; 414 size_t size; 415 416 if (IS_ERR(resp)) { 417 rc = PTR_ERR(resp); 418 resp = NULL; 419 goto exit; 420 } 421 422 rc = ddev->skb_check_crc(resp); 423 if (rc) { 424 PROTOCOL_ERR("14.4.1.6"); 425 goto exit; 426 } 427 428 rc = digital_skb_pull_dep_sod(ddev, resp); 429 if (rc) { 430 PROTOCOL_ERR("14.4.1.2"); 431 goto exit; 432 } 433 434 size = sizeof(struct digital_dep_req_res); 435 dep_req = (struct digital_dep_req_res *)resp->data; 436 437 if (resp->len < size || dep_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || 438 dep_req->cmd != DIGITAL_CMD_DEP_REQ) { 439 rc = -EIO; 440 goto exit; 441 } 442 443 if (DIGITAL_NFC_DEP_DID_BIT_SET(dep_req->pfb)) 444 size++; 445 446 if (resp->len < size) { 447 rc = -EIO; 448 goto exit; 449 } 450 451 switch (DIGITAL_NFC_DEP_PFB_TYPE(dep_req->pfb)) { 452 case DIGITAL_NFC_DEP_PFB_I_PDU: 453 pr_debug("DIGITAL_NFC_DEP_PFB_I_PDU\n"); 454 ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(dep_req->pfb); 455 break; 456 case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: 457 pr_err("Received a ACK/NACK PDU\n"); 458 rc = -EINVAL; 459 goto exit; 460 case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: 461 pr_err("Received a SUPERVISOR PDU\n"); 462 rc = -EINVAL; 463 goto exit; 464 } 465 466 skb_pull(resp, size); 467 468 rc = nfc_tm_data_received(ddev->nfc_dev, resp); 469 470 exit: 471 if (rc) 472 kfree_skb(resp); 473 } 474 475 int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb) 476 { 477 struct digital_dep_req_res *dep_res; 478 479 skb_push(skb, sizeof(struct digital_dep_req_res)); 480 dep_res = (struct digital_dep_req_res *)skb->data; 481 482 dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; 483 dep_res->cmd = DIGITAL_CMD_DEP_RES; 484 dep_res->pfb = ddev->curr_nfc_dep_pni; 485 486 digital_skb_push_dep_sod(ddev, skb); 487 488 ddev->skb_add_crc(skb); 489 490 return digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, 491 NULL); 492 } 493 494 static void digital_tg_send_psl_res_complete(struct nfc_digital_dev *ddev, 495 void *arg, struct sk_buff *resp) 496 { 497 u8 rf_tech = (unsigned long)arg; 498 499 if (IS_ERR(resp)) 500 return; 501 502 digital_tg_set_rf_tech(ddev, rf_tech); 503 504 digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, rf_tech); 505 506 digital_tg_listen(ddev, 1500, digital_tg_recv_dep_req, NULL); 507 508 dev_kfree_skb(resp); 509 } 510 511 static int digital_tg_send_psl_res(struct nfc_digital_dev *ddev, u8 did, 512 u8 rf_tech) 513 { 514 struct digital_psl_res *psl_res; 515 struct sk_buff *skb; 516 int rc; 517 518 skb = digital_skb_alloc(ddev, sizeof(struct digital_psl_res)); 519 if (!skb) 520 return -ENOMEM; 521 522 skb_put(skb, sizeof(struct digital_psl_res)); 523 524 psl_res = (struct digital_psl_res *)skb->data; 525 526 psl_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; 527 psl_res->cmd = DIGITAL_CMD_PSL_RES; 528 psl_res->did = did; 529 530 digital_skb_push_dep_sod(ddev, skb); 531 532 ddev->skb_add_crc(skb); 533 534 rc = digital_tg_send_cmd(ddev, skb, 0, digital_tg_send_psl_res_complete, 535 (void *)(unsigned long)rf_tech); 536 537 if (rc) 538 kfree_skb(skb); 539 540 return rc; 541 } 542 543 static void digital_tg_recv_psl_req(struct nfc_digital_dev *ddev, void *arg, 544 struct sk_buff *resp) 545 { 546 int rc; 547 struct digital_psl_req *psl_req; 548 u8 rf_tech; 549 u8 dsi; 550 551 if (IS_ERR(resp)) { 552 rc = PTR_ERR(resp); 553 resp = NULL; 554 goto exit; 555 } 556 557 rc = ddev->skb_check_crc(resp); 558 if (rc) { 559 PROTOCOL_ERR("14.4.1.6"); 560 goto exit; 561 } 562 563 rc = digital_skb_pull_dep_sod(ddev, resp); 564 if (rc) { 565 PROTOCOL_ERR("14.4.1.2"); 566 goto exit; 567 } 568 569 psl_req = (struct digital_psl_req *)resp->data; 570 571 if (resp->len != sizeof(struct digital_psl_req) || 572 psl_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || 573 psl_req->cmd != DIGITAL_CMD_PSL_REQ) { 574 rc = -EIO; 575 goto exit; 576 } 577 578 dsi = (psl_req->brs >> 3) & 0x07; 579 switch (dsi) { 580 case 0: 581 rf_tech = NFC_DIGITAL_RF_TECH_106A; 582 break; 583 case 1: 584 rf_tech = NFC_DIGITAL_RF_TECH_212F; 585 break; 586 case 2: 587 rf_tech = NFC_DIGITAL_RF_TECH_424F; 588 break; 589 default: 590 pr_err("Unsupported dsi value %d\n", dsi); 591 goto exit; 592 } 593 594 rc = digital_tg_send_psl_res(ddev, psl_req->did, rf_tech); 595 596 exit: 597 kfree_skb(resp); 598 } 599 600 static void digital_tg_send_atr_res_complete(struct nfc_digital_dev *ddev, 601 void *arg, struct sk_buff *resp) 602 { 603 int offset; 604 605 if (IS_ERR(resp)) { 606 digital_poll_next_tech(ddev); 607 return; 608 } 609 610 offset = 2; 611 if (resp->data[0] == DIGITAL_NFC_DEP_NFCA_SOD_SB) 612 offset++; 613 614 if (resp->data[offset] == DIGITAL_CMD_PSL_REQ) 615 digital_tg_recv_psl_req(ddev, arg, resp); 616 else 617 digital_tg_recv_dep_req(ddev, arg, resp); 618 } 619 620 static int digital_tg_send_atr_res(struct nfc_digital_dev *ddev, 621 struct digital_atr_req *atr_req) 622 { 623 struct digital_atr_res *atr_res; 624 struct sk_buff *skb; 625 u8 *gb; 626 size_t gb_len; 627 int rc; 628 629 gb = nfc_get_local_general_bytes(ddev->nfc_dev, &gb_len); 630 if (!gb) 631 gb_len = 0; 632 633 skb = digital_skb_alloc(ddev, sizeof(struct digital_atr_res) + gb_len); 634 if (!skb) 635 return -ENOMEM; 636 637 skb_put(skb, sizeof(struct digital_atr_res)); 638 atr_res = (struct digital_atr_res *)skb->data; 639 640 memset(atr_res, 0, sizeof(struct digital_atr_res)); 641 642 atr_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; 643 atr_res->cmd = DIGITAL_CMD_ATR_RES; 644 memcpy(atr_res->nfcid3, atr_req->nfcid3, sizeof(atr_req->nfcid3)); 645 atr_res->to = 8; 646 atr_res->pp = DIGITAL_LR_BITS_PAYLOAD_SIZE_254B; 647 if (gb_len) { 648 skb_put(skb, gb_len); 649 650 atr_res->pp |= DIGITAL_GB_BIT; 651 memcpy(atr_res->gb, gb, gb_len); 652 } 653 654 digital_skb_push_dep_sod(ddev, skb); 655 656 ddev->skb_add_crc(skb); 657 658 rc = digital_tg_send_cmd(ddev, skb, 999, 659 digital_tg_send_atr_res_complete, NULL); 660 if (rc) { 661 kfree_skb(skb); 662 return rc; 663 } 664 665 return rc; 666 } 667 668 void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg, 669 struct sk_buff *resp) 670 { 671 int rc; 672 struct digital_atr_req *atr_req; 673 size_t gb_len, min_size; 674 u8 poll_tech_count; 675 676 if (IS_ERR(resp)) { 677 rc = PTR_ERR(resp); 678 resp = NULL; 679 goto exit; 680 } 681 682 if (!resp->len) { 683 rc = -EIO; 684 goto exit; 685 } 686 687 if (resp->data[0] == DIGITAL_NFC_DEP_NFCA_SOD_SB) { 688 min_size = DIGITAL_ATR_REQ_MIN_SIZE + 2; 689 digital_tg_set_rf_tech(ddev, NFC_DIGITAL_RF_TECH_106A); 690 } else { 691 min_size = DIGITAL_ATR_REQ_MIN_SIZE + 1; 692 digital_tg_set_rf_tech(ddev, NFC_DIGITAL_RF_TECH_212F); 693 } 694 695 if (resp->len < min_size) { 696 rc = -EIO; 697 goto exit; 698 } 699 700 ddev->curr_protocol = NFC_PROTO_NFC_DEP_MASK; 701 702 rc = ddev->skb_check_crc(resp); 703 if (rc) { 704 PROTOCOL_ERR("14.4.1.6"); 705 goto exit; 706 } 707 708 rc = digital_skb_pull_dep_sod(ddev, resp); 709 if (rc) { 710 PROTOCOL_ERR("14.4.1.2"); 711 goto exit; 712 } 713 714 atr_req = (struct digital_atr_req *)resp->data; 715 716 if (atr_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || 717 atr_req->cmd != DIGITAL_CMD_ATR_REQ) { 718 rc = -EINVAL; 719 goto exit; 720 } 721 722 rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, 723 NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED); 724 if (rc) 725 goto exit; 726 727 rc = digital_tg_send_atr_res(ddev, atr_req); 728 if (rc) 729 goto exit; 730 731 gb_len = resp->len - sizeof(struct digital_atr_req); 732 733 poll_tech_count = ddev->poll_tech_count; 734 ddev->poll_tech_count = 0; 735 736 rc = nfc_tm_activated(ddev->nfc_dev, NFC_PROTO_NFC_DEP_MASK, 737 NFC_COMM_PASSIVE, atr_req->gb, gb_len); 738 if (rc) { 739 ddev->poll_tech_count = poll_tech_count; 740 goto exit; 741 } 742 743 rc = 0; 744 exit: 745 if (rc) 746 digital_poll_next_tech(ddev); 747 748 dev_kfree_skb(resp); 749 } 750