Esempio n. 1
0
        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();
        }
Esempio n. 2
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);
                        item.IsTypeN = (entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht);
                        if (item.IsTypeN && entry.IEs != null && entry.IEs.Length > 0)
                        {
                            item.NSettings = IeParser.Parse(entry.IEs);
                            if (item.NSettings == null)
                            {
                                return(null);
                            }

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

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);

                        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;

                        // tyler's fix
                        // Sometimes there is an issue where the RSSI will become overly positive
                        // (e.g. going from -96 to +160), so subtracting 256 will fix it.
                        if (item.Rssi > 0)
                        {
                            item.Rssi -= 256;
                        }

                        item.Ssid        = ssid;
                        item.Channel     = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);
                        item.Security    = Utilities.CreateSecurityString(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);
        }