private bool ConnectWifiDevice(string comPort) { try { foreach (WlanInterface wlanIface in _wlanClient.Interfaces) { if (wlanIface.InterfaceState == WlanInterfaceState.Connected) { WlanConnectionAttributes conn = wlanIface.CurrentConnection; string ssidString = Encoding.ASCII.GetString(conn.wlanAssociationAttributes.dot11Ssid.SSID).TrimEnd('\0'); if (string.Compare(ssidString, AdapterSsidElm, StringComparison.OrdinalIgnoreCase) == 0) { return(true); } } } } catch (Exception) { // ignored } try { foreach (AccessPoint ap in _wifi.GetAccessPoints()) { if (!ap.IsConnected) { if (string.Compare(ap.Name, AdapterSsidElm, StringComparison.OrdinalIgnoreCase) == 0) { AuthRequest authRequest = new AuthRequest(ap); ap.ConnectAsync(authRequest, true, success => { _form.BeginInvoke((Action)(() => { if (!success) { _form.UpdateTestStatusText("Connection faild"); } else { _form.UpdateTestStatusText("Wifi connected"); Thread.Sleep(1000); ExecuteTest(true, comPort); } })); }); return(false); } } } } catch (Exception) { // ignored } _form.UpdateTestStatusText("No WiFi device found"); return(false); }
private void AddWifiAdapters(ListView listView) { try { foreach (WlanInterface wlanIface in _wlanClient.Interfaces) { if (wlanIface.InterfaceState == WlanInterfaceState.Connected) { WlanConnectionAttributes conn = wlanIface.CurrentConnection; string ssidString = Encoding.ASCII.GetString(conn.wlanAssociationAttributes.dot11Ssid.SSID).TrimEnd('\0'); if (string.Compare(ssidString, Patch.AdapterSsidEnet, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ssidString, Patch.AdapterSsidElm, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ssidString, Patch.AdapterSsidEspLink, StringComparison.OrdinalIgnoreCase) == 0 || ssidString.StartsWith(Patch.AdapterSsidEnetLink, StringComparison.OrdinalIgnoreCase) || ssidString.StartsWith(Patch.AdapterSsidModBmw, StringComparison.OrdinalIgnoreCase) ) { string bssString = conn.wlanAssociationAttributes.Dot11Bssid.ToString(); ListViewItem listViewItem = new ListViewItem(new[] { bssString, conn.profileName }) { Tag = wlanIface }; listView.Items.Add(listViewItem); } } } } catch (Exception) { // ignored } try { foreach (AccessPoint ap in _wifi.GetAccessPoints()) { if (!ap.IsConnected) { if (string.Compare(ap.Name, Patch.AdapterSsidEnet, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ap.Name, Patch.AdapterSsidElm, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ap.Name, Patch.AdapterSsidEspLink, StringComparison.OrdinalIgnoreCase) == 0 || ap.Name.StartsWith(Patch.AdapterSsidEnetLink, StringComparison.OrdinalIgnoreCase) || ap.Name.StartsWith(Patch.AdapterSsidModBmw, StringComparison.OrdinalIgnoreCase) ) { ListViewItem listViewItem = new ListViewItem(new[] { Resources.Strings.DisconnectedAdapter, ap.Name }) { Tag = ap }; listView.Items.Add(listViewItem); } } } } catch (Exception) { // ignored } }
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); } 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); } } else if (devInfo != null) { 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); }
// 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); }