Beispiel #1
0
 private string GetStringForSSID(Wlan.Dot11Ssid ssid)
 {
     return(Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }
Beispiel #2
0
 /// <summary>
 /// Connects (associates) to the specified wireless network, returning either on a success to connect
 /// or a failure.
 /// </summary>
 /// <param name="connectionMode"></param>
 /// <param name="bssType"></param>
 /// <param name="profile"></param>
 /// <param name="connectTimeout"></param>
 /// <returns></returns>
 public bool ConnectSynchronously(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags, int connectTimeout)
 {
     queueEvents = true;
     try
     {
         Connect(connectionMode, bssType, ssid, flags);
         while (queueEvents && eventQueueFilled.WaitOne(connectTimeout, true))
         {
             lock (eventQueue)
             {
                 while (eventQueue.Count != 0)
                 {
                     object e = eventQueue.Dequeue();
                     if (e is WlanConnectionNotificationEventData)
                     {
                         WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
                         // Check if the conditions are good to indicate either success or failure.
                         if (wlanConnectionData.notifyData.notificationSource == Wlan.WlanNotificationSource.ACM)
                         {
                             switch ((Wlan.WlanNotificationCodeAcm)wlanConnectionData.notifyData.notificationCode)
                             {
                             case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
                                 if (wlanConnectionData.connNotifyData.dot11Ssid.SSID.ToString() == ssid.SSID.ToString())
                                 {
                                     return(true);
                                 }
                                 break;
                             }
                         }
                         break;
                     }
                 }
             }
         }
     }
     finally
     {
         queueEvents = false;
         eventQueue.Clear();
     }
     return(false);                // timeout expired and no "connection complete"
 }
Beispiel #3
0
        public void wlanConnectionChangeHandler(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
        {
            string msg     = String.Empty;
            String device1 = String.Empty;
            String device2 = String.Empty;

            switch (notifyData.notificationSource)
            {
            case Wlan.WlanNotificationSource.ACM:

                switch ((Wlan.WlanNotificationCodeAcm)notifyData.notificationCode)
                {
                case Wlan.WlanNotificationCodeAcm.ConnectionStart:
                    msg = "ConnectionStart";
                    break;

                case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
                    msg = "ConnectionComplete";
                    //WlanClient client = new WlanClient();
                    foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
                    {
                        Wlan.WlanAssociationAttributes conAttributes = wlanIface.CurrentConnection.wlanAssociationAttributes;
                        Wlan.Dot11Ssid ssid = conAttributes.dot11Ssid;
                        try
                        {
                            device1 = (String)list2.Items[0];
                            device2 = (String)list2.Items[1];
                        }
                        catch (Exception e)
                        {
                            // If for some reason the device name is not populated then initialize it to NULL .
                            device1 = null;
                            device2 = null;
                        }
                        if (device1 != null && device2 != null)
                        {
                            if (GetStringForSSID(ssid) != device1)
                            {
                                if (GetStringForSSID(ssid) != device2)
                                {
                                    msg = "MainServices (connectionChange Handler): Wireless connection is BROKEN ! Locking the system . ";
                                    log.dispatchLogMessage(msg);
                                    startWireless = 2;
                                    LockWorkStation();
                                    unregisterWlanListener();
                                }
                            }
                        }
                        break;
                    }

                    break;

                case Wlan.WlanNotificationCodeAcm.Disconnecting:
                    msg = "Disconnecting";
                    break;

                case Wlan.WlanNotificationCodeAcm.Disconnected:
                    msg = "Disconnected";
                    break;

                default:
                    msg = "unknown notificationCode =" + notifyData.notificationCode;
                    break;
                }
                //MessageBox.Show(msg + " for profile:" + connNotifyData.profileName);
                break;

            default:
                //MessageBox.Show("irrelevant notification. Ignore");
                break;
            }
        }
Beispiel #4
0
 public static string GetSsidString(Wlan.Dot11Ssid org)
 {
     return(Encoding.ASCII.GetString(org.SSID, 0, (int)org.SSIDLength));
 }
Beispiel #5
0
 public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType,
                                              bool securityEnabled)
 {
     return(_wlanInterface.GetNetworkBssList(ssid, bssType, securityEnabled));
 }
Beispiel #6
0
        private void wifi_checkBox_Checked(object sender, RoutedEventArgs e)
        {
            if (wifi_checkBox.IsChecked == true)
            {
                //punt info in list grid
                var gridView = new GridView();
                this.wifi_listView.View = gridView;

                gridView.Columns.Add(new GridViewColumn
                {
                    Header = "Accesspoints",
                    DisplayMemberBinding = new System.Windows.Data.Binding("AccesPoint")
                });
                gridView.Columns.Add(new GridViewColumn
                {
                    Header = "Signal Strength",
                    DisplayMemberBinding = new System.Windows.Data.Binding("Signal")
                });
                gridView.Columns.Add(new GridViewColumn
                {
                    Header = "BSSType",
                    DisplayMemberBinding = new System.Windows.Data.Binding("BSSType")
                });
                gridView.Columns.Add(new GridViewColumn
                {
                    Header = "MAC",
                    DisplayMemberBinding = new System.Windows.Data.Binding("MAC")
                });
                gridView.Columns.Add(new GridViewColumn
                {
                    Header = "RSSID",
                    DisplayMemberBinding = new System.Windows.Data.Binding("RSSID")
                });



                NativeWifi.WlanClient client = new NativeWifi.WlanClient();

                try
                {
                    wifi_password_label.Content = "";

                    foreach (NativeWifi.WlanClient.WlanInterface wlanIface in client.Interfaces)
                    {
                        Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList();

                        foreach (Wlan.WlanBssEntry network in wlanBssEntries)
                        {
                            int    rss     = network.rssi;
                            byte[] macAddr = network.dot11Bssid;
                            string tMac    = "";

                            for (int i = 0; i < macAddr.Length; i++)
                            {
                                tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();
                            }
                            Wlan.Dot11Ssid ssid = network.dot11Ssid;

                            string networkName = System.Text.Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
                            uint   signal      = network.linkQuality;
                            string bssType     = network.dot11BssType + "";
                            string MAC         = tMac;
                            string RSSID       = rss.ToString();

                            // Populate list
                            wifi_listView.Items.Add(new wifiConnect {
                                AccesPoint = networkName, Signal = signal, BSSType = bssType, MAC = MAC, RSSID = RSSID
                            });
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (wifi_checkBox.IsChecked == false)
            {
                wifi_password_label.Content = "Please select connection type";
            }
        }
Beispiel #7
0
        void WlanScanThread()
        {
            while (tourRecording)
            {
                if (!validGpsSignal)
                {
                    context.MainForm.SetStatusBar("Warte auf gültiges GPS Signal...");
                    while (!validGpsSignal)
                    {
                        Thread.Sleep(100);
                    }
                }
                double signalAge = (DateTime.Now - gpsLlTimestamp).TotalSeconds;
                while (signalAge > 10)
                {
                    context.MainForm.SetStatusBar(String.Format("Letztes GPS Signal ist {0} Sekunden her. Warte auf Erneuerung...", (int)signalAge));
                    Thread.Sleep(1000);
                    signalAge = (DateTime.Now - gpsLlTimestamp).TotalSeconds;
                }

                scanComplete = false;
                usableInterface.Scan();
                while (!scanComplete)
                {
                    Thread.Sleep(100);
                }

                Invoke((MethodInvoker) delegate { listView1.Items.Clear(); });
                int numAps = 0;
                Wlan.WlanAvailableNetwork[] networks = usableInterface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles | Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                {
                    Wlan.Dot11Ssid      ssid       = network.dot11Ssid;
                    Wlan.WlanBssEntry[] bssEntries = usableInterface.GetNetworkBssList(ssid, network.dot11BssType, network.securityEnabled);

                    foreach (Wlan.WlanBssEntry bss in bssEntries)
                    {
                        numAps++;
                        string bssid       = BitConverter.ToString(bss.dot11Bssid);
                        string ssidEncoded = BitConverter.ToString(network.dot11Ssid.SSID);
                        this.Invoke(wifiFoundDelegate, bssid, Encoding.UTF8.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength), bss.rssi, network.dot11BssType, network.dot11DefaultAuthAlgorithm);

                        lock (lockVictim)
                        {
                            tourStreamWriter.WriteLine("NETWORK;{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};" +
                                                       "{12};{13};{14};{15};{16};{17};{18};{19};{20};{21};{22};{23};{24};{25};{26};{27}",
                                                       DateTime.Now.Ticks, DateTime.Now.ToString(), lon, lat, bssid, (int)network.dot11BssType,
                                                       (int)network.dot11DefaultAuthAlgorithm, (int)network.dot11DefaultCipherAlgorithm,
                                                       network.dot11Ssid.SSIDLength, ssidEncoded, (int)network.flags, network.morePhyTypes,
                                                       network.networkConnectable, network.securityEnabled, network.wlanSignalQuality,
                                                       bss.beaconPeriod, bss.capabilityInformation, bss.chCenterFrequency,
                                                       (int)bss.dot11BssPhyType, (int)bss.dot11BssType, bss.hostTimestamp, bss.ieOffset,
                                                       bss.ieSize, bss.inRegDomain, bss.phyId, bss.rssi, bss.timestamp, (int)bss.wlanRateSet.GetRateInMbps(0)
                                                       );
                        }
                    }
                }
                lock (lockVictim)
                {
                    tourStreamWriter.Flush();
                }
                context.MainForm.SetStatusBar(String.Format("{0} Services entdeckt.", numAps));
            }
            scanThreadEnded = true;
            context.MainForm.SetStatusBar("Scan angehalten!");
        }
Beispiel #8
0
 static string GetStringForSSID(Wlan.Dot11Ssid ssid)
 {
     return(Encoding.ASCII.GetString(ssid.SSID,
                                     0, (int)ssid.SSIDLength));
 }
Beispiel #9
0
 /// <summary>
 /// Gets the string representation of a given Wi-Fi network's SSID from
 /// the reference to the instance of
 /// <see cref="T:NativeWifi.Wlan.Dot11Ssid" /> specified in the
 /// <see cref="ssid" /> parameter.
 /// </summary>
 /// <param name="ssid">
 /// Reference to an instance of
 /// <see cref="T:NativeWifi.Wlan.Dot11Ssid" /> representing the SSID of
 /// the desired Wi-Fi network.
 /// </param>
 /// <returns>
 /// String representation of the SSID of the Wi-Fi network referenced by
 /// the <see cref="ssid" /> parameter.
 /// </returns>
 /// <remarks>This method does not seem to be currently called; however, I
 /// forget where it had been used, so until I remember, I won't delete it
 /// or comment it out.
 /// </remarks>
 private static string GetStringForSSID(Wlan.Dot11Ssid ssid)
 {
     // Return the SSID property of the ssid structure, encoded
     // in ASCII
     return(Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }
Beispiel #10
0
 public string GetWlanNameBySsid(Wlan.Dot11Ssid ssid)
 {
     return(Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }
Beispiel #11
0
        void tmrStatusUpdate_Tick(object sender, EventArgs e)
        {
            List <string> alert_msgs = new List <string>();

            #region 1
            if (_droneClient.IsConnected)
            {
                if (ConnectedMessageSent == false)
                {
                    Debug("Connected");
                    ConnectedMessageSent = true;
                }
            }
            #endregion

            #region // wifi signal strength
            if (wlan != null)
            {
                double signal_strength = 0.0d;

                try
                {
                    drone_network = wlan.Interfaces[0].CurrentConnection.wlanAssociationAttributes;
                    Wlan.Dot11Ssid _ssid = drone_network.dot11Ssid;
                    string         SSID  = GetStringForSSID(_ssid);
                    signal_strength = drone_network.wlanSignalQuality;

                    this.Details.DroneWiFiName      = SSID;
                    this.Details.WiFiSignalStrength = signal_strength;

                    string alert = "WARNING! WiFi signal is below 25%. Navigate back now!";

                    if (this.Details.WiFiSignalStrength < 25)
                    {
                        if (!alert_msgs.Contains(alert))
                        {
                            alert_msgs.Add(alert);
                        }
                    }
                    else
                    {
                        alert_msgs.Remove(alert);
                    }
                }
                catch { }
            }
            #endregion

            #region 2
            if (_navigationData != null)
            {
                // battery
                this.Details.BatteryLevel = (int)this._navigationData.Battery.Percentage;
                string alert = "WARNING! Battery is below 25%";

                if (this._navigationData.Battery.Percentage < 25)
                {
                    if (!alert_msgs.Contains(alert))
                    {
                        alert_msgs.Add(alert);
                    }
                }
                else
                {
                    alert_msgs.Remove(alert);
                }

                //this.attitudeControl.SetAttitudeIndicatorParameters(_navigationData.Pitch, -_navigationData.Roll);
                this.Details.Pitch = _navigationData.Pitch;
                this.Details.Roll  = -_navigationData.Roll;

                if (_navigationData.Yaw > 0)
                {
                    //this.headingControl.SetHeadingIndicatorParameters(Convert.ToInt32(_navigationData.Yaw));

                    //rotate_y.Angle = -_navigationData.Yaw;
                    this.Details.Yaw = _navigationData.Yaw;
                    //this.Details.RotateY = -_navigationData.Yaw;
                }
                else
                {
                    float y = (360 + _navigationData.Yaw);

                    //this.headingControl.SetHeadingIndicatorParameters(y);

                    this.Details.Yaw = y;
                    //this.Details.RotateY = -y;
                }

                this.Details.RotateX = -_navigationData.Pitch;
                this.Details.RotateZ = _navigationData.Roll;

                this.Details.Altitude = _navigationData.Altitude;

                UpdateAttitudeIndicator((int)_navigationData.Pitch, (int)_navigationData.Roll);

                //this.altimeterControl.SetAlimeterParameters((int)_navigationData.Altitude);

                Console.WriteLine("Pitch: {0}, Roll: {1}, Yaw: {2}", this.Details.Pitch, this.Details.Roll, this.Details.Yaw);
            }
            #endregion

            if (alert_msgs.Count > 0)
            {
                string alerts = string.Empty;
                alerts = string.Join("\r\n", alert_msgs.ToArray());
                ShowAlertStatus(alerts, true);
            }
            else
            {
                ShowAlertStatus(string.Empty, false);
            }
        }
Beispiel #12
0
 private string GetSsidString(Wlan.Dot11Ssid ssid)
 {
     return(Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }
Beispiel #13
0
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid,
                     Wlan.WlanConnectionFlags flags)
 {
     _wlanInterface.Connect(connectionMode, bssType, ssid, flags);
 }
Beispiel #14
0
 private string GetStringForSSID(Wlan.Dot11Ssid dot11Ssid)
 {
     return(Encoding.ASCII.GetString(dot11Ssid.SSID, 0, (int)dot11Ssid.SSIDLength));
 }
Beispiel #15
0
 //ssid转为字符串
 private static string SsidToString(Wlan.Dot11Ssid ssid)
 {
     return(Encoding.Default.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }
Beispiel #16
0
 private string GetProfileName(Wlan.Dot11Ssid value)
 {
     return(Encoding.UTF8.GetString(value.SSID, 0, (int)value.SSIDLength));
 }
Beispiel #17
0
        public static string GetConnectedSsid()
        {
            Mutex mut = new Mutex();


            //WlanClient wlan = null;
            Collection <String> connectedSsids = new Collection <string>();
            string last = "Not set";

            try
            {
                mut.WaitOne();
                //wlan = new WlanClient();
                if (_wlan.Interfaces != null)
                {
                    foreach (WlanClient.WlanInterface wlanInterface in _wlan.Interfaces)
                    {
                        Wlan.Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid;
                        connectedSsids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength)));
                        last = new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength));
                    }
                }
                //wlan = null;
            }
            catch (Exception)
            {
                throw new ApplicationException("GetConnectedSsid Failed");
            }
            finally
            { mut.ReleaseMutex(); }

            return(last);

            //RaiseIoComsEvent("Getting SSID...");
            //System.Diagnostics.Process p = new System.Diagnostics.Process();
            //p.StartInfo.FileName = "netsh.exe";
            //p.StartInfo.Arguments = "wlan show interfaces";
            //p.StartInfo.UseShellExecute = false;
            //p.StartInfo.RedirectStandardOutput = true;
            //p.Start();
            //string s;
            //string s1;
            //try
            //{
            //    s = p.StandardOutput.ReadToEnd();
            //    s1 = s.Substring(s.IndexOf("SSID"));
            //    s1 = s1.Substring(s1.IndexOf(":"));
            //    s1 = s1.Substring(2, s1.IndexOf("\n")).Trim();

            //    string s2 = s.Substring(s.IndexOf("Signal"));
            //    s2 = s2.Substring(s2.IndexOf(":"));
            //    s2 = s2.Substring(2, s2.IndexOf("\n")).Trim();
            //}
            //catch (Exception ex)
            //{
            //    //RaiseIoComsEvent("SSID: Not a PMC-8 SSID.");
            //    s1 = "Not Connected";
            //}


            ////labelStatus.Text = "WIFI connected to " + s1 + "  " + s2;
            //p.WaitForExit();
            ////RaiseIoComsEvent("SSID: s1");
            //return s1;
        }
Beispiel #18
0
 /// <summary>
 /// Connects to the specified wireless network.
 /// </summary>
 /// <remarks>
 /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
 /// </remarks>
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags)
 {
     Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters();
     connectionParams.wlanConnectionMode = connectionMode;
     connectionParams.dot11SsidPtr       = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
     Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false);
     connectionParams.dot11BssType = bssType;
     connectionParams.flags        = flags;
     Connect(connectionParams);
     Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType());
     Marshal.FreeHGlobal(connectionParams.dot11SsidPtr);
 }
Beispiel #19
0
 public string GetStringForSSID(Wlan.Dot11Ssid ssid)//字符串转换工具,不用管它。
 {
     return(Encoding.UTF8.GetString(ssid.SSID, 0, (int)ssid.SSIDLength));
 }