/// <summary> /// Generates the profile XML for the access point and password /// </summary> internal static string Generate(WlanAvailableNetwork network, string password) { string profile = string.Empty; string template = string.Empty; string name = Encoding.ASCII.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength); string hex = GetHexString(network.dot11Ssid.SSID); var authAlgo = network.dot11DefaultAuthAlgorithm; switch (network.dot11DefaultCipherAlgorithm) { case Dot11CipherAlgorithm.None: template = GetTemplate("OPEN"); profile = string.Format(template, name, hex); break; case Dot11CipherAlgorithm.WEP: template = GetTemplate("WEP"); profile = string.Format(template, name, hex, password); break; case Dot11CipherAlgorithm.CCMP: if (authAlgo == Dot11AuthAlgorithm.RSNA) { template = GetTemplate("WPA2-Enterprise-PEAP-MSCHAPv2"); profile = string.Format(template, name); } else // PSK { template = GetTemplate("WPA2-PSK"); profile = string.Format(template, name, password); } break; case Dot11CipherAlgorithm.TKIP: // #warning Not sure WPA uses RSNA if (authAlgo == Dot11AuthAlgorithm.RSNA) { template = GetTemplate("WPA-Enterprise-PEAP-MSCHAPv2"); profile = string.Format(template, name); } else // PSK { template = GetTemplate("WPA-PSK"); profile = string.Format(template, name, password); } break; default: throw new NotImplementedException("Profile for selected cipher algorithm is not implemented"); } return(profile); }
/// <summary> /// Converts a pointer to a available networks list (header + entries) to an array of available network entries. /// </summary> /// <param name="bssListPtr">A pointer to an available networks list's header.</param> /// <returns>An array of available network entries.</returns> private WlanAvailableNetwork[] ConvertAvailableNetworkListPtr(IntPtr availNetListPtr) { WlanAvailableNetworkListHeader availNetListHeader = (WlanAvailableNetworkListHeader)Marshal.PtrToStructure(availNetListPtr, typeof(WlanAvailableNetworkListHeader)); long availNetListIt = availNetListPtr.ToInt64() + Marshal.SizeOf(typeof(WlanAvailableNetworkListHeader)); WlanAvailableNetwork[] availNets = new WlanAvailableNetwork[availNetListHeader.numberOfItems]; for (int i = 0; i < availNetListHeader.numberOfItems; ++i) { availNets[i] = (WlanAvailableNetwork)Marshal.PtrToStructure(new IntPtr(availNetListIt), typeof(WlanAvailableNetwork)); availNetListIt += Marshal.SizeOf(typeof(WlanAvailableNetwork)); } return(availNets); }
public bool Equals(WlanAvailableNetwork network) { // Compares the two SSID byte arrays return(this.dot11Ssid.SSIDLength == network.dot11Ssid.SSIDLength && this.dot11Ssid.SSID.SequenceEqual(network.dot11Ssid.SSID)); }
/// <summary> /// Internal constructor to create wireless network /// </summary> /// <param name="wlanInterfac">Wifi network interface</param> /// <param name="network">Win32 structure for wireless network</param> internal WirelessNetwork(WlanInterface wlanInterfac, WlanAvailableNetwork network) { _wlanInterface = wlanInterfac; _network = network; }