public byte[] CalcDtMAC(MaslDtFrame frame, uint destAddress) { var totalLen = frame.UserDataLen + 6; using (var memStream = new MemoryStream(totalLen)) { // L var len = (ushort)(totalLen - 2); memStream.WriteByte((byte)((len >> 16) & 0xFF)); memStream.WriteByte((byte)(len & 0xFF)); // DA memStream.WriteByte((byte)((destAddress >> 16) & 0xFF)); memStream.WriteByte((byte)((destAddress >> 8) & 0xFF)); memStream.WriteByte((byte)((destAddress) & 0xFF)); // ETY+MTI+DF memStream.WriteByte(frame.GetHeaderByte()); // UserData memStream.Write(frame.UserData, 0, frame.UserDataLen); // var mac = _macCalc.CalcMac(memStream.ToArray()); return(mac); } }
public byte[] BuildDtPacket(byte[] userData) { var direction = _rsspEndPoint.IsInitiator ? MaslFrameDirection.Client2Server : MaslFrameDirection.Server2Client; var frame = new MaslDtFrame(direction, userData); frame.MAC = this.CalcDtMAC(frame, _rsspEndPoint.RemoteID); return(frame.GetBytes()); }
public void Test1() { var data = new byte[] { 0x11, 0xF1, 0x1C }; var mac = new byte[] { 0x4f, 0x2c, 0xe, 0xa1, 0x3f, 0x3e, 0xb4, 0x4a }; var frame1 = new MaslDtFrame(MaslFrameDirection.Client2Server, data); frame1.MAC = mac; var bytes = frame1.GetBytes(); var frame2 = new MaslDtFrame(); frame2.ParseBytes(bytes, 0, bytes.Length - 1); Assert.AreEqual(frame1.DeviceType, frame2.DeviceType); Assert.AreEqual(frame1.Direction, frame2.Direction); Assert.AreEqual(frame1.FrameType, frame2.FrameType); CollectionAssert.AreEqual(frame1.UserData, frame2.UserData); CollectionAssert.AreEqual(frame1.MAC, frame2.MAC); }
public virtual void HandleDtFrame(MaslDtFrame frame) { LogUtility.Error(string.Format("{0}: {1}.{2} not implement!", this.Context.RsspEP.ID, this.GetType().Name, new StackFrame(0).GetMethod().Name.Split('.').Last())); }