ieee80211_rx.c 43 KB

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