hostap_80211_rx.c 32 KB

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