hostap_80211_rx.c 33 KB

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