0001
0002
0003
0004
0005
0006 #include <net/nfc/hci.h>
0007
0008 #include "st21nfca.h"
0009
0010 #define ST21NFCA_NFCIP1_INITIATOR 0x00
0011 #define ST21NFCA_NFCIP1_REQ 0xd4
0012 #define ST21NFCA_NFCIP1_RES 0xd5
0013 #define ST21NFCA_NFCIP1_ATR_REQ 0x00
0014 #define ST21NFCA_NFCIP1_ATR_RES 0x01
0015 #define ST21NFCA_NFCIP1_PSL_REQ 0x04
0016 #define ST21NFCA_NFCIP1_PSL_RES 0x05
0017 #define ST21NFCA_NFCIP1_DEP_REQ 0x06
0018 #define ST21NFCA_NFCIP1_DEP_RES 0x07
0019
0020 #define ST21NFCA_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03)
0021 #define ST21NFCA_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0)
0022 #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
0023 ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
0024 #define ST21NFCA_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & 0x04)
0025 #define ST21NFCA_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08)
0026 #define ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT 0x10
0027
0028 #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
0029 ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
0030
0031 #define ST21NFCA_NFC_DEP_PFB_I_PDU 0x00
0032 #define ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU 0x40
0033 #define ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU 0x80
0034
0035 #define ST21NFCA_ATR_REQ_MIN_SIZE 17
0036 #define ST21NFCA_ATR_REQ_MAX_SIZE 65
0037 #define ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B 0x30
0038 #define ST21NFCA_GB_BIT 0x02
0039
0040 #define ST21NFCA_EVT_SEND_DATA 0x10
0041 #define ST21NFCA_EVT_FIELD_ON 0x11
0042 #define ST21NFCA_EVT_CARD_DEACTIVATED 0x12
0043 #define ST21NFCA_EVT_CARD_ACTIVATED 0x13
0044 #define ST21NFCA_EVT_FIELD_OFF 0x14
0045
0046 #define ST21NFCA_EVT_CARD_F_BITRATE 0x16
0047 #define ST21NFCA_EVT_READER_F_BITRATE 0x13
0048 #define ST21NFCA_PSL_REQ_SEND_SPEED(brs) (brs & 0x38)
0049 #define ST21NFCA_PSL_REQ_RECV_SPEED(brs) (brs & 0x07)
0050 #define ST21NFCA_PP2LRI(pp) ((pp & 0x30) >> 4)
0051 #define ST21NFCA_CARD_BITRATE_212 0x01
0052 #define ST21NFCA_CARD_BITRATE_424 0x02
0053
0054 #define ST21NFCA_DEFAULT_TIMEOUT 0x0a
0055
0056
0057 #define PROTOCOL_ERR(req) pr_err("%d: ST21NFCA Protocol error: %s\n", \
0058 __LINE__, req)
0059
0060 struct st21nfca_atr_req {
0061 u8 length;
0062 u8 cmd0;
0063 u8 cmd1;
0064 u8 nfcid3[NFC_NFCID3_MAXSIZE];
0065 u8 did;
0066 u8 bsi;
0067 u8 bri;
0068 u8 ppi;
0069 u8 gbi[];
0070 } __packed;
0071
0072 struct st21nfca_atr_res {
0073 u8 length;
0074 u8 cmd0;
0075 u8 cmd1;
0076 u8 nfcid3[NFC_NFCID3_MAXSIZE];
0077 u8 did;
0078 u8 bsi;
0079 u8 bri;
0080 u8 to;
0081 u8 ppi;
0082 u8 gbi[];
0083 } __packed;
0084
0085 struct st21nfca_psl_req {
0086 u8 length;
0087 u8 cmd0;
0088 u8 cmd1;
0089 u8 did;
0090 u8 brs;
0091 u8 fsl;
0092 } __packed;
0093
0094 struct st21nfca_psl_res {
0095 u8 length;
0096 u8 cmd0;
0097 u8 cmd1;
0098 u8 did;
0099 } __packed;
0100
0101 struct st21nfca_dep_req_res {
0102 u8 length;
0103 u8 cmd0;
0104 u8 cmd1;
0105 u8 pfb;
0106 u8 did;
0107 u8 nad;
0108 } __packed;
0109
0110 static void st21nfca_tx_work(struct work_struct *work)
0111 {
0112 struct st21nfca_hci_info *info = container_of(work,
0113 struct st21nfca_hci_info,
0114 dep_info.tx_work);
0115
0116 struct nfc_dev *dev;
0117 struct sk_buff *skb;
0118
0119 if (info) {
0120 dev = info->hdev->ndev;
0121 skb = info->dep_info.tx_pending;
0122
0123 device_lock(&dev->dev);
0124
0125 nfc_hci_send_cmd_async(info->hdev, ST21NFCA_RF_READER_F_GATE,
0126 ST21NFCA_WR_XCHG_DATA, skb->data, skb->len,
0127 info->async_cb, info);
0128 device_unlock(&dev->dev);
0129 kfree_skb(skb);
0130 }
0131 }
0132
0133 static void st21nfca_im_send_pdu(struct st21nfca_hci_info *info,
0134 struct sk_buff *skb)
0135 {
0136 info->dep_info.tx_pending = skb;
0137 schedule_work(&info->dep_info.tx_work);
0138 }
0139
0140 static int st21nfca_tm_send_atr_res(struct nfc_hci_dev *hdev,
0141 struct st21nfca_atr_req *atr_req)
0142 {
0143 struct st21nfca_atr_res *atr_res;
0144 struct sk_buff *skb;
0145 size_t gb_len;
0146 int r;
0147 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0148
0149 gb_len = atr_req->length - sizeof(struct st21nfca_atr_req);
0150 skb = alloc_skb(atr_req->length + 1, GFP_KERNEL);
0151 if (!skb)
0152 return -ENOMEM;
0153
0154 skb_put(skb, sizeof(struct st21nfca_atr_res));
0155
0156 atr_res = (struct st21nfca_atr_res *)skb->data;
0157 memset(atr_res, 0, sizeof(struct st21nfca_atr_res));
0158
0159 atr_res->length = atr_req->length + 1;
0160 atr_res->cmd0 = ST21NFCA_NFCIP1_RES;
0161 atr_res->cmd1 = ST21NFCA_NFCIP1_ATR_RES;
0162
0163 memcpy(atr_res->nfcid3, atr_req->nfcid3, 6);
0164 atr_res->bsi = 0x00;
0165 atr_res->bri = 0x00;
0166 atr_res->to = ST21NFCA_DEFAULT_TIMEOUT;
0167 atr_res->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
0168
0169 if (gb_len) {
0170 skb_put(skb, gb_len);
0171
0172 atr_res->ppi |= ST21NFCA_GB_BIT;
0173 memcpy(atr_res->gbi, atr_req->gbi, gb_len);
0174 r = nfc_set_remote_general_bytes(hdev->ndev, atr_res->gbi,
0175 gb_len);
0176 if (r < 0) {
0177 kfree_skb(skb);
0178 return r;
0179 }
0180 }
0181
0182 info->dep_info.curr_nfc_dep_pni = 0;
0183
0184 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
0185 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
0186 kfree_skb(skb);
0187 return r;
0188 }
0189
0190 static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
0191 struct sk_buff *skb)
0192 {
0193 struct st21nfca_atr_req *atr_req;
0194 size_t gb_len;
0195 int r;
0196
0197 skb_trim(skb, skb->len - 1);
0198
0199 if (!skb->len)
0200 return -EIO;
0201
0202 if (skb->len < ST21NFCA_ATR_REQ_MIN_SIZE)
0203 return -EPROTO;
0204
0205 atr_req = (struct st21nfca_atr_req *)skb->data;
0206
0207 if (atr_req->length < sizeof(struct st21nfca_atr_req))
0208 return -EPROTO;
0209
0210 r = st21nfca_tm_send_atr_res(hdev, atr_req);
0211 if (r)
0212 return r;
0213
0214 gb_len = skb->len - sizeof(struct st21nfca_atr_req);
0215
0216 r = nfc_tm_activated(hdev->ndev, NFC_PROTO_NFC_DEP_MASK,
0217 NFC_COMM_PASSIVE, atr_req->gbi, gb_len);
0218 if (r)
0219 return r;
0220
0221 return 0;
0222 }
0223
0224 static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
0225 struct st21nfca_psl_req *psl_req)
0226 {
0227 struct st21nfca_psl_res *psl_res;
0228 struct sk_buff *skb;
0229 u8 bitrate[2] = {0, 0};
0230 int r;
0231
0232 skb = alloc_skb(sizeof(struct st21nfca_psl_res), GFP_KERNEL);
0233 if (!skb)
0234 return -ENOMEM;
0235 skb_put(skb, sizeof(struct st21nfca_psl_res));
0236
0237 psl_res = (struct st21nfca_psl_res *)skb->data;
0238
0239 psl_res->length = sizeof(struct st21nfca_psl_res);
0240 psl_res->cmd0 = ST21NFCA_NFCIP1_RES;
0241 psl_res->cmd1 = ST21NFCA_NFCIP1_PSL_RES;
0242 psl_res->did = psl_req->did;
0243
0244 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
0245 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
0246 if (r < 0)
0247 goto error;
0248
0249
0250
0251
0252
0253
0254
0255
0256 if (ST21NFCA_PSL_REQ_SEND_SPEED(psl_req->brs) &&
0257 ST21NFCA_PSL_REQ_RECV_SPEED(psl_req->brs)) {
0258 bitrate[0] = ST21NFCA_CARD_BITRATE_424;
0259 bitrate[1] = ST21NFCA_CARD_BITRATE_424;
0260 }
0261
0262
0263 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
0264 ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2);
0265 error:
0266 kfree_skb(skb);
0267 return r;
0268 }
0269
0270 static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,
0271 struct sk_buff *skb)
0272 {
0273 struct st21nfca_psl_req *psl_req;
0274
0275 skb_trim(skb, skb->len - 1);
0276
0277 if (!skb->len)
0278 return -EIO;
0279
0280 psl_req = (struct st21nfca_psl_req *)skb->data;
0281
0282 if (skb->len < sizeof(struct st21nfca_psl_req))
0283 return -EIO;
0284
0285 return st21nfca_tm_send_psl_res(hdev, psl_req);
0286 }
0287
0288 int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb)
0289 {
0290 int r;
0291 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0292
0293 *(u8 *)skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
0294 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_RES;
0295 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_RES;
0296 *(u8 *)skb_push(skb, 1) = skb->len;
0297
0298 r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
0299 ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
0300 kfree_skb(skb);
0301
0302 return r;
0303 }
0304 EXPORT_SYMBOL(st21nfca_tm_send_dep_res);
0305
0306 static int st21nfca_tm_recv_dep_req(struct nfc_hci_dev *hdev,
0307 struct sk_buff *skb)
0308 {
0309 struct st21nfca_dep_req_res *dep_req;
0310 u8 size;
0311 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0312
0313 skb_trim(skb, skb->len - 1);
0314
0315 size = 4;
0316
0317 dep_req = (struct st21nfca_dep_req_res *)skb->data;
0318 if (skb->len < size)
0319 return -EIO;
0320
0321 if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_req->pfb))
0322 size++;
0323 if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_req->pfb))
0324 size++;
0325
0326 if (skb->len < size)
0327 return -EIO;
0328
0329
0330 switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_req->pfb)) {
0331 case ST21NFCA_NFC_DEP_PFB_I_PDU:
0332 info->dep_info.curr_nfc_dep_pni =
0333 ST21NFCA_NFC_DEP_PFB_PNI(dep_req->pfb);
0334 break;
0335 case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
0336 pr_err("Received a ACK/NACK PDU\n");
0337 break;
0338 case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
0339 pr_err("Received a SUPERVISOR PDU\n");
0340 break;
0341 }
0342
0343 skb_pull(skb, size);
0344
0345 return nfc_tm_data_received(hdev->ndev, skb);
0346 }
0347
0348 static int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev,
0349 struct sk_buff *skb)
0350 {
0351 u8 cmd0, cmd1;
0352 int r;
0353
0354 cmd0 = skb->data[1];
0355 switch (cmd0) {
0356 case ST21NFCA_NFCIP1_REQ:
0357 cmd1 = skb->data[2];
0358 switch (cmd1) {
0359 case ST21NFCA_NFCIP1_ATR_REQ:
0360 r = st21nfca_tm_recv_atr_req(hdev, skb);
0361 break;
0362 case ST21NFCA_NFCIP1_PSL_REQ:
0363 r = st21nfca_tm_recv_psl_req(hdev, skb);
0364 break;
0365 case ST21NFCA_NFCIP1_DEP_REQ:
0366 r = st21nfca_tm_recv_dep_req(hdev, skb);
0367 break;
0368 default:
0369 return 1;
0370 }
0371 break;
0372 default:
0373 return 1;
0374 }
0375 return r;
0376 }
0377
0378
0379
0380
0381
0382
0383 int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
0384 u8 event, struct sk_buff *skb)
0385 {
0386 int r = 0;
0387 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0388
0389 pr_debug("dep event: %d\n", event);
0390
0391 switch (event) {
0392 case ST21NFCA_EVT_CARD_ACTIVATED:
0393 info->dep_info.curr_nfc_dep_pni = 0;
0394 break;
0395 case ST21NFCA_EVT_CARD_DEACTIVATED:
0396 break;
0397 case ST21NFCA_EVT_FIELD_ON:
0398 break;
0399 case ST21NFCA_EVT_FIELD_OFF:
0400 break;
0401 case ST21NFCA_EVT_SEND_DATA:
0402 r = st21nfca_tm_event_send_data(hdev, skb);
0403 if (r < 0)
0404 return r;
0405 return 0;
0406 default:
0407 nfc_err(&hdev->ndev->dev, "Unexpected event on card f gate\n");
0408 return 1;
0409 }
0410 kfree_skb(skb);
0411 return r;
0412 }
0413 EXPORT_SYMBOL(st21nfca_dep_event_received);
0414
0415 static void st21nfca_im_send_psl_req(struct nfc_hci_dev *hdev, u8 did, u8 bsi,
0416 u8 bri, u8 lri)
0417 {
0418 struct sk_buff *skb;
0419 struct st21nfca_psl_req *psl_req;
0420 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0421
0422 skb =
0423 alloc_skb(sizeof(struct st21nfca_psl_req) + 1, GFP_KERNEL);
0424 if (!skb)
0425 return;
0426 skb_reserve(skb, 1);
0427
0428 skb_put(skb, sizeof(struct st21nfca_psl_req));
0429 psl_req = (struct st21nfca_psl_req *) skb->data;
0430
0431 psl_req->length = sizeof(struct st21nfca_psl_req);
0432 psl_req->cmd0 = ST21NFCA_NFCIP1_REQ;
0433 psl_req->cmd1 = ST21NFCA_NFCIP1_PSL_REQ;
0434 psl_req->did = did;
0435 psl_req->brs = (0x30 & bsi << 4) | (bri & 0x03);
0436 psl_req->fsl = lri;
0437
0438 *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
0439
0440 st21nfca_im_send_pdu(info, skb);
0441 }
0442
0443 #define ST21NFCA_CB_TYPE_READER_F 1
0444 static void st21nfca_im_recv_atr_res_cb(void *context, struct sk_buff *skb,
0445 int err)
0446 {
0447 struct st21nfca_hci_info *info = context;
0448 struct st21nfca_atr_res *atr_res;
0449 int r;
0450
0451 if (err != 0)
0452 return;
0453
0454 if (!skb)
0455 return;
0456
0457 switch (info->async_cb_type) {
0458 case ST21NFCA_CB_TYPE_READER_F:
0459 skb_trim(skb, skb->len - 1);
0460 atr_res = (struct st21nfca_atr_res *)skb->data;
0461 r = nfc_set_remote_general_bytes(info->hdev->ndev,
0462 atr_res->gbi,
0463 skb->len - sizeof(struct st21nfca_atr_res));
0464 if (r < 0)
0465 return;
0466
0467 if (atr_res->to >= 0x0e)
0468 info->dep_info.to = 0x0e;
0469 else
0470 info->dep_info.to = atr_res->to + 1;
0471
0472 info->dep_info.to |= 0x10;
0473
0474 r = nfc_dep_link_is_up(info->hdev->ndev, info->dep_info.idx,
0475 NFC_COMM_PASSIVE, NFC_RF_INITIATOR);
0476 if (r < 0)
0477 return;
0478
0479 info->dep_info.curr_nfc_dep_pni = 0;
0480 if (ST21NFCA_PP2LRI(atr_res->ppi) != info->dep_info.lri)
0481 st21nfca_im_send_psl_req(info->hdev, atr_res->did,
0482 atr_res->bsi, atr_res->bri,
0483 ST21NFCA_PP2LRI(atr_res->ppi));
0484 break;
0485 default:
0486 kfree_skb(skb);
0487 break;
0488 }
0489 }
0490
0491 int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len)
0492 {
0493 struct sk_buff *skb;
0494 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0495 struct st21nfca_atr_req *atr_req;
0496 struct nfc_target *target;
0497 uint size;
0498
0499 info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
0500 size = ST21NFCA_ATR_REQ_MIN_SIZE + gb_len;
0501 if (size > ST21NFCA_ATR_REQ_MAX_SIZE) {
0502 PROTOCOL_ERR("14.6.1.1");
0503 return -EINVAL;
0504 }
0505
0506 skb =
0507 alloc_skb(sizeof(struct st21nfca_atr_req) + gb_len + 1, GFP_KERNEL);
0508 if (!skb)
0509 return -ENOMEM;
0510
0511 skb_reserve(skb, 1);
0512
0513 skb_put(skb, sizeof(struct st21nfca_atr_req));
0514
0515 atr_req = (struct st21nfca_atr_req *)skb->data;
0516 memset(atr_req, 0, sizeof(struct st21nfca_atr_req));
0517
0518 atr_req->cmd0 = ST21NFCA_NFCIP1_REQ;
0519 atr_req->cmd1 = ST21NFCA_NFCIP1_ATR_REQ;
0520 memset(atr_req->nfcid3, 0, NFC_NFCID3_MAXSIZE);
0521 target = hdev->ndev->targets;
0522
0523 if (target->sensf_res_len > 0)
0524 memcpy(atr_req->nfcid3, target->sensf_res,
0525 target->sensf_res_len);
0526 else
0527 get_random_bytes(atr_req->nfcid3, NFC_NFCID3_MAXSIZE);
0528
0529 atr_req->did = 0x0;
0530
0531 atr_req->bsi = 0x00;
0532 atr_req->bri = 0x00;
0533 atr_req->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
0534 if (gb_len) {
0535 atr_req->ppi |= ST21NFCA_GB_BIT;
0536 skb_put_data(skb, gb, gb_len);
0537 }
0538 atr_req->length = sizeof(struct st21nfca_atr_req) + hdev->gb_len;
0539
0540 *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
0541
0542 info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
0543 info->async_cb_context = info;
0544 info->async_cb = st21nfca_im_recv_atr_res_cb;
0545 info->dep_info.bri = atr_req->bri;
0546 info->dep_info.bsi = atr_req->bsi;
0547 info->dep_info.lri = ST21NFCA_PP2LRI(atr_req->ppi);
0548
0549 return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
0550 ST21NFCA_WR_XCHG_DATA, skb->data,
0551 skb->len, info->async_cb, info);
0552 }
0553 EXPORT_SYMBOL(st21nfca_im_send_atr_req);
0554
0555 static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,
0556 int err)
0557 {
0558 struct st21nfca_hci_info *info = context;
0559 struct st21nfca_dep_req_res *dep_res;
0560
0561 int size;
0562
0563 if (err != 0)
0564 return;
0565
0566 if (!skb)
0567 return;
0568
0569 switch (info->async_cb_type) {
0570 case ST21NFCA_CB_TYPE_READER_F:
0571 dep_res = (struct st21nfca_dep_req_res *)skb->data;
0572
0573 size = 3;
0574 if (skb->len < size)
0575 goto exit;
0576
0577 if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_res->pfb))
0578 size++;
0579 if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_res->pfb))
0580 size++;
0581
0582 if (skb->len < size)
0583 goto exit;
0584
0585 skb_trim(skb, skb->len - 1);
0586
0587
0588 switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_res->pfb)) {
0589 case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
0590 pr_err("Received a ACK/NACK PDU\n");
0591 fallthrough;
0592 case ST21NFCA_NFC_DEP_PFB_I_PDU:
0593 info->dep_info.curr_nfc_dep_pni =
0594 ST21NFCA_NFC_DEP_PFB_PNI(dep_res->pfb + 1);
0595 size++;
0596 skb_pull(skb, size);
0597 nfc_tm_data_received(info->hdev->ndev, skb);
0598 break;
0599 case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
0600 pr_err("Received a SUPERVISOR PDU\n");
0601 skb_pull(skb, size);
0602 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
0603 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
0604 *(u8 *)skb_push(skb, 1) = skb->len;
0605 *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
0606
0607 st21nfca_im_send_pdu(info, skb);
0608 break;
0609 }
0610
0611 return;
0612 default:
0613 break;
0614 }
0615
0616 exit:
0617 kfree_skb(skb);
0618 }
0619
0620 int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb)
0621 {
0622 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0623
0624 info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
0625 info->async_cb_context = info;
0626 info->async_cb = st21nfca_im_recv_dep_res_cb;
0627
0628 *(u8 *)skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
0629 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
0630 *(u8 *)skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
0631 *(u8 *)skb_push(skb, 1) = skb->len;
0632
0633 *(u8 *)skb_push(skb, 1) = info->dep_info.to | 0x10;
0634
0635 return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
0636 ST21NFCA_WR_XCHG_DATA,
0637 skb->data, skb->len,
0638 info->async_cb, info);
0639 }
0640 EXPORT_SYMBOL(st21nfca_im_send_dep_req);
0641
0642 void st21nfca_dep_init(struct nfc_hci_dev *hdev)
0643 {
0644 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0645
0646 INIT_WORK(&info->dep_info.tx_work, st21nfca_tx_work);
0647 info->dep_info.curr_nfc_dep_pni = 0;
0648 info->dep_info.idx = 0;
0649 info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
0650 }
0651 EXPORT_SYMBOL(st21nfca_dep_init);
0652
0653 void st21nfca_dep_deinit(struct nfc_hci_dev *hdev)
0654 {
0655 struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
0656
0657 cancel_work_sync(&info->dep_info.tx_work);
0658 }
0659 EXPORT_SYMBOL(st21nfca_dep_deinit);