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 int nfc_genl_se_connectivity(struct nfc_dev
*dev
, u8 se_idx
)
562 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
566 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
567 NFC_EVENT_SE_CONNECTIVITY
);
571 se
= nfc_find_se(dev
, se_idx
);
575 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
576 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se_idx
) ||
577 nla_put_u8(msg
, NFC_ATTR_SE_TYPE
, se
->type
))
578 goto nla_put_failure
;
580 genlmsg_end(msg
, hdr
);
582 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
587 genlmsg_cancel(msg
, hdr
);
593 static int nfc_genl_send_device(struct sk_buff
*msg
, struct nfc_dev
*dev
,
595 struct netlink_callback
*cb
,
600 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, flags
,
606 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
608 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
609 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
610 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, dev
->supported_protocols
) ||
611 nla_put_u8(msg
, NFC_ATTR_DEVICE_POWERED
, dev
->dev_up
) ||
612 nla_put_u8(msg
, NFC_ATTR_RF_MODE
, dev
->rf_mode
))
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
);
890 device_unlock(&dev
->dev
);
892 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
894 if (dev
->genl_data
.poll_req_portid
!= info
->snd_portid
) {
899 rc
= nfc_stop_poll(dev
);
900 dev
->genl_data
.poll_req_portid
= 0;
903 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
908 static int nfc_genl_activate_target(struct sk_buff
*skb
, struct genl_info
*info
)
911 u32 device_idx
, target_idx
, protocol
;
914 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
915 !info
->attrs
[NFC_ATTR_TARGET_INDEX
] ||
916 !info
->attrs
[NFC_ATTR_PROTOCOLS
])
919 device_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
921 dev
= nfc_get_device(device_idx
);
925 target_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_TARGET_INDEX
]);
926 protocol
= nla_get_u32(info
->attrs
[NFC_ATTR_PROTOCOLS
]);
928 nfc_deactivate_target(dev
, target_idx
, NFC_TARGET_MODE_SLEEP
);
929 rc
= nfc_activate_target(dev
, target_idx
, protocol
);
935 static int nfc_genl_dep_link_up(struct sk_buff
*skb
, struct genl_info
*info
)
942 pr_debug("DEP link up\n");
944 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
945 !info
->attrs
[NFC_ATTR_COMM_MODE
])
948 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
949 if (!info
->attrs
[NFC_ATTR_TARGET_INDEX
])
950 tgt_idx
= NFC_TARGET_IDX_ANY
;
952 tgt_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_TARGET_INDEX
]);
954 comm
= nla_get_u8(info
->attrs
[NFC_ATTR_COMM_MODE
]);
956 if (comm
!= NFC_COMM_ACTIVE
&& comm
!= NFC_COMM_PASSIVE
)
959 dev
= nfc_get_device(idx
);
963 rc
= nfc_dep_link_up(dev
, tgt_idx
, comm
);
970 static int nfc_genl_dep_link_down(struct sk_buff
*skb
, struct genl_info
*info
)
976 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
979 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
981 dev
= nfc_get_device(idx
);
985 rc
= nfc_dep_link_down(dev
);
991 static int nfc_genl_send_params(struct sk_buff
*msg
,
992 struct nfc_llcp_local
*local
,
997 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, 0,
998 NFC_CMD_LLC_GET_PARAMS
);
1002 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, local
->dev
->idx
) ||
1003 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_LTO
, local
->lto
) ||
1004 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_RW
, local
->rw
) ||
1005 nla_put_u16(msg
, NFC_ATTR_LLC_PARAM_MIUX
, be16_to_cpu(local
->miux
)))
1006 goto nla_put_failure
;
1008 genlmsg_end(msg
, hdr
);
1013 genlmsg_cancel(msg
, hdr
);
1017 static int nfc_genl_llc_get_params(struct sk_buff
*skb
, struct genl_info
*info
)
1019 struct nfc_dev
*dev
;
1020 struct nfc_llcp_local
*local
;
1022 struct sk_buff
*msg
= NULL
;
1025 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
1028 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1030 dev
= nfc_get_device(idx
);
1034 device_lock(&dev
->dev
);
1036 local
= nfc_llcp_find_local(dev
);
1042 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1048 rc
= nfc_genl_send_params(msg
, local
, info
->snd_portid
, info
->snd_seq
);
1051 device_unlock(&dev
->dev
);
1053 nfc_put_device(dev
);
1062 return genlmsg_reply(msg
, info
);
1065 static int nfc_genl_llc_set_params(struct sk_buff
*skb
, struct genl_info
*info
)
1067 struct nfc_dev
*dev
;
1068 struct nfc_llcp_local
*local
;
1074 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1075 (!info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
] &&
1076 !info
->attrs
[NFC_ATTR_LLC_PARAM_RW
] &&
1077 !info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]))
1080 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]) {
1081 rw
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]);
1083 if (rw
> LLCP_MAX_RW
)
1087 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]) {
1088 miux
= nla_get_u16(info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]);
1090 if (miux
> LLCP_MAX_MIUX
)
1094 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1096 dev
= nfc_get_device(idx
);
1100 device_lock(&dev
->dev
);
1102 local
= nfc_llcp_find_local(dev
);
1104 nfc_put_device(dev
);
1109 if (info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]) {
1110 if (dev
->dep_link_up
) {
1115 local
->lto
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]);
1118 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
])
1121 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
])
1122 local
->miux
= cpu_to_be16(miux
);
1125 device_unlock(&dev
->dev
);
1127 nfc_put_device(dev
);
1132 static int nfc_genl_llc_sdreq(struct sk_buff
*skb
, struct genl_info
*info
)
1134 struct nfc_dev
*dev
;
1135 struct nfc_llcp_local
*local
;
1136 struct nlattr
*attr
, *sdp_attrs
[NFC_SDP_ATTR_MAX
+1];
1141 size_t uri_len
, tlvs_len
;
1142 struct hlist_head sdreq_list
;
1143 struct nfc_llcp_sdp_tlv
*sdreq
;
1145 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1146 !info
->attrs
[NFC_ATTR_LLC_SDP
])
1149 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1151 dev
= nfc_get_device(idx
);
1155 device_lock(&dev
->dev
);
1157 if (dev
->dep_link_up
== false) {
1162 local
= nfc_llcp_find_local(dev
);
1164 nfc_put_device(dev
);
1169 INIT_HLIST_HEAD(&sdreq_list
);
1173 nla_for_each_nested(attr
, info
->attrs
[NFC_ATTR_LLC_SDP
], rem
) {
1174 rc
= nla_parse_nested(sdp_attrs
, NFC_SDP_ATTR_MAX
, attr
,
1175 nfc_sdp_genl_policy
);
1182 if (!sdp_attrs
[NFC_SDP_ATTR_URI
])
1185 uri_len
= nla_len(sdp_attrs
[NFC_SDP_ATTR_URI
]);
1189 uri
= nla_data(sdp_attrs
[NFC_SDP_ATTR_URI
]);
1190 if (uri
== NULL
|| *uri
== 0)
1193 tid
= local
->sdreq_next_tid
++;
1195 sdreq
= nfc_llcp_build_sdreq_tlv(tid
, uri
, uri_len
);
1196 if (sdreq
== NULL
) {
1201 tlvs_len
+= sdreq
->tlv_len
;
1203 hlist_add_head(&sdreq
->node
, &sdreq_list
);
1206 if (hlist_empty(&sdreq_list
)) {
1211 rc
= nfc_llcp_send_snl_sdreq(local
, &sdreq_list
, tlvs_len
);
1213 device_unlock(&dev
->dev
);
1215 nfc_put_device(dev
);
1220 static int nfc_genl_fw_download(struct sk_buff
*skb
, struct genl_info
*info
)
1222 struct nfc_dev
*dev
;
1225 char firmware_name
[NFC_FIRMWARE_NAME_MAXSIZE
+ 1];
1227 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
1230 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1232 dev
= nfc_get_device(idx
);
1236 nla_strlcpy(firmware_name
, info
->attrs
[NFC_ATTR_FIRMWARE_NAME
],
1237 sizeof(firmware_name
));
1239 rc
= nfc_fw_download(dev
, firmware_name
);
1241 nfc_put_device(dev
);
1245 int nfc_genl_fw_download_done(struct nfc_dev
*dev
, const char *firmware_name
,
1248 struct sk_buff
*msg
;
1251 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1255 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
1256 NFC_CMD_FW_DOWNLOAD
);
1260 if (nla_put_string(msg
, NFC_ATTR_FIRMWARE_NAME
, firmware_name
) ||
1261 nla_put_u32(msg
, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS
, result
) ||
1262 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
1263 goto nla_put_failure
;
1265 genlmsg_end(msg
, hdr
);
1267 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
1272 genlmsg_cancel(msg
, hdr
);
1278 static int nfc_genl_enable_se(struct sk_buff
*skb
, struct genl_info
*info
)
1280 struct nfc_dev
*dev
;
1284 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1285 !info
->attrs
[NFC_ATTR_SE_INDEX
])
1288 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1289 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1291 dev
= nfc_get_device(idx
);
1295 rc
= nfc_enable_se(dev
, se_idx
);
1297 nfc_put_device(dev
);
1301 static int nfc_genl_disable_se(struct sk_buff
*skb
, struct genl_info
*info
)
1303 struct nfc_dev
*dev
;
1307 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1308 !info
->attrs
[NFC_ATTR_SE_INDEX
])
1311 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1312 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1314 dev
= nfc_get_device(idx
);
1318 rc
= nfc_disable_se(dev
, se_idx
);
1320 nfc_put_device(dev
);
1324 static int nfc_genl_send_se(struct sk_buff
*msg
, struct nfc_dev
*dev
,
1325 u32 portid
, u32 seq
,
1326 struct netlink_callback
*cb
,
1330 struct nfc_se
*se
, *n
;
1332 list_for_each_entry_safe(se
, n
, &dev
->secure_elements
, list
) {
1333 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, flags
,
1336 goto nla_put_failure
;
1339 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
1341 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
1342 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, se
->idx
) ||
1343 nla_put_u8(msg
, NFC_ATTR_SE_TYPE
, se
->type
))
1344 goto nla_put_failure
;
1346 genlmsg_end(msg
, hdr
);
1352 genlmsg_cancel(msg
, hdr
);
1356 static int nfc_genl_dump_ses(struct sk_buff
*skb
,
1357 struct netlink_callback
*cb
)
1359 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
1360 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
1361 bool first_call
= false;
1365 iter
= kmalloc(sizeof(struct class_dev_iter
), GFP_KERNEL
);
1368 cb
->args
[0] = (long) iter
;
1371 mutex_lock(&nfc_devlist_mutex
);
1373 cb
->seq
= nfc_devlist_generation
;
1376 nfc_device_iter_init(iter
);
1377 dev
= nfc_device_iter_next(iter
);
1383 rc
= nfc_genl_send_se(skb
, dev
, NETLINK_CB(cb
->skb
).portid
,
1384 cb
->nlh
->nlmsg_seq
, cb
, NLM_F_MULTI
);
1388 dev
= nfc_device_iter_next(iter
);
1391 mutex_unlock(&nfc_devlist_mutex
);
1393 cb
->args
[1] = (long) dev
;
1398 static int nfc_genl_dump_ses_done(struct netlink_callback
*cb
)
1400 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
1402 nfc_device_iter_exit(iter
);
1408 static int nfc_se_io(struct nfc_dev
*dev
, u32 se_idx
,
1409 u8
*apdu
, size_t apdu_length
,
1410 se_io_cb_t cb
, void *cb_context
)
1415 pr_debug("%s se index %d\n", dev_name(&dev
->dev
), se_idx
);
1417 device_lock(&dev
->dev
);
1419 if (!device_is_registered(&dev
->dev
)) {
1429 if (!dev
->ops
->se_io
) {
1434 se
= nfc_find_se(dev
, se_idx
);
1440 if (se
->state
!= NFC_SE_ENABLED
) {
1445 rc
= dev
->ops
->se_io(dev
, se_idx
, apdu
,
1446 apdu_length
, cb
, cb_context
);
1449 device_unlock(&dev
->dev
);
1458 static void se_io_cb(void *context
, u8
*apdu
, size_t apdu_len
, int err
)
1460 struct se_io_ctx
*ctx
= context
;
1461 struct sk_buff
*msg
;
1464 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1470 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
1475 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, ctx
->dev_idx
) ||
1476 nla_put_u32(msg
, NFC_ATTR_SE_INDEX
, ctx
->se_idx
) ||
1477 nla_put(msg
, NFC_ATTR_SE_APDU
, apdu_len
, apdu
))
1478 goto nla_put_failure
;
1480 genlmsg_end(msg
, hdr
);
1482 genlmsg_multicast(&nfc_genl_family
, msg
, 0, 0, GFP_KERNEL
);
1489 genlmsg_cancel(msg
, hdr
);
1497 static int nfc_genl_se_io(struct sk_buff
*skb
, struct genl_info
*info
)
1499 struct nfc_dev
*dev
;
1500 struct se_io_ctx
*ctx
;
1501 u32 dev_idx
, se_idx
;
1505 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1506 !info
->attrs
[NFC_ATTR_SE_INDEX
] ||
1507 !info
->attrs
[NFC_ATTR_SE_APDU
])
1510 dev_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1511 se_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_SE_INDEX
]);
1513 dev
= nfc_get_device(dev_idx
);
1517 if (!dev
->ops
|| !dev
->ops
->se_io
)
1520 apdu_len
= nla_len(info
->attrs
[NFC_ATTR_SE_APDU
]);
1524 apdu
= nla_data(info
->attrs
[NFC_ATTR_SE_APDU
]);
1528 ctx
= kzalloc(sizeof(struct se_io_ctx
), GFP_KERNEL
);
1532 ctx
->dev_idx
= dev_idx
;
1533 ctx
->se_idx
= se_idx
;
1535 return nfc_se_io(dev
, se_idx
, apdu
, apdu_len
, se_io_cb
, ctx
);
1538 static int nfc_genl_vendor_cmd(struct sk_buff
*skb
,
1539 struct genl_info
*info
)
1541 struct nfc_dev
*dev
;
1542 struct nfc_vendor_cmd
*cmd
;
1543 u32 dev_idx
, vid
, subcmd
;
1548 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
1549 !info
->attrs
[NFC_ATTR_VENDOR_ID
] ||
1550 !info
->attrs
[NFC_ATTR_VENDOR_SUBCMD
])
1553 dev_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
1554 vid
= nla_get_u32(info
->attrs
[NFC_ATTR_VENDOR_ID
]);
1555 subcmd
= nla_get_u32(info
->attrs
[NFC_ATTR_VENDOR_SUBCMD
]);
1557 dev
= nfc_get_device(dev_idx
);
1558 if (!dev
|| !dev
->vendor_cmds
|| !dev
->n_vendor_cmds
)
1561 if (info
->attrs
[NFC_ATTR_VENDOR_DATA
]) {
1562 data
= nla_data(info
->attrs
[NFC_ATTR_VENDOR_DATA
]);
1563 data_len
= nla_len(info
->attrs
[NFC_ATTR_VENDOR_DATA
]);
1571 for (i
= 0; i
< dev
->n_vendor_cmds
; i
++) {
1572 cmd
= &dev
->vendor_cmds
[i
];
1574 if (cmd
->vendor_id
!= vid
|| cmd
->subcmd
!= subcmd
)
1577 dev
->cur_cmd_info
= info
;
1578 err
= cmd
->doit(dev
, data
, data_len
);
1579 dev
->cur_cmd_info
= NULL
;
1586 /* message building helper */
1587 static inline void *nfc_hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
1590 /* since there is no private header just add the generic one */
1591 return genlmsg_put(skb
, portid
, seq
, &nfc_genl_family
, flags
, cmd
);
1594 static struct sk_buff
*
1595 __nfc_alloc_vendor_cmd_skb(struct nfc_dev
*dev
, int approxlen
,
1596 u32 portid
, u32 seq
,
1597 enum nfc_attrs attr
,
1598 u32 oui
, u32 subcmd
, gfp_t gfp
)
1600 struct sk_buff
*skb
;
1603 skb
= nlmsg_new(approxlen
+ 100, gfp
);
1607 hdr
= nfc_hdr_put(skb
, portid
, seq
, 0, NFC_CMD_VENDOR
);
1613 if (nla_put_u32(skb
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
1614 goto nla_put_failure
;
1615 if (nla_put_u32(skb
, NFC_ATTR_VENDOR_ID
, oui
))
1616 goto nla_put_failure
;
1617 if (nla_put_u32(skb
, NFC_ATTR_VENDOR_SUBCMD
, subcmd
))
1618 goto nla_put_failure
;
1620 ((void **)skb
->cb
)[0] = dev
;
1621 ((void **)skb
->cb
)[1] = hdr
;
1630 struct sk_buff
*__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev
*dev
,
1631 enum nfc_attrs attr
,
1632 u32 oui
, u32 subcmd
,
1635 if (WARN_ON(!dev
->cur_cmd_info
))
1638 return __nfc_alloc_vendor_cmd_skb(dev
, approxlen
,
1639 dev
->cur_cmd_info
->snd_portid
,
1640 dev
->cur_cmd_info
->snd_seq
, attr
,
1641 oui
, subcmd
, GFP_KERNEL
);
1643 EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb
);
1645 int nfc_vendor_cmd_reply(struct sk_buff
*skb
)
1647 struct nfc_dev
*dev
= ((void **)skb
->cb
)[0];
1648 void *hdr
= ((void **)skb
->cb
)[1];
1650 /* clear CB data for netlink core to own from now on */
1651 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1653 if (WARN_ON(!dev
->cur_cmd_info
)) {
1658 genlmsg_end(skb
, hdr
);
1659 return genlmsg_reply(skb
, dev
->cur_cmd_info
);
1661 EXPORT_SYMBOL(nfc_vendor_cmd_reply
);
1663 static const struct genl_ops nfc_genl_ops
[] = {
1665 .cmd
= NFC_CMD_GET_DEVICE
,
1666 .doit
= nfc_genl_get_device
,
1667 .dumpit
= nfc_genl_dump_devices
,
1668 .done
= nfc_genl_dump_devices_done
,
1669 .policy
= nfc_genl_policy
,
1672 .cmd
= NFC_CMD_DEV_UP
,
1673 .doit
= nfc_genl_dev_up
,
1674 .policy
= nfc_genl_policy
,
1677 .cmd
= NFC_CMD_DEV_DOWN
,
1678 .doit
= nfc_genl_dev_down
,
1679 .policy
= nfc_genl_policy
,
1682 .cmd
= NFC_CMD_START_POLL
,
1683 .doit
= nfc_genl_start_poll
,
1684 .policy
= nfc_genl_policy
,
1687 .cmd
= NFC_CMD_STOP_POLL
,
1688 .doit
= nfc_genl_stop_poll
,
1689 .policy
= nfc_genl_policy
,
1692 .cmd
= NFC_CMD_DEP_LINK_UP
,
1693 .doit
= nfc_genl_dep_link_up
,
1694 .policy
= nfc_genl_policy
,
1697 .cmd
= NFC_CMD_DEP_LINK_DOWN
,
1698 .doit
= nfc_genl_dep_link_down
,
1699 .policy
= nfc_genl_policy
,
1702 .cmd
= NFC_CMD_GET_TARGET
,
1703 .dumpit
= nfc_genl_dump_targets
,
1704 .done
= nfc_genl_dump_targets_done
,
1705 .policy
= nfc_genl_policy
,
1708 .cmd
= NFC_CMD_LLC_GET_PARAMS
,
1709 .doit
= nfc_genl_llc_get_params
,
1710 .policy
= nfc_genl_policy
,
1713 .cmd
= NFC_CMD_LLC_SET_PARAMS
,
1714 .doit
= nfc_genl_llc_set_params
,
1715 .policy
= nfc_genl_policy
,
1718 .cmd
= NFC_CMD_LLC_SDREQ
,
1719 .doit
= nfc_genl_llc_sdreq
,
1720 .policy
= nfc_genl_policy
,
1723 .cmd
= NFC_CMD_FW_DOWNLOAD
,
1724 .doit
= nfc_genl_fw_download
,
1725 .policy
= nfc_genl_policy
,
1728 .cmd
= NFC_CMD_ENABLE_SE
,
1729 .doit
= nfc_genl_enable_se
,
1730 .policy
= nfc_genl_policy
,
1733 .cmd
= NFC_CMD_DISABLE_SE
,
1734 .doit
= nfc_genl_disable_se
,
1735 .policy
= nfc_genl_policy
,
1738 .cmd
= NFC_CMD_GET_SE
,
1739 .dumpit
= nfc_genl_dump_ses
,
1740 .done
= nfc_genl_dump_ses_done
,
1741 .policy
= nfc_genl_policy
,
1744 .cmd
= NFC_CMD_SE_IO
,
1745 .doit
= nfc_genl_se_io
,
1746 .policy
= nfc_genl_policy
,
1749 .cmd
= NFC_CMD_ACTIVATE_TARGET
,
1750 .doit
= nfc_genl_activate_target
,
1751 .policy
= nfc_genl_policy
,
1754 .cmd
= NFC_CMD_VENDOR
,
1755 .doit
= nfc_genl_vendor_cmd
,
1756 .policy
= nfc_genl_policy
,
1761 struct urelease_work
{
1762 struct work_struct w
;
1766 static void nfc_urelease_event_work(struct work_struct
*work
)
1768 struct urelease_work
*w
= container_of(work
, struct urelease_work
, w
);
1769 struct class_dev_iter iter
;
1770 struct nfc_dev
*dev
;
1772 pr_debug("portid %d\n", w
->portid
);
1774 mutex_lock(&nfc_devlist_mutex
);
1776 nfc_device_iter_init(&iter
);
1777 dev
= nfc_device_iter_next(&iter
);
1780 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
1782 if (dev
->genl_data
.poll_req_portid
== w
->portid
) {
1784 dev
->genl_data
.poll_req_portid
= 0;
1787 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
1789 dev
= nfc_device_iter_next(&iter
);
1792 nfc_device_iter_exit(&iter
);
1794 mutex_unlock(&nfc_devlist_mutex
);
1799 static int nfc_genl_rcv_nl_event(struct notifier_block
*this,
1800 unsigned long event
, void *ptr
)
1802 struct netlink_notify
*n
= ptr
;
1803 struct urelease_work
*w
;
1805 if (event
!= NETLINK_URELEASE
|| n
->protocol
!= NETLINK_GENERIC
)
1808 pr_debug("NETLINK_URELEASE event from id %d\n", n
->portid
);
1810 w
= kmalloc(sizeof(*w
), GFP_ATOMIC
);
1812 INIT_WORK((struct work_struct
*) w
, nfc_urelease_event_work
);
1813 w
->portid
= n
->portid
;
1814 schedule_work((struct work_struct
*) w
);
1821 void nfc_genl_data_init(struct nfc_genl_data
*genl_data
)
1823 genl_data
->poll_req_portid
= 0;
1824 mutex_init(&genl_data
->genl_data_mutex
);
1827 void nfc_genl_data_exit(struct nfc_genl_data
*genl_data
)
1829 mutex_destroy(&genl_data
->genl_data_mutex
);
1832 static struct notifier_block nl_notifier
= {
1833 .notifier_call
= nfc_genl_rcv_nl_event
,
1837 * nfc_genl_init() - Initialize netlink interface
1839 * This initialization function registers the nfc netlink family.
1841 int __init
nfc_genl_init(void)
1845 rc
= genl_register_family_with_ops_groups(&nfc_genl_family
,
1851 netlink_register_notifier(&nl_notifier
);
1857 * nfc_genl_exit() - Deinitialize netlink interface
1859 * This exit function unregisters the nfc netlink family.
1861 void nfc_genl_exit(void)
1863 netlink_unregister_notifier(&nl_notifier
);
1864 genl_unregister_family(&nfc_genl_family
);