2012-06-25 17:24:48 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2007-2012 Siemens AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
|
|
|
|
* Sergey Lapin <slapin@ossfans.org>
|
|
|
|
* Maxim Gorbachyov <maxim.gorbachev@siemens.com>
|
|
|
|
* Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/if_arp.h>
|
2014-10-25 01:41:04 -06:00
|
|
|
#include <linux/ieee802154.h>
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
#include <net/rtnetlink.h>
|
|
|
|
#include <linux/nl802154.h>
|
|
|
|
#include <net/af_ieee802154.h>
|
|
|
|
#include <net/mac802154.h>
|
|
|
|
#include <net/ieee802154_netdev.h>
|
2014-10-25 01:41:02 -06:00
|
|
|
#include <net/cfg802154.h>
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 01:41:00 -06:00
|
|
|
#include "ieee802154_i.h"
|
2014-10-28 11:21:21 -06:00
|
|
|
#include "driver-ops.h"
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-05-16 09:46:43 -06:00
|
|
|
static int mac802154_wpan_update_llsec(struct net_device *dev)
|
|
|
|
{
|
2014-10-25 09:16:40 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2014-05-16 09:46:43 -06:00
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (ops->llsec) {
|
|
|
|
struct ieee802154_llsec_params params;
|
|
|
|
int changed = 0;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
params.pan_id = sdata->pan_id;
|
2014-05-16 09:46:43 -06:00
|
|
|
changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
params.hwaddr = sdata->extended_addr;
|
2014-05-16 09:46:43 -06:00
|
|
|
changed |= IEEE802154_LLSEC_PARAM_HWADDR;
|
|
|
|
|
|
|
|
rc = ops->llsec->set_params(dev, ¶ms, changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:24:48 -06:00
|
|
|
static int
|
|
|
|
mac802154_wpan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
|
|
|
{
|
2014-10-25 09:16:40 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2012-06-25 17:24:48 -06:00
|
|
|
struct sockaddr_ieee802154 *sa =
|
|
|
|
(struct sockaddr_ieee802154 *)&ifr->ifr_addr;
|
|
|
|
int err = -ENOIOCTLCMD;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
spin_lock_bh(&sdata->mib_lock);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGIFADDR:
|
2014-03-14 14:23:59 -06:00
|
|
|
{
|
|
|
|
u16 pan_id, short_addr;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
pan_id = le16_to_cpu(sdata->pan_id);
|
|
|
|
short_addr = le16_to_cpu(sdata->short_addr);
|
2014-03-14 14:23:59 -06:00
|
|
|
if (pan_id == IEEE802154_PANID_BROADCAST ||
|
|
|
|
short_addr == IEEE802154_ADDR_BROADCAST) {
|
2012-06-25 17:24:48 -06:00
|
|
|
err = -EADDRNOTAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sa->family = AF_IEEE802154;
|
|
|
|
sa->addr.addr_type = IEEE802154_ADDR_SHORT;
|
2014-03-14 14:23:59 -06:00
|
|
|
sa->addr.pan_id = pan_id;
|
|
|
|
sa->addr.short_addr = short_addr;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
break;
|
2014-03-14 14:23:59 -06:00
|
|
|
}
|
2012-06-25 17:24:48 -06:00
|
|
|
case SIOCSIFADDR:
|
|
|
|
dev_warn(&dev->dev,
|
2014-08-06 07:31:28 -06:00
|
|
|
"Using DEBUGing ioctl SIOCSIFADDR isn't recommended!\n");
|
2012-06-25 17:24:48 -06:00
|
|
|
if (sa->family != AF_IEEE802154 ||
|
|
|
|
sa->addr.addr_type != IEEE802154_ADDR_SHORT ||
|
|
|
|
sa->addr.pan_id == IEEE802154_PANID_BROADCAST ||
|
|
|
|
sa->addr.short_addr == IEEE802154_ADDR_BROADCAST ||
|
|
|
|
sa->addr.short_addr == IEEE802154_ADDR_UNDEF) {
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
sdata->pan_id = cpu_to_le16(sa->addr.pan_id);
|
|
|
|
sdata->short_addr = cpu_to_le16(sa->addr.short_addr);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-05-16 09:46:43 -06:00
|
|
|
err = mac802154_wpan_update_llsec(dev);
|
2012-06-25 17:24:48 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
spin_unlock_bh(&sdata->mib_lock);
|
2012-06-25 17:24:48 -06:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mac802154_wpan_mac_addr(struct net_device *dev, void *p)
|
|
|
|
{
|
2014-11-01 21:18:41 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2012-06-25 17:24:48 -06:00
|
|
|
struct sockaddr *addr = p;
|
2014-11-01 21:18:46 -06:00
|
|
|
__le64 extended_addr;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
if (netif_running(dev))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2014-11-01 21:18:46 -06:00
|
|
|
extended_addr = ieee802154_netdev_to_extended_addr(addr->sa_data);
|
|
|
|
if (!ieee802154_is_valid_extended_addr(extended_addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-06-25 17:24:48 -06:00
|
|
|
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
|
2014-11-01 21:18:46 -06:00
|
|
|
sdata->extended_addr = extended_addr;
|
2014-11-01 21:18:41 -06:00
|
|
|
|
2014-05-16 09:46:43 -06:00
|
|
|
return mac802154_wpan_update_llsec(dev);
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:17 -06:00
|
|
|
static int mac802154_slave_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
|
|
|
struct ieee802154_sub_if_data *subif;
|
|
|
|
struct ieee802154_local *local = sdata->local;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
if (sdata->type == IEEE802154_DEV_WPAN) {
|
|
|
|
mutex_lock(&sdata->local->iflist_mtx);
|
|
|
|
list_for_each_entry(subif, &sdata->local->interfaces, list) {
|
|
|
|
if (subif != sdata && subif->type == sdata->type &&
|
2014-10-28 11:21:24 -06:00
|
|
|
ieee802154_sdata_running(subif)) {
|
2014-10-28 11:21:17 -06:00
|
|
|
mutex_unlock(&sdata->local->iflist_mtx);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&sdata->local->iflist_mtx);
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:24 -06:00
|
|
|
set_bit(SDATA_STATE_RUNNING, &sdata->state);
|
2014-10-28 11:21:17 -06:00
|
|
|
|
2014-10-28 11:21:31 -06:00
|
|
|
if (!local->open_count) {
|
2014-10-28 11:21:21 -06:00
|
|
|
res = drv_start(local);
|
2014-10-28 11:21:17 -06:00
|
|
|
WARN_ON(res);
|
|
|
|
if (res)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:31 -06:00
|
|
|
local->open_count++;
|
2014-10-28 11:21:17 -06:00
|
|
|
netif_start_queue(dev);
|
|
|
|
return 0;
|
|
|
|
err:
|
2014-10-28 11:21:24 -06:00
|
|
|
/* might already be clear but that doesn't matter */
|
|
|
|
clear_bit(SDATA_STATE_RUNNING, &sdata->state);
|
2014-10-28 11:21:17 -06:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-05-14 09:43:11 -06:00
|
|
|
static int mac802154_wpan_open(struct net_device *dev)
|
2014-03-31 13:37:46 -06:00
|
|
|
{
|
|
|
|
int rc;
|
2014-10-25 09:16:40 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2014-10-28 11:21:21 -06:00
|
|
|
struct ieee802154_local *local = sdata->local;
|
2014-10-25 09:16:37 -06:00
|
|
|
struct wpan_phy *phy = sdata->local->phy;
|
2014-03-31 13:37:46 -06:00
|
|
|
|
|
|
|
rc = mac802154_slave_open(dev);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
mutex_lock(&phy->pib_lock);
|
|
|
|
|
2014-10-29 14:34:44 -06:00
|
|
|
if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
|
|
|
|
rc = drv_set_promiscuous_mode(local, sdata->promisuous_mode);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-11-01 21:18:41 -06:00
|
|
|
if (local->hw.flags & IEEE802154_HW_AFILT) {
|
2014-11-01 21:18:43 -06:00
|
|
|
rc = drv_set_pan_id(local, sdata->pan_id);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
|
2014-11-01 21:18:41 -06:00
|
|
|
rc = drv_set_extended_addr(local, sdata->extended_addr);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
2014-11-01 21:18:42 -06:00
|
|
|
|
|
|
|
rc = drv_set_short_addr(local, sdata->short_addr);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
2014-11-01 21:18:41 -06:00
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:23 -06:00
|
|
|
if (local->hw.flags & IEEE802154_HW_LBT) {
|
2014-10-28 11:21:21 -06:00
|
|
|
rc = drv_set_lbt_mode(local, sdata->mac_params.lbt);
|
2014-03-31 13:37:46 -06:00
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:23 -06:00
|
|
|
if (local->hw.flags & IEEE802154_HW_CSMA_PARAMS) {
|
2014-10-28 11:21:21 -06:00
|
|
|
rc = drv_set_csma_params(local, sdata->mac_params.min_be,
|
|
|
|
sdata->mac_params.max_be,
|
|
|
|
sdata->mac_params.csma_retries);
|
2014-03-31 13:37:46 -06:00
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:23 -06:00
|
|
|
if (local->hw.flags & IEEE802154_HW_FRAME_RETRIES) {
|
2014-10-28 11:21:21 -06:00
|
|
|
rc = drv_set_max_frame_retries(local,
|
|
|
|
sdata->mac_params.frame_retries);
|
2014-03-31 13:37:46 -06:00
|
|
|
if (rc < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&phy->pib_lock);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&phy->pib_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-10-28 11:21:17 -06:00
|
|
|
static int mac802154_slave_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
|
|
|
struct ieee802154_local *local = sdata->local;
|
|
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
2014-10-28 11:21:31 -06:00
|
|
|
local->open_count--;
|
2014-10-28 11:21:17 -06:00
|
|
|
|
2014-10-28 11:21:24 -06:00
|
|
|
clear_bit(SDATA_STATE_RUNNING, &sdata->state);
|
2014-10-28 11:21:17 -06:00
|
|
|
|
2014-10-28 11:21:31 -06:00
|
|
|
if (!local->open_count)
|
2014-10-28 11:21:21 -06:00
|
|
|
drv_stop(local);
|
2014-10-28 11:21:17 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
static int mac802154_set_header_security(struct ieee802154_sub_if_data *sdata,
|
2014-05-16 09:46:40 -06:00
|
|
|
struct ieee802154_hdr *hdr,
|
|
|
|
const struct ieee802154_mac_cb *cb)
|
|
|
|
{
|
|
|
|
struct ieee802154_llsec_params params;
|
|
|
|
u8 level;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
mac802154_llsec_get_params(&sdata->sec, ¶ms);
|
2014-05-16 09:46:40 -06:00
|
|
|
|
|
|
|
if (!params.enabled && cb->secen_override && cb->secen)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!params.enabled ||
|
|
|
|
(cb->secen_override && !cb->secen) ||
|
|
|
|
!params.out_level)
|
|
|
|
return 0;
|
|
|
|
if (cb->seclevel_override && !cb->seclevel)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
level = cb->seclevel_override ? cb->seclevel : params.out_level;
|
|
|
|
|
|
|
|
hdr->fc.security_enabled = 1;
|
|
|
|
hdr->sec.level = level;
|
|
|
|
hdr->sec.key_id_mode = params.out_key.mode;
|
|
|
|
if (params.out_key.mode == IEEE802154_SCF_KEY_SHORT_INDEX)
|
|
|
|
hdr->sec.short_src = params.out_key.short_source;
|
|
|
|
else if (params.out_key.mode == IEEE802154_SCF_KEY_HW_INDEX)
|
|
|
|
hdr->sec.extended_src = params.out_key.extended_source;
|
|
|
|
hdr->sec.key_id = params.out_key.id;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:24:48 -06:00
|
|
|
static int mac802154_header_create(struct sk_buff *skb,
|
|
|
|
struct net_device *dev,
|
|
|
|
unsigned short type,
|
2014-03-14 14:24:01 -06:00
|
|
|
const void *daddr,
|
|
|
|
const void *saddr,
|
2012-06-25 17:24:48 -06:00
|
|
|
unsigned len)
|
|
|
|
{
|
2014-03-14 14:24:01 -06:00
|
|
|
struct ieee802154_hdr hdr;
|
2014-10-25 09:16:40 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2014-05-14 09:43:08 -06:00
|
|
|
struct ieee802154_mac_cb *cb = mac_cb(skb);
|
2014-03-14 14:24:01 -06:00
|
|
|
int hlen;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
if (!daddr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
memset(&hdr.fc, 0, sizeof(hdr.fc));
|
2014-05-14 09:43:08 -06:00
|
|
|
hdr.fc.type = cb->type;
|
|
|
|
hdr.fc.security_enabled = cb->secen;
|
|
|
|
hdr.fc.ack_request = cb->ackreq;
|
|
|
|
hdr.seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
if (mac802154_set_header_security(sdata, &hdr, cb) < 0)
|
2014-05-16 09:46:40 -06:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-06-25 17:24:48 -06:00
|
|
|
if (!saddr) {
|
2014-10-25 09:16:36 -06:00
|
|
|
spin_lock_bh(&sdata->mib_lock);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
if (sdata->short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST) ||
|
|
|
|
sdata->short_addr == cpu_to_le16(IEEE802154_ADDR_UNDEF) ||
|
|
|
|
sdata->pan_id == cpu_to_le16(IEEE802154_PANID_BROADCAST)) {
|
2014-03-14 14:24:01 -06:00
|
|
|
hdr.source.mode = IEEE802154_ADDR_LONG;
|
2014-10-25 09:16:36 -06:00
|
|
|
hdr.source.extended_addr = sdata->extended_addr;
|
2012-06-25 17:24:48 -06:00
|
|
|
} else {
|
2014-03-14 14:24:01 -06:00
|
|
|
hdr.source.mode = IEEE802154_ADDR_SHORT;
|
2014-10-25 09:16:36 -06:00
|
|
|
hdr.source.short_addr = sdata->short_addr;
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
hdr.source.pan_id = sdata->pan_id;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
spin_unlock_bh(&sdata->mib_lock);
|
2014-03-14 14:24:01 -06:00
|
|
|
} else {
|
|
|
|
hdr.source = *(const struct ieee802154_addr *)saddr;
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
hdr.dest = *(const struct ieee802154_addr *)daddr;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
hlen = ieee802154_hdr_push(skb, &hdr);
|
|
|
|
if (hlen < 0)
|
|
|
|
return -EINVAL;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2013-10-30 02:18:22 -06:00
|
|
|
skb_reset_mac_header(skb);
|
2014-03-14 14:24:01 -06:00
|
|
|
skb->mac_len = hlen;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-05-14 09:43:07 -06:00
|
|
|
if (len > ieee802154_max_payload(&hdr))
|
2014-03-14 14:24:04 -06:00
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
return hlen;
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
|
|
|
|
{
|
2014-03-14 14:24:01 -06:00
|
|
|
struct ieee802154_hdr hdr;
|
|
|
|
struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
|
|
|
|
pr_debug("malformed packet\n");
|
|
|
|
return 0;
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
2014-03-14 14:24:01 -06:00
|
|
|
*addr = hdr.source;
|
|
|
|
return sizeof(*addr);
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct header_ops mac802154_header_ops = {
|
|
|
|
.create = mac802154_header_create,
|
|
|
|
.parse = mac802154_header_parse,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct net_device_ops mac802154_wpan_ops = {
|
2014-03-31 13:37:46 -06:00
|
|
|
.ndo_open = mac802154_wpan_open,
|
2012-06-25 17:24:48 -06:00
|
|
|
.ndo_stop = mac802154_slave_close,
|
2014-10-26 02:37:13 -06:00
|
|
|
.ndo_start_xmit = ieee802154_subif_start_xmit,
|
2012-06-25 17:24:48 -06:00
|
|
|
.ndo_do_ioctl = mac802154_wpan_ioctl,
|
|
|
|
.ndo_set_mac_address = mac802154_wpan_mac_addr,
|
|
|
|
};
|
|
|
|
|
2014-10-28 11:21:16 -06:00
|
|
|
static const struct net_device_ops mac802154_monitor_ops = {
|
2014-10-29 14:34:44 -06:00
|
|
|
.ndo_open = mac802154_wpan_open,
|
2014-10-28 11:21:16 -06:00
|
|
|
.ndo_stop = mac802154_slave_close,
|
|
|
|
.ndo_start_xmit = ieee802154_monitor_start_xmit,
|
|
|
|
};
|
|
|
|
|
2014-05-16 09:46:40 -06:00
|
|
|
static void mac802154_wpan_free(struct net_device *dev)
|
|
|
|
{
|
2014-10-25 09:16:40 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2014-05-16 09:46:40 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
mac802154_llsec_destroy(&sdata->sec);
|
2014-05-16 09:46:40 -06:00
|
|
|
|
|
|
|
free_netdev(dev);
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:24:48 -06:00
|
|
|
void mac802154_wpan_setup(struct net_device *dev)
|
|
|
|
{
|
2014-10-25 09:16:36 -06:00
|
|
|
struct ieee802154_sub_if_data *sdata;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
|
|
|
dev->addr_len = IEEE802154_ADDR_LEN;
|
|
|
|
memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
|
|
|
|
|
|
|
|
dev->hard_header_len = MAC802154_FRAME_HARD_HEADER_LEN;
|
|
|
|
dev->header_ops = &mac802154_header_ops;
|
2014-05-16 09:46:40 -06:00
|
|
|
dev->needed_tailroom = 2 + 16; /* FCS + MIC */
|
2012-06-25 17:24:48 -06:00
|
|
|
dev->mtu = IEEE802154_MTU;
|
2013-04-02 22:00:57 -06:00
|
|
|
dev->tx_queue_len = 300;
|
2012-06-25 17:24:48 -06:00
|
|
|
dev->type = ARPHRD_IEEE802154;
|
|
|
|
dev->flags = IFF_NOARP | IFF_BROADCAST;
|
|
|
|
|
2014-05-16 09:46:40 -06:00
|
|
|
dev->destructor = mac802154_wpan_free;
|
2012-06-25 17:24:48 -06:00
|
|
|
dev->netdev_ops = &mac802154_wpan_ops;
|
|
|
|
dev->ml_priv = &mac802154_mlme_wpan;
|
|
|
|
|
2014-10-25 09:16:40 -06:00
|
|
|
sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
2014-10-25 09:16:36 -06:00
|
|
|
sdata->type = IEEE802154_DEV_WPAN;
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
spin_lock_init(&sdata->mib_lock);
|
|
|
|
mutex_init(&sdata->sec_mtx);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
get_random_bytes(&sdata->bsn, 1);
|
|
|
|
get_random_bytes(&sdata->dsn, 1);
|
2012-06-25 17:24:48 -06:00
|
|
|
|
2014-03-31 13:37:46 -06:00
|
|
|
/* defaults per 802.15.4-2011 */
|
2014-10-25 09:16:36 -06:00
|
|
|
sdata->mac_params.min_be = 3;
|
|
|
|
sdata->mac_params.max_be = 5;
|
|
|
|
sdata->mac_params.csma_retries = 4;
|
|
|
|
/* for compatibility, actual default is 3 */
|
|
|
|
sdata->mac_params.frame_retries = -1;
|
2014-03-31 13:37:46 -06:00
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
sdata->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
|
|
|
|
sdata->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
|
2014-05-16 09:46:40 -06:00
|
|
|
|
2014-10-29 14:34:44 -06:00
|
|
|
sdata->promisuous_mode = false;
|
|
|
|
|
2014-10-25 09:16:36 -06:00
|
|
|
mac802154_llsec_init(&sdata->sec);
|
2012-06-25 17:24:48 -06:00
|
|
|
}
|
2014-10-28 11:21:16 -06:00
|
|
|
|
|
|
|
void mac802154_monitor_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct ieee802154_sub_if_data *sdata;
|
|
|
|
|
|
|
|
dev->needed_tailroom = 2; /* room for FCS */
|
|
|
|
dev->mtu = IEEE802154_MTU;
|
|
|
|
dev->tx_queue_len = 10;
|
|
|
|
dev->type = ARPHRD_IEEE802154_MONITOR;
|
|
|
|
dev->flags = IFF_NOARP | IFF_BROADCAST;
|
|
|
|
|
|
|
|
dev->destructor = free_netdev;
|
|
|
|
dev->netdev_ops = &mac802154_monitor_ops;
|
|
|
|
dev->ml_priv = &mac802154_mlme_reduced;
|
|
|
|
|
|
|
|
sdata = IEEE802154_DEV_TO_SUB_IF(dev);
|
|
|
|
sdata->type = IEEE802154_DEV_MONITOR;
|
2014-10-29 14:34:44 -06:00
|
|
|
|
|
|
|
sdata->promisuous_mode = true;
|
2014-10-28 11:21:16 -06:00
|
|
|
}
|
2014-11-05 12:51:14 -07:00
|
|
|
|
|
|
|
void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
|
|
|
|
{
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
mutex_lock(&sdata->local->iflist_mtx);
|
|
|
|
list_del_rcu(&sdata->list);
|
|
|
|
mutex_unlock(&sdata->local->iflist_mtx);
|
|
|
|
|
|
|
|
synchronize_rcu();
|
|
|
|
unregister_netdevice(sdata->dev);
|
|
|
|
}
|