facedancer.backends.moondancer module

class facedancer.backends.moondancer.InterruptEvent(data: Tuple[int, int])[source]

Bases: object

USB_BUS_RESET: int = 10
USB_RECEIVE_CONTROL: int = 11
USB_RECEIVE_PACKET: int = 12
USB_SEND_COMPLETE: int = 13
__init__(data: Tuple[int, int])[source]

Parses a tuple of two bytes representing an interrupt event into an InterruptEvent.

Parameters:

data – A tuple of two bytes. The first byte is the interrupt code, the second is the endpoint number.

class facedancer.backends.moondancer.MoondancerApp(device: USBDevice = None, verbose: int = 0, quirks: List[str] = [])[source]

Bases: FacedancerApp, FacedancerBackend

Backend for using Cynthion devices as Facedancers.

SUPPORTED_ENDPOINTS = 16
__init__(device: USBDevice = None, verbose: int = 0, quirks: List[str] = [])[source]

Sets up a new Cynthion-backed Facedancer (Moondancer) application.

Parameters:
  • device – The Cynthion device that will act as our Moondancer.

  • verbose – The verbosity level of the given application.

ack_status_stage(direction: USBDirection = USBDirection.OUT, endpoint_number: int = 0, blocking: bool = False)[source]

Handles the status stage of a correctly completed control request, by priming the appropriate endpoint to handle the status phase.

Parameters:
  • direction – Determines if we’re ACK’ing an IN or OUT vendor request. (This should match the direction of the DATA stage.)

  • endpoint_number – The endpoint number on which the control request occurred.

  • blocking – True if we should wait for the ACK to be fully issued before returning.

app_name = 'Moondancer'
classmethod appropriate_for_environment(backend_name: str) bool[source]

Determines if the current environment seems appropriate for using the Moondancer backend.

clear_halt(endpoint_number: int, direction: USBDirection)[source]

Clears a halt condition on the provided non-control endpoint.

Parameters:
  • endpoint_number – The endpoint number

  • direction – The endpoint direction; or OUT if not provided.

configured(configuration: USBConfiguration)[source]

Callback that’s issued when a USBDevice is configured, e.g. by the SET_CONFIGURATION request. Allows us to apply the new configuration.

Parameters:

configuration – The USBConfiguration object applied by the SET_CONFIG request.

connect(usb_device: USBDevice, max_packet_size_ep0: int = 64, device_speed: DeviceSpeed = DeviceSpeed.FULL)[source]

Prepares Cynthion to connect to the target host and emulate a given device.

Parameters:

usb_device – The USBDevice object that represents the device to be emulated.

disconnect()[source]

Disconnects Cynthion from the target host.

get_version()[source]

Returns information about the active Moondancer version.

handle_bus_reset()[source]

Triggers Moondancer to perform its side of a bus reset.

handle_ep_in_nak_status(nak_status: int)[source]
handle_receive_control(endpoint_number: int)[source]

Handles a known outstanding control event on a given endpoint.

endpoint_number: The endpoint number for which a control event should be serviced.

handle_receive_control_packet(endpoint_number: int)[source]
handle_receive_packet(endpoint_number: int)[source]

Handles a known-completed transfer on a given endpoint.

Parameters:

endpoint_number – The endpoint number for which the transfer should be serviced.

handle_send_complete(endpoint_number: int)[source]
read_from_endpoint(endpoint_number: int) bytes[source]

Reads a block of data from the given endpoint.

Parameters:

endpoint_number – The number of the OUT endpoint on which data is to be rx’d.

reset()[source]

Triggers the Cynthion to handle its side of a bus reset.

send_on_control_endpoint(endpoint_number: int, in_request: USBControlRequest, data: bytes, blocking: bool = True)[source]

Sends a collection of USB data in response to a IN control request by the host.

Parameters:
  • endpoint_number – The number of the IN endpoint on which data should be sent.

  • requested_length – The number of bytes requested by the host.

  • data – The data to be sent.

  • blocking – If true, this function should wait for the transfer to complete.

send_on_endpoint(endpoint_number: int, data: bytes, blocking: bool = True)[source]

Sends a collection of USB data on a given endpoint.

Parameters:
  • endpoint_number – The number of the IN endpoint on which data should be sent.

  • data – The data to be sent.

  • blocking – If true, this function will wait for the transfer to complete.

service_irqs()[source]

Core routine of the Facedancer execution/event loop. Continuously monitors the Moondancer’s execution status, and reacts as events occur.

set_address(address: int, defer: bool = False)[source]

Sets the device address of Moondancer. Usually only used during initial configuration.

Parameters:
  • address – The address that Moondancer should assume.

  • defer – True iff the set_address request should wait for an active transaction to finish.

stall_endpoint(endpoint_number: int, direction: USBDirection = USBDirection.OUT)[source]

Stalls the provided endpoint, as defined in the USB spec.

Parameters:

endpoint_number – The number of the endpoint to be stalled.

class facedancer.backends.moondancer.QuirkFlag(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntFlag

MANUAL_SET_ADDRESS: int = 1