static void nci_target_found(struct nci_dev *ndev, struct nci_rf_intf_activated_ntf *ntf) { struct nfc_target nfc_tgt; if (ntf->rf_protocol == NCI_RF_PROTOCOL_T2T) /* T2T MifareUL */ nfc_tgt.supported_protocols = NFC_PROTO_MIFARE_MASK; else if (ntf->rf_protocol == NCI_RF_PROTOCOL_ISO_DEP) /* 4A */ nfc_tgt.supported_protocols = NFC_PROTO_ISO14443_MASK; else nfc_tgt.supported_protocols = 0; nfc_tgt.sens_res = ntf->rf_tech_specific_params.nfca_poll.sens_res; nfc_tgt.sel_res = ntf->rf_tech_specific_params.nfca_poll.sel_res; if (!(nfc_tgt.supported_protocols & ndev->poll_prots)) { nfc_dbg("the target found does not have the desired protocol"); return; } nfc_dbg("new target found, supported_protocols 0x%x", nfc_tgt.supported_protocols); ndev->target_available_prots = nfc_tgt.supported_protocols; nfc_targets_found(ndev->nfc_dev, &nfc_tgt, 1); }
static void nci_rf_discover_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb) { struct nci_rf_discover_ntf ntf; __u8 *data = skb->data; bool add_target = true; ntf.rf_discovery_id = *data++; ntf.rf_protocol = *data++; ntf.rf_tech_and_mode = *data++; ntf.rf_tech_specific_params_len = *data++; pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id); pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol); pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode); pr_debug("rf_tech_specific_params_len %d\n", ntf.rf_tech_specific_params_len); if (ntf.rf_tech_specific_params_len > 0) { switch (ntf.rf_tech_and_mode) { case NCI_NFC_A_PASSIVE_POLL_MODE: data = nci_extract_rf_params_nfca_passive_poll(ndev, &(ntf.rf_tech_specific_params.nfca_poll), data); break; case NCI_NFC_B_PASSIVE_POLL_MODE: data = nci_extract_rf_params_nfcb_passive_poll(ndev, &(ntf.rf_tech_specific_params.nfcb_poll), data); break; case NCI_NFC_F_PASSIVE_POLL_MODE: data = nci_extract_rf_params_nfcf_passive_poll(ndev, &(ntf.rf_tech_specific_params.nfcf_poll), data); break; default: pr_err("unsupported rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode); data += ntf.rf_tech_specific_params_len; add_target = false; } } ntf.ntf_type = *data++; pr_debug("ntf_type %d\n", ntf.ntf_type); if (add_target == true) nci_add_new_target(ndev, &ntf); if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) { atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES); } else { atomic_set(&ndev->state, NCI_W4_HOST_SELECT); nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); } }
static int nfcsim_target_found(struct nfcsim *dev) { struct nfc_target nfc_tgt; DEV_DBG(dev, "\n"); memset(&nfc_tgt, 0, sizeof(struct nfc_target)); nfc_tgt.supported_protocols = NFC_PROTO_NFC_DEP_MASK; nfc_targets_found(dev->nfc_dev, &nfc_tgt, 1); return 0; }
static void nci_target_auto_activated(struct nci_dev *ndev, struct nci_rf_intf_activated_ntf *ntf) { struct nfc_target *target; int rc; target = &ndev->targets[ndev->n_targets]; rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol, ntf->activation_rf_tech_and_mode, &ntf->rf_tech_specific_params); if (rc) return; target->idx = ntf->rf_discovery_id; ndev->n_targets++; pr_debug("target_idx %d, n_targets %d\n", target->idx, ndev->n_targets); nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); }
static void microread_target_discovered(struct nfc_hci_dev *hdev, u8 gate, struct sk_buff *skb) { struct nfc_target *targets; int r = 0; pr_info("target discovered to gate 0x%x\n", gate); targets = kzalloc(sizeof(struct nfc_target), GFP_KERNEL); if (targets == NULL) { r = -ENOMEM; goto exit; } targets->hci_reader_gate = gate; switch (gate) { case MICROREAD_GATE_ID_MREAD_ISO_A: targets->supported_protocols = nfc_hci_sak_to_protocol(skb->data[MICROREAD_EMCF_A_SAK]); targets->sens_res = be16_to_cpu(*(u16 *)&skb->data[MICROREAD_EMCF_A_ATQA]); targets->sel_res = skb->data[MICROREAD_EMCF_A_SAK]; targets->nfcid1_len = skb->data[MICROREAD_EMCF_A_LEN]; if (targets->nfcid1_len > sizeof(targets->nfcid1)) { r = -EINVAL; goto exit_free; } memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_A_UID], targets->nfcid1_len); break; case MICROREAD_GATE_ID_MREAD_ISO_A_3: targets->supported_protocols = nfc_hci_sak_to_protocol(skb->data[MICROREAD_EMCF_A3_SAK]); targets->sens_res = be16_to_cpu(*(u16 *)&skb->data[MICROREAD_EMCF_A3_ATQA]); targets->sel_res = skb->data[MICROREAD_EMCF_A3_SAK]; targets->nfcid1_len = skb->data[MICROREAD_EMCF_A3_LEN]; if (targets->nfcid1_len > sizeof(targets->nfcid1)) { r = -EINVAL; goto exit_free; } memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_A3_UID], targets->nfcid1_len); break; case MICROREAD_GATE_ID_MREAD_ISO_B: targets->supported_protocols = NFC_PROTO_ISO14443_B_MASK; memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_B_UID], 4); targets->nfcid1_len = 4; break; case MICROREAD_GATE_ID_MREAD_NFC_T1: targets->supported_protocols = NFC_PROTO_JEWEL_MASK; targets->sens_res = le16_to_cpu(*(u16 *)&skb->data[MICROREAD_EMCF_T1_ATQA]); memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_T1_UID], 4); targets->nfcid1_len = 4; break; case MICROREAD_GATE_ID_MREAD_NFC_T3: targets->supported_protocols = NFC_PROTO_FELICA_MASK; memcpy(targets->nfcid1, &skb->data[MICROREAD_EMCF_T3_UID], 8); targets->nfcid1_len = 8; break; default: pr_info("discard target discovered to gate 0x%x\n", gate); goto exit_free; } r = nfc_targets_found(hdev->ndev, targets, 1); exit_free: kfree(targets); exit: kfree_skb(skb); if (r) pr_err("Failed to handle discovered target err=%d", r); }