-
Notifications
You must be signed in to change notification settings - Fork 195
/
netlink.go
102 lines (77 loc) · 2.57 KB
/
netlink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// L2 data link layer
package netlink
import (
"errors"
"net"
"time"
)
var (
ErrConnected = errors.New("Already connected")
ErrConnectFailed = errors.New("Connect failed")
ErrConnectTimeout = errors.New("Connect timed out")
ErrMissingSSID = errors.New("Missing WiFi SSID")
ErrShortPassphrase = errors.New("Invalid Wifi Passphrase < 8 chars")
ErrAuthFailure = errors.New("Wifi authentication failure")
ErrAuthTypeNoGood = errors.New("Wifi authorization type not supported")
ErrConnectModeNoGood = errors.New("Connect mode not supported")
ErrNotSupported = errors.New("Not supported")
)
type Event int
// Network events
const (
// The device's network connection is now UP
EventNetUp Event = iota
// The device's network connection is now DOWN
EventNetDown
)
type ConnectMode int
// Connect modes
const (
ConnectModeSTA = iota // Connect as Wifi station (default)
ConnectModeAP // Connect as Wifi Access Point
)
type AuthType int
// Wifi authorization types. Used when setting up an access point, or
// connecting to an access point
const (
AuthTypeWPA2 = iota // WPA2 authorization (default)
AuthTypeOpen // No authorization required (open)
AuthTypeWPA // WPA authorization
AuthTypeWPA2Mixed // WPA2/WPA mixed authorization
)
const DefaultConnectTimeout = 10 * time.Second
type ConnectParams struct {
// Connect mode
ConnectMode
// SSID of Wifi AP
Ssid string
// Passphrase of Wifi AP
Passphrase string
// Wifi authorization type
AuthType
// Wifi country code as two-char string. E.g. "XX" for world-wide,
// "US" for USA, etc.
Country string
// Retries is how many attempts to connect before returning with a
// "Connect failed" error. Zero means infinite retries.
Retries int
// Timeout duration for each connection attempt. The default zero
// value means 10sec.
ConnectTimeout time.Duration
// Watchdog ticker duration. On tick, the watchdog will check for
// downed connection or hardware fault and try to recover the
// connection. Set to zero to disable watchodog.
WatchdogTimeout time.Duration
}
// 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(params *ConnectParams) error
// Disconnect device from network
NetDisconnect()
// Notify to register callback for network events
NetNotify(cb func(Event))
// GetHardwareAddr returns device MAC address
GetHardwareAddr() (net.HardwareAddr, error)
}