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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
26 #include <net/genetlink.h>
27 #include <linux/nfc.h>
28 #include <linux/slab.h>
32 #include "llcp/llcp.h"
34 static struct genl_multicast_group nfc_genl_event_mcgrp = {
35 .name = NFC_GENL_MCAST_EVENT_NAME,
38 static struct genl_family nfc_genl_family = {
39 .id = GENL_ID_GENERATE,
41 .name = NFC_GENL_NAME,
42 .version = NFC_GENL_VERSION,
43 .maxattr = NFC_ATTR_MAX,
46 static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
47 [NFC_ATTR_DEVICE_INDEX] = { .type = NLA_U32 },
48 [NFC_ATTR_DEVICE_NAME] = { .type = NLA_STRING,
49 .len = NFC_DEVICE_NAME_MAXSIZE },
50 [NFC_ATTR_PROTOCOLS] = { .type = NLA_U32 },
51 [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 },
52 [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
53 [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
54 [NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
55 [NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
58 static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
59 struct netlink_callback *cb, int flags)
63 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
64 &nfc_genl_family, flags, NFC_CMD_GET_TARGET);
68 genl_dump_check_consistent(cb, hdr, &nfc_genl_family);
70 if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) ||
71 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) ||
72 nla_put_u16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res) ||
73 nla_put_u8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res))
75 if (target->nfcid1_len > 0 &&
76 nla_put(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len,
79 if (target->sensb_res_len > 0 &&
80 nla_put(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len,
83 if (target->sensf_res_len > 0 &&
84 nla_put(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len,
88 return genlmsg_end(msg, hdr);
91 genlmsg_cancel(msg, hdr);
95 static struct nfc_dev *__get_device_from_cb(struct netlink_callback *cb)
101 rc = nlmsg_parse(cb->nlh, GENL_HDRLEN + nfc_genl_family.hdrsize,
102 nfc_genl_family.attrbuf,
103 nfc_genl_family.maxattr,
108 if (!nfc_genl_family.attrbuf[NFC_ATTR_DEVICE_INDEX])
109 return ERR_PTR(-EINVAL);
111 idx = nla_get_u32(nfc_genl_family.attrbuf[NFC_ATTR_DEVICE_INDEX]);
113 dev = nfc_get_device(idx);
115 return ERR_PTR(-ENODEV);
120 static int nfc_genl_dump_targets(struct sk_buff *skb,
121 struct netlink_callback *cb)
124 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
128 dev = __get_device_from_cb(cb);
132 cb->args[1] = (long) dev;
135 device_lock(&dev->dev);
137 cb->seq = dev->targets_generation;
139 while (i < dev->n_targets) {
140 rc = nfc_genl_send_target(skb, &dev->targets[i], cb,
148 device_unlock(&dev->dev);
155 static int nfc_genl_dump_targets_done(struct netlink_callback *cb)
157 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
165 int nfc_genl_targets_found(struct nfc_dev *dev)
170 dev->genl_data.poll_req_portid = 0;
172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
176 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
177 NFC_EVENT_TARGETS_FOUND);
181 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
182 goto nla_put_failure;
184 genlmsg_end(msg, hdr);
186 return genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
189 genlmsg_cancel(msg, hdr);
195 int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
204 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
205 NFC_EVENT_TARGET_LOST);
209 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
210 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
211 goto nla_put_failure;
213 genlmsg_end(msg, hdr);
215 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
220 genlmsg_cancel(msg, hdr);
226 int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
235 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
236 NFC_EVENT_TM_ACTIVATED);
240 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
241 goto nla_put_failure;
242 if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
243 goto nla_put_failure;
245 genlmsg_end(msg, hdr);
247 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
252 genlmsg_cancel(msg, hdr);
258 int nfc_genl_tm_deactivated(struct nfc_dev *dev)
263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
267 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
268 NFC_EVENT_TM_DEACTIVATED);
272 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
273 goto nla_put_failure;
275 genlmsg_end(msg, hdr);
277 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
282 genlmsg_cancel(msg, hdr);
288 int nfc_genl_device_added(struct nfc_dev *dev)
293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
297 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
298 NFC_EVENT_DEVICE_ADDED);
302 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
303 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
304 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
305 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up))
306 goto nla_put_failure;
308 genlmsg_end(msg, hdr);
310 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
315 genlmsg_cancel(msg, hdr);
321 int nfc_genl_device_removed(struct nfc_dev *dev)
326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
330 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
331 NFC_EVENT_DEVICE_REMOVED);
335 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
336 goto nla_put_failure;
338 genlmsg_end(msg, hdr);
340 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
345 genlmsg_cancel(msg, hdr);
351 static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
353 struct netlink_callback *cb,
358 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
364 genl_dump_check_consistent(cb, hdr, &nfc_genl_family);
366 if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
367 nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
368 nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
369 nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
370 nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
371 goto nla_put_failure;
373 return genlmsg_end(msg, hdr);
376 genlmsg_cancel(msg, hdr);
380 static int nfc_genl_dump_devices(struct sk_buff *skb,
381 struct netlink_callback *cb)
383 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
384 struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
385 bool first_call = false;
389 iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
392 cb->args[0] = (long) iter;
395 mutex_lock(&nfc_devlist_mutex);
397 cb->seq = nfc_devlist_generation;
400 nfc_device_iter_init(iter);
401 dev = nfc_device_iter_next(iter);
407 rc = nfc_genl_send_device(skb, dev, NETLINK_CB(cb->skb).portid,
408 cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
412 dev = nfc_device_iter_next(iter);
415 mutex_unlock(&nfc_devlist_mutex);
417 cb->args[1] = (long) dev;
422 static int nfc_genl_dump_devices_done(struct netlink_callback *cb)
424 struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
426 nfc_device_iter_exit(iter);
432 int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
433 u8 comm_mode, u8 rf_mode)
438 pr_debug("DEP link is up\n");
440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
444 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, NFC_CMD_DEP_LINK_UP);
448 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
449 goto nla_put_failure;
450 if (rf_mode == NFC_RF_INITIATOR &&
451 nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
452 goto nla_put_failure;
453 if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) ||
454 nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode))
455 goto nla_put_failure;
457 genlmsg_end(msg, hdr);
459 dev->dep_link_up = true;
461 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
466 genlmsg_cancel(msg, hdr);
472 int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
477 pr_debug("DEP link is down\n");
479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
483 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
484 NFC_CMD_DEP_LINK_DOWN);
488 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
489 goto nla_put_failure;
491 genlmsg_end(msg, hdr);
493 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
498 genlmsg_cancel(msg, hdr);
504 static int nfc_genl_get_device(struct sk_buff *skb, struct genl_info *info)
511 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
514 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
516 dev = nfc_get_device(idx);
520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
526 rc = nfc_genl_send_device(msg, dev, info->snd_portid, info->snd_seq,
533 return genlmsg_reply(msg, info);
542 static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
548 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
551 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
553 dev = nfc_get_device(idx);
557 rc = nfc_dev_up(dev);
563 static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
569 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
572 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
574 dev = nfc_get_device(idx);
578 rc = nfc_dev_down(dev);
584 static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
589 u32 im_protocols = 0, tm_protocols = 0;
591 pr_debug("Poll start\n");
593 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
594 ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
595 !info->attrs[NFC_ATTR_PROTOCOLS]) &&
596 !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
599 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
601 if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
602 tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
604 if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
605 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
606 else if (info->attrs[NFC_ATTR_PROTOCOLS])
607 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
609 dev = nfc_get_device(idx);
613 mutex_lock(&dev->genl_data.genl_data_mutex);
615 rc = nfc_start_poll(dev, im_protocols, tm_protocols);
617 dev->genl_data.poll_req_portid = info->snd_portid;
619 mutex_unlock(&dev->genl_data.genl_data_mutex);
625 static int nfc_genl_stop_poll(struct sk_buff *skb, struct genl_info *info)
631 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
634 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
636 dev = nfc_get_device(idx);
640 device_lock(&dev->dev);
643 device_unlock(&dev->dev);
647 device_unlock(&dev->dev);
649 mutex_lock(&dev->genl_data.genl_data_mutex);
651 if (dev->genl_data.poll_req_portid != info->snd_portid) {
656 rc = nfc_stop_poll(dev);
657 dev->genl_data.poll_req_portid = 0;
660 mutex_unlock(&dev->genl_data.genl_data_mutex);
665 static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
672 pr_debug("DEP link up\n");
674 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
675 !info->attrs[NFC_ATTR_COMM_MODE])
678 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
679 if (!info->attrs[NFC_ATTR_TARGET_INDEX])
680 tgt_idx = NFC_TARGET_IDX_ANY;
682 tgt_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
684 comm = nla_get_u8(info->attrs[NFC_ATTR_COMM_MODE]);
686 if (comm != NFC_COMM_ACTIVE && comm != NFC_COMM_PASSIVE)
689 dev = nfc_get_device(idx);
693 rc = nfc_dep_link_up(dev, tgt_idx, comm);
700 static int nfc_genl_dep_link_down(struct sk_buff *skb, struct genl_info *info)
706 if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
709 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
711 dev = nfc_get_device(idx);
715 rc = nfc_dep_link_down(dev);
721 static int nfc_genl_send_params(struct sk_buff *msg,
722 struct nfc_llcp_local *local,
727 hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, 0,
728 NFC_CMD_LLC_GET_PARAMS);
732 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, local->dev->idx) ||
733 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_LTO, local->lto) ||
734 nla_put_u8(msg, NFC_ATTR_LLC_PARAM_RW, local->rw) ||
735 nla_put_u16(msg, NFC_ATTR_LLC_PARAM_MIUX, be16_to_cpu(local->miux)))
736 goto nla_put_failure;
738 return genlmsg_end(msg, hdr);
742 genlmsg_cancel(msg, hdr);
746 static int nfc_genl_llc_get_params(struct sk_buff *skb, struct genl_info *info)
749 struct nfc_llcp_local *local;
751 struct sk_buff *msg = NULL;
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 device_lock(&dev->dev);
765 local = nfc_llcp_find_local(dev);
771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
777 rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
780 device_unlock(&dev->dev);
791 return genlmsg_reply(msg, info);
794 static int nfc_genl_llc_set_params(struct sk_buff *skb, struct genl_info *info)
797 struct nfc_llcp_local *local;
803 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
804 (!info->attrs[NFC_ATTR_LLC_PARAM_LTO] &&
805 !info->attrs[NFC_ATTR_LLC_PARAM_RW] &&
806 !info->attrs[NFC_ATTR_LLC_PARAM_MIUX]))
809 if (info->attrs[NFC_ATTR_LLC_PARAM_RW]) {
810 rw = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_RW]);
812 if (rw > LLCP_MAX_RW)
816 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) {
817 miux = nla_get_u16(info->attrs[NFC_ATTR_LLC_PARAM_MIUX]);
819 if (miux > LLCP_MAX_MIUX)
823 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
825 dev = nfc_get_device(idx);
829 device_lock(&dev->dev);
831 local = nfc_llcp_find_local(dev);
838 if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
839 if (dev->dep_link_up) {
844 local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
847 if (info->attrs[NFC_ATTR_LLC_PARAM_RW])
850 if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
851 local->miux = cpu_to_be16(miux);
854 device_unlock(&dev->dev);
861 static struct genl_ops nfc_genl_ops[] = {
863 .cmd = NFC_CMD_GET_DEVICE,
864 .doit = nfc_genl_get_device,
865 .dumpit = nfc_genl_dump_devices,
866 .done = nfc_genl_dump_devices_done,
867 .policy = nfc_genl_policy,
870 .cmd = NFC_CMD_DEV_UP,
871 .doit = nfc_genl_dev_up,
872 .policy = nfc_genl_policy,
875 .cmd = NFC_CMD_DEV_DOWN,
876 .doit = nfc_genl_dev_down,
877 .policy = nfc_genl_policy,
880 .cmd = NFC_CMD_START_POLL,
881 .doit = nfc_genl_start_poll,
882 .policy = nfc_genl_policy,
885 .cmd = NFC_CMD_STOP_POLL,
886 .doit = nfc_genl_stop_poll,
887 .policy = nfc_genl_policy,
890 .cmd = NFC_CMD_DEP_LINK_UP,
891 .doit = nfc_genl_dep_link_up,
892 .policy = nfc_genl_policy,
895 .cmd = NFC_CMD_DEP_LINK_DOWN,
896 .doit = nfc_genl_dep_link_down,
897 .policy = nfc_genl_policy,
900 .cmd = NFC_CMD_GET_TARGET,
901 .dumpit = nfc_genl_dump_targets,
902 .done = nfc_genl_dump_targets_done,
903 .policy = nfc_genl_policy,
906 .cmd = NFC_CMD_LLC_GET_PARAMS,
907 .doit = nfc_genl_llc_get_params,
908 .policy = nfc_genl_policy,
911 .cmd = NFC_CMD_LLC_SET_PARAMS,
912 .doit = nfc_genl_llc_set_params,
913 .policy = nfc_genl_policy,
918 struct urelease_work {
919 struct work_struct w;
923 static void nfc_urelease_event_work(struct work_struct *work)
925 struct urelease_work *w = container_of(work, struct urelease_work, w);
926 struct class_dev_iter iter;
929 pr_debug("portid %d\n", w->portid);
931 mutex_lock(&nfc_devlist_mutex);
933 nfc_device_iter_init(&iter);
934 dev = nfc_device_iter_next(&iter);
937 mutex_lock(&dev->genl_data.genl_data_mutex);
939 if (dev->genl_data.poll_req_portid == w->portid) {
941 dev->genl_data.poll_req_portid = 0;
944 mutex_unlock(&dev->genl_data.genl_data_mutex);
946 dev = nfc_device_iter_next(&iter);
949 nfc_device_iter_exit(&iter);
951 mutex_unlock(&nfc_devlist_mutex);
956 static int nfc_genl_rcv_nl_event(struct notifier_block *this,
957 unsigned long event, void *ptr)
959 struct netlink_notify *n = ptr;
960 struct urelease_work *w;
962 if (event != NETLINK_URELEASE || n->protocol != NETLINK_GENERIC)
965 pr_debug("NETLINK_URELEASE event from id %d\n", n->portid);
967 w = kmalloc(sizeof(*w), GFP_ATOMIC);
969 INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
970 w->portid = n->portid;
971 schedule_work((struct work_struct *) w);
978 void nfc_genl_data_init(struct nfc_genl_data *genl_data)
980 genl_data->poll_req_portid = 0;
981 mutex_init(&genl_data->genl_data_mutex);
984 void nfc_genl_data_exit(struct nfc_genl_data *genl_data)
986 mutex_destroy(&genl_data->genl_data_mutex);
989 static struct notifier_block nl_notifier = {
990 .notifier_call = nfc_genl_rcv_nl_event,
994 * nfc_genl_init() - Initialize netlink interface
996 * This initialization function registers the nfc netlink family.
998 int __init nfc_genl_init(void)
1002 rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops,
1003 ARRAY_SIZE(nfc_genl_ops));
1007 rc = genl_register_mc_group(&nfc_genl_family, &nfc_genl_event_mcgrp);
1009 netlink_register_notifier(&nl_notifier);
1015 * nfc_genl_exit() - Deinitialize netlink interface
1017 * This exit function unregisters the nfc netlink family.
1019 void nfc_genl_exit(void)
1021 netlink_unregister_notifier(&nl_notifier);
1022 genl_unregister_family(&nfc_genl_family);