/* 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 System.Net.NetworkInformation; using PacketDotNet.Utils; using MiscUtil.Conversion; namespace PacketDotNet { namespace Ieee80211 { /// /// Block acknowledgment request frame. /// public class BlockAcknowledgmentRequestFrame : MacFrame { private class BlockAckRequestField { public readonly static int BlockAckRequestControlLength = 2; public readonly static int BlockAckStartingSequenceControlLength = 2; public readonly static int BlockAckRequestControlPosition; public readonly static int BlockAckStartingSequenceControlPosition; static BlockAckRequestField() { BlockAckRequestControlPosition = MacFields.DurationIDPosition + MacFields.DurationIDLength + (2 * MacFields.AddressLength); BlockAckStartingSequenceControlPosition = BlockAckRequestControlPosition + BlockAckRequestControlLength; } } /// /// Receiver address /// public PhysicalAddress ReceiverAddress {get; set;} /// /// Transmitter address /// public PhysicalAddress TransmitterAddress {get; set;} /// /// Block acknowledgment control bytes are the first two bytes of the frame /// private UInt16 BlockAckRequestControlBytes { get { if(header.Length >= (BlockAckRequestField.BlockAckRequestControlPosition + BlockAckRequestField.BlockAckRequestControlLength)) { return EndianBitConverter.Little.ToUInt16(header.Bytes, header.Offset + BlockAckRequestField.BlockAckRequestControlPosition); } else { return 0; } } set { EndianBitConverter.Little.CopyBytes(value, header.Bytes, header.Offset + BlockAckRequestField.BlockAckRequestControlPosition); } } /// /// Block acknowledgment control field /// public BlockAcknowledgmentControlField BlockAcknowledgmentControl { get; set; } /// /// Gets or sets the sequence number of the first MSDU for which this /// block acknowledgement request frame is sent /// /// /// The block ack starting sequence control field value /// public UInt16 BlockAckStartingSequenceControl {get; set;} /// /// Gets or sets the block ack starting sequence control. /// /// /// The block ack starting sequence control. /// private UInt16 BlockAckStartingSequenceControlBytes { get { if(header.Length >= (BlockAckRequestField.BlockAckStartingSequenceControlPosition + BlockAckRequestField.BlockAckStartingSequenceControlLength)) { return EndianBitConverter.Little.ToUInt16(header.Bytes, header.Offset + BlockAckRequestField.BlockAckStartingSequenceControlPosition); } else { return 0; } } set { EndianBitConverter.Little.CopyBytes(value, header.Bytes, header.Offset + BlockAckRequestField.BlockAckStartingSequenceControlPosition); } } /// /// Length of the frame /// override public int FrameSize { get { return (MacFields.FrameControlLength + MacFields.DurationIDLength + (MacFields.AddressLength * 2) + BlockAckRequestField.BlockAckRequestControlLength + BlockAckRequestField.BlockAckStartingSequenceControlLength); } } /// /// Constructor /// /// /// A /// public BlockAcknowledgmentRequestFrame (ByteArraySegment bas) { header = new ByteArraySegment (bas); FrameControl = new FrameControlField (FrameControlBytes); Duration = new DurationField (DurationBytes); ReceiverAddress = GetAddress (0); TransmitterAddress = GetAddress (1); BlockAcknowledgmentControl = new BlockAcknowledgmentControlField (BlockAckRequestControlBytes); BlockAckStartingSequenceControl = BlockAckStartingSequenceControlBytes; header.Length = FrameSize; } /// /// Initializes a new instance of the class. /// /// /// Transmitter address. /// /// /// Receiver address. /// public BlockAcknowledgmentRequestFrame (PhysicalAddress TransmitterAddress, PhysicalAddress ReceiverAddress) { this.FrameControl = new FrameControlField (); this.Duration = new DurationField (); this.ReceiverAddress = ReceiverAddress; this.TransmitterAddress = TransmitterAddress; this.BlockAcknowledgmentControl = new BlockAcknowledgmentControlField (); this.FrameControl.SubType = FrameControlField.FrameSubTypes.ControlBlockAcknowledgmentRequest; } /// /// 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; SetAddress (0, ReceiverAddress); SetAddress (1, TransmitterAddress); this.BlockAckRequestControlBytes = this.BlockAcknowledgmentControl.Field; this.BlockAckStartingSequenceControlBytes = this.BlockAckStartingSequenceControl; header.Length = FrameSize; } /// /// Returns a string with a description of the addresses used in the packet. /// This is used as a compoent of the string returned by ToString(). /// /// /// The address string. /// protected override String GetAddressString() { return String.Format("RA {0} TA {1}", ReceiverAddress, TransmitterAddress); } } } }