ieee80211softmac_priv.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Internal softmac API definitions.
  3. *
  4. * Copyright (c) 2005, 2006 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_PRIV_H_
  27. #define IEEE80211SOFTMAC_PRIV_H_
  28. #include <net/ieee80211softmac.h>
  29. #include <net/ieee80211softmac_wx.h>
  30. #include <linux/kernel.h>
  31. #include <linux/stringify.h>
  32. #define PFX "SoftMAC: "
  33. #ifdef assert
  34. # undef assert
  35. #endif
  36. #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
  37. #define assert(expr) \
  38. do { \
  39. if (unlikely(!(expr))) { \
  40. printkl(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", #expr, \
  41. __FILE__, __LINE__, __FUNCTION__); \
  42. } \
  43. } while (0)
  44. #else
  45. #define assert(expr) do {} while (0)
  46. #endif
  47. /* rate limited printk(). */
  48. #ifdef printkl
  49. # undef printkl
  50. #endif
  51. #define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
  52. /* rate limited printk() for debugging */
  53. #ifdef dprintkl
  54. # undef dprintkl
  55. #endif
  56. #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
  57. # define dprintkl printkl
  58. #else
  59. # define dprintkl(f, x...) do { /* nothing */ } while (0)
  60. #endif
  61. /* debugging printk() */
  62. #ifdef dprintk
  63. # undef dprintk
  64. #endif
  65. #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
  66. # define dprintk(f, x...) do { printk(f ,##x); } while (0)
  67. #else
  68. # define dprintk(f, x...) do { /* nothing */ } while (0)
  69. #endif
  70. /* private definitions and prototypes */
  71. /*** prototypes from _scan.c */
  72. void ieee80211softmac_scan(void *sm);
  73. /* for internal use if scanning is needed */
  74. int ieee80211softmac_start_scan(struct ieee80211softmac_device *mac);
  75. void ieee80211softmac_stop_scan(struct ieee80211softmac_device *mac);
  76. void ieee80211softmac_wait_for_scan(struct ieee80211softmac_device *mac);
  77. /* for use by _module.c to assign to the callbacks */
  78. int ieee80211softmac_start_scan_implementation(struct net_device *dev);
  79. void ieee80211softmac_stop_scan_implementation(struct net_device *dev);
  80. void ieee80211softmac_wait_for_scan_implementation(struct net_device *dev);
  81. /*** Network prototypes from _module.c */
  82. struct ieee80211softmac_network * ieee80211softmac_create_network(
  83. struct ieee80211softmac_device *mac, struct ieee80211_network *net);
  84. void ieee80211softmac_add_network_locked(struct ieee80211softmac_device *mac,
  85. struct ieee80211softmac_network *net);
  86. void ieee80211softmac_add_network(struct ieee80211softmac_device *mac,
  87. struct ieee80211softmac_network *net);
  88. void ieee80211softmac_del_network_locked(struct ieee80211softmac_device *mac,
  89. struct ieee80211softmac_network *net);
  90. void ieee80211softmac_del_network(struct ieee80211softmac_device *mac,
  91. struct ieee80211softmac_network *net);
  92. struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid_locked(
  93. struct ieee80211softmac_device *mac, u8 *ea);
  94. struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid(
  95. struct ieee80211softmac_device *mac, u8 *ea);
  96. struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid_locked(
  97. struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
  98. struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid(
  99. struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
  100. struct ieee80211softmac_network *
  101. ieee80211softmac_get_network_by_essid_locked(struct ieee80211softmac_device *mac,
  102. struct ieee80211softmac_essid *essid);
  103. struct ieee80211softmac_network *
  104. ieee80211softmac_get_network_by_essid(struct ieee80211softmac_device *mac,
  105. struct ieee80211softmac_essid *essid);
  106. /* Rates related */
  107. int ieee80211softmac_ratesinfo_rate_supported(struct ieee80211softmac_ratesinfo *ri, u8 rate);
  108. u8 ieee80211softmac_lower_rate_delta(struct ieee80211softmac_device *mac, u8 rate, int delta);
  109. void ieee80211softmac_init_txrates(struct ieee80211softmac_device *mac);
  110. void ieee80211softmac_recalc_txrates(struct ieee80211softmac_device *mac);
  111. static inline u8 lower_rate(struct ieee80211softmac_device *mac, u8 rate) {
  112. return ieee80211softmac_lower_rate_delta(mac, rate, 1);
  113. }
  114. static inline u8 get_fallback_rate(struct ieee80211softmac_device *mac, u8 rate)
  115. {
  116. return ieee80211softmac_lower_rate_delta(mac, rate, 2);
  117. }
  118. /*** prototypes from _io.c */
  119. int ieee80211softmac_send_mgt_frame(struct ieee80211softmac_device *mac,
  120. void* ptrarg, u32 type, u32 arg);
  121. /*** prototypes from _auth.c */
  122. /* do these have to go into the public header? */
  123. int ieee80211softmac_auth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net);
  124. int ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net, int reason);
  125. /* for use by _module.c to assign to the callbacks */
  126. int ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth);
  127. int ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_deauth *deauth);
  128. /*** prototypes from _assoc.c */
  129. void ieee80211softmac_assoc_work(void *d);
  130. int ieee80211softmac_handle_assoc_response(struct net_device * dev,
  131. struct ieee80211_assoc_response * resp,
  132. struct ieee80211_network * network);
  133. int ieee80211softmac_handle_disassoc(struct net_device * dev,
  134. struct ieee80211_disassoc * disassoc);
  135. int ieee80211softmac_handle_reassoc_req(struct net_device * dev,
  136. struct ieee80211_reassoc_request * reassoc);
  137. void ieee80211softmac_assoc_timeout(void *d);
  138. void ieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reason);
  139. void ieee80211softmac_disassoc(struct ieee80211softmac_device *mac);
  140. /* some helper functions */
  141. static inline int ieee80211softmac_scan_handlers_check_self(struct ieee80211softmac_device *sm)
  142. {
  143. return (sm->start_scan == ieee80211softmac_start_scan_implementation) &&
  144. (sm->stop_scan == ieee80211softmac_stop_scan_implementation) &&
  145. (sm->wait_for_scan == ieee80211softmac_wait_for_scan_implementation);
  146. }
  147. static inline int ieee80211softmac_scan_sanity_check(struct ieee80211softmac_device *sm)
  148. {
  149. return ((sm->start_scan != ieee80211softmac_start_scan_implementation) &&
  150. (sm->stop_scan != ieee80211softmac_stop_scan_implementation) &&
  151. (sm->wait_for_scan != ieee80211softmac_wait_for_scan_implementation)
  152. ) || ieee80211softmac_scan_handlers_check_self(sm);
  153. }
  154. #define IEEE80211SOFTMAC_PROBE_DELAY HZ/50
  155. #define IEEE80211SOFTMAC_WORKQUEUE_NAME_LEN (17 + IFNAMSIZ)
  156. struct ieee80211softmac_network {
  157. struct list_head list; /* List */
  158. /* Network information copied from ieee80211_network */
  159. u8 bssid[ETH_ALEN];
  160. u8 channel;
  161. struct ieee80211softmac_essid essid;
  162. struct ieee80211softmac_ratesinfo supported_rates;
  163. /* SoftMAC specific */
  164. u16 authenticating:1, /* Status Flags */
  165. authenticated:1,
  166. auth_desynced_once:1;
  167. u16 capabilities; /* Capabilities bitfield */
  168. u8 challenge_len; /* Auth Challenge length */
  169. char *challenge; /* Challenge Text */
  170. };
  171. /* structure used to keep track of networks we're auth'ing to */
  172. struct ieee80211softmac_auth_queue_item {
  173. struct list_head list; /* List head */
  174. struct ieee80211softmac_network *net; /* Network to auth */
  175. struct ieee80211softmac_device *mac; /* SoftMAC device */
  176. u8 retry; /* Retry limit */
  177. u8 state; /* Auth State */
  178. struct work_struct work; /* Work queue */
  179. };
  180. /* scanning information */
  181. struct ieee80211softmac_scaninfo {
  182. u8 current_channel_idx,
  183. number_channels;
  184. struct ieee80211_channel *channels;
  185. u8 started:1,
  186. stop:1;
  187. u8 skip_flags;
  188. struct completion finished;
  189. struct work_struct softmac_scan;
  190. };
  191. /* private event struct */
  192. struct ieee80211softmac_event {
  193. struct list_head list;
  194. int event_type;
  195. void *event_context;
  196. struct work_struct work;
  197. notify_function_ptr fun;
  198. void *context;
  199. struct ieee80211softmac_device *mac;
  200. };
  201. void ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_context);
  202. void ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_context);
  203. int ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
  204. int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask);
  205. #endif /* IEEE80211SOFTMAC_PRIV_H_ */