Пример #1
0
		/// <summary>
		/// Sets wireless settings associated with a given 
		/// interface and AP.  This version of the method is
		/// designed for the case where *all* of the options
		/// are going to be set, where no initial configuration
		/// exists at all.
		/// </summary>
		/// <param name="SSID">Target SSID to connect</param>
		/// <param name="bInfrastructure">Is infrastructure</param>
		/// <param name="Key">binary wep key - 5 or 13 bytes</param>
		/// <param name="authMode">Authentication mode for the connection</param>
		/// <returns>true if succeeded</returns>
		public bool SetWirelessSettingsEx(string SSID, bool bInfrastructure, 
			byte[] Key, AuthenticationMode authMode)
		{
			// Unlike the other SetWirelessSettings versions,
			// we *don't* get the current configuration here;
			// our parameters will set that.
			uint			uret;
			WZC_WLAN_CONFIG thisConfig;

			thisConfig = new WZC_WLAN_CONFIG();

			// Set the length.
			thisConfig.Length = thisConfig.Data.Length;

			// Set the MAC address.
			thisConfig.MACAddr = this.MacAddress;

			// Set the SSID.
			thisConfig.SSID = SSID;

			// Proceed with configuration.
			byte [] arrKey = null;
			if ( Key != null )
			{
				arrKey = Key.Clone() as byte[];
				thisConfig.KeyLength = arrKey.Length;
				thisConfig.CtlFlags |= WZCCTL.WZCCTL_WEPK_PRESENT | WZCCTL.WZCCTL_WEPK_XFORMAT;
				if ( arrKey.Length == 10 )
					thisConfig.CtlFlags |= WZCCTL.WZCCTL_WEPK_40BLEN;
				byte[] chFakeKeyMaterial = new byte[]{0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
				for( int i = 0; i < arrKey.Length; i ++ )
					arrKey[i] ^= chFakeKeyMaterial[(7*i)%13];
				thisConfig.KeyMaterial = arrKey;
			}
			else
			{
				thisConfig.KeyLength = 0;
			}
			thisConfig.AuthenticationMode = authMode;

			// ???? do the right thing, based on the mode.

			// If we have no key, we should probably set this to WEP Off.
			thisConfig.Privacy = ( thisConfig.KeyLength > 0 )? WEPStatus.Ndis802_11WEPEnabled : WEPStatus.Ndis802_11WEPDisabled;
			thisConfig.InfrastructureMode = bInfrastructure? InfrastructureMode.Infrastructure: InfrastructureMode.AdHoc;
			byte [] FullConfig = new byte[thisConfig.Data.Length + 8 ];
			FullConfig[0] = 1; 
			thisConfig.Data.CopyTo(FullConfig, 8);
			RAW_DATA dt = new RAW_DATA(FullConfig);

			// Create the entry that will be passed to WZCSetInterface.
			INTF_ENTRY entry = new INTF_ENTRY();
			entry.Guid = this.Name;
			entry.rdStSSIDList = dt;
			uret = WZCPInvokes.WZCSetInterface(null, INTFFlags.INTF_PREFLIST, ref entry, null);
			if ( uret > 0 )
				throw new AdapterException(uret, "WZCSetInterface");
			entry.Dispose();
			return true;
		}
Пример #2
0
			WZCPassword2Key(
			WZC_WLAN_CONFIG pwzcConfig,
			string cszPassword); 
Пример #3
0
		/// <summary>
		/// Modifies wireless settings associated with a given interface and AP
		/// </summary>
		/// <param name="SSID">Target SSID to connect</param>
		/// <param name="bInfrastructure">Is infrastructure</param>
		/// <param name="Key">binary wep key - 5 or 13 bytes</param>
		/// <returns>true if succeeded</returns>
		public bool SetWirelessSettings(string SSID, bool bInfrastructure, byte[] Key)
		{
			// First, we need to get an INTF_ENTRY for this adapter.
			INTF_ENTRY entry = new INTF_ENTRY();
			entry.Guid = this.Name;
			INTFFlags dwOutFlags;
			uint uret = WZCPInvokes.WZCQueryInterface(null, 
				INTFFlags.INTF_ALL, 
				ref entry, out dwOutFlags);
			if ( uret > 0 )
			{
				// As you can see, we presently don't support
				// total configuration of the adapter with no
				// WZC intervention at all.  Somehow, you have
				// to set things up, other than SSID value, 
				// infrastructure mode, and WEP key, so that we
				// have a starting place.
				throw new AdapterException(uret, "WZCQueryInterface");
			}
			else
			{
				// Perform the 'standard' WZC stuff to set the entry's 
				// configuration.
				int cConfig = BitConverter.ToInt32( entry.rdBSSIDList.lpData, 0 );
				int Index = 8;
				WZC_WLAN_CONFIG thisConfig = null;
				for( int i = 0; i < cConfig; i ++ )
				{
					WZC_WLAN_CONFIG cfg = new WZC_WLAN_CONFIG();
					int cbCfg = BitConverter.ToInt32( entry.rdBSSIDList.lpData, Index );
					Buffer.BlockCopy(entry.rdBSSIDList.lpData, Index, cfg.Data, 0, cbCfg);
					Index += cbCfg;
					if ( cfg.SSID == SSID )
						thisConfig = cfg;
					cfg = null;
				}

				// There are a couple of things going on here:
				//	1. It might be that the user is trying to associate
				//		with an access point that we don't know about.
				//		For now, we don't allow this.
				//	2. It is also possible that the adapter is to be 
				//		placed in ad hoc mode and it just so happens that
				//		this is the first adapter to be enabled with the
				//		SSID.  We need to allow this.
				if ( ( thisConfig == null ) && ( bInfrastructure ) )
					return false;

				// If the config is null, but we are going to continue,
				// we have to create a new one and set it up for us to
				// use.
				if ( thisConfig == null )
				{
					thisConfig = new WZC_WLAN_CONFIG();

					// Set the length.
					thisConfig.Length = thisConfig.Data.Length;

					// Set the MAC address.
					thisConfig.MACAddr = this.MacAddress;

					//				thisConfig.NetworkTypeInUse = NetworkType.????;

					// Set the SSID.
					thisConfig.SSID = SSID;
				}

				// Proceed with configuration.
				byte [] arrKey = null;
				if ( Key != null )
				{
					arrKey = Key.Clone() as byte[];
					thisConfig.KeyLength = arrKey.Length;
					thisConfig.CtlFlags |= WZCCTL.WZCCTL_WEPK_PRESENT | WZCCTL.WZCCTL_WEPK_XFORMAT;
					if ( arrKey.Length == 10 )
						thisConfig.CtlFlags |= WZCCTL.WZCCTL_WEPK_40BLEN;
					byte[] chFakeKeyMaterial = new byte[]{0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
					for( int i = 0; i < arrKey.Length; i ++ )
						arrKey[i] ^= chFakeKeyMaterial[(7*i)%13];
					thisConfig.KeyMaterial = arrKey;
				}
				else
				{
					thisConfig.KeyLength = 0;
				}
				thisConfig.AuthenticationMode = AuthenticationMode.Ndis802_11AuthModeOpen;

				// If we have no key, we should probably set this to WEP Off.
				thisConfig.Privacy = ( thisConfig.KeyLength > 0 )? WEPStatus.Ndis802_11WEPEnabled : WEPStatus.Ndis802_11WEPDisabled;
				thisConfig.InfrastructureMode = bInfrastructure? InfrastructureMode.Infrastructure: InfrastructureMode.AdHoc;
				byte [] FullConfig = new byte[thisConfig.Data.Length + 8 ];
				FullConfig[0] = 1; 
				thisConfig.Data.CopyTo(FullConfig, 8);
				RAW_DATA dt = new RAW_DATA(FullConfig);
				entry.rdStSSIDList = dt;
				uret = WZCPInvokes.WZCSetInterface(null, INTFFlags.INTF_PREFLIST, ref entry, null);
				if ( uret > 0 )
					throw new AdapterException(uret, "WZCSetInterface");
				entry.Dispose();
				return true;
			}
		}