-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemMenu.c
More file actions
executable file
·516 lines (473 loc) · 20.1 KB
/
systemMenu.c
File metadata and controls
executable file
·516 lines (473 loc) · 20.1 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include "reconn.h"
#include "debugMenu.h"
#include "powerMgmt.h"
#include "socket.h"
#include "wifi.h"
#include "version.h"
static int macSet();
static int macShow();
static int serialSet();
static int serialShow();
static int timers();
static int systemStats();
static int resetStats();
static int defaultState();
static int noDefault();
static int showVersion();
#ifndef __SIMULATION__
static char *macWriteWifiCommandString = "calibrator set nvs_mac /lib/firmware/ti-connectivity/wl1271-nvs.bin ";
#endif
debugMenuStruct systemDebugMenu[] =
{
{"system", "System wide debug Menus", NULL, NULL, NULL},
{NULL, NULL, "mac", "displays the reconn mac addresses", macShow},
{NULL, NULL, "macSet", "changes the WiFi mac address", macSet},
{NULL, NULL, "serial", "displays the unit's serial number", serialShow},
{NULL, NULL, "serialSet", "changes the unit's serial number", serialSet},
{NULL, NULL, "stats", "displays some system stats", systemStats},
{NULL, NULL, "reset", "resets all stats", resetStats},
{NULL, NULL, "timers", "Displays the system's shutdown timers", timers},
{NULL, NULL, "default", "Sets the reconn back to default state. Also removes WIFI", defaultState},
{NULL, NULL, "nodefault", "Set box as non-defaulted. Also enables WIFI", noDefault},
{NULL, NULL, "version", "Displays the reconn software version", showVersion}
};
void registerSystemDebugMenu()
{
registerDebugCommand(&systemDebugMenu[0], sizeof(systemDebugMenu)/sizeof(debugMenuStruct));
}
static int timers(int theSocketFd)
{
PowerMgmtEqptCounters eqptCounters;
if(getStandbyCounters(&eqptCounters) == RECONN_SUCCESS)
{
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "\r\n%-25s%s\r\n", "Variable", "Count");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "================================\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-25s%d\r\n", "PowerMeterCounter", eqptCounters.PowerMeterCounter);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-25s%d\r\n", "DmmCounter", eqptCounters.DmmCounter);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-25s%d\r\n", "GpsCounter", eqptCounters.GpsCounter);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-25s%d\r\n", "SpectrumAnalyzerCounter", eqptCounters.SpectrumAnalyzerCounter);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-25s%d\r\n", "ReconnSystemCounter", eqptCounters.ReconnSystemCounter);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
}
return RECONN_SUCCESS;
}
static int serialSet(int theSocketFd)
{
int notDone = TRUE;
unsigned int i;
int allDigits = TRUE;
FILE *serialNumberFd;
size_t bytesRead;
char *responsePtr;
while(notDone)
{
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "\r\nEnter the serial number in the form R 0-9 alpha character\n\rfollowed by 4 digits (Example R1A0001) or q to quit > ");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
if((responsePtr = getInput(theSocketFd, YES)) != NULL)
{
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
if(strlen(responsePtr) > RECONN_SERIALNUM_MAX_LEN)
{
sprintf((char *)&debugOutputString,"\r\n\r\nSerial number is too long.\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
free(responsePtr);
continue;
}
else if((responsePtr[0] == 'Q') || (responsePtr[0] == 'q'))
{
notDone = FALSE;
free(responsePtr);
continue;
}
else if(responsePtr[0] != 'R')
{
sprintf((char *)&debugOutputString,"\r\nFirst Character must be R.\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
free(responsePtr);
continue;
}
else if(!isdigit(responsePtr[1]))
{
sprintf((char *)&debugOutputString,"\r\n%c is not a digit.\r\n", responsePtr[1]);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
free(responsePtr);
continue;
}
else if(!isalpha(responsePtr[2]))
{
sprintf((char *)&debugOutputString,"\r\n%c is not a character.\r\n", responsePtr[1]);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
free(responsePtr);
continue;
}
else
{
for(i = 3; i < strlen(responsePtr); i++)
{
if(!isdigit(responsePtr[i]))
{
sprintf((char *)&debugOutputString,"\r\n%c is not a digit.\r\n", responsePtr[i]);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
allDigits = FALSE;
free(responsePtr);
continue;
}
}
if(allDigits == TRUE)
{
if((serialNumberFd = fopen(RECONN_SERIALNUM_FILE_NAME, "w+")))
{
if((bytesRead = fwrite(responsePtr, 1, strlen(responsePtr), serialNumberFd)) != strlen(responsePtr))
{
reconnDebugPrint("%s: fwrite() failed %d(%s)\n", __FUNCTION__, errno, strerror(errno));
}
fclose(serialNumberFd);
free(responsePtr);
notDone = FALSE;
}
else
{
reconnDebugPrint("%s: fopen(%s, w+)() failed %d(%s)\n", __FUNCTION__, RECONN_SERIALNUM_FILE_NAME, errno, strerror(errno));
}
}
}
}
else
{
reconnDebugPrint("%s: getInput returned NULL\n", __FUNCTION__);
notDone = FALSE;
}
}
return RECONN_SUCCESS;
}
static int serialShow(int theSocketFd)
{
char theSerialNumberString[RECONN_SERIALNUM_MAX_LEN];
short serialBytesRead;
FILE *serialNumberFd = NULL;
if((serialNumberFd = fopen(RECONN_SERIALNUM_FILE_NAME, "r")))
{
memset(&theSerialNumberString, 0, RECONN_SERIALNUM_MAX_LEN);
serialBytesRead = fread(&theSerialNumberString, 1, RECONN_SERIALNUM_MAX_LEN, serialNumberFd);
if((serialBytesRead == 0) && (feof(serialNumberFd)))
{
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\nSerial number record is empty. Use serialSet command to program the serial number\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
reconnDebugPrint("%s: fread () failed %d(%s)\n", __FUNCTION__, errno, strerror(errno));
}
else
{
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n\r\nSerial number is %s\r\n\r\n", theSerialNumberString);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
}
fclose(serialNumberFd);
}
else
{
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\nSerial number has not been configured.\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
reconnDebugPrint("%s: open(%s, r) failed %d(%s)\n", __FUNCTION__, RECONN_SERIALNUM_FILE_NAME, errno,
strerror(errno));
}
return RECONN_SUCCESS;
}
static int macShow(int theSocketFd)
{
char theMacString[RECONN_MACADDR_LEN]; // aa:bb:cc:dd:ee:ff
int tmpSocket, i, index;
struct ifreq buffer;
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
memset(&theMacString, 0, RECONN_MACADDR_LEN);
if(wifiGetMacAddress((char *)&theMacString) == RECONN_SUCCESS)
{
sprintf(debugOutputString, "\r\n\r\nWiFi mac address is ");
strncat(debugOutputString, (char *)&theMacString, RECONN_MACADDR_LEN);
}
else
{
sprintf(debugOutputString, "\r\nCould not read WiFi mac address");
}
strcat(debugOutputString, "\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
memset(&theMacString, 0, RECONN_MACADDR_LEN);
sprintf(debugOutputString, "RJ-45 mac address is ");
if((tmpSocket = socket(PF_INET, SOCK_STREAM, 0)) != -1)
{
#ifndef __SIMULATION__
strcpy (buffer.ifr_name, "usb0");
#else
strcpy (buffer.ifr_name, "eth0");
#endif
ioctl(tmpSocket, SIOCGIFHWADDR, &buffer);
for(index = 0, i = 0; i < 6; i++)
{
sprintf(&(theMacString[index]), "%.2X", (unsigned char)buffer.ifr_hwaddr.sa_data[i]);
if(i < 5)
{
strcat(theMacString, ":");
index += 3;
}
}
strcat((char *)&debugOutputString, theMacString);
close(tmpSocket);
}
else
{
reconnDebugPrint("%s: socket(PF_INET, SOCK_STREAM, 0) failed %d (%s)\n", __FUNCTION__, errno, strerror(errno));
}
strcat(debugOutputString, "\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
return RECONN_SUCCESS;
}
static int macSet(int theSocketFd)
{
int Done = FALSE;
int i, numColons, alphaNumerics, setWiFi = FALSE;
char theCommand[100];
char *responsePtr;
FILE *rj45MacFd;
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
while(Done == FALSE)
{
sendSocket(theSocketFd, (unsigned char *)DEBUG_CLEARSCREEN, strlen(DEBUG_CLEARSCREEN), 0);
sendSocket(theSocketFd, (unsigned char *)DEBUG_CURSORHOME, strlen(DEBUG_CURSORHOME), 0);
sprintf((char *)&debugOutputString, "\r\n1) Wifi\r\n2) RJ-45\r\nq) quit\r\n(1, 2 or q)> ");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
if((responsePtr = getInput(theSocketFd, YES)) != NULL)
{
if(strcmp(responsePtr, "1") == 0)
{
setWiFi = TRUE;
Done = FALSE;
break;
}
else if(strcmp(responsePtr, "2") == 0)
{
Done = FALSE;
break;
}
else if(strcmp(responsePtr, "q") == 0)
{
Done = TRUE;
sendSocket(theSocketFd, (unsigned char *)DEBUG_CLEARSCREEN, strlen(DEBUG_CLEARSCREEN), 0);
sendSocket(theSocketFd, (unsigned char *)DEBUG_CURSORHOME, strlen(DEBUG_CURSORHOME), 0);
}
}
else
{
reconnDebugPrint("%s: recv() failed %d(%s)\n", __FUNCTION__, errno, strerror(errno));
Done = TRUE;
}
}
/*
* Get the mac address from the user.
*/
while(Done == FALSE)
{
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "\r\nEnter the mac address in the form aa:bb:cc:dd:ee:ff or q to quit > ");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
if((responsePtr = getInput(theSocketFd, YES)) != NULL)
{
memset(&debugOutputString, 0, DEBUG_OUTPUT_LEN);
if(strlen(responsePtr) > RECONN_MACADDR_LEN)
{
sprintf((char *)&debugOutputString,"\r\n\r\nIncorrect mac address format\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
continue;
}
else if((responsePtr[0] == 'Q') || (responsePtr[0] == 'q'))
{
Done = TRUE;
continue;
}
/*
* Now check the format. There has to be exactly 5 colons 12 alphanumerics
*/
for(i = numColons = alphaNumerics = 0; i < RECONN_MACADDR_LEN; i++)
{
if(responsePtr[i] == ':')
numColons++;
if(isalnum(responsePtr[i]))
alphaNumerics++;
}
if((numColons != 5) || (alphaNumerics != 12))
{
sprintf(debugOutputString, "\r\ninvalid mac address \r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
continue;
}
if(setWiFi)
{
memset(theCommand, 0, 100);
/*
* Set the mac address in the WIFI configuration file
*/
#ifndef __SIMULATION__
sprintf(theCommand, "%s%s", macWriteWifiCommandString, responsePtr);
#else
sprintf(theCommand, "%s%s%s%s", "echo ", responsePtr, ">", RECONN_MACADDR_FILE_NAME);
#endif
reconnDebugPrint("%s: %s\n", __FUNCTION__, theCommand);
system(theCommand);
/*
* Change the hardware's MAC address
*/
#ifndef __SIMULATION__
sprintf(theCommand, "ifconfig wlan0 down hw ether %s", responsePtr);
system(theCommand);
sleep(2);
#endif
reconnDebugPrint("%s: %s\n", __FUNCTION__, theCommand);
#ifndef __SIMULATION__
system("ifconfig wlan0 up");
#endif
reconnDebugPrint("%s: ifconfig wlan0 up\n", __FUNCTION__);
Done = TRUE;
}
else
{
if((rj45MacFd = fopen(RJ45_MAC_ADDRRESS_FILE_NAME, "w")))
{
if (fwrite(responsePtr, 1, RECONN_MACADDR_LEN, rj45MacFd) != RECONN_MACADDR_LEN)
{
reconnDebugPrint("%s: fwrite(%s, 1, %d, %d) failed %d (%s)\n", __FUNCTION__,
responsePtr, RECONN_MACADDR_LEN, rj45MacFd, errno, strerror(errno));
fclose(rj45MacFd);
Done = TRUE;
}
else
{
fclose(rj45MacFd);
memset(theCommand, 0, 100);
sprintf(theCommand, "ifconfig usb0 down hw ether %s", responsePtr);
#ifndef __SIMULATION__
system(theCommand);
sleep(2);
#endif
reconnDebugPrint("%s: %s\n\n", __FUNCTION__, theCommand);
sprintf(theCommand, "ifconfig usb0 up");
#ifndef __SIMULATION__
system(theCommand);
#endif
reconnDebugPrint("%s: %s\n\n", __FUNCTION__, theCommand);
Done = TRUE;
}
}
else
{
reconnDebugPrint("%s: fopen(%s, w) failed %d (%s)\n", __FUNCTION__,
RJ45_MAC_ADDRRESS_FILE_NAME, errno, strerror(errno));
Done = TRUE;
}
}
}
else
{
reconnDebugPrint("%s: recv() failed %d(%s)\n", __FUNCTION__, errno, strerror(errno));
Done = FALSE;
}
}
return RECONN_SUCCESS;
}
static int systemStats(int theSocketFd)
{
extern int gAnalyzerHigh, gPayloadHigh, gDmmHigh, gPowerMeterHigh;
extern int gDmmResponses, gAnalyzerResponses, gMeterResponses;
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "\r\n%-20s%s\r\n", "Variable", "Value");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "================================\r\n");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gAnalyzerHigh", gAnalyzerHigh);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gDmmHigh", gDmmHigh);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gPowerMeterHigh", gPowerMeterHigh);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gPayloadHigh", gPayloadHigh);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gDmmResponses", gDmmResponses);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gAnalyzerResponses", gAnalyzerResponses);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "%-20s%d\r\n", "gMeterResponses", gMeterResponses);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
return RECONN_SUCCESS;
}
static int resetStats(int theSocketFd)
{
extern int gAnalyzerHigh, gPayloadHigh, gDmmHigh, gPowerMeterHigh;
extern int gDmmResponses, gAnalyzerResponses, gMeterResponses;
UNUSED_PARAM(theSocketFd);
gAnalyzerHigh = gPayloadHigh = gDmmHigh = gPowerMeterHigh = 0;
gDmmResponses = gAnalyzerResponses = gMeterResponses = 0;
return RECONN_SUCCESS;
}
static int noDefault(int theSocketFd)
{
UNUSED_PARAM(theSocketFd);
unlink(RECONN_DEFAULT_FILE_NAME);
wifiSetState(WIFI_ENABLE);
return RECONN_SUCCESS;
}
static int defaultState(int theSocketFd)
{
char *theCommand;
int length = strlen("touch ") + strlen(RECONN_DEFAULT_FILE_NAME) + 1;
UNUSED_PARAM(theSocketFd);
theCommand = malloc(length);
if(theCommand)
{
memset(theCommand, 0, length);
strcat(theCommand, "touch ");
strcat(theCommand, RECONN_DEFAULT_FILE_NAME);
system(theCommand);
wifiSetState(WIFI_DISABLE);
unlink(WIFI_ACTIVE_FILE_NAME);
free(theCommand);
}
return RECONN_SUCCESS;
}
static int showVersion(int theSocketFd)
{
sendSocket(theSocketFd, (unsigned char *)getReconnSwVersion(), strlen(getReconnSwVersion()), 0);
return RECONN_SUCCESS;
}