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