ieee80211softmac.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifndef IEEE80211SOFTMAC_H_
  2. #define IEEE80211SOFTMAC_H_
  3. #include <linux/kernel.h>
  4. #include <linux/spinlock.h>
  5. #include <linux/workqueue.h>
  6. #include <linux/list.h>
  7. #include <net/ieee80211.h>
  8. /* Once the API is considered more or less stable,
  9. * this should be incremented on API incompatible changes.
  10. */
  11. #define IEEE80211SOFTMAC_API 0
  12. #define IEEE80211SOFTMAC_MAX_RATES_LEN 8
  13. #define IEEE80211SOFTMAC_MAX_EX_RATES_LEN 255
  14. struct ieee80211softmac_ratesinfo {
  15. u8 count;
  16. u8 rates[IEEE80211SOFTMAC_MAX_RATES_LEN + IEEE80211SOFTMAC_MAX_EX_RATES_LEN];
  17. };
  18. /* internal structures */
  19. struct ieee80211softmac_network;
  20. struct ieee80211softmac_scaninfo;
  21. struct ieee80211softmac_essid {
  22. u8 len;
  23. char data[IW_ESSID_MAX_SIZE+1];
  24. };
  25. struct ieee80211softmac_wpa {
  26. char *IE;
  27. int IElen;
  28. int IEbuflen;
  29. };
  30. /*
  31. * Information about association
  32. *
  33. * Do we need a lock for this?
  34. * We only ever use this structure inlined
  35. * into our global struct. I've used its lock,
  36. * but maybe we need a local one here?
  37. */
  38. struct ieee80211softmac_assoc_info {
  39. /*
  40. * This is the requested ESSID. It is written
  41. * only by the WX handlers.
  42. *
  43. */
  44. struct ieee80211softmac_essid req_essid;
  45. /*
  46. * the ESSID of the network we're currently
  47. * associated (or trying) to. This is
  48. * updated to the network's actual ESSID
  49. * even if the requested ESSID was 'ANY'
  50. */
  51. struct ieee80211softmac_essid associate_essid;
  52. /* BSSID we're trying to associate to */
  53. char bssid[ETH_ALEN];
  54. /* some flags.
  55. * static_essid is valid if the essid is constant,
  56. * this is for use by the wx handlers only.
  57. *
  58. * associating is true, if the network has been
  59. * auth'ed on and we are in the process of associating.
  60. *
  61. * bssvalid is true if we found a matching network
  62. * and saved it's BSSID into the bssid above.
  63. */
  64. u8 static_essid:1,
  65. associating:1,
  66. bssvalid:1;
  67. /* Scan retries remaining */
  68. int scan_retry;
  69. struct work_struct work;
  70. struct work_struct timeout;
  71. };
  72. enum {
  73. IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1,
  74. IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2,
  75. };
  76. enum {
  77. IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1,
  78. IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2,
  79. IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3,
  80. IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4,
  81. };
  82. /* We should make these tunable
  83. * AUTH_TIMEOUT seems really long, but that's what it is in BSD */
  84. #define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ)
  85. #define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5
  86. #define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3
  87. struct ieee80211softmac_txrates {
  88. /* The Bit-Rate to be used for multicast frames. */
  89. u8 mcast_rate;
  90. /* The Bit-Rate to be used for multicast fallback
  91. * (If the device supports fallback and hardware-retry)
  92. */
  93. u8 mcast_fallback;
  94. /* The Bit-Rate to be used for any other (normal) data packet. */
  95. u8 default_rate;
  96. /* The Bit-Rate to be used for default fallback
  97. * (If the device supports fallback and hardware-retry)
  98. */
  99. u8 default_fallback;
  100. };
  101. /* Bits for txrates_change callback. */
  102. #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */
  103. #define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */
  104. #define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */
  105. #define IEEE80211SOFTMAC_TXRATECHG_MCAST_FBACK (1 << 3) /* mcast_fallback */
  106. struct ieee80211softmac_device {
  107. /* 802.11 structure for data stuff */
  108. struct ieee80211_device *ieee;
  109. struct net_device *dev;
  110. /* only valid if associated, then holds the Association ID */
  111. u16 association_id;
  112. /* the following methods are callbacks that the driver
  113. * using this framework has to assign
  114. */
  115. /* always assign these */
  116. void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid);
  117. void (*set_channel)(struct net_device *dev, u8 channel);
  118. /* assign if you need it, informational only */
  119. void (*link_change)(struct net_device *dev);
  120. /* If the hardware can do scanning, assign _all_ three of these callbacks.
  121. * When the scan finishes, call ieee80211softmac_scan_finished().
  122. */
  123. /* when called, start_scan is guaranteed to not be called again
  124. * until you call ieee80211softmac_scan_finished.
  125. * Return 0 if scanning could start, error otherwise.
  126. * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */
  127. int (*start_scan)(struct net_device *dev);
  128. /* this should block until after ieee80211softmac_scan_finished was called
  129. * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */
  130. void (*wait_for_scan)(struct net_device *dev);
  131. /* stop_scan aborts a scan, but is asynchronous.
  132. * if you want to wait for it too, use wait_for_scan
  133. * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */
  134. void (*stop_scan)(struct net_device *dev);
  135. /* we'll need something about beacons here too, for AP or ad-hoc modes */
  136. /* Transmission rates to be used by the driver.
  137. * The SoftMAC figures out the best possible rates.
  138. * The driver just needs to read them.
  139. */
  140. struct ieee80211softmac_txrates txrates;
  141. /* If the driver needs to do stuff on TX rate changes, assign this callback. */
  142. void (*txrates_change)(struct net_device *dev,
  143. u32 changes, /* see IEEE80211SOFTMAC_TXRATECHG flags */
  144. const struct ieee80211softmac_txrates *rates_before_change);
  145. /* private stuff follows */
  146. /* this lock protects this structure */
  147. spinlock_t lock;
  148. /* couple of flags */
  149. u8 scanning:1, /* protects scanning from being done multiple times at once */
  150. associated:1;
  151. struct ieee80211softmac_scaninfo *scaninfo;
  152. struct ieee80211softmac_assoc_info associnfo;
  153. struct list_head auth_queue;
  154. struct list_head events;
  155. struct ieee80211softmac_ratesinfo ratesinfo;
  156. int txrate_badness;
  157. /* WPA stuff */
  158. struct ieee80211softmac_wpa wpa;
  159. /* we need to keep a list of network structs we copied */
  160. struct list_head network_list;
  161. /* This must be the last item so that it points to the data
  162. * allocated beyond this structure by alloc_ieee80211 */
  163. u8 priv[0];
  164. };
  165. extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm);
  166. static inline void * ieee80211softmac_priv(struct net_device *dev)
  167. {
  168. return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv;
  169. }
  170. extern struct net_device * alloc_ieee80211softmac(int sizeof_priv);
  171. extern void free_ieee80211softmac(struct net_device *dev);
  172. /* Call this function if you detect a lost TX fragment.
  173. * (If the device indicates failure of ACK RX, for example.)
  174. * It is wise to call this function if you are able to detect lost packets,
  175. * because it contributes to the TX Rates auto adjustment.
  176. */
  177. extern void ieee80211softmac_fragment_lost(struct net_device *dev,
  178. u16 wireless_sequence_number);
  179. /* Call this function before _start to tell the softmac what rates
  180. * the hw supports. The rates parameter is copied, so you can
  181. * free it right after calling this function.
  182. * Note that the rates need to be sorted. */
  183. extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates);
  184. /* Start the SoftMAC. Call this after you initialized the device
  185. * and it is ready to run.
  186. */
  187. extern void ieee80211softmac_start(struct net_device *dev);
  188. /* Stop the SoftMAC. Call this before you shutdown the device. */
  189. extern void ieee80211softmac_stop(struct net_device *dev);
  190. /*
  191. * Event system
  192. */
  193. /* valid event types */
  194. #define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/
  195. #define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0
  196. #define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1
  197. #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2
  198. #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3
  199. #define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4
  200. #define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5
  201. #define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6
  202. #define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7
  203. /* keep this updated! */
  204. #define IEEE80211SOFTMAC_EVENT_LAST 7
  205. /*
  206. * If you want to be notified of certain events, you can call
  207. * ieee80211softmac_notify[_atomic] with
  208. * - event set to one of the constants below
  209. * - fun set to a function pointer of the appropriate type
  210. * - context set to the context data you want passed
  211. * The return value is 0, or an error.
  212. */
  213. typedef void (*notify_function_ptr)(struct net_device *dev, void *context);
  214. #define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL);
  215. #define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC);
  216. extern int ieee80211softmac_notify_gfp(struct net_device *dev,
  217. int event, notify_function_ptr fun, void *context, gfp_t gfp_mask);
  218. /* To clear pending work (for ifconfig down, etc.) */
  219. extern void
  220. ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm);
  221. #endif /* IEEE80211SOFTMAC_H_ */