public void Test_Bytes_ConstructedPacketWithFcsIncluded() { //We will use a DataDataFrame for this test but the //type isn't really important. var dataFrame = new DataDataFrame(); dataFrame.FrameControl.FromDS = true; dataFrame.BssId = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.SourceAddress = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.DestinationAddress = PhysicalAddress.Parse("112233445566"); dataFrame.PayloadData = new Byte[] { 0x1, 0x2, 0x3, 0x4 }; //Force it to recalculate the FCS and include it when serialised dataFrame.UpdateFrameCheckSequence(); dataFrame.AppendFcs = true; Assert.IsTrue(dataFrame.FCSValid); var expectedLength = dataFrame.FrameSize + dataFrame.PayloadData.Length + 4; Byte[] frameBytes = dataFrame.Bytes; Assert.AreEqual(expectedLength, frameBytes.Length); Assert.AreEqual(dataFrame.FrameCheckSequence.ToString("X"), EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4).ToString("X")); Assert.AreEqual(dataFrame.FrameCheckSequence, EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4)); }
public void Test_Constructor_UnecryptedDataFrameFromValues() { DataDataFrame frame = new DataDataFrame(); 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.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 DataDataFrame recreatedFrame = MacFrame.ParsePacket(bas) 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_Bytes_ConstructedPacketWithFcsNotIncluded() { //We will use a DataDataFrame for this test but the //type isn't really important. var dataFrame = new DataDataFrame(); dataFrame.FrameControl.FromDS = true; dataFrame.BssId = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.SourceAddress = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.DestinationAddress = PhysicalAddress.Parse("112233445566"); dataFrame.PayloadData = new Byte[] { 0x01, 0x02, 0x03, 0x04 }; //Force it to recalculate the FCS but don't include it when serialised dataFrame.UpdateFrameCheckSequence(); dataFrame.AppendFcs = false; var expectedLength = dataFrame.FrameSize + dataFrame.PayloadData.Length; var frameBytes = dataFrame.Bytes; Assert.AreEqual(expectedLength, frameBytes.Length); //Check that we get last four bytes of data at the end rather than the FCS Assert.AreEqual(0x01020304, EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4)); }
public void Test_Constructor_UnecryptedDataFrameFromValues () { DataDataFrame frame = new DataDataFrame (); 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.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 DataDataFrame recreatedFrame = MacFrame.ParsePacket (bas) 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_Bytes_ConstructedPacketWithFcsNotIncluded() { //We will use a DataDataFrame for this test but the //type isn't really important. var dataFrame = new DataDataFrame(); dataFrame.FrameControl.FromDS = true; dataFrame.BssId = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.SourceAddress = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.DestinationAddress = PhysicalAddress.Parse("112233445566"); dataFrame.PayloadData = new byte[]{0x01, 0x02, 0x03, 0x04}; //Force it to recalculate the FCS but don't include it when serialised dataFrame.UpdateFrameCheckSequence(); dataFrame.AppendFcs = false; var expectedLength = dataFrame.FrameSize + dataFrame.PayloadData.Length; var frameBytes = dataFrame.Bytes; Assert.AreEqual(expectedLength, frameBytes.Length); //Check that we get last four bytes of data at the end rather than the FCS Assert.AreEqual(0x01020304, EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4)); }
public void Test_Bytes_ConstructedPacketWithFcsIncluded() { //We will use a DataDataFrame for this test but the //type isn't really important. var dataFrame = new DataDataFrame(); dataFrame.FrameControl.FromDS = true; dataFrame.BssId = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.SourceAddress = PhysicalAddress.Parse("AABBCCDDEEFF"); dataFrame.DestinationAddress = PhysicalAddress.Parse("112233445566"); dataFrame.PayloadData = new byte[]{0x1, 0x2, 0x3, 0x4}; //Force it to recalculate the FCS and include it when serialised dataFrame.UpdateFrameCheckSequence(); dataFrame.AppendFcs = true; Assert.IsTrue(dataFrame.FCSValid); var expectedLength = dataFrame.FrameSize + dataFrame.PayloadData.Length + 4; byte[] frameBytes = dataFrame.Bytes; Assert.AreEqual(expectedLength, frameBytes.Length); Assert.AreEqual(dataFrame.FrameCheckSequence.ToString("X"), EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4).ToString("X")); Assert.AreEqual(dataFrame.FrameCheckSequence, EndianBitConverter.Big.ToUInt32(frameBytes, frameBytes.Length - 4)); }