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];
659 nfc_device_iter_exit(iter);
666 int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
667 u8 comm_mode, u8 rf_mode)
672 pr_debug("DEP link is up\n");
674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
678 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, NFC_CMD_DEP_LINK_UP);
682 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
683 goto nla_put_failure;
684 if (rf_mode == NFC_RF_INITIATOR &&
685 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
686 goto nla_put_failure;
687 if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) ||
688 nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode))
689 goto nla_put_failure;
691 genlmsg_end(msg, hdr);
693 dev->dep_link_up = true;
695 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
705 int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
710 pr_debug("DEP link is down\n");
712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
716 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
717 NFC_CMD_DEP_LINK_DOWN);
721 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
722 goto nla_put_failure;
724 genlmsg_end(msg, hdr);
726 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
736 static int nfc_genl_get_device(struct sk_buff *skb, struct genl_info *info)
743 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
746 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
748 dev = nfc_get_device(idx);
752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
758 rc = nfc_genl_send_device(msg, dev, info->snd_portid, info->snd_seq,
765 return genlmsg_reply(msg, info);
774 static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
780 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
783 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
785 dev = nfc_get_device(idx);
789 rc = nfc_dev_up(dev);
795 static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
801 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
804 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
806 dev = nfc_get_device(idx);
810 rc = nfc_dev_down(dev);
816 static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
821 u32 im_protocols = 0, tm_protocols = 0;
823 pr_debug("Poll start\n");
825 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
826 ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
827 !info->attrs[NFC_ATTR_PROTOCOLS]) &&
828 !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
831 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
833 if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
834 tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
836 if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
837 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
838 else if (info->attrs[NFC_ATTR_PROTOCOLS])
839 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
841 dev = nfc_get_device(idx);
845 mutex_lock(&dev->genl_data.genl_data_mutex);
847 rc = nfc_start_poll(dev, im_protocols, tm_protocols);
849 dev->genl_data.poll_req_portid = info->snd_portid;
851 mutex_unlock(&dev->genl_data.genl_data_mutex);
857 static int nfc_genl_stop_poll(struct sk_buff *skb, struct genl_info *info)
863 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
866 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
868 dev = nfc_get_device(idx);
872 device_lock(&dev->dev);
875 device_unlock(&dev->dev);
880 device_unlock(&dev->dev);
882 mutex_lock(&dev->genl_data.genl_data_mutex);
884 if (dev->genl_data.poll_req_portid != info->snd_portid) {
889 rc = nfc_stop_poll(dev);
890 dev->genl_data.poll_req_portid = 0;
893 mutex_unlock(&dev->genl_data.genl_data_mutex);
898 static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
901 u32 device_idx, target_idx, protocol;
904 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
905 !info->attrs[NFC_ATTR_TARGET_INDEX] ||
906 !info->attrs[NFC_ATTR_PROTOCOLS])
909 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
911 dev = nfc_get_device(device_idx);
915 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
916 protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
918 nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
919 rc = nfc_activate_target(dev, target_idx, protocol);
925 static int nfc_genl_deactivate_target(struct sk_buff *skb,
926 struct genl_info *info)
929 u32 device_idx, target_idx;
932 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
933 !info->attrs[NFC_ATTR_TARGET_INDEX])
936 device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
938 dev = nfc_get_device(device_idx);
942 target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
944 rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
950 static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
957 pr_debug("DEP link up\n");
959 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
960 !info->attrs[NFC_ATTR_COMM_MODE])
963 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
964 if (!info->attrs[NFC_ATTR_TARGET_INDEX])
965 tgt_idx = NFC_TARGET_IDX_ANY;
967 tgt_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
969 comm = nla_get_u8(info->attrs[NFC_ATTR_COMM_MODE]);
971 if (comm != NFC_COMM_ACTIVE && comm != NFC_COMM_PASSIVE)
974 dev = nfc_get_device(idx);
978 rc = nfc_dep_link_up(dev, tgt_idx, comm);
985 static int nfc_genl_dep_link_down(struct sk_buff *skb, struct genl_info *info)
991 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
992 !info->attrs[NFC_ATTR_TARGET_INDEX])
995 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
997 dev = nfc_get_device(idx);
1001 rc = nfc_dep_link_down(dev);
1003 nfc_put_device(dev);
1007 static int nfc_genl_send_params(struct sk_buff *msg,
1008 struct nfc_llcp_local *local,
1009 u32 portid, u32 seq)
1013 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, 0,
1014 NFC_CMD_LLC_GET_PARAMS);
1018 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, local->dev->idx) ||
1019 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_LTO, local->lto) ||
1020 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_RW, local->rw) ||
1021 nla_put_u16(msg, NFC_ATTR_LLC_PARAM_MIUX, be16_to_cpu(local->miux)))
1022 goto nla_put_failure;
1024 genlmsg_end(msg, hdr);
1028 genlmsg_cancel(msg, hdr);
1032 static int nfc_genl_llc_get_params(struct sk_buff *skb, struct genl_info *info)
1034 struct nfc_dev *dev;
1035 struct nfc_llcp_local *local;
1037 struct sk_buff *msg = NULL;
1040 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1041 !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1044 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1046 dev = nfc_get_device(idx);
1050 device_lock(&dev->dev);
1052 local = nfc_llcp_find_local(dev);
1058 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1064 rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
1067 device_unlock(&dev->dev);
1069 nfc_put_device(dev);
1078 return genlmsg_reply(msg, info);
1081 static int nfc_genl_llc_set_params(struct sk_buff *skb, struct genl_info *info)
1083 struct nfc_dev *dev;
1084 struct nfc_llcp_local *local;
1090 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1091 (!info->attrs[NFC_ATTR_LLC_PARAM_LTO] &&
1092 !info->attrs[NFC_ATTR_LLC_PARAM_RW] &&
1093 !info->attrs[NFC_ATTR_LLC_PARAM_MIUX]))
1096 if (info->attrs[NFC_ATTR_LLC_PARAM_RW]) {
1097 rw = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_RW]);
1099 if (rw > LLCP_MAX_RW)
1103 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) {
1104 miux = nla_get_u16(info->attrs[NFC_ATTR_LLC_PARAM_MIUX]);
1106 if (miux > LLCP_MAX_MIUX)
1110 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1112 dev = nfc_get_device(idx);
1116 device_lock(&dev->dev);
1118 local = nfc_llcp_find_local(dev);
1124 if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
1125 if (dev->dep_link_up) {
1130 local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
1133 if (info->attrs[NFC_ATTR_LLC_PARAM_RW])
1136 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
1137 local->miux = cpu_to_be16(miux);
1140 device_unlock(&dev->dev);
1142 nfc_put_device(dev);
1147 static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
1149 struct nfc_dev *dev;
1150 struct nfc_llcp_local *local;
1151 struct nlattr *attr, *sdp_attrs[NFC_SDP_ATTR_MAX+1];
1156 size_t uri_len, tlvs_len;
1157 struct hlist_head sdreq_list;
1158 struct nfc_llcp_sdp_tlv *sdreq;
1160 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1161 !info->attrs[NFC_ATTR_LLC_SDP])
1164 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1166 dev = nfc_get_device(idx);
1170 device_lock(&dev->dev);
1172 if (dev->dep_link_up == false) {
1177 local = nfc_llcp_find_local(dev);
1183 INIT_HLIST_HEAD(&sdreq_list);
1187 nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) {
1188 rc = nla_parse_nested(sdp_attrs, NFC_SDP_ATTR_MAX, attr,
1189 nfc_sdp_genl_policy, info->extack);
1196 if (!sdp_attrs[NFC_SDP_ATTR_URI])
1199 uri_len = nla_len(sdp_attrs[NFC_SDP_ATTR_URI]);
1203 uri = nla_data(sdp_attrs[NFC_SDP_ATTR_URI]);
1204 if (uri == NULL || *uri == 0)
1207 tid = local->sdreq_next_tid++;
1209 sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len);
1210 if (sdreq == NULL) {
1215 tlvs_len += sdreq->tlv_len;
1217 hlist_add_head(&sdreq->node, &sdreq_list);
1220 if (hlist_empty(&sdreq_list)) {
1225 rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len);
1227 device_unlock(&dev->dev);
1229 nfc_put_device(dev);
1234 static int nfc_genl_fw_download(struct sk_buff *skb, struct genl_info *info)
1236 struct nfc_dev *dev;
1239 char firmware_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
1241 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_FIRMWARE_NAME])
1244 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1246 dev = nfc_get_device(idx);
1250 nla_strlcpy(firmware_name, info->attrs[NFC_ATTR_FIRMWARE_NAME],
1251 sizeof(firmware_name));
1253 rc = nfc_fw_download(dev, firmware_name);
1255 nfc_put_device(dev);
1259 int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
1262 struct sk_buff *msg;
1265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1269 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1270 NFC_CMD_FW_DOWNLOAD);
1274 if (nla_put_string(msg, NFC_ATTR_FIRMWARE_NAME, firmware_name) ||
1275 nla_put_u32(msg, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS, result) ||
1276 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
1277 goto nla_put_failure;
1279 genlmsg_end(msg, hdr);
1281 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
1291 static int nfc_genl_enable_se(struct sk_buff *skb, struct genl_info *info)
1293 struct nfc_dev *dev;
1297 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1298 !info->attrs[NFC_ATTR_SE_INDEX])
1301 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1302 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1304 dev = nfc_get_device(idx);
1308 rc = nfc_enable_se(dev, se_idx);
1310 nfc_put_device(dev);
1314 static int nfc_genl_disable_se(struct sk_buff *skb, struct genl_info *info)
1316 struct nfc_dev *dev;
1320 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1321 !info->attrs[NFC_ATTR_SE_INDEX])
1324 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1325 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1327 dev = nfc_get_device(idx);
1331 rc = nfc_disable_se(dev, se_idx);
1333 nfc_put_device(dev);
1337 static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev,
1338 u32 portid, u32 seq,
1339 struct netlink_callback *cb,
1343 struct nfc_se *se, *n;
1345 list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
1346 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
1349 goto nla_put_failure;
1352 genl_dump_check_consistent(cb, hdr);
1354 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
1355 nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) ||
1356 nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
1357 goto nla_put_failure;
1359 genlmsg_end(msg, hdr);
1365 genlmsg_cancel(msg, hdr);
1369 static int nfc_genl_dump_ses(struct sk_buff *skb,
1370 struct netlink_callback *cb)
1372 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1373 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
1374 bool first_call = false;
1378 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
1381 cb->args[0] = (long) iter;
1384 mutex_lock(&nfc_devlist_mutex);
1386 cb->seq = nfc_devlist_generation;
1389 nfc_device_iter_init(iter);
1390 dev = nfc_device_iter_next(iter);
1396 rc = nfc_genl_send_se(skb, dev, NETLINK_CB(cb->skb).portid,
1397 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
1401 dev = nfc_device_iter_next(iter);
1404 mutex_unlock(&nfc_devlist_mutex);
1406 cb->args[1] = (long) dev;
1411 static int nfc_genl_dump_ses_done(struct netlink_callback *cb)
1413 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
1416 nfc_device_iter_exit(iter);
1423 static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
1424 u8 *apdu, size_t apdu_length,
1425 se_io_cb_t cb, void *cb_context)
1430 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
1432 device_lock(&dev->dev);
1434 if (!device_is_registered(&dev->dev)) {
1444 if (!dev->ops->se_io) {
1449 se = nfc_find_se(dev, se_idx);
1455 if (se->state != NFC_SE_ENABLED) {
1460 rc = dev->ops->se_io(dev, se_idx, apdu,
1461 apdu_length, cb, cb_context);
1463 device_unlock(&dev->dev);
1467 device_unlock(&dev->dev);
1477 static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
1479 struct se_io_ctx *ctx = context;
1480 struct sk_buff *msg;
1483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1489 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
1494 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, ctx->dev_idx) ||
1495 nla_put_u32(msg, NFC_ATTR_SE_INDEX, ctx->se_idx) ||
1496 nla_put(msg, NFC_ATTR_SE_APDU, apdu_len, apdu))
1497 goto nla_put_failure;
1499 genlmsg_end(msg, hdr);
1501 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1515 static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
1517 struct nfc_dev *dev;
1518 struct se_io_ctx *ctx;
1519 u32 dev_idx, se_idx;
1524 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1525 !info->attrs[NFC_ATTR_SE_INDEX] ||
1526 !info->attrs[NFC_ATTR_SE_APDU])
1529 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1530 se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
1532 dev = nfc_get_device(dev_idx);
1536 if (!dev->ops || !dev->ops->se_io) {
1541 apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
1542 if (apdu_len == 0) {
1547 apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
1553 ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
1559 ctx->dev_idx = dev_idx;
1560 ctx->se_idx = se_idx;
1562 rc = nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
1565 nfc_put_device(dev);
1569 static int nfc_genl_vendor_cmd(struct sk_buff *skb,
1570 struct genl_info *info)
1572 struct nfc_dev *dev;
1573 struct nfc_vendor_cmd *cmd;
1574 u32 dev_idx, vid, subcmd;
1579 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
1580 !info->attrs[NFC_ATTR_VENDOR_ID] ||
1581 !info->attrs[NFC_ATTR_VENDOR_SUBCMD])
1584 dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
1585 vid = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_ID]);
1586 subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]);
1588 dev = nfc_get_device(dev_idx);
1592 if (!dev->vendor_cmds || !dev->n_vendor_cmds) {
1597 if (info->attrs[NFC_ATTR_VENDOR_DATA]) {
1598 data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]);
1599 data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]);
1600 if (data_len == 0) {
1609 for (i = 0; i < dev->n_vendor_cmds; i++) {
1610 cmd = &dev->vendor_cmds[i];
1612 if (cmd->vendor_id != vid || cmd->subcmd != subcmd)
1615 dev->cur_cmd_info = info;
1616 err = cmd->doit(dev, data, data_len);
1617 dev->cur_cmd_info = NULL;
1624 nfc_put_device(dev);
1628 /* message building helper */
1629 static inline void *nfc_hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
1632 /* since there is no private header just add the generic one */
1633 return genlmsg_put(skb, portid, seq, &nfc_genl_family, flags, cmd);
1636 static struct sk_buff *
1637 __nfc_alloc_vendor_cmd_skb(struct nfc_dev *dev, int approxlen,
1638 u32 portid, u32 seq,
1639 enum nfc_attrs attr,
1640 u32 oui, u32 subcmd, gfp_t gfp)
1642 struct sk_buff *skb;
1645 skb = nlmsg_new(approxlen + 100, gfp);
1649 hdr = nfc_hdr_put(skb, portid, seq, 0, NFC_CMD_VENDOR);
1655 if (nla_put_u32(skb, NFC_ATTR_DEVICE_INDEX, dev->idx))
1656 goto nla_put_failure;
1657 if (nla_put_u32(skb, NFC_ATTR_VENDOR_ID, oui))
1658 goto nla_put_failure;
1659 if (nla_put_u32(skb, NFC_ATTR_VENDOR_SUBCMD, subcmd))
1660 goto nla_put_failure;
1662 ((void **)skb->cb)[0] = dev;
1663 ((void **)skb->cb)[1] = hdr;
1672 struct sk_buff *__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev *dev,
1673 enum nfc_attrs attr,
1674 u32 oui, u32 subcmd,
1677 if (WARN_ON(!dev->cur_cmd_info))
1680 return __nfc_alloc_vendor_cmd_skb(dev, approxlen,
1681 dev->cur_cmd_info->snd_portid,
1682 dev->cur_cmd_info->snd_seq, attr,
1683 oui, subcmd, GFP_KERNEL);
1685 EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb);
1687 int nfc_vendor_cmd_reply(struct sk_buff *skb)
1689 struct nfc_dev *dev = ((void **)skb->cb)[0];
1690 void *hdr = ((void **)skb->cb)[1];
1692 /* clear CB data for netlink core to own from now on */
1693 memset(skb->cb, 0, sizeof(skb->cb));
1695 if (WARN_ON(!dev->cur_cmd_info)) {
1700 genlmsg_end(skb, hdr);
1701 return genlmsg_reply(skb, dev->cur_cmd_info);
1703 EXPORT_SYMBOL(nfc_vendor_cmd_reply);
1705 static const struct genl_ops nfc_genl_ops[] = {
1707 .cmd = NFC_CMD_GET_DEVICE,
1708 .doit = nfc_genl_get_device,
1709 .dumpit = nfc_genl_dump_devices,
1710 .done = nfc_genl_dump_devices_done,
1711 .policy = nfc_genl_policy,
1714 .cmd = NFC_CMD_DEV_UP,
1715 .doit = nfc_genl_dev_up,
1716 .policy = nfc_genl_policy,
1719 .cmd = NFC_CMD_DEV_DOWN,
1720 .doit = nfc_genl_dev_down,
1721 .policy = nfc_genl_policy,
1724 .cmd = NFC_CMD_START_POLL,
1725 .doit = nfc_genl_start_poll,
1726 .policy = nfc_genl_policy,
1729 .cmd = NFC_CMD_STOP_POLL,
1730 .doit = nfc_genl_stop_poll,
1731 .policy = nfc_genl_policy,
1734 .cmd = NFC_CMD_DEP_LINK_UP,
1735 .doit = nfc_genl_dep_link_up,
1736 .policy = nfc_genl_policy,
1739 .cmd = NFC_CMD_DEP_LINK_DOWN,
1740 .doit = nfc_genl_dep_link_down,
1741 .policy = nfc_genl_policy,
1744 .cmd = NFC_CMD_GET_TARGET,
1745 .dumpit = nfc_genl_dump_targets,
1746 .done = nfc_genl_dump_targets_done,
1747 .policy = nfc_genl_policy,
1750 .cmd = NFC_CMD_LLC_GET_PARAMS,
1751 .doit = nfc_genl_llc_get_params,
1752 .policy = nfc_genl_policy,
1755 .cmd = NFC_CMD_LLC_SET_PARAMS,
1756 .doit = nfc_genl_llc_set_params,
1757 .policy = nfc_genl_policy,
1760 .cmd = NFC_CMD_LLC_SDREQ,
1761 .doit = nfc_genl_llc_sdreq,
1762 .policy = nfc_genl_policy,
1765 .cmd = NFC_CMD_FW_DOWNLOAD,
1766 .doit = nfc_genl_fw_download,
1767 .policy = nfc_genl_policy,
1770 .cmd = NFC_CMD_ENABLE_SE,
1771 .doit = nfc_genl_enable_se,
1772 .policy = nfc_genl_policy,
1775 .cmd = NFC_CMD_DISABLE_SE,
1776 .doit = nfc_genl_disable_se,
1777 .policy = nfc_genl_policy,
1780 .cmd = NFC_CMD_GET_SE,
1781 .dumpit = nfc_genl_dump_ses,
1782 .done = nfc_genl_dump_ses_done,
1783 .policy = nfc_genl_policy,
1786 .cmd = NFC_CMD_SE_IO,
1787 .doit = nfc_genl_se_io,
1788 .policy = nfc_genl_policy,
1791 .cmd = NFC_CMD_ACTIVATE_TARGET,
1792 .doit = nfc_genl_activate_target,
1793 .policy = nfc_genl_policy,
1796 .cmd = NFC_CMD_VENDOR,
1797 .doit = nfc_genl_vendor_cmd,
1798 .policy = nfc_genl_policy,
1801 .cmd = NFC_CMD_DEACTIVATE_TARGET,
1802 .doit = nfc_genl_deactivate_target,
1803 .policy = nfc_genl_policy,
1807 static struct genl_family nfc_genl_family __ro_after_init = {
1809 .name = NFC_GENL_NAME,
1810 .version = NFC_GENL_VERSION,
1811 .maxattr = NFC_ATTR_MAX,
1812 .module = THIS_MODULE,
1813 .ops = nfc_genl_ops,
1814 .n_ops = ARRAY_SIZE(nfc_genl_ops),
1815 .mcgrps = nfc_genl_mcgrps,
1816 .n_mcgrps = ARRAY_SIZE(nfc_genl_mcgrps),
1820 struct urelease_work {
1821 struct work_struct w;
1825 static void nfc_urelease_event_work(struct work_struct *work)
1827 struct urelease_work *w = container_of(work, struct urelease_work, w);
1828 struct class_dev_iter iter;
1829 struct nfc_dev *dev;
1831 pr_debug("portid %d\n", w->portid);
1833 mutex_lock(&nfc_devlist_mutex);
1835 nfc_device_iter_init(&iter);
1836 dev = nfc_device_iter_next(&iter);
1839 mutex_lock(&dev->genl_data.genl_data_mutex);
1841 if (dev->genl_data.poll_req_portid == w->portid) {
1843 dev->genl_data.poll_req_portid = 0;
1846 mutex_unlock(&dev->genl_data.genl_data_mutex);
1848 dev = nfc_device_iter_next(&iter);
1851 nfc_device_iter_exit(&iter);
1853 mutex_unlock(&nfc_devlist_mutex);
1858 static int nfc_genl_rcv_nl_event(struct notifier_block *this,
1859 unsigned long event, void *ptr)
1861 struct netlink_notify *n = ptr;
1862 struct urelease_work *w;
1864 if (event != NETLINK_URELEASE || n->protocol != NETLINK_GENERIC)
1867 pr_debug("NETLINK_URELEASE event from id %d\n", n->portid);
1869 w = kmalloc(sizeof(*w), GFP_ATOMIC);
1871 INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
1872 w->portid = n->portid;
1873 schedule_work((struct work_struct *) w);
1880 void nfc_genl_data_init(struct nfc_genl_data *genl_data)
1882 genl_data->poll_req_portid = 0;
1883 mutex_init(&genl_data->genl_data_mutex);
1886 void nfc_genl_data_exit(struct nfc_genl_data *genl_data)
1888 mutex_destroy(&genl_data->genl_data_mutex);
1891 static struct notifier_block nl_notifier = {
1892 .notifier_call = nfc_genl_rcv_nl_event,
1896 * nfc_genl_init() - Initialize netlink interface
1898 * This initialization function registers the nfc netlink family.
1900 int __init nfc_genl_init(void)
1904 rc = genl_register_family(&nfc_genl_family);
1908 netlink_register_notifier(&nl_notifier);
1914 * nfc_genl_exit() - Deinitialize netlink interface
1916 * This exit function unregisters the nfc netlink family.
1918 void nfc_genl_exit(void)
1920 netlink_unregister_notifier(&nl_notifier);
1921 genl_unregister_family(&nfc_genl_family);