Use an enum for EAP SM requests

Control requests will be extended for non-EAP uses later, so it makes
sense to have them be generic. Furthermore, having them defined as an
enum is easier for processing internally, and more generic for control
interfaces that may not use field names. The public ctrl_req_type /
field_name conversion function will be used later by the D-Bus control
interface too.

Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
Dan Williams 2011-10-24 11:00:19 -05:00 committed by Jouni Malinen
parent af72d17e72
commit 9ef1aaae24
7 changed files with 95 additions and 39 deletions

View file

@ -267,4 +267,17 @@ enum hostapd_hw_mode {
NUM_HOSTAPD_MODES NUM_HOSTAPD_MODES
}; };
/**
* enum wpa_ctrl_req_type - Control interface request types
*/
enum wpa_ctrl_req_type {
WPA_CTRL_REQ_EAP_IDENTITY,
WPA_CTRL_REQ_EAP_PASSWORD,
WPA_CTRL_REQ_EAP_NEW_PASSWORD,
WPA_CTRL_REQ_EAP_PIN,
WPA_CTRL_REQ_EAP_OTP,
WPA_CTRL_REQ_EAP_PASSPHRASE,
NUM_WPA_CTRL_REQS
};
#endif /* DEFS_H */ #endif /* DEFS_H */

View file

@ -1468,16 +1468,11 @@ int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen, int verbose)
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
typedef enum { static void eap_sm_request(struct eap_sm *sm, enum wpa_ctrl_req_type field,
TYPE_IDENTITY, TYPE_PASSWORD, TYPE_OTP, TYPE_PIN, TYPE_NEW_PASSWORD,
TYPE_PASSPHRASE
} eap_ctrl_req_type;
static void eap_sm_request(struct eap_sm *sm, eap_ctrl_req_type type,
const char *msg, size_t msglen) const char *msg, size_t msglen)
{ {
struct eap_peer_config *config; struct eap_peer_config *config;
char *field, *txt, *tmp; char *txt = NULL, *tmp;
if (sm == NULL) if (sm == NULL)
return; return;
@ -1485,29 +1480,20 @@ static void eap_sm_request(struct eap_sm *sm, eap_ctrl_req_type type,
if (config == NULL) if (config == NULL)
return; return;
switch (type) { switch (field) {
case TYPE_IDENTITY: case WPA_CTRL_REQ_EAP_IDENTITY:
field = "IDENTITY";
txt = "Identity";
config->pending_req_identity++; config->pending_req_identity++;
break; break;
case TYPE_PASSWORD: case WPA_CTRL_REQ_EAP_PASSWORD:
field = "PASSWORD";
txt = "Password";
config->pending_req_password++; config->pending_req_password++;
break; break;
case TYPE_NEW_PASSWORD: case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
field = "NEW_PASSWORD";
txt = "New Password";
config->pending_req_new_password++; config->pending_req_new_password++;
break; break;
case TYPE_PIN: case WPA_CTRL_REQ_EAP_PIN:
field = "PIN";
txt = "PIN";
config->pending_req_pin++; config->pending_req_pin++;
break; break;
case TYPE_OTP: case WPA_CTRL_REQ_EAP_OTP:
field = "OTP";
if (msg) { if (msg) {
tmp = os_malloc(msglen + 3); tmp = os_malloc(msglen + 3);
if (tmp == NULL) if (tmp == NULL)
@ -1526,9 +1512,7 @@ static void eap_sm_request(struct eap_sm *sm, eap_ctrl_req_type type,
txt = config->pending_req_otp; txt = config->pending_req_otp;
} }
break; break;
case TYPE_PASSPHRASE: case WPA_CTRL_REQ_EAP_PASSPHRASE:
field = "PASSPHRASE";
txt = "Private key passphrase";
config->pending_req_passphrase++; config->pending_req_passphrase++;
break; break;
default: default:
@ -1561,7 +1545,7 @@ const char * eap_sm_get_method_name(struct eap_sm *sm)
*/ */
void eap_sm_request_identity(struct eap_sm *sm) void eap_sm_request_identity(struct eap_sm *sm)
{ {
eap_sm_request(sm, TYPE_IDENTITY, NULL, 0); eap_sm_request(sm, WPA_CTRL_REQ_EAP_IDENTITY, NULL, 0);
} }
@ -1576,7 +1560,7 @@ void eap_sm_request_identity(struct eap_sm *sm)
*/ */
void eap_sm_request_password(struct eap_sm *sm) void eap_sm_request_password(struct eap_sm *sm)
{ {
eap_sm_request(sm, TYPE_PASSWORD, NULL, 0); eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSWORD, NULL, 0);
} }
@ -1591,7 +1575,7 @@ void eap_sm_request_password(struct eap_sm *sm)
*/ */
void eap_sm_request_new_password(struct eap_sm *sm) void eap_sm_request_new_password(struct eap_sm *sm)
{ {
eap_sm_request(sm, TYPE_NEW_PASSWORD, NULL, 0); eap_sm_request(sm, WPA_CTRL_REQ_EAP_NEW_PASSWORD, NULL, 0);
} }
@ -1606,7 +1590,7 @@ void eap_sm_request_new_password(struct eap_sm *sm)
*/ */
void eap_sm_request_pin(struct eap_sm *sm) void eap_sm_request_pin(struct eap_sm *sm)
{ {
eap_sm_request(sm, TYPE_PIN, NULL, 0); eap_sm_request(sm, WPA_CTRL_REQ_EAP_PIN, NULL, 0);
} }
@ -1622,7 +1606,7 @@ void eap_sm_request_pin(struct eap_sm *sm)
*/ */
void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len) void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
{ {
eap_sm_request(sm, TYPE_OTP, msg, msg_len); eap_sm_request(sm, WPA_CTRL_REQ_EAP_OTP, msg, msg_len);
} }
@ -1637,7 +1621,7 @@ void eap_sm_request_otp(struct eap_sm *sm, const char *msg, size_t msg_len)
*/ */
void eap_sm_request_passphrase(struct eap_sm *sm) void eap_sm_request_passphrase(struct eap_sm *sm)
{ {
eap_sm_request(sm, TYPE_PASSPHRASE, NULL, 0); eap_sm_request(sm, WPA_CTRL_REQ_EAP_PASSPHRASE, NULL, 0);
} }

View file

@ -216,10 +216,10 @@ struct eapol_callbacks {
/** /**
* eap_param_needed - Notify that EAP parameter is needed * eap_param_needed - Notify that EAP parameter is needed
* @ctx: eapol_ctx from eap_peer_sm_init() call * @ctx: eapol_ctx from eap_peer_sm_init() call
* @field: Field name (e.g., "IDENTITY") * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
* @txt: User readable text describing the required parameter * @txt: User readable text describing the required parameter
*/ */
void (*eap_param_needed)(void *ctx, const char *field, void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
const char *txt); const char *txt);
/** /**

View file

@ -1813,7 +1813,7 @@ static void eapol_sm_notify_pending(void *ctx)
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
static void eapol_sm_eap_param_needed(void *ctx, const char *field, static void eapol_sm_eap_param_needed(void *ctx, enum wpa_ctrl_req_type field,
const char *txt) const char *txt)
{ {
struct eapol_sm *sm = ctx; struct eapol_sm *sm = ctx;

View file

@ -208,10 +208,10 @@ struct eapol_ctx {
/** /**
* eap_param_needed - Notify that EAP parameter is needed * eap_param_needed - Notify that EAP parameter is needed
* @ctx: Callback context (ctx) * @ctx: Callback context (ctx)
* @field: Field name (e.g., "IDENTITY") * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
* @txt: User readable text describing the required parameter * @txt: User readable text describing the required parameter
*/ */
void (*eap_param_needed)(void *ctx, const char *field, void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
const char *txt); const char *txt);
/** /**

View file

@ -587,13 +587,60 @@ static int wpa_supplicant_tdls_peer_addset(
#endif /* CONFIG_TDLS */ #endif /* CONFIG_TDLS */
const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
const char *default_txt,
const char **txt)
{
const char *ret = NULL;
*txt = default_txt;
switch (field) {
case WPA_CTRL_REQ_EAP_IDENTITY:
*txt = "Identity";
ret = "IDENTITY";
break;
case WPA_CTRL_REQ_EAP_PASSWORD:
*txt = "Password";
ret = "PASSWORD";
break;
case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
*txt = "New Password";
ret = "NEW_PASSWORD";
break;
case WPA_CTRL_REQ_EAP_PIN:
*txt = "PIN";
ret = "PIN";
break;
case WPA_CTRL_REQ_EAP_OTP:
ret = "OTP";
break;
case WPA_CTRL_REQ_EAP_PASSPHRASE:
*txt = "Private key passphrase";
ret = "PASSPHRASE";
break;
default:
break;
}
/* txt needs to be something */
if (*txt == NULL) {
wpa_printf(MSG_WARNING, "No message for request %d", field);
ret = NULL;
}
return ret;
}
#ifdef IEEE8021X_EAPOL #ifdef IEEE8021X_EAPOL
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
static void wpa_supplicant_eap_param_needed(void *ctx, const char *field, static void wpa_supplicant_eap_param_needed(void *ctx,
const char *txt) enum wpa_ctrl_req_type field,
const char *default_txt)
{ {
struct wpa_supplicant *wpa_s = ctx; struct wpa_supplicant *wpa_s = ctx;
struct wpa_ssid *ssid = wpa_s->current_ssid; struct wpa_ssid *ssid = wpa_s->current_ssid;
const char *field_name, *txt = NULL;
char *buf; char *buf;
size_t buflen; size_t buflen;
int len; int len;
@ -601,13 +648,21 @@ static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
if (ssid == NULL) if (ssid == NULL)
return; return;
field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
&txt);
if (field_name == NULL) {
wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
field);
return;
}
buflen = 100 + os_strlen(txt) + ssid->ssid_len; buflen = 100 + os_strlen(txt) + ssid->ssid_len;
buf = os_malloc(buflen); buf = os_malloc(buflen);
if (buf == NULL) if (buf == NULL)
return; return;
len = os_snprintf(buf, buflen, len = os_snprintf(buf, buflen,
WPA_CTRL_REQ "%s-%d:%s needed for SSID ", WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
field, ssid->id, txt); field_name, ssid->id, txt);
if (len < 0 || (size_t) len >= buflen) { if (len < 0 || (size_t) len >= buflen) {
os_free(buf); os_free(buf);
return; return;

View file

@ -20,4 +20,8 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s);
void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s, void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid); struct wpa_ssid *ssid);
const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
const char *default_txt,
const char **txt);
#endif /* WPAS_GLUE_H */ #endif /* WPAS_GLUE_H */