ieee80211_rx.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  1. /*
  2. * Original code based Host AP (software wireless LAN access point) driver
  3. * for Intersil Prism2/2.5/3 - hostap.o module, common routines
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <jkmaline@cc.hut.fi>
  7. * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  8. * Copyright (c) 2004-2005, Intel Corporation
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation. See README and COPYING for
  13. * more details.
  14. */
  15. #include <linux/compiler.h>
  16. #include <linux/config.h>
  17. #include <linux/errno.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/in6.h>
  20. #include <linux/in.h>
  21. #include <linux/ip.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/skbuff.h>
  27. #include <linux/slab.h>
  28. #include <linux/tcp.h>
  29. #include <linux/types.h>
  30. #include <linux/wireless.h>
  31. #include <linux/etherdevice.h>
  32. #include <asm/uaccess.h>
  33. #include <linux/ctype.h>
  34. #include <net/ieee80211.h>
  35. static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
  36. struct sk_buff *skb,
  37. struct ieee80211_rx_stats *rx_stats)
  38. {
  39. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  40. u16 fc = le16_to_cpu(hdr->frame_ctl);
  41. skb->dev = ieee->dev;
  42. skb->mac.raw = skb->data;
  43. skb_pull(skb, ieee80211_get_hdrlen(fc));
  44. skb->pkt_type = PACKET_OTHERHOST;
  45. skb->protocol = __constant_htons(ETH_P_80211_RAW);
  46. memset(skb->cb, 0, sizeof(skb->cb));
  47. netif_rx(skb);
  48. }
  49. /* Called only as a tasklet (software IRQ) */
  50. static struct ieee80211_frag_entry *ieee80211_frag_cache_find(struct
  51. ieee80211_device
  52. *ieee,
  53. unsigned int seq,
  54. unsigned int frag,
  55. u8 * src,
  56. u8 * dst)
  57. {
  58. struct ieee80211_frag_entry *entry;
  59. int i;
  60. for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) {
  61. entry = &ieee->frag_cache[i];
  62. if (entry->skb != NULL &&
  63. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  64. IEEE80211_DEBUG_FRAG("expiring fragment cache entry "
  65. "seq=%u last_frag=%u\n",
  66. entry->seq, entry->last_frag);
  67. dev_kfree_skb_any(entry->skb);
  68. entry->skb = NULL;
  69. }
  70. if (entry->skb != NULL && entry->seq == seq &&
  71. (entry->last_frag + 1 == frag || frag == -1) &&
  72. memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
  73. memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
  74. return entry;
  75. }
  76. return NULL;
  77. }
  78. /* Called only as a tasklet (software IRQ) */
  79. static struct sk_buff *ieee80211_frag_cache_get(struct ieee80211_device *ieee,
  80. struct ieee80211_hdr_4addr *hdr)
  81. {
  82. struct sk_buff *skb = NULL;
  83. u16 sc;
  84. unsigned int frag, seq;
  85. struct ieee80211_frag_entry *entry;
  86. sc = le16_to_cpu(hdr->seq_ctl);
  87. frag = WLAN_GET_SEQ_FRAG(sc);
  88. seq = WLAN_GET_SEQ_SEQ(sc);
  89. if (frag == 0) {
  90. /* Reserve enough space to fit maximum frame length */
  91. skb = dev_alloc_skb(ieee->dev->mtu +
  92. sizeof(struct ieee80211_hdr_4addr) +
  93. 8 /* LLC */ +
  94. 2 /* alignment */ +
  95. 8 /* WEP */ + ETH_ALEN /* WDS */ );
  96. if (skb == NULL)
  97. return NULL;
  98. entry = &ieee->frag_cache[ieee->frag_next_idx];
  99. ieee->frag_next_idx++;
  100. if (ieee->frag_next_idx >= IEEE80211_FRAG_CACHE_LEN)
  101. ieee->frag_next_idx = 0;
  102. if (entry->skb != NULL)
  103. dev_kfree_skb_any(entry->skb);
  104. entry->first_frag_time = jiffies;
  105. entry->seq = seq;
  106. entry->last_frag = frag;
  107. entry->skb = skb;
  108. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  109. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  110. } else {
  111. /* received a fragment of a frame for which the head fragment
  112. * should have already been received */
  113. entry = ieee80211_frag_cache_find(ieee, seq, frag, hdr->addr2,
  114. hdr->addr1);
  115. if (entry != NULL) {
  116. entry->last_frag = frag;
  117. skb = entry->skb;
  118. }
  119. }
  120. return skb;
  121. }
  122. /* Called only as a tasklet (software IRQ) */
  123. static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee,
  124. struct ieee80211_hdr_4addr *hdr)
  125. {
  126. u16 sc;
  127. unsigned int seq;
  128. struct ieee80211_frag_entry *entry;
  129. sc = le16_to_cpu(hdr->seq_ctl);
  130. seq = WLAN_GET_SEQ_SEQ(sc);
  131. entry = ieee80211_frag_cache_find(ieee, seq, -1, hdr->addr2,
  132. hdr->addr1);
  133. if (entry == NULL) {
  134. IEEE80211_DEBUG_FRAG("could not invalidate fragment cache "
  135. "entry (seq=%u)\n", seq);
  136. return -1;
  137. }
  138. entry->skb = NULL;
  139. return 0;
  140. }
  141. #ifdef NOT_YET
  142. /* ieee80211_rx_frame_mgtmt
  143. *
  144. * Responsible for handling management control frames
  145. *
  146. * Called by ieee80211_rx */
  147. static inline int
  148. ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
  149. struct ieee80211_rx_stats *rx_stats, u16 type,
  150. u16 stype)
  151. {
  152. if (ieee->iw_mode == IW_MODE_MASTER) {
  153. printk(KERN_DEBUG "%s: Master mode not yet suppported.\n",
  154. ieee->dev->name);
  155. return 0;
  156. /*
  157. hostap_update_sta_ps(ieee, (struct hostap_ieee80211_hdr_4addr *)
  158. skb->data);*/
  159. }
  160. if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
  161. if (stype == WLAN_FC_STYPE_BEACON &&
  162. ieee->iw_mode == IW_MODE_MASTER) {
  163. struct sk_buff *skb2;
  164. /* Process beacon frames also in kernel driver to
  165. * update STA(AP) table statistics */
  166. skb2 = skb_clone(skb, GFP_ATOMIC);
  167. if (skb2)
  168. hostap_rx(skb2->dev, skb2, rx_stats);
  169. }
  170. /* send management frames to the user space daemon for
  171. * processing */
  172. ieee->apdevstats.rx_packets++;
  173. ieee->apdevstats.rx_bytes += skb->len;
  174. prism2_rx_80211(ieee->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  175. return 0;
  176. }
  177. if (ieee->iw_mode == IW_MODE_MASTER) {
  178. if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
  179. printk(KERN_DEBUG "%s: unknown management frame "
  180. "(type=0x%02x, stype=0x%02x) dropped\n",
  181. skb->dev->name, type, stype);
  182. return -1;
  183. }
  184. hostap_rx(skb->dev, skb, rx_stats);
  185. return 0;
  186. }
  187. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: management frame "
  188. "received in non-Host AP mode\n", skb->dev->name);
  189. return -1;
  190. }
  191. #endif
  192. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  193. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  194. static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  195. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  196. static unsigned char bridge_tunnel_header[] =
  197. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  198. /* No encapsulation header if EtherType < 0x600 (=length) */
  199. /* Called by ieee80211_rx_frame_decrypt */
  200. static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee,
  201. struct sk_buff *skb)
  202. {
  203. struct net_device *dev = ieee->dev;
  204. u16 fc, ethertype;
  205. struct ieee80211_hdr_3addr *hdr;
  206. u8 *pos;
  207. if (skb->len < 24)
  208. return 0;
  209. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  210. fc = le16_to_cpu(hdr->frame_ctl);
  211. /* check that the frame is unicast frame to us */
  212. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  213. IEEE80211_FCTL_TODS &&
  214. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
  215. memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
  216. /* ToDS frame with own addr BSSID and DA */
  217. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  218. IEEE80211_FCTL_FROMDS &&
  219. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  220. /* FromDS frame with own addr as DA */
  221. } else
  222. return 0;
  223. if (skb->len < 24 + 8)
  224. return 0;
  225. /* check for port access entity Ethernet type */
  226. pos = skb->data + 24;
  227. ethertype = (pos[6] << 8) | pos[7];
  228. if (ethertype == ETH_P_PAE)
  229. return 1;
  230. return 0;
  231. }
  232. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  233. static inline int
  234. ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
  235. struct ieee80211_crypt_data *crypt)
  236. {
  237. struct ieee80211_hdr_3addr *hdr;
  238. int res, hdrlen;
  239. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  240. return 0;
  241. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  242. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  243. atomic_inc(&crypt->refcnt);
  244. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  245. atomic_dec(&crypt->refcnt);
  246. if (res < 0) {
  247. IEEE80211_DEBUG_DROP("decryption failed (SA=" MAC_FMT
  248. ") res=%d\n", MAC_ARG(hdr->addr2), res);
  249. if (res == -2)
  250. IEEE80211_DEBUG_DROP("Decryption failed ICV "
  251. "mismatch (key %d)\n",
  252. skb->data[hdrlen + 3] >> 6);
  253. ieee->ieee_stats.rx_discards_undecryptable++;
  254. return -1;
  255. }
  256. return res;
  257. }
  258. /* Called only as a tasklet (software IRQ), by ieee80211_rx */
  259. static inline int
  260. ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee,
  261. struct sk_buff *skb, int keyidx,
  262. struct ieee80211_crypt_data *crypt)
  263. {
  264. struct ieee80211_hdr_3addr *hdr;
  265. int res, hdrlen;
  266. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  267. return 0;
  268. hdr = (struct ieee80211_hdr_3addr *)skb->data;
  269. hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  270. atomic_inc(&crypt->refcnt);
  271. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  272. atomic_dec(&crypt->refcnt);
  273. if (res < 0) {
  274. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  275. " (SA=" MAC_FMT " keyidx=%d)\n",
  276. ieee->dev->name, MAC_ARG(hdr->addr2), keyidx);
  277. return -1;
  278. }
  279. return 0;
  280. }
  281. /* All received frames are sent to this function. @skb contains the frame in
  282. * IEEE 802.11 format, i.e., in the format it was sent over air.
  283. * This function is called only as a tasklet (software IRQ). */
  284. int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
  285. struct ieee80211_rx_stats *rx_stats)
  286. {
  287. struct net_device *dev = ieee->dev;
  288. struct ieee80211_hdr_4addr *hdr;
  289. size_t hdrlen;
  290. u16 fc, type, stype, sc;
  291. struct net_device_stats *stats;
  292. unsigned int frag;
  293. u8 *payload;
  294. u16 ethertype;
  295. #ifdef NOT_YET
  296. struct net_device *wds = NULL;
  297. struct sk_buff *skb2 = NULL;
  298. struct net_device *wds = NULL;
  299. int frame_authorized = 0;
  300. int from_assoc_ap = 0;
  301. void *sta = NULL;
  302. #endif
  303. u8 dst[ETH_ALEN];
  304. u8 src[ETH_ALEN];
  305. struct ieee80211_crypt_data *crypt = NULL;
  306. int keyidx = 0;
  307. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  308. stats = &ieee->stats;
  309. if (skb->len < 10) {
  310. printk(KERN_INFO "%s: SKB length < 10\n", dev->name);
  311. goto rx_dropped;
  312. }
  313. fc = le16_to_cpu(hdr->frame_ctl);
  314. type = WLAN_FC_GET_TYPE(fc);
  315. stype = WLAN_FC_GET_STYPE(fc);
  316. sc = le16_to_cpu(hdr->seq_ctl);
  317. frag = WLAN_GET_SEQ_FRAG(sc);
  318. hdrlen = ieee80211_get_hdrlen(fc);
  319. /* Put this code here so that we avoid duplicating it in all
  320. * Rx paths. - Jean II */
  321. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  322. #ifdef CONFIG_NET_RADIO
  323. /* If spy monitoring on */
  324. if (ieee->spy_data.spy_number > 0) {
  325. struct iw_quality wstats;
  326. wstats.updated = 0;
  327. if (rx_stats->mask & IEEE80211_STATMASK_RSSI) {
  328. wstats.level = rx_stats->rssi;
  329. wstats.updated |= IW_QUAL_LEVEL_UPDATED;
  330. } else
  331. wstats.updated |= IW_QUAL_LEVEL_INVALID;
  332. if (rx_stats->mask & IEEE80211_STATMASK_NOISE) {
  333. wstats.noise = rx_stats->noise;
  334. wstats.updated |= IW_QUAL_NOISE_UPDATED;
  335. } else
  336. wstats.updated |= IW_QUAL_NOISE_INVALID;
  337. if (rx_stats->mask & IEEE80211_STATMASK_SIGNAL) {
  338. wstats.qual = rx_stats->signal;
  339. wstats.updated |= IW_QUAL_QUAL_UPDATED;
  340. } else
  341. wstats.updated |= IW_QUAL_QUAL_INVALID;
  342. /* Update spy records */
  343. wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
  344. }
  345. #endif /* CONFIG_NET_RADIO */
  346. #endif /* IW_WIRELESS_SPY */
  347. #ifdef NOT_YET
  348. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  349. #endif
  350. if (ieee->iw_mode == IW_MODE_MONITOR) {
  351. ieee80211_monitor_rx(ieee, skb, rx_stats);
  352. stats->rx_packets++;
  353. stats->rx_bytes += skb->len;
  354. return 1;
  355. }
  356. if ((is_multicast_ether_addr(hdr->addr1) ||
  357. is_broadcast_ether_addr(hdr->addr2)) ? ieee->host_mc_decrypt :
  358. ieee->host_decrypt) {
  359. int idx = 0;
  360. if (skb->len >= hdrlen + 3)
  361. idx = skb->data[hdrlen + 3] >> 6;
  362. crypt = ieee->crypt[idx];
  363. #ifdef NOT_YET
  364. sta = NULL;
  365. /* Use station specific key to override default keys if the
  366. * receiver address is a unicast address ("individual RA"). If
  367. * bcrx_sta_key parameter is set, station specific key is used
  368. * even with broad/multicast targets (this is against IEEE
  369. * 802.11, but makes it easier to use different keys with
  370. * stations that do not support WEP key mapping). */
  371. if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
  372. (void)hostap_handle_sta_crypto(local, hdr, &crypt,
  373. &sta);
  374. #endif
  375. /* allow NULL decrypt to indicate an station specific override
  376. * for default encryption */
  377. if (crypt && (crypt->ops == NULL ||
  378. crypt->ops->decrypt_mpdu == NULL))
  379. crypt = NULL;
  380. if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
  381. /* This seems to be triggered by some (multicast?)
  382. * frames from other than current BSS, so just drop the
  383. * frames silently instead of filling system log with
  384. * these reports. */
  385. IEEE80211_DEBUG_DROP("Decryption failed (not set)"
  386. " (SA=" MAC_FMT ")\n",
  387. MAC_ARG(hdr->addr2));
  388. ieee->ieee_stats.rx_discards_undecryptable++;
  389. goto rx_dropped;
  390. }
  391. }
  392. #ifdef NOT_YET
  393. if (type != WLAN_FC_TYPE_DATA) {
  394. if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
  395. fc & IEEE80211_FCTL_PROTECTED && ieee->host_decrypt &&
  396. (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
  397. printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
  398. "from " MAC_FMT "\n", dev->name,
  399. MAC_ARG(hdr->addr2));
  400. /* TODO: could inform hostapd about this so that it
  401. * could send auth failure report */
  402. goto rx_dropped;
  403. }
  404. if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
  405. goto rx_dropped;
  406. else
  407. goto rx_exit;
  408. }
  409. #endif
  410. /* Data frame - extract src/dst addresses */
  411. if (skb->len < IEEE80211_3ADDR_LEN)
  412. goto rx_dropped;
  413. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  414. case IEEE80211_FCTL_FROMDS:
  415. memcpy(dst, hdr->addr1, ETH_ALEN);
  416. memcpy(src, hdr->addr3, ETH_ALEN);
  417. break;
  418. case IEEE80211_FCTL_TODS:
  419. memcpy(dst, hdr->addr3, ETH_ALEN);
  420. memcpy(src, hdr->addr2, ETH_ALEN);
  421. break;
  422. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  423. if (skb->len < IEEE80211_4ADDR_LEN)
  424. goto rx_dropped;
  425. memcpy(dst, hdr->addr3, ETH_ALEN);
  426. memcpy(src, hdr->addr4, ETH_ALEN);
  427. break;
  428. case 0:
  429. memcpy(dst, hdr->addr1, ETH_ALEN);
  430. memcpy(src, hdr->addr2, ETH_ALEN);
  431. break;
  432. }
  433. #ifdef NOT_YET
  434. if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
  435. goto rx_dropped;
  436. if (wds) {
  437. skb->dev = dev = wds;
  438. stats = hostap_get_stats(dev);
  439. }
  440. if (ieee->iw_mode == IW_MODE_MASTER && !wds &&
  441. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  442. IEEE80211_FCTL_FROMDS && ieee->stadev
  443. && memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {
  444. /* Frame from BSSID of the AP for which we are a client */
  445. skb->dev = dev = ieee->stadev;
  446. stats = hostap_get_stats(dev);
  447. from_assoc_ap = 1;
  448. }
  449. #endif
  450. dev->last_rx = jiffies;
  451. #ifdef NOT_YET
  452. if ((ieee->iw_mode == IW_MODE_MASTER ||
  453. ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {
  454. switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
  455. wds != NULL)) {
  456. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  457. frame_authorized = 0;
  458. break;
  459. case AP_RX_CONTINUE:
  460. frame_authorized = 1;
  461. break;
  462. case AP_RX_DROP:
  463. goto rx_dropped;
  464. case AP_RX_EXIT:
  465. goto rx_exit;
  466. }
  467. }
  468. #endif
  469. /* Nullfunc frames may have PS-bit set, so they must be passed to
  470. * hostap_handle_sta_rx() before being dropped here. */
  471. stype &= ~IEEE80211_STYPE_QOS_DATA;
  472. if (stype != IEEE80211_STYPE_DATA &&
  473. stype != IEEE80211_STYPE_DATA_CFACK &&
  474. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  475. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  476. if (stype != IEEE80211_STYPE_NULLFUNC)
  477. IEEE80211_DEBUG_DROP("RX: dropped data frame "
  478. "with no data (type=0x%02x, "
  479. "subtype=0x%02x, len=%d)\n",
  480. type, stype, skb->len);
  481. goto rx_dropped;
  482. }
  483. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  484. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  485. (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
  486. goto rx_dropped;
  487. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  488. /* skb: hdr + (possibly fragmented) plaintext payload */
  489. // PR: FIXME: hostap has additional conditions in the "if" below:
  490. // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  491. if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
  492. int flen;
  493. struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
  494. IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
  495. if (!frag_skb) {
  496. IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,
  497. "Rx cannot get skb from fragment "
  498. "cache (morefrag=%d seq=%u frag=%u)\n",
  499. (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  500. WLAN_GET_SEQ_SEQ(sc), frag);
  501. goto rx_dropped;
  502. }
  503. flen = skb->len;
  504. if (frag != 0)
  505. flen -= hdrlen;
  506. if (frag_skb->tail + flen > frag_skb->end) {
  507. printk(KERN_WARNING "%s: host decrypted and "
  508. "reassembled frame did not fit skb\n",
  509. dev->name);
  510. ieee80211_frag_cache_invalidate(ieee, hdr);
  511. goto rx_dropped;
  512. }
  513. if (frag == 0) {
  514. /* copy first fragment (including full headers) into
  515. * beginning of the fragment cache skb */
  516. memcpy(skb_put(frag_skb, flen), skb->data, flen);
  517. } else {
  518. /* append frame payload to the end of the fragment
  519. * cache skb */
  520. memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
  521. flen);
  522. }
  523. dev_kfree_skb_any(skb);
  524. skb = NULL;
  525. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  526. /* more fragments expected - leave the skb in fragment
  527. * cache for now; it will be delivered to upper layers
  528. * after all fragments have been received */
  529. goto rx_exit;
  530. }
  531. /* this was the last fragment and the frame will be
  532. * delivered, so remove skb from fragment cache */
  533. skb = frag_skb;
  534. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  535. ieee80211_frag_cache_invalidate(ieee, hdr);
  536. }
  537. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  538. * encrypted/authenticated */
  539. if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  540. ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
  541. goto rx_dropped;
  542. hdr = (struct ieee80211_hdr_4addr *)skb->data;
  543. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {
  544. if ( /*ieee->ieee802_1x && */
  545. ieee80211_is_eapol_frame(ieee, skb)) {
  546. /* pass unencrypted EAPOL frames even if encryption is
  547. * configured */
  548. } else {
  549. IEEE80211_DEBUG_DROP("encryption configured, but RX "
  550. "frame not encrypted (SA=" MAC_FMT
  551. ")\n", MAC_ARG(hdr->addr2));
  552. goto rx_dropped;
  553. }
  554. }
  555. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&
  556. !ieee80211_is_eapol_frame(ieee, skb)) {
  557. IEEE80211_DEBUG_DROP("dropped unencrypted RX data "
  558. "frame from " MAC_FMT
  559. " (drop_unencrypted=1)\n",
  560. MAC_ARG(hdr->addr2));
  561. goto rx_dropped;
  562. }
  563. /* skb: hdr + (possible reassembled) full plaintext payload */
  564. payload = skb->data + hdrlen;
  565. ethertype = (payload[6] << 8) | payload[7];
  566. #ifdef NOT_YET
  567. /* If IEEE 802.1X is used, check whether the port is authorized to send
  568. * the received frame. */
  569. if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {
  570. if (ethertype == ETH_P_PAE) {
  571. printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",
  572. dev->name);
  573. if (ieee->hostapd && ieee->apdev) {
  574. /* Send IEEE 802.1X frames to the user
  575. * space daemon for processing */
  576. prism2_rx_80211(ieee->apdev, skb, rx_stats,
  577. PRISM2_RX_MGMT);
  578. ieee->apdevstats.rx_packets++;
  579. ieee->apdevstats.rx_bytes += skb->len;
  580. goto rx_exit;
  581. }
  582. } else if (!frame_authorized) {
  583. printk(KERN_DEBUG "%s: dropped frame from "
  584. "unauthorized port (IEEE 802.1X): "
  585. "ethertype=0x%04x\n", dev->name, ethertype);
  586. goto rx_dropped;
  587. }
  588. }
  589. #endif
  590. /* convert hdr + possible LLC headers into Ethernet header */
  591. if (skb->len - hdrlen >= 8 &&
  592. ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&
  593. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  594. memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {
  595. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  596. * replace EtherType */
  597. skb_pull(skb, hdrlen + SNAP_SIZE);
  598. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  599. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  600. } else {
  601. u16 len;
  602. /* Leave Ethernet header part of hdr and full payload */
  603. skb_pull(skb, hdrlen);
  604. len = htons(skb->len);
  605. memcpy(skb_push(skb, 2), &len, 2);
  606. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  607. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  608. }
  609. #ifdef NOT_YET
  610. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  611. IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {
  612. /* Non-standard frame: get addr4 from its bogus location after
  613. * the payload */
  614. memcpy(skb->data + ETH_ALEN,
  615. skb->data + skb->len - ETH_ALEN, ETH_ALEN);
  616. skb_trim(skb, skb->len - ETH_ALEN);
  617. }
  618. #endif
  619. stats->rx_packets++;
  620. stats->rx_bytes += skb->len;
  621. #ifdef NOT_YET
  622. if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {
  623. if (dst[0] & 0x01) {
  624. /* copy multicast frame both to the higher layers and
  625. * to the wireless media */
  626. ieee->ap->bridged_multicast++;
  627. skb2 = skb_clone(skb, GFP_ATOMIC);
  628. if (skb2 == NULL)
  629. printk(KERN_DEBUG "%s: skb_clone failed for "
  630. "multicast frame\n", dev->name);
  631. } else if (hostap_is_sta_assoc(ieee->ap, dst)) {
  632. /* send frame directly to the associated STA using
  633. * wireless media and not passing to higher layers */
  634. ieee->ap->bridged_unicast++;
  635. skb2 = skb;
  636. skb = NULL;
  637. }
  638. }
  639. if (skb2 != NULL) {
  640. /* send to wireless media */
  641. skb2->protocol = __constant_htons(ETH_P_802_3);
  642. skb2->mac.raw = skb2->nh.raw = skb2->data;
  643. /* skb2->nh.raw = skb2->data + ETH_HLEN; */
  644. skb2->dev = dev;
  645. dev_queue_xmit(skb2);
  646. }
  647. #endif
  648. if (skb) {
  649. skb->protocol = eth_type_trans(skb, dev);
  650. memset(skb->cb, 0, sizeof(skb->cb));
  651. skb->dev = dev;
  652. skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
  653. netif_rx(skb);
  654. }
  655. rx_exit:
  656. #ifdef NOT_YET
  657. if (sta)
  658. hostap_handle_sta_release(sta);
  659. #endif
  660. return 1;
  661. rx_dropped:
  662. stats->rx_dropped++;
  663. /* Returning 0 indicates to caller that we have not handled the SKB--
  664. * so it is still allocated and can be used again by underlying
  665. * hardware as a DMA target */
  666. return 0;
  667. }
  668. #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
  669. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  670. /*
  671. * Make ther structure we read from the beacon packet has
  672. * the right values
  673. */
  674. static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
  675. *info_element, int sub_type)
  676. {
  677. if (info_element->qui_subtype != sub_type)
  678. return -1;
  679. if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
  680. return -1;
  681. if (info_element->qui_type != QOS_OUI_TYPE)
  682. return -1;
  683. if (info_element->version != QOS_VERSION_1)
  684. return -1;
  685. return 0;
  686. }
  687. /*
  688. * Parse a QoS parameter element
  689. */
  690. static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
  691. *element_param, struct ieee80211_info_element
  692. *info_element)
  693. {
  694. int ret = 0;
  695. u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
  696. if ((info_element == NULL) || (element_param == NULL))
  697. return -1;
  698. if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
  699. memcpy(element_param->info_element.qui, info_element->data,
  700. info_element->len);
  701. element_param->info_element.elementID = info_element->id;
  702. element_param->info_element.length = info_element->len;
  703. } else
  704. ret = -1;
  705. if (ret == 0)
  706. ret = ieee80211_verify_qos_info(&element_param->info_element,
  707. QOS_OUI_PARAM_SUB_TYPE);
  708. return ret;
  709. }
  710. /*
  711. * Parse a QoS information element
  712. */
  713. static int ieee80211_read_qos_info_element(struct
  714. ieee80211_qos_information_element
  715. *element_info, struct ieee80211_info_element
  716. *info_element)
  717. {
  718. int ret = 0;
  719. u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
  720. if (element_info == NULL)
  721. return -1;
  722. if (info_element == NULL)
  723. return -1;
  724. if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
  725. memcpy(element_info->qui, info_element->data,
  726. info_element->len);
  727. element_info->elementID = info_element->id;
  728. element_info->length = info_element->len;
  729. } else
  730. ret = -1;
  731. if (ret == 0)
  732. ret = ieee80211_verify_qos_info(element_info,
  733. QOS_OUI_INFO_SUB_TYPE);
  734. return ret;
  735. }
  736. /*
  737. * Write QoS parameters from the ac parameters.
  738. */
  739. static int ieee80211_qos_convert_ac_to_parameters(struct
  740. ieee80211_qos_parameter_info
  741. *param_elm, struct
  742. ieee80211_qos_parameters
  743. *qos_param)
  744. {
  745. int rc = 0;
  746. int i;
  747. struct ieee80211_qos_ac_parameter *ac_params;
  748. u32 txop;
  749. u8 cw_min;
  750. u8 cw_max;
  751. for (i = 0; i < QOS_QUEUE_NUM; i++) {
  752. ac_params = &(param_elm->ac_params_record[i]);
  753. qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;
  754. qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;
  755. cw_min = ac_params->ecw_min_max & 0x0F;
  756. qos_param->cw_min[i] = (u16) ((1 << cw_min) - 1);
  757. cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;
  758. qos_param->cw_max[i] = (u16) ((1 << cw_max) - 1);
  759. qos_param->flag[i] =
  760. (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
  761. txop = le16_to_cpu(ac_params->tx_op_limit) * 32;
  762. qos_param->tx_op_limit[i] = (u16) txop;
  763. }
  764. return rc;
  765. }
  766. /*
  767. * we have a generic data element which it may contain QoS information or
  768. * parameters element. check the information element length to decide
  769. * which type to read
  770. */
  771. static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
  772. *info_element,
  773. struct ieee80211_network *network)
  774. {
  775. int rc = 0;
  776. struct ieee80211_qos_parameters *qos_param = NULL;
  777. struct ieee80211_qos_information_element qos_info_element;
  778. rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
  779. if (rc == 0) {
  780. network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
  781. network->flags |= NETWORK_HAS_QOS_INFORMATION;
  782. } else {
  783. struct ieee80211_qos_parameter_info param_element;
  784. rc = ieee80211_read_qos_param_element(&param_element,
  785. info_element);
  786. if (rc == 0) {
  787. qos_param = &(network->qos_data.parameters);
  788. ieee80211_qos_convert_ac_to_parameters(&param_element,
  789. qos_param);
  790. network->flags |= NETWORK_HAS_QOS_PARAMETERS;
  791. network->qos_data.param_count =
  792. param_element.info_element.ac_info & 0x0F;
  793. }
  794. }
  795. if (rc == 0) {
  796. IEEE80211_DEBUG_QOS("QoS is supported\n");
  797. network->qos_data.supported = 1;
  798. }
  799. return rc;
  800. }
  801. static int ieee80211_parse_info_param(struct ieee80211_info_element
  802. *info_element, u16 length,
  803. struct ieee80211_network *network)
  804. {
  805. u8 i;
  806. #ifdef CONFIG_IEEE80211_DEBUG
  807. char rates_str[64];
  808. char *p;
  809. #endif
  810. while (length >= sizeof(*info_element)) {
  811. if (sizeof(*info_element) + info_element->len > length) {
  812. IEEE80211_DEBUG_MGMT("Info elem: parse failed: "
  813. "info_element->len + 2 > left : "
  814. "info_element->len+2=%zd left=%d, id=%d.\n",
  815. info_element->len +
  816. sizeof(*info_element),
  817. length, info_element->id);
  818. return 1;
  819. }
  820. switch (info_element->id) {
  821. case MFIE_TYPE_SSID:
  822. if (ieee80211_is_empty_essid(info_element->data,
  823. info_element->len)) {
  824. network->flags |= NETWORK_EMPTY_ESSID;
  825. break;
  826. }
  827. network->ssid_len = min(info_element->len,
  828. (u8) IW_ESSID_MAX_SIZE);
  829. memcpy(network->ssid, info_element->data,
  830. network->ssid_len);
  831. if (network->ssid_len < IW_ESSID_MAX_SIZE)
  832. memset(network->ssid + network->ssid_len, 0,
  833. IW_ESSID_MAX_SIZE - network->ssid_len);
  834. IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
  835. network->ssid, network->ssid_len);
  836. break;
  837. case MFIE_TYPE_RATES:
  838. #ifdef CONFIG_IEEE80211_DEBUG
  839. p = rates_str;
  840. #endif
  841. network->rates_len = min(info_element->len,
  842. MAX_RATES_LENGTH);
  843. for (i = 0; i < network->rates_len; i++) {
  844. network->rates[i] = info_element->data[i];
  845. #ifdef CONFIG_IEEE80211_DEBUG
  846. p += snprintf(p, sizeof(rates_str) -
  847. (p - rates_str), "%02X ",
  848. network->rates[i]);
  849. #endif
  850. if (ieee80211_is_ofdm_rate
  851. (info_element->data[i])) {
  852. network->flags |= NETWORK_HAS_OFDM;
  853. if (info_element->data[i] &
  854. IEEE80211_BASIC_RATE_MASK)
  855. network->flags &=
  856. ~NETWORK_HAS_CCK;
  857. }
  858. }
  859. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
  860. rates_str, network->rates_len);
  861. break;
  862. case MFIE_TYPE_RATES_EX:
  863. #ifdef CONFIG_IEEE80211_DEBUG
  864. p = rates_str;
  865. #endif
  866. network->rates_ex_len = min(info_element->len,
  867. MAX_RATES_EX_LENGTH);
  868. for (i = 0; i < network->rates_ex_len; i++) {
  869. network->rates_ex[i] = info_element->data[i];
  870. #ifdef CONFIG_IEEE80211_DEBUG
  871. p += snprintf(p, sizeof(rates_str) -
  872. (p - rates_str), "%02X ",
  873. network->rates[i]);
  874. #endif
  875. if (ieee80211_is_ofdm_rate
  876. (info_element->data[i])) {
  877. network->flags |= NETWORK_HAS_OFDM;
  878. if (info_element->data[i] &
  879. IEEE80211_BASIC_RATE_MASK)
  880. network->flags &=
  881. ~NETWORK_HAS_CCK;
  882. }
  883. }
  884. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
  885. rates_str, network->rates_ex_len);
  886. break;
  887. case MFIE_TYPE_DS_SET:
  888. IEEE80211_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
  889. info_element->data[0]);
  890. network->channel = info_element->data[0];
  891. break;
  892. case MFIE_TYPE_FH_SET:
  893. IEEE80211_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
  894. break;
  895. case MFIE_TYPE_CF_SET:
  896. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
  897. break;
  898. case MFIE_TYPE_TIM:
  899. IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: ignored\n");
  900. break;
  901. case MFIE_TYPE_ERP_INFO:
  902. network->erp_value = info_element->data[0];
  903. IEEE80211_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
  904. network->erp_value);
  905. break;
  906. case MFIE_TYPE_IBSS_SET:
  907. network->atim_window = info_element->data[0];
  908. IEEE80211_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
  909. network->atim_window);
  910. break;
  911. case MFIE_TYPE_CHALLENGE:
  912. IEEE80211_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
  913. break;
  914. case MFIE_TYPE_GENERIC:
  915. IEEE80211_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
  916. info_element->len);
  917. if (!ieee80211_parse_qos_info_param_IE(info_element,
  918. network))
  919. break;
  920. if (info_element->len >= 4 &&
  921. info_element->data[0] == 0x00 &&
  922. info_element->data[1] == 0x50 &&
  923. info_element->data[2] == 0xf2 &&
  924. info_element->data[3] == 0x01) {
  925. network->wpa_ie_len = min(info_element->len + 2,
  926. MAX_WPA_IE_LEN);
  927. memcpy(network->wpa_ie, info_element,
  928. network->wpa_ie_len);
  929. }
  930. break;
  931. case MFIE_TYPE_RSN:
  932. IEEE80211_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
  933. info_element->len);
  934. network->rsn_ie_len = min(info_element->len + 2,
  935. MAX_WPA_IE_LEN);
  936. memcpy(network->rsn_ie, info_element,
  937. network->rsn_ie_len);
  938. break;
  939. case MFIE_TYPE_QOS_PARAMETER:
  940. printk(KERN_ERR
  941. "QoS Error need to parse QOS_PARAMETER IE\n");
  942. break;
  943. default:
  944. IEEE80211_DEBUG_MGMT("unsupported IE %d\n",
  945. info_element->id);
  946. break;
  947. }
  948. length -= sizeof(*info_element) + info_element->len;
  949. info_element =
  950. (struct ieee80211_info_element *)&info_element->
  951. data[info_element->len];
  952. }
  953. return 0;
  954. }
  955. static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
  956. *frame, struct ieee80211_rx_stats *stats)
  957. {
  958. struct ieee80211_network network_resp;
  959. struct ieee80211_network *network = &network_resp;
  960. struct net_device *dev = ieee->dev;
  961. network->flags = 0;
  962. network->qos_data.active = 0;
  963. network->qos_data.supported = 0;
  964. network->qos_data.param_count = 0;
  965. network->qos_data.old_param_count = 0;
  966. //network->atim_window = le16_to_cpu(frame->aid) & (0x3FFF);
  967. network->atim_window = le16_to_cpu(frame->aid);
  968. network->listen_interval = le16_to_cpu(frame->status);
  969. memcpy(network->bssid, frame->header.addr3, ETH_ALEN);
  970. network->capability = le16_to_cpu(frame->capability);
  971. network->last_scanned = jiffies;
  972. network->rates_len = network->rates_ex_len = 0;
  973. network->last_associate = 0;
  974. network->ssid_len = 0;
  975. network->erp_value =
  976. (network->capability & WLAN_CAPABILITY_IBSS) ? 0x3 : 0x0;
  977. if (stats->freq == IEEE80211_52GHZ_BAND) {
  978. /* for A band (No DS info) */
  979. network->channel = stats->received_channel;
  980. } else
  981. network->flags |= NETWORK_HAS_CCK;
  982. network->wpa_ie_len = 0;
  983. network->rsn_ie_len = 0;
  984. if (ieee80211_parse_info_param
  985. (frame->info_element, stats->len - sizeof(*frame), network))
  986. return 1;
  987. network->mode = 0;
  988. if (stats->freq == IEEE80211_52GHZ_BAND)
  989. network->mode = IEEE_A;
  990. else {
  991. if (network->flags & NETWORK_HAS_OFDM)
  992. network->mode |= IEEE_G;
  993. if (network->flags & NETWORK_HAS_CCK)
  994. network->mode |= IEEE_B;
  995. }
  996. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  997. network->flags |= NETWORK_EMPTY_ESSID;
  998. memcpy(&network->stats, stats, sizeof(network->stats));
  999. if (ieee->handle_assoc_response != NULL)
  1000. ieee->handle_assoc_response(dev, frame, network);
  1001. return 0;
  1002. }
  1003. /***************************************************/
  1004. static inline int ieee80211_network_init(struct ieee80211_device *ieee, struct ieee80211_probe_response
  1005. *beacon,
  1006. struct ieee80211_network *network,
  1007. struct ieee80211_rx_stats *stats)
  1008. {
  1009. network->qos_data.active = 0;
  1010. network->qos_data.supported = 0;
  1011. network->qos_data.param_count = 0;
  1012. network->qos_data.old_param_count = 0;
  1013. /* Pull out fixed field data */
  1014. memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
  1015. network->capability = le16_to_cpu(beacon->capability);
  1016. network->last_scanned = jiffies;
  1017. network->time_stamp[0] = le32_to_cpu(beacon->time_stamp[0]);
  1018. network->time_stamp[1] = le32_to_cpu(beacon->time_stamp[1]);
  1019. network->beacon_interval = le16_to_cpu(beacon->beacon_interval);
  1020. /* Where to pull this? beacon->listen_interval; */
  1021. network->listen_interval = 0x0A;
  1022. network->rates_len = network->rates_ex_len = 0;
  1023. network->last_associate = 0;
  1024. network->ssid_len = 0;
  1025. network->flags = 0;
  1026. network->atim_window = 0;
  1027. network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
  1028. 0x3 : 0x0;
  1029. if (stats->freq == IEEE80211_52GHZ_BAND) {
  1030. /* for A band (No DS info) */
  1031. network->channel = stats->received_channel;
  1032. } else
  1033. network->flags |= NETWORK_HAS_CCK;
  1034. network->wpa_ie_len = 0;
  1035. network->rsn_ie_len = 0;
  1036. if (ieee80211_parse_info_param
  1037. (beacon->info_element, stats->len - sizeof(*beacon), network))
  1038. return 1;
  1039. network->mode = 0;
  1040. if (stats->freq == IEEE80211_52GHZ_BAND)
  1041. network->mode = IEEE_A;
  1042. else {
  1043. if (network->flags & NETWORK_HAS_OFDM)
  1044. network->mode |= IEEE_G;
  1045. if (network->flags & NETWORK_HAS_CCK)
  1046. network->mode |= IEEE_B;
  1047. }
  1048. if (network->mode == 0) {
  1049. IEEE80211_DEBUG_SCAN("Filtered out '%s (" MAC_FMT ")' "
  1050. "network.\n",
  1051. escape_essid(network->ssid,
  1052. network->ssid_len),
  1053. MAC_ARG(network->bssid));
  1054. return 1;
  1055. }
  1056. if (ieee80211_is_empty_essid(network->ssid, network->ssid_len))
  1057. network->flags |= NETWORK_EMPTY_ESSID;
  1058. memcpy(&network->stats, stats, sizeof(network->stats));
  1059. return 0;
  1060. }
  1061. static inline int is_same_network(struct ieee80211_network *src,
  1062. struct ieee80211_network *dst)
  1063. {
  1064. /* A network is only a duplicate if the channel, BSSID, and ESSID
  1065. * all match. We treat all <hidden> with the same BSSID and channel
  1066. * as one network */
  1067. return ((src->ssid_len == dst->ssid_len) &&
  1068. (src->channel == dst->channel) &&
  1069. !memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
  1070. !memcmp(src->ssid, dst->ssid, src->ssid_len));
  1071. }
  1072. static inline void update_network(struct ieee80211_network *dst,
  1073. struct ieee80211_network *src)
  1074. {
  1075. int qos_active;
  1076. u8 old_param;
  1077. memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
  1078. dst->capability = src->capability;
  1079. memcpy(dst->rates, src->rates, src->rates_len);
  1080. dst->rates_len = src->rates_len;
  1081. memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len);
  1082. dst->rates_ex_len = src->rates_ex_len;
  1083. dst->mode = src->mode;
  1084. dst->flags = src->flags;
  1085. dst->time_stamp[0] = src->time_stamp[0];
  1086. dst->time_stamp[1] = src->time_stamp[1];
  1087. dst->beacon_interval = src->beacon_interval;
  1088. dst->listen_interval = src->listen_interval;
  1089. dst->atim_window = src->atim_window;
  1090. dst->erp_value = src->erp_value;
  1091. memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
  1092. dst->wpa_ie_len = src->wpa_ie_len;
  1093. memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len);
  1094. dst->rsn_ie_len = src->rsn_ie_len;
  1095. dst->last_scanned = jiffies;
  1096. qos_active = src->qos_data.active;
  1097. old_param = dst->qos_data.old_param_count;
  1098. if (dst->flags & NETWORK_HAS_QOS_MASK)
  1099. memcpy(&dst->qos_data, &src->qos_data,
  1100. sizeof(struct ieee80211_qos_data));
  1101. else {
  1102. dst->qos_data.supported = src->qos_data.supported;
  1103. dst->qos_data.param_count = src->qos_data.param_count;
  1104. }
  1105. if (dst->qos_data.supported == 1) {
  1106. if (dst->ssid_len)
  1107. IEEE80211_DEBUG_QOS
  1108. ("QoS the network %s is QoS supported\n",
  1109. dst->ssid);
  1110. else
  1111. IEEE80211_DEBUG_QOS
  1112. ("QoS the network is QoS supported\n");
  1113. }
  1114. dst->qos_data.active = qos_active;
  1115. dst->qos_data.old_param_count = old_param;
  1116. /* dst->last_associate is not overwritten */
  1117. }
  1118. static inline int is_beacon(int fc)
  1119. {
  1120. return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == IEEE80211_STYPE_BEACON);
  1121. }
  1122. static inline void ieee80211_process_probe_response(struct ieee80211_device
  1123. *ieee, struct
  1124. ieee80211_probe_response
  1125. *beacon, struct ieee80211_rx_stats
  1126. *stats)
  1127. {
  1128. struct net_device *dev = ieee->dev;
  1129. struct ieee80211_network network;
  1130. struct ieee80211_network *target;
  1131. struct ieee80211_network *oldest = NULL;
  1132. #ifdef CONFIG_IEEE80211_DEBUG
  1133. struct ieee80211_info_element *info_element = beacon->info_element;
  1134. #endif
  1135. unsigned long flags;
  1136. IEEE80211_DEBUG_SCAN("'%s' (" MAC_FMT
  1137. "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
  1138. escape_essid(info_element->data,
  1139. info_element->len),
  1140. MAC_ARG(beacon->header.addr3),
  1141. (beacon->capability & (1 << 0xf)) ? '1' : '0',
  1142. (beacon->capability & (1 << 0xe)) ? '1' : '0',
  1143. (beacon->capability & (1 << 0xd)) ? '1' : '0',
  1144. (beacon->capability & (1 << 0xc)) ? '1' : '0',
  1145. (beacon->capability & (1 << 0xb)) ? '1' : '0',
  1146. (beacon->capability & (1 << 0xa)) ? '1' : '0',
  1147. (beacon->capability & (1 << 0x9)) ? '1' : '0',
  1148. (beacon->capability & (1 << 0x8)) ? '1' : '0',
  1149. (beacon->capability & (1 << 0x7)) ? '1' : '0',
  1150. (beacon->capability & (1 << 0x6)) ? '1' : '0',
  1151. (beacon->capability & (1 << 0x5)) ? '1' : '0',
  1152. (beacon->capability & (1 << 0x4)) ? '1' : '0',
  1153. (beacon->capability & (1 << 0x3)) ? '1' : '0',
  1154. (beacon->capability & (1 << 0x2)) ? '1' : '0',
  1155. (beacon->capability & (1 << 0x1)) ? '1' : '0',
  1156. (beacon->capability & (1 << 0x0)) ? '1' : '0');
  1157. if (ieee80211_network_init(ieee, beacon, &network, stats)) {
  1158. IEEE80211_DEBUG_SCAN("Dropped '%s' (" MAC_FMT ") via %s.\n",
  1159. escape_essid(info_element->data,
  1160. info_element->len),
  1161. MAC_ARG(beacon->header.addr3),
  1162. is_beacon(le16_to_cpu
  1163. (beacon->header.
  1164. frame_ctl)) ?
  1165. "BEACON" : "PROBE RESPONSE");
  1166. return;
  1167. }
  1168. /* The network parsed correctly -- so now we scan our known networks
  1169. * to see if we can find it in our list.
  1170. *
  1171. * NOTE: This search is definitely not optimized. Once its doing
  1172. * the "right thing" we'll optimize it for efficiency if
  1173. * necessary */
  1174. /* Search for this entry in the list and update it if it is
  1175. * already there. */
  1176. spin_lock_irqsave(&ieee->lock, flags);
  1177. list_for_each_entry(target, &ieee->network_list, list) {
  1178. if (is_same_network(target, &network))
  1179. break;
  1180. if ((oldest == NULL) ||
  1181. (target->last_scanned < oldest->last_scanned))
  1182. oldest = target;
  1183. }
  1184. /* If we didn't find a match, then get a new network slot to initialize
  1185. * with this beacon's information */
  1186. if (&target->list == &ieee->network_list) {
  1187. if (list_empty(&ieee->network_free_list)) {
  1188. /* If there are no more slots, expire the oldest */
  1189. list_del(&oldest->list);
  1190. target = oldest;
  1191. IEEE80211_DEBUG_SCAN("Expired '%s' (" MAC_FMT ") from "
  1192. "network list.\n",
  1193. escape_essid(target->ssid,
  1194. target->ssid_len),
  1195. MAC_ARG(target->bssid));
  1196. } else {
  1197. /* Otherwise just pull from the free list */
  1198. target = list_entry(ieee->network_free_list.next,
  1199. struct ieee80211_network, list);
  1200. list_del(ieee->network_free_list.next);
  1201. }
  1202. #ifdef CONFIG_IEEE80211_DEBUG
  1203. IEEE80211_DEBUG_SCAN("Adding '%s' (" MAC_FMT ") via %s.\n",
  1204. escape_essid(network.ssid,
  1205. network.ssid_len),
  1206. MAC_ARG(network.bssid),
  1207. is_beacon(le16_to_cpu
  1208. (beacon->header.
  1209. frame_ctl)) ?
  1210. "BEACON" : "PROBE RESPONSE");
  1211. #endif
  1212. memcpy(target, &network, sizeof(*target));
  1213. list_add_tail(&target->list, &ieee->network_list);
  1214. } else {
  1215. IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
  1216. escape_essid(target->ssid,
  1217. target->ssid_len),
  1218. MAC_ARG(target->bssid),
  1219. is_beacon(le16_to_cpu
  1220. (beacon->header.
  1221. frame_ctl)) ?
  1222. "BEACON" : "PROBE RESPONSE");
  1223. update_network(target, &network);
  1224. }
  1225. spin_unlock_irqrestore(&ieee->lock, flags);
  1226. if (is_beacon(le16_to_cpu(beacon->header.frame_ctl))) {
  1227. if (ieee->handle_beacon != NULL)
  1228. ieee->handle_beacon(dev, beacon, &network);
  1229. } else {
  1230. if (ieee->handle_probe_response != NULL)
  1231. ieee->handle_probe_response(dev, beacon, &network);
  1232. }
  1233. }
  1234. void ieee80211_rx_mgt(struct ieee80211_device *ieee,
  1235. struct ieee80211_hdr_4addr *header,
  1236. struct ieee80211_rx_stats *stats)
  1237. {
  1238. switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
  1239. case IEEE80211_STYPE_ASSOC_RESP:
  1240. IEEE80211_DEBUG_MGMT("received ASSOCIATION RESPONSE (%d)\n",
  1241. WLAN_FC_GET_STYPE(le16_to_cpu
  1242. (header->frame_ctl)));
  1243. ieee80211_handle_assoc_resp(ieee,
  1244. (struct ieee80211_assoc_response *)
  1245. header, stats);
  1246. break;
  1247. case IEEE80211_STYPE_REASSOC_RESP:
  1248. IEEE80211_DEBUG_MGMT("received REASSOCIATION RESPONSE (%d)\n",
  1249. WLAN_FC_GET_STYPE(le16_to_cpu
  1250. (header->frame_ctl)));
  1251. break;
  1252. case IEEE80211_STYPE_PROBE_REQ:
  1253. IEEE80211_DEBUG_MGMT("recieved auth (%d)\n",
  1254. WLAN_FC_GET_STYPE(le16_to_cpu
  1255. (header->frame_ctl)));
  1256. if (ieee->handle_probe_request != NULL)
  1257. ieee->handle_probe_request(ieee->dev,
  1258. (struct
  1259. ieee80211_probe_request *)
  1260. header, stats);
  1261. break;
  1262. case IEEE80211_STYPE_PROBE_RESP:
  1263. IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
  1264. WLAN_FC_GET_STYPE(le16_to_cpu
  1265. (header->frame_ctl)));
  1266. IEEE80211_DEBUG_SCAN("Probe response\n");
  1267. ieee80211_process_probe_response(ieee,
  1268. (struct
  1269. ieee80211_probe_response *)
  1270. header, stats);
  1271. break;
  1272. case IEEE80211_STYPE_BEACON:
  1273. IEEE80211_DEBUG_MGMT("received BEACON (%d)\n",
  1274. WLAN_FC_GET_STYPE(le16_to_cpu
  1275. (header->frame_ctl)));
  1276. IEEE80211_DEBUG_SCAN("Beacon\n");
  1277. ieee80211_process_probe_response(ieee,
  1278. (struct
  1279. ieee80211_probe_response *)
  1280. header, stats);
  1281. break;
  1282. case IEEE80211_STYPE_AUTH:
  1283. IEEE80211_DEBUG_MGMT("recieved auth (%d)\n",
  1284. WLAN_FC_GET_STYPE(le16_to_cpu
  1285. (header->frame_ctl)));
  1286. if (ieee->handle_auth != NULL)
  1287. ieee->handle_auth(ieee->dev,
  1288. (struct ieee80211_auth *)header);
  1289. break;
  1290. case IEEE80211_STYPE_DISASSOC:
  1291. if (ieee->handle_disassoc != NULL)
  1292. ieee->handle_disassoc(ieee->dev,
  1293. (struct ieee80211_disassoc *)
  1294. header);
  1295. break;
  1296. case IEEE80211_STYPE_DEAUTH:
  1297. printk("DEAUTH from AP\n");
  1298. if (ieee->handle_deauth != NULL)
  1299. ieee->handle_deauth(ieee->dev, (struct ieee80211_auth *)
  1300. header);
  1301. break;
  1302. default:
  1303. IEEE80211_DEBUG_MGMT("received UNKNOWN (%d)\n",
  1304. WLAN_FC_GET_STYPE(le16_to_cpu
  1305. (header->frame_ctl)));
  1306. IEEE80211_WARNING("%s: Unknown management packet: %d\n",
  1307. ieee->dev->name,
  1308. WLAN_FC_GET_STYPE(le16_to_cpu
  1309. (header->frame_ctl)));
  1310. break;
  1311. }
  1312. }
  1313. EXPORT_SYMBOL(ieee80211_rx_mgt);
  1314. EXPORT_SYMBOL(ieee80211_rx);