hostap_80211_rx.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. #include <linux/etherdevice.h>
  2. #include <net/ieee80211_crypt.h>
  3. #include "hostap_80211.h"
  4. #include "hostap.h"
  5. #include "hostap_ap.h"
  6. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  7. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  8. static unsigned char rfc1042_header[] =
  9. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  10. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  11. static unsigned char bridge_tunnel_header[] =
  12. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  13. /* No encapsulation header if EtherType < 0x600 (=length) */
  14. void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
  15. struct hostap_80211_rx_status *rx_stats)
  16. {
  17. struct ieee80211_hdr_4addr *hdr;
  18. u16 fc;
  19. DECLARE_MAC_BUF(mac);
  20. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  21. printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
  22. "jiffies=%ld\n",
  23. name, rx_stats->signal, rx_stats->noise, rx_stats->rate,
  24. skb->len, jiffies);
  25. if (skb->len < 2)
  26. return;
  27. fc = le16_to_cpu(hdr->frame_ctl);
  28. printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s",
  29. fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
  30. fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
  31. fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
  32. if (skb->len < IEEE80211_DATA_HDR3_LEN) {
  33. printk("\n");
  34. return;
  35. }
  36. printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
  37. le16_to_cpu(hdr->seq_ctl));
  38. printk(KERN_DEBUG " A1=%s", print_mac(mac, hdr->addr1));
  39. printk(" A2=%s", print_mac(mac, hdr->addr2));
  40. printk(" A3=%s", print_mac(mac, hdr->addr3));
  41. if (skb->len >= 30)
  42. printk(" A4=%s", print_mac(mac, hdr->addr4));
  43. printk("\n");
  44. }
  45. /* Send RX frame to netif with 802.11 (and possible prism) header.
  46. * Called from hardware or software IRQ context. */
  47. int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
  48. struct hostap_80211_rx_status *rx_stats, int type)
  49. {
  50. struct hostap_interface *iface;
  51. local_info_t *local;
  52. int hdrlen, phdrlen, head_need, tail_need;
  53. u16 fc;
  54. int prism_header, ret;
  55. struct ieee80211_hdr_4addr *hdr;
  56. iface = netdev_priv(dev);
  57. local = iface->local;
  58. dev->last_rx = jiffies;
  59. if (dev->type == ARPHRD_IEEE80211_PRISM) {
  60. if (local->monitor_type == PRISM2_MONITOR_PRISM) {
  61. prism_header = 1;
  62. phdrlen = sizeof(struct linux_wlan_ng_prism_hdr);
  63. } else { /* local->monitor_type == PRISM2_MONITOR_CAPHDR */
  64. prism_header = 2;
  65. phdrlen = sizeof(struct linux_wlan_ng_cap_hdr);
  66. }
  67. } else {
  68. prism_header = 0;
  69. phdrlen = 0;
  70. }
  71. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  72. fc = le16_to_cpu(hdr->frame_ctl);
  73. if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
  74. printk(KERN_DEBUG "%s: dropped management frame with header "
  75. "version %d\n", dev->name, fc & IEEE80211_FCTL_VERS);
  76. dev_kfree_skb_any(skb);
  77. return 0;
  78. }
  79. hdrlen = hostap_80211_get_hdrlen(fc);
  80. /* check if there is enough room for extra data; if not, expand skb
  81. * buffer to be large enough for the changes */
  82. head_need = phdrlen;
  83. tail_need = 0;
  84. #ifdef PRISM2_ADD_BOGUS_CRC
  85. tail_need += 4;
  86. #endif /* PRISM2_ADD_BOGUS_CRC */
  87. head_need -= skb_headroom(skb);
  88. tail_need -= skb_tailroom(skb);
  89. if (head_need > 0 || tail_need > 0) {
  90. if (pskb_expand_head(skb, head_need > 0 ? head_need : 0,
  91. tail_need > 0 ? tail_need : 0,
  92. GFP_ATOMIC)) {
  93. printk(KERN_DEBUG "%s: prism2_rx_80211 failed to "
  94. "reallocate skb buffer\n", dev->name);
  95. dev_kfree_skb_any(skb);
  96. return 0;
  97. }
  98. }
  99. /* We now have an skb with enough head and tail room, so just insert
  100. * the extra data */
  101. #ifdef PRISM2_ADD_BOGUS_CRC
  102. memset(skb_put(skb, 4), 0xff, 4); /* Prism2 strips CRC */
  103. #endif /* PRISM2_ADD_BOGUS_CRC */
  104. if (prism_header == 1) {
  105. struct linux_wlan_ng_prism_hdr *hdr;
  106. hdr = (struct linux_wlan_ng_prism_hdr *)
  107. skb_push(skb, phdrlen);
  108. memset(hdr, 0, phdrlen);
  109. hdr->msgcode = LWNG_CAP_DID_BASE;
  110. hdr->msglen = sizeof(*hdr);
  111. memcpy(hdr->devname, dev->name, sizeof(hdr->devname));
  112. #define LWNG_SETVAL(f,i,s,l,d) \
  113. hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \
  114. hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
  115. LWNG_SETVAL(hosttime, 1, 0, 4, jiffies);
  116. LWNG_SETVAL(mactime, 2, 0, 4, rx_stats->mac_time);
  117. LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0);
  118. LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0);
  119. LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0);
  120. LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal);
  121. LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise);
  122. LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5);
  123. LWNG_SETVAL(istx, 9, 0, 4, 0);
  124. LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen);
  125. #undef LWNG_SETVAL
  126. } else if (prism_header == 2) {
  127. struct linux_wlan_ng_cap_hdr *hdr;
  128. hdr = (struct linux_wlan_ng_cap_hdr *)
  129. skb_push(skb, phdrlen);
  130. memset(hdr, 0, phdrlen);
  131. hdr->version = htonl(LWNG_CAPHDR_VERSION);
  132. hdr->length = htonl(phdrlen);
  133. hdr->mactime = __cpu_to_be64(rx_stats->mac_time);
  134. hdr->hosttime = __cpu_to_be64(jiffies);
  135. hdr->phytype = htonl(4); /* dss_dot11_b */
  136. hdr->channel = htonl(local->channel);
  137. hdr->datarate = htonl(rx_stats->rate);
  138. hdr->antenna = htonl(0); /* unknown */
  139. hdr->priority = htonl(0); /* unknown */
  140. hdr->ssi_type = htonl(3); /* raw */
  141. hdr->ssi_signal = htonl(rx_stats->signal);
  142. hdr->ssi_noise = htonl(rx_stats->noise);
  143. hdr->preamble = htonl(0); /* unknown */
  144. hdr->encoding = htonl(1); /* cck */
  145. }
  146. ret = skb->len - phdrlen;
  147. skb->dev = dev;
  148. skb_reset_mac_header(skb);
  149. skb_pull(skb, hdrlen);
  150. if (prism_header)
  151. skb_pull(skb, phdrlen);
  152. skb->pkt_type = PACKET_OTHERHOST;
  153. skb->protocol = __constant_htons(ETH_P_802_2);
  154. memset(skb->cb, 0, sizeof(skb->cb));
  155. netif_rx(skb);
  156. return ret;
  157. }
  158. /* Called only as a tasklet (software IRQ) */
  159. static void monitor_rx(struct net_device *dev, struct sk_buff *skb,
  160. struct hostap_80211_rx_status *rx_stats)
  161. {
  162. struct net_device_stats *stats;
  163. int len;
  164. len = prism2_rx_80211(dev, skb, rx_stats, PRISM2_RX_MONITOR);
  165. stats = hostap_get_stats(dev);
  166. stats->rx_packets++;
  167. stats->rx_bytes += len;
  168. }
  169. /* Called only as a tasklet (software IRQ) */
  170. static struct prism2_frag_entry *
  171. prism2_frag_cache_find(local_info_t *local, unsigned int seq,
  172. unsigned int frag, u8 *src, u8 *dst)
  173. {
  174. struct prism2_frag_entry *entry;
  175. int i;
  176. for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
  177. entry = &local->frag_cache[i];
  178. if (entry->skb != NULL &&
  179. time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  180. printk(KERN_DEBUG "%s: expiring fragment cache entry "
  181. "seq=%u last_frag=%u\n",
  182. local->dev->name, entry->seq, entry->last_frag);
  183. dev_kfree_skb(entry->skb);
  184. entry->skb = NULL;
  185. }
  186. if (entry->skb != NULL && entry->seq == seq &&
  187. (entry->last_frag + 1 == frag || frag == -1) &&
  188. memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
  189. memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
  190. return entry;
  191. }
  192. return NULL;
  193. }
  194. /* Called only as a tasklet (software IRQ) */
  195. static struct sk_buff *
  196. prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
  197. {
  198. struct sk_buff *skb = NULL;
  199. u16 sc;
  200. unsigned int frag, seq;
  201. struct prism2_frag_entry *entry;
  202. sc = le16_to_cpu(hdr->seq_ctl);
  203. frag = WLAN_GET_SEQ_FRAG(sc);
  204. seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
  205. if (frag == 0) {
  206. /* Reserve enough space to fit maximum frame length */
  207. skb = dev_alloc_skb(local->dev->mtu +
  208. sizeof(struct ieee80211_hdr_4addr) +
  209. 8 /* LLC */ +
  210. 2 /* alignment */ +
  211. 8 /* WEP */ + ETH_ALEN /* WDS */);
  212. if (skb == NULL)
  213. return NULL;
  214. entry = &local->frag_cache[local->frag_next_idx];
  215. local->frag_next_idx++;
  216. if (local->frag_next_idx >= PRISM2_FRAG_CACHE_LEN)
  217. local->frag_next_idx = 0;
  218. if (entry->skb != NULL)
  219. dev_kfree_skb(entry->skb);
  220. entry->first_frag_time = jiffies;
  221. entry->seq = seq;
  222. entry->last_frag = frag;
  223. entry->skb = skb;
  224. memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
  225. memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
  226. } else {
  227. /* received a fragment of a frame for which the head fragment
  228. * should have already been received */
  229. entry = prism2_frag_cache_find(local, seq, frag, hdr->addr2,
  230. hdr->addr1);
  231. if (entry != NULL) {
  232. entry->last_frag = frag;
  233. skb = entry->skb;
  234. }
  235. }
  236. return skb;
  237. }
  238. /* Called only as a tasklet (software IRQ) */
  239. static int prism2_frag_cache_invalidate(local_info_t *local,
  240. struct ieee80211_hdr_4addr *hdr)
  241. {
  242. u16 sc;
  243. unsigned int seq;
  244. struct prism2_frag_entry *entry;
  245. sc = le16_to_cpu(hdr->seq_ctl);
  246. seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
  247. entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1);
  248. if (entry == NULL) {
  249. printk(KERN_DEBUG "%s: could not invalidate fragment cache "
  250. "entry (seq=%u)\n",
  251. local->dev->name, seq);
  252. return -1;
  253. }
  254. entry->skb = NULL;
  255. return 0;
  256. }
  257. static struct hostap_bss_info *__hostap_get_bss(local_info_t *local, u8 *bssid,
  258. u8 *ssid, size_t ssid_len)
  259. {
  260. struct list_head *ptr;
  261. struct hostap_bss_info *bss;
  262. list_for_each(ptr, &local->bss_list) {
  263. bss = list_entry(ptr, struct hostap_bss_info, list);
  264. if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
  265. (ssid == NULL ||
  266. (ssid_len == bss->ssid_len &&
  267. memcmp(ssid, bss->ssid, ssid_len) == 0))) {
  268. list_move(&bss->list, &local->bss_list);
  269. return bss;
  270. }
  271. }
  272. return NULL;
  273. }
  274. static struct hostap_bss_info *__hostap_add_bss(local_info_t *local, u8 *bssid,
  275. u8 *ssid, size_t ssid_len)
  276. {
  277. struct hostap_bss_info *bss;
  278. if (local->num_bss_info >= HOSTAP_MAX_BSS_COUNT) {
  279. bss = list_entry(local->bss_list.prev,
  280. struct hostap_bss_info, list);
  281. list_del(&bss->list);
  282. local->num_bss_info--;
  283. } else {
  284. bss = (struct hostap_bss_info *)
  285. kmalloc(sizeof(*bss), GFP_ATOMIC);
  286. if (bss == NULL)
  287. return NULL;
  288. }
  289. memset(bss, 0, sizeof(*bss));
  290. memcpy(bss->bssid, bssid, ETH_ALEN);
  291. memcpy(bss->ssid, ssid, ssid_len);
  292. bss->ssid_len = ssid_len;
  293. local->num_bss_info++;
  294. list_add(&bss->list, &local->bss_list);
  295. return bss;
  296. }
  297. static void __hostap_expire_bss(local_info_t *local)
  298. {
  299. struct hostap_bss_info *bss;
  300. while (local->num_bss_info > 0) {
  301. bss = list_entry(local->bss_list.prev,
  302. struct hostap_bss_info, list);
  303. if (!time_after(jiffies, bss->last_update + 60 * HZ))
  304. break;
  305. list_del(&bss->list);
  306. local->num_bss_info--;
  307. kfree(bss);
  308. }
  309. }
  310. /* Both IEEE 802.11 Beacon and Probe Response frames have similar structure, so
  311. * the same routine can be used to parse both of them. */
  312. static void hostap_rx_sta_beacon(local_info_t *local, struct sk_buff *skb,
  313. int stype)
  314. {
  315. struct hostap_ieee80211_mgmt *mgmt;
  316. int left, chan = 0;
  317. u8 *pos;
  318. u8 *ssid = NULL, *wpa = NULL, *rsn = NULL;
  319. size_t ssid_len = 0, wpa_len = 0, rsn_len = 0;
  320. struct hostap_bss_info *bss;
  321. if (skb->len < IEEE80211_MGMT_HDR_LEN + sizeof(mgmt->u.beacon))
  322. return;
  323. mgmt = (struct hostap_ieee80211_mgmt *) skb->data;
  324. pos = mgmt->u.beacon.variable;
  325. left = skb->len - (pos - skb->data);
  326. while (left >= 2) {
  327. if (2 + pos[1] > left)
  328. return; /* parse failed */
  329. switch (*pos) {
  330. case WLAN_EID_SSID:
  331. ssid = pos + 2;
  332. ssid_len = pos[1];
  333. break;
  334. case WLAN_EID_GENERIC:
  335. if (pos[1] >= 4 &&
  336. pos[2] == 0x00 && pos[3] == 0x50 &&
  337. pos[4] == 0xf2 && pos[5] == 1) {
  338. wpa = pos;
  339. wpa_len = pos[1] + 2;
  340. }
  341. break;
  342. case WLAN_EID_RSN:
  343. rsn = pos;
  344. rsn_len = pos[1] + 2;
  345. break;
  346. case WLAN_EID_DS_PARAMS:
  347. if (pos[1] >= 1)
  348. chan = pos[2];
  349. break;
  350. }
  351. left -= 2 + pos[1];
  352. pos += 2 + pos[1];
  353. }
  354. if (wpa_len > MAX_WPA_IE_LEN)
  355. wpa_len = MAX_WPA_IE_LEN;
  356. if (rsn_len > MAX_WPA_IE_LEN)
  357. rsn_len = MAX_WPA_IE_LEN;
  358. if (ssid_len > sizeof(bss->ssid))
  359. ssid_len = sizeof(bss->ssid);
  360. spin_lock(&local->lock);
  361. bss = __hostap_get_bss(local, mgmt->bssid, ssid, ssid_len);
  362. if (bss == NULL)
  363. bss = __hostap_add_bss(local, mgmt->bssid, ssid, ssid_len);
  364. if (bss) {
  365. bss->last_update = jiffies;
  366. bss->count++;
  367. bss->capab_info = le16_to_cpu(mgmt->u.beacon.capab_info);
  368. if (wpa) {
  369. memcpy(bss->wpa_ie, wpa, wpa_len);
  370. bss->wpa_ie_len = wpa_len;
  371. } else
  372. bss->wpa_ie_len = 0;
  373. if (rsn) {
  374. memcpy(bss->rsn_ie, rsn, rsn_len);
  375. bss->rsn_ie_len = rsn_len;
  376. } else
  377. bss->rsn_ie_len = 0;
  378. bss->chan = chan;
  379. }
  380. __hostap_expire_bss(local);
  381. spin_unlock(&local->lock);
  382. }
  383. static int
  384. hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
  385. struct hostap_80211_rx_status *rx_stats, u16 type,
  386. u16 stype)
  387. {
  388. if (local->iw_mode == IW_MODE_MASTER) {
  389. hostap_update_sta_ps(local, (struct ieee80211_hdr_4addr *)
  390. skb->data);
  391. }
  392. if (local->hostapd && type == IEEE80211_FTYPE_MGMT) {
  393. if (stype == IEEE80211_STYPE_BEACON &&
  394. local->iw_mode == IW_MODE_MASTER) {
  395. struct sk_buff *skb2;
  396. /* Process beacon frames also in kernel driver to
  397. * update STA(AP) table statistics */
  398. skb2 = skb_clone(skb, GFP_ATOMIC);
  399. if (skb2)
  400. hostap_rx(skb2->dev, skb2, rx_stats);
  401. }
  402. /* send management frames to the user space daemon for
  403. * processing */
  404. local->apdevstats.rx_packets++;
  405. local->apdevstats.rx_bytes += skb->len;
  406. if (local->apdev == NULL)
  407. return -1;
  408. prism2_rx_80211(local->apdev, skb, rx_stats, PRISM2_RX_MGMT);
  409. return 0;
  410. }
  411. if (local->iw_mode == IW_MODE_MASTER) {
  412. if (type != IEEE80211_FTYPE_MGMT &&
  413. type != IEEE80211_FTYPE_CTL) {
  414. printk(KERN_DEBUG "%s: unknown management frame "
  415. "(type=0x%02x, stype=0x%02x) dropped\n",
  416. skb->dev->name, type >> 2, stype >> 4);
  417. return -1;
  418. }
  419. hostap_rx(skb->dev, skb, rx_stats);
  420. return 0;
  421. } else if (type == IEEE80211_FTYPE_MGMT &&
  422. (stype == IEEE80211_STYPE_BEACON ||
  423. stype == IEEE80211_STYPE_PROBE_RESP)) {
  424. hostap_rx_sta_beacon(local, skb, stype);
  425. return -1;
  426. } else if (type == IEEE80211_FTYPE_MGMT &&
  427. (stype == IEEE80211_STYPE_ASSOC_RESP ||
  428. stype == IEEE80211_STYPE_REASSOC_RESP)) {
  429. /* Ignore (Re)AssocResp silently since these are not currently
  430. * needed but are still received when WPA/RSN mode is enabled.
  431. */
  432. return -1;
  433. } else {
  434. printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: dropped unhandled"
  435. " management frame in non-Host AP mode (type=%d:%d)\n",
  436. skb->dev->name, type >> 2, stype >> 4);
  437. return -1;
  438. }
  439. }
  440. /* Called only as a tasklet (software IRQ) */
  441. static struct net_device *prism2_rx_get_wds(local_info_t *local,
  442. u8 *addr)
  443. {
  444. struct hostap_interface *iface = NULL;
  445. struct list_head *ptr;
  446. read_lock_bh(&local->iface_lock);
  447. list_for_each(ptr, &local->hostap_interfaces) {
  448. iface = list_entry(ptr, struct hostap_interface, list);
  449. if (iface->type == HOSTAP_INTERFACE_WDS &&
  450. memcmp(iface->u.wds.remote_addr, addr, ETH_ALEN) == 0)
  451. break;
  452. iface = NULL;
  453. }
  454. read_unlock_bh(&local->iface_lock);
  455. return iface ? iface->dev : NULL;
  456. }
  457. static int
  458. hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
  459. u16 fc, struct net_device **wds)
  460. {
  461. DECLARE_MAC_BUF(mac);
  462. /* FIX: is this really supposed to accept WDS frames only in Master
  463. * mode? What about Repeater or Managed with WDS frames? */
  464. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) !=
  465. (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS) &&
  466. (local->iw_mode != IW_MODE_MASTER || !(fc & IEEE80211_FCTL_TODS)))
  467. return 0; /* not a WDS frame */
  468. /* Possible WDS frame: either IEEE 802.11 compliant (if FromDS)
  469. * or own non-standard frame with 4th address after payload */
  470. if (memcmp(hdr->addr1, local->dev->dev_addr, ETH_ALEN) != 0 &&
  471. (hdr->addr1[0] != 0xff || hdr->addr1[1] != 0xff ||
  472. hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff ||
  473. hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
  474. /* RA (or BSSID) is not ours - drop */
  475. PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with "
  476. "not own or broadcast %s=%s\n",
  477. local->dev->name,
  478. fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID",
  479. print_mac(mac, hdr->addr1));
  480. return -1;
  481. }
  482. /* check if the frame came from a registered WDS connection */
  483. *wds = prism2_rx_get_wds(local, hdr->addr2);
  484. if (*wds == NULL && fc & IEEE80211_FCTL_FROMDS &&
  485. (local->iw_mode != IW_MODE_INFRA ||
  486. !(local->wds_type & HOSTAP_WDS_AP_CLIENT) ||
  487. memcmp(hdr->addr2, local->bssid, ETH_ALEN) != 0)) {
  488. /* require that WDS link has been registered with TA or the
  489. * frame is from current AP when using 'AP client mode' */
  490. PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame "
  491. "from unknown TA=%s\n",
  492. local->dev->name, print_mac(mac, hdr->addr2));
  493. if (local->ap && local->ap->autom_ap_wds)
  494. hostap_wds_link_oper(local, hdr->addr2, WDS_ADD);
  495. return -1;
  496. }
  497. if (*wds && !(fc & IEEE80211_FCTL_FROMDS) && local->ap &&
  498. hostap_is_sta_assoc(local->ap, hdr->addr2)) {
  499. /* STA is actually associated with us even though it has a
  500. * registered WDS link. Assume it is in 'AP client' mode.
  501. * Since this is a 3-addr frame, assume it is not (bogus) WDS
  502. * frame and process it like any normal ToDS frame from
  503. * associated STA. */
  504. *wds = NULL;
  505. }
  506. return 0;
  507. }
  508. static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
  509. {
  510. struct net_device *dev = local->dev;
  511. u16 fc, ethertype;
  512. struct ieee80211_hdr_4addr *hdr;
  513. u8 *pos;
  514. if (skb->len < 24)
  515. return 0;
  516. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  517. fc = le16_to_cpu(hdr->frame_ctl);
  518. /* check that the frame is unicast frame to us */
  519. if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  520. IEEE80211_FCTL_TODS &&
  521. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
  522. memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
  523. /* ToDS frame with own addr BSSID and DA */
  524. } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  525. IEEE80211_FCTL_FROMDS &&
  526. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  527. /* FromDS frame with own addr as DA */
  528. } else
  529. return 0;
  530. if (skb->len < 24 + 8)
  531. return 0;
  532. /* check for port access entity Ethernet type */
  533. pos = skb->data + 24;
  534. ethertype = (pos[6] << 8) | pos[7];
  535. if (ethertype == ETH_P_PAE)
  536. return 1;
  537. return 0;
  538. }
  539. /* Called only as a tasklet (software IRQ) */
  540. static int
  541. hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
  542. struct ieee80211_crypt_data *crypt)
  543. {
  544. struct ieee80211_hdr_4addr *hdr;
  545. int res, hdrlen;
  546. DECLARE_MAC_BUF(mac);
  547. if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
  548. return 0;
  549. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  550. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  551. if (local->tkip_countermeasures &&
  552. strcmp(crypt->ops->name, "TKIP") == 0) {
  553. if (net_ratelimit()) {
  554. printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
  555. "received packet from %s\n",
  556. local->dev->name, print_mac(mac, hdr->addr2));
  557. }
  558. return -1;
  559. }
  560. atomic_inc(&crypt->refcnt);
  561. res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
  562. atomic_dec(&crypt->refcnt);
  563. if (res < 0) {
  564. printk(KERN_DEBUG "%s: decryption failed (SA=%s"
  565. ") res=%d\n",
  566. local->dev->name, print_mac(mac, hdr->addr2), res);
  567. local->comm_tallies.rx_discards_wep_undecryptable++;
  568. return -1;
  569. }
  570. return res;
  571. }
  572. /* Called only as a tasklet (software IRQ) */
  573. static int
  574. hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
  575. int keyidx, struct ieee80211_crypt_data *crypt)
  576. {
  577. struct ieee80211_hdr_4addr *hdr;
  578. int res, hdrlen;
  579. DECLARE_MAC_BUF(mac);
  580. if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
  581. return 0;
  582. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  583. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
  584. atomic_inc(&crypt->refcnt);
  585. res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
  586. atomic_dec(&crypt->refcnt);
  587. if (res < 0) {
  588. printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
  589. " (SA=%s keyidx=%d)\n",
  590. local->dev->name, print_mac(mac, hdr->addr2), keyidx);
  591. return -1;
  592. }
  593. return 0;
  594. }
  595. /* All received frames are sent to this function. @skb contains the frame in
  596. * IEEE 802.11 format, i.e., in the format it was sent over air.
  597. * This function is called only as a tasklet (software IRQ). */
  598. void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
  599. struct hostap_80211_rx_status *rx_stats)
  600. {
  601. struct hostap_interface *iface;
  602. local_info_t *local;
  603. struct ieee80211_hdr_4addr *hdr;
  604. size_t hdrlen;
  605. u16 fc, type, stype, sc;
  606. struct net_device *wds = NULL;
  607. struct net_device_stats *stats;
  608. unsigned int frag;
  609. u8 *payload;
  610. struct sk_buff *skb2 = NULL;
  611. u16 ethertype;
  612. int frame_authorized = 0;
  613. int from_assoc_ap = 0;
  614. u8 dst[ETH_ALEN];
  615. u8 src[ETH_ALEN];
  616. struct ieee80211_crypt_data *crypt = NULL;
  617. void *sta = NULL;
  618. int keyidx = 0;
  619. DECLARE_MAC_BUF(mac);
  620. iface = netdev_priv(dev);
  621. local = iface->local;
  622. iface->stats.rx_packets++;
  623. iface->stats.rx_bytes += skb->len;
  624. /* dev is the master radio device; change this to be the default
  625. * virtual interface (this may be changed to WDS device below) */
  626. dev = local->ddev;
  627. iface = netdev_priv(dev);
  628. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  629. stats = hostap_get_stats(dev);
  630. if (skb->len < 10)
  631. goto rx_dropped;
  632. fc = le16_to_cpu(hdr->frame_ctl);
  633. type = WLAN_FC_GET_TYPE(fc);
  634. stype = WLAN_FC_GET_STYPE(fc);
  635. sc = le16_to_cpu(hdr->seq_ctl);
  636. frag = WLAN_GET_SEQ_FRAG(sc);
  637. hdrlen = hostap_80211_get_hdrlen(fc);
  638. /* Put this code here so that we avoid duplicating it in all
  639. * Rx paths. - Jean II */
  640. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  641. /* If spy monitoring on */
  642. if (iface->spy_data.spy_number > 0) {
  643. struct iw_quality wstats;
  644. wstats.level = rx_stats->signal;
  645. wstats.noise = rx_stats->noise;
  646. wstats.updated = IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED
  647. | IW_QUAL_QUAL_INVALID | IW_QUAL_DBM;
  648. /* Update spy records */
  649. wireless_spy_update(dev, hdr->addr2, &wstats);
  650. }
  651. #endif /* IW_WIRELESS_SPY */
  652. hostap_update_rx_stats(local->ap, hdr, rx_stats);
  653. if (local->iw_mode == IW_MODE_MONITOR) {
  654. monitor_rx(dev, skb, rx_stats);
  655. return;
  656. }
  657. if (local->host_decrypt) {
  658. int idx = 0;
  659. if (skb->len >= hdrlen + 3)
  660. idx = skb->data[hdrlen + 3] >> 6;
  661. crypt = local->crypt[idx];
  662. sta = NULL;
  663. /* Use station specific key to override default keys if the
  664. * receiver address is a unicast address ("individual RA"). If
  665. * bcrx_sta_key parameter is set, station specific key is used
  666. * even with broad/multicast targets (this is against IEEE
  667. * 802.11, but makes it easier to use different keys with
  668. * stations that do not support WEP key mapping). */
  669. if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
  670. (void) hostap_handle_sta_crypto(local, hdr, &crypt,
  671. &sta);
  672. /* allow NULL decrypt to indicate an station specific override
  673. * for default encryption */
  674. if (crypt && (crypt->ops == NULL ||
  675. crypt->ops->decrypt_mpdu == NULL))
  676. crypt = NULL;
  677. if (!crypt && (fc & IEEE80211_FCTL_PROTECTED)) {
  678. #if 0
  679. /* This seems to be triggered by some (multicast?)
  680. * frames from other than current BSS, so just drop the
  681. * frames silently instead of filling system log with
  682. * these reports. */
  683. printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
  684. " (SA=%s)\n",
  685. local->dev->name, print_mac(mac, hdr->addr2));
  686. #endif
  687. local->comm_tallies.rx_discards_wep_undecryptable++;
  688. goto rx_dropped;
  689. }
  690. }
  691. if (type != IEEE80211_FTYPE_DATA) {
  692. if (type == IEEE80211_FTYPE_MGMT &&
  693. stype == IEEE80211_STYPE_AUTH &&
  694. fc & IEEE80211_FCTL_PROTECTED && local->host_decrypt &&
  695. (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
  696. {
  697. printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
  698. "from %s\n", dev->name,
  699. print_mac(mac, hdr->addr2));
  700. /* TODO: could inform hostapd about this so that it
  701. * could send auth failure report */
  702. goto rx_dropped;
  703. }
  704. if (hostap_rx_frame_mgmt(local, skb, rx_stats, type, stype))
  705. goto rx_dropped;
  706. else
  707. goto rx_exit;
  708. }
  709. /* Data frame - extract src/dst addresses */
  710. if (skb->len < IEEE80211_DATA_HDR3_LEN)
  711. goto rx_dropped;
  712. switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  713. case IEEE80211_FCTL_FROMDS:
  714. memcpy(dst, hdr->addr1, ETH_ALEN);
  715. memcpy(src, hdr->addr3, ETH_ALEN);
  716. break;
  717. case IEEE80211_FCTL_TODS:
  718. memcpy(dst, hdr->addr3, ETH_ALEN);
  719. memcpy(src, hdr->addr2, ETH_ALEN);
  720. break;
  721. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  722. if (skb->len < IEEE80211_DATA_HDR4_LEN)
  723. goto rx_dropped;
  724. memcpy(dst, hdr->addr3, ETH_ALEN);
  725. memcpy(src, hdr->addr4, ETH_ALEN);
  726. break;
  727. case 0:
  728. memcpy(dst, hdr->addr1, ETH_ALEN);
  729. memcpy(src, hdr->addr2, ETH_ALEN);
  730. break;
  731. }
  732. if (hostap_rx_frame_wds(local, hdr, fc, &wds))
  733. goto rx_dropped;
  734. if (wds) {
  735. skb->dev = dev = wds;
  736. stats = hostap_get_stats(dev);
  737. }
  738. if (local->iw_mode == IW_MODE_MASTER && !wds &&
  739. (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  740. IEEE80211_FCTL_FROMDS &&
  741. local->stadev &&
  742. memcmp(hdr->addr2, local->assoc_ap_addr, ETH_ALEN) == 0) {
  743. /* Frame from BSSID of the AP for which we are a client */
  744. skb->dev = dev = local->stadev;
  745. stats = hostap_get_stats(dev);
  746. from_assoc_ap = 1;
  747. }
  748. dev->last_rx = jiffies;
  749. if ((local->iw_mode == IW_MODE_MASTER ||
  750. local->iw_mode == IW_MODE_REPEAT) &&
  751. !from_assoc_ap) {
  752. switch (hostap_handle_sta_rx(local, dev, skb, rx_stats,
  753. wds != NULL)) {
  754. case AP_RX_CONTINUE_NOT_AUTHORIZED:
  755. frame_authorized = 0;
  756. break;
  757. case AP_RX_CONTINUE:
  758. frame_authorized = 1;
  759. break;
  760. case AP_RX_DROP:
  761. goto rx_dropped;
  762. case AP_RX_EXIT:
  763. goto rx_exit;
  764. }
  765. }
  766. /* Nullfunc frames may have PS-bit set, so they must be passed to
  767. * hostap_handle_sta_rx() before being dropped here. */
  768. if (stype != IEEE80211_STYPE_DATA &&
  769. stype != IEEE80211_STYPE_DATA_CFACK &&
  770. stype != IEEE80211_STYPE_DATA_CFPOLL &&
  771. stype != IEEE80211_STYPE_DATA_CFACKPOLL) {
  772. if (stype != IEEE80211_STYPE_NULLFUNC)
  773. printk(KERN_DEBUG "%s: RX: dropped data frame "
  774. "with no data (type=0x%02x, subtype=0x%02x)\n",
  775. dev->name, type >> 2, stype >> 4);
  776. goto rx_dropped;
  777. }
  778. /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
  779. if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  780. (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
  781. goto rx_dropped;
  782. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  783. /* skb: hdr + (possibly fragmented) plaintext payload */
  784. if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  785. (frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
  786. int flen;
  787. struct sk_buff *frag_skb =
  788. prism2_frag_cache_get(local, hdr);
  789. if (!frag_skb) {
  790. printk(KERN_DEBUG "%s: Rx cannot get skb from "
  791. "fragment cache (morefrag=%d seq=%u frag=%u)\n",
  792. dev->name, (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
  793. WLAN_GET_SEQ_SEQ(sc) >> 4, frag);
  794. goto rx_dropped;
  795. }
  796. flen = skb->len;
  797. if (frag != 0)
  798. flen -= hdrlen;
  799. if (frag_skb->tail + flen > frag_skb->end) {
  800. printk(KERN_WARNING "%s: host decrypted and "
  801. "reassembled frame did not fit skb\n",
  802. dev->name);
  803. prism2_frag_cache_invalidate(local, hdr);
  804. goto rx_dropped;
  805. }
  806. if (frag == 0) {
  807. /* copy first fragment (including full headers) into
  808. * beginning of the fragment cache skb */
  809. skb_copy_from_linear_data(skb, skb_put(frag_skb, flen),
  810. flen);
  811. } else {
  812. /* append frame payload to the end of the fragment
  813. * cache skb */
  814. skb_copy_from_linear_data_offset(skb, hdrlen,
  815. skb_put(frag_skb,
  816. flen), flen);
  817. }
  818. dev_kfree_skb(skb);
  819. skb = NULL;
  820. if (fc & IEEE80211_FCTL_MOREFRAGS) {
  821. /* more fragments expected - leave the skb in fragment
  822. * cache for now; it will be delivered to upper layers
  823. * after all fragments have been received */
  824. goto rx_exit;
  825. }
  826. /* this was the last fragment and the frame will be
  827. * delivered, so remove skb from fragment cache */
  828. skb = frag_skb;
  829. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  830. prism2_frag_cache_invalidate(local, hdr);
  831. }
  832. /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
  833. * encrypted/authenticated */
  834. if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
  835. hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
  836. goto rx_dropped;
  837. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  838. if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) {
  839. if (local->ieee_802_1x &&
  840. hostap_is_eapol_frame(local, skb)) {
  841. /* pass unencrypted EAPOL frames even if encryption is
  842. * configured */
  843. PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X - passing "
  844. "unencrypted EAPOL frame\n", local->dev->name);
  845. } else {
  846. printk(KERN_DEBUG "%s: encryption configured, but RX "
  847. "frame not encrypted (SA=%s)\n",
  848. local->dev->name, print_mac(mac, hdr->addr2));
  849. goto rx_dropped;
  850. }
  851. }
  852. if (local->drop_unencrypted && !(fc & IEEE80211_FCTL_PROTECTED) &&
  853. !hostap_is_eapol_frame(local, skb)) {
  854. if (net_ratelimit()) {
  855. printk(KERN_DEBUG "%s: dropped unencrypted RX data "
  856. "frame from %s"
  857. " (drop_unencrypted=1)\n",
  858. dev->name, print_mac(mac, hdr->addr2));
  859. }
  860. goto rx_dropped;
  861. }
  862. /* skb: hdr + (possible reassembled) full plaintext payload */
  863. payload = skb->data + hdrlen;
  864. ethertype = (payload[6] << 8) | payload[7];
  865. /* If IEEE 802.1X is used, check whether the port is authorized to send
  866. * the received frame. */
  867. if (local->ieee_802_1x && local->iw_mode == IW_MODE_MASTER) {
  868. if (ethertype == ETH_P_PAE) {
  869. PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X frame\n",
  870. dev->name);
  871. if (local->hostapd && local->apdev) {
  872. /* Send IEEE 802.1X frames to the user
  873. * space daemon for processing */
  874. prism2_rx_80211(local->apdev, skb, rx_stats,
  875. PRISM2_RX_MGMT);
  876. local->apdevstats.rx_packets++;
  877. local->apdevstats.rx_bytes += skb->len;
  878. goto rx_exit;
  879. }
  880. } else if (!frame_authorized) {
  881. printk(KERN_DEBUG "%s: dropped frame from "
  882. "unauthorized port (IEEE 802.1X): "
  883. "ethertype=0x%04x\n",
  884. dev->name, ethertype);
  885. goto rx_dropped;
  886. }
  887. }
  888. /* convert hdr + possible LLC headers into Ethernet header */
  889. if (skb->len - hdrlen >= 8 &&
  890. ((memcmp(payload, rfc1042_header, 6) == 0 &&
  891. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  892. memcmp(payload, bridge_tunnel_header, 6) == 0)) {
  893. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  894. * replace EtherType */
  895. skb_pull(skb, hdrlen + 6);
  896. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  897. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  898. } else {
  899. u16 len;
  900. /* Leave Ethernet header part of hdr and full payload */
  901. skb_pull(skb, hdrlen);
  902. len = htons(skb->len);
  903. memcpy(skb_push(skb, 2), &len, 2);
  904. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  905. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  906. }
  907. if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
  908. IEEE80211_FCTL_TODS) &&
  909. skb->len >= ETH_HLEN + ETH_ALEN) {
  910. /* Non-standard frame: get addr4 from its bogus location after
  911. * the payload */
  912. skb_copy_from_linear_data_offset(skb, skb->len - ETH_ALEN,
  913. skb->data + ETH_ALEN,
  914. ETH_ALEN);
  915. skb_trim(skb, skb->len - ETH_ALEN);
  916. }
  917. stats->rx_packets++;
  918. stats->rx_bytes += skb->len;
  919. if (local->iw_mode == IW_MODE_MASTER && !wds &&
  920. local->ap->bridge_packets) {
  921. if (dst[0] & 0x01) {
  922. /* copy multicast frame both to the higher layers and
  923. * to the wireless media */
  924. local->ap->bridged_multicast++;
  925. skb2 = skb_clone(skb, GFP_ATOMIC);
  926. if (skb2 == NULL)
  927. printk(KERN_DEBUG "%s: skb_clone failed for "
  928. "multicast frame\n", dev->name);
  929. } else if (hostap_is_sta_authorized(local->ap, dst)) {
  930. /* send frame directly to the associated STA using
  931. * wireless media and not passing to higher layers */
  932. local->ap->bridged_unicast++;
  933. skb2 = skb;
  934. skb = NULL;
  935. }
  936. }
  937. if (skb2 != NULL) {
  938. /* send to wireless media */
  939. skb2->dev = dev;
  940. skb2->protocol = __constant_htons(ETH_P_802_3);
  941. skb_reset_mac_header(skb2);
  942. skb_reset_network_header(skb2);
  943. /* skb2->network_header += ETH_HLEN; */
  944. dev_queue_xmit(skb2);
  945. }
  946. if (skb) {
  947. skb->protocol = eth_type_trans(skb, dev);
  948. memset(skb->cb, 0, sizeof(skb->cb));
  949. netif_rx(skb);
  950. }
  951. rx_exit:
  952. if (sta)
  953. hostap_handle_sta_release(sta);
  954. return;
  955. rx_dropped:
  956. dev_kfree_skb(skb);
  957. stats->rx_dropped++;
  958. goto rx_exit;
  959. }
  960. EXPORT_SYMBOL(hostap_80211_rx);