nl-mac.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. #include <linux/gfp.h>
  25. #include <linux/kernel.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/netdevice.h>
  28. #include <net/netlink.h>
  29. #include <net/genetlink.h>
  30. #include <net/sock.h>
  31. #include <linux/nl802154.h>
  32. #include <net/af_ieee802154.h>
  33. #include <net/nl802154.h>
  34. #include <net/ieee802154.h>
  35. #include <net/ieee802154_netdev.h>
  36. #include <net/wpan-phy.h>
  37. #include "ieee802154.h"
  38. static struct genl_multicast_group ieee802154_coord_mcgrp = {
  39. .name = IEEE802154_MCAST_COORD_NAME,
  40. };
  41. static struct genl_multicast_group ieee802154_beacon_mcgrp = {
  42. .name = IEEE802154_MCAST_BEACON_NAME,
  43. };
  44. int ieee802154_nl_assoc_indic(struct net_device *dev,
  45. struct ieee802154_addr *addr, u8 cap)
  46. {
  47. struct sk_buff *msg;
  48. pr_debug("%s\n", __func__);
  49. if (addr->addr_type != IEEE802154_ADDR_LONG) {
  50. pr_err("%s: received non-long source address!\n", __func__);
  51. return -EINVAL;
  52. }
  53. msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
  54. if (!msg)
  55. return -ENOBUFS;
  56. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  57. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  58. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  59. dev->dev_addr);
  60. NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
  61. addr->hwaddr);
  62. NLA_PUT_U8(msg, IEEE802154_ATTR_CAPABILITY, cap);
  63. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  64. nla_put_failure:
  65. nlmsg_free(msg);
  66. return -ENOBUFS;
  67. }
  68. EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
  69. int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
  70. u8 status)
  71. {
  72. struct sk_buff *msg;
  73. pr_debug("%s\n", __func__);
  74. msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
  75. if (!msg)
  76. return -ENOBUFS;
  77. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  78. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  79. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  80. dev->dev_addr);
  81. NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr);
  82. NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
  83. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  84. nla_put_failure:
  85. nlmsg_free(msg);
  86. return -ENOBUFS;
  87. }
  88. EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
  89. int ieee802154_nl_disassoc_indic(struct net_device *dev,
  90. struct ieee802154_addr *addr, u8 reason)
  91. {
  92. struct sk_buff *msg;
  93. pr_debug("%s\n", __func__);
  94. msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
  95. if (!msg)
  96. return -ENOBUFS;
  97. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  98. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  99. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  100. dev->dev_addr);
  101. if (addr->addr_type == IEEE802154_ADDR_LONG)
  102. NLA_PUT(msg, IEEE802154_ATTR_SRC_HW_ADDR, IEEE802154_ADDR_LEN,
  103. addr->hwaddr);
  104. else
  105. NLA_PUT_U16(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
  106. addr->short_addr);
  107. NLA_PUT_U8(msg, IEEE802154_ATTR_REASON, reason);
  108. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  109. nla_put_failure:
  110. nlmsg_free(msg);
  111. return -ENOBUFS;
  112. }
  113. EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
  114. int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
  115. {
  116. struct sk_buff *msg;
  117. pr_debug("%s\n", __func__);
  118. msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
  119. if (!msg)
  120. return -ENOBUFS;
  121. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  122. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  123. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  124. dev->dev_addr);
  125. NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
  126. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  127. nla_put_failure:
  128. nlmsg_free(msg);
  129. return -ENOBUFS;
  130. }
  131. EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
  132. int ieee802154_nl_beacon_indic(struct net_device *dev,
  133. u16 panid, u16 coord_addr)
  134. {
  135. struct sk_buff *msg;
  136. pr_debug("%s\n", __func__);
  137. msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
  138. if (!msg)
  139. return -ENOBUFS;
  140. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  141. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  142. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  143. dev->dev_addr);
  144. NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr);
  145. NLA_PUT_U16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid);
  146. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  147. nla_put_failure:
  148. nlmsg_free(msg);
  149. return -ENOBUFS;
  150. }
  151. EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
  152. int ieee802154_nl_scan_confirm(struct net_device *dev,
  153. u8 status, u8 scan_type, u32 unscanned, u8 page,
  154. u8 *edl/* , struct list_head *pan_desc_list */)
  155. {
  156. struct sk_buff *msg;
  157. pr_debug("%s\n", __func__);
  158. msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
  159. if (!msg)
  160. return -ENOBUFS;
  161. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  162. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  163. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  164. dev->dev_addr);
  165. NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
  166. NLA_PUT_U8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type);
  167. NLA_PUT_U32(msg, IEEE802154_ATTR_CHANNELS, unscanned);
  168. NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, page);
  169. if (edl)
  170. NLA_PUT(msg, IEEE802154_ATTR_ED_LIST, 27, edl);
  171. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  172. nla_put_failure:
  173. nlmsg_free(msg);
  174. return -ENOBUFS;
  175. }
  176. EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
  177. int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
  178. {
  179. struct sk_buff *msg;
  180. pr_debug("%s\n", __func__);
  181. msg = ieee802154_nl_create(0, IEEE802154_START_CONF);
  182. if (!msg)
  183. return -ENOBUFS;
  184. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  185. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  186. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  187. dev->dev_addr);
  188. NLA_PUT_U8(msg, IEEE802154_ATTR_STATUS, status);
  189. return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
  190. nla_put_failure:
  191. nlmsg_free(msg);
  192. return -ENOBUFS;
  193. }
  194. EXPORT_SYMBOL(ieee802154_nl_start_confirm);
  195. static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 pid,
  196. u32 seq, int flags, struct net_device *dev)
  197. {
  198. void *hdr;
  199. struct wpan_phy *phy;
  200. pr_debug("%s\n", __func__);
  201. hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
  202. IEEE802154_LIST_IFACE);
  203. if (!hdr)
  204. goto out;
  205. phy = ieee802154_mlme_ops(dev)->get_phy(dev);
  206. BUG_ON(!phy);
  207. NLA_PUT_STRING(msg, IEEE802154_ATTR_DEV_NAME, dev->name);
  208. NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
  209. NLA_PUT_U32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex);
  210. NLA_PUT(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
  211. dev->dev_addr);
  212. NLA_PUT_U16(msg, IEEE802154_ATTR_SHORT_ADDR,
  213. ieee802154_mlme_ops(dev)->get_short_addr(dev));
  214. NLA_PUT_U16(msg, IEEE802154_ATTR_PAN_ID,
  215. ieee802154_mlme_ops(dev)->get_pan_id(dev));
  216. wpan_phy_put(phy);
  217. return genlmsg_end(msg, hdr);
  218. nla_put_failure:
  219. wpan_phy_put(phy);
  220. genlmsg_cancel(msg, hdr);
  221. out:
  222. return -EMSGSIZE;
  223. }
  224. /* Requests from userspace */
  225. static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
  226. {
  227. struct net_device *dev;
  228. if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
  229. char name[IFNAMSIZ + 1];
  230. nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
  231. sizeof(name));
  232. dev = dev_get_by_name(&init_net, name);
  233. } else if (info->attrs[IEEE802154_ATTR_DEV_INDEX])
  234. dev = dev_get_by_index(&init_net,
  235. nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
  236. else
  237. return NULL;
  238. if (!dev)
  239. return NULL;
  240. if (dev->type != ARPHRD_IEEE802154) {
  241. dev_put(dev);
  242. return NULL;
  243. }
  244. return dev;
  245. }
  246. static int ieee802154_associate_req(struct sk_buff *skb,
  247. struct genl_info *info)
  248. {
  249. struct net_device *dev;
  250. struct ieee802154_addr addr;
  251. u8 page;
  252. int ret = -EINVAL;
  253. if (!info->attrs[IEEE802154_ATTR_CHANNEL] ||
  254. !info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
  255. (!info->attrs[IEEE802154_ATTR_COORD_HW_ADDR] &&
  256. !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]) ||
  257. !info->attrs[IEEE802154_ATTR_CAPABILITY])
  258. return -EINVAL;
  259. dev = ieee802154_nl_get_dev(info);
  260. if (!dev)
  261. return -ENODEV;
  262. if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
  263. addr.addr_type = IEEE802154_ADDR_LONG;
  264. nla_memcpy(addr.hwaddr,
  265. info->attrs[IEEE802154_ATTR_COORD_HW_ADDR],
  266. IEEE802154_ADDR_LEN);
  267. } else {
  268. addr.addr_type = IEEE802154_ADDR_SHORT;
  269. addr.short_addr = nla_get_u16(
  270. info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
  271. }
  272. addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
  273. if (info->attrs[IEEE802154_ATTR_PAGE])
  274. page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
  275. else
  276. page = 0;
  277. ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
  278. nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
  279. page,
  280. nla_get_u8(info->attrs[IEEE802154_ATTR_CAPABILITY]));
  281. dev_put(dev);
  282. return ret;
  283. }
  284. static int ieee802154_associate_resp(struct sk_buff *skb,
  285. struct genl_info *info)
  286. {
  287. struct net_device *dev;
  288. struct ieee802154_addr addr;
  289. int ret = -EINVAL;
  290. if (!info->attrs[IEEE802154_ATTR_STATUS] ||
  291. !info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] ||
  292. !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])
  293. return -EINVAL;
  294. dev = ieee802154_nl_get_dev(info);
  295. if (!dev)
  296. return -ENODEV;
  297. addr.addr_type = IEEE802154_ADDR_LONG;
  298. nla_memcpy(addr.hwaddr, info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
  299. IEEE802154_ADDR_LEN);
  300. addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
  301. ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
  302. nla_get_u16(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
  303. nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
  304. dev_put(dev);
  305. return ret;
  306. }
  307. static int ieee802154_disassociate_req(struct sk_buff *skb,
  308. struct genl_info *info)
  309. {
  310. struct net_device *dev;
  311. struct ieee802154_addr addr;
  312. int ret = -EINVAL;
  313. if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
  314. !info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
  315. !info->attrs[IEEE802154_ATTR_REASON])
  316. return -EINVAL;
  317. dev = ieee802154_nl_get_dev(info);
  318. if (!dev)
  319. return -ENODEV;
  320. if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
  321. addr.addr_type = IEEE802154_ADDR_LONG;
  322. nla_memcpy(addr.hwaddr,
  323. info->attrs[IEEE802154_ATTR_DEST_HW_ADDR],
  324. IEEE802154_ADDR_LEN);
  325. } else {
  326. addr.addr_type = IEEE802154_ADDR_SHORT;
  327. addr.short_addr = nla_get_u16(
  328. info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
  329. }
  330. addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
  331. ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
  332. nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
  333. dev_put(dev);
  334. return ret;
  335. }
  336. /*
  337. * PANid, channel, beacon_order = 15, superframe_order = 15,
  338. * PAN_coordinator, battery_life_extension = 0,
  339. * coord_realignment = 0, security_enable = 0
  340. */
  341. static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
  342. {
  343. struct net_device *dev;
  344. struct ieee802154_addr addr;
  345. u8 channel, bcn_ord, sf_ord;
  346. u8 page;
  347. int pan_coord, blx, coord_realign;
  348. int ret;
  349. if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
  350. !info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
  351. !info->attrs[IEEE802154_ATTR_CHANNEL] ||
  352. !info->attrs[IEEE802154_ATTR_BCN_ORD] ||
  353. !info->attrs[IEEE802154_ATTR_SF_ORD] ||
  354. !info->attrs[IEEE802154_ATTR_PAN_COORD] ||
  355. !info->attrs[IEEE802154_ATTR_BAT_EXT] ||
  356. !info->attrs[IEEE802154_ATTR_COORD_REALIGN]
  357. )
  358. return -EINVAL;
  359. dev = ieee802154_nl_get_dev(info);
  360. if (!dev)
  361. return -ENODEV;
  362. addr.addr_type = IEEE802154_ADDR_SHORT;
  363. addr.short_addr = nla_get_u16(
  364. info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
  365. addr.pan_id = nla_get_u16(info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
  366. channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]);
  367. bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]);
  368. sf_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_SF_ORD]);
  369. pan_coord = nla_get_u8(info->attrs[IEEE802154_ATTR_PAN_COORD]);
  370. blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
  371. coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
  372. if (info->attrs[IEEE802154_ATTR_PAGE])
  373. page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
  374. else
  375. page = 0;
  376. if (addr.short_addr == IEEE802154_ADDR_BROADCAST) {
  377. ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
  378. dev_put(dev);
  379. return -EINVAL;
  380. }
  381. ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
  382. bcn_ord, sf_ord, pan_coord, blx, coord_realign);
  383. dev_put(dev);
  384. return ret;
  385. }
  386. static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
  387. {
  388. struct net_device *dev;
  389. int ret;
  390. u8 type;
  391. u32 channels;
  392. u8 duration;
  393. u8 page;
  394. if (!info->attrs[IEEE802154_ATTR_SCAN_TYPE] ||
  395. !info->attrs[IEEE802154_ATTR_CHANNELS] ||
  396. !info->attrs[IEEE802154_ATTR_DURATION])
  397. return -EINVAL;
  398. dev = ieee802154_nl_get_dev(info);
  399. if (!dev)
  400. return -ENODEV;
  401. type = nla_get_u8(info->attrs[IEEE802154_ATTR_SCAN_TYPE]);
  402. channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
  403. duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
  404. if (info->attrs[IEEE802154_ATTR_PAGE])
  405. page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
  406. else
  407. page = 0;
  408. ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels, page,
  409. duration);
  410. dev_put(dev);
  411. return ret;
  412. }
  413. static int ieee802154_list_iface(struct sk_buff *skb,
  414. struct genl_info *info)
  415. {
  416. /* Request for interface name, index, type, IEEE address,
  417. PAN Id, short address */
  418. struct sk_buff *msg;
  419. struct net_device *dev = NULL;
  420. int rc = -ENOBUFS;
  421. pr_debug("%s\n", __func__);
  422. dev = ieee802154_nl_get_dev(info);
  423. if (!dev)
  424. return -ENODEV;
  425. msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  426. if (!msg)
  427. goto out_dev;
  428. rc = ieee802154_nl_fill_iface(msg, info->snd_pid, info->snd_seq,
  429. 0, dev);
  430. if (rc < 0)
  431. goto out_free;
  432. dev_put(dev);
  433. return genlmsg_reply(msg, info);
  434. out_free:
  435. nlmsg_free(msg);
  436. out_dev:
  437. dev_put(dev);
  438. return rc;
  439. }
  440. static int ieee802154_dump_iface(struct sk_buff *skb,
  441. struct netlink_callback *cb)
  442. {
  443. struct net *net = sock_net(skb->sk);
  444. struct net_device *dev;
  445. int idx;
  446. int s_idx = cb->args[0];
  447. pr_debug("%s\n", __func__);
  448. idx = 0;
  449. for_each_netdev(net, dev) {
  450. if (idx < s_idx || (dev->type != ARPHRD_IEEE802154))
  451. goto cont;
  452. if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).pid,
  453. cb->nlh->nlmsg_seq, NLM_F_MULTI, dev) < 0)
  454. break;
  455. cont:
  456. idx++;
  457. }
  458. cb->args[0] = idx;
  459. return skb->len;
  460. }
  461. static struct genl_ops ieee802154_coordinator_ops[] = {
  462. IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
  463. IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
  464. IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
  465. IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
  466. IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
  467. IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
  468. ieee802154_dump_iface),
  469. };
  470. /*
  471. * No need to unregister as family unregistration will do it.
  472. */
  473. int nl802154_mac_register(void)
  474. {
  475. int i;
  476. int rc;
  477. rc = genl_register_mc_group(&nl802154_family,
  478. &ieee802154_coord_mcgrp);
  479. if (rc)
  480. return rc;
  481. rc = genl_register_mc_group(&nl802154_family,
  482. &ieee802154_beacon_mcgrp);
  483. if (rc)
  484. return rc;
  485. for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
  486. rc = genl_register_ops(&nl802154_family,
  487. &ieee802154_coordinator_ops[i]);
  488. if (rc)
  489. return rc;
  490. }
  491. return 0;
  492. }