ieee80211_rx.c 49 KB

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