private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value) { IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int)); Marshal.WriteInt32(valuePtr, value); try { Wlan.ThrowIfError( Wlan.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero)); } finally { Marshal.FreeHGlobal(valuePtr); } }
protected void Connect(Wlan.WlanConnectionParameters connectionParams) { Wlan.ThrowIfError( Wlan.WlanConnect(client.clientHandle, info.interfaceGuid, ref connectionParams, IntPtr.Zero)); }
private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode) { IntPtr valuePtr; int valueSize; Wlan.WlanOpcodeValueType opcodeValueType; Wlan.ThrowIfError( Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType)); try { return Marshal.ReadInt32(valuePtr); } finally { Wlan.WlanFreeMemory(valuePtr); } }
internal void OnWlanNotification(Wlan.WlanNotificationData notifyData) { if (WlanNotification != null) WlanNotification(notifyData); }
internal void OnWlanReason(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode) { if (WlanReasonNotification != null) WlanReasonNotification(notifyData, reasonCode); if (queueEvents) { WlanReasonNotificationData queuedEvent = new WlanReasonNotificationData(); queuedEvent.notifyData = notifyData; queuedEvent.reasonCode = reasonCode; EnqueueEvent(queuedEvent); } }
public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite) { Wlan.WlanReasonCode reasonCode; Wlan.ThrowIfError( Wlan.WlanSetProfile(client.clientHandle, info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out reasonCode)); return reasonCode; }
internal void OnWlanConnection(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData) { if (WlanConnectionNotification != null) WlanConnectionNotification(notifyData, connNotifyData); if (queueEvents) { WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData(); queuedEvent.notifyData = notifyData; queuedEvent.connNotifyData = connNotifyData; EnqueueEvent(queuedEvent); } }
public Wlan.WlanAvailableNetwork[] GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags) { IntPtr availNetListPtr; Wlan.ThrowIfError( Wlan.WlanGetAvailableNetworkList(client.clientHandle, info.interfaceGuid, flags, IntPtr.Zero, out availNetListPtr)); try { return ConvertAvailableNetworkListPtr(availNetListPtr); } finally { Wlan.WlanFreeMemory(availNetListPtr); } }
public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled) { IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid)); Marshal.StructureToPtr(ssid, ssidPtr, false); try { IntPtr bssListPtr; Wlan.ThrowIfError( Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr)); try { return ConvertBssListPtr(bssListPtr); } finally { Wlan.WlanFreeMemory(bssListPtr); } } finally { Marshal.FreeHGlobal(ssidPtr); } }
public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags) { Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters(); connectionParams.wlanConnectionMode = connectionMode; connectionParams.dot11SsidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid)); Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false); connectionParams.dot11BssType = bssType; connectionParams.flags = flags; Connect(connectionParams); Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType()); Marshal.FreeHGlobal(connectionParams.dot11SsidPtr); }
public bool ConnectSynchronously(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile, int connectTimeout) { queueEvents = true; try { Connect(connectionMode, bssType, profile); while (queueEvents && eventQueueFilled.WaitOne(connectTimeout, true)) { lock (eventQueue) { while (eventQueue.Count != 0) { object e = eventQueue.Dequeue(); if (e is WlanConnectionNotificationEventData) { WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e; if (wlanConnectionData.notifyData.notificationSource == Wlan.WlanNotificationSource.ACM) { switch ((Wlan.WlanNotificationCodeAcm)wlanConnectionData.notifyData.notificationCode) { case Wlan.WlanNotificationCodeAcm.ConnectionComplete: if (wlanConnectionData.connNotifyData.profileName == profile) return true; break; } } break; } } } } } finally { queueEvents = false; eventQueue.Clear(); } return false; }
public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile) { Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters(); connectionParams.wlanConnectionMode = connectionMode; connectionParams.profile = profile; connectionParams.dot11BssType = bssType; connectionParams.flags = 0; Connect(connectionParams); }
internal WlanInterface(WlanClient client, Wlan.WlanInterfaceInfo info) { this.client = client; this.info = info; }
private Wlan.WlanConnectionNotificationData? ParseWlanConnectionNotification(ref Wlan.WlanNotificationData notifyData) { int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanConnectionNotificationData)); if (notifyData.dataSize < expectedSize) return null; Wlan.WlanConnectionNotificationData connNotifyData = (Wlan.WlanConnectionNotificationData) Marshal.PtrToStructure(notifyData.dataPtr, typeof(Wlan.WlanConnectionNotificationData)); if (connNotifyData.wlanReasonCode == Wlan.WlanReasonCode.Success) { IntPtr profileXmlPtr = new IntPtr( notifyData.dataPtr.ToInt64() + Marshal.OffsetOf(typeof(Wlan.WlanConnectionNotificationData), "profileXml").ToInt64()); connNotifyData.profileXml = Marshal.PtrToStringUni(profileXmlPtr); } return connNotifyData; }
private void OnWlanNotification(ref Wlan.WlanNotificationData notifyData, IntPtr context) { WlanInterface wlanIface = ifaces.ContainsKey(notifyData.interfaceGuid) ? ifaces[notifyData.interfaceGuid] : null; switch(notifyData.notificationSource) { case Wlan.WlanNotificationSource.ACM: switch((Wlan.WlanNotificationCodeAcm)notifyData.notificationCode) { case Wlan.WlanNotificationCodeAcm.ConnectionStart: case Wlan.WlanNotificationCodeAcm.ConnectionComplete: case Wlan.WlanNotificationCodeAcm.ConnectionAttemptFail: case Wlan.WlanNotificationCodeAcm.Disconnecting: case Wlan.WlanNotificationCodeAcm.Disconnected: Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData); if (connNotifyData.HasValue) if (wlanIface != null) wlanIface.OnWlanConnection(notifyData, connNotifyData.Value); break; case Wlan.WlanNotificationCodeAcm.ScanFail: { int expectedSize = Marshal.SizeOf(typeof (Wlan.WlanReasonCode)); if (notifyData.dataSize >= expectedSize) { Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode) Marshal.ReadInt32(notifyData.dataPtr); if (wlanIface != null) wlanIface.OnWlanReason(notifyData, reasonCode); } } break; } break; case Wlan.WlanNotificationSource.MSM: switch((Wlan.WlanNotificationCodeMsm)notifyData.notificationCode) { case Wlan.WlanNotificationCodeMsm.Associating: case Wlan.WlanNotificationCodeMsm.Associated: case Wlan.WlanNotificationCodeMsm.Authenticating: case Wlan.WlanNotificationCodeMsm.Connected: case Wlan.WlanNotificationCodeMsm.RoamingStart: case Wlan.WlanNotificationCodeMsm.RoamingEnd: case Wlan.WlanNotificationCodeMsm.Disassociating: case Wlan.WlanNotificationCodeMsm.Disconnected: case Wlan.WlanNotificationCodeMsm.PeerJoin: case Wlan.WlanNotificationCodeMsm.PeerLeave: case Wlan.WlanNotificationCodeMsm.AdapterRemoval: Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData); if (connNotifyData.HasValue) if (wlanIface != null) wlanIface.OnWlanConnection(notifyData, connNotifyData.Value); break; } break; } if (wlanIface != null) wlanIface.OnWlanNotification(notifyData); }
public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode) { StringBuilder sb = new StringBuilder(1024); // Wlan.ThrowIfError( Wlan.WlanReasonCodeToString(reasonCode, sb.Capacity, sb, IntPtr.Zero)); return sb.ToString(); }