NetMD.Simulator.Gadget (NetMD v0.1.0)

Copy Markdown View Source

Present the NetMD.Simulator brain as a real USB NetMD device.

Where NetMD.Simulator implements a NetMD.Transport for in-process use, this wires the same device brain to a Linux USB gadget over BodgeUSBGadget and BodgeUSBGadget.FunctionFs. The vendor control protocol (reply-length poll, command, read-reply, factory) arrives as FunctionFS SETUP events; the bulk OUT endpoint (track download) is read by a task. The result is an actual USB device on the bus.

With dummy_hcd loaded, the gadget and a host driving it with the real NetMD.Transport.Usb can run in the same machine, so the whole stack is exercised over usbfs without any external hardware. This is the "both sides in one VM" setup; see vm/ and README_VM.md.

Requirements (root)

configfs and functionfs mounted, libcomposite and usb_f_fs loaded, a UDC available (dummy_hcd provides dummy_udc.0). It does nothing useful off a Linux gadget host, so it is not started by the library.

Use

{:ok, g} = NetMD.Simulator.Gadget.start_link(udc: "dummy_udc.0")
# ... a host now enumerates a Sony NetMD device and can be driven
# with NetMD.open() (real transport) from another process/VM ...
:ok = NetMD.Simulator.Gadget.stop(g)

Pass disc: to start from a custom NetMD.Simulator.Disc.

Summary

Functions

The device brain process, for inspecting or seeding disc state.

Returns a specification to start this module under a supervisor.

Start the gadget. Options

Tear the gadget down (unbind, remove, unmount) and stop the brain.

Functions

brain(server)

@spec brain(GenServer.server()) :: pid()

The device brain process, for inspecting or seeding disc state.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the gadget. Options:

  • :disc - a NetMD.Simulator.Disc to present (default: demo disc)
  • :vendor_id / :product_id - USB ids (default Sony MZ-N710)
  • :udc - the UDC to bind to (default: first in /sys/class/udc)
  • :gadget / :instance / :mountpoint - naming overrides
  • :name - register the GenServer under a name

stop(server)

@spec stop(GenServer.server()) :: :ok

Tear the gadget down (unbind, remove, unmount) and stop the brain.