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

📄 p80211conv.c

📁 Linux的无线局域网方案是一个Linux设备驱动程序和子系统 一揽子方案的用意是提供全系列的IEEE 802.11标准的Mac 管理功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/* src/p80211/p80211conv.c** Ether/802.11 conversions and packet buffer routines** Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.* --------------------------------------------------------------------** linux-wlan**   The contents of this file are subject to the Mozilla Public*   License Version 1.1 (the "License"); you may not use this file*   except in compliance with the License. You may obtain a copy of*   the License at http://www.mozilla.org/MPL/**   Software distributed under the License is distributed on an "AS*   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or*   implied. See the License for the specific language governing*   rights and limitations under the License.**   Alternatively, the contents of this file may be used under the*   terms of the GNU Public License version 2 (the "GPL"), in which*   case the provisions of the GPL are applicable instead of the*   above.  If you wish to allow the use of your version of this file*   only under the terms of the GPL and not to allow others to use*   your version of this file under the MPL, indicate your decision*   by deleting the provisions above and replace them with the notice*   and other provisions required by the GPL.  If you do not delete*   the provisions above, a recipient may use your version of this*   file under either the MPL or the GPL.** --------------------------------------------------------------------** Inquiries regarding the linux-wlan Open Source project can be* made directly to:** AbsoluteValue Systems Inc.* info@linux-wlan.com* http://www.linux-wlan.com** --------------------------------------------------------------------** Portions of the development of this software were funded by * Intersil Corporation as part of PRISM(R) chipset product development.** --------------------------------------------------------------------** This file defines the functions that perform Ethernet to/from* 802.11 frame conversions.  Additionally,  the functions for* manipulating the wlan_pb_t packet buffer structures are here.** --------------------------------------------------------------------*//*================================================================*//* System Includes */#define __NO_VERSION__		/* prevent the static definition */#include <linux/config.h>#include <linux/version.h>#include <wlan/wlan_compat.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/skbuff.h>#include <linux/slab.h>#include <linux/netdevice.h>#include <asm/byteorder.h>/*================================================================*//* Project Includes */#include <wlan/version.h>#include <wlan/p80211types.h>#include <wlan/p80211hdr.h>#include <wlan/p80211conv.h>#include <wlan/p80211mgmt.h>#include <wlan/p80211msg.h>#include <wlan/p80211netdev.h>#include <wlan/p80211ioctl.h>#include <wlan/p80211req.h>/*================================================================*//* Local Constants *//*================================================================*//* Local Macros *//*================================================================*//* Local Types *//*================================================================*//* Local Static Definitions */static UINT8	oui_rfc1042[] = {0x00, 0x00, 0x00};static UINT8	oui_8021h[] = {0x00, 0x00, 0xf8};/*================================================================*//* Local Function Declarations *//*================================================================*//* Function Definitions *//*----------------------------------------------------------------* p80211pb_ether_to_80211** Uses the contents of the ether frame and the etherconv setting* to build the elements of the 802.11 frame.  ** We don't actually set * up the frame header here.  That's the MAC's job.  We're only handling* conversion of DIXII or 802.3+LLC frames to something that works* with 802.11.** Assume the following are already set:*   pb->ethfree*   pb->ethhostbuf*   pb->ethbuf;*   pb->ethbuflen*   pb->eth_hdr*	returns: zero on success, non-zero on failure** Arguments:*	ethconv		Conversion type to perform*	pb		Packet buffer containing the ether frame** Returns: *	0 on success, non-zero otherwise*	* Call context:*	May be called in interrupt or non-interrupt context----------------------------------------------------------------*/int p80211pb_ether_to_p80211( wlandevice_t *wlandev, UINT32 ethconv, wlan_pb_t *pb){	UINT16	proto;	UINT16	fc;	UINT8	*a1 = NULL;	UINT8	*a2 = NULL;	UINT8	*a3 = NULL;	DBFENTER;	if ( ethconv == WLAN_ETHCONV_ENCAP ) { /* simplest case */		/* here, we don't care what kind of ether frm. Just stick it */		/*  in the 80211 payload */		pb->p80211hostbuf = kmalloc( WLAN_HDR_A3_LEN, GFP_ATOMIC);		if ( pb->p80211hostbuf == NULL ) {			return 1;			WLAN_LOG_DEBUG0(1, "Failed to alloc hostbuf1\n");		}		pb->p80211buflen = WLAN_HDR_A3_LEN;		pb->p80211free = p80211pb_kfree_s;		pb->p80211buf = (UINT8*)(pb->p80211hostbuf);		pb->p80211_hdr = (p80211_hdr_t*)pb->p80211buf;		pb->p80211_payload = pb->ethbuf;		pb->p80211_payloadlen = pb->ethbuflen;	} else {		/* step 1: classify ether frame, DIX or 802.3? */		proto = ntohs(pb->eth_hdr->type);		if ( proto <= 1500 ) { /* codes <= 1500 reserved for 802.3 lengths */			/* it's 802.3, pass ether payload unchanged,  */			/*   leave off any PAD octets.  */			pb->p80211hostbuf = kmalloc( WLAN_HDR_A3_LEN, GFP_ATOMIC);			if ( pb->p80211hostbuf == NULL ) {				WLAN_LOG_DEBUG0(1, "Failed to alloc hostbuf2\n");				return 1;			}			pb->p80211buflen = WLAN_HDR_A3_LEN;			pb->p80211free = p80211pb_kfree_s;			pb->p80211buf = (UINT8*)(pb->p80211hostbuf);			pb->p80211_hdr = (p80211_hdr_t*)pb->p80211buf;			/* setup the payload ptrs */			pb->p80211_payload = pb->ethbuf + sizeof(wlan_ethhdr_t);			pb->p80211_payloadlen = ntohs(pb->eth_hdr->type);		} else {			/* it's DIXII, time for some conversion */			pb->p80211hostbuf = kmalloc( 						WLAN_HDR_A3_LEN + 						sizeof(wlan_llc_t) +						sizeof(wlan_snap_t), GFP_ATOMIC);			if ( pb->p80211hostbuf == NULL ) {				WLAN_LOG_DEBUG0(1, "Failed to alloc hostbuf3\n");				return 1;			}			pb->p80211buflen = 						WLAN_HDR_A3_LEN + 						sizeof(wlan_llc_t) +						sizeof(wlan_snap_t);			pb->p80211free = p80211pb_kfree_s;			pb->p80211buf = (UINT8*)pb->p80211hostbuf;			pb->p80211_hdr = (p80211_hdr_t*)pb->p80211buf;			pb->p80211_llc = (wlan_llc_t*)(pb->p80211buf + WLAN_HDR_A3_LEN);			pb->p80211_snap = (wlan_snap_t*)(((UINT8*)pb->p80211_llc) + sizeof(wlan_llc_t));			/* setup the LLC header */			pb->p80211_llc->dsap = 0xAA;	/* SNAP, see IEEE 802 */			pb->p80211_llc->ssap = 0xAA;			pb->p80211_llc->ctl = 0x03;					/* setup the SNAP header */			pb->p80211_snap->type = htons(proto);			if ( ethconv == WLAN_ETHCONV_8021h && 				 p80211_stt_findproto(proto) ) {				memcpy( pb->p80211_snap->oui, oui_8021h, WLAN_IEEE_OUI_LEN);			} else {				memcpy( pb->p80211_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN);			}			/* setup the payload ptrs */			pb->p80211_payload = pb->ethbuf + sizeof(wlan_ethhdr_t);			pb->p80211_payloadlen = pb->ethbuflen - sizeof(wlan_ethhdr_t);		}	}	/* Set up the 802.11 header */	/* It's a data frame */	fc = host2ieee16( WLAN_SET_FC_FTYPE(WLAN_FTYPE_DATA) |  			WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DATAONLY));	pb->p80211_hdr->a3.dur = 0;	pb->p80211_hdr->a3.seq = 0;	switch ( wlandev->macmode ) {	case WLAN_MACMODE_IBSS_STA: 		a1 = pb->eth_hdr->daddr;	/*dest*/		a2 = wlandev->netdev->dev_addr;	/*src*/		a3 = wlandev->bssid;		/*bssid*/		break;	case WLAN_MACMODE_ESS_STA:		fc |= host2ieee16(WLAN_SET_FC_TODS(1));		a1 = wlandev->bssid;		/*bssid*/		a2 = wlandev->netdev->dev_addr;	/*src*/		a3 = pb->eth_hdr->daddr;	/*dest*/		break;	case WLAN_MACMODE_ESS_AP:		fc |= host2ieee16(WLAN_SET_FC_FROMDS(1));		a1 = pb->eth_hdr->daddr;		a2 = wlandev->bssid;		a3 = pb->eth_hdr->saddr;		break;	default:		WLAN_LOG_ERROR0("Error: Converting eth to wlan in unknown mode.\n");		return 1;		break;	}	pb->p80211_hdr->a3.fc = fc;	memcpy( pb->p80211_hdr->a3.a1, a1, WLAN_ADDR_LEN); 	memcpy( pb->p80211_hdr->a3.a2, a2, WLAN_ADDR_LEN);	memcpy( pb->p80211_hdr->a3.a3, a3, WLAN_ADDR_LEN);	/* Note that lower layers may set more bits in the fc field */	DBFEXIT;	return 0;}/*----------------------------------------------------------------* p80211pb_80211_to_ether** Uses the contents of a received 802.11 frame and the etherconv * setting to build an ether frame.** This function extracts the src and dest address from the 802.11* frame to use in the construction of the eth frame.** This function _will_ set the ethfree member.  If a caller wants* to allow some other component (a higher layer?) take responsiblity* for freeing the ethhostbuf, the caller should set ethfree to NULL.** Assume the following are already set:*	pb->p80211free*	pb->p80211hostbuf*	pb->p80211buf*	pb->p80211buflen*	pb->p80211_hdr*	pb->p80211_payload*	pb->p80211_payloadlen** Arguments:*	ethconv		Conversion type to perform*	pb		Packet buffer containing the 802.11 frame** Returns: *	0 on success, non-zero otherwise*	* Call context:*	May be called in interrupt or non-interrupt context----------------------------------------------------------------*/int p80211pb_p80211_to_ether( wlandevice_t *wlandev, UINT32 ethconv, wlan_pb_t *pb){	UINT8			*daddr = NULL;	UINT8			*saddr = NULL;	wlan_ethhdr_t	*ethhdr;	UINT			llclen;		/* 802 LLC+data length */	UINT			dixlen;		/* DIX data length */	UINT			buflen;		/* full frame length, including PAD */	UINT16			fc;	/* setup some vars for convenience */	fc = ieee2host16(pb->p80211_hdr->a3.fc);	if ( (WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0) ) {		daddr = pb->p80211_hdr->a3.a1;		saddr = pb->p80211_hdr->a3.a2;	} else if( (WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 1) ) {		daddr = pb->p80211_hdr->a3.a1;		saddr = pb->p80211_hdr->a3.a3;	} else if( (WLAN_GET_FC_TODS(fc) == 1) && (WLAN_GET_FC_FROMDS(fc) == 0) ) {		daddr = pb->p80211_hdr->a3.a3;		saddr = pb->p80211_hdr->a3.a2;	} else {		WLAN_LOG_ERROR0("HDR_A4 detected! A4 currently not supported.\n");		/* set some bogus pointers so at least we won't crash */		daddr = pb->p80211_hdr->a3.a1;		saddr = pb->p80211_hdr->a3.a2;	}	ethhdr = (wlan_ethhdr_t*)(pb->p80211_payload);	pb->p80211_llc = (wlan_llc_t*)(((UINT8*)pb->p80211_hdr) + sizeof(p80211_hdr_a3_t));	pb->p80211_snap = (wlan_snap_t*)(((UINT8*)pb->p80211_llc) + sizeof(wlan_llc_t));	/* Test for the various encodings */	if ( memcmp( daddr, ethhdr->daddr, WLAN_ETHADDR_LEN) == 0 && 		memcmp(  saddr, ethhdr->saddr, WLAN_ETHADDR_LEN) == 0 ) {		/* ENCAP */		/* Test for an overlength frame */		if ( pb->p80211frmlen > WLAN_HDR_A3_LEN+WLAN_CRC_LEN+WLAN_MAX_ETHFRM_LEN) {			/* A bogus length ethfrm has been encap'd. */			/* Is someone trying an oflow attack? */			return 1;		}		/* allocate space and setup host buffer */		buflen = llclen = pb->p80211frmlen - WLAN_HDR_A3_LEN - WLAN_CRC_LEN;		pb->ethhostbuf = dev_alloc_skb(buflen + 2); /* +2 is attempt to align IP header */		if ( pb->ethhostbuf == NULL ) return 1;		pb->ethfree = p80211pb_freeskb;		skb_reserve( pb->ethhostbuf, 2);

⌨️ 快捷键说明

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