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, |
| 103 | associating:1, |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame^] | 104 | bssvalid:1, |
| 105 | bssfixed:1; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 106 | |
| 107 | /* Scan retries remaining */ |
| 108 | int scan_retry; |
| 109 | |
| 110 | struct work_struct work; |
| 111 | struct work_struct timeout; |
| 112 | }; |
| 113 | |
| 114 | enum { |
| 115 | IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1, |
| 116 | IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2, |
| 117 | }; |
| 118 | |
| 119 | enum { |
| 120 | IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1, |
| 121 | IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2, |
| 122 | IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3, |
| 123 | IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4, |
| 124 | }; |
| 125 | |
| 126 | /* We should make these tunable |
| 127 | * AUTH_TIMEOUT seems really long, but that's what it is in BSD */ |
| 128 | #define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ) |
| 129 | #define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5 |
| 130 | #define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3 |
| 131 | |
| 132 | struct ieee80211softmac_txrates { |
| 133 | /* The Bit-Rate to be used for multicast frames. */ |
| 134 | u8 mcast_rate; |
| 135 | /* The Bit-Rate to be used for multicast fallback |
| 136 | * (If the device supports fallback and hardware-retry) |
| 137 | */ |
| 138 | u8 mcast_fallback; |
| 139 | /* The Bit-Rate to be used for any other (normal) data packet. */ |
| 140 | u8 default_rate; |
| 141 | /* The Bit-Rate to be used for default fallback |
| 142 | * (If the device supports fallback and hardware-retry) |
| 143 | */ |
| 144 | u8 default_fallback; |
| 145 | }; |
| 146 | |
| 147 | /* Bits for txrates_change callback. */ |
| 148 | #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */ |
| 149 | #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */ |
| 150 | #define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */ |
| 151 | #define IEEE80211SOFTMAC_TXRATECHG_MCAST_FBACK (1 << 3) /* mcast_fallback */ |
| 152 | |
| 153 | struct ieee80211softmac_device { |
| 154 | /* 802.11 structure for data stuff */ |
| 155 | struct ieee80211_device *ieee; |
| 156 | struct net_device *dev; |
| 157 | |
| 158 | /* only valid if associated, then holds the Association ID */ |
| 159 | u16 association_id; |
| 160 | |
| 161 | /* the following methods are callbacks that the driver |
| 162 | * using this framework has to assign |
| 163 | */ |
| 164 | |
| 165 | /* always assign these */ |
| 166 | void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid); |
| 167 | void (*set_channel)(struct net_device *dev, u8 channel); |
| 168 | |
| 169 | /* assign if you need it, informational only */ |
| 170 | void (*link_change)(struct net_device *dev); |
| 171 | |
| 172 | /* If the hardware can do scanning, assign _all_ three of these callbacks. |
| 173 | * When the scan finishes, call ieee80211softmac_scan_finished(). |
| 174 | */ |
| 175 | |
| 176 | /* when called, start_scan is guaranteed to not be called again |
| 177 | * until you call ieee80211softmac_scan_finished. |
| 178 | * Return 0 if scanning could start, error otherwise. |
| 179 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */ |
| 180 | int (*start_scan)(struct net_device *dev); |
| 181 | /* this should block until after ieee80211softmac_scan_finished was called |
| 182 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */ |
| 183 | void (*wait_for_scan)(struct net_device *dev); |
| 184 | /* stop_scan aborts a scan, but is asynchronous. |
| 185 | * if you want to wait for it too, use wait_for_scan |
| 186 | * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */ |
| 187 | void (*stop_scan)(struct net_device *dev); |
| 188 | |
| 189 | /* we'll need something about beacons here too, for AP or ad-hoc modes */ |
| 190 | |
| 191 | /* Transmission rates to be used by the driver. |
| 192 | * The SoftMAC figures out the best possible rates. |
| 193 | * The driver just needs to read them. |
| 194 | */ |
| 195 | struct ieee80211softmac_txrates txrates; |
| 196 | /* If the driver needs to do stuff on TX rate changes, assign this callback. */ |
| 197 | void (*txrates_change)(struct net_device *dev, |
| 198 | u32 changes, /* see IEEE80211SOFTMAC_TXRATECHG flags */ |
| 199 | const struct ieee80211softmac_txrates *rates_before_change); |
| 200 | |
| 201 | /* private stuff follows */ |
| 202 | /* this lock protects this structure */ |
| 203 | spinlock_t lock; |
| 204 | |
| 205 | /* couple of flags */ |
| 206 | u8 scanning:1, /* protects scanning from being done multiple times at once */ |
| 207 | associated:1; |
| 208 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 209 | struct ieee80211softmac_scaninfo *scaninfo; |
| 210 | struct ieee80211softmac_assoc_info associnfo; |
| 211 | |
| 212 | struct list_head auth_queue; |
| 213 | struct list_head events; |
| 214 | |
| 215 | struct ieee80211softmac_ratesinfo ratesinfo; |
| 216 | int txrate_badness; |
| 217 | |
| 218 | /* WPA stuff */ |
| 219 | struct ieee80211softmac_wpa wpa; |
| 220 | |
| 221 | /* we need to keep a list of network structs we copied */ |
| 222 | struct list_head network_list; |
| 223 | |
| 224 | /* This must be the last item so that it points to the data |
| 225 | * allocated beyond this structure by alloc_ieee80211 */ |
| 226 | u8 priv[0]; |
| 227 | }; |
| 228 | |
| 229 | extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm); |
| 230 | |
| 231 | static inline void * ieee80211softmac_priv(struct net_device *dev) |
| 232 | { |
| 233 | return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv; |
| 234 | } |
| 235 | |
| 236 | extern struct net_device * alloc_ieee80211softmac(int sizeof_priv); |
| 237 | extern void free_ieee80211softmac(struct net_device *dev); |
| 238 | |
| 239 | /* Call this function if you detect a lost TX fragment. |
| 240 | * (If the device indicates failure of ACK RX, for example.) |
| 241 | * It is wise to call this function if you are able to detect lost packets, |
| 242 | * because it contributes to the TX Rates auto adjustment. |
| 243 | */ |
| 244 | extern void ieee80211softmac_fragment_lost(struct net_device *dev, |
| 245 | u16 wireless_sequence_number); |
| 246 | /* Call this function before _start to tell the softmac what rates |
| 247 | * the hw supports. The rates parameter is copied, so you can |
| 248 | * free it right after calling this function. |
| 249 | * Note that the rates need to be sorted. */ |
| 250 | extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates); |
| 251 | |
| 252 | /* Start the SoftMAC. Call this after you initialized the device |
| 253 | * and it is ready to run. |
| 254 | */ |
| 255 | extern void ieee80211softmac_start(struct net_device *dev); |
| 256 | /* Stop the SoftMAC. Call this before you shutdown the device. */ |
| 257 | extern void ieee80211softmac_stop(struct net_device *dev); |
| 258 | |
| 259 | /* |
| 260 | * Event system |
| 261 | */ |
| 262 | |
| 263 | /* valid event types */ |
| 264 | #define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/ |
| 265 | #define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0 |
| 266 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1 |
| 267 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2 |
| 268 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3 |
| 269 | #define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4 |
| 270 | #define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5 |
| 271 | #define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6 |
| 272 | #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7 |
Johannes Berg | feeeaa8 | 2006-04-13 02:42:42 +0200 | [diff] [blame] | 273 | #define IEEE80211SOFTMAC_EVENT_DISASSOCIATED 8 |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 274 | /* keep this updated! */ |
Johannes Berg | feeeaa8 | 2006-04-13 02:42:42 +0200 | [diff] [blame] | 275 | #define IEEE80211SOFTMAC_EVENT_LAST 8 |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 276 | /* |
| 277 | * If you want to be notified of certain events, you can call |
| 278 | * ieee80211softmac_notify[_atomic] with |
| 279 | * - event set to one of the constants below |
| 280 | * - fun set to a function pointer of the appropriate type |
| 281 | * - context set to the context data you want passed |
| 282 | * The return value is 0, or an error. |
| 283 | */ |
| 284 | typedef void (*notify_function_ptr)(struct net_device *dev, void *context); |
| 285 | |
| 286 | #define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL); |
| 287 | #define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC); |
| 288 | |
| 289 | extern int ieee80211softmac_notify_gfp(struct net_device *dev, |
| 290 | int event, notify_function_ptr fun, void *context, gfp_t gfp_mask); |
| 291 | |
| 292 | /* To clear pending work (for ifconfig down, etc.) */ |
| 293 | extern void |
| 294 | ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm); |
| 295 | |
| 296 | #endif /* IEEE80211SOFTMAC_H_ */ |