-
Notifications
You must be signed in to change notification settings - Fork 1
/
wifi_logger.cpp
executable file
·1444 lines (1254 loc) · 53.9 KB
/
wifi_logger.cpp
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
#include <stdint.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <linux/rtnetlink.h>
#include <netpacket/packet.h>
#include <linux/filter.h>
#include <linux/errqueue.h>
#include <linux/pkt_sched.h>
#include <netlink/object-api.h>
#include <netlink/netlink.h>
#include <netlink/socket.h>
#include <netlink/object-api.h>
#include <netlink/types.h>
#include "nl80211_copy.h"
#include "sync.h"
#define LOG_TAG "WifiHAL"
#include <utils/Log.h>
#include <hardware_legacy/wifi_hal.h>
#include "common.h"
#include "cpp_bindings.h"
/* using namespace android; */
typedef enum {
ENHANCE_LOGGER_START_LOGGING = ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START,
ENHANCE_LOGGER_TRIGGER_FW_MEM_DUMP,
ENHANCE_LOGGER_GET_FW_MEM_DUMP,
ENHANCE_LOGGER_GET_VER,
ENHANCE_LOGGER_GET_RING_STATUS,
ENHANCE_LOGGER_GET_RING_DATA,
ENHANCE_LOGGER_GET_FEATURE,
ENHANCE_LOGGER_RESET_LOGGING,
ENHANCE_LOGGER_TRIGGER_DRIVER_MEM_DUMP,
ENHANCE_LOGGER_GET_DRIVER_MEM_DUMP,
ENHANCE_LOGGER_START_PKT_FATE_MONITORING,
ENHANCE_LOGGER_GET_TX_PKT_FATES,
ENHANCE_LOGGER_GET_RX_PKT_FATES,
ENHANCE_LOGGER_GET_WAKE_REASON_STATS,
} DEBUG_SUB_COMMAND;
typedef enum {
ENHANCE_LOGGER_ATTRIBUTE_DRIVER_VER,
ENHANCE_LOGGER_ATTRIBUTE_FW_VER,
ENHANCE_LOGGER_ATTRIBUTE_RING_ID,
ENHANCE_LOGGER_ATTRIBUTE_RING_NAME,
ENHANCE_LOGGER_ATTRIBUTE_RING_FLAGS,
ENHANCE_LOGGER_ATTRIBUTE_LOG_LEVEL,
ENHANCE_LOGGER_ATTRIBUTE_LOG_TIME_INTVAL,
ENHANCE_LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE,
ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN,
ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA,
// LOGGER_ATTRIBUTE_FW_ERR_CODE,
ENHANCE_LOGGER_ATTRIBUTE_RING_DATA,
ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS,
ENHANCE_LOGGER_ATTRIBUTE_RING_NUM,
ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_LEN,
ENHANCE_LOGGER_ATTRIBUTE_DRIVER_DUMP_DATA,
ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM,
ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA,
//Attributes for data used by wake stats subcmd.
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_INVALID = 0,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_CMD_EVENT_WAKE,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_PTR,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_CMD_EVENT_WAKE_CNT_SZ,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_DRIVER_FW_LOCAL_WAKE,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_PTR,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_DRIVER_FW_LOCAL_WAKE_CNT_SZ,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_TOTAL_RX_DATA_WAKE,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_UNICAST_CNT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_MULTICAST_CNT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_RX_BROADCAST_CNT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP_PKT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_PKT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RA,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NA,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_NS,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP4_RX_MULTICAST_CNT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_ICMP6_RX_MULTICAST_CNT,
ENHANCE_LOGGER_ATTRIBUTE_WAKE_STATS_OTHER_RX_MULTICAST_CNT,
} ENHANCE_LOGGER_ATTRIBUTE;
typedef enum {
DEBUG_OFF = 0,
DEBUG_NORMAL,
DEBUG_VERBOSE,
DEBUG_VERY,
DEBUG_VERY_VERY,
} ENHANCE_LOGGER_LEVEL;
typedef enum {
GET_FW_VER,
GET_DRV_VER,
GET_RING_DATA,
GET_RING_STATUS,
GET_FEATURE,
START_RING_LOG,
GET_FW_DUMP,
GET_DRIVER_DUMP,
} GetCmdType;
typedef enum {
PACKET_MONITOR_START,
TX_PACKET_FATE,
RX_PACKET_FATE,
} PktFateReqType;
class DebugCommand : public WifiCommand
{
char *mBuff = NULL;
int *mBuffSize = NULL;
u32 *mNumRings = NULL;
wifi_ring_buffer_status *mStatus = NULL;
unsigned int *mSupport = NULL;
u32 mVerboseLevel = 0;
u32 mFlags = 0;
u32 mMaxIntervalSec = 0;
u32 mMinDataSize = 0;
char *mRingName = NULL;
GetCmdType mType;
public:
// constructor for get version
DebugCommand(wifi_interface_handle iface, char *buffer, int *buffer_size,
GetCmdType cmdType)
: WifiCommand(iface, 0), mBuff(buffer), mBuffSize(buffer_size), mType
(cmdType)
{
memset(mBuff, 0, *mBuffSize);
}
// constructor for ring data
DebugCommand(wifi_interface_handle iface, char *ring_name, GetCmdType cmdType)
: WifiCommand(iface, 0), mRingName(ring_name), mType(cmdType)
{ }
// constructor for ring status
DebugCommand(wifi_interface_handle iface, u32 *num_rings,
wifi_ring_buffer_status *status, GetCmdType cmdType)
: WifiCommand(iface, 0), mNumRings(num_rings), mStatus(status), mType(cmdType)
{
memset(mStatus, 0, sizeof(wifi_ring_buffer_status) * (*mNumRings));
}
// constructor for feature set
DebugCommand(wifi_interface_handle iface, unsigned int *support, GetCmdType cmdType)
: WifiCommand(iface, 0), mSupport(support), mType(cmdType)
{ }
// constructor for ring params
DebugCommand(wifi_interface_handle iface, u32 verbose_level, u32 flags,
u32 max_interval_sec, u32 min_data_size, char *ring_name, GetCmdType cmdType)
: WifiCommand(iface, 0), mVerboseLevel(verbose_level), mFlags(flags),
mMaxIntervalSec(max_interval_sec), mMinDataSize(min_data_size),
mRingName(ring_name), mType(cmdType)
{ }
int createRingRequest(WifiRequest& request) {
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_START_LOGGING);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create start ring logger request; result = %d", result);
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_LEVEL, mVerboseLevel);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put log level; result = %d", result);
return result;
}
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_RING_FLAGS, mFlags);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put ring flags; result = %d", result);
return result;
}
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_TIME_INTVAL, mMaxIntervalSec);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put log time interval; result = %d", result);
return result;
}
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE, mMinDataSize);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put min data size; result = %d", result);
return result;
}
result = request.put_string(ENHANCE_LOGGER_ATTRIBUTE_RING_NAME, mRingName);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put ringbuffer name; result = %d", result);
return result;
}
request.attr_end(data);
return WIFI_SUCCESS;
}
int createRequest(WifiRequest &request) {
int result;
switch (mType) {
case GET_FW_VER:
{
result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_VER);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get fw version request; result = %d", result);
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
// Driver expecting only attribute type, passing mbuff as data with
// length 0 to avoid undefined state
result = request.put(ENHANCE_LOGGER_ATTRIBUTE_FW_VER, mBuff, 0);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put get fw version request; result = %d", result);
return result;
}
request.attr_end(data);
break;
}
case GET_DRV_VER:
{
result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_VER);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get drv version request; result = %d", result);
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
// Driver expecting only attribute type, passing mbuff as data with
// length 0 to avoid undefined state
result = request.put(ENHANCE_LOGGER_ATTRIBUTE_DRIVER_VER, mBuff, 0);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put get drv version request; result = %d", result);
return result;
}
request.attr_end(data);
break;
}
case GET_RING_DATA:
{
result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RING_DATA);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get ring data request; result = %d", result);
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_string(ENHANCE_LOGGER_ATTRIBUTE_RING_NAME, mRingName);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put ring data request; result = %d", result);
return result;
}
request.attr_end(data);
break;
}
case GET_RING_STATUS:
{
result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RING_STATUS);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get ring status request; result = %d", result);
return result;
}
break;
}
case GET_FEATURE:
{
result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_FEATURE);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get feature request; result = %d", result);
return result;
}
break;
}
case START_RING_LOG:
result = createRingRequest(request);
break;
default:
ALOGE("Unknown Debug command");
result = WIFI_ERROR_UNKNOWN;
}
return result;
}
int start() {
// ALOGD("Start debug command");
WifiRequest request(familyId(), ifaceId());
int result = createRequest(request);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create debug request; result = %d", result);
return result;
}
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to register debug response; result = %d", result);
}
return result;
}
virtual int handleResponse(WifiEvent& reply) {
ALOGD("In DebugCommand::handleResponse");
if (reply.get_cmd() != NL80211_CMD_VENDOR) {
ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());
return NL_SKIP;
}
switch (mType) {
case GET_DRV_VER:
case GET_FW_VER:
{
void *data = reply.get_vendor_data();
int len = reply.get_vendor_data_len();
ALOGD("len = %d, expected len = %d", len, *mBuffSize);
memcpy(mBuff, data, min(len, *mBuffSize));
if (*mBuffSize < len)
return NL_SKIP;
*mBuffSize = len;
break;
}
case START_RING_LOG:
case GET_RING_DATA:
break;
case GET_RING_STATUS:
{
nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = reply.get_vendor_data_len();
wifi_ring_buffer_status *status(mStatus);
if (vendor_data == NULL || len == 0) {
ALOGE("No Debug data found");
return NL_SKIP;
}
nl_iterator it(vendor_data);
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_NUM) {
unsigned int num_rings = it.get_u32();
if (*mNumRings < num_rings) {
ALOGE("Not enough status buffers provided, available: %d required: %d",
*mNumRings, num_rings);
} else {
*mNumRings = num_rings;
}
} else {
ALOGE("Unknown attribute: %d expecting %d",
it.get_type(), ENHANCE_LOGGER_ATTRIBUTE_RING_NUM);
return NL_SKIP;
}
it.next();
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS) {
memcpy(status, it.get_data(), sizeof(wifi_ring_buffer_status) * (*mNumRings));
} else {
ALOGW("Ignoring invalid attribute type = %d, size = %d",
it.get_type(), it.get_len());
}
break;
}
case GET_FEATURE:
{
void *data = reply.get_vendor_data();
ALOGD("len = %d, expected len = %lu", reply.get_vendor_data_len(), (unsigned long)sizeof(unsigned int));
memcpy(mSupport, data, sizeof(unsigned int));
break;
}
default:
ALOGW("Unknown Debug command");
}
return NL_OK;
}
virtual int handleEvent(WifiEvent& event) {
/* NO events! */
return NL_SKIP;
}
};
/* API to get supportable feature */
wifi_error wifi_get_logger_supported_feature_set(wifi_interface_handle iface,
unsigned int *support)
{
if (support) {
DebugCommand *cmd = new DebugCommand(iface, support, GET_FEATURE);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
} else {
ALOGE("Get support buffer NULL");
return WIFI_ERROR_INVALID_ARGS;
}
}
/* API to get the status of all ring buffers supported by driver */
wifi_error wifi_get_ring_buffers_status(wifi_interface_handle iface,
u32 *num_rings, wifi_ring_buffer_status *status)
{
if (status && num_rings) {
DebugCommand *cmd = new DebugCommand(iface, num_rings, status, GET_RING_STATUS);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
} else {
ALOGE("Ring status buffer NULL");
return WIFI_ERROR_INVALID_ARGS;
}
}
/* API to collect driver records */
wifi_error wifi_get_ring_data(wifi_interface_handle iface, char *ring_name)
{
DebugCommand *cmd = new DebugCommand(iface, ring_name, GET_RING_DATA);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
}
wifi_error wifi_start_logging(wifi_interface_handle iface, u32 verbose_level,
u32 flags, u32 max_interval_sec, u32 min_data_size, char *ring_name)
{
if (ring_name) {
DebugCommand *cmd = new DebugCommand(iface, verbose_level, flags, max_interval_sec,
min_data_size, ring_name, START_RING_LOG);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
} else {
ALOGE("Ring name NULL");
return WIFI_ERROR_INVALID_ARGS;
}
}
/* API to collect a firmware version string */
wifi_error wifi_get_firmware_version(wifi_interface_handle iface, char *buffer,
int buffer_size)
{
if (buffer && (buffer_size > 0)) {
DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_FW_VER);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
} else {
ALOGE("FW version buffer NULL");
return WIFI_ERROR_INVALID_ARGS;
}
}
/* API to collect a driver version string */
wifi_error wifi_get_driver_version(wifi_interface_handle iface, char *buffer, int buffer_size)
{
if (buffer && (buffer_size > 0)) {
DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_DRV_VER);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
} else {
ALOGE("Driver version buffer NULL");
return WIFI_ERROR_INVALID_ARGS;
}
}
///////////////////////////////////////////////////////////////////////////////
class SetLogHandler : public WifiCommand
{
wifi_ring_buffer_data_handler mHandler;
public:
SetLogHandler(wifi_interface_handle iface, int id, wifi_ring_buffer_data_handler handler)
: WifiCommand(iface, id), mHandler(handler)
{ }
int start() {
ALOGV("Register loghandler");
registerVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_RING_EVENT);
return WIFI_SUCCESS;
}
virtual int cancel() {
/* Send a command to driver to stop generating logging events */
ALOGV("Clear loghandler");
/* unregister event handler */
unregisterVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_RING_EVENT);
WifiRequest request(familyId(), ifaceId());
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_RESET_LOGGING);
if (result != WIFI_SUCCESS) {
ALOGE("failed to create reset request; result = %d", result);
return result;
}
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("failed to request reset; result = %d", result);
return result;
}
ALOGD("Success to clear loghandler");
return WIFI_SUCCESS;
}
virtual int handleEvent(WifiEvent& event) {
char *buffer = NULL;
int buffer_size = 0;
// ALOGD("In SetLogHandler::handleEvent");
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = event.get_vendor_data_len();
int event_id = event.get_vendor_subcmd();
// ALOGI("Got Logger event: %d", event_id);
if (vendor_data == NULL || len == 0) {
ALOGE("No Debug data found");
return NL_SKIP;
}
if(event_id == ENHANCE_LOGGER_RING_EVENT) {
wifi_ring_buffer_status status;
memset(&status, 0, sizeof(status));
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_STATUS) {
memcpy(&status, it.get_data(), sizeof(status));
} else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_DATA) {
buffer_size = it.get_len();
buffer = (char *)it.get_data();
} else {
ALOGW("Ignoring invalid attribute type = %d, size = %d",
it.get_type(), it.get_len());
}
}
// ALOGI("Retrieved Debug data");
if (mHandler.on_ring_buffer_data) {
(*mHandler.on_ring_buffer_data)((char *)status.name, buffer, buffer_size,
&status);
}
} else {
ALOGE("Unknown Event");
return NL_SKIP;
}
return NL_OK;
}
};
wifi_error wifi_set_log_handler(wifi_request_id id, wifi_interface_handle iface,
wifi_ring_buffer_data_handler handler)
{
wifi_handle handle = getWifiHandle(iface);
ALOGV("Loghandler start, handle = %p", handle);
SetLogHandler *cmd = new SetLogHandler(iface, id, handler);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = wifi_register_cmd(handle, id, cmd);
if (result != WIFI_SUCCESS) {
cmd->releaseRef();
return result;
}
result = (wifi_error)cmd->start();
if (result != WIFI_SUCCESS) {
wifi_unregister_cmd(handle, id);
cmd->releaseRef();
return result;
}
return result;
}
wifi_error wifi_reset_log_handler(wifi_request_id id, wifi_interface_handle iface)
{
wifi_handle handle = getWifiHandle(iface);
ALOGV("Loghandler reset, wifi_request_id = %d, handle = %p", id, handle);
if (id == -1) {
wifi_ring_buffer_data_handler handler;
memset(&handler, 0, sizeof(handler));
SetLogHandler *cmd = new SetLogHandler(iface, id, handler);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
cmd->cancel();
cmd->releaseRef();
return WIFI_SUCCESS;
}
return wifi_cancel_cmd(id, iface);
}
///////////////////////////////////////////////////////////////////////////////
class SetAlertHandler : public WifiCommand
{
wifi_alert_handler mHandler;
int mBuffSize;
char *mBuff;
int mErrCode;
public:
SetAlertHandler(wifi_interface_handle iface, int id, wifi_alert_handler handler)
: WifiCommand(iface, id), mHandler(handler), mBuffSize(0), mBuff(NULL),
mErrCode(0)
{ }
int start() {
ALOGV("Start Alerting");
registerVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);
return WIFI_SUCCESS;
}
virtual int cancel() {
ALOGV("Clear alerthandler");
/* unregister alert handler */
unregisterVendorHandler(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);
wifi_unregister_cmd(wifiHandle(), id());
ALOGD("Success to clear alerthandler");
return WIFI_SUCCESS;
}
virtual int handleResponse(WifiEvent& reply) {
ALOGD("In SetAlertHandler::handleResponse");
if (reply.get_cmd() != NL80211_CMD_VENDOR) {
ALOGD("Ignoring reply with cmd = %d", reply.get_cmd());
return NL_SKIP;
}
nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = reply.get_vendor_data_len();
ALOGD("len = %d", len);
if (vendor_data == NULL || len == 0) {
ALOGE("no vendor data in memory dump response; ignoring it");
return NL_SKIP;
}
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA) {
ALOGI("Initiating alert callback");
if (mHandler.on_alert) {
(*mHandler.on_alert)(id(), mBuff, mBuffSize, mErrCode);
}
if (mBuff) {
free(mBuff);
mBuff = NULL;
}
}
}
return NL_OK;
}
virtual int handleEvent(WifiEvent& event) {
char *buffer = NULL;
int buffer_size = 0;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = event.get_vendor_data_len();
int event_id = event.get_vendor_subcmd();
ALOGI("Got event: %d", event_id);
if (vendor_data == NULL || len == 0) {
ALOGE("No Debug data found");
return NL_SKIP;
}
if (event_id == ENHANCE_LOGGER_MEM_DUMP_EVENT) {
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN) {
mBuffSize = it.get_u32();
} else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_RING_DATA) {
buffer_size = it.get_len();
buffer = (char *)it.get_data();
/*
} else if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_FW_ERR_CODE) {
mErrCode = it.get_u32();
*/
} else {
ALOGW("Ignoring invalid attribute type = %d, size = %d",
it.get_type(), it.get_len());
}
}
if (mBuffSize) {
ALOGD("dump size: %d meta data size: %d", mBuffSize, buffer_size);
if (mBuff) free(mBuff);
mBuff = (char *)malloc(mBuffSize + buffer_size);
if (!mBuff) {
ALOGE("Buffer allocation failed");
return NL_SKIP;
}
memcpy(mBuff, buffer, buffer_size);
WifiRequest request(familyId(), ifaceId());
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_MEM_DUMP_EVENT);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to create get memory dump request; result = %d", result);
free(mBuff);
return NL_SKIP;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_LEN, mBuffSize);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put get memory dump request; result = %d", result);
return result;
}
result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_FW_DUMP_DATA,
(uint64_t)(mBuff+buffer_size));
if (result != WIFI_SUCCESS) {
ALOGE("Failed to put get memory dump request; result = %d", result);
return result;
}
request.attr_end(data);
mBuffSize += buffer_size;
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to register get momory dump response; result = %d", result);
}
} else {
ALOGE("dump event missing dump length attribute");
return NL_SKIP;
}
}
return NL_OK;
}
};
wifi_error wifi_set_alert_handler(wifi_request_id id, wifi_interface_handle iface,
wifi_alert_handler handler)
{
wifi_handle handle = getWifiHandle(iface);
ALOGV("Alerthandler start, handle = %p", handle);
SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = wifi_register_cmd(handle, id, cmd);
if (result != WIFI_SUCCESS) {
cmd->releaseRef();
return result;
}
result = (wifi_error)cmd->start();
if (result != WIFI_SUCCESS) {
wifi_unregister_cmd(handle, id);
cmd->releaseRef();
return result;
}
return result;
}
wifi_error wifi_reset_alert_handler(wifi_request_id id, wifi_interface_handle iface)
{
wifi_handle handle = getWifiHandle(iface);
ALOGV("Alerthandler reset, wifi_request_id = %d, handle = %p", id, handle);
if (id == -1) {
wifi_alert_handler handler;
memset(&handler, 0, sizeof(handler));
SetAlertHandler *cmd = new SetAlertHandler(iface, id, handler);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
cmd->cancel();
cmd->releaseRef();
return WIFI_SUCCESS;
}
return wifi_cancel_cmd(id, iface);
}
class PacketFateCommand: public WifiCommand
{
void *mReportBufs = NULL;
size_t mNoReqFates = 0;
size_t *mNoProvidedFates = NULL;
PktFateReqType mReqType;
public:
PacketFateCommand(wifi_interface_handle handle)
: WifiCommand(handle, 0), mReqType(PACKET_MONITOR_START)
{ }
PacketFateCommand(wifi_interface_handle handle, wifi_tx_report *tx_report_bufs,
size_t n_requested_fates, size_t *n_provided_fates)
: WifiCommand(handle, 0), mReportBufs(tx_report_bufs),
mNoReqFates(n_requested_fates), mNoProvidedFates(n_provided_fates),
mReqType(TX_PACKET_FATE)
{ }
PacketFateCommand(wifi_interface_handle handle, wifi_rx_report *rx_report_bufs,
size_t n_requested_fates, size_t *n_provided_fates)
: WifiCommand(handle, 0), mReportBufs(rx_report_bufs),
mNoReqFates(n_requested_fates), mNoProvidedFates(n_provided_fates),
mReqType(RX_PACKET_FATE)
{ }
int createRequest(WifiRequest& request) {
if (mReqType == TX_PACKET_FATE) {
ALOGD("%s Get Tx packet fate request\n", __FUNCTION__);
return createTxPktFateRequest(request);
} else if (mReqType == RX_PACKET_FATE) {
ALOGD("%s Get Rx packet fate request\n", __FUNCTION__);
return createRxPktFateRequest(request);
} else if (mReqType == PACKET_MONITOR_START) {
ALOGD("%s Monitor packet fate request\n", __FUNCTION__);
return createMonitorPktFateRequest(request);
} else {
ALOGE("%s Unknown packet fate request\n", __FUNCTION__);
return WIFI_ERROR_NOT_SUPPORTED;
}
return WIFI_SUCCESS;
}
int createMonitorPktFateRequest(WifiRequest& request) {
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_START_PKT_FATE_MONITORING);
if (result < 0) {
return result;
}
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
request.attr_end(data);
return result;
}
int createTxPktFateRequest(WifiRequest& request) {
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_TX_PKT_FATES);
if (result < 0) {
return result;
}
memset(mReportBufs, 0, (mNoReqFates * sizeof(wifi_tx_report)));
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM, mNoReqFates);
if (result < 0) {
return result;
}
result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA, (uint64_t)mReportBufs);
if (result < 0) {
return result;
}
request.attr_end(data);
return result;
}
int createRxPktFateRequest(WifiRequest& request) {
int result = request.create(GOOGLE_OUI, ENHANCE_LOGGER_GET_RX_PKT_FATES);
if (result < 0) {
return result;
}
memset(mReportBufs, 0, (mNoReqFates * sizeof(wifi_rx_report)));
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
result = request.put_u32(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM, mNoReqFates);
if (result < 0) {
return result;
}
result = request.put_u64(ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_DATA, (uint64_t)mReportBufs);
if (result < 0) {
return result;
}
request.attr_end(data);
return result;
}
int start() {
ALOGD("Start get packet fate command\n");
WifiRequest request(familyId(), ifaceId());
int result = createRequest(request);
if (result < 0) {
ALOGE("Failed to create get pkt fate request; result = %d\n", result);
return result;
}
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("Failed to register get pkt fate response; result = %d\n", result);
}
return result;
}
int handleResponse(WifiEvent& reply) {
ALOGD("In GetPktFateCommand::handleResponse\n");
if (reply.get_cmd() != NL80211_CMD_VENDOR) {
ALOGI("Ignoring reply with cmd = %d", reply.get_cmd());
return NL_SKIP;
}
int id = reply.get_vendor_id();
int subcmd = reply.get_vendor_subcmd();
nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);
int len = reply.get_vendor_data_len();
ALOGI("Id = %0x, subcmd = %d, len = %d", id, subcmd, len);
if (mReqType == TX_PACKET_FATE) {
ALOGI("Response recieved for get TX pkt fate command\n");
} else if (mReqType == RX_PACKET_FATE) {
ALOGI("Response recieved for get RX pkt fate command\n");
} else if (mReqType == PACKET_MONITOR_START) {
ALOGI("Response recieved for monitor pkt fate command\n");
return NL_OK;
} else {
ALOGE("Response recieved for unknown pkt fate command\n");
return NL_SKIP;
}
if (vendor_data == NULL || len == 0) {
ALOGE("no vendor data in GetPktFateCommand response; ignoring it\n");
return NL_SKIP;
}
for (nl_iterator it(vendor_data); it.has_next(); it.next()) {
if (it.get_type() == ENHANCE_LOGGER_ATTRIBUTE_PKT_FATE_NUM) {
*mNoProvidedFates = it.get_u32();
ALOGI("No: of pkt fates provided is %zu\n", *mNoProvidedFates);
} else {
ALOGE("Ignoring invalid attribute type = %d, size = %d\n",
it.get_type(), it.get_len());
}
}
return NL_OK;
}
int handleEvent(WifiEvent& event) {
/* NO events to handle here! */
return NL_SKIP;
}
};
wifi_error wifi_start_pkt_fate_monitoring(wifi_interface_handle handle)
{
PacketFateCommand *cmd = new PacketFateCommand(handle);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
return result;
}
wifi_error wifi_get_tx_pkt_fates(wifi_interface_handle handle,
wifi_tx_report *tx_report_bufs, size_t n_requested_fates,
size_t *n_provided_fates)
{
PacketFateCommand *cmd = new PacketFateCommand(handle, tx_report_bufs,
n_requested_fates, n_provided_fates);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
memset(tx_report_bufs, 0, (n_requested_fates * sizeof(wifi_tx_report)));
return result;
}
wifi_error wifi_get_rx_pkt_fates(wifi_interface_handle handle,
wifi_rx_report *rx_report_bufs, size_t n_requested_fates,
size_t *n_provided_fates)
{
PacketFateCommand *cmd = new PacketFateCommand(handle, rx_report_bufs,
n_requested_fates, n_provided_fates);
NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY);
wifi_error result = (wifi_error)cmd->start();
cmd->releaseRef();
memset(rx_report_bufs, 0, (n_requested_fates * sizeof(wifi_rx_report)));
return result;
}
class MemoryDumpCommand: public WifiCommand
{
wifi_firmware_memory_dump_handler mHandler;
wifi_driver_memory_dump_callbacks mcallback;
int mBuffSize;