Ifone.USB (Ifone v1.1.0)

View Source

USB interface discovery for iOS devices.

Provides functions to:

  • List NCM data interfaces for a device by serial number or USB location
  • Look up the USB serial number for a network interface

Summary

Functions

Gets the USB serial number for a network interface.

Lists all connected iOS devices and their NCM interfaces.

Lists NCM data interfaces for a USB device.

Types

interfaces_result()

@type interfaces_result() :: %{
  configuration: non_neg_integer(),
  interfaces: %{required(non_neg_integer()) => String.t() | nil}
}

Functions

get_serial_for_interface(interface_name)

@spec get_serial_for_interface(String.t()) :: {:ok, String.t()} | {:error, atom()}

Gets the USB serial number for a network interface.

Arguments

  • interface_name - Network interface name (e.g., "en16")

Returns

  • {:ok, serial} - The USB serial number
  • {:error, :not_found} - Interface not found or not a USB NCM interface

Examples

iex> Ifone.USB.get_serial_for_interface("en16")
{:ok, "0000811000180C36263B801E"}

list_devices()

@spec list_devices() ::
  {:ok, %{required(String.t()) => interfaces_result()}} | {:error, atom()}

Lists all connected iOS devices and their NCM interfaces.

Returns

  • {:ok, %{serial => %{configuration: N, interfaces: %{...}}}} - Map of every connected iOS device keyed by USB serial number
  • {:error, reason} - Other error

Examples

iex> Ifone.USB.list_devices()
{:ok, %{"0000811000180C36263B801E" => %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}}

list_ncm_data_interfaces(identifier)

@spec list_ncm_data_interfaces(String.t() | non_neg_integer()) ::
  {:ok, interfaces_result()} | {:error, atom()}

Lists NCM data interfaces for a USB device.

Arguments

  • identifier - Either a device identifier (string) or USB location ID (integer)

A string identifier may be written either as the raw USB serial number reported by IOKit and sysfs ("0000811000180C36263B801E"), or as the hyphenated UDID reported by usbmuxd, lockdownd and RemoteXPC ("00008110-00180C36263B801E"). The hyphen is removed before the lookup, so both spellings select the same device. Only that exact shape - eight hex digits, one hyphen, sixteen hex digits - is treated as a UDID; every other identifier, including a legacy 40-character UDID, is matched verbatim.

Returns

  • {:ok, %{configuration: N, interfaces: %{...}}} - Map with configuration and interfaces map
  • {:error, :not_found} - Device not found
  • {:error, reason} - Other error

Examples

iex> Ifone.USB.list_ncm_data_interfaces("0000811000180C36263B801E")
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}

iex> Ifone.USB.list_ncm_data_interfaces("00008110-00180C36263B801E")
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}

iex> Ifone.USB.list_ncm_data_interfaces(34603008)
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}