ExIEC61850.Hal.Ethernet (ex_iec61850 v0.1.0)

Copy Markdown View Source

Linux Layer 2 Ethernet (AF_PACKET / SOCK_RAW) transport for GOOSE (0x88B8) and Sampled Values (0x88BA). Uses Erlang/OTP's :socket module (no C NIF required).

Summary

Functions

Closes the raw Ethernet socket.

Decodes an Ethernet frame (with or without 802.1Q VLAN tag).

Encodes an IEEE 802.3 / 802.1Q Ethernet frame for GOOSE or SV.

Reads the Linux interface index from /sys/class/net/<interface>/ifindex.

Reads the 6-byte MAC address from /sys/class/net/<interface>/address.

Opens a Linux AF_PACKET raw socket bound to interface_name (requires CAP_NET_RAW / root).

Sends a raw Ethernet frame on an open :socket.socket().

Functions

close_socket(sock)

@spec close_socket(:socket.socket()) :: :ok

Closes the raw Ethernet socket.

decode_frame(arg1)

@spec decode_frame(binary()) :: {:ok, map()} | {:error, term()}

Decodes an Ethernet frame (with or without 802.1Q VLAN tag).

encode_frame(dst_mac, src_mac, ethertype, payload, opts \\ [])

@spec encode_frame(binary(), binary(), non_neg_integer(), binary(), keyword()) ::
  binary()

Encodes an IEEE 802.3 / 802.1Q Ethernet frame for GOOSE or SV.

ethertype_goose()

ethertype_sv()

get_interface_index(interface_name)

@spec get_interface_index(String.t()) :: {:ok, non_neg_integer()} | {:error, term()}

Reads the Linux interface index from /sys/class/net/<interface>/ifindex.

get_interface_mac(interface_name)

@spec get_interface_mac(String.t()) :: {:ok, binary()} | {:error, term()}

Reads the 6-byte MAC address from /sys/class/net/<interface>/address.

open_socket(interface_name, protocol \\ 3)

@spec open_socket(String.t(), non_neg_integer()) ::
  {:ok, :socket.socket()} | {:error, term()}

Opens a Linux AF_PACKET raw socket bound to interface_name (requires CAP_NET_RAW / root).

send_frame(sock, frame)

@spec send_frame(:socket.socket(), binary()) :: :ok | {:error, term()}

Sends a raw Ethernet frame on an open :socket.socket().