prism2mgmt.c

来自「Linux的无线局域网方案是一个Linux设备驱动程序和子系统 一揽子方案的用」· C语言 代码 · 共 2,318 行 · 第 1/5 页

C
2,318
字号
	pstr = (p80211pstrd_t*)&(msg->ssid.data);	prism2mgmt_pstr2bytestr(p2bytestr, pstr);	result = hfa384x_drvr_setconfig( hw, HFA384x_RID_CNFOWNSSID,				bytebuf, HFA384x_RID_CNFOWNSSID_LEN);	if ( result ) {		WLAN_LOG_ERROR1(__FUNCTION__			": Failed to set SSID, result=0x%04x\n", result);		goto failed;	}	/* bsstype - we use the default in the ap firmware */	/* beacon period */	word = msg->beaconperiod.data;	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set beacon period=%d.\n", word);		goto failed;	}	/* dschannel */	word = msg->dschannel.data;	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set channel=%d.\n", word);		goto failed;	}	/* Basic rates */	word = p80211rate_to_p2bit(msg->basicrate1.data);	if ( msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate2.data);	}	if ( msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate3.data);	}	if ( msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate4.data);	}	if ( msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate5.data);	}	if ( msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate6.data);	}	if ( msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate7.data);	}	if ( msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->basicrate8.data);	}	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set basicrates=%d.\n", word);		goto failed;	}	/* Operational rates (supprates and txratecontrol) */	word = p80211rate_to_p2bit(msg->operationalrate1.data);	if ( msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate2.data);	}	if ( msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate3.data);	}	if ( msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate4.data);	}	if ( msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate5.data);	}	if ( msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate6.data);	}	if ( msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate7.data);	}	if ( msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok ) {		word |= p80211rate_to_p2bit(msg->operationalrate8.data);	}	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set supprates=%d.\n", word);		goto failed;	}	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL0, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set txrates=%d.\n", word);		goto failed;	}	/* ibssatimwindow */	WLAN_LOG_INFO0("atimwindow not used in Infrastructure mode, ignored.\n");	/* DTIM period */	word = msg->dtimperiod.data;	result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNDTIMPER, &word);	if ( result ) {		WLAN_LOG_ERROR1("Failed to set dtim period=%d.\n", word);		goto failed;	}	/* probedelay */	WLAN_LOG_INFO0("prism2mgmt_start: probedelay not supported in prism2, ignored.\n");	/* cfpollable, cfpollreq, cfpperiod, cfpmaxduration */	if (msg->cfpollable.data == P80211ENUM_truth_true && 	    msg->cfpollreq.data == P80211ENUM_truth_true ) {		WLAN_LOG_ERROR0("cfpollable=cfpollreq=true is illegal.\n");		result = -1;		goto failed;	}	/* read the PCFInfo and update */	result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFAPPCFINFO, 					pcfinfo, HFA384x_RID_CNFAPPCFINFO_LEN);	if ( result ) {		WLAN_LOG_INFO0("prism2mgmt_start: read(pcfinfo) failed, "				"assume it's "				"not supported, pcf settings ignored.\n");		goto pcf_skip;	}	if ((msg->cfpollable.data == P80211ENUM_truth_false && 	     msg->cfpollreq.data == P80211ENUM_truth_false) ) {	    	pcfinfo->MediumOccupancyLimit = 0;		pcfinfo->CFPPeriod = 0;		pcfinfo->CFPMaxDuration = 0;		pcfinfo->CFPFlags &= host2hfa384x_16((UINT16)~BIT0);				if ( msg->cfpperiod.data == P80211ENUM_msgitem_status_data_ok ||		     msg->cfpmaxduration.data == P80211ENUM_msgitem_status_data_ok ) {			WLAN_LOG_WARNING0(				"Setting cfpperiod or cfpmaxduration when "				"cfpollable and cfreq are false is pointless.\n");		}	}	if ((msg->cfpollable.data == P80211ENUM_truth_true ||	     msg->cfpollreq.data == P80211ENUM_truth_true) ) {		if ( msg->cfpollable.data == P80211ENUM_truth_true) {			pcfinfo->CFPFlags |= host2hfa384x_16((UINT16)BIT0);		}		if ( msg->cfpperiod.status == P80211ENUM_msgitem_status_data_ok) {			pcfinfo->CFPPeriod = msg->cfpperiod.data;			pcfinfo->CFPPeriod = host2hfa384x_16(pcfinfo->CFPPeriod);		}		if ( msg->cfpmaxduration.status == P80211ENUM_msgitem_status_data_ok) {			pcfinfo->CFPMaxDuration = msg->cfpmaxduration.data;			pcfinfo->CFPMaxDuration = host2hfa384x_16(pcfinfo->CFPMaxDuration); 			pcfinfo->MediumOccupancyLimit = pcfinfo->CFPMaxDuration;		}	}	result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFAPPCFINFO, 					pcfinfo, HFA384x_RID_CNFAPPCFINFO_LEN);	if ( result ) {		WLAN_LOG_ERROR0("write(pcfinfo) failed.\n");		goto failed;	}pcf_skip:#if (WLAN_HOSTIF != WLAN_USB)	/* Enable the interrupts */	hfa384x_setreg(hw, 0x0, HFA384x_EVSTAT);	hfa384x_setreg(hw, 0xffff, HFA384x_EVACK);	hfa384x_setreg(hw, 		(HFA384x_INTEN_INFDROP_SET(1) |		 HFA384x_INTEN_INFO_SET(1) |		 HFA384x_INTEN_ALLOC_SET(1) |		 HFA384x_INTEN_TXEXC_SET(1) |		 HFA384x_INTEN_DTIM_SET(1) |		 HFA384x_INTEN_TX_SET(1) |		 HFA384x_INTEN_RX_SET(1)),		HFA384x_INTEN);#endif	/* Set the macmode so the frame setup code knows what to do */	if ( msg->bsstype.data == P80211ENUM_bsstype_infrastructure ) {		wlandev->macmode = WLAN_MACMODE_ESS_AP;		word=2304;  /* lets extend the data length a bit */		hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, &word);	}	/* Set the BSSID to the same as our MAC */	memcpy( wlandev->bssid, wlandev->netdev->dev_addr, WLAN_BSSID_LEN);	/* Enable the Port */	result = hfa384x_drvr_enable(hw, 0);	if ( result ) {		WLAN_LOG_ERROR1("Enable macport failed, result=%d.\n", result);		goto failed;	}		msg->resultcode.data = P80211ENUM_resultcode_success;        priv->state = WLAN_STATE_STARTED;	if (priv->log)		printk(KERN_INFO "wlan-ap: Access Point started.\n");	goto done;failed:	WLAN_LOG_DEBUG1(1, "Failed to set a config option, result=%d\n", result);	msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;done:	result = 0;	DBFEXIT;	return result;}/*----------------------------------------------------------------* prism2mgmt_enable** Start a BSS.  Any station can do this for IBSS, only AP for ESS.** Arguments:*	wlandev		wlan device structure*	msgp		ptr to msg buffer** Returns: *	0	success and done*	<0	success, but we're waiting for something to finish.*	>0	an error occurred while handling the message.* Side effects:** Call context:*	process thread  (usually)*	interrupt----------------------------------------------------------------*/int prism2mgmt_enable(wlandevice_t *wlandev, void *msgp){	int			result = 0;	prism2sta_priv_t	*priv = (prism2sta_priv_t*)wlandev->priv;	hfa384x_t		*hw = priv->hw;	p80211msg_p2req_enable_t	*msg = msgp;	DBFENTER;	if (!priv->ap) {		/*** STATION ***/		/* Ad-Hoc not quite supported on Prism2 */		msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;		msg->resultcode.data = P80211ENUM_resultcode_not_supported;		goto done;	}	/*** ACCESS POINT ***/	msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	/* Is the tertiary loaded? */	if ( priv->cap_sup_sta.id != 5) {		WLAN_LOG_ERROR0("AP driver failed to detect AP firmware.\n");		goto failed;	}#if (WLAN_HOSTIF != WLAN_USB)	/* Enable the interrupts */	hfa384x_setreg(hw, 0xffff, HFA384x_EVSTAT);	hfa384x_setreg(hw, 		(HFA384x_INTEN_INFDROP_SET(1) |		 HFA384x_INTEN_INFO_SET(1) |		 HFA384x_INTEN_ALLOC_SET(1) |		 HFA384x_INTEN_TXEXC_SET(1) |		 HFA384x_INTEN_DTIM_SET(1) |		 HFA384x_INTEN_TX_SET(1) |		 HFA384x_INTEN_RX_SET(1)),		HFA384x_INTEN);#endif	/* Set the macmode so the frame setup code knows what to do */	wlandev->macmode = WLAN_MACMODE_ESS_AP;	/* Set the BSSID to the same as our MAC */	memcpy( wlandev->bssid, wlandev->netdev->dev_addr, WLAN_BSSID_LEN);	/* Enable the Port */	result = hfa384x_drvr_enable(hw, 0);	if ( result ) {		WLAN_LOG_ERROR1("Enable macport failed, result=%d.\n", result);		goto failed;	}		msg->resultcode.data = P80211ENUM_resultcode_success;        priv->state = WLAN_STATE_STARTED;	if (priv->log)		printk(KERN_INFO "wlan-ap: Access Point started.\n");	goto done;failed:	msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters;done:	result = 0;	DBFEXIT;	return result;}/*----------------------------------------------------------------* prism2mgmt_readpda** Collect the PDA data and put it in the message.** Arguments:*	wlandev		wlan device structure*	msgp		ptr to msg buffer** Returns: *	0	success and done*	<0	success, but we're waiting for something to finish.*	>0	an error occurred while handling the message.* Side effects:** Call context:*	process thread  (usually)----------------------------------------------------------------*/int prism2mgmt_readpda(wlandevice_t *wlandev, void *msgp){	prism2sta_priv_t		*priv;	p80211msg_p2req_readpda_t	*msg = msgp;	int				result;	DBFENTER;	priv = wlandev->priv;	/* We only support collecting the PDA when in the FWLOAD	 * state.	 */	if (wlandev->msdstate != WLAN_MSD_FWLOAD) {		WLAN_LOG_ERROR0(			"PDA may only be read "			"in the fwload state.\n");		msg->resultcode.data = 			P80211ENUM_resultcode_implementation_failure;		msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	} else {		/*  Call drvr_readpda(), it handles the auxport enable		 *  and validating the returned PDA.		 */		result = hfa384x_drvr_readpda(			priv->hw, 			msg->pda.data, 			HFA384x_PDA_LEN_MAX);		if (result) {			WLAN_LOG_ERROR1(				"hfa384x_drvr_readpda() failed, "				"result=%d\n",				result);						msg->resultcode.data = 				P80211ENUM_resultcode_implementation_failure;			msg->resultcode.status = 				P80211ENUM_msgitem_status_data_ok;			DBFEXIT;			return 0;		}		msg->pda.status = P80211ENUM_msgitem_status_data_ok;		msg->resultcode.data = P80211ENUM_resultcode_success;		msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	}	DBFEXIT;	return 0;}/*----------------------------------------------------------------* prism2mgmt_readcis** Collect the CIS data and put it in the message.** Arguments:*	wlandev		wlan device structure*	msgp		ptr to msg buffer** Returns: *	0	success and done*	<0	success, but we're waiting for something to finish.*	>0	an error occurred while handling the message.* Side effects:** Call context:*	process thread  (usually)----------------------------------------------------------------*/int prism2mgmt_readcis(wlandevice_t *wlandev, void *msgp){	int			result;	prism2sta_priv_t	*priv = (prism2sta_priv_t*)wlandev->priv;	hfa384x_t		*hw = priv->hw;	p80211msg_p2req_readcis_t	*msg = msgp;	DBFENTER;        memset(msg->cis.data, 0, sizeof(msg->cis.data));	result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CIS, 					msg->cis.data, HFA384x_RID_CIS_LEN);	if ( result ) {		WLAN_LOG_INFO0("prism2mgmt_readcis: read(cis) failed.\n");		msg->cis.status = P80211ENUM_msgitem_status_no_value;		msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;				}	else {		msg->cis.status = P80211ENUM_msgitem_status_data_ok;		msg->resultcode.data = P80211ENUM_resultcode_success;		}	msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	DBFEXIT;	return 0;}/*----------------------------------------------------------------* prism2mgmt_auxport_state** Enables/Disables the card's auxiliary port.  Should be called * before and after a sequence of auxport_read()/auxport_write() * calls.** Arguments:*	wlandev		wlan device structure*	msgp		ptr to msg buffer** Returns: *	0	success and done*	<0	success, but we're waiting for something to finish.*	>0	an error occurred while handling the message.* Side effects:** Call context:*	process thread  (usually)----------------------------------------------------------------*/int prism2mgmt_auxport_state(wlandevice_t *wlandev, void *msgp){	p80211msg_p2req_auxport_state_t	*msg = msgp;#if (WLAN_HOSTIF != WLAN_USB)	prism2sta_priv_t	*priv = (prism2sta_priv_t*)wlandev->priv;	hfa384x_t		*hw = priv->hw;	DBFENTER;	msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	if (msg->enable.data == P80211ENUM_truth_true) {		if ( hfa384x_cmd_aux_enable(hw) ) {			msg->resultcode.data = P80211ENUM_resultcode_implementation_failure;		} else {			msg->resultcode.data = P80211ENUM_resultcode_success;		}	} else {		hfa384x_cmd_aux_disable(hw);		msg->resultcode.data = P80211ENUM_resultcode_success;	}#else /* !USB */	DBFENTER;	msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;	msg->resultcode.data = P80211ENUM_resultcode_not_supported;

⌨️ 快捷键说明

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