hostap_80211_rx.c 32 KB

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