2 * IrDA netlink layer, for stack configuration.
6 * Partly based on the 802.11 nelink implementation
7 * (see net/wireless/nl80211.c) which is:
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 #include <linux/socket.h>
17 #include <linux/irda.h>
18 #include <linux/gfp.h>
19 #include <net/net_namespace.h>
21 #include <net/irda/irda.h>
22 #include <net/irda/irlap.h>
23 #include <net/genetlink.h>
27 static struct genl_family irda_nl_family;
29 static struct net_device * ifname_to_netdev(struct net *net, struct genl_info *info)
33 if (!info->attrs[IRDA_NL_ATTR_IFNAME])
36 ifname = nla_data(info->attrs[IRDA_NL_ATTR_IFNAME]);
38 pr_debug("%s(): Looking for %s\n", __func__, ifname);
40 return dev_get_by_name(net, ifname);
43 static int irda_nl_set_mode(struct sk_buff *skb, struct genl_info *info)
45 struct net_device * dev;
46 struct irlap_cb * irlap;
49 if (!info->attrs[IRDA_NL_ATTR_MODE])
52 mode = nla_get_u32(info->attrs[IRDA_NL_ATTR_MODE]);
54 pr_debug("%s(): Switching to mode: %d\n", __func__, mode);
56 dev = ifname_to_netdev(&init_net, info);
60 irlap = (struct irlap_cb *)dev->atalk_ptr;
73 static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
75 struct net_device * dev;
76 struct irlap_cb * irlap;
81 dev = ifname_to_netdev(&init_net, info);
85 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
91 irlap = (struct irlap_cb *)dev->atalk_ptr;
97 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
98 &irda_nl_family, 0, IRDA_NL_CMD_GET_MODE);
104 if(nla_put_string(msg, IRDA_NL_ATTR_IFNAME,
108 if(nla_put_u32(msg, IRDA_NL_ATTR_MODE, irlap->mode))
111 genlmsg_end(msg, hdr);
113 return genlmsg_reply(msg, info);
122 static const struct nla_policy irda_nl_policy[IRDA_NL_ATTR_MAX + 1] = {
123 [IRDA_NL_ATTR_IFNAME] = { .type = NLA_NUL_STRING,
125 [IRDA_NL_ATTR_MODE] = { .type = NLA_U32 },
128 static const struct genl_ops irda_nl_ops[] = {
130 .cmd = IRDA_NL_CMD_SET_MODE,
131 .doit = irda_nl_set_mode,
132 .policy = irda_nl_policy,
133 .flags = GENL_ADMIN_PERM,
136 .cmd = IRDA_NL_CMD_GET_MODE,
137 .doit = irda_nl_get_mode,
138 .policy = irda_nl_policy,
139 /* can be retrieved by unprivileged users */
144 static struct genl_family irda_nl_family __ro_after_init = {
145 .name = IRDA_NL_NAME,
147 .version = IRDA_NL_VERSION,
148 .maxattr = IRDA_NL_CMD_MAX,
149 .module = THIS_MODULE,
151 .n_ops = ARRAY_SIZE(irda_nl_ops),
154 int __init irda_nl_register(void)
156 return genl_register_family(&irda_nl_family);
159 void irda_nl_unregister(void)
161 genl_unregister_family(&irda_nl_family);