From 32db8fc4552a590785fbd265a2f0b25287dc2ba2 Mon Sep 17 00:00:00 2001 From: Bruin06 <419738327@qq.com> Date: Sat, 21 Jun 2025 17:25:04 +0800 Subject: [PATCH 1/2] update wap_supplicant ext ability Signed-off-by: Bruin06 <419738327@qq.com> --- .../src/eap_common/ext_authentication.c | 13 ++++++++++++- .../src/eap_common/ext_authentication.h | 8 ++++---- .../src/eap_peer/eap.c | 9 +++++++-- .../src/eapol_supp/eapol_supp_sm.c | 11 ++++++++--- .../wpa_supplicant/ctrl_iface.c | 19 +++++++------------ 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c index d2af5f8..93c3b1b 100644 --- a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c +++ b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c @@ -21,6 +21,15 @@ const char *g_ifnameToString[] = { "eth0" }; +const char *ifname_to_string(int ifname) +{ + if (ifname <= IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification ifname_to_string : ifname : %d", ifname); + return g_ifnameToString[0]; + } + return g_ifnameToString[ifname]; +} + bool reg_ext_auth(int code, int type, int ifname) { wpa_printf(MSG_INFO, "ext_certification reg_ext_auth : code : %d , type : %d, ifname : %d", code, type, ifname); @@ -128,7 +137,7 @@ struct eap_sm* get_eap_sm() static struct encrypt_data g_encryptData; void set_encrypt_data(struct eap_ssl_data *ssl, int eapType, int version, unsigned char id) { - wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_data : eapType : %d , version : %d", eapType, + wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_data : eapType : %d , version : %d, id : %hhu", eapType, vertion, (u8)id); g_encryptData.ssl = ssl; g_encryptData.eapType = eapType; @@ -151,11 +160,13 @@ int g_code = 0; int get_code() { + wpa_printf(MSG_DEBUG, "ext_certification get_code : code : %d", g_code); return g_code; } void set_code(int code) { + wpa_printf(MSG_DEBUG, "ext_certification set_code : code : %d", code); g_code = code; } diff --git a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h index 1de63b2..0d401c3 100644 --- a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h +++ b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h @@ -21,11 +21,11 @@ enum Ifname { IFNAME_SIZE = 3 }; - extern const char* g_ifnameToString[]; +const char *ifname_to_string(int ifname); - bool reg_ext_auth(int code, int type, int ifname); - bool un_reg_ext_auth(int code, int type); - int get_ext_auth(int code, int type); +bool reg_ext_auth(int code, int type, int ifname); +bool un_reg_ext_auth(int code, int type); +int get_ext_auth(int code, int type); // 递增的数字标识符 int get_authentication_idx(); diff --git a/wpa_supplicant-2.9_standard/src/eap_peer/eap.c b/wpa_supplicant-2.9_standard/src/eap_peer/eap.c index f1b5b24..77b92ce 100644 --- a/wpa_supplicant-2.9_standard/src/eap_peer/eap.c +++ b/wpa_supplicant-2.9_standard/src/eap_peer/eap.c @@ -908,7 +908,12 @@ static void tx_ext_certification(STATE_MACHINE_DATA *sm) wpa_printf(MSG_DEBUG, "ext_certification tx_ext_certification %u:2:%d", get_authentication_idx(), sm->eapRespData->buf[TYPE_OFFSET]); int ifname = get_ext_auth(EAP_CODE_RESPONSE, (int)(sm->eapRespData->buf[TYPE_OFFSET])); - if (ifname == IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + if (ifname == IFNAME_UNKNOWN) { + eapol_set_bool(sm, EAPOL_eapResp, true); + return; + } + if (ifname < IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification tx_ext_certification ifname error : %d", ifname); eapol_set_bool(sm, EAPOL_eapResp, true); return; } @@ -937,7 +942,7 @@ static void tx_ext_certification(STATE_MACHINE_DATA *sm) return; } - WpaEventReport(g_ifnameToString[ifname], WPA_EVENT_STA_NOTIFY, (void *) param); + WpaEventReport(ifname_to_string(ifname), WPA_EVENT_STA_NOTIFY, (void *) param); clear_eap_data(); eapol_set_bool(sm, EAPOL_eapResp, false); #endif diff --git a/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c b/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c index 94f27bd..ecd6c88 100644 --- a/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c +++ b/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c @@ -1180,7 +1180,12 @@ static void rx_ext_certification(struct eapol_sm *sm) wpa_printf(MSG_DEBUG, "ext_certification rx_ext_certification %u:1:%d", get_authentication_idx(), sm->eapReqData->buf[TYPE_OFFSET]); int ifname = get_ext_auth(EAP_CODE_REQUEST, (int)(sm->eapReqData->buf[TYPE_OFFSET])); - if (ifname == IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + if (ifname == IFNAME_UNKNOWN) { + eapol_sm_step(sm); + return; + } + if (ifname < IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification ifname error : %d", ifname); eapol_sm_step(sm); return; } @@ -1188,7 +1193,7 @@ static void rx_ext_certification(struct eapol_sm *sm) set_eap_sm(sm); size_t length = PARAM_LEN + (size_t)((sm->eapReqData->size + BASE64_NUM - 1) / BASE64_NUM * (BASE64_NUM + 1)); if (length > BUF_SIZE) { - wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification ptr is NULL"); + wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification length error"); return; } #ifdef CONFIG_LIBWPA_VENDOR @@ -1206,7 +1211,7 @@ static void rx_ext_certification(struct eapol_sm *sm) return; } free(base64Parm); - WpaEventReport(g_ifnameToString[ifname], WPA_EVENT_STA_NOTIFY, (void *)param); + WpaEventReport(ifname_to_string(ifname), WPA_EVENT_STA_NOTIFY, (void *)param); #endif } #endif /* EXT_AUTHENTICATION_SUPPORT */ diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c index b6cc3ff..f0e857b 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c @@ -12821,9 +12821,9 @@ static int ext_auth_reg(char *params) if (datas != NULL) { // 输出解析结果 for (int i = 0; i < count; ++i) { - int value = datas[i]; - uint type = ((int64_t)value) & ((1 << EXT_OFFSET) - 1); - uint code = ((int64_t)value) >> EXT_OFFSET; + uint value = (uint)datas[i]; + uint type = value & ((1 << EXT_OFFSET) - 1); + uint code = value >> EXT_OFFSET; wpa_printf(MSG_DEBUG, "ext_certification EXT_AUTH_REG_PREFIX: value: %d, %u, %u", value, type, code); reg_ext_auth(code, type, ifname); } @@ -12843,9 +12843,9 @@ static int ext_auth_unreg(char *params) if (datas != NULL) { // 输出解析结果 for (int i = 0; i < count; ++i) { - int value = datas[i]; - uint type = ((int64_t)value) & ((1 << EXT_OFFSET) - 1); - uint code = ((int64_t)value) >> EXT_OFFSET; + uint value = (uint)datas[i]; + uint type = value & ((1 << EXT_OFFSET) - 1); + uint code = value >> EXT_OFFSET; wpa_printf(MSG_DEBUG, "ext_certification EXT_AUTH_UNREG_PREFIX_SIZE: value: %d, %u, %u", value, type, code); un_reg_ext_auth(code, type); @@ -12866,11 +12866,6 @@ static int ext_auth_data_inner(struct wpa_supplicant * wpa_s, u8* dataBuf, int r eapol_sm_notify_eap_fail(wpa_s->eapol, true); return 0; } - if (result == EXT_AUTH_FINISH) { - wpa_printf(MSG_DEBUG, "ext_auth_data_inner EXT_AUTH_FINISH"); - eapol_sm_notify_eap_success(wpa_s->eapol, true); - return 0; - } // 修改sm if (code == EAP_CODE_REQUEST) { wpa_printf(MSG_DEBUG, "ext_certification code = EAP_CODE_REQUEST"); @@ -12926,7 +12921,7 @@ static int ext_auth_data(struct wpa_supplicant *wpa_s, char *params) size_t count = 0; u8* databuf = base64_decode(params + startIdx, strlen(params + startIdx), &count); - bool illegal = (count != bufferLen) || (get_authentication_idx() != (int)idx) ||(dataBuf == NULL); + bool illegal = (count != bufferLen) || (get_authentication_idx() != (int)idx) || (dataBuf == NULL); if (illegal) { os_free(dataBuf); dataBuf = NULL; -- Gitee From 5a00d41ec0530094de3fa98bdcca6fae4b4b44d4 Mon Sep 17 00:00:00 2001 From: Bruin06 <419738327@qq.com> Date: Sat, 21 Jun 2025 17:25:04 +0800 Subject: [PATCH 2/2] update wap_supplicant ext ability Signed-off-by: Bruin06 <419738327@qq.com> --- .../src/eap_common/ext_authentication.c | 13 ++++++++++++- .../src/eap_common/ext_authentication.h | 10 +++++----- .../src/eap_peer/eap.c | 9 +++++++-- .../src/eapol_supp/eapol_supp_sm.c | 11 ++++++++--- .../wpa_supplicant/ctrl_iface.c | 19 +++++++------------ 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c index d2af5f8..93c3b1b 100644 --- a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c +++ b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.c @@ -21,6 +21,15 @@ const char *g_ifnameToString[] = { "eth0" }; +const char *ifname_to_string(int ifname) +{ + if (ifname <= IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification ifname_to_string : ifname : %d", ifname); + return g_ifnameToString[0]; + } + return g_ifnameToString[ifname]; +} + bool reg_ext_auth(int code, int type, int ifname) { wpa_printf(MSG_INFO, "ext_certification reg_ext_auth : code : %d , type : %d, ifname : %d", code, type, ifname); @@ -128,7 +137,7 @@ struct eap_sm* get_eap_sm() static struct encrypt_data g_encryptData; void set_encrypt_data(struct eap_ssl_data *ssl, int eapType, int version, unsigned char id) { - wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_data : eapType : %d , version : %d", eapType, + wpa_printf(MSG_DEBUG, "ext_certification set_encrypt_data : eapType : %d , version : %d, id : %hhu", eapType, vertion, (u8)id); g_encryptData.ssl = ssl; g_encryptData.eapType = eapType; @@ -151,11 +160,13 @@ int g_code = 0; int get_code() { + wpa_printf(MSG_DEBUG, "ext_certification get_code : code : %d", g_code); return g_code; } void set_code(int code) { + wpa_printf(MSG_DEBUG, "ext_certification set_code : code : %d", code); g_code = code; } diff --git a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h index 1de63b2..ba5d71d 100644 --- a/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h +++ b/wpa_supplicant-2.9_standard/src/eap_common/ext_authentication.h @@ -21,11 +21,11 @@ enum Ifname { IFNAME_SIZE = 3 }; - extern const char* g_ifnameToString[]; +const char *ifname_to_string(int ifname); - bool reg_ext_auth(int code, int type, int ifname); - bool un_reg_ext_auth(int code, int type); - int get_ext_auth(int code, int type); +bool reg_ext_auth(int code, int type, int ifname); +bool un_reg_ext_auth(int code, int type); +int get_ext_auth(int code, int type); // 递增的数字标识符 int get_authentication_idx(); @@ -37,7 +37,7 @@ void clear_eap_data(); void set_eap_data(uint8_t* eapData, int eapDataLen); struct eap_sm; -void set_eap_sm(struct eap *eapSm); +void set_eap_sm(struct eap_sm *eapSm); struct eap_sm* get_eap_sm(); struct eap_ssl_data; diff --git a/wpa_supplicant-2.9_standard/src/eap_peer/eap.c b/wpa_supplicant-2.9_standard/src/eap_peer/eap.c index f1b5b24..77b92ce 100644 --- a/wpa_supplicant-2.9_standard/src/eap_peer/eap.c +++ b/wpa_supplicant-2.9_standard/src/eap_peer/eap.c @@ -908,7 +908,12 @@ static void tx_ext_certification(STATE_MACHINE_DATA *sm) wpa_printf(MSG_DEBUG, "ext_certification tx_ext_certification %u:2:%d", get_authentication_idx(), sm->eapRespData->buf[TYPE_OFFSET]); int ifname = get_ext_auth(EAP_CODE_RESPONSE, (int)(sm->eapRespData->buf[TYPE_OFFSET])); - if (ifname == IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + if (ifname == IFNAME_UNKNOWN) { + eapol_set_bool(sm, EAPOL_eapResp, true); + return; + } + if (ifname < IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification tx_ext_certification ifname error : %d", ifname); eapol_set_bool(sm, EAPOL_eapResp, true); return; } @@ -937,7 +942,7 @@ static void tx_ext_certification(STATE_MACHINE_DATA *sm) return; } - WpaEventReport(g_ifnameToString[ifname], WPA_EVENT_STA_NOTIFY, (void *) param); + WpaEventReport(ifname_to_string(ifname), WPA_EVENT_STA_NOTIFY, (void *) param); clear_eap_data(); eapol_set_bool(sm, EAPOL_eapResp, false); #endif diff --git a/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c b/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c index 94f27bd..ecd6c88 100644 --- a/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c +++ b/wpa_supplicant-2.9_standard/src/eapol_supp/eapol_supp_sm.c @@ -1180,7 +1180,12 @@ static void rx_ext_certification(struct eapol_sm *sm) wpa_printf(MSG_DEBUG, "ext_certification rx_ext_certification %u:1:%d", get_authentication_idx(), sm->eapReqData->buf[TYPE_OFFSET]); int ifname = get_ext_auth(EAP_CODE_REQUEST, (int)(sm->eapReqData->buf[TYPE_OFFSET])); - if (ifname == IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + if (ifname == IFNAME_UNKNOWN) { + eapol_sm_step(sm); + return; + } + if (ifname < IFNAME_UNKNOWN || ifname >= IFNAME_SIZE) { + wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification ifname error : %d", ifname); eapol_sm_step(sm); return; } @@ -1188,7 +1193,7 @@ static void rx_ext_certification(struct eapol_sm *sm) set_eap_sm(sm); size_t length = PARAM_LEN + (size_t)((sm->eapReqData->size + BASE64_NUM - 1) / BASE64_NUM * (BASE64_NUM + 1)); if (length > BUF_SIZE) { - wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification ptr is NULL"); + wpa_printf(MSG_ERROR, "ext_certification rx_ext_certification length error"); return; } #ifdef CONFIG_LIBWPA_VENDOR @@ -1206,7 +1211,7 @@ static void rx_ext_certification(struct eapol_sm *sm) return; } free(base64Parm); - WpaEventReport(g_ifnameToString[ifname], WPA_EVENT_STA_NOTIFY, (void *)param); + WpaEventReport(ifname_to_string(ifname), WPA_EVENT_STA_NOTIFY, (void *)param); #endif } #endif /* EXT_AUTHENTICATION_SUPPORT */ diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c index b6cc3ff..f0e857b 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c @@ -12821,9 +12821,9 @@ static int ext_auth_reg(char *params) if (datas != NULL) { // 输出解析结果 for (int i = 0; i < count; ++i) { - int value = datas[i]; - uint type = ((int64_t)value) & ((1 << EXT_OFFSET) - 1); - uint code = ((int64_t)value) >> EXT_OFFSET; + uint value = (uint)datas[i]; + uint type = value & ((1 << EXT_OFFSET) - 1); + uint code = value >> EXT_OFFSET; wpa_printf(MSG_DEBUG, "ext_certification EXT_AUTH_REG_PREFIX: value: %d, %u, %u", value, type, code); reg_ext_auth(code, type, ifname); } @@ -12843,9 +12843,9 @@ static int ext_auth_unreg(char *params) if (datas != NULL) { // 输出解析结果 for (int i = 0; i < count; ++i) { - int value = datas[i]; - uint type = ((int64_t)value) & ((1 << EXT_OFFSET) - 1); - uint code = ((int64_t)value) >> EXT_OFFSET; + uint value = (uint)datas[i]; + uint type = value & ((1 << EXT_OFFSET) - 1); + uint code = value >> EXT_OFFSET; wpa_printf(MSG_DEBUG, "ext_certification EXT_AUTH_UNREG_PREFIX_SIZE: value: %d, %u, %u", value, type, code); un_reg_ext_auth(code, type); @@ -12866,11 +12866,6 @@ static int ext_auth_data_inner(struct wpa_supplicant * wpa_s, u8* dataBuf, int r eapol_sm_notify_eap_fail(wpa_s->eapol, true); return 0; } - if (result == EXT_AUTH_FINISH) { - wpa_printf(MSG_DEBUG, "ext_auth_data_inner EXT_AUTH_FINISH"); - eapol_sm_notify_eap_success(wpa_s->eapol, true); - return 0; - } // 修改sm if (code == EAP_CODE_REQUEST) { wpa_printf(MSG_DEBUG, "ext_certification code = EAP_CODE_REQUEST"); @@ -12926,7 +12921,7 @@ static int ext_auth_data(struct wpa_supplicant *wpa_s, char *params) size_t count = 0; u8* databuf = base64_decode(params + startIdx, strlen(params + startIdx), &count); - bool illegal = (count != bufferLen) || (get_authentication_idx() != (int)idx) ||(dataBuf == NULL); + bool illegal = (count != bufferLen) || (get_authentication_idx() != (int)idx) || (dataBuf == NULL); if (illegal) { os_free(dataBuf); dataBuf = NULL; -- Gitee