# Path: umap2/core/usb_base.py
# class USBBaseActor(object):
# 
#     name = 'Actor'
# 
#     def __init__(self, app, phy):
#         '''
#         :param app: Umap2 application
#         :param phy: Physical connection
#         '''
#         self.phy = phy
#         self.app = app
#         self.session_data = {}
#         self.str_dict = {}
#         self.logger = logging.getLogger('umap2')
# 
#     def get_mutation(self, stage, data=None):
#         '''
#         :param stage: stage name
#         :param data: dictionary (string: bytearray) of data for the fuzzer (default: None)
#         :return: mutation for current stage, None if not current fuzzing stage
#         '''
#         return self.app.get_mutation(stage, data)
# 
#     def send_on_endpoint(self, ep, data):
#         '''
#         Send data on a given endpoint
# 
#         :param ep: endpoint number
#         :param data: data to send
#         '''
#         self.phy.send_on_endpoint(ep, data)
# 
#     def get_session_data(self, stage):
#         '''
#         If an entity wants to pass specific data to the fuzzer when getting a mutation,
#         it could return a session data here.
#         This session data should be a dictionary of string:bytearray.
#         The keys of the dictionary should match the keys in the templates.
# 
#         :param stage: stage that the session data is for
#         :return: dictionary of session data
#         '''
#         return self.session_data
# 
#     def usb_function_supported(self, reason=None):
#         '''
#         Mark current USB function as supported by the host.
#         This will tell the application to stop emulating current device.
# 
#         :param reason: reason why we decided it is supported (default: None)
#         '''
#         self.app.usb_function_supported(reason)
# 
#     def add_string_with_id(self, str_id, s):
#         '''
#         Add a string to the string dictionary
# 
#         :param str_id: id of the string
#         :param s: the string
#         '''
#         self.str_dict[str_id] = s
# 
#     def get_string_by_id(self, str_id):
#         '''
#         Get a string by it's id
# 
#         :param str_id: string id
#         :return: the string, or None if id does not exist
#         '''
#         self.debug('Getting string by id %#x' % (str_id))
#         if str_id in self.str_dict:
#             return self.str_dict[str_id]
#         return None
# 
#     def verbose(self, msg, *args, **kwargs):
#         self.logger.verbose('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def debug(self, msg, *args, **kwargs):
#         self.logger.debug('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def info(self, msg, *args, **kwargs):
#         self.logger.info('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def warning(self, msg, *args, **kwargs):
#         self.logger.warning('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def error(self, msg, *args, **kwargs):
#         self.logger.error('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def critical(self, msg, *args, **kwargs):
#         self.logger.critical('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def always(self, msg, *args, **kwargs):
#         self.logger.always('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
# Path: umap2/fuzz/helpers.py
# def mutable(stage, silent=False):
#     def wrap_f(func):
#         func_self = None
#         if inspect.ismethod(func):
#             func_self = func.im_self
#             func = func.im_func
# 
#         def wrapper(*args, **kwargs):
#             if func_self is None:
#                 self = args[0]
#                 args = tuple(args[1:])
#             else:
#                 self = func_self
#             response = None
#             valid_req = kwargs.get('valid', False)
#             info = self.info if not silent else self.debug
#             if not valid_req:
#                 log_stage(stage)
#                 session_data = self.get_session_data(stage)
#                 data = kwargs.get('fuzzing_data', {})
#                 data.update(session_data)
#                 response = self.get_mutation(stage=stage, data=data)
#             try:
#                 if response is not None:
#                     if not silent:
#                         info('Got mutation for stage %s' % stage)
#                 else:
#                     if valid_req:
#                         info('Calling %s' % (func.__name__))
#                     else:
#                         info('Calling %s (stage: "%s")' % (func.__name__, stage))
#                     response = func(self, *args, **kwargs)
#             except Exception as e:
#                 self.logger.error(traceback.format_exc())
#                 self.logger.error(''.join(traceback.format_stack()))
#                 raise e
#             if response is not None:
#                 info('Response: %s' % binascii.hexlify(response))
#             return response
#         return wrapper
#     return wrap_f


import struct
from umap2.core.usb_base import USBBaseActor
from umap2.fuzz.helpers import mutable
# USBEndpoint.py
#
# Contains class definition for USBEndpoint.


class USBEndpoint(USBBaseActor):
    name = 'Endpoint'
    direction_out = 0x00
    direction_in = 0x01

    transfer_type_control = 0x00
    transfer_type_isochronous = 0x01

# Path: umap2/core/usb_base.py
# class USBBaseActor(object):
# 
#     name = 'Actor'
# 
#     def __init__(self, app, phy):
#         '''
#         :param app: Umap2 application
#         :param phy: Physical connection
#         '''
#         self.phy = phy
#         self.app = app
#         self.session_data = {}
#         self.str_dict = {}
#         self.logger = logging.getLogger('umap2')
# 
#     def get_mutation(self, stage, data=None):
#         '''
#         :param stage: stage name
#         :param data: dictionary (string: bytearray) of data for the fuzzer (default: None)
#         :return: mutation for current stage, None if not current fuzzing stage
#         '''
#         return self.app.get_mutation(stage, data)
# 
#     def send_on_endpoint(self, ep, data):
#         '''
#         Send data on a given endpoint
# 
#         :param ep: endpoint number
#         :param data: data to send
#         '''
#         self.phy.send_on_endpoint(ep, data)
# 
#     def get_session_data(self, stage):
#         '''
#         If an entity wants to pass specific data to the fuzzer when getting a mutation,
#         it could return a session data here.
#         This session data should be a dictionary of string:bytearray.
#         The keys of the dictionary should match the keys in the templates.
# 
#         :param stage: stage that the session data is for
#         :return: dictionary of session data
#         '''
#         return self.session_data
# 
#     def usb_function_supported(self, reason=None):
#         '''
#         Mark current USB function as supported by the host.
#         This will tell the application to stop emulating current device.
# 
#         :param reason: reason why we decided it is supported (default: None)
#         '''
#         self.app.usb_function_supported(reason)
# 
#     def add_string_with_id(self, str_id, s):
#         '''
#         Add a string to the string dictionary
# 
#         :param str_id: id of the string
#         :param s: the string
#         '''
#         self.str_dict[str_id] = s
# 
#     def get_string_by_id(self, str_id):
#         '''
#         Get a string by it's id
# 
#         :param str_id: string id
#         :return: the string, or None if id does not exist
#         '''
#         self.debug('Getting string by id %#x' % (str_id))
#         if str_id in self.str_dict:
#             return self.str_dict[str_id]
#         return None
# 
#     def verbose(self, msg, *args, **kwargs):
#         self.logger.verbose('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def debug(self, msg, *args, **kwargs):
#         self.logger.debug('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def info(self, msg, *args, **kwargs):
#         self.logger.info('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def warning(self, msg, *args, **kwargs):
#         self.logger.warning('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def error(self, msg, *args, **kwargs):
#         self.logger.error('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def critical(self, msg, *args, **kwargs):
#         self.logger.critical('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
#     def always(self, msg, *args, **kwargs):
#         self.logger.always('[%s] %s' % (self.name, msg), *args, **kwargs)
# 
# Path: umap2/fuzz/helpers.py
# def mutable(stage, silent=False):
#     def wrap_f(func):
#         func_self = None
#         if inspect.ismethod(func):
#             func_self = func.im_self
#             func = func.im_func
# 
#         def wrapper(*args, **kwargs):
#             if func_self is None:
#                 self = args[0]
#                 args = tuple(args[1:])
#             else:
#                 self = func_self
#             response = None
#             valid_req = kwargs.get('valid', False)
#             info = self.info if not silent else self.debug
#             if not valid_req:
#                 log_stage(stage)
#                 session_data = self.get_session_data(stage)
#                 data = kwargs.get('fuzzing_data', {})
#                 data.update(session_data)
#                 response = self.get_mutation(stage=stage, data=data)
#             try:
#                 if response is not None:
#                     if not silent:
#                         info('Got mutation for stage %s' % stage)
#                 else:
#                     if valid_req:
#                         info('Calling %s' % (func.__name__))
#                     else:
#                         info('Calling %s (stage: "%s")' % (func.__name__, stage))
#                     response = func(self, *args, **kwargs)
#             except Exception as e:
#                 self.logger.error(traceback.format_exc())
#                 self.logger.error(''.join(traceback.format_stack()))
#                 raise e
#             if response is not None:
#                 info('Response: %s' % binascii.hexlify(response))
#             return response
#         return wrapper
#     return wrap_f


# Path: umap2/core/usb_endpoint.py
import struct
from umap2.core.usb_base import USBBaseActor
from umap2.fuzz.helpers import mutable

# USBEndpoint.py
#
# Contains class definition for USBEndpoint.


class USBEndpoint(USBBaseActor):
    name = 'Endpoint'
    direction_out = 0x00
    direction_in = 0x01

    transfer_type_control = 0x00
    transfer_type_isochronous = 0x01

    transfer_type_bulk = 0x02