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 .id
= GENL_ID_GENERATE
,
44 .name
= NFC_GENL_NAME
,
45 .version
= NFC_GENL_VERSION
,
46 .maxattr
= NFC_ATTR_MAX
,
49 static const struct nla_policy nfc_genl_policy
[NFC_ATTR_MAX
+ 1] = {
50 [NFC_ATTR_DEVICE_INDEX
] = { .type
= NLA_U32
},
51 [NFC_ATTR_DEVICE_NAME
] = { .type
= NLA_STRING
,
52 .len
= NFC_DEVICE_NAME_MAXSIZE
},
53 [NFC_ATTR_PROTOCOLS
] = { .type
= NLA_U32
},
54 [NFC_ATTR_COMM_MODE
] = { .type
= NLA_U8
},
55 [NFC_ATTR_RF_MODE
] = { .type
= NLA_U8
},
56 [NFC_ATTR_DEVICE_POWERED
] = { .type
= NLA_U8
},
57 [NFC_ATTR_IM_PROTOCOLS
] = { .type
= NLA_U32
},
58 [NFC_ATTR_TM_PROTOCOLS
] = { .type
= NLA_U32
},
59 [NFC_ATTR_LLC_PARAM_LTO
] = { .type
= NLA_U8
},
60 [NFC_ATTR_LLC_PARAM_RW
] = { .type
= NLA_U8
},
61 [NFC_ATTR_LLC_PARAM_MIUX
] = { .type
= NLA_U16
},
62 [NFC_ATTR_LLC_SDP
] = { .type
= NLA_NESTED
},
63 [NFC_ATTR_FIRMWARE_NAME
] = { .type
= NLA_STRING
,
64 .len
= NFC_FIRMWARE_NAME_MAXSIZE
},
65 [NFC_ATTR_SE_APDU
] = { .type
= NLA_BINARY
},
66 [NFC_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
70 static const struct nla_policy nfc_sdp_genl_policy
[NFC_SDP_ATTR_MAX
+ 1] = {
71 [NFC_SDP_ATTR_URI
] = { .type
= NLA_STRING
,
73 [NFC_SDP_ATTR_SAP
] = { .type
= NLA_U8
},
76 static int nfc_genl_send_target(struct sk_buff
*msg
, struct nfc_target
*target
,
77 struct netlink_callback
*cb
, int flags
)
81 hdr
= genlmsg_put(msg
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
82 &nfc_genl_family
, flags
, NFC_CMD_GET_TARGET
);
86 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
88 if (nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target
->idx
) ||
89 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, target
->supported_protocols
) ||
90 nla_put_u16(msg
, NFC_ATTR_TARGET_SENS_RES
, target
->sens_res
) ||
91 nla_put_u8(msg
, NFC_ATTR_TARGET_SEL_RES
, target
->sel_res
))
93 if (target
->nfcid1_len
> 0 &&
94 nla_put(msg
, NFC_ATTR_TARGET_NFCID1
, target
->nfcid1_len
,
97 if (target
->sensb_res_len
> 0 &&
98 nla_put(msg
, NFC_ATTR_TARGET_SENSB_RES
, target
->sensb_res_len
,
100 goto nla_put_failure
;
101 if (target
->sensf_res_len
> 0 &&
102 nla_put(msg
, NFC_ATTR_TARGET_SENSF_RES
, target
->sensf_res_len
,
104 goto nla_put_failure
;
106 if (target
->is_iso15693
) {
107 if (nla_put_u8(msg
, NFC_ATTR_TARGET_ISO15693_DSFID
,
108 target
->iso15693_dsfid
) ||
109 nla_put(msg
, NFC_ATTR_TARGET_ISO15693_UID
,
110 sizeof(target
->iso15693_uid
), target
->iso15693_uid
))
111 goto nla_put_failure
;
114 genlmsg_end(msg
, hdr
);
118 genlmsg_cancel(msg
, hdr
);
122 static struct nfc_dev
*__get_device_from_cb(struct netlink_callback
*cb
)
128 rc
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nfc_genl_family
.hdrsize
,
129 nfc_genl_family
.attrbuf
,
130 nfc_genl_family
.maxattr
,
135 if (!nfc_genl_family
.attrbuf
[NFC_ATTR_DEVICE_INDEX
])
136 return ERR_PTR(-EINVAL
);
138 idx
= nla_get_u32(nfc_genl_family
.attrbuf
[NFC_ATTR_DEVICE_INDEX
]);
140 dev
= nfc_get_device(idx
);
142 return ERR_PTR(-ENODEV
);
147 static int nfc_genl_dump_targets(struct sk_buff
*skb
,
148 struct netlink_callback
*cb
)
151 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
155 dev
= __get_device_from_cb(cb
);
159 cb
->args
[1] = (long) dev
;
162 device_lock(&dev
->dev
);
164 cb
->seq
= dev
->targets_generation
;
166 while (i
< dev
->n_targets
) {
167 rc
= nfc_genl_send_target(skb
, &dev
->targets
[i
], cb
,
175 device_unlock(&dev
->dev
);
182 static int nfc_genl_dump_targets_done(struct netlink_callback
*cb
)
184 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
192 int nfc_genl_targets_found(struct nfc_dev
*dev
)
197 dev
->genl_data
.poll_req_portid
= 0;
199 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
203 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
204 NFC_EVENT_TARGETS_FOUND
);
208 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
209 goto nla_put_failure
;
211 genlmsg_end(msg
, hdr
);
213 return genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_ATOMIC
);
216 genlmsg_cancel(msg
, hdr
);
222 int nfc_genl_target_lost(struct nfc_dev
*dev
, u32 target_idx
)
227 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
231 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
232 NFC_EVENT_TARGET_LOST
);
236 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
237 nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target_idx
))
238 goto nla_put_failure
;
240 genlmsg_end(msg
, hdr
);
242 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
247 genlmsg_cancel(msg
, hdr
);
253 int nfc_genl_tm_activated(struct nfc_dev
*dev
, u32 protocol
)
258 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
262 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
263 NFC_EVENT_TM_ACTIVATED
);
267 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
268 goto nla_put_failure
;
269 if (nla_put_u32(msg
, NFC_ATTR_TM_PROTOCOLS
, protocol
))
270 goto nla_put_failure
;
272 genlmsg_end(msg
, hdr
);
274 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
279 genlmsg_cancel(msg
, hdr
);
285 int nfc_genl_tm_deactivated(struct nfc_dev
*dev
)
290 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
294 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
295 NFC_EVENT_TM_DEACTIVATED
);
299 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
300 goto nla_put_failure
;
302 genlmsg_end(msg
, hdr
);
304 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
309 genlmsg_cancel(msg
, hdr
);
315 int nfc_genl_device_added(struct nfc_dev
*dev
)
320 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
324 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
325 NFC_EVENT_DEVICE_ADDED
);
329 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
330 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
331 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, dev
->supported_protocols
) ||
332 nla_put_u8(msg
, NFC_ATTR_DEVICE_POWERED
, dev
->dev_up
))
333 goto nla_put_failure
;
335 genlmsg_end(msg
, hdr
);
337 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
342 genlmsg_cancel(msg
, hdr
);
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
);
372 genlmsg_cancel(msg
, hdr
);
378 int nfc_genl_llc_send_sdres(struct nfc_dev
*dev
, struct hlist_head
*sdres_list
)
381 struct nlattr
*sdp_attr
, *uri_attr
;
382 struct nfc_llcp_sdp_tlv
*sdres
;
383 struct hlist_node
*n
;
388 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
392 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
393 NFC_EVENT_LLC_SDRES
);
397 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
398 goto nla_put_failure
;
400 sdp_attr
= nla_nest_start(msg
, NFC_ATTR_LLC_SDP
);
401 if (sdp_attr
== NULL
) {
403 goto nla_put_failure
;
407 hlist_for_each_entry_safe(sdres
, n
, sdres_list
, node
) {
408 pr_debug("uri: %s, sap: %d\n", sdres
->uri
, sdres
->sap
);
410 uri_attr
= nla_nest_start(msg
, i
++);
411 if (uri_attr
== NULL
) {
413 goto nla_put_failure
;
416 if (nla_put_u8(msg
, NFC_SDP_ATTR_SAP
, sdres
->sap
))
417 goto nla_put_failure
;
419 if (nla_put_string(msg
, NFC_SDP_ATTR_URI
, sdres
->uri
))
420 goto nla_put_failure
;
422 nla_nest_end(msg
, uri_attr
);
424 hlist_del(&sdres
->node
);
426 nfc_llcp_free_sdp_tlv(sdres
);
429 nla_nest_end(msg
, sdp_attr
);
431 genlmsg_end(msg
, hdr
);
433 return genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_ATOMIC
);
436 genlmsg_cancel(msg
, hdr
);
441 nfc_llcp_free_sdp_tlv_list(sdres_list
);
446 int nfc_genl_se_added(struct nfc_dev
*dev
, u32 se_idx
, u16 type
)
451 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
455 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
460 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
461 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se_idx
) ||
462 nla_put_u8(msg
, NFC_ATTR_SE_TYPE
, type
))
463 goto nla_put_failure
;
465 genlmsg_end(msg
, hdr
);
467 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
472 genlmsg_cancel(msg
, hdr
);
478 int nfc_genl_se_removed(struct nfc_dev
*dev
, u32 se_idx
)
483 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
487 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
488 NFC_EVENT_SE_REMOVED
);
492 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
493 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se_idx
))
494 goto nla_put_failure
;
496 genlmsg_end(msg
, hdr
);
498 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
503 genlmsg_cancel(msg
, hdr
);
509 int nfc_genl_se_transaction(struct nfc_dev
*dev
, u8 se_idx
,
510 struct nfc_evt_transaction
*evt_transaction
)
516 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
520 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
521 NFC_EVENT_SE_TRANSACTION
);
525 se
= nfc_find_se(dev
, se_idx
);
529 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
530 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se_idx
) ||
531 nla_put_u8(msg
, NFC_ATTR_SE_TYPE
, se
->type
) ||
532 nla_put(msg
, NFC_ATTR_SE_AID
, evt_transaction
->aid_len
,
533 evt_transaction
->aid
) ||
534 nla_put(msg
, NFC_ATTR_SE_PARAMS
, evt_transaction
->params_len
,
535 evt_transaction
->params
))
536 goto nla_put_failure
;
538 /* evt_transaction is no more used */
539 devm_kfree(&dev
->dev
, evt_transaction
);
541 genlmsg_end(msg
, hdr
);
543 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
548 genlmsg_cancel(msg
, hdr
);
550 /* evt_transaction is no more used */
551 devm_kfree(&dev
->dev
, evt_transaction
);
556 static int nfc_genl_send_device(struct sk_buff
*msg
, struct nfc_dev
*dev
,
558 struct netlink_callback
*cb
,
563 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, flags
,
569 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
571 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
572 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
573 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, dev
->supported_protocols
) ||
574 nla_put_u8(msg
, NFC_ATTR_DEVICE_POWERED
, dev
->dev_up
) ||
575 nla_put_u8(msg
, NFC_ATTR_RF_MODE
, dev
->rf_mode
))
576 goto nla_put_failure
;
578 genlmsg_end(msg
, hdr
);
582 genlmsg_cancel(msg
, hdr
);
586 static int nfc_genl_dump_devices(struct sk_buff
*skb
,
587 struct netlink_callback
*cb
)
589 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
590 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
591 bool first_call
= false;
595 iter
= kmalloc(sizeof(struct class_dev_iter
), GFP_KERNEL
);
598 cb
->args
[0] = (long) iter
;
601 mutex_lock(&nfc_devlist_mutex
);
603 cb
->seq
= nfc_devlist_generation
;
606 nfc_device_iter_init(iter
);
607 dev
= nfc_device_iter_next(iter
);
613 rc
= nfc_genl_send_device(skb
, dev
, NETLINK_CB(cb
->skb
).portid
,
614 cb
->nlh
->nlmsg_seq
, cb
, NLM_F_MULTI
);
618 dev
= nfc_device_iter_next(iter
);
621 mutex_unlock(&nfc_devlist_mutex
);
623 cb
->args
[1] = (long) dev
;
628 static int nfc_genl_dump_devices_done(struct netlink_callback
*cb
)
630 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
632 nfc_device_iter_exit(iter
);
638 int nfc_genl_dep_link_up_event(struct nfc_dev
*dev
, u32 target_idx
,
639 u8 comm_mode
, u8 rf_mode
)
644 pr_debug("DEP link is up\n");
646 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
650 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0, NFC_CMD_DEP_LINK_UP
);
654 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
655 goto nla_put_failure
;
656 if (rf_mode
== NFC_RF_INITIATOR
&&
657 nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target_idx
))
658 goto nla_put_failure
;
659 if (nla_put_u8(msg
, NFC_ATTR_COMM_MODE
, comm_mode
) ||
660 nla_put_u8(msg
, NFC_ATTR_RF_MODE
, rf_mode
))
661 goto nla_put_failure
;
663 genlmsg_end(msg
, hdr
);
665 dev
->dep_link_up
= true;
667 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_ATOMIC
);
672 genlmsg_cancel(msg
, hdr
);
678 int nfc_genl_dep_link_down_event(struct nfc_dev
*dev
)
683 pr_debug("DEP link is down\n");
685 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
689 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
690 NFC_CMD_DEP_LINK_DOWN
);
694 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
695 goto nla_put_failure
;
697 genlmsg_end(msg
, hdr
);
699 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_ATOMIC
);
704 genlmsg_cancel(msg
, hdr
);
710 static int nfc_genl_get_device(struct sk_buff
*skb
, struct genl_info
*info
)
717 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
720 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
722 dev
= nfc_get_device(idx
);
726 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
732 rc
= nfc_genl_send_device(msg
, dev
, info
->snd_portid
, info
->snd_seq
,
739 return genlmsg_reply(msg
, info
);
748 static int nfc_genl_dev_up(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 rc
= nfc_dev_up(dev
);
769 static int nfc_genl_dev_down(struct sk_buff
*skb
, struct genl_info
*info
)
775 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
778 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
780 dev
= nfc_get_device(idx
);
784 rc
= nfc_dev_down(dev
);
790 static int nfc_genl_start_poll(struct sk_buff
*skb
, struct genl_info
*info
)
795 u32 im_protocols
= 0, tm_protocols
= 0;
797 pr_debug("Poll start\n");
799 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
800 ((!info
->attrs
[NFC_ATTR_IM_PROTOCOLS
] &&
801 !info
->attrs
[NFC_ATTR_PROTOCOLS
]) &&
802 !info
->attrs
[NFC_ATTR_TM_PROTOCOLS
]))
805 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
807 if (info
->attrs
[NFC_ATTR_TM_PROTOCOLS
])
808 tm_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_TM_PROTOCOLS
]);
810 if (info
->attrs
[NFC_ATTR_IM_PROTOCOLS
])
811 im_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_IM_PROTOCOLS
]);
812 else if (info
->attrs
[NFC_ATTR_PROTOCOLS
])
813 im_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_PROTOCOLS
]);
815 dev
= nfc_get_device(idx
);
819 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
821 rc
= nfc_start_poll(dev
, im_protocols
, tm_protocols
);
823 dev
->genl_data
.poll_req_portid
= info
->snd_portid
;
825 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
831 static int nfc_genl_stop_poll(struct sk_buff
*skb
, struct genl_info
*info
)
837 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
840 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
842 dev
= nfc_get_device(idx
);
846 device_lock(&dev
->dev
);
849 device_unlock(&dev
->dev
);
853 device_unlock(&dev
->dev
);
855 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
857 if (dev
->genl_data
.poll_req_portid
!= info
->snd_portid
) {
862 rc
= nfc_stop_poll(dev
);
863 dev
->genl_data
.poll_req_portid
= 0;
866 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
871 static int nfc_genl_activate_target(struct sk_buff
*skb
, struct genl_info
*info
)
874 u32 device_idx
, target_idx
, protocol
;
877 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
878 !info
->attrs
[NFC_ATTR_TARGET_INDEX
] ||
879 !info
->attrs
[NFC_ATTR_PROTOCOLS
])
882 device_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
884 dev
= nfc_get_device(device_idx
);
888 target_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_TARGET_INDEX
]);
889 protocol
= nla_get_u32(info
->attrs
[NFC_ATTR_PROTOCOLS
]);
891 nfc_deactivate_target(dev
, target_idx
, NFC_TARGET_MODE_SLEEP
);
892 rc
= nfc_activate_target(dev
, target_idx
, protocol
);
898 static int nfc_genl_dep_link_up(struct sk_buff
*skb
, struct genl_info
*info
)
905 pr_debug("DEP link up\n");
907 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
908 !info
->attrs
[NFC_ATTR_COMM_MODE
])
911 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
912 if (!info
->attrs
[NFC_ATTR_TARGET_INDEX
])
913 tgt_idx
= NFC_TARGET_IDX_ANY
;
915 tgt_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_TARGET_INDEX
]);
917 comm
= nla_get_u8(info
->attrs
[NFC_ATTR_COMM_MODE
]);
919 if (comm
!= NFC_COMM_ACTIVE
&& comm
!= NFC_COMM_PASSIVE
)
922 dev
= nfc_get_device(idx
);
926 rc
= nfc_dep_link_up(dev
, tgt_idx
, comm
);
933 static int nfc_genl_dep_link_down(struct sk_buff
*skb
, struct genl_info
*info
)
939 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
942 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
944 dev
= nfc_get_device(idx
);
948 rc
= nfc_dep_link_down(dev
);
954 static int nfc_genl_send_params(struct sk_buff
*msg
,
955 struct nfc_llcp_local
*local
,
960 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, 0,
961 NFC_CMD_LLC_GET_PARAMS
);
965 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, local
->dev
->idx
) ||
966 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_LTO
, local
->lto
) ||
967 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_RW
, local
->rw
) ||
968 nla_put_u16(msg
, NFC_ATTR_LLC_PARAM_MIUX
, be16_to_cpu(local
->miux
)))
969 goto nla_put_failure
;
971 genlmsg_end(msg
, hdr
);
976 genlmsg_cancel(msg
, hdr
);
980 static int nfc_genl_llc_get_params(struct sk_buff
*skb
, struct genl_info
*info
)
983 struct nfc_llcp_local
*local
;
985 struct sk_buff
*msg
= NULL
;
988 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
991 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
993 dev
= nfc_get_device(idx
);
997 device_lock(&dev
->dev
);
999 local
= nfc_llcp_find_local(dev
);
1005 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1011 rc
= nfc_genl_send_params(msg
, local
, info
->snd_portid
, info
->snd_seq
);
1014 device_unlock(&dev
->dev
);
1016 nfc_put_device(dev
);
1025 return genlmsg_reply(msg
, info
);
1028 static int nfc_genl_llc_set_params(struct sk_buff
*skb
, struct genl_info
*info
)
1030 struct nfc_dev
*dev
;
1031 struct nfc_llcp_local
*local
;
1037 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1038 (!info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
] &&
1039 !info
->attrs
[NFC_ATTR_LLC_PARAM_RW
] &&
1040 !info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]))
1043 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]) {
1044 rw
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]);
1046 if (rw
> LLCP_MAX_RW
)
1050 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]) {
1051 miux
= nla_get_u16(info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]);
1053 if (miux
> LLCP_MAX_MIUX
)
1057 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1059 dev
= nfc_get_device(idx
);
1063 device_lock(&dev
->dev
);
1065 local
= nfc_llcp_find_local(dev
);
1067 nfc_put_device(dev
);
1072 if (info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]) {
1073 if (dev
->dep_link_up
) {
1078 local
->lto
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]);
1081 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
])
1084 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
])
1085 local
->miux
= cpu_to_be16(miux
);
1088 device_unlock(&dev
->dev
);
1090 nfc_put_device(dev
);
1095 static int nfc_genl_llc_sdreq(struct sk_buff
*skb
, struct genl_info
*info
)
1097 struct nfc_dev
*dev
;
1098 struct nfc_llcp_local
*local
;
1099 struct nlattr
*attr
, *sdp_attrs
[NFC_SDP_ATTR_MAX
+1];
1104 size_t uri_len
, tlvs_len
;
1105 struct hlist_head sdreq_list
;
1106 struct nfc_llcp_sdp_tlv
*sdreq
;
1108 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1109 !info
->attrs
[NFC_ATTR_LLC_SDP
])
1112 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1114 dev
= nfc_get_device(idx
);
1118 device_lock(&dev
->dev
);
1120 if (dev
->dep_link_up
== false) {
1125 local
= nfc_llcp_find_local(dev
);
1127 nfc_put_device(dev
);
1132 INIT_HLIST_HEAD(&sdreq_list
);
1136 nla_for_each_nested(attr
, info
->attrs
[NFC_ATTR_LLC_SDP
], rem
) {
1137 rc
= nla_parse_nested(sdp_attrs
, NFC_SDP_ATTR_MAX
, attr
,
1138 nfc_sdp_genl_policy
);
1145 if (!sdp_attrs
[NFC_SDP_ATTR_URI
])
1148 uri_len
= nla_len(sdp_attrs
[NFC_SDP_ATTR_URI
]);
1152 uri
= nla_data(sdp_attrs
[NFC_SDP_ATTR_URI
]);
1153 if (uri
== NULL
|| *uri
== 0)
1156 tid
= local
->sdreq_next_tid
++;
1158 sdreq
= nfc_llcp_build_sdreq_tlv(tid
, uri
, uri_len
);
1159 if (sdreq
== NULL
) {
1164 tlvs_len
+= sdreq
->tlv_len
;
1166 hlist_add_head(&sdreq
->node
, &sdreq_list
);
1169 if (hlist_empty(&sdreq_list
)) {
1174 rc
= nfc_llcp_send_snl_sdreq(local
, &sdreq_list
, tlvs_len
);
1176 device_unlock(&dev
->dev
);
1178 nfc_put_device(dev
);
1183 static int nfc_genl_fw_download(struct sk_buff
*skb
, struct genl_info
*info
)
1185 struct nfc_dev
*dev
;
1188 char firmware_name
[NFC_FIRMWARE_NAME_MAXSIZE
+ 1];
1190 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
1193 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1195 dev
= nfc_get_device(idx
);
1199 nla_strlcpy(firmware_name
, info
->attrs
[NFC_ATTR_FIRMWARE_NAME
],
1200 sizeof(firmware_name
));
1202 rc
= nfc_fw_download(dev
, firmware_name
);
1204 nfc_put_device(dev
);
1208 int nfc_genl_fw_download_done(struct nfc_dev
*dev
, const char *firmware_name
,
1211 struct sk_buff
*msg
;
1214 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1218 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
1219 NFC_CMD_FW_DOWNLOAD
);
1223 if (nla_put_string(msg
, NFC_ATTR_FIRMWARE_NAME
, firmware_name
) ||
1224 nla_put_u32(msg
, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS
, result
) ||
1225 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
1226 goto nla_put_failure
;
1228 genlmsg_end(msg
, hdr
);
1230 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
1235 genlmsg_cancel(msg
, hdr
);
1241 static int nfc_genl_enable_se(struct sk_buff
*skb
, struct genl_info
*info
)
1243 struct nfc_dev
*dev
;
1247 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1248 !info
->attrs
[NFC_ATTR_SE_INDEX
])
1251 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1252 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1254 dev
= nfc_get_device(idx
);
1258 rc
= nfc_enable_se(dev
, se_idx
);
1260 nfc_put_device(dev
);
1264 static int nfc_genl_disable_se(struct sk_buff
*skb
, struct genl_info
*info
)
1266 struct nfc_dev
*dev
;
1270 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1271 !info
->attrs
[NFC_ATTR_SE_INDEX
])
1274 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1275 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1277 dev
= nfc_get_device(idx
);
1281 rc
= nfc_disable_se(dev
, se_idx
);
1283 nfc_put_device(dev
);
1287 static int nfc_genl_send_se(struct sk_buff
*msg
, struct nfc_dev
*dev
,
1288 u32 portid
, u32 seq
,
1289 struct netlink_callback
*cb
,
1293 struct nfc_se
*se
, *n
;
1295 list_for_each_entry_safe(se
, n
, &dev
->secure_elements
, list
) {
1296 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, flags
,
1299 goto nla_put_failure
;
1302 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
1304 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
1305 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se
->idx
) ||
1306 nla_put_u8(msg
, NFC_ATTR_SE_TYPE
, se
->type
))
1307 goto nla_put_failure
;
1309 genlmsg_end(msg
, hdr
);
1315 genlmsg_cancel(msg
, hdr
);
1319 static int nfc_genl_dump_ses(struct sk_buff
*skb
,
1320 struct netlink_callback
*cb
)
1322 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
1323 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
1324 bool first_call
= false;
1328 iter
= kmalloc(sizeof(struct class_dev_iter
), GFP_KERNEL
);
1331 cb
->args
[0] = (long) iter
;
1334 mutex_lock(&nfc_devlist_mutex
);
1336 cb
->seq
= nfc_devlist_generation
;
1339 nfc_device_iter_init(iter
);
1340 dev
= nfc_device_iter_next(iter
);
1346 rc
= nfc_genl_send_se(skb
, dev
, NETLINK_CB(cb
->skb
).portid
,
1347 cb
->nlh
->nlmsg_seq
, cb
, NLM_F_MULTI
);
1351 dev
= nfc_device_iter_next(iter
);
1354 mutex_unlock(&nfc_devlist_mutex
);
1356 cb
->args
[1] = (long) dev
;
1361 static int nfc_genl_dump_ses_done(struct netlink_callback
*cb
)
1363 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
1365 nfc_device_iter_exit(iter
);
1371 static int nfc_se_io(struct nfc_dev
*dev
, u32 se_idx
,
1372 u8
*apdu
, size_t apdu_length
,
1373 se_io_cb_t cb
, void *cb_context
)
1378 pr_debug("%s se index %d\n", dev_name(&dev
->dev
), se_idx
);
1380 device_lock(&dev
->dev
);
1382 if (!device_is_registered(&dev
->dev
)) {
1392 if (!dev
->ops
->se_io
) {
1397 se
= nfc_find_se(dev
, se_idx
);
1403 if (se
->state
!= NFC_SE_ENABLED
) {
1408 rc
= dev
->ops
->se_io(dev
, se_idx
, apdu
,
1409 apdu_length
, cb
, cb_context
);
1412 device_unlock(&dev
->dev
);
1421 static void se_io_cb(void *context
, u8
*apdu
, size_t apdu_len
, int err
)
1423 struct se_io_ctx
*ctx
= context
;
1424 struct sk_buff
*msg
;
1427 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1433 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
1438 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, ctx
->dev_idx
) ||
1439 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, ctx
->se_idx
) ||
1440 nla_put(msg
, NFC_ATTR_SE_APDU
, apdu_len
, apdu
))
1441 goto nla_put_failure
;
1443 genlmsg_end(msg
, hdr
);
1445 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
1452 genlmsg_cancel(msg
, hdr
);
1460 static int nfc_genl_se_io(struct sk_buff
*skb
, struct genl_info
*info
)
1462 struct nfc_dev
*dev
;
1463 struct se_io_ctx
*ctx
;
1464 u32 dev_idx
, se_idx
;
1468 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1469 !info
->attrs
[NFC_ATTR_SE_INDEX
] ||
1470 !info
->attrs
[NFC_ATTR_SE_APDU
])
1473 dev_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1474 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1476 dev
= nfc_get_device(dev_idx
);
1480 if (!dev
->ops
|| !dev
->ops
->se_io
)
1483 apdu_len
= nla_len(info
->attrs
[NFC_ATTR_SE_APDU
]);
1487 apdu
= nla_data(info
->attrs
[NFC_ATTR_SE_APDU
]);
1491 ctx
= kzalloc(sizeof(struct se_io_ctx
), GFP_KERNEL
);
1495 ctx
->dev_idx
= dev_idx
;
1496 ctx
->se_idx
= se_idx
;
1498 return nfc_se_io(dev
, se_idx
, apdu
, apdu_len
, se_io_cb
, ctx
);
1501 static int nfc_genl_vendor_cmd(struct sk_buff
*skb
,
1502 struct genl_info
*info
)
1504 struct nfc_dev
*dev
;
1505 struct nfc_vendor_cmd
*cmd
;
1506 u32 dev_idx
, vid
, subcmd
;
1511 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1512 !info
->attrs
[NFC_ATTR_VENDOR_ID
] ||
1513 !info
->attrs
[NFC_ATTR_VENDOR_SUBCMD
])
1516 dev_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1517 vid
= nla_get_u32(info
->attrs
[NFC_ATTR_VENDOR_ID
]);
1518 subcmd
= nla_get_u32(info
->attrs
[NFC_ATTR_VENDOR_SUBCMD
]);
1520 dev
= nfc_get_device(dev_idx
);
1521 if (!dev
|| !dev
->vendor_cmds
|| !dev
->n_vendor_cmds
)
1524 if (info
->attrs
[NFC_ATTR_VENDOR_DATA
]) {
1525 data
= nla_data(info
->attrs
[NFC_ATTR_VENDOR_DATA
]);
1526 data_len
= nla_len(info
->attrs
[NFC_ATTR_VENDOR_DATA
]);
1534 for (i
= 0; i
< dev
->n_vendor_cmds
; i
++) {
1535 cmd
= &dev
->vendor_cmds
[i
];
1537 if (cmd
->vendor_id
!= vid
|| cmd
->subcmd
!= subcmd
)
1540 dev
->cur_cmd_info
= info
;
1541 err
= cmd
->doit(dev
, data
, data_len
);
1542 dev
->cur_cmd_info
= NULL
;
1549 /* message building helper */
1550 static inline void *nfc_hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
1553 /* since there is no private header just add the generic one */
1554 return genlmsg_put(skb
, portid
, seq
, &nfc_genl_family
, flags
, cmd
);
1557 static struct sk_buff
*
1558 __nfc_alloc_vendor_cmd_skb(struct nfc_dev
*dev
, int approxlen
,
1559 u32 portid
, u32 seq
,
1560 enum nfc_attrs attr
,
1561 u32 oui
, u32 subcmd
, gfp_t gfp
)
1563 struct sk_buff
*skb
;
1566 skb
= nlmsg_new(approxlen
+ 100, gfp
);
1570 hdr
= nfc_hdr_put(skb
, portid
, seq
, 0, NFC_CMD_VENDOR
);
1576 if (nla_put_u32(skb
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
1577 goto nla_put_failure
;
1578 if (nla_put_u32(skb
, NFC_ATTR_VENDOR_ID
, oui
))
1579 goto nla_put_failure
;
1580 if (nla_put_u32(skb
, NFC_ATTR_VENDOR_SUBCMD
, subcmd
))
1581 goto nla_put_failure
;
1583 ((void **)skb
->cb
)[0] = dev
;
1584 ((void **)skb
->cb
)[1] = hdr
;
1593 struct sk_buff
*__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev
*dev
,
1594 enum nfc_attrs attr
,
1595 u32 oui
, u32 subcmd
,
1598 if (WARN_ON(!dev
->cur_cmd_info
))
1601 return __nfc_alloc_vendor_cmd_skb(dev
, approxlen
,
1602 dev
->cur_cmd_info
->snd_portid
,
1603 dev
->cur_cmd_info
->snd_seq
, attr
,
1604 oui
, subcmd
, GFP_KERNEL
);
1606 EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb
);
1608 int nfc_vendor_cmd_reply(struct sk_buff
*skb
)
1610 struct nfc_dev
*dev
= ((void **)skb
->cb
)[0];
1611 void *hdr
= ((void **)skb
->cb
)[1];
1613 /* clear CB data for netlink core to own from now on */
1614 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1616 if (WARN_ON(!dev
->cur_cmd_info
)) {
1621 genlmsg_end(skb
, hdr
);
1622 return genlmsg_reply(skb
, dev
->cur_cmd_info
);
1624 EXPORT_SYMBOL(nfc_vendor_cmd_reply
);
1626 static const struct genl_ops nfc_genl_ops
[] = {
1628 .cmd
= NFC_CMD_GET_DEVICE
,
1629 .doit
= nfc_genl_get_device
,
1630 .dumpit
= nfc_genl_dump_devices
,
1631 .done
= nfc_genl_dump_devices_done
,
1632 .policy
= nfc_genl_policy
,
1635 .cmd
= NFC_CMD_DEV_UP
,
1636 .doit
= nfc_genl_dev_up
,
1637 .policy
= nfc_genl_policy
,
1640 .cmd
= NFC_CMD_DEV_DOWN
,
1641 .doit
= nfc_genl_dev_down
,
1642 .policy
= nfc_genl_policy
,
1645 .cmd
= NFC_CMD_START_POLL
,
1646 .doit
= nfc_genl_start_poll
,
1647 .policy
= nfc_genl_policy
,
1650 .cmd
= NFC_CMD_STOP_POLL
,
1651 .doit
= nfc_genl_stop_poll
,
1652 .policy
= nfc_genl_policy
,
1655 .cmd
= NFC_CMD_DEP_LINK_UP
,
1656 .doit
= nfc_genl_dep_link_up
,
1657 .policy
= nfc_genl_policy
,
1660 .cmd
= NFC_CMD_DEP_LINK_DOWN
,
1661 .doit
= nfc_genl_dep_link_down
,
1662 .policy
= nfc_genl_policy
,
1665 .cmd
= NFC_CMD_GET_TARGET
,
1666 .dumpit
= nfc_genl_dump_targets
,
1667 .done
= nfc_genl_dump_targets_done
,
1668 .policy
= nfc_genl_policy
,
1671 .cmd
= NFC_CMD_LLC_GET_PARAMS
,
1672 .doit
= nfc_genl_llc_get_params
,
1673 .policy
= nfc_genl_policy
,
1676 .cmd
= NFC_CMD_LLC_SET_PARAMS
,
1677 .doit
= nfc_genl_llc_set_params
,
1678 .policy
= nfc_genl_policy
,
1681 .cmd
= NFC_CMD_LLC_SDREQ
,
1682 .doit
= nfc_genl_llc_sdreq
,
1683 .policy
= nfc_genl_policy
,
1686 .cmd
= NFC_CMD_FW_DOWNLOAD
,
1687 .doit
= nfc_genl_fw_download
,
1688 .policy
= nfc_genl_policy
,
1691 .cmd
= NFC_CMD_ENABLE_SE
,
1692 .doit
= nfc_genl_enable_se
,
1693 .policy
= nfc_genl_policy
,
1696 .cmd
= NFC_CMD_DISABLE_SE
,
1697 .doit
= nfc_genl_disable_se
,
1698 .policy
= nfc_genl_policy
,
1701 .cmd
= NFC_CMD_GET_SE
,
1702 .dumpit
= nfc_genl_dump_ses
,
1703 .done
= nfc_genl_dump_ses_done
,
1704 .policy
= nfc_genl_policy
,
1707 .cmd
= NFC_CMD_SE_IO
,
1708 .doit
= nfc_genl_se_io
,
1709 .policy
= nfc_genl_policy
,
1712 .cmd
= NFC_CMD_ACTIVATE_TARGET
,
1713 .doit
= nfc_genl_activate_target
,
1714 .policy
= nfc_genl_policy
,
1717 .cmd
= NFC_CMD_VENDOR
,
1718 .doit
= nfc_genl_vendor_cmd
,
1719 .policy
= nfc_genl_policy
,
1724 struct urelease_work
{
1725 struct work_struct w
;
1729 static void nfc_urelease_event_work(struct work_struct
*work
)
1731 struct urelease_work
*w
= container_of(work
, struct urelease_work
, w
);
1732 struct class_dev_iter iter
;
1733 struct nfc_dev
*dev
;
1735 pr_debug("portid %d\n", w
->portid
);
1737 mutex_lock(&nfc_devlist_mutex
);
1739 nfc_device_iter_init(&iter
);
1740 dev
= nfc_device_iter_next(&iter
);
1743 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
1745 if (dev
->genl_data
.poll_req_portid
== w
->portid
) {
1747 dev
->genl_data
.poll_req_portid
= 0;
1750 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
1752 dev
= nfc_device_iter_next(&iter
);
1755 nfc_device_iter_exit(&iter
);
1757 mutex_unlock(&nfc_devlist_mutex
);
1762 static int nfc_genl_rcv_nl_event(struct notifier_block
*this,
1763 unsigned long event
, void *ptr
)
1765 struct netlink_notify
*n
= ptr
;
1766 struct urelease_work
*w
;
1768 if (event
!= NETLINK_URELEASE
|| n
->protocol
!= NETLINK_GENERIC
)
1771 pr_debug("NETLINK_URELEASE event from id %d\n", n
->portid
);
1773 w
= kmalloc(sizeof(*w
), GFP_ATOMIC
);
1775 INIT_WORK((struct work_struct
*) w
, nfc_urelease_event_work
);
1776 w
->portid
= n
->portid
;
1777 schedule_work((struct work_struct
*) w
);
1784 void nfc_genl_data_init(struct nfc_genl_data
*genl_data
)
1786 genl_data
->poll_req_portid
= 0;
1787 mutex_init(&genl_data
->genl_data_mutex
);
1790 void nfc_genl_data_exit(struct nfc_genl_data
*genl_data
)
1792 mutex_destroy(&genl_data
->genl_data_mutex
);
1795 static struct notifier_block nl_notifier
= {
1796 .notifier_call
= nfc_genl_rcv_nl_event
,
1800 * nfc_genl_init() - Initialize netlink interface
1802 * This initialization function registers the nfc netlink family.
1804 int __init
nfc_genl_init(void)
1808 rc
= genl_register_family_with_ops_groups(&nfc_genl_family
,
1814 netlink_register_notifier(&nl_notifier
);
1820 * nfc_genl_exit() - Deinitialize netlink interface
1822 * This exit function unregisters the nfc netlink family.
1824 void nfc_genl_exit(void)
1826 netlink_unregister_notifier(&nl_notifier
);
1827 genl_unregister_family(&nfc_genl_family
);