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

📄 am930mac.c

📁 Linux Wireless LAN Project 的目标是开发一个完整的
💻 C
📖 第 1 页 / 共 4 页
字号:
				/* silently drop it, (the tx would fail anyway) */				am930shim_pbfree(pb);				return 0;			}			break;	}	/* Enqueue for transmission */	result = am930q_enqueue( mac->llcq, pb);		am930hw_txkick(mac->hw);	#if (WLAN_OS == WLAN_LWOS)		am930lw_readerkick();	#endif	DBFEXIT;	return result;}/*----------------------------------------------------------------*	am930mac_txmac**	Public method called from mac and mgr to send a frame.  In this*	case, the 80211 header has already been set up.  All we need*	to do is queue the frame.**	returns: *		0 success *		1 alloc failure*		2 queue full*		3 queue busy----------------------------------------------------------------*/UINT32 am930mac_txmac( am930mac_t *mac, wlan_pb_t *pb){	UINT32			result = 0;	DBFENTER;	if ( mac->mode == AM930_MACMODE_NOTRUNNING ||		 mac->mode == AM930_MACMODE_NOTJOINED )	{		WLAN_LOG_WARNING0("tx attempt, not joined, frame dropped\n");		return result;	}	result = am930q_enqueue( mac->macq, pb);	#if (WLAN_OS == WLAN_LINUX_KERNEL )		am930hw_txkick(mac->hw);	#elif (WLAN_OS == WLAN_LWOS )		am930lw_readerkick();	#else		#error  "No WLAN_OS match!"	#endif	DBFEXIT;	return result;}/*----------------------------------------------------------------*	am930q_init**	Initilizes a new queue.  To get rid of it, the caller should *	empty it and then use kfree_s(q, sizeof(am930q_t)).*	*	returns:*		NULL - alloc failure*		else - success----------------------------------------------------------------*/am930q_t *am930q_init(UINT maxlen){	am930q_t *q = NULL;	q = kmalloc(sizeof(am930q_t), GFP_ATOMIC);	if ( q != NULL )	{		memset(q, 0, sizeof(am930q_t));		q->maxlen = maxlen;	}	return q;}/*----------------------------------------------------------------*	am930q_enqueue**	Adds an item to the given queue if it won't exceed the max*	length.**	returns:*		0 success, more space avail *		1 success, no more space*		2 alloc failure*		3 queue full*		4 queue busy----------------------------------------------------------------*/int am930q_enqueue(am930q_t *q, void *data){	int				result = 0;	wlan_flags_t	flags;	am930qitem_t	*qitem;	WLAN_INT_DISABLE(flags);		/* TODO: need safe lock here */	if ( q->busy == 0 )	{		q->busy = 1;		if ( q->len < q->maxlen )		{			qitem = kmalloc(sizeof(am930qitem_t), GFP_ATOMIC);			if ( qitem != NULL )			{				memset(qitem, 0, sizeof(am930qitem_t));				qitem->data = data;				qitem->q = q;				qitem->prev = q->tail;				if (q->tail != NULL)				{					q->tail->next = qitem;					q->tail = qitem;				}				else				{					q->head = q->tail = qitem;				}				q->len++;				result = ((q->len < q->maxlen) ? 0 : 1);			}			else			{				result = 2;			}		}		else		{			result = 3;		}		q->busy = 0;		WLAN_INT_ENABLE(flags);	}	else	{		WLAN_INT_ENABLE(flags);		WLAN_LOG_DEBUG0(2, "queue is busy\n");		result = 4;	}	return result;}/*----------------------------------------------------------------*	am930q_dequeue**	Retrieves an item from the front of the queue.*	*	returns:*		NULL - queue empty or busy*		else - success----------------------------------------------------------------*/void *am930q_dequeue(am930q_t *q){	void			*data = NULL;	am930qitem_t	*qitem;	wlan_flags_t	flags;	WLAN_INT_DISABLE(flags);	if ( q->busy == 0 )	{		q->busy = 1;		if ( q->len > 0 && q->head != NULL)		{			data = q->head->data;			qitem = q->head;			if ( q->head != q->tail )			{				q->head = qitem->next;				q->head->prev = NULL;			}			else			{				q->head = q->tail = NULL;			}			kfree_s(qitem, sizeof(am930qitem_t));			q->len--;		}		q->busy = 0;		WLAN_INT_ENABLE(flags);	}	else	{		WLAN_INT_ENABLE(flags);		WLAN_LOG_DEBUG0(2, "queue is busy\n");	}	return data;}/*----------------------------------------------------------------*	am930q_requeue**	TODO: add code to reinsert an item into the front of a queue.*			Don't test maxlen.*	returns:*		0 success *		1 alloc failure----------------------------------------------------------------*//*int am930q_requeue(am930q_t *q, void *data){}*//*----------------------------------------------------------------*	am930q_peek**	TODO: add a function that will return the data ptr from the*		front of the queue without removing the item.*	*	returns:*		NULL - queue empty*		else - success----------------------------------------------------------------*//*void *am930q_peek(am930q_t *q, void *data){	return		NULL - queue empty		else - success	}*/#ifdef WLAN_INCLUDE_WEP	#include "wepcode.c.inc"#else/*----------------------------------------------------------------*	am930mac_wep_initprng**	Initializes the WEP Psuedo-Random number generator using a*	given seed.  The seed is usually the private key.*	Arguments:*		prng	- a structure, allocated by the caller, that will *				maintain state information during the use of this*				prng.*		k		- an array of bytes containing the seed*		klen	- length of seed*	*	returns: nothing----------------------------------------------------------------*/void am930mac_wep_initprng( wlan_wepprng_t *prng, UINT8 *k,  UINT klen){}/*----------------------------------------------------------------*	am930mac_wep_nextprn**	Retrieves the next value from a prng initialized with*	wep_prng.*	Arguments:*		prng	- a prng structure previosly initialized with*				wep_initprng.*	*	returns: next psuedo-random number----------------------------------------------------------------*/UINT8	am930mac_wep_nextprn( wlan_wepprng_t *prng){	return 0;}/*----------------------------------------------------------------*	am930mac_wep_block**	WEP encrypts a block of bytes in place.*	Arguments:*		prng	- a prng structure previosly initialized with*				wep_initprng.*		d		- ptr to the block of bytes to be encrypted.*		dlen	- length of the block*	*	returns: nothing----------------------------------------------------------------*/void am930mac_wep_block( wlan_wepprng_t *prng, UINT8 *d, UINT dlen){	return;}/*----------------------------------------------------------------*	am930mac_wep_decrypt**	Inspects the given frame, if it doesn't require decryption*	just return it.  If the frame does require decryption, check*	to see that we set up for decryption.  If we're not set up*	for decryption, drop the frame and return NULL.  If the frame*	needs decryption _and_ we support and are configured for it,*	decrypt the frame inside the given pb and return it to the *	caller.*	Arguments:*		mac		- the receiver*		pb		- packet buffer containing the frame*	*	returns: *		pb		- if the frame doesn't need decryption or the frame*					is successfully decrypted*		NULL	- if the frame requires decryption and:*					- we don't support it *					- we haven't been configured for it. *						(i.e. mac->privacy_invoked == 0, no keys set, etc.)*					- the ICV check failed.----------------------------------------------------------------*/wlan_pb_t *am930mac_wep_decrypt( am930mac_t *mac, wlan_pb_t *pb){	return pb;}/*----------------------------------------------------------------*	am930mac_wep_encrypt**	Takes the given frame, and if privacy_invoked==true, encrypts*	it.*	Arguments:*		mac		- the receiver*		pb		- packet buffer containing the frame*	*	returns: nothing**	note: after the call, the pb->iscrypt field indicates whether*			the frame was successfully encrypted.----------------------------------------------------------------*/void am930mac_wep_encrypt( am930mac_t *mac, wlan_pb_t *pb){	return;}#endif /* WLAN_INCLUDE_WEP */#ifdef WLAN_INCLUDE_SNIF/*----------------------------------------------------------------*	am930mac_snifframe**	Takes the given frame tacks on a sniffer_t to the front and*	sends it up to the LLC layer.**	Arguments:*		mac		- the receiver*		pb		- packet buffer containing the frame*		stats	- info about the frame*	*	returns: nothing----------------------------------------------------------------*/void am930mac_snifframe(am930mac_t *mac, wlan_pb_t *pb, am930rxstats_t *stats){	wlan_sniffer_t	snif;	struct sk_buff	*skb;	snif.time = jiffies;	/* determine the pb type and size */	if ( stats != NULL )	{		snif.rssi = stats->rssi;		snif.ch = stats->ch;		snif.rate = stats->rate;		snif.istx = 0;		/* it's an rx frame, the whole thing is in p80211buf */		snif.len = pb->p80211frmlen;	}	else	{		snif.rssi = 0;		snif.ch = 0;		snif.rate = 0;		snif.istx = 1;		/* note: tx frames, we add 4 for the missing FCS */		if ( pb->ethhostbuf != NULL )		{			/* it's a tx frame, that's been converted from ether */			snif.len = pb->p80211buflen + pb->p80211_payloadlen + 4;		}		else		{			/* it's a tx frame, that that has everything in the p80211buf */			/*  Note the FCS fix again... */			snif.len = pb->p80211frmlen + WLAN_FCS_LEN;		}	}	if ( pb->wep_iscrypt )	{		snif.len += WLAN_WEP_IV_LEN + WLAN_WEP_ICV_LEN;	}	/* allocate an skb for sniffer_t + frame */	skb = alloc_skb(snif.len + sizeof(snif), GFP_ATOMIC);	skb_put(skb, snif.len + sizeof(snif));	/* fill skb */	memcpy( skb->data, &snif, sizeof(snif));	if ( !snif.istx )	{		/* It's an rx frame, all in p80211buf (except iv and icv) */		UINT8	*src = pb->p80211buf;		UINT8	*dst = skb->data + sizeof(snif);		memcpy( dst, src, WLAN_HDR_A3_LEN);		dst += WLAN_HDR_A3_LEN;		src += WLAN_HDR_A3_LEN;		if ( pb->wep_iscrypt )		{			memcpy( dst, &(pb->wep_iv), WLAN_WEP_IV_LEN);			dst += WLAN_WEP_IV_LEN;		}		memcpy( dst, src, pb->p80211frmlen - WLAN_HDR_A3_LEN - WLAN_FCS_LEN);		dst += pb->p80211frmlen - WLAN_HDR_A3_LEN - WLAN_FCS_LEN;		src += pb->p80211frmlen - WLAN_HDR_A3_LEN - WLAN_FCS_LEN;		if ( pb->wep_iscrypt )		{			memcpy( dst, &(pb->wep_icv), WLAN_WEP_ICV_LEN);			dst += WLAN_WEP_ICV_LEN;		}		memcpy( dst, src, WLAN_FCS_LEN);	}	else	{		/* We don't support TX sniffing right now */		#ifdef NOTUSED		if ( pb->ethhostbuf != NULL )		{			memcpy( skb->data + sizeof(snif), pb->p80211buf, pb->p80211buflen);			memcpy( skb->data + sizeof(snif) + pb->p80211buflen,						pb->p80211_payload, pb->p80211_payloadlen);			memset( 				skb->data + sizeof(snif) + pb->p80211buflen + pb->p80211_payloadlen,				0,				WLAN_CRC_LEN);		}		else		{			memcpy( skb->data + sizeof(snif), pb->p80211buf, snif.len - WLAN_CRC_LEN);			memset( skb->data + sizeof(snif) + snif.len - WLAN_CRC_LEN, 0, WLAN_CRC_LEN);		}		#endif	}	/* call llc */	am930llc_sendtosniffer(mac->llc, skb);	return;}#endif /* WLAN_INCLUDE_SNIF */

⌨️ 快捷键说明

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