# Ifone
iOS 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`:
```elixir
def deps do
[
{:ifone, "~> 0.1.0"}
]
end
```
## Usage
List NCM data interfaces for a device by serial number:
```elixir
# 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:
```elixir
case Ifone.list_ncm_data_interfaces("00008101000000000000001E") do
{:ok, %{configuration: 5, interfaces: interfaces}} ->
ifname = interfaces[2] || interfaces[3]
# ...
{:error, reason} ->
# ...
end
```
Or by USB location ID (macOS only):
```elixir
iex> Ifone.list_ncm_data_interfaces(0x02100000)
{:ok, %{configuration: 5, interfaces: %{3 => "en16", 5 => "en17"}}}
```
Look up which device a network interface belongs to:
```elixir
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