Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * An interface between IEEE802.15.4 device and rest of the kernel. |
| 3 | * |
alex.bluesman.smirnov@gmail.com | 74a02fc | 2012-05-15 20:50:23 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007-2012 Siemens AG |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 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 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Written by: |
| 20 | * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> |
| 21 | * Maxim Gorbachyov <maxim.gorbachev@siemens.com> |
| 22 | * Maxim Osipov <maxim.osipov@siemens.com> |
| 23 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
alex.bluesman.smirnov@gmail.com | 74a02fc | 2012-05-15 20:50:23 +0000 | [diff] [blame] | 24 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef IEEE802154_NETDEVICE_H |
| 28 | #define IEEE802154_NETDEVICE_H |
| 29 | |
alex.bluesman.smirnov@gmail.com | 1cd829c | 2012-05-15 20:50:21 +0000 | [diff] [blame] | 30 | #include <net/af_ieee802154.h> |
| 31 | |
Phoebe Buckheister | 46ef0eb | 2014-03-14 21:23:58 +0100 | [diff] [blame] | 32 | struct ieee802154_addr { |
| 33 | u8 mode; |
| 34 | __le16 pan_id; |
| 35 | union { |
| 36 | __le16 short_addr; |
| 37 | __le64 extended_addr; |
| 38 | }; |
| 39 | }; |
| 40 | |
| 41 | static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1, |
| 42 | const struct ieee802154_addr *a2) |
| 43 | { |
| 44 | if (a1->pan_id != a2->pan_id || a1->mode != a2->mode) |
| 45 | return false; |
| 46 | |
| 47 | if ((a1->mode == IEEE802154_ADDR_LONG && |
| 48 | a1->extended_addr != a2->extended_addr) || |
| 49 | (a1->mode == IEEE802154_ADDR_SHORT && |
| 50 | a1->short_addr != a2->short_addr)) |
| 51 | return false; |
| 52 | |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | static inline __le64 ieee802154_devaddr_from_raw(const void *raw) |
| 57 | { |
| 58 | u64 temp; |
| 59 | |
| 60 | memcpy(&temp, raw, IEEE802154_ADDR_LEN); |
| 61 | return (__force __le64)swab64(temp); |
| 62 | } |
| 63 | |
| 64 | static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr) |
| 65 | { |
| 66 | u64 temp = swab64((__force u64)addr); |
| 67 | |
| 68 | memcpy(raw, &temp, IEEE802154_ADDR_LEN); |
| 69 | } |
| 70 | |
| 71 | static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a, |
| 72 | const struct ieee802154_addr_sa *sa) |
| 73 | { |
| 74 | a->mode = sa->addr_type; |
| 75 | a->pan_id = cpu_to_le16(sa->pan_id); |
| 76 | |
| 77 | switch (a->mode) { |
| 78 | case IEEE802154_ADDR_SHORT: |
| 79 | a->short_addr = cpu_to_le16(sa->short_addr); |
| 80 | break; |
| 81 | case IEEE802154_ADDR_LONG: |
| 82 | a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa, |
| 88 | const struct ieee802154_addr *a) |
| 89 | { |
| 90 | sa->addr_type = a->mode; |
| 91 | sa->pan_id = le16_to_cpu(a->pan_id); |
| 92 | |
| 93 | switch (a->mode) { |
| 94 | case IEEE802154_ADDR_SHORT: |
| 95 | sa->short_addr = le16_to_cpu(a->short_addr); |
| 96 | break; |
| 97 | case IEEE802154_ADDR_LONG: |
| 98 | ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | |
Alexander Aring | 89745c9 | 2014-02-28 07:32:43 +0100 | [diff] [blame] | 104 | struct ieee802154_frag_info { |
| 105 | __be16 d_tag; |
| 106 | u16 d_size; |
| 107 | u8 d_offset; |
| 108 | }; |
| 109 | |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 110 | /* |
| 111 | * A control block of skb passed between the ARPHRD_IEEE802154 device |
| 112 | * and other stack parts. |
| 113 | */ |
| 114 | struct ieee802154_mac_cb { |
| 115 | u8 lqi; |
Phoebe Buckheister | 376b7bd | 2014-03-14 21:23:57 +0100 | [diff] [blame] | 116 | struct ieee802154_addr_sa sa; |
| 117 | struct ieee802154_addr_sa da; |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 118 | u8 flags; |
| 119 | u8 seq; |
Alexander Aring | 89745c9 | 2014-02-28 07:32:43 +0100 | [diff] [blame] | 120 | struct ieee802154_frag_info frag_info; |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb) |
| 124 | { |
| 125 | return (struct ieee802154_mac_cb *)skb->cb; |
| 126 | } |
| 127 | |
| 128 | #define MAC_CB_FLAG_TYPEMASK ((1 << 3) - 1) |
| 129 | |
| 130 | #define MAC_CB_FLAG_ACKREQ (1 << 3) |
| 131 | #define MAC_CB_FLAG_SECEN (1 << 4) |
| 132 | #define MAC_CB_FLAG_INTRAPAN (1 << 5) |
| 133 | |
| 134 | static inline int mac_cb_is_ackreq(struct sk_buff *skb) |
| 135 | { |
| 136 | return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ; |
| 137 | } |
| 138 | |
| 139 | static inline int mac_cb_is_secen(struct sk_buff *skb) |
| 140 | { |
| 141 | return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN; |
| 142 | } |
| 143 | |
| 144 | static inline int mac_cb_is_intrapan(struct sk_buff *skb) |
| 145 | { |
| 146 | return mac_cb(skb)->flags & MAC_CB_FLAG_INTRAPAN; |
| 147 | } |
| 148 | |
| 149 | static inline int mac_cb_type(struct sk_buff *skb) |
| 150 | { |
| 151 | return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK; |
| 152 | } |
| 153 | |
| 154 | #define IEEE802154_MAC_SCAN_ED 0 |
| 155 | #define IEEE802154_MAC_SCAN_ACTIVE 1 |
| 156 | #define IEEE802154_MAC_SCAN_PASSIVE 2 |
| 157 | #define IEEE802154_MAC_SCAN_ORPHAN 3 |
| 158 | |
Dmitry Eremin-Solenikov | 4272344 | 2009-11-04 17:53:23 +0300 | [diff] [blame] | 159 | struct wpan_phy; |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 160 | /* |
| 161 | * This should be located at net_device->ml_priv |
Dmitry Eremin-Solenikov | 4272344 | 2009-11-04 17:53:23 +0300 | [diff] [blame] | 162 | * |
| 163 | * get_phy should increment the reference counting on returned phy. |
| 164 | * Use wpan_wpy_put to put that reference. |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 165 | */ |
| 166 | struct ieee802154_mlme_ops { |
Werner Almesberger | 56aa091 | 2013-04-04 06:32:35 +0000 | [diff] [blame] | 167 | /* The following fields are optional (can be NULL). */ |
| 168 | |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 169 | int (*assoc_req)(struct net_device *dev, |
Phoebe Buckheister | 376b7bd | 2014-03-14 21:23:57 +0100 | [diff] [blame] | 170 | struct ieee802154_addr_sa *addr, |
Dmitry Eremin-Solenikov | 16eea49 | 2009-08-19 19:32:24 +0400 | [diff] [blame] | 171 | u8 channel, u8 page, u8 cap); |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 172 | int (*assoc_resp)(struct net_device *dev, |
Phoebe Buckheister | 376b7bd | 2014-03-14 21:23:57 +0100 | [diff] [blame] | 173 | struct ieee802154_addr_sa *addr, |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame^] | 174 | __le16 short_addr, u8 status); |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 175 | int (*disassoc_req)(struct net_device *dev, |
Phoebe Buckheister | 376b7bd | 2014-03-14 21:23:57 +0100 | [diff] [blame] | 176 | struct ieee802154_addr_sa *addr, |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 177 | u8 reason); |
| 178 | int (*start_req)(struct net_device *dev, |
Phoebe Buckheister | 376b7bd | 2014-03-14 21:23:57 +0100 | [diff] [blame] | 179 | struct ieee802154_addr_sa *addr, |
Dmitry Eremin-Solenikov | 16eea49 | 2009-08-19 19:32:24 +0400 | [diff] [blame] | 180 | u8 channel, u8 page, u8 bcn_ord, u8 sf_ord, |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 181 | u8 pan_coord, u8 blx, u8 coord_realign); |
| 182 | int (*scan_req)(struct net_device *dev, |
Dmitry Eremin-Solenikov | 16eea49 | 2009-08-19 19:32:24 +0400 | [diff] [blame] | 183 | u8 type, u32 channels, u8 page, u8 duration); |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 184 | |
Werner Almesberger | 56aa091 | 2013-04-04 06:32:35 +0000 | [diff] [blame] | 185 | /* The fields below are required. */ |
| 186 | |
Dmitry Eremin-Solenikov | 4272344 | 2009-11-04 17:53:23 +0300 | [diff] [blame] | 187 | struct wpan_phy *(*get_phy)(const struct net_device *dev); |
| 188 | |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 189 | /* |
| 190 | * FIXME: these should become the part of PIB/MIB interface. |
| 191 | * However we still don't have IB interface of any kind |
| 192 | */ |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame^] | 193 | __le16 (*get_pan_id)(const struct net_device *dev); |
| 194 | __le16 (*get_short_addr)(const struct net_device *dev); |
Dmitry Eremin-Solenikov | a9966b5 | 2009-10-02 19:05:00 +0400 | [diff] [blame] | 195 | u8 (*get_dsn)(const struct net_device *dev); |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
alex.bluesman.smirnov@gmail.com | 74a02fc | 2012-05-15 20:50:23 +0000 | [diff] [blame] | 198 | /* The IEEE 802.15.4 standard defines 2 type of the devices: |
| 199 | * - FFD - full functionality device |
| 200 | * - RFD - reduce functionality device |
| 201 | * |
| 202 | * So 2 sets of mlme operations are needed |
| 203 | */ |
| 204 | struct ieee802154_reduced_mlme_ops { |
| 205 | struct wpan_phy *(*get_phy)(const struct net_device *dev); |
| 206 | }; |
| 207 | |
| 208 | static inline struct ieee802154_mlme_ops * |
| 209 | ieee802154_mlme_ops(const struct net_device *dev) |
| 210 | { |
| 211 | return dev->ml_priv; |
| 212 | } |
| 213 | |
| 214 | static inline struct ieee802154_reduced_mlme_ops * |
| 215 | ieee802154_reduced_mlme_ops(const struct net_device *dev) |
Sergey Lapin | 9ec7671 | 2009-06-08 12:18:48 +0000 | [diff] [blame] | 216 | { |
| 217 | return dev->ml_priv; |
| 218 | } |
| 219 | |
| 220 | #endif |