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

📄 wlan_cmd.c

📁 marvell wifi driver GSPI-8385-LINUX-OMAP1510-5.0.10.p0-144-src.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
	/*
	 * Fill in the parameters for 2 data structures:
	 * 1. HostCmd_DS_802_11_AD_HOC_START Command
	 * 2. Adapter->BSSIDList[i]
	 * Driver will fill up SSID, BSSType,IBSS param, Physical Param,
	 * probe delay, and Cap info.
	 * Firmware will fill up beacon period, DTIM, Basic rates 
	 * and operational rates. 
	 */
	for (j = 0; j < MRVDRV_MAX_SSID_LENGTH; j++) {
		if (((PWLAN_802_11_SSID) InformationBuffer)->Ssid[j] == '\0')
	break;
	}

	memset(adhs->SSID, 0, MRVDRV_MAX_SSID_LENGTH);	// with 2.0.23
							// reference 
	memcpy(adhs->SSID,((PWLAN_802_11_SSID) InformationBuffer)->Ssid,
			((PWLAN_802_11_SSID) InformationBuffer)->SsidLength);

	PRINTK1("Inside the adhoc_start command %s\n", adhs->SSID);

	memset(Adapter->BSSIDList[i].Ssid.Ssid, 0, MRVDRV_MAX_SSID_LENGTH);
	memcpy(Adapter->BSSIDList[i].Ssid.Ssid,
			((PWLAN_802_11_SSID) InformationBuffer)->Ssid,
			((PWLAN_802_11_SSID) InformationBuffer)->SsidLength);

	Adapter->BSSIDList[i].Ssid.SsidLength =
		((PWLAN_802_11_SSID) InformationBuffer)->SsidLength;

	/* Set the length of Adapter->BSSIDList[i] */
	Adapter->BSSIDList[i].Length = sizeof(WLAN_802_11_BSSID);
	/* set the length of configuration in Adapter->BSSIDList[i] */
	Adapter->BSSIDList[i].Configuration.Length =
		sizeof(WLAN_802_11_CONFIGURATION);

	/* set the BSS type */
	adhs->BSSType = HostCmd_BSS_TYPE_IBSS;
	Adapter->BSSIDList[i].InfrastructureMode = Wlan802_11IBSS;

	/* set Physical param set */
	adhs->PhyParamSet.DsParamSet.ElementId = 3;
	adhs->PhyParamSet.DsParamSet.Len = 1;

	if (Adapter->AdhocChannel == 0) {
#ifdef MULTI_BANDS
		if (Adapter->adhoc_start_band == BAND_A) 
			Adapter->AdhocChannel = DEFAULT_AD_HOC_CHANNEL_A;
		else
#endif
			Adapter->AdhocChannel = DEFAULT_AD_HOC_CHANNEL;
	}

	PRINTK1("Creating ADHOC on Channel %d\n", Adapter->AdhocChannel);

	Adapter->CurBssParams.channel = Adapter->AdhocChannel;
#ifdef MULTI_BANDS
	Adapter->CurBssParams.band = Adapter->adhoc_start_band;
#endif

	Adapter->BSSIDList[i].Channel = Adapter->AdhocChannel;
	adhs->PhyParamSet.DsParamSet.CurrentChan = Adapter->AdhocChannel;

	memcpy(&Adapter->BSSIDList[i].PhyParamSet,
			&adhs->PhyParamSet, sizeof(IEEEtypes_PhyParamSet_t));

	Adapter->BSSIDList[i].NetworkTypeInUse = Wlan802_11DS;
	Adapter->BSSIDList[i].Configuration.DSConfig =
	DSFreqList[adhs->PhyParamSet.DsParamSet.CurrentChan];

	/* set IBSS param set */
	adhs->SsParamSet.IbssParamSet.ElementId = 6;
	adhs->SsParamSet.IbssParamSet.Len = 2;
	adhs->SsParamSet.IbssParamSet.AtimWindow = Adapter->AtimWindow;
	memcpy(&Adapter->BSSIDList[i].SsParamSet,
			&(adhs->SsParamSet), sizeof(IEEEtypes_SsParamSet_t));

	/* set Capability info */
	adhs->Cap.Ess = 0;
	adhs->Cap.Ibss = 1;
	Adapter->BSSIDList[i].Cap.Ibss = 1;
#ifdef ENABLE_802_11H_TPC
	if (Adapter->State11HTPC.Enable11HTPC==TRUE )
		adhs->Cap.SpectrumMgmt = 1;
	PRINTK2("11HTPC: Start AD-HOC Cap=%x len=%d\n", *(unsigned int*)&(adhs->Cap), sizeof(adhs->Cap) );
#endif

	/* ProbeDelay */
	adhs->ProbeDelay = wlan_cpu_to_le16(HostCmd_SCAN_PROBE_DELAY_TIME);

	/* set up privacy in Adapter->BSSIDList[i] */
	if (Adapter->SecInfo.WEPStatus == Wlan802_11WEPEnabled
#ifdef ADHOCAES
		|| Adapter->AdhocAESEnabled
#endif
		) {
		PRINTK1("WEPStatus set, BSSIDList[i].Privacy to WEP\n");
		Adapter->BSSIDList[i].Privacy = Wlan802_11PrivFilter8021xWEP;
		adhs->Cap.Privacy = 1;
	} else {
		PRINTK1("WEPStatus NOTSET, Setting"
				"BSSIDList[i].Privacy to ACCEPT ALL\n");
		Adapter->BSSIDList[i].Privacy = Wlan802_11PrivFilterAcceptAll;
	}

	memcpy(&TmpCap, &adhs->Cap, sizeof(u16));
	TmpCap = wlan_cpu_to_le16(TmpCap);
	memcpy(&adhs->Cap, &TmpCap, sizeof(u16));
	
	/* Get ready to start an ad hoc network */
	Adapter->bIsAssociationInProgress = TRUE;

	/* need to report disconnect event if currently associated */
	if (Adapter->CurBssParams.ssid.SsidLength != 0) {
		MacEventDisconnected(priv);
	}
		
	memset(adhs->DataRate, 0, sizeof(adhs->DataRate));
#ifdef	MULTI_BANDS
	if (Adapter->adhoc_start_band & BAND_A) 
		memcpy(adhs->DataRate, AdhocRates_A, 
				MIN(sizeof(adhs->DataRate),
				sizeof(AdhocRates_A)));
	else if (Adapter->adhoc_start_band & BAND_B) 
		memcpy(adhs->DataRate, AdhocRates_B, 
				MIN(sizeof(adhs->DataRate),
				sizeof(AdhocRates_B)));
	else if (Adapter->adhoc_start_band & BAND_G) 
		memcpy(adhs->DataRate, AdhocRates_G, 
				MIN(sizeof(adhs->DataRate),
				sizeof(AdhocRates_G)));
#else 
#ifdef ADHOC_GRATE
	if (Adapter->adhoc_grate_enabled == TRUE)
		memcpy(adhs->DataRate, AdhocRates_G, MIN(sizeof(adhs->DataRate),
							sizeof(AdhocRates_G)));
	else
		memcpy(adhs->DataRate, AdhocRates_B, MIN(sizeof(adhs->DataRate),
							sizeof(AdhocRates_B)));
#else
	memcpy(adhs->DataRate, AdhocRates_B, MIN(sizeof(adhs->DataRate),
							sizeof(AdhocRates_B)));
#endif /* ADHOC_GRATE */
#endif

	for (i=0; i < sizeof(adhs->DataRate) && adhs->DataRate[i]; i++) {
	}
	Adapter->CurBssParams.NumOfRates = i;

	/* Copy the ad-hoc creating rates into Current BSS state structure */
	memcpy(&Adapter->CurBssParams.DataRates, &adhs->DataRate, 
		Adapter->CurBssParams.NumOfRates);

	PRINTK("Rates=%02x %02x %02x %02x \n", 
			adhs->DataRate[0], adhs->DataRate[1],
			adhs->DataRate[2], adhs->DataRate[3]);

	PRINTK1("HWAC - AD HOC Start command is ready\n");

#ifdef MULTI_BANDS
	if (Adapter->is_multiband) {
		bc.BandSelection = Adapter->CurBssParams.band;
		bc.Channel = Adapter->CurBssParams.channel;

		ret = PrepareAndSendCommand(priv,
			HostCmd_CMD_802_11_BAND_CONFIG,
			HostCmd_ACT_SET, HostCmd_OPTION_USE_INT 
			| HostCmd_OPTION_WAITFORRSP
			, 0, HostCmd_PENDING_ON_NONE, &bc);

		if (ret) {
			LEAVE();
			return ret;
		}
	}
#endif /* MULTI_BANDS */

#ifdef ENABLE_802_11D
	ret = wlan_create_dnld_countryinfo_11d( priv );
	if ( ret ) {
		LEAVE();
		return ret;
	}
#endif

#ifdef ENABLE_802_11H_TPC
	/*Before Start Ad-hoc, set power cap and constraint first*/

	PRINTK2("11HTPC:Enable11H=%s\n", 
		(Adapter->State11HTPC.Enable11HTPC==TRUE)?"TRUE":"FALSE");

	if (Adapter->State11HTPC.Enable11HTPC==TRUE ) {
		Adapter->State11HTPC.InfoTpc.Chan = Adapter->AdhocChannel;
		Adapter->State11HTPC.InfoTpc.PowerConstraint = 
				Adapter->State11HTPC.UsrDefPowerConstraint;
		ret = PrepareAndSendCommand(priv,
			HostCmd_CMD_802_11H_TPC_INFO,
			HostCmd_ACT_SET, HostCmd_OPTION_USE_INT,
			0, HostCmd_PENDING_ON_NONE, NULL);
		if (ret) {
			PRINTK2("Err: Send TPC_INFO CMD: %d\n", ret);
			LEAVE();
			return ret;
		}
	}
#endif

	return ret;
}

static inline int wlan_cmd_802_11_ad_hoc_stop(wlan_private * priv, 
		HostCmd_DS_COMMAND * cmd)
{
	cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
	cmd->Size = wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_AD_HOC_STOP) + S_DS_GEN);

	return 0;
}

static inline int wlan_cmd_802_11_ad_hoc_join(wlan_private * priv,
			    CmdCtrlNode * cmdnode, void *InformationBuffer)
{
	int				ret = 0;

	HostCmd_DS_COMMAND 		*cmd =
		(HostCmd_DS_COMMAND *) cmdnode->BufVirtualAddr;

	HostCmd_DS_802_11_AD_HOC_JOIN 	*pAdHocJoin = &cmd->params.adj;
	wlan_adapter   			*Adapter = priv->adapter;
	int             		i;
	u8				*pReqBSSID = NULL;
	u8				*card_rates;
	int				card_rates_size;
	u16				TmpCap;
#ifdef MULTI_BANDS
	HostCmd_DS_802_11_BAND_CONFIG bc;
#endif /* MULTI BANDS*/
	int				index;

	ENTER();

	cmd->Command = wlan_cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN);
	cmd->Size = wlan_cpu_to_le16(sizeof(HostCmd_DS_802_11_AD_HOC_JOIN) + S_DS_GEN);

	if (Adapter->RequestViaBSSID)
		pReqBSSID = Adapter->RequestedBSSID;
    
	/* find out the BSSID that matches 
	 * the SSID given in InformationBuffer 
	 */
	for (i = 0; i < Adapter->ulNumOfBSSIDs; i++) {
		/* if found a match on SSID, get the MAC address(BSSID) */
		if (!SSIDcmp(&Adapter->BSSIDList[i].Ssid,
					(PWLAN_802_11_SSID)InformationBuffer)) {
			if (!pReqBSSID || !memcmp(Adapter->BSSIDList[i].
						MacAddress, pReqBSSID, 
						ETH_ALEN)) {
				if (Adapter->BSSIDList[i].InfrastructureMode !=
						Wlan802_11Infrastructure) {
					break;
				}
			}
		}
	}

	/* check if the matching SSID is found, if not, return */
	if (i == Adapter->ulNumOfBSSIDs) {
		return WLAN_STATUS_FAILURE;
	}
	
	PRINTK1("***Adapter ssid =%s\n", Adapter->CurBssParams.ssid.Ssid);
	PRINTK1("***Adapter Length =%u\n", 
					Adapter->CurBssParams.ssid.SsidLength);
	PRINTK1("***Info Buffer ssid =%s\n",
			((PWLAN_802_11_SSID) InformationBuffer)->Ssid);
	PRINTK1("**Info buffer Length =%u\n",
			((PWLAN_802_11_SSID) InformationBuffer)->SsidLength);

	/* check if the requested SSID is already joined */
	if (Adapter->CurBssParams.ssid.SsidLength &&
        !SSIDcmp((PWLAN_802_11_SSID)InformationBuffer,
                 &Adapter->CurBssParams.ssid)) 
	{
		if (Adapter->CurrentBSSIDDescriptor.InfrastructureMode ==
			Wlan802_11IBSS) {
			PRINTK1("New ad-hoc SSID is the same as current, "
					"not attempting to re-join");
            
			/*
			 * should return WLAN_STATUS_NOT_ACCEPTED in any case,
			 * not just for WHQL_FIX
			 * return WLAN_STATUS_SUCCESS;
			 * scan expects the result to be true always!!
			 * Changed to fix the issue of zero size command 
			 * being sent to pendingQ. 
			 * It would stuck there if issue the same essid to
			 * driver after it has joined already.  
			 */
			return WLAN_STATUS_NOT_ACCEPTED;
		}
	}
	/* Set the temporary BSSID Index */
	Adapter->ulAttemptedBSSIDIndex = index = i;

	pAdHocJoin->BssDescriptor.BSSType = HostCmd_BSS_TYPE_IBSS;

	pAdHocJoin->BssDescriptor.BeaconPeriod = 
		Adapter->BSSIDList[index].Configuration.BeaconPeriod;

	memcpy(&pAdHocJoin->BssDescriptor.BSSID,
           &Adapter->BSSIDList[index].MacAddress,
           MRVDRV_ETH_ADDR_LEN);

	memcpy(&pAdHocJoin->BssDescriptor.SSID,
           &Adapter->BSSIDList[index].Ssid.Ssid,
           Adapter->BSSIDList[index].Ssid.SsidLength);
    
	memcpy(&pAdHocJoin->BssDescriptor.PhyParamSet, 
           &Adapter->BSSIDList[index].PhyParamSet,
           sizeof(IEEEtypes_PhyParamSet_t));
    
	memcpy(&pAdHocJoin->BssDescriptor.SsParamSet,
           &Adapter->BSSIDList[index].SsParamSet,
					sizeof(IEEEtypes_SsParamSet_t));

	memcpy(&TmpCap, &Adapter->BSSIDList[index].Cap,
					sizeof(IEEEtypes_CapInfo_t));
	TmpCap &= CAPINFO_MASK;
	PRINTK("TmpCap=%4X CAPINFO_MASK=%4X\n", TmpCap, CAPINFO_MASK);
	memcpy(&pAdHocJoin->BssDescriptor.Cap, &TmpCap,
					sizeof(IEEEtypes_CapInfo_t));


	/* information on BSSID descriptor passed to FW */
	PRINTK1("Adhoc Join - BSSID = %2x-%2x-%2x-%2x-%2x-%2x, SSID = %s\n",
			pAdHocJoin->BssDescriptor.BSSID[0],
			pAdHocJoin->BssDescriptor.BSSID[1],
			pAdHocJoin->BssDescriptor.BSSID[2],
			pAdHocJoin->BssDescriptor.BSSID[3],
			pAdHocJoin->BssDescriptor.BSSID[4],
			pAdHocJoin->BssDescriptor.BSSID[5],
			pAdHocJoin->BssDescriptor.SSID);

	PRINTK1("Data Rate = %x\n", (u32) pAdHocJoin->BssDescriptor.DataRates);

	/* FailTimeOut */
	pAdHocJoin->FailTimeOut = wlan_cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);

	/* ProbeDelay */
	pAdHocJoin->ProbeDelay = wlan_cpu_to_le16(HostCmd_SCAN_PROBE_DELAY_TIME);

	/* Copy Data Rates from the Rates recorded in scan response */
	memset(pAdHocJoin->BssDescriptor.DataRates, 0, 
           sizeof(pAdHocJoin->BssDescriptor.DataRates));
	memcpy(pAdHocJoin->BssDescriptor.DataRates, 
           Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].DataRates, 
           MIN(sizeof(pAdHocJoin->BssDescriptor.DataRates),
               sizeof(Adapter->BSSIDList[Adapter
                                         ->ulAttemptedBSSIDIndex].DataRates)));

#ifdef	MULTI_BANDS
	if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band == BAND_A) {
		card_rates = SupportedRates_A;
		card_rates_size = sizeof(SupportedRates_A);
	}
	else if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band == BAND_B) {
		card_rates = SupportedRates_B;
		card_rates_size = sizeof(SupportedRates_B);
	}
	else if (Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band == BAND_G) {
		card_rates = SupportedRates_G;
		card_rates_size = sizeof(SupportedRates_G);
	}
	else {
		return -EINVAL;
	}
#else
	card_rates = SupportedRates;
	card_rates_size = sizeof(SupportedRates);
#endif	/* MULTI_BANDS*/

	Adapter->CurBssParams.channel = 
		Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].Channel;
#ifdef	MULTI_BANDS
	Adapter->CurBssParams.band = 
		Adapter->BSSIDList[Adapter->ulAttemptedBSSIDIndex].bss_band;
#endif	/* MULTI_BANDS*/

	if (get_common_rates(Adapter, pAdHocJoin->BssDescriptor.DataRates, 
                         sizeof(pAdHocJoin->BssDescriptor.DataRates),
                         card_rates, card_rates_size)) {
		return -EINVAL;
	}

	for (i=0; i < sizeof(pAdHocJoin->BssDescriptor.DataRates) 
		&& pAdHocJoin->BssDescriptor.DataRates[i]; i++) {
	}
	Adapter->CurBssParams.NumOfRates = i;

	/* 
	** Copy the adhoc joining rates to Current BSS State structure 
	*/
	memcpy(Adapter->CurBssParams.DataRates, 
		pAdHocJoin->BssDescriptor.DataRates,
		Adapter->CurBssParams.NumOfRates);

	/* Get ready to join */
	Adapter->bIsAssociationInProgress = TRUE;

	pAdHocJoin->BssDescriptor.SsParamSet.IbssParamSet.AtimWindow =
	wlan_cpu_to_le16(Adapter->BSSIDList[index].Configuration.ATIMWindow);

	if (Adapter->SecInfo.WEPStatus == Wlan802_11WEPEnabled
#ifdef ADHOCAES
		|| Adapter->AdhocAESEnabled
#endif
		) {
		pAdHocJoin->BssDescriptor.Cap.Privacy =  1;
	}

	memcpy(&TmpCap, &pAdHocJoin->BssDescriptor.Cap, sizeof(IEEEtypes_CapInfo_t));

	TmpCap = wlan_cpu_to_le16(TmpCap);

	memcpy(&pAdHocJoin->BssDescriptor.Cap, &TmpCap, sizeof(IEEEtypes_CapInfo_t));

	/* need to report disconnect event if currently associated */
	if (Adapter->CurBssParams.ssid.SsidLength != 0) {
		MacEventDisconnected(priv);
	}
#ifdef PS_REQUIRED
	/*
	 * Note that firmware does not go back to power save 
	 * after association for ad hoc mode
	 */
	if (Adapter->PSMode == Wlan802_11PowerModeMAX_PSP) {
		/* wake up first */
		WLAN_802_11_POWER_MODE LocalPSMode;

		LocalPSMode = Wlan802_11PowerModeCAM;

⌨️ 快捷键说明

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