libipw_rx.c 50 KB

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