ieee80211_rx.c 51 KB

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