ipv6: some ipv6 statistic counters failed to disable bh
[linux-2.6-block.git] / net / ieee802154 / nl-mac.c
CommitLineData
78fe738d
DES
1/*
2 * Netlink inteface for IEEE 802.15.4 stack
3 *
4 * Copyright 2007, 2008 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Written by:
20 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
22 * Maxim Osipov <maxim.osipov@siemens.com>
23 */
24
5a0e3ad6 25#include <linux/gfp.h>
78fe738d
DES
26#include <linux/kernel.h>
27#include <linux/if_arp.h>
28#include <linux/netdevice.h>
29#include <net/netlink.h>
30#include <net/genetlink.h>
31#include <net/sock.h>
32#include <linux/nl802154.h>
bc3b2d7f 33#include <linux/export.h>
78fe738d
DES
34#include <net/af_ieee802154.h>
35#include <net/nl802154.h>
36#include <net/ieee802154.h>
37#include <net/ieee802154_netdev.h>
0a868b26 38#include <net/wpan-phy.h>
78fe738d
DES
39
40#include "ieee802154.h"
41
ae531b94
PB
42static int nla_put_hwaddr(struct sk_buff *msg, int type, __le64 hwaddr)
43{
44 return nla_put_u64(msg, type, swab64((__force u64)hwaddr));
45}
46
47static __le64 nla_get_hwaddr(const struct nlattr *nla)
48{
49 return ieee802154_devaddr_from_raw(nla_data(nla));
50}
51
52static int nla_put_shortaddr(struct sk_buff *msg, int type, __le16 addr)
53{
54 return nla_put_u16(msg, type, le16_to_cpu(addr));
55}
56
57static __le16 nla_get_shortaddr(const struct nlattr *nla)
58{
59 return cpu_to_le16(nla_get_u16(nla));
60}
61
78fe738d 62int ieee802154_nl_assoc_indic(struct net_device *dev,
ae531b94 63 struct ieee802154_addr *addr, u8 cap)
78fe738d
DES
64{
65 struct sk_buff *msg;
66
67 pr_debug("%s\n", __func__);
68
ae531b94 69 if (addr->mode != IEEE802154_ADDR_LONG) {
78fe738d
DES
70 pr_err("%s: received non-long source address!\n", __func__);
71 return -EINVAL;
72 }
73
74 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
75 if (!msg)
76 return -ENOBUFS;
77
be51da0f
DM
78 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
79 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
80 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
81 dev->dev_addr) ||
ae531b94
PB
82 nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
83 addr->extended_addr) ||
be51da0f
DM
84 nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
85 goto nla_put_failure;
78fe738d 86
2a94fe48 87 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
88
89nla_put_failure:
90 nlmsg_free(msg);
91 return -ENOBUFS;
92}
93EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
94
b70ab2e8 95int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
78fe738d
DES
96 u8 status)
97{
98 struct sk_buff *msg;
99
100 pr_debug("%s\n", __func__);
101
102 msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
103 if (!msg)
104 return -ENOBUFS;
105
be51da0f
DM
106 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
107 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
108 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
109 dev->dev_addr) ||
ae531b94 110 nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
be51da0f
DM
111 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
112 goto nla_put_failure;
2a94fe48 113 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
114
115nla_put_failure:
116 nlmsg_free(msg);
117 return -ENOBUFS;
118}
119EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
120
121int ieee802154_nl_disassoc_indic(struct net_device *dev,
ae531b94 122 struct ieee802154_addr *addr, u8 reason)
78fe738d
DES
123{
124 struct sk_buff *msg;
125
126 pr_debug("%s\n", __func__);
127
128 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
129 if (!msg)
130 return -ENOBUFS;
131
be51da0f
DM
132 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
133 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
134 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
135 dev->dev_addr))
136 goto nla_put_failure;
ae531b94
PB
137 if (addr->mode == IEEE802154_ADDR_LONG) {
138 if (nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
139 addr->extended_addr))
be51da0f
DM
140 goto nla_put_failure;
141 } else {
ae531b94
PB
142 if (nla_put_shortaddr(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
143 addr->short_addr))
be51da0f
DM
144 goto nla_put_failure;
145 }
146 if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
147 goto nla_put_failure;
2a94fe48 148 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
149
150nla_put_failure:
151 nlmsg_free(msg);
152 return -ENOBUFS;
153}
154EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
155
156int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
157{
158 struct sk_buff *msg;
159
160 pr_debug("%s\n", __func__);
161
162 msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
163 if (!msg)
164 return -ENOBUFS;
165
be51da0f
DM
166 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
167 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
168 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
169 dev->dev_addr) ||
170 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
171 goto nla_put_failure;
2a94fe48 172 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
173
174nla_put_failure:
175 nlmsg_free(msg);
176 return -ENOBUFS;
177}
178EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
179
b70ab2e8
PB
180int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
181 __le16 coord_addr)
78fe738d
DES
182{
183 struct sk_buff *msg;
184
185 pr_debug("%s\n", __func__);
186
187 msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
188 if (!msg)
189 return -ENOBUFS;
190
be51da0f
DM
191 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
192 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
193 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
194 dev->dev_addr) ||
ae531b94
PB
195 nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_SHORT_ADDR,
196 coord_addr) ||
197 nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
be51da0f 198 goto nla_put_failure;
2a94fe48 199 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
200
201nla_put_failure:
202 nlmsg_free(msg);
203 return -ENOBUFS;
204}
205EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
206
207int ieee802154_nl_scan_confirm(struct net_device *dev,
208 u8 status, u8 scan_type, u32 unscanned, u8 page,
209 u8 *edl/* , struct list_head *pan_desc_list */)
210{
211 struct sk_buff *msg;
212
213 pr_debug("%s\n", __func__);
214
215 msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
216 if (!msg)
217 return -ENOBUFS;
218
be51da0f
DM
219 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
220 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
221 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
222 dev->dev_addr) ||
223 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) ||
224 nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) ||
225 nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) ||
226 nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) ||
227 (edl &&
228 nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
229 goto nla_put_failure;
2a94fe48 230 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
231
232nla_put_failure:
233 nlmsg_free(msg);
234 return -ENOBUFS;
235}
236EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
237
238int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
239{
240 struct sk_buff *msg;
241
242 pr_debug("%s\n", __func__);
243
244 msg = ieee802154_nl_create(0, IEEE802154_START_CONF);
245 if (!msg)
246 return -ENOBUFS;
247
be51da0f
DM
248 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
249 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
250 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
251 dev->dev_addr) ||
252 nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
253 goto nla_put_failure;
2a94fe48 254 return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
78fe738d
DES
255
256nla_put_failure:
257 nlmsg_free(msg);
258 return -ENOBUFS;
259}
260EXPORT_SYMBOL(ieee802154_nl_start_confirm);
261
15e47304 262static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
78fe738d
DES
263 u32 seq, int flags, struct net_device *dev)
264{
265 void *hdr;
0a868b26 266 struct wpan_phy *phy;
ae531b94 267 __le16 short_addr, pan_id;
78fe738d
DES
268
269 pr_debug("%s\n", __func__);
270
271 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
272 IEEE802154_LIST_IFACE);
273 if (!hdr)
274 goto out;
275
0a868b26
DES
276 phy = ieee802154_mlme_ops(dev)->get_phy(dev);
277 BUG_ON(!phy);
278
ae531b94
PB
279 short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
280 pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
b70ab2e8 281
be51da0f
DM
282 if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
283 nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
284 nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
285 nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
286 dev->dev_addr) ||
ae531b94
PB
287 nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
288 nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, pan_id))
be51da0f 289 goto nla_put_failure;
0a868b26 290 wpan_phy_put(phy);
78fe738d
DES
291 return genlmsg_end(msg, hdr);
292
293nla_put_failure:
0a868b26 294 wpan_phy_put(phy);
78fe738d
DES
295 genlmsg_cancel(msg, hdr);
296out:
297 return -EMSGSIZE;
298}
299
300/* Requests from userspace */
301static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
302{
303 struct net_device *dev;
304
305 if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
306 char name[IFNAMSIZ + 1];
307 nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
308 sizeof(name));
309 dev = dev_get_by_name(&init_net, name);
310 } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX])
311 dev = dev_get_by_index(&init_net,
312 nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
313 else
314 return NULL;
315
316 if (!dev)
317 return NULL;
318
319 if (dev->type != ARPHRD_IEEE802154) {
320 dev_put(dev);
321 return NULL;
322 }
323
324 return dev;
325}
326
1c582d91 327int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
328{
329 struct net_device *dev;
ae531b94 330 struct ieee802154_addr addr;
78fe738d 331 u8 page;
56aa091d 332 int ret = -EOPNOTSUPP;
78fe738d
DES
333
334 if (!info->attrs[IEEE802154_ATTR_CHANNEL] ||
335 !info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
336 (!info->attrs[IEEE802154_ATTR_COORD_HW_ADDR] &&
337 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]) ||
338 !info->attrs[IEEE802154_ATTR_CAPABILITY])
339 return -EINVAL;
340
341 dev = ieee802154_nl_get_dev(info);
342 if (!dev)
343 return -ENODEV;
56aa091d
WA
344 if (!ieee802154_mlme_ops(dev)->assoc_req)
345 goto out;
78fe738d
DES
346
347 if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
ae531b94
PB
348 addr.mode = IEEE802154_ADDR_LONG;
349 addr.extended_addr = nla_get_hwaddr(
350 info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]);
78fe738d 351 } else {
ae531b94
PB
352 addr.mode = IEEE802154_ADDR_SHORT;
353 addr.short_addr = nla_get_shortaddr(
78fe738d
DES
354 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
355 }
ae531b94
PB
356 addr.pan_id = nla_get_shortaddr(
357 info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
78fe738d
DES
358
359 if (info->attrs[IEEE802154_ATTR_PAGE])
360 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
361 else
362 page = 0;
363
364 ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
365 nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
366 page,
367 nla_get_u8(info->attrs[IEEE802154_ATTR_CAPABILITY]));
368
56aa091d 369out:
78fe738d
DES
370 dev_put(dev);
371 return ret;
372}
373
1c582d91 374int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
375{
376 struct net_device *dev;
ae531b94 377 struct ieee802154_addr addr;
56aa091d 378 int ret = -EOPNOTSUPP;
78fe738d
DES
379
380 if (!info->attrs[IEEE802154_ATTR_STATUS] ||
381 !info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] ||
382 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])
383 return -EINVAL;
384
385 dev = ieee802154_nl_get_dev(info);
386 if (!dev)
387 return -ENODEV;
56aa091d
WA
388 if (!ieee802154_mlme_ops(dev)->assoc_resp)
389 goto out;
78fe738d 390
ae531b94
PB
391 addr.mode = IEEE802154_ADDR_LONG;
392 addr.extended_addr = nla_get_hwaddr(
393 info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
394 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
78fe738d
DES
395
396 ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
ae531b94 397 nla_get_shortaddr(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
78fe738d
DES
398 nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
399
56aa091d 400out:
78fe738d
DES
401 dev_put(dev);
402 return ret;
403}
404
1c582d91 405int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
406{
407 struct net_device *dev;
ae531b94 408 struct ieee802154_addr addr;
56aa091d 409 int ret = -EOPNOTSUPP;
78fe738d
DES
410
411 if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
412 !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
413 !info->attrs[IEEE802154_ATTR_REASON])
414 return -EINVAL;
415
416 dev = ieee802154_nl_get_dev(info);
417 if (!dev)
418 return -ENODEV;
56aa091d
WA
419 if (!ieee802154_mlme_ops(dev)->disassoc_req)
420 goto out;
78fe738d
DES
421
422 if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
ae531b94
PB
423 addr.mode = IEEE802154_ADDR_LONG;
424 addr.extended_addr = nla_get_hwaddr(
425 info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
78fe738d 426 } else {
ae531b94
PB
427 addr.mode = IEEE802154_ADDR_SHORT;
428 addr.short_addr = nla_get_shortaddr(
78fe738d
DES
429 info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
430 }
ae531b94 431 addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
78fe738d
DES
432
433 ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
434 nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
435
56aa091d 436out:
78fe738d
DES
437 dev_put(dev);
438 return ret;
439}
440
441/*
442 * PANid, channel, beacon_order = 15, superframe_order = 15,
443 * PAN_coordinator, battery_life_extension = 0,
444 * coord_realignment = 0, security_enable = 0
445*/
1c582d91 446int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
447{
448 struct net_device *dev;
ae531b94 449 struct ieee802154_addr addr;
78fe738d
DES
450
451 u8 channel, bcn_ord, sf_ord;
452 u8 page;
453 int pan_coord, blx, coord_realign;
56aa091d 454 int ret = -EOPNOTSUPP;
78fe738d
DES
455
456 if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
457 !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
458 !info->attrs[IEEE802154_ATTR_CHANNEL] ||
459 !info->attrs[IEEE802154_ATTR_BCN_ORD] ||
460 !info->attrs[IEEE802154_ATTR_SF_ORD] ||
461 !info->attrs[IEEE802154_ATTR_PAN_COORD] ||
462 !info->attrs[IEEE802154_ATTR_BAT_EXT] ||
463 !info->attrs[IEEE802154_ATTR_COORD_REALIGN]
464 )
465 return -EINVAL;
466
467 dev = ieee802154_nl_get_dev(info);
468 if (!dev)
469 return -ENODEV;
56aa091d
WA
470 if (!ieee802154_mlme_ops(dev)->start_req)
471 goto out;
78fe738d 472
ae531b94
PB
473 addr.mode = IEEE802154_ADDR_SHORT;
474 addr.short_addr = nla_get_shortaddr(
78fe738d 475 info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
ae531b94
PB
476 addr.pan_id = nla_get_shortaddr(
477 info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
78fe738d
DES
478
479 channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]);
480 bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]);
481 sf_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_SF_ORD]);
482 pan_coord = nla_get_u8(info->attrs[IEEE802154_ATTR_PAN_COORD]);
483 blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
484 coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
485
486 if (info->attrs[IEEE802154_ATTR_PAGE])
487 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
488 else
489 page = 0;
490
491
ae531b94 492 if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) {
78fe738d
DES
493 ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
494 dev_put(dev);
495 return -EINVAL;
496 }
497
498 ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
499 bcn_ord, sf_ord, pan_coord, blx, coord_realign);
500
56aa091d 501out:
78fe738d
DES
502 dev_put(dev);
503 return ret;
504}
505
1c582d91 506int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
507{
508 struct net_device *dev;
56aa091d 509 int ret = -EOPNOTSUPP;
78fe738d
DES
510 u8 type;
511 u32 channels;
512 u8 duration;
513 u8 page;
514
515 if (!info->attrs[IEEE802154_ATTR_SCAN_TYPE] ||
516 !info->attrs[IEEE802154_ATTR_CHANNELS] ||
517 !info->attrs[IEEE802154_ATTR_DURATION])
518 return -EINVAL;
519
520 dev = ieee802154_nl_get_dev(info);
521 if (!dev)
522 return -ENODEV;
56aa091d
WA
523 if (!ieee802154_mlme_ops(dev)->scan_req)
524 goto out;
78fe738d
DES
525
526 type = nla_get_u8(info->attrs[IEEE802154_ATTR_SCAN_TYPE]);
527 channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
528 duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
529
530 if (info->attrs[IEEE802154_ATTR_PAGE])
531 page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
532 else
533 page = 0;
534
535
536 ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, page,
537 duration);
538
56aa091d 539out:
78fe738d
DES
540 dev_put(dev);
541 return ret;
542}
543
1c582d91 544int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
78fe738d
DES
545{
546 /* Request for interface name, index, type, IEEE address,
547 PAN Id, short address */
548 struct sk_buff *msg;
549 struct net_device *dev = NULL;
550 int rc = -ENOBUFS;
551
552 pr_debug("%s\n", __func__);
553
554 dev = ieee802154_nl_get_dev(info);
555 if (!dev)
556 return -ENODEV;
557
58050fce 558 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
78fe738d
DES
559 if (!msg)
560 goto out_dev;
561
15e47304 562 rc = ieee802154_nl_fill_iface(msg, info->snd_portid, info->snd_seq,
78fe738d
DES
563 0, dev);
564 if (rc < 0)
565 goto out_free;
566
567 dev_put(dev);
568
569 return genlmsg_reply(msg, info);
570out_free:
571 nlmsg_free(msg);
572out_dev:
573 dev_put(dev);
574 return rc;
575
576}
577
1c582d91 578int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
78fe738d
DES
579{
580 struct net *net = sock_net(skb->sk);
581 struct net_device *dev;
582 int idx;
583 int s_idx = cb->args[0];
584
585 pr_debug("%s\n", __func__);
586
587 idx = 0;
588 for_each_netdev(net, dev) {
589 if (idx < s_idx || (dev->type != ARPHRD_IEEE802154))
590 goto cont;
591
15e47304 592 if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
78fe738d
DES
593 cb->nlh->nlmsg_seq, NLM_F_MULTI, dev) < 0)
594 break;
595cont:
596 idx++;
597 }
598 cb->args[0] = idx;
599
600 return skb->len;
601}