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