ieee80211_rx.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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/in.h>
  20. #include <linux/ip.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/slab.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/ieee80211.h>
  34. static void ieee80211_monitor_rx(struct ieee80211_device *ieee,
  35. struct sk_buff *skb,
  36. struct ieee80211_rx_stats *rx_stats)
  37. {
  38. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  39. u16 fc = le16_to_cpu(hdr->frame_ctl);
  40. skb->dev = ieee->dev;
  41. skb_reset_mac_header(skb);
  42. skb_pull(skb, ieee80211_get_hdrlen(fc));
  43. skb->pkt_type = PACKET_OTHERHOST;
  44. skb->protocol = __constant_htons(ETH_P_80211_RAW);
  45. memset(skb->cb, 0, sizeof(skb->cb));
  46. netif_rx(skb);
  47. }
  48. /* Called only as a tasklet (software IRQ) */
  49. static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
  50. ieee80211_device
  51. *ieee,
  52. unsigned int seq,
  53. unsigned int frag,
  54. u8 * src,
  55. u8 * dst)
  56. {
  57. struct ieee80211_frag_entry *entry;
  58. int i;
  59. for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
  60. entry = &ieee->frag_cache[i];
  61. if (entry->skb != NULL &&
  62. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  63. IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
  64. "seq=%u last_frag=%u\n",
  65. entry->seq, entry->last_frag);
  66. dev_kfree_skb_any(entry->skb);
  67. entry->skb = NULL;
  68. }
  69. if (entry->skb != NULL && entry->seq == seq &&
  70. (entry->last_frag + 1 == frag || frag == -1) &&
  71. !compare_ether_addr(entry->src_addr, src) &&
  72. !compare_ether_addr(entry->dst_addr, dst))
  73. return entry;
  74. }
  75. return NULL;
  76. }
  77. /* Called only as a tasklet (software IRQ) */
  78. static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
  79. struct ieee80211_hdr_4addr *hdr)
  80. {
  81. struct sk_buff *skb = NULL;
  82. u16 sc;
  83. unsigned int frag, seq;
  84. struct ieee80211_frag_entry *entry;
  85. sc = le16_to_cpu(hdr->seq_ctl);
  86. frag = WLAN_GET_SEQ_FRAG(sc);
  87. seq = WLAN_GET_SEQ_SEQ(sc);
  88. if (frag == 0) {
  89. /* Reserve enough space to fit maximum frame length */
  90. skb = dev_alloc_skb(ieee->dev->mtu +
  91. sizeof(struct ieee80211_hdr_4addr) +
  92. 8 /* LLC */ +
  93. 2 /* alignment */ +
  94. 8 /* WEP */ + ETH_ALEN /* WDS */ );
  95. if (skb == NULL)
  96. return NULL;
  97. entry = &ieee->frag_cache[ieee->frag_next_idx];
  98. ieee->frag_next_idx++;
  99. if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
  100. ieee->frag_next_idx = 0;
  101. if (entry->skb != NULL)
  102. dev_kfree_skb_any(entry->skb);
  103. entry->first_frag_time = jiffies;
  104. entry->seq = seq;
  105. entry->last_frag = frag;
  106. entry->skb = skb;
  107. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  108. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  109. } else {
  110. /* received a fragment of a frame for which the head fragment
  111. * should have already been received */
  112. entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
  113. hdr->addr1);
  114. if (entry != NULL) {
  115. entry->last_frag = frag;
  116. skb = entry->skb;
  117. }
  118. }
  119. return skb;
  120. }
  121. /* Called only as a tasklet (software IRQ) */
  122. static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
  123. struct ieee80211_hdr_4addr *hdr)
  124. {
  125. u16 sc;
  126. unsigned int seq;
  127. struct ieee80211_frag_entry *entry;
  128. sc = le16_to_cpu(hdr->seq_ctl);
  129. seq = WLAN_GET_SEQ_SEQ(sc);
  130. entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
  131. hdr->addr1);
  132. if (entry == NULL) {
  133. IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
  134. "entry (seq=%u)\n", seq);
  135. return -1;
  136. }
  137. entry->skb = NULL;
  138. return 0;
  139. }
  140. #ifdef NOT_YET
  141. /* ieee80211_rx_frame_mgtmt
  142. *
  143. * Responsible for handling management control frames
  144. *
  145. * Called by ieee80211_rx */
  146. static int
  147. ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
  148. struct ieee80211_rx_stats *rx_stats, u16 type,
  149. u16 stype)
  150. {
  151. if (ieee->iw_mode == IW_MODE_MASTER) {
  152. printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
  153. ieee->dev->name);
  154. return 0;
  155. /*
  156. hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
  157. skb->data);*/
  158. }
  159. if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
  160. if (stype == WLAN_FC_STYPE_BEACON &&
  161. ieee->iw_mode == IW_MODE_MASTER) {
  162. struct sk_buff *skb2;
  163. /* Process beacon frames also in kernel driver to
  164. * update STA(AP) table statistics */
  165. skb2 = skb_clone(skb, GFP_ATOMIC);
  166. if (skb2)
  167. hostap_rx(skb2->dev, skb2, rx_stats);
  168. }
  169. /* send management frames to the user space daemon for
  170. * processing */
  171. ieee->apdevstats.rx_packets++;
  172. ieee->apdevstats.rx_bytes += skb->len;
  173. prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  174. return 0;
  175. }
  176. if (ieee->iw_mode == IW_MODE_MASTER) {
  177. if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
  178. printk(KERN_DEBUG "%s: unknown management frame "
  179. "(type=0x%02x, stype=0x%02x) dropped\n",
  180. skb->dev->name, type, stype);
  181. return -1;
  182. }
  183. hostap_rx(skb->dev, skb, rx_stats);
  184. return 0;
  185. }
  186. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
  187. "received in non-Host AP mode\n", skb->dev->name);
  188. return -1;
  189. }
  190. #endif
  191. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  192. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  193. static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  194. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  195. static unsigned char bridge_tunnel_header[] =
  196. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  197. /* No encapsulation header if EtherType < 0x600 (=length) */
  198. /* Called by ieee80211_rx_frame_decrypt */
  199. static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
  200. struct sk_buff *skb)
  201. {
  202. struct net_device *dev = ieee->dev;
  203. u16 fc, ethertype;
  204. struct ieee80211_hdr_3addr *hdr;
  205. u8 *pos;
  206. if (skb->len < 24)
  207. return 0;
  208. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  209. fc = le16_to_cpu(hdr->frame_ctl);
  210. /* check that the frame is unicast frame to us */
  211. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  212. IEEE80211_FCTL_TODS &&
  213. !compare_ether_addr(hdr->addr1, dev->dev_addr) &&
  214. !compare_ether_addr(hdr->addr3, dev->dev_addr)) {
  215. /* ToDS frame with own addr BSSID and DA */
  216. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  217. IEEE80211_FCTL_FROMDS &&
  218. !compare_ether_addr(hdr->addr1, dev->dev_addr)) {
  219. /* FromDS frame with own addr as DA */
  220. } else
  221. return 0;
  222. if (skb->len < 24 + 8)
  223. return 0;
  224. /* check for port access entity Ethernet type */
  225. pos = skb->data + 24;
  226. ethertype = (pos[6] << 8) | pos[7];
  227. if (ethertype == ETH_P_PAE)
  228. return 1;
  229. return 0;
  230. }
  231. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  232. static int
  233. ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
  234. struct ieee80211_crypt_data *crypt)
  235. {
  236. struct ieee80211_hdr_3addr *hdr;
  237. int res, hdrlen;
  238. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  239. return 0;
  240. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  241. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  242. atomic_inc(&crypt->refcnt);
  243. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  244. atomic_dec(&crypt->refcnt);
  245. if (res < 0) {
  246. IEEE80211_DEBUG_DROP("decryption failed (SA=" MAC_FMT
  247. ") res=%d\n", MAC_ARG(hdr->addr2), res);
  248. if (res == -2)
  249. IEEE80211_DEBUG_DROP("Decryption failed ICV "
  250. "mismatch (key %d)\n",
  251. skb->data[hdrlen + 3] >> 6);
  252. ieee->ieee_stats.rx_discards_undecryptable++;
  253. return -1;
  254. }
  255. return res;
  256. }
  257. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  258. static int
  259. ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
  260. struct sk_buff *skb, int keyidx,
  261. struct ieee80211_crypt_data *crypt)
  262. {
  263. struct ieee80211_hdr_3addr *hdr;
  264. int res, hdrlen;
  265. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  266. return 0;
  267. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  268. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  269. atomic_inc(&crypt->refcnt);
  270. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  271. atomic_dec(&crypt->refcnt);
  272. if (res < 0) {
  273. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  274. " (SA=" MAC_FMT " keyidx=%d)\n",
  275. ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
  276. return -1;
  277. }
  278. return 0;
  279. }
  280. /* All received frames are sent to this function. @skb contains the frame in
  281. * IEEE 802.11 format, i.e., in the format it was sent over air.
  282. * This function is called only as a tasklet (software IRQ). */
  283. int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
  284. struct ieee80211_rx_stats *rx_stats)
  285. {
  286. struct net_device *dev = ieee->dev;
  287. struct ieee80211_hdr_4addr *hdr;
  288. size_t hdrlen;
  289. u16 fc, type, stype, sc;
  290. struct net_device_stats *stats;
  291. unsigned int frag;
  292. u8 *payload;
  293. u16 ethertype;
  294. #ifdef NOT_YET
  295. struct net_device *wds = NULL;
  296. struct sk_buff *skb2 = NULL;
  297. struct net_device *wds = NULL;
  298. int frame_authorized = 0;
  299. int from_assoc_ap = 0;
  300. void *sta = NULL;
  301. #endif
  302. u8 dst[ETH_ALEN];
  303. u8 src[ETH_ALEN];
  304. struct ieee80211_crypt_data *crypt = NULL;
  305. int keyidx = 0;
  306. int can_be_decrypted = 0;
  307. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  308. stats = &ieee->stats;
  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 = ieee80211_get_hdrlen(fc);
  319. /* Put this code here so that we avoid duplicating it in all
  320. * Rx paths. - Jean II */
  321. #ifdef CONFIG_WIRELESS_EXT
  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. #endif /* CONFIG_WIRELESS_EXT */
  347. #ifdef NOT_YET
  348. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  349. #endif
  350. if (ieee->iw_mode == IW_MODE_MONITOR) {
  351. stats->rx_packets++;
  352. stats->rx_bytes += skb->len;
  353. ieee80211_monitor_rx(ieee, skb, rx_stats);
  354. return 1;
  355. }
  356. can_be_decrypted = (is_multicast_ether_addr(hdr->addr1) ||
  357. is_broadcast_ether_addr(hdr->addr2)) ?
  358. ieee->host_mc_decrypt : ieee->host_decrypt;
  359. if (can_be_decrypted) {
  360. if (skb->len >= hdrlen + 3) {
  361. /* Top two-bits of byte 3 are the key index */
  362. keyidx = skb->data[hdrlen + 3] >> 6;
  363. }
  364. /* ieee->crypt[] is WEP_KEY (4) in length. Given that keyidx
  365. * is only allowed 2-bits of storage, no value of keyidx can
  366. * be provided via above code that would result in keyidx
  367. * being out of range */
  368. crypt = ieee->crypt[keyidx];
  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. /* drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.29) */
  417. if (sc == ieee->prev_seq_ctl)
  418. goto rx_dropped;
  419. else
  420. ieee->prev_seq_ctl = sc;
  421. /* Data frame - extract src/dst addresses */
  422. if (skb->len < IEEE80211_3ADDR_LEN)
  423. goto rx_dropped;
  424. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  425. case IEEE80211_FCTL_FROMDS:
  426. memcpy(dst, hdr->addr1, ETH_ALEN);
  427. memcpy(src, hdr->addr3, ETH_ALEN);
  428. break;
  429. case IEEE80211_FCTL_TODS:
  430. memcpy(dst, hdr->addr3, ETH_ALEN);
  431. memcpy(src, hdr->addr2, ETH_ALEN);
  432. break;
  433. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  434. if (skb->len < IEEE80211_4ADDR_LEN)
  435. goto rx_dropped;
  436. memcpy(dst, hdr->addr3, ETH_ALEN);
  437. memcpy(src, hdr->addr4, ETH_ALEN);
  438. break;
  439. case 0:
  440. memcpy(dst, hdr->addr1, ETH_ALEN);
  441. memcpy(src, hdr->addr2, ETH_ALEN);
  442. break;
  443. }
  444. #ifdef NOT_YET
  445. if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
  446. goto rx_dropped;
  447. if (wds) {
  448. skb->dev = dev = wds;
  449. stats = hostap_get_stats(dev);
  450. }
  451. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  452. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  453. IEEE80211_FCTL_FROMDS && ieee->stadev
  454. && !compare_ether_addr(hdr->addr2, ieee->assoc_ap_addr)) {
  455. /* Frame from BSSID of the AP for which we are a client */
  456. skb->dev = dev = ieee->stadev;
  457. stats = hostap_get_stats(dev);
  458. from_assoc_ap = 1;
  459. }
  460. #endif
  461. dev->last_rx = jiffies;
  462. #ifdef NOT_YET
  463. if ((ieee->iw_mode == IW_MODE_MASTER ||
  464. ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
  465. switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
  466. wds != NULL)) {
  467. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  468. frame_authorized = 0;
  469. break;
  470. case AP_RX_CONTINUE:
  471. frame_authorized = 1;
  472. break;
  473. case AP_RX_DROP:
  474. goto rx_dropped;
  475. case AP_RX_EXIT:
  476. goto rx_exit;
  477. }
  478. }
  479. #endif
  480. /* Nullfunc frames may have PS-bit set, so they must be passed to
  481. * hostap_handle_sta_rx() before being dropped here. */
  482. stype &= ~IEEE80211_STYPE_QOS_DATA;
  483. if (stype != IEEE80211_STYPE_DATA &&
  484. stype != IEEE80211_STYPE_DATA_CFACK &&
  485. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  486. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  487. if (stype != IEEE80211_STYPE_NULLFUNC)
  488. IEEE80211_DEBUG_DROP("RX: dropped data frame "
  489. "with no data (type=0x%02x, "
  490. "subtype=0x%02x, len=%d)\n",
  491. type, stype, skb->len);
  492. goto rx_dropped;
  493. }
  494. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  495. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  496. (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  497. goto rx_dropped;
  498. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  499. /* skb: hdr + (possibly fragmented) plaintext payload */
  500. // PR: FIXME: hostap has additional conditions in the "if" below:
  501. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  502. if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
  503. int flen;
  504. struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
  505. IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  506. if (!frag_skb) {
  507. IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
  508. "Rx cannot get skb from fragment "
  509. "cache (morefrag=%d seq=%u frag=%u)\n",
  510. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  511. WLAN_GET_SEQ_SEQ(sc), frag);
  512. goto rx_dropped;
  513. }
  514. flen = skb->len;
  515. if (frag != 0)
  516. flen -= hdrlen;
  517. if (frag_skb->tail + flen > frag_skb->end) {
  518. printk(KERN_WARNING "%s: host decrypted and "
  519. "reassembled frame did not fit skb\n",
  520. dev->name);
  521. ieee80211_frag_cache_invalidate(ieee, hdr);
  522. goto rx_dropped;
  523. }
  524. if (frag == 0) {
  525. /* copy first fragment (including full headers) into
  526. * beginning of the fragment cache skb */
  527. skb_copy_from_linear_data(skb, skb_put(frag_skb, flen), flen);
  528. } else {
  529. /* append frame payload to the end of the fragment
  530. * cache skb */
  531. skb_copy_from_linear_data_offset(skb, hdrlen,
  532. skb_put(frag_skb, flen), flen);
  533. }
  534. dev_kfree_skb_any(skb);
  535. skb = NULL;
  536. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  537. /* more fragments expected - leave the skb in fragment
  538. * cache for now; it will be delivered to upper layers
  539. * after all fragments have been received */
  540. goto rx_exit;
  541. }
  542. /* this was the last fragment and the frame will be
  543. * delivered, so remove skb from fragment cache */
  544. skb = frag_skb;
  545. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  546. ieee80211_frag_cache_invalidate(ieee, hdr);
  547. }
  548. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  549. * encrypted/authenticated */
  550. if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
  551. ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  552. goto rx_dropped;
  553. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  554. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  555. if ( /*ieee->ieee802_1x && */
  556. ieee80211_is_eapol_frame(ieee, skb)) {
  557. /* pass unencrypted EAPOL frames even if encryption is
  558. * configured */
  559. } else {
  560. IEEE80211_DEBUG_DROP("encryption configured, but RX "
  561. "frame not encrypted (SA=" MAC_FMT
  562. ")\n", MAC_ARG(hdr->addr2));
  563. goto rx_dropped;
  564. }
  565. }
  566. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  567. !ieee80211_is_eapol_frame(ieee, skb)) {
  568. IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
  569. "frame from " MAC_FMT
  570. " (drop_unencrypted=1)\n",
  571. MAC_ARG(hdr->addr2));
  572. goto rx_dropped;
  573. }
  574. /* If the frame was decrypted in hardware, we may need to strip off
  575. * any security data (IV, ICV, etc) that was left behind */
  576. if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
  577. ieee->host_strip_iv_icv) {
  578. int trimlen = 0;
  579. /* Top two-bits of byte 3 are the key index */
  580. if (skb->len >= hdrlen + 3)
  581. keyidx = skb->data[hdrlen + 3] >> 6;
  582. /* To strip off any security data which appears before the
  583. * payload, we simply increase hdrlen (as the header gets
  584. * chopped off immediately below). For the security data which
  585. * appears after the payload, we use skb_trim. */
  586. switch (ieee->sec.encode_alg[keyidx]) {
  587. case SEC_ALG_WEP:
  588. /* 4 byte IV */
  589. hdrlen += 4;
  590. /* 4 byte ICV */
  591. trimlen = 4;
  592. break;
  593. case SEC_ALG_TKIP:
  594. /* 4 byte IV, 4 byte ExtIV */
  595. hdrlen += 8;
  596. /* 8 byte MIC, 4 byte ICV */
  597. trimlen = 12;
  598. break;
  599. case SEC_ALG_CCMP:
  600. /* 8 byte CCMP header */
  601. hdrlen += 8;
  602. /* 8 byte MIC */
  603. trimlen = 8;
  604. break;
  605. }
  606. if (skb->len < trimlen)
  607. goto rx_dropped;
  608. __skb_trim(skb, skb->len - trimlen);
  609. if (skb->len < hdrlen)
  610. goto rx_dropped;
  611. }
  612. /* skb: hdr + (possible reassembled) full plaintext payload */
  613. payload = skb->data + hdrlen;
  614. ethertype = (payload[6] << 8) | payload[7];
  615. #ifdef NOT_YET
  616. /* If IEEE 802.1X is used, check whether the port is authorized to send
  617. * the received frame. */
  618. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  619. if (ethertype == ETH_P_PAE) {
  620. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  621. dev->name);
  622. if (ieee->hostapd && ieee->apdev) {
  623. /* Send IEEE 802.1X frames to the user
  624. * space daemon for processing */
  625. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  626. PRISM2_RX_MGMT);
  627. ieee->apdevstats.rx_packets++;
  628. ieee->apdevstats.rx_bytes += skb->len;
  629. goto rx_exit;
  630. }
  631. } else if (!frame_authorized) {
  632. printk(KERN_DEBUG "%s: dropped frame from "
  633. "unauthorized port (IEEE 802.1X): "
  634. "ethertype=0x%04x\n", dev->name, ethertype);
  635. goto rx_dropped;
  636. }
  637. }
  638. #endif
  639. /* convert hdr + possible LLC headers into Ethernet header */
  640. if (skb->len - hdrlen >= 8 &&
  641. ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
  642. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  643. memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
  644. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  645. * replace EtherType */
  646. skb_pull(skb, hdrlen + SNAP_SIZE);
  647. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  648. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  649. } else {
  650. u16 len;
  651. /* Leave Ethernet header part of hdr and full payload */
  652. skb_pull(skb, hdrlen);
  653. len = htons(skb->len);
  654. memcpy(skb_push(skb, 2), &len, 2);
  655. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  656. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  657. }
  658. #ifdef NOT_YET
  659. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  660. IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
  661. /* Non-standard frame: get addr4 from its bogus location after
  662. * the payload */
  663. skb_copy_to_linear_data_offset(skb, ETH_ALEN,
  664. skb->data + skb->len - ETH_ALEN,
  665. ETH_ALEN);
  666. skb_trim(skb, skb->len - ETH_ALEN);
  667. }
  668. #endif
  669. stats->rx_packets++;
  670. stats->rx_bytes += skb->len;
  671. #ifdef NOT_YET
  672. if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
  673. if (dst[0] & 0x01) {
  674. /* copy multicast frame both to the higher layers and
  675. * to the wireless media */
  676. ieee->ap->bridged_multicast++;
  677. skb2 = skb_clone(skb, GFP_ATOMIC);
  678. if (skb2 == NULL)
  679. printk(KERN_DEBUG "%s: skb_clone failed for "
  680. "multicast frame\n", dev->name);
  681. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  682. /* send frame directly to the associated STA using
  683. * wireless media and not passing to higher layers */
  684. ieee->ap->bridged_unicast++;
  685. skb2 = skb;
  686. skb = NULL;
  687. }
  688. }
  689. if (skb2 != NULL) {
  690. /* send to wireless media */
  691. skb2->dev = dev;
  692. skb2->protocol = __constant_htons(ETH_P_802_3);
  693. skb_reset_mac_header(skb2);
  694. skb_reset_network_header(skb2);
  695. /* skb2->network_header += ETH_HLEN; */
  696. dev_queue_xmit(skb2);
  697. }
  698. #endif
  699. if (skb) {
  700. skb->protocol = eth_type_trans(skb, dev);
  701. memset(skb->cb, 0, sizeof(skb->cb));
  702. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  703. if (netif_rx(skb) == NET_RX_DROP) {
  704. /* netif_rx always succeeds, but it might drop
  705. * the packet. If it drops the packet, we log that
  706. * in our stats. */
  707. IEEE80211_DEBUG_DROP
  708. ("RX: netif_rx dropped the packet\n");
  709. stats->rx_dropped++;
  710. }
  711. }
  712. rx_exit:
  713. #ifdef NOT_YET
  714. if (sta)
  715. hostap_handle_sta_release(sta);
  716. #endif
  717. return 1;
  718. rx_dropped:
  719. stats->rx_dropped++;
  720. /* Returning 0 indicates to caller that we have not handled the SKB--
  721. * so it is still allocated and can be used again by underlying
  722. * hardware as a DMA target */
  723. return 0;
  724. }
  725. /* Filter out unrelated packets, call ieee80211_rx[_mgt]
  726. * This function takes over the skb, it should not be used again after calling
  727. * this function. */
  728. void ieee80211_rx_any(struct ieee80211_device *ieee,
  729. struct sk_buff *skb, struct ieee80211_rx_stats *stats)
  730. {
  731. struct ieee80211_hdr_4addr *hdr;
  732. int is_packet_for_us;
  733. u16 fc;
  734. if (ieee->iw_mode == IW_MODE_MONITOR) {
  735. if (!ieee80211_rx(ieee, skb, stats))
  736. dev_kfree_skb_irq(skb);
  737. return;
  738. }
  739. if (skb->len < sizeof(struct ieee80211_hdr))
  740. goto drop_free;
  741. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  742. fc = le16_to_cpu(hdr->frame_ctl);
  743. if ((fc & IEEE80211_FCTL_VERS) != 0)
  744. goto drop_free;
  745. switch (fc & IEEE80211_FCTL_FTYPE) {
  746. case IEEE80211_FTYPE_MGMT:
  747. if (skb->len < sizeof(struct ieee80211_hdr_3addr))
  748. goto drop_free;
  749. ieee80211_rx_mgt(ieee, hdr, stats);
  750. dev_kfree_skb_irq(skb);
  751. return;
  752. case IEEE80211_FTYPE_DATA:
  753. break;
  754. case IEEE80211_FTYPE_CTL:
  755. return;
  756. default:
  757. return;
  758. }
  759. is_packet_for_us = 0;
  760. switch (ieee->iw_mode) {
  761. case IW_MODE_ADHOC:
  762. /* our BSS and not from/to DS */
  763. if (memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) == 0)
  764. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == 0) {
  765. /* promisc: get all */
  766. if (ieee->dev->flags & IFF_PROMISC)
  767. is_packet_for_us = 1;
  768. /* to us */
  769. else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
  770. is_packet_for_us = 1;
  771. /* mcast */
  772. else if (is_multicast_ether_addr(hdr->addr1))
  773. is_packet_for_us = 1;
  774. }
  775. break;
  776. case IW_MODE_INFRA:
  777. /* our BSS (== from our AP) and from DS */
  778. if (memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) == 0)
  779. if ((fc & (IEEE80211_FCTL_TODS+IEEE80211_FCTL_FROMDS)) == IEEE80211_FCTL_FROMDS) {
  780. /* promisc: get all */
  781. if (ieee->dev->flags & IFF_PROMISC)
  782. is_packet_for_us = 1;
  783. /* to us */
  784. else if (memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN) == 0)
  785. is_packet_for_us = 1;
  786. /* mcast */
  787. else if (is_multicast_ether_addr(hdr->addr1)) {
  788. /* not our own packet bcasted from AP */
  789. if (memcmp(hdr->addr3, ieee->dev->dev_addr, ETH_ALEN))
  790. is_packet_for_us = 1;
  791. }
  792. }
  793. break;
  794. default:
  795. /* ? */
  796. break;
  797. }
  798. if (is_packet_for_us)
  799. if (!ieee80211_rx(ieee, skb, stats))
  800. dev_kfree_skb_irq(skb);
  801. return;
  802. drop_free:
  803. dev_kfree_skb_irq(skb);
  804. ieee->stats.rx_dropped++;
  805. return;
  806. }
  807. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  808. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  809. /*
  810. * Make ther structure we read from the beacon packet has
  811. * the right values
  812. */
  813. static int ieee80211_verify_qos_info(struct ieee80211_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 ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
  830. *element_param, struct ieee80211_info_element
  831. *info_element)
  832. {
  833. int ret = 0;
  834. u16 size = sizeof(struct ieee80211_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 = ieee80211_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 ieee80211_read_qos_info_element(struct
  853. ieee80211_qos_information_element
  854. *element_info, struct ieee80211_info_element
  855. *info_element)
  856. {
  857. int ret = 0;
  858. u16 size = sizeof(struct ieee80211_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 = ieee80211_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 ieee80211_qos_convert_ac_to_parameters(struct
  879. ieee80211_qos_parameter_info
  880. *param_elm, struct
  881. ieee80211_qos_parameters
  882. *qos_param)
  883. {
  884. int rc = 0;
  885. int i;
  886. struct ieee80211_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] = (u16) ((1 << cw_min) - 1);
  896. cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
  897. qos_param->cw_max[i] = (u16) ((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] = (u16) 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 ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
  911. *info_element,
  912. struct ieee80211_network *network)
  913. {
  914. int rc = 0;
  915. struct ieee80211_qos_parameters *qos_param = NULL;
  916. struct ieee80211_qos_information_element qos_info_element;
  917. rc = ieee80211_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 ieee80211_qos_parameter_info param_element;
  923. rc = ieee80211_read_qos_param_element(&param_element,
  924. info_element);
  925. if (rc == 0) {
  926. qos_param = &(network->qos_data.parameters);
  927. ieee80211_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. IEEE80211_DEBUG_QOS("QoS is supported\n");
  936. network->qos_data.supported = 1;
  937. }
  938. return rc;
  939. }
  940. #ifdef CONFIG_IEEE80211_DEBUG
  941. #define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
  942. static const char *get_info_element_string(u16 id)
  943. {
  944. switch (id) {
  945. MFIE_STRING(SSID);
  946. MFIE_STRING(RATES);
  947. MFIE_STRING(FH_SET);
  948. MFIE_STRING(DS_SET);
  949. MFIE_STRING(CF_SET);
  950. MFIE_STRING(TIM);
  951. MFIE_STRING(IBSS_SET);
  952. MFIE_STRING(COUNTRY);
  953. MFIE_STRING(HOP_PARAMS);
  954. MFIE_STRING(HOP_TABLE);
  955. MFIE_STRING(REQUEST);
  956. MFIE_STRING(CHALLENGE);
  957. MFIE_STRING(POWER_CONSTRAINT);
  958. MFIE_STRING(POWER_CAPABILITY);
  959. MFIE_STRING(TPC_REQUEST);
  960. MFIE_STRING(TPC_REPORT);
  961. MFIE_STRING(SUPP_CHANNELS);
  962. MFIE_STRING(CSA);
  963. MFIE_STRING(MEASURE_REQUEST);
  964. MFIE_STRING(MEASURE_REPORT);
  965. MFIE_STRING(QUIET);
  966. MFIE_STRING(IBSS_DFS);
  967. MFIE_STRING(ERP_INFO);
  968. MFIE_STRING(RSN);
  969. MFIE_STRING(RATES_EX);
  970. MFIE_STRING(GENERIC);
  971. MFIE_STRING(QOS_PARAMETER);
  972. default:
  973. return "UNKNOWN";
  974. }
  975. }
  976. #endif
  977. static int ieee80211_parse_info_param(struct ieee80211_info_element
  978. *info_element, u16 length,
  979. struct ieee80211_network *network)
  980. {
  981. u8 i;
  982. #ifdef CONFIG_IEEE80211_DEBUG
  983. char rates_str[64];
  984. char *p;
  985. #endif
  986. while (length >= sizeof(*info_element)) {
  987. if (sizeof(*info_element) + info_element->len > length) {
  988. IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
  989. "info_element->len + 2 > left : "
  990. "info_element->len+2=%zd left=%d, id=%d.\n",
  991. info_element->len +
  992. sizeof(*info_element),
  993. length, info_element->id);
  994. /* We stop processing but don't return an error here
  995. * because some misbehaviour APs break this rule. ie.
  996. * Orinoco AP1000. */
  997. break;
  998. }
  999. switch (info_element->id) {
  1000. case MFIE_TYPE_SSID:
  1001. if (ieee80211_is_empty_essid(info_element->data,
  1002. info_element->len)) {
  1003. network->flags |= NETWORK_EMPTY_ESSID;
  1004. break;
  1005. }
  1006. network->ssid_len = min(info_element->len,
  1007. (u8) IW_ESSID_MAX_SIZE);
  1008. memcpy(network->ssid, info_element->data,
  1009. network->ssid_len);
  1010. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  1011. memset(network->ssid + network->ssid_len, 0,
  1012. IW_ESSID_MAX_SIZE - network->ssid_len);
  1013. IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
  1014. network->ssid, network->ssid_len);
  1015. break;
  1016. case MFIE_TYPE_RATES:
  1017. #ifdef CONFIG_IEEE80211_DEBUG
  1018. p = rates_str;
  1019. #endif
  1020. network->rates_len = min(info_element->len,
  1021. MAX_RATES_LENGTH);
  1022. for (i = 0; i < network->rates_len; i++) {
  1023. network->rates[i] = info_element->data[i];
  1024. #ifdef CONFIG_IEEE80211_DEBUG
  1025. p += snprintf(p, sizeof(rates_str) -
  1026. (p - rates_str), "%02X ",
  1027. network->rates[i]);
  1028. #endif
  1029. if (ieee80211_is_ofdm_rate
  1030. (info_element->data[i])) {
  1031. network->flags |= NETWORK_HAS_OFDM;
  1032. if (info_element->data[i] &
  1033. IEEE80211_BASIC_RATE_MASK)
  1034. network->flags &=
  1035. ~NETWORK_HAS_CCK;
  1036. }
  1037. }
  1038. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
  1039. rates_str, network->rates_len);
  1040. break;
  1041. case MFIE_TYPE_RATES_EX:
  1042. #ifdef CONFIG_IEEE80211_DEBUG
  1043. p = rates_str;
  1044. #endif
  1045. network->rates_ex_len = min(info_element->len,
  1046. MAX_RATES_EX_LENGTH);
  1047. for (i = 0; i < network->rates_ex_len; i++) {
  1048. network->rates_ex[i] = info_element->data[i];
  1049. #ifdef CONFIG_IEEE80211_DEBUG
  1050. p += snprintf(p, sizeof(rates_str) -
  1051. (p - rates_str), "%02X ",
  1052. network->rates[i]);
  1053. #endif
  1054. if (ieee80211_is_ofdm_rate
  1055. (info_element->data[i])) {
  1056. network->flags |= NETWORK_HAS_OFDM;
  1057. if (info_element->data[i] &
  1058. IEEE80211_BASIC_RATE_MASK)
  1059. network->flags &=
  1060. ~NETWORK_HAS_CCK;
  1061. }
  1062. }
  1063. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
  1064. rates_str, network->rates_ex_len);
  1065. break;
  1066. case MFIE_TYPE_DS_SET:
  1067. IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
  1068. info_element->data[0]);
  1069. network->channel = info_element->data[0];
  1070. break;
  1071. case MFIE_TYPE_FH_SET:
  1072. IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
  1073. break;
  1074. case MFIE_TYPE_CF_SET:
  1075. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
  1076. break;
  1077. case MFIE_TYPE_TIM:
  1078. network->tim.tim_count = info_element->data[0];
  1079. network->tim.tim_period = info_element->data[1];
  1080. IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
  1081. break;
  1082. case MFIE_TYPE_ERP_INFO:
  1083. network->erp_value = info_element->data[0];
  1084. network->flags |= NETWORK_HAS_ERP_VALUE;
  1085. IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
  1086. network->erp_value);
  1087. break;
  1088. case MFIE_TYPE_IBSS_SET:
  1089. network->atim_window = info_element->data[0];
  1090. IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
  1091. network->atim_window);
  1092. break;
  1093. case MFIE_TYPE_CHALLENGE:
  1094. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
  1095. break;
  1096. case MFIE_TYPE_GENERIC:
  1097. IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
  1098. info_element->len);
  1099. if (!ieee80211_parse_qos_info_param_IE(info_element,
  1100. network))
  1101. break;
  1102. if (info_element->len >= 4 &&
  1103. info_element->data[0] == 0x00 &&
  1104. info_element->data[1] == 0x50 &&
  1105. info_element->data[2] == 0xf2 &&
  1106. info_element->data[3] == 0x01) {
  1107. network->wpa_ie_len = min(info_element->len + 2,
  1108. MAX_WPA_IE_LEN);
  1109. memcpy(network->wpa_ie, info_element,
  1110. network->wpa_ie_len);
  1111. }
  1112. break;
  1113. case MFIE_TYPE_RSN:
  1114. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
  1115. info_element->len);
  1116. network->rsn_ie_len = min(info_element->len + 2,
  1117. MAX_WPA_IE_LEN);
  1118. memcpy(network->rsn_ie, info_element,
  1119. network->rsn_ie_len);
  1120. break;
  1121. case MFIE_TYPE_QOS_PARAMETER:
  1122. printk(KERN_ERR
  1123. "QoS Error need to parse QOS_PARAMETER IE\n");
  1124. break;
  1125. /* 802.11h */
  1126. case MFIE_TYPE_POWER_CONSTRAINT:
  1127. network->power_constraint = info_element->data[0];
  1128. network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
  1129. break;
  1130. case MFIE_TYPE_CSA:
  1131. network->power_constraint = info_element->data[0];
  1132. network->flags |= NETWORK_HAS_CSA;
  1133. break;
  1134. case MFIE_TYPE_QUIET:
  1135. network->quiet.count = info_element->data[0];
  1136. network->quiet.period = info_element->data[1];
  1137. network->quiet.duration = info_element->data[2];
  1138. network->quiet.offset = info_element->data[3];
  1139. network->flags |= NETWORK_HAS_QUIET;
  1140. break;
  1141. case MFIE_TYPE_IBSS_DFS:
  1142. if (network->ibss_dfs)
  1143. break;
  1144. network->ibss_dfs = kmemdup(info_element->data,
  1145. info_element->len,
  1146. GFP_ATOMIC);
  1147. if (!network->ibss_dfs)
  1148. return 1;
  1149. network->flags |= NETWORK_HAS_IBSS_DFS;
  1150. break;
  1151. case MFIE_TYPE_TPC_REPORT:
  1152. network->tpc_report.transmit_power =
  1153. info_element->data[0];
  1154. network->tpc_report.link_margin = info_element->data[1];
  1155. network->flags |= NETWORK_HAS_TPC_REPORT;
  1156. break;
  1157. default:
  1158. IEEE80211_DEBUG_MGMT
  1159. ("Unsupported info element: %s (%d)\n",
  1160. get_info_element_string(info_element->id),
  1161. info_element->id);
  1162. break;
  1163. }
  1164. length -= sizeof(*info_element) + info_element->len;
  1165. info_element =
  1166. (struct ieee80211_info_element *)&info_element->
  1167. data[info_element->len];
  1168. }
  1169. return 0;
  1170. }
  1171. static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
  1172. *frame, struct ieee80211_rx_stats *stats)
  1173. {
  1174. struct ieee80211_network network_resp = {
  1175. .ibss_dfs = NULL,
  1176. };
  1177. struct ieee80211_network *network = &network_resp;
  1178. struct net_device *dev = ieee->dev;
  1179. network->flags = 0;
  1180. network->qos_data.active = 0;
  1181. network->qos_data.supported = 0;
  1182. network->qos_data.param_count = 0;
  1183. network->qos_data.old_param_count = 0;
  1184. //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
  1185. network->atim_window = le16_to_cpu(frame->aid);
  1186. network->listen_interval = le16_to_cpu(frame->status);
  1187. memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
  1188. network->capability = le16_to_cpu(frame->capability);
  1189. network->last_scanned = jiffies;
  1190. network->rates_len = network->rates_ex_len = 0;
  1191. network->last_associate = 0;
  1192. network->ssid_len = 0;
  1193. network->erp_value =
  1194. (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
  1195. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1196. /* for A band (No DS info) */
  1197. network->channel = stats->received_channel;
  1198. } else
  1199. network->flags |= NETWORK_HAS_CCK;
  1200. network->wpa_ie_len = 0;
  1201. network->rsn_ie_len = 0;
  1202. if (ieee80211_parse_info_param
  1203. (frame->info_element, stats->len - sizeof(*frame), network))
  1204. return 1;
  1205. network->mode = 0;
  1206. if (stats->freq == IEEE80211_52GHZ_BAND)
  1207. network->mode = IEEE_A;
  1208. else {
  1209. if (network->flags & NETWORK_HAS_OFDM)
  1210. network->mode |= IEEE_G;
  1211. if (network->flags & NETWORK_HAS_CCK)
  1212. network->mode |= IEEE_B;
  1213. }
  1214. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  1215. network->flags |= NETWORK_EMPTY_ESSID;
  1216. memcpy(&network->stats, stats, sizeof(network->stats));
  1217. if (ieee->handle_assoc_response != NULL)
  1218. ieee->handle_assoc_response(dev, frame, network);
  1219. return 0;
  1220. }
  1221. /***************************************************/
  1222. static int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
  1223. *beacon,
  1224. struct ieee80211_network *network,
  1225. struct ieee80211_rx_stats *stats)
  1226. {
  1227. network->qos_data.active = 0;
  1228. network->qos_data.supported = 0;
  1229. network->qos_data.param_count = 0;
  1230. network->qos_data.old_param_count = 0;
  1231. /* Pull out fixed field data */
  1232. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  1233. network->capability = le16_to_cpu(beacon->capability);
  1234. network->last_scanned = jiffies;
  1235. network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
  1236. network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
  1237. network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
  1238. /* Where to pull this? beacon->listen_interval; */
  1239. network->listen_interval = 0x0A;
  1240. network->rates_len = network->rates_ex_len = 0;
  1241. network->last_associate = 0;
  1242. network->ssid_len = 0;
  1243. network->flags = 0;
  1244. network->atim_window = 0;
  1245. network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
  1246. 0x3 : 0x0;
  1247. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1248. /* for A band (No DS info) */
  1249. network->channel = stats->received_channel;
  1250. } else
  1251. network->flags |= NETWORK_HAS_CCK;
  1252. network->wpa_ie_len = 0;
  1253. network->rsn_ie_len = 0;
  1254. if (ieee80211_parse_info_param
  1255. (beacon->info_element, stats->len - sizeof(*beacon), network))
  1256. return 1;
  1257. network->mode = 0;
  1258. if (stats->freq == IEEE80211_52GHZ_BAND)
  1259. network->mode = IEEE_A;
  1260. else {
  1261. if (network->flags & NETWORK_HAS_OFDM)
  1262. network->mode |= IEEE_G;
  1263. if (network->flags & NETWORK_HAS_CCK)
  1264. network->mode |= IEEE_B;
  1265. }
  1266. if (network->mode == 0) {
  1267. IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
  1268. "network.\n",
  1269. escape_essid(network->ssid,
  1270. network->ssid_len),
  1271. MAC_ARG(network->bssid));
  1272. return 1;
  1273. }
  1274. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  1275. network->flags |= NETWORK_EMPTY_ESSID;
  1276. memcpy(&network->stats, stats, sizeof(network->stats));
  1277. return 0;
  1278. }
  1279. static inline int is_same_network(struct ieee80211_network *src,
  1280. struct ieee80211_network *dst)
  1281. {
  1282. /* A network is only a duplicate if the channel, BSSID, and ESSID
  1283. * all match. We treat all <hidden> with the same BSSID and channel
  1284. * as one network */
  1285. return ((src->ssid_len == dst->ssid_len) &&
  1286. (src->channel == dst->channel) &&
  1287. !compare_ether_addr(src->bssid, dst->bssid) &&
  1288. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  1289. }
  1290. static void update_network(struct ieee80211_network *dst,
  1291. struct ieee80211_network *src)
  1292. {
  1293. int qos_active;
  1294. u8 old_param;
  1295. ieee80211_network_reset(dst);
  1296. dst->ibss_dfs = src->ibss_dfs;
  1297. /* We only update the statistics if they were created by receiving
  1298. * the network information on the actual channel the network is on.
  1299. *
  1300. * This keeps beacons received on neighbor channels from bringing
  1301. * down the signal level of an AP. */
  1302. if (dst->channel == src->stats.received_channel)
  1303. memcpy(&dst->stats, &src->stats,
  1304. sizeof(struct ieee80211_rx_stats));
  1305. else
  1306. IEEE80211_DEBUG_SCAN("Network " MAC_FMT " info received "
  1307. "off channel (%d vs. %d)\n", MAC_ARG(src->bssid),
  1308. dst->channel, src->stats.received_channel);
  1309. dst->capability = src->capability;
  1310. memcpy(dst->rates, src->rates, src->rates_len);
  1311. dst->rates_len = src->rates_len;
  1312. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  1313. dst->rates_ex_len = src->rates_ex_len;
  1314. dst->mode = src->mode;
  1315. dst->flags = src->flags;
  1316. dst->time_stamp[0] = src->time_stamp[0];
  1317. dst->time_stamp[1] = src->time_stamp[1];
  1318. dst->beacon_interval = src->beacon_interval;
  1319. dst->listen_interval = src->listen_interval;
  1320. dst->atim_window = src->atim_window;
  1321. dst->erp_value = src->erp_value;
  1322. dst->tim = src->tim;
  1323. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  1324. dst->wpa_ie_len = src->wpa_ie_len;
  1325. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  1326. dst->rsn_ie_len = src->rsn_ie_len;
  1327. dst->last_scanned = jiffies;
  1328. qos_active = src->qos_data.active;
  1329. old_param = dst->qos_data.old_param_count;
  1330. if (dst->flags & NETWORK_HAS_QOS_MASK)
  1331. memcpy(&dst->qos_data, &src->qos_data,
  1332. sizeof(struct ieee80211_qos_data));
  1333. else {
  1334. dst->qos_data.supported = src->qos_data.supported;
  1335. dst->qos_data.param_count = src->qos_data.param_count;
  1336. }
  1337. if (dst->qos_data.supported == 1) {
  1338. if (dst->ssid_len)
  1339. IEEE80211_DEBUG_QOS
  1340. ("QoS the network %s is QoS supported\n",
  1341. dst->ssid);
  1342. else
  1343. IEEE80211_DEBUG_QOS
  1344. ("QoS the network is QoS supported\n");
  1345. }
  1346. dst->qos_data.active = qos_active;
  1347. dst->qos_data.old_param_count = old_param;
  1348. /* dst->last_associate is not overwritten */
  1349. }
  1350. static inline int is_beacon(__le16 fc)
  1351. {
  1352. return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
  1353. }
  1354. static void ieee80211_process_probe_response(struct ieee80211_device
  1355. *ieee, struct
  1356. ieee80211_probe_response
  1357. *beacon, struct ieee80211_rx_stats
  1358. *stats)
  1359. {
  1360. struct net_device *dev = ieee->dev;
  1361. struct ieee80211_network network = {
  1362. .ibss_dfs = NULL,
  1363. };
  1364. struct ieee80211_network *target;
  1365. struct ieee80211_network *oldest = NULL;
  1366. #ifdef CONFIG_IEEE80211_DEBUG
  1367. struct ieee80211_info_element *info_element = beacon->info_element;
  1368. #endif
  1369. unsigned long flags;
  1370. IEEE80211_DEBUG_SCAN("'%s' (" MAC_FMT
  1371. "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  1372. escape_essid(info_element->data,
  1373. info_element->len),
  1374. MAC_ARG(beacon->header.addr3),
  1375. (beacon->capability & (1 << 0xf)) ? '1' : '0',
  1376. (beacon->capability & (1 << 0xe)) ? '1' : '0',
  1377. (beacon->capability & (1 << 0xd)) ? '1' : '0',
  1378. (beacon->capability & (1 << 0xc)) ? '1' : '0',
  1379. (beacon->capability & (1 << 0xb)) ? '1' : '0',
  1380. (beacon->capability & (1 << 0xa)) ? '1' : '0',
  1381. (beacon->capability & (1 << 0x9)) ? '1' : '0',
  1382. (beacon->capability & (1 << 0x8)) ? '1' : '0',
  1383. (beacon->capability & (1 << 0x7)) ? '1' : '0',
  1384. (beacon->capability & (1 << 0x6)) ? '1' : '0',
  1385. (beacon->capability & (1 << 0x5)) ? '1' : '0',
  1386. (beacon->capability & (1 << 0x4)) ? '1' : '0',
  1387. (beacon->capability & (1 << 0x3)) ? '1' : '0',
  1388. (beacon->capability & (1 << 0x2)) ? '1' : '0',
  1389. (beacon->capability & (1 << 0x1)) ? '1' : '0',
  1390. (beacon->capability & (1 << 0x0)) ? '1' : '0');
  1391. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  1392. IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
  1393. escape_essid(info_element->data,
  1394. info_element->len),
  1395. MAC_ARG(beacon->header.addr3),
  1396. is_beacon(beacon->header.frame_ctl) ?
  1397. "BEACON" : "PROBE RESPONSE");
  1398. return;
  1399. }
  1400. /* The network parsed correctly -- so now we scan our known networks
  1401. * to see if we can find it in our list.
  1402. *
  1403. * NOTE: This search is definitely not optimized. Once its doing
  1404. * the "right thing" we'll optimize it for efficiency if
  1405. * necessary */
  1406. /* Search for this entry in the list and update it if it is
  1407. * already there. */
  1408. spin_lock_irqsave(&ieee->lock, flags);
  1409. list_for_each_entry(target, &ieee->network_list, list) {
  1410. if (is_same_network(target, &network))
  1411. break;
  1412. if ((oldest == NULL) ||
  1413. (target->last_scanned < oldest->last_scanned))
  1414. oldest = target;
  1415. }
  1416. /* If we didn't find a match, then get a new network slot to initialize
  1417. * with this beacon's information */
  1418. if (&target->list == &ieee->network_list) {
  1419. if (list_empty(&ieee->network_free_list)) {
  1420. /* If there are no more slots, expire the oldest */
  1421. list_del(&oldest->list);
  1422. target = oldest;
  1423. IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
  1424. "network list.\n",
  1425. escape_essid(target->ssid,
  1426. target->ssid_len),
  1427. MAC_ARG(target->bssid));
  1428. ieee80211_network_reset(target);
  1429. } else {
  1430. /* Otherwise just pull from the free list */
  1431. target = list_entry(ieee->network_free_list.next,
  1432. struct ieee80211_network, list);
  1433. list_del(ieee->network_free_list.next);
  1434. }
  1435. #ifdef CONFIG_IEEE80211_DEBUG
  1436. IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
  1437. escape_essid(network.ssid,
  1438. network.ssid_len),
  1439. MAC_ARG(network.bssid),
  1440. is_beacon(beacon->header.frame_ctl) ?
  1441. "BEACON" : "PROBE RESPONSE");
  1442. #endif
  1443. memcpy(target, &network, sizeof(*target));
  1444. network.ibss_dfs = NULL;
  1445. list_add_tail(&target->list, &ieee->network_list);
  1446. } else {
  1447. IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
  1448. escape_essid(target->ssid,
  1449. target->ssid_len),
  1450. MAC_ARG(target->bssid),
  1451. is_beacon(beacon->header.frame_ctl) ?
  1452. "BEACON" : "PROBE RESPONSE");
  1453. update_network(target, &network);
  1454. network.ibss_dfs = NULL;
  1455. }
  1456. spin_unlock_irqrestore(&ieee->lock, flags);
  1457. if (is_beacon(beacon->header.frame_ctl)) {
  1458. if (ieee->handle_beacon != NULL)
  1459. ieee->handle_beacon(dev, beacon, target);
  1460. } else {
  1461. if (ieee->handle_probe_response != NULL)
  1462. ieee->handle_probe_response(dev, beacon, target);
  1463. }
  1464. }
  1465. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1466. struct ieee80211_hdr_4addr *header,
  1467. struct ieee80211_rx_stats *stats)
  1468. {
  1469. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1470. case IEEE80211_STYPE_ASSOC_RESP:
  1471. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1472. WLAN_FC_GET_STYPE(le16_to_cpu
  1473. (header->frame_ctl)));
  1474. ieee80211_handle_assoc_resp(ieee,
  1475. (struct ieee80211_assoc_response *)
  1476. header, stats);
  1477. break;
  1478. case IEEE80211_STYPE_REASSOC_RESP:
  1479. IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1480. WLAN_FC_GET_STYPE(le16_to_cpu
  1481. (header->frame_ctl)));
  1482. break;
  1483. case IEEE80211_STYPE_PROBE_REQ:
  1484. IEEE80211_DEBUG_MGMT("received auth (%d)\n",
  1485. WLAN_FC_GET_STYPE(le16_to_cpu
  1486. (header->frame_ctl)));
  1487. if (ieee->handle_probe_request != NULL)
  1488. ieee->handle_probe_request(ieee->dev,
  1489. (struct
  1490. ieee80211_probe_request *)
  1491. header, stats);
  1492. break;
  1493. case IEEE80211_STYPE_PROBE_RESP:
  1494. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1495. WLAN_FC_GET_STYPE(le16_to_cpu
  1496. (header->frame_ctl)));
  1497. IEEE80211_DEBUG_SCAN("Probe response\n");
  1498. ieee80211_process_probe_response(ieee,
  1499. (struct
  1500. ieee80211_probe_response *)
  1501. header, stats);
  1502. break;
  1503. case IEEE80211_STYPE_BEACON:
  1504. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1505. WLAN_FC_GET_STYPE(le16_to_cpu
  1506. (header->frame_ctl)));
  1507. IEEE80211_DEBUG_SCAN("Beacon\n");
  1508. ieee80211_process_probe_response(ieee,
  1509. (struct
  1510. ieee80211_probe_response *)
  1511. header, stats);
  1512. break;
  1513. case IEEE80211_STYPE_AUTH:
  1514. IEEE80211_DEBUG_MGMT("received auth (%d)\n",
  1515. WLAN_FC_GET_STYPE(le16_to_cpu
  1516. (header->frame_ctl)));
  1517. if (ieee->handle_auth != NULL)
  1518. ieee->handle_auth(ieee->dev,
  1519. (struct ieee80211_auth *)header);
  1520. break;
  1521. case IEEE80211_STYPE_DISASSOC:
  1522. if (ieee->handle_disassoc != NULL)
  1523. ieee->handle_disassoc(ieee->dev,
  1524. (struct ieee80211_disassoc *)
  1525. header);
  1526. break;
  1527. case IEEE80211_STYPE_ACTION:
  1528. IEEE80211_DEBUG_MGMT("ACTION\n");
  1529. if (ieee->handle_action)
  1530. ieee->handle_action(ieee->dev,
  1531. (struct ieee80211_action *)
  1532. header, stats);
  1533. break;
  1534. case IEEE80211_STYPE_REASSOC_REQ:
  1535. IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
  1536. WLAN_FC_GET_STYPE(le16_to_cpu
  1537. (header->frame_ctl)));
  1538. IEEE80211_DEBUG_MGMT("%s: IEEE80211_REASSOC_REQ received\n",
  1539. ieee->dev->name);
  1540. if (ieee->handle_reassoc_request != NULL)
  1541. ieee->handle_reassoc_request(ieee->dev,
  1542. (struct ieee80211_reassoc_request *)
  1543. header);
  1544. break;
  1545. case IEEE80211_STYPE_ASSOC_REQ:
  1546. IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
  1547. WLAN_FC_GET_STYPE(le16_to_cpu
  1548. (header->frame_ctl)));
  1549. IEEE80211_DEBUG_MGMT("%s: IEEE80211_ASSOC_REQ received\n",
  1550. ieee->dev->name);
  1551. if (ieee->handle_assoc_request != NULL)
  1552. ieee->handle_assoc_request(ieee->dev);
  1553. break;
  1554. case IEEE80211_STYPE_DEAUTH:
  1555. IEEE80211_DEBUG_MGMT("DEAUTH\n");
  1556. if (ieee->handle_deauth != NULL)
  1557. ieee->handle_deauth(ieee->dev,
  1558. (struct ieee80211_deauth *)
  1559. header);
  1560. break;
  1561. default:
  1562. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1563. WLAN_FC_GET_STYPE(le16_to_cpu
  1564. (header->frame_ctl)));
  1565. IEEE80211_DEBUG_MGMT("%s: Unknown management packet: %d\n",
  1566. ieee->dev->name,
  1567. WLAN_FC_GET_STYPE(le16_to_cpu
  1568. (header->frame_ctl)));
  1569. break;
  1570. }
  1571. }
  1572. EXPORT_SYMBOL_GPL(ieee80211_rx_any);
  1573. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1574. EXPORT_SYMBOL(ieee80211_rx);