1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2021 Samsung Electrnoics
4 * Bongsu Jeon <bongsu.jeon@samsung.com>
12 #include <sys/ioctl.h>
15 #include <linux/genetlink.h>
16 #include <sys/socket.h>
17 #include <linux/nfc.h>
19 #include "../kselftest_harness.h"
21 #define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
22 #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
23 #define NLA_DATA(na) ((void *)((char *)(na) + NLA_HDRLEN))
24 #define NLA_PAYLOAD(len) ((len) - NLA_HDRLEN)
26 #define MAX_MSG_SIZE 1024
28 #define IOCTL_GET_NCIDEV_IDX 0
29 #define VIRTUAL_NFC_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
30 NFC_PROTO_MIFARE_MASK | \
31 NFC_PROTO_FELICA_MASK | \
32 NFC_PROTO_ISO14443_MASK | \
33 NFC_PROTO_ISO14443_B_MASK | \
34 NFC_PROTO_ISO15693_MASK)
36 const __u8 nci_reset_cmd[] = {0x20, 0x00, 0x01, 0x01};
37 const __u8 nci_init_cmd[] = {0x20, 0x01, 0x00};
38 const __u8 nci_rf_discovery_cmd[] = {0x21, 0x03, 0x09, 0x04, 0x00, 0x01,
39 0x01, 0x01, 0x02, 0x01, 0x06, 0x01};
40 const __u8 nci_init_cmd_v2[] = {0x20, 0x01, 0x02, 0x00, 0x00};
41 const __u8 nci_rf_disc_map_cmd[] = {0x21, 0x00, 0x07, 0x02, 0x04, 0x03,
42 0x02, 0x05, 0x03, 0x03};
43 const __u8 nci_rf_deact_cmd[] = {0x21, 0x06, 0x01, 0x00};
44 const __u8 nci_reset_rsp[] = {0x40, 0x00, 0x03, 0x00, 0x10, 0x01};
45 const __u8 nci_reset_rsp_v2[] = {0x40, 0x00, 0x01, 0x00};
46 const __u8 nci_reset_ntf[] = {0x60, 0x00, 0x09, 0x02, 0x01, 0x20, 0x0e,
47 0x04, 0x61, 0x00, 0x04, 0x02};
48 const __u8 nci_init_rsp[] = {0x40, 0x01, 0x14, 0x00, 0x02, 0x0e, 0x02,
49 0x00, 0x03, 0x01, 0x02, 0x03, 0x02, 0xc8,
50 0x00, 0xff, 0x10, 0x00, 0x0e, 0x12, 0x00,
52 const __u8 nci_init_rsp_v2[] = {0x40, 0x01, 0x1c, 0x00, 0x1a, 0x7e, 0x06,
53 0x00, 0x02, 0x92, 0x04, 0xff, 0xff, 0x01,
54 0x00, 0x40, 0x06, 0x00, 0x00, 0x01, 0x01,
55 0x00, 0x02, 0x00, 0x03, 0x01, 0x01, 0x06,
57 const __u8 nci_rf_disc_map_rsp[] = {0x41, 0x00, 0x01, 0x00};
58 const __u8 nci_rf_disc_rsp[] = {0x41, 0x03, 0x01, 0x00};
59 const __u8 nci_rf_deact_rsp[] = {0x41, 0x06, 0x01, 0x00};
60 const __u8 nci_rf_deact_ntf[] = {0x61, 0x06, 0x02, 0x00, 0x00};
61 const __u8 nci_rf_activate_ntf[] = {0x61, 0x05, 0x1D, 0x01, 0x02, 0x04, 0x00,
62 0xFF, 0xFF, 0x0C, 0x44, 0x03, 0x07, 0x04,
63 0x62, 0x26, 0x11, 0x80, 0x1D, 0x80, 0x01,
64 0x20, 0x00, 0x00, 0x00, 0x06, 0x05, 0x75,
65 0x77, 0x81, 0x02, 0x80};
66 const __u8 nci_t4t_select_cmd[] = {0x00, 0x00, 0x0C, 0x00, 0xA4, 0x04, 0x00,
67 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01};
68 const __u8 nci_t4t_select_cmd2[] = {0x00, 0x00, 0x07, 0x00, 0xA4, 0x00, 0x0C, 0x02,
70 const __u8 nci_t4t_select_cmd3[] = {0x00, 0x00, 0x07, 0x00, 0xA4, 0x00, 0x0C, 0x02,
72 const __u8 nci_t4t_read_cmd[] = {0x00, 0x00, 0x05, 0x00, 0xB0, 0x00, 0x00, 0x0F};
73 const __u8 nci_t4t_read_rsp[] = {0x00, 0x00, 0x11, 0x00, 0x0F, 0x20, 0x00, 0x3B,
74 0x00, 0x34, 0x04, 0x06, 0xE1, 0x04, 0x08, 0x00,
75 0x00, 0x00, 0x90, 0x00};
76 const __u8 nci_t4t_read_cmd2[] = {0x00, 0x00, 0x05, 0x00, 0xB0, 0x00, 0x00, 0x02};
77 const __u8 nci_t4t_read_rsp2[] = {0x00, 0x00, 0x04, 0x00, 0x0F, 0x90, 0x00};
78 const __u8 nci_t4t_read_cmd3[] = {0x00, 0x00, 0x05, 0x00, 0xB0, 0x00, 0x02, 0x0F};
79 const __u8 nci_t4t_read_rsp3[] = {0x00, 0x00, 0x11, 0xD1, 0x01, 0x0B, 0x54, 0x02,
80 0x65, 0x6E, 0x4E, 0x46, 0x43, 0x20, 0x54, 0x45,
81 0x53, 0x54, 0x90, 0x00};
82 const __u8 nci_t4t_rsp_ok[] = {0x00, 0x00, 0x02, 0x90, 0x00};
87 char buf[MAX_MSG_SIZE];
90 static int create_nl_socket(void)
93 struct sockaddr_nl local;
95 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
99 memset(&local, 0, sizeof(local));
100 local.nl_family = AF_NETLINK;
102 if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0)
111 static int send_cmd_mt_nla(int sd, __u16 nlmsg_type, __u32 nlmsg_pid,
112 __u8 genl_cmd, int nla_num, __u16 nla_type[],
113 void *nla_data[], int nla_len[], __u16 flags)
115 struct sockaddr_nl nladdr;
116 struct msgtemplate msg;
122 msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
123 msg.n.nlmsg_type = nlmsg_type;
124 msg.n.nlmsg_flags = flags;
126 msg.n.nlmsg_pid = nlmsg_pid;
127 msg.g.cmd = genl_cmd;
131 for (cnt = 0; cnt < nla_num; cnt++) {
132 na = (struct nlattr *)(GENLMSG_DATA(&msg) + prv_len);
133 na->nla_type = nla_type[cnt];
134 na->nla_len = nla_len[cnt] + NLA_HDRLEN;
136 if (nla_len[cnt] > 0)
137 memcpy(NLA_DATA(na), nla_data[cnt], nla_len[cnt]);
139 prv_len = NLA_ALIGN(nla_len[cnt]) + NLA_HDRLEN;
140 msg.n.nlmsg_len += prv_len;
144 buflen = msg.n.nlmsg_len;
145 memset(&nladdr, 0, sizeof(nladdr));
146 nladdr.nl_family = AF_NETLINK;
148 while ((r = sendto(sd, buf, buflen, 0, (struct sockaddr *)&nladdr,
149 sizeof(nladdr))) < buflen) {
153 } else if (errno != EAGAIN) {
160 static int send_get_nfc_family(int sd, __u32 pid)
162 __u16 nla_get_family_type = CTRL_ATTR_FAMILY_NAME;
163 void *nla_get_family_data;
164 int nla_get_family_len;
165 char family_name[100];
167 nla_get_family_len = strlen(NFC_GENL_NAME) + 1;
168 strcpy(family_name, NFC_GENL_NAME);
169 nla_get_family_data = family_name;
171 return send_cmd_mt_nla(sd, GENL_ID_CTRL, pid, CTRL_CMD_GETFAMILY,
172 1, &nla_get_family_type, &nla_get_family_data,
173 &nla_get_family_len, NLM_F_REQUEST);
176 static int get_family_id(int sd, __u32 pid, __u32 *event_group)
189 rc = send_get_nfc_family(sd, pid);
194 resp_len = recv(sd, &ans, sizeof(ans), 0);
196 if (ans.n.nlmsg_type == NLMSG_ERROR || resp_len < 0 ||
197 !NLMSG_OK(&ans.n, resp_len))
201 resp_len = GENLMSG_PAYLOAD(&ans.n);
202 na = (struct nlattr *)GENLMSG_DATA(&ans);
204 while (len < resp_len) {
205 len += NLA_ALIGN(na->nla_len);
206 if (na->nla_type == CTRL_ATTR_FAMILY_ID) {
207 id = *(__u16 *)NLA_DATA(na);
208 } else if (na->nla_type == CTRL_ATTR_MCAST_GROUPS) {
209 struct nlattr *nested_na;
210 struct nlattr *group_na;
214 nested_na = (struct nlattr *)((char *)na + NLA_HDRLEN);
215 group_na = (struct nlattr *)((char *)nested_na + NLA_HDRLEN);
218 for (group_attr = CTRL_ATTR_MCAST_GRP_UNSPEC;
219 group_attr < CTRL_ATTR_MCAST_GRP_MAX; group_attr++) {
220 if (group_na->nla_type == CTRL_ATTR_MCAST_GRP_ID) {
221 *event_group = *(__u32 *)((char *)group_na +
226 group_attr_len += NLA_ALIGN(group_na->nla_len) +
228 if (group_attr_len >= nested_na->nla_len)
231 group_na = (struct nlattr *)((char *)group_na +
232 NLA_ALIGN(group_na->nla_len));
235 na = (struct nlattr *)(GENLMSG_DATA(&ans) + len);
240 static int send_cmd_with_idx(int sd, __u16 nlmsg_type, __u32 nlmsg_pid,
241 __u8 genl_cmd, int dev_id)
243 __u16 nla_type = NFC_ATTR_DEVICE_INDEX;
244 void *nla_data = &dev_id;
247 return send_cmd_mt_nla(sd, nlmsg_type, nlmsg_pid, genl_cmd, 1,
248 &nla_type, &nla_data, &nla_len, NLM_F_REQUEST);
251 static int get_nci_devid(int sd, __u16 fid, __u32 pid, int dev_id, struct msgtemplate *msg)
255 rc = send_cmd_with_idx(sd, fid, pid, NFC_CMD_GET_DEVICE, dev_id);
261 resp_len = recv(sd, msg, sizeof(*msg), 0);
267 if (msg->n.nlmsg_type == NLMSG_ERROR ||
268 !NLMSG_OK(&msg->n, resp_len)) {
278 static __u8 get_dev_enable_state(struct msgtemplate *msg)
284 resp_len = GENLMSG_PAYLOAD(&msg->n);
285 na = (struct nlattr *)GENLMSG_DATA(msg);
288 while (len < resp_len) {
289 len += NLA_ALIGN(na->nla_len);
290 if (na->nla_type == NFC_ATTR_DEVICE_POWERED)
291 return *(char *)NLA_DATA(na);
292 na = (struct nlattr *)(GENLMSG_DATA(msg) + len);
309 FIXTURE_VARIANT(NCI) {
313 FIXTURE_VARIANT_ADD(NCI, NCI1_0) {
317 FIXTURE_VARIANT_ADD(NCI, NCI2_0) {
321 static void *virtual_dev_open(void *data)
327 dev_fd = *(int *)data;
329 len = read(dev_fd, buf, 258);
332 if (len != sizeof(nci_reset_cmd))
334 if (memcmp(nci_reset_cmd, buf, len))
336 write(dev_fd, nci_reset_rsp, sizeof(nci_reset_rsp));
338 len = read(dev_fd, buf, 258);
341 if (len != sizeof(nci_init_cmd))
343 if (memcmp(nci_init_cmd, buf, len))
345 write(dev_fd, nci_init_rsp, sizeof(nci_init_rsp));
347 len = read(dev_fd, buf, 258);
350 if (len != sizeof(nci_rf_disc_map_cmd))
352 if (memcmp(nci_rf_disc_map_cmd, buf, len))
354 write(dev_fd, nci_rf_disc_map_rsp, sizeof(nci_rf_disc_map_rsp));
361 static void *virtual_dev_open_v2(void *data)
367 dev_fd = *(int *)data;
369 len = read(dev_fd, buf, 258);
372 if (len != sizeof(nci_reset_cmd))
374 if (memcmp(nci_reset_cmd, buf, len))
376 write(dev_fd, nci_reset_rsp_v2, sizeof(nci_reset_rsp_v2));
377 write(dev_fd, nci_reset_ntf, sizeof(nci_reset_ntf));
379 len = read(dev_fd, buf, 258);
382 if (len != sizeof(nci_init_cmd_v2))
384 if (memcmp(nci_init_cmd_v2, buf, len))
386 write(dev_fd, nci_init_rsp_v2, sizeof(nci_init_rsp_v2));
388 len = read(dev_fd, buf, 258);
391 if (len != sizeof(nci_rf_disc_map_cmd))
393 if (memcmp(nci_rf_disc_map_cmd, buf, len))
395 write(dev_fd, nci_rf_disc_map_rsp, sizeof(nci_rf_disc_map_rsp));
404 struct msgtemplate msg;
410 self->open_state = false;
411 self->proto = VIRTUAL_NFC_PROTOCOLS;
412 self->isNCI2 = variant->isNCI2;
414 self->sd = create_nl_socket();
415 ASSERT_NE(self->sd, -1);
417 self->pid = getpid();
418 self->fid = get_family_id(self->sd, self->pid, &event_group);
419 ASSERT_NE(self->fid, -1);
421 self->virtual_nci_fd = open("/dev/virtual_nci", O_RDWR);
422 ASSERT_GT(self->virtual_nci_fd, -1);
424 rc = setsockopt(self->sd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &event_group,
425 sizeof(event_group));
428 rc = ioctl(self->virtual_nci_fd, IOCTL_GET_NCIDEV_IDX, &self->dev_idex);
431 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex, &msg);
433 EXPECT_EQ(get_dev_enable_state(&msg), 0);
436 rc = pthread_create(&thread_t, NULL, virtual_dev_open_v2,
437 (void *)&self->virtual_nci_fd);
439 rc = pthread_create(&thread_t, NULL, virtual_dev_open,
440 (void *)&self->virtual_nci_fd);
443 rc = send_cmd_with_idx(self->sd, self->fid, self->pid,
444 NFC_CMD_DEV_UP, self->dev_idex);
447 pthread_join(thread_t, (void **)&status);
448 ASSERT_EQ(status, 0);
449 self->open_state = true;
452 static void *virtual_deinit(void *data)
458 dev_fd = *(int *)data;
460 len = read(dev_fd, buf, 258);
463 if (len != sizeof(nci_reset_cmd))
465 if (memcmp(nci_reset_cmd, buf, len))
467 write(dev_fd, nci_reset_rsp, sizeof(nci_reset_rsp));
474 static void *virtual_deinit_v2(void *data)
480 dev_fd = *(int *)data;
482 len = read(dev_fd, buf, 258);
485 if (len != sizeof(nci_reset_cmd))
487 if (memcmp(nci_reset_cmd, buf, len))
489 write(dev_fd, nci_reset_rsp_v2, sizeof(nci_reset_rsp_v2));
490 write(dev_fd, nci_reset_ntf, sizeof(nci_reset_ntf));
497 FIXTURE_TEARDOWN(NCI)
503 if (self->open_state) {
505 rc = pthread_create(&thread_t, NULL,
507 (void *)&self->virtual_nci_fd);
509 rc = pthread_create(&thread_t, NULL, virtual_deinit,
510 (void *)&self->virtual_nci_fd);
513 rc = send_cmd_with_idx(self->sd, self->fid, self->pid,
514 NFC_CMD_DEV_DOWN, self->dev_idex);
517 pthread_join(thread_t, (void **)&status);
518 ASSERT_EQ(status, 0);
522 close(self->virtual_nci_fd);
523 self->open_state = false;
528 struct msgtemplate msg;
531 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex,
534 EXPECT_EQ(get_dev_enable_state(&msg), 1);
537 static void *virtual_poll_start(void *data)
543 dev_fd = *(int *)data;
545 len = read(dev_fd, buf, 258);
548 if (len != sizeof(nci_rf_discovery_cmd))
550 if (memcmp(nci_rf_discovery_cmd, buf, len))
552 write(dev_fd, nci_rf_disc_rsp, sizeof(nci_rf_disc_rsp));
559 static void *virtual_poll_stop(void *data)
565 dev_fd = *(int *)data;
567 len = read(dev_fd, buf, 258);
570 if (len != sizeof(nci_rf_deact_cmd))
572 if (memcmp(nci_rf_deact_cmd, buf, len))
574 write(dev_fd, nci_rf_deact_rsp, sizeof(nci_rf_deact_rsp));
581 int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pid)
583 __u16 nla_start_poll_type[2] = {NFC_ATTR_DEVICE_INDEX,
585 void *nla_start_poll_data[2] = {&dev_idx, &proto};
586 int nla_start_poll_len[2] = {4, 4};
591 rc = pthread_create(&thread_t, NULL, virtual_poll_start,
592 (void *)&virtual_fd);
596 rc = send_cmd_mt_nla(sd, fid, pid, NFC_CMD_START_POLL, 2, nla_start_poll_type,
597 nla_start_poll_data, nla_start_poll_len, NLM_F_REQUEST);
601 pthread_join(thread_t, (void **)&status);
605 int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid)
611 rc = pthread_create(&thread_t, NULL, virtual_poll_stop,
612 (void *)&virtual_fd);
616 rc = send_cmd_with_idx(sd, fid, pid,
617 NFC_CMD_STOP_POLL, dev_idx);
621 pthread_join(thread_t, (void **)&status);
625 TEST_F(NCI, start_poll)
629 status = start_polling(self->dev_idex, self->proto, self->virtual_nci_fd,
630 self->sd, self->fid, self->pid);
631 EXPECT_EQ(status, 0);
633 status = stop_polling(self->dev_idex, self->virtual_nci_fd, self->sd,
634 self->fid, self->pid);
635 EXPECT_EQ(status, 0);
638 int get_taginfo(int dev_idx, int sd, int fid, int pid)
654 void *tagid_type_data;
657 tagid_type = NFC_ATTR_DEVICE_INDEX;
658 tagid_type_data = &dev_idx;
661 send_cmd_mt_nla(sd, fid, pid, NFC_CMD_GET_TARGET, 1, &tagid_type,
662 &tagid_type_data, &tagid_len, NLM_F_REQUEST | NLM_F_DUMP);
663 resp_len = recv(sd, &ans, sizeof(ans), 0);
664 if (ans.n.nlmsg_type == NLMSG_ERROR || resp_len < 0 ||
665 !NLMSG_OK(&ans.n, resp_len))
668 resp_len = GENLMSG_PAYLOAD(&ans.n);
669 na = (struct nlattr *)GENLMSG_DATA(&ans);
676 while (len < resp_len) {
677 len += NLA_ALIGN(na->nla_len);
679 if (na->nla_type == NFC_ATTR_TARGET_INDEX)
680 targetidx = *(int *)((char *)na + NLA_HDRLEN);
681 else if (na->nla_type == NFC_ATTR_TARGET_SEL_RES)
682 sel_res = *(__u8 *)((char *)na + NLA_HDRLEN);
683 else if (na->nla_type == NFC_ATTR_PROTOCOLS)
684 protocol = *(__u32 *)((char *)na + NLA_HDRLEN);
686 na = (struct nlattr *)(GENLMSG_DATA(&ans) + len);
689 if (targetidx == -1 || sel_res != 0x20 || protocol != NFC_PROTO_ISO14443_MASK)
695 int connect_socket(int dev_idx, int target_idx)
697 struct sockaddr_nfc addr;
701 sock = socket(AF_NFC, SOCK_SEQPACKET, NFC_SOCKPROTO_RAW);
705 addr.sa_family = AF_NFC;
706 addr.dev_idx = dev_idx;
707 addr.target_idx = target_idx;
708 addr.nfc_protocol = NFC_PROTO_ISO14443;
710 err = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
719 int connect_tag(int dev_idx, int virtual_fd, int sd, int fid, int pid)
721 struct genlmsghdr *genlhdr;
728 write(virtual_fd, nci_rf_activate_ntf, sizeof(nci_rf_activate_ntf));
729 resp_len = recv(sd, evt_data, sizeof(evt_data), 0);
733 genlhdr = (struct genlmsghdr *)((struct nlmsghdr *)evt_data + 1);
734 na = (struct nlattr *)(genlhdr + 1);
735 evt_dev = *(int *)((char *)na + NLA_HDRLEN);
736 if (dev_idx != evt_dev)
739 target_idx = get_taginfo(dev_idx, sd, fid, pid);
740 if (target_idx == -1)
742 return connect_socket(dev_idx, target_idx);
745 int read_write_nci_cmd(int nfc_sock, int virtual_fd, const __u8 *cmd, __u32 cmd_len,
746 const __u8 *rsp, __u32 rsp_len)
751 send(nfc_sock, &cmd[3], cmd_len - 3, 0);
752 len = read(virtual_fd, buf, cmd_len);
753 if (len < 0 || memcmp(buf, cmd, cmd_len))
756 write(virtual_fd, rsp, rsp_len);
757 len = recv(nfc_sock, buf, rsp_len - 2, 0);
758 if (len < 0 || memcmp(&buf[1], &rsp[3], rsp_len - 3))
764 int read_tag(int nfc_sock, int virtual_fd)
766 if (read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_select_cmd,
767 sizeof(nci_t4t_select_cmd), nci_t4t_rsp_ok,
768 sizeof(nci_t4t_rsp_ok)))
771 if (read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_select_cmd2,
772 sizeof(nci_t4t_select_cmd2), nci_t4t_rsp_ok,
773 sizeof(nci_t4t_rsp_ok)))
776 if (read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_read_cmd,
777 sizeof(nci_t4t_read_cmd), nci_t4t_read_rsp,
778 sizeof(nci_t4t_read_rsp)))
781 if (read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_select_cmd3,
782 sizeof(nci_t4t_select_cmd3), nci_t4t_rsp_ok,
783 sizeof(nci_t4t_rsp_ok)))
786 if (read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_read_cmd2,
787 sizeof(nci_t4t_read_cmd2), nci_t4t_read_rsp2,
788 sizeof(nci_t4t_read_rsp2)))
791 return read_write_nci_cmd(nfc_sock, virtual_fd, nci_t4t_read_cmd3,
792 sizeof(nci_t4t_read_cmd3), nci_t4t_read_rsp3,
793 sizeof(nci_t4t_read_rsp3));
796 static void *virtual_deactivate_proc(void *data)
803 virtual_fd = *(int *)data;
804 deactcmd_len = sizeof(nci_rf_deact_cmd);
805 len = read(virtual_fd, buf, deactcmd_len);
806 if (len != deactcmd_len || memcmp(buf, nci_rf_deact_cmd, deactcmd_len))
809 write(virtual_fd, nci_rf_deact_rsp, sizeof(nci_rf_deact_rsp));
810 write(virtual_fd, nci_rf_deact_ntf, sizeof(nci_rf_deact_ntf));
815 int disconnect_tag(int nfc_sock, int virtual_fd)
822 send(nfc_sock, &nci_t4t_select_cmd3[3], sizeof(nci_t4t_select_cmd3) - 3, 0);
823 len = read(virtual_fd, buf, sizeof(nci_t4t_select_cmd3));
824 if (len < 0 || memcmp(buf, nci_t4t_select_cmd3, sizeof(nci_t4t_select_cmd3)))
827 len = recv(nfc_sock, buf, sizeof(nci_t4t_rsp_ok), 0);
831 status = pthread_create(&thread_t, NULL, virtual_deactivate_proc,
832 (void *)&virtual_fd);
835 pthread_join(thread_t, (void **)&status);
839 TEST_F(NCI, t4t_tag_read)
844 status = start_polling(self->dev_idex, self->proto, self->virtual_nci_fd,
845 self->sd, self->fid, self->pid);
846 EXPECT_EQ(status, 0);
848 nfc_sock = connect_tag(self->dev_idex, self->virtual_nci_fd, self->sd,
849 self->fid, self->pid);
850 ASSERT_GT(nfc_sock, -1);
852 status = read_tag(nfc_sock, self->virtual_nci_fd);
853 ASSERT_EQ(status, 0);
855 status = disconnect_tag(nfc_sock, self->virtual_nci_fd);
856 EXPECT_EQ(status, 0);
861 struct msgtemplate msg;
866 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex,
869 EXPECT_EQ(get_dev_enable_state(&msg), 1);
872 rc = pthread_create(&thread_t, NULL, virtual_deinit_v2,
873 (void *)&self->virtual_nci_fd);
875 rc = pthread_create(&thread_t, NULL, virtual_deinit,
876 (void *)&self->virtual_nci_fd);
879 rc = send_cmd_with_idx(self->sd, self->fid, self->pid,
880 NFC_CMD_DEV_DOWN, self->dev_idex);
883 pthread_join(thread_t, (void **)&status);
884 self->open_state = 0;
885 ASSERT_EQ(status, 0);
887 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex,
890 EXPECT_EQ(get_dev_enable_state(&msg), 0);