NanoKVMGo.USB (nano_kvm_go v0.4.0)

Copy Markdown View Source

The NanoKVM-Go's USB gadget, as its Nerves system sets it up at boot.

The system makes the gadget /sys/kernel/config/usb_gadget/nanokvm with a network (NCM) function and binds it to the device controller; a gadget library such as Kuroneko.Gadget adds the KVM functions. gadget_options/1 gives such a library what this board needs:

  • the largest packets its USB controller (DWC3) takes: its smallest transmit FIFO holds 832 bytes of one, and its receive FIFO three of 682
  • the names the target computer sees: "NanoKVM-Go Audio" and its directions, and the drive "NanoKVM Virtual Media"
  • the network function and its addresses

The network's addresses stay the same from boot to boot, so that the computer keeps one network interface for the NanoKVM: the system gives it those in the U-Boot environment's usbnet_devaddr and usbnet_hostaddr, else addresses made from the serial number (default_network_addresses/1). persist_network_addresses/2 puts new ones there, through Nerves.Runtime.KV or another module with its put/1 (the :kv option).

children = [
  {Kuroneko.Gadget, NanoKVMGo.USB.gadget_options() ++ [functions: [:keyboard, :mouse]]}
]

The microphone and the speaker of the USB audio function play and record through NanoKVMGo.Microphone and NanoKVMGo.Audio.

Summary

Types

A MAC address, such as "02:12:34:56:78:9a".

Functions

The addresses the NanoKVM-Go system gives the USB network when the U-Boot environment has none: the first six bytes of the SHA-256 of the serial number (boardid's) for the NanoKVM's end and the next six for the computer's, as locally administered unicast addresses.

The configfs directory of the gadget the NanoKVM-Go system sets up.

The options of the gadget on this board, for Kuroneko.Gadget: :gadget, :endpoints, :max_packet, :names and :network. The AX620E's DWC3 has eight IN and eight OUT endpoints, seven of each besides endpoint 0.

Persists USB network addresses in the U-Boot environment, where the NanoKVM-Go system reads them at the next boots: :device_address (the NanoKVM's end), :host_address (the computer's), each an address or :default for the one made from the serial number.

Types

mac_address()

@type mac_address() :: String.t()

A MAC address, such as "02:12:34:56:78:9a".

network_addresses()

@type network_addresses() :: %{
  device_address: mac_address(),
  host_address: mac_address()
}

option()

@type option() :: {:serial_number, String.t() | nil} | {:kv, module()}

Functions

default_network_addresses(serial_number)

@spec default_network_addresses(String.t()) :: network_addresses()

The addresses the NanoKVM-Go system gives the USB network when the U-Boot environment has none: the first six bytes of the SHA-256 of the serial number (boardid's) for the NanoKVM's end and the next six for the computer's, as locally administered unicast addresses.

iex> NanoKVMGo.USB.default_network_addresses("0123456789abcdef")
%{device_address: "9e:9f:51:11:f7:b2", host_address: "7a:78:1f:1f:1d:dd"}

gadget()

@spec gadget() :: Path.t()

The configfs directory of the gadget the NanoKVM-Go system sets up.

gadget_options(opts \\ [])

@spec gadget_options([option()]) :: keyword()

The options of the gadget on this board, for Kuroneko.Gadget: :gadget, :endpoints, :max_packet, :names and :network. The AX620E's DWC3 has eight IN and eight OUT endpoints, seven of each besides endpoint 0.

Options

  • :serial_number - what the default network addresses are made from, by default the board's (boardid's); nil for no default addresses
  • :kv - the U-Boot environment, where the network addresses persist, Nerves.Runtime.KV by default

persist_network_addresses(addresses, opts \\ [])

@spec persist_network_addresses(
  %{optional(:device_address | :host_address) => mac_address() | :default},
  [{:kv, module()}]
) :: :ok | {:error, term()}

Persists USB network addresses in the U-Boot environment, where the NanoKVM-Go system reads them at the next boots: :device_address (the NanoKVM's end), :host_address (the computer's), each an address or :default for the one made from the serial number.

Options