16 #include <linux/compiler.h>
17 #include <linux/errno.h>
18 #include <linux/if_arp.h>
19 #include <linux/in6.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/netdevice.h>
28 #include <linux/tcp.h>
29 #include <linux/types.h>
30 #include <linux/wireless.h>
32 #include <asm/uaccess.h>
33 #include <linux/ctype.h>
47 skb_reset_mac_header(skb);
51 memset(skb->cb, 0,
sizeof(skb->cb));
72 "seq=%u last_frag=%u\n",
79 (entry->
last_frag + 1 == frag || frag == -1) &&
80 ether_addr_equal(entry->
src_addr, src) &&
81 ether_addr_equal(entry->
dst_addr, dst))
94 unsigned int frag, seq;
103 skb = dev_alloc_skb(ieee->
dev->mtu +
128 entry = libipw_frag_cache_find(ieee, seq, frag, hdr->
addr2,
140 static int libipw_frag_cache_invalidate(
struct libipw_device *ieee,
150 entry = libipw_frag_cache_find(ieee, seq, -1, hdr->
addr2,
155 "entry (seq=%u)\n", seq);
183 if (ieee->hostapd && type == WLAN_FC_TYPE_MGMT) {
184 if (stype == WLAN_FC_STYPE_BEACON &&
196 ieee->apdevstats.rx_packets++;
197 ieee->apdevstats.rx_bytes += skb->
len;
203 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
205 "(type=0x%02x, stype=0x%02x) dropped\n",
206 skb->
dev->name, type, stype);
215 "received in non-Host AP mode\n", skb->
dev->name);
222 static unsigned char libipw_rfc1042_header[] =
223 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
226 static unsigned char libipw_bridge_tunnel_header[] =
227 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
258 if (skb->
len < 24 + 8)
262 pos = skb->
data + 24;
263 ethertype = (pos[6] << 8) | pos[7];
278 if (crypt ==
NULL || crypt->
ops->decrypt_mpdu ==
NULL)
285 res = crypt->
ops->decrypt_mpdu(skb, hdrlen, crypt->
priv);
292 "mismatch (key %d)\n",
293 skb->
data[hdrlen + 3] >> 6);
304 struct sk_buff *skb,
int keyidx,
310 if (crypt ==
NULL || crypt->
ops->decrypt_msdu ==
NULL)
317 res = crypt->
ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->
priv);
321 " (SA=%pM keyidx=%d)\n", ieee->
dev->name, hdr->
addr2,
346 int frame_authorized = 0;
347 int from_assoc_ap = 0;
354 int can_be_decrypted = 0;
367 hdrlen = libipw_get_hdrlen(fc);
369 if (skb->
len < hdrlen) {
377 #ifdef CONFIG_WIRELESS_EXT
378 #ifdef IW_WIRELESS_SPY
380 if (ieee->
spy_data.spy_number > 0) {
413 dev->
stats.rx_packets++;
415 libipw_monitor_rx(ieee, skb, rx_stats);
419 can_be_decrypted = (is_multicast_ether_addr(hdr->
addr1) ||
420 is_broadcast_ether_addr(hdr->
addr2)) ?
423 if (can_be_decrypted) {
424 if (skb->
len >= hdrlen + 3) {
426 keyidx = skb->
data[hdrlen + 3] >> 6;
445 if (is_unicast_ether_addr(hdr->
addr1) || local->bcrx_sta_key)
452 if (crypt && (crypt->
ops ==
NULL ||
453 crypt->
ops->decrypt_mpdu ==
NULL))
462 " (SA=%pM)\n", hdr->
addr2);
468 if (type != WLAN_FC_TYPE_DATA) {
471 (keyidx = hostap_rx_frame_decrypt(ieee, skb, crypt)) < 0) {
479 if (libipw_rx_frame_mgmt(ieee, skb, rx_stats, type, stype))
517 if (hostap_rx_frame_wds(ieee, hdr, fc, &wds))
520 skb->
dev = dev = wds;
527 ether_addr_equal(hdr->
addr2, ieee->assoc_ap_addr)) {
529 skb->
dev = dev = ieee->stadev;
541 frame_authorized = 0;
544 frame_authorized = 1;
565 "with no data (type=0x%02x, "
566 "subtype=0x%02x, len=%d)\n",
567 type, stype, skb->
len);
574 (keyidx = libipw_rx_frame_decrypt(ieee, skb, crypt)) < 0)
584 struct sk_buff *frag_skb = libipw_frag_cache_get(ieee, hdr);
589 "Rx cannot get skb from fragment "
590 "cache (morefrag=%d seq=%u frag=%u)\n",
600 if (frag_skb->
tail + flen > frag_skb->
end) {
602 "reassembled frame did not fit skb\n",
604 libipw_frag_cache_invalidate(ieee, hdr);
611 skb_copy_from_linear_data(skb,
skb_put(frag_skb, flen), flen);
615 skb_copy_from_linear_data_offset(skb, hdrlen,
616 skb_put(frag_skb, flen), flen);
632 libipw_frag_cache_invalidate(ieee, hdr);
637 if ((fc & IEEE80211_FCTL_PROTECTED) && can_be_decrypted &&
638 libipw_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))
642 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->
open_wep) {
644 libipw_is_eapol_frame(ieee, skb)) {
649 "frame not encrypted (SA=%pM)\n",
655 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->
open_wep &&
656 !libipw_is_eapol_frame(ieee, skb)) {
658 "frame from %pM (drop_unencrypted=1)\n",
665 if (!can_be_decrypted && (fc & IEEE80211_FCTL_PROTECTED) &&
670 if (skb->
len >= hdrlen + 3)
671 keyidx = skb->
data[hdrlen + 3] >> 6;
678 switch (ieee->
sec.encode_alg[keyidx]) {
699 if (skb->
len < trimlen)
702 __skb_trim(skb, skb->
len - trimlen);
704 if (skb->
len < hdrlen)
711 ethertype = (payload[6] << 8) | payload[7];
720 if (ieee->hostapd && ieee->apdev) {
725 ieee->apdevstats.rx_packets++;
726 ieee->apdevstats.rx_bytes += skb->
len;
729 }
else if (!frame_authorized) {
731 "unauthorized port (IEEE 802.1X): "
732 "ethertype=0x%04x\n", dev->
name, ethertype);
739 if (skb->
len - hdrlen >= 8 &&
763 skb_copy_to_linear_data_offset(skb,
ETH_ALEN,
770 dev->
stats.rx_packets++;
775 if (is_multicast_ether_addr(dst)) {
778 ieee->ap->bridged_multicast++;
782 "multicast frame\n", dev->
name);
786 ieee->ap->bridged_unicast++;
796 skb_reset_mac_header(skb2);
797 skb_reset_network_header(skb2);
805 memset(skb->cb, 0,
sizeof(skb->cb));
812 (
"RX: netif_rx dropped the packet\n");
813 dev->
stats.rx_dropped++;
825 dev->
stats.rx_dropped++;
840 int is_packet_for_us;
873 is_packet_for_us = 0;
881 is_packet_for_us = 1;
884 is_packet_for_us = 1;
886 else if (is_multicast_ether_addr(hdr->
addr1))
887 is_packet_for_us = 1;
896 is_packet_for_us = 1;
899 is_packet_for_us = 1;
901 else if (is_multicast_ether_addr(hdr->
addr1)) {
904 is_packet_for_us = 1;
913 if (is_packet_for_us)
920 ieee->
dev->stats.rx_dropped++;
923 #define MGMT_FRAME_FIXED_PART_LENGTH 0x24
957 if ((info_element ==
NULL) || (element_param ==
NULL))
968 ret = libipw_verify_qos_info(&element_param->
info_element,
976 static int libipw_read_qos_info_element(
struct
984 if (element_info ==
NULL)
986 if (info_element ==
NULL)
993 element_info->
length = info_element->
len;
998 ret = libipw_verify_qos_info(element_info,
1006 static int libipw_qos_convert_ac_to_parameters(
struct
1023 qos_param->
aifs[
i] -= (qos_param->
aifs[
i] < 2) ? 0 : 2;
1031 qos_param->
flag[
i] =
1032 (ac_params->
aci_aifsn & 0x10) ? 0x01 : 0x00;
1053 rc = libipw_read_qos_info_element(&qos_info_element, info_element);
1056 network->
qos_data.param_count = qos_info_element.ac_info & 0x0F;
1061 rc = libipw_read_qos_param_element(¶m_element,
1064 qos_param = &(network->
qos_data.parameters);
1065 libipw_qos_convert_ac_to_parameters(¶m_element,
1069 param_element.info_element.ac_info & 0x0F;
1080 #ifdef CONFIG_LIBIPW_DEBUG
1081 #define MFIE_STRING(x) case WLAN_EID_ ##x: return #x
1083 static const char *get_info_element_string(
u16 id)
1125 #ifdef CONFIG_LIBIPW_DEBUG
1130 while (length >=
sizeof(*info_element)) {
1131 if (
sizeof(*info_element) + info_element->
len > length) {
1133 "info_element->len + 2 > left : "
1134 "info_element->len+2=%zd left=%d, id=%d.\n",
1136 sizeof(*info_element),
1137 length, info_element->
id);
1144 switch (info_element->
id) {
1161 #ifdef CONFIG_LIBIPW_DEBUG
1166 for (i = 0; i < network->
rates_len; i++) {
1168 #ifdef CONFIG_LIBIPW_DEBUG
1169 p +=
snprintf(p,
sizeof(rates_str) -
1170 (p - rates_str),
"%02X ",
1173 if (libipw_is_ofdm_rate
1174 (info_element->
data[i])) {
1176 if (info_element->
data[i] &
1188 #ifdef CONFIG_LIBIPW_DEBUG
1195 #ifdef CONFIG_LIBIPW_DEBUG
1196 p +=
snprintf(p,
sizeof(rates_str) -
1197 (p - rates_str),
"%02X ",
1200 if (libipw_is_ofdm_rate
1201 (info_element->
data[i])) {
1203 if (info_element->
data[i] &
1216 info_element->
data[0]);
1229 network->
tim.tim_count = info_element->
data[0];
1230 network->
tim.tim_period = info_element->
data[1];
1254 if (!libipw_parse_qos_info_param_IE(info_element,
1258 if (info_element->
len >= 4 &&
1259 info_element->
data[0] == 0x00 &&
1260 info_element->
data[1] == 0x50 &&
1261 info_element->
data[2] == 0xf2 &&
1262 info_element->
data[3] == 0x01) {
1281 "QoS Error need to parse QOS_PARAMETER IE\n");
1295 network->
quiet.count = info_element->
data[0];
1296 network->
quiet.period = info_element->
data[1];
1297 network->
quiet.duration = info_element->
data[2];
1298 network->
quiet.offset = info_element->
data[3];
1315 info_element->
data[0];
1322 (
"Unsupported info element: %s (%d)\n",
1323 get_info_element_string(info_element->
id),
1328 length -=
sizeof(*info_element) + info_element->
len;
1350 network->
qos_data.old_param_count = 0;
1373 if (libipw_parse_info_param
1407 network->
qos_data.old_param_count = 0;
1435 if (libipw_parse_info_param
1449 if (network->
mode == 0) {
1494 "off channel (%d vs. %d)\n", src->
bssid,
1521 old_param = dst->
qos_data.old_param_count;
1530 if (dst->
qos_data.supported == 1) {
1533 (
"QoS the network %s is QoS supported\n",
1537 (
"QoS the network is QoS supported\n");
1540 dst->
qos_data.old_param_count = old_param;
1545 static inline int is_beacon(
__le16 fc)
1550 static void libipw_process_probe_response(
struct libipw_device
1562 #ifdef CONFIG_LIBIPW_DEBUG
1565 unsigned long flags;
1569 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
1589 if (libipw_network_init(ieee, beacon, &network, stats)) {
1594 is_beacon(beacon->
header.frame_ctl) ?
1595 "BEACON" :
"PROBE RESPONSE");
1612 if (is_same_network(target, &network))
1615 if ((oldest ==
NULL) ||
1640 #ifdef CONFIG_LIBIPW_DEBUG
1645 is_beacon(beacon->
header.frame_ctl) ?
1646 "BEACON" :
"PROBE RESPONSE");
1648 memcpy(target, &network,
sizeof(*target));
1656 is_beacon(beacon->
header.frame_ctl) ?
1657 "BEACON" :
"PROBE RESPONSE");
1662 spin_unlock_irqrestore(&ieee->
lock, flags);
1664 if (is_beacon(beacon->
header.frame_ctl)) {
1682 libipw_handle_assoc_resp(ieee,
1710 libipw_process_probe_response(ieee,
1721 libipw_process_probe_response(ieee,