Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions netlink/netlink.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// L2 data link layer

// package netlink provides an interface for L2 data link layer operations.
package netlink

import (
Expand All @@ -20,6 +19,7 @@ var (
ErrNotSupported = errors.New("Not supported")
)

// Event is a network event type passed to the callback registered with NetNotify.
type Event int

// Network events
Expand All @@ -38,6 +38,7 @@ const (
ConnectModeAP // Connect as Wifi Access Point
)

// AuthType is the type of WiFi authorization to use when connecting to an access point.
type AuthType int

// Wifi authorization types. Used when setting up an access point, or
Expand All @@ -49,10 +50,11 @@ const (
AuthTypeWPA2Mixed // WPA2/WPA mixed authorization
)

// DefaultConnectTimeout is the default timeout for connection attempts. This is used when ConnectParams.ConnectTimeout is zero.
const DefaultConnectTimeout = 10 * time.Second

// ConnectParams is the set of parameters used to connect a Netlinker device to a network.
type ConnectParams struct {

// Connect mode
ConnectMode

Expand Down Expand Up @@ -81,22 +83,23 @@ type ConnectParams struct {
// downed connection or hardware fault and try to recover the
// connection. Set to zero to disable watchodog.
WatchdogTimeout time.Duration

// Hostname to use for this device.
Hostname string
}

// Netlinker is TinyGo's OSI L2 data link layer interface. Network device
// drivers implement Netlinker to expose the device's L2 functionality.

type Netlinker interface {

// Connect device to network
// NetConnect connects the device to a network
NetConnect(params *ConnectParams) error

// Disconnect device from network
// NetDisconnect disconnects the device from the network
NetDisconnect()

// Notify to register callback for network events
// NetNotify registers a callback for network events
NetNotify(cb func(Event))

// GetHardwareAddr returns device MAC address
// GetHardwareAddr returns the device's MAC address
GetHardwareAddr() (net.HardwareAddr, error)
}