~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/mac802154/iface.c

Version: ~ [ linux-6.0-rc6 ] ~ [ linux-5.19.10 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.69 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.144 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.214 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.259 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.294 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.329 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2007-2012 Siemens AG
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Public License version 2
  6  * as published by the Free Software Foundation.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  *
 13  * Written by:
 14  * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
 15  * Sergey Lapin <slapin@ossfans.org>
 16  * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
 17  * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
 18  */
 19 
 20 #include <linux/netdevice.h>
 21 #include <linux/module.h>
 22 #include <linux/if_arp.h>
 23 #include <linux/ieee802154.h>
 24 
 25 #include <net/nl802154.h>
 26 #include <net/mac802154.h>
 27 #include <net/ieee802154_netdev.h>
 28 #include <net/cfg802154.h>
 29 
 30 #include "ieee802154_i.h"
 31 #include "driver-ops.h"
 32 
 33 static int mac802154_wpan_update_llsec(struct net_device *dev)
 34 {
 35         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
 36         struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
 37         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
 38         int rc = 0;
 39 
 40         if (ops->llsec) {
 41                 struct ieee802154_llsec_params params;
 42                 int changed = 0;
 43 
 44                 params.pan_id = wpan_dev->pan_id;
 45                 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
 46 
 47                 params.hwaddr = wpan_dev->extended_addr;
 48                 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
 49 
 50                 rc = ops->llsec->set_params(dev, &params, changed);
 51         }
 52 
 53         return rc;
 54 }
 55 
 56 static int
 57 mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 58 {
 59         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
 60         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
 61         struct sockaddr_ieee802154 *sa =
 62                 (struct sockaddr_ieee802154 *)&ifr->ifr_addr;
 63         int err = -ENOIOCTLCMD;
 64 
 65         if (cmd != SIOCGIFADDR && cmd != SIOCSIFADDR)
 66                 return err;
 67 
 68         rtnl_lock();
 69 
 70         switch (cmd) {
 71         case SIOCGIFADDR:
 72         {
 73                 u16 pan_id, short_addr;
 74 
 75                 pan_id = le16_to_cpu(wpan_dev->pan_id);
 76                 short_addr = le16_to_cpu(wpan_dev->short_addr);
 77                 if (pan_id == IEEE802154_PANID_BROADCAST ||
 78                     short_addr == IEEE802154_ADDR_BROADCAST) {
 79                         err = -EADDRNOTAVAIL;
 80                         break;
 81                 }
 82 
 83                 sa->family = AF_IEEE802154;
 84                 sa->addr.addr_type = IEEE802154_ADDR_SHORT;
 85                 sa->addr.pan_id = pan_id;
 86                 sa->addr.short_addr = short_addr;
 87 
 88                 err = 0;
 89                 break;
 90         }
 91         case SIOCSIFADDR:
 92                 if (netif_running(dev)) {
 93                         rtnl_unlock();
 94                         return -EBUSY;
 95                 }
 96 
 97                 dev_warn(&dev->dev,
 98                          "Using DEBUGing ioctl SIOCSIFADDR isn't recommended!\n");
 99                 if (sa->family != AF_IEEE802154 ||
100                     sa->addr.addr_type != IEEE802154_ADDR_SHORT ||
101                     sa->addr.pan_id == IEEE802154_PANID_BROADCAST ||
102                     sa->addr.short_addr == IEEE802154_ADDR_BROADCAST ||
103                     sa->addr.short_addr == IEEE802154_ADDR_UNDEF) {
104                         err = -EINVAL;
105                         break;
106                 }
107 
108                 wpan_dev->pan_id = cpu_to_le16(sa->addr.pan_id);
109                 wpan_dev->short_addr = cpu_to_le16(sa->addr.short_addr);
110 
111                 err = mac802154_wpan_update_llsec(dev);
112                 break;
113         }
114 
115         rtnl_unlock();
116         return err;
117 }
118 
119 static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
120 {
121         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
122         struct sockaddr *addr = p;
123         __le64 extended_addr;
124 
125         if (netif_running(dev))
126                 return -EBUSY;
127 
128         ieee802154_be64_to_le64(&extended_addr, addr->sa_data);
129         if (!ieee802154_is_valid_extended_unicast_addr(extended_addr))
130                 return -EINVAL;
131 
132         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
133         sdata->wpan_dev.extended_addr = extended_addr;
134 
135         return mac802154_wpan_update_llsec(dev);
136 }
137 
138 static int ieee802154_setup_hw(struct ieee802154_sub_if_data *sdata)
139 {
140         struct ieee802154_local *local = sdata->local;
141         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
142         int ret;
143 
144         if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
145                 ret = drv_set_promiscuous_mode(local,
146                                                wpan_dev->promiscuous_mode);
147                 if (ret < 0)
148                         return ret;
149         }
150 
151         if (local->hw.flags & IEEE802154_HW_AFILT) {
152                 ret = drv_set_pan_id(local, wpan_dev->pan_id);
153                 if (ret < 0)
154                         return ret;
155 
156                 ret = drv_set_extended_addr(local, wpan_dev->extended_addr);
157                 if (ret < 0)
158                         return ret;
159 
160                 ret = drv_set_short_addr(local, wpan_dev->short_addr);
161                 if (ret < 0)
162                         return ret;
163         }
164 
165         if (local->hw.flags & IEEE802154_HW_LBT) {
166                 ret = drv_set_lbt_mode(local, wpan_dev->lbt);
167                 if (ret < 0)
168                         return ret;
169         }
170 
171         if (local->hw.flags & IEEE802154_HW_CSMA_PARAMS) {
172                 ret = drv_set_csma_params(local, wpan_dev->min_be,
173                                           wpan_dev->max_be,
174                                           wpan_dev->csma_retries);
175                 if (ret < 0)
176                         return ret;
177         }
178 
179         if (local->hw.flags & IEEE802154_HW_FRAME_RETRIES) {
180                 ret = drv_set_max_frame_retries(local, wpan_dev->frame_retries);
181                 if (ret < 0)
182                         return ret;
183         }
184 
185         return 0;
186 }
187 
188 static int mac802154_slave_open(struct net_device *dev)
189 {
190         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
191         struct ieee802154_local *local = sdata->local;
192         int res;
193 
194         ASSERT_RTNL();
195 
196         set_bit(SDATA_STATE_RUNNING, &sdata->state);
197 
198         if (!local->open_count) {
199                 res = ieee802154_setup_hw(sdata);
200                 if (res)
201                         goto err;
202 
203                 res = drv_start(local);
204                 if (res)
205                         goto err;
206         }
207 
208         local->open_count++;
209         netif_start_queue(dev);
210         return 0;
211 err:
212         /* might already be clear but that doesn't matter */
213         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
214 
215         return res;
216 }
217 
218 static int
219 ieee802154_check_mac_settings(struct ieee802154_local *local,
220                               struct wpan_dev *wpan_dev,
221                               struct wpan_dev *nwpan_dev)
222 {
223         ASSERT_RTNL();
224 
225         if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
226                 if (wpan_dev->promiscuous_mode != nwpan_dev->promiscuous_mode)
227                         return -EBUSY;
228         }
229 
230         if (local->hw.flags & IEEE802154_HW_AFILT) {
231                 if (wpan_dev->pan_id != nwpan_dev->pan_id ||
232                     wpan_dev->short_addr != nwpan_dev->short_addr ||
233                     wpan_dev->extended_addr != nwpan_dev->extended_addr)
234                         return -EBUSY;
235         }
236 
237         if (local->hw.flags & IEEE802154_HW_CSMA_PARAMS) {
238                 if (wpan_dev->min_be != nwpan_dev->min_be ||
239                     wpan_dev->max_be != nwpan_dev->max_be ||
240                     wpan_dev->csma_retries != nwpan_dev->csma_retries)
241                         return -EBUSY;
242         }
243 
244         if (local->hw.flags & IEEE802154_HW_FRAME_RETRIES) {
245                 if (wpan_dev->frame_retries != nwpan_dev->frame_retries)
246                         return -EBUSY;
247         }
248 
249         if (local->hw.flags & IEEE802154_HW_LBT) {
250                 if (wpan_dev->lbt != nwpan_dev->lbt)
251                         return -EBUSY;
252         }
253 
254         return 0;
255 }
256 
257 static int
258 ieee802154_check_concurrent_iface(struct ieee802154_sub_if_data *sdata,
259                                   enum nl802154_iftype iftype)
260 {
261         struct ieee802154_local *local = sdata->local;
262         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
263         struct ieee802154_sub_if_data *nsdata;
264 
265         /* we hold the RTNL here so can safely walk the list */
266         list_for_each_entry(nsdata, &local->interfaces, list) {
267                 if (nsdata != sdata && ieee802154_sdata_running(nsdata)) {
268                         int ret;
269 
270                         /* TODO currently we don't support multiple node types
271                          * we need to run skb_clone at rx path. Check if there
272                          * exist really an use case if we need to support
273                          * multiple node types at the same time.
274                          */
275                         if (wpan_dev->iftype == NL802154_IFTYPE_NODE &&
276                             nsdata->wpan_dev.iftype == NL802154_IFTYPE_NODE)
277                                 return -EBUSY;
278 
279                         /* check all phy mac sublayer settings are the same.
280                          * We have only one phy, different values makes trouble.
281                          */
282                         ret = ieee802154_check_mac_settings(local, wpan_dev,
283                                                             &nsdata->wpan_dev);
284                         if (ret < 0)
285                                 return ret;
286                 }
287         }
288 
289         return 0;
290 }
291 
292 static int mac802154_wpan_open(struct net_device *dev)
293 {
294         int rc;
295         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
296         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
297 
298         rc = ieee802154_check_concurrent_iface(sdata, wpan_dev->iftype);
299         if (rc < 0)
300                 return rc;
301 
302         return mac802154_slave_open(dev);
303 }
304 
305 static int mac802154_slave_close(struct net_device *dev)
306 {
307         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
308         struct ieee802154_local *local = sdata->local;
309 
310         ASSERT_RTNL();
311 
312         netif_stop_queue(dev);
313         local->open_count--;
314 
315         clear_bit(SDATA_STATE_RUNNING, &sdata->state);
316 
317         if (!local->open_count) {
318                 flush_workqueue(local->workqueue);
319                 hrtimer_cancel(&local->ifs_timer);
320                 drv_stop(local);
321         }
322 
323         return 0;
324 }
325 
326 static int mac802154_set_header_security(struct ieee802154_sub_if_data *sdata,
327                                          struct ieee802154_hdr *hdr,
328                                          const struct ieee802154_mac_cb *cb)
329 {
330         struct ieee802154_llsec_params params;
331         u8 level;
332 
333         mac802154_llsec_get_params(&sdata->sec, &params);
334 
335         if (!params.enabled && cb->secen_override && cb->secen)
336                 return -EINVAL;
337         if (!params.enabled ||
338             (cb->secen_override && !cb->secen) ||
339             !params.out_level)
340                 return 0;
341         if (cb->seclevel_override && !cb->seclevel)
342                 return -EINVAL;
343 
344         level = cb->seclevel_override ? cb->seclevel : params.out_level;
345 
346         hdr->fc.security_enabled = 1;
347         hdr->sec.level = level;
348         hdr->sec.key_id_mode = params.out_key.mode;
349         if (params.out_key.mode == IEEE802154_SCF_KEY_SHORT_INDEX)
350                 hdr->sec.short_src = params.out_key.short_source;
351         else if (params.out_key.mode == IEEE802154_SCF_KEY_HW_INDEX)
352                 hdr->sec.extended_src = params.out_key.extended_source;
353         hdr->sec.key_id = params.out_key.id;
354 
355         return 0;
356 }
357 
358 static int mac802154_header_create(struct sk_buff *skb,
359                                    struct net_device *dev,
360                                    unsigned short type,
361                                    const void *daddr,
362                                    const void *saddr,
363                                    unsigned len)
364 {
365         struct ieee802154_hdr hdr;
366         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
367         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
368         struct ieee802154_mac_cb *cb = mac_cb(skb);
369         int hlen;
370 
371         if (!daddr)
372                 return -EINVAL;
373 
374         memset(&hdr.fc, 0, sizeof(hdr.fc));
375         hdr.fc.type = cb->type;
376         hdr.fc.security_enabled = cb->secen;
377         hdr.fc.ack_request = cb->ackreq;
378         hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;
379 
380         if (mac802154_set_header_security(sdata, &hdr, cb) < 0)
381                 return -EINVAL;
382 
383         if (!saddr) {
384                 if (wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
385                     wpan_dev->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
386                     wpan_dev->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
387                         hdr.source.mode = IEEE802154_ADDR_LONG;
388                         hdr.source.extended_addr = wpan_dev->extended_addr;
389                 } else {
390                         hdr.source.mode = IEEE802154_ADDR_SHORT;
391                         hdr.source.short_addr = wpan_dev->short_addr;
392                 }
393 
394                 hdr.source.pan_id = wpan_dev->pan_id;
395         } else {
396                 hdr.source = *(const struct ieee802154_addr *)saddr;
397         }
398 
399         hdr.dest = *(const struct ieee802154_addr *)daddr;
400 
401         hlen = ieee802154_hdr_push(skb, &hdr);
402         if (hlen < 0)
403                 return -EINVAL;
404 
405         skb_reset_mac_header(skb);
406         skb->mac_len = hlen;
407 
408         if (len > ieee802154_max_payload(&hdr))
409                 return -EMSGSIZE;
410 
411         return hlen;
412 }
413 
414 static int
415 mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
416 {
417         struct ieee802154_hdr hdr;
418         struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
419 
420         if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
421                 pr_debug("malformed packet\n");
422                 return 0;
423         }
424 
425         *addr = hdr.source;
426         return sizeof(*addr);
427 }
428 
429 static struct header_ops mac802154_header_ops = {
430         .create         = mac802154_header_create,
431         .parse          = mac802154_header_parse,
432 };
433 
434 static const struct net_device_ops mac802154_wpan_ops = {
435         .ndo_open               = mac802154_wpan_open,
436         .ndo_stop               = mac802154_slave_close,
437         .ndo_start_xmit         = ieee802154_subif_start_xmit,
438         .ndo_do_ioctl           = mac802154_wpan_ioctl,
439         .ndo_set_mac_address    = mac802154_wpan_mac_addr,
440 };
441 
442 static const struct net_device_ops mac802154_monitor_ops = {
443         .ndo_open               = mac802154_wpan_open,
444         .ndo_stop               = mac802154_slave_close,
445         .ndo_start_xmit         = ieee802154_monitor_start_xmit,
446 };
447 
448 static void mac802154_wpan_free(struct net_device *dev)
449 {
450         struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
451 
452         mac802154_llsec_destroy(&sdata->sec);
453 
454         free_netdev(dev);
455 }
456 
457 static void ieee802154_if_setup(struct net_device *dev)
458 {
459         dev->addr_len           = IEEE802154_EXTENDED_ADDR_LEN;
460         memset(dev->broadcast, 0xff, IEEE802154_EXTENDED_ADDR_LEN);
461 
462         dev->hard_header_len    = MAC802154_FRAME_HARD_HEADER_LEN;
463         dev->needed_tailroom    = 2 + 16; /* FCS + MIC */
464         dev->mtu                = IEEE802154_MTU;
465         dev->tx_queue_len       = 300;
466         dev->flags              = IFF_NOARP | IFF_BROADCAST;
467 }
468 
469 static int
470 ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
471                        enum nl802154_iftype type)
472 {
473         struct wpan_dev *wpan_dev = &sdata->wpan_dev;
474         u8 tmp;
475 
476         /* set some type-dependent values */
477         sdata->wpan_dev.iftype = type;
478 
479         get_random_bytes(&tmp, sizeof(tmp));
480         atomic_set(&wpan_dev->bsn, tmp);
481         get_random_bytes(&tmp, sizeof(tmp));
482         atomic_set(&wpan_dev->dsn, tmp);
483 
484         /* defaults per 802.15.4-2011 */
485         wpan_dev->min_be = 3;
486         wpan_dev->max_be = 5;
487         wpan_dev->csma_retries = 4;
488         /* for compatibility, actual default is 3 */
489         wpan_dev->frame_retries = -1;
490 
491         wpan_dev->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
492         wpan_dev->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
493 
494         switch (type) {
495         case NL802154_IFTYPE_NODE:
496                 ieee802154_be64_to_le64(&wpan_dev->extended_addr,
497                                         sdata->dev->dev_addr);
498 
499                 sdata->dev->header_ops = &mac802154_header_ops;
500                 sdata->dev->destructor = mac802154_wpan_free;
501                 sdata->dev->netdev_ops = &mac802154_wpan_ops;
502                 sdata->dev->ml_priv = &mac802154_mlme_wpan;
503                 wpan_dev->promiscuous_mode = false;
504 
505                 mutex_init(&sdata->sec_mtx);
506 
507                 mac802154_llsec_init(&sdata->sec);
508                 break;
509         case NL802154_IFTYPE_MONITOR:
510                 sdata->dev->destructor = free_netdev;
511                 sdata->dev->netdev_ops = &mac802154_monitor_ops;
512                 wpan_dev->promiscuous_mode = true;
513                 break;
514         default:
515                 BUG();
516         }
517 
518         return 0;
519 }
520 
521 struct net_device *
522 ieee802154_if_add(struct ieee802154_local *local, const char *name,
523                   unsigned char name_assign_type, enum nl802154_iftype type,
524                   __le64 extended_addr)
525 {
526         struct net_device *ndev = NULL;
527         struct ieee802154_sub_if_data *sdata = NULL;
528         int ret = -ENOMEM;
529 
530         ASSERT_RTNL();
531 
532         ndev = alloc_netdev(sizeof(*sdata), name,
533                             name_assign_type, ieee802154_if_setup);
534         if (!ndev)
535                 return ERR_PTR(-ENOMEM);
536 
537         ndev->needed_headroom = local->hw.extra_tx_headroom;
538 
539         ret = dev_alloc_name(ndev, ndev->name);
540         if (ret < 0)
541                 goto err;
542 
543         ieee802154_le64_to_be64(ndev->perm_addr,
544                                 &local->hw.phy->perm_extended_addr);
545         switch (type) {
546         case NL802154_IFTYPE_NODE:
547                 ndev->type = ARPHRD_IEEE802154;
548                 if (ieee802154_is_valid_extended_unicast_addr(extended_addr))
549                         ieee802154_le64_to_be64(ndev->dev_addr, &extended_addr);
550                 else
551                         memcpy(ndev->dev_addr, ndev->perm_addr,
552                                IEEE802154_EXTENDED_ADDR_LEN);
553                 break;
554         case NL802154_IFTYPE_MONITOR:
555                 ndev->type = ARPHRD_IEEE802154_MONITOR;
556                 break;
557         default:
558                 ret = -EINVAL;
559                 goto err;
560         }
561 
562         /* TODO check this */
563         SET_NETDEV_DEV(ndev, &local->phy->dev);
564         sdata = netdev_priv(ndev);
565         ndev->ieee802154_ptr = &sdata->wpan_dev;
566         memcpy(sdata->name, ndev->name, IFNAMSIZ);
567         sdata->dev = ndev;
568         sdata->wpan_dev.wpan_phy = local->hw.phy;
569         sdata->local = local;
570 
571         /* setup type-dependent data */
572         ret = ieee802154_setup_sdata(sdata, type);
573         if (ret)
574                 goto err;
575 
576         ret = register_netdevice(ndev);
577         if (ret < 0)
578                 goto err;
579 
580         mutex_lock(&local->iflist_mtx);
581         list_add_tail_rcu(&sdata->list, &local->interfaces);
582         mutex_unlock(&local->iflist_mtx);
583 
584         return ndev;
585 
586 err:
587         free_netdev(ndev);
588         return ERR_PTR(ret);
589 }
590 
591 void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
592 {
593         ASSERT_RTNL();
594 
595         mutex_lock(&sdata->local->iflist_mtx);
596         list_del_rcu(&sdata->list);
597         mutex_unlock(&sdata->local->iflist_mtx);
598 
599         synchronize_rcu();
600         unregister_netdevice(sdata->dev);
601 }
602 
603 void ieee802154_remove_interfaces(struct ieee802154_local *local)
604 {
605         struct ieee802154_sub_if_data *sdata, *tmp;
606 
607         mutex_lock(&local->iflist_mtx);
608         list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
609                 list_del(&sdata->list);
610 
611                 unregister_netdevice(sdata->dev);
612         }
613         mutex_unlock(&local->iflist_mtx);
614 }
615 
616 static int netdev_notify(struct notifier_block *nb,
617                          unsigned long state, void *ptr)
618 {
619         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
620         struct ieee802154_sub_if_data *sdata;
621 
622         if (state != NETDEV_CHANGENAME)
623                 return NOTIFY_DONE;
624 
625         if (!dev->ieee802154_ptr || !dev->ieee802154_ptr->wpan_phy)
626                 return NOTIFY_DONE;
627 
628         if (dev->ieee802154_ptr->wpan_phy->privid != mac802154_wpan_phy_privid)
629                 return NOTIFY_DONE;
630 
631         sdata = IEEE802154_DEV_TO_SUB_IF(dev);
632         memcpy(sdata->name, dev->name, IFNAMSIZ);
633 
634         return NOTIFY_OK;
635 }
636 
637 static struct notifier_block mac802154_netdev_notifier = {
638         .notifier_call = netdev_notify,
639 };
640 
641 int ieee802154_iface_init(void)
642 {
643         return register_netdevice_notifier(&mac802154_netdev_notifier);
644 }
645 
646 void ieee802154_iface_exit(void)
647 {
648         unregister_netdevice_notifier(&mac802154_netdev_notifier);
649 }
650 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp