blob: c17acbd0dadcd0f4f3ef57fe9ad74ba5d70b5b27 [file] [log] [blame]
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +00001/*
2 * IEEE802.15.4-2003 specification
3 *
4 * Copyright (C) 2007-2012 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000015 */
16#ifndef NET_MAC802154_H
17#define NET_MAC802154_H
18
19#include <net/af_ieee802154.h>
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010020#include <linux/skbuff.h>
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000021
alex.bluesman.smirnov@gmail.com32bad7e2012-06-25 23:24:48 +000022/* General MAC frame format:
23 * 2 bytes: Frame Control
24 * 1 byte: Sequence Number
25 * 20 bytes: Addressing fields
26 * 14 bytes: Auxiliary Security Header
27 */
28#define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
29
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000030/* The following flags are used to indicate changed address settings from
31 * the stack to the hardware.
32 */
33
34/* indicates that the Short Address changed */
Alexander Aring57205c12014-10-25 05:25:09 +020035#define IEEE802154_AFILT_SADDR_CHANGED 0x00000001
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000036/* indicates that the IEEE Address changed */
Alexander Aring57205c12014-10-25 05:25:09 +020037#define IEEE802154_AFILT_IEEEADDR_CHANGED 0x00000002
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000038/* indicates that the PAN ID changed */
Alexander Aring57205c12014-10-25 05:25:09 +020039#define IEEE802154_AFILT_PANID_CHANGED 0x00000004
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000040/* indicates that PAN Coordinator status changed */
Alexander Aring57205c12014-10-25 05:25:09 +020041#define IEEE802154_AFILT_PANC_CHANGED 0x00000008
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000042
43struct ieee802154_hw_addr_filt {
44 __le16 pan_id; /* Each independent PAN selects a unique
45 * identifier. This PAN id allows communication
46 * between devices within a network using short
47 * addresses and enables transmissions between
48 * devices across independent networks.
49 */
50 __le16 short_addr;
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010051 __le64 ieee_addr;
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000052 u8 pan_coord;
53};
54
Alexander Aring5a504392014-10-25 17:16:34 +020055struct ieee802154_hw {
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000056 /* filled by the driver */
57 int extra_tx_headroom;
58 u32 flags;
59 struct device *parent;
60
61 /* filled by mac802154 core */
62 struct ieee802154_hw_addr_filt hw_filt;
63 void *priv;
64 struct wpan_phy *phy;
65};
66
67/* Checksum is in hardware and is omitted from a packet
68 *
69 * These following flags are used to indicate hardware capabilities to
70 * the stack. Generally, flags here should have their meaning
71 * done in a way that the simplest hardware doesn't need setting
72 * any particular flags. There are some exceptions to this rule,
73 * however, so you are advised to review these flags carefully.
74 */
75
Alexander Aring90386a72014-10-29 21:34:34 +010076/* Indicates that xmitter will add FCS on it's own. */
77#define IEEE802154_HW_TX_OMIT_CKSUM 0x00000001
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +000078/* Indicates that receiver will autorespond with ACK frames. */
Alexander Aring90a61612014-10-29 21:34:29 +010079#define IEEE802154_HW_AACK 0x00000002
Alexander Aring640985e2014-07-03 00:20:43 +020080/* Indicates that transceiver will support transmit power setting. */
Alexander Aring90a61612014-10-29 21:34:29 +010081#define IEEE802154_HW_TXPOWER 0x00000004
Alexander Aring640985e2014-07-03 00:20:43 +020082/* Indicates that transceiver will support listen before transmit. */
Alexander Aring90a61612014-10-29 21:34:29 +010083#define IEEE802154_HW_LBT 0x00000008
Alexander Aring640985e2014-07-03 00:20:43 +020084/* Indicates that transceiver will support cca mode setting. */
Alexander Aring90a61612014-10-29 21:34:29 +010085#define IEEE802154_HW_CCA_MODE 0x00000010
Alexander Aring640985e2014-07-03 00:20:43 +020086/* Indicates that transceiver will support cca ed level setting. */
Alexander Aring90a61612014-10-29 21:34:29 +010087#define IEEE802154_HW_CCA_ED_LEVEL 0x00000020
Alexander Aring640985e2014-07-03 00:20:43 +020088/* Indicates that transceiver will support csma (max_be, min_be, csma retries)
89 * settings. */
Alexander Aring90a61612014-10-29 21:34:29 +010090#define IEEE802154_HW_CSMA_PARAMS 0x00000040
Alexander Aring640985e2014-07-03 00:20:43 +020091/* Indicates that transceiver will support ARET frame retries setting. */
Alexander Aring90a61612014-10-29 21:34:29 +010092#define IEEE802154_HW_FRAME_RETRIES 0x00000080
Alexander Aringc8fc84e2014-10-29 21:34:31 +010093/* Indicates that transceiver will support hardware address filter setting. */
94#define IEEE802154_HW_AFILT 0x00000100
Alexander Aring94b79222014-10-29 21:34:32 +010095/* Indicates that transceiver will support promiscuous mode setting. */
96#define IEEE802154_HW_PROMISCUOUS 0x00000200
Alexander Aring90386a72014-10-29 21:34:34 +010097/* Indicates that receiver omits FCS. */
98#define IEEE802154_HW_RX_OMIT_CKSUM 0x00000400
Alexander Aringec718f32014-10-29 21:34:37 +010099/* Indicates that receiver will not filter frames with bad checksum. */
100#define IEEE802154_HW_RX_DROP_BAD_CKSUM 0x00000800
Alexander Aring90386a72014-10-29 21:34:34 +0100101
102/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
103#define IEEE802154_HW_OMIT_CKSUM (IEEE802154_HW_TX_OMIT_CKSUM | \
104 IEEE802154_HW_RX_OMIT_CKSUM)
Alexander Aring640985e2014-07-03 00:20:43 +0200105
106/* This groups the most common CSMA support fields into one. */
107#define IEEE802154_HW_CSMA (IEEE802154_HW_CCA_MODE | \
108 IEEE802154_HW_CCA_ED_LEVEL | \
Alexander Aringab79be32014-10-29 21:34:30 +0100109 IEEE802154_HW_CSMA_PARAMS)
110
111/* This groups the most common ARET support fields into one. */
112#define IEEE802154_HW_ARET (IEEE802154_HW_CSMA | \
Alexander Aring640985e2014-07-03 00:20:43 +0200113 IEEE802154_HW_FRAME_RETRIES)
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000114
115/* struct ieee802154_ops - callbacks from mac802154 to the driver
116 *
117 * This structure contains various callbacks that the driver may
118 * handle or, in some cases, must handle, for example to transmit
119 * a frame.
120 *
121 * start: Handler that 802.15.4 module calls for device initialization.
122 * This function is called before the first interface is attached.
123 *
124 * stop: Handler that 802.15.4 module calls for device cleanup.
125 * This function is called after the last interface is removed.
126 *
Alexander Aringed0a5dc2014-10-26 09:37:08 +0100127 * xmit_sync:
128 * Handler that 802.15.4 module calls for each transmitted frame.
129 * skb cntains the buffer starting from the IEEE 802.15.4 header.
130 * The low-level driver should send the frame based on available
131 * configuration. This is called by a workqueue and useful for
132 * synchronous 802.15.4 drivers.
133 * This function should return zero or negative errno.
134 *
Alexander Aring1e7283a2014-10-26 09:37:14 +0100135 * WARNING:
136 * This will be deprecated soon. We don't accept synced xmit callbacks
137 * drivers anymore.
138 *
Alexander Aringed0a5dc2014-10-26 09:37:08 +0100139 * xmit_async:
140 * Handler that 802.15.4 module calls for each transmitted frame.
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000141 * skb cntains the buffer starting from the IEEE 802.15.4 header.
142 * The low-level driver should send the frame based on available
143 * configuration.
Alexander Aringdc67c6b2014-10-26 09:37:04 +0100144 * This function should return zero or negative errno.
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000145 *
146 * ed: Handler that 802.15.4 module calls for Energy Detection.
147 * This function should place the value for detected energy
148 * (usually device-dependant) in the level pointer and return
149 * either zero or negative errno. Called with pib_lock held.
150 *
151 * set_channel:
152 * Set radio for listening on specific channel.
153 * Set the device for listening on specified channel.
154 * Returns either zero, or negative errno. Called with pib_lock held.
155 *
156 * set_hw_addr_filt:
157 * Set radio for listening on specific address.
158 * Set the device for listening on specified address.
159 * Returns either zero, or negative errno.
Phoebe Buckheister9b2777d2014-02-17 11:34:08 +0100160 *
161 * set_txpower:
162 * Set radio transmit power in dB. Called with pib_lock held.
163 * Returns either zero, or negative errno.
Phoebe Buckheister84dda3c2014-02-17 11:34:10 +0100164 *
165 * set_lbt
166 * Enables or disables listen before talk on the device. Called with
167 * pib_lock held.
168 * Returns either zero, or negative errno.
Phoebe Buckheisterba08fea2014-02-17 11:34:11 +0100169 *
170 * set_cca_mode
171 * Sets the CCA mode used by the device. Called with pib_lock held.
172 * Returns either zero, or negative errno.
Phoebe Buckheister6ca00192014-02-17 11:34:12 +0100173 *
174 * set_cca_ed_level
175 * Sets the CCA energy detection threshold in dBm. Called with pib_lock
176 * held.
177 * Returns either zero, or negative errno.
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100178 *
179 * set_csma_params
180 * Sets the CSMA parameter set for the PHY. Called with pib_lock held.
181 * Returns either zero, or negative errno.
182 *
183 * set_frame_retries
184 * Sets the retransmission attempt limit. Called with pib_lock held.
185 * Returns either zero, or negative errno.
Alexander Aring94b79222014-10-29 21:34:32 +0100186 *
187 * set_promiscuous_mode
188 * Enables or disable promiscuous mode.
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000189 */
190struct ieee802154_ops {
191 struct module *owner;
Alexander Aring5a504392014-10-25 17:16:34 +0200192 int (*start)(struct ieee802154_hw *hw);
193 void (*stop)(struct ieee802154_hw *hw);
Alexander Aringed0a5dc2014-10-26 09:37:08 +0100194 int (*xmit_sync)(struct ieee802154_hw *hw,
195 struct sk_buff *skb);
196 int (*xmit_async)(struct ieee802154_hw *hw,
197 struct sk_buff *skb);
Alexander Aring5a504392014-10-25 17:16:34 +0200198 int (*ed)(struct ieee802154_hw *hw, u8 *level);
Alexander Aringe37d2ec2014-10-28 18:21:19 +0100199 int (*set_channel)(struct ieee802154_hw *hw, u8 page,
200 u8 channel);
Alexander Aring5a504392014-10-25 17:16:34 +0200201 int (*set_hw_addr_filt)(struct ieee802154_hw *hw,
202 struct ieee802154_hw_addr_filt *filt,
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000203 unsigned long changed);
Alexander Aring5a504392014-10-25 17:16:34 +0200204 int (*set_txpower)(struct ieee802154_hw *hw, int db);
205 int (*set_lbt)(struct ieee802154_hw *hw, bool on);
206 int (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode);
207 int (*set_cca_ed_level)(struct ieee802154_hw *hw,
Phoebe Buckheister6ca00192014-02-17 11:34:12 +0100208 s32 level);
Alexander Aring5a504392014-10-25 17:16:34 +0200209 int (*set_csma_params)(struct ieee802154_hw *hw,
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100210 u8 min_be, u8 max_be, u8 retries);
Alexander Aring5a504392014-10-25 17:16:34 +0200211 int (*set_frame_retries)(struct ieee802154_hw *hw,
Phoebe Buckheister4244db12014-02-17 11:34:14 +0100212 s8 retries);
Alexander Aring94b79222014-10-29 21:34:32 +0100213 int (*set_promiscuous_mode)(struct ieee802154_hw *hw,
214 const bool on);
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000215};
216
Alexander Aringab24f502014-11-02 04:18:40 +0100217/**
218 * ieee802154_netdev_to_extended_addr - convert __be64 u8 pointer to __le64
219 * @dev_addr: big endian address pointer like netdevice dev_addr attribute
220 */
221static inline __le64 ieee802154_netdev_to_extended_addr(const u8 *dev_addr)
222{
223 return (__le64)swab64(*((__be64 *)dev_addr));
224}
225
Alexander Aring5a504392014-10-25 17:16:34 +0200226/* Basic interface to register ieee802154 hwice */
227struct ieee802154_hw *
Alexander Aring16301862014-10-28 18:21:18 +0100228ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
Alexander Aring5a504392014-10-25 17:16:34 +0200229void ieee802154_free_hw(struct ieee802154_hw *hw);
230int ieee802154_register_hw(struct ieee802154_hw *hw);
231void ieee802154_unregister_hw(struct ieee802154_hw *hw);
alex.bluesman.smirnov@gmail.com1010f542012-05-15 20:50:20 +0000232
Alexander Aringc5c47e62014-10-27 17:13:30 +0100233void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
Alexander Aring5a504392014-10-25 17:16:34 +0200234void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +0000235 u8 lqi);
236
Alexander Aringc2085102014-10-26 09:37:05 +0100237void ieee802154_wake_queue(struct ieee802154_hw *hw);
238void ieee802154_stop_queue(struct ieee802154_hw *hw);
239void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb);
240
alex.bluesman.smirnov@gmail.com0afd7ad2012-05-15 20:50:19 +0000241#endif /* NET_MAC802154_H */