From: <off...@us...> - 2011-11-06 13:41:54
|
Revision: 4325 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4325&view=rev Author: offbyonebb Date: 2011-11-06 13:41:46 +0000 (Sun, 06 Nov 2011) Log Message: ----------- added WiFiManager plugin (C# code, DefaultWide skin, MPEI installer script) Added Paths: ----------- trunk/plugins/WiFiManager/ trunk/plugins/WiFiManager/Installer/ trunk/plugins/WiFiManager/Installer/WifiManager.xmp2 trunk/plugins/WiFiManager/Skins/ trunk/plugins/WiFiManager/Skins/DefaultWide/ trunk/plugins/WiFiManager/Skins/DefaultWide/Media/ trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/ trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/Secure.png trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/WiFi.png trunk/plugins/WiFiManager/Skins/DefaultWide/Media/hover_WifiManager.png trunk/plugins/WiFiManager/Skins/DefaultWide/WifiManager.xml trunk/plugins/WiFiManager/WiFiManager/ trunk/plugins/WiFiManager/WiFiManager/GuiWifiManager.cs trunk/plugins/WiFiManager/WiFiManager/NativeWifi/ trunk/plugins/WiFiManager/WiFiManager/NativeWifi/Interop.cs trunk/plugins/WiFiManager/WiFiManager/NativeWifi/WlanApi.cs trunk/plugins/WiFiManager/WiFiManager/Properties/ trunk/plugins/WiFiManager/WiFiManager/Properties/AssemblyInfo.cs trunk/plugins/WiFiManager/WiFiManager/WiFiManager.csproj trunk/plugins/WiFiManager/WiFiManager/WiFiManager.png trunk/plugins/WiFiManager/WiFiManager/WiFiManagerDisabled.png trunk/plugins/WiFiManager/WiFiManager.sln Added: trunk/plugins/WiFiManager/Installer/WifiManager.xmp2 =================================================================== --- trunk/plugins/WiFiManager/Installer/WifiManager.xmp2 (rev 0) +++ trunk/plugins/WiFiManager/Installer/WifiManager.xmp2 2011-11-06 13:41:46 UTC (rev 4325) @@ -0,0 +1,320 @@ +<?xml version="1.0" encoding="utf-8"?> +<PackageClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <Version>2.0</Version> + <Groups> + <Items> + <GroupItem Name="Default"> + <ParentGroup /> + <DisplayName>Default</DisplayName> + <DefaulChecked>true</DefaulChecked> + <Description>Default</Description> + <Files> + <Items> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\..\..\..\..\..\..\Program Files (x86)\Team MediaPortal\MediaPortal\plugins\Windows\WiFiManager.dll</LocalFileName> + <ZipFileName>Installer{CopyFile}\{aab3d026-d2e8-4f15-8480-3b70f83f3691}-WiFiManager.dll</ZipFileName> + <DestinationFilename>%Plugins%\Windows\WiFiManager.dll</DestinationFilename> + </FileItem> + </Items> + </Files> + </GroupItem> + <GroupItem Name="DefaultWide"> + <DisplayName>DefaultWide</DisplayName> + <DefaulChecked>true</DefaulChecked> + <Description>DefaultWide</Description> + <Files> + <Items> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\WifiManager.xml</LocalFileName> + <ZipFileName>Installer{CopyFile}\{944d093b-3705-4475-861f-990902757585}-WifiManager.xml</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\WifiManager.xml</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\hover_WifiManager.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{04f2f181-b6ab-40f7-b1fc-c750ad55f179}-hover_WifiManager.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\hover_WifiManager.png</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\WifiManager\Secure.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{4c2639f2-c49d-4282-ae9f-efec23cd8590}-Secure.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\WifiManager\Secure.png</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\WifiManager\WiFi.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{f1ca47e1-c17f-4dea-8ec9-593b889b2b66}-WiFi.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\WifiManager\WiFi.png</DestinationFilename> + </FileItem> + </Items> + </Files> + </GroupItem> + </Items> + </Groups> + <Sections> + <Items> + <SectionItem Guid="69d915bb-c231-409b-bd58-dafd64a2e470" Name="Welcome Screen" ConditionGroup=""> + <Params> + <Items> + <SectionParam Name="Header text"> + <Value>Welcome to the Extension Installer for [Name]</Value> + <ValueType>String</ValueType> + <Description /> + </SectionParam> + <SectionParam Name="Description"> + <Value>This will install [Name] version [Version] on your computer. +It is recommended that you close all other applications before continuing. +Click Next to continue or Cancel to exit Setup.</Value> + <ValueType>String</ValueType> + <Description /> + </SectionParam> + <SectionParam Name="Left part image"> + <Value /> + <ValueType>File</ValueType> + <Description /> + </SectionParam> + <SectionParam Name="Header image"> + <Value /> + <ValueType>File</ValueType> + <Description>Image in upper right part</Description> + </SectionParam> + </Items> + </Params> + <Actions> + <Items /> + </Actions> + <IncludedGroups /> + <PanelName>Welcome Screen</PanelName> + <WizardButtonsEnum>NextCancel</WizardButtonsEnum> + </SectionItem> + <SectionItem Guid="a29114e3-8300-476d-8271-fe07bb3c58e2" Name="Install Section" ConditionGroup=""> + <Params> + <Items> + <SectionParam Name="Header Title"> + <Value /> + <ValueType>String</ValueType> + <Description>Header title</Description> + </SectionParam> + <SectionParam Name="Header description"> + <Value /> + <ValueType>String</ValueType> + <Description>Description of section, shown in under section title</Description> + </SectionParam> + <SectionParam Name="Header image"> + <Value /> + <ValueType>File</ValueType> + <Description>Image in upper right part</Description> + </SectionParam> + </Items> + </Params> + <Actions> + <Items> + <ActionItem Name="InstallFiles" ActionType="InstallFiles" ConditionGroup=""> + <Params> + <Items /> + </Params> + <ExecuteLocation>AfterPanelShow</ExecuteLocation> + </ActionItem> + </Items> + </Actions> + <IncludedGroups /> + <PanelName>Install Section</PanelName> + <WizardButtonsEnum>Next</WizardButtonsEnum> + </SectionItem> + <SectionItem Guid="645d811e-4b75-4ed8-a3ce-06bfe821f676" Name="Setup Complete" ConditionGroup=""> + <Params> + <Items> + <SectionParam Name="Header text"> + <Value>The Extension Installer Wizard has successfully installed [Name].</Value> + <ValueType>String</ValueType> + <Description /> + </SectionParam> + <SectionParam Name="Left part image"> + <Value /> + <ValueType>File</ValueType> + <Description /> + </SectionParam> + <SectionParam Name="Show radio buttons"> + <Value /> + <ValueType>Bool</ValueType> + <Description>Use radiobutton in place of combobox</Description> + </SectionParam> + <SectionParam Name="Header image"> + <Value /> + <ValueType>File</ValueType> + <Description>Image in upper right part</Description> + </SectionParam> + </Items> + </Params> + <Actions> + <Items /> + </Actions> + <IncludedGroups /> + <PanelName>Setup Complete</PanelName> + <WizardButtonsEnum>Finish</WizardButtonsEnum> + </SectionItem> + </Items> + </Sections> + <Dependencies> + <Items> + <DependencyItem> + <Type>MediaPortal</Type> + <Id /> + <MinVersion> + <Major>1</Major> + <Minor>1</Minor> + <Build>6</Build> + <Revision>27644</Revision> + </MinVersion> + <MaxVersion> + <Major>1</Major> + <Minor>1</Minor> + <Build>6</Build> + <Revision>27644</Revision> + </MaxVersion> + <WarnOnly>false</WarnOnly> + <Message>requires MediaPortal version 1.1.6.27644 to 1.1.6.27644.</Message> + <Name>MediaPortal</Name> + </DependencyItem> + </Items> + </Dependencies> + <PluginDependencies> + <Items> + <PluginDependencyItem AssemblyName="WiFiManager.dll"> + <CompatibleVersion> + <Items> + <CompatibleVersionItem> + <MinRequiredVersion>1.1.6.27644</MinRequiredVersion> + <DesignedForVersion>1.1.6.27644</DesignedForVersion> + </CompatibleVersionItem> + </Items> + </CompatibleVersion> + <SubSystemsUsed> + <Items> + <SubSystemItem Name="MP.Input" /> + <SubSystemItem Name="MP.SkinEngine" /> + <SubSystemItem Name="MP.Config" /> + </Items> + </SubSystemsUsed> + </PluginDependencyItem> + </Items> + </PluginDependencies> + <GeneralInfo> + <Name>WifiManager</Name> + <Id>dbd7af5e-8b89-420d-b8b4-a935fa9282c2</Id> + <Author>offbyone</Author> + <HomePage /> + <ForumPage /> + <UpdateUrl /> + <Version> + <Major>1</Major> + <Minor>0</Minor> + <Build>0</Build> + <Revision>0</Revision> + </Version> + <ExtensionDescription>This plugin displays a list of available wireless networks if you have a WiFi adapter installed on your machine and allows connecting or disconnecting without the need to go to your Windows Desktop.</ExtensionDescription> + <VersionDescription /> + <DevelopmentStatus>Beta</DevelopmentStatus> + <OnlineLocation /> + <ReleaseDate>2011-10-03T21:30:37.6965017+02:00</ReleaseDate> + <Tags>settings, wlan, wifi</Tags> + <Location>C:\Users\offbyone\Documents\Code\CodeUnlimited\WiFiManager\Installers\WifiManager.mpe1</Location> + <Params> + <Items> + <SectionParam Name="Icon"> + <Value>..\Skins\DefaultWide\Media\hover_WifiManager.png</Value> + <ValueType>File</ValueType> + <Description>The icon file of the package (jpg,png,bmp)</Description> + </SectionParam> + <SectionParam Name="Online Icon"> + <Value /> + <ValueType>String</ValueType> + <Description>The icon file of the package stored online (jpg,png,bmp)</Description> + </SectionParam> + <SectionParam Name="Configuration file"> + <Value /> + <ValueType>Template</ValueType> + <Description>The file used to configure the extension. + If have .exe extension the will be executed + If have .dll extension used like MP plugin configuration</Description> + </SectionParam> + <SectionParam Name="Online Screenshots"> + <Value /> + <ValueType>String</ValueType> + <Description>Online stored screenshot urls separated by ; </Description> + </SectionParam> + <SectionParam Name="Force to uninstall on update"> + <Value>yes</Value> + <ValueType>Bool</ValueType> + <Description>Show dialog and force to uninstall previous version when updating an extension. Should only be disabled if you are using an NSIS/MSI installer.</Description> + </SectionParam> + </Items> + </Params> + </GeneralInfo> + <UniqueFileList> + <Items> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="true"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\..\..\..\..\..\..\Program Files (x86)\Team MediaPortal\MediaPortal\plugins\Windows\WiFiManager.dll</LocalFileName> + <ZipFileName>Installer{CopyFile}\{aab3d026-d2e8-4f15-8480-3b70f83f3691}-WiFiManager.dll</ZipFileName> + <DestinationFilename>%Plugins%\Windows\WiFiManager.dll</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\WifiManager.xml</LocalFileName> + <ZipFileName>Installer{CopyFile}\{944d093b-3705-4475-861f-990902757585}-WifiManager.xml</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\WifiManager.xml</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="true" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\hover_WifiManager.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{04f2f181-b6ab-40f7-b1fc-c750ad55f179}-hover_WifiManager.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\hover_WifiManager.png</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\WifiManager\Secure.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{4c2639f2-c49d-4282-ae9f-efec23cd8590}-Secure.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\WifiManager\Secure.png</DestinationFilename> + </FileItem> + <FileItem InstallType="CopyFile" SystemFile="false" Modified="false"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName>..\Skins\DefaultWide\Media\WifiManager\WiFi.png</LocalFileName> + <ZipFileName>Installer{CopyFile}\{f1ca47e1-c17f-4dea-8ec9-593b889b2b66}-WiFi.png</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\Media\WifiManager\WiFi.png</DestinationFilename> + </FileItem> + </Items> + </UniqueFileList> + <ProjectSettings> + <FolderGroups> + <FolderGroup InstallType="CopyFile" SystemFile="false" Modified="true"> + <Param1 /> + <UpdateOption>OverwriteIfOlder</UpdateOption> + <LocalFileName /> + <ZipFileName>Installer{CopyFile}\{cabbe550-cd32-474d-8a9b-8024dcda05c9}-</ZipFileName> + <DestinationFilename>%Skin%\DefaultWide\</DestinationFilename> + <Folder>..\Skins\DefaultWide</Folder> + <Group>DefaultWide</Group> + <Recursive>true</Recursive> + </FolderGroup> + </FolderGroups> + <ProjectFilename>WifiManager.xmp2</ProjectFilename> + <UpdatePath1 /> + <UpdatePath2 /> + <UpdatePath3 /> + </ProjectSettings> + <IsSkin>false</IsSkin> +</PackageClass> \ No newline at end of file Added: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/Secure.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/Secure.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/WiFi.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/WifiManager/WiFi.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/hover_WifiManager.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/WiFiManager/Skins/DefaultWide/Media/hover_WifiManager.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WiFiManager/Skins/DefaultWide/WifiManager.xml =================================================================== --- trunk/plugins/WiFiManager/Skins/DefaultWide/WifiManager.xml (rev 0) +++ trunk/plugins/WiFiManager/Skins/DefaultWide/WifiManager.xml 2011-11-06 13:41:46 UTC (rev 4325) @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<window> + <id>4855</id> + <defaultcontrol>50</defaultcontrol> + <allowoverlay>yes</allowoverlay> + <controls> + <control> + <description>background image</description> + <type>image</type> + <id>1</id> + <width>1280</width> + <height>720</height> + </control> + <import>common.window.xml</import> + <import>common.time.xml</import> + <control> + <type>label</type> + <id>1</id> + <posX>60</posX> + <posY>27</posY> + <label>#currentmodule</label> + <font>font16</font> + <align>left</align> + <textcolor>White</textcolor> + </control> + <control> + <type>actiongroup</type> + <description>action menu</description> + <defaultcontrol>2</defaultcontrol> + <onexit>50</onexit> + <buttonX>0</buttonX> + <buttonY>0</buttonY> + <buttonwidth>106</buttonwidth> + <buttonheight>720</buttonheight> + <textureFocus>-</textureFocus> + <textureNoFocus>Action_nofocus.png</textureNoFocus> + <width>275</width> + <height>900</height> + <dimColor>00ffffff</dimColor> + <control> + <type>image</type> + <posX>26</posX> + <posY>78</posY> + <width>367</width> + <height>591</height> + <texture>Backslide.png</texture> + <colorDiffuse>fffffffff</colorDiffuse> + <visible>!Control.HasFocus(50)</visible> + <animation effect="slide" time="70" start="-300,0" reversible="false">visible</animation> + <animation effect="slide" time="70" end="-300,0" reversible="false">hidden</animation> + </control> + <control> + <description>button group</description> + <type>group</type> + <animation effect="slide" time="70" start="-300,0" reversible="false">visible</animation> + <animation effect="slide" time="70" end="-300,0" reversible="false">hidden</animation> + <posX>71</posX> + <posY>121</posY> + <layout>StackLayout</layout> + <visible>!Control.HasFocus(50)</visible> + <control> + <description>Scan button</description> + <type>button</type> + <id>2</id> + <label>Scan</label> + <onright>50</onright> + </control> + <control> + <description>Refresh button</description> + <type>button</type> + <id>3</id> + <label>Refresh List</label> + <onright>50</onright> + </control> + </control> + </control> + <import>common.facade.xml</import> + </controls> +</window> Added: trunk/plugins/WiFiManager/WiFiManager/GuiWifiManager.cs =================================================================== --- trunk/plugins/WiFiManager/WiFiManager/GuiWifiManager.cs (rev 0) +++ trunk/plugins/WiFiManager/WiFiManager/GuiWifiManager.cs 2011-11-06 13:41:46 UTC (rev 4325) @@ -0,0 +1,474 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; +using NativeWifi; +using MediaPortal.Dialogs; +using System.IO; + +namespace WiFiManager +{ + [PluginIcons("WiFiManager.WiFiManager.png", "WiFiManager.WiFiManagerDisabled.png")] + public class GuiWifiManager : GUIWindow, ISetupForm, IShowPlugin + { + #region Constants + public const int WINDOW_ID = 4855; + public const string FRIENDLY_NAME = "Wifi Manager"; + #endregion + + #region Fields + int outstandingScans = 0; + string selectedSSID = null; + WlanClient wlanClient = null; + #endregion + + #region Enums + enum WinProfileAuthenticationEnumeration { open, shared, WPA, WPAPSK, WPA2, WPA2PSK }; + enum WinProfileEncryptionEnumeration { none, WEP, TKIP, AES }; + #endregion + + #region Skin Controls + [SkinControlAttribute(50)] + protected GUIFacadeControl GUI_facadeWlans = null; + [SkinControlAttribute(2)] + protected GUIButtonControl GUI_btnScan = null; + [SkinControlAttribute(3)] + protected GUIButtonControl GUI_btnRefresh = null; + #endregion + + #region ISetupForm + string ISetupForm.Author() + { + return "offbyone"; + } + + bool ISetupForm.CanEnable() + { + return true; + } + + bool ISetupForm.DefaultEnabled() + { + return true; + } + + string ISetupForm.Description() + { + return "This Plugin list available wirelesse networks and allow connecting to one."; + } + + bool ISetupForm.GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = FRIENDLY_NAME; + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = @"hover_WifiManager.png"; + return true; + } + + int ISetupForm.GetWindowId() + { + return GetID; + } + + bool ISetupForm.HasSetup() + { + return false; + } + + string ISetupForm.PluginName() + { + return "WifiManager"; + } + + void ISetupForm.ShowPlugin() + { + + } + #endregion + + #region IShowPlugin + bool IShowPlugin.ShowDefaultHome() + { + return false; + } + #endregion + + #region GUIWindow overrides + public override int GetID + { + get { return WINDOW_ID; } + set { base.GetID = value; } + } + + public override string GetModuleName() + { + return FRIENDLY_NAME; + } + + public override bool Init() + { + return Load(GUIGraphicsContext.Skin + @"\WifiManager.xml"); + } + + protected override void OnPageLoad() + { + if (wlanClient == null) + { + try + { + wlanClient = new WlanClient(); + } + catch (Exception ex) + { + Log.Warn("WiFiManager: Error creating WlanClient: {0}", ex.Message); + wlanClient = null; + ShowMessage(ex.Message, "Wifi Manager Error"); + } + } + if (wlanClient != null) + { + foreach (var nic in wlanClient.Interfaces) nic.WlanNotification += new WlanClient.WlanInterface.WlanNotificationEventHandler(nic_WlanNotification); + FindNetworks(); + GUI_btnScan.IsEnabled = true; + GUI_btnRefresh.IsEnabled = true; + } + else + { + GUI_btnScan.IsEnabled = false; + GUI_btnRefresh.IsEnabled = false; + } + GUIPropertyManager.SetProperty("#itemtype", "Networks"); + base.OnPageLoad(); + } + + protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) + { + if (control == GUI_btnScan) + { + outstandingScans = wlanClient.Interfaces.Length; + GUIWaitCursor.Init(); GUIWaitCursor.Show(); // init and show the wait cursor in MediaPortal + foreach (WlanClient.WlanInterface wlanIface in wlanClient.Interfaces) wlanIface.Scan(); + } + else if (control == GUI_btnRefresh) + { + FindNetworks(); + GUIControl.FocusControl(GetID, GUI_facadeWlans.GetID); + } + else if (control == GUI_facadeWlans) + { + GUIDialogMenu dlgWlanOptions = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + if (dlgWlanOptions == null) return; + string ssid = GUI_facadeWlans.SelectedListItem.Label; + dlgWlanOptions.Reset(); + dlgWlanOptions.SetHeading(ssid); + WlanClient.WlanInterface nic = (WlanClient.WlanInterface)GUI_facadeWlans.SelectedListItem.TVTag; + Wlan.WlanAvailableNetwork network = (Wlan.WlanAvailableNetwork)GUI_facadeWlans.SelectedListItem.AlbumInfoTag; + if ((network.flags & Wlan.WlanAvailableNetworkFlags.Connected) == Wlan.WlanAvailableNetworkFlags.Connected) + { + dlgWlanOptions.Add(new GUIListItem("Disconnect")); + if (!string.IsNullOrEmpty(network.profileName)) dlgWlanOptions.Add(new GUIListItem("Save Profile To XML")); + } + else + { + dlgWlanOptions.Add(new GUIListItem("Connect")); + if (!string.IsNullOrEmpty(network.profileName)) dlgWlanOptions.Add(new GUIListItem("Delete Profile")); + } + dlgWlanOptions.DoModal(GetID); + if (dlgWlanOptions.SelectedId == -1) return; + if (dlgWlanOptions.SelectedLabelText == "Connect") + { + ConnectNetwork(ssid, nic, network); + } + else if (dlgWlanOptions.SelectedLabelText == "Disconnect") + { + Log.Info("WiFiManager: Disconnecting from WLAN '{0}'", ssid); + nic.Disconnect(); + } + else if (dlgWlanOptions.SelectedLabelText == "Delete Profile") + { + Log.Info("WiFiManager: Deleting WLAN Profile '{0}'", network.profileName); + nic.DeleteProfile(network.profileName); + FindNetworks(); + } + else if (dlgWlanOptions.SelectedLabelText == "Save Profile To XML") + { + File.WriteAllText(Config.GetFile(Config.Dir.Log, string.Format("{0}#{1}#{2}.xml", network.profileName, network.dot11DefaultAuthAlgorithm.ToString(), network.dot11DefaultCipherAlgorithm.ToString())), nic.GetProfileXml(network.profileName)); + } + } + else base.OnClicked(controlId, control, actionType); + } + #endregion + + internal static bool GetUserInputString(ref string sString, bool password) + { + VirtualKeyboard keyBoard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + if (keyBoard == null) return false; + keyBoard.Reset(); + keyBoard.Text = sString; + keyBoard.Password = password; + keyBoard.DoModal(GUIWindowManager.ActiveWindow); + if (keyBoard.IsConfirmed) sString = keyBoard.Text; + return keyBoard.IsConfirmed; + } + + internal static void ShowMessage(string message, string header = "Wifi Manager") + { + GUIDialogNotify dlg_error = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); + if (dlg_error != null) + { + dlg_error.Reset(); + dlg_error.SetImage(string.Format(@"{0}\Media\WifiManager\WiFi.png", GUIGraphicsContext.Skin)); + dlg_error.SetHeading(header); + dlg_error.SetText(message); + dlg_error.DoModal(GUIWindowManager.ActiveWindow); + } + } + + /// <summary> + /// Converts a 802.11 SSID to a string. + /// </summary> + internal static string GetStringForSSID(Wlan.Dot11Ssid ssid) + { + return Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength); + } + + void nic_WlanNotification(Wlan.WlanNotificationData notifyData) + { + if (notifyData.notificationSource == Wlan.WlanNotificationSource.ACM) + { + if (outstandingScans > 0 && (notifyData.notificationCode == (int)NativeWifi.Wlan.WlanNotificationCodeAcm.ScanComplete || notifyData.notificationCode == (int)NativeWifi.Wlan.WlanNotificationCodeAcm.ScanFail)) + { + outstandingScans--; + if (outstandingScans <= 0) + { + if (GUIWindowManager.ActiveWindow == GetID) + { + GUIWindowManager.SendThreadCallback((p1, p2, o) => + { + GUIWaitCursor.Hide(); // hide the wait cursor in MediaPortal + FindNetworks(); + GUIControl.FocusControl(GetID, GUI_facadeWlans.GetID); + return 0; + }, 0, 0, null); + } + } + } + else if (notifyData.notificationCode == (int)NativeWifi.Wlan.WlanNotificationCodeAcm.ConnectionAttemptFail) + { + ShowMessage("Connection failed!", "Wifi Manager Error"); + } + else if (notifyData.notificationCode == (int)NativeWifi.Wlan.WlanNotificationCodeAcm.ConnectionComplete) + { + string connectedTo = ""; + try + { + connectedTo = wlanClient.Interfaces.First(i => i.InterfaceGuid == notifyData.interfaceGuid).CurrentConnection.profileName; + connectedTo = " to " + connectedTo; + } + catch (Exception) { } + if (GUIWindowManager.ActiveWindow == GetID) + { + GUIWindowManager.SendThreadCallback((p1, p2, o) => + { + ShowMessage(string.Format("Successfully connected{0}!", connectedTo)); + FindNetworks(); + return 0; + }, 0, 0, null); + } + } + } + else if (notifyData.notificationSource == Wlan.WlanNotificationSource.MSM) + { + if (notifyData.notificationCode == (int)Wlan.WlanNotificationCodeMsm.Disconnected) + { + if (GUIWindowManager.ActiveWindow == GetID) + { + GUIWindowManager.SendThreadCallback((p1, p2, o) => + { + ShowMessage("Successfully disconnected!"); + FindNetworks(); + return 0; + }, 0, 0, null); + } + } + } + } + + void FindNetworks() + { + if (GUI_facadeWlans == null) return; + + selectedSSID = GUI_facadeWlans.SelectedListItem != null ? GUI_facadeWlans.SelectedListItem.Label : null; // remember the currently selected one + int selectedIndex = 0; // index to select when the currently selected one is found in the new list + GUI_facadeWlans.Clear(); + + + foreach (WlanClient.WlanInterface wlanIface in wlanClient.Interfaces) + { + Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0); + Dictionary<string, List<Wlan.WlanAvailableNetwork>> hashedNetworks = new Dictionary<string, List<Wlan.WlanAvailableNetwork>>(); + foreach (Wlan.WlanAvailableNetwork network in networks) + { + string ssid = GetStringForSSID(network.dot11Ssid); + if (!string.IsNullOrEmpty(ssid)) + { + List<Wlan.WlanAvailableNetwork> networksForSSID = null; + if (!hashedNetworks.TryGetValue(ssid, out networksForSSID)) hashedNetworks[ssid] = networksForSSID = new List<Wlan.WlanAvailableNetwork>(); + networksForSSID.Add(network); + } + } + foreach (List<Wlan.WlanAvailableNetwork> networklist in hashedNetworks.Values.OrderByDescending(v => v.Max(n => n.wlanSignalQuality))) + { + networklist.Sort((n1,n2) => + { + int result = ((int)n2.flags).CompareTo((int)n1.flags); // the higher the flags the earlier in the list + if (result == 0) result = n2.wlanSignalQuality.CompareTo(n1.wlanSignalQuality); // equal flags -> sort by signal strength descending + return result; + }); + Wlan.WlanAvailableNetwork network = networklist[0]; + if (network.networkConnectable) + { + GUIListItem item = new GUIListItem(GetStringForSSID(network.dot11Ssid)); + if (item.Label == selectedSSID) selectedIndex = GUI_facadeWlans.Count; + if (item.Label.Length == 0) item.Label = "No SSID"; + item.Label2 = network.wlanSignalQuality.ToString() + "%"; + if (network.securityEnabled) item.IconImage = "WifiManager/Secure.png"; + item.IsPlayed = (network.flags & Wlan.WlanAvailableNetworkFlags.Connected) == Wlan.WlanAvailableNetworkFlags.Connected; + if (!item.IsPlayed) item.IsRemote = (network.flags & Wlan.WlanAvailableNetworkFlags.HasProfile) == Wlan.WlanAvailableNetworkFlags.HasProfile; + item.AlbumInfoTag = network; + item.TVTag = wlanIface; + GUI_facadeWlans.Add(item); + } + } + } + + GUIPropertyManager.SetProperty("#itemcount", GUI_facadeWlans.Count.ToString()); + GUI_facadeWlans.SelectedListItemIndex = selectedIndex; + } + + void ConnectNetwork(string ssid, WlanClient.WlanInterface nic, Wlan.WlanAvailableNetwork network) + { + if (!string.IsNullOrEmpty(network.profileName)) + { + Log.Info("WiFiManager: Using existing Profile to connect to WLAN '{0}'", ssid); + bool success = nic.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, network.profileName, 15000); + FindNetworks(); + } + else + { + if (network.securityEnabled) + { + string key = ""; + if (GetUserInputString(ref key, false) && key.Length > 0) + { + Log.Info("WiFiManager: Building new Profile to connect to WLAN '{0}'", ssid); + string profileXml = GetProfileXml(ssid, key, network.dot11DefaultAuthAlgorithm, network.dot11DefaultCipherAlgorithm); + if (profileXml != null) + { + string error = null; + try + { + Wlan.WlanReasonCode reasonCode = nic.SetProfile(Wlan.WlanProfileFlags.User, profileXml, true); + if (reasonCode != Wlan.WlanReasonCode.Success) error = reasonCode.ToString(); + } + catch (Exception ex) + { + error = ex.Message; + } + if (error == null) + { + nic.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, ssid); + } + else + { + Log.Warn("WiFiManager: Setting Profile for WLAN '{0}' failed: '{1}'", ssid, error); + ShowMessage(error, "Wifi Manager Error"); + } + } + else + { + // don't know how to build profile + ShowMessage("Unable to build profile. Connect in Windows and save profile to xml in MP.", "Wifi Manager Error"); + } + } + } + else + { + Log.Info("WiFiManager: Connecting to unsecured WLAN '{0}'", ssid); + nic.Connect(Wlan.WlanConnectionMode.Auto, Wlan.Dot11BssType.Any, network.dot11Ssid, 0); + } + } + } + + /// <summary> + /// Create a valid Profile xml according to: http://msdn.microsoft.com/en-us/library/ms707381(v=VS.85).aspx + /// </summary> + /// <param name="ssid"></param> + /// <param name="key"></param> + /// <param name="authAlg"></param> + /// <param name="encAlg"></param> + /// <returns></returns> + string GetProfileXml(string ssid, string key, Wlan.Dot11AuthAlgorithm authAlg, Wlan.Dot11CipherAlgorithm encAlg) + { + WinProfileAuthenticationEnumeration? auth = null; + WinProfileEncryptionEnumeration? enc = null; + switch (authAlg) + { + case Wlan.Dot11AuthAlgorithm.IEEE80211_SharedKey: + auth = WinProfileAuthenticationEnumeration.open; + enc = WinProfileEncryptionEnumeration.WEP; + break; + case Wlan.Dot11AuthAlgorithm.WPA_PSK: + auth = WinProfileAuthenticationEnumeration.WPAPSK; + break; + case Wlan.Dot11AuthAlgorithm.RSNA_PSK: + auth = WinProfileAuthenticationEnumeration.WPA2PSK; + break; + } + switch (encAlg) + { + case Wlan.Dot11CipherAlgorithm.TKIP: + enc = WinProfileEncryptionEnumeration.TKIP; + break; + case Wlan.Dot11CipherAlgorithm.CCMP: + enc = WinProfileEncryptionEnumeration.AES; + break; + } + + if (enc == null || auth == null) + { + Log.Warn("WiFiManager: No known Mapping to create Profile '{0}' for AuthAlg: '{1}' and CipherAlg: '{2}'", ssid, authAlg.ToString(), encAlg.ToString()); + return null; + } + + return string.Format(@"<?xml version=""1.0""?> +<WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""> + <name>{0}</name> + <SSIDConfig> + <SSID> + <name>{0}</name> + </SSID> + </SSIDConfig> + <connectionType>ESS</connectionType> + <connectionMode>auto</connectionMode> + <MSM> + <security> + <authEncryption> + <authentication>{2}</authentication> + <encryption>{3}</encryption> + <useOneX>false</useOneX> + </authEncryption> + <sharedKey> + <keyType>passPhrase</keyType> + <protected>false</protected> + <keyMaterial>{1}</keyMaterial> + </sharedKey> + </security> + </MSM> +</WLANProfile>", ssid, key, auth.ToString(), enc.ToString()); + } + } +} Added: trunk/plugins/WiFiManager/WiFiManager/NativeWifi/Interop.cs =================================================================== --- trunk/plugins/WiFiManager/WiFiManager/NativeWifi/Interop.cs (rev 0) +++ trunk/plugins/WiFiManager/WiFiManager/NativeWifi/Interop.cs 2011-11-06 13:41:46 UTC (rev 4325) @@ -0,0 +1,1612 @@ +using System; +using System.Runtime.InteropServices; +using System.Net.NetworkInformation; +using System.Text; +using System.Diagnostics; +using System.ComponentModel; + +namespace NativeWifi +{ + // TODO: Separate the functions and the structs/enums. Many of the structs/enums should remain public + // (since they're reused in the OOP interfaces) -- the rest (including all P/Invoke function mappings) + // should become internal. + + // All structures which native methods rely on should be kept in the Wlan class. + // Only change the layout of those structures if it matches the native API documentation. + // Some structures might have helper properties but adding or changing fields is prohibited. + // This class is not documented since all the documentation resides in the MSDN. The code + // documentation only covers details which concern interop users. + // Some identifier names were modified to correspond to .NET naming conventions + // but otherwise retain their native meaning. + + /// <summary> + /// Defines the Native Wifi API through P/Invoke interop. + /// </summary> + /// <remarks> + /// This class is intended for internal use. Use the <see cref="WlanCliient"/> class instead. + /// </remarks> + public static class Wlan + { + #region P/Invoke API + /// <summary> + /// Defines various opcodes used to set and query parameters for an interface. + /// </summary> + /// <remarks> + /// Corresponds to the native <c>WLAN_INTF_OPCODE</c> type. + /// </remarks> + public enum WlanIntfOpcode + { + /// <summary> + /// Opcode used to set or query whether auto config is enabled. + /// </summary> + AutoconfEnabled = 1, + /// <summary> + /// Opcode used to set or query whether background scan is enabled. + /// </summary> + BackgroundScanEnabled, + /// <summary> + /// Opcode used to set or query the media streaming mode of the driver. + /// </summary> + MediaStreamingMode, + /// <summary> + /// Opcode used to set or query the radio state. + /// </summary> + RadioState, + /// <summary> + /// Opcode used to set or query the BSS type of the interface. + /// </summary> + BssType, + /// <summary> + /// Opcode used to query the state of the interface. + /// </summary> + InterfaceState, + /// <summary> + /// Opcode used to query information about the current connection of the interface. + /// </summary> + CurrentConnection, + /// <summary> + /// Opcose used to query the current channel on which the wireless interface is operating. + /// </summary> + ChannelNumber, + /// <summary> + /// Opcode used to query the supported auth/cipher pairs for infrastructure mode. + /// </summary> + SupportedInfrastructureAuthCipherPairs, + /// <summary> + /// Opcode used to query the supported auth/cipher pairs for ad hoc mode. + /// </summary> + SupportedAdhocAuthCipherPairs, + /// <summary> + /// Opcode used to query the list of supported country or region strings. + /// </summary> + SupportedCountryOrRegionStringList, + /// <summary> + /// Opcode used to set or query the current operation mode of the wireless interface. + /// </summary> + CurrentOperationMode, + /// <summary> + /// Opcode used to query driver statistics. + /// </summary> + Statistics = 0x10000101, + /// <summary> + /// Opcode used to query the received signal strength. + /// </summary> + RSSI, + SecurityStart = 0x20010000, + SecurityEnd = 0x2fffffff, + IhvStart = 0x30000000, + IhvEnd = 0x3fffffff + } + + /// <summary> + /// Specifies the origin of automatic configuration (auto config) settings. + /// </summary> + /// <remarks> + /// Corresponds to the native <c>WLAN_OPCODE_VALUE_TYPE</c> type. + /// </remarks> + public enum WlanOpcodeValueType + { + /// <summary> + /// The auto config settings were queried, but the origin of the settings was not determined. + /// </summary> + QueryOnly = 0, + /// <summary> + /// The auto config settings were set by group policy. + /// </summary> + SetByGroupPolicy = 1, + /// <summary> + /// The auto config settings were set by the user. + /// </summary> + SetByUser = 2, + /// <summary> + /// The auto config settings are invalid. + /// </summary> + Invalid = 3 + } + + public const uint WLAN_CLIENT_VERSION_XP_SP2 = 1; + public const uint WLAN_CLIENT_VERSION_LONGHORN = 2; + + [DllImport("wlanapi.dll")] + public static extern int WlanOpenHandle( + [In] UInt32 clientVersion, + [In, Out] IntPtr pReserved, + [Out] out UInt32 negotiatedVersion, + [Out] out IntPtr clientHandle); + + [DllImport("wlanapi.dll")] + public static extern int WlanCloseHandle( + [In] IntPtr clientHandle, + [In, Out] IntPtr pReserved); + + [DllImport("wlanapi.dll")] + public static extern int WlanEnumInterfaces( + [In] IntPtr clientHandle, + [In, Out] IntPtr pReserved, + [Out] out IntPtr ppInterfaceList); + + [DllImport("wlanapi.dll")] + public static extern int WlanQueryInterface( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] WlanIntfOpcode opCode, + [In, Out] IntPtr pReserved, + [Out] out int dataSize, + [Out] out IntPtr ppData, + [Out] out WlanOpcodeValueType wlanOpcodeValueType); + + [DllImport("wlanapi.dll")] + public static extern int WlanSetInterface( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] WlanIntfOpcode opCode, + [In] uint dataSize, + [In] IntPtr pData, + [In, Out] IntPtr pReserved); + + /// <param name="pDot11Ssid">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param> + /// <param name="pIeData">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param> + [DllImport("wlanapi.dll")] + public static extern int WlanScan( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] IntPtr pDot11Ssid, + [In] IntPtr pIeData, + [In, Out] IntPtr pReserved); + + /// <summary> + /// Defines flags passed to <see cref="WlanGetAvailableNetworkList"/>. + /// </summary> + [Flags] + public enum WlanGetAvailableNetworkFlags + { + /// <summary> + /// Include all ad-hoc network profiles in the available network list, including profiles that are not visible. + /// </summary> + IncludeAllAdhocProfiles = 0x00000001, + /// <summary> + /// Include all hidden network profiles in the available network list, including profiles that are not visible. + /// </summary> + IncludeAllManualHiddenProfiles = 0x00000002 + } + + /// <summary> + /// The header of an array of information about available networks. + /// </summary> + [StructLayout(LayoutKind.Sequential)] + internal struct WlanAvailableNetworkListHeader + { + /// <summary> + /// Contains the number of <see cref=""/> items following the header. + /// </summary> + public uint numberOfItems; + /// <summary> + /// The index of the current item. The index of the first item is 0. + /// </summary> + public uint index; + } + + /// <summary> + /// Contains various flags for the network. + /// </summary> + [Flags] + public enum WlanAvailableNetworkFlags + { + /// <summary> + /// This network is currently connected. + /// </summary> + Connected = 0x00000001, + /// <summary> + /// There is a profile for this network. + /// </summary> + HasProfile = 0x00000002 + } + + /// <summary> + /// Contains information about an available wireless network. + /// </summary> + [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] + public struct WlanAvailableNetwork + { + /// <summary> + /// Contains the profile name associated with the network. + /// If the network doesn't have a profile, this member will be empty. + /// If multiple profiles are associated with the network, there will be multiple entries with the same SSID in the visible network list. Profile names are case-sensitive. + /// </summary> + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string profileName; + /// <summary> + /// Contains the SSID of the visible wireless network. + /// </summary> + public Dot11Ssid dot11Ssid; + /// <summary> + /// Specifies whether the network is infrastructure or ad hoc. + /// </summary> + public Dot11BssType dot11BssType; + /// <summary> + /// Indicates the number of BSSIDs in the network. + /// </summary> + public uint numberOfBssids; + /// <summary> + /// Indicates whether the network is connectable or not. + /// </summary> + public bool networkConnectable; + /// <summary> + /// Indicates why a network cannot be connected to. This member is only valid when <see cref="networkConnectable"/> is <c>false</c>. + /// </summary> + public WlanReasonCode wlanNotConnectableReason; + /// <summary> + /// The number of PHY types supported on available networks. + /// The maximum value of this field is 8. If more than 8 PHY types are supported, <see cref="morePhyTypes"/> must be set to <c>true</c>. + /// </summary> + private uint numberOfPhyTypes; + /// <summary> + /// Contains an array of <see cref="Dot11PhyType"/> values that represent the PHY types supported by the available networks. + /// When <see cref="numberOfPhyTypes"/> is greater than 8, this array contains only the first 8 PHY types. + /// </summary> + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] + private Dot11PhyType[] dot11PhyTypes; + /// <summary> + /// Gets the <see cref="Dot11PhyType"/> values that represent the PHY types supported by the available networks. + /// </summary> + public Dot11PhyType[] Dot11PhyTypes + { + get + { + Dot11PhyType[] ret = new Dot11PhyType[numberOfPhyTypes]; + Array.Copy(dot11PhyTypes, ret, numberOfPhyTypes); + return ret; + } + } + /// <summary> + /// Specifies if there are more than 8 PHY types supported. + /// When this member is set to <c>true</c>, an application must call <see cref="WlanClient.WlanInterface.GetNetworkBssList"/> to get the complete list of PHY types. + /// <see cref="WlanBssEntry.phyId"/> contains the PHY type for an entry. + /// </summary> + public bool morePhyTypes; + /// <summary> + /// A percentage value that represents the signal quality of the network. + /// This field contains a value between 0 and 100. + /// A value of 0 implies an actual RSSI signal strength of -100 dbm. + /// A value of 100 implies an actual RSSI signal strength of -50 dbm. + /// You can calculate the RSSI signal strength value for values between 1 and 99 using linear interpolation. + /// </summary> + public uint wlanSignalQuality; + /// <summary> + /// Indicates whether security is enabled on the network. + /// </summary> + public bool securityEnabled; + /// <summary> + /// Indicates the default authentication algorithm used to join this network for the first time. + /// </summary> + public Dot11AuthAlgorithm dot11DefaultAuthAlgorithm; + /// <summary> + /// Indicates the default cipher algorithm to be used when joining this network. + /// </summary> + public Dot11CipherAlgorithm dot11DefaultCipherAlgorithm; + /// <summary> + /// Contains various flags for the network. + /// </summary> + public WlanAvailableNetworkFlags flags; + /// <summary> + /// Reserved for future use. Must be set to NULL. + /// </summary> + uint reserved; + } + + [DllImport("wlanapi.dll")] + public static extern int WlanGetAvailableNetworkList( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] WlanGetAvailableNetworkFlags flags, + [In, Out] IntPtr reservedPtr, + [Out] out IntPtr availableNetworkListPtr); + + [Flags] + public enum WlanProfileFlags + { + /// <remarks> + /// The only option available on Windows XP SP2. + /// </remarks> + AllUser = 0, + GroupPolicy = 1, + User = 2 + } + + [DllImport("wlanapi.dll")] + public static extern int WlanSetProfile( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] WlanProfileFlags flags, + [In, MarshalAs(UnmanagedType.LPWStr)] string profileXml, + [In, Optional, MarshalAs(UnmanagedType.LPWStr)] string allUserProfileSecurity, + [In] bool overwrite, + [In] IntPtr pReserved, + [Out] out WlanReasonCode reasonCode); + + /// <summary> + /// Defines the access mask of an all-user profile. + /// </summary> + [Flags] + public enum WlanAccess + { + /// <summary> + /// The user can view profile permissions. + /// </summary> + ReadAccess = 0x00020000 | 0x0001, + /// <summary> + /// The user has read access, and the user can also connect to and disconnect from a network using the profile. + /// </summary> + ExecuteAccess = ReadAccess | 0x0020, + /// <summary> + /// The user has execute access and the user can also modify and delete permissions associated with a profile. + /// </summary> + WriteAccess = ReadAccess | ExecuteAccess | 0x0002 | 0x00010000 | 0x00040000 + } + + /// <param name="flags">Not supported on Windows XP SP2: must be a <c>null</c> reference.</param> + [DllImport("wlanapi.dll")] + public static extern int WlanGetProfile( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In, MarshalAs(UnmanagedType.LPWStr)] string profileName, + [In] IntPtr pReserved, + [Out] out IntPtr profileXml, + [Out, Optional] out WlanProfileFlags flags, + [Out, Optional] out WlanAccess grantedAccess); + + [DllImport("wlanapi.dll")] + public static extern int WlanGetProfileList( + [In] IntPtr clientHandle, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, + [In] IntPtr pReserved, + [Out] out IntPtr profileList + ); + + [DllImport("wlanapi.dll")] + public static extern void WlanFreeMemory(IntPtr pMemory); + + [DllImport("wlanapi.dll")] + public static extern int WlanReasonCodeToString( + [In] WlanReasonCode reasonCode, + [In] int bufferSize, + [In, Out] StringBuilder stringBuffer, + IntPtr pReserved + ); + + /// <summary> + /// Specifies where the notification comes from. + /// </summary> + [Flags] + public enum WlanNotificationSource + { + None = 0, + /// <summary> + /// All notifications, including those generated by the 802.1X module. + /// </summary> + All = 0X0000FFFF, + /// <summary> + /// Notifications generated by the auto configuration module. + /// </summary> + ACM = 0X00000008, + /// <summary> + /// Notifications generated by MSM. + /// </summary> + MSM = 0X00000010, + /// <summary> + /// Notifications generated by the security module. + /// </summary> + Security = 0X00000020, + /// <summary> + /// Notifications generated by independent hardware vendors (IHV). + /// </summary> + IHV = 0X00000040 + } + + /// <summary> + /// Indicates the type of an ACM (<see cref="WlanNotificationSource.ACM"/>) notification. + /// </summary> + /// <remarks> + /// The enumeration identifiers correspond to the native <c>wlan_notification_acm_</c> identifiers. + /// On Windows XP SP2, only the <c>ConnectionComplete</c> and <c>Disconnected</c> notifications are available. + /// </remarks> + public enum WlanNotificationCodeAcm + { + AutoconfEnabled = 1, + AutoconfDisabled, + BackgroundScanEnabled, + BackgroundScanDisabled, + BssTypeChange, + PowerSettingChange, + ScanComplete, + ScanFail, + ConnectionStart, + ConnectionComplete, + ConnectionAttemptFail, + FilterListChange, + InterfaceArrival, + InterfaceRemoval, + ProfileChange, + ProfileNameChange, + ProfilesExhausted, + NetworkNotAvailable, + NetworkAvailable, + Disconnecting, + Disconnected, + AdhocNetworkStateChange + } + + /// <summary> + /// Indicates the type of an MSM (<see cref="WlanNotificationSource.MSM"/>) notification. + /// </summary> + /// <remarks> + /// The enumeration identifiers correspond to the native <c>wlan_notification_msm_</c> identifiers. + /// </remarks> + public enum WlanNotificationCodeMsm + { + Associating = 1, + Associated, + Authenticating, + Connected, + RoamingStart, + RoamingEnd, + RadioStateChange, + SignalQualityChange, + Disassociating, + Disconnected, + PeerJoin, + PeerLeave, + AdapterRemoval, + AdapterOperationModeChange + } + + /// <summary> + /// Contains information provided when registering for notifications. + /// </summary> + /// <remarks> + /// Corresponds to the native <c>WLAN_NOTIFICATION_DATA</c> type. + /// </remarks> + [StructLayout(LayoutKind.Sequential)] + public struct WlanNotificationData + { + /// <summary> + /// Specifies where the notification comes from. + /// </summary> + /// <remarks> + /// On Windows XP SP2, this field must be set to <see cref="WlanNotificationSource.None"/>, <see cref="WlanNotificationSource.All"/> or <see cref="WlanNotificationSource.ACM"/>. + /// </remarks> + public WlanNotificationSource notificationSource; + /// <summary> + /// Indicates the type of notification. The value of this field indicates what type of associated data will be present in <see cref="dataPtr"/>. + /// </summary> + public int notificationCode; + /// <summary> + /// Indicates which interface the notification is for. + /// </summary> + public Guid interfaceGuid; + /// <summary> + /// Specifies the size of <see cref="dataPtr"/>, in bytes. + /// </summary> + public int dataSize; + /// <summary> + /// Pointer to additional data needed for the notification, as indicated by <see cref="notificationCode"/>. + /// </summary> + public IntPtr dataPtr; + + /// <summary> + /// Gets the notification code (in the correct enumeration type) according to the notification source. + /// </summary> + public object NotificationCode + { + get + { + if (notificationSource == WlanNotificationSource.MSM) + return (WlanNotificationCodeMsm)notificationCode; + else if (notificationSource == WlanNotificationSource.ACM) + return (WlanNotificationCodeAcm)notificationCode; + else + return notificationCode; + } + + } + } + + /// <summary> + /// Defines the callback function which accepts WLAN notifications. + /// </summary> + public delegate void WlanNotificationCallbackDelegate(ref WlanNotificationData notificationData, IntPtr context); + + [DllImport("wlanapi.dll")] + public static extern int WlanRegisterNotification( + [In] IntPtr clientHandle, + [In] WlanNotificationSource notifSource, + [In] bool ignoreDuplicate, + [In] WlanNotificationCallbackDelegate funcCallback, + [In] IntPtr callbackContext, + [In] IntPtr reserved, + [Out] out WlanNotificationSource prevNotifSource); + + /// <summary> + /// Defines connection parameter flags. + /// </summary> + [Flags] + public enum WlanConnectionFlags + { + /// <summary> + /// Connect to the destination network even if the destination is a hidden network. A hidden network does not broadcast its SSID. Do not use this flag if the destination network is an ad-hoc network. + /// <para>If the profile specified by <see cref="WlanConnect... [truncated message content] |