libipw.h 30 KB

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