hostap_80211_rx.c 32 KB

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