libipw.h 27 KB

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