/// <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; }
/// <summary> /// handler for mac beacon notifications /// </summary> /// <param name="sender"></param> /// <param name="BSN"></param> /// <param name="panDescriptor"></param> /// <param name="pendingShortAddrs"></param> /// <param name="pendingExtendedAddrs"></param> /// <param name="beaconPayload"></param> public void MacBeaconNotifyIndication( IMacMgmtSap sender, ushort BSN, PanDescriptor panDescriptor, ushort[] pendingShortAddrs, UInt64[] pendingExtendedAddrs, Frame beaconPayload) { if (!_scanning) return; ScanResultInternal res = new ScanResultInternal(); res.panDescriptor = panDescriptor; res.isMeshProtocol = false; if (beaconPayload.LengthDataUsed == 8) { UInt64 meshId = beaconPayload.ReadUInt64Canonical(0); if (meshId == NetworkLayer.cMeshId) { res.isMeshProtocol = true; } Frame.Release(ref beaconPayload); } lock (_scanResults) { _scanResults.Add(res); } }