/
dot11_wps_attrs.go
207 lines (182 loc) · 4.8 KB
/
dot11_wps_attrs.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package packets
import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"strings"
)
type wpsAttrType int
const (
wpsHex wpsAttrType = 0
wpsStr wpsAttrType = 1
)
type wpsAttr struct {
Name string
Type wpsAttrType
Func func([]byte, *map[string]string) string
Desc map[string]string
}
type wpsDevType struct {
Category string
Subcats map[uint16]string
}
var (
wfaExtensionBytes = []byte{0x00, 0x37, 0x2a}
wpsVersion2ID = uint8(0x00)
wpsVersionDesc = map[string]string{
"10": "1.0",
"11": "1.1",
"20": "2.0",
}
wpsDeviceTypes = map[uint16]wpsDevType{
0x0001: {"Computer", map[uint16]string{
0x0001: "PC",
0x0002: "Server",
0x0003: "Media Center",
}},
0x0002: {"Input Device", map[uint16]string{}},
0x0003: {"Printers, Scanners, Faxes and Copiers", map[uint16]string{
0x0001: "Printer",
0x0002: "Scanner",
}},
0x0004: {"Camera", map[uint16]string{
0x0001: "Digital Still Camera",
}},
0x0005: {"Storage", map[uint16]string{
0x0001: "NAS",
}},
0x0006: {"Network Infra", map[uint16]string{
0x0001: "AP",
0x0002: "Router",
0x0003: "Switch",
}},
0x0007: {"Display", map[uint16]string{
0x0001: "TV",
0x0002: "Electronic Picture Frame",
0x0003: "Projector",
}},
0x0008: {"Multimedia Device", map[uint16]string{
0x0001: "DAR",
0x0002: "PVR",
0x0003: "MCX",
}},
0x0009: {"Gaming Device", map[uint16]string{
0x0001: "XBox",
0x0002: "XBox360",
0x0003: "Playstation",
}},
0x000F: {"Telephone", map[uint16]string{
0x0001: "Windows Mobile",
}},
}
wpsAttributes = map[uint16]wpsAttr{
0x104A: {Name: "Version", Desc: wpsVersionDesc},
0x1044: {Name: "State", Desc: map[string]string{
"01": "Not Configured",
"02": "Configured",
}},
0x1012: {Name: "Device Password ID", Desc: map[string]string{
"0000": "Pin",
"0004": "PushButton",
}},
0x103B: {Name: "Response Type", Desc: map[string]string{
"00": "Enrollee Info",
"01": "Enrollee",
"02": "Registrar",
"03": "AP",
}},
0x1054: {Name: "Primary Device Type", Func: dot11ParseWPSDeviceType},
0x1049: {Name: "Vendor Extension", Func: dot11ParseWPSVendorExtension},
0x1053: {Name: "Selected Registrar Config Methods", Func: dot11ParseWPSConfigMethods},
0x1008: {Name: "Config Methods", Func: dot11ParseWPSConfigMethods},
0x103C: {Name: "RF Bands", Func: dott11ParseWPSBands},
0x1057: {Name: "AP Setup Locked"},
0x1041: {Name: "Selected Registrar"},
0x1047: {Name: "UUID-E"},
0x1021: {Name: "Manufacturer", Type: wpsStr},
0x1023: {Name: "Model Name", Type: wpsStr},
0x1024: {Name: "Model Number", Type: wpsStr},
0x1042: {Name: "Serial Number", Type: wpsStr},
0x1011: {Name: "Device Name", Type: wpsStr},
0x1045: {Name: "SSID", Type: wpsStr},
0x102D: {Name: "OS Version", Type: wpsStr},
}
wpsConfigs = map[uint16]string{
0x0001: "USB",
0x0002: "Ethernet",
0x0004: "Label",
0x0008: "Display",
0x0010: "External NFC",
0x0020: "Internal NFC",
0x0040: "NFC Interface",
0x0080: "Push Button",
0x0100: "Keypad",
}
wpsBands = map[uint8]string{
0x01: "2.4Ghz",
0x02: "5.0Ghz",
}
)
func dott11ParseWPSBands(data []byte, info *map[string]string) string {
if len(data) == 1 {
mask := uint8(data[0])
bands := []string{}
for bit, band := range wpsBands {
if mask&bit != 0 {
bands = append(bands, band)
}
}
if len(bands) > 0 {
return strings.Join(bands, ", ")
}
}
return hex.EncodeToString(data)
}
func dot11ParseWPSConfigMethods(data []byte, info *map[string]string) string {
if len(data) == 2 {
mask := binary.BigEndian.Uint16(data)
configs := []string{}
for bit, conf := range wpsConfigs {
if mask&bit != 0 {
configs = append(configs, conf)
}
}
if len(configs) > 0 {
return strings.Join(configs, ", ")
}
}
return hex.EncodeToString(data)
}
func dot11ParseWPSVendorExtension(data []byte, info *map[string]string) string {
if len(data) > 3 && bytes.Equal(data[0:3], wfaExtensionBytes) {
size := len(data)
for offset := 3; offset < size; {
idByte := uint8(data[offset])
sizeByte := uint8(data[offset+1])
if idByte == wpsVersion2ID {
verByte := fmt.Sprintf("%x", data[offset+2])
(*info)["Version"] = wpsVersionDesc[verByte]
data = data[offset+3:]
break
}
offset += int(sizeByte) + 2
}
}
return hex.EncodeToString(data)
}
func dot11ParseWPSDeviceType(data []byte, info *map[string]string) string {
if len(data) == 8 {
catId := binary.BigEndian.Uint16(data[0:2])
oui := data[2:6]
subCatId := binary.BigEndian.Uint16(data[6:8])
if cat, found := wpsDeviceTypes[catId]; found {
if sub, found := cat.Subcats[subCatId]; found {
return fmt.Sprintf("%s (oui:%x)", sub, oui)
}
return fmt.Sprintf("%s (oui:%x)", cat.Category, oui)
}
return fmt.Sprintf("cat:%x sub:%x oui:%x %x", catId, subCatId, oui, data)
}
return hex.EncodeToString(data)
}