Пример #1
0
        public static int DecodeAllBlocks(System.IO.Stream buffer, ushort dcp_length, out Dictionary <BlockOptions, object> blocks)
        {
            int ret = 0, r;
            KeyValuePair <DCP.BlockOptions, object> value;

            blocks = new Dictionary <BlockOptions, object>();
            while ((r = DCP.DecodeNextBlock(buffer, (ushort)(dcp_length - ret), out value)) > 0)
            {
                ret += r;
                if (!blocks.ContainsKey(value.Key))
                {
                    blocks.Add(value.Key, value.Value);
                }
                else
                {
                    Trace.TraceError("Multiple blocks in reply: " + value.Key);
                }
            }
            if (r < 0)
            {
                return(r);                      //error
            }
            else
            {
                return(ret);
            }
        }
Пример #2
0
        public static int EncodeHeader(System.IO.Stream buffer, PacketTypes type, Flags1 flags1, Flags2 flags2, Encodings encoding, UInt16 serial_high_low, Guid object_id, Guid interface_id, Guid activity_id, UInt32 server_boot_time, UInt32 sequence_no, Operations op, UInt16 body_length, UInt16 fragment_no, out long body_length_position)
        {
            int ret = 0;

            ret += DCP.EncodeU8(buffer, 4);             //RPCVersion
            ret += DCP.EncodeU8(buffer, (byte)type);
            ret += DCP.EncodeU8(buffer, (byte)flags1);
            ret += DCP.EncodeU8(buffer, (byte)flags2);
            ret += DCP.EncodeU16(buffer, (ushort)encoding);
            ret += DCP.EncodeU8(buffer, 0);             //pad
            ret += DCP.EncodeU8(buffer, (byte)(serial_high_low >> 8));
            ret += EncodeGuid(buffer, encoding, object_id);
            ret += EncodeGuid(buffer, encoding, interface_id);
            ret += EncodeGuid(buffer, encoding, activity_id);
            ret += EncodeU32(buffer, encoding, server_boot_time);
            ret += EncodeU32(buffer, encoding, 1);               //interface version
            ret += EncodeU32(buffer, encoding, sequence_no);
            ret += EncodeU16(buffer, encoding, (ushort)op);
            ret += EncodeU16(buffer, encoding, 0xFFFF);                 //interface hint
            ret += EncodeU16(buffer, encoding, 0xFFFF);                 //activity hint
            body_length_position = buffer.Position;
            ret += EncodeU16(buffer, encoding, body_length);
            ret += EncodeU16(buffer, encoding, fragment_no);
            ret += DCP.EncodeU8(buffer, 0);             //authentication protocol
            ret += DCP.EncodeU8(buffer, (byte)(serial_high_low & 0xFF));

            return(ret);
        }
Пример #3
0
        public static int DecodeFrameId(System.IO.Stream buffer, out FrameIds value)
        {
            ushort val;

            DCP.DecodeU16(buffer, out val);
            value = (FrameIds)val;
            return(2);
        }
Пример #4
0
        public static int EncodeRTCStatus(System.IO.Stream buffer, UInt16 CycleCounter, DataStatus DataStatus, TransferStatus TransferStatus)
        {
            int ret = 0;

            ret += DCP.EncodeU16(buffer, CycleCounter);
            ret += DCP.EncodeU8(buffer, (byte)DataStatus);
            ret += DCP.EncodeU8(buffer, (byte)TransferStatus);

            return(ret);
        }
Пример #5
0
        public static int Encode(System.IO.Stream buffer, System.Net.NetworkInformation.PhysicalAddress destination, System.Net.NetworkInformation.PhysicalAddress source, Type type)
        {
            //destination
            DCP.EncodeOctets(buffer, destination.GetAddressBytes());

            //source
            DCP.EncodeOctets(buffer, source.GetAddressBytes());

            //type
            DCP.EncodeU16(buffer, (ushort)type);

            return(14);
        }
Пример #6
0
        public static int DecodeRTCStatus(System.IO.Stream buffer, out UInt16 CycleCounter, out DataStatus DataStatus, out TransferStatus TransferStatus)
        {
            int  ret = 0;
            byte tmp;

            ret           += DCP.DecodeU16(buffer, out CycleCounter);
            ret           += DCP.DecodeU8(buffer, out tmp);
            DataStatus     = (DataStatus)tmp;
            ret           += DCP.DecodeU8(buffer, out tmp);
            TransferStatus = (TransferStatus)tmp;

            return(ret);
        }
Пример #7
0
        public static int DecodeHeader(System.IO.Stream buffer, out PacketTypes type, out Flags1 flags1, out Flags2 flags2, out Encodings encoding, out UInt16 serial_high_low, out Guid object_id, out Guid interface_id, out Guid activity_id, out UInt32 server_boot_time, out UInt32 sequence_no, out Operations op, out UInt16 body_length, out UInt16 fragment_no)
        {
            int    ret = 0;
            byte   tmp1;
            UInt16 tmp2;
            UInt32 tmp3;

            serial_high_low = 0;

            ret += DCP.DecodeU8(buffer, out tmp1);             //RPCVersion
            if (tmp1 != 4)
            {
                throw new Exception("Wrong protocol");
            }
            ret             += DCP.DecodeU8(buffer, out tmp1);
            type             = (PacketTypes)tmp1;
            ret             += DCP.DecodeU8(buffer, out tmp1);
            flags1           = (Flags1)tmp1;
            ret             += DCP.DecodeU8(buffer, out tmp1);
            flags2           = (Flags2)tmp1;
            ret             += DCP.DecodeU16(buffer, out tmp2);
            encoding         = (Encodings)tmp2;
            ret             += DCP.DecodeU8(buffer, out tmp1); //pad
            ret             += DCP.DecodeU8(buffer, out tmp1);
            serial_high_low |= (UInt16)(tmp1 << 8);
            ret             += DecodeGuid(buffer, encoding, out object_id);
            ret             += DecodeGuid(buffer, encoding, out interface_id);
            ret             += DecodeGuid(buffer, encoding, out activity_id);
            ret             += DecodeU32(buffer, encoding, out server_boot_time);
            ret             += DecodeU32(buffer, encoding, out tmp3);   //interface version
            if ((tmp3 & 0xFFFF) != 1)
            {
                throw new Exception("Wrong protocol version");
            }
            ret             += DecodeU32(buffer, encoding, out sequence_no);
            ret             += DecodeU16(buffer, encoding, out tmp2);
            op               = (Operations)tmp2;
            ret             += DecodeU16(buffer, encoding, out tmp2);     //interface hint
            ret             += DecodeU16(buffer, encoding, out tmp2);     //activity hint
            ret             += DecodeU16(buffer, encoding, out body_length);
            ret             += DecodeU16(buffer, encoding, out fragment_no);
            ret             += DCP.DecodeU8(buffer, out tmp1); //authentication protocol
            ret             += DCP.DecodeU8(buffer, out tmp1);
            serial_high_low |= tmp1;

            return(ret);
        }
Пример #8
0
        public static int EncodeGuid(System.IO.Stream buffer, Encodings encoding, Guid value)
        {
            int ret = 0;

            byte[] bytes = value.ToByteArray();
            UInt32 Data1 = BitConverter.ToUInt32(bytes, 0);
            UInt16 Data2 = BitConverter.ToUInt16(bytes, 4);
            UInt16 Data3 = BitConverter.ToUInt16(bytes, 6);

            byte[] Data4 = new byte[8];
            Array.Copy(bytes, 8, Data4, 0, 8);
            ret += EncodeU32(buffer, encoding, Data1);
            ret += EncodeU16(buffer, encoding, Data2);
            ret += EncodeU16(buffer, encoding, Data3);
            ret += DCP.EncodeOctets(buffer, Data4);
            return(ret);
        }
Пример #9
0
        public static int DecodeRTAHeader(System.IO.Stream buffer, out UInt16 AlarmDestinationEndpoint, out UInt16 AlarmSourceEndpoint, out PDUTypes PDUType, out AddFlags AddFlags, out UInt16 SendSeqNum, out UInt16 AckSeqNum, out UInt16 VarPartLen)
        {
            int  ret = 0;
            byte tmp;

            ret     += DCP.DecodeU16(buffer, out AlarmDestinationEndpoint);
            ret     += DCP.DecodeU16(buffer, out AlarmSourceEndpoint);
            ret     += DCP.DecodeU8(buffer, out tmp);
            PDUType  = (PDUTypes)tmp;
            ret     += DCP.DecodeU8(buffer, out tmp);
            AddFlags = (AddFlags)tmp;
            ret     += DCP.DecodeU16(buffer, out SendSeqNum);
            ret     += DCP.DecodeU16(buffer, out AckSeqNum);
            ret     += DCP.DecodeU16(buffer, out VarPartLen);

            return(ret);
        }
Пример #10
0
        public static int Encode(System.IO.Stream buffer, Priorities priority, Type type)
        {
            UInt16 tmp = 0;

            //Priority
            tmp |= (UInt16)((((UInt16)priority) & 0x7) << 13);

            //CanonicalFormatIdentificator
            tmp |= 0 << 12;

            //VLAN_Id
            tmp |= 0;

            DCP.EncodeU16(buffer, tmp);
            DCP.EncodeU16(buffer, (UInt16)type);

            return(4);
        }
Пример #11
0
 public static int EncodeFrameId(System.IO.Stream buffer, FrameIds value)
 {
     return(DCP.EncodeU16(buffer, (ushort)value));
 }