Exemplo n.º 1
0
        public IEnumerable<NetworkData> GetNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();
            IEnumerable<NdisWlanBssidEx> exArray = Ndis.QueryBssidList(_interface);

            //Gets the connected AP BSSID
            byte[] connectedBssid = Ndis.QueryConnected(_interface);
            if (exArray != null)
            {
                foreach (NdisWlanBssidEx ex in exArray)
                {
                    NetworkData data2 = new NetworkData(ex.MacAddress);
                    data2.Channel = Utilities.ConvertToChannel(ex.Configuration.DSConfig);
                    NetworkData item = data2;
                    if ((ex.IELength <= ex.IEs.Length) && (ex.IELength > 28))
                    {
                        bool foundNIes = false;
                        for (int i = 0; i < (ex.IELength/* - 29*/); i++)
                        {
                            if (((ex.IEs[i] == 0x2D) && (ex.IEs[i + 1] == 26)) && ((ex.IEs[i + 28] == 0x3D) && (ex.IEs[(i + 28) + 1] == 0x16)))
                            {
                                foundNIes = true;
                                break;
                            }
                        }
                        if (foundNIes)
                        {
                            item.IsTypeN = true;
                            item.NSettings = IeParser.Parse(ex.IEs);
                            if (item.NSettings != null)
                            {
                                //Add the extended 802.11N rates
                                item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                                item.Rates.Sort();
                            }
                        }
                    }
                    Utilities.ConvertToMbs(ex.SupportedRates, item.Rates, item.IsTypeN);
                    item.Rssi = ex.Rssi;
                    item.SignalQuality = 0;
                    string str = Encoding.ASCII.GetString(ex.Ssid, 0, (int)ex.SsidLength);
                    if (str != null)
                    {
                        str = str.Trim();
                    }
                    item.Ssid = str;
                    item.Privacy = Ndis.GetPrivacyString(ex);
                    item.NetworkType = Utilities.FindValueString(Utilities.InfrastructureText, (int)ex.InfrastructureMode);

                    //Check to see if this AP is the connected one
                    item.Connected = item.MyMacAddress.Bytes.SequenceEqual(connectedBssid);

                    list.Add(item);
                }
            }
            return list;
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            NetworkData data = obj as NetworkData;

            if (data == null)
            {
                return(false);
            }
            return(data.MyMacAddress.Equals(MyMacAddress));
        }
Exemplo n.º 3
0
        public AccessPoint(NetworkData dataItem)
        {
            Index        = _counter++;
            Graph        = true;
            Highlight    = false;
            _networkData = new List <NetworkData>(MaxDataPoints);
            _networkData.Add(dataItem);

            _orignalData      = (NetworkData)dataItem.Clone();
            Timestamp         = dataItem.MyTimestamp;
            LastSeenTimestamp = dataItem.MyTimestamp;
        }
        public IEnumerable<NetworkData> GetNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();
            IEnumerable<NdisWlanBssidEx> exArray = Ndis.QueryBssidList(_interface);

            //Gets the connected AP BSSID
            byte[] connectedBssid = Ndis.QueryConnected(_interface);
            if (exArray != null)
            {
                foreach (NdisWlanBssidEx ex in exArray)
                {
                    NetworkData data2 = new NetworkData(ex.MacAddress);
                    data2.Channel = Utilities.ConvertToChannel(ex.Configuration.DSConfig);
                    NetworkData item = data2;

                    if (item.MyMacAddress.MyValue == 0)
                        continue;

                    if ((ex.IELength <= ex.IEs.Length) && (ex.IELength > 28))
                    {
                        byte[] ies = new byte[ex.IELength];
                        Array.Copy(ex.IEs, 0, ies, 0, ex.IELength);

                            item.NSettings = IeParser.Parse(ies);
                            item.IsTypeN = item.NSettings != null;
                            if (item.NSettings != null)
                            {
                                //Add the extended 802.11N rates
                                item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                                item.Rates.Sort();
                            }
                        //}
                    }
                    Utilities.ConvertToMbs(ex.SupportedRates, item.Rates, item.IsTypeN);
                    item.Rssi = ex.Rssi;
                    item.SignalQuality = 0;
                    string str = Encoding.ASCII.GetString(ex.Ssid, 0, (int)ex.SsidLength);
                    if (str != null)
                    {
                        str = str.Trim();
                    }
                    item.Ssid = str;
                    item.Security = Ndis.GetSecurityString(ex);
                    item.NetworkType = Utilities.FindValueString(Utilities.InfrastructureText, (int)ex.InfrastructureMode);

                    //Check to see if this AP is the connected one
                    item.Connected = item.MyMacAddress.Bytes.SequenceEqual(connectedBssid);

                    list.Add(item);
                }
            }
            return list;
        }
Exemplo n.º 5
0
        public AccessPoint(NetworkData dataItem)
        {
            Index = _counter++;
            Graph = true;
            Highlight = false;
            _networkData = new List<NetworkData>(MaxDataPoints);
            _networkData.Add(dataItem);

            _orignalData = (NetworkData)dataItem.Clone();
            Timestamp = dataItem.MyTimestamp;
            LastSeenTimestamp = dataItem.MyTimestamp;
        }
Exemplo n.º 6
0
        public static Waypoint ConvertNetworkDataToWaypoint(NetworkData data, GpsData gpsData)
        {
            Waypoint outpoint = new Waypoint();

            outpoint.Latitude = gpsData.Latitude;
            outpoint.Longitude = gpsData.Longitude;

            outpoint.Elevation = gpsData.Altitude;
            outpoint.Time = string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                          new object[]
                                              {
                                                  gpsData.SatelliteTime.Year,
                                                  gpsData.SatelliteTime.Month.ToString("D2"),
                                                  gpsData.SatelliteTime.Day.ToString("D2"),
                                                  gpsData.SatelliteTime.Hour.ToString("D2"),
                                                  gpsData.SatelliteTime.Minute.ToString("D2"),
                                                  gpsData.SatelliteTime.Second,
                                                  gpsData.SatelliteTime.Millisecond
                                              });

            outpoint.GeoidHeight = gpsData.GeoidSeperation;
            //The SSID must be cleaned
            outpoint.Name = XmlHelper.CleanString(data.Ssid) + " [" + data.MyMacAddress + "]";

            outpoint.Cmt = gpsData.Speed.ToString(CultureInfo.InvariantCulture.NumberFormat);

            //outpoint.Description = string.Format(
            //    "{0}\r\n[{1}]\r\nRSSI: {2} dB\r\nQuality: {3}%\r\nChannel {4}\r\nSpeed (kph): {5}\r\n{6}",
            //    new object[]
            //        {
            //            XmlHelper.CleanString(data.Ssid), data.MyMacAddress.ToString(), data.Rssi, data.SignalQuality,
            //            data.Channel, gpsData.Speed,
            //            gpsData.SatelliteTime.ToString()
            //        });

            outpoint.Fix = gpsData.FixType;
            outpoint.SatCount = gpsData.SatellitesUsed;
            outpoint.Hdop = gpsData.Hdop;
            outpoint.Vdop = gpsData.Vdop;
            outpoint.Pdop = gpsData.Pdop;

            outpoint.Extensions.MacAddress = data.MyMacAddress.ToString();
            outpoint.Extensions.Ssid = XmlHelper.CleanString(data.Ssid);
            outpoint.Extensions.Rssi = data.Rssi;
            outpoint.Extensions.Channel = data.Channel;
            outpoint.Extensions.Privacy = data.Privacy;
            outpoint.Extensions.SignalQuality = data.SignalQuality;
            outpoint.Extensions.NetworkType = data.NetworkType;
            outpoint.Extensions.Rates = data.SupportedRates;

            return outpoint;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Clones and then adds data to this AP
        /// </summary>
        /// <param name="data"></param>
        public void AddData(NetworkData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            lock (MyNetworkDataCollection)
            {
                MyNetworkDataCollection.Add((NetworkData)data.Clone());
            }
            Timestamp = data.MyTimestamp;

            //Remove old data, if any
            DeleteOldData(Timestamp - TimeSpan.FromMinutes(8));
        }
Exemplo n.º 8
0
        public object Clone()
        {
            NetworkData data = new NetworkData(MyMacAddress.Bytes)
            {
                NetworkType   = NetworkType,
                Security      = Security,
                Rssi          = Rssi,
                SignalQuality = SignalQuality,
                Ssid          = Ssid,
                Channel       = Channel,
                MyTimestamp   = MyTimestamp,
                NSettings     = NSettings,
                IsTypeN       = IsTypeN,
                Connected     = Connected
            };

            foreach (double num in Rates)
            {
                data.Rates.Add(num);
            }
            return(data);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Clones and then adds data to this AP
        /// </summary>
        /// <param name="data">The data to add</param>
        /// <param name="gpsData">The GPS data to go with</param>
        public void AddData(NetworkData data, GpsData gpsData)
        {
            if (data == null) throw new ArgumentNullException("data");
            if (gpsData == null) throw new ArgumentNullException("gpsData");

            NetworkData nd2 = (NetworkData)data.Clone();

            lock (MyNetworkDataCollection)
            {
                //Check if the RSSI had been consistently stronger and stronger than the strongest reading before updating the GPS data
                //This means if this reading and the last reading are both higher than 2 readings ago, update the GPS data
                if ((MyNetworkDataCollection.Count > 1 && nd2.Rssi > MyNetworkDataCollection.Max(nd => nd.Rssi) &&
                     (nd2.Rssi > MyNetworkDataCollection[MyNetworkDataCollection.Count - 2].Rssi &&
                      MyNetworkDataCollection[MyNetworkDataCollection.Count - 1].Rssi >
                      MyNetworkDataCollection[MyNetworkDataCollection.Count - 2].Rssi)) ||
                    (nd2.Rssi > -100 && GpsData.SatelliteTime == DateTime.MinValue))
                {
                    //Update GPS data
                    GpsData = gpsData;
                }
                //Add the data
                MyNetworkDataCollection.Add(nd2);
            }
            Timestamp = nd2.MyTimestamp;
            LastSeenTimestamp = nd2.MyTimestamp;

            //Remove old data, if any
            DeleteOldData(Timestamp - TimeSpan.FromMinutes(8));
        }
Exemplo n.º 10
0
 public object Clone()
 {
     NetworkData data = new NetworkData(MyMacAddress.Bytes)
     {
         NetworkType = NetworkType,
         Privacy = Privacy,
         Rssi = Rssi,
         SignalQuality = SignalQuality,
         Ssid = Ssid,
         Channel = Channel,
         MyTimestamp = MyTimestamp,
         NSettings = NSettings,
         IsTypeN = IsTypeN,
         Connected = Connected
     };
     foreach (double num in Rates)
     {
         data.Rates.Add(num);
     }
     return data;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Clones and then adds data to this AP
        /// </summary>
        /// <param name="data"></param>
        public void AddData(NetworkData data)
        {
            if (data == null) throw new ArgumentNullException("data");
            lock (MyNetworkDataCollection)
            {
                MyNetworkDataCollection.Add((NetworkData) data.Clone());
            }
            Timestamp = data.MyTimestamp;

            //Remove old data, if any
            DeleteOldData(Timestamp - TimeSpan.FromMinutes(8));
        }
 public ScanCompleteEventArgs(NetworkData[] data, GpsData gpsData)
 {
     Data = data;
     GpsData = gpsData;
 }
        public IEnumerable<NetworkData> GetNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();

            //If the interface is null, return nothing
            if(_interface == null) return list;

            IEnumerable<Wlan.WlanBssEntryN> networkBssList = null;
            IEnumerable<Wlan.WlanAvailableNetwork> availableNetworkList = null;

            try
            {
                networkBssList = _interface.GetNetworkBssList();
                availableNetworkList = _interface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles);
            }
            catch (NullReferenceException)
            {
                //Hopefully the call will succeed next time.
            }
            if ((networkBssList != null) && (availableNetworkList != null))
            {
                //Get connected to AP
                Wlan.WlanAssociationAttributes connectedAP = new Wlan.WlanAssociationAttributes();
                try
                {
                    if (_interface.CurrentConnection.isState == Wlan.WlanInterfaceState.Connected)
                    {
                        connectedAP = _interface.CurrentConnection.wlanAssociationAttributes;
                    }
                }
                catch (NullReferenceException) { /*Hopefully it will work next time*/ }

                Wlan.WlanAvailableNetwork foundNetwork = new Wlan.WlanAvailableNetwork();
                foreach (Wlan.WlanBssEntryN entry in networkBssList)
                {
                    string ssid = Encoding.ASCII.GetString(entry.BaseEntry.dot11Ssid.SSID, 0,
                                                           (int)entry.BaseEntry.dot11Ssid.SSIDLength);

                    if (FindNetwork(ssid, availableNetworkList, ref foundNetwork))
                    {
                        NetworkData item = new NetworkData(entry.BaseEntry.dot11Bssid);

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);
                        if (entry.NSettings != null)
                        {
                            item.NSettings = new IeParser.TypeNSettings(entry.NSettings);

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }

                        item.IsTypeN = entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht;
                        int num = Utilities.ComputeRssi(entry.BaseEntry.linkQuality);
                        item.Rssi = (entry.BaseEntry.rssi > num) ? entry.BaseEntry.rssi : num;
                        if (item.Rssi > 0)
                            item.Rssi -= 256; // Sometimes there is an issure where the RSSI will become overly positive
                                              // (e.g. going from -96 to +160), so subtracting 256 will fix it.
                        item.Ssid = ssid;
                        item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);

                        if (foundNetwork.numberOfBssids > 1)
                        {
                            // More than 1 network with the same SSID
                            // Get all BSSes with the SSID
                            Wlan.WlanBssEntryN[] secureNetworks = _interface.GetNetworkBssList(ssid, true);
                            Wlan.WlanBssEntryN[] openNetworks = _interface.GetNetworkBssList(ssid, false);
                            if (secureNetworks.Count(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)) > 0)
                            {
                                item.Privacy = _interface.GetPrivacyString(secureNetworks.First(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)).IEs, true);
                            }
                            else if (openNetworks.Count(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)) > 0)
                            {
                                item.Privacy = "None";
                            }
                        }
                        else
                        {
                            item.Privacy = Utilities.CreatePrivacyString(foundNetwork.dot11DefaultAuthAlgorithm,
                                                                         foundNetwork.dot11DefaultCipherAlgorithm);
                        }
                        item.SignalQuality = foundNetwork.wlanSignalQuality;

                        //Check to see if this AP is the connected one
                        item.Connected = item.MyMacAddress.CompareToPhysicalAddress(connectedAP.Dot11Bssid);

                        list.Add(item);
                    }
                }
            }
            return list;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds data to the cache, and filler(-100 rssi) data if the AP isn't in the data
        /// </summary>
        /// <param name="data"></param>
        /// <param name="gpsData"></param>
        public void AddData(NetworkData[] data, GpsData gpsData)
        {
            if (data == null || data.Length < 1) return;

            //Keep a tally of the APs that weren't here.
            List<MacAddress> missing = new List<MacAddress>();
            missing.AddRange(_cache.Keys);

            lock (_cache)
            {
                //Loop through all supplied data and add or update accesspoints
                foreach (NetworkData n2 in data)
                {
                    //Check if the cache contains this AP already
                    if (_cache.ContainsKey(n2.MyMacAddress))
                    {
                        //It does, update it!
                        GetAccessPointByMacAddress(n2.MyMacAddress).AddData(n2, gpsData);
                        //The AP was here, remove it from the missing list
                        missing.Remove(n2.MyMacAddress);
                    }
                    else
                    {
                        //nope, never heard of it. Add it!
                        _cache.Add(n2.MyMacAddress, new AccessPoint(n2)
                                                        {
                                                            MyColor = Utilities.GetColor(),
                                                            Vendor = _av.GetVendor(n2.MyMacAddress),
                                                            GpsData = gpsData
                                                        });

                    }
                }
            }

            //Add filler data for all absent APs
            foreach (MacAddress mac in missing)
            {
                GetAccessPointByMacAddress(mac).AddFiller(
                    DateTime.FromFileTime(data.Max(nd => nd.MyTimestamp.ToFileTime())));
            }
        }
Exemplo n.º 15
0
 private void OnScanComplete(NetworkData[] data,GpsData gpsData)
 {
     if (ScanComplete != null) ScanComplete(this, new ScanCompleteEventArgs(data, gpsData));
 }
Exemplo n.º 16
0
        private void TNullScanElapsed(object sender, ElapsedEventArgs e)
        {
            // _tNullScan.Interval = 750;
            List<NetworkData> networkDataList = new List<NetworkData>();

            if(_usedData.Count == 0)
            {
                for (int i = 0; i < numNull; i++)
                {
                    _usedData.Add(new NullNetData
                                      {
                                          Mac = GenerateFakeMacAddress(),
                                          Channel = (uint) random.Next(1, 14),
                                          Ssid = "Fake SSID",
                                          Rssi = random.Next(-90, -20)
                                      });
                }
                return;
            }

            for (int i = 0; i < numNull; i++)
            {
                NetworkData ndTemp = new NetworkData(DateTime.Now,
                                                     _usedData[i].Mac,
                                                     "WPA2-Enterprise",
                                                     _usedData[i].Ssid,
                                                     _usedData[i].Channel,
                                                     _usedData[i].Rssi,
                                                     50,
                                                     "1/2/5.5/6/12/24/36/48/54",
                                                     "Fake");
                //generate new rssi
                _usedData[i].Rssi = GenerateFakeRssi(_usedData[i].Rssi);
                networkDataList.Add(ndTemp);
            }

            //Add to cache
            Cache.AddData(networkDataList.ToArray(), GpsData.Empty);

            //Fire ScanComplete
            OnScanComplete(networkDataList.ToArray(),GpsData.Empty);
        }
Exemplo n.º 17
0
        private IEnumerable<NetworkData> GetNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();
            IEnumerable<Wlan.WlanBssEntryN> networkBssList = MyWlanInterface.GetNetworkBssList();
            IEnumerable<Wlan.WlanAvailableNetwork> availableNetworkList =
                MyWlanInterface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles);
            if ((networkBssList != null) && (availableNetworkList != null))
            {
                Wlan.WlanAvailableNetwork foundNetwork = new Wlan.WlanAvailableNetwork();
                foreach (Wlan.WlanBssEntryN entry in networkBssList)
                {
                    string ssid = Encoding.ASCII.GetString(entry.BaseEntry.dot11Ssid.SSID, 0,
                                                           (int) entry.BaseEntry.dot11Ssid.SSIDLength);
                    if (FindNetwork(ssid, availableNetworkList, ref foundNetwork))
                    {
                        NetworkData item = new NetworkData(entry.BaseEntry.dot11Bssid);

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);
                        if (entry.NSettings != null)
                        {
                            item.NSettings = new IeParser.TypeNSettings(entry.NSettings);

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }

                        item.IsTypeN = entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht;
                        int num = Utilities.ComputeRssi(entry.BaseEntry.linkQuality);
                        item.Rssi = (entry.BaseEntry.rssi > num) ? entry.BaseEntry.rssi : num;
                        item.Ssid = ssid;
                        item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);
                        item.Privacy = Utilities.CreatePrivacyString(foundNetwork.dot11DefaultAuthAlgorithm,
                                                                     foundNetwork.dot11DefaultCipherAlgorithm);
                        item.SignalQuality = foundNetwork.wlanSignalQuality;
                        list.Add(item);
                    }
                }
            }
            return list;
        }
Exemplo n.º 18
0
        private IEnumerable<NetworkData> GetXpNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();
            IEnumerable<NdisWlanBssidEx> exArray = MyNdis.QueryBssidList(MyWlanInterface.NetworkInterface);
            if (exArray != null)
            {
                foreach (NdisWlanBssidEx ex in exArray)
                {
                    NetworkData data2 = new NetworkData(ex.MacAddress);
                    data2.Channel = Utilities.ConvertToChannel(ex.Configuration.DSConfig);
                    NetworkData item = data2;
                    if ((ex.IELength <= ex.IEs.Length) && (ex.IELength > 28))
                    {
                        bool foundNIes = false;
                        for (int i = 0; i < (ex.IELength/* - 29*/); i++)
                        {
                            if (((ex.IEs[i] == 0x2D) && (ex.IEs[i + 1] == 26)) && ((ex.IEs[i + 28] == 0x3D) && (ex.IEs[(i + 28) + 1] == 0x16)))
                            {
                                foundNIes = true;
                                break;
                            }
                        }
                        if(foundNIes)
                        {
                            item.IsTypeN = true;
                            item.NSettings = IeParser.Parse(ex.IEs);
                            //item.Rates.Add(IEParser.MCSSet.GetSpeed(item.NSettings.maxMCS, item.NSettings.ShortGI20MHz,
                            //                                        item.NSettings.ShortGI40MHz, item.NSettings.Is40MHz));

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }
                    }
                    Utilities.ConvertToMbs(ex.SupportedRates, item.Rates, item.IsTypeN);
                    item.Rssi = ex.Rssi;
                    item.SignalQuality = 0;
                    string str = Encoding.ASCII.GetString(ex.Ssid, 0, (int)ex.SsidLength);
                    if (str != null)
                    {
                        str = str.Trim();
                    }
                    item.Ssid = str;
                    item.Privacy = MyNdis.GetPrivacyString(ex);
                    item.NetworkType = Utilities.FindValueString(Utilities.NetworkTypeText, (int)ex.NetworkTypeInUse);
                    list.Add(item);
                }
            }
            return list;
        }
Exemplo n.º 19
0
        /*
        public void AppendEntry(NetworkData[] aps, GpsData gpsData)
        {
            if(_doc == null) return;
            if(aps.Length < 1) return;

            XmlElement newE = null;
            XmlElement ne;

            foreach (NetworkData ap in aps)
            {

                //Ignore anything -100 (or below?)
                if(ap.Rssi <= -100) continue;

                newE = _doc.CreateElement("wpt");

                //Set lat and lon as attributes
                newE.SetAttribute("lat", gpsData.Latitude.ToString(CultureInfo.InvariantCulture.NumberFormat));
                newE.SetAttribute("lon", gpsData.Longitude.ToString(CultureInfo.InvariantCulture.NumberFormat));

                ne = _doc.CreateElement("ele");
                ne.AppendChild(_doc.CreateTextNode(gpsData.Altitude.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("time");
                ne.AppendChild(
                    _doc.CreateTextNode(string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                                      new object[]
                                                          {
                                                              gpsData.SatelliteTime.Year,
                                                              gpsData.SatelliteTime.Month.ToString("D2"),
                                                              gpsData.SatelliteTime.Day.ToString("D2"),
                                                              gpsData.SatelliteTime.Hour.ToString("D2"),
                                                              gpsData.SatelliteTime.Minute.ToString("D2"),
                                                              gpsData.SatelliteTime.Second,
                                                              gpsData.SatelliteTime.Millisecond
                                                          })));
                newE.AppendChild(ne);

                //ne = _doc.CreateElement("time");
                //ne.AppendChild(_doc.CreateTextNode(""));
                //newE.AppendChild(ne);

                ne = _doc.CreateElement("geoidheight");
                ne.AppendChild(_doc.CreateTextNode(gpsData.GeoidSeperation.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("name");
                ne.AppendChild(_doc.CreateTextNode(XmlHelper.CleanString(ap.Ssid) + " [" + ap.MyMacAddress + "]"));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("cmt");
                ne.AppendChild(_doc.CreateTextNode(gpsData.Speed.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("desc");
                ne.AppendChild(_doc.CreateTextNode(
                                   string.Format(
                                       "{0}\r\n[{1}]\r\nRSSI: {2} dB\r\nQuality: {3}%\r\nChannel {4}\r\nSpeed (kph): {5}\r\n{6}",
                                       new object[]
                                           {
                                               XmlHelper.CleanString(ap.Ssid), ap.MyMacAddress.ToString(), ap.Rssi, ap.SignalQuality,
                                               ap.Channel, gpsData.Speed,
                                               gpsData.SatelliteTime.ToString()
                                           })));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("fix");
                ne.AppendChild(_doc.CreateTextNode(gpsData.FixType));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("sat");
                ne.AppendChild(_doc.CreateTextNode(gpsData.SatCount.ToString()));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("hdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.HDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("vdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.VDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("pdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.PDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                //Extensions = ap data
                ne = _doc.CreateElement("extensions");

                XmlElement ext = _doc.CreateElement("MAC");
                ext.AppendChild(_doc.CreateTextNode(ap.MyMacAddress.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("SSID");
                ext.AppendChild(_doc.CreateTextNode(XmlHelper.CleanString(ap.Ssid)));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("RSSI");
                ext.AppendChild(_doc.CreateTextNode(ap.Rssi.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("ChannelID");
                ext.AppendChild(_doc.CreateTextNode(ap.Channel.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("Security");
                ext.AppendChild(_doc.CreateTextNode(ap.Security));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("signalQuality");
                ext.AppendChild(_doc.CreateTextNode(ap.SignalQuality.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("networkType");
                ext.AppendChild(_doc.CreateTextNode(ap.NetworkType));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("rates");
                ext.AppendChild(_doc.CreateTextNode(ap.SupportedRates));
                ne.AppendChild(ext);

                newE.AppendChild(ne);

                _doc.GetElementsByTagName("gpx").Item(0).AppendChild(newE);
            }

            //Auto save if it's enabled and had been long enough
            if(AutoSave && (DateTime.Now - _lastSaveTime >= AutoSaveInterval || _lastSaveTime == DateTime.MinValue))
            {
                SaveLogFile();
                _lastSaveTime = DateTime.Now;
            }
        }
        */
        public void AppendEntry(NetworkData[] data, GpsData gpsData)
        {
            if (data.Length < 1) return;

            lock (_data)
            {
                foreach (NetworkData nd in data)
                {
                    _data.Add(GpxIO.ConvertNetworkDataToWaypoint(nd, gpsData));
                }
            }

            //Auto save if it's enabled and had been long enough
            if (AutoSave && (DateTime.Now - _lastSaveTime >= AutoSaveInterval || _lastSaveTime == DateTime.MinValue))
            {
                SaveLogFile();
                _lastSaveTime = DateTime.Now;
            }
        }
Exemplo n.º 20
0
        public IEnumerable<NetworkData> GetNetworkData()
        {
            List<NetworkData> list = new List<NetworkData>();

            //If the interface is null, return nothing
            if(_interface == null) return list;

            IEnumerable<Wlan.WlanBssEntryN> networkBssList = null;
            IEnumerable<Wlan.WlanAvailableNetwork> availableNetworkList = null;

            try
            {
                networkBssList = _interface.GetNetworkBssList();
                availableNetworkList = _interface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles);
            }
            catch (NullReferenceException)
            {
                //Hopefully the call will succeed next time.
            }
            if ((networkBssList != null) && (availableNetworkList != null))
            {
                //Get connected to AP
                Wlan.WlanAssociationAttributes connectedAP = new Wlan.WlanAssociationAttributes();
                try
                {
                    if (_interface.CurrentConnection.isState == Wlan.WlanInterfaceState.Connected)
                    {
                        connectedAP = _interface.CurrentConnection.wlanAssociationAttributes;
                    }
                }
                catch (NullReferenceException) { /*Hopefully it will work next time*/ }

                Wlan.WlanAvailableNetwork foundNetwork = new Wlan.WlanAvailableNetwork();
                foreach (Wlan.WlanBssEntryN entry in networkBssList)
                {
                    string ssid = Encoding.ASCII.GetString(entry.BaseEntry.dot11Ssid.SSID, 0,
                                                           (int)entry.BaseEntry.dot11Ssid.SSIDLength);
                    if (FindNetwork(ssid, availableNetworkList, ref foundNetwork))
                    {

                        NetworkData item = new NetworkData(entry.BaseEntry.dot11Bssid);

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);
                        if (entry.NSettings != null)
                        {
                            item.NSettings = new IeParser.TypeNSettings(entry.NSettings);

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }

                        item.IsTypeN = entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht;
                        int num = Utilities.ComputeRssi(entry.BaseEntry.linkQuality);
                        item.Rssi = (entry.BaseEntry.rssi > num) ? entry.BaseEntry.rssi : num;
                        item.Ssid = ssid;
                        item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);
                        item.Privacy = Utilities.CreatePrivacyString(foundNetwork.dot11DefaultAuthAlgorithm,
                                                                     foundNetwork.dot11DefaultCipherAlgorithm);
                        item.SignalQuality = foundNetwork.wlanSignalQuality;

                        //Check to see if this AP is the connected one
                        item.Connected = item.MyMacAddress.CompareToPhysicalAddress(connectedAP.Dot11Bssid);

                        list.Add(item);
                    }
                }
            }
            return list;
        }