示例#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);
            }
示例#2
0
            public void Test_Constructor_ConstructWithValues()
            {
                QosNullDataFrame frame = new QosNullDataFrame();

                frame.FrameControl.ToDS          = false;
                frame.FrameControl.FromDS        = true;
                frame.FrameControl.MoreFragments = 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.AppendFcs = 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
                QosNullDataFrame recreatedFrame = MacFrame.ParsePacketWithFcs(bas) as QosNullDataFrame;

                Assert.AreEqual(FrameControlField.FrameSubTypes.QosNullData, 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());

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
示例#3
0
        public void Test_Constructor_ConstructWithValues()
        {
            var frame = new NullDataFrame
            {
                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 },
                AppendFcs   = true
            };

            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.ParsePacketWithFcs(byteArraySegment) as NullDataFrame;

            Assert.AreEqual(FrameControlField.FrameSubTypes.DataNullFunctionNoData, 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());

            Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
        }
示例#4
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);
            }