1 /* 2 * The NFC Controller Interface is the communication protocol between an 3 * NFC Controller (NFCC) and a Device Host (DH). 4 * 5 * Copyright (C) 2014 Marvell International Ltd. 6 * Copyright (C) 2011 Texas Instruments, Inc. 7 * 8 * Written by Ilan Elias <ilane@ti.com> 9 * 10 * Acknowledgements: 11 * This file is based on hci_event.c, which was written 12 * by Maxim Krasnyansky. 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License version 2 16 * as published by the Free Software Foundation 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, see <http://www.gnu.org/licenses/>. 25 * 26 */ 27 28 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ 29 30 #include <linux/types.h> 31 #include <linux/interrupt.h> 32 #include <linux/bitops.h> 33 #include <linux/skbuff.h> 34 35 #include "../nfc.h" 36 #include <net/nfc/nci.h> 37 #include <net/nfc/nci_core.h> 38 #include <linux/nfc.h> 39 40 /* Handle NCI Notification packets */ 41 42 static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev, 43 struct sk_buff *skb) 44 { 45 struct nci_core_conn_credit_ntf *ntf = (void *) skb->data; 46 int i; 47 48 pr_debug("num_entries %d\n", ntf->num_entries); 49 50 if (ntf->num_entries > NCI_MAX_NUM_CONN) 51 ntf->num_entries = NCI_MAX_NUM_CONN; 52 53 /* update the credits */ 54 for (i = 0; i < ntf->num_entries; i++) { 55 ntf->conn_entries[i].conn_id = 56 nci_conn_id(&ntf->conn_entries[i].conn_id); 57 58 pr_debug("entry[%d]: conn_id %d, credits %d\n", 59 i, ntf->conn_entries[i].conn_id, 60 ntf->conn_entries[i].credits); 61 62 if (ntf->conn_entries[i].conn_id == NCI_STATIC_RF_CONN_ID) { 63 /* found static rf connection */ 64 atomic_add(ntf->conn_entries[i].credits, 65 &ndev->credits_cnt); 66 } 67 } 68 69 /* trigger the next tx */ 70 if (!skb_queue_empty(&ndev->tx_q)) 71 queue_work(ndev->tx_wq, &ndev->tx_work); 72 } 73 74 static void nci_core_generic_error_ntf_packet(struct nci_dev *ndev, 75 struct sk_buff *skb) 76 { 77 __u8 status = skb->data[0]; 78 79 pr_debug("status 0x%x\n", status); 80 81 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) { 82 /* Activation failed, so complete the request 83 (the state remains the same) */ 84 nci_req_complete(ndev, status); 85 } 86 } 87 88 static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev, 89 struct sk_buff *skb) 90 { 91 struct nci_core_intf_error_ntf *ntf = (void *) skb->data; 92 93 ntf->conn_id = nci_conn_id(&ntf->conn_id); 94 95 pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id); 96 97 /* complete the data exchange transaction, if exists */ 98 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) 99 nci_data_exchange_complete(ndev, NULL, -EIO); 100 } 101 102 static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev, 103 struct rf_tech_specific_params_nfca_poll *nfca_poll, 104 __u8 *data) 105 { 106 nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data)); 107 data += 2; 108 109 nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE); 110 111 pr_debug("sens_res 0x%x, nfcid1_len %d\n", 112 nfca_poll->sens_res, nfca_poll->nfcid1_len); 113 114 memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len); 115 data += nfca_poll->nfcid1_len; 116 117 nfca_poll->sel_res_len = *data++; 118 119 if (nfca_poll->sel_res_len != 0) 120 nfca_poll->sel_res = *data++; 121 122 pr_debug("sel_res_len %d, sel_res 0x%x\n", 123 nfca_poll->sel_res_len, 124 nfca_poll->sel_res); 125 126 return data; 127 } 128 129 static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev, 130 struct rf_tech_specific_params_nfcb_poll *nfcb_poll, 131 __u8 *data) 132 { 133 nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE); 134 135 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len); 136 137 memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len); 138 data += nfcb_poll->sensb_res_len; 139 140 return data; 141 } 142 143 static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev, 144 struct rf_tech_specific_params_nfcf_poll *nfcf_poll, 145 __u8 *data) 146 { 147 nfcf_poll->bit_rate = *data++; 148 nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE); 149 150 pr_debug("bit_rate %d, sensf_res_len %d\n", 151 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len); 152 153 memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len); 154 data += nfcf_poll->sensf_res_len; 155 156 return data; 157 } 158 159 static __u8 *nci_extract_rf_params_nfcv_passive_poll(struct nci_dev *ndev, 160 struct rf_tech_specific_params_nfcv_poll *nfcv_poll, 161 __u8 *data) 162 { 163 ++data; 164 nfcv_poll->dsfid = *data++; 165 memcpy(nfcv_poll->uid, data, NFC_ISO15693_UID_MAXSIZE); 166 data += NFC_ISO15693_UID_MAXSIZE; 167 return data; 168 } 169 170 static int nci_add_new_protocol(struct nci_dev *ndev, 171 struct nfc_target *target, 172 __u8 rf_protocol, 173 __u8 rf_tech_and_mode, 174 void *params) 175 { 176 struct rf_tech_specific_params_nfca_poll *nfca_poll; 177 struct rf_tech_specific_params_nfcb_poll *nfcb_poll; 178 struct rf_tech_specific_params_nfcf_poll *nfcf_poll; 179 struct rf_tech_specific_params_nfcv_poll *nfcv_poll; 180 __u32 protocol; 181 182 if (rf_protocol == NCI_RF_PROTOCOL_T1T) 183 protocol = NFC_PROTO_JEWEL_MASK; 184 else if (rf_protocol == NCI_RF_PROTOCOL_T2T) 185 protocol = NFC_PROTO_MIFARE_MASK; 186 else if (rf_protocol == NCI_RF_PROTOCOL_ISO_DEP) 187 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) 188 protocol = NFC_PROTO_ISO14443_MASK; 189 else 190 protocol = NFC_PROTO_ISO14443_B_MASK; 191 else if (rf_protocol == NCI_RF_PROTOCOL_T3T) 192 protocol = NFC_PROTO_FELICA_MASK; 193 else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) 194 protocol = NFC_PROTO_NFC_DEP_MASK; 195 else if (rf_protocol == NCI_RF_PROTOCOL_T5T) 196 protocol = NFC_PROTO_ISO15693_MASK; 197 else 198 protocol = 0; 199 200 if (!(protocol & ndev->poll_prots)) { 201 pr_err("the target found does not have the desired protocol\n"); 202 return -EPROTO; 203 } 204 205 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) { 206 nfca_poll = (struct rf_tech_specific_params_nfca_poll *)params; 207 208 target->sens_res = nfca_poll->sens_res; 209 target->sel_res = nfca_poll->sel_res; 210 target->nfcid1_len = nfca_poll->nfcid1_len; 211 if (target->nfcid1_len > 0) { 212 memcpy(target->nfcid1, nfca_poll->nfcid1, 213 target->nfcid1_len); 214 } 215 } else if (rf_tech_and_mode == NCI_NFC_B_PASSIVE_POLL_MODE) { 216 nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params; 217 218 target->sensb_res_len = nfcb_poll->sensb_res_len; 219 if (target->sensb_res_len > 0) { 220 memcpy(target->sensb_res, nfcb_poll->sensb_res, 221 target->sensb_res_len); 222 } 223 } else if (rf_tech_and_mode == NCI_NFC_F_PASSIVE_POLL_MODE) { 224 nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params; 225 226 target->sensf_res_len = nfcf_poll->sensf_res_len; 227 if (target->sensf_res_len > 0) { 228 memcpy(target->sensf_res, nfcf_poll->sensf_res, 229 target->sensf_res_len); 230 } 231 } else if (rf_tech_and_mode == NCI_NFC_V_PASSIVE_POLL_MODE) { 232 nfcv_poll = (struct rf_tech_specific_params_nfcv_poll *)params; 233 234 target->is_iso15693 = 1; 235 target->iso15693_dsfid = nfcv_poll->dsfid; 236 memcpy(target->iso15693_uid, nfcv_poll->uid, NFC_ISO15693_UID_MAXSIZE); 237 } else { 238 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode); 239 return -EPROTO; 240 } 241 242 target->supported_protocols |= protocol; 243 244 pr_debug("protocol 0x%x\n", protocol); 245 246 return 0; 247 } 248 249 static void nci_add_new_target(struct nci_dev *ndev, 250 struct nci_rf_discover_ntf *ntf) 251 { 252 struct nfc_target *target; 253 int i, rc; 254 255 for (i = 0; i < ndev->n_targets; i++) { 256 target = &ndev->targets[i]; 257 if (target->logical_idx == ntf->rf_discovery_id) { 258 /* This target already exists, add the new protocol */ 259 nci_add_new_protocol(ndev, target, ntf->rf_protocol, 260 ntf->rf_tech_and_mode, 261 &ntf->rf_tech_specific_params); 262 return; 263 } 264 } 265 266 /* This is a new target, check if we've enough room */ 267 if (ndev->n_targets == NCI_MAX_DISCOVERED_TARGETS) { 268 pr_debug("not enough room, ignoring new target...\n"); 269 return; 270 } 271 272 target = &ndev->targets[ndev->n_targets]; 273 274 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol, 275 ntf->rf_tech_and_mode, 276 &ntf->rf_tech_specific_params); 277 if (!rc) { 278 target->logical_idx = ntf->rf_discovery_id; 279 ndev->n_targets++; 280 281 pr_debug("logical idx %d, n_targets %d\n", target->logical_idx, 282 ndev->n_targets); 283 } 284 } 285 286 void nci_clear_target_list(struct nci_dev *ndev) 287 { 288 memset(ndev->targets, 0, 289 (sizeof(struct nfc_target)*NCI_MAX_DISCOVERED_TARGETS)); 290 291 ndev->n_targets = 0; 292 } 293 294 static void nci_rf_discover_ntf_packet(struct nci_dev *ndev, 295 struct sk_buff *skb) 296 { 297 struct nci_rf_discover_ntf ntf; 298 __u8 *data = skb->data; 299 bool add_target = true; 300 301 ntf.rf_discovery_id = *data++; 302 ntf.rf_protocol = *data++; 303 ntf.rf_tech_and_mode = *data++; 304 ntf.rf_tech_specific_params_len = *data++; 305 306 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id); 307 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol); 308 pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode); 309 pr_debug("rf_tech_specific_params_len %d\n", 310 ntf.rf_tech_specific_params_len); 311 312 if (ntf.rf_tech_specific_params_len > 0) { 313 switch (ntf.rf_tech_and_mode) { 314 case NCI_NFC_A_PASSIVE_POLL_MODE: 315 data = nci_extract_rf_params_nfca_passive_poll(ndev, 316 &(ntf.rf_tech_specific_params.nfca_poll), data); 317 break; 318 319 case NCI_NFC_B_PASSIVE_POLL_MODE: 320 data = nci_extract_rf_params_nfcb_passive_poll(ndev, 321 &(ntf.rf_tech_specific_params.nfcb_poll), data); 322 break; 323 324 case NCI_NFC_F_PASSIVE_POLL_MODE: 325 data = nci_extract_rf_params_nfcf_passive_poll(ndev, 326 &(ntf.rf_tech_specific_params.nfcf_poll), data); 327 break; 328 329 case NCI_NFC_V_PASSIVE_POLL_MODE: 330 data = nci_extract_rf_params_nfcv_passive_poll(ndev, 331 &(ntf.rf_tech_specific_params.nfcv_poll), data); 332 break; 333 334 default: 335 pr_err("unsupported rf_tech_and_mode 0x%x\n", 336 ntf.rf_tech_and_mode); 337 data += ntf.rf_tech_specific_params_len; 338 add_target = false; 339 } 340 } 341 342 ntf.ntf_type = *data++; 343 pr_debug("ntf_type %d\n", ntf.ntf_type); 344 345 if (add_target == true) 346 nci_add_new_target(ndev, &ntf); 347 348 if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) { 349 atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES); 350 } else { 351 atomic_set(&ndev->state, NCI_W4_HOST_SELECT); 352 nfc_targets_found(ndev->nfc_dev, ndev->targets, 353 ndev->n_targets); 354 } 355 } 356 357 static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev, 358 struct nci_rf_intf_activated_ntf *ntf, __u8 *data) 359 { 360 struct activation_params_nfca_poll_iso_dep *nfca_poll; 361 struct activation_params_nfcb_poll_iso_dep *nfcb_poll; 362 363 switch (ntf->activation_rf_tech_and_mode) { 364 case NCI_NFC_A_PASSIVE_POLL_MODE: 365 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep; 366 nfca_poll->rats_res_len = min_t(__u8, *data++, 20); 367 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len); 368 if (nfca_poll->rats_res_len > 0) { 369 memcpy(nfca_poll->rats_res, 370 data, nfca_poll->rats_res_len); 371 } 372 break; 373 374 case NCI_NFC_B_PASSIVE_POLL_MODE: 375 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep; 376 nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50); 377 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len); 378 if (nfcb_poll->attrib_res_len > 0) { 379 memcpy(nfcb_poll->attrib_res, 380 data, nfcb_poll->attrib_res_len); 381 } 382 break; 383 384 default: 385 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", 386 ntf->activation_rf_tech_and_mode); 387 return NCI_STATUS_RF_PROTOCOL_ERROR; 388 } 389 390 return NCI_STATUS_OK; 391 } 392 393 static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev, 394 struct nci_rf_intf_activated_ntf *ntf, __u8 *data) 395 { 396 struct activation_params_poll_nfc_dep *poll; 397 398 switch (ntf->activation_rf_tech_and_mode) { 399 case NCI_NFC_A_PASSIVE_POLL_MODE: 400 case NCI_NFC_F_PASSIVE_POLL_MODE: 401 poll = &ntf->activation_params.poll_nfc_dep; 402 poll->atr_res_len = min_t(__u8, *data++, 63); 403 pr_debug("atr_res_len %d\n", poll->atr_res_len); 404 if (poll->atr_res_len > 0) 405 memcpy(poll->atr_res, data, poll->atr_res_len); 406 break; 407 408 default: 409 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", 410 ntf->activation_rf_tech_and_mode); 411 return NCI_STATUS_RF_PROTOCOL_ERROR; 412 } 413 414 return NCI_STATUS_OK; 415 } 416 417 static void nci_target_auto_activated(struct nci_dev *ndev, 418 struct nci_rf_intf_activated_ntf *ntf) 419 { 420 struct nfc_target *target; 421 int rc; 422 423 target = &ndev->targets[ndev->n_targets]; 424 425 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol, 426 ntf->activation_rf_tech_and_mode, 427 &ntf->rf_tech_specific_params); 428 if (rc) 429 return; 430 431 target->logical_idx = ntf->rf_discovery_id; 432 ndev->n_targets++; 433 434 pr_debug("logical idx %d, n_targets %d\n", 435 target->logical_idx, ndev->n_targets); 436 437 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); 438 } 439 440 static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev, 441 struct sk_buff *skb) 442 { 443 struct nci_rf_intf_activated_ntf ntf; 444 __u8 *data = skb->data; 445 int err = NCI_STATUS_OK; 446 447 ntf.rf_discovery_id = *data++; 448 ntf.rf_interface = *data++; 449 ntf.rf_protocol = *data++; 450 ntf.activation_rf_tech_and_mode = *data++; 451 ntf.max_data_pkt_payload_size = *data++; 452 ntf.initial_num_credits = *data++; 453 ntf.rf_tech_specific_params_len = *data++; 454 455 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id); 456 pr_debug("rf_interface 0x%x\n", ntf.rf_interface); 457 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol); 458 pr_debug("activation_rf_tech_and_mode 0x%x\n", 459 ntf.activation_rf_tech_and_mode); 460 pr_debug("max_data_pkt_payload_size 0x%x\n", 461 ntf.max_data_pkt_payload_size); 462 pr_debug("initial_num_credits 0x%x\n", 463 ntf.initial_num_credits); 464 pr_debug("rf_tech_specific_params_len %d\n", 465 ntf.rf_tech_specific_params_len); 466 467 if (ntf.rf_tech_specific_params_len > 0) { 468 switch (ntf.activation_rf_tech_and_mode) { 469 case NCI_NFC_A_PASSIVE_POLL_MODE: 470 data = nci_extract_rf_params_nfca_passive_poll(ndev, 471 &(ntf.rf_tech_specific_params.nfca_poll), data); 472 break; 473 474 case NCI_NFC_B_PASSIVE_POLL_MODE: 475 data = nci_extract_rf_params_nfcb_passive_poll(ndev, 476 &(ntf.rf_tech_specific_params.nfcb_poll), data); 477 break; 478 479 case NCI_NFC_F_PASSIVE_POLL_MODE: 480 data = nci_extract_rf_params_nfcf_passive_poll(ndev, 481 &(ntf.rf_tech_specific_params.nfcf_poll), data); 482 break; 483 484 case NCI_NFC_V_PASSIVE_POLL_MODE: 485 data = nci_extract_rf_params_nfcv_passive_poll(ndev, 486 &(ntf.rf_tech_specific_params.nfcv_poll), data); 487 break; 488 489 default: 490 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", 491 ntf.activation_rf_tech_and_mode); 492 err = NCI_STATUS_RF_PROTOCOL_ERROR; 493 goto exit; 494 } 495 } 496 497 ntf.data_exch_rf_tech_and_mode = *data++; 498 ntf.data_exch_tx_bit_rate = *data++; 499 ntf.data_exch_rx_bit_rate = *data++; 500 ntf.activation_params_len = *data++; 501 502 pr_debug("data_exch_rf_tech_and_mode 0x%x\n", 503 ntf.data_exch_rf_tech_and_mode); 504 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf.data_exch_tx_bit_rate); 505 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf.data_exch_rx_bit_rate); 506 pr_debug("activation_params_len %d\n", ntf.activation_params_len); 507 508 if (ntf.activation_params_len > 0) { 509 switch (ntf.rf_interface) { 510 case NCI_RF_INTERFACE_ISO_DEP: 511 err = nci_extract_activation_params_iso_dep(ndev, 512 &ntf, data); 513 break; 514 515 case NCI_RF_INTERFACE_NFC_DEP: 516 err = nci_extract_activation_params_nfc_dep(ndev, 517 &ntf, data); 518 break; 519 520 case NCI_RF_INTERFACE_FRAME: 521 /* no activation params */ 522 break; 523 524 default: 525 pr_err("unsupported rf_interface 0x%x\n", 526 ntf.rf_interface); 527 err = NCI_STATUS_RF_PROTOCOL_ERROR; 528 break; 529 } 530 } 531 532 exit: 533 if (err == NCI_STATUS_OK) { 534 ndev->max_data_pkt_payload_size = ntf.max_data_pkt_payload_size; 535 ndev->initial_num_credits = ntf.initial_num_credits; 536 537 /* set the available credits to initial value */ 538 atomic_set(&ndev->credits_cnt, ndev->initial_num_credits); 539 540 /* store general bytes to be reported later in dep_link_up */ 541 if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) { 542 ndev->remote_gb_len = 0; 543 544 if (ntf.activation_params_len > 0) { 545 /* ATR_RES general bytes at offset 15 */ 546 ndev->remote_gb_len = min_t(__u8, 547 (ntf.activation_params 548 .poll_nfc_dep.atr_res_len 549 - NFC_ATR_RES_GT_OFFSET), 550 NFC_MAX_GT_LEN); 551 memcpy(ndev->remote_gb, 552 (ntf.activation_params.poll_nfc_dep 553 .atr_res + NFC_ATR_RES_GT_OFFSET), 554 ndev->remote_gb_len); 555 } 556 } 557 } 558 559 if (atomic_read(&ndev->state) == NCI_DISCOVERY) { 560 /* A single target was found and activated automatically */ 561 atomic_set(&ndev->state, NCI_POLL_ACTIVE); 562 if (err == NCI_STATUS_OK) 563 nci_target_auto_activated(ndev, &ntf); 564 } else { /* ndev->state == NCI_W4_HOST_SELECT */ 565 /* A selected target was activated, so complete the request */ 566 atomic_set(&ndev->state, NCI_POLL_ACTIVE); 567 nci_req_complete(ndev, err); 568 } 569 } 570 571 static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev, 572 struct sk_buff *skb) 573 { 574 struct nci_rf_deactivate_ntf *ntf = (void *) skb->data; 575 576 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason); 577 578 /* drop tx data queue */ 579 skb_queue_purge(&ndev->tx_q); 580 581 /* drop partial rx data packet */ 582 if (ndev->rx_data_reassembly) { 583 kfree_skb(ndev->rx_data_reassembly); 584 ndev->rx_data_reassembly = NULL; 585 } 586 587 /* complete the data exchange transaction, if exists */ 588 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) 589 nci_data_exchange_complete(ndev, NULL, -EIO); 590 591 nci_clear_target_list(ndev); 592 atomic_set(&ndev->state, NCI_IDLE); 593 nci_req_complete(ndev, NCI_STATUS_OK); 594 } 595 596 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb) 597 { 598 __u16 ntf_opcode = nci_opcode(skb->data); 599 600 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n", 601 nci_pbf(skb->data), 602 nci_opcode_gid(ntf_opcode), 603 nci_opcode_oid(ntf_opcode), 604 nci_plen(skb->data)); 605 606 /* strip the nci control header */ 607 skb_pull(skb, NCI_CTRL_HDR_SIZE); 608 609 switch (ntf_opcode) { 610 case NCI_OP_CORE_CONN_CREDITS_NTF: 611 nci_core_conn_credits_ntf_packet(ndev, skb); 612 break; 613 614 case NCI_OP_CORE_GENERIC_ERROR_NTF: 615 nci_core_generic_error_ntf_packet(ndev, skb); 616 break; 617 618 case NCI_OP_CORE_INTF_ERROR_NTF: 619 nci_core_conn_intf_error_ntf_packet(ndev, skb); 620 break; 621 622 case NCI_OP_RF_DISCOVER_NTF: 623 nci_rf_discover_ntf_packet(ndev, skb); 624 break; 625 626 case NCI_OP_RF_INTF_ACTIVATED_NTF: 627 nci_rf_intf_activated_ntf_packet(ndev, skb); 628 break; 629 630 case NCI_OP_RF_DEACTIVATE_NTF: 631 nci_rf_deactivate_ntf_packet(ndev, skb); 632 break; 633 634 default: 635 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode); 636 break; 637 } 638 639 kfree_skb(skb); 640 } 641