ieee80211_rx.c 52 KB

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