ieee80211softmac.h 12 KB

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