Example #1
0
        private static void ParseHTCapabilities(InformationElement ie, TypeNSettings settings)
        {
            settings.Is40Mhz = ((ie.ItsData[0] & 0x02) == 0x02);

            settings.ShortGi20MHz = (ie.ItsData[0] & 0x20) == 0x20;
            settings.ShortGi40MHz = (ie.ItsData[0] & 0x40) == 0x40;

            //Get supported MCS indexes
            //1 bit per index

            byte[] bits = new byte[4];
            //Array.ConstrainedCopy(ies, index + 5, bits, 0, 4);
            Array.Copy(ie.ItsData, 4, bits, 0, 4);

            BitArray b = new BitArray(bits);

            //settings.Rates = new List<double>();

            //The MCS indexes are in little endian,
            //so this loop will start at the lowest rates
            for (int i = 0; i < b.Length; i++)
            {
                //If the MCS index bit is 0, skip it
                if (b[i] == false)
                {
                    continue;
                }

                //Add the rate
                settings.Rates.Add(McsSet.GetSpeed((uint)i, settings.ShortGi20MHz, settings.ShortGi40MHz,
                                                   settings.Is40Mhz));
            }
        }
Example #2
0
 public TypeNSettings(TypeNSettings settings)
 {
     Is40Mhz               = settings.Is40Mhz;
     ShortGi20MHz          = settings.ShortGi20MHz;
     ShortGi40MHz          = settings.ShortGi40MHz;
     PrimaryChannel        = settings.PrimaryChannel;
     SecondaryChannelLower = settings.SecondaryChannelLower;
     //MaxMcs = settings.MaxMcs;
     Rates = settings.Rates;
 }
Example #3
0
            public override bool Equals(object obj)
            {
                if (obj is TypeNSettings)
                {
                    TypeNSettings set = (TypeNSettings)obj;
                    bool          yes = set.Is40Mhz == Is40Mhz;
                    yes &= set.ShortGi20MHz == ShortGi20MHz;
                    yes &= set.ShortGi40MHz == ShortGi40MHz;
                    yes &= set.PrimaryChannel == PrimaryChannel;
                    yes &= set.SecondaryChannelLower == SecondaryChannelLower;
                    //Don't compare rates

                    return(yes);
                }
                return(false);
            }
Example #4
0
        private static void ParseHTOperation(InformationElement ie, TypeNSettings settings)
        {
            const int channel = 0;
            const int subset1 = 1;

            //Primary channel
            settings.PrimaryChannel = ie.ItsData[0];

            //Secondary channel location
            settings.SecondaryChannelLower = (ie.ItsData[channel] & 0x03) == 0x03;

            //Check if there is no secondary channel and set 40MHz to false
            if (settings.Is40Mhz)
            {
                settings.Is40Mhz = (ie.ItsData[subset1] & 0x03) == 0x03 || (ie.ItsData[subset1] & 0x01) == 0x01;
            }
        }
Example #5
0
        public static TypeNSettings Parse(byte[] ies)
        {

            var informationElements = BuildInformationElements(ies);
            var settings = new TypeNSettings();
            bool returnNull = true;

            foreach (var informationElement in informationElements)
            {
                switch (informationElement.ItsNumber)
                {
                    case 45: //HT Capabilities
                        ParseHTCapabilities(informationElement, settings);
                        returnNull = false;
                        break;
                    case 61: //HT Information
                        ParseHTOperation(informationElement, settings);
                        returnNull = false;
                        break;
                }
            }

            return returnNull ? null : settings;
        }
Example #6
0
        public static TypeNSettings Parse(byte[] ies)
        {
            var  informationElements = BuildInformationElements(ies);
            var  settings            = new TypeNSettings();
            bool returnNull          = true;

            foreach (var informationElement in informationElements)
            {
                switch (informationElement.ItsNumber)
                {
                case 45:     //HT Capabilities
                    ParseHTCapabilities(informationElement, settings);
                    returnNull = false;
                    break;

                case 61:     //HT Information
                    ParseHTOperation(informationElement, settings);
                    returnNull = false;
                    break;
                }
            }

            return(returnNull ? null : settings);
        }
Example #7
0
 public TypeNSettings(TypeNSettings settings)
 {
     Is40Mhz = settings.Is40Mhz;
     ShortGi20MHz = settings.ShortGi20MHz;
     ShortGi40MHz = settings.ShortGi40MHz;
     PrimaryChannel = settings.PrimaryChannel;
     SecondaryChannelLower = settings.SecondaryChannelLower;
     //MaxMcs = settings.MaxMcs;
     Rates = settings.Rates;
 }
Example #8
0
        private static void ParseHTCapabilities(InformationElement ie, TypeNSettings settings)
        {
            settings.Is40Mhz = ((ie.ItsData[0] & 0x02) == 0x02);

            settings.ShortGi20MHz = (ie.ItsData[0] & 0x20) == 0x20;
            settings.ShortGi40MHz = (ie.ItsData[0] & 0x40) == 0x40;

            //Get supported MCS indexes 
            //1 bit per index

            byte[] bits = new byte[4];
            //Array.ConstrainedCopy(ies, index + 5, bits, 0, 4);
            Array.Copy(ie.ItsData, 4, bits, 0, 4);

            BitArray b = new BitArray(bits);
            //settings.Rates = new List<double>();

            //The MCS indexes are in little endian,
            //so this loop will start at the lowest rates
            for (int i = 0; i < b.Length; i++)
            {
                   //If the MCS index bit is 0, skip it
                if (b[i] == false) continue;

                //Add the rate
                settings.Rates.Add(McsSet.GetSpeed((uint) i, settings.ShortGi20MHz, settings.ShortGi40MHz,
                                                   settings.Is40Mhz));
            }
        }
Example #9
0
        private static void ParseHTOperation(InformationElement ie, TypeNSettings settings)
        {
            const int channel = 0;
            const int subset1 = 1;

            //Primary channel
            settings.PrimaryChannel = ie.ItsData[0]; 

            //Secondary channel location
            settings.SecondaryChannelLower = (ie.ItsData[channel] & 0x03) == 0x03;

            //Check if there is no secondary channel and set 40MHz to false
            if (settings.Is40Mhz)
                settings.Is40Mhz = (ie.ItsData[subset1] & 0x03) == 0x03 || (ie.ItsData[subset1] & 0x01) == 0x01;
        }
Example #10
0
        /*public static TypeNSettings Parse(byte[] ies)
        {
            try
            {
                int index = -1;

                //for (int i = 0; i < ies.Length; i++)
                for (int i = 0; i < ies.Length - 31; i++)
                {
                    //loop until we find the HT IE field 41 with length of 26 and the extended info futher down
                    //HT IE 1's signature is 2D 1A
                    //HT IE 2's signature is 3D 16
                    if ((ies[i] == 0x2D && ies[i + 1] == 0x1A) && (ies[i + 28] == 0x3D && ies[i + 29] == 0x16))
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1) return null;

                // We know that ies.Length > index + 31 so all of the following array indexes should be in bounds

                TypeNSettings settings = new TypeNSettings
                                             {
                                                 Is40MHz = ((ies[index + 2] & 0x02) == 0x02),
                                                 ShortGi20MHz = (ies[index + 2] & 0x20) == 0x20,
                                                 ShortGi40MHz = (ies[index + 2] & 0x40) == 0x40
                                             };

                //Supported MCS indexes
                //1 bit per index
                byte[] bits = new byte[4];
                Array.ConstrainedCopy(ies, index + 5, bits, 0, 4);

                BitArray b = new BitArray(bits);
                settings.Rates = new List<double>();
                int maxIndex = -1;

                for (int i = 0; i < b.Length; i++)
                {
                    if (b[i] == false) continue;
                    //Update the highest MCS index
                    if (b[i]) maxIndex = i;
                    //Add the rate
                    settings.Rates.Add(McsSet.GetSpeed((uint)i, settings.ShortGi20MHz, settings.ShortGi40MHz,
                                                       settings.Is40MHz));
                }
                if (maxIndex == -1) return null; // there has been an error

                //settings.MaxMcs = (uint)maxIndex;
                //Extended info
                //Primary channel
                settings.PrimaryChannel = ies[index + 30];

                //Secondary channel location
                settings.SecondaryChannelLower = (ies[index + 31] & 0x03) == 0x03;

                //Check if there is no secondary channel and set 40MHz to false
                if (settings.Is40MHz)
                    settings.Is40MHz = (ies[index + 31] & 0x03) == 0x03 || (ies[index + 31] & 0x01) == 0x01;

                return settings;
            }
            catch (IndexOutOfRangeException)
            {
                //We can't get the 802.11n IEs. Just return null
                return null;
            }
        }*/
        public static TypeNSettings Parse(byte[] ies)
        {
            //The indexes for both elements
            int HtCapIndex = -1;
            int HtInfoIndex = -1;

            bool returnNull = true;

            //Look for the HT Capabilities element
            for (int i = 0; i < ies.Length - 31; i++)
            {
                //HT Capabilities's signature is 2D 1A
                if ((ies[i] == 0x2D && ies[i + 1] == 0x1A) && (ies.Length >= i + 27))
                {
                    //Found it
                    HtCapIndex = i;
                }

                //HT Information's signature is 3D 16
                if ((ies[i] == 0x3D && ies[i + 1] == 0x16) && (ies.Length >= i + 24))
                {
                    //Found it
                    HtInfoIndex = i;
                }
            }

            TypeNSettings settings = new TypeNSettings();

            //Parse the info blocks if we found them
            if (HtCapIndex > -1)
            {
                settings.Is40MHz = ((ies[HtCapIndex + 2] & 0x02) == 0x02);

                settings.ShortGi20MHz = (ies[HtCapIndex + 2] & 0x20) == 0x20;
                settings.ShortGi40MHz = (ies[HtCapIndex + 2] & 0x40) == 0x40;

                //Get supported MCS indexes
                //1 bit per index

                byte[] bits = new byte[4];
                //Array.ConstrainedCopy(ies, index + 5, bits, 0, 4);
                Array.Copy(ies, HtCapIndex + 5, bits, 0, 4);

                BitArray b = new BitArray(bits);
                //settings.Rates = new List<double>();

                //The MCS indexes are in little endian,
                //so this loop will start at the lowest rates
                for (int i = 0; i < b.Length; i++)
                {
                    //If the MCS index bit is 0, skip it
                    if (b[i] == false) continue;

                    //Add the rate
                    settings.Rates.Add(McsSet.GetSpeed((uint)i, settings.ShortGi20MHz, settings.ShortGi40MHz,
                                                       settings.Is40MHz));
                }

                returnNull = false;
            }

            if (HtInfoIndex > -1)
            {
                //Primary channel
                settings.PrimaryChannel = ies[HtInfoIndex + 2];

                //Secondary channel location
                settings.SecondaryChannelLower = (ies[HtInfoIndex + 3] & 0x03) == 0x03;

                //Check if there is no secondary channel and set 40MHz to false
                if (settings.Is40MHz)
                    settings.Is40MHz = (ies[HtInfoIndex + 3] & 0x03) == 0x03 || (ies[HtInfoIndex + 3] & 0x01) == 0x01;

                returnNull = false;
            }

            return returnNull ? null : settings;
        }
Example #11
0
        public static TypeNSettings Parse(byte[] ies)
        {
            try
            {
                int index = -1;

                //for (int i = 0; i < ies.Length; i++)
                for (int i = 0; i < ies.Length - 31; i++)
                {
                    //loop until we find the HT IE field 41 with length of 26 and the extended info futher down
                    //HT IE 1's signature is 2D 1A
                    //HT IE 2's signature is 3D 16
                    if ((ies[i] == 0x2D && ies[i + 1] == 0x1A) && (ies[i + 28] == 0x3D && ies[i + 29] == 0x16))
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1) return null;

                // We know that ies.Length > index + 31 so all of the following array indexes should be in bounds

                TypeNSettings settings = new TypeNSettings
                                             {
                                                 Is40MHz = ((ies[index + 2] & 0x02) == 0x02),
                                                 ShortGi20MHz = (ies[index + 2] & 0x20) == 0x20,
                                                 ShortGi40MHz = (ies[index + 2] & 0x40) == 0x40
                                             };

                //Supported MCS indexes
                //1 bit per index
                byte[] bits = new byte[4];
                Array.ConstrainedCopy(ies, index + 5, bits, 0, 4);

                BitArray b = new BitArray(bits);
                settings.Rates = new List<double>();
                int maxIndex = -1;

                for (int i = 0; i < b.Length; i++)
                {
                    if (b[i] == false) continue;
                    //Update the highest MCS index
                    if (b[i]) maxIndex = i;
                    //Add the rate
                    settings.Rates.Add(McsSet.GetSpeed((uint) i, settings.ShortGi20MHz, settings.ShortGi40MHz,
                                                       settings.Is40MHz));
                }
                if (maxIndex == -1) return null; // there has been an error

                settings.MaxMcs = (uint) maxIndex;
                //Extended info
                //Primary channel
                settings.PrimaryChannel = ies[index + 30];

                //Secondary channel location
                settings.SecondaryChannelLower = (ies[index + 31] & 0x03) == 0x03;

                //Check if there is no secondary channel and set 40MHz to false
                if (settings.Is40MHz)
                    settings.Is40MHz = (ies[index + 31] & 0x03) == 0x03 || (ies[index + 31] & 0x01) == 0x01;

                return settings;
            }
            catch(IndexOutOfRangeException)
            {
                //We can't get the 802.11n IEs. Just return null
                return null;
            }
        }