Esempio n. 1
0
            internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment payload, FlagsRadioTapField flagsField)
            {
                var      payloadPacketOrData = new PacketOrByteArraySegment();
                MacFrame frame = null;

                if (flagsField != null)
                {
                    bool fcsPresent = ((flagsField.Flags & RadioTapFlags.FcsIncludedInFrame) == RadioTapFlags.FcsIncludedInFrame);

                    if (fcsPresent)
                    {
                        frame = MacFrame.ParsePacketWithFcs(payload);
                    }
                    else
                    {
                        frame = MacFrame.ParsePacket(payload);
                    }
                }
                else
                {
                    frame = MacFrame.ParsePacket(payload);
                }

                if (frame == null)
                {
                    payloadPacketOrData.TheByteArraySegment = payload;
                }
                else
                {
                    payloadPacketOrData.ThePacket = frame;
                }

                return(payloadPacketOrData);
            }
Esempio n. 2
0
            public void Test_Constructor_ConstructWithValues()
            {
                AckFrame frame = new AckFrame(PhysicalAddress.Parse("111111111111"));

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

                frame.Duration.Field = 0x1234;

                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
                AckFrame recreatedFrame = MacFrame.ParsePacket(bas) as AckFrame;

                recreatedFrame.UpdateFrameCheckSequence();

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

                Assert.AreEqual("111111111111", recreatedFrame.ReceiverAddress.ToString().ToUpper());

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
        public void Test_Constructor_ConstructWithValues()
        {
            var frame = new ContentionFreeEndFrame(PhysicalAddress.Parse("111111111111"),
                                                   PhysicalAddress.Parse("222222222222"))
            {
                FrameControl = { ToDS = false, FromDS = true, MoreFragments = true },
                Duration     = { Field = 0x1234 }
            };

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

            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 ContentionFreeEndFrame;

            recreatedFrame.UpdateFrameCheckSequence();

            Assert.AreEqual(FrameControlField.FrameSubTypes.ControlCFEnd, recreatedFrame.FrameControl.SubType);
            Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
            Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
            Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);
            Assert.AreEqual(0x1234, recreatedFrame.Duration.Field);

            Assert.AreEqual("111111111111", recreatedFrame.ReceiverAddress.ToString().ToUpper());
            Assert.AreEqual("222222222222", recreatedFrame.BssId.ToString().ToUpper());

            Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
        }
Esempio n. 4
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);
            }
Esempio n. 5
0
        /// <summary>Parse bytes into a packet</summary>
        /// <param name="LinkLayer">
        /// A <see cref="T:PacketDotNet.LinkLayers" /></param>
        /// <param name="PacketData">
        /// A <see cref="T:System.Byte" /></param>
        /// <returns>
        /// A <see cref="T:PacketDotNet.Packet" /></returns>
        public static Packet ParsePacket(LinkLayers LinkLayer, byte[] PacketData)
        {
            ByteArraySegment bas = new ByteArraySegment(PacketData);

            switch (LinkLayer)
            {
            case LinkLayers.Ethernet:
                return((Packet) new EthernetPacket(bas));

            case LinkLayers.Ppp:
                return((Packet) new PPPPacket(bas));

            case LinkLayers.Ieee80211:
                return((Packet)MacFrame.ParsePacket(bas));

            case LinkLayers.LinuxSLL:
                return((Packet) new LinuxSLLPacket(bas));

            case LinkLayers.Ieee80211_Radio:
                return((Packet) new RadioPacket(bas));

            case LinkLayers.PerPacketInformation:
                return((Packet) new PpiPacket(bas));

            default:
                throw new NotImplementedException("LinkLayer of " + (object)LinkLayer + " is not implemented");
            }
        }
            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);
            }
        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);
        }
Esempio n. 8
0
            public void Test_Constructor_ConstructWithValues()
            {
                QosDataFrame frame = new QosDataFrame();

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

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

                frame.Duration.Field = 0x1234;

                frame.QosControl = 0x9876;

                frame.DestinationAddress = PhysicalAddress.Parse("111111111111");
                frame.SourceAddress      = PhysicalAddress.Parse("222222222222");
                frame.BssId = PhysicalAddress.Parse("333333333333");

                frame.PayloadData = new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

                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
                QosDataFrame recreatedFrame = MacFrame.ParsePacket(bas) as QosDataFrame;

                recreatedFrame.UpdateFrameCheckSequence();

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

                Assert.AreEqual(0x89, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual(0x1, recreatedFrame.SequenceControl.FragmentNumber);
                Assert.AreEqual(0x9876, recreatedFrame.QosControl);

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

                CollectionAssert.AreEqual(new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, recreatedFrame.PayloadData);

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
            public void Test_Constructor_ConstructWithValues()
            {
                Byte[] BlockAckBitmap = new Byte[] { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 };

                BlockAcknowledgmentFrame frame = new BlockAcknowledgmentFrame(PhysicalAddress.Parse("111111111111"),
                                                                              PhysicalAddress.Parse("222222222222"),
                                                                              BlockAckBitmap);

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

                frame.Duration.Field = 0x1234;

                frame.BlockAcknowledgmentControl.Policy = BlockAcknowledgmentControlField.AcknowledgementPolicy.Delayed;
                frame.BlockAcknowledgmentControl.Tid    = 0xF;

                frame.BlockAckStartingSequenceControl = 0x5678;

                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
                BlockAcknowledgmentFrame recreatedFrame = MacFrame.ParsePacket(bas) as BlockAcknowledgmentFrame;

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ControlBlockAcknowledgment, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);
                Assert.AreEqual(0x1234, recreatedFrame.Duration.Field);
                Assert.AreEqual(BlockAcknowledgmentControlField.AcknowledgementPolicy.Delayed,
                                recreatedFrame.BlockAcknowledgmentControl.Policy);

                Assert.AreEqual(0xF, recreatedFrame.BlockAcknowledgmentControl.Tid);
                Assert.IsTrue(recreatedFrame.BlockAcknowledgmentControl.CompressedBitmap);
                Assert.AreEqual(0x5678, recreatedFrame.BlockAckStartingSequenceControl);

                Assert.AreEqual("111111111111", recreatedFrame.TransmitterAddress.ToString().ToUpper());
                Assert.AreEqual("222222222222", recreatedFrame.ReceiverAddress.ToString().ToUpper());

                CollectionAssert.AreEqual(BlockAckBitmap, recreatedFrame.BlockAckBitmap);

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
Esempio n. 10
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);
            }
Esempio n. 11
0
            public void Test_Constructor_ConstructWithValues()
            {
                DeauthenticationFrame frame = new DeauthenticationFrame(PhysicalAddress.Parse("111111111111"),
                                                                        PhysicalAddress.Parse("222222222222"),
                                                                        PhysicalAddress.Parse("333333333333"));

                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.Reason = ReasonCode.LeavingToRoam;

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

                var bytes = frame.Bytes;
                var bas   = new ByteArraySegment(bytes);

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

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementDeauthentication, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);
                Assert.AreEqual(0x1234, recreatedFrame.Duration.Field);

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

                Assert.AreEqual(ReasonCode.LeavingToRoam, recreatedFrame.Reason);

                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);
            }
Esempio n. 12
0
        /// <summary>
        ///     Parse bytes into a packet
        /// </summary>
        /// <param name="linkLayer">
        ///     A <see cref="LinkLayers" />
        /// </param>
        /// <param name="packetData">
        ///     A <see cref="System.Byte" />
        /// </param>
        /// <returns>
        ///     A <see cref="Packet" />
        /// </returns>
        public static Packet ParsePacket(LinkLayers linkLayer, byte[] packetData)
        {
            Packet p;
            var    bas = new ByteArraySegment(packetData);

            Log.DebugFormat("LinkLayer {0}", linkLayer);

            switch (linkLayer)
            {
            case LinkLayers.Ethernet:
                p = new EthernetPacket(bas);
                break;

            case LinkLayers.LinuxSLL:
                p = new LinuxSLLPacket(bas);
                break;

            case LinkLayers.Ppp:
                p = new PPPPacket(bas);
                break;

            case LinkLayers.Ieee80211:
                p = MacFrame.ParsePacket(bas);
                break;

            case LinkLayers.Ieee80211_Radio:
                p = new RadioPacket(bas);
                break;

            case LinkLayers.PerPacketInformation:
                p = new PpiPacket(bas);
                break;

            //http://sourceforge.net/p/packetnet/patches/1/
            case LinkLayers.Raw:
                var ipVer = (packetData[0] & 0xf0) >> 4;
                p = (ipVer == 4)? new IPv4Packet(bas) : new IPv6Packet(bas) as Packet;
                break;

            default:
                throw new NotImplementedException("LinkLayer of " + linkLayer + " is not implemented");
            }

            return(p);
        }
Esempio n. 13
0
        public void Test_Constructor_UnecryptedDataFrameFromValues()
        {
            var frame = new DataDataFrame
            {
                FrameControl       = { ToDS = false, FromDS = true, MoreFragments = true },
                SequenceControl    = { SequenceNumber = 0x89, FragmentNumber = 0x1 },
                Duration           = { Field = 0x1234 },
                DestinationAddress = PhysicalAddress.Parse("111111111111"),
                SourceAddress      = PhysicalAddress.Parse("222222222222"),
                BssId       = PhysicalAddress.Parse("333333333333"),
                PayloadData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }
            };

            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 DataDataFrame;

            recreatedFrame.UpdateFrameCheckSequence();

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

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

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

            CollectionAssert.AreEqual(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, recreatedFrame.PayloadData);

            Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
        }
        public void Test_Constructor_ConstructWithValues()
        {
            var frame = new BlockAcknowledgmentRequestFrame(PhysicalAddress.Parse("111111111111"),
                                                            PhysicalAddress.Parse("222222222222"))
            {
                FrameControl = { ToDS = false, FromDS = true, MoreFragments = true },
                Duration     = { Field = 0x1234 },
                BlockAcknowledgmentControl      = { CompressedBitmap = true, Policy = BlockAcknowledgmentControlField.AcknowledgementPolicy.Delayed, Tid = 0xF },
                BlockAckStartingSequenceControl = 0x5678
            };

            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 BlockAcknowledgmentRequestFrame;

            recreatedFrame.UpdateFrameCheckSequence();

            Assert.AreEqual(FrameControlField.FrameSubTypes.ControlBlockAcknowledgmentRequest, recreatedFrame.FrameControl.SubType);
            Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
            Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
            Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);
            Assert.AreEqual(0x1234, recreatedFrame.Duration.Field);
            Assert.AreEqual(BlockAcknowledgmentControlField.AcknowledgementPolicy.Delayed,
                            recreatedFrame.BlockAcknowledgmentControl.Policy);

            Assert.AreEqual(0xF, recreatedFrame.BlockAcknowledgmentControl.Tid);
            Assert.IsTrue(recreatedFrame.BlockAcknowledgmentControl.CompressedBitmap);
            Assert.AreEqual(0x5678, recreatedFrame.BlockAckStartingSequenceControl);

            Assert.AreEqual("111111111111", recreatedFrame.TransmitterAddress.ToString().ToUpper());
            Assert.AreEqual("222222222222", recreatedFrame.ReceiverAddress.ToString().ToUpper());

            Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
        }
Esempio n. 15
0
            /// <summary>
            ///     Used by the Ieee80211PpiPacket constructor.
            /// </summary>
            /// <param name="header">
            ///     A <see cref="ByteArraySegment" />
            /// </param>
            /// <param name="commonField">
            ///     The <see cref="PpiCommon" /> object in the PPI packet or null if not available
            /// </param>
            /// <returns>
            ///     A <see cref="PacketOrByteArraySegment" />
            /// </returns>
            internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment header, PpiCommon commonField)
            {
                // slice off the payload
                var      payload             = header.EncapsulatedBytes();
                var      payloadPacketOrData = new PacketOrByteArraySegment();
                MacFrame frame = null;

                if (commonField != null)
                {
                    var fcsPresent = ((commonField.Flags & PpiCommon.CommonFlags.FcsIncludedInFrame) == PpiCommon.CommonFlags.FcsIncludedInFrame);

                    if (fcsPresent)
                    {
                        frame = MacFrame.ParsePacketWithFcs(payload);
                    }
                    else
                    {
                        frame = MacFrame.ParsePacket(payload);
                    }
                }
                else
                {
                    frame = MacFrame.ParsePacket(payload);
                }

                if (frame == null)
                {
                    payloadPacketOrData.TheByteArraySegment = payload;
                }
                else
                {
                    payloadPacketOrData.ThePacket = frame;
                }

                return(payloadPacketOrData);
            }