-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwpal_cli.c
2857 lines (2406 loc) · 101 KB
/
dwpal_cli.c
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: BSD-2-Clause-Patent
*
* Copyright (c) 2016-2019 Intel Corporation
*
* This code is subject to the terms of the BSD+Patent license.
* See LICENSE file for more details.
*/
/* *****************************************************************************
* File Name : dwpal_debug_cli.c *
* Description : test utility in order to test D-WPAL control interface *
* *
* *****************************************************************************/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <signal.h>
#include <malloc.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#if defined YOCTO
#include <errno.h>
#endif
#include <readline/readline.h>
#include <readline/history.h>
#include <sys/select.h>
#if defined YOCTO
#include <slibc/string.h>
#else
#include "safe_str_lib.h"
#endif
#include "dwpal.h"
#include "dwpal_ext.h"
#include "dwpal_log.h" //Logging
#include <pthread.h>
#if defined YOCTO
#if !defined RSIZE_MAX_STR
#define RSIZE_MAX_STR 256
#endif
//Logging Macros
#ifndef LOG_LEVEL
unsigned int LOGLEVEL = SYS_LOG_DEBUG + 1;
#else
unsigned int LOGLEVEL = LOG_LEVEL + 1;
#endif
#ifndef LOG_TYPE
unsigned int LOGTYPE = SYS_LOG_TYPE_CONSOLE | SYS_LOG_TYPE_FILE;
#else
unsigned int LOGTYPE = LOG_TYPE;
#endif
unsigned int LOGPROFILE;
#endif //END YOCTO
#define NUM_OF_LISTENING_EVENTS 16
extern int check_stats_cmd(int num_arg,char *cmd[]);
DWPAL_Ret nlCliOneShotEventCallback(char *ifname, int event, int subevent, size_t len, unsigned char *data);
DWPAL_Ret nlCliEventCallback(char *ifname, int event, int subevent, size_t len, unsigned char *data);
void dwpalCliCtrlEventCallback(char *msg, size_t len);
typedef struct
{
char *interfaceType;
char *radioName;
char *serviceName;
int fd, fdCmdGet;
} DwpalService;
typedef struct
{
char MACAddress[18];
int rx_packets;
char rssi[128];
} DWPAL_unconnected_sta_rssi_event;
typedef struct
{
char MACAddress[18];
int channel;
int dialog_token;
int measurement_rep_mode;
int op_class;
int duration;
int rcpi;
int rsni;
char bssid[18];
} DWPAL_rrm_beacon_rep_received_event;
typedef struct
{
int freq;
char chan_width[8];
int cf1;
} DWPAL_dfs_nop_finished_event;
typedef struct
{
int success;
int freq;
int timeout;
char chan_width[8];
} DWPAL_dfs_cac_completed_event;
typedef struct
{
char MACAddress[18];
int status_code;
} DWPAL_bss_tm_resp_event;
typedef struct
{
char VAPName[16];
char channel[8];
int OperatingChannelBandwidt;
int ExtensionChannel;
int cf1;
int dfs_chan;
char reason[32];
} DWPAL_acs_completed_event;
typedef struct
{
char VAPName[16];
int Channel;
int OperatingChannelBandwidt;
int ExtensionChannel;
int cf1;
int dfs_chan;
char reason[32];
} DWPAL_csa_finished_channel_int_event;
typedef struct
{
char VAPName[16];
char Channel[8];
int OperatingChannelBandwidt;
int ExtensionChannel;
int cf1;
int dfs_chan;
char reason[32];
} DWPAL_csa_finished_event;
typedef struct
{
char VAPName[16];
char MACAddress[18];
} DWPAL_sta_disconnected_event;
typedef struct
{
char VAPName[16];
char MACAddress[18];
int signalStrength;
int supportedRates[32];
int HT_CAP;
int HT_MCS[32];
int VHT_CAP;
int VHT_MCS[32];
bool btm_supported;
bool nr_enabled;
char non_pref_chan[32][HOSTAPD_TO_DWPAL_VALUE_STRING_LENGTH];
bool cell_capa;
char assoc_req[HOSTAPD_TO_DWPAL_VALUE_STRING_LENGTH];
} DWPAL_sta_connected_event;
typedef struct
{
int dialog_token;
} DWPAL_req_beacon;
typedef struct
{
char ShortTermRSSIAverage[32];
} DWPAL_get_sta_measurements;
typedef struct
{
char BSSID[18];
char SSID[128];
long long int BytesSent;
char BytesReceived[16];
char PacketsSent[16];
char PacketsReceived[16];
int ErrorsSent;
int ErrorsReceived;
int RetransCount;
} DWPAL_get_vap_measurements;
typedef struct
{
char freq[32];
int bandwidth;
} DWPAL_get_failsafe_channel;
typedef struct
{
char Name[HOSTAPD_TO_DWPAL_VALUE_STRING_LENGTH];
int HostapdEnabled;
int TxEnabled;
int Channel;
int BytesSent;
int BytesReceived;
int PacketsSent;
int PacketsReceived;
int ErrorsSent;
int ErrorsReceived;
int DiscardPacketsSent;
int DiscardPacketsReceived;
int PLCPErrorCount;
int FCSErrorCount;
int InvalidMACCount;
int PacketsOtherReceived;
int Noise;
int BSS_load;
int TxPower;
int RxAntennas;
int TxAntennas;
int Freq;
int OperatingChannelBandwidt;
int Cf1;
int Dfs_chan;
} DWPAL_radio_info_get;
typedef struct
{
int Ch;
int BW;
int DFS;
int pow;
int NF;
int bss;
int pri;
int load;
} DWPAL_acs_report_get;
#if 0
static DwpalService dwpalService[] = { { "hostap", "wlan0", "TWO_WAY", -1, -1 }, /* Will send commands and get events on the same socket */
#else
static DwpalService dwpalService[] = { { "hostap", "wlan0", "ONE_WAY", -1, -1 }, /* Will send commands and get events on a different socket */
#endif
{ "hostap", "wlan1", "ONE_WAY", -1, -1 },
{ "hostap", "wlan2", "ONE_WAY", -1, -1 }, /* Will send commands and get events on a different socket */
{ "hostap", "wlan3", "ONE_WAY", -1, -1 },
{ "hostap", "wlan4", "ONE_WAY", -1, -1 },
{ "hostap", "wlan5", "ONE_WAY", -1, -1 },
{ "Driver", "ALL", "TWO_WAY", -1, -1 } };
static void *context[sizeof(dwpalService) / sizeof(DwpalService)] = { [0 ... (sizeof(dwpalService) / sizeof(DwpalService) - 1) ] = NULL };
static bool isCliRunning = true;
static char oneShotCommand[DWPAL_TO_HOSTAPD_MSG_LENGTH] = "\0";
static int numOfListeningEvents = 0;
static char opCodeForListener[NUM_OF_LISTENING_EVENTS][DWPAL_OPCODE_STRING_LENGTH] = { [0 ... (NUM_OF_LISTENING_EVENTS - 1)] = "\0" }; //"\0";
static char oneShotVAPName[DWPAL_VAP_NAME_STRING_LENGTH] = "\0";
static bool isContinueListening = true;
/* Supported commands */
static const char *s_arrDwpalCommands[][2] =
{
{ "help", "CLI help" },
{ "exit", "Exit the CLI" },
{ "quit", "Exit the CLI" },
{ "DWPAL_INIT", "DWPAL init" },
{ "DWPAL_HOSTAP_CMD_SEND", "DWPAL hostap command send" },
{ "DWPAL_EXT_HOSTAP_IF_ATTACH", "DWPAL Extender hostap interface attach" },
{ "DWPAL_EXT_HOSTAP_IF_DETACH", "DWPAL Extender hostap interface detach" },
{ "DWPAL_EXT_DRIVER_NL_IF_ATTACH", "DWPAL Extender driver nl interface attach" },
{ "DWPAL_EXT_DRIVER_NL_IF_DETACH", "DWPAL Extender driver nl interface detach" },
{ "DWPAL_EXT_DRIVER_NL_CMD_SEND", "DWPAL Extender driver nl command send" },
/* Must be at the end */
{ "__END__", "MUST BE THE LAST ENTRY!" }
};
DWPAL_Ret nlCliOneShotEventCallback(char *ifname, int event, int subevent, size_t len, unsigned char *data)
{
if (event == NL80211_CMD_VENDOR)
{
switch (subevent)
{
case LTQ_NL80211_VENDOR_EVENT_ASSERT_DUMP_READY:
if (!strncmp("FW_DUMP_READY", opCodeForListener[0], 13))
{
if (!strncmp(ifname, oneShotVAPName, 5))
{
console_printf("%s; LTQ_NL80211_VENDOR_EVENT_ASSERT_DUMP_READY received => exit!\n", __FUNCTION__);
exit(0); /* Terminate the process */
}
console_printf("%s; LTQ_NL80211_VENDOR_EVENT_ASSERT_DUMP_READY received from %s " \
"listening only to %s => ignore\n", __FUNCTION__, ifname, oneShotVAPName);
}
break;
default:
console_printf("%s; unsupported vendor sub event received; ifname= '%s', event= %d, subevent= %d (len= %d)\n",
__FUNCTION__, ifname, event, subevent, len);
break;
}
}
else
{
console_printf("%s; unsupported event (%d) received\n", __FUNCTION__, event);
}
if ( (oneShotCommand[0] != '\0') && (opCodeForListener[0][0] == '\0') )
{
/* Not waiting for a specific event ==> solicited event received (due to 'get command') */
console_printf("%s; solicited event received => print first bytes (up to 10), and exit!\n", __FUNCTION__);
size_t i, lenToPrint = (len <= 10)? len : 10;
for (i=0; i < lenToPrint; i++)
{
console_printf(" 0x%x", data[i]);
}
console_printf("\n");
exit(0); /* Terminate the process */
}
return DWPAL_SUCCESS;
}
DWPAL_Ret nlCliEventCallback(char *ifname, int event, int subevent, size_t len, unsigned char *data)
{
size_t i, lenToPrint = (len <= 10)? len : 10;
console_printf("%s Entry; ifname= '%s', event= %d, subevent= %d (len= %d)\n", __FUNCTION__, ifname, event, subevent, len);
for (i=0; i < lenToPrint; i++)
{
console_printf(" 0x%x", data[i]);
}
console_printf("\n");
return DWPAL_SUCCESS;
}
static DWPAL_Ret nlCliCmdGetCallback(char *ifname, int event, int subevent, size_t len, unsigned char *data)
{
size_t i, lenToPrint = (len <= 10)? len : 10;
console_printf("%s Entry; ifname= '%s', event= %d, subevent= %d (len= %d)\n", __FUNCTION__, ifname, event, subevent, len);
for (i=0; i < lenToPrint; i++)
{
console_printf(" 0x%x", data[i]);
}
console_printf("\n");
return DWPAL_SUCCESS;
}
void dwpalCliCtrlEventCallback(char *msg, size_t len)
{
console_printf("%s; len= %d, msg= '%s'\n", __FUNCTION__, len, msg);
}
static char *dwpal_debug_cli_tab_completion_entry(const char *text , int start)
{
(void)text;
(void)start;
return (NULL);
}
static void sigterm_handler(void)
{
isCliRunning = false;
fclose(stdin);
console_printf("\n");
}
static void sigint_handler(void)
{
isCliRunning = false;
fclose(stdin);
console_printf("\n");
}
static void init_signals(void)
{
struct sigaction sigterm_action;
sigterm_action.sa_handler = (__sighandler_t)sigterm_handler;
sigemptyset(&sigterm_action.sa_mask);
sigterm_action.sa_flags = 0;
sigaction(SIGTERM, &sigterm_action, NULL);
struct sigaction sigint_action;
sigint_action.sa_handler = (__sighandler_t)sigint_handler;
sigemptyset(&sigint_action.sa_mask);
sigint_action.sa_flags = 0;
sigaction(SIGINT, &sigint_action, NULL);
}
static char *dupstr(const char *s)
{
char *r;
if (!(r = (char *)malloc((size_t)(strnlen_s(s, 256) + 1))))
{
console_printf("Error: Out of memory. Exiting\n");
sigterm_handler();
}
else
{
strcpy_s(r, strnlen_s(s, RSIZE_MAX_STR) + 1, s);
}
return (r);
}
static char *dwpal_debug_cli_generator(const char *text, int state)
{
static int list_index, len;
const char *name;
if (!state)
{
list_index = 0;
len = strnlen_s(text, 256);
}
while (strncmp(s_arrDwpalCommands[list_index][0], "__END__", 7))
{
name = s_arrDwpalCommands[list_index++][0];
if (strncmp(name, text, len) == 0)
return (dupstr(name));
}
return NULL;
}
static char **dwpal_debug_cli_tab_completion(const char *text , int start, int end)
{
char **matches = NULL;
(void)end;
if (start == 0)
matches = rl_completion_matches(text, dwpal_debug_cli_generator);
else
matches = (char **)NULL;
return (matches);
}
static void dwpal_debug_cli_show_help(void)
{
int i = 0;
console_printf("Supported commands:\n");
/* run till the end of the list */
while (strncmp(s_arrDwpalCommands[i][0], "__END__", 7))
{
console_printf("%-26s - %s\n", s_arrDwpalCommands[i][0], s_arrDwpalCommands[i][1]);
i++;
}
console_printf("\n");
}
static int interfaceIndexGet(char *interfaceType, const char *radioName)
{
int i;
size_t numOfInterfaces = sizeof(dwpalService) / sizeof(DwpalService);
for (i=0; i < (int)numOfInterfaces; i++)
{
if ( (!strncmp(interfaceType, dwpalService[i].interfaceType, 6)) &&
(!strncmp(radioName, dwpalService[i].radioName, 5)) &&
( (!strncmp(dwpalService[i].serviceName, "TWO_WAY", 10)) ||
(!strncmp(dwpalService[i].serviceName, "ONE_WAY", 10)) ) )
{
return i;
}
}
return -1;
}
static bool resultsPrint(FieldsToParse fieldsToParse[], size_t totalSizeOfArg, size_t sizeOfStruct)
{
int i = 0;
size_t j = 0, k;
void *field;
bool isValid = true;
char indexToPrint[16] = "\0";
if (fieldsToParse == NULL)
{
console_printf("%s; input params error ==> Abort!\n", __FUNCTION__);
return false;
}
for (k=0; k < totalSizeOfArg; k++)
{
i = 0;
if (isValid == false)
{ /* When parsing many lines, when a complete set of struct params is invalid, stop printing */
//console_printf("%s; Stop the trace (k= %d)\n", __FUNCTION__, k);
break;
}
if (totalSizeOfArg > 1)
{
snprintf(indexToPrint, sizeof(indexToPrint), "[%d] ", k);
//console_printf("%s; sizeof(indexToPrint)= %d, indexToPrint= '%s'\n", __FUNCTION__, sizeof(indexToPrint), indexToPrint);
}
isValid = false;
while (fieldsToParse[i].parsingType != DWPAL_NUM_OF_PARSING_TYPES)
{
if ( (k > 0) && (k >= *(fieldsToParse[i].numOfValidArgs)) )
{
i++;
continue;
}
if (*(fieldsToParse[i].numOfValidArgs) == 0)
{
console_printf("%s; %s%s=> No valid value!\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch);
}
/* set the output parameter - move it to the next array index (needed when parsing many lines) */
field = (void *)((unsigned int)fieldsToParse[i].field + k * sizeOfStruct);
//console_printf("%s; k= %d, field= 0x%x\n", __FUNCTION__, k, (unsigned int)field);
switch (fieldsToParse[i].parsingType)
{
case DWPAL_STR_PARAM:
if (fieldsToParse[i].stringToSearch == NULL)
{ /* Handle mandatory parameters WITHOUT any string-prefix */
if (field != NULL)
{
console_printf("%s; %s\n", __FUNCTION__, (char *)field);
}
}
else
{
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %s\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, (char *)field);
}
}
break;
case DWPAL_STR_ARRAY_PARAM:
for (j=0; j < *(fieldsToParse[i].numOfValidArgs); j++)
{
char fieldName[DWPAL_FIELD_NAME_LENGTH];
size_t fieldNameLength = strnlen_s(fieldsToParse[i].stringToSearch, DWPAL_FIELD_NAME_LENGTH) - 1;
isValid = true;
/* Copy the entire name except of the last character (which is "=") */
strncpy_s(fieldName, sizeof(fieldName), fieldsToParse[i].stringToSearch, fieldNameLength);
fieldName[fieldNameLength] = '\0';
console_printf("%s; %s%s[%d]= %s\n", __FUNCTION__, indexToPrint, fieldName, j, (char *)&(((char *)field)[j * HOSTAPD_TO_DWPAL_VALUE_STRING_LENGTH]));
}
break;
case DWPAL_CHAR_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %d\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((char *)field));
}
break;
case DWPAL_UNSIGNED_CHAR_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %d\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((unsigned char *)field));
}
break;
case DWPAL_SHORT_INT_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %d\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((short int *)field));
}
break;
case DWPAL_INT_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %d\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((int *)field));
}
break;
case DWPAL_UNSIGNED_INT_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %u\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((unsigned int *)field));
}
break;
case DWPAL_LONG_LONG_INT_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %lld\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((long long int *)field));
}
break;
case DWPAL_UNSIGNED_LONG_LONG_INT_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %llu\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((unsigned long long int *)field));
}
break;
case DWPAL_INT_ARRAY_PARAM:
for (j=0; j < *(fieldsToParse[i].numOfValidArgs); j++)
{
char fieldName[DWPAL_FIELD_NAME_LENGTH];
size_t fieldNameLength = strnlen_s(fieldsToParse[i].stringToSearch, DWPAL_FIELD_NAME_LENGTH) - 1;
isValid = true;
/* Copy the entire name except of the last character (which is "=") */
strncpy_s(fieldName, sizeof(fieldName), fieldsToParse[i].stringToSearch, fieldNameLength);
fieldName[fieldNameLength] = '\0';
console_printf("%s; %s%s[%d]= %d\n", __FUNCTION__, indexToPrint, fieldName, j, ((int *)field)[j]);
}
break;
case DWPAL_INT_HEX_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s 0x%x\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((int *)field));
}
break;
case DWPAL_INT_HEX_ARRAY_PARAM:
for (j=0; j < *(fieldsToParse[i].numOfValidArgs); j++)
{
char fieldName[DWPAL_FIELD_NAME_LENGTH];
size_t fieldNameLength = strnlen_s(fieldsToParse[i].stringToSearch, DWPAL_FIELD_NAME_LENGTH) - 1;
isValid = true;
/* Copy the entire name except of the last character (which is "=") */
strncpy_s(fieldName, sizeof(fieldName), fieldsToParse[i].stringToSearch, fieldNameLength);
fieldName[fieldNameLength] = '\0';
console_printf("%s; %s%s[%d]= 0x%x\n", __FUNCTION__, indexToPrint, fieldName, j, ((int *)field)[j]);
}
break;
case DWPAL_BOOL_PARAM:
if (*(fieldsToParse[i].numOfValidArgs) > 0)
{
isValid = true;
console_printf("%s; %s%s %d\n", __FUNCTION__, indexToPrint, fieldsToParse[i].stringToSearch, *((bool *)field));
}
break;
default:
console_printf("%s; parsingType= %d; ERROR ==> Abort!\n", __FUNCTION__, fieldsToParse[i].parsingType);
break;
}
i++;
}
}
return true;
}
static DWPAL_Ret dwpal_req_beacon_handle(void *localContext, char *VAPName, char *fields[], bool isDwpalExtenderMode)
{
char *reply = (char *)malloc((size_t)(HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char)));
size_t replyLen = HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char) - 1;
DWPAL_req_beacon req_beacon;
DWPAL_Ret ret;
char cmd[DWPAL_TO_HOSTAPD_MSG_LENGTH];
size_t i, numOfValidArgs[1];
FieldsToParse fieldsToParse[] =
{
{ (void *)&req_beacon.dialog_token, &numOfValidArgs[0], DWPAL_INT_PARAM, "dialog_token=", 0 },
/* Must be at the end */
{ NULL, NULL, DWPAL_NUM_OF_PARSING_TYPES, NULL, 0 }
};
console_printf("%s; VAPName= '%s', isDwpalExtenderMode= %d\n", __FUNCTION__, VAPName, isDwpalExtenderMode);
if (reply == NULL)
{
console_printf("%s; malloc error ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
memset((void *)reply, '\0', HOSTAPD_TO_DWPAL_MSG_LENGTH); /* Clear the output buffer */
snprintf(cmd, DWPAL_TO_HOSTAPD_MSG_LENGTH, "REQ_BEACON");
for (i=0; i < 9; i++)
{
snprintf(cmd, DWPAL_TO_HOSTAPD_MSG_LENGTH, "%s %s", cmd, fields[i]);
}
console_printf("%s; cmd= '%s'\n", __FUNCTION__, cmd);
if (isDwpalExtenderMode)
{
ret = dwpal_ext_hostap_cmd_send(VAPName, cmd, NULL, reply, &replyLen);
}
else
{
ret = dwpal_hostap_cmd_send(localContext, cmd, NULL, reply, &replyLen);
}
if (ret == DWPAL_FAILURE)
{
console_printf("%s; REQ_BEACON command send error\n", __FUNCTION__);
}
else
{
console_printf("%s; replyLen= %d\nresponse=\n%s\n", __FUNCTION__, replyLen, reply);
if ((ret = dwpal_string_to_struct_parse(reply, replyLen, fieldsToParse)) == DWPAL_FAILURE)
{
console_printf("%s; dwpal_string_to_struct_parse ERROR ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
if (resultsPrint(fieldsToParse, 1, sizeof(DWPAL_radio_info_get)) == false)
{
console_printf("%s; resultsPrint ERROR ==> Abort!\n", __FUNCTION__);
}
/* Example for return value:
dialog_token=8
*/
}
free((void *)reply);
return DWPAL_SUCCESS;
}
static DWPAL_Ret dwpal_get_sta_measurements_handle(void *localContext, char *VAPName, char *MACAddress, bool isDwpalExtenderMode)
{
char *reply = (char *)malloc((size_t)(HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char)));
size_t replyLen = HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char) - 1;
DWPAL_get_sta_measurements get_sta_measurements;
DWPAL_Ret ret;
char cmd[DWPAL_TO_HOSTAPD_MSG_LENGTH];
size_t numOfValidArgs[1];
FieldsToParse fieldsToParse[] =
{
{ (void *)&get_sta_measurements.ShortTermRSSIAverage, &numOfValidArgs[0], DWPAL_STR_PARAM, "ShortTermRSSIAverage=", sizeof(get_sta_measurements.ShortTermRSSIAverage) },
/* Must be at the end */
{ NULL, NULL, DWPAL_NUM_OF_PARSING_TYPES, NULL, 0 }
};
console_printf("%s; VAPName= '%s', isDwpalExtenderMode= %d\n", __FUNCTION__, VAPName, isDwpalExtenderMode);
if (reply == NULL)
{
console_printf("%s; malloc error ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
memset((void *)reply, '\0', HOSTAPD_TO_DWPAL_MSG_LENGTH); /* Clear the output buffer */
snprintf(cmd, DWPAL_TO_HOSTAPD_MSG_LENGTH, "STA_MEASUREMENTS %s %s", VAPName, MACAddress);
if (isDwpalExtenderMode)
{
ret = dwpal_ext_hostap_cmd_send(VAPName, cmd, NULL, reply, &replyLen);
}
else
{
ret = dwpal_hostap_cmd_send(localContext, cmd, NULL, reply, &replyLen);
}
if (ret == DWPAL_FAILURE)
{
console_printf("%s; GET_STA_MEASUREMENTS command send error\n", __FUNCTION__);
}
else
{
console_printf("%s; replyLen= %d\nresponse=\n%s\n", __FUNCTION__, replyLen, reply);
if ((ret = dwpal_string_to_struct_parse(reply, replyLen, fieldsToParse)) == DWPAL_FAILURE)
{
console_printf("%s; dwpal_string_to_struct_parse ERROR ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
if (resultsPrint(fieldsToParse, 1, sizeof(DWPAL_radio_info_get)) == false)
{
console_printf("%s; resultsPrint ERROR ==> Abort!\n", __FUNCTION__);
}
/* Example for return value:
MACAddress=fc:c2:de:f3:e8:de
OperatingStandard=b g n ac
AuthenticationState=1
LastDataDownlinkRate=6500
LastDataUplinkRate=1000
SignalStrength=-85
ShortTermRSSIAverage=-88 -128 -85 -128
Retransmissions=0
Active=1
BytesSent=8448
BytesReceived=8409
PacketsSent=91
PacketsReceived=0
ErrorsSent=UNKNOWN
RetryCount=0
FailedRetransCount=0
RetryCount=UNKNOWN
MultipleRetryCount=UNKNOWN
*/
}
free((void *)reply);
return DWPAL_SUCCESS;
}
static DWPAL_Ret dwpal_get_vap_measurements_handle(void *localContext, char *VAPName, bool isDwpalExtenderMode)
{
char *reply = (char *)malloc((size_t)(HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char)));
size_t replyLen = HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char) - 1;
DWPAL_get_vap_measurements get_vap_measurements;
DWPAL_Ret ret;
char cmd[DWPAL_TO_HOSTAPD_MSG_LENGTH];
size_t numOfValidArgs[9];
FieldsToParse fieldsToParse[] =
{
{ (void *)&get_vap_measurements.BSSID, &numOfValidArgs[0], DWPAL_STR_PARAM, "BSSID=", sizeof(get_vap_measurements.BSSID) },
{ (void *)&get_vap_measurements.SSID, &numOfValidArgs[1], DWPAL_STR_PARAM, "SSID=", sizeof(get_vap_measurements.SSID) },
{ (void *)&get_vap_measurements.BytesSent, &numOfValidArgs[2], DWPAL_LONG_LONG_INT_PARAM, "BytesSent=", 0 },
{ (void *)&get_vap_measurements.BytesReceived, &numOfValidArgs[3], DWPAL_STR_PARAM, "BytesReceived=", sizeof(get_vap_measurements.BytesReceived) },
{ (void *)&get_vap_measurements.PacketsSent, &numOfValidArgs[4], DWPAL_STR_PARAM, "PacketsSent=", sizeof(get_vap_measurements.PacketsSent) },
{ (void *)&get_vap_measurements.PacketsReceived, &numOfValidArgs[5], DWPAL_STR_PARAM, "PacketsReceived=", sizeof(get_vap_measurements.PacketsReceived) },
{ (void *)&get_vap_measurements.ErrorsSent, &numOfValidArgs[6], DWPAL_INT_PARAM, "ErrorsSent=", 0 },
{ (void *)&get_vap_measurements.ErrorsReceived, &numOfValidArgs[7], DWPAL_INT_PARAM, "ErrorsReceived=", 0 },
{ (void *)&get_vap_measurements.RetransCount, &numOfValidArgs[8], DWPAL_INT_PARAM, "RetransCount=", 0 },
/* Must be at the end */
{ NULL, NULL, DWPAL_NUM_OF_PARSING_TYPES, NULL, 0 }
};
console_printf("%s; VAPName= '%s', isDwpalExtenderMode= %d\n", __FUNCTION__, VAPName, isDwpalExtenderMode);
if (reply == NULL)
{
console_printf("%s; malloc error ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
memset((void *)reply, '\0', HOSTAPD_TO_DWPAL_MSG_LENGTH); /* Clear the output buffer */
snprintf(cmd, DWPAL_TO_HOSTAPD_MSG_LENGTH, "GET_VAP_MEASUREMENTS %s", VAPName);
console_printf("%s; cmd= '%s'\n", __FUNCTION__, cmd);
if (isDwpalExtenderMode)
{
ret = dwpal_ext_hostap_cmd_send(VAPName, cmd, NULL, reply, &replyLen);
}
else
{
ret = dwpal_hostap_cmd_send(localContext, cmd, NULL, reply, &replyLen);
}
if (ret == DWPAL_FAILURE)
{
console_printf("%s; GET_VAP_MEASUREMENTS command send error\n", __FUNCTION__);
}
else
{
console_printf("%s; replyLen= %d\nresponse=\n%s\n", __FUNCTION__, replyLen, reply);
if ((ret = dwpal_string_to_struct_parse(reply, replyLen, fieldsToParse)) == DWPAL_FAILURE)
{
console_printf("%s; dwpal_string_to_struct_parse ERROR ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
if (resultsPrint(fieldsToParse, 1, sizeof(DWPAL_radio_info_get)) == false)
{
console_printf("%s; resultsPrint ERROR ==> Abort!\n", __FUNCTION__);
}
/* Example for return value:
Name=wlan0
Enable=1
BSSID=00:0a:1b:0e:04:60
SSID=test_2.4
BytesSent=389633
BytesReceived=416427
PacketsSent=1268
PacketsReceived=1531
ErrorsSent=14
RetransCount=2
FailedRetransCount=0
RetryCount=0
MultipleRetryCount=0
ACKFailureCount=328867
AggregatedPacketCount=2321066
ErrorsReceived=19831
UnicastPacketsSent=1006
UnicastPacketsReceived=1433
DiscardPacketsSent=14
DiscardPacketsReceived=0
MulticastPacketsSent=0
MulticastPacketsReceived=98
BroadcastPacketsSent=262
BroadcastPacketsReceived=0
UnknownProtoPacketsReceived=0
*/
}
free((void *)reply);
return DWPAL_SUCCESS;
}
static DWPAL_Ret dwpal_get_restricted_channels_handle(void *localContext, char *VAPName, bool isDwpalExtenderMode)
{
char *reply = (char *)malloc((size_t)(HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char)));
size_t replyLen = HOSTAPD_TO_DWPAL_MSG_LENGTH * sizeof(char) - 1;
DWPAL_Ret ret;
console_printf("%s; VAPName= '%s', isDwpalExtenderMode= %d\n", __FUNCTION__, VAPName, isDwpalExtenderMode);
if (reply == NULL)
{
console_printf("%s; malloc error ==> Abort!\n", __FUNCTION__);
return DWPAL_FAILURE;
}
memset((void *)reply, '\0', HOSTAPD_TO_DWPAL_MSG_LENGTH); /* Clear the output buffer */
if (isDwpalExtenderMode)
{
ret = dwpal_ext_hostap_cmd_send(VAPName, "GET_RESTRICTED_CHANNELS", NULL, reply, &replyLen);
}
else
{
ret = dwpal_hostap_cmd_send(localContext, "GET_RESTRICTED_CHANNELS", NULL, reply, &replyLen);
}
if (ret == DWPAL_FAILURE)
{
console_printf("%s; GET_RESTRICTED_CHANNELS command send error\n", __FUNCTION__);
}
else
{
console_printf("%s; replyLen= %d\nresponse=\n%s\n", __FUNCTION__, replyLen, reply);
/* Note: "reply" itself is already in the needed parsed format! */
/* Example for return value: