2 * Copyright (C) 2011 Instituto Nokia de Tecnologia
5 * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
6 * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
8 * Vendor commands implementation based on net/wireless/nl80211.c
11 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
12 * Copyright 2013-2014 Intel Mobile Communications GmbH
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
30 #include <net/genetlink.h>
31 #include <linux/nfc.h>
32 #include <linux/slab.h>
37 static const struct genl_multicast_group nfc_genl_mcgrps[] = {
38 { .name = NFC_GENL_MCAST_EVENT_NAME, },
41 static struct genl_family nfc_genl_family;
42 static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
43 [NFC_ATTR_DEVICE_INDEX] = { .type = NLA_U32 },
44 [NFC_ATTR_DEVICE_NAME] = { .type = NLA_STRING,
45 .len = NFC_DEVICE_NAME_MAXSIZE },
46 [NFC_ATTR_PROTOCOLS] = { .type = NLA_U32 },
47 [NFC_ATTR_TARGET_INDEX] = { .type = NLA_U32 },
48 [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 },
49 [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
50 [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
51 [NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
52 [NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
53 [NFC_ATTR_LLC_PARAM_LTO] = { .type = NLA_U8 },
54 [NFC_ATTR_LLC_PARAM_RW] = { .type = NLA_U8 },
55 [NFC_ATTR_LLC_PARAM_MIUX] = { .type = NLA_U16 },
56 [NFC_ATTR_LLC_SDP] = { .type = NLA_NESTED },
57 [NFC_ATTR_FIRMWARE_NAME] = { .type = NLA_STRING,
58 .len = NFC_FIRMWARE_NAME_MAXSIZE },
59 [NFC_ATTR_SE_INDEX] = { .type = NLA_U32 },
60 [NFC_ATTR_SE_APDU] = { .type = NLA_BINARY },
61 [NFC_ATTR_VENDOR_ID] = { .type = NLA_U32 },
62 [NFC_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
63 [NFC_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
67 static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX + 1] = {
68 [NFC_SDP_ATTR_URI] = { .type = NLA_STRING,
70 [NFC_SDP_ATTR_SAP] = { .type = NLA_U8 },
73 static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
74 struct netlink_callback *cb, int flags)
78 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
79 &nfc_genl_family, flags, NFC_CMD_GET_TARGET);
83 genl_dump_check_consistent(cb, hdr);
85 if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) ||
86 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) ||
87 nla_put_u16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res) ||
88 nla_put_u8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res))
90 if (target->nfcid1_len > 0 &&
91 nla_put(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len,
94 if (target->sensb_res_len > 0 &&
95 nla_put(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len,
98 if (target->sensf_res_len > 0 &&
99 nla_put(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len,
101 goto nla_put_failure;
103 if (target->is_iso15693) {
104 if (nla_put_u8(msg, NFC_ATTR_TARGET_ISO15693_DSFID,
105 target->iso15693_dsfid) ||
106 nla_put(msg, NFC_ATTR_TARGET_ISO15693_UID,
107 sizeof(target->iso15693_uid), target->iso15693_uid))
108 goto nla_put_failure;
111 genlmsg_end(msg, hdr);
115 genlmsg_cancel(msg, hdr);
119 static struct nfc_dev *__get_device_from_cb(struct netlink_callback *cb)
121 struct nlattr **attrbuf = genl_family_attrbuf(&nfc_genl_family);
126 rc = nlmsg_parse(cb->nlh, GENL_HDRLEN + nfc_genl_family.hdrsize,
127 attrbuf, nfc_genl_family.maxattr, nfc_genl_policy,
132 if (!attrbuf[NFC_ATTR_DEVICE_INDEX])
133 return ERR_PTR(-EINVAL);
135 idx = nla_get_u32(attrbuf[NFC_ATTR_DEVICE_INDEX]);
137 dev = nfc_get_device(idx);
139 return ERR_PTR(-ENODEV);
144 static int nfc_genl_dump_targets(struct sk_buff *skb,
145 struct netlink_callback *cb)
148 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
152 dev = __get_device_from_cb(cb);
156 cb->args[1] = (long) dev;
159 device_lock(&dev->dev);
161 cb->seq = dev->targets_generation;
163 while (i < dev->n_targets) {
164 rc = nfc_genl_send_target(skb, &dev->targets[i], cb,
172 device_unlock(&dev->dev);
179 static int nfc_genl_dump_targets_done(struct netlink_callback *cb)
181 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
189 int nfc_genl_targets_found(struct nfc_dev *dev)
194 dev->genl_data.poll_req_portid = 0;
196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
200 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
201 NFC_EVENT_TARGETS_FOUND);
205 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
206 goto nla_put_failure;
208 genlmsg_end(msg, hdr);
210 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
218 int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
223 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
227 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
228 NFC_EVENT_TARGET_LOST);
232 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
233 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
234 goto nla_put_failure;
236 genlmsg_end(msg, hdr);
238 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
248 int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
257 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
258 NFC_EVENT_TM_ACTIVATED);
262 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
263 goto nla_put_failure;
264 if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
265 goto nla_put_failure;
267 genlmsg_end(msg, hdr);
269 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
279 int nfc_genl_tm_deactivated(struct nfc_dev *dev)
284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
288 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
289 NFC_EVENT_TM_DEACTIVATED);
293 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
294 goto nla_put_failure;
296 genlmsg_end(msg, hdr);
298 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
308 static int nfc_genl_setup_device_added(struct nfc_dev *dev, struct sk_buff *msg)
310 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
311 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
312 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
313 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
314 nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
319 int nfc_genl_device_added(struct nfc_dev *dev)
324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
328 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
329 NFC_EVENT_DEVICE_ADDED);
333 if (nfc_genl_setup_device_added(dev, msg))
334 goto nla_put_failure;
336 genlmsg_end(msg, hdr);
338 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
348 int nfc_genl_device_removed(struct nfc_dev *dev)
353 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
357 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
358 NFC_EVENT_DEVICE_REMOVED);
362 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
363 goto nla_put_failure;
365 genlmsg_end(msg, hdr);
367 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
377 int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
380 struct nlattr *sdp_attr, *uri_attr;
381 struct nfc_llcp_sdp_tlv *sdres;
382 struct hlist_node *n;
387 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
391 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
392 NFC_EVENT_LLC_SDRES);
396 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
397 goto nla_put_failure;
399 sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP);
400 if (sdp_attr == NULL) {
402 goto nla_put_failure;
406 hlist_for_each_entry_safe(sdres, n, sdres_list, node) {
407 pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap);
409 uri_attr = nla_nest_start(msg, i++);
410 if (uri_attr == NULL) {
412 goto nla_put_failure;
415 if (nla_put_u8(msg, NFC_SDP_ATTR_SAP, sdres->sap))
416 goto nla_put_failure;
418 if (nla_put_string(msg, NFC_SDP_ATTR_URI, sdres->uri))
419 goto nla_put_failure;
421 nla_nest_end(msg, uri_attr);
423 hlist_del(&sdres->node);
425 nfc_llcp_free_sdp_tlv(sdres);
428 nla_nest_end(msg, sdp_attr);
430 genlmsg_end(msg, hdr);
432 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
438 nfc_llcp_free_sdp_tlv_list(sdres_list);
443 int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
448 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
452 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
457 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
458 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
459 nla_put_u8(msg, NFC_ATTR_SE_TYPE, type))
460 goto nla_put_failure;
462 genlmsg_end(msg, hdr);
464 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
474 int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
483 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
484 NFC_EVENT_SE_REMOVED);
488 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
489 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx))
490 goto nla_put_failure;
492 genlmsg_end(msg, hdr);
494 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
504 int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
505 struct nfc_evt_transaction *evt_transaction)
511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
515 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
516 NFC_EVENT_SE_TRANSACTION);
520 se = nfc_find_se(dev, se_idx);
524 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
525 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
526 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type) ||
527 nla_put(msg, NFC_ATTR_SE_AID, evt_transaction->aid_len,
528 evt_transaction->aid) ||
529 nla_put(msg, NFC_ATTR_SE_PARAMS, evt_transaction->params_len,
530 evt_transaction->params))
531 goto nla_put_failure;
533 /* evt_transaction is no more used */
534 devm_kfree(&dev->dev, evt_transaction);
536 genlmsg_end(msg, hdr);
538 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
544 /* evt_transaction is no more used */
545 devm_kfree(&dev->dev, evt_transaction);
550 int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx)
556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
560 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
561 NFC_EVENT_SE_CONNECTIVITY);
565 se = nfc_find_se(dev, se_idx);
569 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
570 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
571 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
572 goto nla_put_failure;
574 genlmsg_end(msg, hdr);
576 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
586 static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
588 struct netlink_callback *cb,
593 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
599 genl_dump_check_consistent(cb, hdr);
601 if (nfc_genl_setup_device_added(dev, msg))
602 goto nla_put_failure;
604 genlmsg_end(msg, hdr);
608 genlmsg_cancel(msg, hdr);
612 static int nfc_genl_dump_devices(struct sk_buff *skb,
613 struct netlink_callback *cb)
615 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
616 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
617 bool first_call = false;
621 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
624 cb->args[0] = (long) iter;
627 mutex_lock(&nfc_devlist_mutex);
629 cb->seq = nfc_devlist_generation;
632 nfc_device_iter_init(iter);
633 dev = nfc_device_iter_next(iter);
639 rc = nfc_genl_send_device(skb, dev, NETLINK_CB(cb->skb).portid,
640 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
644 dev = nfc_device_iter_next(iter);
647 mutex_unlock(&nfc_devlist_mutex);
649 cb->args[1] = (long) dev;
654 static int nfc_genl_dump_devices_done(struct netlink_callback *cb)
656 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
658 nfc_device_iter_exit(iter);
664 int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
665 u8 comm_mode, u8 rf_mode)
670 pr_debug("DEP link is up\n");
672 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
676 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, NFC_CMD_DEP_LINK_UP);
680 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
681 goto nla_put_failure;
682 if (rf_mode == NFC_RF_INITIATOR &&
683 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
684 goto nla_put_failure;
685 if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) ||
686 nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode))
687 goto nla_put_failure;
689 genlmsg_end(msg, hdr);
691 dev->dep_link_up = true;
693 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
703 int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
708 pr_debug("DEP link is down\n");
710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
714 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
715 NFC_CMD_DEP_LINK_DOWN);
719 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
720 goto nla_put_failure;
722 genlmsg_end(msg, hdr);
724 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
734 static int nfc_genl_get_device(struct sk_buff *skb, struct genl_info *info)
741 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
744 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
746 dev = nfc_get_device(idx);
750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
756 rc = nfc_genl_send_device(msg, dev, info->snd_portid, info->snd_seq,
763 return genlmsg_reply(msg, info);
772 static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
778 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
781 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
783 dev = nfc_get_device(idx);
787 rc = nfc_dev_up(dev);
793 static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
799 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
802 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
804 dev = nfc_get_device(idx);
808 rc = nfc_dev_down(dev);
814 static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
819 u32 im_protocols = 0, tm_protocols = 0;
821 pr_debug("Poll start\n");
823 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
824 ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
825 !info->attrs[NFC_ATTR_PROTOCOLS]) &&
826 !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
829 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
831 if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
832 tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
834 if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
835 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
836 else if (info->attrs[NFC_ATTR_PROTOCOLS])
837 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
839 dev = nfc_get_device(idx);
843 mutex_lock(&dev->genl_data.genl_data_mutex);
845 rc = nfc_start_poll(dev, im_protocols, tm_protocols);
847 dev->genl_data.poll_req_portid = info->snd_portid;
849 mutex_unlock(&dev->genl_data.genl_data_mutex);
855 static int nfc_genl_stop_poll(struct sk_buff *skb, struct genl_info *info)
861 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
864 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
866 dev = nfc_get_device(idx);
870 device_lock(&dev->dev);
873 device_unlock(&dev->dev);
878 device_unlock(&dev->dev);
880 mutex_lock(&dev->genl_data.genl_data_mutex);
882 if (dev->genl_data.poll_req_portid != info->snd_portid) {
887 rc = nfc_stop_poll(dev);
888 dev->genl_data.poll_req_portid = 0;
891 mutex_unlock(&dev->genl_data.genl_data_mutex);
896 static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
899 u32 device_idx, target_idx, protocol;
902 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
903 !info->attrs[NFC_ATTR_TARGET_INDEX] ||
904 !info->attrs[NFC_ATTR_PROTOCOLS])
907 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
909 dev = nfc_get_device(device_idx);
913 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
914 protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
916 nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
917 rc = nfc_activate_target(dev, target_idx, protocol);
923 static int nfc_genl_deactivate_target(struct sk_buff *skb,
924 struct genl_info *info)
927 u32 device_idx, target_idx;
930 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
931 !info->attrs[NFC_ATTR_TARGET_INDEX])
934 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
936 dev = nfc_get_device(device_idx);
940 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
942 rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
948 static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
955 pr_debug("DEP link up\n");
957 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
958 !info->attrs[NFC_ATTR_COMM_MODE])
961 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
962 if (!info->attrs[NFC_ATTR_TARGET_INDEX])
963 tgt_idx = NFC_TARGET_IDX_ANY;
965 tgt_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
967 comm = nla_get_u8(info->attrs[NFC_ATTR_COMM_MODE]);
969 if (comm != NFC_COMM_ACTIVE && comm != NFC_COMM_PASSIVE)
972 dev = nfc_get_device(idx);
976 rc = nfc_dep_link_up(dev, tgt_idx, comm);
983 static int nfc_genl_dep_link_down(struct sk_buff *skb, struct genl_info *info)
989 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
990 !info->attrs[NFC_ATTR_TARGET_INDEX])
993 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
995 dev = nfc_get_device(idx);
999 rc = nfc_dep_link_down(dev);
1001 nfc_put_device(dev);
1005 static int nfc_genl_send_params(struct sk_buff *msg,
1006 struct nfc_llcp_local *local,
1007 u32 portid, u32 seq)
1011 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, 0,
1012 NFC_CMD_LLC_GET_PARAMS);
1016 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, local->dev->idx) ||
1017 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_LTO, local->lto) ||
1018 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_RW, local->rw) ||
1019 nla_put_u16(msg, NFC_ATTR_LLC_PARAM_MIUX, be16_to_cpu(local->miux)))
1020 goto nla_put_failure;
1022 genlmsg_end(msg, hdr);
1026 genlmsg_cancel(msg, hdr);
1030 static int nfc_genl_llc_get_params(struct sk_buff *skb, struct genl_info *info)
1032 struct nfc_dev *dev;
1033 struct nfc_llcp_local *local;
1035 struct sk_buff *msg = NULL;
1038 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1039 !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1042 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1044 dev = nfc_get_device(idx);
1048 device_lock(&dev->dev);
1050 local = nfc_llcp_find_local(dev);
1056 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1062 rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
1065 device_unlock(&dev->dev);
1067 nfc_put_device(dev);
1076 return genlmsg_reply(msg, info);
1079 static int nfc_genl_llc_set_params(struct sk_buff *skb, struct genl_info *info)
1081 struct nfc_dev *dev;
1082 struct nfc_llcp_local *local;
1088 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1089 (!info->attrs[NFC_ATTR_LLC_PARAM_LTO] &&
1090 !info->attrs[NFC_ATTR_LLC_PARAM_RW] &&
1091 !info->attrs[NFC_ATTR_LLC_PARAM_MIUX]))
1094 if (info->attrs[NFC_ATTR_LLC_PARAM_RW]) {
1095 rw = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_RW]);
1097 if (rw > LLCP_MAX_RW)
1101 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) {
1102 miux = nla_get_u16(info->attrs[NFC_ATTR_LLC_PARAM_MIUX]);
1104 if (miux > LLCP_MAX_MIUX)
1108 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1110 dev = nfc_get_device(idx);
1114 device_lock(&dev->dev);
1116 local = nfc_llcp_find_local(dev);
1122 if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
1123 if (dev->dep_link_up) {
1128 local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
1131 if (info->attrs[NFC_ATTR_LLC_PARAM_RW])
1134 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
1135 local->miux = cpu_to_be16(miux);
1138 device_unlock(&dev->dev);
1140 nfc_put_device(dev);
1145 static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
1147 struct nfc_dev *dev;
1148 struct nfc_llcp_local *local;
1149 struct nlattr *attr, *sdp_attrs[NFC_SDP_ATTR_MAX+1];
1154 size_t uri_len, tlvs_len;
1155 struct hlist_head sdreq_list;
1156 struct nfc_llcp_sdp_tlv *sdreq;
1158 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1159 !info->attrs[NFC_ATTR_LLC_SDP])
1162 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1164 dev = nfc_get_device(idx);
1168 device_lock(&dev->dev);
1170 if (dev->dep_link_up == false) {
1175 local = nfc_llcp_find_local(dev);
1181 INIT_HLIST_HEAD(&sdreq_list);
1185 nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) {
1186 rc = nla_parse_nested(sdp_attrs, NFC_SDP_ATTR_MAX, attr,
1187 nfc_sdp_genl_policy, info->extack);
1194 if (!sdp_attrs[NFC_SDP_ATTR_URI])
1197 uri_len = nla_len(sdp_attrs[NFC_SDP_ATTR_URI]);
1201 uri = nla_data(sdp_attrs[NFC_SDP_ATTR_URI]);
1202 if (uri == NULL || *uri == 0)
1205 tid = local->sdreq_next_tid++;
1207 sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len);
1208 if (sdreq == NULL) {
1213 tlvs_len += sdreq->tlv_len;
1215 hlist_add_head(&sdreq->node, &sdreq_list);
1218 if (hlist_empty(&sdreq_list)) {
1223 rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len);
1225 device_unlock(&dev->dev);
1227 nfc_put_device(dev);
1232 static int nfc_genl_fw_download(struct sk_buff *skb, struct genl_info *info)
1234 struct nfc_dev *dev;
1237 char firmware_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
1239 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1242 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1244 dev = nfc_get_device(idx);
1248 nla_strlcpy(firmware_name, info->attrs[NFC_ATTR_FIRMWARE_NAME],
1249 sizeof(firmware_name));
1251 rc = nfc_fw_download(dev, firmware_name);
1253 nfc_put_device(dev);
1257 int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
1260 struct sk_buff *msg;
1263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1267 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1268 NFC_CMD_FW_DOWNLOAD);
1272 if (nla_put_string(msg, NFC_ATTR_FIRMWARE_NAME, firmware_name) ||
1273 nla_put_u32(msg, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS, result) ||
1274 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
1275 goto nla_put_failure;
1277 genlmsg_end(msg, hdr);
1279 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1289 static int nfc_genl_enable_se(struct sk_buff *skb, struct genl_info *info)
1291 struct nfc_dev *dev;
1295 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1296 !info->attrs[NFC_ATTR_SE_INDEX])
1299 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1300 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1302 dev = nfc_get_device(idx);
1306 rc = nfc_enable_se(dev, se_idx);
1308 nfc_put_device(dev);
1312 static int nfc_genl_disable_se(struct sk_buff *skb, struct genl_info *info)
1314 struct nfc_dev *dev;
1318 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1319 !info->attrs[NFC_ATTR_SE_INDEX])
1322 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1323 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1325 dev = nfc_get_device(idx);
1329 rc = nfc_disable_se(dev, se_idx);
1331 nfc_put_device(dev);
1335 static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev,
1336 u32 portid, u32 seq,
1337 struct netlink_callback *cb,
1341 struct nfc_se *se, *n;
1343 list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
1344 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
1347 goto nla_put_failure;
1350 genl_dump_check_consistent(cb, hdr);
1352 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
1353 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) ||
1354 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
1355 goto nla_put_failure;
1357 genlmsg_end(msg, hdr);
1363 genlmsg_cancel(msg, hdr);
1367 static int nfc_genl_dump_ses(struct sk_buff *skb,
1368 struct netlink_callback *cb)
1370 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1371 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
1372 bool first_call = false;
1376 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
1379 cb->args[0] = (long) iter;
1382 mutex_lock(&nfc_devlist_mutex);
1384 cb->seq = nfc_devlist_generation;
1387 nfc_device_iter_init(iter);
1388 dev = nfc_device_iter_next(iter);
1394 rc = nfc_genl_send_se(skb, dev, NETLINK_CB(cb->skb).portid,
1395 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
1399 dev = nfc_device_iter_next(iter);
1402 mutex_unlock(&nfc_devlist_mutex);
1404 cb->args[1] = (long) dev;
1409 static int nfc_genl_dump_ses_done(struct netlink_callback *cb)
1411 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1413 nfc_device_iter_exit(iter);
1419 static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
1420 u8 *apdu, size_t apdu_length,
1421 se_io_cb_t cb, void *cb_context)
1426 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
1428 device_lock(&dev->dev);
1430 if (!device_is_registered(&dev->dev)) {
1440 if (!dev->ops->se_io) {
1445 se = nfc_find_se(dev, se_idx);
1451 if (se->state != NFC_SE_ENABLED) {
1456 rc = dev->ops->se_io(dev, se_idx, apdu,
1457 apdu_length, cb, cb_context);
1460 device_unlock(&dev->dev);
1469 static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
1471 struct se_io_ctx *ctx = context;
1472 struct sk_buff *msg;
1475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1481 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1486 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, ctx->dev_idx) ||
1487 nla_put_u32(msg, NFC_ATTR_SE_INDEX, ctx->se_idx) ||
1488 nla_put(msg, NFC_ATTR_SE_APDU, apdu_len, apdu))
1489 goto nla_put_failure;
1491 genlmsg_end(msg, hdr);
1493 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1507 static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
1509 struct nfc_dev *dev;
1510 struct se_io_ctx *ctx;
1511 u32 dev_idx, se_idx;
1515 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1516 !info->attrs[NFC_ATTR_SE_INDEX] ||
1517 !info->attrs[NFC_ATTR_SE_APDU])
1520 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1521 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1523 dev = nfc_get_device(dev_idx);
1527 if (!dev->ops || !dev->ops->se_io)
1530 apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
1534 apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
1538 ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
1542 ctx->dev_idx = dev_idx;
1543 ctx->se_idx = se_idx;
1545 return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
1548 static int nfc_genl_vendor_cmd(struct sk_buff *skb,
1549 struct genl_info *info)
1551 struct nfc_dev *dev;
1552 struct nfc_vendor_cmd *cmd;
1553 u32 dev_idx, vid, subcmd;
1558 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1559 !info->attrs[NFC_ATTR_VENDOR_ID] ||
1560 !info->attrs[NFC_ATTR_VENDOR_SUBCMD])
1563 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1564 vid = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_ID]);
1565 subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]);
1567 dev = nfc_get_device(dev_idx);
1568 if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds)
1571 if (info->attrs[NFC_ATTR_VENDOR_DATA]) {
1572 data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]);
1573 data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]);
1581 for (i = 0; i < dev->n_vendor_cmds; i++) {
1582 cmd = &dev->vendor_cmds[i];
1584 if (cmd->vendor_id != vid || cmd->subcmd != subcmd)
1587 dev->cur_cmd_info = info;
1588 err = cmd->doit(dev, data, data_len);
1589 dev->cur_cmd_info = NULL;
1596 /* message building helper */
1597 static inline void *nfc_hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1600 /* since there is no private header just add the generic one */
1601 return genlmsg_put(skb, portid, seq, &nfc_genl_family, flags, cmd);
1604 static struct sk_buff *
1605 __nfc_alloc_vendor_cmd_skb(struct nfc_dev *dev, int approxlen,
1606 u32 portid, u32 seq,
1607 enum nfc_attrs attr,
1608 u32 oui, u32 subcmd, gfp_t gfp)
1610 struct sk_buff *skb;
1613 skb = nlmsg_new(approxlen + 100, gfp);
1617 hdr = nfc_hdr_put(skb, portid, seq, 0, NFC_CMD_VENDOR);
1623 if (nla_put_u32(skb, NFC_ATTR_DEVICE_INDEX, dev->idx))
1624 goto nla_put_failure;
1625 if (nla_put_u32(skb, NFC_ATTR_VENDOR_ID, oui))
1626 goto nla_put_failure;
1627 if (nla_put_u32(skb, NFC_ATTR_VENDOR_SUBCMD, subcmd))
1628 goto nla_put_failure;
1630 ((void **)skb->cb)[0] = dev;
1631 ((void **)skb->cb)[1] = hdr;
1640 struct sk_buff *__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev *dev,
1641 enum nfc_attrs attr,
1642 u32 oui, u32 subcmd,
1645 if (WARN_ON(!dev->cur_cmd_info))
1648 return __nfc_alloc_vendor_cmd_skb(dev, approxlen,
1649 dev->cur_cmd_info->snd_portid,
1650 dev->cur_cmd_info->snd_seq, attr,
1651 oui, subcmd, GFP_KERNEL);
1653 EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb);
1655 int nfc_vendor_cmd_reply(struct sk_buff *skb)
1657 struct nfc_dev *dev = ((void **)skb->cb)[0];
1658 void *hdr = ((void **)skb->cb)[1];
1660 /* clear CB data for netlink core to own from now on */
1661 memset(skb->cb, 0, sizeof(skb->cb));
1663 if (WARN_ON(!dev->cur_cmd_info)) {
1668 genlmsg_end(skb, hdr);
1669 return genlmsg_reply(skb, dev->cur_cmd_info);
1671 EXPORT_SYMBOL(nfc_vendor_cmd_reply);
1673 static const struct genl_ops nfc_genl_ops[] = {
1675 .cmd = NFC_CMD_GET_DEVICE,
1676 .doit = nfc_genl_get_device,
1677 .dumpit = nfc_genl_dump_devices,
1678 .done = nfc_genl_dump_devices_done,
1679 .policy = nfc_genl_policy,
1682 .cmd = NFC_CMD_DEV_UP,
1683 .doit = nfc_genl_dev_up,
1684 .policy = nfc_genl_policy,
1687 .cmd = NFC_CMD_DEV_DOWN,
1688 .doit = nfc_genl_dev_down,
1689 .policy = nfc_genl_policy,
1692 .cmd = NFC_CMD_START_POLL,
1693 .doit = nfc_genl_start_poll,
1694 .policy = nfc_genl_policy,
1697 .cmd = NFC_CMD_STOP_POLL,
1698 .doit = nfc_genl_stop_poll,
1699 .policy = nfc_genl_policy,
1702 .cmd = NFC_CMD_DEP_LINK_UP,
1703 .doit = nfc_genl_dep_link_up,
1704 .policy = nfc_genl_policy,
1707 .cmd = NFC_CMD_DEP_LINK_DOWN,
1708 .doit = nfc_genl_dep_link_down,
1709 .policy = nfc_genl_policy,
1712 .cmd = NFC_CMD_GET_TARGET,
1713 .dumpit = nfc_genl_dump_targets,
1714 .done = nfc_genl_dump_targets_done,
1715 .policy = nfc_genl_policy,
1718 .cmd = NFC_CMD_LLC_GET_PARAMS,
1719 .doit = nfc_genl_llc_get_params,
1720 .policy = nfc_genl_policy,
1723 .cmd = NFC_CMD_LLC_SET_PARAMS,
1724 .doit = nfc_genl_llc_set_params,
1725 .policy = nfc_genl_policy,
1728 .cmd = NFC_CMD_LLC_SDREQ,
1729 .doit = nfc_genl_llc_sdreq,
1730 .policy = nfc_genl_policy,
1733 .cmd = NFC_CMD_FW_DOWNLOAD,
1734 .doit = nfc_genl_fw_download,
1735 .policy = nfc_genl_policy,
1738 .cmd = NFC_CMD_ENABLE_SE,
1739 .doit = nfc_genl_enable_se,
1740 .policy = nfc_genl_policy,
1743 .cmd = NFC_CMD_DISABLE_SE,
1744 .doit = nfc_genl_disable_se,
1745 .policy = nfc_genl_policy,
1748 .cmd = NFC_CMD_GET_SE,
1749 .dumpit = nfc_genl_dump_ses,
1750 .done = nfc_genl_dump_ses_done,
1751 .policy = nfc_genl_policy,
1754 .cmd = NFC_CMD_SE_IO,
1755 .doit = nfc_genl_se_io,
1756 .policy = nfc_genl_policy,
1759 .cmd = NFC_CMD_ACTIVATE_TARGET,
1760 .doit = nfc_genl_activate_target,
1761 .policy = nfc_genl_policy,
1764 .cmd = NFC_CMD_VENDOR,
1765 .doit = nfc_genl_vendor_cmd,
1766 .policy = nfc_genl_policy,
1769 .cmd = NFC_CMD_DEACTIVATE_TARGET,
1770 .doit = nfc_genl_deactivate_target,
1771 .policy = nfc_genl_policy,
1775 static struct genl_family nfc_genl_family __ro_after_init = {
1777 .name = NFC_GENL_NAME,
1778 .version = NFC_GENL_VERSION,
1779 .maxattr = NFC_ATTR_MAX,
1780 .module = THIS_MODULE,
1781 .ops = nfc_genl_ops,
1782 .n_ops = ARRAY_SIZE(nfc_genl_ops),
1783 .mcgrps = nfc_genl_mcgrps,
1784 .n_mcgrps = ARRAY_SIZE(nfc_genl_mcgrps),
1788 struct urelease_work {
1789 struct work_struct w;
1793 static void nfc_urelease_event_work(struct work_struct *work)
1795 struct urelease_work *w = container_of(work, struct urelease_work, w);
1796 struct class_dev_iter iter;
1797 struct nfc_dev *dev;
1799 pr_debug("portid %d\n", w->portid);
1801 mutex_lock(&nfc_devlist_mutex);
1803 nfc_device_iter_init(&iter);
1804 dev = nfc_device_iter_next(&iter);
1807 mutex_lock(&dev->genl_data.genl_data_mutex);
1809 if (dev->genl_data.poll_req_portid == w->portid) {
1811 dev->genl_data.poll_req_portid = 0;
1814 mutex_unlock(&dev->genl_data.genl_data_mutex);
1816 dev = nfc_device_iter_next(&iter);
1819 nfc_device_iter_exit(&iter);
1821 mutex_unlock(&nfc_devlist_mutex);
1826 static int nfc_genl_rcv_nl_event(struct notifier_block *this,
1827 unsigned long event, void *ptr)
1829 struct netlink_notify *n = ptr;
1830 struct urelease_work *w;
1832 if (event != NETLINK_URELEASE || n->protocol != NETLINK_GENERIC)
1835 pr_debug("NETLINK_URELEASE event from id %d\n", n->portid);
1837 w = kmalloc(sizeof(*w), GFP_ATOMIC);
1839 INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
1840 w->portid = n->portid;
1841 schedule_work((struct work_struct *) w);
1848 void nfc_genl_data_init(struct nfc_genl_data *genl_data)
1850 genl_data->poll_req_portid = 0;
1851 mutex_init(&genl_data->genl_data_mutex);
1854 void nfc_genl_data_exit(struct nfc_genl_data *genl_data)
1856 mutex_destroy(&genl_data->genl_data_mutex);
1859 static struct notifier_block nl_notifier = {
1860 .notifier_call = nfc_genl_rcv_nl_event,
1864 * nfc_genl_init() - Initialize netlink interface
1866 * This initialization function registers the nfc netlink family.
1868 int __init nfc_genl_init(void)
1872 rc = genl_register_family(&nfc_genl_family);
1876 netlink_register_notifier(&nl_notifier);
1882 * nfc_genl_exit() - Deinitialize netlink interface
1884 * This exit function unregisters the nfc netlink family.
1886 void nfc_genl_exit(void)
1888 netlink_unregister_notifier(&nl_notifier);
1889 genl_unregister_family(&nfc_genl_family);