# Path: umap2/dev/cdc.py
# class FunctionalDescriptor(USBCSInterface):
#     '''
#     The functional descriptors are sent as Class-Specific descriptors.
#     '''
#     Header = 0x00
#     CM = 0x01  # Call Management Functional Descriptor.
#     ACM = 0x02  # Abstract Control Management Functional Descriptor.
#     DLM = 0x03  # Direct Line Management Functional Descriptor.
#     TR = 0x04  # Telephone Ringer Functional Descriptor.
#     TCLSRC = 0x05  # Telephone Call and Line State Reporting Capabilities Functional Descriptor.
#     UN = 0x06  # Union Functional Descriptor
#     CS = 0x07  # Country Selection Functional Descriptor
#     TOM = 0x08  # Telephone Operational Modes Functional Descriptor
#     USBT = 0x09  # USB Terminal Functional Descriptor
#     NCT = 0x0A  # Network Channel Terminal Descriptor
#     PU = 0x0B  # Protocol Unit Functional Descriptor
#     EU = 0x0C  # Extension Unit Functional Descriptor
#     MCM = 0x0D  # Multi-Channel Management Functional Descriptor
#     CCM = 0x0E  # CAPI Control Management Functional Descriptor
#     EN = 0x0F  # Ethernet Networking Functional Descriptor
#     ATMN = 0x10  # ATM Networking Functional Descriptor
#     WHCM = 0x11  # Wireless Handset Control Model Functional Descriptor
#     MDLM = 0x12  # Mobile Direct Line Model Functional Descriptor
#     MDLMD = 0x13  # MDLM Detail Functional Descriptor
#     DMM = 0x14  # Device Management Model Functional Descriptor
#     OBEX = 0x15  # OBEX Functional Descriptor
#     CMDS = 0x16  # Command Set Functional Descriptor
#     CMDSD = 0x17  # Command Set Detail Functional Descriptor
#     TC = 0x18  # Telephone Control Model Functional Descriptor
#     OBSEXSI = 0x19  # OBEX Service Identifier Functional Descriptor
#     NCM = 0x1A  # NCM Functional Descriptor
# 
#     def __init__(self, app, phy, subtype, cs_config):
#         name = FunctionalDescriptor.get_subtype_name(subtype)
#         cs_config = struct.pack('B', subtype) + cs_config
#         super(FunctionalDescriptor, self).__init__(name, app, phy, cs_config)
# 
#     @classmethod
#     def get_subtype_name(cls, subtype):
#         for vn in dir(cls):
#             if getattr(cls, vn) == subtype:
#                 return vn
#         return 'FunctionalDescriptor-%02x' % subtype
# 
# class CommunicationClassSubclassCodes:
#     '''
#     Subclass codes for the communication class,
#     as defined in CDC120, table 4
#     '''
# 
#     Reserved = 0x00
#     DirectLineControlModel = 0x01
#     AbstractControlModel = 0x02
#     TelephoneControlModel = 0x03
#     MultiChannelControlModel = 0x04
#     CapiControlModel = 0x05
#     EthernetNetworkingControlModel = 0x06
#     AtmNetworkingControlModel = 0x07
#     WirelessHandsetControlModel = 0x08
#     DeviceManagement = 0x09
#     MobileDirectLineModel = 0x0a
#     Obex = 0x0b
#     EthernetEmulationModel = 0x0c
#     NetworkControlModel = 0x0d
#     # 0x0e - 0x7f - reserved (future use)
#     # 0x80 - 0xfe - reserved (vendor specific)
# 
# Path: umap2/core/usb_class.py
# class USBClass(USBBaseActor):
#     name = 'Class'
# 
#     Unspecified = 0x00
#     Audio = 0x01
#     CDC = 0x02
#     HID = 0x03
#     PID = 0x05
#     Image = 0x06
#     Printer = 0x07
#     MassStorage = 0x08
#     Hub = 0x09
#     CDCData = 0x0a
#     SmartCard = 0x0b
#     ContentSecurity = 0x0d
#     Video = 0x0e
#     PHDC = 0x0f
#     AudioVideo = 0x10
#     Billboard = 0x11
#     DiagnosticDevice = 0xdc
#     WirelessController = 0xe0
#     Miscellaneous = 0xed
#     ApplicationSpecific = 0xfe
#     VendorSpecific = 0xff
# 
#     def __init__(self, app, phy):
#         '''
#         :param app: Umap2 application
#         :param phy: Physical connection
#         '''
#         super(USBClass, self).__init__(app, phy)
#         self.setup_request_handlers()
#         self.device = None
#         self.interface = None
#         self.endpoint = None
# 
#     def setup_request_handlers(self):
#         self.setup_local_handlers()
#         self.request_handlers = {
#             x: self._global_handler for x in self.local_handlers
#         }
# 
#     def setup_local_handlers(self):
#         self.local_handlers = {}
# 
#     def _global_handler(self, req):
#         handler = self.local_handlers[req.request]
#         response = handler(req)
#         if response is not None:
#             self.phy.send_on_endpoint(0, response)
#         self.usb_function_supported('class specific setup request received')
# 
#     def default_handler(self, req):
#         self._global_handler(req)
# 
# Path: umap2/core/usb.py
# class DescriptorType(object):
#     device = 0x01
#     configuration = 0x02
#     string = 0x03
#     interface = 0x04
#     endpoint = 0x05
#     device_qualifier = 0x06
#     other_speed_configuration = 0x07
#     interface_power = 0x08
#     bos = 0x0f
#     device_capability = 0x10
#     hid = 0x21
#     report = 0x22
#     cs_interface = 0x24
#     cs_endpoint = 0x25
#     hub = 0x29


from umap2.dev.cdc import FunctionalDescriptor, CommunicationClassSubclassCodes
from umap2.core.usb_class import USBClass
from umap2.core.usb import DescriptorType
from kitty.model import UInt8, LE16, RandomBytes, BitField, Static
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
from kitty.model import ElementCount
from kitty.model import MutableField
from generic import SubDescriptor
'''
CDC Device tempaltes
'''


cdc_control_interface_descriptor = Template(
    name='cdc_control_interface_descriptor',
    fields=[
        SubDescriptor(
            name='Standard interface descriptor',

# Path: umap2/dev/cdc.py
# class FunctionalDescriptor(USBCSInterface):
#     '''
#     The functional descriptors are sent as Class-Specific descriptors.
#     '''
#     Header = 0x00
#     CM = 0x01  # Call Management Functional Descriptor.
#     ACM = 0x02  # Abstract Control Management Functional Descriptor.
#     DLM = 0x03  # Direct Line Management Functional Descriptor.
#     TR = 0x04  # Telephone Ringer Functional Descriptor.
#     TCLSRC = 0x05  # Telephone Call and Line State Reporting Capabilities Functional Descriptor.
#     UN = 0x06  # Union Functional Descriptor
#     CS = 0x07  # Country Selection Functional Descriptor
#     TOM = 0x08  # Telephone Operational Modes Functional Descriptor
#     USBT = 0x09  # USB Terminal Functional Descriptor
#     NCT = 0x0A  # Network Channel Terminal Descriptor
#     PU = 0x0B  # Protocol Unit Functional Descriptor
#     EU = 0x0C  # Extension Unit Functional Descriptor
#     MCM = 0x0D  # Multi-Channel Management Functional Descriptor
#     CCM = 0x0E  # CAPI Control Management Functional Descriptor
#     EN = 0x0F  # Ethernet Networking Functional Descriptor
#     ATMN = 0x10  # ATM Networking Functional Descriptor
#     WHCM = 0x11  # Wireless Handset Control Model Functional Descriptor
#     MDLM = 0x12  # Mobile Direct Line Model Functional Descriptor
#     MDLMD = 0x13  # MDLM Detail Functional Descriptor
#     DMM = 0x14  # Device Management Model Functional Descriptor
#     OBEX = 0x15  # OBEX Functional Descriptor
#     CMDS = 0x16  # Command Set Functional Descriptor
#     CMDSD = 0x17  # Command Set Detail Functional Descriptor
#     TC = 0x18  # Telephone Control Model Functional Descriptor
#     OBSEXSI = 0x19  # OBEX Service Identifier Functional Descriptor
#     NCM = 0x1A  # NCM Functional Descriptor
# 
#     def __init__(self, app, phy, subtype, cs_config):
#         name = FunctionalDescriptor.get_subtype_name(subtype)
#         cs_config = struct.pack('B', subtype) + cs_config
#         super(FunctionalDescriptor, self).__init__(name, app, phy, cs_config)
# 
#     @classmethod
#     def get_subtype_name(cls, subtype):
#         for vn in dir(cls):
#             if getattr(cls, vn) == subtype:
#                 return vn
#         return 'FunctionalDescriptor-%02x' % subtype
# 
# class CommunicationClassSubclassCodes:
#     '''
#     Subclass codes for the communication class,
#     as defined in CDC120, table 4
#     '''
# 
#     Reserved = 0x00
#     DirectLineControlModel = 0x01
#     AbstractControlModel = 0x02
#     TelephoneControlModel = 0x03
#     MultiChannelControlModel = 0x04
#     CapiControlModel = 0x05
#     EthernetNetworkingControlModel = 0x06
#     AtmNetworkingControlModel = 0x07
#     WirelessHandsetControlModel = 0x08
#     DeviceManagement = 0x09
#     MobileDirectLineModel = 0x0a
#     Obex = 0x0b
#     EthernetEmulationModel = 0x0c
#     NetworkControlModel = 0x0d
#     # 0x0e - 0x7f - reserved (future use)
#     # 0x80 - 0xfe - reserved (vendor specific)
# 
# Path: umap2/core/usb_class.py
# class USBClass(USBBaseActor):
#     name = 'Class'
# 
#     Unspecified = 0x00
#     Audio = 0x01
#     CDC = 0x02
#     HID = 0x03
#     PID = 0x05
#     Image = 0x06
#     Printer = 0x07
#     MassStorage = 0x08
#     Hub = 0x09
#     CDCData = 0x0a
#     SmartCard = 0x0b
#     ContentSecurity = 0x0d
#     Video = 0x0e
#     PHDC = 0x0f
#     AudioVideo = 0x10
#     Billboard = 0x11
#     DiagnosticDevice = 0xdc
#     WirelessController = 0xe0
#     Miscellaneous = 0xed
#     ApplicationSpecific = 0xfe
#     VendorSpecific = 0xff
# 
#     def __init__(self, app, phy):
#         '''
#         :param app: Umap2 application
#         :param phy: Physical connection
#         '''
#         super(USBClass, self).__init__(app, phy)
#         self.setup_request_handlers()
#         self.device = None
#         self.interface = None
#         self.endpoint = None
# 
#     def setup_request_handlers(self):
#         self.setup_local_handlers()
#         self.request_handlers = {
#             x: self._global_handler for x in self.local_handlers
#         }
# 
#     def setup_local_handlers(self):
#         self.local_handlers = {}
# 
#     def _global_handler(self, req):
#         handler = self.local_handlers[req.request]
#         response = handler(req)
#         if response is not None:
#             self.phy.send_on_endpoint(0, response)
#         self.usb_function_supported('class specific setup request received')
# 
#     def default_handler(self, req):
#         self._global_handler(req)
# 
# Path: umap2/core/usb.py
# class DescriptorType(object):
#     device = 0x01
#     configuration = 0x02
#     string = 0x03
#     interface = 0x04
#     endpoint = 0x05
#     device_qualifier = 0x06
#     other_speed_configuration = 0x07
#     interface_power = 0x08
#     bos = 0x0f
#     device_capability = 0x10
#     hid = 0x21
#     report = 0x22
#     cs_interface = 0x24
#     cs_endpoint = 0x25
#     hub = 0x29


# Path: umap2/fuzz/templates/cdc.py
from umap2.dev.cdc import FunctionalDescriptor, CommunicationClassSubclassCodes
from umap2.core.usb_class import USBClass
from umap2.core.usb import DescriptorType
from kitty.model import UInt8, LE16, RandomBytes, BitField, Static
from kitty.model import Template, Repeat, List, Container, ForEach, OneOf
from kitty.model import ElementCount
from kitty.model import MutableField
from generic import SubDescriptor

'''
CDC Device tempaltes
'''


cdc_control_interface_descriptor = Template(
    name='cdc_control_interface_descriptor',
    fields=[
        SubDescriptor(
            name='Standard interface descriptor',

            descriptor_type=DescriptorType.interface,