|
@@ -0,0 +1,228 @@
|
|
1
|
+package main
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "flag"
|
|
5
|
+ "fmt"
|
|
6
|
+ "os"
|
|
7
|
+)
|
|
8
|
+
|
|
9
|
+func main() {
|
|
10
|
+
|
|
11
|
+ var serial, option, value int
|
|
12
|
+ var valueStr string
|
|
13
|
+ var listOptions bool
|
|
14
|
+
|
|
15
|
+ flag.BoolVar(&listOptions, "l", false, "list options and exit")
|
|
16
|
+ flag.IntVar(&serial, "s", 0, "serial number of receiver")
|
|
17
|
+ flag.IntVar(&option, "o", 0, "option number (use -l to list)")
|
|
18
|
+ flag.StringVar(&valueStr, "v", "", "option value in hex (typically 00 = enable, FF = disable)")
|
|
19
|
+
|
|
20
|
+ flag.Parse()
|
|
21
|
+
|
|
22
|
+ if listOptions {
|
|
23
|
+ for i, name := range optionNames {
|
|
24
|
+ if name == "" {
|
|
25
|
+ continue
|
|
26
|
+ }
|
|
27
|
+ fmt.Printf("Option %2d = %s\n", i, name)
|
|
28
|
+ }
|
|
29
|
+ os.Exit(0)
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ if serial == 0 || option == 0 || valueStr == "" {
|
|
33
|
+ flag.PrintDefaults()
|
|
34
|
+ os.Exit(1)
|
|
35
|
+
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ if option < 0 || option > 59 {
|
|
39
|
+ fmt.Printf("Option number %d is out of range (allowed: 0-59)\n", option)
|
|
40
|
+ os.Exit(1)
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ n, err := fmt.Sscanf(valueStr, "%2x", &value)
|
|
44
|
+
|
|
45
|
+ if n == 0 || err != nil {
|
|
46
|
+ fmt.Println("Unable to parse option value.")
|
|
47
|
+ os.Exit(1)
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ e := encrypt(serial, option, value)
|
|
51
|
+
|
|
52
|
+ fmt.Printf("Receiver Serial Number: %d\n", serial)
|
|
53
|
+ if option < len(optionNames) {
|
|
54
|
+ fmt.Printf("Option Number: %d (%s)\n", option, optionNames[option])
|
|
55
|
+ } else {
|
|
56
|
+ fmt.Printf("Option Number: %d (out of range)\n", option)
|
|
57
|
+ }
|
|
58
|
+ fmt.Printf("Option Value: %02X\n", value)
|
|
59
|
+ fmt.Printf("Code: %s\n", e)
|
|
60
|
+
|
|
61
|
+ return
|
|
62
|
+
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+func encrypt(serialNumber, feature, value int) string {
|
|
66
|
+
|
|
67
|
+ passwordStr := fmt.Sprintf("%05d%02d%02X", serialNumber, feature, value)
|
|
68
|
+
|
|
69
|
+ password := []byte(passwordStr)
|
|
70
|
+
|
|
71
|
+ fromASCII(password)
|
|
72
|
+
|
|
73
|
+ sn := byte(serialNumber) & 0xF
|
|
74
|
+ secret := []byte{7, 7, 5, 5, 9, 8, 1, 4, 2}
|
|
75
|
+
|
|
76
|
+ encrypted := make([]byte, 10)
|
|
77
|
+
|
|
78
|
+ for x := 0; x < 9; x++ {
|
|
79
|
+ encrypted[8-x] = sn ^ secret[8-x] ^ reverseBits(password[x])
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ encrypted[9] = calculateCheck(encrypted)
|
|
83
|
+
|
|
84
|
+ toASCII(encrypted)
|
|
85
|
+
|
|
86
|
+ return string(encrypted)
|
|
87
|
+
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+func decrypt(serialNumber int, passwordStr string) (int, int, int, error) {
|
|
91
|
+
|
|
92
|
+ if len(passwordStr) != 10 {
|
|
93
|
+ return 0, 0, 0, fmt.Errorf("password must be 10 characters long")
|
|
94
|
+ }
|
|
95
|
+ password := []byte(passwordStr)
|
|
96
|
+
|
|
97
|
+ fromASCII(password)
|
|
98
|
+
|
|
99
|
+ sum := calculateCheck(password)
|
|
100
|
+ if password[9] != sum {
|
|
101
|
+ return 0, 0, 0, fmt.Errorf("bad checksum")
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ sn := byte(serialNumber) & 0xF
|
|
105
|
+ secret := []byte{7, 7, 5, 5, 9, 8, 1, 4, 2}
|
|
106
|
+
|
|
107
|
+ decrypted := make([]byte, 9)
|
|
108
|
+
|
|
109
|
+ for x := 0; x < 9; x++ {
|
|
110
|
+ decrypted[8-x] = reverseBits(sn ^ secret[x] ^ password[x])
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ toASCII(decrypted)
|
|
114
|
+
|
|
115
|
+ var serial, option, value int
|
|
116
|
+
|
|
117
|
+ _, err := fmt.Sscanf(string(decrypted), "%5d%2d%2X", &serial, &option, &value)
|
|
118
|
+ if err != nil {
|
|
119
|
+ return 0, 0, 0, err
|
|
120
|
+ }
|
|
121
|
+ return serial, option, value, nil
|
|
122
|
+
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+func calculateCheck(password []byte) byte {
|
|
126
|
+ sum := 0
|
|
127
|
+
|
|
128
|
+ for i := 8; i >= 0; i-- {
|
|
129
|
+ for j := 3; j >= 0; j-- {
|
|
130
|
+ sum += int(password[i]) >> j & 1
|
|
131
|
+ }
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ return byte(sum & 0xF)
|
|
135
|
+}
|
|
136
|
+
|
|
137
|
+func reverseBits(in byte) byte {
|
|
138
|
+ var out byte
|
|
139
|
+ for i := 0; i < 4; i++ {
|
|
140
|
+ if in&(1<<i) != 0 {
|
|
141
|
+ out |= 1 << (3 - i)
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+ return out
|
|
145
|
+}
|
|
146
|
+
|
|
147
|
+func fromASCII(s []byte) {
|
|
148
|
+ for i, b := range s {
|
|
149
|
+ if b > '9' {
|
|
150
|
+ s[i] -= '7'
|
|
151
|
+ } else {
|
|
152
|
+ s[i] -= '0'
|
|
153
|
+ }
|
|
154
|
+ }
|
|
155
|
+}
|
|
156
|
+
|
|
157
|
+func toASCII(s []byte) {
|
|
158
|
+ for i, b := range s {
|
|
159
|
+ if b > 9 {
|
|
160
|
+ s[i] += '7'
|
|
161
|
+ } else {
|
|
162
|
+ s[i] += '0'
|
|
163
|
+ }
|
|
164
|
+ }
|
|
165
|
+}
|
|
166
|
+
|
|
167
|
+var optionNames = []string{
|
|
168
|
+ "POWER UP PORT SETTINGS",
|
|
169
|
+ "POWER UP OUTPUT MSGS",
|
|
170
|
+ "LOCATOR",
|
|
171
|
+ "POWER UP NV ERASE",
|
|
172
|
+ "RTCM ASCII",
|
|
173
|
+ "CYCLE PRINT",
|
|
174
|
+ "POSITION STATISTICS",
|
|
175
|
+ "TAILBOUY",
|
|
176
|
+ "PATHFINDER",
|
|
177
|
+ "LANDSEIS",
|
|
178
|
+ "RTCM NETWORK INPUT",
|
|
179
|
+ "CARRIER PHASE",
|
|
180
|
+ "HALF CYCLE L2",
|
|
181
|
+ "MAXWELL L1 ONLY",
|
|
182
|
+ "REMOTE DOWNLOAD",
|
|
183
|
+ "DEMO EQUIPMENT ONLY",
|
|
184
|
+ "",
|
|
185
|
+ "RT SURVEY DATA",
|
|
186
|
+ "LOCAL DATUMS",
|
|
187
|
+ "RSIM INTERFACE",
|
|
188
|
+ "DUAL FREQ / MULTI-BIT",
|
|
189
|
+ "RS-232 PORTS",
|
|
190
|
+ "MULTIPLE DATUMS",
|
|
191
|
+ "EXTERNAL TIMEBASE",
|
|
192
|
+ "EVENT MARKER",
|
|
193
|
+ "1 PPS",
|
|
194
|
+ "",
|
|
195
|
+ "FIRMWARE UPDATE",
|
|
196
|
+ "RTCM INPUTS",
|
|
197
|
+ "RTCM OUTPUTS",
|
|
198
|
+ "SYNC INTERVAL",
|
|
199
|
+ "NMEA-0183",
|
|
200
|
+ "SV SWAPPING",
|
|
201
|
+ "KEYBOARD TYPE",
|
|
202
|
+ "NAVIGATION",
|
|
203
|
+ "LctrCrPh",
|
|
204
|
+ "KINEMATIC",
|
|
205
|
+ "CONFIGURED",
|
|
206
|
+ "DATA LOGGING SIZE",
|
|
207
|
+ "SURVEY TYPE",
|
|
208
|
+ "RTK OTF CAPABILITIES",
|
|
209
|
+ "IONO-FREE POSITIONING",
|
|
210
|
+ "",
|
|
211
|
+ "I/O DRIVERS",
|
|
212
|
+ "",
|
|
213
|
+ "CMR TYPE2 RATE",
|
|
214
|
+ "RTK SPECIALS",
|
|
215
|
+ "",
|
|
216
|
+ "",
|
|
217
|
+ "",
|
|
218
|
+ "",
|
|
219
|
+ "",
|
|
220
|
+ "",
|
|
221
|
+ "",
|
|
222
|
+ "",
|
|
223
|
+ "",
|
|
224
|
+ "",
|
|
225
|
+ "",
|
|
226
|
+ "",
|
|
227
|
+ "",
|
|
228
|
+}
|