public void Test_Bytes_MultipleInfoElements()
        {
            var ie1 = new InformationElement(
                InformationElement.ElementId.WifiProtectedAccess,
                new byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 });

            var ie2 = new InformationElement(
                InformationElement.ElementId.VendorSpecific,
                new byte[] { 0xFF, 0xFE, 0xFD, 0xFC });

            var ieList = new InformationElementList {
                ie1, ie2
            };

            byte[] expectedBytes = { 0xD3, 0x5, 0x1, 0x2, 0x3, 0x4, 0x5, 0xDD, 0x4, 0xFF, 0xFE, 0xFD, 0xFC };

            var b = ieList.Bytes;

            Assert.AreEqual(0xD3, b[0]);
            Assert.AreEqual(0x5, b[1]);
            Assert.AreEqual(0x1, b[2]);
            Assert.AreEqual(0x2, b[3]);
            Assert.AreEqual(0x3, b[4]);
            Assert.AreEqual(0x4, b[5]);
            Assert.AreEqual(0x5, b[6]);
            Assert.AreEqual(0xDD, b[7]);
            Assert.AreEqual(0x4, b[8]);
            Assert.AreEqual(0xFF, b[9]);
            Assert.AreEqual(0xFE, b[10]);
            Assert.AreEqual(0xFD, b[11]);
            Assert.AreEqual(0xFC, b[12]);

            Assert.IsTrue(ieList.Bytes.SequenceEqual(expectedBytes));
        }
예제 #2
0
        private static IEnumerable <InformationElement> BuildInformationElements(byte[] ies)
        {
            var informationElements = new List <InformationElement>();

            var index = 0;

            while (index < ies.Length)
            {
                var ie = new InformationElement();
                ie.ItsNumber = ies[index];
                if (index + 1 >= ies.Length)
                {
                    break;
                }
                ie.ItsLength = ies[index + 1];
                ie.ItsData   = new byte[ie.ItsLength];
                int length;
                if (ies.Length - (index + 2) < ie.ItsLength)
                {
                    length = ies.Length - (index + 2);
                }
                else
                {
                    length = ie.ItsLength;
                }
                Array.Copy(ies, index + 2, ie.ItsData, 0, length);

                informationElements.Add(ie);
                index += ie.ItsLength + 2;
            }
            return(informationElements);
        }
예제 #3
0
            public void Test_Constructor_ConstructWithValues()
            {
                InformationElement ssidInfoElement = new InformationElement(InformationElement.ElementId.ServiceSetIdentity,
                                                                            new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });
                InformationElement vendorElement = new InformationElement(InformationElement.ElementId.VendorSpecific,
                                                                          new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });


                ProbeResponseFrame frame = new ProbeResponseFrame(PhysicalAddress.Parse("111111111111"),
                                                                  PhysicalAddress.Parse("222222222222"),
                                                                  PhysicalAddress.Parse("333333333333"),
                                                                  new InformationElementList()
                {
                    ssidInfoElement, vendorElement
                });

                frame.FrameControl.ToDS          = false;
                frame.FrameControl.FromDS        = true;
                frame.FrameControl.MoreFragments = true;

                frame.Duration.Field = 0x1234;

                frame.SequenceControl.SequenceNumber = 0x77;
                frame.SequenceControl.FragmentNumber = 0x1;

                frame.CapabilityInformation.IsEss          = true;
                frame.CapabilityInformation.ChannelAgility = true;

                frame.UpdateFrameCheckSequence();
                UInt32 fcs = frame.FrameCheckSequence;

                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas   = new ByteArraySegment(bytes);

                //create a new frame that should be identical to the original
                ProbeResponseFrame recreatedFrame = MacFrame.ParsePacket(bas) as ProbeResponseFrame;

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementProbeResponse, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);

                Assert.AreEqual(0x77, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual(0x1, recreatedFrame.SequenceControl.FragmentNumber);

                Assert.IsTrue(frame.CapabilityInformation.IsEss);
                Assert.IsTrue(frame.CapabilityInformation.ChannelAgility);

                Assert.AreEqual("111111111111", recreatedFrame.SourceAddress.ToString().ToUpper());
                Assert.AreEqual("222222222222", recreatedFrame.DestinationAddress.ToString().ToUpper());
                Assert.AreEqual("333333333333", recreatedFrame.BssId.ToString().ToUpper());

                Assert.AreEqual(ssidInfoElement, recreatedFrame.InformationElements [0]);
                Assert.AreEqual(vendorElement, recreatedFrame.InformationElements [1]);

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
 public void Test_Constructor_ValueTooLong ()
 {
     Byte[] value = new Byte[300];
     InformationElement infoElement = new InformationElement (
         InformationElement.ElementId.CfParameterSet, value);
     
 }
예제 #5
0
        private static void ParseVHTCapabilities(InformationElement ie, TypeACSettings settings)
        {
            settings.Capabilities = new TypeACSettings.VHTCapabilities();

            var capabilities = new byte[4];

            Array.Copy(ie.ItsData, 0, capabilities, 0, 4);

            var supportedMCS = new byte[8];

            Array.Copy(ie.ItsData, 4, supportedMCS, 0, 8);

            var supportedChannelWidth = (capabilities[0] & 0x0C) >> 2;

            switch (supportedChannelWidth)
            {
            case 1:
                settings.Capabilities.Supports160Mhz = true;
                break;

            case 2:
                settings.Capabilities.Supports80Plus80Mhz = true;
                settings.Capabilities.Supports160Mhz      = true;
                break;
            }

            settings.Capabilities.ShortGi160MHz = (capabilities[0] & 0x40) == 0x40;
            settings.Capabilities.ShortGi80MHz  = (capabilities[0] & 0x20) == 0x20;

            settings.Capabilities.MaxRecieveRate  = BitConverter.ToUInt16(supportedMCS, 2);
            settings.Capabilities.MaxTransmitRate = BitConverter.ToUInt16(supportedMCS, 6);
        }
예제 #6
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));
            }
        }
예제 #7
0
            public void Test_Constructor_ConstructWithValues()
            {
                InformationElement ssidInfoElement = new InformationElement(InformationElement.ElementId.ServiceSetIdentity,
                                                                            new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });
                InformationElement vendorElement = new InformationElement(InformationElement.ElementId.VendorSpecific,
                                                                          new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });


                AuthenticationFrame frame = new AuthenticationFrame(PhysicalAddress.Parse("111111111111"),
                                                                    PhysicalAddress.Parse("222222222222"),
                                                                    PhysicalAddress.Parse("333333333333"),
                                                                    new InformationElementList()
                {
                    ssidInfoElement, vendorElement
                });

                frame.FrameControl.ToDS          = false;
                frame.FrameControl.FromDS        = true;
                frame.FrameControl.MoreFragments = true;

                frame.Duration.Field = 0x1234;

                frame.SequenceControl.SequenceNumber = 0x77;
                frame.SequenceControl.FragmentNumber = 0x1;

                frame.AuthenticationAlgorithmNumber = 0x4444;
                frame.AuthenticationAlgorithmTransactionSequenceNumber = 0x5555;
                frame.StatusCode = AuthenticationStatusCode.Success;

                frame.UpdateFrameCheckSequence();
                UInt32 fcs = frame.FrameCheckSequence;

                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas   = new ByteArraySegment(bytes);

                //create a new frame that should be identical to the original
                AuthenticationFrame recreatedFrame = MacFrame.ParsePacket(bas) as AuthenticationFrame;

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementAuthentication, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);

                Assert.AreEqual(0x77, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual(0x1, recreatedFrame.SequenceControl.FragmentNumber);

                Assert.AreEqual(0x4444, recreatedFrame.AuthenticationAlgorithmNumber);
                Assert.AreEqual(0x5555, recreatedFrame.AuthenticationAlgorithmTransactionSequenceNumber);
                Assert.AreEqual(AuthenticationStatusCode.Success, recreatedFrame.StatusCode);

                Assert.AreEqual("111111111111", recreatedFrame.SourceAddress.ToString().ToUpper());
                Assert.AreEqual("222222222222", recreatedFrame.DestinationAddress.ToString().ToUpper());
                Assert.AreEqual("333333333333", recreatedFrame.BssId.ToString().ToUpper());

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
예제 #8
0
            public void Test_FindFirstById_FindElement()
            {
                BeaconFrame beaconFrame = LoadBeaconFrameFromFile("../../CaptureFiles/80211_beacon_frame.pcap");

                InformationElement infoElement = beaconFrame.InformationElements.FindFirstById(InformationElement.ElementId.DsParameterSet);

                Assert.AreEqual(InformationElement.ElementId.DsParameterSet, infoElement.Id);
            }
예제 #9
0
            public void Test_FindFirstById_ElementNotPresent()
            {
                BeaconFrame beaconFrame = LoadBeaconFrameFromFile("../../CaptureFiles/80211_beacon_frame.pcap");

                InformationElement infoElement = beaconFrame.InformationElements.FindFirstById(InformationElement.ElementId.ChallengeText);

                Assert.IsNull(infoElement);
            }
예제 #10
0
        public void Test_Constructor_BufferCorrectSize()
        {
            byte[] value            = { 0x0, 0x2, 0x1, 0x2 };
            var    byteArraySegment = new ByteArraySegment(value);

            var infoElement = new InformationElement(byteArraySegment);

            Assert.AreEqual(2, infoElement.ValueLength);
            Assert.AreEqual(2, infoElement.Value.Length);
        }
            public void Test_Constructor_ValidParameters()
            {
                Byte[] value = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                Assert.AreEqual(InformationElement.ElementId.ChallengeText, infoElement.Id);
                Assert.AreEqual(value, infoElement.Value);
                Assert.AreEqual(5, infoElement.ValueLength);
            }
예제 #12
0
            public void Test_Constructor_ValidParameters()
            {
                Byte[]             value       = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                Assert.AreEqual(InformationElement.ElementId.ChallengeText, infoElement.Id);
                Assert.AreEqual(value, infoElement.Value);
                Assert.AreEqual(5, infoElement.ValueLength);
            }
예제 #13
0
            public void Test_Constructor_BufferCorrectSize()
            {
                Byte[]           value = new Byte[] { 0x0, 0x2, 0x1, 0x2, };
                ByteArraySegment bas   = new ByteArraySegment(value);

                InformationElement infoElement = new InformationElement(bas);

                Assert.AreEqual(2, infoElement.ValueLength);
                Assert.AreEqual(2, infoElement.Value.Length);
            }
        public void Test_Constructor_ConstructWithValues()
        {
            var ssidInfoElement = new InformationElement(InformationElement.ElementId.ServiceSetIdentity,
                                                         new byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });

            var vendorElement = new InformationElement(InformationElement.ElementId.VendorSpecific,
                                                       new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });

            var frame = new AssociationResponseFrame(PhysicalAddress.Parse("111111111111"),
                                                     PhysicalAddress.Parse("222222222222"),
                                                     PhysicalAddress.Parse("333333333333"),
                                                     new InformationElementList {
                ssidInfoElement, vendorElement
            })
            {
                FrameControl          = { ToDS = false, FromDS = true, MoreFragments = true },
                Duration              = { Field = 0x1234 },
                SequenceControl       = { SequenceNumber = 0x77, FragmentNumber = 0x1 },
                CapabilityInformation = { Privacy = true, ChannelAgility = true },
                StatusCode            = AuthenticationStatusCode.Success,
                AssociationId         = 0x2
            };

            frame.UpdateFrameCheckSequence();
            var fcs = frame.FrameCheckSequence;

            //serialize the frame into a byte buffer
            var bytes            = frame.Bytes;
            var byteArraySegment = new ByteArraySegment(bytes);

            //create a new frame that should be identical to the original
            var recreatedFrame = MacFrame.ParsePacket(byteArraySegment) as AssociationResponseFrame;

            recreatedFrame.UpdateFrameCheckSequence();

            Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementAssociationResponse, recreatedFrame.FrameControl.SubType);
            Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
            Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
            Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);

            Assert.AreEqual(0x77, recreatedFrame.SequenceControl.SequenceNumber);
            Assert.AreEqual(0x1, recreatedFrame.SequenceControl.FragmentNumber);

            Assert.IsTrue(recreatedFrame.CapabilityInformation.Privacy);
            Assert.IsTrue(recreatedFrame.CapabilityInformation.ChannelAgility);

            Assert.AreEqual(AuthenticationStatusCode.Success, recreatedFrame.StatusCode);
            Assert.AreEqual(0x2, recreatedFrame.AssociationId);

            Assert.AreEqual("111111111111", recreatedFrame.SourceAddress.ToString().ToUpper());
            Assert.AreEqual("222222222222", recreatedFrame.DestinationAddress.ToString().ToUpper());
            Assert.AreEqual("333333333333", recreatedFrame.BssId.ToString().ToUpper());

            Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
        }
 public void Test_Constructor_BufferTooShort ()
 {
     //This IE will have and length of 5 but only three bytes of data
     Byte[] value = new Byte[] { 0x0, 0x5, 0x1, 0x2, 0x3 };
     ByteArraySegment bas = new ByteArraySegment (value);
     
     InformationElement infoElement = new InformationElement (bas);
     
     Assert.AreEqual (3, infoElement.ValueLength);
     Assert.AreEqual (3, infoElement.Value.Length);
 }
예제 #16
0
            /// <summary>
            /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="Kavprot.Packets.Ieee80211.InformationElement"/>.
            /// </summary>
            /// <param name='obj'>
            /// The <see cref="System.Object"/> to compare with the current <see cref="Kavprot.Packets.Ieee80211.InformationElement"/>.
            /// </param>
            /// <returns>
            /// <c>true</c> if the specified <see cref="System.Object"/> is equal to the current
            /// <see cref="Kavprot.Packets.Ieee80211.InformationElement"/>; otherwise, <c>false</c>.
            /// </returns>
            public override bool Equals(object obj)
            {
                if (obj == null || GetType() != obj.GetType())
                {
                    return(false);
                }

                InformationElement ie = obj as InformationElement;

                return((Id == ie.Id) && (Value.SequenceEqual(ie.Value)));
            }
예제 #17
0
            public void Test_Equals_AreEqual()
            {
                Byte[]             value       = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                InformationElement otherInfoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                Assert.IsTrue(infoElement.Equals(otherInfoElement));
            }
예제 #18
0
            public void Test_Constructor_BufferTooShort()
            {
                //This IE will have and length of 5 but only three bytes of data
                Byte[]           value = new Byte[] { 0x0, 0x5, 0x1, 0x2, 0x3 };
                ByteArraySegment bas   = new ByteArraySegment(value);

                InformationElement infoElement = new InformationElement(bas);

                Assert.AreEqual(3, infoElement.ValueLength);
                Assert.AreEqual(3, infoElement.Value.Length);
            }
예제 #19
0
            public void Test_Equals_AreNotEqual()
            {
                Byte[]             value       = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.RobustSecurityNetwork, value);

                Byte[]             otherValue       = new Byte[] { 0xa, 0xb, 0xc, 0xd, 0xe };
                InformationElement otherInfoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, otherValue);

                Assert.IsFalse(infoElement.Equals(otherInfoElement));
            }
예제 #20
0
            public void Test_Constructor_BufferLongerThanElement()
            {
                //This IE will have and length of 2 but there are three bytes of data available,
                //the last one should be ignored
                Byte[]           value = new Byte[] { 0x0, 0x2, 0x1, 0x2, 0x3 };
                ByteArraySegment bas   = new ByteArraySegment(value);

                InformationElement infoElement = new InformationElement(bas);

                Assert.AreEqual(2, infoElement.ValueLength);
                Assert.AreEqual(2, infoElement.Value.Length);
            }
 public void Test_Constructor_BufferLongerThanElement ()
 {
     //This IE will have and length of 2 but there are three bytes of data available,
     //the last one should be ignored
     Byte[] value = new Byte[] { 0x0, 0x2, 0x1, 0x2, 0x3 };
     ByteArraySegment bas = new ByteArraySegment (value);
     
     InformationElement infoElement = new InformationElement (bas);
     
     Assert.AreEqual (2, infoElement.ValueLength);
     Assert.AreEqual (2, infoElement.Value.Length);
 }
예제 #22
0
         public void Test_Constructor_ConstructWithValues ()
         {
             InformationElement ssidInfoElement = new InformationElement (InformationElement.ElementId.ServiceSetIdentity, 
                                                                        new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });
             InformationElement vendorElement = new InformationElement (InformationElement.ElementId.VendorSpecific,
                                                                        new Byte[] {0x01, 0x02, 0x03, 0x04, 0x05});
             
             
             ProbeRequestFrame frame = new ProbeRequestFrame (PhysicalAddress.Parse ("111111111111"),
                                                              PhysicalAddress.Parse ("222222222222"),
                                                              PhysicalAddress.Parse ("333333333333"),
                                                             new InformationElementList (){ssidInfoElement, vendorElement});
             
             frame.FrameControl.ToDS = false;
             frame.FrameControl.FromDS = true;
             frame.FrameControl.MoreFragments = true;
             
             frame.Duration.Field = 0x1234;
             
             frame.SequenceControl.SequenceNumber = 0x77;
             frame.SequenceControl.FragmentNumber = 0x1;
             
             frame.UpdateFrameCheckSequence ();
             UInt32 fcs = frame.FrameCheckSequence;
             
             //serialize the frame into a byte buffer
             var bytes = frame.Bytes;
             var bas = new ByteArraySegment (bytes);
 
             //create a new frame that should be identical to the original
             ProbeRequestFrame recreatedFrame = MacFrame.ParsePacket (bas) as ProbeRequestFrame;
             recreatedFrame.UpdateFrameCheckSequence();
             
             Assert.AreEqual (FrameControlField.FrameSubTypes.ManagementProbeRequest, recreatedFrame.FrameControl.SubType);
             Assert.IsFalse (recreatedFrame.FrameControl.ToDS);
             Assert.IsTrue (recreatedFrame.FrameControl.FromDS);
             Assert.IsTrue (recreatedFrame.FrameControl.MoreFragments);
             
             Assert.AreEqual (0x77, recreatedFrame.SequenceControl.SequenceNumber);
             Assert.AreEqual (0x1, recreatedFrame.SequenceControl.FragmentNumber);
             
             Assert.AreEqual ("111111111111", recreatedFrame.SourceAddress.ToString ().ToUpper ());
             Assert.AreEqual ("222222222222", recreatedFrame.DestinationAddress.ToString ().ToUpper ());
             Assert.AreEqual ("333333333333", recreatedFrame.BssId.ToString ().ToUpper ());
             
             Assert.AreEqual (ssidInfoElement, recreatedFrame.InformationElements [0]);
             Assert.AreEqual (vendorElement, recreatedFrame.InformationElements [1]);
             
             Assert.AreEqual (fcs, recreatedFrame.FrameCheckSequence);
         }
예제 #23
0
            public void Test_Bytes()
            {
                Byte[]             value       = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.VendorSpecific, value);

                Byte[] ieArray = infoElement.Bytes;

                Assert.AreEqual(7, ieArray.Length);
                Assert.AreEqual((Byte)InformationElement.ElementId.VendorSpecific, ieArray[0]);
                Assert.AreEqual(5, ieArray[1]);

                Byte[] actualValue = new Byte[5];
                Array.Copy(ieArray, 2, actualValue, 0, 5);
                Assert.IsTrue(value.SequenceEqual(actualValue));
            }
예제 #24
0
            public void TestConstructWithValues()
            {
                InformationElement ssidInfoElement = new InformationElement(InformationElement.ElementId.ServiceSetIdentity, new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });

                BeaconFrame frame = new BeaconFrame(
                    PhysicalAddress.Parse("11-11-11-11-11-11"),
                    PhysicalAddress.Parse("22-22-22-22-22-22"),
                    new InformationElementList()
                {
                    ssidInfoElement
                });

                frame.FrameControl.ToDS              = true;
                frame.FrameControl.Protected         = true;
                frame.Duration.Field                 = 12345;
                frame.SequenceControl.SequenceNumber = 3;
                frame.Timestamp      = 123456789;
                frame.BeaconInterval = 4444;
                frame.CapabilityInformation.IsIbss  = true;
                frame.CapabilityInformation.Privacy = true;
                frame.UpdateFrameCheckSequence();
                UInt32 fcs = frame.FrameCheckSequence;


                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas   = new ByteArraySegment(bytes);

                //create a new frame that should be identical to the original
                BeaconFrame recreatedFrame = MacFrame.ParsePacket(bas) as BeaconFrame;

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementBeacon, recreatedFrame.FrameControl.SubType);
                Assert.AreEqual(PhysicalAddress.Parse("11-11-11-11-11-11"), recreatedFrame.SourceAddress);
                Assert.AreEqual(PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF"), recreatedFrame.DestinationAddress);
                Assert.AreEqual(PhysicalAddress.Parse("22-22-22-22-22-22"), recreatedFrame.BssId);
                Assert.IsTrue(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.Protected);
                Assert.AreEqual(12345, recreatedFrame.Duration.Field);
                Assert.AreEqual(3, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual(123456789, recreatedFrame.Timestamp);
                Assert.AreEqual(4444, recreatedFrame.BeaconInterval);
                Assert.AreEqual(ssidInfoElement, recreatedFrame.InformationElements [0]);

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
예제 #25
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;
            }
        }
예제 #26
0
        private static void ParseVHTOperation(InformationElement ie, TypeACSettings settings)
        {
            settings.Operations = new TypeACSettings.VHTOperations();

            var operations = new byte[4];

            Array.Copy(ie.ItsData, 0, operations, 0, 3);

            var basicMCSSet = new byte[8];

            Array.Copy(ie.ItsData, 3, basicMCSSet, 0, 2);

            settings.Operations.ChannelWidth =
                (TypeACSettings.VHTOperations.VHTChannelWidth)Enum.Parse(
                    typeof(TypeACSettings.VHTOperations.VHTChannelWidth),
                    operations[0].ToString(CultureInfo.InvariantCulture)
                    );
        }
예제 #27
0
            public void TestConstructWithValues ()
            {
            
                InformationElement ssidInfoElement = new InformationElement (InformationElement.ElementId.ServiceSetIdentity, new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f }); 
                
                BeaconFrame frame = new BeaconFrame (
                     PhysicalAddress.Parse ("11-11-11-11-11-11"),
                     PhysicalAddress.Parse ("22-22-22-22-22-22"),
                    new InformationElementList (){ssidInfoElement});

                frame.FrameControl.ToDS = true;
                frame.FrameControl.Wep = true;
                frame.Duration.Field = 12345;
                frame.SequenceControl.SequenceNumber = 3;
                frame.Timestamp = 123456789;
                frame.BeaconInterval = 4444;
                frame.CapabilityInformation.IsIbss = true;
                frame.CapabilityInformation.Privacy = true;
                frame.UpdateFrameCheckSequence ();
                UInt32 fcs = frame.FrameCheckSequence;
                
                
                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas = new ByteArraySegment (bytes);

                //create a new frame that should be identical to the original
                BeaconFrame recreatedFrame = MacFrame.ParsePacket (bas) as BeaconFrame;
                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual (FrameControlField.FrameSubTypes.ManagementBeacon, recreatedFrame.FrameControl.SubType);
                Assert.AreEqual (PhysicalAddress.Parse ("11-11-11-11-11-11"), recreatedFrame.SourceAddress);
                Assert.AreEqual (PhysicalAddress.Parse ("FF-FF-FF-FF-FF-FF"), recreatedFrame.DestinationAddress);
                Assert.AreEqual (PhysicalAddress.Parse ("22-22-22-22-22-22"), recreatedFrame.BssId);
                Assert.IsTrue (recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue (recreatedFrame.FrameControl.Wep);
                Assert.AreEqual (12345, recreatedFrame.Duration.Field);
                Assert.AreEqual (3, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual (123456789, recreatedFrame.Timestamp);
                Assert.AreEqual (4444, recreatedFrame.BeaconInterval);
                Assert.AreEqual (ssidInfoElement, recreatedFrame.InformationElements [0]);
                
                Assert.AreEqual (fcs, recreatedFrame.FrameCheckSequence);
            }
 public void Test_Constructor_BufferCorrectSize ()
 {
     Byte[] value = new Byte[] { 0x0, 0x2, 0x1, 0x2,};
     ByteArraySegment bas = new ByteArraySegment (value);
     
     InformationElement infoElement = new InformationElement (bas);
     
     Assert.AreEqual (2, infoElement.ValueLength);
     Assert.AreEqual (2, infoElement.Value.Length);
 }
예제 #29
0
 /// <summary>
 /// Execute the delegate
 /// </summary>
 /// <param name="value"></param>
 public void Run(InformationElement value) => target.SendMessage(functionName, value);
예제 #30
0
        private static void ParseVHTOperation(InformationElement ie, TypeACSettings settings)
        {
            settings.Operations = new TypeACSettings.VHTOperations();

            var operations = new byte[4];
            Array.Copy(ie.ItsData, 0, operations, 0, 3);

            var basicMCSSet = new byte[8];
            Array.Copy(ie.ItsData, 3, basicMCSSet, 0, 2);

            settings.Operations.ChannelWidth = 
                (TypeACSettings.VHTOperations.VHTChannelWidth) Enum.Parse(
                    typeof(TypeACSettings.VHTOperations.VHTChannelWidth), 
                    operations[0].ToString(CultureInfo.InvariantCulture)
                    );
        }
예제 #31
0
        private static void ParseVHTCapabilities(InformationElement ie, TypeACSettings settings)
        {
            settings.Capabilities = new TypeACSettings.VHTCapabilities();

            var capabilities = new byte[4];
            Array.Copy(ie.ItsData, 0, capabilities, 0, 4);

            var supportedMCS = new byte[8];
            Array.Copy(ie.ItsData, 4, supportedMCS, 0, 8);

            var supportedChannelWidth = ( capabilities[0] & 0x0C ) >> 2;

            switch (supportedChannelWidth)
            {
                case 1:
                    settings.Capabilities.Supports160Mhz = true;
                    break;
                case 2:
                    settings.Capabilities.Supports80Plus80Mhz = true;
                    settings.Capabilities.Supports160Mhz = true;
                    break;
            }

            settings.Capabilities. ShortGi160MHz = (capabilities[0] & 0x40) == 0x40;
            settings.Capabilities.ShortGi80MHz = (capabilities[0] & 0x20) == 0x20;

            settings.Capabilities.MaxRecieveRate = BitConverter.ToUInt16(supportedMCS, 2);
            settings.Capabilities.MaxTransmitRate = BitConverter.ToUInt16(supportedMCS, 6);
        }
예제 #32
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;
        }
예제 #33
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));
            }
        }
예제 #34
0
        private static IEnumerable<InformationElement> BuildInformationElements(byte[] ies)
        {
            var informationElements = new List<InformationElement>();

            var index = 0;

            while (index < ies.Length)
            {
                var ie = new InformationElement();
                ie.ItsNumber = ies[index];
                ie.ItsLength = ies[index + 1];
                ie.ItsData = new byte[ie.ItsLength];
                Array.Copy(ies, index + 2, ie.ItsData, 0, ie.ItsLength);

                informationElements.Add(ie);
                index += ie.ItsLength + 2;
            }
            return informationElements;
        }
            public void Test_Equals_AreEqual()
            {
                Byte[] value = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                InformationElement otherInfoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, value);

                Assert.IsTrue(infoElement.Equals(otherInfoElement));
            }
예제 #36
0
        private static void Main()
        {
            // Print SharpPcap version
            var ver = SharpPcap.Version.VersionString;

            Console.WriteLine("PacketDotNet example using SharpPcap {0}", ver);

            // Retrieve the device list
            var devices = AirPcapDeviceList.Instance;

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine();
            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            var i = 0;

            // Print out the devices
            foreach (var dev in devices)
            {
                /* Description */
                Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description);
                i++;
            }

            Console.WriteLine();
            Console.Write("-- Please choose a device to capture: ");
            i = Int32.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

            // Register a cancel handler that lets us break out of our capture loop
            // since we currently need to synchronously receive packets in order to get
            // raw packets. Future versions of SharpPcap are likely to
            // return ONLY raw packets at which time we can simplify this code and
            // use a PcapDevice.OnPacketArrival handler
            Console.CancelKeyPress += HandleCancelKeyPress;

            var device = (AirPcapDevice)devices[i];

            device.Open(DeviceMode.Normal);
            device.FcsValidation   = AirPcapValidationType.ACCEPT_CORRECT_FRAMES;
            _adapterAddress        = device.MacAddress;
            device.AirPcapLinkType = AirPcapLinkTypes._802_11;

            var broadcastAddress = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");

            Console.Write("Please enter the SSID to probe for (use empty string for broadcast probe): ");
            var ssid = Console.ReadLine();

            Console.WriteLine();

            //Make the probe packet to send
            var encoding         = new ASCIIEncoding();
            var ssidIe           = new InformationElement(InformationElement.ElementId.ServiceSetIdentity, encoding.GetBytes(ssid ?? throw new InvalidOperationException()));
            var supportedRatesIe = new InformationElement(InformationElement.ElementId.SupportedRates,
                                                          new byte[] { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24 });

            var extendedSupportedRatesIe = new InformationElement(InformationElement.ElementId.ExtendedSupportedRates,
                                                                  new byte[] { 0x30, 0x48, 0x60, 0x6c });

            //Create a broadcast probe
            var probe = new ProbeRequestFrame(device.MacAddress,
                                              broadcastAddress,
                                              broadcastAddress,
                                              new InformationElementList {
                ssidIe, supportedRatesIe, extendedSupportedRatesIe
            });

            var probeBytes = probe.Bytes;

            device.SendPacket(probeBytes, probeBytes.Length - 4);

            while (_stopCapturing == false)
            {
                var rawCapture = device.GetNextPacket();

                // null packets can be returned in the case where
                // the GetNextRawPacket() timed out, we should just attempt
                // to retrieve another packet by looping the while() again
                if (rawCapture == null)
                {
                    // go back to the start of the while()
                    continue;
                }

                // use PacketDotNet to parse this packet and print out
                // its high level information
                if (Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data) is MacFrame p && p.FrameControl.SubType == FrameControlField.FrameSubTypes.ManagementProbeResponse)
                {
                    if (p is ProbeResponseFrame probeResponse && probeResponse.DestinationAddress.Equals(_adapterAddress))
                    {
                        var ie = probeResponse.InformationElements.FindFirstById(InformationElement.ElementId.ServiceSetIdentity);
                        Console.WriteLine("Response: {0}, SSID: {1}", probeResponse.SourceAddress, Encoding.UTF8.GetString(ie.Value));
                    }
                }
            }
        }
예제 #37
0
        public InformationObject(BinaryReader reader, TypeId typeId, int numberOfSequenceElements,
                                 ConnectionSettings settings)
        {
            if (settings.IoaFieldLength == 1)
            {
                informationObjectAddress = reader.ReadByte();
            }
            else if (settings.IoaFieldLength == 2)
            {
                informationObjectAddress = reader.ReadByte() + (reader.ReadByte() << 8);
            }
            else if (settings.IoaFieldLength == 3)
            {
                informationObjectAddress = reader.ReadByte() + (reader.ReadByte() << 8) + (reader.ReadByte() << 16);
            }

            switch (typeId)
            {
            // 1
            case TypeId.M_SP_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[1];
                    informationElements[i][0] = new IeSinglePointWithQuality(reader);
                }
                break;

            // 2
            case TypeId.M_SP_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeSinglePointWithQuality(reader), new IeTime24(reader) } };
                break;

            // 3
            case TypeId.M_DP_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[1];
                    informationElements[i][0] = new IeDoublePointWithQuality(reader);
                }
                break;

            // 4
            case TypeId.M_DP_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeDoublePointWithQuality(reader), new IeTime24(reader) } };
                break;

            // 5
            case TypeId.M_ST_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeValueWithTransientState(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 6
            case TypeId.M_ST_TA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeValueWithTransientState(reader), new IeQuality(reader), new IeTime24(reader) }
                };
                break;

            // 7
            case TypeId.M_BO_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeBinaryStateInformation(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 8
            case TypeId.M_BO_TA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeBinaryStateInformation(reader), new IeQuality(reader), new IeTime24(reader) }
                };
                break;

            // 9
            case TypeId.M_ME_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeNormalizedValue(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 10
            case TypeId.M_ME_TA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeNormalizedValue(reader), new IeQuality(reader), new IeTime24(reader) }
                };
                break;

            // 11
            case TypeId.M_ME_NB_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeScaledValue(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 12
            case TypeId.M_ME_TB_1:
                informationElements = new[]
                { new InformationElement[] { new IeScaledValue(reader), new IeQuality(reader), new IeTime24(reader) } };
                break;

            // 13
            case TypeId.M_ME_NC_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeShortFloat(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 14
            case TypeId.M_ME_TC_1:
                informationElements = new[]
                { new InformationElement[] { new IeShortFloat(reader), new IeQuality(reader), new IeTime24(reader) } };
                break;

            // 15
            case TypeId.M_IT_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[1];
                    informationElements[i][0] = new IeBinaryCounterReading(reader);
                }
                break;

            // 16
            case TypeId.M_IT_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeBinaryCounterReading(reader), new IeTime24(reader) } };
                break;

            // 17
            case TypeId.M_EP_TA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeSingleProtectionEvent(reader), new IeTime16(reader), new IeTime24(reader) }
                };
                break;

            // 18
            case TypeId.M_EP_TB_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeProtectionStartEvent(reader),
                        new IeProtectionQuality(reader), new IeTime16(reader), new IeTime24(reader)
                    }
                };
                break;

            // 19
            case TypeId.M_EP_TC_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeProtectionOutputCircuitInformation(reader),
                        new IeProtectionQuality(reader), new IeTime16(reader), new IeTime24(reader)
                    }
                };
                break;

            // 20
            case TypeId.M_PS_NA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[2];
                    informationElements[i][0] = new IeStatusAndStatusChanges(reader);
                    informationElements[i][1] = new IeQuality(reader);
                }
                break;

            // 21
            case TypeId.M_ME_ND_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[1];
                    informationElements[i][0] = new IeNormalizedValue(reader);
                }
                break;

            // 30
            case TypeId.M_SP_TB_1:
                informationElements = new[]
                { new InformationElement[] { new IeSinglePointWithQuality(reader), new IeTime56(reader) } };
                break;

            // 31
            case TypeId.M_DP_TB_1:
                informationElements = new[]
                { new InformationElement[] { new IeDoublePointWithQuality(reader), new IeTime56(reader) } };
                break;

            // 32
            case TypeId.M_ST_TB_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeValueWithTransientState(reader), new IeQuality(reader), new IeTime56(reader) }
                };
                break;

            // 33
            case TypeId.M_BO_TB_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeBinaryStateInformation(reader), new IeQuality(reader), new IeTime56(reader) }
                };
                break;

            // 34
            case TypeId.M_ME_TD_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeNormalizedValue(reader), new IeQuality(reader), new IeTime56(reader) }
                };
                break;

            // 35
            case TypeId.M_ME_TE_1:
                informationElements = new[]
                { new InformationElement[] { new IeScaledValue(reader), new IeQuality(reader), new IeTime56(reader) } };
                break;

            // 36
            case TypeId.M_ME_TF_1:
                informationElements = new[]
                { new InformationElement[] { new IeShortFloat(reader), new IeQuality(reader), new IeTime56(reader) } };
                break;

            // 37
            case TypeId.M_IT_TB_1:
                informationElements = new[]
                { new InformationElement[] { new IeBinaryCounterReading(reader), new IeTime56(reader) } };
                break;

            // 38
            case TypeId.M_EP_TD_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    { new IeSingleProtectionEvent(reader), new IeTime16(reader), new IeTime56(reader) }
                };
                break;

            // 39
            case TypeId.M_EP_TE_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeProtectionStartEvent(reader),
                        new IeProtectionQuality(reader), new IeTime16(reader), new IeTime56(reader)
                    }
                };
                break;

            // 40
            case TypeId.M_EP_TF_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeProtectionOutputCircuitInformation(reader),
                        new IeProtectionQuality(reader), new IeTime16(reader), new IeTime56(reader)
                    }
                };
                break;

            // 45
            case TypeId.C_SC_NA_1:
                informationElements = new[] { new InformationElement[] { new IeSingleCommand(reader) } };
                break;

            // 46
            case TypeId.C_DC_NA_1:
                informationElements = new[] { new InformationElement[] { new IeDoubleCommand(reader) } };
                break;

            // 47
            case TypeId.C_RC_NA_1:
                informationElements = new[] { new InformationElement[] { new IeRegulatingStepCommand(reader) } };
                break;

            // 48
            case TypeId.C_SE_NA_1:
                informationElements = new[]
                { new InformationElement[] { new IeNormalizedValue(reader), new IeQualifierOfSetPointCommand(reader) } };
                break;

            // 49
            case TypeId.C_SE_NB_1:
                informationElements = new[]
                { new InformationElement[] { new IeScaledValue(reader), new IeQualifierOfSetPointCommand(reader) } };
                break;

            // 50
            case TypeId.C_SE_NC_1:
                informationElements = new[]
                { new InformationElement[] { new IeShortFloat(reader), new IeQualifierOfSetPointCommand(reader) } };
                break;

            // 51
            case TypeId.C_BO_NA_1:
                informationElements = new[] { new InformationElement[] { new IeBinaryStateInformation(reader) } };
                break;

            // 58
            case TypeId.C_SC_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeSingleCommand(reader), new IeTime56(reader) } };
                break;

            // 59
            case TypeId.C_DC_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeDoubleCommand(reader), new IeTime56(reader) } };
                break;

            // 60
            case TypeId.C_RC_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeBinaryStateInformation(reader), new IeTime56(reader) } };
                break;

            // 61
            case TypeId.C_SE_TA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNormalizedValue(reader),
                        new IeQualifierOfSetPointCommand(reader), new IeTime56(reader)
                    }
                };
                break;

            // 62
            case TypeId.C_SE_TB_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeScaledValue(reader),
                        new IeQualifierOfSetPointCommand(reader), new IeTime56(reader)
                    }
                };
                break;

            // 63
            case TypeId.C_SE_TC_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeShortFloat(reader),
                        new IeQualifierOfSetPointCommand(reader), new IeTime56(reader)
                    }
                };
                break;

            // 64
            case TypeId.C_BO_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeBinaryStateInformation(reader), new IeTime56(reader) } };
                break;

            // 70
            case TypeId.M_EI_NA_1:
                informationElements = new[] { new InformationElement[] { new IeCauseOfInitialization(reader) } };
                break;

            // 100
            case TypeId.C_IC_NA_1:
                informationElements = new[] { new InformationElement[] { new IeQualifierOfInterrogation(reader) } };
                break;

            // 101
            case TypeId.C_CI_NA_1:
                informationElements = new[]
                { new InformationElement[] { new IeQualifierOfCounterInterrogation(reader) } };
                break;

            // 102
            case TypeId.C_RD_NA_1:
                informationElements = new InformationElement[0][];
                break;

            // 103
            case TypeId.C_CS_NA_1:
                informationElements = new[] { new InformationElement[] { new IeTime56(reader) } };
                break;

            // 104
            case TypeId.C_TS_NA_1:
                informationElements = new[] { new InformationElement[] { new IeFixedTestBitPattern(reader) } };
                break;

            // 105
            case TypeId.C_RP_NA_1:
                informationElements = new[]
                { new InformationElement[] { new IeQualifierOfResetProcessCommand(reader) } };
                break;

            // 106
            case TypeId.C_CD_NA_1:
                informationElements = new[] { new InformationElement[] { new IeTime16(reader) } };
                break;

            // 107
            case TypeId.C_TS_TA_1:
                informationElements = new[]
                { new InformationElement[] { new IeTestSequenceCounter(reader), new IeTime56(reader) } };
                break;

            // 110
            case TypeId.P_ME_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNormalizedValue(reader),
                        new IeQualifierOfParameterOfMeasuredValues(reader)
                    }
                };
                break;

            // 111
            case TypeId.P_ME_NB_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeScaledValue(reader),
                        new IeQualifierOfParameterOfMeasuredValues(reader)
                    }
                };
                break;

            // 112
            case TypeId.P_ME_NC_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeShortFloat(reader),
                        new IeQualifierOfParameterOfMeasuredValues(reader)
                    }
                };
                break;

            // 113
            case TypeId.P_AC_NA_1:
                informationElements = new[]
                { new InformationElement[] { new IeQualifierOfParameterActivation(reader) } };
                break;

            // 120
            case TypeId.F_FR_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeLengthOfFileOrSection(reader),
                        new IeFileReadyQualifier(reader)
                    }
                };
                break;

            // 121
            case TypeId.F_SR_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeNameOfSection(reader),
                        new IeLengthOfFileOrSection(reader), new IeSectionReadyQualifier(reader)
                    }
                };
                break;

            // 122
            case TypeId.F_SC_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeNameOfSection(reader),
                        new IeSelectAndCallQualifier(reader)
                    }
                };
                break;

            // 123
            case TypeId.F_LS_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeNameOfSection(reader),
                        new IeLastSectionOrSegmentQualifier(reader), new IeChecksum(reader)
                    }
                };
                break;

            // 124
            case TypeId.F_AF_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeNameOfSection(reader),
                        new IeAckFileOrSectionQualifier(reader)
                    }
                };
                break;

            // 125
            case TypeId.F_SG_NA_1:
                informationElements = new[]
                {
                    new InformationElement[]
                    {
                        new IeNameOfFile(reader), new IeNameOfSection(reader),
                        new IeFileSegment(reader)
                    }
                };
                break;

            // 126
            case TypeId.F_DR_TA_1:
                informationElements = new InformationElement[numberOfSequenceElements][];
                for (var i = 0; i < numberOfSequenceElements; i++)
                {
                    informationElements[i]    = new InformationElement[4];
                    informationElements[i][0] = new IeNameOfFile(reader);
                    informationElements[i][1] = new IeLengthOfFileOrSection(reader);
                    informationElements[i][2] = new IeStatusOfFile(reader);
                    informationElements[i][3] = new IeTime56(reader);
                }
                break;

            // 127
            case TypeId.F_SC_NB_1:
                informationElements = new[]
                { new InformationElement[] { new IeNameOfFile(reader), new IeTime56(reader), new IeTime56(reader) } };
                break;

            default:
                throw new IOException(
                          "Unable to parse Information Object because of unknown Type Identification: " + typeId);
            }
        }
예제 #38
0
        static void Main(string[] args)
        {
            // Print SharpPcap version
            string ver = SharpPcap.Version.VersionString;
            Console.WriteLine("PacketDotNet example using SharpPcap {0}", ver);

            // Retrieve the device list
            var devices = AirPcapDeviceList.Instance;

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine();
            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            int i = 0;

            // Print out the devices
            foreach (var dev in devices)
            {
                /* Description */
                Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description);
                i++;
            }

            Console.WriteLine();
            Console.Write("-- Please choose a device to capture: ");
            i = int.Parse(Console.ReadLine());

            // Register a cancle handler that lets us break out of our capture loop
            // since we currently need to synchronously receive packets in order to get
            // raw packets. Future versions of SharpPcap are likely to
            // return ONLY raw packets at which time we can simplify this code and
            // use a PcapDevice.OnPacketArrival handler
            Console.CancelKeyPress += HandleCancelKeyPress;

            var device = (AirPcapDevice)devices[i];
            
            device.Open(DeviceMode.Normal);
            device.FcsValidation = AirPcapValidationType.ACCEPT_CORRECT_FRAMES;
            adapterAddress = device.MacAddress;
            device.AirPcapLinkType = AirPcapLinkTypes._802_11;

            PhysicalAddress broadcastAddress = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");

            
            Console.Write("Please enter the SSID to probe for (use empty string for broadcast probe): ");
            String ssid = Console.ReadLine();
            Console.WriteLine();



            //Make the probe packet to send
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            InformationElement ssidIe = new InformationElement(InformationElement.ElementId.ServiceSetIdentity, encoding.GetBytes(ssid));
            InformationElement supportedRatesIe = new InformationElement(InformationElement.ElementId.SupportedRates,
                new byte[] { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24 });
            InformationElement extendedSupportedRatesIe = new InformationElement(InformationElement.ElementId.ExtendedSupportedRates,
                new byte[] { 0x30, 0x48, 0x60, 0x6c });
            //Create a broadcast probe
            ProbeRequestFrame probe = new ProbeRequestFrame(device.MacAddress,
                                                            broadcastAddress,
                                                            broadcastAddress,
                                                            new InformationElementList() {ssidIe, supportedRatesIe, extendedSupportedRatesIe});

            Byte[] probeBytes = probe.Bytes;
            device.SendPacket(probeBytes, probeBytes.Length - 4);


            while (stopCapturing == false)
            {
                var rawCapture = device.GetNextPacket();

                // null packets can be returned in the case where
                // the GetNextRawPacket() timed out, we should just attempt
                // to retrieve another packet by looping the while() again
                if (rawCapture == null)
                {
                    // go back to the start of the while()
                    continue;
                }

                // use PacketDotNet to parse this packet and print out
                // its high level information
                MacFrame p = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data) as MacFrame;
                if (p.FrameControl.SubType == FrameControlField.FrameSubTypes.ManagementProbeResponse)
                {
                    ProbeResponseFrame probeResponse = p as ProbeResponseFrame;
                    if (probeResponse.DestinationAddress.Equals(adapterAddress))
                    {
                        var ie = probeResponse.InformationElements.FindFirstById(InformationElement.ElementId.ServiceSetIdentity);
                        Console.WriteLine("Response: {0}, SSID: {1}", probeResponse.SourceAddress, Encoding.UTF8.GetString(ie.Value)); 
                    }
                }
            }
        }
            public void Test_Bytes()
            {
                Byte[] value = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.VendorSpecific, value);

                Byte[] ieArray = infoElement.Bytes;

                Assert.AreEqual(7, ieArray.Length);
                Assert.AreEqual((Byte)InformationElement.ElementId.VendorSpecific, ieArray[0]);
                Assert.AreEqual(5, ieArray[1]);

                Byte[] actualValue = new Byte[5];
                Array.Copy(ieArray, 2, actualValue, 0, 5);
                Assert.IsTrue(value.SequenceEqual(actualValue));
            }
 public void Test_Constructor_ValueTooLong()
 {
     Byte[]             value       = new Byte[300];
     InformationElement infoElement = new InformationElement(
         InformationElement.ElementId.CfParameterSet, value);
 }
            public void Test_Equals_AreNotEqual()
            {
                Byte[] value = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 };
                InformationElement infoElement = new InformationElement(
                    InformationElement.ElementId.RobustSecurityNetwork, value);

                Byte[] otherValue = new Byte[] { 0xa, 0xb, 0xc, 0xd, 0xe };
                InformationElement otherInfoElement = new InformationElement(
                    InformationElement.ElementId.ChallengeText, otherValue);

                Assert.IsFalse(infoElement.Equals(otherInfoElement));
            }
            public void Test_Bytes_MultipleInfoElements ()
            {
                InformationElement ie1 = new InformationElement (
                    InformationElement.ElementId.WifiProtectedAccess, new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5 });

                InformationElement ie2 = new InformationElement (
                    InformationElement.ElementId.VendorSpecific, new Byte[] { 0xFF, 0xFE, 0xFD, 0xFC });
          
                InformationElementList ieList = new InformationElementList ();
                ieList.Add (ie1);
                ieList.Add (ie2);

                Byte[] expectedBytes = new Byte[] { 0xD3, 0x5, 0x1, 0x2, 0x3, 0x4, 0x5, 0xDD, 0x4, 0xFF, 0xFE, 0xFD, 0xFC };

                Byte[] b = ieList.Bytes;

                Assert.AreEqual (0xD3, b [0]);
                Assert.AreEqual (0x5, b [1]);
                Assert.AreEqual (0x1, b [2]);
                Assert.AreEqual (0x2, b [3]);
                Assert.AreEqual (0x3, b [4]);
                Assert.AreEqual (0x4, b [5]);
                Assert.AreEqual (0x5, b [6]);
                Assert.AreEqual (0xDD, b [7]);
                Assert.AreEqual (0x4, b [8]);
                Assert.AreEqual (0xFF, b [9]);
                Assert.AreEqual (0xFE, b [10]);
                Assert.AreEqual (0xFD, b [11]);
                Assert.AreEqual (0xFC, b [12]);

                Assert.IsTrue (ieList.Bytes.SequenceEqual (expectedBytes));
            }