/// <summary> /// ReadFromFrame frame type /// </summary> /// <param name="frame">frame containing encoded Mac SDU</param> /// <returns>type, reserved value on error</returns> static public bool GetType(Frame frame, out Type type) { if (frame != null && frame.LengthDataUsed >= 2) { FCS fcs = new FCS(); fcs.Value = frame.ReadUInt16Canonical(0); type = fcs.Type; return true; } type = Type.Ack; // any value return false; }
/// <summary> /// Decodes a header /// </summary> /// <param name="frame">The frame containing the header</param> /// <param name="removeHeader">If true, the header will be removed from the frame after decoding</param> /// <returns>True on success, false on decoding error</returns> public bool ReadFromFrameHeader(Frame frame, bool removeHeader) { int len = 2 + 1; // fcs + seqNo // check minimum length if (frame.LengthDataUsed < len) return false; fcs.Value = frame.ReadUInt16Canonical(0); seqNo = frame.ReadByte(2); // calculate variable length len = Length(); if (frame.LengthDataUsed < len) return false; AddressingMode dstMode = fcs.DstAddrMode; AddressingMode srcMode = fcs.SrcAddrMode; bool panIdCompression = fcs.PanIdCompression; int offset = 3; if (dstMode != AddressingMode.None) { // dstPanId dstPanId = frame.ReadUInt16Canonical(offset); offset += 2; } if (dstMode == AddressingMode.Short) { // dstAddrShort dstAddrShort = frame.ReadUInt16Canonical(offset); offset += 2; } if (dstMode == AddressingMode.Extended) { // dstAddrShort dstAddrExt = frame.ReadUInt64Canonical(offset); offset += 8; } if (srcMode != AddressingMode.None && !panIdCompression) { // srcPanId srcPanId = frame.ReadUInt16Canonical(offset); offset += 2; } if (srcMode == AddressingMode.Short) { // dstAddrShort srcAddrShort = frame.ReadUInt16Canonical(offset); offset += 2; } if (srcMode == AddressingMode.Extended) { // dstAddrShort srcAddrExt = frame.ReadUInt64Canonical(offset); offset += 8; } // FIXME: secHeader if (removeHeader) frame.DeleteFromFront(len); return true; }