^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <net/nfc/hci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "st21nfca.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define ST21NFCA_NFCIP1_INITIATOR 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define ST21NFCA_NFCIP1_REQ 0xd4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define ST21NFCA_NFCIP1_RES 0xd5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define ST21NFCA_NFCIP1_ATR_REQ 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define ST21NFCA_NFCIP1_ATR_RES 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ST21NFCA_NFCIP1_PSL_REQ 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ST21NFCA_NFCIP1_PSL_RES 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ST21NFCA_NFCIP1_DEP_REQ 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ST21NFCA_NFCIP1_DEP_RES 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ST21NFCA_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ST21NFCA_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ST21NFCA_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define ST21NFCA_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define ST21NFCA_NFC_DEP_PFB_I_PDU 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define ST21NFCA_ATR_REQ_MIN_SIZE 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define ST21NFCA_ATR_REQ_MAX_SIZE 65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define ST21NFCA_GB_BIT 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define ST21NFCA_EVT_SEND_DATA 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define ST21NFCA_EVT_FIELD_ON 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define ST21NFCA_EVT_CARD_DEACTIVATED 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define ST21NFCA_EVT_CARD_ACTIVATED 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define ST21NFCA_EVT_FIELD_OFF 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define ST21NFCA_EVT_CARD_F_BITRATE 0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define ST21NFCA_EVT_READER_F_BITRATE 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define ST21NFCA_PSL_REQ_SEND_SPEED(brs) (brs & 0x38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define ST21NFCA_PSL_REQ_RECV_SPEED(brs) (brs & 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define ST21NFCA_PP2LRI(pp) ((pp & 0x30) >> 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define ST21NFCA_CARD_BITRATE_212 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define ST21NFCA_CARD_BITRATE_424 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define ST21NFCA_DEFAULT_TIMEOUT 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define PROTOCOL_ERR(req) pr_err("%d: ST21NFCA Protocol error: %s\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __LINE__, req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct st21nfca_atr_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u8 cmd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u8 cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u8 nfcid3[NFC_NFCID3_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u8 bsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u8 bri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 ppi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u8 gbi[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct st21nfca_atr_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 cmd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u8 cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u8 nfcid3[NFC_NFCID3_MAXSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u8 bsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u8 bri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u8 to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 ppi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u8 gbi[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct st21nfca_psl_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 cmd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u8 brs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u8 fsl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct st21nfca_psl_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 cmd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u8 cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct st21nfca_dep_req_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u8 cmd0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u8 cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u8 pfb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u8 did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u8 nad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void st21nfca_tx_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct st21nfca_hci_info *info = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct st21nfca_hci_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) dep_info.tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct nfc_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) dev = info->hdev->ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) skb = info->dep_info.tx_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) device_lock(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) nfc_hci_send_cmd_async(info->hdev, ST21NFCA_RF_READER_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ST21NFCA_WR_XCHG_DATA, skb->data, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) info->async_cb, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) device_unlock(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void st21nfca_im_send_pdu(struct st21nfca_hci_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) info->dep_info.tx_pending = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) schedule_work(&info->dep_info.tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int st21nfca_tm_send_atr_res(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct st21nfca_atr_req *atr_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct st21nfca_atr_res *atr_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) size_t gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) gb_len = atr_req->length - sizeof(struct st21nfca_atr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) skb = alloc_skb(atr_req->length + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) skb_put(skb, sizeof(struct st21nfca_atr_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) atr_res = (struct st21nfca_atr_res *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) memset(atr_res, 0, sizeof(struct st21nfca_atr_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) atr_res->length = atr_req->length + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) atr_res->cmd0 = ST21NFCA_NFCIP1_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) atr_res->cmd1 = ST21NFCA_NFCIP1_ATR_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) memcpy(atr_res->nfcid3, atr_req->nfcid3, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) atr_res->bsi = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) atr_res->bri = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) atr_res->to = ST21NFCA_DEFAULT_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) atr_res->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (gb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) skb_put(skb, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) atr_res->ppi |= ST21NFCA_GB_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) memcpy(atr_res->gbi, atr_req->gbi, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) r = nfc_set_remote_general_bytes(hdev->ndev, atr_res->gbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) info->dep_info.curr_nfc_dep_pni = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct st21nfca_atr_req *atr_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) size_t gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) skb_trim(skb, skb->len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (skb->len < ST21NFCA_ATR_REQ_MIN_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) r = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) atr_req = (struct st21nfca_atr_req *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (atr_req->length < sizeof(struct st21nfca_atr_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) r = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) r = st21nfca_tm_send_atr_res(hdev, atr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) gb_len = skb->len - sizeof(struct st21nfca_atr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) r = nfc_tm_activated(hdev->ndev, NFC_PROTO_NFC_DEP_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) NFC_COMM_PASSIVE, atr_req->gbi, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct st21nfca_psl_req *psl_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct st21nfca_psl_res *psl_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) u8 bitrate[2] = {0, 0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) skb = alloc_skb(sizeof(struct st21nfca_psl_res), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) skb_put(skb, sizeof(struct st21nfca_psl_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) psl_res = (struct st21nfca_psl_res *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) psl_res->length = sizeof(struct st21nfca_psl_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) psl_res->cmd0 = ST21NFCA_NFCIP1_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) psl_res->cmd1 = ST21NFCA_NFCIP1_PSL_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) psl_res->did = psl_req->did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * ST21NFCA only support P2P passive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * PSL_REQ BRS value != 0 has only a meaning to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * change technology to type F.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * We change to BITRATE 424Kbits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * In other case switch to BITRATE 106Kbits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (ST21NFCA_PSL_REQ_SEND_SPEED(psl_req->brs) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ST21NFCA_PSL_REQ_RECV_SPEED(psl_req->brs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) bitrate[0] = ST21NFCA_CARD_BITRATE_424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) bitrate[1] = ST21NFCA_CARD_BITRATE_424;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Send an event to change bitrate change event to card f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct st21nfca_psl_req *psl_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) skb_trim(skb, skb->len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) psl_req = (struct st21nfca_psl_req *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (skb->len < sizeof(struct st21nfca_psl_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) r = st21nfca_tm_send_psl_res(hdev, psl_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) *(u8 *)skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_RES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *(u8 *)skb_push(skb, 1) = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) EXPORT_SYMBOL(st21nfca_tm_send_dep_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int st21nfca_tm_recv_dep_req(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct st21nfca_dep_req_res *dep_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) u8 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) skb_trim(skb, skb->len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) size = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) dep_req = (struct st21nfca_dep_req_res *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (skb->len < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_req->pfb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_req->pfb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (skb->len < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* Receiving DEP_REQ - Decoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_req->pfb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) case ST21NFCA_NFC_DEP_PFB_I_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) info->dep_info.curr_nfc_dep_pni =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ST21NFCA_NFC_DEP_PFB_PNI(dep_req->pfb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) pr_err("Received a ACK/NACK PDU\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) pr_err("Received a SUPERVISOR PDU\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) skb_pull(skb, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return nfc_tm_data_received(hdev->ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) u8 cmd0, cmd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) cmd0 = skb->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) switch (cmd0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) case ST21NFCA_NFCIP1_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) cmd1 = skb->data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) switch (cmd1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) case ST21NFCA_NFCIP1_ATR_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) r = st21nfca_tm_recv_atr_req(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) case ST21NFCA_NFCIP1_PSL_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) r = st21nfca_tm_recv_psl_req(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) case ST21NFCA_NFCIP1_DEP_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) r = st21nfca_tm_recv_dep_req(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * <= 0: driver handled the event, skb consumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * 1: driver does not handle the event, please do standard processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) u8 event, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) pr_debug("dep event: %d\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) case ST21NFCA_EVT_CARD_ACTIVATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) info->dep_info.curr_nfc_dep_pni = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) case ST21NFCA_EVT_CARD_DEACTIVATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case ST21NFCA_EVT_FIELD_ON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) case ST21NFCA_EVT_FIELD_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case ST21NFCA_EVT_SEND_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) r = st21nfca_tm_event_send_data(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) nfc_err(&hdev->ndev->dev, "Unexpected event on card f gate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) EXPORT_SYMBOL(st21nfca_dep_event_received);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static void st21nfca_im_send_psl_req(struct nfc_hci_dev *hdev, u8 did, u8 bsi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) u8 bri, u8 lri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct st21nfca_psl_req *psl_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) skb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) alloc_skb(sizeof(struct st21nfca_psl_req) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) skb_reserve(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) skb_put(skb, sizeof(struct st21nfca_psl_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) psl_req = (struct st21nfca_psl_req *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) psl_req->length = sizeof(struct st21nfca_psl_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) psl_req->cmd0 = ST21NFCA_NFCIP1_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) psl_req->cmd1 = ST21NFCA_NFCIP1_PSL_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) psl_req->did = did;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) psl_req->brs = (0x30 & bsi << 4) | (bri & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) psl_req->fsl = lri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) st21nfca_im_send_pdu(info, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #define ST21NFCA_CB_TYPE_READER_F 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static void st21nfca_im_recv_atr_res_cb(void *context, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct st21nfca_hci_info *info = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct st21nfca_atr_res *atr_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) switch (info->async_cb_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) case ST21NFCA_CB_TYPE_READER_F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) skb_trim(skb, skb->len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) atr_res = (struct st21nfca_atr_res *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) r = nfc_set_remote_general_bytes(info->hdev->ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) atr_res->gbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) skb->len - sizeof(struct st21nfca_atr_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (atr_res->to >= 0x0e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) info->dep_info.to = 0x0e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) info->dep_info.to = atr_res->to + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) info->dep_info.to |= 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) r = nfc_dep_link_is_up(info->hdev->ndev, info->dep_info.idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) NFC_COMM_PASSIVE, NFC_RF_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) info->dep_info.curr_nfc_dep_pni = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (ST21NFCA_PP2LRI(atr_res->ppi) != info->dep_info.lri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) st21nfca_im_send_psl_req(info->hdev, atr_res->did,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) atr_res->bsi, atr_res->bri,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) ST21NFCA_PP2LRI(atr_res->ppi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct st21nfca_atr_req *atr_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct nfc_target *target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) uint size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) size = ST21NFCA_ATR_REQ_MIN_SIZE + gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (size > ST21NFCA_ATR_REQ_MAX_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) PROTOCOL_ERR("14.6.1.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) skb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) alloc_skb(sizeof(struct st21nfca_atr_req) + gb_len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) skb_reserve(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) skb_put(skb, sizeof(struct st21nfca_atr_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) atr_req = (struct st21nfca_atr_req *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) memset(atr_req, 0, sizeof(struct st21nfca_atr_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) atr_req->cmd0 = ST21NFCA_NFCIP1_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) atr_req->cmd1 = ST21NFCA_NFCIP1_ATR_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) memset(atr_req->nfcid3, 0, NFC_NFCID3_MAXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) target = hdev->ndev->targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (target->sensf_res_len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) memcpy(atr_req->nfcid3, target->sensf_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) target->sensf_res_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) get_random_bytes(atr_req->nfcid3, NFC_NFCID3_MAXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) atr_req->did = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) atr_req->bsi = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) atr_req->bri = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) atr_req->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (gb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) atr_req->ppi |= ST21NFCA_GB_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) skb_put_data(skb, gb, gb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) atr_req->length = sizeof(struct st21nfca_atr_req) + hdev->gb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10; /* timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) info->async_cb_context = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) info->async_cb = st21nfca_im_recv_atr_res_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) info->dep_info.bri = atr_req->bri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) info->dep_info.bsi = atr_req->bsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) info->dep_info.lri = ST21NFCA_PP2LRI(atr_req->ppi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ST21NFCA_WR_XCHG_DATA, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) skb->len, info->async_cb, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) EXPORT_SYMBOL(st21nfca_im_send_atr_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct st21nfca_hci_info *info = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct st21nfca_dep_req_res *dep_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) switch (info->async_cb_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) case ST21NFCA_CB_TYPE_READER_F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) dep_res = (struct st21nfca_dep_req_res *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) size = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (skb->len < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_res->pfb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_res->pfb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (skb->len < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) skb_trim(skb, skb->len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* Receiving DEP_REQ - Decoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_res->pfb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) pr_err("Received a ACK/NACK PDU\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) case ST21NFCA_NFC_DEP_PFB_I_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) info->dep_info.curr_nfc_dep_pni =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ST21NFCA_NFC_DEP_PFB_PNI(dep_res->pfb + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) skb_pull(skb, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) nfc_tm_data_received(info->hdev->ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) pr_err("Received a SUPERVISOR PDU\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) skb_pull(skb, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) *(u8 *)skb_push(skb, 1) = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) st21nfca_im_send_pdu(info, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) info->async_cb_context = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) info->async_cb = st21nfca_im_recv_dep_res_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) *(u8 *)skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) *(u8 *)skb_push(skb, 1) = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) ST21NFCA_WR_XCHG_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) skb->data, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) info->async_cb, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) EXPORT_SYMBOL(st21nfca_im_send_dep_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) void st21nfca_dep_init(struct nfc_hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) INIT_WORK(&info->dep_info.tx_work, st21nfca_tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) info->dep_info.curr_nfc_dep_pni = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) info->dep_info.idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) EXPORT_SYMBOL(st21nfca_dep_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) void st21nfca_dep_deinit(struct nfc_hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) cancel_work_sync(&info->dep_info.tx_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) EXPORT_SYMBOL(st21nfca_dep_deinit);