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

📄 wlan_wext.c

📁 marvell cf wifi driver source code CF-8385-linux-x86-5.0.4.p0-132-src.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
	wlan_private	*priv = dev->priv;
	wlan_adapter	*Adapter = priv->adapter;
	
	WLAN_802_11_NETWORK_INFRASTRUCTURE	WantedMode;

	ENTER();

#ifdef DEEP_SLEEP
#ifdef CONFIG_MARVELL_PM
	if ((Adapter->DeepSleep_State == DEEP_SLEEP_USER_ENABLED) || 
		(Adapter->DeepSleep_State == DEEP_SLEEP_OS_ENABLED)) {
#else
	if ((Adapter->IsDeepSleep == TRUE)) {
#endif
		printk("<1>SIOCSIWMODE: IOCTLS called when station is in DeepSleep\n");
		return -EBUSY;
	}
#endif

	switch (*uwrq) {
		case IW_MODE_ADHOC:
			PRINTK1("Wanted Mode is ad-hoc: current DataRate=%#x\n",Adapter->DataRate);
			WantedMode = Wlan802_11IBSS;
#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;
			break;

		case IW_MODE_INFRA:
			PRINTK1("Wanted Mode is Infrastructure\n");
			WantedMode = Wlan802_11Infrastructure;
			break;

		case IW_MODE_AUTO:
			PRINTK1("Wanted Mode is Auto\n");
			WantedMode = Wlan802_11AutoUnknown;
			break;

		default:
			PRINTK1("Wanted Mode is Unknown: 0x%x\n", *uwrq);
			return -EINVAL;
	}

	if (Adapter->InfrastructureMode == WantedMode ||
			WantedMode == Wlan802_11AutoUnknown) {
		PRINTK1("Already set to required mode! No change!\n");

		Adapter->InfrastructureMode = WantedMode;

		LEAVE();
		return 0;
	}

	if (Adapter->InfrastructureMode == Wlan802_11Infrastructure) {
#ifdef PS_REQUIRED
		if (Adapter->PSState != PS_STATE_FULL_POWER) {
			PSWakeup(priv, HostCmd_OPTION_WAITFORRSP);
		}
		Adapter->PSMode = Wlan802_11PowerModeCAM;
#endif
	}
	
	if (Adapter->MediaConnectStatus == WlanMediaStateConnected) {
		if (Adapter->InfrastructureMode == Wlan802_11Infrastructure) {
			ret = SendDeauthentication(priv, 
					HostCmd_PENDING_ON_NONE);

			if (ret) {
				LEAVE();
				return ret;
			}
		} else if (Adapter->InfrastructureMode == Wlan802_11IBSS) {
			/* If current mode is Adhoc, clean stale information */
			ret = StopAdhocNetwork(priv, HostCmd_PENDING_ON_NONE);

			if (ret) {
				LEAVE();
				return ret;
			}
		}
	} 

	if (Adapter->SecInfo.WEPStatus == Wlan802_11WEPEnabled) {
		/* If there is a key with the specified SSID, 
		 * send REMOVE WEP command, to make sure we clean up
		 * the WEP keys in firmware
		 */
		ret = PrepareAndSendCommand(priv,
			HostCmd_CMD_802_11_SET_WEP,
			0, HostCmd_OPTION_USE_INT
			| HostCmd_OPTION_WAITFORRSP
			, OID_802_11_REMOVE_WEP,
			HostCmd_PENDING_ON_CMD,
			NULL);

		if (ret) {
			LEAVE();
			return ret;
		}

		Adapter->CurrentPacketFilter &= ~HostCmd_ACT_MAC_WEP_ENABLE;

		SetMacPacketFilter(priv);
	}

	Adapter->SecInfo.WEPStatus = Wlan802_11WEPDisabled;
	Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeOpen;

	Adapter->InfrastructureMode = WantedMode;

	ret = PrepareAndSendCommand(priv,
			HostCmd_CMD_802_11_SNMP_MIB,
			0, HostCmd_OPTION_USE_INT
			| HostCmd_OPTION_WAITFORRSP
			, OID_802_11_INFRASTRUCTURE_MODE,
			HostCmd_PENDING_ON_SET_OID, NULL);

	if (ret) {
		LEAVE();
		return ret;
	}

	LEAVE();
	return 0;
}

#ifdef WPA
int wlan_set_encode_wpa(struct net_device *dev, 
			struct iw_request_info *info,
				struct iw_point *dwrq, char *extra)
{
	int			ret = 0;
	wlan_private		*priv = dev->priv;
	wlan_adapter		*Adapter = priv->adapter;
	PWLAN_802_11_KEY	pKey;

	ENTER();

#ifdef DEEP_SLEEP
#ifdef CONFIG_MARVELL_PM
	if ((Adapter->DeepSleep_State == DEEP_SLEEP_USER_ENABLED) || 
		(Adapter->DeepSleep_State == DEEP_SLEEP_OS_ENABLED)) {
#else
	if ((Adapter->IsDeepSleep == TRUE)) {
#endif
		printk("<1>():%s IOCTLS called when station is"
					" in DeepSleep\n",__FUNCTION__);
		return -EBUSY;
	}
#endif

	pKey = (PWLAN_802_11_KEY) extra;

	HEXDUMP("Key buffer: ", extra, dwrq->length);

	HEXDUMP("KeyMaterial: ", (unsigned char *) pKey->KeyMaterial,
			pKey->KeyLength);

	// current driver only supports key length of up to 32 bytes
	if (pKey->KeyLength > MRVL_MAX_WPA_KEY_LENGTH) {
		PRINTK1(" Error in key length \n");
		return -1;
	}

#ifdef WPA2
	ret = PrepareAndSendCommand(priv,
		HostCmd_CMD_802_11_KEY_MATERIAL,
		HostCmd_ACT_SET,
		HostCmd_OPTION_USE_INT
		| HostCmd_OPTION_WAITFORRSP
		, KEY_INFO_ENABLED, HostCmd_PENDING_ON_SET_OID,
		pKey);
	if (ret) {
		LEAVE();
		return ret;
	}
#else
	// check bit 30 for pairwise key, if pairwise key, store in 
	// location 0 of the key map
	if (pKey->KeyIndex & 0x40000000) {
		/*
		 * This scheduling is needed to let the 4th EAPOL
		 * packet to be sent out before setting the PTK.
		 */
		os_sched_timeout(10);

		Adapter->EncryptionStatus =
			Wlan802_11Encryption2Enabled;

		memcpy(Adapter->WpaPwkKey.KeyMaterial,
			pKey->KeyMaterial, pKey->KeyLength);

		if (pKey->KeyLength == WPA_AES_KEY_LEN) {
	
			PRINTK1("Set PWK WPA - AES Key\n");
			
			ret = PrepareAndSendCommand(priv,
				HostCmd_CMD_802_11_PWK_KEY,
				HostCmd_ACT_SET_AES,
				HostCmd_OPTION_USE_INT
				| HostCmd_OPTION_WAITFORRSP
				, 0, HostCmd_PENDING_ON_SET_OID,
				&Adapter->WpaPwkKey.KeyMaterial);

			if (ret) {
				LEAVE();
				return ret;
			}
		} 
		else if (pKey->KeyLength == WPA_TKIP_KEY_LEN) {

			PRINTK1("Set PWK WPA - TKIP Key\n");
			
			ret = PrepareAndSendCommand(priv,
					HostCmd_CMD_802_11_PWK_KEY,
					HostCmd_ACT_SET,
					HostCmd_OPTION_USE_INT
					| HostCmd_OPTION_WAITFORRSP
					, 0, HostCmd_PENDING_ON_SET_OID,
					&Adapter->WpaPwkKey.KeyMaterial);

			if (ret) {
				LEAVE();
				return ret;
			}
		}
	} else {
		PRINTK1("GROUP KEY\n");	

		Adapter->EncryptionStatus =
			Wlan802_11Encryption2Enabled;

		memcpy(Adapter->WpaGrpKey.KeyMaterial,
			pKey->KeyMaterial, pKey->KeyLength);

		if (pKey->KeyLength == WPA_AES_KEY_LEN) {
	
			PRINTK1("Set GTK WPA - AES Key\n");

			ret = PrepareAndSendCommand(priv, 
				HostCmd_CMD_802_11_GRP_KEY,
				HostCmd_ACT_SET_AES, 
				HostCmd_OPTION_USE_INT
				| HostCmd_OPTION_WAITFORRSP
				, 0, HostCmd_PENDING_ON_SET_OID,
				&Adapter->WpaGrpKey.KeyMaterial);

			if (ret) {
				LEAVE();
				return ret;
			}
		}
		else if (pKey->KeyLength == WPA_TKIP_KEY_LEN) {
	
			PRINTK1("Set GTK WPA - TKIP Key\n");

			ret = PrepareAndSendCommand(priv, 
				HostCmd_CMD_802_11_GRP_KEY,
				HostCmd_ACT_SET, 
				HostCmd_OPTION_USE_INT
				| HostCmd_OPTION_WAITFORRSP
				, 0, HostCmd_PENDING_ON_SET_OID,
				&Adapter->WpaGrpKey.KeyMaterial);

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

	LEAVE();
	return ret;
}

#endif

/*
 *  iwconfig ethX key on:	WEPEnabled;
 *  iwconfig ethX key off:	WEPDisabled;
 *  iwconfig ethX key [x]:	CurrentWepKeyIndex = x; WEPEnabled;
 *  iwconfig ethX key [x] kstr:	WepKey[x] = kstr;
 *  iwconfig ethX key kstr:	WepKey[CurrentWepKeyIndex] = kstr;
 *
 *  all:			Send command SET_WEP;
 				SetMacPacketFilter;
 */

int wlan_set_encode_nonwpa(struct net_device *dev,
			       struct iw_request_info *info,
				       struct iw_point *dwrq, char *extra)
{
	int			ret = 0;
	wlan_private		*priv = dev->priv;
	wlan_adapter		*Adapter = priv->adapter;
	MRVL_WEP_KEY		*pWep;
	WLAN_802_11_SSID	ssid;
	int			index, PrevAuthMode;

	ENTER();

	pWep = &Adapter->WepKey[Adapter->CurrentWepKeyIndex];
	PrevAuthMode = Adapter->SecInfo.AuthenticationMode;

	index = (dwrq->flags & IW_ENCODE_INDEX) - 1;

	if(index >= 4) {
		PRINTK("Key index #%d out of range.\n", index + 1);
		return -EINVAL;
	}

#ifdef DEEP_SLEEP
#ifdef CONFIG_MARVELL_PM
	if ((Adapter->DeepSleep_State == DEEP_SLEEP_USER_ENABLED) || 
		(Adapter->DeepSleep_State == DEEP_SLEEP_OS_ENABLED)) {
#else
	if ((Adapter->IsDeepSleep == TRUE)) {
#endif
		printk(KERN_ALERT "():%s IOCTLS called when station is"
					" in DeepSleep\n",__FUNCTION__);
		return -EBUSY;
	}
#endif

	PRINTK1("Flags=0x%x, Length=%d Index=%d CurrentWepKeyIndex=%d\n", 
			dwrq->flags, dwrq->length, index, Adapter->CurrentWepKeyIndex);

//	if (dwrq->flags == 0x801) /* User has to explicitely mention the
//				   * Auth mode (open/restricted)
//		dwrq->flags |= 0x2000;

	if (dwrq->length > 0) {
		/* iwconfig ethX key [n] xxxxxxxxxxx 
		 * Key has been provided by the user 
		 */

		/*
		 * Check the size of the key 
		 */

		if (dwrq->length > MAX_KEY_SIZE) {
			return -EINVAL;
		}

		/*
		 * Check the index (none -> use current) 
		 */

		if (index < 0 || index > 3)		//invalid index or no index
			index = Adapter->CurrentWepKeyIndex;
		else					//index is given & valid
			pWep = &Adapter->WepKey[index];

		/*
		 * Check if the key is not marked as invalid 
		 */
		if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
			/* Cleanup */
			memset(pWep, 0, sizeof(MRVL_WEP_KEY));

			/* Copy the key in the driver */
			memcpy(pWep->KeyMaterial, extra, dwrq->length);

			/* Set the length */
			if (dwrq->length > MIN_KEY_SIZE) {
				pWep->KeyLength = MAX_KEY_SIZE;
			} else {
				if (dwrq->length > 0) {
					pWep->KeyLength = MIN_KEY_SIZE;
				} else {
					/* Disable the key */
					pWep->KeyLength = 0;
				}
			}
			pWep->KeyIndex = index;

			if(Adapter->SecInfo.WEPStatus != Wlan802_11WEPEnabled) {
				/*
				 * The status is set as Key Absent 
				 * so as to make sure we display the 
				 * keys when iwlist ethX key is 
				 * used - MPS 
				 */

				Adapter->SecInfo.WEPStatus = 
					Wlan802_11WEPKeyAbsent;
			}

			PRINTK1("KeyIndex=%u KeyLength=%u\n", 
					pWep->KeyIndex,
					pWep->KeyLength);
			HEXDUMP("WepKey", (u8 *) pWep->KeyMaterial, 
					pWep->KeyLength);
		}
	} else {
		/*
		 * No key provided so it is either enable key, 
		 * on or off */
		if (dwrq->flags & IW_ENCODE_DISABLED) {
			PRINTK1("******** iwconfig ethX key off **********\n");

			Adapter->SecInfo.WEPStatus = Wlan802_11WEPDisabled;
			if (Adapter->SecInfo.AuthenticationMode == Wlan802_11AuthModeShared)
				Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeOpen;
		} else {
			/* iwconfig ethX key [n]
			 * iwconfig ethX key on 
			 * Do we want to just set the transmit key index ? 
			 */

			if (index < 0 || index > 3) {
				PRINTK1("******** iwconfig ethX key on **********\n");
				index = Adapter->CurrentWepKeyIndex;
			}
			else {
				PRINTK1("******** iwconfig ethX key [x=%d] **********\n",index);
				Adapter->CurrentWepKeyIndex = index;
			}

			/* Copy the required key as the current key */
			pWep = &Adapter->WepKey[index];

			if (!pWep->KeyLength) {
				PRINTK1("Key not set,so cannot enable it\n");
				return -EPERM;
			}
	    
			Adapter->SecInfo.WEPStatus = Wlan802_11WEPEnabled;

			HEXDUMP("KeyMaterial", (u8 *) pWep->KeyMaterial,
					pWep->KeyLength);
		}
	}

	if(pWep->KeyLength) {
		ret = PrepareAndSendCommand(priv,
			HostCmd_CMD_802_11_SET_WEP,
			0, HostCmd_OPTION_USE_INT
			| HostCmd_OPTION_WAITFORRSP
			, OID_802_11_ADD_WEP,
			HostCmd_PENDING_ON_SET_OID, NULL);

		if (ret) {
			LEAVE();
			return ret;
		}
	}

	if (Adapter->SecInfo.WEPStatus == Wlan802_11WEPEnabled) {
		Adapter->CurrentPacketFilter |= HostCmd_ACT_MAC_WEP_ENABLE;
	} else {
		Adapter->CurrentPacketFilter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
	}

	SetMacPacketFilter(priv);

	// PRINTK ("Flags %x\n", dwrq->flags);
	if (dwrq->flags & IW_ENCODE_RESTRICTED) {
		/* iwconfig ethX restricted key [1] */
		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeShared;
		PRINTK1("Authentication mode restricted!\n");
	} else if (dwrq->flags & IW_ENCODE_OPEN) {
		/* iwconfig ethX key [2] open */
		Adapter->SecInfo.AuthenticationMode = Wlan802_11AuthModeOpen;
		PRINTK1("Authentication mode open!\n");
	}

	/*
	 * If authentication mode changed - de-authenticate, set authentication
	 * method and re-associate if we were previously associated.
	 */
	if (Adapter->SecInfo.AuthenticationMode != PrevAuthMode) {
		if (Adapter->MediaConnectStatus == WlanMediaStateConnected &&
				Adapter->InfrastructureMode == 
				Wlan802_11Infrastructure) {

			/* keep a copy of the ssid associated with */
			memcpy(&ssid, &Adapter->CurBssParams.ssid, sizeof(ssid));

			/*
			 * De-authenticate from AP 
			 */
				
			ret = SendDeauthentication(priv, 
						HostCmd_PENDING_ON_SET_OID);

			if (ret) {
				LEAVE();
				return ret;
			}

		} else {
			/* reset ssid */
			memset(&ssid, 0, sizeof(ssid));
		}
	}

	LEAVE();
	return 0;
}

int wlan_set_encode(struct net_device *dev,
		struct iw_request_info *info,
		struct iw_point *dwrq, char *extra)
{

	PWLAN_802_11_KEY pKey = NULL;

	ENTER();
	
	if (dwrq->length > MAX_KEY_SIZE) {
		pKey = (PWLAN_802_11_KEY) extra;

		if(pKey->KeyLength <= MAX_KEY_SIZE) {
			//dynamic WEP
			dwrq->length = pKey->KeyLength;
			dwrq->flags = pKey->KeyIndex + 1;
			return wlan_set_encode_nonwpa(dev, info, dwrq, 
					pKey->KeyMaterial);
		}
		else {
#ifdef	WPA
			//WPA
			return wlan_set_encode_wpa(dev, info, dwrq, extra);
#endif
		}
	}
	else {
		//static WEP
		PRINTK1("Setting WEP\n");
		return wlan_set_encode_nonwpa(dev, info, dwrq, extra);
	}

	return -EINVAL;
}

int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
			   		struct iw_param *vwrq, char *extra)
{
	int		ret = 0;
	wlan_private *priv= dev->priv;
	wlan_adapter *Adapter= priv->adapter;

	int wlan_radio_ioctl(wlan_private *priv, u8 option);

	u16	dbm;
	
	ENTER();

#ifdef DEEP_SLEEP
#ifdef CONFIG_MARVELL_PM
	if ((Adapter->DeepSleep_State == DEEP_SLEEP_USER_ENABLED) || 
		(Adapter->DeepSleep_State == DEEP_SLEEP_OS_ENABLED)) {
#else
	if ((Adapter->IsDeepSleep == TRUE)) {

⌨️ 快捷键说明

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