-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.go
97 lines (87 loc) · 2.14 KB
/
config.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
package wifiqr
import (
"errors"
"strings"
)
// EncryptionProtocol represents a WiFi encryption protocol.
type EncryptionProtocol int
const (
WPA2 EncryptionProtocol = iota
WPA
WEP
NONE
wpa2Str = "WPA2"
wpaStr = "WPA"
wepStr = "WEP"
noneStr = "NONE"
wpa2Code = wpa2Str
wpaCode = wpaStr
wepCode = wepStr
noneCode = "nopass"
)
// String returns the string representation of the EncryptionProtocol.
func (ep EncryptionProtocol) String() string {
switch ep {
case WPA2:
return wpa2Str
case WPA:
return wpaStr
case WEP:
return wepStr
case NONE:
return noneStr
}
return ""
}
// Code returns a string code for the EncryptionProtocol.
func (ep EncryptionProtocol) Code() string {
switch ep {
case WPA2:
return wpa2Code
case WPA:
return wpaCode
case WEP:
return wepCode
case NONE:
return noneCode
}
return ""
}
// NewEncryptionProtocol returns a new EncryptionProtocol from the specified string.
func NewEncryptionProtocol(t string) (EncryptionProtocol, error) {
switch strings.ToUpper(t) {
case wpa2Str:
return WPA2, nil
case wpaStr:
return WPA, nil
case wepStr:
return WEP, nil
case noneStr, noneCode, "":
return NONE, nil
}
return WPA2, errors.New("no such protocol")
}
// Config is the Wi-Fi network configuration parameters.
type Config struct {
// The Service Set Identifier (SSID) is the name of the wireless network.
// It can be contained in the beacons sent out by APs, or it can be ‘hidden’ so that clients
// who wish to associate must first know the name of the network. Early security guidance was
// to hide the SSID of your network, but modern networking tools can detect the SSID by simply
// watching for legitimate client association, as SSIDs are transmitted in cleartext.
SSID string
// A pre-shared key (PSK).
Key string
// The wireless network encryption protocol (WEP, WPA, WPA2).
Encryption EncryptionProtocol
// Defines if the SSID is ‘hidden’.
Hidden bool
}
// NewConfig returns a new Config.
func NewConfig(ssid string, key string, enc EncryptionProtocol, hidden bool) *Config {
return &Config{
SSID: ssid,
Key: key,
Encryption: enc,
Hidden: hidden,
}
}