am930mgr.c

来自「Linux Wireless LAN Project 的目标是开发一个完整的」· C语言 代码 · 共 2,470 行 · 第 1/5 页

C
2,470
字号
	return am930hw_mibset( mgr->hw, mibsec, 0, len, buf);}UINT32 am930mgr_mibsetitem( am930mgr_t *mgr, UINT32 itemid, 							void *buf, UINT32 len){	return am930hw_mibsetitem( mgr->hw, itemid, buf, len);}/*----------------------------------------------------------------*	am930mgr_mkchallengetext**	Constructs the challengetext used primarily for shared key*	authentication.  Uses the given key to initialize the wep*	PRNG, then generates chbuflen PRNs.**	Arguments:*		chbuf		challenge text buffer*		chbuflen	challenge text buffer length*		key			key used to initialize the wep  PRNG*		keylen		length of the key**	Returns: *		nothing----------------------------------------------------------------*/void am930mgr_mkchallengetext( am930mgr_t *mgr, 	UINT8 *chbuf, UINT chbuflen, UINT8 *key, UINT keylen){	wlan_wepprng_t	prng;	int				i;	am930mac_wep_initprng(&prng, key, keylen);	for ( i = 0; i < chbuflen; i++)	{		chbuf[i] = am930mac_wep_nextprn(&prng);	}	return;}/*----------------------------------------------------------------*	am930mgr_mkfrm_auth**	Constructs an auth frame using the arguments provided.**	Arguments:*		daddr		destination address (6 bytes)*		alg			auth algorithm code (see p80211mgmt.h)*		seq			1-4*		status		status code (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_auth( am930mgr_t *mgr, 	UINT8 *daddr, UINT16 alg, UINT16 seq, UINT16 status, UINT8 *challenge){	wlan_pb_t 			*pb;	wlan_fr_authen_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{		am930shim_pballoc_p80211( pb, WLAN_AUTHEN_FR_MAXLEN);		if (pb->p80211hostbuf == NULL )		{			am930shim_pbfree(pb);			pb = NULL;		}		else		{			/* finish buffer setup */			pb->p80211_payloadlen += 4;  /* length fix again, see pballoc_p80211 */			/* Setup the reply structure.  We assume there's no challenge */			/*   included.  If challenge is present, we fix up the len later */			reply.buf = pb->p80211buf;			reply.len = WLAN_AUTHEN_FR_MAXLEN;			wlan_mgmt_encode_authen(&reply);			/* Setup the header */			reply.hdr->a3.fc = host2ieee16(				WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) | 				WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN));			memcpy( reply.hdr->a3.a1, daddr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a2, mgr->hw->addr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a3, mgr->curr_bssid, WLAN_BSSID_LEN);			/* Set up the alg and seq, they're validated below */			*(reply.auth_alg) = host2ieee16(alg);			*(reply.auth_seq) = host2ieee16(seq);			/* Set up the status and validate the alg and seq */			if ( alg == WLAN_AUTH_ALG_OPENSYSTEM )			{				switch (seq)				{					case 1:						/* open(1), status is always zero */						WLAN_ASSERT(status == 0); 						*(reply.status) = 0;						break;					case 2:						*(reply.status) = host2ieee16(status);						break;					default:						WLAN_LOG_ERROR1("OPENSYSTEM invalid seq=%d\n", seq);						am930shim_pbfree(pb);						pb = NULL;						break;				}			}			else if ( alg == WLAN_AUTH_ALG_SHAREDKEY )			{				switch (seq)				{					case 1:						/* sharedkey(1), status is always zero */						WLAN_ASSERT(status == 0);						*(reply.status) = 0;						break;					case 2:						*(reply.status) = host2ieee16(status);						break;					case 3:						/* sharedkey(3), status is always zero */						WLAN_ASSERT(status == 0);						*(reply.status) = 0;						break;					case 4:						*(reply.status) = host2ieee16(status);						break;					default:						WLAN_LOG_ERROR1("SHAREDKEY invalid seq=%d\n", seq);						am930shim_pbfree(pb);						pb = NULL;						break;				}			}			else			{				WLAN_LOG_ERROR1("Invalid alg=%d\n", alg);				am930shim_pbfree(pb);				pb = NULL;							}			/* Set up the challenge text */			if ( pb != NULL )			{				if ( alg == WLAN_AUTH_ALG_SHAREDKEY )				{					if ( (seq == 2 && status == WLAN_MGMT_STATUS_SUCCESS) || 						 (seq == 3) )					{						if ( challenge != NULL )						{							reply.challenge = 								(wlan_ie_challenge_t*)(reply.buf + reply.len);							reply.len += WLAN_CHALLENGE_IE_LEN;							reply.challenge->eid = WLAN_EID_CHALLENGE;							reply.challenge->len = WLAN_CHALLENGE_LEN;							memcpy(reply.challenge->challenge, challenge, WLAN_CHALLENGE_LEN);						}						else						{							WLAN_LOG_ERROR0("SHAREDKEY, seq=2|3, null challenge\n");							am930shim_pbfree(pb);							pb = NULL;						}					}				}			}			/* Adjust the length fields */			if ( pb != NULL )			{				pb->p80211frmlen = reply.len;				pb->p80211_payloadlen = reply.len - WLAN_HDR_A3_LEN;			}		}	}	DBFEXIT;	return pb;}/*----------------------------------------------------------------*	am930mgr_mkfrm_assocreq**	Constructs an assocreq frame using the arguments provided.  Arguments*	are in host order.**	Note: The mkfrm_reassocreq will probably be a *			cut-n-paste of this function,*			changes here will probably have to go there as well.**	Arguments:*		daddr		destination address (6 bytes)*		status		status code (see p80211mgmt.h)*		aid			association ID (see p80211mgmt.h)*		oprates		operational rate set (as an ie) (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_assocreq( am930mgr_t *mgr, 	UINT8 *daddr, UINT16 capinfo, UINT16 listen_int,	wlan_ie_ssid_t *ssid,	wlan_ie_supp_rates_t *rates){	wlan_pb_t 			*pb;	wlan_fr_assocreq_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{		am930shim_pballoc_p80211( pb, WLAN_ASSOCREQ_FR_MAXLEN);		if (pb->p80211hostbuf == NULL )		{			am930shim_pbfree(pb);			pb = NULL;		}		else		{			/* finish buffer setup */			pb->p80211_payloadlen += 4;  /* length fix again, see pballoc_p80211 */			/* Setup the reply structure. */			reply.buf = pb->p80211buf;			reply.len = WLAN_ASSOCREQ_FR_MAXLEN;			wlan_mgmt_encode_assocreq(&reply);			/* Setup the header */			reply.hdr->a3.fc = host2ieee16(				WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) | 				WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ));			memcpy( reply.hdr->a3.a1, daddr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a2, mgr->hw->addr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a3, mgr->curr_bssid, WLAN_BSSID_LEN);			/* Set the status and aid */			*(reply.cap_info) = host2ieee16(capinfo);			*(reply.listen_int) = host2ieee16(listen_int);			/* Copy the SSID */			reply.ssid = (wlan_ie_ssid_t*)(reply.buf + reply.len);			reply.len += ssid->len + WLAN_IEHDR_LEN;			memcpy(reply.ssid, ssid, ssid->len + WLAN_IEHDR_LEN);			/* Copy the rate set */			reply.supp_rates = (wlan_ie_supp_rates_t*)(reply.buf + reply.len);			reply.len += rates->len + WLAN_IEHDR_LEN;			memcpy(reply.supp_rates, rates, rates->len + WLAN_IEHDR_LEN);						/* Adjust the length fields */			if ( pb != NULL )			{				pb->p80211frmlen = reply.len;				pb->p80211_payloadlen = reply.len - WLAN_HDR_A3_LEN;			}		}	}	DBFEXIT;	return pb;}/*----------------------------------------------------------------*	am930mgr_mkfrm_assocresp**	Constructs an assocresp frame using the arguments provided.  Arguments*	are in host order.**	Note: The mkfrm_reassocresp is a cut-n-paste of this function,*			changes here will probably have to go there as well.**	Arguments:*		daddr		destination address (6 bytes)*		status		status code (see p80211mgmt.h)*		aid			association ID (see p80211mgmt.h)*		oprates		operational rate set (as an ie) (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_assocresp( am930mgr_t *mgr, 	UINT8 *daddr, UINT16 capinfo, UINT16 status, UINT16 aid, 	wlan_ie_supp_rates_t *rates){	wlan_pb_t 			*pb;	wlan_fr_assocresp_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{		am930shim_pballoc_p80211( pb, WLAN_ASSOCRESP_FR_MAXLEN);		if (pb->p80211hostbuf == NULL )		{			am930shim_pbfree(pb);			pb = NULL;		}		else		{			/* finish buffer setup */			pb->p80211_payloadlen += 4;  /* length fix again, see pballoc_p80211 */			/* Setup the reply structure. */			reply.buf = pb->p80211buf;			reply.len = WLAN_ASSOCRESP_FR_MAXLEN;			wlan_mgmt_encode_assocresp(&reply);			/* Setup the header */			reply.hdr->a3.fc = host2ieee16(				WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) | 				WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP));			memcpy( reply.hdr->a3.a1, daddr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a2, mgr->hw->addr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a3, mgr->curr_bssid, WLAN_BSSID_LEN);			/* Set the status and aid */			*(reply.cap_info) = host2ieee16(capinfo);			*(reply.status) = host2ieee16(status);			*(reply.aid) = host2ieee16(aid);			/* Copy the rate set */			reply.supp_rates = (wlan_ie_supp_rates_t*)(reply.buf + reply.len);			reply.len += rates->len + WLAN_IEHDR_LEN;			memcpy(reply.supp_rates, rates, rates->len + WLAN_IEHDR_LEN);						/* Adjust the length fields */			if ( pb != NULL )			{				pb->p80211frmlen = reply.len;				pb->p80211_payloadlen = reply.len - WLAN_HDR_A3_LEN;			}		}	}	DBFEXIT;	return pb;}/*----------------------------------------------------------------*	am930mgr_mkfrm_deauth**	Constructs a deauth frame using the arguments provided. Arguments*	are in host order.**	Arguments:*		daddr		destination address (6 bytes)*		reason		reason code (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_deauth( am930mgr_t *mgr, UINT8 *daddr, UINT16 reason){	wlan_pb_t 			*pb;	wlan_fr_deauthen_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{		am930shim_pballoc_p80211( pb, WLAN_DEAUTHEN_FR_MAXLEN);		if (pb->p80211hostbuf == NULL )		{			am930shim_pbfree(pb);			pb = NULL;		}		else		{			/* finish buffer setup */			pb->p80211_payloadlen += 4;  /* length fix again, see pballoc_p80211 */			/* Setup the reply structure. */			reply.buf = pb->p80211buf;			reply.len = WLAN_DEAUTHEN_FR_MAXLEN;			wlan_mgmt_encode_deauthen(&reply);			/* Setup the header */			reply.hdr->a3.fc = host2ieee16(				WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) | 				WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN));			memcpy( reply.hdr->a3.a1, daddr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a2, mgr->hw->addr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a3, mgr->curr_bssid, WLAN_BSSID_LEN);			/* Set up the reason */			*(reply.reason) = host2ieee16(reason);		}	}	DBFEXIT;	return pb;}/*----------------------------------------------------------------*	am930mgr_mkfrm_disassoc**	Constructs a disassoc frame using the arguments provided. Arguments*	are in host order.**	Arguments:*		daddr		destination address (6 bytes)*		reason		reason code (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error or allocation failure.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_disassoc( am930mgr_t *mgr, UINT8 *daddr, UINT16 reason){	wlan_pb_t 			*pb;	wlan_fr_disassoc_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{		am930shim_pballoc_p80211( pb, WLAN_DISASSOC_FR_MAXLEN);		if (pb->p80211hostbuf == NULL )		{			am930shim_pbfree(pb);			pb = NULL;		}		else		{			/* finish buffer setup */			pb->p80211_payloadlen += 4;  /* length fix again, see pballoc_p80211 */			/* Setup the reply structure. */			reply.buf = pb->p80211buf;			reply.len = WLAN_DISASSOC_FR_MAXLEN;			wlan_mgmt_encode_disassoc(&reply);			/* Setup the header */			reply.hdr->a3.fc = host2ieee16(				WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) | 				WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC));			memcpy( reply.hdr->a3.a1, daddr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a2, mgr->hw->addr, WLAN_ADDR_LEN);			memcpy( reply.hdr->a3.a3, mgr->curr_bssid, WLAN_BSSID_LEN);			/* Set up the reason */			*(reply.reason) = host2ieee16(reason);		}	}	DBFEXIT;	return pb;}/*----------------------------------------------------------------*	am930mgr_mkfrm_reassocresp**	Constructs a reassocresp frame using the arguments provided.  Arguments*	are in host order.**	NOTE: This is a cut-n-paste of the mkfrm_assocresp function.*			Changes made here will probably need to be made in *			assocresp as well.**	Arguments:*		daddr		destination address (6 bytes)*		status		status code (see p80211mgmt.h)*		aid			association ID (see p80211mgmt.h)*		oprates		operational rate set (as an ie) (see p80211mgmt.h)**	Returns: *		A ptr to a pb containing the frame or NULL on a severe*		argument validation error.----------------------------------------------------------------*/wlan_pb_t *am930mgr_mkfrm_reassocresp( am930mgr_t *mgr, 	UINT8 *daddr, UINT16 capinfo, UINT16 status, UINT16 aid, 	wlan_ie_supp_rates_t *rates){	wlan_pb_t 				*pb;	wlan_fr_reassocresp_t	reply;	DBFENTER;		pb = am930shim_pballoc();	if ( pb != NULL )	{

⌨️ 快捷键说明

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