• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
3  */
4 #ifdef EXT_AUTHENTICATION_SUPPORT
5 #include "ext_authentication.h"
6 
7 #include "common.h"
8 #include "includes.h"
9 #include "securec.h"
10 #include "trace.h"
11 #include "wpa_debug.h"
12 
13 #define EXT_AUTH_CODE_SIZE 5
14 #define EAP_TYPE_SIZE 255
15 
16 static u8 g_authMap[EXT_AUTH_CODE_SIZE][EAP_TYPE_SIZE] = {0};
17 
18 const char *g_ifnameToString[] = {
19     "unkown",
20     "wlan0",
21     "eth0"
22 };
23 
reg_ext_auth(int code,int type,int ifname)24 bool reg_ext_auth(int code, int type, int ifname)
25 {
26     wpa_printf(MSG_INFO, "ext_certification reg_ext_auth : code : %d , type : %d, ifname : %d", code, type, ifname);
27     bool illegal = code < 1 || code >= EXT_AUTH_CODE_SIZE || type < 0 || type >= EAP_TYPE_SIZE || ifname < 0 ||
28         ifname >= IFNAME_SIZE;
29     if (illegal) {
30         wpa_printf(MSG_ERROR, "ext_authentication reg_ext_auth : code : %d , type : %d, ifname : %d", code, type,
31             ifname);
32         return false;
33     }
34     g_authMap[code][type] = ifname;
35     return true;
36 }
37 
un_reg_ext_auth(int code,int type)38 bool un_reg_ext_auth(int code, int type)
39 {
40     wpa_printf(MSG_INFO, "ext_certification un_reg_ext_auth : code : %d , type : %d", code, type);
41     if (code < 1 || code >= EXT_AUTH_CODE_SIZE || type < 0 || type >= EAP_TYPE_SIZE) {
42         wpa_printf(MSG_ERROR, "ext_certification un_reg_ext_auth : code : %d , type : %d", code, type);
43         return false;
44     }
45     g_authMap[code][type] = IFNAME_UNKNOWN;
46     return true;
47 }
48 
get_ext_auth(int code,int type)49 int get_ext_auth(int code, int type)
50 {
51     wpa_printf(MSG_DEBUG, "ext_certification get_ext_auth : code : %d , type : %d, res : %d", code, type,
52         (int)g_authMap[code][type]);
53     if (code < 1 || code >= EXT_AUTH_CODE_SIZE || type < 0 || type >= EAP_TYPE_SIZE) {
54         wpa_printf(MSG_ERROR, "ext_authentication get_ext_auth : code : %d , type : %d", code, type);
55         return IFNAME_UNKNOWN;
56     }
57     return g_authMap[code][type];
58 }
59 
60 static int g_idx = 0;
61 
get_authentication_idx()62 int get_authentication_idx()
63 {
64     return g_idx;
65 }
66 
add_authentication_idx()67 void add_authentication_idx()
68 {
69     int idxMod = 100;
70     g_idx = (g_idx + 1) % idxMod;
71 }
72 
73 static uint8_t* g_eapData = NULL;
74 static int g_eapDataLen = 0;
75 
get_eap_data()76 uint8_t* get_eap_data()
77 {
78     return g_eapData;
79 }
80 
get_eap_data_len()81 int get_eap_data_len()
82 {
83     return g_eapDataLen;
84 }
85 
clear_eap_data()86 void clear_eap_data()
87 {
88     free(g_eapData);
89     g_eapData = NULL;
90     g_eapDataLen = 0;
91 }
92 
set_eap_data(u8 * eapData,int eapDataLen)93 void set_eap_data(u8* eapData, int eapDataLen)
94 {
95     if (eapData == NULL || eapDataLen <= 0) {
96         wpa_printf(MSG_ERROR, "set_eap_data input error");
97         return;
98     }
99     if (g_eapData != NULL) {
100         free(g_eapData); // 保险机制
101     }
102 
103     g_eapDataLen = eapDataLen;
104     g_eapData = (u8*)malloc(eapDataLen * sizeof(u8));
105     if (g_eapData == NULL) {
106         wpa_printf(MSG_ERROR, "set_eap_data malloc error");
107         return;
108     }
109     // 拷贝数据
110     if (memcpy_s(g_eapData, eapDataLen, eapData, eapDataLen) != 0) {
111         wpa_printf(MSG_ERROR, "set_eap_data memcpy_s error");
112         clear_eap_data();
113     }
114 }
115 
116 static struct eap_sm* g_eapSm = NULL;
117 
set_eap_sm(struct eap_sm * eapSm)118 void set_eap_sm(struct eap_sm *eapSm)
119 {
120     g_eapSm = eapSm;
121 }
122 
get_eap_sm()123 struct eap_sm* get_eap_sm()
124 {
125     return g_eapSm;
126 }
127 
128 static struct encrypt_data g_encryptData;
set_encrypt_data(struct eap_ssl_data * ssl,int eapType,int version,unsigned char id)129 void set_encrypt_data(struct eap_ssl_data *ssl, int eapType, int version, unsigned char id)
130 {
131     wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_data : eapType : %d , version : %d", eapType,
132         vertion, (u8)id);
133     g_encryptData.ssl = ssl;
134     g_encryptData.eapType = eapType;
135     g_encryptData.vertion = vertion;
136     g_encryptData.id = id;
137 }
138 
set_encrypt_eap_type(int eapType)139 void set_encrypt_eap_type(int eapType)
140 {
141     wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_eap_type : eapType : %d", eapType);
142     g_encryptData.eapType = eapType;
143 }
144 
get_encrypt_data()145 struct encrypt_data* get_encrypt_data()
146 {
147     return &g_encryptData;
148 }
149 
150 int g_code = 0;
151 
get_code()152 int get_code()
153 {
154     return g_code;
155 }
156 
set_code(int code)157 void set_code(int code)
158 {
159     g_code = code;
160 }
161 
162 #endif /* EXT_AUTHENTICATION_SUPPORT */