1 //
2 // Copyright (c) 2010-2018 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 using Antmicro.Renode.Utilities;
10 
11 
12 namespace Antmicro.Renode.Peripherals.USBDeprecated
13 {
14     public class USBEthernetControlModelDevicesSubclass : USBCommunicationClass
15     {
USBEthernetControlModelDevicesSubclass()16         public USBEthernetControlModelDevicesSubclass ()
17         {
18             //base.deviceDescriptor.DeviceSubClass = DeviceSubclassCode;
19         }
20         protected const byte DeviceSubclassCode = (byte)SubclassCode.EthernetNetworkingControlModel;
21         protected const byte ProtocolSubclassCode = (byte)ProtocolCode.NoClassSpecific;
22 
23         [Flags]
24         protected enum EthernetStatisticsCapability : uint
25         {
26             XmitOK = 1 << 0,
27             RvcOK = 1 << 1,
28             XmitError = 1 << 2,
29             RvcError = 1 << 3,
30             RvcNoBuffer = 1 << 4,
31             DirectedBytesXmit = 1 << 5,
32             DirectedFramesXmit = 1 << 6,
33             MulticastBytesXmit = 1 << 7,
34             MulticastFramesXmit = 1 << 8,
35             BroadcastBytesXmit = 1 << 9,
36             BroadcastFramesXmit = 1 << 10,
37             DirectedBytesRcv = 1 << 11,
38             DirectedFramesRcv = 1 << 12,
39             MulticastBytesRcv = 1 << 13,
40             MulticastFramesRcv = 1 << 14,
41             BroadcastBytesRcv = 1 << 15,
42             BroadcastFramesRcv = 1 << 16,
43             RcvCRCError = 1 << 17,
44             TransmitQueueLength = 1 << 18,
45             RcvErrorAlignment = 1 << 19,
46             XmitOneCollision  = 1 << 20,
47             XmitMoreCollision  = 1 << 21,
48             XmitDeferred  = 1 << 22,
49             XmitMaxCollisions = 1 << 23,
50             RcvOverrun = 1 << 24,
51             XmitUnderrun = 1 << 25,
52             XmitHeartbeatFailure = 1 << 26,
53             XmitTimesCrsLost = 1 << 27,
54             XmitLateCollisions = 1 << 28
55         }
56 
57         protected enum SubclassSpecificRequestCode
58         {
59             SetEthernetMulticastFilters = 0x40,
60             SetEthernetPowerManagementPatternFilter = 0x41,
61             GetEthernetPowerManagementPatternFilter = 0x42,
62             SetEthernetPacketFilter = 0x43,
63             GetEthernetStatistic = 0x44
64 
65         }
66 
67         protected enum SubclassSpecificNotificationCode
68         {
69             NetworkConnection = 0x00,
70             ResponseAvaliable = 0x01,
71             ConnectionSpeedChange = 0x2A
72         }
73 
74         protected enum EthernetStatisticsFeatureSelectorCode : byte
75         {
76             XmitOK = 0x01,
77             RvcOK = 0x02,
78             XmitError = 0x03,
79             RvcError = 0x04,
80             RvcNoBuffer = 0x05,
81             DirectedBytesXmit = 0x06,
82             DirectedFramesXmit = 0x07,
83             MulticastBytesXmit = 0x08,
84             MulticastFramesXmit = 0x09,
85             BroadcastBytesXmit = 0x0A,
86             BroadcastFramesXmit = 0x0B,
87             DirectedBytesRcv = 0x0C,
88             DirectedFramesRcv = 0x0D,
89             MulticastBytesRcv = 0x0F,
90             MulticastFramesRcv = 0x10,
91             BroadcastBytesRcv = 0x11,
92             BroadcastFramesRcv = 0x12,
93             RcvCRCError = 0x13,
94             TransmitQueueLength = 0x14,
95             RcvErrorAlignment = 0x15,
96             XmitOneCollision  = 0x16,
97             XmitMoreCollision  = 0x17,
98             XmitDeferred  = 0x18,
99             XmitMaxCollisions = 0x19,
100             RcvOverrun = 0x1A,
101             XmitUnderrun = 0x1B,
102             XmitHeartbeatFailure = 0x1C,
103             XmitTimesCrsLost = 0x1D,
104             XmitLateCollisions = 0x1D
105         }
106 
107         protected struct EthernetStatistics
108         {
109             public uint XmitOK;
110             public uint RvcOK;
111             public uint XmitError;
112             public uint RvcError;
113             public uint RvcNoBuffer;
114             public uint DirectedBytesXmit;
115             public uint DirectedFramesXmit;
116             public uint MulticastBytesXmit;
117             public uint MulticastFramesXmit;
118             public uint BroadcastBytesXmit;
119             public uint BroadcastFramesXmit;
120             public uint DirectedBytesRcv;
121             public uint DirectedFramesRcv;
122             public uint MulticastBytesRcv;
123             public uint MulticastFramesRcv;
124             public uint BroadcastBytesRcv;
125             public uint BroadcastFramesRcv;
126             public uint RcvCRCError;
127             public uint TransmitQueueLength;
128             public uint RcvErrorAlignment;
129             public uint XmitOneCollision;
130             public uint XmitMoreCollision;
131             public uint XmitDeferred;
132             public uint XmitMaxCollisions;
133             public uint RcvOverrun;
134             public uint XmitUnderrun;
135             public uint XmitHeartbeatFailure;
136             public uint XmitTimesCrsLost;
137             public uint XmitLateCollisions;
138         }
139 
140         protected class EthernetNetworkingFuncionalDescriptor : USBDescriptor
141         {
EthernetNetworkingFuncionalDescriptor()142             public EthernetNetworkingFuncionalDescriptor ()
143             {
144                 base.Length = 0x0D;
145                 base.Type = (DescriptorType) CommunicationClassDescriptorType.Interface;
146             }
147 
148             public const byte DescriptorSubtype = DeviceSubclassCode;
149             public byte MacAddressIndex;
150             public uint EthernetStatistics;
151             public ushort MaxSegmentSize;
152             public ushort MulticastFiltersNumber;
153             public byte PowerFiltersNumber;
154 
155 
ToArray()156             public override byte[] ToArray ()
157             {
158                 var arr = base.ToArray ();
159                 arr[0x02] = DescriptorSubtype;
160                 arr[0x03] = MacAddressIndex;
161                 BitConverter.GetBytes(EthernetStatistics).CopyTo(arr,0x04);
162                 BitConverter.GetBytes(MaxSegmentSize).CopyTo(arr,0x08);
163                 BitConverter.GetBytes(MulticastFiltersNumber).CopyTo(arr,0x0A);
164                 arr[0x0C] = PowerFiltersNumber;
165                 return arr;
166             }
167 
168         }
169 
170 
171     }
172 }
173 
174