0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
0017
0018 #include <linux/types.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/bitops.h>
0021 #include <linux/skbuff.h>
0022
0023 #include "../nfc.h"
0024 #include <net/nfc/nci.h>
0025 #include <net/nfc/nci_core.h>
0026 #include <linux/nfc.h>
0027
0028
0029
0030 static void nci_core_reset_ntf_packet(struct nci_dev *ndev,
0031 const struct sk_buff *skb)
0032 {
0033
0034 const struct nci_core_reset_ntf *ntf = (void *)skb->data;
0035
0036 ndev->nci_ver = ntf->nci_ver;
0037 pr_debug("nci_ver 0x%x, config_status 0x%x\n",
0038 ntf->nci_ver, ntf->config_status);
0039
0040 ndev->manufact_id = ntf->manufact_id;
0041 ndev->manufact_specific_info =
0042 __le32_to_cpu(ntf->manufact_specific_info);
0043
0044 nci_req_complete(ndev, NCI_STATUS_OK);
0045 }
0046
0047 static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
0048 struct sk_buff *skb)
0049 {
0050 struct nci_core_conn_credit_ntf *ntf = (void *) skb->data;
0051 struct nci_conn_info *conn_info;
0052 int i;
0053
0054 pr_debug("num_entries %d\n", ntf->num_entries);
0055
0056 if (ntf->num_entries > NCI_MAX_NUM_CONN)
0057 ntf->num_entries = NCI_MAX_NUM_CONN;
0058
0059
0060 for (i = 0; i < ntf->num_entries; i++) {
0061 ntf->conn_entries[i].conn_id =
0062 nci_conn_id(&ntf->conn_entries[i].conn_id);
0063
0064 pr_debug("entry[%d]: conn_id %d, credits %d\n",
0065 i, ntf->conn_entries[i].conn_id,
0066 ntf->conn_entries[i].credits);
0067
0068 conn_info = nci_get_conn_info_by_conn_id(ndev,
0069 ntf->conn_entries[i].conn_id);
0070 if (!conn_info)
0071 return;
0072
0073 atomic_add(ntf->conn_entries[i].credits,
0074 &conn_info->credits_cnt);
0075 }
0076
0077
0078 if (!skb_queue_empty(&ndev->tx_q))
0079 queue_work(ndev->tx_wq, &ndev->tx_work);
0080 }
0081
0082 static void nci_core_generic_error_ntf_packet(struct nci_dev *ndev,
0083 const struct sk_buff *skb)
0084 {
0085 __u8 status = skb->data[0];
0086
0087 pr_debug("status 0x%x\n", status);
0088
0089 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
0090
0091
0092 nci_req_complete(ndev, status);
0093 }
0094 }
0095
0096 static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
0097 struct sk_buff *skb)
0098 {
0099 struct nci_core_intf_error_ntf *ntf = (void *) skb->data;
0100
0101 ntf->conn_id = nci_conn_id(&ntf->conn_id);
0102
0103 pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id);
0104
0105
0106 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
0107 nci_data_exchange_complete(ndev, NULL, ntf->conn_id, -EIO);
0108 }
0109
0110 static const __u8 *
0111 nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
0112 struct rf_tech_specific_params_nfca_poll *nfca_poll,
0113 const __u8 *data)
0114 {
0115 nfca_poll->sens_res = __le16_to_cpu(*((__le16 *)data));
0116 data += 2;
0117
0118 nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE);
0119
0120 pr_debug("sens_res 0x%x, nfcid1_len %d\n",
0121 nfca_poll->sens_res, nfca_poll->nfcid1_len);
0122
0123 memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len);
0124 data += nfca_poll->nfcid1_len;
0125
0126 nfca_poll->sel_res_len = *data++;
0127
0128 if (nfca_poll->sel_res_len != 0)
0129 nfca_poll->sel_res = *data++;
0130
0131 pr_debug("sel_res_len %d, sel_res 0x%x\n",
0132 nfca_poll->sel_res_len,
0133 nfca_poll->sel_res);
0134
0135 return data;
0136 }
0137
0138 static const __u8 *
0139 nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev,
0140 struct rf_tech_specific_params_nfcb_poll *nfcb_poll,
0141 const __u8 *data)
0142 {
0143 nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE);
0144
0145 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len);
0146
0147 memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len);
0148 data += nfcb_poll->sensb_res_len;
0149
0150 return data;
0151 }
0152
0153 static const __u8 *
0154 nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev,
0155 struct rf_tech_specific_params_nfcf_poll *nfcf_poll,
0156 const __u8 *data)
0157 {
0158 nfcf_poll->bit_rate = *data++;
0159 nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE);
0160
0161 pr_debug("bit_rate %d, sensf_res_len %d\n",
0162 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len);
0163
0164 memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len);
0165 data += nfcf_poll->sensf_res_len;
0166
0167 return data;
0168 }
0169
0170 static const __u8 *
0171 nci_extract_rf_params_nfcv_passive_poll(struct nci_dev *ndev,
0172 struct rf_tech_specific_params_nfcv_poll *nfcv_poll,
0173 const __u8 *data)
0174 {
0175 ++data;
0176 nfcv_poll->dsfid = *data++;
0177 memcpy(nfcv_poll->uid, data, NFC_ISO15693_UID_MAXSIZE);
0178 data += NFC_ISO15693_UID_MAXSIZE;
0179 return data;
0180 }
0181
0182 static const __u8 *
0183 nci_extract_rf_params_nfcf_passive_listen(struct nci_dev *ndev,
0184 struct rf_tech_specific_params_nfcf_listen *nfcf_listen,
0185 const __u8 *data)
0186 {
0187 nfcf_listen->local_nfcid2_len = min_t(__u8, *data++,
0188 NFC_NFCID2_MAXSIZE);
0189 memcpy(nfcf_listen->local_nfcid2, data, nfcf_listen->local_nfcid2_len);
0190 data += nfcf_listen->local_nfcid2_len;
0191
0192 return data;
0193 }
0194
0195 static __u32 nci_get_prop_rf_protocol(struct nci_dev *ndev, __u8 rf_protocol)
0196 {
0197 if (ndev->ops->get_rfprotocol)
0198 return ndev->ops->get_rfprotocol(ndev, rf_protocol);
0199 return 0;
0200 }
0201
0202 static int nci_add_new_protocol(struct nci_dev *ndev,
0203 struct nfc_target *target,
0204 __u8 rf_protocol,
0205 __u8 rf_tech_and_mode,
0206 const void *params)
0207 {
0208 const struct rf_tech_specific_params_nfca_poll *nfca_poll;
0209 const struct rf_tech_specific_params_nfcb_poll *nfcb_poll;
0210 const struct rf_tech_specific_params_nfcf_poll *nfcf_poll;
0211 const struct rf_tech_specific_params_nfcv_poll *nfcv_poll;
0212 __u32 protocol;
0213
0214 if (rf_protocol == NCI_RF_PROTOCOL_T1T)
0215 protocol = NFC_PROTO_JEWEL_MASK;
0216 else if (rf_protocol == NCI_RF_PROTOCOL_T2T)
0217 protocol = NFC_PROTO_MIFARE_MASK;
0218 else if (rf_protocol == NCI_RF_PROTOCOL_ISO_DEP)
0219 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE)
0220 protocol = NFC_PROTO_ISO14443_MASK;
0221 else
0222 protocol = NFC_PROTO_ISO14443_B_MASK;
0223 else if (rf_protocol == NCI_RF_PROTOCOL_T3T)
0224 protocol = NFC_PROTO_FELICA_MASK;
0225 else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP)
0226 protocol = NFC_PROTO_NFC_DEP_MASK;
0227 else if (rf_protocol == NCI_RF_PROTOCOL_T5T)
0228 protocol = NFC_PROTO_ISO15693_MASK;
0229 else
0230 protocol = nci_get_prop_rf_protocol(ndev, rf_protocol);
0231
0232 if (!(protocol & ndev->poll_prots)) {
0233 pr_err("the target found does not have the desired protocol\n");
0234 return -EPROTO;
0235 }
0236
0237 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) {
0238 nfca_poll = (struct rf_tech_specific_params_nfca_poll *)params;
0239
0240 target->sens_res = nfca_poll->sens_res;
0241 target->sel_res = nfca_poll->sel_res;
0242 target->nfcid1_len = nfca_poll->nfcid1_len;
0243 if (target->nfcid1_len > 0) {
0244 memcpy(target->nfcid1, nfca_poll->nfcid1,
0245 target->nfcid1_len);
0246 }
0247 } else if (rf_tech_and_mode == NCI_NFC_B_PASSIVE_POLL_MODE) {
0248 nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params;
0249
0250 target->sensb_res_len = nfcb_poll->sensb_res_len;
0251 if (target->sensb_res_len > 0) {
0252 memcpy(target->sensb_res, nfcb_poll->sensb_res,
0253 target->sensb_res_len);
0254 }
0255 } else if (rf_tech_and_mode == NCI_NFC_F_PASSIVE_POLL_MODE) {
0256 nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params;
0257
0258 target->sensf_res_len = nfcf_poll->sensf_res_len;
0259 if (target->sensf_res_len > 0) {
0260 memcpy(target->sensf_res, nfcf_poll->sensf_res,
0261 target->sensf_res_len);
0262 }
0263 } else if (rf_tech_and_mode == NCI_NFC_V_PASSIVE_POLL_MODE) {
0264 nfcv_poll = (struct rf_tech_specific_params_nfcv_poll *)params;
0265
0266 target->is_iso15693 = 1;
0267 target->iso15693_dsfid = nfcv_poll->dsfid;
0268 memcpy(target->iso15693_uid, nfcv_poll->uid, NFC_ISO15693_UID_MAXSIZE);
0269 } else {
0270 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode);
0271 return -EPROTO;
0272 }
0273
0274 target->supported_protocols |= protocol;
0275
0276 pr_debug("protocol 0x%x\n", protocol);
0277
0278 return 0;
0279 }
0280
0281 static void nci_add_new_target(struct nci_dev *ndev,
0282 const struct nci_rf_discover_ntf *ntf)
0283 {
0284 struct nfc_target *target;
0285 int i, rc;
0286
0287 for (i = 0; i < ndev->n_targets; i++) {
0288 target = &ndev->targets[i];
0289 if (target->logical_idx == ntf->rf_discovery_id) {
0290
0291 nci_add_new_protocol(ndev, target, ntf->rf_protocol,
0292 ntf->rf_tech_and_mode,
0293 &ntf->rf_tech_specific_params);
0294 return;
0295 }
0296 }
0297
0298
0299 if (ndev->n_targets == NCI_MAX_DISCOVERED_TARGETS) {
0300 pr_debug("not enough room, ignoring new target...\n");
0301 return;
0302 }
0303
0304 target = &ndev->targets[ndev->n_targets];
0305
0306 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
0307 ntf->rf_tech_and_mode,
0308 &ntf->rf_tech_specific_params);
0309 if (!rc) {
0310 target->logical_idx = ntf->rf_discovery_id;
0311 ndev->n_targets++;
0312
0313 pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
0314 ndev->n_targets);
0315 }
0316 }
0317
0318 void nci_clear_target_list(struct nci_dev *ndev)
0319 {
0320 memset(ndev->targets, 0,
0321 (sizeof(struct nfc_target)*NCI_MAX_DISCOVERED_TARGETS));
0322
0323 ndev->n_targets = 0;
0324 }
0325
0326 static void nci_rf_discover_ntf_packet(struct nci_dev *ndev,
0327 const struct sk_buff *skb)
0328 {
0329 struct nci_rf_discover_ntf ntf;
0330 const __u8 *data = skb->data;
0331 bool add_target = true;
0332
0333 ntf.rf_discovery_id = *data++;
0334 ntf.rf_protocol = *data++;
0335 ntf.rf_tech_and_mode = *data++;
0336 ntf.rf_tech_specific_params_len = *data++;
0337
0338 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
0339 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
0340 pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode);
0341 pr_debug("rf_tech_specific_params_len %d\n",
0342 ntf.rf_tech_specific_params_len);
0343
0344 if (ntf.rf_tech_specific_params_len > 0) {
0345 switch (ntf.rf_tech_and_mode) {
0346 case NCI_NFC_A_PASSIVE_POLL_MODE:
0347 data = nci_extract_rf_params_nfca_passive_poll(ndev,
0348 &(ntf.rf_tech_specific_params.nfca_poll), data);
0349 break;
0350
0351 case NCI_NFC_B_PASSIVE_POLL_MODE:
0352 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
0353 &(ntf.rf_tech_specific_params.nfcb_poll), data);
0354 break;
0355
0356 case NCI_NFC_F_PASSIVE_POLL_MODE:
0357 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
0358 &(ntf.rf_tech_specific_params.nfcf_poll), data);
0359 break;
0360
0361 case NCI_NFC_V_PASSIVE_POLL_MODE:
0362 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
0363 &(ntf.rf_tech_specific_params.nfcv_poll), data);
0364 break;
0365
0366 default:
0367 pr_err("unsupported rf_tech_and_mode 0x%x\n",
0368 ntf.rf_tech_and_mode);
0369 data += ntf.rf_tech_specific_params_len;
0370 add_target = false;
0371 }
0372 }
0373
0374 ntf.ntf_type = *data++;
0375 pr_debug("ntf_type %d\n", ntf.ntf_type);
0376
0377 if (add_target == true)
0378 nci_add_new_target(ndev, &ntf);
0379
0380 if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) {
0381 atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES);
0382 } else {
0383 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
0384 nfc_targets_found(ndev->nfc_dev, ndev->targets,
0385 ndev->n_targets);
0386 }
0387 }
0388
0389 static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
0390 struct nci_rf_intf_activated_ntf *ntf,
0391 const __u8 *data)
0392 {
0393 struct activation_params_nfca_poll_iso_dep *nfca_poll;
0394 struct activation_params_nfcb_poll_iso_dep *nfcb_poll;
0395
0396 switch (ntf->activation_rf_tech_and_mode) {
0397 case NCI_NFC_A_PASSIVE_POLL_MODE:
0398 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep;
0399 nfca_poll->rats_res_len = min_t(__u8, *data++, 20);
0400 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len);
0401 if (nfca_poll->rats_res_len > 0) {
0402 memcpy(nfca_poll->rats_res,
0403 data, nfca_poll->rats_res_len);
0404 }
0405 break;
0406
0407 case NCI_NFC_B_PASSIVE_POLL_MODE:
0408 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep;
0409 nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50);
0410 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len);
0411 if (nfcb_poll->attrib_res_len > 0) {
0412 memcpy(nfcb_poll->attrib_res,
0413 data, nfcb_poll->attrib_res_len);
0414 }
0415 break;
0416
0417 default:
0418 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
0419 ntf->activation_rf_tech_and_mode);
0420 return NCI_STATUS_RF_PROTOCOL_ERROR;
0421 }
0422
0423 return NCI_STATUS_OK;
0424 }
0425
0426 static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev,
0427 struct nci_rf_intf_activated_ntf *ntf,
0428 const __u8 *data)
0429 {
0430 struct activation_params_poll_nfc_dep *poll;
0431 struct activation_params_listen_nfc_dep *listen;
0432
0433 switch (ntf->activation_rf_tech_and_mode) {
0434 case NCI_NFC_A_PASSIVE_POLL_MODE:
0435 case NCI_NFC_F_PASSIVE_POLL_MODE:
0436 poll = &ntf->activation_params.poll_nfc_dep;
0437 poll->atr_res_len = min_t(__u8, *data++,
0438 NFC_ATR_RES_MAXSIZE - 2);
0439 pr_debug("atr_res_len %d\n", poll->atr_res_len);
0440 if (poll->atr_res_len > 0)
0441 memcpy(poll->atr_res, data, poll->atr_res_len);
0442 break;
0443
0444 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
0445 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
0446 listen = &ntf->activation_params.listen_nfc_dep;
0447 listen->atr_req_len = min_t(__u8, *data++,
0448 NFC_ATR_REQ_MAXSIZE - 2);
0449 pr_debug("atr_req_len %d\n", listen->atr_req_len);
0450 if (listen->atr_req_len > 0)
0451 memcpy(listen->atr_req, data, listen->atr_req_len);
0452 break;
0453
0454 default:
0455 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
0456 ntf->activation_rf_tech_and_mode);
0457 return NCI_STATUS_RF_PROTOCOL_ERROR;
0458 }
0459
0460 return NCI_STATUS_OK;
0461 }
0462
0463 static void nci_target_auto_activated(struct nci_dev *ndev,
0464 const struct nci_rf_intf_activated_ntf *ntf)
0465 {
0466 struct nfc_target *target;
0467 int rc;
0468
0469 target = &ndev->targets[ndev->n_targets];
0470
0471 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
0472 ntf->activation_rf_tech_and_mode,
0473 &ntf->rf_tech_specific_params);
0474 if (rc)
0475 return;
0476
0477 target->logical_idx = ntf->rf_discovery_id;
0478 ndev->n_targets++;
0479
0480 pr_debug("logical idx %d, n_targets %d\n",
0481 target->logical_idx, ndev->n_targets);
0482
0483 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
0484 }
0485
0486 static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
0487 const struct nci_rf_intf_activated_ntf *ntf)
0488 {
0489 ndev->remote_gb_len = 0;
0490
0491 if (ntf->activation_params_len <= 0)
0492 return NCI_STATUS_OK;
0493
0494 switch (ntf->activation_rf_tech_and_mode) {
0495 case NCI_NFC_A_PASSIVE_POLL_MODE:
0496 case NCI_NFC_F_PASSIVE_POLL_MODE:
0497 ndev->remote_gb_len = min_t(__u8,
0498 (ntf->activation_params.poll_nfc_dep.atr_res_len
0499 - NFC_ATR_RES_GT_OFFSET),
0500 NFC_ATR_RES_GB_MAXSIZE);
0501 memcpy(ndev->remote_gb,
0502 (ntf->activation_params.poll_nfc_dep.atr_res
0503 + NFC_ATR_RES_GT_OFFSET),
0504 ndev->remote_gb_len);
0505 break;
0506
0507 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
0508 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
0509 ndev->remote_gb_len = min_t(__u8,
0510 (ntf->activation_params.listen_nfc_dep.atr_req_len
0511 - NFC_ATR_REQ_GT_OFFSET),
0512 NFC_ATR_REQ_GB_MAXSIZE);
0513 memcpy(ndev->remote_gb,
0514 (ntf->activation_params.listen_nfc_dep.atr_req
0515 + NFC_ATR_REQ_GT_OFFSET),
0516 ndev->remote_gb_len);
0517 break;
0518
0519 default:
0520 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
0521 ntf->activation_rf_tech_and_mode);
0522 return NCI_STATUS_RF_PROTOCOL_ERROR;
0523 }
0524
0525 return NCI_STATUS_OK;
0526 }
0527
0528 static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
0529 const struct sk_buff *skb)
0530 {
0531 struct nci_conn_info *conn_info;
0532 struct nci_rf_intf_activated_ntf ntf;
0533 const __u8 *data = skb->data;
0534 int err = NCI_STATUS_OK;
0535
0536 ntf.rf_discovery_id = *data++;
0537 ntf.rf_interface = *data++;
0538 ntf.rf_protocol = *data++;
0539 ntf.activation_rf_tech_and_mode = *data++;
0540 ntf.max_data_pkt_payload_size = *data++;
0541 ntf.initial_num_credits = *data++;
0542 ntf.rf_tech_specific_params_len = *data++;
0543
0544 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
0545 pr_debug("rf_interface 0x%x\n", ntf.rf_interface);
0546 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
0547 pr_debug("activation_rf_tech_and_mode 0x%x\n",
0548 ntf.activation_rf_tech_and_mode);
0549 pr_debug("max_data_pkt_payload_size 0x%x\n",
0550 ntf.max_data_pkt_payload_size);
0551 pr_debug("initial_num_credits 0x%x\n",
0552 ntf.initial_num_credits);
0553 pr_debug("rf_tech_specific_params_len %d\n",
0554 ntf.rf_tech_specific_params_len);
0555
0556
0557
0558
0559
0560 if (ntf.rf_interface == NCI_RF_INTERFACE_NFCEE_DIRECT)
0561 goto listen;
0562
0563 if (ntf.rf_tech_specific_params_len > 0) {
0564 switch (ntf.activation_rf_tech_and_mode) {
0565 case NCI_NFC_A_PASSIVE_POLL_MODE:
0566 data = nci_extract_rf_params_nfca_passive_poll(ndev,
0567 &(ntf.rf_tech_specific_params.nfca_poll), data);
0568 break;
0569
0570 case NCI_NFC_B_PASSIVE_POLL_MODE:
0571 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
0572 &(ntf.rf_tech_specific_params.nfcb_poll), data);
0573 break;
0574
0575 case NCI_NFC_F_PASSIVE_POLL_MODE:
0576 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
0577 &(ntf.rf_tech_specific_params.nfcf_poll), data);
0578 break;
0579
0580 case NCI_NFC_V_PASSIVE_POLL_MODE:
0581 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
0582 &(ntf.rf_tech_specific_params.nfcv_poll), data);
0583 break;
0584
0585 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
0586
0587 break;
0588
0589 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
0590 data = nci_extract_rf_params_nfcf_passive_listen(ndev,
0591 &(ntf.rf_tech_specific_params.nfcf_listen),
0592 data);
0593 break;
0594
0595 default:
0596 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
0597 ntf.activation_rf_tech_and_mode);
0598 err = NCI_STATUS_RF_PROTOCOL_ERROR;
0599 goto exit;
0600 }
0601 }
0602
0603 ntf.data_exch_rf_tech_and_mode = *data++;
0604 ntf.data_exch_tx_bit_rate = *data++;
0605 ntf.data_exch_rx_bit_rate = *data++;
0606 ntf.activation_params_len = *data++;
0607
0608 pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
0609 ntf.data_exch_rf_tech_and_mode);
0610 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf.data_exch_tx_bit_rate);
0611 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf.data_exch_rx_bit_rate);
0612 pr_debug("activation_params_len %d\n", ntf.activation_params_len);
0613
0614 if (ntf.activation_params_len > 0) {
0615 switch (ntf.rf_interface) {
0616 case NCI_RF_INTERFACE_ISO_DEP:
0617 err = nci_extract_activation_params_iso_dep(ndev,
0618 &ntf, data);
0619 break;
0620
0621 case NCI_RF_INTERFACE_NFC_DEP:
0622 err = nci_extract_activation_params_nfc_dep(ndev,
0623 &ntf, data);
0624 break;
0625
0626 case NCI_RF_INTERFACE_FRAME:
0627
0628 break;
0629
0630 default:
0631 pr_err("unsupported rf_interface 0x%x\n",
0632 ntf.rf_interface);
0633 err = NCI_STATUS_RF_PROTOCOL_ERROR;
0634 break;
0635 }
0636 }
0637
0638 exit:
0639 if (err == NCI_STATUS_OK) {
0640 conn_info = ndev->rf_conn_info;
0641 if (!conn_info)
0642 return;
0643
0644 conn_info->max_pkt_payload_len = ntf.max_data_pkt_payload_size;
0645 conn_info->initial_num_credits = ntf.initial_num_credits;
0646
0647
0648 atomic_set(&conn_info->credits_cnt,
0649 conn_info->initial_num_credits);
0650
0651
0652 if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
0653 err = nci_store_general_bytes_nfc_dep(ndev, &ntf);
0654 if (err != NCI_STATUS_OK)
0655 pr_err("unable to store general bytes\n");
0656 }
0657 }
0658
0659 if (!(ntf.activation_rf_tech_and_mode & NCI_RF_TECH_MODE_LISTEN_MASK)) {
0660
0661 if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
0662
0663
0664 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
0665 if (err == NCI_STATUS_OK)
0666 nci_target_auto_activated(ndev, &ntf);
0667 } else {
0668
0669
0670 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
0671 nci_req_complete(ndev, err);
0672 }
0673 } else {
0674 listen:
0675
0676 atomic_set(&ndev->state, NCI_LISTEN_ACTIVE);
0677 if (err == NCI_STATUS_OK &&
0678 ntf.rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) {
0679 err = nfc_tm_activated(ndev->nfc_dev,
0680 NFC_PROTO_NFC_DEP_MASK,
0681 NFC_COMM_PASSIVE,
0682 ndev->remote_gb,
0683 ndev->remote_gb_len);
0684 if (err != NCI_STATUS_OK)
0685 pr_err("error when signaling tm activation\n");
0686 }
0687 }
0688 }
0689
0690 static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
0691 const struct sk_buff *skb)
0692 {
0693 const struct nci_conn_info *conn_info;
0694 const struct nci_rf_deactivate_ntf *ntf = (void *)skb->data;
0695
0696 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
0697
0698 conn_info = ndev->rf_conn_info;
0699 if (!conn_info)
0700 return;
0701
0702
0703 skb_queue_purge(&ndev->tx_q);
0704
0705
0706 if (ndev->rx_data_reassembly) {
0707 kfree_skb(ndev->rx_data_reassembly);
0708 ndev->rx_data_reassembly = NULL;
0709 }
0710
0711
0712 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
0713 nci_data_exchange_complete(ndev, NULL, NCI_STATIC_RF_CONN_ID,
0714 -EIO);
0715
0716 switch (ntf->type) {
0717 case NCI_DEACTIVATE_TYPE_IDLE_MODE:
0718 nci_clear_target_list(ndev);
0719 atomic_set(&ndev->state, NCI_IDLE);
0720 break;
0721 case NCI_DEACTIVATE_TYPE_SLEEP_MODE:
0722 case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE:
0723 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
0724 break;
0725 case NCI_DEACTIVATE_TYPE_DISCOVERY:
0726 nci_clear_target_list(ndev);
0727 atomic_set(&ndev->state, NCI_DISCOVERY);
0728 break;
0729 }
0730
0731 nci_req_complete(ndev, NCI_STATUS_OK);
0732 }
0733
0734 static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
0735 const struct sk_buff *skb)
0736 {
0737 u8 status = NCI_STATUS_OK;
0738 const struct nci_nfcee_discover_ntf *nfcee_ntf =
0739 (struct nci_nfcee_discover_ntf *)skb->data;
0740
0741
0742
0743
0744
0745
0746 ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id;
0747 ndev->cur_params.id = nfcee_ntf->nfcee_id;
0748
0749 nci_req_complete(ndev, status);
0750 }
0751
0752 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
0753 {
0754 __u16 ntf_opcode = nci_opcode(skb->data);
0755
0756 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
0757 nci_pbf(skb->data),
0758 nci_opcode_gid(ntf_opcode),
0759 nci_opcode_oid(ntf_opcode),
0760 nci_plen(skb->data));
0761
0762
0763 skb_pull(skb, NCI_CTRL_HDR_SIZE);
0764
0765 if (nci_opcode_gid(ntf_opcode) == NCI_GID_PROPRIETARY) {
0766 if (nci_prop_ntf_packet(ndev, ntf_opcode, skb) == -ENOTSUPP) {
0767 pr_err("unsupported ntf opcode 0x%x\n",
0768 ntf_opcode);
0769 }
0770
0771 goto end;
0772 }
0773
0774 switch (ntf_opcode) {
0775 case NCI_OP_CORE_RESET_NTF:
0776 nci_core_reset_ntf_packet(ndev, skb);
0777 break;
0778
0779 case NCI_OP_CORE_CONN_CREDITS_NTF:
0780 nci_core_conn_credits_ntf_packet(ndev, skb);
0781 break;
0782
0783 case NCI_OP_CORE_GENERIC_ERROR_NTF:
0784 nci_core_generic_error_ntf_packet(ndev, skb);
0785 break;
0786
0787 case NCI_OP_CORE_INTF_ERROR_NTF:
0788 nci_core_conn_intf_error_ntf_packet(ndev, skb);
0789 break;
0790
0791 case NCI_OP_RF_DISCOVER_NTF:
0792 nci_rf_discover_ntf_packet(ndev, skb);
0793 break;
0794
0795 case NCI_OP_RF_INTF_ACTIVATED_NTF:
0796 nci_rf_intf_activated_ntf_packet(ndev, skb);
0797 break;
0798
0799 case NCI_OP_RF_DEACTIVATE_NTF:
0800 nci_rf_deactivate_ntf_packet(ndev, skb);
0801 break;
0802
0803 case NCI_OP_NFCEE_DISCOVER_NTF:
0804 nci_nfcee_discover_ntf_packet(ndev, skb);
0805 break;
0806
0807 case NCI_OP_RF_NFCEE_ACTION_NTF:
0808 break;
0809
0810 default:
0811 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
0812 break;
0813 }
0814
0815 nci_core_ntf_packet(ndev, ntf_opcode, skb);
0816 end:
0817 kfree_skb(skb);
0818 }