Ifone
View SourceiOS device USB interface discovery for Elixir.
This library provides functions to discover NCM (Network Control Model) data interfaces on connected iOS devices, and to look up USB device information from network interface names.
Platform Support
- macOS: Uses IOKit via a NIF
- Linux: Uses sysfs traversal (pure Elixir, no NIF required)
Note: On Linux, USB location ID lookup is not supported — use serial numbers instead.
The interface numbers in the returned map differ by platform. On macOS, network interfaces are reported on the CDC-Data interface (e.g., interface 3). On Linux, they are reported on the CDC-Control interface (e.g., interface 2).
Installation
Add ifone to your list of dependencies in mix.exs:
def deps do
[
{:ifone, "~> 0.1.0"}
]
endUsage
List NCM data interfaces for a device by serial number:
# macOS — keyed by CDC-Data interface number
iex> Ifone.list_ncm_data_interfaces("00008101000000000000001E")
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}
# Linux — keyed by CDC-Control interface number
iex> Ifone.list_ncm_data_interfaces("00008101000000000000001E")
{:ok, %{configuration: 5, interfaces: %{2 => "enx8e7aaa54ae75", 4 => "enxb60457655ed3"}}}To write cross-platform code, check for both interface numbers:
case Ifone.list_ncm_data_interfaces("00008101000000000000001E") do
{:ok, %{configuration: 5, interfaces: interfaces}} ->
ifname = interfaces[2] || interfaces[3]
# ...
{:error, reason} ->
# ...
endOr by USB location ID (macOS only):
iex> Ifone.list_ncm_data_interfaces(0x02100000)
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}Enumerate every connected iOS device and its NCM interfaces in one call. The
result is keyed by USB serial number, and each value has the same shape as
list_ncm_data_interfaces/1:
# macOS — interfaces keyed by CDC-Data interface number
iex> Ifone.list_devices()
{:ok, %{"00008101000000000000001E" => %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}}
# Linux — interfaces keyed by CDC-Control interface number
iex> Ifone.list_devices()
{:ok, %{"00008101000000000000001E" => %{configuration: 5, interfaces: %{2 => "enx8e7aaa54ae75", 4 => "enxb60457655ed3"}}}}Look up which device a network interface belongs to:
iex> Ifone.get_serial_for_interface("en16")
{:ok, "00008101000000000000001E"}Building
The NIF is compiled automatically via elixir_make. You'll need:
- Xcode Command Line Tools (macOS)
- Erlang development headers