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_COMM_MODE] = { .type = NLA_U8 },
48 [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
49 [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
50 [NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
51 [NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
52 [NFC_ATTR_LLC_PARAM_LTO] = { .type = NLA_U8 },
53 [NFC_ATTR_LLC_PARAM_RW] = { .type = NLA_U8 },
54 [NFC_ATTR_LLC_PARAM_MIUX] = { .type = NLA_U16 },
55 [NFC_ATTR_LLC_SDP] = { .type = NLA_NESTED },
56 [NFC_ATTR_FIRMWARE_NAME] = { .type = NLA_STRING,
57 .len = NFC_FIRMWARE_NAME_MAXSIZE },
58 [NFC_ATTR_SE_INDEX] = { .type = NLA_U32 },
59 [NFC_ATTR_SE_APDU] = { .type = NLA_BINARY },
60 [NFC_ATTR_VENDOR_ID] = { .type = NLA_U32 },
61 [NFC_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
62 [NFC_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
66 static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX + 1] = {
67 [NFC_SDP_ATTR_URI] = { .type = NLA_STRING,
69 [NFC_SDP_ATTR_SAP] = { .type = NLA_U8 },
72 static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
73 struct netlink_callback *cb, int flags)
77 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
78 &nfc_genl_family, flags, NFC_CMD_GET_TARGET);
82 genl_dump_check_consistent(cb, hdr, &nfc_genl_family);
84 if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) ||
85 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) ||
86 nla_put_u16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res) ||
87 nla_put_u8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res))
89 if (target->nfcid1_len > 0 &&
90 nla_put(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len,
93 if (target->sensb_res_len > 0 &&
94 nla_put(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len,
97 if (target->sensf_res_len > 0 &&
98 nla_put(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len,
100 goto nla_put_failure;
102 if (target->is_iso15693) {
103 if (nla_put_u8(msg, NFC_ATTR_TARGET_ISO15693_DSFID,
104 target->iso15693_dsfid) ||
105 nla_put(msg, NFC_ATTR_TARGET_ISO15693_UID,
106 sizeof(target->iso15693_uid), target->iso15693_uid))
107 goto nla_put_failure;
110 genlmsg_end(msg, hdr);
114 genlmsg_cancel(msg, hdr);
118 static struct nfc_dev *__get_device_from_cb(struct netlink_callback *cb)
120 struct nlattr **attrbuf = genl_family_attrbuf(&nfc_genl_family);
125 rc = nlmsg_parse(cb->nlh, GENL_HDRLEN + nfc_genl_family.hdrsize,
126 attrbuf, nfc_genl_family.maxattr, nfc_genl_policy,
131 if (!attrbuf[NFC_ATTR_DEVICE_INDEX])
132 return ERR_PTR(-EINVAL);
134 idx = nla_get_u32(attrbuf[NFC_ATTR_DEVICE_INDEX]);
136 dev = nfc_get_device(idx);
138 return ERR_PTR(-ENODEV);
143 static int nfc_genl_dump_targets(struct sk_buff *skb,
144 struct netlink_callback *cb)
147 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
151 dev = __get_device_from_cb(cb);
155 cb->args[1] = (long) dev;
158 device_lock(&dev->dev);
160 cb->seq = dev->targets_generation;
162 while (i < dev->n_targets) {
163 rc = nfc_genl_send_target(skb, &dev->targets[i], cb,
171 device_unlock(&dev->dev);
178 static int nfc_genl_dump_targets_done(struct netlink_callback *cb)
180 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
188 int nfc_genl_targets_found(struct nfc_dev *dev)
193 dev->genl_data.poll_req_portid = 0;
195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
199 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
200 NFC_EVENT_TARGETS_FOUND);
204 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
205 goto nla_put_failure;
207 genlmsg_end(msg, hdr);
209 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
212 genlmsg_cancel(msg, hdr);
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);
243 genlmsg_cancel(msg, hdr);
249 int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
258 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
259 NFC_EVENT_TM_ACTIVATED);
263 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
264 goto nla_put_failure;
265 if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
266 goto nla_put_failure;
268 genlmsg_end(msg, hdr);
270 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
275 genlmsg_cancel(msg, hdr);
281 int nfc_genl_tm_deactivated(struct nfc_dev *dev)
286 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
290 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
291 NFC_EVENT_TM_DEACTIVATED);
295 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
296 goto nla_put_failure;
298 genlmsg_end(msg, hdr);
300 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
305 genlmsg_cancel(msg, hdr);
311 static int nfc_genl_setup_device_added(struct nfc_dev *dev, struct sk_buff *msg)
313 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
314 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
315 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
316 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
317 nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
322 int nfc_genl_device_added(struct nfc_dev *dev)
327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
331 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
332 NFC_EVENT_DEVICE_ADDED);
336 if (nfc_genl_setup_device_added(dev, msg))
337 goto nla_put_failure;
339 genlmsg_end(msg, hdr);
341 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
346 genlmsg_cancel(msg, hdr);
352 int nfc_genl_device_removed(struct nfc_dev *dev)
357 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
361 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
362 NFC_EVENT_DEVICE_REMOVED);
366 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
367 goto nla_put_failure;
369 genlmsg_end(msg, hdr);
371 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
376 genlmsg_cancel(msg, hdr);
382 int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
385 struct nlattr *sdp_attr, *uri_attr;
386 struct nfc_llcp_sdp_tlv *sdres;
387 struct hlist_node *n;
392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
396 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
397 NFC_EVENT_LLC_SDRES);
401 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
402 goto nla_put_failure;
404 sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP);
405 if (sdp_attr == NULL) {
407 goto nla_put_failure;
411 hlist_for_each_entry_safe(sdres, n, sdres_list, node) {
412 pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap);
414 uri_attr = nla_nest_start(msg, i++);
415 if (uri_attr == NULL) {
417 goto nla_put_failure;
420 if (nla_put_u8(msg, NFC_SDP_ATTR_SAP, sdres->sap))
421 goto nla_put_failure;
423 if (nla_put_string(msg, NFC_SDP_ATTR_URI, sdres->uri))
424 goto nla_put_failure;
426 nla_nest_end(msg, uri_attr);
428 hlist_del(&sdres->node);
430 nfc_llcp_free_sdp_tlv(sdres);
433 nla_nest_end(msg, sdp_attr);
435 genlmsg_end(msg, hdr);
437 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
440 genlmsg_cancel(msg, hdr);
445 nfc_llcp_free_sdp_tlv_list(sdres_list);
450 int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
459 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
464 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
465 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
466 nla_put_u8(msg, NFC_ATTR_SE_TYPE, type))
467 goto nla_put_failure;
469 genlmsg_end(msg, hdr);
471 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
476 genlmsg_cancel(msg, hdr);
482 int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
491 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
492 NFC_EVENT_SE_REMOVED);
496 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
497 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx))
498 goto nla_put_failure;
500 genlmsg_end(msg, hdr);
502 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
507 genlmsg_cancel(msg, hdr);
513 int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
514 struct nfc_evt_transaction *evt_transaction)
520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
524 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
525 NFC_EVENT_SE_TRANSACTION);
529 se = nfc_find_se(dev, se_idx);
533 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
534 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
535 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type) ||
536 nla_put(msg, NFC_ATTR_SE_AID, evt_transaction->aid_len,
537 evt_transaction->aid) ||
538 nla_put(msg, NFC_ATTR_SE_PARAMS, evt_transaction->params_len,
539 evt_transaction->params))
540 goto nla_put_failure;
542 /* evt_transaction is no more used */
543 devm_kfree(&dev->dev, evt_transaction);
545 genlmsg_end(msg, hdr);
547 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
552 genlmsg_cancel(msg, hdr);
554 /* evt_transaction is no more used */
555 devm_kfree(&dev->dev, evt_transaction);
560 int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx)
566 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
570 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
571 NFC_EVENT_SE_CONNECTIVITY);
575 se = nfc_find_se(dev, se_idx);
579 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
580 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
581 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
582 goto nla_put_failure;
584 genlmsg_end(msg, hdr);
586 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
591 genlmsg_cancel(msg, hdr);
597 static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
599 struct netlink_callback *cb,
604 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
610 genl_dump_check_consistent(cb, hdr, &nfc_genl_family);
612 if (nfc_genl_setup_device_added(dev, msg))
613 goto nla_put_failure;
615 genlmsg_end(msg, hdr);
619 genlmsg_cancel(msg, hdr);
623 static int nfc_genl_dump_devices(struct sk_buff *skb,
624 struct netlink_callback *cb)
626 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
627 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
628 bool first_call = false;
632 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
635 cb->args[0] = (long) iter;
638 mutex_lock(&nfc_devlist_mutex);
640 cb->seq = nfc_devlist_generation;
643 nfc_device_iter_init(iter);
644 dev = nfc_device_iter_next(iter);
650 rc = nfc_genl_send_device(skb, dev, NETLINK_CB(cb->skb).portid,
651 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
655 dev = nfc_device_iter_next(iter);
658 mutex_unlock(&nfc_devlist_mutex);
660 cb->args[1] = (long) dev;
665 static int nfc_genl_dump_devices_done(struct netlink_callback *cb)
667 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
669 nfc_device_iter_exit(iter);
675 int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
676 u8 comm_mode, u8 rf_mode)
681 pr_debug("DEP link is up\n");
683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
687 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, NFC_CMD_DEP_LINK_UP);
691 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
692 goto nla_put_failure;
693 if (rf_mode == NFC_RF_INITIATOR &&
694 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
695 goto nla_put_failure;
696 if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) ||
697 nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode))
698 goto nla_put_failure;
700 genlmsg_end(msg, hdr);
702 dev->dep_link_up = true;
704 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
709 genlmsg_cancel(msg, hdr);
715 int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
720 pr_debug("DEP link is down\n");
722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
726 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
727 NFC_CMD_DEP_LINK_DOWN);
731 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
732 goto nla_put_failure;
734 genlmsg_end(msg, hdr);
736 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
741 genlmsg_cancel(msg, hdr);
747 static int nfc_genl_get_device(struct sk_buff *skb, struct genl_info *info)
754 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
757 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
759 dev = nfc_get_device(idx);
763 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
769 rc = nfc_genl_send_device(msg, dev, info->snd_portid, info->snd_seq,
776 return genlmsg_reply(msg, info);
785 static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
791 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
794 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
796 dev = nfc_get_device(idx);
800 rc = nfc_dev_up(dev);
806 static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
812 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
815 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
817 dev = nfc_get_device(idx);
821 rc = nfc_dev_down(dev);
827 static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
832 u32 im_protocols = 0, tm_protocols = 0;
834 pr_debug("Poll start\n");
836 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
837 ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
838 !info->attrs[NFC_ATTR_PROTOCOLS]) &&
839 !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
842 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
844 if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
845 tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
847 if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
848 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
849 else if (info->attrs[NFC_ATTR_PROTOCOLS])
850 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
852 dev = nfc_get_device(idx);
856 mutex_lock(&dev->genl_data.genl_data_mutex);
858 rc = nfc_start_poll(dev, im_protocols, tm_protocols);
860 dev->genl_data.poll_req_portid = info->snd_portid;
862 mutex_unlock(&dev->genl_data.genl_data_mutex);
868 static int nfc_genl_stop_poll(struct sk_buff *skb, struct genl_info *info)
874 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
877 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
879 dev = nfc_get_device(idx);
883 device_lock(&dev->dev);
886 device_unlock(&dev->dev);
891 device_unlock(&dev->dev);
893 mutex_lock(&dev->genl_data.genl_data_mutex);
895 if (dev->genl_data.poll_req_portid != info->snd_portid) {
900 rc = nfc_stop_poll(dev);
901 dev->genl_data.poll_req_portid = 0;
904 mutex_unlock(&dev->genl_data.genl_data_mutex);
909 static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
912 u32 device_idx, target_idx, protocol;
915 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
916 !info->attrs[NFC_ATTR_TARGET_INDEX] ||
917 !info->attrs[NFC_ATTR_PROTOCOLS])
920 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
922 dev = nfc_get_device(device_idx);
926 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
927 protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
929 nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
930 rc = nfc_activate_target(dev, target_idx, protocol);
936 static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
943 pr_debug("DEP link up\n");
945 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
946 !info->attrs[NFC_ATTR_COMM_MODE])
949 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
950 if (!info->attrs[NFC_ATTR_TARGET_INDEX])
951 tgt_idx = NFC_TARGET_IDX_ANY;
953 tgt_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
955 comm = nla_get_u8(info->attrs[NFC_ATTR_COMM_MODE]);
957 if (comm != NFC_COMM_ACTIVE && comm != NFC_COMM_PASSIVE)
960 dev = nfc_get_device(idx);
964 rc = nfc_dep_link_up(dev, tgt_idx, comm);
971 static int nfc_genl_dep_link_down(struct sk_buff *skb, struct genl_info *info)
977 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
978 !info->attrs[NFC_ATTR_TARGET_INDEX])
981 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
983 dev = nfc_get_device(idx);
987 rc = nfc_dep_link_down(dev);
993 static int nfc_genl_send_params(struct sk_buff *msg,
994 struct nfc_llcp_local *local,
999 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, 0,
1000 NFC_CMD_LLC_GET_PARAMS);
1004 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, local->dev->idx) ||
1005 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_LTO, local->lto) ||
1006 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_RW, local->rw) ||
1007 nla_put_u16(msg, NFC_ATTR_LLC_PARAM_MIUX, be16_to_cpu(local->miux)))
1008 goto nla_put_failure;
1010 genlmsg_end(msg, hdr);
1015 genlmsg_cancel(msg, hdr);
1019 static int nfc_genl_llc_get_params(struct sk_buff *skb, struct genl_info *info)
1021 struct nfc_dev *dev;
1022 struct nfc_llcp_local *local;
1024 struct sk_buff *msg = NULL;
1027 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1028 !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1031 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1033 dev = nfc_get_device(idx);
1037 device_lock(&dev->dev);
1039 local = nfc_llcp_find_local(dev);
1045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1051 rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
1054 device_unlock(&dev->dev);
1056 nfc_put_device(dev);
1065 return genlmsg_reply(msg, info);
1068 static int nfc_genl_llc_set_params(struct sk_buff *skb, struct genl_info *info)
1070 struct nfc_dev *dev;
1071 struct nfc_llcp_local *local;
1077 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1078 (!info->attrs[NFC_ATTR_LLC_PARAM_LTO] &&
1079 !info->attrs[NFC_ATTR_LLC_PARAM_RW] &&
1080 !info->attrs[NFC_ATTR_LLC_PARAM_MIUX]))
1083 if (info->attrs[NFC_ATTR_LLC_PARAM_RW]) {
1084 rw = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_RW]);
1086 if (rw > LLCP_MAX_RW)
1090 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) {
1091 miux = nla_get_u16(info->attrs[NFC_ATTR_LLC_PARAM_MIUX]);
1093 if (miux > LLCP_MAX_MIUX)
1097 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1099 dev = nfc_get_device(idx);
1103 device_lock(&dev->dev);
1105 local = nfc_llcp_find_local(dev);
1111 if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
1112 if (dev->dep_link_up) {
1117 local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
1120 if (info->attrs[NFC_ATTR_LLC_PARAM_RW])
1123 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
1124 local->miux = cpu_to_be16(miux);
1127 device_unlock(&dev->dev);
1129 nfc_put_device(dev);
1134 static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
1136 struct nfc_dev *dev;
1137 struct nfc_llcp_local *local;
1138 struct nlattr *attr, *sdp_attrs[NFC_SDP_ATTR_MAX+1];
1143 size_t uri_len, tlvs_len;
1144 struct hlist_head sdreq_list;
1145 struct nfc_llcp_sdp_tlv *sdreq;
1147 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1148 !info->attrs[NFC_ATTR_LLC_SDP])
1151 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1153 dev = nfc_get_device(idx);
1157 device_lock(&dev->dev);
1159 if (dev->dep_link_up == false) {
1164 local = nfc_llcp_find_local(dev);
1170 INIT_HLIST_HEAD(&sdreq_list);
1174 nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) {
1175 rc = nla_parse_nested(sdp_attrs, NFC_SDP_ATTR_MAX, attr,
1176 nfc_sdp_genl_policy, info->extack);
1183 if (!sdp_attrs[NFC_SDP_ATTR_URI])
1186 uri_len = nla_len(sdp_attrs[NFC_SDP_ATTR_URI]);
1190 uri = nla_data(sdp_attrs[NFC_SDP_ATTR_URI]);
1191 if (uri == NULL || *uri == 0)
1194 tid = local->sdreq_next_tid++;
1196 sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len);
1197 if (sdreq == NULL) {
1202 tlvs_len += sdreq->tlv_len;
1204 hlist_add_head(&sdreq->node, &sdreq_list);
1207 if (hlist_empty(&sdreq_list)) {
1212 rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len);
1214 device_unlock(&dev->dev);
1216 nfc_put_device(dev);
1221 static int nfc_genl_fw_download(struct sk_buff *skb, struct genl_info *info)
1223 struct nfc_dev *dev;
1226 char firmware_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
1228 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1231 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1233 dev = nfc_get_device(idx);
1237 nla_strlcpy(firmware_name, info->attrs[NFC_ATTR_FIRMWARE_NAME],
1238 sizeof(firmware_name));
1240 rc = nfc_fw_download(dev, firmware_name);
1242 nfc_put_device(dev);
1246 int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
1249 struct sk_buff *msg;
1252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1256 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1257 NFC_CMD_FW_DOWNLOAD);
1261 if (nla_put_string(msg, NFC_ATTR_FIRMWARE_NAME, firmware_name) ||
1262 nla_put_u32(msg, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS, result) ||
1263 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
1264 goto nla_put_failure;
1266 genlmsg_end(msg, hdr);
1268 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1273 genlmsg_cancel(msg, hdr);
1279 static int nfc_genl_enable_se(struct sk_buff *skb, struct genl_info *info)
1281 struct nfc_dev *dev;
1285 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1286 !info->attrs[NFC_ATTR_SE_INDEX])
1289 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1290 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1292 dev = nfc_get_device(idx);
1296 rc = nfc_enable_se(dev, se_idx);
1298 nfc_put_device(dev);
1302 static int nfc_genl_disable_se(struct sk_buff *skb, struct genl_info *info)
1304 struct nfc_dev *dev;
1308 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1309 !info->attrs[NFC_ATTR_SE_INDEX])
1312 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1313 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1315 dev = nfc_get_device(idx);
1319 rc = nfc_disable_se(dev, se_idx);
1321 nfc_put_device(dev);
1325 static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev,
1326 u32 portid, u32 seq,
1327 struct netlink_callback *cb,
1331 struct nfc_se *se, *n;
1333 list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
1334 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
1337 goto nla_put_failure;
1340 genl_dump_check_consistent(cb, hdr, &nfc_genl_family);
1342 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
1343 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) ||
1344 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
1345 goto nla_put_failure;
1347 genlmsg_end(msg, hdr);
1353 genlmsg_cancel(msg, hdr);
1357 static int nfc_genl_dump_ses(struct sk_buff *skb,
1358 struct netlink_callback *cb)
1360 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1361 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
1362 bool first_call = false;
1366 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
1369 cb->args[0] = (long) iter;
1372 mutex_lock(&nfc_devlist_mutex);
1374 cb->seq = nfc_devlist_generation;
1377 nfc_device_iter_init(iter);
1378 dev = nfc_device_iter_next(iter);
1384 rc = nfc_genl_send_se(skb, dev, NETLINK_CB(cb->skb).portid,
1385 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
1389 dev = nfc_device_iter_next(iter);
1392 mutex_unlock(&nfc_devlist_mutex);
1394 cb->args[1] = (long) dev;
1399 static int nfc_genl_dump_ses_done(struct netlink_callback *cb)
1401 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1403 nfc_device_iter_exit(iter);
1409 static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
1410 u8 *apdu, size_t apdu_length,
1411 se_io_cb_t cb, void *cb_context)
1416 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
1418 device_lock(&dev->dev);
1420 if (!device_is_registered(&dev->dev)) {
1430 if (!dev->ops->se_io) {
1435 se = nfc_find_se(dev, se_idx);
1441 if (se->state != NFC_SE_ENABLED) {
1446 rc = dev->ops->se_io(dev, se_idx, apdu,
1447 apdu_length, cb, cb_context);
1450 device_unlock(&dev->dev);
1459 static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
1461 struct se_io_ctx *ctx = context;
1462 struct sk_buff *msg;
1465 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1471 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1476 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, ctx->dev_idx) ||
1477 nla_put_u32(msg, NFC_ATTR_SE_INDEX, ctx->se_idx) ||
1478 nla_put(msg, NFC_ATTR_SE_APDU, apdu_len, apdu))
1479 goto nla_put_failure;
1481 genlmsg_end(msg, hdr);
1483 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1490 genlmsg_cancel(msg, hdr);
1498 static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
1500 struct nfc_dev *dev;
1501 struct se_io_ctx *ctx;
1502 u32 dev_idx, se_idx;
1506 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1507 !info->attrs[NFC_ATTR_SE_INDEX] ||
1508 !info->attrs[NFC_ATTR_SE_APDU])
1511 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1512 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1514 dev = nfc_get_device(dev_idx);
1518 if (!dev->ops || !dev->ops->se_io)
1521 apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
1525 apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
1529 ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
1533 ctx->dev_idx = dev_idx;
1534 ctx->se_idx = se_idx;
1536 return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
1539 static int nfc_genl_vendor_cmd(struct sk_buff *skb,
1540 struct genl_info *info)
1542 struct nfc_dev *dev;
1543 struct nfc_vendor_cmd *cmd;
1544 u32 dev_idx, vid, subcmd;
1549 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1550 !info->attrs[NFC_ATTR_VENDOR_ID] ||
1551 !info->attrs[NFC_ATTR_VENDOR_SUBCMD])
1554 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1555 vid = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_ID]);
1556 subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]);
1558 dev = nfc_get_device(dev_idx);
1559 if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds)
1562 if (info->attrs[NFC_ATTR_VENDOR_DATA]) {
1563 data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]);
1564 data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]);
1572 for (i = 0; i < dev->n_vendor_cmds; i++) {
1573 cmd = &dev->vendor_cmds[i];
1575 if (cmd->vendor_id != vid || cmd->subcmd != subcmd)
1578 dev->cur_cmd_info = info;
1579 err = cmd->doit(dev, data, data_len);
1580 dev->cur_cmd_info = NULL;
1587 /* message building helper */
1588 static inline void *nfc_hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1591 /* since there is no private header just add the generic one */
1592 return genlmsg_put(skb, portid, seq, &nfc_genl_family, flags, cmd);
1595 static struct sk_buff *
1596 __nfc_alloc_vendor_cmd_skb(struct nfc_dev *dev, int approxlen,
1597 u32 portid, u32 seq,
1598 enum nfc_attrs attr,
1599 u32 oui, u32 subcmd, gfp_t gfp)
1601 struct sk_buff *skb;
1604 skb = nlmsg_new(approxlen + 100, gfp);
1608 hdr = nfc_hdr_put(skb, portid, seq, 0, NFC_CMD_VENDOR);
1614 if (nla_put_u32(skb, NFC_ATTR_DEVICE_INDEX, dev->idx))
1615 goto nla_put_failure;
1616 if (nla_put_u32(skb, NFC_ATTR_VENDOR_ID, oui))
1617 goto nla_put_failure;
1618 if (nla_put_u32(skb, NFC_ATTR_VENDOR_SUBCMD, subcmd))
1619 goto nla_put_failure;
1621 ((void **)skb->cb)[0] = dev;
1622 ((void **)skb->cb)[1] = hdr;
1631 struct sk_buff *__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev *dev,
1632 enum nfc_attrs attr,
1633 u32 oui, u32 subcmd,
1636 if (WARN_ON(!dev->cur_cmd_info))
1639 return __nfc_alloc_vendor_cmd_skb(dev, approxlen,
1640 dev->cur_cmd_info->snd_portid,
1641 dev->cur_cmd_info->snd_seq, attr,
1642 oui, subcmd, GFP_KERNEL);
1644 EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb);
1646 int nfc_vendor_cmd_reply(struct sk_buff *skb)
1648 struct nfc_dev *dev = ((void **)skb->cb)[0];
1649 void *hdr = ((void **)skb->cb)[1];
1651 /* clear CB data for netlink core to own from now on */
1652 memset(skb->cb, 0, sizeof(skb->cb));
1654 if (WARN_ON(!dev->cur_cmd_info)) {
1659 genlmsg_end(skb, hdr);
1660 return genlmsg_reply(skb, dev->cur_cmd_info);
1662 EXPORT_SYMBOL(nfc_vendor_cmd_reply);
1664 static const struct genl_ops nfc_genl_ops[] = {
1666 .cmd = NFC_CMD_GET_DEVICE,
1667 .doit = nfc_genl_get_device,
1668 .dumpit = nfc_genl_dump_devices,
1669 .done = nfc_genl_dump_devices_done,
1670 .policy = nfc_genl_policy,
1673 .cmd = NFC_CMD_DEV_UP,
1674 .doit = nfc_genl_dev_up,
1675 .policy = nfc_genl_policy,
1678 .cmd = NFC_CMD_DEV_DOWN,
1679 .doit = nfc_genl_dev_down,
1680 .policy = nfc_genl_policy,
1683 .cmd = NFC_CMD_START_POLL,
1684 .doit = nfc_genl_start_poll,
1685 .policy = nfc_genl_policy,
1688 .cmd = NFC_CMD_STOP_POLL,
1689 .doit = nfc_genl_stop_poll,
1690 .policy = nfc_genl_policy,
1693 .cmd = NFC_CMD_DEP_LINK_UP,
1694 .doit = nfc_genl_dep_link_up,
1695 .policy = nfc_genl_policy,
1698 .cmd = NFC_CMD_DEP_LINK_DOWN,
1699 .doit = nfc_genl_dep_link_down,
1700 .policy = nfc_genl_policy,
1703 .cmd = NFC_CMD_GET_TARGET,
1704 .dumpit = nfc_genl_dump_targets,
1705 .done = nfc_genl_dump_targets_done,
1706 .policy = nfc_genl_policy,
1709 .cmd = NFC_CMD_LLC_GET_PARAMS,
1710 .doit = nfc_genl_llc_get_params,
1711 .policy = nfc_genl_policy,
1714 .cmd = NFC_CMD_LLC_SET_PARAMS,
1715 .doit = nfc_genl_llc_set_params,
1716 .policy = nfc_genl_policy,
1719 .cmd = NFC_CMD_LLC_SDREQ,
1720 .doit = nfc_genl_llc_sdreq,
1721 .policy = nfc_genl_policy,
1724 .cmd = NFC_CMD_FW_DOWNLOAD,
1725 .doit = nfc_genl_fw_download,
1726 .policy = nfc_genl_policy,
1729 .cmd = NFC_CMD_ENABLE_SE,
1730 .doit = nfc_genl_enable_se,
1731 .policy = nfc_genl_policy,
1734 .cmd = NFC_CMD_DISABLE_SE,
1735 .doit = nfc_genl_disable_se,
1736 .policy = nfc_genl_policy,
1739 .cmd = NFC_CMD_GET_SE,
1740 .dumpit = nfc_genl_dump_ses,
1741 .done = nfc_genl_dump_ses_done,
1742 .policy = nfc_genl_policy,
1745 .cmd = NFC_CMD_SE_IO,
1746 .doit = nfc_genl_se_io,
1747 .policy = nfc_genl_policy,
1750 .cmd = NFC_CMD_ACTIVATE_TARGET,
1751 .doit = nfc_genl_activate_target,
1752 .policy = nfc_genl_policy,
1755 .cmd = NFC_CMD_VENDOR,
1756 .doit = nfc_genl_vendor_cmd,
1757 .policy = nfc_genl_policy,
1761 static struct genl_family nfc_genl_family __ro_after_init = {
1763 .name = NFC_GENL_NAME,
1764 .version = NFC_GENL_VERSION,
1765 .maxattr = NFC_ATTR_MAX,
1766 .module = THIS_MODULE,
1767 .ops = nfc_genl_ops,
1768 .n_ops = ARRAY_SIZE(nfc_genl_ops),
1769 .mcgrps = nfc_genl_mcgrps,
1770 .n_mcgrps = ARRAY_SIZE(nfc_genl_mcgrps),
1774 struct urelease_work {
1775 struct work_struct w;
1779 static void nfc_urelease_event_work(struct work_struct *work)
1781 struct urelease_work *w = container_of(work, struct urelease_work, w);
1782 struct class_dev_iter iter;
1783 struct nfc_dev *dev;
1785 pr_debug("portid %d\n", w->portid);
1787 mutex_lock(&nfc_devlist_mutex);
1789 nfc_device_iter_init(&iter);
1790 dev = nfc_device_iter_next(&iter);
1793 mutex_lock(&dev->genl_data.genl_data_mutex);
1795 if (dev->genl_data.poll_req_portid == w->portid) {
1797 dev->genl_data.poll_req_portid = 0;
1800 mutex_unlock(&dev->genl_data.genl_data_mutex);
1802 dev = nfc_device_iter_next(&iter);
1805 nfc_device_iter_exit(&iter);
1807 mutex_unlock(&nfc_devlist_mutex);
1812 static int nfc_genl_rcv_nl_event(struct notifier_block *this,
1813 unsigned long event, void *ptr)
1815 struct netlink_notify *n = ptr;
1816 struct urelease_work *w;
1818 if (event != NETLINK_URELEASE || n->protocol != NETLINK_GENERIC)
1821 pr_debug("NETLINK_URELEASE event from id %d\n", n->portid);
1823 w = kmalloc(sizeof(*w), GFP_ATOMIC);
1825 INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
1826 w->portid = n->portid;
1827 schedule_work((struct work_struct *) w);
1834 void nfc_genl_data_init(struct nfc_genl_data *genl_data)
1836 genl_data->poll_req_portid = 0;
1837 mutex_init(&genl_data->genl_data_mutex);
1840 void nfc_genl_data_exit(struct nfc_genl_data *genl_data)
1842 mutex_destroy(&genl_data->genl_data_mutex);
1845 static struct notifier_block nl_notifier = {
1846 .notifier_call = nfc_genl_rcv_nl_event,
1850 * nfc_genl_init() - Initialize netlink interface
1852 * This initialization function registers the nfc netlink family.
1854 int __init nfc_genl_init(void)
1858 rc = genl_register_family(&nfc_genl_family);
1862 netlink_register_notifier(&nl_notifier);
1868 * nfc_genl_exit() - Deinitialize netlink interface
1870 * This exit function unregisters the nfc netlink family.
1872 void nfc_genl_exit(void)
1874 netlink_unregister_notifier(&nl_notifier);
1875 genl_unregister_family(&nfc_genl_family);