1 //
2 // Copyright (c) 2010-2020 Antmicro
3 //
4 //  This file is licensed under the MIT License.
5 //  Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System;
8 using System.Collections.Generic;
9 using Antmicro.Renode.Logging;
10 using Antmicro.Renode.Utilities;
11 
12 namespace Antmicro.Renode.Core.USB.CDC
13 {
14     public class Interface : USBInterface
15     {
Interface(IUSBDevice device, byte identifier, byte subClassCode, byte protocol, IEnumerable<FunctionalDescriptor> descriptors = null, string description = null)16         public Interface(IUSBDevice device,
17                            byte identifier,
18                            byte subClassCode,
19                            byte protocol,
20                            IEnumerable<FunctionalDescriptor> descriptors = null,
21                            string description = null) : base(device, identifier, USBClassCode.CommunicationsCDCControl, subClassCode, protocol, description)
22         {
23             if(descriptors != null)
24             {
25                 var pos = 0;
26                 foreach(var d in descriptors)
27                 {
28                     RegisterSubdescriptor(d, pos++);
29                 }
30             }
31         }
32 
HandleRequest(SetupPacket packet)33         public override BitStream HandleRequest(SetupPacket packet)
34         {
35             switch(packet.Type)
36             {
37                 case PacketType.Class:
38                     return HandleClassRequest((CdcClassRequest)packet.Request);
39                 default:
40                     device.Log(LogLevel.Warning, "Unsupported type: 0x{0:x}", packet.Type);
41                     return BitStream.Empty;
42             }
43         }
44 
HandleClassRequest(CdcClassRequest request)45         private BitStream HandleClassRequest(CdcClassRequest request)
46         {
47             device.Log(LogLevel.Warning, "Handling an unimplemented CDC class request: {0}", request);
48             return BitStream.Empty;
49         }
50 
51         private enum CdcClassRequest
52         {
53             SetLineEncoding = 0x20,
54             GetLineEncoding = 0x21,
55             SetControlLineState = 0x22,
56             SendBreak = 0x23
57         }
58     }
59 }
60