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