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
},
56 [NFC_ATTR_LLC_PARAM_LTO
] = { .type
= NLA_U8
},
57 [NFC_ATTR_LLC_PARAM_RW
] = { .type
= NLA_U8
},
58 [NFC_ATTR_LLC_PARAM_MIUX
] = { .type
= NLA_U16
},
61 static int nfc_genl_send_target(struct sk_buff
*msg
, struct nfc_target
*target
,
62 struct netlink_callback
*cb
, int flags
)
66 hdr
= genlmsg_put(msg
, NETLINK_CB(cb
->skb
).portid
, cb
->nlh
->nlmsg_seq
,
67 &nfc_genl_family
, flags
, NFC_CMD_GET_TARGET
);
71 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
73 if (nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target
->idx
) ||
74 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, target
->supported_protocols
) ||
75 nla_put_u16(msg
, NFC_ATTR_TARGET_SENS_RES
, target
->sens_res
) ||
76 nla_put_u8(msg
, NFC_ATTR_TARGET_SEL_RES
, target
->sel_res
))
78 if (target
->nfcid1_len
> 0 &&
79 nla_put(msg
, NFC_ATTR_TARGET_NFCID1
, target
->nfcid1_len
,
82 if (target
->sensb_res_len
> 0 &&
83 nla_put(msg
, NFC_ATTR_TARGET_SENSB_RES
, target
->sensb_res_len
,
86 if (target
->sensf_res_len
> 0 &&
87 nla_put(msg
, NFC_ATTR_TARGET_SENSF_RES
, target
->sensf_res_len
,
91 return genlmsg_end(msg
, hdr
);
94 genlmsg_cancel(msg
, hdr
);
98 static struct nfc_dev
*__get_device_from_cb(struct netlink_callback
*cb
)
104 rc
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nfc_genl_family
.hdrsize
,
105 nfc_genl_family
.attrbuf
,
106 nfc_genl_family
.maxattr
,
111 if (!nfc_genl_family
.attrbuf
[NFC_ATTR_DEVICE_INDEX
])
112 return ERR_PTR(-EINVAL
);
114 idx
= nla_get_u32(nfc_genl_family
.attrbuf
[NFC_ATTR_DEVICE_INDEX
]);
116 dev
= nfc_get_device(idx
);
118 return ERR_PTR(-ENODEV
);
123 static int nfc_genl_dump_targets(struct sk_buff
*skb
,
124 struct netlink_callback
*cb
)
127 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
131 dev
= __get_device_from_cb(cb
);
135 cb
->args
[1] = (long) dev
;
138 device_lock(&dev
->dev
);
140 cb
->seq
= dev
->targets_generation
;
142 while (i
< dev
->n_targets
) {
143 rc
= nfc_genl_send_target(skb
, &dev
->targets
[i
], cb
,
151 device_unlock(&dev
->dev
);
158 static int nfc_genl_dump_targets_done(struct netlink_callback
*cb
)
160 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
168 int nfc_genl_targets_found(struct nfc_dev
*dev
)
173 dev
->genl_data
.poll_req_portid
= 0;
175 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
179 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
180 NFC_EVENT_TARGETS_FOUND
);
184 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
185 goto nla_put_failure
;
187 genlmsg_end(msg
, hdr
);
189 return genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_ATOMIC
);
192 genlmsg_cancel(msg
, hdr
);
198 int nfc_genl_target_lost(struct nfc_dev
*dev
, u32 target_idx
)
203 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
207 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
208 NFC_EVENT_TARGET_LOST
);
212 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
213 nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target_idx
))
214 goto nla_put_failure
;
216 genlmsg_end(msg
, hdr
);
218 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_KERNEL
);
223 genlmsg_cancel(msg
, hdr
);
229 int nfc_genl_tm_activated(struct nfc_dev
*dev
, u32 protocol
)
234 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
238 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
239 NFC_EVENT_TM_ACTIVATED
);
243 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
244 goto nla_put_failure
;
245 if (nla_put_u32(msg
, NFC_ATTR_TM_PROTOCOLS
, protocol
))
246 goto nla_put_failure
;
248 genlmsg_end(msg
, hdr
);
250 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_KERNEL
);
255 genlmsg_cancel(msg
, hdr
);
261 int nfc_genl_tm_deactivated(struct nfc_dev
*dev
)
266 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
270 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
271 NFC_EVENT_TM_DEACTIVATED
);
275 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
276 goto nla_put_failure
;
278 genlmsg_end(msg
, hdr
);
280 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_KERNEL
);
285 genlmsg_cancel(msg
, hdr
);
291 int nfc_genl_device_added(struct nfc_dev
*dev
)
296 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
300 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
301 NFC_EVENT_DEVICE_ADDED
);
305 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
306 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
307 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, dev
->supported_protocols
) ||
308 nla_put_u8(msg
, NFC_ATTR_DEVICE_POWERED
, dev
->dev_up
))
309 goto nla_put_failure
;
311 genlmsg_end(msg
, hdr
);
313 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_KERNEL
);
318 genlmsg_cancel(msg
, hdr
);
324 int nfc_genl_device_removed(struct nfc_dev
*dev
)
329 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
333 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
334 NFC_EVENT_DEVICE_REMOVED
);
338 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
339 goto nla_put_failure
;
341 genlmsg_end(msg
, hdr
);
343 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_KERNEL
);
348 genlmsg_cancel(msg
, hdr
);
354 static int nfc_genl_send_device(struct sk_buff
*msg
, struct nfc_dev
*dev
,
356 struct netlink_callback
*cb
,
361 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, flags
,
367 genl_dump_check_consistent(cb
, hdr
, &nfc_genl_family
);
369 if (nla_put_string(msg
, NFC_ATTR_DEVICE_NAME
, nfc_device_name(dev
)) ||
370 nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
) ||
371 nla_put_u32(msg
, NFC_ATTR_PROTOCOLS
, dev
->supported_protocols
) ||
372 nla_put_u32(msg
, NFC_ATTR_SE
, dev
->supported_se
) ||
373 nla_put_u8(msg
, NFC_ATTR_DEVICE_POWERED
, dev
->dev_up
) ||
374 nla_put_u8(msg
, NFC_ATTR_RF_MODE
, dev
->rf_mode
))
375 goto nla_put_failure
;
377 return genlmsg_end(msg
, hdr
);
380 genlmsg_cancel(msg
, hdr
);
384 static int nfc_genl_dump_devices(struct sk_buff
*skb
,
385 struct netlink_callback
*cb
)
387 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
388 struct nfc_dev
*dev
= (struct nfc_dev
*) cb
->args
[1];
389 bool first_call
= false;
393 iter
= kmalloc(sizeof(struct class_dev_iter
), GFP_KERNEL
);
396 cb
->args
[0] = (long) iter
;
399 mutex_lock(&nfc_devlist_mutex
);
401 cb
->seq
= nfc_devlist_generation
;
404 nfc_device_iter_init(iter
);
405 dev
= nfc_device_iter_next(iter
);
411 rc
= nfc_genl_send_device(skb
, dev
, NETLINK_CB(cb
->skb
).portid
,
412 cb
->nlh
->nlmsg_seq
, cb
, NLM_F_MULTI
);
416 dev
= nfc_device_iter_next(iter
);
419 mutex_unlock(&nfc_devlist_mutex
);
421 cb
->args
[1] = (long) dev
;
426 static int nfc_genl_dump_devices_done(struct netlink_callback
*cb
)
428 struct class_dev_iter
*iter
= (struct class_dev_iter
*) cb
->args
[0];
430 nfc_device_iter_exit(iter
);
436 int nfc_genl_dep_link_up_event(struct nfc_dev
*dev
, u32 target_idx
,
437 u8 comm_mode
, u8 rf_mode
)
442 pr_debug("DEP link is up\n");
444 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
448 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0, NFC_CMD_DEP_LINK_UP
);
452 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
453 goto nla_put_failure
;
454 if (rf_mode
== NFC_RF_INITIATOR
&&
455 nla_put_u32(msg
, NFC_ATTR_TARGET_INDEX
, target_idx
))
456 goto nla_put_failure
;
457 if (nla_put_u8(msg
, NFC_ATTR_COMM_MODE
, comm_mode
) ||
458 nla_put_u8(msg
, NFC_ATTR_RF_MODE
, rf_mode
))
459 goto nla_put_failure
;
461 genlmsg_end(msg
, hdr
);
463 dev
->dep_link_up
= true;
465 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_ATOMIC
);
470 genlmsg_cancel(msg
, hdr
);
476 int nfc_genl_dep_link_down_event(struct nfc_dev
*dev
)
481 pr_debug("DEP link is down\n");
483 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
487 hdr
= genlmsg_put(msg
, 0, 0, &nfc_genl_family
, 0,
488 NFC_CMD_DEP_LINK_DOWN
);
492 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, dev
->idx
))
493 goto nla_put_failure
;
495 genlmsg_end(msg
, hdr
);
497 genlmsg_multicast(msg
, 0, nfc_genl_event_mcgrp
.id
, GFP_ATOMIC
);
502 genlmsg_cancel(msg
, hdr
);
508 static int nfc_genl_get_device(struct sk_buff
*skb
, struct genl_info
*info
)
515 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
518 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
520 dev
= nfc_get_device(idx
);
524 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
530 rc
= nfc_genl_send_device(msg
, dev
, info
->snd_portid
, info
->snd_seq
,
537 return genlmsg_reply(msg
, info
);
546 static int nfc_genl_dev_up(struct sk_buff
*skb
, struct genl_info
*info
)
552 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
555 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
557 dev
= nfc_get_device(idx
);
561 rc
= nfc_dev_up(dev
);
567 static int nfc_genl_dev_down(struct sk_buff
*skb
, struct genl_info
*info
)
573 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
576 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
578 dev
= nfc_get_device(idx
);
582 rc
= nfc_dev_down(dev
);
588 static int nfc_genl_start_poll(struct sk_buff
*skb
, struct genl_info
*info
)
593 u32 im_protocols
= 0, tm_protocols
= 0;
595 pr_debug("Poll start\n");
597 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
598 ((!info
->attrs
[NFC_ATTR_IM_PROTOCOLS
] &&
599 !info
->attrs
[NFC_ATTR_PROTOCOLS
]) &&
600 !info
->attrs
[NFC_ATTR_TM_PROTOCOLS
]))
603 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
605 if (info
->attrs
[NFC_ATTR_TM_PROTOCOLS
])
606 tm_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_TM_PROTOCOLS
]);
608 if (info
->attrs
[NFC_ATTR_IM_PROTOCOLS
])
609 im_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_IM_PROTOCOLS
]);
610 else if (info
->attrs
[NFC_ATTR_PROTOCOLS
])
611 im_protocols
= nla_get_u32(info
->attrs
[NFC_ATTR_PROTOCOLS
]);
613 dev
= nfc_get_device(idx
);
617 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
619 rc
= nfc_start_poll(dev
, im_protocols
, tm_protocols
);
621 dev
->genl_data
.poll_req_portid
= info
->snd_portid
;
623 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
629 static int nfc_genl_stop_poll(struct sk_buff
*skb
, struct genl_info
*info
)
635 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
638 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
640 dev
= nfc_get_device(idx
);
644 device_lock(&dev
->dev
);
647 device_unlock(&dev
->dev
);
651 device_unlock(&dev
->dev
);
653 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
655 if (dev
->genl_data
.poll_req_portid
!= info
->snd_portid
) {
660 rc
= nfc_stop_poll(dev
);
661 dev
->genl_data
.poll_req_portid
= 0;
664 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
669 static int nfc_genl_dep_link_up(struct sk_buff
*skb
, struct genl_info
*info
)
676 pr_debug("DEP link up\n");
678 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
679 !info
->attrs
[NFC_ATTR_COMM_MODE
])
682 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
683 if (!info
->attrs
[NFC_ATTR_TARGET_INDEX
])
684 tgt_idx
= NFC_TARGET_IDX_ANY
;
686 tgt_idx
= nla_get_u32(info
->attrs
[NFC_ATTR_TARGET_INDEX
]);
688 comm
= nla_get_u8(info
->attrs
[NFC_ATTR_COMM_MODE
]);
690 if (comm
!= NFC_COMM_ACTIVE
&& comm
!= NFC_COMM_PASSIVE
)
693 dev
= nfc_get_device(idx
);
697 rc
= nfc_dep_link_up(dev
, tgt_idx
, comm
);
704 static int nfc_genl_dep_link_down(struct sk_buff
*skb
, struct genl_info
*info
)
710 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
713 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
715 dev
= nfc_get_device(idx
);
719 rc
= nfc_dep_link_down(dev
);
725 static int nfc_genl_send_params(struct sk_buff
*msg
,
726 struct nfc_llcp_local
*local
,
731 hdr
= genlmsg_put(msg
, portid
, seq
, &nfc_genl_family
, 0,
732 NFC_CMD_LLC_GET_PARAMS
);
736 if (nla_put_u32(msg
, NFC_ATTR_DEVICE_INDEX
, local
->dev
->idx
) ||
737 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_LTO
, local
->lto
) ||
738 nla_put_u8(msg
, NFC_ATTR_LLC_PARAM_RW
, local
->rw
) ||
739 nla_put_u16(msg
, NFC_ATTR_LLC_PARAM_MIUX
, be16_to_cpu(local
->miux
)))
740 goto nla_put_failure
;
742 return genlmsg_end(msg
, hdr
);
746 genlmsg_cancel(msg
, hdr
);
750 static int nfc_genl_llc_get_params(struct sk_buff
*skb
, struct genl_info
*info
)
753 struct nfc_llcp_local
*local
;
755 struct sk_buff
*msg
= NULL
;
758 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
])
761 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
763 dev
= nfc_get_device(idx
);
767 device_lock(&dev
->dev
);
769 local
= nfc_llcp_find_local(dev
);
775 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
781 rc
= nfc_genl_send_params(msg
, local
, info
->snd_portid
, info
->snd_seq
);
784 device_unlock(&dev
->dev
);
795 return genlmsg_reply(msg
, info
);
798 static int nfc_genl_llc_set_params(struct sk_buff
*skb
, struct genl_info
*info
)
801 struct nfc_llcp_local
*local
;
807 if (!info
->attrs
[NFC_ATTR_DEVICE_INDEX
] ||
808 (!info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
] &&
809 !info
->attrs
[NFC_ATTR_LLC_PARAM_RW
] &&
810 !info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]))
813 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]) {
814 rw
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_RW
]);
816 if (rw
> LLCP_MAX_RW
)
820 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]) {
821 miux
= nla_get_u16(info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
]);
823 if (miux
> LLCP_MAX_MIUX
)
827 idx
= nla_get_u32(info
->attrs
[NFC_ATTR_DEVICE_INDEX
]);
829 dev
= nfc_get_device(idx
);
833 device_lock(&dev
->dev
);
835 local
= nfc_llcp_find_local(dev
);
842 if (info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]) {
843 if (dev
->dep_link_up
) {
848 local
->lto
= nla_get_u8(info
->attrs
[NFC_ATTR_LLC_PARAM_LTO
]);
851 if (info
->attrs
[NFC_ATTR_LLC_PARAM_RW
])
854 if (info
->attrs
[NFC_ATTR_LLC_PARAM_MIUX
])
855 local
->miux
= cpu_to_be16(miux
);
858 device_unlock(&dev
->dev
);
865 static struct genl_ops nfc_genl_ops
[] = {
867 .cmd
= NFC_CMD_GET_DEVICE
,
868 .doit
= nfc_genl_get_device
,
869 .dumpit
= nfc_genl_dump_devices
,
870 .done
= nfc_genl_dump_devices_done
,
871 .policy
= nfc_genl_policy
,
874 .cmd
= NFC_CMD_DEV_UP
,
875 .doit
= nfc_genl_dev_up
,
876 .policy
= nfc_genl_policy
,
879 .cmd
= NFC_CMD_DEV_DOWN
,
880 .doit
= nfc_genl_dev_down
,
881 .policy
= nfc_genl_policy
,
884 .cmd
= NFC_CMD_START_POLL
,
885 .doit
= nfc_genl_start_poll
,
886 .policy
= nfc_genl_policy
,
889 .cmd
= NFC_CMD_STOP_POLL
,
890 .doit
= nfc_genl_stop_poll
,
891 .policy
= nfc_genl_policy
,
894 .cmd
= NFC_CMD_DEP_LINK_UP
,
895 .doit
= nfc_genl_dep_link_up
,
896 .policy
= nfc_genl_policy
,
899 .cmd
= NFC_CMD_DEP_LINK_DOWN
,
900 .doit
= nfc_genl_dep_link_down
,
901 .policy
= nfc_genl_policy
,
904 .cmd
= NFC_CMD_GET_TARGET
,
905 .dumpit
= nfc_genl_dump_targets
,
906 .done
= nfc_genl_dump_targets_done
,
907 .policy
= nfc_genl_policy
,
910 .cmd
= NFC_CMD_LLC_GET_PARAMS
,
911 .doit
= nfc_genl_llc_get_params
,
912 .policy
= nfc_genl_policy
,
915 .cmd
= NFC_CMD_LLC_SET_PARAMS
,
916 .doit
= nfc_genl_llc_set_params
,
917 .policy
= nfc_genl_policy
,
922 struct urelease_work
{
923 struct work_struct w
;
927 static void nfc_urelease_event_work(struct work_struct
*work
)
929 struct urelease_work
*w
= container_of(work
, struct urelease_work
, w
);
930 struct class_dev_iter iter
;
933 pr_debug("portid %d\n", w
->portid
);
935 mutex_lock(&nfc_devlist_mutex
);
937 nfc_device_iter_init(&iter
);
938 dev
= nfc_device_iter_next(&iter
);
941 mutex_lock(&dev
->genl_data
.genl_data_mutex
);
943 if (dev
->genl_data
.poll_req_portid
== w
->portid
) {
945 dev
->genl_data
.poll_req_portid
= 0;
948 mutex_unlock(&dev
->genl_data
.genl_data_mutex
);
950 dev
= nfc_device_iter_next(&iter
);
953 nfc_device_iter_exit(&iter
);
955 mutex_unlock(&nfc_devlist_mutex
);
960 static int nfc_genl_rcv_nl_event(struct notifier_block
*this,
961 unsigned long event
, void *ptr
)
963 struct netlink_notify
*n
= ptr
;
964 struct urelease_work
*w
;
966 if (event
!= NETLINK_URELEASE
|| n
->protocol
!= NETLINK_GENERIC
)
969 pr_debug("NETLINK_URELEASE event from id %d\n", n
->portid
);
971 w
= kmalloc(sizeof(*w
), GFP_ATOMIC
);
973 INIT_WORK((struct work_struct
*) w
, nfc_urelease_event_work
);
974 w
->portid
= n
->portid
;
975 schedule_work((struct work_struct
*) w
);
982 void nfc_genl_data_init(struct nfc_genl_data
*genl_data
)
984 genl_data
->poll_req_portid
= 0;
985 mutex_init(&genl_data
->genl_data_mutex
);
988 void nfc_genl_data_exit(struct nfc_genl_data
*genl_data
)
990 mutex_destroy(&genl_data
->genl_data_mutex
);
993 static struct notifier_block nl_notifier
= {
994 .notifier_call
= nfc_genl_rcv_nl_event
,
998 * nfc_genl_init() - Initialize netlink interface
1000 * This initialization function registers the nfc netlink family.
1002 int __init
nfc_genl_init(void)
1006 rc
= genl_register_family_with_ops(&nfc_genl_family
, nfc_genl_ops
,
1007 ARRAY_SIZE(nfc_genl_ops
));
1011 rc
= genl_register_mc_group(&nfc_genl_family
, &nfc_genl_event_mcgrp
);
1013 netlink_register_notifier(&nl_notifier
);
1019 * nfc_genl_exit() - Deinitialize netlink interface
1021 * This exit function unregisters the nfc netlink family.
1023 void nfc_genl_exit(void)
1025 netlink_unregister_notifier(&nl_notifier
);
1026 genl_unregister_family(&nfc_genl_family
);