⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieee80211_rx.c

📁 Source for the 802.11 (wireless) network stack for Linux
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (ieee->iw_mode == IW_MODE_MASTER && !wds &&	    (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==	    IEEE80211_FCTL_FROMDS && ieee->stadev	    && memcmp(hdr->addr2, ieee->assoc_ap_addr, ETH_ALEN) == 0) {		/* Frame from BSSID of the AP for which we are a client */		skb->dev = dev = ieee->stadev;		stats = hostap_get_stats(dev);		from_assoc_ap = 1;	}#endif	dev->last_rx = jiffies;#ifdef NOT_YET	if ((ieee->iw_mode == IW_MODE_MASTER ||	     ieee->iw_mode == IW_MODE_REPEAT) && !from_assoc_ap) {		switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,					     wds != NULL)) {		case AP_RX_CONTINUE_NOT_AUTHORIZED:			frame_authorized = 0;			break;		case AP_RX_CONTINUE:			frame_authorized = 1;			break;		case AP_RX_DROP:			goto rx_dropped;		case AP_RX_EXIT:			goto rx_exit;		}	}#endif	/* Nullfunc frames may have PS-bit set, so they must be passed to	 * hostap_handle_sta_rx() before being dropped here. */	stype &= ~IEEE80211_STYPE_QOS_DATA;	if (stype != IEEE80211_STYPE_DATA &&	    stype != IEEE80211_STYPE_DATA_CFACK &&	    stype != IEEE80211_STYPE_DATA_CFPOLL &&	    stype != IEEE80211_STYPE_DATA_CFACKPOLL) {		if (stype != IEEE80211_STYPE_NULLFUNC)			IEEE80211_DEBUG_DROP("RX: dropped data frame "					     "with no data (type=0x%02x, "					     "subtype=0x%02x, len=%d)\n",					     type, stype, skb->len);		goto rx_dropped;	}	/* skb: hdr + (possibly fragmented, possibly encrypted) payload */	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&	    (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)		goto rx_dropped;	hdr = (struct ieee80211_hdr_4addr *)skb->data;	/* skb: hdr + (possibly fragmented) plaintext payload */	// PR: FIXME: hostap has additional conditions in the "if" below:	// ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&	if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {		int flen;		struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);		IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);		if (!frag_skb) {			IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG,					"Rx cannot get skb from fragment "					"cache (morefrag=%d seq=%u frag=%u)\n",					(fc & IEEE80211_FCTL_MOREFRAGS) != 0,					WLAN_GET_SEQ_SEQ(sc), frag);			goto rx_dropped;		}		flen = skb->len;		if (frag != 0)			flen -= hdrlen;		if (frag_skb->tail + flen > frag_skb->end) {			printk(KERN_WARNING "%s: host decrypted and "			       "reassembled frame did not fit skb\n",			       dev->name);			ieee80211_frag_cache_invalidate(ieee, hdr);			goto rx_dropped;		}		if (frag == 0) {			/* copy first fragment (including full headers) into			 * beginning of the fragment cache skb */			memcpy(skb_put(frag_skb, flen), skb->data, flen);		} else {			/* append frame payload to the end of the fragment			 * cache skb */			memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,			       flen);		}		dev_kfree_skb_any(skb);		skb = NULL;		if (fc & IEEE80211_FCTL_MOREFRAGS) {			/* more fragments expected - leave the skb in fragment			 * cache for now; it will be delivered to upper layers			 * after all fragments have been received */			goto rx_exit;		}		/* this was the last fragment and the frame will be		 * delivered, so remove skb from fragment cache */		skb = frag_skb;		hdr = (struct ieee80211_hdr_4addr *)skb->data;		ieee80211_frag_cache_invalidate(ieee, hdr);	}	/* skb: hdr + (possible reassembled) full MSDU payload; possibly still	 * encrypted/authenticated */	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&	    ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt))		goto rx_dropped;	hdr = (struct ieee80211_hdr_4addr *)skb->data;	if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep) {		if (		/*ieee->ieee802_1x && */			   ieee80211_is_eapol_frame(ieee, skb)) {			/* pass unencrypted EAPOL frames even if encryption is			 * configured */		} else {			IEEE80211_DEBUG_DROP("encryption configured, but RX "					     "frame not encrypted (SA=" MAC_FMT					     ")\n", MAC_ARG(hdr->addr2));			goto rx_dropped;		}	}	if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !ieee->open_wep &&	    !ieee80211_is_eapol_frame(ieee, skb)) {		IEEE80211_DEBUG_DROP("dropped unencrypted RX data "				     "frame from " MAC_FMT				     " (drop_unencrypted=1)\n",				     MAC_ARG(hdr->addr2));		goto rx_dropped;	}	/* skb: hdr + (possible reassembled) full plaintext payload */	payload = skb->data + hdrlen;	ethertype = (payload[6] << 8) | payload[7];#ifdef NOT_YET	/* If IEEE 802.1X is used, check whether the port is authorized to send	 * the received frame. */	if (ieee->ieee802_1x && ieee->iw_mode == IW_MODE_MASTER) {		if (ethertype == ETH_P_PAE) {			printk(KERN_DEBUG "%s: RX: IEEE 802.1X frame\n",			       dev->name);			if (ieee->hostapd && ieee->apdev) {				/* Send IEEE 802.1X frames to the user				 * space daemon for processing */				prism2_rx_80211(ieee->apdev, skb, rx_stats,						PRISM2_RX_MGMT);				ieee->apdevstats.rx_packets++;				ieee->apdevstats.rx_bytes += skb->len;				goto rx_exit;			}		} else if (!frame_authorized) {			printk(KERN_DEBUG "%s: dropped frame from "			       "unauthorized port (IEEE 802.1X): "			       "ethertype=0x%04x\n", dev->name, ethertype);			goto rx_dropped;		}	}#endif	/* convert hdr + possible LLC headers into Ethernet header */	if (skb->len - hdrlen >= 8 &&	    ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 &&	      ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||	     memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) {		/* remove RFC1042 or Bridge-Tunnel encapsulation and		 * replace EtherType */		skb_pull(skb, hdrlen + SNAP_SIZE);		memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);		memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);	} else {		u16 len;		/* Leave Ethernet header part of hdr and full payload */		skb_pull(skb, hdrlen);		len = htons(skb->len);		memcpy(skb_push(skb, 2), &len, 2);		memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);		memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);	}#ifdef NOT_YET	if (wds && ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==		    IEEE80211_FCTL_TODS) && skb->len >= ETH_HLEN + ETH_ALEN) {		/* Non-standard frame: get addr4 from its bogus location after		 * the payload */		memcpy(skb->data + ETH_ALEN,		       skb->data + skb->len - ETH_ALEN, ETH_ALEN);		skb_trim(skb, skb->len - ETH_ALEN);	}#endif	stats->rx_packets++;	stats->rx_bytes += skb->len;#ifdef NOT_YET	if (ieee->iw_mode == IW_MODE_MASTER && !wds && ieee->ap->bridge_packets) {		if (dst[0] & 0x01) {			/* copy multicast frame both to the higher layers and			 * to the wireless media */			ieee->ap->bridged_multicast++;			skb2 = skb_clone(skb, GFP_ATOMIC);			if (skb2 == NULL)				printk(KERN_DEBUG "%s: skb_clone failed for "				       "multicast frame\n", dev->name);		} else if (hostap_is_sta_assoc(ieee->ap, dst)) {			/* send frame directly to the associated STA using			 * wireless media and not passing to higher layers */			ieee->ap->bridged_unicast++;			skb2 = skb;			skb = NULL;		}	}	if (skb2 != NULL) {		/* send to wireless media */		skb2->protocol = __constant_htons(ETH_P_802_3);		skb2->mac.raw = skb2->nh.raw = skb2->data;		/* skb2->nh.raw = skb2->data + ETH_HLEN; */		skb2->dev = dev;		dev_queue_xmit(skb2);	}#endif	if (skb) {		skb->protocol = eth_type_trans(skb, dev);		memset(skb->cb, 0, sizeof(skb->cb));		skb->dev = dev;		skb->ip_summed = CHECKSUM_NONE;	/* 802.11 crc not sufficient */		netif_rx(skb);	}      rx_exit:#ifdef NOT_YET	if (sta)		hostap_handle_sta_release(sta);#endif	return 1;      rx_dropped:	stats->rx_dropped++;	/* Returning 0 indicates to caller that we have not handled the SKB--	 * so it is still allocated and can be used again by underlying	 * hardware as a DMA target */	return 0;}#define MGMT_FRAME_FIXED_PART_LENGTH		0x24static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };/** Make ther structure we read from the beacon packet has* the right values*/static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element				     *info_element, int sub_type){	if (info_element->qui_subtype != sub_type)		return -1;	if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))		return -1;	if (info_element->qui_type != QOS_OUI_TYPE)		return -1;	if (info_element->version != QOS_VERSION_1)		return -1;	return 0;}/* * Parse a QoS parameter element */static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info					    *element_param, struct ieee80211_info_element					    *info_element){	int ret = 0;	u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;	if ((info_element == NULL) || (element_param == NULL))		return -1;	if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {		memcpy(element_param->info_element.qui, info_element->data,		       info_element->len);		element_param->info_element.elementID = info_element->id;		element_param->info_element.length = info_element->len;	} else		ret = -1;	if (ret == 0)		ret = ieee80211_verify_qos_info(&element_param->info_element,						QOS_OUI_PARAM_SUB_TYPE);	return ret;}/* * Parse a QoS information element */static int ieee80211_read_qos_info_element(struct					   ieee80211_qos_information_element					   *element_info, struct ieee80211_info_element					   *info_element){	int ret = 0;	u16 size = sizeof(struct ieee80211_qos_information_element) - 2;	if (element_info == NULL)		return -1;	if (info_element == NULL)		return -1;	if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {		memcpy(element_info->qui, info_element->data,		       info_element->len);		element_info->elementID = info_element->id;		element_info->length = info_element->len;	} else		ret = -1;	if (ret == 0)		ret = ieee80211_verify_qos_info(element_info,						QOS_OUI_INFO_SUB_TYPE);	return ret;}/* * Write QoS parameters from the ac parameters. */static int ieee80211_qos_convert_ac_to_parameters(struct						  ieee80211_qos_parameter_info						  *param_elm, struct						  ieee80211_qos_parameters						  *qos_param){	int rc = 0;	int i;	struct ieee80211_qos_ac_parameter *ac_params;	u32 txop;	u8 cw_min;	u8 cw_max;	for (i = 0; i < QOS_QUEUE_NUM; i++) {		ac_params = &(param_elm->ac_params_record[i]);		qos_param->aifs[i] = (ac_params->aci_aifsn) & 0x0F;		qos_param->aifs[i] -= (qos_param->aifs[i] < 2) ? 0 : 2;		cw_min = ac_params->ecw_min_max & 0x0F;		qos_param->cw_min[i] = (u16) ((1 << cw_min) - 1);		cw_max = (ac_params->ecw_min_max & 0xF0) >> 4;		qos_param->cw_max[i] = (u16) ((1 << cw_max) - 1);		qos_param->flag[i] =		    (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;		txop = le16_to_cpu(ac_params->tx_op_limit) * 32;		qos_param->tx_op_limit[i] = (u16) txop;	}	return rc;}/* * we have a generic data element which it may contain QoS information or * parameters element. check the information element length to decide * which type to read */static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element					     *info_element,					     struct ieee80211_network *network){	int rc = 0;	struct ieee80211_qos_parameters *qos_param = NULL;	struct ieee80211_qos_information_element qos_info_element;	rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);	if (rc == 0) {		network->qos_data.param_count = qos_info_element.ac_info & 0x0F;		network->flags |= NETWORK_HAS_QOS_INFORMATION;	} else {		struct ieee80211_qos_parameter_info param_element;		rc = ieee80211_read_qos_param_element(&param_element,						      info_element);		if (rc == 0) {			qos_param = &(network->qos_data.parameters);			ieee80211_qos_convert_ac_to_parameters(&param_element,							       qos_param);			network->flags |= NETWORK_HAS_QOS_PARAMETERS;			network->qos_data.param_count =			    param_element.info_element.ac_info & 0x0F;		}	}	if (rc == 0) {		IEEE80211_DEBUG_QOS("QoS is supported\n");		network->qos_data.supported = 1;	}	return rc;}static int ieee80211_parse_info_param(struct ieee80211_info_element				      *info_element, u16 length,				      struct ieee80211_network *network){	u8 i;#ifdef CONFIG_IEEE80211_DEBUG	char rates_str[64];	char *p;#endif	while (length >= sizeof(*info_element)) {		if (sizeof(*info_element) + info_element->len > length) {			IEEE80211_DEBUG_MGMT("Info elem: parse failed: "					     "info_element->len + 2 > left : "					     "info_element->len+2=%zd left=%d, id=%d.\n",					     info_element->len +					     sizeof(*info_element),					     length, info_element->id);			return 1;		}		switch (info_element->id) {		case MFIE_TYPE_SSID:			if (ieee80211_is_empty_essid(info_element->data,						     info_element->len)) {				network->flags |= NETWORK_EMPTY_ESSID;				break;			}			network->ssid_len = min(info_element->len,						(u8) IW_ESSID_MAX_SIZE);			memcpy(network->ssid, info_element->data,			       network->ssid_len);			if (network->ssid_len < IW_ESSID_MAX_SIZE)				memset(network->ssid + network->ssid_len, 0,				       IW_ESSID_MAX_SIZE - network->ssid_len);			IEEE80211_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",					     network->ssid, network->ssid_len);			break;		case MFIE_TYPE_RATES:#ifdef CONFIG_IEEE80211_DEBUG			p = rates_str;#endif			network->rates_len = min(info_element->len,						 MAX_RATES_LENGTH);			for (i = 0; i < network->rates_len; i++) {				network->rates[i] = info_element->data[i];#ifdef CONFIG_IEEE80211_DEBUG				p += snprintf(p, sizeof(rates_str) -					      (p - rates_str), "%02X ",					      network->rates[i]);#endif				if (ieee80211_is_ofdm_rate				    (info_element->data[i])) {					network->flags |= NETWORK_HAS_OFDM;					if (info_element->data[i] &					    IEEE80211_BASIC_RATE_MASK)						network->flags &=						    ~NETWORK_HAS_CCK;				}			}			IEEE80211_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",					     rates_str, network->rates_len);			break;		case MFIE_TYPE_RATES_EX:#ifdef CONFIG_IEEE80211_DEBUG			p = rates_str;#endif			network->rates_ex_len = min(info_element->len,						    MAX_RATES_EX_LENGTH);			for (i = 0; i < network->rates_ex_len; i++) {				network->rates_ex[i] = info_element->data[i];#ifdef CONFIG_IEEE80211_DEBUG				p += snprintf(p, sizeof(rates_str) -					      (p - rates_str), "%02X ",					      network->rates[i]);#endif				if (ieee80211_is_ofdm_rate				    (info_element->data[i])) {					network->flags |= NETWORK_HAS_OFDM;					if (info_element->data[i] &					    IEEE80211_BASIC_RATE_MASK)						network->flags &=						    ~NETWORK_HAS_CCK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -