Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ieee80211softmac.h - public interface to the softmac |
| 3 | * |
| 4 | * Copyright (c) 2005 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Joseph Jezak <josejx@gentoo.org> |
| 6 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 7 | * Danny van Dyk <kugelfang@gentoo.org> |
| 8 | * Michael Buesch <mbuesch@freenet.de> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * |
| 23 | * The full GNU General Public License is included in this distribution in the |
| 24 | * file called COPYING. |
| 25 | */ |
| 26 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 27 | #ifndef IEEE80211SOFTMAC_H_ |
| 28 | #define IEEE80211SOFTMAC_H_ |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/spinlock.h> |
| 32 | #include <linux/workqueue.h> |
| 33 | #include <linux/list.h> |
| 34 | #include <net/ieee80211.h> |
| 35 | |
| 36 | /* Once the API is considered more or less stable, |
| 37 | * this should be incremented on API incompatible changes. |
| 38 | */ |
| 39 | #define IEEE80211SOFTMAC_API 0 |
| 40 | |
| 41 | #define IEEE80211SOFTMAC_MAX_RATES_LEN 8 |
| 42 | #define IEEE80211SOFTMAC_MAX_EX_RATES_LEN 255 |
| 43 | |
| 44 | struct ieee80211softmac_ratesinfo { |
| 45 | u8 count; |
| 46 | u8 rates[IEEE80211SOFTMAC_MAX_RATES_LEN + IEEE80211SOFTMAC_MAX_EX_RATES_LEN]; |
| 47 | }; |
| 48 | |
| 49 | /* internal structures */ |
| 50 | struct ieee80211softmac_network; |
| 51 | struct ieee80211softmac_scaninfo; |
| 52 | |
| 53 | struct ieee80211softmac_essid { |
| 54 | u8 len; |
| 55 | char data[IW_ESSID_MAX_SIZE+1]; |
| 56 | }; |
| 57 | |
| 58 | struct ieee80211softmac_wpa { |
| 59 | char *IE; |
| 60 | int IElen; |
| 61 | int IEbuflen; |
| 62 | }; |
| 63 | |
| 64 | /* |
| 65 | * Information about association |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 66 | */ |
| 67 | struct ieee80211softmac_assoc_info { |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 68 | |
| 69 | struct mutex mutex; |
| 70 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 71 | /* |
| 72 | * This is the requested ESSID. It is written |
| 73 | * only by the WX handlers. |
| 74 | * |
| 75 | */ |
| 76 | struct ieee80211softmac_essid req_essid; |
| 77 | /* |
| 78 | * the ESSID of the network we're currently |
| 79 | * associated (or trying) to. This is |
| 80 | * updated to the network's actual ESSID |
| 81 | * even if the requested ESSID was 'ANY' |
| 82 | */ |
| 83 | struct ieee80211softmac_essid associate_essid; |
| 84 | |
| 85 | /* BSSID we're trying to associate to */ |
| 86 | char bssid[ETH_ALEN]; |
| 87 | |
| 88 | /* some flags. |
| 89 | * static_essid is valid if the essid is constant, |
| 90 | * this is for use by the wx handlers only. |
| 91 | * |
| 92 | * associating is true, if the network has been |
| 93 | * auth'ed on and we are in the process of associating. |
| 94 | * |
| 95 | * bssvalid is true if we found a matching network |
| 96 | * and saved it's BSSID into the bssid above. |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 97 | * |
| 98 | * bssfixed is used for SIOCSIWAP. |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 99 | */ |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 100 | u8 static_essid; |
| 101 | u8 short_preamble_available; |
| 102 | u8 associating; |
| 103 | u8 associated; |
| 104 | u8 assoc_wait; |
| 105 | u8 bssvalid; |
| 106 | u8 bssfixed; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 107 | |
| 108 | /* Scan retries remaining */ |
| 109 | int scan_retry; |
| 110 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 111 | struct delayed_work work; |
| 112 | struct delayed_work timeout; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 115 | struct ieee80211softmac_bss_info { |
| 116 | /* Rates supported by the network */ |
| 117 | struct ieee80211softmac_ratesinfo supported_rates; |
| 118 | |
| 119 | /* This indicates whether frames can currently be transmitted with |
| 120 | * short preamble (only use this variable during TX at CCK rates) */ |
| 121 | u8 short_preamble:1; |
| 122 | |
| 123 | /* This indicates whether protection (e.g. self-CTS) should be used |
| 124 | * when transmitting with OFDM modulation */ |
| 125 | u8 use_protection:1; |
| 126 | }; |
| 127 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 128 | enum { |
| 129 | IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1, |
| 130 | IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2, |
| 131 | }; |
| 132 | |
| 133 | enum { |
| 134 | IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1, |
| 135 | IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2, |
| 136 | IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3, |
| 137 | IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4, |
| 138 | }; |
| 139 | |
| 140 | /* We should make these tunable |
| 141 | * AUTH_TIMEOUT seems really long, but that's what it is in BSD */ |
| 142 | #define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ) |
| 143 | #define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5 |
| 144 | #define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3 |
| 145 | |
| 146 | struct ieee80211softmac_txrates { |
| 147 | /* The Bit-Rate to be used for multicast frames. */ |
| 148 | u8 mcast_rate; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 149 | |
| 150 | /* The Bit-Rate to be used for multicast management frames. */ |
| 151 | u8 mgt_mcast_rate; |
| 152 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 153 | /* The Bit-Rate to be used for any other (normal) data packet. */ |
| 154 | u8 default_rate; |
| 155 | /* The Bit-Rate to be used for default fallback |
| 156 | * (If the device supports fallback and hardware-retry) |
| 157 | */ |
| 158 | u8 default_fallback; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 159 | |
| 160 | /* This is the rate that the user asked for */ |
| 161 | u8 user_rate; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | /* Bits for txrates_change callback. */ |
| 165 | #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */ |
| 166 | #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */ |
| 167 | #define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */ |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 168 | #define IEEE80211SOFTMAC_TXRATECHG_MGT_MCAST (1 << 3) /* mgt_mcast_rate */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 169 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 170 | #define IEEE80211SOFTMAC_BSSINFOCHG_RATES (1 << 0) /* supported_rates */ |
| 171 | #define IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE (1 << 1) /* short_preamble */ |
| 172 | #define IEEE80211SOFTMAC_BSSINFOCHG_PROTECTION (1 << 2) /* use_protection */ |
| 173 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 174 | struct ieee80211softmac_device { |
| 175 | /* 802.11 structure for data stuff */ |
| 176 | struct ieee80211_device *ieee; |
| 177 | struct net_device *dev; |
| 178 | |
| 179 | /* only valid if associated, then holds the Association ID */ |
| 180 | u16 association_id; |
| 181 | |
| 182 | /* the following methods are callbacks that the driver |
| 183 | * using this framework has to assign |
| 184 | */ |
| 185 | |
| 186 | /* always assign these */ |
| 187 | void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid); |
| 188 | void (*set_channel)(struct net_device *dev, u8 channel); |
| 189 | |
| 190 | /* assign if you need it, informational only */ |
| 191 | void (*link_change)(struct net_device *dev); |
| 192 | |
| 193 | /* If the hardware can do scanning, assign _all_ three of these callbacks. |
| 194 | * When the scan finishes, call ieee80211softmac_scan_finished(). |
| 195 | */ |
| 196 | |
| 197 | /* when called, start_scan is guaranteed to not be called again |
| 198 | * until you call ieee80211softmac_scan_finished. |
| 199 | * Return 0 if scanning could start, error otherwise. |
| 200 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */ |
| 201 | int (*start_scan)(struct net_device *dev); |
| 202 | /* this should block until after ieee80211softmac_scan_finished was called |
| 203 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */ |
| 204 | void (*wait_for_scan)(struct net_device *dev); |
| 205 | /* stop_scan aborts a scan, but is asynchronous. |
| 206 | * if you want to wait for it too, use wait_for_scan |
| 207 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */ |
| 208 | void (*stop_scan)(struct net_device *dev); |
| 209 | |
| 210 | /* we'll need something about beacons here too, for AP or ad-hoc modes */ |
| 211 | |
| 212 | /* Transmission rates to be used by the driver. |
| 213 | * The SoftMAC figures out the best possible rates. |
| 214 | * The driver just needs to read them. |
| 215 | */ |
| 216 | struct ieee80211softmac_txrates txrates; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 217 | |
| 218 | /* If the driver needs to do stuff on TX rate changes, assign this |
| 219 | * callback. See IEEE80211SOFTMAC_TXRATECHG for change flags. */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 220 | void (*txrates_change)(struct net_device *dev, |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 221 | u32 changes); |
| 222 | |
| 223 | /* If the driver needs to do stuff when BSS properties change, assign |
| 224 | * this callback. see IEEE80211SOFTMAC_BSSINFOCHG for change flags. */ |
| 225 | void (*bssinfo_change)(struct net_device *dev, |
| 226 | u32 changes); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 227 | |
| 228 | /* private stuff follows */ |
| 229 | /* this lock protects this structure */ |
| 230 | spinlock_t lock; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 231 | |
| 232 | u8 running; /* SoftMAC started? */ |
| 233 | u8 scanning; |
| 234 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 235 | struct ieee80211softmac_scaninfo *scaninfo; |
| 236 | struct ieee80211softmac_assoc_info associnfo; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 237 | struct ieee80211softmac_bss_info bssinfo; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 238 | |
| 239 | struct list_head auth_queue; |
| 240 | struct list_head events; |
| 241 | |
| 242 | struct ieee80211softmac_ratesinfo ratesinfo; |
| 243 | int txrate_badness; |
| 244 | |
| 245 | /* WPA stuff */ |
| 246 | struct ieee80211softmac_wpa wpa; |
| 247 | |
| 248 | /* we need to keep a list of network structs we copied */ |
| 249 | struct list_head network_list; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 250 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 251 | /* This must be the last item so that it points to the data |
| 252 | * allocated beyond this structure by alloc_ieee80211 */ |
| 253 | u8 priv[0]; |
| 254 | }; |
| 255 | |
| 256 | extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm); |
| 257 | |
| 258 | static inline void * ieee80211softmac_priv(struct net_device *dev) |
| 259 | { |
| 260 | return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv; |
| 261 | } |
| 262 | |
| 263 | extern struct net_device * alloc_ieee80211softmac(int sizeof_priv); |
| 264 | extern void free_ieee80211softmac(struct net_device *dev); |
| 265 | |
| 266 | /* Call this function if you detect a lost TX fragment. |
| 267 | * (If the device indicates failure of ACK RX, for example.) |
| 268 | * It is wise to call this function if you are able to detect lost packets, |
| 269 | * because it contributes to the TX Rates auto adjustment. |
| 270 | */ |
| 271 | extern void ieee80211softmac_fragment_lost(struct net_device *dev, |
| 272 | u16 wireless_sequence_number); |
| 273 | /* Call this function before _start to tell the softmac what rates |
| 274 | * the hw supports. The rates parameter is copied, so you can |
| 275 | * free it right after calling this function. |
| 276 | * Note that the rates need to be sorted. */ |
| 277 | extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates); |
| 278 | |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 279 | /* Finds the highest rate which is: |
| 280 | * 1. Present in ri (optionally a basic rate) |
| 281 | * 2. Supported by the device |
| 282 | * 3. Less than or equal to the user-defined rate |
| 283 | */ |
| 284 | extern u8 ieee80211softmac_highest_supported_rate(struct ieee80211softmac_device *mac, |
| 285 | struct ieee80211softmac_ratesinfo *ri, int basic_only); |
| 286 | |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 287 | /* Helper function which advises you the rate at which a frame should be |
| 288 | * transmitted at. */ |
| 289 | static inline u8 ieee80211softmac_suggest_txrate(struct ieee80211softmac_device *mac, |
| 290 | int is_multicast, |
| 291 | int is_mgt) |
| 292 | { |
| 293 | struct ieee80211softmac_txrates *txrates = &mac->txrates; |
| 294 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 295 | if (!mac->associnfo.associated) |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 296 | return txrates->mgt_mcast_rate; |
| 297 | |
| 298 | /* We are associated, sending unicast frame */ |
| 299 | if (!is_multicast) |
| 300 | return txrates->default_rate; |
| 301 | |
| 302 | /* We are associated, sending multicast frame */ |
| 303 | if (is_mgt) |
| 304 | return txrates->mgt_mcast_rate; |
| 305 | else |
| 306 | return txrates->mcast_rate; |
| 307 | } |
| 308 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 309 | /* Helper function which advises you when it is safe to transmit with short |
| 310 | * preamble. |
| 311 | * You should only call this function when transmitting at CCK rates. */ |
| 312 | static inline int ieee80211softmac_short_preamble_ok(struct ieee80211softmac_device *mac, |
| 313 | int is_multicast, |
| 314 | int is_mgt) |
| 315 | { |
| 316 | return (is_multicast && is_mgt) ? 0 : mac->bssinfo.short_preamble; |
| 317 | } |
| 318 | |
| 319 | /* Helper function which advises you whether protection (e.g. self-CTS) is |
| 320 | * needed. 1 = protection needed, 0 = no protection needed |
| 321 | * Only use this function when transmitting with OFDM modulation. */ |
| 322 | static inline int ieee80211softmac_protection_needed(struct ieee80211softmac_device *mac) |
| 323 | { |
| 324 | return mac->bssinfo.use_protection; |
| 325 | } |
| 326 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 327 | /* Start the SoftMAC. Call this after you initialized the device |
| 328 | * and it is ready to run. |
| 329 | */ |
| 330 | extern void ieee80211softmac_start(struct net_device *dev); |
| 331 | /* Stop the SoftMAC. Call this before you shutdown the device. */ |
| 332 | extern void ieee80211softmac_stop(struct net_device *dev); |
| 333 | |
| 334 | /* |
| 335 | * Event system |
| 336 | */ |
| 337 | |
| 338 | /* valid event types */ |
| 339 | #define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/ |
| 340 | #define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0 |
| 341 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1 |
| 342 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2 |
| 343 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3 |
| 344 | #define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4 |
| 345 | #define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5 |
| 346 | #define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6 |
| 347 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7 |
Johannes Berg | feeeaa8 | 2006-04-13 02:42:42 +0200 | [diff] [blame] | 348 | #define IEEE80211SOFTMAC_EVENT_DISASSOCIATED 8 |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 349 | /* keep this updated! */ |
Johannes Berg | feeeaa8 | 2006-04-13 02:42:42 +0200 | [diff] [blame] | 350 | #define IEEE80211SOFTMAC_EVENT_LAST 8 |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 351 | /* |
| 352 | * If you want to be notified of certain events, you can call |
| 353 | * ieee80211softmac_notify[_atomic] with |
| 354 | * - event set to one of the constants below |
| 355 | * - fun set to a function pointer of the appropriate type |
| 356 | * - context set to the context data you want passed |
| 357 | * The return value is 0, or an error. |
| 358 | */ |
Daniel Drake | 6ae15df | 2006-06-01 15:37:22 +0100 | [diff] [blame] | 359 | typedef void (*notify_function_ptr)(struct net_device *dev, int event_type, void *context); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 360 | |
| 361 | #define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL); |
| 362 | #define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC); |
| 363 | |
| 364 | extern int ieee80211softmac_notify_gfp(struct net_device *dev, |
| 365 | int event, notify_function_ptr fun, void *context, gfp_t gfp_mask); |
| 366 | |
| 367 | /* To clear pending work (for ifconfig down, etc.) */ |
| 368 | extern void |
| 369 | ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm); |
| 370 | |
| 371 | #endif /* IEEE80211SOFTMAC_H_ */ |