ieee80211_rx.c 52 KB

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