-
Notifications
You must be signed in to change notification settings - Fork 2
/
wifi_nan.cpp
executable file
·1590 lines (1324 loc) · 75.1 KB
/
wifi_nan.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 <stddef.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/handlers.h>
#include "sync.h"
#include <utils/Log.h>
#include "wifi_hal.h"
#include "common.h"
#include "cpp_bindings.h"
#include "nan_data.h"
#include "nan_common.h"
#define SLSI_WIFI_HAL_NAN_VERSION 1
class NanCommand : public WifiCommand {
static NanCallbackHandler callbackEventHandler;
int subscribeID[2];
int publishID[2];
int followupID[2];
int version;
NanCapabilities capabilities;
NanDataCommand datacmd;
void registerNanEvents(void) {
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_PUBLISH_TERMINATED);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH_EXPIRED);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_FOLLOWUP);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_DISCOVERY_ENGINE);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_REQ);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_CFM);
registerVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_END);
}
void unregisterNanEvents(void) {
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_PUBLISH_TERMINATED);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_MATCH_EXPIRED);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_FOLLOWUP);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_DISCOVERY_ENGINE);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_REQ);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_CFM);
unregisterVendorHandler(GOOGLE_OUI, SLSI_NAN_EVENT_NDP_END);
}
static const u8 *getEventName(int event) {
switch(event) {
case SLSI_NAN_EVENT_RESPONSE:
return (const u8 *)"SLSI_NAN_EVENT_RESPONSE";
case SLSI_NAN_EVENT_PUBLISH_TERMINATED:
return (const u8 *)"SLSI_NAN_EVENT_PUBLISH_TERMINATED";
case SLSI_NAN_EVENT_MATCH:
return (const u8 *)"SLSI_NAN_EVENT_MATCH";
case SLSI_NAN_EVENT_MATCH_EXPIRED:
return (const u8 *)"SLSI_NAN_EVENT_MATCH_EXPIRED";
case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED:
return (const u8 *)"SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED";
case SLSI_NAN_EVENT_FOLLOWUP:
return (const u8 *)"SLSI_NAN_EVENT_FOLLOWUP";
case SLSI_NAN_EVENT_DISCOVERY_ENGINE:
return (const u8 *)"SLSI_NAN_EVENT_DISCOVERY_ENGINE";
case SLSI_NAN_EVENT_DISABLED:
return (const u8 *)"SLSI_NAN_EVENT_DISABLED";
case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS:
return (const u8 *)"SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS";
case SLSI_NAN_EVENT_NDP_REQ:
return (const u8 *)"SLSI_NAN_EVENT_NDP_REQ";
case SLSI_NAN_EVENT_NDP_CFM:
return (const u8 *)"SLSI_NAN_EVENT_NDP_CFM";
case SLSI_NAN_EVENT_NDP_END:
return (const u8 *)"SLSI_NAN_EVENT_NDP_END";
default:
return (const u8 *)"UNKNOWN event";
}
return (const u8 *)"UNKNOWN event";
}
int processResponse(WifiEvent &reply, NanResponseMsg *response) {
NanCapabilities *capabilities = &response->body.nan_capabilities;
nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);
unsigned int val;
transaction_id id = 0;
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_REPLY_ATTR_STATUS_TYPE:
response->status = NanStatusType(nl_itr.get_u32());
break;
case NAN_REPLY_ATTR_VALUE:
val = nl_itr.get_u32();
if (val) {
strncpy(response->nan_error, "Lower_layer_error",NAN_ERROR_STR_LEN);
}
break;
case NAN_REPLY_ATTR_RESPONSE_TYPE:
response->response_type = NanResponseType(nl_itr.get_u32());
break;
case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE:
response->body.publish_response.publish_id = nl_itr.get_u16();
break;
case NAN_REPLY_ATTR_NDP_INSTANCE_ID:
response->body.data_request_response.ndp_instance_id = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER:
capabilities->max_concurrent_nan_clusters = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES:
capabilities->max_publishes = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES:
capabilities->max_subscribes = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN:
capabilities->max_service_name_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN:
capabilities->max_match_filter_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN:
capabilities->max_total_match_filter_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN:
capabilities->max_service_specific_info_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN:
capabilities->max_vsa_data_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN:
capabilities->max_mesh_data_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES:
capabilities->max_ndi_interfaces = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS:
capabilities->max_ndp_sessions = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN:
capabilities->max_app_info_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS:
capabilities->max_queued_transmit_followup_msgs = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS:
capabilities->ndp_supported_bands = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED:
capabilities->cipher_suites_supported = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN:
capabilities->max_scid_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED:
capabilities->is_ndp_security_supported = (bool)nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN:
capabilities->max_sdea_service_specific_info_len = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS:
capabilities->max_subscribe_address = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED:
capabilities->ndpe_attr_supported = nl_itr.get_u32();
break;
case NAN_REPLY_ATTR_HAL_TRANSACTION_ID:
id = nl_itr.get_u16();
break;
default :
ALOGE("received unknown type(%d) in response", nl_itr.get_type());
return -1;
}
}
this->capabilities = *capabilities;
return id;
}
int processMatchEvent(WifiEvent &event) {
NanMatchInd ind;
memset(&ind,0,sizeof(NanMatchInd));
int famchan_idx = 0, disc_idx = 0;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID:
ind.publish_subscribe_id = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID:
ind.requestor_instance_id = nl_itr.get_u32();
break;
case NAN_EVT_ATTR_MATCH_ADDR:
memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN);
break;
case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN:
ind.service_specific_info_len = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO:
memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len);
break;
case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN:
ind.sdf_match_filter_len = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER:
memcpy(ind.sdf_match_filter, nl_itr.get_data(), ind.sdf_match_filter_len);
break;
case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG:
ind.match_occured_flag = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG:
ind.out_of_resource_flag = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_RSSI_VALUE:
ind.rssi_value = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED:
ind.conn_capability.is_ibss_supported = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED:
ind.conn_capability.is_wfd_supported = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED:
ind.conn_capability.is_wfds_supported = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED:
ind.conn_capability.is_tdls_supported = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED:
ind.conn_capability.is_mesh_supported= nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD:
ind.conn_capability.wlan_infra_field = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR:
ind.num_rx_discovery_attr = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR:
NanReceivePostDiscovery *disc_attr;
disc_attr = &ind.discovery_attr[disc_idx];
disc_idx++;
for(nl_iterator nl_nested_itr((struct nlattr *)nl_itr.get_data()); nl_nested_itr.has_next(); nl_nested_itr.next()) {
switch(nl_nested_itr.get_type()) {
case NAN_EVT_ATTR_MATCH_DISC_ATTR_TYPE:
disc_attr->type = (NanConnectionType)nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE:
disc_attr->role = (NanDeviceRole)nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION:
disc_attr->duration = (NanAvailDuration)nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP:
disc_attr->avail_interval_bitmap = nl_nested_itr.get_u32();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID:
disc_attr->mapid = nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR:
memcpy(disc_attr->addr, nl_nested_itr.get_data(), NAN_MAC_ADDR_LEN);
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN:
disc_attr->mesh_id_len = nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID:
memcpy(disc_attr->mesh_id, nl_nested_itr.get_data(), disc_attr->mesh_id_len);
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN:
disc_attr->infrastructure_ssid_len = nl_nested_itr.get_u16();
break;
case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_VAL:
memcpy(disc_attr->infrastructure_ssid_val, nl_nested_itr.get_data(), disc_attr->infrastructure_ssid_len);
break;
}
}
break;
case NAN_EVT_ATTR_MATCH_NUM_CHANS:
ind.num_chans = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_FAMCHAN:
NanFurtherAvailabilityChannel *famchan;
famchan = &ind.famchan[famchan_idx];
famchan_idx++;
for(nl_iterator nl_nested_itr((struct nlattr *)nl_itr.get_data()); nl_nested_itr.has_next(); nl_nested_itr.next()) {
switch(nl_nested_itr.get_type()) {
case NAN_EVT_ATTR_MATCH_FAM_ENTRY_CONTROL:
famchan->entry_control = (NanAvailDuration)nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL:
famchan->class_val = nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_FAM_CHANNEL:
famchan->channel = nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_FAM_MAPID:
famchan->mapid = nl_nested_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP:
famchan->avail_interval_bitmap = nl_nested_itr.get_u32();
break;
}
}
break;
case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN:
ind.cluster_attribute_len = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE:
memcpy(ind.cluster_attribute, nl_itr.get_data(), ind.cluster_attribute_len);
break;
case NAN_EVT_ATTR_SDEA_LEN:
ind.sdea_service_specific_info_len = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_SDEA:
memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len);
break;
case NAN_EVT_ATTR_SCID_LEN:
ind.scid_len = nl_itr.get_u32();
break;
case NAN_EVT_ATTR_SCID:
memcpy(ind.scid, nl_itr.get_data(), ind.scid_len);
break;
case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH:
ind.peer_sdea_params.config_nan_data_path = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE:
ind.peer_sdea_params.ndp_type = (NdpType)nl_itr.get_u8();
break;
case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG:
ind.peer_sdea_params.security_cfg = (NanDataPathSecurityCfgStatus)nl_itr.get_u8();
break;
case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE:
ind.peer_sdea_params.ranging_state = (NanRangingState)nl_itr.get_u8();
break;
case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT:
ind.peer_sdea_params.range_report = (NanRangeReport)nl_itr.get_u8();
break;
case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG:
ind.peer_sdea_params.qos_cfg = (NanQosCfgStatus)nl_itr.get_u8();
break;
case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM:
ind.range_info.range_measurement_mm = nl_itr.get_u32();
break;
case NAN_EVT_ATTR_RANGEING_EVENT_TYPE:
ind.range_info.ranging_event_type = nl_itr.get_u32();
break;
}
}
if (this->callbackEventHandler.EventMatch)
this->callbackEventHandler.EventMatch(&ind);
return NL_OK;
}
int processMatchExpiredEvent(WifiEvent &event) {
NanMatchExpiredInd ind;
memset(&ind,0,sizeof(NanMatchExpiredInd));
for(nl_iterator nl_itr((struct nlattr *)event.get_vendor_data()); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID:
ind.publish_subscribe_id = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID:
ind.requestor_instance_id = nl_itr.get_u32();
break;
default :
ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventMatchExpired)
callbackEventHandler.EventMatchExpired(&ind);
return NL_OK;
}
int processPublishTerminatedEvent(WifiEvent &event) {
NanPublishTerminatedInd ind;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
memset(&ind,0,sizeof(ind));
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_PUBLISH_ID:
ind.publish_id = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_PUBLISH_REASON:
ind.reason = (NanStatusType)nl_itr.get_u32();
break;
case NAN_EVT_ATTR_STATUS:
break;
default :
ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventPublishTerminated)
callbackEventHandler.EventPublishTerminated(&ind);
return NL_OK;
}
int processSubscribeTerminatedEvent(WifiEvent &event) {
NanSubscribeTerminatedInd ind;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
memset(&ind,0,sizeof(ind));
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_SUBSCRIBE_ID:
ind.subscribe_id = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_SUBSCRIBE_REASON:
ind.reason = (NanStatusType)nl_itr.get_u32();
break;
case NAN_EVT_ATTR_STATUS:
break;
default :
ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventSubscribeTerminated)
callbackEventHandler.EventSubscribeTerminated(&ind);
return NL_OK;
}
int processFollowupEvent(WifiEvent &event) {
NanFollowupInd ind;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
memset(&ind,0,sizeof(ind));
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID:
ind.publish_subscribe_id = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID:
ind.requestor_instance_id = nl_itr.get_u32();
break;
case NAN_EVT_ATTR_FOLLOWUP_ADDR:
memcpy(ind.addr, nl_itr.get_data(), NAN_MAC_ADDR_LEN);
break;
case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW:
ind.dw_or_faw = nl_itr.get_u8();
break;
case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN:
ind.service_specific_info_len = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO:
memcpy(ind.service_specific_info, nl_itr.get_data(), ind.service_specific_info_len);
break;
case NAN_EVT_ATTR_SDEA_LEN:
ind.sdea_service_specific_info_len = nl_itr.get_u16();
break;
case NAN_EVT_ATTR_SDEA:
memcpy(ind.sdea_service_specific_info, nl_itr.get_data(), ind.sdea_service_specific_info_len);
break;
default :
ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventFollowup)
callbackEventHandler.EventFollowup(&ind);
return NL_OK;
}
int processNanDisabledEvent(WifiEvent &event) {
NanDisabledInd ind;
memset(&ind,0,sizeof(ind));
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_DISABLED_REASON:
ind.reason = (NanStatusType)nl_itr.get_u32();
break;
default :
ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventDisabled)
callbackEventHandler.EventDisabled(&ind);
return NL_OK;
}
int processNanDiscoveryEvent(WifiEvent &event) {
NanDiscEngEventInd ind;
memset(&ind,0,sizeof(ind));
u8 *addr = NULL;
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
switch(nl_itr.get_type()) {
case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE:
ind.event_type = (NanDiscEngEventType)nl_itr.get_u16();
break;
case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR:
addr = (u8 *)nl_itr.get_data();
break;
case NAN_EVT_ATTR_STATUS:
break;
default :
ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (addr) {
if (ind.event_type == NAN_EVENT_ID_DISC_MAC_ADDR)
memcpy(ind.data.mac_addr.addr, addr, NAN_MAC_ADDR_LEN);
else
memcpy(ind.data.cluster.addr, addr, NAN_MAC_ADDR_LEN);
} else {
ALOGE("processNanDiscoveryEvent: No Mac/cluster Address");
}
if (callbackEventHandler.EventDiscEngEvent)
callbackEventHandler.EventDiscEngEvent(&ind);
return NL_OK;
}
int processNanFollowupStatus(WifiEvent &event) {
NanTransmitFollowupInd ind;
memset(&ind,0,sizeof(ind));
nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
for(nl_iterator nl_itr(vendor_data); nl_itr.has_next(); nl_itr.next()) {
if (nl_itr.get_type() == NAN_EVT_ATTR_STATUS) {
ind.reason = (NanStatusType)nl_itr.get_u16();
} else if(nl_itr.get_type() == NAN_EVT_ATTR_HAL_TRANSACTION_ID) {
ind.id = nl_itr.get_u16();
}else {
ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr.get_type());
return NL_SKIP;
}
}
if (callbackEventHandler.EventTransmitFollowup)
callbackEventHandler.EventTransmitFollowup(&ind);
return NL_OK;
}
int putSdeaParams(NanSdeaCtrlParams *sdea_params, WifiRequest *request)
{
int result;
if (!sdea_params->config_nan_data_path)
return 0;
result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_NDP_TYPE, sdea_params->ndp_type);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM ndp_type");
result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_SECURITY_CFG, sdea_params->security_cfg);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM security_cfg");
result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGING_STATE, sdea_params->ranging_state);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM ranging_state");
result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGE_REPORT, sdea_params->range_report);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM range_report");
result = request->put_u8(NAN_REQ_ATTR_SDEA_PARAM_QOS_CFG, sdea_params->qos_cfg);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put SDEA PARAM qos_cfg");
return result;
}
int putRangingCfg(NanRangingCfg *ranging_cfg, WifiRequest *request)
{
int result;
result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INTERVAL, ranging_cfg->ranging_interval_msec);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG ranging_interval_msec");
result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INDICATION, ranging_cfg->config_ranging_indications);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG config_ranging_indications");
result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_INGRESS_MM, ranging_cfg->distance_ingress_mm);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG distance_ingress_mm");
result = request->put_u32(NAN_REQ_ATTR_RANGING_CFG_EGRESS_MM, ranging_cfg->distance_egress_mm);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put Ranging CFG distance_egress_mm");
return result;
}
int putRangeResponseCfg(NanRangeResponseCfg *range_resp_cfg, WifiRequest *request)
{
int result;
result = request->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PUBLISH_ID, range_resp_cfg->publish_id);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::publish_id");
result = request->put_u32(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_REQUESTOR_ID, range_resp_cfg->requestor_instance_id);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::requestor_instance_id");
result = request->put_addr(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PEER_ADDR, range_resp_cfg->peer_addr);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::peer_addr");
result = request->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_RANGING_RESPONSE, range_resp_cfg->ranging_response);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "Failed to put range response cfg::ranging_response");
return result;
}
public:
NanCommand(wifi_interface_handle iface, int id)
: WifiCommand(iface, id), datacmd()
{
subscribeID[0] = 0;
subscribeID[1] = 0;
publishID[0] = 0;
publishID[1] = 0;
followupID[0] = 0;
followupID[1] = 0;
version = 0;
memset(&capabilities, 0, sizeof(capabilities));
}
int enable(transaction_id id, NanEnableRequest *msg) {
ALOGD("NAN enable id:%d", id);
WifiRequest request(familyId(), ifaceId());
int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to create WifiRequest");
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
if (!data) {
ALOGE("enable: request.attr_start fail");
return WIFI_ERROR_OUT_OF_MEMORY;
}
/* Valid master pref values are 2-254 */
int master_pref;
if (msg->master_pref < 2)
master_pref = 2;
else if (msg->master_pref > 254)
master_pref = 254;
else
master_pref = msg->master_pref;
result = request.put_u8(NAN_REQ_ATTR_MASTER_PREF, master_pref);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put master_pref");
result = request.put_u16(NAN_REQ_ATTR_CLUSTER_LOW, msg->cluster_low);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put cluster_low");
result = request.put_u16(NAN_REQ_ATTR_CLUSTER_HIGH, msg->cluster_high);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "enable:Failed to put cluster_high");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_support_5g, msg->support_5g_val,
NAN_REQ_ATTR_SUPPORT_5G_VAL, request, result, "enable:Failed to put support_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_sid_beacon, msg->sid_beacon_val,
NAN_REQ_ATTR_SID_BEACON_VAL, request, result, "enable:Failed to put sid_beacon_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_close, msg->rssi_close_2dot4g_val,
NAN_REQ_ATTR_RSSI_CLOSE_2G4_VAL, request, result, "enable:Failed to put rssi_close_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_middle, msg->rssi_middle_2dot4g_val,
NAN_REQ_ATTR_RSSI_MIDDLE_2G4_VAL, request, result, "enable:Failed to put rssi_middle_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_rssi_proximity, msg->rssi_proximity_2dot4g_val,
NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL, request, result, "enable:Failed to put rssi_proximity_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_limit, msg->hop_count_limit_val,
NAN_REQ_ATTR_HOP_COUNT_LIMIT_VAL, request, result, "enable:Failed to put hop_count_limit_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_support, msg->support_2dot4g_val,
NAN_REQ_ATTR_SUPPORT_2G4_VAL, request, result, "enable:Failed to put support_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_beacons, msg->beacon_2dot4g_val,
NAN_REQ_ATTR_BEACONS_2G4_VAL, request, result, "enable:Failed to put beacon_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_2dot4g_sdf, msg->sdf_2dot4g_val,
NAN_REQ_ATTR_SDF_2G4_VAL, request, result, "enable:Failed to put sdf_2dot4g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_beacons, msg->beacon_5g_val,
NAN_REQ_ATTR_BEACON_5G_VAL, request, result, "enable:Failed to put beacon_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_sdf, msg->sdf_5g_val,
NAN_REQ_ATTR_SDF_5G_VAL, request, result, "enable:Failed to put sdf_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close, msg->rssi_close_5g_val,
NAN_REQ_ATTR_RSSI_CLOSE_5G_VAL, request, result, "enable:Failed to put rssi_close_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_middle, msg->rssi_middle_5g_val,
NAN_REQ_ATTR_RSSI_MIDDLE_5G_VAL, request, result, "enable:Failed to put rssi_middle_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close_proximity, msg->rssi_close_proximity_5g_val,
NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL, request, result, "enable:Failed to put rssi_close_proximity_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_window_size, msg->rssi_window_size_val,
NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL, request, result, "enable:Failed to put rssi_window_size_val");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_oui, msg->oui_val,
NAN_REQ_ATTR_OUI_VAL, request, result, "enable:Failed to put oui_val");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_intf_addr, msg->intf_addr_val, NAN_MAC_ADDR_LEN,
NAN_REQ_ATTR_MAC_ADDR_VAL, request, result, "enable:Failed to put intf_addr_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->config_cluster_attribute_val,
NAN_REQ_ATTR_CLUSTER_VAL, request, result, "enable:Failed to put config_cluster_attribute_val");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.dwell_time, sizeof(msg->scan_params_val.dwell_time),
NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME, request, result, "enable:Failed to put scan_params_val.dwell_time");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.scan_period, sizeof(msg->scan_params_val.scan_period),
NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD, request, result, "enable:Failed to put scan_params_val.scan_period");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_random_factor_force, msg->random_factor_force_val,
NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL, request, result, "enable:Failed to put random_factor_force_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_force, msg->hop_count_force_val,
NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL, request, result, "enable:Failed to put hop_count_force_val");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_24g_channel, msg->channel_24g_val,
NAN_REQ_ATTR_CHANNEL_2G4_MHZ_VAL, request, result, "enable:Failed to put channel_24g_val");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_5g_channel, msg->channel_5g_val,
NAN_REQ_ATTR_CHANNEL_5G_MHZ_VAL, request, result, "enable:Failed to put channel_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_subscribe_sid_beacon, msg->subscribe_sid_beacon_val,
NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL, request, result, "enable:Failed to put subscribe_sid_beacon_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_2dot4g_dw_band, msg->config_dw.dw_2dot4g_interval_val,
NAN_REQ_ATTR_DW_2G4_INTERVAL, request, result, "enable:Failed to put dw_2dot4g_interval_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_5g_dw_band, msg->config_dw.dw_5g_interval_val,
NAN_REQ_ATTR_DW_5G_INTERVAL, request, result, "enable:Failed to put dw_5g_interval_val");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_disc_mac_addr_randomization, msg->disc_mac_addr_rand_interval_sec,
NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL, request, result, "enable:Failed to put disc_mac_addr_rand_interval_sec");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_ndpe_attr, msg->use_ndpe_attr,
NAN_REQ_ATTR_USE_NDPE_ATTR, request, result, "enable:Failed to put use_ndpe_attr");
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "enable:Failed to put transaction id");
request.attr_end(data);
registerNanEvents();
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("failed to NAN; result = %d", result);
unregisterNanEvents();
} else {
ALOGD("Start NAN...success");
}
return result;
}
int disable(transaction_id id)
{
ALOGD("NAN disable id:%d", id);
WifiRequest request(familyId(), ifaceId());
unregisterNanEvents();
int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "disable:Failed to create WifiRequest");
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
if (!data) {
ALOGE("enable: request.attr_start fail");
return WIFI_ERROR_OUT_OF_MEMORY;
}
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "disable:Failed to put transaction id");
request.attr_end(data);
result = requestResponse(request);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "disable:Failed to requestResponse");
return result;
}
int config(transaction_id id, NanConfigRequest *msg) {
ALOGD("NAN config id:%d", id);
WifiRequest request(familyId(), ifaceId());
int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "config:Failed to create WifiRequest");
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
if (!data) {
ALOGE("config: request.attr_start fail");
return WIFI_ERROR_OUT_OF_MEMORY;
}
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_sid_beacon, msg->sid_beacon,
NAN_REQ_ATTR_SID_BEACON_VAL, request, result, "config:Failed to put sid_beacon");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_proximity, msg->rssi_proximity,
NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL, request, result, "config:Failed to put rssi_proximity");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_master_pref, msg->master_pref,
NAN_REQ_ATTR_MASTER_PREF, request, result, "config:Failed to put master_pref");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_5g_rssi_close_proximity, msg->rssi_close_proximity_5g_val,
NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL, request, result, "config:Failed to put rssi_close_proximity_5g_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_rssi_window_size, msg->rssi_window_size_val,
NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL, request, result, "config:Failed to put rssi_window_size_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->config_cluster_attribute_val,
NAN_REQ_ATTR_CLUSTER_VAL, request, result, "config:Failed to put config_cluster_attribute_val");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.dwell_time, sizeof(msg->scan_params_val.dwell_time),
NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME, request, result, "config:Failed to put scan_params_val.dwell_time");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->config_scan_params, msg->scan_params_val.scan_period, sizeof(msg->scan_params_val.scan_period),
NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD, request, result, "config:Failed to put scan_params_val.scan_period");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_random_factor_force, msg->random_factor_force_val,
NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL, request, result, "config:Failed to put random_factor_force_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_hop_count_force, msg->hop_count_force_val,
NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL, request, result, "config:Failed to put hop_count_force_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.payload_transmit_flag,
NAN_REQ_ATTR_CONN_CAPABILITY_PAYLOAD_TX, request, result, "config:Failed to put payload_transmit_flag");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_wfd_supported,
NAN_REQ_ATTR_CONN_CAPABILITY_WFD, request, result, "config:Failed to put is_wfd_supported");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_wfds_supported,
NAN_REQ_ATTR_CONN_CAPABILITY_WFDS, request, result, "config:Failed to put is_wfds_supported");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_tdls_supported,
NAN_REQ_ATTR_CONN_CAPABILITY_TDLS, request, result, "config:Failed to put is_tdls_supported");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_ibss_supported,
NAN_REQ_ATTR_CONN_CAPABILITY_IBSS, request, result, "config:Failed to put is_ibss_supported");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.is_mesh_supported,
NAN_REQ_ATTR_CONN_CAPABILITY_MESH, request, result, "config:Failed to put is_mesh_supported");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_conn_capability, msg->conn_capability_val.wlan_infra_field,
NAN_REQ_ATTR_CONN_CAPABILITY_WLAN_INFRA, request, result, "config:Failed to put wlan_infra_field");
if (msg->num_config_discovery_attr) {
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->num_config_discovery_attr,
NAN_REQ_ATTR_DISCOVERY_ATTR_NUM_ENTRIES, request, result, "config:Failed to put msg->num_config_discovery_attr");
for (int i = 0; i < msg->num_config_discovery_attr; i++) {
nlattr *nl_disc_attribute = request.attr_start(NAN_REQ_ATTR_DISCOVERY_ATTR_VAL);
NanTransmitPostDiscovery *discovery_attr = &msg->discovery_attr_val[i];
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->type,
NAN_REQ_ATTR_CONN_TYPE, request, result, "config:Failed to put discovery_attr->type");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->role,
NAN_REQ_ATTR_NAN_ROLE, request, result, "config:Failed to put discovery_attr->role");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->transmit_freq,
NAN_REQ_ATTR_TRANSMIT_FREQ, request, result, "config:Failed to put discovery_attr->transmit_freq");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr->duration,
NAN_REQ_ATTR_AVAILABILITY_DURATION, request, result, "config:Failed to put discovery_attr->duration");
CHECK_CONFIG_PUT_32_RETURN_FAIL(1, discovery_attr->avail_interval_bitmap,
NAN_REQ_ATTR_AVAILABILITY_INTERVAL, request, result, "config:Failed to put discovery_attr->avail_interval_bitmap");
CHECK_CONFIG_PUT_RETURN_FAIL(1, discovery_attr->addr, NAN_MAC_ADDR_LEN,
NAN_REQ_ATTR_MAC_ADDR_VAL, request, result, "config:Failed to put discovery_attr->addr");
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr->mesh_id_len,
NAN_REQ_ATTR_MESH_ID_LEN, request, result, "config:Failed to put discovery_attr->mesh_id");
CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr->mesh_id_len, discovery_attr->mesh_id, discovery_attr->mesh_id_len,
NAN_REQ_ATTR_MESH_ID, request, result, "config:Failed to put discovery_attr->mesh_id");
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr->infrastructure_ssid_len,
NAN_REQ_ATTR_INFRASTRUCTURE_SSID_LEN, request, result, "config:Failed to put discovery_attr->infrastructure_ssid_val");
CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr->infrastructure_ssid_len, discovery_attr->infrastructure_ssid_val, discovery_attr->infrastructure_ssid_len,
NAN_REQ_ATTR_INFRASTRUCTURE_SSID, request, result, "config:Failed to put discovery_attr->infrastructure_ssid_val");
request.attr_end(nl_disc_attribute);
}
}
if (msg->config_fam) {
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->fam_val.numchans,
NAN_REQ_ATTR_FURTHER_AVAIL_NUM_ENTRIES, request, result, "config:Failed to put msg->fam_val.numchans");
for (int i = 0; i < msg->fam_val.numchans; i++) {
nlattr *nl_fam_attribute = request.attr_start(NAN_REQ_ATTR_FURTHER_AVAIL_VAL);
NanFurtherAvailabilityChannel *further_avail_chan = &msg->fam_val.famchan[i];
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->entry_control,
NAN_REQ_ATTR_FURTHER_AVAIL_ENTRY_CTRL, request, result, "config:Failed to put further_avail_chan->entry_control");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->class_val,
NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_CLASS, request, result, "config:Failed to put further_avail_chan->class_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->channel,
NAN_REQ_ATTR_FURTHER_AVAIL_CHAN, request, result, "config:Failed to put further_avail_chan->channel");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan->mapid,
NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_MAPID, request, result, "config:Failed to put further_avail_chan->mapid");
CHECK_CONFIG_PUT_32_RETURN_FAIL(1, further_avail_chan->avail_interval_bitmap,
NAN_REQ_ATTR_FURTHER_AVAIL_INTERVAL_BITMAP, request, result, "config:Failed to put further_avail_chan->avail_interval_bitmap");
request.attr_end(nl_fam_attribute);
}
}
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_subscribe_sid_beacon, msg->subscribe_sid_beacon_val,
NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL, request, result, "config:Failed to put subscribe_sid_beacon_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_2dot4g_dw_band, msg->config_dw.dw_2dot4g_interval_val,
NAN_REQ_ATTR_DW_2G4_INTERVAL, request, result, "config:Failed to put dw_2dot4g_interval_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_dw.config_5g_dw_band, msg->config_dw.dw_5g_interval_val,
NAN_REQ_ATTR_DW_5G_INTERVAL, request, result, "config:Failed to put dw_5g_interval_val");
CHECK_CONFIG_PUT_8_RETURN_FAIL(msg->config_disc_mac_addr_randomization, msg->disc_mac_addr_rand_interval_sec,
NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL, request, result, "config:Failed to put disc_mac_addr_rand_interval_sec");
CHECK_CONFIG_PUT_32_RETURN_FAIL(msg->config_ndpe_attr, msg->use_ndpe_attr,
NAN_REQ_ATTR_USE_NDPE_ATTR, request, result, "config:Failed to put use_ndpe_attr");
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id, NAN_REQ_ATTR_HAL_TRANSACTION_ID, request, result, "config:Failed to put transaction id");
request.attr_end(data);
result = requestResponse(request);
if (result != WIFI_SUCCESS) {
ALOGE("failed to set_config; result = %d", result);
} else {
ALOGD("NAN config...success");
}
return result;
}
static int setCallbackHandler(NanCallbackHandler handlers) {
callbackEventHandler = handlers;
return WIFI_SUCCESS;
}
static int getVersion(NanVersion *version) {
*version = SLSI_WIFI_HAL_NAN_VERSION;
return WIFI_SUCCESS;
}
int publish(transaction_id id, NanPublishRequest *msg) {
ALOGD("NAN publish transId:%d publishId:%d publishType:%d", id, msg->publish_id, msg->publish_type);
WifiRequest request(familyId(), ifaceId());
int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH);
CHECK_WIFI_STATUS_RETURN_FAIL(result, "publish:Failed to create WifiRequest");
nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
if (!data) {
ALOGE("publish: request.attr_start fail");
return WIFI_ERROR_OUT_OF_MEMORY;
}
CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->publish_id, msg->publish_id,
NAN_REQ_ATTR_PUBLISH_ID, request, result, "publish:Failed to put msg->publish_id");
CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->ttl, msg->ttl,
NAN_REQ_ATTR_PUBLISH_TTL, request, result, "publish:Failed to put msg->ttl");
CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg->period,
NAN_REQ_ATTR_PUBLISH_PERIOD, request, result, "publish:Failed to put msg->period");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_type,
NAN_REQ_ATTR_PUBLISH_TYPE, request, result, "publish:Failed to put msg->publish_type");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->tx_type,
NAN_REQ_ATTR_PUBLISH_TX_TYPE, request, result, "publish:Failed to put msg->tx_type");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_count,
NAN_REQ_ATTR_PUBLISH_COUNT, request, result, "publish:Failed to put msg->publish_count");
CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_name_len, msg->service_name_len,
NAN_REQ_ATTR_PUBLISH_SERVICE_NAME_LEN, request, result, "publish:Failed to put msg->service_name_len");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_name_len, msg->service_name, msg->service_name_len,
NAN_REQ_ATTR_PUBLISH_SERVICE_NAME, request, result, "publish:Failed to put msg->service_name");
CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg->publish_match_indicator,
NAN_REQ_ATTR_PUBLISH_MATCH_ALGO, request, result, "publish:Failed to put msg->publish_match_indicator");
CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info_len,
NAN_REQ_ATTR_PUBLISH_SERVICE_INFO_LEN, request, result, "publish:Failed to put msg->service_specific_info_len");
CHECK_CONFIG_PUT_RETURN_FAIL(msg->service_specific_info_len, msg->service_specific_info, msg->service_specific_info_len,
NAN_REQ_ATTR_PUBLISH_SERVICE_INFO, request, result, "publish:Failed to put msg->service_specific_info");
CHECK_CONFIG_PUT_16_RETURN_FAIL(msg->rx_match_filter_len, msg->rx_match_filter_len,
NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER_LEN, request, result, "publish:Failed to put msg->rx_match_filter_len");