public WhckAssociation(RunTimeConfiguration RuntimeConfig, APConfigParameter AP1Config24GHz, APConfigParameter AP1Config5GHz, APConfigParameter AP2Config24GHz, APConfigParameter AP2Config5GHz, ASSOC_TEST_OPTIONS AssocTestOptions) { if (RuntimeConfig == null) { throw new ArgumentNullException("RuntimeConfig"); } m_TraceProvider = new WlanHckTestLogger("WhckAssociation"); this.m_AssociationConfiguration = RuntimeConfig; this.m_AP1Config24GHz = AP1Config24GHz; this.m_AP1Config5GHz = AP1Config5GHz; this.m_AP2Config24GHz = AP2Config24GHz; this.m_AP2Config5GHz = AP2Config5GHz; this.m_AssocTestOptions = AssocTestOptions; m_WlanApi = new Wlan(); m_TestInterface = Helpers.GetWlanInterface(m_WlanApi); m_ApConfigClient = Helpers.ConnectToService(m_AssociationConfiguration.ServiceBackChannelAddress); m_Routers = Helpers.GetRouterCollection(m_ApConfigClient); this.m_DeviceSupports5GHz = RuntimeConfig.DeviceSupports5Ghz; m_PowerManager = new PowerManager(); m_bIsAccessPointSetup = false; }
public bool SaveProfileXml(string profileName, WlanInterface wlanIface, bool isProtected = true) { if (CheckExistsPath(true)) { string path = System.IO.Path.Combine(Path, profileName + ".xml"); var xml = wlanIface.GetProfileXml(profileName, isProtected); if (!string.IsNullOrEmpty(xml)) { try { File.WriteAllText(path, xml); return(true); } catch { return(false); } } else { return(false); } } else { return(false); } }
/// <summary> /// Returns a list over all available access points from specified wlaninterface. /// </summary> /// <param name="wlanIface"></param> /// <returns></returns> public List <AccessPoint> GetAccessPoints(WlanInterface wlanIface) { List <AccessPoint> accessPoints = new List <AccessPoint>(); if (_client.NoWifiAvailable) { return(accessPoints); } WlanAvailableNetwork[] rawNetworks = wlanIface.GetAvailableNetworkList(); List <WlanAvailableNetwork> networks = new List <WlanAvailableNetwork>(); // Remove network entries without profile name if one exist with a profile name. foreach (WlanAvailableNetwork network in rawNetworks) { bool hasProfileName = !string.IsNullOrEmpty(network.profileName); bool anotherInstanceWithProfileExists = rawNetworks.Any(n => n.Equals(network) && !string.IsNullOrEmpty(n.profileName)); if (!anotherInstanceWithProfileExists || hasProfileName) { networks.Add(network); } } foreach (WlanAvailableNetwork network in networks) { accessPoints.Add(new AccessPoint(wlanIface, network)); } return(accessPoints); }
public WhckRoaming(RunTimeConfiguration rc, APConfigParameter AP1Config24GHz, APConfigParameter AP1Config5GHz, APConfigParameter AP2Config24GHz, APConfigParameter AP2Config5GHz, ROAM_TEST_OPTIONS RoamTestOptions) { if (rc == null) { throw new ArgumentNullException("rc"); } traceProvider = new WlanHckTestLogger("WhckRoaming"); this.RoamingConfiguration = rc; this.m_AP1Config24GHz = AP1Config24GHz; this.m_AP1Config5GHz = AP1Config5GHz; this.m_AP2Config24GHz = AP2Config24GHz; this.m_AP2Config5GHz = AP2Config5GHz; this.m_RoamTestOptions = RoamTestOptions; Api = new Wlan(); TestInterface = Helpers.GetWlanInterface(Api); AC = Helpers.ConnectToService(RoamingConfiguration.ServiceBackChannelAddress); routers = Helpers.GetRouterCollection(AC); AccessPointSetup = false; DeviceSupports5Ghz = rc.DeviceSupports5Ghz; }
public void Init(NetworkInterface wlanInterface, out Exception error) { error = null; _interface = null; Guid interfaceId = new Guid(wlanInterface.Id); //Translate the NetworkInterface to a WlanInterface foreach (WlanInterface wlan in InterfaceManager.Instance.WlanClient.Interfaces) { if (!wlan.InterfaceGuid.Equals(interfaceId)) { continue; } _interface = wlan; break; } if (_interface == null) { error = new ArgumentException("Invalid wireless interface", "wlanInterface"); return; } _interface.WlanNotification += WlanApi_WlanNotification; }
private void button3_Click(object sender, EventArgs e) { try { WlanInterface wlanIface = client.Interfaces.Where(s => s.InterfaceDescription.Equals(listBox1.SelectedItem.ToString())).First(); wlanIface.Disconnect(); } catch { } }
internal AccessPoint(WlanInterface interfac, WlanAvailableNetwork network) { Interface = interfac; Network = network; //For WIndows 7 //If XP Return ERROR_NOT_SUPPORTED //The request is not supported.This error is returned if this function was called from a Windows XP with SP3 or Wireless LAN API for Windows XP with SP2 client.This error is also returned if the WLAN AutoConfig service is disabled. Bssids = Interface.GetNetworkBssList(Network.dot11Ssid, Network.dot11BssType).ToList(); }
public WlanInterface GetSelectedWifiDevice() { WlanInterface wlanIface = null; if (listViewDevices.SelectedItems.Count > 0) { wlanIface = listViewDevices.SelectedItems[0].Tag as WlanInterface; } return(wlanIface); }
internal JAccessPoint(WlanInterface wlanInterface, WlanAvailableNetwork network, AccessPoint thisAP) { InterfaceName = wlanInterface.InterfaceName; name = thisAP.Name; signalStrength = thisAP.SignalStrength; AuthAlgorithm = Enum.GetName(typeof(Dot11AuthAlgorithm), network.dot11DefaultAuthAlgorithm); CipherAlgorithm = Enum.GetName(typeof(Dot11CipherAlgorithm), network.dot11DefaultCipherAlgorithm); BssType = Enum.GetName(typeof(Dot11BssType), network.dot11BssType); connectable = network.networkConnectable; wlanNotConnectableReason = Enum.GetName(typeof(WlanReasonCode), network.wlanNotConnectableReason); }
/// <summary> /// Constructor to create authentication settings /// </summary> /// <param name="wirelessNetwork">Wireless Network object</param> public AuthSettings(WirelessNetwork wirelessNetwork) { _network = wirelessNetwork.Network; _wlanInterface = wirelessNetwork.Interface; // read the wifi network settings and assign local properties IsPasswordRequired = _network.securityEnabled && _network.dot11DefaultCipherAlgorithm != Dot11CipherAlgorithm.None; bool isEAPStore = _network.dot11DefaultAuthAlgorithm == Dot11AuthAlgorithm.RSNA || _network.dot11DefaultAuthAlgorithm == Dot11AuthAlgorithm.WPA; IsUsernameRequired = isEAPStore; IsDomainSupported = isEAPStore; }
public uint getWlanSignalQuqlity() { WlanInterface Iface = WIFI.CurrentInterface; if (Iface.InterfaceState == NativeWifi.Wlan.WlanInterfaceState.Connected) { return(Iface.CurrentConnection.wlanAssociationAttributes.wlanSignalQuality); } else { return(0); } }
public AuthRequest(AccessPoint ap) { _network = ap.Network; _interface = ap.Interface; _ssidBroadcast = ap.IsSsidBroadcasted; _isPasswordRequired = _network.securityEnabled && _network.dot11DefaultCipherAlgorithm != Dot11CipherAlgorithm.None; _isEAPStore = _network.dot11DefaultAuthAlgorithm == Dot11AuthAlgorithm.RSNA || _network.dot11DefaultAuthAlgorithm == Dot11AuthAlgorithm.WPA; _isUsernameRequired = _isEAPStore; _isDomainSupported = _isEAPStore; }
/// <summary> /// Return one access point that matached specified ssid Name from specified wlaninterface. /// </summary> /// <param name="wlanIface"></param> /// <param name="SsidName"></param> /// <returns></returns> public AccessPoint GetAccessPoint(WlanInterface wlanIface, string SsidName) { if (_client.NoWifiAvailable) { return(null); } if (wlanIface == null) { return(null); } WlanAvailableNetwork[] rawNetworks = wlanIface.GetAvailableNetworkList(); List <WlanAvailableNetwork> networks = new List <WlanAvailableNetwork>(); // Remove network entries without profile name if one exist with a profile name. foreach (WlanAvailableNetwork network in rawNetworks) { bool hasProfileName = !string.IsNullOrEmpty(network.profileName); bool anotherInstanceWithProfileExists = rawNetworks.Any(n => n.Equals(network) && !string.IsNullOrEmpty(n.profileName)); if (!anotherInstanceWithProfileExists || hasProfileName) { networks.Add(network); } } foreach (WlanAvailableNetwork network in networks) { if (Encoding.ASCII.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength) != SsidName) { continue; } AccessPoint accessPoint = new AccessPoint(wlanIface, network); return(accessPoint); } return(null); }
public WhckScanning(RunTimeConfiguration rc, APConfigParameter AP1Config24GHz, APConfigParameter AP1Config5GHz, APConfigParameter AP2Config24GHz, APConfigParameter AP2Config5GHz, SCAN_TEST_OPTIONS ScanTestOptions) { if (rc == null) { throw new ArgumentNullException("rc"); } traceProvider = new TraceProvider("WhckScanning"); this.ScanningConfiguration = rc; this.m_AP1Config24GHz = AP1Config24GHz; this.m_AP1Config5GHz = AP1Config5GHz; this.m_AP2Config24GHz = AP2Config24GHz; this.m_AP2Config5GHz = AP2Config5GHz; this.m_ScanTestOptions = ScanTestOptions; Api = new Wlan(); TestInterface = Helpers.GetWlanInterface(Api); AC = null; AC = Helpers.ConnectToService(ScanningConfiguration.ServiceBackChannelAddress); if (AC == null) { Log("Helpers.ConnectToService failed"); AC = null; throw new Exception("Helpers.ConnectToService failed"); } routers = Helpers.GetRouterCollection(AC); AccessPointSetup = false; }
/// <summary> /// Get Known Profile's Xmls from specified interfaces /// </summary> /// <param name="wlanIface"></param> /// <param name="isProtected">if false, key material not encrypted</param> /// <returns></returns> public List <string> GetKnownProfileXmls(WlanInterface wlanIface, bool isProtected = true) { List <string> profiles = new List <string>(); if (_client.NoWifiAvailable) { return(null); } string[] rawProfileInfo = wlanIface.GetProfilesXml(isProtected); foreach (string profileInfo in rawProfileInfo) { bool anotherInstanceWithProfileExists = rawProfileInfo.Any(n => n.Equals(profileInfo) && !string.IsNullOrEmpty(n)); if (!anotherInstanceWithProfileExists) { profiles.Add(profileInfo); } } return(profiles); }
/// <summary> /// Get known profile names from specified interface. /// </summary> /// <param name="wlanIface"></param> /// <returns></returns> public List <string> GetKnownProfileNames(WlanInterface wlanIface) { List <string> profiles = new List <string>(); if (_client.NoWifiAvailable) { return(null); } WlanProfileInfo[] rawProfileInfo = wlanIface.GetProfiles(); foreach (WlanProfileInfo profileInfo in rawProfileInfo) { bool anotherInstanceWithProfileExists = rawProfileInfo.Any(n => n.Equals(profileInfo) && !string.IsNullOrEmpty(n.profileName)); if (!anotherInstanceWithProfileExists) { profiles.Add(profileInfo.profileName); } } return(profiles); }
private void buttonPatch_Click(object sender, EventArgs e) { ClearInitMessage(); BluetoothDeviceInfo devInfo = GetSelectedBtDevice(); WlanInterface wlanIface = GetSelectedWifiDevice(); if (devInfo == null && wlanIface == null) { return; } string dirName = null; Patch.PatchType patchType = Patch.PatchType.Ediabas; if (sender == buttonPatchEdiabas) { dirName = _ediabasDirBmw; patchType = Patch.PatchType.Ediabas; } else if (sender == buttonPatchVasPc) { dirName = _ediabasDirVag; patchType = Patch.PatchType.VasPc; } else if (sender == buttonPatchIstad) { dirName = _ediabasDirIstad; patchType = Patch.PatchType.Istad; } if (!string.IsNullOrEmpty(dirName)) { StringBuilder sr = new StringBuilder(); Patch.PatchEdiabas(sr, patchType, _test.AdapterType, dirName, devInfo, wlanIface, textBoxBluetoothPin.Text); UpdateStatusText(sr.ToString()); } UpdateButtonStatus(); }
private void timer1_Tick(object sender, EventArgs e) { try { if (checkBox1.Checked) { listView1.Items.Clear(); if (listBox1.SelectedItem != null) { WlanInterface wlanIface = client.Interfaces.Where(s => s.InterfaceDescription.Equals(listBox1.SelectedItem.ToString())).First(); try { if (wlanIface.InterfaceState == WlanInterfaceState.Connected) { connectedSSID = wlanIface.CurrentConnection.profileName; label1.Text = "Current connection: " + connectedSSID + " " + wlanIface.CurrentConnection.isState; button3.Enabled = true; } else { connectedSSID = string.Empty; label1.Text = "Current connection: " + wlanIface.InterfaceState; button3.Enabled = false; } } catch { connectedSSID = string.Empty; label1.Text = "Current connection: " + wlanIface.InterfaceState; button3.Enabled = false; } wlanIface.Scan(); WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles); foreach (WlanAvailableNetwork network in networks.GroupBy(x => GetStringForSSID(x.dot11Ssid)).Select(y => y.First()).OrderByDescending(r => r.wlanSignalQuality)) { ListViewItem li = new ListViewItem(); li.Text = GetStringForSSID(network.dot11Ssid); li.SubItems.Add(network.networkConnectable.ToString()); li.SubItems.Add(network.wlanSignalQuality.ToString()); li.SubItems.Add(network.dot11DefaultCipherAlgorithm.ToString()); li.SubItems.Add(network.dot11DefaultAuthAlgorithm.ToString()); li.SubItems.Add(network.securityEnabled.ToString()); try { WlanProfileInfo[] wpi = wlanIface.GetProfiles().Where(s => s.profileName.Equals(li.Text)).ToArray(); li.Tag = (wpi.Length > 0 && wlanIface.InterfaceState != WlanInterfaceState.Connected) ? "true" : "false"; } catch { li.Tag = "false"; } if (selectedSSID == li.Text) { li.Selected = true; if (li.Tag.ToString() == "true") { button2.Enabled = true; } else { button2.Enabled = false; } } if (connectedSSID == li.Text) { li.ForeColor = Color.White; li.BackColor = Color.Green; } else { li.ForeColor = Color.Black; li.BackColor = Color.LightCyan; } listView1.Items.Add(li); } } /*foreach (AccessPoint ap in wifi.GetAccessPoints()) * { * ListViewItem li = new ListViewItem(); * li.Text = ap.Name; * li.SubItems.Add(ap.SignalStrength.ToString()); * li.SubItems.Add(ap.Interface.Channel.ToString()); * li.SubItems.Add(ap.HasProfile.ToString()); * li.SubItems.Add(ap.IsConnected.ToString()); * li.SubItems.Add(ap.IsSecure.ToString()); * if (selectedSSID == li.Text) * { * li.Selected = true; * } * if (connectedSSID == li.Text) * { * li.ForeColor = Color.White; * li.BackColor = Color.Green; * } * else * { * li.ForeColor = Color.Black; * li.BackColor = Color.LightCyan; * } * listView1.Items.Add(li); * }*/ } } catch { } }
// ReSharper disable once UnusedMethodReturnValue.Local public bool ExecuteTest(bool configure) { if (_testThread != null) { return(false); } CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TestOk = false; ConfigPossible = false; AdapterType = -1; AccessPoint ap = _form.GetSelectedAp(); if (ap != null) { AuthRequest authRequest = new AuthRequest(ap); if (authRequest.IsPasswordRequired) { authRequest.Password = _form.WifiPassword; } ap.ConnectAsync(authRequest, true, success => { _form.BeginInvoke((Action)(() => { if (!success) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); } else { _form.PerformSearch(); } })); }); return(true); } WlanInterface wlanIface = _form.GetSelectedWifiDevice(); if (wlanIface != null) { try { WlanConnectionAttributes conn = wlanIface.CurrentConnection; string ssidString = Encoding.ASCII.GetString(conn.wlanAssociationAttributes.dot11Ssid.SSID).TrimEnd('\0'); string ipAddr = string.Empty; bool isEnet = string.Compare(ssidString, Patch.AdapterSsidEnet, StringComparison.OrdinalIgnoreCase) == 0; IPInterfaceProperties ipProp = wlanIface.NetworkInterface.GetIPProperties(); if (ipProp == null) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } ipAddr = (from addr in ipProp.DhcpServerAddresses where addr.AddressFamily == AddressFamily.InterNetwork select addr.ToString()).FirstOrDefault(); if (string.IsNullOrEmpty(ipAddr)) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } if (isEnet) { if (configure) { Process.Start(string.Format("http://{0}", ipAddr)); _form.UpdateStatusText(Resources.Strings.WifiUrlOk); TestOk = true; ConfigPossible = true; return(true); } } _testThread = new Thread(() => { try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; if (isEnet) { TestOk = RunWifiTestEnetRetry(ipAddr); if (TestOk) { ConfigPossible = true; } } else { TestOk = RunWifiTestElm(ipAddr, configure, out bool configRequired); if (TestOk && configRequired) { ConfigPossible = true; } } } finally { _testThread = null; _form.UpdateButtonStatus(); } }); _testThread.Start(); } catch (Exception) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } return(true); } BluetoothDeviceInfo devInfo = _form.GetSelectedBtDevice(); if (devInfo == null) { return(false); } string pin = _form.BluetoothPin; _testThread = new Thread(() => { try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; _form.UpdateStatusText(Resources.Strings.Connecting); if (!ConnectBtDevice(devInfo, pin)) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return; } TestOk = RunBtTest(configure, out bool configRequired); if (TestOk && configRequired) { ConfigPossible = true; } } finally { DisconnectStream(); _testThread = null; _form.UpdateButtonStatus(); } }); _testThread.Start(); return(true); }
private void OnWlanNotification(ref Wlan.WlanNotificationData notifyData, IntPtr context) { WlanInterface wlanIface = null;// = GenericInfo.WlanInterface; foreach (WlanInterface wli in this.Interfaces) { if (wli.InterfaceGuid == notifyData.interfaceGuid) { wlanIface = wli; } } switch (notifyData.notificationSource) { case Wlan.WlanNotificationSource.ACM: Console.WriteLine("ACM-EVENT: " + (Wlan.WlanNotificationCodeAcm)notifyData.NotificationCode); switch ((Wlan.WlanNotificationCodeAcm)notifyData.notificationCode) { case Wlan.WlanNotificationCodeAcm.ConnectionStart: break; case Wlan.WlanNotificationCodeAcm.ConnectionComplete: wlanIface.LatestConnection = wlanIface.CurrentConnection; //LINK UP INDICATION LINK_SAP_CS_80211.LINK_SAP_80211.Events.EventHandler.HandleLinkUp(notifyData); break; case Wlan.WlanNotificationCodeAcm.ConnectionAttemptFail: break; case Wlan.WlanNotificationCodeAcm.Disconnecting: break; case Wlan.WlanNotificationCodeAcm.Disconnected: //LINK DOWN INDICATION LINK_SAP_CS_80211.LINK_SAP_80211.Events.EventHandler.HandleLinkDown(notifyData); Wlan.WlanConnectionNotificationData?connNotifyData = ParseWlanConnectionNotification(ref notifyData); if (connNotifyData.HasValue) { if (wlanIface != null) { wlanIface.OnWlanConnection(notifyData, connNotifyData.Value); } } break; case Wlan.WlanNotificationCodeAcm.ScanComplete: //Handles LINK DETECTED INDICATION LINK_SAP_CS_80211.LINK_SAP_80211.Events.EventHandler.HandleScanComplete(notifyData); break; case Wlan.WlanNotificationCodeAcm.ScanFail: { int expectedSize = Marshal.SizeOf(typeof(int)); 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: Console.WriteLine("MSM-EVENT: " + (Wlan.WlanNotificationCodeMsm)notifyData.NotificationCode); switch ((Wlan.WlanNotificationCodeMsm)notifyData.notificationCode) { case Wlan.WlanNotificationCodeMsm.SignalQualityChange: LINK_SAP_CS_80211.LINK_SAP_80211.Events.EventHandler.HandleParamsReport(notifyData); break; case Wlan.WlanNotificationCodeMsm.Associating: break; case Wlan.WlanNotificationCodeMsm.Associated: break; case Wlan.WlanNotificationCodeMsm.Authenticating: break; case Wlan.WlanNotificationCodeMsm.Connected: break; case Wlan.WlanNotificationCodeMsm.RoamingStart: break; case Wlan.WlanNotificationCodeMsm.RoamingEnd: break; case Wlan.WlanNotificationCodeMsm.Disassociating: break; case Wlan.WlanNotificationCodeMsm.Disconnected: break; case Wlan.WlanNotificationCodeMsm.PeerJoin: break; case Wlan.WlanNotificationCodeMsm.PeerLeave: break; 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); } }
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: { try { 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); } } } catch { } } 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 static bool UpdateConfigFile(string fileName, BluetoothDeviceInfo devInfo, WlanInterface wlanIface, string pin) { try { XDocument xDocument = XDocument.Load(fileName); XElement settingsNode = xDocument.Root?.Element("appSettings"); if (settingsNode == null) { return(false); } if (wlanIface != null) { UpdateConfigNode(settingsNode, @"EnetRemoteHost", @"auto:all"); UpdateConfigNode(settingsNode, @"Interface", @"ENET"); } else if (devInfo != null) { string interfaceValue = @"STD:OBD"; if (fileName.ToLowerInvariant().Contains(@"\SIDIS\home\DBaseSys2\".ToLowerInvariant())) { // VAS-PC instalation interfaceValue = @"EDIC"; } string portValue = string.Format("BLUETOOTH:{0}#{1}", devInfo.DeviceAddress, pin); UpdateConfigNode(settingsNode, @"ObdComPort", portValue); UpdateConfigNode(settingsNode, @"Interface", interfaceValue); } else { return(false); } xDocument.Save(fileName); } catch (Exception) { return(false); } return(true); }
public static bool UpdateConfigFile(string fileName, int adapterType, BluetoothDeviceInfo devInfo, WlanInterface wlanIface, string pin) { try { XDocument xDocument = XDocument.Load(fileName); XElement settingsNode = xDocument.Root?.Element("appSettings"); if (settingsNode == null) { return(false); } string interfaceValue = @"STD:OBD"; if (fileName.ToLowerInvariant().Contains(@"\SIDIS\home\DBaseSys2\".ToLowerInvariant())) { // VAS-PC instalation interfaceValue = @"EDIC"; } if (wlanIface != null) { WlanConnectionAttributes conn = wlanIface.CurrentConnection; string ssidString = Encoding.ASCII.GetString(conn.wlanAssociationAttributes.dot11Ssid.SSID).TrimEnd('\0'); if (string.Compare(ssidString, AdapterSsidEnet, StringComparison.OrdinalIgnoreCase) == 0) { UpdateConfigNode(settingsNode, @"EnetRemoteHost", @"auto:all"); UpdateConfigNode(settingsNode, @"Interface", @"ENET"); } else { UpdateConfigNode(settingsNode, @"ObdComPort", "DEEPOBDWIFI"); UpdateConfigNode(settingsNode, @"Interface", interfaceValue); } UpdateConfigNode(settingsNode, @"ObdKeepConnectionOpen", "0"); } else if (devInfo != null) { string portValue = string.Format("BLUETOOTH:{0}#{1}", devInfo.DeviceAddress, pin); UpdateConfigNode(settingsNode, @"ObdComPort", portValue); UpdateConfigNode(settingsNode, @"Interface", interfaceValue); string keepConnectionValue; switch (adapterType) { case 4: // HC04 case 5: // SPP-UART keepConnectionValue = @"1"; break; default: keepConnectionValue = @"0"; break; } UpdateConfigNode(settingsNode, @"ObdKeepConnectionOpen", keepConnectionValue); } else { return(false); } xDocument.Save(fileName); } catch (Exception) { return(false); } return(true); }
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: { //HACK: Prevents exception on WLAN connection: System.ArgumentException: Type 'NativeWifi.Wlan+WlanReasonCode' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed. int expectedSize = 0; //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); } }
internal AccessPoint(WlanInterface interfac, WlanAvailableNetwork network) { _interface = interfac; _network = network; }
public static bool PatchEdiabas(StringBuilder sr, PatchType patchType, int adapterType, string dirName, BluetoothDeviceInfo devInfo, WlanInterface wlanIface, string pin) { try { sr.AppendFormat(Resources.Strings.PatchDirectory, dirName); if (!PatchFiles(sr, dirName)) { return(false); } string configFile = Path.Combine(dirName, ConfigFileName); if (!UpdateConfigFile(configFile, adapterType, devInfo, wlanIface, pin)) { sr.Append("\r\n"); sr.Append(Resources.Strings.PatchConfigUpdateFailed); return(false); } sr.Append("\r\n"); sr.Append(Resources.Strings.PatchConfigUpdateOk); switch (patchType) { case PatchType.Istad: sr.Append("\r\n"); sr.Append(Resources.Strings.PatchInstadInfo); break; case PatchType.VasPc: sr.Append("\r\n"); sr.Append(Resources.Strings.PatchVaspcInfo); break; } } catch (Exception) { sr.Append("\r\n"); sr.Append(Resources.Strings.PatchConfigUpdateFailed); return(false); } return(true); }
public void UpdateButtonStatus() { if (InvokeRequired) { BeginInvoke((Action)UpdateButtonStatus); return; } if (_test == null) { return; } comboBoxLanguage.Enabled = !_searching && !_test.ThreadActive; buttonSearch.Enabled = !_searching && !_test.ThreadActive && ((_cli != null) || !_wlanClient.NoWifiAvailable); buttonClose.Enabled = !_searching && !_test.ThreadActive; BluetoothDeviceInfo devInfo = GetSelectedBtDevice(); WlanInterface wlanIface = GetSelectedWifiDevice(); AccessPoint ap = GetSelectedAp(); buttonTest.Enabled = buttonSearch.Enabled && ((devInfo != null) || (wlanIface != null) || (ap != null)) && !_test.ThreadActive; bool allowPatch = buttonTest.Enabled && _test.TestOk && ((wlanIface != null) || (devInfo != null)); bool allowRestore = !_searching && !_test.ThreadActive; bool bmwValid = Patch.IsValid(_ediabasDirBmw); groupBoxEdiabas.Enabled = bmwValid; buttonPatchEdiabas.Enabled = bmwValid && allowPatch; buttonRestoreEdiabas.Enabled = bmwValid && allowRestore && Patch.IsPatched(_ediabasDirBmw); bool vagValid = Patch.IsValid(_ediabasDirVag); groupBoxVasPc.Enabled = vagValid; buttonPatchVasPc.Enabled = vagValid && allowPatch && (devInfo != null); buttonRestoreVasPc.Enabled = vagValid && allowRestore && Patch.IsPatched(_ediabasDirVag); bool istadValid = Patch.IsValid(_ediabasDirIstad); groupBoxIstad.Enabled = true; buttonDirIstad.Enabled = allowRestore; buttonPatchIstad.Enabled = istadValid && allowPatch; buttonRestoreIstad.Enabled = istadValid && allowRestore && Patch.IsPatched(_ediabasDirIstad); textBoxBluetoothPin.Enabled = !_test.ThreadActive; textBoxWifiPassword.Enabled = !_test.ThreadActive; if ((devInfo != null) || (wlanIface != null)) { if (_test.TestOk && _test.ConfigPossible) { buttonTest.Text = Resources.Strings.ButtonTestConfiguration; } else { buttonTest.Text = Resources.Strings.ButtonTestCheck; } } else if (ap != null) { buttonTest.Text = Resources.Strings.ButtonTestConnect; } else { buttonTest.Text = Resources.Strings.ButtonTestCheck; } }
public AccessPoint(WlanInterface interfac, WlanAvailableNetwork network, bool ssidBroadcasted = false) { _interface = interfac; _network = network; }
// ReSharper disable once UnusedMethodReturnValue.Local public bool ExecuteTest(bool configure) { if (_testThread != null) { return(false); } CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TestOk = false; ConfigPossible = false; AccessPoint ap = _form.GetSelectedAp(); if (ap != null) { AuthRequest authRequest = new AuthRequest(ap); if (authRequest.IsPasswordRequired) { authRequest.Password = _form.WifiPassword; } ap.ConnectAsync(authRequest, true, success => { _form.BeginInvoke((Action)(() => { if (!success) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); } else { _form.PerformSearch(); } })); }); return(true); } WlanInterface wlanIface = _form.GetSelectedWifiDevice(); if (wlanIface != null) { try { IPInterfaceProperties ipProp = wlanIface.NetworkInterface.GetIPProperties(); if (ipProp == null) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } string ipAddr = (from addr in ipProp.DhcpServerAddresses where addr.AddressFamily == AddressFamily.InterNetwork select addr.ToString()).FirstOrDefault(); if (string.IsNullOrEmpty(ipAddr)) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } if (configure) { Process.Start(string.Format("http://{0}", ipAddr)); _form.UpdateStatusText(Resources.Strings.WifiUrlOk); TestOk = true; ConfigPossible = true; return(true); } _testThread = new Thread(() => { try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; TestOk = RunWifiTestRetry(ipAddr); if (TestOk) { ConfigPossible = true; } } finally { _testThread = null; _form.UpdateButtonStatus(); } }); _testThread.Start(); } catch (Exception) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return(false); } return(true); } BluetoothDeviceInfo devInfo = _form.GetSelectedBtDevice(); if (devInfo == null) { return(false); } string pin = _form.BluetoothPin; _testThread = new Thread(() => { try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; _form.UpdateStatusText(Resources.Strings.Connecting); if (!ConnectBtDevice(devInfo, pin)) { _form.UpdateStatusText(Resources.Strings.ConnectionFailed); return; } bool configRequired; TestOk = RunBtTest(configure, out configRequired); if (TestOk && configRequired) { ConfigPossible = true; } } finally { DisconnectBtDevice(); _testThread = null; _form.UpdateButtonStatus(); } }); _testThread.Start(); return(true); }