Lines Matching +full:local +full:- +full:pid

1 // SPDX-License-Identifier: GPL-2.0-only
22 #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
24 #define NLA_PAYLOAD(len) ((len) - NLA_HDRLEN)
93 struct sockaddr_nl local; in create_nl_socket() local
97 return -1; in create_nl_socket()
99 memset(&local, 0, sizeof(local)); in create_nl_socket()
100 local.nl_family = AF_NETLINK; in create_nl_socket()
102 if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) in create_nl_socket()
108 return -1; in create_nl_socket()
133 na->nla_type = nla_type[cnt]; in send_cmd_mt_nla()
134 na->nla_len = nla_len[cnt] + NLA_HDRLEN; in send_cmd_mt_nla()
152 buflen -= r; in send_cmd_mt_nla()
154 return -1; in send_cmd_mt_nla()
160 static int send_get_nfc_family(int sd, __u32 pid) in send_get_nfc_family() argument
171 return send_cmd_mt_nla(sd, GENL_ID_CTRL, pid, CTRL_CMD_GETFAMILY, in send_get_nfc_family()
176 static int get_family_id(int sd, __u32 pid, __u32 *event_group) in get_family_id() argument
189 rc = send_get_nfc_family(sd, pid); in get_family_id()
205 len += NLA_ALIGN(na->nla_len); in get_family_id()
206 if (na->nla_type == CTRL_ATTR_FAMILY_ID) { in get_family_id()
208 } else if (na->nla_type == CTRL_ATTR_MCAST_GROUPS) { in get_family_id()
220 if (group_na->nla_type == CTRL_ATTR_MCAST_GRP_ID) { in get_family_id()
226 group_attr_len += NLA_ALIGN(group_na->nla_len) + in get_family_id()
228 if (group_attr_len >= nested_na->nla_len) in get_family_id()
232 NLA_ALIGN(group_na->nla_len)); in get_family_id()
251 static int get_nci_devid(int sd, __u16 fid, __u32 pid, int dev_id, struct msgtemplate *msg) in get_nci_devid() argument
255 rc = send_cmd_with_idx(sd, fid, pid, NFC_CMD_GET_DEVICE, dev_id); in get_nci_devid()
257 rc = -1; in get_nci_devid()
263 rc = -2; in get_nci_devid()
267 if (msg->n.nlmsg_type == NLMSG_ERROR || in get_nci_devid()
268 !NLMSG_OK(&msg->n, resp_len)) { in get_nci_devid()
269 rc = -3; in get_nci_devid()
284 resp_len = GENLMSG_PAYLOAD(&msg->n); in get_dev_enable_state()
289 len += NLA_ALIGN(na->nla_len); in get_dev_enable_state()
290 if (na->nla_type == NFC_ATTR_DEVICE_POWERED) in get_dev_enable_state()
304 __u32 pid; in FIXTURE() local
358 return (void *)-1; in virtual_dev_open()
399 return (void *)-1; in virtual_dev_open_v2()
410 self->open_state = false; in FIXTURE_SETUP()
411 self->proto = VIRTUAL_NFC_PROTOCOLS; in FIXTURE_SETUP()
412 self->isNCI2 = variant->isNCI2; in FIXTURE_SETUP()
414 self->sd = create_nl_socket(); in FIXTURE_SETUP()
415 ASSERT_NE(self->sd, -1); in FIXTURE_SETUP()
417 self->pid = getpid(); in FIXTURE_SETUP()
418 self->fid = get_family_id(self->sd, self->pid, &event_group); in FIXTURE_SETUP()
419 ASSERT_NE(self->fid, -1); in FIXTURE_SETUP()
421 self->virtual_nci_fd = open("/dev/virtual_nci", O_RDWR); in FIXTURE_SETUP()
422 ASSERT_GT(self->virtual_nci_fd, -1); in FIXTURE_SETUP()
424 rc = setsockopt(self->sd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &event_group, in FIXTURE_SETUP()
426 ASSERT_NE(rc, -1); in FIXTURE_SETUP()
428 rc = ioctl(self->virtual_nci_fd, IOCTL_GET_NCIDEV_IDX, &self->dev_idex); in FIXTURE_SETUP()
431 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex, &msg); in FIXTURE_SETUP()
435 if (self->isNCI2) in FIXTURE_SETUP()
437 (void *)&self->virtual_nci_fd); in FIXTURE_SETUP()
440 (void *)&self->virtual_nci_fd); in FIXTURE_SETUP()
441 ASSERT_GT(rc, -1); in FIXTURE_SETUP()
443 rc = send_cmd_with_idx(self->sd, self->fid, self->pid, in FIXTURE_SETUP()
444 NFC_CMD_DEV_UP, self->dev_idex); in FIXTURE_SETUP()
449 self->open_state = true; in FIXTURE_SETUP()
471 return (void *)-1; in virtual_deinit()
494 return (void *)-1; in virtual_deinit_v2()
503 if (self->open_state) { in FIXTURE_TEARDOWN()
504 if (self->isNCI2) in FIXTURE_TEARDOWN()
507 (void *)&self->virtual_nci_fd); in FIXTURE_TEARDOWN()
510 (void *)&self->virtual_nci_fd); in FIXTURE_TEARDOWN()
512 ASSERT_GT(rc, -1); in FIXTURE_TEARDOWN()
513 rc = send_cmd_with_idx(self->sd, self->fid, self->pid, in FIXTURE_TEARDOWN()
514 NFC_CMD_DEV_DOWN, self->dev_idex); in FIXTURE_TEARDOWN()
521 close(self->sd); in FIXTURE_TEARDOWN()
522 close(self->virtual_nci_fd); in FIXTURE_TEARDOWN()
523 self->open_state = false; in FIXTURE_TEARDOWN()
531 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex, in TEST_F()
556 return (void *)-1; in virtual_poll_start()
578 return (void *)-1; in virtual_poll_stop()
581 int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pid) in start_polling() argument
596 rc = send_cmd_mt_nla(sd, fid, pid, NFC_CMD_START_POLL, 2, nla_start_poll_type, in start_polling()
605 int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid) in stop_polling() argument
616 rc = send_cmd_with_idx(sd, fid, pid, in stop_polling()
629 status = start_polling(self->dev_idex, self->proto, self->virtual_nci_fd, in TEST_F()
630 self->sd, self->fid, self->pid); in TEST_F()
633 status = stop_polling(self->dev_idex, self->virtual_nci_fd, self->sd, in TEST_F()
634 self->fid, self->pid); in TEST_F()
638 int get_taginfo(int dev_idx, int sd, int fid, int pid) in get_taginfo() argument
661 send_cmd_mt_nla(sd, fid, pid, NFC_CMD_GET_TARGET, 1, &tagid_type, in get_taginfo()
666 return -1; in get_taginfo()
672 targetidx = -1; in get_taginfo()
673 protocol = -1; in get_taginfo()
674 sel_res = -1; in get_taginfo()
677 len += NLA_ALIGN(na->nla_len); in get_taginfo()
679 if (na->nla_type == NFC_ATTR_TARGET_INDEX) in get_taginfo()
681 else if (na->nla_type == NFC_ATTR_TARGET_SEL_RES) in get_taginfo()
683 else if (na->nla_type == NFC_ATTR_PROTOCOLS) in get_taginfo()
689 if (targetidx == -1 || sel_res != 0x20 || protocol != NFC_PROTO_ISO14443_MASK) in get_taginfo()
690 return -1; in get_taginfo()
702 if (sock == -1) in connect_socket()
703 return -1; in connect_socket()
713 return -1; in connect_socket()
719 int connect_tag(int dev_idx, int virtual_fd, int sd, int fid, int pid) in connect_tag() argument
731 return -1; in connect_tag()
737 return -1; in connect_tag()
739 target_idx = get_taginfo(dev_idx, sd, fid, pid); in connect_tag()
740 if (target_idx == -1) in connect_tag()
741 return -1; in connect_tag()
751 send(nfc_sock, &cmd[3], cmd_len - 3, 0); in read_write_nci_cmd()
754 return -1; in read_write_nci_cmd()
757 len = recv(nfc_sock, buf, rsp_len - 2, 0); in read_write_nci_cmd()
758 if (len < 0 || memcmp(&buf[1], &rsp[3], rsp_len - 3)) in read_write_nci_cmd()
759 return -1; in read_write_nci_cmd()
769 return -1; in read_tag()
774 return -1; in read_tag()
779 return -1; in read_tag()
784 return -1; in read_tag()
789 return -1; in read_tag()
807 return (void *)-1; in virtual_deactivate_proc()
822 send(nfc_sock, &nci_t4t_select_cmd3[3], sizeof(nci_t4t_select_cmd3) - 3, 0); in disconnect_tag()
825 return -1; in disconnect_tag()
828 if (len != -1) in disconnect_tag()
829 return -1; in disconnect_tag()
844 status = start_polling(self->dev_idex, self->proto, self->virtual_nci_fd, in TEST_F()
845 self->sd, self->fid, self->pid); in TEST_F()
848 nfc_sock = connect_tag(self->dev_idex, self->virtual_nci_fd, self->sd, in TEST_F()
849 self->fid, self->pid); in TEST_F()
850 ASSERT_GT(nfc_sock, -1); in TEST_F()
852 status = read_tag(nfc_sock, self->virtual_nci_fd); in TEST_F()
855 status = disconnect_tag(nfc_sock, self->virtual_nci_fd); in TEST_F()
866 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex, in TEST_F()
871 if (self->isNCI2) in TEST_F()
873 (void *)&self->virtual_nci_fd); in TEST_F()
876 (void *)&self->virtual_nci_fd); in TEST_F()
877 ASSERT_GT(rc, -1); in TEST_F()
879 rc = send_cmd_with_idx(self->sd, self->fid, self->pid, in TEST_F()
880 NFC_CMD_DEV_DOWN, self->dev_idex); in TEST_F()
884 self->open_state = 0; in TEST_F()
887 rc = get_nci_devid(self->sd, self->fid, self->pid, self->dev_idex, in TEST_F()