Skip to content

Commit 6153c6d

Browse files
authored
Changes to support PAC and 802.1X interaction (#89)
#Why I did it These changes are done to support the interaction between PAC and the 8021.X which is in sonic-wpasupplicant. #How I did it #How to verify it
1 parent 3c7fd8e commit 6153c6d

File tree

8 files changed

+101
-4
lines changed

8 files changed

+101
-4
lines changed

hostapd/ctrl_iface.c

+3
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,9 @@ static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data *hapd,
27732773
if (!sta || !sta->eapol_sm)
27742774
return -1;
27752775

2776+
#ifdef CONFIG_SONIC_HOSTAPD
2777+
memset(&sta->attr_info, 0, sizeof (sta->attr_info));
2778+
#endif
27762779
eapol_auth_reauthenticate(sta->eapol_sm);
27772780
return 0;
27782781
}

src/ap/ieee802_1x.c

+56-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include "common/ieee802_11_defs.h"
2020
#include "radius/radius.h"
2121
#include "radius/radius_client.h"
22+
#ifdef CONFIG_SONIC_RADIUS
23+
#include "radius/radius_attr_parse.h"
24+
#endif
2225
#include "eap_server/eap.h"
2326
#include "eap_common/eap_wsc_common.h"
2427
#include "eapol_auth/eapol_auth_sm.h"
@@ -460,6 +463,7 @@ static int add_common_radius_sta_attr(struct hostapd_data *hapd,
460463
return -1;
461464
}
462465

466+
#ifndef CONFIG_SONIC_RADIUS
463467
if (sta->flags & WLAN_STA_PREAUTH) {
464468
os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
465469
sizeof(buf));
@@ -487,6 +491,7 @@ static int add_common_radius_sta_attr(struct hostapd_data *hapd,
487491
return -1;
488492
}
489493
}
494+
#endif
490495

491496
if ((hapd->conf->wpa & 2) &&
492497
!hapd->conf->disable_pmksa_caching &&
@@ -565,8 +570,13 @@ int add_common_radius_attr(struct hostapd_data *hapd,
565570
return -1;
566571
}
567572

573+
#ifdef CONFIG_SONIC_RADIUS
574+
len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
575+
MAC2STR(hapd->own_addr));
576+
#else
568577
len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
569578
MAC2STR(hapd->own_addr));
579+
#endif
570580
os_memcpy(&buf[len], hapd->conf->ssid.ssid,
571581
hapd->conf->ssid.ssid_len);
572582
len += hapd->conf->ssid.ssid_len;
@@ -708,7 +718,13 @@ void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
708718
wpa_printf(MSG_INFO, "Could not add User-Name");
709719
goto fail;
710720
}
711-
721+
#ifdef CONFIG_SONIC_RADIUS
722+
else {
723+
memset(sta->attr_info.userName,'\0', sizeof(sta->attr_info.userName));
724+
strncpy(sta->attr_info.userName, sm->identity, sm->identity_len);
725+
sta->attr_info.userNameLen = sm->identity_len;
726+
}
727+
#endif
712728
if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
713729
msg) < 0)
714730
goto fail;
@@ -1183,6 +1199,19 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
11831199
sta->eapol_sm->eapolLogoff = true;
11841200
sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
11851201
eap_server_clear_identity(sta->eapol_sm->eap);
1202+
1203+
#ifdef CONFIG_SONIC_HOSTAPD
1204+
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1205+
HOSTAPD_LEVEL_DEBUG,
1206+
"sending client_disconnect for EAPOL-Logoff from STA");
1207+
/* Inform PAC */
1208+
if (0 != hostapd_drv_auth_resp_send(hapd, hapd->conf->iface, sta->addr, "client_disconnected", NULL))
1209+
{
1210+
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1211+
HOSTAPD_LEVEL_DEBUG,
1212+
"sending client_disconnect for EAPOL-Logoff from STA not successful");
1213+
}
1214+
#endif
11861215
break;
11871216

11881217
case IEEE802_1X_TYPE_EAPOL_KEY:
@@ -2006,6 +2035,14 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
20062035
break;
20072036
#endif /* CONFIG_NO_VLAN */
20082037

2038+
#ifdef CONFIG_SONIC_RADIUS
2039+
if (0 != radiusClientAcceptProcess(msg, &sta->attr_info))
2040+
{
2041+
wpa_printf(MSG_DEBUG, "radiusClientAcceptProcess failed \n");
2042+
}
2043+
#endif
2044+
2045+
#ifndef CONFIG_SONIC_RADIUS
20092046
sta->session_timeout_set = !!session_timeout_set;
20102047
os_get_reltime(&sta->session_timeout);
20112048
sta->session_timeout.sec += session_timeout;
@@ -2018,6 +2055,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
20182055
ap_sta_session_timeout(hapd, sta, session_timeout);
20192056
else
20202057
ap_sta_no_session_timeout(hapd, sta);
2058+
#endif
20212059

20222060
sm->eap_if->aaaSuccess = true;
20232061
override_eapReq = 1;
@@ -2110,6 +2148,11 @@ void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
21102148
MAC2STR(sta->addr));
21112149

21122150
sm->eap_if->portEnabled = false;
2151+
#ifdef CONFIG_SONIC_RADIUS
2152+
/* Invoke driver to inform PAC */
2153+
hostapd_drv_auth_resp_send(hapd, hapd->conf->iface, sta->addr,
2154+
"auth_timeout", (void *) sta);
2155+
#endif
21132156
ap_sta_disconnect(hapd, sta, sta->addr,
21142157
WLAN_REASON_PREV_AUTH_NOT_VALID);
21152158
}
@@ -2998,5 +3041,16 @@ static void ieee802_1x_finished(struct hostapd_data *hapd,
29983041
* EAPOL authentication to be started to complete connection.
29993042
*/
30003043
ap_sta_delayed_1x_auth_fail_disconnect(hapd, sta);
3001-
}
3044+
3045+
#ifdef CONFIG_SONIC_HOSTAPD
3046+
/* Invoke driver to inform PAC */
3047+
hostapd_drv_auth_resp_send(hapd, hapd->conf->iface, sta->addr, "auth_fail", (void *) sta);
3048+
#endif
3049+
}
3050+
#ifdef CONFIG_SONIC_HOSTAPD
3051+
else {
3052+
/* Invoke driver to inform PAC */
3053+
hostapd_drv_auth_resp_send(hapd, hapd->conf->iface, sta->addr, "auth_success", (void *) sta);
3054+
}
3055+
#endif
30023056
}

src/eap_server/eap.h

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ struct eap_eapol_interface {
8282
struct wpabuf *aaaEapRespData;
8383
/* aaaIdentity -> eap_get_identity() */
8484
bool aaaTimeout;
85+
#ifdef CONFIG_SONIC_HOSTAPD
86+
bool client_reauth;
87+
#endif
8588
};
8689

8790
struct eap_server_erp_key {

src/eap_server/eap_server.c

+10
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ SM_STATE(EAP, INITIALIZE)
231231
}
232232

233233
sm->try_initiate_reauth = false;
234+
#ifdef CONFIG_SONIC_HOSTAPD
235+
if (!sm->eap_if.client_reauth)
236+
sm->currentId = -1;
237+
#else
234238
sm->currentId = -1;
239+
#endif
235240
sm->eap_if.eapSuccess = false;
236241
sm->eap_if.eapFail = false;
237242
sm->eap_if.eapTimeout = false;
@@ -402,6 +407,11 @@ SM_STATE(EAP, METHOD_REQUEST)
402407
return;
403408
}
404409

410+
#ifdef CONFIG_SONIC_HOSTAPD
411+
wpa_printf(MSG_DEBUG, "EAP: lastId %d",
412+
sm->lastId);
413+
#endif
414+
405415
sm->currentId = eap_sm_nextId(sm, sm->currentId);
406416
wpa_printf(MSG_DEBUG, "EAP: building EAP-Request: Identifier %d",
407417
sm->currentId);

src/eapol_auth/eapol_auth_sm.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static void eapol_port_timers_tick(void *eloop_ctx, void *timeout_ctx)
168168
}
169169
}
170170

171+
#ifndef CONFIG_SONIC_HOSTAPD
171172
if (state->reAuthWhen > 0) {
172173
state->reAuthWhen--;
173174
if (state->reAuthWhen == 0) {
@@ -176,6 +177,7 @@ static void eapol_port_timers_tick(void *eloop_ctx, void *timeout_ctx)
176177
MAC2STR(state->addr));
177178
}
178179
}
180+
#endif
179181

180182
if (state->eap_if->retransWhile > 0) {
181183
state->eap_if->retransWhile--;
@@ -241,13 +243,25 @@ SM_STATE(AUTH_PAE, DISCONNECTED)
241243

242244
SM_STATE(AUTH_PAE, RESTART)
243245
{
246+
#ifdef CONFIG_SONIC_HOSTAPD
247+
#ifdef HOSTAPD
248+
sm->eap_if->client_reauth = false;
249+
#endif
250+
#endif
244251
if (sm->auth_pae_state == AUTH_PAE_AUTHENTICATED) {
245252
if (sm->reAuthenticate)
246253
sm->authAuthReauthsWhileAuthenticated++;
247254
if (sm->eapolStart)
248255
sm->authAuthEapStartsWhileAuthenticated++;
249256
if (sm->eapolLogoff)
250257
sm->authAuthEapLogoffWhileAuthenticated++;
258+
259+
#ifdef CONFIG_SONIC_HOSTAPD
260+
#ifdef HOSTAPD
261+
if (sm->reAuthenticate)
262+
sm->eap_if->client_reauth = true;
263+
#endif
264+
#endif
251265
}
252266

253267
SM_ENTRY_MA(AUTH_PAE, RESTART, auth_pae);
@@ -503,8 +517,9 @@ SM_STATE(BE_AUTH, RESPONSE)
503517
SM_STATE(BE_AUTH, SUCCESS)
504518
{
505519
SM_ENTRY_MA(BE_AUTH, SUCCESS, be_auth);
506-
520+
#ifndef CONFIG_SONIC_HOSTAPD
507521
txReq();
522+
#endif
508523
sm->authSuccess = true;
509524
sm->keyRun = true;
510525
}
@@ -513,8 +528,9 @@ SM_STATE(BE_AUTH, SUCCESS)
513528
SM_STATE(BE_AUTH, FAIL)
514529
{
515530
SM_ENTRY_MA(BE_AUTH, FAIL, be_auth);
516-
531+
#ifndef CONFIG_SONIC_HOSTAPD
517532
txReq();
533+
#endif
518534
sm->authFail = true;
519535
}
520536

src/eapol_auth/eapol_auth_sm.h

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
struct eapol_auth_config {
1818
const struct eap_config *eap_cfg;
1919
int eap_reauth_period;
20+
#ifdef CONFIG_SONIC_HOSTAPD
21+
int eap_server_timeout;
22+
int eap_quiet_period;
23+
#endif
2024
int wpa;
2125
int individual_wep_key_len;
2226
char *eap_req_id_text; /* a copy of this will be allocated */

src/eapol_auth/eapol_auth_sm_i.h

+4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ struct eapol_state_machine {
7373
unsigned int reAuthCount;
7474
/* constants */
7575
unsigned int quietPeriod; /* default 60; 0..65535 */
76+
#ifdef CONFIG_SONIC_HOSTAPD
77+
#define AUTH_PAE_DEFAULT_quietPeriod 2
78+
#else
7679
#define AUTH_PAE_DEFAULT_quietPeriod 60
80+
#endif
7781
unsigned int reAuthMax; /* default 2 */
7882
#define AUTH_PAE_DEFAULT_reAuthMax 2
7983
/* counters */

src/utils/wpa_debug.c

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ void wpa_printf(int level, const char *fmt, ...)
237237
va_start(ap, fmt);
238238
vprintf(fmt, ap);
239239
printf("\n");
240+
#ifdef CONFIG_SONIC_RADIUS
241+
fflush(stdout);
242+
#endif
240243
va_end(ap);
241244
}
242245
#endif /* CONFIG_ANDROID_LOG */

0 commit comments

Comments
 (0)