libipw_rx.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. /*
  2. * Original code based Host AP (software wireless LAN access point) driver
  3. * for Intersil Prism2/2.5/3 - hostap.o module, common routines
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <j@w1.fi>
  7. * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
  8. * Copyright (c) 2004-2005, Intel Corporation
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation. See README and COPYING for
  13. * more details.
  14. */
  15. #include <linux/compiler.h>
  16. #include <linux/errno.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/in6.h>
  19. #include <linux/gfp.h>
  20. #include <linux/in.h>
  21. #include <linux/ip.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/tcp.h>
  28. #include <linux/types.h>
  29. #include <linux/wireless.h>
  30. #include <linux/etherdevice.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/ctype.h>
  33. #include <net/lib80211.h>
  34. #include "libipw.h"
  35. static void libipw_monitor_rx(struct libipw_device *ieee,
  36. struct sk_buff *skb,
  37. struct libipw_rx_stats *rx_stats)
  38. {
  39. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  40. u16 fc = le16_to_cpu(hdr->frame_control);
  41. skb->dev = ieee->dev;
  42. skb_reset_mac_header(skb);
  43. skb_pull(skb, libipw_get_hdrlen(fc));
  44. skb->pkt_type = PACKET_OTHERHOST;
  45. skb->protocol = htons(ETH_P_80211_RAW);
  46. memset(skb->cb, 0, sizeof(skb->cb));
  47. netif_rx(skb);
  48. }
  49. /* Called only as a tasklet (software IRQ) */
  50. static struct libipw_frag_entry *libipw_frag_cache_find(struct
  51. libipw_device
  52. *ieee,
  53. unsigned int seq,
  54. unsigned int frag,
  55. u8 * src,
  56. u8 * dst)
  57. {
  58. struct libipw_frag_entry *entry;
  59. int i;
  60. for (i = 0; i < LIBIPW_FRAG_CACHE_LEN; i++) {
  61. entry = &ieee->frag_cache[i];
  62. if (entry->skb != NULL &&
  63. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  64. LIBIPW_DEBUG_FRAG("expiring fragment cache entry "
  65. "seq=%u last_frag=%u\n",
  66. entry->seq, entry->last_frag);
  67. dev_kfree_skb_any(entry->skb);
  68. entry->skb = NULL;
  69. }
  70. if (entry->skb != NULL && entry->seq == seq &&
  71. (entry->last_frag + 1 == frag || frag == -1) &&
  72. ether_addr_equal(entry->src_addr, src) &&
  73. ether_addr_equal(entry->dst_addr, dst))
  74. return entry;
  75. }
  76. return NULL;
  77. }
  78. /* Called only as a tasklet (software IRQ) */
  79. static struct sk_buff *libipw_frag_cache_get(struct libipw_device *ieee,
  80. struct libipw_hdr_4addr *hdr)
  81. {
  82. struct sk_buff *skb = NULL;
  83. u16 sc;
  84. unsigned int frag, seq;
  85. struct libipw_frag_entry *entry;
  86. sc = le16_to_cpu(hdr->seq_ctl);
  87. frag = WLAN_GET_SEQ_FRAG(sc);
  88. seq = WLAN_GET_SEQ_SEQ(sc);
  89. if (frag == 0) {
  90. /* Reserve enough space to fit maximum frame length */
  91. skb = dev_alloc_skb(ieee->dev->mtu +
  92. sizeof(struct libipw_hdr_4addr) +
  93. 8 /* LLC */ +
  94. 2 /* alignment */ +
  95. 8 /* WEP */ + ETH_ALEN /* WDS */ );
  96. if (skb == NULL)
  97. return NULL;
  98. entry = &ieee->frag_cache[ieee->frag_next_idx];
  99. ieee->frag_next_idx++;
  100. if (ieee->frag_next_idx >= LIBIPW_FRAG_CACHE_LEN)
  101. ieee->frag_next_idx = 0;
  102. if (entry->skb != NULL)
  103. dev_kfree_skb_any(entry->skb);
  104. entry->first_frag_time = jiffies;
  105. entry->seq = seq;
  106. entry->last_frag = frag;
  107. entry->skb = skb;
  108. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  109. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  110. } else {
  111. /* received a fragment of a frame for which the head fragment
  112. * should have already been received */
  113. entry = libipw_frag_cache_find(ieee, seq, frag, hdr->addr2,
  114. hdr->addr1);
  115. if (entry != NULL) {
  116. entry->last_frag = frag;
  117. skb = entry->skb;
  118. }
  119. }
  120. return skb;
  121. }
  122. /* Called only as a tasklet (software IRQ) */
  123. static int libipw_frag_cache_invalidate(struct libipw_device *ieee,
  124. struct libipw_hdr_4addr *hdr)
  125. {
  126. u16 sc;
  127. unsigned int seq;
  128. struct libipw_frag_entry *entry;
  129. sc = le16_to_cpu(hdr->seq_ctl);
  130. seq = WLAN_GET_SEQ_SEQ(sc);
  131. entry = libipw_frag_cache_find(ieee, seq, -1, hdr->addr2,
  132. hdr->addr1);
  133. if (entry == NULL) {
  134. LIBIPW_DEBUG_FRAG("could not invalidate fragment cache "
  135. "entry (seq=%u)\n", seq);
  136. return -1;
  137. }
  138. entry->skb = NULL;
  139. return 0;
  140. }
  141. #ifdef NOT_YET
  142. /* libipw_rx_frame_mgtmt
  143. *
  144. * Responsible for handling management control frames
  145. *
  146. * Called by libipw_rx */
  147. static int
  148. libipw_rx_frame_mgmt(struct libipw_device *ieee, struct sk_buff *skb,
  149. struct libipw_rx_stats *rx_stats, u16 type,
  150. u16 stype)
  151. {
  152. if (ieee->iw_mode == IW_MODE_MASTER) {
  153. printk(KERN_DEBUG "%s: Master mode not yet supported.\n",
  154. ieee->dev->name);
  155. return 0;
  156. /*
  157. hostap_update_sta_ps(ieee, (struct hostap_libipw_hdr_4addr *)
  158. skb->data);*/
  159. }
  160. if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
  161. if (stype == WLAN_FC_STYPE_BEACON &&
  162. ieee->iw_mode == IW_MODE_MASTER) {
  163. struct sk_buff *skb2;
  164. /* Process beacon frames also in kernel driver to
  165. * update STA(AP) table statistics */
  166. skb2 = skb_clone(skb, GFP_ATOMIC);
  167. if (skb2)
  168. hostap_rx(skb2->dev, skb2, rx_stats);
  169. }
  170. /* send management frames to the user space daemon for
  171. * processing */
  172. ieee->apdevstats.rx_packets++;
  173. ieee->apdevstats.rx_bytes += skb->len;
  174. prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  175. return 0;
  176. }
  177. if (ieee->iw_mode == IW_MODE_MASTER) {
  178. if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
  179. printk(KERN_DEBUG "%s: unknown management frame "
  180. "(type=0x%02x, stype=0x%02x) dropped\n",
  181. skb->dev->name, type, stype);
  182. return -1;
  183. }
  184. hostap_rx(skb->dev, skb, rx_stats);
  185. return 0;
  186. }
  187. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
  188. "received in non-Host AP mode\n", skb->dev->name);
  189. return -1;
  190. }
  191. #endif
  192. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  193. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  194. static unsigned char libipw_rfc1042_header[] =
  195. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  196. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  197. static unsigned char libipw_bridge_tunnel_header[] =
  198. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  199. /* No encapsulation header if EtherType < 0x600 (=length) */
  200. /* Called by libipw_rx_frame_decrypt */
  201. static int libipw_is_eapol_frame(struct libipw_device *ieee,
  202. struct sk_buff *skb)
  203. {
  204. struct net_device *dev = ieee->dev;
  205. u16 fc, ethertype;
  206. struct libipw_hdr_3addr *hdr;
  207. u8 *pos;
  208. if (skb->len < 24)
  209. return 0;
  210. hdr = (struct libipw_hdr_3addr *)skb->data;
  211. fc = le16_to_cpu(hdr->frame_ctl);
  212. /* check that the frame is unicast frame to us */
  213. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  214. IEEE80211_FCTL_TODS &&
  215. ether_addr_equal(hdr->addr1, dev->dev_addr) &&
  216. ether_addr_equal(hdr->addr3, dev->dev_addr)) {
  217. /* ToDS frame with own addr BSSID and DA */
  218. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  219. IEEE80211_FCTL_FROMDS &&
  220. ether_addr_equal(hdr->addr1, dev->dev_addr)) {
  221. /* FromDS frame with own addr as DA */
  222. } else
  223. return 0;
  224. if (skb->len < 24 + 8)
  225. return 0;
  226. /* check for port access entity Ethernet type */
  227. pos = skb->data + 24;
  228. ethertype = (pos[6] << 8) | pos[7];
  229. if (ethertype == ETH_P_PAE)
  230. return 1;
  231. return 0;
  232. }
  233. /* Called only as a tasklet (software IRQ), by libipw_rx */
  234. static int
  235. libipw_rx_frame_decrypt(struct libipw_device *ieee, struct sk_buff *skb,
  236. struct lib80211_crypt_data *crypt)
  237. {
  238. struct libipw_hdr_3addr *hdr;
  239. int res, hdrlen;
  240. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  241. return 0;
  242. hdr = (struct libipw_hdr_3addr *)skb->data;
  243. hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  244. atomic_inc(&crypt->refcnt);
  245. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  246. atomic_dec(&crypt->refcnt);
  247. if (res < 0) {
  248. LIBIPW_DEBUG_DROP("decryption failed (SA=%pM) res=%d\n",
  249. hdr->addr2, res);
  250. if (res == -2)
  251. LIBIPW_DEBUG_DROP("Decryption failed ICV "
  252. "mismatch (key %d)\n",
  253. skb->data[hdrlen + 3] >> 6);
  254. ieee->ieee_stats.rx_discards_undecryptable++;
  255. return -1;
  256. }
  257. return res;
  258. }
  259. /* Called only as a tasklet (software IRQ), by libipw_rx */
  260. static int
  261. libipw_rx_frame_decrypt_msdu(struct libipw_device *ieee,
  262. struct sk_buff *skb, int keyidx,
  263. struct lib80211_crypt_data *crypt)
  264. {
  265. struct libipw_hdr_3addr *hdr;
  266. int res, hdrlen;
  267. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  268. return 0;
  269. hdr = (struct libipw_hdr_3addr *)skb->data;
  270. hdrlen = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  271. atomic_inc(&crypt->refcnt);
  272. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  273. atomic_dec(&crypt->refcnt);
  274. if (res < 0) {
  275. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  276. " (SA=%pM keyidx=%d)\n", ieee->dev->name, hdr->addr2,
  277. keyidx);
  278. return -1;
  279. }
  280. return 0;
  281. }
  282. /* All received frames are sent to this function. @skb contains the frame in
  283. * IEEE 802.11 format, i.e., in the format it was sent over air.
  284. * This function is called only as a tasklet (software IRQ). */
  285. int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
  286. struct libipw_rx_stats *rx_stats)
  287. {
  288. struct net_device *dev = ieee->dev;
  289. struct libipw_hdr_4addr *hdr;
  290. size_t hdrlen;
  291. u16 fc, type, stype, sc;
  292. unsigned int frag;
  293. u8 *payload;
  294. u16 ethertype;
  295. #ifdef NOT_YET
  296. struct net_device *wds = NULL;
  297. struct sk_buff *skb2 = NULL;
  298. struct net_device *wds = NULL;
  299. int frame_authorized = 0;
  300. int from_assoc_ap = 0;
  301. void *sta = NULL;
  302. #endif
  303. u8 dst[ETH_ALEN];
  304. u8 src[ETH_ALEN];
  305. struct lib80211_crypt_data *crypt = NULL;
  306. int keyidx = 0;
  307. int can_be_decrypted = 0;
  308. hdr = (struct libipw_hdr_4addr *)skb->data;
  309. if (skb->len < 10) {
  310. printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
  311. goto rx_dropped;
  312. }
  313. fc = le16_to_cpu(hdr->frame_ctl);
  314. type = WLAN_FC_GET_TYPE(fc);
  315. stype = WLAN_FC_GET_STYPE(fc);
  316. sc = le16_to_cpu(hdr->seq_ctl);
  317. frag = WLAN_GET_SEQ_FRAG(sc);
  318. hdrlen = libipw_get_hdrlen(fc);
  319. if (skb->len < hdrlen) {
  320. printk(KERN_INFO "%s: invalid SKB length %d\n",
  321. dev->name, skb->len);
  322. goto rx_dropped;
  323. }
  324. /* Put this code here so that we avoid duplicating it in all
  325. * Rx paths. - Jean II */
  326. #ifdef CONFIG_WIRELESS_EXT
  327. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  328. /* If spy monitoring on */
  329. if (ieee->spy_data.spy_number > 0) {
  330. struct iw_quality wstats;
  331. wstats.updated = 0;
  332. if (rx_stats->mask & LIBIPW_STATMASK_RSSI) {
  333. wstats.level = rx_stats->signal;
  334. wstats.updated |= IW_QUAL_LEVEL_UPDATED;
  335. } else
  336. wstats.updated |= IW_QUAL_LEVEL_INVALID;
  337. if (rx_stats->mask & LIBIPW_STATMASK_NOISE) {
  338. wstats.noise = rx_stats->noise;
  339. wstats.updated |= IW_QUAL_NOISE_UPDATED;
  340. } else
  341. wstats.updated |= IW_QUAL_NOISE_INVALID;
  342. if (rx_stats->mask & LIBIPW_STATMASK_SIGNAL) {
  343. wstats.qual = rx_stats->signal;
  344. wstats.updated |= IW_QUAL_QUAL_UPDATED;
  345. } else
  346. wstats.updated |= IW_QUAL_QUAL_INVALID;
  347. /* Update spy records */
  348. wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
  349. }
  350. #endif /* IW_WIRELESS_SPY */
  351. #endif /* CONFIG_WIRELESS_EXT */
  352. #ifdef NOT_YET
  353. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  354. #endif
  355. if (ieee->iw_mode == IW_MODE_MONITOR) {
  356. dev->stats.rx_packets++;
  357. dev->stats.rx_bytes += skb->len;
  358. libipw_monitor_rx(ieee, skb, rx_stats);
  359. return 1;
  360. }
  361. can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
  362. is_broadcast_ether_addr(hdr->addr2)) ?
  363. ieee->host_mc_decrypt : ieee->host_decrypt;
  364. if (can_be_decrypted) {
  365. if (skb->len >= hdrlen + 3) {
  366. /* Top two-bits of byte 3 are the key index */
  367. keyidx = skb->data[hdrlen + 3] >> 6;
  368. }
  369. /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
  370. * is only allowed 2-bits of storage, no value of keyidx can
  371. * be provided via above code that would result in keyidx
  372. * being out of range */
  373. crypt = ieee->crypt_info.crypt[keyidx];
  374. #ifdef NOT_YET
  375. sta = NULL;
  376. /* Use station specific key to override default keys if the
  377. * receiver address is a unicast address ("individual RA"). If
  378. * bcrx_sta_key parameter is set, station specific key is used
  379. * even with broad/multicast targets (this is against IEEE
  380. * 802.11, but makes it easier to use different keys with
  381. * stations that do not support WEP key mapping). */
  382. if (is_unicast_ether_addr(hdr->addr1) || local->bcrx_sta_key)
  383. (void)hostap_handle_sta_crypto(local, hdr, &crypt,
  384. &sta);
  385. #endif
  386. /* allow NULL decrypt to indicate an station specific override
  387. * for default encryption */
  388. if (crypt && (crypt->ops == NULL ||
  389. crypt->ops->decrypt_mpdu == NULL))
  390. crypt = NULL;
  391. if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
  392. /* This seems to be triggered by some (multicast?)
  393. * frames from other than current BSS, so just drop the
  394. * frames silently instead of filling system log with
  395. * these reports. */
  396. LIBIPW_DEBUG_DROP("Decryption failed (not set)"
  397. " (SA=%pM)\n", hdr->addr2);
  398. ieee->ieee_stats.rx_discards_undecryptable++;
  399. goto rx_dropped;
  400. }
  401. }
  402. #ifdef NOT_YET
  403. if (type != WLAN_FC_TYPE_DATA) {
  404. if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
  405. fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
  406. (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
  407. printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
  408. "from %pM\n", dev->name, hdr->addr2);
  409. /* TODO: could inform hostapd about this so that it
  410. * could send auth failure report */
  411. goto rx_dropped;
  412. }
  413. if (libipw_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
  414. goto rx_dropped;
  415. else
  416. goto rx_exit;
  417. }
  418. #endif
  419. /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
  420. if (sc == ieee->prev_seq_ctl)
  421. goto rx_dropped;
  422. else
  423. ieee->prev_seq_ctl = sc;
  424. /* Data frame - extract src/dst addresses */
  425. if (skb->len < LIBIPW_3ADDR_LEN)
  426. goto rx_dropped;
  427. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  428. case IEEE80211_FCTL_FROMDS:
  429. memcpy(dst, hdr->addr1, ETH_ALEN);
  430. memcpy(src, hdr->addr3, ETH_ALEN);
  431. break;
  432. case IEEE80211_FCTL_TODS:
  433. memcpy(dst, hdr->addr3, ETH_ALEN);
  434. memcpy(src, hdr->addr2, ETH_ALEN);
  435. break;
  436. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  437. if (skb->len < LIBIPW_4ADDR_LEN)
  438. goto rx_dropped;
  439. memcpy(dst, hdr->addr3, ETH_ALEN);
  440. memcpy(src, hdr->addr4, ETH_ALEN);
  441. break;
  442. case 0:
  443. memcpy(dst, hdr->addr1, ETH_ALEN);
  444. memcpy(src, hdr->addr2, ETH_ALEN);
  445. break;
  446. }
  447. #ifdef NOT_YET
  448. if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
  449. goto rx_dropped;
  450. if (wds) {
  451. skb->dev = dev = wds;
  452. stats = hostap_get_stats(dev);
  453. }
  454. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  455. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  456. IEEE80211_FCTL_FROMDS && ieee->stadev &&
  457. ether_addr_equal(hdr->addr2, ieee->assoc_ap_addr)) {
  458. /* Frame from BSSID of the AP for which we are a client */
  459. skb->dev = dev = ieee->stadev;
  460. stats = hostap_get_stats(dev);
  461. from_assoc_ap = 1;
  462. }
  463. #endif
  464. #ifdef NOT_YET
  465. if ((ieee->iw_mode == IW_MODE_MASTER ||
  466. ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
  467. switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
  468. wds != NULL)) {
  469. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  470. frame_authorized = 0;
  471. break;
  472. case AP_RX_CONTINUE:
  473. frame_authorized = 1;
  474. break;
  475. case AP_RX_DROP:
  476. goto rx_dropped;
  477. case AP_RX_EXIT:
  478. goto rx_exit;
  479. }
  480. }
  481. #endif
  482. /* Nullfunc frames may have PS-bit set, so they must be passed to
  483. * hostap_handle_sta_rx() before being dropped here. */
  484. stype &= ~IEEE80211_STYPE_QOS_DATA;
  485. if (stype != IEEE80211_STYPE_DATA &&
  486. stype != IEEE80211_STYPE_DATA_CFACK &&
  487. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  488. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  489. if (stype != IEEE80211_STYPE_NULLFUNC)
  490. LIBIPW_DEBUG_DROP("RX: dropped data frame "
  491. "with no data (type=0x%02x, "
  492. "subtype=0x%02x, len=%d)\n",
  493. type, stype, skb->len);
  494. goto rx_dropped;
  495. }
  496. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  497. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  498. (keyidx = libipw_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  499. goto rx_dropped;
  500. hdr = (struct libipw_hdr_4addr *)skb->data;
  501. /* skb: hdr + (possibly fragmented) plaintext payload */
  502. // PR: FIXME: hostap has additional conditions in the "if" below:
  503. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  504. if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
  505. int flen;
  506. struct sk_buff *frag_skb = libipw_frag_cache_get(ieee, hdr);
  507. LIBIPW_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  508. if (!frag_skb) {
  509. LIBIPW_DEBUG(LIBIPW_DL_RX | LIBIPW_DL_FRAG,
  510. "Rx cannot get skb from fragment "
  511. "cache (morefrag=%d seq=%u frag=%u)\n",
  512. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  513. WLAN_GET_SEQ_SEQ(sc), frag);
  514. goto rx_dropped;
  515. }
  516. flen = skb->len;
  517. if (frag != 0)
  518. flen -= hdrlen;
  519. if (frag_skb->tail + flen > frag_skb->end) {
  520. printk(KERN_WARNING "%s: host decrypted and "
  521. "reassembled frame did not fit skb\n",
  522. dev->name);
  523. libipw_frag_cache_invalidate(ieee, hdr);
  524. goto rx_dropped;
  525. }
  526. if (frag == 0) {
  527. /* copy first fragment (including full headers) into
  528. * beginning of the fragment cache skb */
  529. skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
  530. } else {
  531. /* append frame payload to the end of the fragment
  532. * cache skb */
  533. skb_copy_from_linear_data_offset(skb, hdrlen,
  534. skb_put(frag_skb, flen), flen);
  535. }
  536. dev_kfree_skb_any(skb);
  537. skb = NULL;
  538. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  539. /* more fragments expected - leave the skb in fragment
  540. * cache for now; it will be delivered to upper layers
  541. * after all fragments have been received */
  542. goto rx_exit;
  543. }
  544. /* this was the last fragment and the frame will be
  545. * delivered, so remove skb from fragment cache */
  546. skb = frag_skb;
  547. hdr = (struct libipw_hdr_4addr *)skb->data;
  548. libipw_frag_cache_invalidate(ieee, hdr);
  549. }
  550. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  551. * encrypted/authenticated */
  552. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  553. libipw_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  554. goto rx_dropped;
  555. hdr = (struct libipw_hdr_4addr *)skb->data;
  556. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  557. if ( /*ieee->ieee802_1x && */
  558. libipw_is_eapol_frame(ieee, skb)) {
  559. /* pass unencrypted EAPOL frames even if encryption is
  560. * configured */
  561. } else {
  562. LIBIPW_DEBUG_DROP("encryption configured, but RX "
  563. "frame not encrypted (SA=%pM)\n",
  564. hdr->addr2);
  565. goto rx_dropped;
  566. }
  567. }
  568. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  569. !libipw_is_eapol_frame(ieee, skb)) {
  570. LIBIPW_DEBUG_DROP("dropped unencrypted RX data "
  571. "frame from %pM (drop_unencrypted=1)\n",
  572. hdr->addr2);
  573. goto rx_dropped;
  574. }
  575. /* If the frame was decrypted in hardware, we may need to strip off
  576. * any security data (IV, ICV, etc) that was left behind */
  577. if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
  578. ieee->host_strip_iv_icv) {
  579. int trimlen = 0;
  580. /* Top two-bits of byte 3 are the key index */
  581. if (skb->len >= hdrlen + 3)
  582. keyidx = skb->data[hdrlen + 3] >> 6;
  583. /* To strip off any security data which appears before the
  584. * payload, we simply increase hdrlen (as the header gets
  585. * chopped off immediately below). For the security data which
  586. * appears after the payload, we use skb_trim. */
  587. switch (ieee->sec.encode_alg[keyidx]) {
  588. case SEC_ALG_WEP:
  589. /* 4 byte IV */
  590. hdrlen += 4;
  591. /* 4 byte ICV */
  592. trimlen = 4;
  593. break;
  594. case SEC_ALG_TKIP:
  595. /* 4 byte IV, 4 byte ExtIV */
  596. hdrlen += 8;
  597. /* 8 byte MIC, 4 byte ICV */
  598. trimlen = 12;
  599. break;
  600. case SEC_ALG_CCMP:
  601. /* 8 byte CCMP header */
  602. hdrlen += 8;
  603. /* 8 byte MIC */
  604. trimlen = 8;
  605. break;
  606. }
  607. if (skb->len < trimlen)
  608. goto rx_dropped;
  609. __skb_trim(skb, skb->len - trimlen);
  610. if (skb->len < hdrlen)
  611. goto rx_dropped;
  612. }
  613. /* skb: hdr + (possible reassembled) full plaintext payload */
  614. payload = skb->data + hdrlen;
  615. ethertype = (payload[6] << 8) | payload[7];
  616. #ifdef NOT_YET
  617. /* If IEEE 802.1X is used, check whether the port is authorized to send
  618. * the received frame. */
  619. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  620. if (ethertype == ETH_P_PAE) {
  621. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  622. dev->name);
  623. if (ieee->hostapd && ieee->apdev) {
  624. /* Send IEEE 802.1X frames to the user
  625. * space daemon for processing */
  626. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  627. PRISM2_RX_MGMT);
  628. ieee->apdevstats.rx_packets++;
  629. ieee->apdevstats.rx_bytes += skb->len;
  630. goto rx_exit;
  631. }
  632. } else if (!frame_authorized) {
  633. printk(KERN_DEBUG "%s: dropped frame from "
  634. "unauthorized port (IEEE 802.1X): "
  635. "ethertype=0x%04x\n", dev->name, ethertype);
  636. goto rx_dropped;
  637. }
  638. }
  639. #endif
  640. /* convert hdr + possible LLC headers into Ethernet header */
  641. if (skb->len - hdrlen >= 8 &&
  642. ((memcmp(payload, libipw_rfc1042_header, SNAP_SIZE) == 0 &&
  643. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  644. memcmp(payload, libipw_bridge_tunnel_header, SNAP_SIZE) == 0)) {
  645. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  646. * replace EtherType */
  647. skb_pull(skb, hdrlen + SNAP_SIZE);
  648. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  649. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  650. } else {
  651. __be16 len;
  652. /* Leave Ethernet header part of hdr and full payload */
  653. skb_pull(skb, hdrlen);
  654. len = htons(skb->len);
  655. memcpy(skb_push(skb, 2), &len, 2);
  656. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  657. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  658. }
  659. #ifdef NOT_YET
  660. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  661. IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
  662. /* Non-standard frame: get addr4 from its bogus location after
  663. * the payload */
  664. skb_copy_to_linear_data_offset(skb, ETH_ALEN,
  665. skb->data + skb->len - ETH_ALEN,
  666. ETH_ALEN);
  667. skb_trim(skb, skb->len - ETH_ALEN);
  668. }
  669. #endif
  670. dev->stats.rx_packets++;
  671. dev->stats.rx_bytes += skb->len;
  672. #ifdef NOT_YET
  673. if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
  674. if (is_multicast_ether_addr(dst)) {
  675. /* copy multicast frame both to the higher layers and
  676. * to the wireless media */
  677. ieee->ap->bridged_multicast++;
  678. skb2 = skb_clone(skb, GFP_ATOMIC);
  679. if (skb2 == NULL)
  680. printk(KERN_DEBUG "%s: skb_clone failed for "
  681. "multicast frame\n", dev->name);
  682. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  683. /* send frame directly to the associated STA using
  684. * wireless media and not passing to higher layers */
  685. ieee->ap->bridged_unicast++;
  686. skb2 = skb;
  687. skb = NULL;
  688. }
  689. }
  690. if (skb2 != NULL) {
  691. /* send to wireless media */
  692. skb2->dev = dev;
  693. skb2->protocol = htons(ETH_P_802_3);
  694. skb_reset_mac_header(skb2);
  695. skb_reset_network_header(skb2);
  696. /* skb2->network_header += ETH_HLEN; */
  697. dev_queue_xmit(skb2);
  698. }
  699. #endif
  700. if (skb) {
  701. skb->protocol = eth_type_trans(skb, dev);
  702. memset(skb->cb, 0, sizeof(skb->cb));
  703. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  704. if (netif_rx(skb) == NET_RX_DROP) {
  705. /* netif_rx always succeeds, but it might drop
  706. * the packet. If it drops the packet, we log that
  707. * in our stats. */
  708. LIBIPW_DEBUG_DROP
  709. ("RX: netif_rx dropped the packet\n");
  710. dev->stats.rx_dropped++;
  711. }
  712. }
  713. rx_exit:
  714. #ifdef NOT_YET
  715. if (sta)
  716. hostap_handle_sta_release(sta);
  717. #endif
  718. return 1;
  719. rx_dropped:
  720. dev->stats.rx_dropped++;
  721. /* Returning 0 indicates to caller that we have not handled the SKB--
  722. * so it is still allocated and can be used again by underlying
  723. * hardware as a DMA target */
  724. return 0;
  725. }
  726. /* Filter out unrelated packets, call libipw_rx[_mgt]
  727. * This function takes over the skb, it should not be used again after calling
  728. * this function. */
  729. void libipw_rx_any(struct libipw_device *ieee,
  730. struct sk_buff *skb, struct libipw_rx_stats *stats)
  731. {
  732. struct libipw_hdr_4addr *hdr;
  733. int is_packet_for_us;
  734. u16 fc;
  735. if (ieee->iw_mode == IW_MODE_MONITOR) {
  736. if (!libipw_rx(ieee, skb, stats))
  737. dev_kfree_skb_irq(skb);
  738. return;
  739. }
  740. if (skb->len < sizeof(struct ieee80211_hdr))
  741. goto drop_free;
  742. hdr = (struct libipw_hdr_4addr *)skb->data;
  743. fc = le16_to_cpu(hdr->frame_ctl);
  744. if ((fc & IEEE80211_FCTL_VERS) != 0)
  745. goto drop_free;
  746. switch (fc & IEEE80211_FCTL_FTYPE) {
  747. case IEEE80211_FTYPE_MGMT:
  748. if (skb->len < sizeof(struct libipw_hdr_3addr))
  749. goto drop_free;
  750. libipw_rx_mgt(ieee, hdr, stats);
  751. dev_kfree_skb_irq(skb);
  752. return;
  753. case IEEE80211_FTYPE_DATA:
  754. break;
  755. case IEEE80211_FTYPE_CTL:
  756. return;
  757. default:
  758. return;
  759. }
  760. is_packet_for_us = 0;
  761. switch (ieee->iw_mode) {
  762. case IW_MODE_ADHOC:
  763. /* our BSS and not from/to DS */
  764. if (ether_addr_equal(hdr->addr3, ieee->bssid))
  765. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
  766. /* promisc: get all */
  767. if (ieee->dev->flags & IFF_PROMISC)
  768. is_packet_for_us = 1;
  769. /* to us */
  770. else if (ether_addr_equal(hdr->addr1, ieee->dev->dev_addr))
  771. is_packet_for_us = 1;
  772. /* mcast */
  773. else if (is_multicast_ether_addr(hdr->addr1))
  774. is_packet_for_us = 1;
  775. }
  776. break;
  777. case IW_MODE_INFRA:
  778. /* our BSS (== from our AP) and from DS */
  779. if (ether_addr_equal(hdr->addr2, ieee->bssid))
  780. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
  781. /* promisc: get all */
  782. if (ieee->dev->flags & IFF_PROMISC)
  783. is_packet_for_us = 1;
  784. /* to us */
  785. else if (ether_addr_equal(hdr->addr1, ieee->dev->dev_addr))
  786. is_packet_for_us = 1;
  787. /* mcast */
  788. else if (is_multicast_ether_addr(hdr->addr1)) {
  789. /* not our own packet bcasted from AP */
  790. if (!ether_addr_equal(hdr->addr3, ieee->dev->dev_addr))
  791. is_packet_for_us = 1;
  792. }
  793. }
  794. break;
  795. default:
  796. /* ? */
  797. break;
  798. }
  799. if (is_packet_for_us)
  800. if (!libipw_rx(ieee, skb, stats))
  801. dev_kfree_skb_irq(skb);
  802. return;
  803. drop_free:
  804. dev_kfree_skb_irq(skb);
  805. ieee->dev->stats.rx_dropped++;
  806. }
  807. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  808. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  809. /*
  810. * Make the structure we read from the beacon packet to have
  811. * the right values
  812. */
  813. static int libipw_verify_qos_info(struct libipw_qos_information_element
  814. *info_element, int sub_type)
  815. {
  816. if (info_element->qui_subtype != sub_type)
  817. return -1;
  818. if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
  819. return -1;
  820. if (info_element->qui_type != QOS_OUI_TYPE)
  821. return -1;
  822. if (info_element->version != QOS_VERSION_1)
  823. return -1;
  824. return 0;
  825. }
  826. /*
  827. * Parse a QoS parameter element
  828. */
  829. static int libipw_read_qos_param_element(struct libipw_qos_parameter_info
  830. *element_param, struct libipw_info_element
  831. *info_element)
  832. {
  833. int ret = 0;
  834. u16 size = sizeof(struct libipw_qos_parameter_info) - 2;
  835. if ((info_element == NULL) || (element_param == NULL))
  836. return -1;
  837. if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
  838. memcpy(element_param->info_element.qui, info_element->data,
  839. info_element->len);
  840. element_param->info_element.elementID = info_element->id;
  841. element_param->info_element.length = info_element->len;
  842. } else
  843. ret = -1;
  844. if (ret == 0)
  845. ret = libipw_verify_qos_info(&element_param->info_element,
  846. QOS_OUI_PARAM_SUB_TYPE);
  847. return ret;
  848. }
  849. /*
  850. * Parse a QoS information element
  851. */
  852. static int libipw_read_qos_info_element(struct
  853. libipw_qos_information_element
  854. *element_info, struct libipw_info_element
  855. *info_element)
  856. {
  857. int ret = 0;
  858. u16 size = sizeof(struct libipw_qos_information_element) - 2;
  859. if (element_info == NULL)
  860. return -1;
  861. if (info_element == NULL)
  862. return -1;
  863. if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
  864. memcpy(element_info->qui, info_element->data,
  865. info_element->len);
  866. element_info->elementID = info_element->id;
  867. element_info->length = info_element->len;
  868. } else
  869. ret = -1;
  870. if (ret == 0)
  871. ret = libipw_verify_qos_info(element_info,
  872. QOS_OUI_INFO_SUB_TYPE);
  873. return ret;
  874. }
  875. /*
  876. * Write QoS parameters from the ac parameters.
  877. */
  878. static int libipw_qos_convert_ac_to_parameters(struct
  879. libipw_qos_parameter_info
  880. *param_elm, struct
  881. libipw_qos_parameters
  882. *qos_param)
  883. {
  884. int rc = 0;
  885. int i;
  886. struct libipw_qos_ac_parameter *ac_params;
  887. u32 txop;
  888. u8 cw_min;
  889. u8 cw_max;
  890. for (i = 0; i < QOS_QUEUE_NUM; i++) {
  891. ac_params = &(param_elm->ac_params_record[i]);
  892. qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
  893. qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
  894. cw_min = ac_params->ecw_min_max & 0x0F;
  895. qos_param->cw_min[i] = cpu_to_le16((1 << cw_min) - 1);
  896. cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
  897. qos_param->cw_max[i] = cpu_to_le16((1 << cw_max) - 1);
  898. qos_param->flag[i] =
  899. (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
  900. txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
  901. qos_param->tx_op_limit[i] = cpu_to_le16(txop);
  902. }
  903. return rc;
  904. }
  905. /*
  906. * we have a generic data element which it may contain QoS information or
  907. * parameters element. check the information element length to decide
  908. * which type to read
  909. */
  910. static int libipw_parse_qos_info_param_IE(struct libipw_info_element
  911. *info_element,
  912. struct libipw_network *network)
  913. {
  914. int rc = 0;
  915. struct libipw_qos_parameters *qos_param = NULL;
  916. struct libipw_qos_information_element qos_info_element;
  917. rc = libipw_read_qos_info_element(&qos_info_element, info_element);
  918. if (rc == 0) {
  919. network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
  920. network->flags |= NETWORK_HAS_QOS_INFORMATION;
  921. } else {
  922. struct libipw_qos_parameter_info param_element;
  923. rc = libipw_read_qos_param_element(&param_element,
  924. info_element);
  925. if (rc == 0) {
  926. qos_param = &(network->qos_data.parameters);
  927. libipw_qos_convert_ac_to_parameters(&param_element,
  928. qos_param);
  929. network->flags |= NETWORK_HAS_QOS_PARAMETERS;
  930. network->qos_data.param_count =
  931. param_element.info_element.ac_info & 0x0F;
  932. }
  933. }
  934. if (rc == 0) {
  935. LIBIPW_DEBUG_QOS("QoS is supported\n");
  936. network->qos_data.supported = 1;
  937. }
  938. return rc;
  939. }
  940. #ifdef CONFIG_LIBIPW_DEBUG
  941. #define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
  942. static const char *get_info_element_string(u16 id)
  943. {
  944. switch (id) {
  945. MFIE_STRING(SSID);
  946. MFIE_STRING(SUPP_RATES);
  947. MFIE_STRING(FH_PARAMS);
  948. MFIE_STRING(DS_PARAMS);
  949. MFIE_STRING(CF_PARAMS);
  950. MFIE_STRING(TIM);
  951. MFIE_STRING(IBSS_PARAMS);
  952. MFIE_STRING(COUNTRY);
  953. MFIE_STRING(REQUEST);
  954. MFIE_STRING(CHALLENGE);
  955. MFIE_STRING(PWR_CONSTRAINT);
  956. MFIE_STRING(PWR_CAPABILITY);
  957. MFIE_STRING(TPC_REQUEST);
  958. MFIE_STRING(TPC_REPORT);
  959. MFIE_STRING(SUPPORTED_CHANNELS);
  960. MFIE_STRING(CHANNEL_SWITCH);
  961. MFIE_STRING(MEASURE_REQUEST);
  962. MFIE_STRING(MEASURE_REPORT);
  963. MFIE_STRING(QUIET);
  964. MFIE_STRING(IBSS_DFS);
  965. MFIE_STRING(ERP_INFO);
  966. MFIE_STRING(RSN);
  967. MFIE_STRING(EXT_SUPP_RATES);
  968. MFIE_STRING(VENDOR_SPECIFIC);
  969. MFIE_STRING(QOS_PARAMETER);
  970. default:
  971. return "UNKNOWN";
  972. }
  973. }
  974. #endif
  975. static int libipw_parse_info_param(struct libipw_info_element
  976. *info_element, u16 length,
  977. struct libipw_network *network)
  978. {
  979. u8 i;
  980. #ifdef CONFIG_LIBIPW_DEBUG
  981. char rates_str[64];
  982. char *p;
  983. #endif
  984. while (length >= sizeof(*info_element)) {
  985. if (sizeof(*info_element) + info_element->len > length) {
  986. LIBIPW_DEBUG_MGMT("Info elem: parse failed: "
  987. "info_element->len + 2 > left : "
  988. "info_element->len+2=%zd left=%d, id=%d.\n",
  989. info_element->len +
  990. sizeof(*info_element),
  991. length, info_element->id);
  992. /* We stop processing but don't return an error here
  993. * because some misbehaviour APs break this rule. ie.
  994. * Orinoco AP1000. */
  995. break;
  996. }
  997. switch (info_element->id) {
  998. case WLAN_EID_SSID:
  999. network->ssid_len = min(info_element->len,
  1000. (u8) IW_ESSID_MAX_SIZE);
  1001. memcpy(network->ssid, info_element->data,
  1002. network->ssid_len);
  1003. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  1004. memset(network->ssid + network->ssid_len, 0,
  1005. IW_ESSID_MAX_SIZE - network->ssid_len);
  1006. LIBIPW_DEBUG_MGMT("WLAN_EID_SSID: '%*pE' len=%d.\n",
  1007. network->ssid_len, network->ssid,
  1008. network->ssid_len);
  1009. break;
  1010. case WLAN_EID_SUPP_RATES:
  1011. #ifdef CONFIG_LIBIPW_DEBUG
  1012. p = rates_str;
  1013. #endif
  1014. network->rates_len = min(info_element->len,
  1015. MAX_RATES_LENGTH);
  1016. for (i = 0; i < network->rates_len; i++) {
  1017. network->rates[i] = info_element->data[i];
  1018. #ifdef CONFIG_LIBIPW_DEBUG
  1019. p += snprintf(p, sizeof(rates_str) -
  1020. (p - rates_str), "%02X ",
  1021. network->rates[i]);
  1022. #endif
  1023. if (libipw_is_ofdm_rate
  1024. (info_element->data[i])) {
  1025. network->flags |= NETWORK_HAS_OFDM;
  1026. if (info_element->data[i] &
  1027. LIBIPW_BASIC_RATE_MASK)
  1028. network->flags &=
  1029. ~NETWORK_HAS_CCK;
  1030. }
  1031. }
  1032. LIBIPW_DEBUG_MGMT("WLAN_EID_SUPP_RATES: '%s' (%d)\n",
  1033. rates_str, network->rates_len);
  1034. break;
  1035. case WLAN_EID_EXT_SUPP_RATES:
  1036. #ifdef CONFIG_LIBIPW_DEBUG
  1037. p = rates_str;
  1038. #endif
  1039. network->rates_ex_len = min(info_element->len,
  1040. MAX_RATES_EX_LENGTH);
  1041. for (i = 0; i < network->rates_ex_len; i++) {
  1042. network->rates_ex[i] = info_element->data[i];
  1043. #ifdef CONFIG_LIBIPW_DEBUG
  1044. p += snprintf(p, sizeof(rates_str) -
  1045. (p - rates_str), "%02X ",
  1046. network->rates_ex[i]);
  1047. #endif
  1048. if (libipw_is_ofdm_rate
  1049. (info_element->data[i])) {
  1050. network->flags |= NETWORK_HAS_OFDM;
  1051. if (info_element->data[i] &
  1052. LIBIPW_BASIC_RATE_MASK)
  1053. network->flags &=
  1054. ~NETWORK_HAS_CCK;
  1055. }
  1056. }
  1057. LIBIPW_DEBUG_MGMT("WLAN_EID_EXT_SUPP_RATES: '%s' (%d)\n",
  1058. rates_str, network->rates_ex_len);
  1059. break;
  1060. case WLAN_EID_DS_PARAMS:
  1061. LIBIPW_DEBUG_MGMT("WLAN_EID_DS_PARAMS: %d\n",
  1062. info_element->data[0]);
  1063. network->channel = info_element->data[0];
  1064. break;
  1065. case WLAN_EID_FH_PARAMS:
  1066. LIBIPW_DEBUG_MGMT("WLAN_EID_FH_PARAMS: ignored\n");
  1067. break;
  1068. case WLAN_EID_CF_PARAMS:
  1069. LIBIPW_DEBUG_MGMT("WLAN_EID_CF_PARAMS: ignored\n");
  1070. break;
  1071. case WLAN_EID_TIM:
  1072. network->tim.tim_count = info_element->data[0];
  1073. network->tim.tim_period = info_element->data[1];
  1074. LIBIPW_DEBUG_MGMT("WLAN_EID_TIM: partially ignored\n");
  1075. break;
  1076. case WLAN_EID_ERP_INFO:
  1077. network->erp_value = info_element->data[0];
  1078. network->flags |= NETWORK_HAS_ERP_VALUE;
  1079. LIBIPW_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
  1080. network->erp_value);
  1081. break;
  1082. case WLAN_EID_IBSS_PARAMS:
  1083. network->atim_window = info_element->data[0];
  1084. LIBIPW_DEBUG_MGMT("WLAN_EID_IBSS_PARAMS: %d\n",
  1085. network->atim_window);
  1086. break;
  1087. case WLAN_EID_CHALLENGE:
  1088. LIBIPW_DEBUG_MGMT("WLAN_EID_CHALLENGE: ignored\n");
  1089. break;
  1090. case WLAN_EID_VENDOR_SPECIFIC:
  1091. LIBIPW_DEBUG_MGMT("WLAN_EID_VENDOR_SPECIFIC: %d bytes\n",
  1092. info_element->len);
  1093. if (!libipw_parse_qos_info_param_IE(info_element,
  1094. network))
  1095. break;
  1096. if (info_element->len >= 4 &&
  1097. info_element->data[0] == 0x00 &&
  1098. info_element->data[1] == 0x50 &&
  1099. info_element->data[2] == 0xf2 &&
  1100. info_element->data[3] == 0x01) {
  1101. network->wpa_ie_len = min(info_element->len + 2,
  1102. MAX_WPA_IE_LEN);
  1103. memcpy(network->wpa_ie, info_element,
  1104. network->wpa_ie_len);
  1105. }
  1106. break;
  1107. case WLAN_EID_RSN:
  1108. LIBIPW_DEBUG_MGMT("WLAN_EID_RSN: %d bytes\n",
  1109. info_element->len);
  1110. network->rsn_ie_len = min(info_element->len + 2,
  1111. MAX_WPA_IE_LEN);
  1112. memcpy(network->rsn_ie, info_element,
  1113. network->rsn_ie_len);
  1114. break;
  1115. case WLAN_EID_QOS_PARAMETER:
  1116. printk(KERN_ERR
  1117. "QoS Error need to parse QOS_PARAMETER IE\n");
  1118. break;
  1119. /* 802.11h */
  1120. case WLAN_EID_PWR_CONSTRAINT:
  1121. network->power_constraint = info_element->data[0];
  1122. network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
  1123. break;
  1124. case WLAN_EID_CHANNEL_SWITCH:
  1125. network->power_constraint = info_element->data[0];
  1126. network->flags |= NETWORK_HAS_CSA;
  1127. break;
  1128. case WLAN_EID_QUIET:
  1129. network->quiet.count = info_element->data[0];
  1130. network->quiet.period = info_element->data[1];
  1131. network->quiet.duration = info_element->data[2];
  1132. network->quiet.offset = info_element->data[3];
  1133. network->flags |= NETWORK_HAS_QUIET;
  1134. break;
  1135. case WLAN_EID_IBSS_DFS:
  1136. network->flags |= NETWORK_HAS_IBSS_DFS;
  1137. break;
  1138. case WLAN_EID_TPC_REPORT:
  1139. network->tpc_report.transmit_power =
  1140. info_element->data[0];
  1141. network->tpc_report.link_margin = info_element->data[1];
  1142. network->flags |= NETWORK_HAS_TPC_REPORT;
  1143. break;
  1144. default:
  1145. LIBIPW_DEBUG_MGMT
  1146. ("Unsupported info element: %s (%d)\n",
  1147. get_info_element_string(info_element->id),
  1148. info_element->id);
  1149. break;
  1150. }
  1151. length -= sizeof(*info_element) + info_element->len;
  1152. info_element =
  1153. (struct libipw_info_element *)&info_element->
  1154. data[info_element->len];
  1155. }
  1156. return 0;
  1157. }
  1158. static int libipw_handle_assoc_resp(struct libipw_device *ieee, struct libipw_assoc_response
  1159. *frame, struct libipw_rx_stats *stats)
  1160. {
  1161. struct libipw_network network_resp = { };
  1162. struct libipw_network *network = &network_resp;
  1163. struct net_device *dev = ieee->dev;
  1164. network->flags = 0;
  1165. network->qos_data.active = 0;
  1166. network->qos_data.supported = 0;
  1167. network->qos_data.param_count = 0;
  1168. network->qos_data.old_param_count = 0;
  1169. //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
  1170. network->atim_window = le16_to_cpu(frame->aid);
  1171. network->listen_interval = le16_to_cpu(frame->status);
  1172. memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
  1173. network->capability = le16_to_cpu(frame->capability);
  1174. network->last_scanned = jiffies;
  1175. network->rates_len = network->rates_ex_len = 0;
  1176. network->last_associate = 0;
  1177. network->ssid_len = 0;
  1178. network->erp_value =
  1179. (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
  1180. if (stats->freq == LIBIPW_52GHZ_BAND) {
  1181. /* for A band (No DS info) */
  1182. network->channel = stats->received_channel;
  1183. } else
  1184. network->flags |= NETWORK_HAS_CCK;
  1185. network->wpa_ie_len = 0;
  1186. network->rsn_ie_len = 0;
  1187. if (libipw_parse_info_param
  1188. (frame->info_element, stats->len - sizeof(*frame), network))
  1189. return 1;
  1190. network->mode = 0;
  1191. if (stats->freq == LIBIPW_52GHZ_BAND)
  1192. network->mode = IEEE_A;
  1193. else {
  1194. if (network->flags & NETWORK_HAS_OFDM)
  1195. network->mode |= IEEE_G;
  1196. if (network->flags & NETWORK_HAS_CCK)
  1197. network->mode |= IEEE_B;
  1198. }
  1199. memcpy(&network->stats, stats, sizeof(network->stats));
  1200. if (ieee->handle_assoc_response != NULL)
  1201. ieee->handle_assoc_response(dev, frame, network);
  1202. return 0;
  1203. }
  1204. /***************************************************/
  1205. static int libipw_network_init(struct libipw_device *ieee, struct libipw_probe_response
  1206. *beacon,
  1207. struct libipw_network *network,
  1208. struct libipw_rx_stats *stats)
  1209. {
  1210. network->qos_data.active = 0;
  1211. network->qos_data.supported = 0;
  1212. network->qos_data.param_count = 0;
  1213. network->qos_data.old_param_count = 0;
  1214. /* Pull out fixed field data */
  1215. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  1216. network->capability = le16_to_cpu(beacon->capability);
  1217. network->last_scanned = jiffies;
  1218. network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
  1219. network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
  1220. network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
  1221. /* Where to pull this? beacon->listen_interval; */
  1222. network->listen_interval = 0x0A;
  1223. network->rates_len = network->rates_ex_len = 0;
  1224. network->last_associate = 0;
  1225. network->ssid_len = 0;
  1226. network->flags = 0;
  1227. network->atim_window = 0;
  1228. network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
  1229. 0x3 : 0x0;
  1230. if (stats->freq == LIBIPW_52GHZ_BAND) {
  1231. /* for A band (No DS info) */
  1232. network->channel = stats->received_channel;
  1233. } else
  1234. network->flags |= NETWORK_HAS_CCK;
  1235. network->wpa_ie_len = 0;
  1236. network->rsn_ie_len = 0;
  1237. if (libipw_parse_info_param
  1238. (beacon->info_element, stats->len - sizeof(*beacon), network))
  1239. return 1;
  1240. network->mode = 0;
  1241. if (stats->freq == LIBIPW_52GHZ_BAND)
  1242. network->mode = IEEE_A;
  1243. else {
  1244. if (network->flags & NETWORK_HAS_OFDM)
  1245. network->mode |= IEEE_G;
  1246. if (network->flags & NETWORK_HAS_CCK)
  1247. network->mode |= IEEE_B;
  1248. }
  1249. if (network->mode == 0) {
  1250. LIBIPW_DEBUG_SCAN("Filtered out '%*pE (%pM)' network.\n",
  1251. network->ssid_len, network->ssid,
  1252. network->bssid);
  1253. return 1;
  1254. }
  1255. memcpy(&network->stats, stats, sizeof(network->stats));
  1256. return 0;
  1257. }
  1258. static inline int is_same_network(struct libipw_network *src,
  1259. struct libipw_network *dst)
  1260. {
  1261. /* A network is only a duplicate if the channel, BSSID, and ESSID
  1262. * all match. We treat all <hidden> with the same BSSID and channel
  1263. * as one network */
  1264. return ((src->ssid_len == dst->ssid_len) &&
  1265. (src->channel == dst->channel) &&
  1266. ether_addr_equal_64bits(src->bssid, dst->bssid) &&
  1267. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  1268. }
  1269. static void update_network(struct libipw_network *dst,
  1270. struct libipw_network *src)
  1271. {
  1272. int qos_active;
  1273. u8 old_param;
  1274. /* We only update the statistics if they were created by receiving
  1275. * the network information on the actual channel the network is on.
  1276. *
  1277. * This keeps beacons received on neighbor channels from bringing
  1278. * down the signal level of an AP. */
  1279. if (dst->channel == src->stats.received_channel)
  1280. memcpy(&dst->stats, &src->stats,
  1281. sizeof(struct libipw_rx_stats));
  1282. else
  1283. LIBIPW_DEBUG_SCAN("Network %pM info received "
  1284. "off channel (%d vs. %d)\n", src->bssid,
  1285. dst->channel, src->stats.received_channel);
  1286. dst->capability = src->capability;
  1287. memcpy(dst->rates, src->rates, src->rates_len);
  1288. dst->rates_len = src->rates_len;
  1289. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  1290. dst->rates_ex_len = src->rates_ex_len;
  1291. dst->mode = src->mode;
  1292. dst->flags = src->flags;
  1293. dst->time_stamp[0] = src->time_stamp[0];
  1294. dst->time_stamp[1] = src->time_stamp[1];
  1295. dst->beacon_interval = src->beacon_interval;
  1296. dst->listen_interval = src->listen_interval;
  1297. dst->atim_window = src->atim_window;
  1298. dst->erp_value = src->erp_value;
  1299. dst->tim = src->tim;
  1300. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  1301. dst->wpa_ie_len = src->wpa_ie_len;
  1302. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  1303. dst->rsn_ie_len = src->rsn_ie_len;
  1304. dst->last_scanned = jiffies;
  1305. qos_active = src->qos_data.active;
  1306. old_param = dst->qos_data.old_param_count;
  1307. if (dst->flags & NETWORK_HAS_QOS_MASK)
  1308. memcpy(&dst->qos_data, &src->qos_data,
  1309. sizeof(struct libipw_qos_data));
  1310. else {
  1311. dst->qos_data.supported = src->qos_data.supported;
  1312. dst->qos_data.param_count = src->qos_data.param_count;
  1313. }
  1314. if (dst->qos_data.supported == 1) {
  1315. if (dst->ssid_len)
  1316. LIBIPW_DEBUG_QOS
  1317. ("QoS the network %s is QoS supported\n",
  1318. dst->ssid);
  1319. else
  1320. LIBIPW_DEBUG_QOS
  1321. ("QoS the network is QoS supported\n");
  1322. }
  1323. dst->qos_data.active = qos_active;
  1324. dst->qos_data.old_param_count = old_param;
  1325. /* dst->last_associate is not overwritten */
  1326. }
  1327. static inline int is_beacon(__le16 fc)
  1328. {
  1329. return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
  1330. }
  1331. static void libipw_process_probe_response(struct libipw_device
  1332. *ieee, struct
  1333. libipw_probe_response
  1334. *beacon, struct libipw_rx_stats
  1335. *stats)
  1336. {
  1337. struct net_device *dev = ieee->dev;
  1338. struct libipw_network network = { };
  1339. struct libipw_network *target;
  1340. struct libipw_network *oldest = NULL;
  1341. #ifdef CONFIG_LIBIPW_DEBUG
  1342. struct libipw_info_element *info_element = beacon->info_element;
  1343. #endif
  1344. unsigned long flags;
  1345. LIBIPW_DEBUG_SCAN("'%*pE' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  1346. info_element->len, info_element->data,
  1347. beacon->header.addr3,
  1348. (beacon->capability & cpu_to_le16(1 << 0xf)) ? '1' : '0',
  1349. (beacon->capability & cpu_to_le16(1 << 0xe)) ? '1' : '0',
  1350. (beacon->capability & cpu_to_le16(1 << 0xd)) ? '1' : '0',
  1351. (beacon->capability & cpu_to_le16(1 << 0xc)) ? '1' : '0',
  1352. (beacon->capability & cpu_to_le16(1 << 0xb)) ? '1' : '0',
  1353. (beacon->capability & cpu_to_le16(1 << 0xa)) ? '1' : '0',
  1354. (beacon->capability & cpu_to_le16(1 << 0x9)) ? '1' : '0',
  1355. (beacon->capability & cpu_to_le16(1 << 0x8)) ? '1' : '0',
  1356. (beacon->capability & cpu_to_le16(1 << 0x7)) ? '1' : '0',
  1357. (beacon->capability & cpu_to_le16(1 << 0x6)) ? '1' : '0',
  1358. (beacon->capability & cpu_to_le16(1 << 0x5)) ? '1' : '0',
  1359. (beacon->capability & cpu_to_le16(1 << 0x4)) ? '1' : '0',
  1360. (beacon->capability & cpu_to_le16(1 << 0x3)) ? '1' : '0',
  1361. (beacon->capability & cpu_to_le16(1 << 0x2)) ? '1' : '0',
  1362. (beacon->capability & cpu_to_le16(1 << 0x1)) ? '1' : '0',
  1363. (beacon->capability & cpu_to_le16(1 << 0x0)) ? '1' : '0');
  1364. if (libipw_network_init(ieee, beacon, &network, stats)) {
  1365. LIBIPW_DEBUG_SCAN("Dropped '%*pE' (%pM) via %s.\n",
  1366. info_element->len, info_element->data,
  1367. beacon->header.addr3,
  1368. is_beacon(beacon->header.frame_ctl) ?
  1369. "BEACON" : "PROBE RESPONSE");
  1370. return;
  1371. }
  1372. /* The network parsed correctly -- so now we scan our known networks
  1373. * to see if we can find it in our list.
  1374. *
  1375. * NOTE: This search is definitely not optimized. Once its doing
  1376. * the "right thing" we'll optimize it for efficiency if
  1377. * necessary */
  1378. /* Search for this entry in the list and update it if it is
  1379. * already there. */
  1380. spin_lock_irqsave(&ieee->lock, flags);
  1381. list_for_each_entry(target, &ieee->network_list, list) {
  1382. if (is_same_network(target, &network))
  1383. break;
  1384. if ((oldest == NULL) ||
  1385. time_before(target->last_scanned, oldest->last_scanned))
  1386. oldest = target;
  1387. }
  1388. /* If we didn't find a match, then get a new network slot to initialize
  1389. * with this beacon's information */
  1390. if (&target->list == &ieee->network_list) {
  1391. if (list_empty(&ieee->network_free_list)) {
  1392. /* If there are no more slots, expire the oldest */
  1393. list_del(&oldest->list);
  1394. target = oldest;
  1395. LIBIPW_DEBUG_SCAN("Expired '%*pE' (%pM) from network list.\n",
  1396. target->ssid_len, target->ssid,
  1397. target->bssid);
  1398. } else {
  1399. /* Otherwise just pull from the free list */
  1400. target = list_entry(ieee->network_free_list.next,
  1401. struct libipw_network, list);
  1402. list_del(ieee->network_free_list.next);
  1403. }
  1404. #ifdef CONFIG_LIBIPW_DEBUG
  1405. LIBIPW_DEBUG_SCAN("Adding '%*pE' (%pM) via %s.\n",
  1406. network.ssid_len, network.ssid,
  1407. network.bssid,
  1408. is_beacon(beacon->header.frame_ctl) ?
  1409. "BEACON" : "PROBE RESPONSE");
  1410. #endif
  1411. memcpy(target, &network, sizeof(*target));
  1412. list_add_tail(&target->list, &ieee->network_list);
  1413. } else {
  1414. LIBIPW_DEBUG_SCAN("Updating '%*pE' (%pM) via %s.\n",
  1415. target->ssid_len, target->ssid,
  1416. target->bssid,
  1417. is_beacon(beacon->header.frame_ctl) ?
  1418. "BEACON" : "PROBE RESPONSE");
  1419. update_network(target, &network);
  1420. }
  1421. spin_unlock_irqrestore(&ieee->lock, flags);
  1422. if (is_beacon(beacon->header.frame_ctl)) {
  1423. if (ieee->handle_beacon != NULL)
  1424. ieee->handle_beacon(dev, beacon, target);
  1425. } else {
  1426. if (ieee->handle_probe_response != NULL)
  1427. ieee->handle_probe_response(dev, beacon, target);
  1428. }
  1429. }
  1430. void libipw_rx_mgt(struct libipw_device *ieee,
  1431. struct libipw_hdr_4addr *header,
  1432. struct libipw_rx_stats *stats)
  1433. {
  1434. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1435. case IEEE80211_STYPE_ASSOC_RESP:
  1436. LIBIPW_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1437. WLAN_FC_GET_STYPE(le16_to_cpu
  1438. (header->frame_ctl)));
  1439. libipw_handle_assoc_resp(ieee,
  1440. (struct libipw_assoc_response *)
  1441. header, stats);
  1442. break;
  1443. case IEEE80211_STYPE_REASSOC_RESP:
  1444. LIBIPW_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1445. WLAN_FC_GET_STYPE(le16_to_cpu
  1446. (header->frame_ctl)));
  1447. break;
  1448. case IEEE80211_STYPE_PROBE_REQ:
  1449. LIBIPW_DEBUG_MGMT("received auth (%d)\n",
  1450. WLAN_FC_GET_STYPE(le16_to_cpu
  1451. (header->frame_ctl)));
  1452. if (ieee->handle_probe_request != NULL)
  1453. ieee->handle_probe_request(ieee->dev,
  1454. (struct
  1455. libipw_probe_request *)
  1456. header, stats);
  1457. break;
  1458. case IEEE80211_STYPE_PROBE_RESP:
  1459. LIBIPW_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1460. WLAN_FC_GET_STYPE(le16_to_cpu
  1461. (header->frame_ctl)));
  1462. LIBIPW_DEBUG_SCAN("Probe response\n");
  1463. libipw_process_probe_response(ieee,
  1464. (struct
  1465. libipw_probe_response *)
  1466. header, stats);
  1467. break;
  1468. case IEEE80211_STYPE_BEACON:
  1469. LIBIPW_DEBUG_MGMT("received BEACON (%d)\n",
  1470. WLAN_FC_GET_STYPE(le16_to_cpu
  1471. (header->frame_ctl)));
  1472. LIBIPW_DEBUG_SCAN("Beacon\n");
  1473. libipw_process_probe_response(ieee,
  1474. (struct
  1475. libipw_probe_response *)
  1476. header, stats);
  1477. break;
  1478. case IEEE80211_STYPE_AUTH:
  1479. LIBIPW_DEBUG_MGMT("received auth (%d)\n",
  1480. WLAN_FC_GET_STYPE(le16_to_cpu
  1481. (header->frame_ctl)));
  1482. if (ieee->handle_auth != NULL)
  1483. ieee->handle_auth(ieee->dev,
  1484. (struct libipw_auth *)header);
  1485. break;
  1486. case IEEE80211_STYPE_DISASSOC:
  1487. if (ieee->handle_disassoc != NULL)
  1488. ieee->handle_disassoc(ieee->dev,
  1489. (struct libipw_disassoc *)
  1490. header);
  1491. break;
  1492. case IEEE80211_STYPE_ACTION:
  1493. LIBIPW_DEBUG_MGMT("ACTION\n");
  1494. if (ieee->handle_action)
  1495. ieee->handle_action(ieee->dev,
  1496. (struct libipw_action *)
  1497. header, stats);
  1498. break;
  1499. case IEEE80211_STYPE_REASSOC_REQ:
  1500. LIBIPW_DEBUG_MGMT("received reassoc (%d)\n",
  1501. WLAN_FC_GET_STYPE(le16_to_cpu
  1502. (header->frame_ctl)));
  1503. LIBIPW_DEBUG_MGMT("%s: LIBIPW_REASSOC_REQ received\n",
  1504. ieee->dev->name);
  1505. if (ieee->handle_reassoc_request != NULL)
  1506. ieee->handle_reassoc_request(ieee->dev,
  1507. (struct libipw_reassoc_request *)
  1508. header);
  1509. break;
  1510. case IEEE80211_STYPE_ASSOC_REQ:
  1511. LIBIPW_DEBUG_MGMT("received assoc (%d)\n",
  1512. WLAN_FC_GET_STYPE(le16_to_cpu
  1513. (header->frame_ctl)));
  1514. LIBIPW_DEBUG_MGMT("%s: LIBIPW_ASSOC_REQ received\n",
  1515. ieee->dev->name);
  1516. if (ieee->handle_assoc_request != NULL)
  1517. ieee->handle_assoc_request(ieee->dev);
  1518. break;
  1519. case IEEE80211_STYPE_DEAUTH:
  1520. LIBIPW_DEBUG_MGMT("DEAUTH\n");
  1521. if (ieee->handle_deauth != NULL)
  1522. ieee->handle_deauth(ieee->dev,
  1523. (struct libipw_deauth *)
  1524. header);
  1525. break;
  1526. default:
  1527. LIBIPW_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1528. WLAN_FC_GET_STYPE(le16_to_cpu
  1529. (header->frame_ctl)));
  1530. LIBIPW_DEBUG_MGMT("%s: Unknown management packet: %d\n",
  1531. ieee->dev->name,
  1532. WLAN_FC_GET_STYPE(le16_to_cpu
  1533. (header->frame_ctl)));
  1534. break;
  1535. }
  1536. }
  1537. EXPORT_SYMBOL_GPL(libipw_rx_any);
  1538. EXPORT_SYMBOL(libipw_rx_mgt);
  1539. EXPORT_SYMBOL(libipw_rx);