facedancer.backends.libusbhost module
Host support for accessing libusb with a Facedancer-like syntax.
- class facedancer.backends.libusbhost.LibUSBHostApp(verbose=0, quirks=[], index=0, **kwargs)[source]
Bases:
FacedancerUSBHostClass that represents a libusb-based USB host.
- __init__(verbose=0, quirks=[], index=0, **kwargs)[source]
Creates a new libusb backend for communicating with a target device.
- app_name = 'LibUSB Host'
- classmethod appropriate_for_environment(backend_name)[source]
Determines if the current environment seems appropriate for using the libusb backend.
- bus_reset(delay=0)[source]
Issues a “bus reset”, requesting that the downstream device reset itself.
- Parameters:
delay – The amount of time, in seconds, to wait before or after the reset request. To be compliant, this should be omitted, or set to 0.1s.
- connect(device_speed=None)[source]
Sets up our host to talk to the device, including turning on VBUS.
- control_request_in(request_type, recipient, request, value=0, index=0, length=0)[source]
Performs an IN control request.
- Parameters:
request_type – Determines if this is a standard, class, or vendor request. Accepts a REQUEST_TYPE_* constant.
recipient – Determines the context in which this command is interpreted. Accepts a REQUEST_RECIPIENT_* constant.
request – The request number to be performed.
value, index – The standard USB request arguments, to be included in the setup packet. Their meaning varies depending on the request.
length – The maximum length of data expected in response, or 0 if we don’t expect any data back.
- control_request_out(request_type, recipient, request, value=0, index=0, data=[])[source]
Performs an OUT control request.
- Parameters:
request_type – Determines if this is a standard, class, or vendor request. Accepts a REQUEST_TYPE_* constant.
recipient – Determines the context in which this command is interpreted. Accepts a REQUEST_RECIPIENT_* constant.
request – The request number to be performed.
value, index – The standard USB request arguments, to be included in the setup packet. Their meaning varies depending on the request.
data – The data to be transmitted with this control request.
- current_device_speed(as_string=False)[source]
Returns the speed of the connected device
- Parameters:
as_string – If true, returns the speed as a string for printing; otherwise returns a DEVICE_SPEED_* constant.
- current_line_state(as_string=False)[source]
Returns the current state of the USB differential pair
- as_stringIf true, returns the speed as a string for printing; otherwise
returns a LINE_STATE_* constant.
- initialize_control_endpoint(device_address=None, device_speed=None, max_packet_size=None)[source]
Set up the device’s control endpoint, so we can use it for e.g. enumeration.
- read_from_endpoint(endpoint_number, expected_read_size=64, data_packet_pid=0)[source]
Sends a block of data on the provided endpoints.
- Parameters:
endpoint_number – The endpoint number on which to send.
expected_read_size – The expected amount of data to be read.
data_packet_pid – The data packet PID to use (1 or 0). Ignored if the endpoint is set to automatically alternate data PIDs.
raises an IOError on a communications error or stall
- send_on_endpoint(endpoint_number, data, is_setup=False, blocking=True, data_packet_pid=0)[source]
Sends a block of data on the provided endpoints.
- Parameters:
endpoint_number – The endpoint number on which to send.
data – The data to be transmitted.
is_setup – True iff this transfer should begin with a SETUP token.
blocking – True iff this transaction should wait for the transaction to complete.
data_packet_pid – The data packet PID to use (1 or 0). Ignored if the endpoint is set to automatically alternate data PIDs.
raises an IOError on a communications error or stall
- set_up_endpoint(endpoint_address_or_object, endpoint_type=None, max_packet_size=None, device_address=None, endpoint_speed=None, handle_data_toggle=None, is_control_endpoint=None)[source]
Sets up an endpoint for use. Can be used to initialize an endpoint or to update its parameters. Two forms exist:
- Parameters:
endpoint_object – a USBEndpoint object with the parameters to be populated
or
- Parameters:
endpoint_address – the address of the endpoint to be setup; including the direction bit
endpoint_type – one of the ENDPOINT_TYPE constants that specifies the transfer mode on the endpoint_address
max_packet_size – the maximum packet size to be communicated on the given endpoint
device_address – the address of the device to be communicated with; if not provided, the last address will be used
endpoint_speed – the speed of the packets to be communicated on the endpoint; should be a DEVICE_SPEED_* constant; if not provided, the last device’s speed will be used.
handle_data_toggle – true iff the hardware should automatically handle selection of data packet PIDs
is_control_endpoint – true iff the given packet is a for a control endpoint