Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <inttypes.h>
#include "esp_err.h"
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/wpa_debug.h"
#include "common/wpa_ctrl.h"
#include "common/eapol_common.h"
#include "common/ieee802_11_defs.h"
#include "utils/state_machine.h"
#include "rsn_supp/wpa.h"
#include "crypto/crypto.h"
#include "utils/ext_password.h"
#include "crypto/tls.h"
#include "eap_peer/eap_i.h"
#include "eap_peer/eap_config.h"
#include "eap_peer/eap.h"
#include "eap_peer/eap_tls.h"
#include "eap_peer/eap_methods.h"
#include "esp_wifi_driver.h"
#include "esp_private/wifi.h"
#include "esp_wpa_err.h"
#include "esp_crt_bundle.h"
#include "esp_wpas_glue.h"
#include "esp_eap_client_i.h"
#include "esp_eap_client.h"
#define WPA2_VERSION
#define DATA_MUTEX_TAKE
#define DATA_MUTEX_GIVE
#define FAST_PROVISIONING_CONFIG_STR_LEN
#define FAST_MAX_PAC_LIST_CONFIG_STR_LEN
#define FAST_PAC_FORMAT_STR_LEN
#define PHASE1_PARAM_STRING_LEN
s_wpa2_data_lock
gEapSm
#define WPA2_TASK_PRIORITY
s_wpa2_task_hdl
s_wpa2_queue
s_wpa2_state
s_wpa2_api_lock
s_wifi_wpa2_sync_sem
s_disable_time_check
wpa2_api_lock()
wpa2_api_unlock()
wpa2_is_enabled()
wpa2_is_disabled()
wpa2_set_state(wpa2_state_t)
wpa2_set_eap_state(wpa2_ent_eap_state_t)
eap_client_get_eap_state()
wpa2_task_delete(void *)
#define WPA_ADDR_LEN
wpa2_rx_param
s_wpa2_rxq
wpa2_rxq_init()
wpa2_rxq_enqueue(struct wpa2_rx_param *)
wpa2_rxq_dequeue()
wpa2_rxq_deinit()
wpa2_task(void *)
wpa2_post(uint32_t, uint32_t)
eap_sm_send_eapol(struct eap_sm *, struct wpabuf *)
eap_sm_process_request(struct eap_sm *, struct wpabuf *)
eap_sm_rx_eapol(u8 *, u8 *, u32, uint8_t *)
wpa2_ent_rx_eapol(u8 *, u8 *, u32, uint8_t *)
eap_sm_rx_eapol_internal(u8 *, u8 *, u32, uint8_t *)
wpa2_start_eapol()
wpa2_start_eapol_internal()
eap_peer_sm_init()
eap_peer_sm_deinit()
esp_client_enable_fn(void *)
esp_wifi_sta_enterprise_enable()
eap_client_disable_fn(void *)
esp_wifi_sta_enterprise_disable()
esp_eap_client_set_certificate_and_key(const unsigned char *, int, const unsigned char *, int, const unsigned char *, int)
esp_eap_client_clear_certificate_and_key()
esp_eap_client_set_ca_cert(const unsigned char *, int)
esp_eap_client_clear_ca_cert()
#define ANONYMOUS_ID_LEN_MAX
esp_eap_client_set_identity(const unsigned char *, int)
esp_eap_client_clear_identity()
#define USERNAME_LEN_MAX
esp_eap_client_set_username(const unsigned char *, int)
esp_eap_client_clear_username()
esp_eap_client_set_password(const unsigned char *, int)
esp_eap_client_clear_password()
esp_eap_client_set_new_password(const unsigned char *, int)
esp_eap_client_clear_new_password()
esp_eap_client_set_disable_time_check(bool)
wifi_sta_get_enterprise_disable_time_check()
esp_eap_client_get_disable_time_check(bool *)
esp_eap_client_set_ttls_phase2_method(esp_eap_ttls_phase2_types)
esp_eap_client_set_suiteb_192bit_certification(bool)
esp_eap_client_set_pac_file(const unsigned char *, int)
esp_eap_client_set_fast_params(esp_eap_fast_config)
esp_eap_client_use_default_cert_bundle(bool)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
esp_supplicant
include
src
crypto
include
port
src
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/wpa_supplicant/esp_supplicant/src/esp_eap_client.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include <inttypes.h> #include "esp_err.h" #include "utils/includes.h" #include "utils/common.h" #include "utils/wpa_debug.h" #include "common/wpa_ctrl.h" #include "common/eapol_common.h" #include "common/ieee802_11_defs.h" #include "utils/state_machine.h" #include "rsn_supp/wpa.h" #include "crypto/crypto.h" #include "utils/ext_password.h" #include "crypto/tls.h" #include "eap_peer/eap_i.h" #include "eap_peer/eap_config.h" #include "eap_peer/eap.h" #include "eap_peer/eap_tls.h"18 includes #ifdef EAP_PEER_METHOD #include "eap_peer/eap_methods.h" #endif #include "esp_wifi_driver.h" #include "esp_private/wifi.h" #include "esp_wpa_err.h" #ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE #include "esp_crt_bundle.h" #endif #include "esp_wpas_glue.h" #include "esp_eap_client_i.h" #include "esp_eap_client.h" #define WPA2_VERSION "v2.0" #define DATA_MUTEX_TAKE() os_mutex_lock(s_wpa2_data_lock) #define DATA_MUTEX_GIVE() os_mutex_unlock(s_wpa2_data_lock) //length of the string "fast_provisioning={0/1/2} " #define FAST_PROVISIONING_CONFIG_STR_LEN 20 //length of the string "fast_max_pac_list_len=(int < 100) " #define FAST_MAX_PAC_LIST_CONFIG_STR_LEN 25 //length of the string "fast_pac_format=binary" #define FAST_PAC_FORMAT_STR_LEN 22 //Total #define PHASE1_PARAM_STRING_LEN FAST_PROVISIONING_CONFIG_STR_LEN + FAST_MAX_PAC_LIST_CONFIG_STR_LEN + FAST_PAC_FORMAT_STR_LEN7 defines static void *s_wpa2_data_lock = NULL; static struct eap_sm *gEapSm = NULL; static int eap_peer_sm_init(void); static void eap_peer_sm_deinit(void); static int eap_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len, uint8_t *bssid); static int wpa2_start_eapol_internal(void); int wpa2_post(uint32_t sig, uint32_t par); #ifdef USE_WPA2_TASK #define WPA2_TASK_PRIORITY 7 static void *s_wpa2_task_hdl = NULL; static void *s_wpa2_queue = NULL; static wpa2_state_t s_wpa2_state = WPA2_STATE_DISABLED; static void *s_wpa2_api_lock = NULL; static void *s_wifi_wpa2_sync_sem = NULL; static bool s_disable_time_check = true; static void wpa2_api_lock(void) { if (s_wpa2_api_lock == NULL) { s_wpa2_api_lock = os_recursive_mutex_create(); if (!s_wpa2_api_lock) { wpa_printf(MSG_ERROR, "EAP: failed to create EAP api lock"); return; }{...} }{...} os_mutex_lock(s_wpa2_api_lock); }{ ... } static void wpa2_api_unlock(void) { if (s_wpa2_api_lock) { os_mutex_unlock(s_wpa2_api_lock); }{...} }{ ... } static bool inline wpa2_is_enabled(void) { return (s_wpa2_state == WPA2_STATE_ENABLED); }{ ... } static bool inline wpa2_is_disabled(void) { return (s_wpa2_state == WPA2_STATE_DISABLED); }{ ... } static void inline wpa2_set_state(wpa2_state_t state) { s_wpa2_state = state; }{ ... } static void wpa2_set_eap_state(wpa2_ent_eap_state_t state) { if (!gEapSm) { return; }{...} gEapSm->finish_state = state; esp_wifi_set_wpa2_ent_state_internal(state); }{ ... } wpa2_ent_eap_state_t eap_client_get_eap_state(void) { if (!gEapSm) { return WPA2_ENT_EAP_STATE_NOT_START; }{...} return gEapSm->finish_state; }{ ... } static inline void wpa2_task_delete(void *arg) { void *my_task_hdl = os_task_get_current_task(); int ret = ESP_OK; if (my_task_hdl == s_wpa2_task_hdl) { wpa_printf(MSG_ERROR, "EAP: should never call task delete api in eap task context"); return; }{...} ret = wpa2_post(SIG_WPA2_TASK_DEL, 0); if (ESP_OK != ret) { wpa_printf(MSG_ERROR, "EAP: failed to post task delete event, ret=%d", ret); return; }{...} }{ ... } #define WPA_ADDR_LEN 6 struct wpa2_rx_param { uint8_t *bssid; u8 sa[WPA_ADDR_LEN]; u8 *buf; int len; STAILQ_ENTRY(wpa2_rx_param) bqentry; }{ ... }; static STAILQ_HEAD(, wpa2_rx_param) s_wpa2_rxq; static void wpa2_rxq_init(void) { DATA_MUTEX_TAKE(); STAILQ_INIT(&s_wpa2_rxq); DATA_MUTEX_GIVE(); }{ ... } static void wpa2_rxq_enqueue(struct wpa2_rx_param *param) { DATA_MUTEX_TAKE(); STAILQ_INSERT_TAIL(&s_wpa2_rxq, param, bqentry); DATA_MUTEX_GIVE(); }{ ... } static struct wpa2_rx_param * wpa2_rxq_dequeue(void) { struct wpa2_rx_param *param = NULL; DATA_MUTEX_TAKE(); if ((param = STAILQ_FIRST(&s_wpa2_rxq)) != NULL) { STAILQ_REMOVE_HEAD(&s_wpa2_rxq, bqentry); STAILQ_NEXT(param, bqentry) = NULL; }{...} DATA_MUTEX_GIVE(); return param; }{ ... } static void wpa2_rxq_deinit(void) { struct wpa2_rx_param *param = NULL; DATA_MUTEX_TAKE(); while ((param = STAILQ_FIRST(&s_wpa2_rxq)) != NULL) { STAILQ_REMOVE_HEAD(&s_wpa2_rxq, bqentry); STAILQ_NEXT(param, bqentry) = NULL; os_free(param->buf); os_free(param); }{...} DATA_MUTEX_GIVE(); }{ ... } void wpa2_task(void *pvParameters) { ETSEvent e; struct eap_sm *sm = gEapSm; bool task_del = false; if (!sm) { return; }{...} for (;;) { if (TRUE == os_queue_recv(s_wpa2_queue, &e, OS_BLOCK)) { if (e.sig < SIG_WPA2_MAX) { DATA_MUTEX_TAKE(); if (sm->wpa2_sig_cnt[e.sig]) { sm->wpa2_sig_cnt[e.sig]--; }{...} else { wpa_printf(MSG_ERROR, "wpa2_task: invalid sig cnt, sig=%" PRId32 " cnt=%d", e.sig, sm->wpa2_sig_cnt[e.sig]); }{...} DATA_MUTEX_GIVE(); }{...} switch (e.sig) { case SIG_WPA2_TASK_DEL: task_del = true; break;... case SIG_WPA2_START: wpa2_start_eapol_internal(); break;... case SIG_WPA2_RX: { struct wpa2_rx_param *param = NULL; while ((param = wpa2_rxq_dequeue()) != NULL) { eap_sm_rx_eapol_internal(param->sa, param->buf, param->len, param->bssid); os_free(param->buf); os_free(param); }{...} break; }{...} ... default: break;... }{...} if (task_del) { break; }{...} if (s_wifi_wpa2_sync_sem) { wpa_printf(MSG_DEBUG, "EAP: wifi->EAP api completed"); os_semphr_give(s_wifi_wpa2_sync_sem); }{...} else { wpa_printf(MSG_ERROR, "EAP: null wifi->EAP sync sem"); }{...} }{...} }{...} wpa_printf(MSG_DEBUG, "EAP: queue deleted"); os_queue_delete(s_wpa2_queue); wpa_printf(MSG_DEBUG, "EAP: task deleted"); s_wpa2_queue = NULL; if (s_wifi_wpa2_sync_sem) { wpa_printf(MSG_DEBUG, "EAP: wifi->EAP api completed"); os_semphr_give(s_wifi_wpa2_sync_sem); }{...} else { wpa_printf(MSG_ERROR, "EAP: null wifi->EAP sync sem"); }{...} /* At this point, we completed */ os_task_delete(NULL); }{ ... } int wpa2_post(uint32_t sig, uint32_t par) { struct eap_sm *sm = gEapSm; ETSEvent evt; if (!sm) { return ESP_FAIL; }{...} DATA_MUTEX_TAKE(); if (sm->wpa2_sig_cnt[sig]) { DATA_MUTEX_GIVE(); return ESP_OK; }{...} sm->wpa2_sig_cnt[sig]++; DATA_MUTEX_GIVE(); evt.sig = sig; evt.par = par; if (os_queue_send(s_wpa2_queue, &evt, os_task_ms_to_tick(10)) != TRUE) { wpa_printf(MSG_ERROR, "EAP: Q S E"); return ESP_FAIL; }{...} if (s_wifi_wpa2_sync_sem) { os_semphr_take(s_wifi_wpa2_sync_sem, OS_BLOCK); wpa_printf(MSG_DEBUG, "EAP: EAP api return, sm->state(%d)", sm->finish_state); }{...} else { wpa_printf(MSG_ERROR, "EAP: null wifi->EAP sync sem"); }{...} return ESP_OK; }{ ... } /* ... */#endif /* USE_WPA2_TASK */ int eap_sm_send_eapol(struct eap_sm *sm, struct wpabuf *resp) { size_t outlen; int ret; u8 *outbuf = NULL; u8 bssid[6]; ret = esp_wifi_get_assoc_bssid_internal(bssid); if (ret != 0) { wpa_printf(MSG_DEBUG, "bssid is empty"); return WPA_ERR_INVALID_BSSID; }{...} outbuf = wpa_alloc_eapol(sm, IEEE802_1X_TYPE_EAP_PACKET, wpabuf_head_u8(resp), wpabuf_len(resp), &outlen, NULL); if (!outbuf) { return ESP_ERR_NO_MEM; }{...} ret = wpa_ether_send(sm, bssid, ETH_P_EAPOL, outbuf, outlen); wpa_free_eapol(outbuf); if (ret) { return ESP_FAIL; }{...} return ESP_OK; }{ ... } int eap_sm_process_request(struct eap_sm *sm, struct wpabuf *reqData) { size_t plen; u32 reqVendor, reqVendorMethod; u8 type, *pos; struct eap_hdr *ehdr; const struct eap_method *m = NULL; struct wpabuf *resp = NULL; struct eap_method_ret m_res; int ret = 0; if (reqData == NULL || wpabuf_len(reqData) < sizeof(*ehdr)) { return ESP_ERR_INVALID_ARG; }{...} ehdr = (struct eap_hdr *)wpabuf_head(reqData); plen = be_to_host16(ehdr->length); if (plen > wpabuf_len(reqData)) { return ESP_FAIL; }{...} if (ehdr->identifier == sm->current_identifier && sm->lastRespData != NULL) { /*Retransmit*/ resp = sm->lastRespData; goto send_resp; }{...} sm->current_identifier = ehdr->identifier; pos = (u8 *)(ehdr + 1); type = *pos++; if (type == EAP_TYPE_IDENTITY) { resp = (struct wpabuf *)eap_sm_build_identity_resp(sm, ehdr->identifier, 0); goto send_resp; }{...} else if (type == EAP_TYPE_NOTIFICATION) { /*Ignore*/ goto out; }{...} else if (type == EAP_TYPE_EXPANDED) { if (plen < sizeof(*ehdr) + 8) { return ESP_FAIL; }{...} reqVendor = WPA_GET_BE24(pos); pos += 3; reqVendorMethod = WPA_GET_BE32(pos); }{...} else { reqVendor = EAP_VENDOR_IETF; reqVendorMethod = type; }{...} if (sm->m && sm->m->process && sm->eap_method_priv && reqVendor == sm->m->vendor && reqVendorMethod == sm->m->method) { resp = sm->m->process(sm, sm->eap_method_priv, &m_res, reqData); }{...} else { m = eap_peer_get_eap_method(reqVendor, reqVendorMethod); if (m == NULL) { goto build_nak; }{...} if (!eap_sm_allowMethod(sm, reqVendor, reqVendorMethod)) { wpa_printf(MSG_DEBUG, "EAP: vendor %" PRIu32 " method %" PRIu32 " not allowed", reqVendor, reqVendorMethod); wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_PROPOSED_METHOD "vendor=%" PRIu32 " method=%" PRIu32 " -> NAK", reqVendor, reqVendorMethod); goto build_nak; }{...} if (sm->m) { eap_deinit_prev_method(sm, "GET_METHOD"); }{...} sm->m = m; sm->eap_method_priv = sm->m->init(sm); if (sm->eap_method_priv == NULL) { wpa_printf(MSG_ERROR, "Method private structure allocated failure"); sm->m = NULL; goto build_nak; }{...} if (sm->m->process) { resp = sm->m->process(sm, sm->eap_method_priv, &m_res, reqData); }{...} }{...} if (sm->m->isKeyAvailable && sm->m->getKey && sm->m->isKeyAvailable(sm, sm->eap_method_priv)) { if (sm->eapKeyData) { os_free(sm->eapKeyData); }{...} sm->eapKeyData = sm->m->getKey(sm, sm->eap_method_priv, &sm->eapKeyDataLen); }{...} goto send_resp; build_nak: resp = (struct wpabuf *)eap_sm_build_nak(sm, type, ehdr->identifier); if (resp == NULL) { return ESP_FAIL; }{...} send_resp: if (resp == NULL) { wpa_printf(MSG_ERROR, "Response build fail, return."); wpabuf_free(sm->lastRespData); sm->lastRespData = resp; wpa2_set_eap_state(WPA2_ENT_EAP_STATE_FAIL); return WPA2_ENT_EAP_STATE_FAIL; }{...} ret = eap_sm_send_eapol(sm, resp); if (resp != sm->lastRespData) { wpabuf_free(sm->lastRespData); }{...} if (ret != ESP_OK) { wpabuf_free(resp); resp = NULL; if (ret == WPA_ERR_INVALID_BSSID) { ret = WPA2_ENT_EAP_STATE_FAIL; wpa2_set_eap_state(WPA2_ENT_EAP_STATE_FAIL); }{...} }{...} sm->lastRespData = resp; out: return ret; }{ ... } static int eap_sm_rx_eapol(u8 *src_addr, u8 *buf, u32 len, uint8_t *bssid) { struct eap_sm *sm = gEapSm; if (!sm) { return ESP_FAIL; }{...} #ifdef USE_WPA2_TASK { struct wpa2_rx_param *param = (struct wpa2_rx_param *)os_zalloc(sizeof(struct wpa2_rx_param)); /* free in task */ if (!param) { return ESP_ERR_NO_MEM; }{...} param->buf = (u8 *)os_zalloc(len); /* free in task */ if (!param->buf) { os_free(param); return ESP_ERR_NO_MEM; }{...} param->bssid = bssid; memcpy(param->buf, buf, len); param->len = len; memcpy(param->sa, src_addr, WPA_ADDR_LEN); wpa2_rxq_enqueue(param); return wpa2_post(SIG_WPA2_RX, 0); }/* ... */ {...}#else return eap_sm_rx_eapol_internal(src_addr, buf, len, bssid);/* ... */ #endif }{ ... } static int wpa2_ent_rx_eapol(u8 *src_addr, u8 *buf, u32 len, uint8_t *bssid) { struct ieee802_1x_hdr *hdr; int ret = ESP_OK; hdr = (struct ieee802_1x_hdr *) buf; switch (hdr->type) { case IEEE802_1X_TYPE_EAPOL_START: case IEEE802_1X_TYPE_EAP_PACKET: case IEEE802_1X_TYPE_EAPOL_LOGOFF: ret = eap_sm_rx_eapol(src_addr, buf, len, bssid); break;... case IEEE802_1X_TYPE_EAPOL_KEY: ret = wpa_sm_rx_eapol(src_addr, buf, len); break;... default: wpa_printf(MSG_ERROR, "Unknown EAPOL packet type - %d", hdr->type); break;... }{...} return ret; }{ ... } static int eap_sm_rx_eapol_internal(u8 *src_addr, u8 *buf, u32 len, uint8_t *bssid) { struct eap_sm *sm = gEapSm; u32 plen, data_len; struct ieee802_1x_hdr *hdr; struct eap_hdr *ehdr; struct wpabuf *req = NULL; u8 *tmp; int ret = ESP_FAIL; if (!sm) { return ESP_FAIL; }{...} if (len < sizeof(*hdr) + sizeof(*ehdr)) { wpa_printf(MSG_DEBUG, "WPA: EAPOL frame too short to be a WPA " "EAPOL-Key (len %lu, expecting at least %lu)", (unsigned long) len, (unsigned long) sizeof(*hdr) + sizeof(*ehdr)); return ESP_FAIL; }{...} tmp = buf; hdr = (struct ieee802_1x_hdr *) tmp; ehdr = (struct eap_hdr *)(hdr + 1); plen = be_to_host16(hdr->length); data_len = plen + sizeof(*hdr); wpa_printf(MSG_DEBUG, "IEEE 802.1X RX: version=%d type=%d length=%" PRId32 "", hdr->version, hdr->type, plen); if (hdr->version < EAPOL_VERSION) { /* TODO: backwards compatibility */ }{...} if (hdr->type != IEEE802_1X_TYPE_EAP_PACKET) { wpa_printf(MSG_DEBUG, "EAP: EAP frame (type %u) discarded, " "not a EAP PACKET frame", hdr->type); ret = -2; goto _out; }{...} if (plen > len - sizeof(*hdr) || plen < sizeof(*ehdr)) { wpa_printf(MSG_DEBUG, "EAP: EAPOL frame payload size %lu " "invalid (frame size %lu)", (unsigned long) plen, (unsigned long) len); ret = -2; goto _out; }{...} wpa_hexdump(MSG_MSGDUMP, "EAP: RX EAPOL-EAP PACKET", tmp, len); if (data_len < len) { wpa_printf(MSG_DEBUG, "WPA: ignoring %lu bytes after the IEEE " "802.1X data\n", (unsigned long) len - data_len); }{...} #ifdef EAP_PEER_METHOD switch (ehdr->code) { case EAP_CODE_REQUEST: /* Handle EAP-reauthentication case */ if (sm->finish_state == WPA2_ENT_EAP_STATE_SUCCESS) { wpa_printf(MSG_INFO, "EAP Re-authentication in progress"); wpa2_set_eap_state(WPA2_ENT_EAP_STATE_IN_PROGRESS); }{...} req = wpabuf_alloc_copy((u8 *)ehdr, len - sizeof(*hdr)); ret = eap_sm_process_request(sm, req); break;... case EAP_CODE_RESPONSE: /*Ignore*/ break;... case EAP_CODE_SUCCESS: if (sm->eapKeyData) { wpa_set_pmk(sm->eapKeyData, 0, NULL, false); os_free(sm->eapKeyData); sm->eapKeyData = NULL; wpa_printf(MSG_INFO, ">>>>>EAP FINISH"); ret = WPA2_ENT_EAP_STATE_SUCCESS; wpa2_set_eap_state(WPA2_ENT_EAP_STATE_SUCCESS); eap_deinit_prev_method(sm, "EAP Success"); }{...} else { wpa_printf(MSG_INFO, ">>>>>EAP FAILED, receive EAP_SUCCESS but pmk is empty, potential attack!"); ret = WPA2_ENT_EAP_STATE_FAIL; wpa2_set_eap_state(WPA2_ENT_EAP_STATE_FAIL); }{...} break;... case EAP_CODE_FAILURE: wpa_printf(MSG_INFO, ">>>>>EAP FAILED"); ret = WPA2_ENT_EAP_STATE_FAIL; wpa2_set_eap_state(WPA2_ENT_EAP_STATE_FAIL); break;... }{...} _out: wpabuf_free(req);/* ... */ #endif return ret; }{ ... } static int wpa2_start_eapol(void) { #ifdef USE_WPA2_TASK return wpa2_post(SIG_WPA2_START, 0); #else return wpa2_start_eapol_internal(); #endif }{ ... } static int wpa2_start_eapol_internal(void) { struct eap_sm *sm = gEapSm; int ret = 0; u8 bssid[6]; u8 *buf; size_t len; if (!sm) { return ESP_FAIL; }{...} if (wpa_sta_cur_pmksa_matches_akm()) { wpa_printf(MSG_DEBUG, "RSN: PMKSA caching - do not send EAPOL-Start"); return ESP_FAIL; }{...} ret = esp_wifi_get_assoc_bssid_internal(bssid); if (ret != 0) { wpa_printf(MSG_ERROR, "bssid is empty!"); return WPA_ERR_INVALID_BSSID; }{...} buf = wpa_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START, (u8 *)"", 0, &len, NULL); if (!buf) { return ESP_FAIL; }{...} wpa2_set_eap_state(WPA2_ENT_EAP_STATE_IN_PROGRESS); wpa_ether_send(sm, bssid, ETH_P_EAPOL, buf, len); wpa_free_eapol(buf); return ESP_OK; }{ ... } /** * eap_peer_sm_init - Allocate and initialize EAP peer state machine * @eapol_ctx: Context data to be used with eapol_cb calls * @eapol_cb: Pointer to EAPOL callback functions * @msg_ctx: Context data for wpa_msg() calls * @conf: EAP configuration * Returns: Pointer to the allocated EAP state machine or %NULL on failure * * This function allocates and initializes an EAP state machine. In addition, * this initializes TLS library for the new EAP state machine. eapol_cb pointer * will be in use until eap_peer_sm_deinit() is used to deinitialize this EAP * state machine. Consequently, the caller must make sure that this data * structure remains alive while the EAP state machine is active. *//* ... */ static int eap_peer_sm_init(void) { int ret = 0; struct eap_sm *sm; if (gEapSm) { wpa_printf(MSG_ERROR, "EAP: EAP sm not null, deinit it"); eap_peer_sm_deinit(); }{...} sm = (struct eap_sm *)os_zalloc(sizeof(*sm)); if (sm == NULL) { ret = ESP_ERR_NO_MEM; return ret; }{...} gEapSm = sm; s_wpa2_data_lock = os_recursive_mutex_create(); if (!s_wpa2_data_lock) { wpa_printf(MSG_ERROR, "EAP eap_peer_sm_init: failed to alloc data lock"); ret = ESP_ERR_NO_MEM; goto _err; }{...} wpa2_set_eap_state(WPA2_ENT_EAP_STATE_NOT_START); sm->current_identifier = 0xff; esp_wifi_get_macaddr_internal(WIFI_IF_STA, sm->ownaddr); ret = eap_peer_blob_init(sm); if (ret) { wpa_printf(MSG_ERROR, "eap_peer_blob_init failed"); ret = ESP_FAIL; goto _err; }{...} ret = eap_peer_config_init(sm, g_wpa_private_key_passwd, g_wpa_private_key_passwd_len); if (ret) { wpa_printf(MSG_ERROR, "eap_peer_config_init failed"); ret = ESP_FAIL; goto _err; }{...} sm->ssl_ctx = tls_init(NULL); if (sm->ssl_ctx == NULL) { wpa_printf(MSG_WARNING, "SSL: Failed to initialize TLS context."); ret = ESP_FAIL; goto _err; }{...} wpa2_rxq_init(); gEapSm = sm; #ifdef USE_WPA2_TASK s_wpa2_queue = os_queue_create(SIG_WPA2_MAX, sizeof(ETSEvent)); ret = os_task_create(wpa2_task, "wpa2T", WPA2_TASK_STACK_SIZE, NULL, WPA2_TASK_PRIORITY, &s_wpa2_task_hdl); if (ret != TRUE) { wpa_printf(MSG_ERROR, "wps enable: failed to create task"); ret = ESP_FAIL; goto _err; }{...} s_wifi_wpa2_sync_sem = os_semphr_create(1, 0); if (!s_wifi_wpa2_sync_sem) { wpa_printf(MSG_ERROR, "EAP: failed create wifi EAP task sync sem"); ret = ESP_FAIL; goto _err; }{...} wpa_printf(MSG_INFO, "wifi_task prio:%d, stack:%d", WPA2_TASK_PRIORITY, WPA2_TASK_STACK_SIZE);/* ... */ #endif sm->workaround = 1; return ESP_OK; _err: eap_peer_sm_deinit(); return ret; }{ ... } /** * eap_peer_sm_deinit - Deinitialize and free an EAP peer state machine * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init() * * This function deinitializes EAP state machine and frees all allocated * resources. *//* ... */ static void eap_peer_sm_deinit(void) { struct eap_sm *sm = gEapSm; if (sm == NULL) { return; }{...} eap_peer_config_deinit(sm); eap_peer_blob_deinit(sm); eap_deinit_prev_method(sm, "EAP deinit"); eap_sm_abort(sm); tls_deinit(sm->ssl_ctx); #ifdef USE_WPA2_TASK wpa2_task_delete(0); #endif if (STAILQ_FIRST((&s_wpa2_rxq)) != NULL) { wpa2_rxq_deinit(); }{...} if (s_wifi_wpa2_sync_sem) { os_semphr_delete(s_wifi_wpa2_sync_sem); s_wifi_wpa2_sync_sem = NULL; }{...} if (s_wpa2_data_lock) { os_mutex_delete(s_wpa2_data_lock); s_wpa2_data_lock = NULL; wpa_printf(MSG_DEBUG, "EAP: eap_peer_sm_deinit: free data lock"); }{...} if (s_wpa2_queue) { os_queue_delete(s_wpa2_queue); s_wpa2_queue = NULL; }{...} os_free(sm); gEapSm = NULL; }{ ... } static esp_err_t esp_client_enable_fn(void *arg) { struct wpa2_funcs *wpa2_cb; wpa_printf(MSG_INFO, "WiFi Enterprise enable"); wpa2_cb = (struct wpa2_funcs *)os_zalloc(sizeof(struct wpa2_funcs)); if (wpa2_cb == NULL) { wpa_printf(MSG_ERROR, "EAP: no mem for eap cb"); return ESP_ERR_NO_MEM; }{...} wpa2_cb->wpa2_sm_rx_eapol = wpa2_ent_rx_eapol; wpa2_cb->wpa2_start = wpa2_start_eapol; wpa2_cb->wpa2_init = eap_peer_sm_init; wpa2_cb->wpa2_deinit = eap_peer_sm_deinit; esp_wifi_register_wpa2_cb_internal(wpa2_cb); wpa_printf(MSG_DEBUG, "WiFi Enterprise crypto init.\r"); #ifdef EAP_PEER_METHOD if (eap_peer_register_methods()) { wpa_printf(MSG_ERROR, "Register EAP Peer methods Failure"); }{...} #endif/* ... */ return ESP_OK; }{ ... } esp_err_t esp_wifi_sta_enterprise_enable(void) { wifi_wpa2_param_t param; esp_err_t ret; struct wpa_sm *sm = &gWpaSm; wpa2_api_lock(); if (wpa2_is_enabled()) { wpa_printf(MSG_INFO, "EAP: already enabled"); wpa2_api_unlock(); return ESP_OK; }{...} param.fn = (wifi_wpa2_fn_t)esp_client_enable_fn; param.param = NULL; ret = esp_wifi_sta_wpa2_ent_enable_internal(&param); if (ESP_OK == ret) { wpa2_set_state(WPA2_STATE_ENABLED); sm->wpa_sm_eap_disable = esp_wifi_sta_enterprise_disable; }{...} else { wpa_printf(MSG_ERROR, "failed to enable eap ret=%d", ret); }{...} wpa2_api_unlock(); return ret; }{ ... } static esp_err_t eap_client_disable_fn(void *param) { struct wpa_sm *sm = &gWpaSm; wpa_printf(MSG_INFO, "WiFi enterprise disable"); esp_wifi_unregister_wpa2_cb_internal(); if (gEapSm) { eap_peer_sm_deinit(); }{...} #ifdef EAP_PEER_METHOD eap_peer_unregister_methods(); #endif sm->wpa_sm_eap_disable = NULL; return ESP_OK; }{ ... } esp_err_t esp_wifi_sta_enterprise_disable(void) { wifi_wpa2_param_t param; esp_err_t ret; wpa2_api_lock(); if (wpa2_is_disabled()) { wpa_printf(MSG_INFO, "EAP: already disabled"); wpa2_api_unlock(); return ESP_OK; }{...} param.fn = (wifi_wpa2_fn_t)eap_client_disable_fn; param.param = 0; ret = esp_wifi_sta_wpa2_ent_disable_internal(&param); if (ESP_OK == ret) { wpa2_set_state(WPA2_STATE_DISABLED); }{...} else { wpa_printf(MSG_ERROR, "failed to disable eap ret=%d", ret); }{...} wpa2_api_unlock(); return ret; }{ ... } esp_err_t esp_eap_client_set_certificate_and_key(const unsigned char *client_cert, int client_cert_len, const unsigned char *private_key, int private_key_len, const unsigned char *private_key_passwd, int private_key_passwd_len) { if (client_cert && client_cert_len > 0) { g_wpa_client_cert = client_cert; g_wpa_client_cert_len = client_cert_len; }{...} if (private_key && private_key_len > 0) { g_wpa_private_key = private_key; g_wpa_private_key_len = private_key_len; }{...} if (private_key_passwd && private_key_passwd_len > 0) { g_wpa_private_key_passwd = private_key_passwd; g_wpa_private_key_passwd_len = private_key_passwd_len; }{...} return ESP_OK; }{ ... } void esp_eap_client_clear_certificate_and_key(void) { g_wpa_client_cert = NULL; g_wpa_client_cert_len = 0; g_wpa_private_key = NULL; g_wpa_private_key_len = 0; g_wpa_private_key_passwd = NULL; g_wpa_private_key_passwd_len = 0; os_free(g_wpa_pac_file); g_wpa_pac_file = NULL; g_wpa_pac_file_len = 0; }{ ... } esp_err_t esp_eap_client_set_ca_cert(const unsigned char *ca_cert, int ca_cert_len) { if (ca_cert && ca_cert_len > 0) { g_wpa_ca_cert = ca_cert; g_wpa_ca_cert_len = ca_cert_len; }{...} return ESP_OK; }{ ... } void esp_eap_client_clear_ca_cert(void) { g_wpa_ca_cert = NULL; g_wpa_ca_cert_len = 0; }{ ... } #define ANONYMOUS_ID_LEN_MAX 128 esp_err_t esp_eap_client_set_identity(const unsigned char *identity, int len) { if (len <= 0 || len > ANONYMOUS_ID_LEN_MAX) { return ESP_ERR_INVALID_ARG; }{...} if (g_wpa_anonymous_identity) { os_free(g_wpa_anonymous_identity); g_wpa_anonymous_identity = NULL; }{...} g_wpa_anonymous_identity = (u8 *)os_zalloc(len); if (g_wpa_anonymous_identity == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_anonymous_identity, identity, len); g_wpa_anonymous_identity_len = len; return ESP_OK; }{ ... } void esp_eap_client_clear_identity(void) { if (g_wpa_anonymous_identity) { os_free(g_wpa_anonymous_identity); }{...} g_wpa_anonymous_identity = NULL; g_wpa_anonymous_identity_len = 0; }{ ... } #define USERNAME_LEN_MAX 128 esp_err_t esp_eap_client_set_username(const unsigned char *username, int len) { if (len <= 0 || len > USERNAME_LEN_MAX) { return ESP_ERR_INVALID_ARG; }{...} if (g_wpa_username) { os_free(g_wpa_username); g_wpa_username = NULL; }{...} g_wpa_username = (u8 *)os_zalloc(len); if (g_wpa_username == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_username, username, len); g_wpa_username_len = len; return ESP_OK; }{ ... } void esp_eap_client_clear_username(void) { if (g_wpa_username) { os_free(g_wpa_username); }{...} g_wpa_username = NULL; g_wpa_username_len = 0; }{ ... } esp_err_t esp_eap_client_set_password(const unsigned char *password, int len) { if (len <= 0) { return ESP_ERR_INVALID_ARG; }{...} if (g_wpa_password) { os_free(g_wpa_password); g_wpa_password = NULL; }{...} g_wpa_password = (u8 *)os_zalloc(len); if (g_wpa_password == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_password, password, len); g_wpa_password_len = len; return ESP_OK; }{ ... } void esp_eap_client_clear_password(void) { if (g_wpa_password) { os_free(g_wpa_password); }{...} g_wpa_password = NULL; g_wpa_password_len = 0; }{ ... } esp_err_t esp_eap_client_set_new_password(const unsigned char *new_password, int len) { if (len <= 0) { return ESP_ERR_INVALID_ARG; }{...} if (g_wpa_new_password) { os_free(g_wpa_new_password); g_wpa_new_password = NULL; }{...} g_wpa_new_password = (u8 *)os_zalloc(len); if (g_wpa_new_password == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_new_password, new_password, len); g_wpa_password_len = len; return ESP_OK; }{ ... } void esp_eap_client_clear_new_password(void) { if (g_wpa_new_password) { os_free(g_wpa_new_password); }{...} g_wpa_new_password = NULL; g_wpa_new_password_len = 0; }{ ... } esp_err_t esp_eap_client_set_disable_time_check(bool disable) { s_disable_time_check = disable; return ESP_OK; }{ ... } bool wifi_sta_get_enterprise_disable_time_check(void) { return s_disable_time_check; }{ ... } esp_err_t esp_eap_client_get_disable_time_check(bool *disable) { *disable = wifi_sta_get_enterprise_disable_time_check(); return ESP_OK; }{ ... } esp_err_t esp_eap_client_set_ttls_phase2_method(esp_eap_ttls_phase2_types type) { switch (type) { case ESP_EAP_TTLS_PHASE2_EAP: g_wpa_ttls_phase2_type = "auth=EAP"; break;... case ESP_EAP_TTLS_PHASE2_MSCHAPV2: g_wpa_ttls_phase2_type = "auth=MSCHAPV2"; break;... case ESP_EAP_TTLS_PHASE2_MSCHAP: g_wpa_ttls_phase2_type = "auth=MSCHAP"; break;... case ESP_EAP_TTLS_PHASE2_PAP: g_wpa_ttls_phase2_type = "auth=PAP"; break;... case ESP_EAP_TTLS_PHASE2_CHAP: g_wpa_ttls_phase2_type = "auth=CHAP"; break;... default: g_wpa_ttls_phase2_type = "auth=MSCHAPV2"; break;... }{...} return ESP_OK; }{ ... } esp_err_t esp_eap_client_set_suiteb_192bit_certification(bool enable) { #ifdef CONFIG_SUITEB192 g_wpa_suiteb_certification = enable; return ESP_OK;/* ... */ #else return ESP_FAIL; #endif }{ ... } esp_err_t esp_eap_client_set_pac_file(const unsigned char *pac_file, int pac_file_len) { if (pac_file && pac_file_len > -1) { if (pac_file_len < 512) { // The file contains less than 1 pac and is to be rewritten later g_wpa_pac_file = (u8 *)os_zalloc(512); if (g_wpa_pac_file == NULL) { return ESP_ERR_NO_MEM; }{...} g_wpa_pac_file_len = 0; }{...} else { // The file contains pac data g_wpa_pac_file = (u8 *)os_zalloc(pac_file_len); if (g_wpa_pac_file == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_pac_file, pac_file, pac_file_len); g_wpa_pac_file_len = pac_file_len; }{...} }{...} else { return ESP_FAIL; }{...} return ESP_OK; }{ ... } esp_err_t esp_eap_client_set_fast_params(esp_eap_fast_config config) { char config_for_supplicant[PHASE1_PARAM_STRING_LEN] = ""; if ((config.fast_provisioning > -1) && (config.fast_provisioning <= 2)) { os_snprintf((char *) &config_for_supplicant, PHASE1_PARAM_STRING_LEN, "fast_provisioning=%d ", config.fast_provisioning); }{...} else { return ESP_ERR_INVALID_ARG; }{...} if (config.fast_max_pac_list_len && config.fast_max_pac_list_len < 100) { os_snprintf((char *) &config_for_supplicant + strlen(config_for_supplicant), PHASE1_PARAM_STRING_LEN - strlen(config_for_supplicant), "fast_max_pac_list_len=%d ", config.fast_max_pac_list_len); }{...} else if (config.fast_max_pac_list_len >= 100) { return ESP_ERR_INVALID_ARG; }{...} if (config.fast_pac_format_binary) { os_strcat((char *) &config_for_supplicant, (const char *) "fast_pac_format=binary"); }{...} // Free the old buffer if it already exists if (g_wpa_phase1_options != NULL) { os_free(g_wpa_phase1_options); }{...} g_wpa_phase1_options = (char *)os_zalloc(sizeof(config_for_supplicant)); if (g_wpa_phase1_options == NULL) { return ESP_ERR_NO_MEM; }{...} os_memcpy(g_wpa_phase1_options, &config_for_supplicant, sizeof(config_for_supplicant)); return ESP_OK; }{ ... } esp_err_t esp_eap_client_use_default_cert_bundle(bool use_default_bundle) { #ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE g_wpa_default_cert_bundle = use_default_bundle; if (use_default_bundle) { esp_crt_bundle_attach_fn = esp_crt_bundle_attach; }{...} else { esp_crt_bundle_attach_fn = NULL; }{...} return ESP_OK;/* ... */ #else return ESP_FAIL; #endif }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.