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 Antmicro.Renode.Logging; 9 using Antmicro.Renode.Utilities; 10 11 namespace Antmicro.Renode.Core.USB.CDC 12 { 13 public class FunctionalDescriptor: IProvidesDescriptor 14 { FunctionalDescriptor(CdcFunctionalDescriptorType type, CdcFunctionalDescriptorSubtype subtype, params byte[] specificData)15 public FunctionalDescriptor(CdcFunctionalDescriptorType type, CdcFunctionalDescriptorSubtype subtype, params byte[] specificData) 16 { 17 this.type = type; 18 this.subtype = subtype; 19 this.specificData = specificData; 20 } 21 GetDescriptor(bool recursive, BitStream buffer = null)22 public BitStream GetDescriptor(bool recursive, BitStream buffer = null) 23 { 24 if(buffer == null) 25 { 26 buffer = new BitStream(); 27 } 28 29 buffer.Append((byte)DescriptorLength); 30 buffer.Append((byte)type); 31 buffer.Append((byte)subtype); 32 buffer.Append(specificData); 33 34 return buffer; 35 } 36 37 public int RecursiveDescriptorLength => DescriptorLength; 38 public int DescriptorLength => specificData.Length + 3; 39 40 private readonly CdcFunctionalDescriptorType type; 41 private readonly CdcFunctionalDescriptorSubtype subtype; 42 private readonly byte[] specificData; 43 } 44 45 public enum CdcFunctionalDescriptorType : byte 46 { 47 Interface = 0x24, 48 Endpoint = 0x25 49 } 50 51 public enum CdcFunctionalDescriptorSubtype : byte 52 { 53 Header = 0x00, 54 CallManagement = 0x01, 55 AbstractControlManagement = 0x02, 56 DirectLineManagement = 0x03, 57 TelephoneRinger = 0x04, 58 TelephoneCallLineState = 0x05, 59 Union = 0x06, 60 CountrySelection = 0x07, 61 TelephoneOperationalModes = 0x08, 62 USBTerminal = 0x09, 63 NetworkChannel = 0x0A, 64 ProtocolUnit = 0x0B, 65 ExtensionUnit = 0x0C, 66 MultiChannelManagement = 0x0D, 67 CAPIControlManagement = 0x0E, 68 EthernetNetworking = 0x0F, 69 ATMNetworking = 0x10, 70 71 // 0x11 - 0xFF RESERVED 72 } 73 } 74