hostap_80211_rx.c 32 KB

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