aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.WiFi
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-15 16:06:38 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-15 16:06:38 +0300
commita3aedf6ba1e0f9cc65877c88f66af6f330484086 (patch)
tree453f7b4204d27a697f09602b95ee6946e274482b /Software/Visual_Studio/Tango.WiFi
parentbbbf57af4d61e1b6d61b67418415008f58dadb3c (diff)
downloadTango-a3aedf6ba1e0f9cc65877c88f66af6f330484086.tar.gz
Tango-a3aedf6ba1e0f9cc65877c88f66af6f330484086.zip
Working on PPC WiFi connectivity!
Diffstat (limited to 'Software/Visual_Studio/Tango.WiFi')
-rw-r--r--Software/Visual_Studio/Tango.WiFi/AvailableWifiNetwork.cs87
-rw-r--r--Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs2
-rw-r--r--Software/Visual_Studio/Tango.WiFi/NetworkAuthenticationRequest.cs41
-rw-r--r--Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs2
-rw-r--r--Software/Visual_Studio/Tango.WiFi/Tango.WiFi.csproj9
-rw-r--r--Software/Visual_Studio/Tango.WiFi/WiFiManager.cs89
-rw-r--r--Software/Visual_Studio/Tango.WiFi/Wifi.cs1
7 files changed, 229 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Tango.WiFi/AvailableWifiNetwork.cs b/Software/Visual_Studio/Tango.WiFi/AvailableWifiNetwork.cs
new file mode 100644
index 000000000..c9aeb0722
--- /dev/null
+++ b/Software/Visual_Studio/Tango.WiFi/AvailableWifiNetwork.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+
+namespace Tango.WiFi
+{
+ public class AvailableWifiNetwork : ExtendedObject
+ {
+ private Wifi _wifi;
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get { return _isConnected; }
+ set { _isConnected = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _name;
+ public String Name
+ {
+ get { return _name; }
+ set { _name = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _signalStregth;
+ public double SignalStrength
+ {
+ get { return _signalStregth; }
+ set { _signalStregth = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isSecure;
+ public bool IsSecure
+ {
+ get { return _isSecure; }
+ set { _isSecure = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _hasProfile;
+ public bool HasProfile
+ {
+ get { return _hasProfile; }
+ set { _hasProfile = value; RaisePropertyChangedAuto(); }
+ }
+
+ private AccessPoint _accessPoint;
+ public AccessPoint AccessPoint
+ {
+ get { return _accessPoint; }
+ set { _accessPoint = value; RaisePropertyChangedAuto(); }
+ }
+
+ public AvailableWifiNetwork(AccessPoint accessPoint, Wifi wifi)
+ {
+ _wifi = wifi;
+ AccessPoint = accessPoint;
+ }
+
+ public NetworkAuthenticationRequest CreateAuthenticationRequest()
+ {
+ return new NetworkAuthenticationRequest(new AuthRequest(AccessPoint));
+ }
+
+ public Task<bool> Connect(NetworkAuthenticationRequest request)
+ {
+ return Task.Factory.StartNew<bool>(() =>
+ {
+ return AccessPoint.Connect(request.AuthRequest, false);
+ });
+ }
+
+ public void Forget()
+ {
+ AccessPoint.DeleteProfile();
+ HasProfile = false;
+ }
+
+ public void Disconnect()
+ {
+ _wifi.Disconnect();
+ IsConnected = false;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs b/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs
index c10ab987b..26f5c1852 100644
--- a/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs
+++ b/Software/Visual_Studio/Tango.WiFi/EapUserFactory.cs
@@ -40,7 +40,7 @@ namespace Tango.WiFi
/// </summary>
private static string GetTemplate(string name)
{
- string resourceName = string.Format("SimpleWifi.EapUserXML.{0}.xml", name);
+ string resourceName = string.Format("Tango.WiFi.EapUserXML.{0}.xml", name);
using (StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)))
{
diff --git a/Software/Visual_Studio/Tango.WiFi/NetworkAuthenticationRequest.cs b/Software/Visual_Studio/Tango.WiFi/NetworkAuthenticationRequest.cs
new file mode 100644
index 000000000..238161987
--- /dev/null
+++ b/Software/Visual_Studio/Tango.WiFi/NetworkAuthenticationRequest.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+
+namespace Tango.WiFi
+{
+ public class NetworkAuthenticationRequest : ExtendedObject
+ {
+ public AuthRequest AuthRequest { get; set; }
+
+ public bool IsUserNameRequired
+ {
+ get { return AuthRequest.IsUsernameRequired; }
+ }
+
+ public bool IsPasswordRequired
+ {
+ get { return AuthRequest.IsPasswordRequired; }
+ }
+
+ public String UserName
+ {
+ get { return AuthRequest.Username; }
+ set { AuthRequest.Username = value; RaisePropertyChangedAuto(); }
+ }
+
+ public String Password
+ {
+ get { return AuthRequest.Password; }
+ set { AuthRequest.Password = value; RaisePropertyChangedAuto(); }
+ }
+
+ public NetworkAuthenticationRequest(AuthRequest request)
+ {
+ AuthRequest = request;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs b/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs
index e85b55bba..ca9b3740b 100644
--- a/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs
+++ b/Software/Visual_Studio/Tango.WiFi/ProfileFactory.cs
@@ -71,7 +71,7 @@ namespace Tango.WiFi
/// </summary>
private static string GetTemplate(string name)
{
- string resourceName = string.Format("SimpleWifi.ProfileXML.{0}.xml", name);
+ string resourceName = string.Format("Tango.WiFi.ProfileXML.{0}.xml", name);
using (StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)))
{
diff --git a/Software/Visual_Studio/Tango.WiFi/Tango.WiFi.csproj b/Software/Visual_Studio/Tango.WiFi/Tango.WiFi.csproj
index a028b70c2..c7d345402 100644
--- a/Software/Visual_Studio/Tango.WiFi/Tango.WiFi.csproj
+++ b/Software/Visual_Studio/Tango.WiFi/Tango.WiFi.csproj
@@ -62,9 +62,12 @@
<Link>GlobalVersionInfo.cs</Link>
</Compile>
<Compile Include="AccessPoint.cs" />
+ <Compile Include="AvailableWifiNetwork.cs" />
<Compile Include="EapUserFactory.cs" />
<Compile Include="AuthRequest.cs" />
+ <Compile Include="NetworkAuthenticationRequest.cs" />
<Compile Include="ProfileFactory.cs" />
+ <Compile Include="WiFiManager.cs" />
<Compile Include="Win32\Helpers\WlanHelpers.cs" />
<Compile Include="Win32\Interop\Enums.cs" />
<Compile Include="Win32\Interop\Exceptions.cs" />
@@ -113,6 +116,12 @@
<ItemGroup>
<EmbeddedResource Include="ProfileXML\OPEN.xml" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Tango.Core\Tango.Core.csproj">
+ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
+ <Name>Tango.Core</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/Software/Visual_Studio/Tango.WiFi/WiFiManager.cs b/Software/Visual_Studio/Tango.WiFi/WiFiManager.cs
new file mode 100644
index 000000000..68f020ae0
--- /dev/null
+++ b/Software/Visual_Studio/Tango.WiFi/WiFiManager.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Tango.Core;
+
+namespace Tango.WiFi
+{
+ public class WiFiManager : ExtendedObject
+ {
+ private Wifi _wifi;
+ private Thread _scanThread;
+
+ private bool _enabled;
+ public bool Enabled
+ {
+ get { return _enabled; }
+ set
+ {
+ if (_enabled != value)
+ {
+ _enabled = value;
+ RaisePropertyChangedAuto();
+
+ if (_enabled)
+ {
+ Start();
+ }
+ }
+ }
+ }
+
+ public ObservableCollection<AvailableWifiNetwork> AvailableWifiNetworks { get; set; }
+
+ public WiFiManager()
+ {
+ _wifi = new Wifi();
+ AvailableWifiNetworks = new ObservableCollection<AvailableWifiNetwork>();
+ AvailableWifiNetworks.EnableCrossThreadOperations();
+ }
+
+ public void Start()
+ {
+ Enabled = true;
+ _scanThread = new Thread(ScanThreadMethod);
+ _scanThread.IsBackground = true;
+ _scanThread.Start();
+ }
+
+ private void ScanThreadMethod()
+ {
+ while (_enabled)
+ {
+ var accessPoints = _wifi.GetAccessPoints().OrderByDescending(ap => ap.SignalStrength).ToList();
+
+ AvailableWifiNetworks.Where(x => !accessPoints.Exists(y => y.Name == x.Name)).ToList().ForEach(x => AvailableWifiNetworks.Remove(x));
+
+ foreach (AccessPoint ap in accessPoints)
+ {
+ var network = AvailableWifiNetworks.FirstOrDefault(x => x.Name == ap.Name);
+
+ if (network == null)
+ {
+ network = new AvailableWifiNetwork(ap, _wifi);
+ AvailableWifiNetworks.Add(network);
+ }
+
+ network.AccessPoint = ap;
+ network.Name = ap.Name;
+ network.IsConnected = ap.IsConnected;
+ network.SignalStrength = ap.SignalStrength;
+ network.IsSecure = ap.IsSecure;
+ network.HasProfile = ap.HasProfile;
+ }
+
+ Thread.Sleep(5000);
+ }
+ }
+
+ public void Stop()
+ {
+ Enabled = false;
+ _scanThread = null;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.WiFi/Wifi.cs b/Software/Visual_Studio/Tango.WiFi/Wifi.cs
index 8929eacf1..ea6aaa285 100644
--- a/Software/Visual_Studio/Tango.WiFi/Wifi.cs
+++ b/Software/Visual_Studio/Tango.WiFi/Wifi.cs
@@ -41,6 +41,7 @@ namespace Tango.WiFi
foreach (WlanInterface wlanIface in _client.Interfaces)
{
+ wlanIface.Scan();
WlanAvailableNetwork[] rawNetworks = wlanIface.GetAvailableNetworkList(0);
List<WlanAvailableNetwork> networks = new List<WlanAvailableNetwork>();