/* This file is part of PacketDotNet PacketDotNet is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PacketDotNet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with PacketDotNet. If not, see . */ /* * Copyright 2012 Alan Rushforth */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using PacketDotNet.Utils; namespace PacketDotNet { namespace Ieee80211 { /// /// Data data frame. /// public class DataDataFrame : DataFrame { /// /// Gets the size of the frame. /// /// /// The size of the frame. /// public override int FrameSize { get { //if we are in WDS mode then there are 4 addresses (normally it is just 3) int numOfAddressFields = (FrameControl.ToDS && FrameControl.FromDS) ? 4 : 3; return (MacFields.FrameControlLength + MacFields.DurationIDLength + (MacFields.AddressLength * numOfAddressFields) + MacFields.SequenceControlLength); } } /// /// Initializes a new instance of the class. /// /// /// Bas. /// public DataDataFrame (ByteArraySegment bas) { header = new ByteArraySegment (bas); FrameControl = new FrameControlField (FrameControlBytes); Duration = new DurationField (DurationBytes); SequenceControl = new SequenceControlField (SequenceControlBytes); ReadAddresses (); //must do this after reading FrameControl header.Length = FrameSize; var availablePayloadLength = GetAvailablePayloadLength(); if(availablePayloadLength > 0) { payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes (availablePayloadLength); } } /// /// Initializes a new instance of the class. /// public DataDataFrame () { this.FrameControl = new FrameControlField (); this.Duration = new DurationField (); this.SequenceControl = new SequenceControlField (); AssignDefaultAddresses (); FrameControl.SubType = FrameControlField.FrameSubTypes.Data; } /// /// Writes the current packet properties to the backing ByteArraySegment. /// public override void UpdateCalculatedValues () { if ((header == null) || (header.Length > (header.BytesLength - header.Offset)) || (header.Length < FrameSize)) { header = new ByteArraySegment (new Byte[FrameSize]); } this.FrameControlBytes = this.FrameControl.Field; this.DurationBytes = this.Duration.Field; this.SequenceControlBytes = this.SequenceControl.Field; WriteAddressBytes (); } } } }