facedancer.backends.greatdancer module

class facedancer.backends.greatdancer.GreatDancerApp(device=None, verbose=0, quirks=None)[source]

Bases: FacedancerApp, FacedancerBackend

Backend for using GreatFET devices as Facedancers.

DEVICE_TO_HOST = 1
GET_ENDPTCOMPLETE = 2
GET_ENDPTNAK = 4
GET_ENDPTSETUPSTAT = 1
GET_ENDPTSTATUS = 3
GET_USBSTS = 0
HOST_TO_DEVICE = 0
QUIRK_MANUAL_SET_ADDRESS = 1
SUPPORTED_ENDPOINTS = 4
USBSTS_D_NAKI = 65536
USBSTS_D_UI = 1
USBSTS_D_URI = 64
__init__(device=None, verbose=0, quirks=None)[source]

Sets up a new GreatFET-backed Facedancer (GreatDancer) application.

device: The GreatFET device that will act as our GreatDancer. verbose: The verbosity level of the given application.

ack_status_stage(direction=0, endpoint_number=0, blocking=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 = 'GreatDancer'
app_num = 0
classmethod appropriate_for_environment(backend_name)[source]

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

configured(configuration)[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 configuration applied by the SET_CONFIG request.

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

Prepares the GreatDancer 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 the GreatDancer from its target host.

get_version()[source]

Returns information about the active GreatDancer version.

init_commands()[source]

API compatibility function; not necessary for GreatDancer.

read_from_endpoint(ep_num)[source]

Reads a block of data from the given endpoint.

Parameters:

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

reset()[source]

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

send_on_endpoint(ep_num, data, blocking=True)[source]

Sends a collection of USB data on a given endpoint.

Parameters:
  • ep_num – 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 GreatDancer’s execution status, and reacts as events occur.

set_address(address, defer=False)[source]

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

Parameters:
  • address – The address that the GreatDancer should assume.

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

stall_endpoint(ep_num, direction=0)[source]

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

Parameters:

ep_num – The number of the endpoint to be stalled.

stall_ep0(direction=0)[source]

Convenience function that stalls the control endpoint zero.