libipw.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /*
  2. * Merged with mainline ieee80211.h in Aug 2004. Original ieee802_11
  3. * remains copyright by the original authors
  4. *
  5. * Portions of the merged code are based on Host AP (software wireless
  6. * LAN access point) driver for Intersil Prism2/2.5/3.
  7. *
  8. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  9. * <j@w1.fi>
  10. * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
  11. *
  12. * Adaption to a generic IEEE 802.11 stack by James Ketrenos
  13. * <jketreno@linux.intel.com>
  14. * Copyright (c) 2004-2005, Intel Corporation
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation. See README and COPYING for
  19. * more details.
  20. *
  21. * API Version History
  22. * 1.0.x -- Initial version
  23. * 1.1.x -- Added radiotap, QoS, TIM, libipw_geo APIs,
  24. * various structure changes, and crypto API init method
  25. */
  26. #ifndef LIBIPW_H
  27. #define LIBIPW_H
  28. #include <linux/if_ether.h> /* ETH_ALEN */
  29. #include <linux/kernel.h> /* ARRAY_SIZE */
  30. #include <linux/wireless.h>
  31. #include <linux/ieee80211.h>
  32. #include <net/lib80211.h>
  33. #include <net/cfg80211.h>
  34. #define LIBIPW_VERSION "git-1.1.13"
  35. #define LIBIPW_DATA_LEN 2304
  36. /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
  37. 6.2.1.1.2.
  38. The figure in section 7.1.2 suggests a body size of up to 2312
  39. bytes is allowed, which is a bit confusing, I suspect this
  40. represents the 2304 bytes of real data, plus a possible 8 bytes of
  41. WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
  42. #define LIBIPW_1ADDR_LEN 10
  43. #define LIBIPW_2ADDR_LEN 16
  44. #define LIBIPW_3ADDR_LEN 24
  45. #define LIBIPW_4ADDR_LEN 30
  46. #define LIBIPW_FCS_LEN 4
  47. #define LIBIPW_HLEN (LIBIPW_4ADDR_LEN)
  48. #define LIBIPW_FRAME_LEN (LIBIPW_DATA_LEN + LIBIPW_HLEN)
  49. #define MIN_FRAG_THRESHOLD 256U
  50. #define MAX_FRAG_THRESHOLD 2346U
  51. /* QOS control */
  52. #define LIBIPW_QCTL_TID 0x000F
  53. /* debug macros */
  54. #ifdef CONFIG_LIBIPW_DEBUG
  55. extern u32 libipw_debug_level;
  56. #define LIBIPW_DEBUG(level, fmt, args...) \
  57. do { if (libipw_debug_level & (level)) \
  58. printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
  59. in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
  60. static inline bool libipw_ratelimit_debug(u32 level)
  61. {
  62. return (libipw_debug_level & level) && net_ratelimit();
  63. }
  64. #else
  65. #define LIBIPW_DEBUG(level, fmt, args...) do {} while (0)
  66. static inline bool libipw_ratelimit_debug(u32 level)
  67. {
  68. return false;
  69. }
  70. #endif /* CONFIG_LIBIPW_DEBUG */
  71. /*
  72. * To use the debug system:
  73. *
  74. * If you are defining a new debug classification, simply add it to the #define
  75. * list here in the form of:
  76. *
  77. * #define LIBIPW_DL_xxxx VALUE
  78. *
  79. * shifting value to the left one bit from the previous entry. xxxx should be
  80. * the name of the classification (for example, WEP)
  81. *
  82. * You then need to either add a LIBIPW_xxxx_DEBUG() macro definition for your
  83. * classification, or use LIBIPW_DEBUG(LIBIPW_DL_xxxx, ...) whenever you want
  84. * to send output to that classification.
  85. *
  86. * To add your debug level to the list of levels seen when you perform
  87. *
  88. * % cat /proc/net/ieee80211/debug_level
  89. *
  90. * you simply need to add your entry to the libipw_debug_level array.
  91. *
  92. * If you do not see debug_level in /proc/net/ieee80211 then you do not have
  93. * CONFIG_LIBIPW_DEBUG defined in your kernel configuration
  94. *
  95. */
  96. #define LIBIPW_DL_INFO (1<<0)
  97. #define LIBIPW_DL_WX (1<<1)
  98. #define LIBIPW_DL_SCAN (1<<2)
  99. #define LIBIPW_DL_STATE (1<<3)
  100. #define LIBIPW_DL_MGMT (1<<4)
  101. #define LIBIPW_DL_FRAG (1<<5)
  102. #define LIBIPW_DL_DROP (1<<7)
  103. #define LIBIPW_DL_TX (1<<8)
  104. #define LIBIPW_DL_RX (1<<9)
  105. #define LIBIPW_DL_QOS (1<<31)
  106. #define LIBIPW_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
  107. #define LIBIPW_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
  108. #define LIBIPW_DEBUG_INFO(f, a...) LIBIPW_DEBUG(LIBIPW_DL_INFO, f, ## a)
  109. #define LIBIPW_DEBUG_WX(f, a...) LIBIPW_DEBUG(LIBIPW_DL_WX, f, ## a)
  110. #define LIBIPW_DEBUG_SCAN(f, a...) LIBIPW_DEBUG(LIBIPW_DL_SCAN, f, ## a)
  111. #define LIBIPW_DEBUG_STATE(f, a...) LIBIPW_DEBUG(LIBIPW_DL_STATE, f, ## a)
  112. #define LIBIPW_DEBUG_MGMT(f, a...) LIBIPW_DEBUG(LIBIPW_DL_MGMT, f, ## a)
  113. #define LIBIPW_DEBUG_FRAG(f, a...) LIBIPW_DEBUG(LIBIPW_DL_FRAG, f, ## a)
  114. #define LIBIPW_DEBUG_DROP(f, a...) LIBIPW_DEBUG(LIBIPW_DL_DROP, f, ## a)
  115. #define LIBIPW_DEBUG_TX(f, a...) LIBIPW_DEBUG(LIBIPW_DL_TX, f, ## a)
  116. #define LIBIPW_DEBUG_RX(f, a...) LIBIPW_DEBUG(LIBIPW_DL_RX, f, ## a)
  117. #define LIBIPW_DEBUG_QOS(f, a...) LIBIPW_DEBUG(LIBIPW_DL_QOS, f, ## a)
  118. #include <linux/netdevice.h>
  119. #include <linux/if_arp.h> /* ARPHRD_ETHER */
  120. #ifndef WIRELESS_SPY
  121. #define WIRELESS_SPY /* enable iwspy support */
  122. #endif
  123. #include <net/iw_handler.h> /* new driver API */
  124. #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
  125. #ifndef ETH_P_80211_RAW
  126. #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
  127. #endif
  128. /* IEEE 802.11 defines */
  129. #define P80211_OUI_LEN 3
  130. struct libipw_snap_hdr {
  131. u8 dsap; /* always 0xAA */
  132. u8 ssap; /* always 0xAA */
  133. u8 ctrl; /* always 0x03 */
  134. u8 oui[P80211_OUI_LEN]; /* organizational universal id */
  135. } __attribute__ ((packed));
  136. #define SNAP_SIZE sizeof(struct libipw_snap_hdr)
  137. #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
  138. #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
  139. #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
  140. #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
  141. #define WLAN_GET_SEQ_SEQ(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  142. #define LIBIPW_STATMASK_SIGNAL (1<<0)
  143. #define LIBIPW_STATMASK_RSSI (1<<1)
  144. #define LIBIPW_STATMASK_NOISE (1<<2)
  145. #define LIBIPW_STATMASK_RATE (1<<3)
  146. #define LIBIPW_STATMASK_WEMASK 0x7
  147. #define LIBIPW_CCK_MODULATION (1<<0)
  148. #define LIBIPW_OFDM_MODULATION (1<<1)
  149. #define LIBIPW_24GHZ_BAND (1<<0)
  150. #define LIBIPW_52GHZ_BAND (1<<1)
  151. #define LIBIPW_CCK_RATE_1MB 0x02
  152. #define LIBIPW_CCK_RATE_2MB 0x04
  153. #define LIBIPW_CCK_RATE_5MB 0x0B
  154. #define LIBIPW_CCK_RATE_11MB 0x16
  155. #define LIBIPW_OFDM_RATE_6MB 0x0C
  156. #define LIBIPW_OFDM_RATE_9MB 0x12
  157. #define LIBIPW_OFDM_RATE_12MB 0x18
  158. #define LIBIPW_OFDM_RATE_18MB 0x24
  159. #define LIBIPW_OFDM_RATE_24MB 0x30
  160. #define LIBIPW_OFDM_RATE_36MB 0x48
  161. #define LIBIPW_OFDM_RATE_48MB 0x60
  162. #define LIBIPW_OFDM_RATE_54MB 0x6C
  163. #define LIBIPW_BASIC_RATE_MASK 0x80
  164. #define LIBIPW_CCK_RATE_1MB_MASK (1<<0)
  165. #define LIBIPW_CCK_RATE_2MB_MASK (1<<1)
  166. #define LIBIPW_CCK_RATE_5MB_MASK (1<<2)
  167. #define LIBIPW_CCK_RATE_11MB_MASK (1<<3)
  168. #define LIBIPW_OFDM_RATE_6MB_MASK (1<<4)
  169. #define LIBIPW_OFDM_RATE_9MB_MASK (1<<5)
  170. #define LIBIPW_OFDM_RATE_12MB_MASK (1<<6)
  171. #define LIBIPW_OFDM_RATE_18MB_MASK (1<<7)
  172. #define LIBIPW_OFDM_RATE_24MB_MASK (1<<8)
  173. #define LIBIPW_OFDM_RATE_36MB_MASK (1<<9)
  174. #define LIBIPW_OFDM_RATE_48MB_MASK (1<<10)
  175. #define LIBIPW_OFDM_RATE_54MB_MASK (1<<11)
  176. #define LIBIPW_CCK_RATES_MASK 0x0000000F
  177. #define LIBIPW_CCK_BASIC_RATES_MASK (LIBIPW_CCK_RATE_1MB_MASK | \
  178. LIBIPW_CCK_RATE_2MB_MASK)
  179. #define LIBIPW_CCK_DEFAULT_RATES_MASK (LIBIPW_CCK_BASIC_RATES_MASK | \
  180. LIBIPW_CCK_RATE_5MB_MASK | \
  181. LIBIPW_CCK_RATE_11MB_MASK)
  182. #define LIBIPW_OFDM_RATES_MASK 0x00000FF0
  183. #define LIBIPW_OFDM_BASIC_RATES_MASK (LIBIPW_OFDM_RATE_6MB_MASK | \
  184. LIBIPW_OFDM_RATE_12MB_MASK | \
  185. LIBIPW_OFDM_RATE_24MB_MASK)
  186. #define LIBIPW_OFDM_DEFAULT_RATES_MASK (LIBIPW_OFDM_BASIC_RATES_MASK | \
  187. LIBIPW_OFDM_RATE_9MB_MASK | \
  188. LIBIPW_OFDM_RATE_18MB_MASK | \
  189. LIBIPW_OFDM_RATE_36MB_MASK | \
  190. LIBIPW_OFDM_RATE_48MB_MASK | \
  191. LIBIPW_OFDM_RATE_54MB_MASK)
  192. #define LIBIPW_DEFAULT_RATES_MASK (LIBIPW_OFDM_DEFAULT_RATES_MASK | \
  193. LIBIPW_CCK_DEFAULT_RATES_MASK)
  194. #define LIBIPW_NUM_OFDM_RATES 8
  195. #define LIBIPW_NUM_CCK_RATES 4
  196. #define LIBIPW_OFDM_SHIFT_MASK_A 4
  197. /* NOTE: This data is for statistical purposes; not all hardware provides this
  198. * information for frames received.
  199. * For libipw_rx_mgt, you need to set at least the 'len' parameter.
  200. */
  201. struct libipw_rx_stats {
  202. u32 mac_time;
  203. s8 rssi;
  204. u8 signal;
  205. u8 noise;
  206. u16 rate; /* in 100 kbps */
  207. u8 received_channel;
  208. u8 control;
  209. u8 mask;
  210. u8 freq;
  211. u16 len;
  212. u64 tsf;
  213. u32 beacon_time;
  214. };
  215. /* IEEE 802.11 requires that STA supports concurrent reception of at least
  216. * three fragmented frames. This define can be increased to support more
  217. * concurrent frames, but it should be noted that each entry can consume about
  218. * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
  219. #define LIBIPW_FRAG_CACHE_LEN 4
  220. struct libipw_frag_entry {
  221. unsigned long first_frag_time;
  222. unsigned int seq;
  223. unsigned int last_frag;
  224. struct sk_buff *skb;
  225. u8 src_addr[ETH_ALEN];
  226. u8 dst_addr[ETH_ALEN];
  227. };
  228. struct libipw_stats {
  229. unsigned int tx_unicast_frames;
  230. unsigned int tx_multicast_frames;
  231. unsigned int tx_fragments;
  232. unsigned int tx_unicast_octets;
  233. unsigned int tx_multicast_octets;
  234. unsigned int tx_deferred_transmissions;
  235. unsigned int tx_single_retry_frames;
  236. unsigned int tx_multiple_retry_frames;
  237. unsigned int tx_retry_limit_exceeded;
  238. unsigned int tx_discards;
  239. unsigned int rx_unicast_frames;
  240. unsigned int rx_multicast_frames;
  241. unsigned int rx_fragments;
  242. unsigned int rx_unicast_octets;
  243. unsigned int rx_multicast_octets;
  244. unsigned int rx_fcs_errors;
  245. unsigned int rx_discards_no_buffer;
  246. unsigned int tx_discards_wrong_sa;
  247. unsigned int rx_discards_undecryptable;
  248. unsigned int rx_message_in_msg_fragments;
  249. unsigned int rx_message_in_bad_msg_fragments;
  250. };
  251. struct libipw_device;
  252. #define SEC_KEY_1 (1<<0)
  253. #define SEC_KEY_2 (1<<1)
  254. #define SEC_KEY_3 (1<<2)
  255. #define SEC_KEY_4 (1<<3)
  256. #define SEC_ACTIVE_KEY (1<<4)
  257. #define SEC_AUTH_MODE (1<<5)
  258. #define SEC_UNICAST_GROUP (1<<6)
  259. #define SEC_LEVEL (1<<7)
  260. #define SEC_ENABLED (1<<8)
  261. #define SEC_ENCRYPT (1<<9)
  262. #define SEC_LEVEL_0 0 /* None */
  263. #define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */
  264. #define SEC_LEVEL_2 2 /* Level 1 + TKIP */
  265. #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
  266. #define SEC_LEVEL_3 4 /* Level 2 + CCMP */
  267. #define SEC_ALG_NONE 0
  268. #define SEC_ALG_WEP 1
  269. #define SEC_ALG_TKIP 2
  270. #define SEC_ALG_CCMP 3
  271. #define WEP_KEYS 4
  272. #define WEP_KEY_LEN 13
  273. #define SCM_KEY_LEN 32
  274. #define SCM_TEMPORAL_KEY_LENGTH 16
  275. struct libipw_security {
  276. u16 active_key:2, enabled:1, unicast_uses_group:1, encrypt:1;
  277. u8 auth_mode;
  278. u8 encode_alg[WEP_KEYS];
  279. u8 key_sizes[WEP_KEYS];
  280. u8 keys[WEP_KEYS][SCM_KEY_LEN];
  281. u8 level;
  282. u16 flags;
  283. } __attribute__ ((packed));
  284. /*
  285. 802.11 data frame from AP
  286. ,-------------------------------------------------------------------.
  287. Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
  288. |------|------|---------|---------|---------|------|---------|------|
  289. Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs |
  290. | | tion | (BSSID) | | | ence | data | |
  291. `-------------------------------------------------------------------'
  292. Total: 28-2340 bytes
  293. */
  294. #define BEACON_PROBE_SSID_ID_POSITION 12
  295. struct libipw_hdr_1addr {
  296. __le16 frame_ctl;
  297. __le16 duration_id;
  298. u8 addr1[ETH_ALEN];
  299. u8 payload[0];
  300. } __attribute__ ((packed));
  301. struct libipw_hdr_2addr {
  302. __le16 frame_ctl;
  303. __le16 duration_id;
  304. u8 addr1[ETH_ALEN];
  305. u8 addr2[ETH_ALEN];
  306. u8 payload[0];
  307. } __attribute__ ((packed));
  308. struct libipw_hdr_3addr {
  309. __le16 frame_ctl;
  310. __le16 duration_id;
  311. u8 addr1[ETH_ALEN];
  312. u8 addr2[ETH_ALEN];
  313. u8 addr3[ETH_ALEN];
  314. __le16 seq_ctl;
  315. u8 payload[0];
  316. } __attribute__ ((packed));
  317. struct libipw_hdr_4addr {
  318. __le16 frame_ctl;
  319. __le16 duration_id;
  320. u8 addr1[ETH_ALEN];
  321. u8 addr2[ETH_ALEN];
  322. u8 addr3[ETH_ALEN];
  323. __le16 seq_ctl;
  324. u8 addr4[ETH_ALEN];
  325. u8 payload[0];
  326. } __attribute__ ((packed));
  327. struct libipw_hdr_3addrqos {
  328. __le16 frame_ctl;
  329. __le16 duration_id;
  330. u8 addr1[ETH_ALEN];
  331. u8 addr2[ETH_ALEN];
  332. u8 addr3[ETH_ALEN];
  333. __le16 seq_ctl;
  334. u8 payload[0];
  335. __le16 qos_ctl;
  336. } __attribute__ ((packed));
  337. struct libipw_info_element {
  338. u8 id;
  339. u8 len;
  340. u8 data[0];
  341. } __attribute__ ((packed));
  342. /*
  343. * These are the data types that can make up management packets
  344. *
  345. u16 auth_algorithm;
  346. u16 auth_sequence;
  347. u16 beacon_interval;
  348. u16 capability;
  349. u8 current_ap[ETH_ALEN];
  350. u16 listen_interval;
  351. struct {
  352. u16 association_id:14, reserved:2;
  353. } __attribute__ ((packed));
  354. u32 time_stamp[2];
  355. u16 reason;
  356. u16 status;
  357. */
  358. struct libipw_auth {
  359. struct libipw_hdr_3addr header;
  360. __le16 algorithm;
  361. __le16 transaction;
  362. __le16 status;
  363. /* challenge */
  364. struct libipw_info_element info_element[0];
  365. } __attribute__ ((packed));
  366. struct libipw_channel_switch {
  367. u8 id;
  368. u8 len;
  369. u8 mode;
  370. u8 channel;
  371. u8 count;
  372. } __attribute__ ((packed));
  373. struct libipw_action {
  374. struct libipw_hdr_3addr header;
  375. u8 category;
  376. u8 action;
  377. union {
  378. struct libipw_action_exchange {
  379. u8 token;
  380. struct libipw_info_element info_element[0];
  381. } exchange;
  382. struct libipw_channel_switch channel_switch;
  383. } format;
  384. } __attribute__ ((packed));
  385. struct libipw_disassoc {
  386. struct libipw_hdr_3addr header;
  387. __le16 reason;
  388. } __attribute__ ((packed));
  389. /* Alias deauth for disassoc */
  390. #define libipw_deauth libipw_disassoc
  391. struct libipw_probe_request {
  392. struct libipw_hdr_3addr header;
  393. /* SSID, supported rates */
  394. struct libipw_info_element info_element[0];
  395. } __attribute__ ((packed));
  396. struct libipw_probe_response {
  397. struct libipw_hdr_3addr header;
  398. __le32 time_stamp[2];
  399. __le16 beacon_interval;
  400. __le16 capability;
  401. /* SSID, supported rates, FH params, DS params,
  402. * CF params, IBSS params, TIM (if beacon), RSN */
  403. struct libipw_info_element info_element[0];
  404. } __attribute__ ((packed));
  405. /* Alias beacon for probe_response */
  406. #define libipw_beacon libipw_probe_response
  407. struct libipw_assoc_request {
  408. struct libipw_hdr_3addr header;
  409. __le16 capability;
  410. __le16 listen_interval;
  411. /* SSID, supported rates, RSN */
  412. struct libipw_info_element info_element[0];
  413. } __attribute__ ((packed));
  414. struct libipw_reassoc_request {
  415. struct libipw_hdr_3addr header;
  416. __le16 capability;
  417. __le16 listen_interval;
  418. u8 current_ap[ETH_ALEN];
  419. struct libipw_info_element info_element[0];
  420. } __attribute__ ((packed));
  421. struct libipw_assoc_response {
  422. struct libipw_hdr_3addr header;
  423. __le16 capability;
  424. __le16 status;
  425. __le16 aid;
  426. /* supported rates */
  427. struct libipw_info_element info_element[0];
  428. } __attribute__ ((packed));
  429. struct libipw_txb {
  430. u8 nr_frags;
  431. u8 encrypted;
  432. u8 rts_included;
  433. u8 reserved;
  434. u16 frag_size;
  435. u16 payload_size;
  436. struct sk_buff *fragments[0];
  437. };
  438. /* SWEEP TABLE ENTRIES NUMBER */
  439. #define MAX_SWEEP_TAB_ENTRIES 42
  440. #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET 7
  441. /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
  442. * only use 8, and then use extended rates for the remaining supported
  443. * rates. Other APs, however, stick all of their supported rates on the
  444. * main rates information element... */
  445. #define MAX_RATES_LENGTH ((u8)12)
  446. #define MAX_RATES_EX_LENGTH ((u8)16)
  447. #define MAX_NETWORK_COUNT 128
  448. #define CRC_LENGTH 4U
  449. #define MAX_WPA_IE_LEN 64
  450. #define NETWORK_HAS_OFDM (1<<1)
  451. #define NETWORK_HAS_CCK (1<<2)
  452. /* QoS structure */
  453. #define NETWORK_HAS_QOS_PARAMETERS (1<<3)
  454. #define NETWORK_HAS_QOS_INFORMATION (1<<4)
  455. #define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \
  456. NETWORK_HAS_QOS_INFORMATION)
  457. /* 802.11h */
  458. #define NETWORK_HAS_POWER_CONSTRAINT (1<<5)
  459. #define NETWORK_HAS_CSA (1<<6)
  460. #define NETWORK_HAS_QUIET (1<<7)
  461. #define NETWORK_HAS_IBSS_DFS (1<<8)
  462. #define NETWORK_HAS_TPC_REPORT (1<<9)
  463. #define NETWORK_HAS_ERP_VALUE (1<<10)
  464. #define QOS_QUEUE_NUM 4
  465. #define QOS_OUI_LEN 3
  466. #define QOS_OUI_TYPE 2
  467. #define QOS_ELEMENT_ID 221
  468. #define QOS_OUI_INFO_SUB_TYPE 0
  469. #define QOS_OUI_PARAM_SUB_TYPE 1
  470. #define QOS_VERSION_1 1
  471. #define QOS_AIFSN_MIN_VALUE 2
  472. struct libipw_qos_information_element {
  473. u8 elementID;
  474. u8 length;
  475. u8 qui[QOS_OUI_LEN];
  476. u8 qui_type;
  477. u8 qui_subtype;
  478. u8 version;
  479. u8 ac_info;
  480. } __attribute__ ((packed));
  481. struct libipw_qos_ac_parameter {
  482. u8 aci_aifsn;
  483. u8 ecw_min_max;
  484. __le16 tx_op_limit;
  485. } __attribute__ ((packed));
  486. struct libipw_qos_parameter_info {
  487. struct libipw_qos_information_element info_element;
  488. u8 reserved;
  489. struct libipw_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
  490. } __attribute__ ((packed));
  491. struct libipw_qos_parameters {
  492. __le16 cw_min[QOS_QUEUE_NUM];
  493. __le16 cw_max[QOS_QUEUE_NUM];
  494. u8 aifs[QOS_QUEUE_NUM];
  495. u8 flag[QOS_QUEUE_NUM];
  496. __le16 tx_op_limit[QOS_QUEUE_NUM];
  497. } __attribute__ ((packed));
  498. struct libipw_qos_data {
  499. struct libipw_qos_parameters parameters;
  500. int active;
  501. int supported;
  502. u8 param_count;
  503. u8 old_param_count;
  504. };
  505. struct libipw_tim_parameters {
  506. u8 tim_count;
  507. u8 tim_period;
  508. } __attribute__ ((packed));
  509. /*******************************************************/
  510. enum { /* libipw_basic_report.map */
  511. LIBIPW_BASIC_MAP_BSS = (1 << 0),
  512. LIBIPW_BASIC_MAP_OFDM = (1 << 1),
  513. LIBIPW_BASIC_MAP_UNIDENTIFIED = (1 << 2),
  514. LIBIPW_BASIC_MAP_RADAR = (1 << 3),
  515. LIBIPW_BASIC_MAP_UNMEASURED = (1 << 4),
  516. /* Bits 5-7 are reserved */
  517. };
  518. struct libipw_basic_report {
  519. u8 channel;
  520. __le64 start_time;
  521. __le16 duration;
  522. u8 map;
  523. } __attribute__ ((packed));
  524. enum { /* libipw_measurement_request.mode */
  525. /* Bit 0 is reserved */
  526. LIBIPW_MEASUREMENT_ENABLE = (1 << 1),
  527. LIBIPW_MEASUREMENT_REQUEST = (1 << 2),
  528. LIBIPW_MEASUREMENT_REPORT = (1 << 3),
  529. /* Bits 4-7 are reserved */
  530. };
  531. enum {
  532. LIBIPW_REPORT_BASIC = 0, /* required */
  533. LIBIPW_REPORT_CCA = 1, /* optional */
  534. LIBIPW_REPORT_RPI = 2, /* optional */
  535. /* 3-255 reserved */
  536. };
  537. struct libipw_measurement_params {
  538. u8 channel;
  539. __le64 start_time;
  540. __le16 duration;
  541. } __attribute__ ((packed));
  542. struct libipw_measurement_request {
  543. struct libipw_info_element ie;
  544. u8 token;
  545. u8 mode;
  546. u8 type;
  547. struct libipw_measurement_params params[0];
  548. } __attribute__ ((packed));
  549. struct libipw_measurement_report {
  550. struct libipw_info_element ie;
  551. u8 token;
  552. u8 mode;
  553. u8 type;
  554. union {
  555. struct libipw_basic_report basic[0];
  556. } u;
  557. } __attribute__ ((packed));
  558. struct libipw_tpc_report {
  559. u8 transmit_power;
  560. u8 link_margin;
  561. } __attribute__ ((packed));
  562. struct libipw_channel_map {
  563. u8 channel;
  564. u8 map;
  565. } __attribute__ ((packed));
  566. struct libipw_ibss_dfs {
  567. struct libipw_info_element ie;
  568. u8 owner[ETH_ALEN];
  569. u8 recovery_interval;
  570. struct libipw_channel_map channel_map[0];
  571. };
  572. struct libipw_csa {
  573. u8 mode;
  574. u8 channel;
  575. u8 count;
  576. } __attribute__ ((packed));
  577. struct libipw_quiet {
  578. u8 count;
  579. u8 period;
  580. u8 duration;
  581. u8 offset;
  582. } __attribute__ ((packed));
  583. struct libipw_network {
  584. /* These entries are used to identify a unique network */
  585. u8 bssid[ETH_ALEN];
  586. u8 channel;
  587. /* Ensure null-terminated for any debug msgs */
  588. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  589. u8 ssid_len;
  590. struct libipw_qos_data qos_data;
  591. /* These are network statistics */
  592. struct libipw_rx_stats stats;
  593. u16 capability;
  594. u8 rates[MAX_RATES_LENGTH];
  595. u8 rates_len;
  596. u8 rates_ex[MAX_RATES_EX_LENGTH];
  597. u8 rates_ex_len;
  598. unsigned long last_scanned;
  599. u8 mode;
  600. u32 flags;
  601. u32 last_associate;
  602. u32 time_stamp[2];
  603. u16 beacon_interval;
  604. u16 listen_interval;
  605. u16 atim_window;
  606. u8 erp_value;
  607. u8 wpa_ie[MAX_WPA_IE_LEN];
  608. size_t wpa_ie_len;
  609. u8 rsn_ie[MAX_WPA_IE_LEN];
  610. size_t rsn_ie_len;
  611. struct libipw_tim_parameters tim;
  612. /* 802.11h info */
  613. /* Power Constraint - mandatory if spctrm mgmt required */
  614. u8 power_constraint;
  615. /* TPC Report - mandatory if spctrm mgmt required */
  616. struct libipw_tpc_report tpc_report;
  617. /* IBSS DFS - mandatory if spctrm mgmt required and IBSS
  618. * NOTE: This is variable length and so must be allocated dynamically */
  619. struct libipw_ibss_dfs *ibss_dfs;
  620. /* Channel Switch Announcement - optional if spctrm mgmt required */
  621. struct libipw_csa csa;
  622. /* Quiet - optional if spctrm mgmt required */
  623. struct libipw_quiet quiet;
  624. struct list_head list;
  625. };
  626. enum libipw_state {
  627. LIBIPW_UNINITIALIZED = 0,
  628. LIBIPW_INITIALIZED,
  629. LIBIPW_ASSOCIATING,
  630. LIBIPW_ASSOCIATED,
  631. LIBIPW_AUTHENTICATING,
  632. LIBIPW_AUTHENTICATED,
  633. LIBIPW_SHUTDOWN
  634. };
  635. #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
  636. #define DEFAULT_FTS 2346
  637. #define CFG_LIBIPW_RESERVE_FCS (1<<0)
  638. #define CFG_LIBIPW_COMPUTE_FCS (1<<1)
  639. #define CFG_LIBIPW_RTS (1<<2)
  640. #define LIBIPW_24GHZ_MIN_CHANNEL 1
  641. #define LIBIPW_24GHZ_MAX_CHANNEL 14
  642. #define LIBIPW_24GHZ_CHANNELS (LIBIPW_24GHZ_MAX_CHANNEL - \
  643. LIBIPW_24GHZ_MIN_CHANNEL + 1)
  644. #define LIBIPW_52GHZ_MIN_CHANNEL 34
  645. #define LIBIPW_52GHZ_MAX_CHANNEL 165
  646. #define LIBIPW_52GHZ_CHANNELS (LIBIPW_52GHZ_MAX_CHANNEL - \
  647. LIBIPW_52GHZ_MIN_CHANNEL + 1)
  648. enum {
  649. LIBIPW_CH_PASSIVE_ONLY = (1 << 0),
  650. LIBIPW_CH_80211H_RULES = (1 << 1),
  651. LIBIPW_CH_B_ONLY = (1 << 2),
  652. LIBIPW_CH_NO_IBSS = (1 << 3),
  653. LIBIPW_CH_UNIFORM_SPREADING = (1 << 4),
  654. LIBIPW_CH_RADAR_DETECT = (1 << 5),
  655. LIBIPW_CH_INVALID = (1 << 6),
  656. };
  657. struct libipw_channel {
  658. u32 freq; /* in MHz */
  659. u8 channel;
  660. u8 flags;
  661. u8 max_power; /* in dBm */
  662. };
  663. struct libipw_geo {
  664. u8 name[4];
  665. u8 bg_channels;
  666. u8 a_channels;
  667. struct libipw_channel bg[LIBIPW_24GHZ_CHANNELS];
  668. struct libipw_channel a[LIBIPW_52GHZ_CHANNELS];
  669. };
  670. struct libipw_device {
  671. struct net_device *dev;
  672. struct wireless_dev wdev;
  673. struct libipw_security sec;
  674. /* Bookkeeping structures */
  675. struct libipw_stats ieee_stats;
  676. struct libipw_geo geo;
  677. struct ieee80211_supported_band bg_band;
  678. struct ieee80211_supported_band a_band;
  679. /* Probe / Beacon management */
  680. struct list_head network_free_list;
  681. struct list_head network_list;
  682. struct libipw_network *networks;
  683. int scans;
  684. int scan_age;
  685. int iw_mode; /* operating mode (IW_MODE_*) */
  686. struct iw_spy_data spy_data; /* iwspy support */
  687. spinlock_t lock;
  688. int tx_headroom; /* Set to size of any additional room needed at front
  689. * of allocated Tx SKBs */
  690. u32 config;
  691. /* WEP and other encryption related settings at the device level */
  692. int open_wep; /* Set to 1 to allow unencrypted frames */
  693. int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
  694. * WEP key changes */
  695. /* If the host performs {en,de}cryption, then set to 1 */
  696. int host_encrypt;
  697. int host_encrypt_msdu;
  698. int host_decrypt;
  699. /* host performs multicast decryption */
  700. int host_mc_decrypt;
  701. /* host should strip IV and ICV from protected frames */
  702. /* meaningful only when hardware decryption is being used */
  703. int host_strip_iv_icv;
  704. int host_open_frag;
  705. int host_build_iv;
  706. int ieee802_1x; /* is IEEE 802.1X used */
  707. /* WPA data */
  708. int wpa_enabled;
  709. int drop_unencrypted;
  710. int privacy_invoked;
  711. size_t wpa_ie_len;
  712. u8 *wpa_ie;
  713. struct lib80211_crypt_info crypt_info;
  714. int bcrx_sta_key; /* use individual keys to override default keys even
  715. * with RX of broad/multicast frames */
  716. /* Fragmentation structures */
  717. struct libipw_frag_entry frag_cache[LIBIPW_FRAG_CACHE_LEN];
  718. unsigned int frag_next_idx;
  719. u16 fts; /* Fragmentation Threshold */
  720. u16 rts; /* RTS threshold */
  721. /* Association info */
  722. u8 bssid[ETH_ALEN];
  723. enum libipw_state state;
  724. int mode; /* A, B, G */
  725. int modulation; /* CCK, OFDM */
  726. int freq_band; /* 2.4Ghz, 5.2Ghz, Mixed */
  727. int abg_true; /* ABG flag */
  728. int perfect_rssi;
  729. int worst_rssi;
  730. u16 prev_seq_ctl; /* used to drop duplicate frames */
  731. /* Callback functions */
  732. void (*set_security) (struct net_device * dev,
  733. struct libipw_security * sec);
  734. netdev_tx_t (*hard_start_xmit) (struct libipw_txb * txb,
  735. struct net_device * dev, int pri);
  736. int (*reset_port) (struct net_device * dev);
  737. int (*is_queue_full) (struct net_device * dev, int pri);
  738. int (*handle_management) (struct net_device * dev,
  739. struct libipw_network * network, u16 type);
  740. int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
  741. /* Typical STA methods */
  742. int (*handle_auth) (struct net_device * dev,
  743. struct libipw_auth * auth);
  744. int (*handle_deauth) (struct net_device * dev,
  745. struct libipw_deauth * auth);
  746. int (*handle_action) (struct net_device * dev,
  747. struct libipw_action * action,
  748. struct libipw_rx_stats * stats);
  749. int (*handle_disassoc) (struct net_device * dev,
  750. struct libipw_disassoc * assoc);
  751. int (*handle_beacon) (struct net_device * dev,
  752. struct libipw_beacon * beacon,
  753. struct libipw_network * network);
  754. int (*handle_probe_response) (struct net_device * dev,
  755. struct libipw_probe_response * resp,
  756. struct libipw_network * network);
  757. int (*handle_probe_request) (struct net_device * dev,
  758. struct libipw_probe_request * req,
  759. struct libipw_rx_stats * stats);
  760. int (*handle_assoc_response) (struct net_device * dev,
  761. struct libipw_assoc_response * resp,
  762. struct libipw_network * network);
  763. /* Typical AP methods */
  764. int (*handle_assoc_request) (struct net_device * dev);
  765. int (*handle_reassoc_request) (struct net_device * dev,
  766. struct libipw_reassoc_request * req);
  767. /* This must be the last item so that it points to the data
  768. * allocated beyond this structure by alloc_ieee80211 */
  769. u8 priv[0];
  770. };
  771. #define IEEE_A (1<<0)
  772. #define IEEE_B (1<<1)
  773. #define IEEE_G (1<<2)
  774. #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G)
  775. static inline void *libipw_priv(struct net_device *dev)
  776. {
  777. return ((struct libipw_device *)netdev_priv(dev))->priv;
  778. }
  779. static inline int libipw_is_valid_mode(struct libipw_device *ieee,
  780. int mode)
  781. {
  782. /*
  783. * It is possible for both access points and our device to support
  784. * combinations of modes, so as long as there is one valid combination
  785. * of ap/device supported modes, then return success
  786. *
  787. */
  788. if ((mode & IEEE_A) &&
  789. (ieee->modulation & LIBIPW_OFDM_MODULATION) &&
  790. (ieee->freq_band & LIBIPW_52GHZ_BAND))
  791. return 1;
  792. if ((mode & IEEE_G) &&
  793. (ieee->modulation & LIBIPW_OFDM_MODULATION) &&
  794. (ieee->freq_band & LIBIPW_24GHZ_BAND))
  795. return 1;
  796. if ((mode & IEEE_B) &&
  797. (ieee->modulation & LIBIPW_CCK_MODULATION) &&
  798. (ieee->freq_band & LIBIPW_24GHZ_BAND))
  799. return 1;
  800. return 0;
  801. }
  802. static inline int libipw_get_hdrlen(u16 fc)
  803. {
  804. int hdrlen = LIBIPW_3ADDR_LEN;
  805. u16 stype = WLAN_FC_GET_STYPE(fc);
  806. switch (WLAN_FC_GET_TYPE(fc)) {
  807. case IEEE80211_FTYPE_DATA:
  808. if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
  809. hdrlen = LIBIPW_4ADDR_LEN;
  810. if (stype & IEEE80211_STYPE_QOS_DATA)
  811. hdrlen += 2;
  812. break;
  813. case IEEE80211_FTYPE_CTL:
  814. switch (WLAN_FC_GET_STYPE(fc)) {
  815. case IEEE80211_STYPE_CTS:
  816. case IEEE80211_STYPE_ACK:
  817. hdrlen = LIBIPW_1ADDR_LEN;
  818. break;
  819. default:
  820. hdrlen = LIBIPW_2ADDR_LEN;
  821. break;
  822. }
  823. break;
  824. }
  825. return hdrlen;
  826. }
  827. static inline u8 *libipw_get_payload(struct ieee80211_hdr *hdr)
  828. {
  829. switch (libipw_get_hdrlen(le16_to_cpu(hdr->frame_control))) {
  830. case LIBIPW_1ADDR_LEN:
  831. return ((struct libipw_hdr_1addr *)hdr)->payload;
  832. case LIBIPW_2ADDR_LEN:
  833. return ((struct libipw_hdr_2addr *)hdr)->payload;
  834. case LIBIPW_3ADDR_LEN:
  835. return ((struct libipw_hdr_3addr *)hdr)->payload;
  836. case LIBIPW_4ADDR_LEN:
  837. return ((struct libipw_hdr_4addr *)hdr)->payload;
  838. }
  839. return NULL;
  840. }
  841. static inline int libipw_is_ofdm_rate(u8 rate)
  842. {
  843. switch (rate & ~LIBIPW_BASIC_RATE_MASK) {
  844. case LIBIPW_OFDM_RATE_6MB:
  845. case LIBIPW_OFDM_RATE_9MB:
  846. case LIBIPW_OFDM_RATE_12MB:
  847. case LIBIPW_OFDM_RATE_18MB:
  848. case LIBIPW_OFDM_RATE_24MB:
  849. case LIBIPW_OFDM_RATE_36MB:
  850. case LIBIPW_OFDM_RATE_48MB:
  851. case LIBIPW_OFDM_RATE_54MB:
  852. return 1;
  853. }
  854. return 0;
  855. }
  856. static inline int libipw_is_cck_rate(u8 rate)
  857. {
  858. switch (rate & ~LIBIPW_BASIC_RATE_MASK) {
  859. case LIBIPW_CCK_RATE_1MB:
  860. case LIBIPW_CCK_RATE_2MB:
  861. case LIBIPW_CCK_RATE_5MB:
  862. case LIBIPW_CCK_RATE_11MB:
  863. return 1;
  864. }
  865. return 0;
  866. }
  867. /* ieee80211.c */
  868. extern void free_ieee80211(struct net_device *dev, int monitor);
  869. extern struct net_device *alloc_ieee80211(int sizeof_priv, int monitor);
  870. extern void unregister_ieee80211(struct libipw_device *ieee);
  871. extern int libipw_change_mtu(struct net_device *dev, int new_mtu);
  872. extern void libipw_networks_age(struct libipw_device *ieee,
  873. unsigned long age_secs);
  874. extern int libipw_set_encryption(struct libipw_device *ieee);
  875. /* libipw_tx.c */
  876. extern netdev_tx_t libipw_xmit(struct sk_buff *skb,
  877. struct net_device *dev);
  878. extern void libipw_txb_free(struct libipw_txb *);
  879. /* libipw_rx.c */
  880. extern void libipw_rx_any(struct libipw_device *ieee,
  881. struct sk_buff *skb, struct libipw_rx_stats *stats);
  882. extern int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
  883. struct libipw_rx_stats *rx_stats);
  884. /* make sure to set stats->len */
  885. extern void libipw_rx_mgt(struct libipw_device *ieee,
  886. struct libipw_hdr_4addr *header,
  887. struct libipw_rx_stats *stats);
  888. extern void libipw_network_reset(struct libipw_network *network);
  889. /* libipw_geo.c */
  890. extern const struct libipw_geo *libipw_get_geo(struct libipw_device
  891. *ieee);
  892. extern int libipw_set_geo(struct libipw_device *ieee,
  893. const struct libipw_geo *geo);
  894. extern int libipw_is_valid_channel(struct libipw_device *ieee,
  895. u8 channel);
  896. extern int libipw_channel_to_index(struct libipw_device *ieee,
  897. u8 channel);
  898. extern u8 libipw_freq_to_channel(struct libipw_device *ieee, u32 freq);
  899. extern u8 libipw_get_channel_flags(struct libipw_device *ieee,
  900. u8 channel);
  901. extern const struct libipw_channel *libipw_get_channel(struct
  902. libipw_device
  903. *ieee, u8 channel);
  904. extern u32 libipw_channel_to_freq(struct libipw_device * ieee,
  905. u8 channel);
  906. /* libipw_wx.c */
  907. extern int libipw_wx_get_scan(struct libipw_device *ieee,
  908. struct iw_request_info *info,
  909. union iwreq_data *wrqu, char *key);
  910. extern int libipw_wx_set_encode(struct libipw_device *ieee,
  911. struct iw_request_info *info,
  912. union iwreq_data *wrqu, char *key);
  913. extern int libipw_wx_get_encode(struct libipw_device *ieee,
  914. struct iw_request_info *info,
  915. union iwreq_data *wrqu, char *key);
  916. extern int libipw_wx_set_encodeext(struct libipw_device *ieee,
  917. struct iw_request_info *info,
  918. union iwreq_data *wrqu, char *extra);
  919. extern int libipw_wx_get_encodeext(struct libipw_device *ieee,
  920. struct iw_request_info *info,
  921. union iwreq_data *wrqu, char *extra);
  922. static inline void libipw_increment_scans(struct libipw_device *ieee)
  923. {
  924. ieee->scans++;
  925. }
  926. static inline int libipw_get_scans(struct libipw_device *ieee)
  927. {
  928. return ieee->scans;
  929. }
  930. #endif /* LIBIPW_H */