Skip to content

Commit

Permalink
net: add IEEE 802.15.4 socket family implementation
Browse files Browse the repository at this point in the history
Add support for communication over IEEE 802.15.4 networks. This implementation
is neither certified nor complete, but aims to that goal. This commit contains
only the socket interface for communication over IEEE 802.15.4 networks.
One can either send RAW datagrams or use SOCK_DGRAM to encapsulate data
inside normal IEEE 802.15.4 packets.

Configuration interface, drivers and software MAC 802.15.4 implementation will
follow.

Initial implementation was done by Maxim Gorbachyov, Maxim Osipov and Pavel
Smolensky as a research project at Siemens AG. Later the stack was heavily
reworked to better suit the linux networking model, and is now maitained
as an open project partially sponsored by Siemens.

Signed-off-by: Dmitry Eremin-Solenikov <[email protected]>
Signed-off-by: Sergey Lapin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
slapin authored and davem330 committed Jun 9, 2009
1 parent fcb94e4 commit 9ec7671
Show file tree
Hide file tree
Showing 11 changed files with 1,409 additions and 0 deletions.
60 changes: 60 additions & 0 deletions include/net/ieee802154/af_ieee802154.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* IEEE 802.15.4 inteface for userspace
*
* Copyright 2007, 2008 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Written by:
* Sergey Lapin <[email protected]>
* Dmitry Eremin-Solenikov <[email protected]>
*/

#ifndef _AF_IEEE802154_H
#define _AF_IEEE802154_H

#include <linux/socket.h> /* for sa_family_t */

enum {
IEEE802154_ADDR_NONE = 0x0,
/* RESERVED = 0x01, */
IEEE802154_ADDR_SHORT = 0x2, /* 16-bit address + PANid */
IEEE802154_ADDR_LONG = 0x3, /* 64-bit address + PANid */
};

/* address length, octets */
#define IEEE802154_ADDR_LEN 8

struct ieee802154_addr {
int addr_type;
u16 pan_id;
union {
u8 hwaddr[IEEE802154_ADDR_LEN];
u16 short_addr;
};
};

#define IEEE802154_PANID_BROADCAST 0xffff
#define IEEE802154_ADDR_BROADCAST 0xffff
#define IEEE802154_ADDR_UNDEF 0xfffe

struct sockaddr_ieee802154 {
sa_family_t family; /* AF_IEEE802154 */
struct ieee802154_addr addr;
};

/* master device */
#define IEEE802154_SIOC_ADD_SLAVE (SIOCDEVPRIVATE + 0)

#endif
160 changes: 160 additions & 0 deletions include/net/ieee802154/mac_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* IEEE802.15.4-2003 specification
*
* Copyright (C) 2007, 2008 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Written by:
* Pavel Smolenskiy <[email protected]>
* Maxim Gorbachyov <[email protected]>
* Maxim Osipov <[email protected]>
* Dmitry Eremin-Solenikov <[email protected]>
*/

#ifndef IEEE802154_MAC_DEF_H
#define IEEE802154_MAC_DEF_H

#define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */
#define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */
#define IEEE802154_FC_TYPE_ACK 0x2 /* Frame is acknowledgment */
#define IEEE802154_FC_TYPE_MAC_CMD 0x3 /* Frame is MAC command */

#define IEEE802154_FC_TYPE_SHIFT 0
#define IEEE802154_FC_TYPE_MASK ((1 << 3) - 1)
#define IEEE802154_FC_TYPE(x) ((x & IEEE802154_FC_TYPE_MASK) >> IEEE802154_FC_TYPE_SHIFT)
#define IEEE802154_FC_SET_TYPE(v, x) do { \
v = (((v) & ~IEEE802154_FC_TYPE_MASK) | \
(((x) << IEEE802154_FC_TYPE_SHIFT) & IEEE802154_FC_TYPE_MASK)); \
} while (0)

#define IEEE802154_FC_SECEN (1 << 3)
#define IEEE802154_FC_FRPEND (1 << 4)
#define IEEE802154_FC_ACK_REQ (1 << 5)
#define IEEE802154_FC_INTRA_PAN (1 << 6)

#define IEEE802154_FC_SAMODE_SHIFT 14
#define IEEE802154_FC_SAMODE_MASK (3 << IEEE802154_FC_SAMODE_SHIFT)
#define IEEE802154_FC_DAMODE_SHIFT 10
#define IEEE802154_FC_DAMODE_MASK (3 << IEEE802154_FC_DAMODE_SHIFT)

#define IEEE802154_FC_SAMODE(x) \
(((x) & IEEE802154_FC_SAMODE_MASK) >> IEEE802154_FC_SAMODE_SHIFT)

#define IEEE802154_FC_DAMODE(x) \
(((x) & IEEE802154_FC_DAMODE_MASK) >> IEEE802154_FC_DAMODE_SHIFT)


/* MAC's Command Frames Identifiers */
#define IEEE802154_CMD_ASSOCIATION_REQ 0x01
#define IEEE802154_CMD_ASSOCIATION_RESP 0x02
#define IEEE802154_CMD_DISASSOCIATION_NOTIFY 0x03
#define IEEE802154_CMD_DATA_REQ 0x04
#define IEEE802154_CMD_PANID_CONFLICT_NOTIFY 0x05
#define IEEE802154_CMD_ORPHAN_NOTIFY 0x06
#define IEEE802154_CMD_BEACON_REQ 0x07
#define IEEE802154_CMD_COORD_REALIGN_NOTIFY 0x08
#define IEEE802154_CMD_GTS_REQ 0x09

/*
* The return values of MAC operations
*/
enum {
/*
* The requested operation was completed successfully.
* For a transmission request, this value indicates
* a successful transmission.
*/
IEEE802154_SUCCESS = 0x0,

/* The beacon was lost following a synchronization request. */
IEEE802154_BEACON_LOSS = 0xe0,
/*
* A transmission could not take place due to activity on the
* channel, i.e., the CSMA-CA mechanism has failed.
*/
IEEE802154_CHNL_ACCESS_FAIL = 0xe1,
/* The GTS request has been denied by the PAN coordinator. */
IEEE802154_DENINED = 0xe2,
/* The attempt to disable the transceiver has failed. */
IEEE802154_DISABLE_TRX_FAIL = 0xe3,
/*
* The received frame induces a failed security check according to
* the security suite.
*/
IEEE802154_FAILED_SECURITY_CHECK = 0xe4,
/*
* The frame resulting from secure processing has a length that is
* greater than aMACMaxFrameSize.
*/
IEEE802154_FRAME_TOO_LONG = 0xe5,
/*
* The requested GTS transmission failed because the specified GTS
* either did not have a transmit GTS direction or was not defined.
*/
IEEE802154_INVALID_GTS = 0xe6,
/*
* A request to purge an MSDU from the transaction queue was made using
* an MSDU handle that was not found in the transaction table.
*/
IEEE802154_INVALID_HANDLE = 0xe7,
/* A parameter in the primitive is out of the valid range.*/
IEEE802154_INVALID_PARAMETER = 0xe8,
/* No acknowledgment was received after aMaxFrameRetries. */
IEEE802154_NO_ACK = 0xe9,
/* A scan operation failed to find any network beacons.*/
IEEE802154_NO_BEACON = 0xea,
/* No response data were available following a request. */
IEEE802154_NO_DATA = 0xeb,
/* The operation failed because a short address was not allocated. */
IEEE802154_NO_SHORT_ADDRESS = 0xec,
/*
* A receiver enable request was unsuccessful because it could not be
* completed within the CAP.
*/
IEEE802154_OUT_OF_CAP = 0xed,
/*
* A PAN identifier conflict has been detected and communicated to the
* PAN coordinator.
*/
IEEE802154_PANID_CONFLICT = 0xee,
/* A coordinator realignment command has been received. */
IEEE802154_REALIGMENT = 0xef,
/* The transaction has expired and its information discarded. */
IEEE802154_TRANSACTION_EXPIRED = 0xf0,
/* There is no capacity to store the transaction. */
IEEE802154_TRANSACTION_OVERFLOW = 0xf1,
/*
* The transceiver was in the transmitter enabled state when the
* receiver was requested to be enabled.
*/
IEEE802154_TX_ACTIVE = 0xf2,
/* The appropriate key is not available in the ACL. */
IEEE802154_UNAVAILABLE_KEY = 0xf3,
/*
* A SET/GET request was issued with the identifier of a PIB attribute
* that is not supported.
*/
IEEE802154_UNSUPPORTED_ATTR = 0xf4,
/*
* A request to perform a scan operation failed because the MLME was
* in the process of performing a previously initiated scan operation.
*/
IEEE802154_SCAN_IN_PROGRESS = 0xfc,
};


#endif


115 changes: 115 additions & 0 deletions include/net/ieee802154/netdevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* An interface between IEEE802.15.4 device and rest of the kernel.
*
* Copyright (C) 2007, 2008, 2009 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Written by:
* Pavel Smolenskiy <[email protected]>
* Maxim Gorbachyov <[email protected]>
* Maxim Osipov <[email protected]>
* Dmitry Eremin-Solenikov <[email protected]>
*/

#ifndef IEEE802154_NETDEVICE_H
#define IEEE802154_NETDEVICE_H

/*
* A control block of skb passed between the ARPHRD_IEEE802154 device
* and other stack parts.
*/
struct ieee802154_mac_cb {
u8 lqi;
struct ieee802154_addr sa;
struct ieee802154_addr da;
u8 flags;
u8 seq;
};

static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
{
return (struct ieee802154_mac_cb *)skb->cb;
}

#define MAC_CB_FLAG_TYPEMASK ((1 << 3) - 1)

#define MAC_CB_FLAG_ACKREQ (1 << 3)
#define MAC_CB_FLAG_SECEN (1 << 4)
#define MAC_CB_FLAG_INTRAPAN (1 << 5)

static inline int mac_cb_is_ackreq(struct sk_buff *skb)
{
return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ;
}

static inline int mac_cb_is_secen(struct sk_buff *skb)
{
return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN;
}

static inline int mac_cb_is_intrapan(struct sk_buff *skb)
{
return mac_cb(skb)->flags & MAC_CB_FLAG_INTRAPAN;
}

static inline int mac_cb_type(struct sk_buff *skb)
{
return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK;
}

#define IEEE802154_MAC_SCAN_ED 0
#define IEEE802154_MAC_SCAN_ACTIVE 1
#define IEEE802154_MAC_SCAN_PASSIVE 2
#define IEEE802154_MAC_SCAN_ORPHAN 3

/*
* This should be located at net_device->ml_priv
*/
struct ieee802154_mlme_ops {
int (*assoc_req)(struct net_device *dev,
struct ieee802154_addr *addr,
u8 channel, u8 cap);
int (*assoc_resp)(struct net_device *dev,
struct ieee802154_addr *addr,
u16 short_addr, u8 status);
int (*disassoc_req)(struct net_device *dev,
struct ieee802154_addr *addr,
u8 reason);
int (*start_req)(struct net_device *dev,
struct ieee802154_addr *addr,
u8 channel, u8 bcn_ord, u8 sf_ord,
u8 pan_coord, u8 blx, u8 coord_realign);
int (*scan_req)(struct net_device *dev,
u8 type, u32 channels, u8 duration);

/*
* FIXME: these should become the part of PIB/MIB interface.
* However we still don't have IB interface of any kind
*/
u16 (*get_pan_id)(struct net_device *dev);
u16 (*get_short_addr)(struct net_device *dev);
u8 (*get_dsn)(struct net_device *dev);
u8 (*get_bsn)(struct net_device *dev);
};

static inline struct ieee802154_mlme_ops *ieee802154_mlme_ops(
struct net_device *dev)
{
return dev->ml_priv;
}

#endif


1 change: 1 addition & 0 deletions net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ source "net/lapb/Kconfig"
source "net/econet/Kconfig"
source "net/wanrouter/Kconfig"
source "net/phonet/Kconfig"
source "net/ieee802154/Kconfig"
source "net/sched/Kconfig"
source "net/dcb/Kconfig"

Expand Down
1 change: 1 addition & 0 deletions net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ obj-$(CONFIG_NET_9P) += 9p/
ifneq ($(CONFIG_DCB),)
obj-y += dcb/
endif
obj-y += ieee802154/

ifeq ($(CONFIG_NET),y)
obj-$(CONFIG_SYSCTL) += sysctl_net.o
Expand Down
12 changes: 12 additions & 0 deletions net/ieee802154/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config IEEE802154
tristate "IEEE Std 802.15.4 Low-Rate Wireless Personal Area Networks support (EXPERIMENTAL)"
depends on EXPERIMENTAL
---help---
IEEE Std 802.15.4 defines a low data rate, low power and low
complexity short range wireless personal area networks. It was
designed to organise networks of sensors, switches, etc automation
devices. Maximum allowed data rate is 250 kb/s and typical personal
operating space around 10m.

Say Y here to compile LR-WPAN support into the kernel or say M to
compile it as modules.
4 changes: 4 additions & 0 deletions net/ieee802154/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj-$(CONFIG_IEEE802154) += af_802154.o
af_802154-y := af_ieee802154.o raw.o dgram.o

ccflags-y += -Wall -DDEBUG
Loading

0 comments on commit 9ec7671

Please sign in to comment.