Define struct wpa_ssid::mode as an enum with more readable values

This commit is contained in:
Jouni Malinen 2009-12-28 16:00:36 +02:00 committed by Jouni Malinen
parent 139a33f34e
commit d7dcba70bc
5 changed files with 32 additions and 17 deletions

View file

@ -155,7 +155,17 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
os_memset(&params, 0, sizeof(params));
params.ssid = ssid->ssid;
params.ssid_len = ssid->ssid_len;
params.mode = ssid->mode;
switch (ssid->mode) {
case WPAS_MODE_INFRA:
params.mode = IEEE80211_MODE_INFRA;
break;
case WPAS_MODE_IBSS:
params.mode = IEEE80211_MODE_IBSS;
break;
case WPAS_MODE_AP:
params.mode = IEEE80211_MODE_AP;
break;
}
params.freq = ssid->frequency;
if (wpa_drv_associate(wpa_s, &params) < 0) {

View file

@ -280,7 +280,11 @@ struct wpa_ssid {
* pairwise=NONE, group=TKIP (or CCMP, but not both), and psk must also
* be set (either directly or using ASCII passphrase).
*/
int mode;
enum wpas_mode {
WPAS_MODE_INFRA = 0,
WPAS_MODE_IBSS = 1,
WPAS_MODE_AP = 2,
} mode;
/**
* disabled - Whether this network is currently disabled

View file

@ -476,15 +476,15 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
}
switch (ssid->mode) {
case 0:
case WPAS_MODE_INFRA:
ret = os_snprintf(pos, end - pos,
"mode=station\n");
break;
case 1:
case WPAS_MODE_IBSS:
ret = os_snprintf(pos, end - pos,
"mode=IBSS\n");
break;
case 2:
case WPAS_MODE_AP:
ret = os_snprintf(pos, end - pos,
"mode=AP\n");
break;

View file

@ -754,7 +754,7 @@ static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
u16 auth_alg, auth_transaction, status_code;
int adhoc;
adhoc = ssid && ssid->mode == 1;
adhoc = ssid && ssid->mode == WPAS_MODE_IBSS;
if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
@ -1685,7 +1685,7 @@ static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
u8 *pos, *end;
struct wpa_ssid *ssid = wpa_s->current_ssid;
adhoc = ssid && ssid->mode == 1;
adhoc = ssid && ssid->mode == WPAS_MODE_IBSS;
if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
@ -2193,7 +2193,7 @@ static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx)
static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
{
struct wpa_ssid *ssid = wpa_s->current_ssid;
if (ssid && ssid->mode != 0)
if (ssid && ssid->mode != WPAS_MODE_INFRA)
return;
#if 0 /* FIX */
@ -2665,7 +2665,7 @@ int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
wpa_s->mlme.channel, wpa_s->mlme.freq);
if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
if (params->mode == WPAS_MODE_IBSS && !wpa_s->mlme.bssid_set) {
os_get_time(&wpa_s->mlme.ibss_join_req);
wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
return ieee80211_sta_find_ibss(wpa_s);

View file

@ -150,7 +150,7 @@ static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
/* IBSS/WPA-None uses only one key (Group) for both receiving and
* sending unicast and multicast packets. */
if (ssid->mode != IEEE80211_MODE_IBSS) {
if (ssid->mode != WPAS_MODE_IBSS) {
wpa_printf(MSG_INFO, "WPA: Invalid mode %d (not IBSS/ad-hoc) "
"for WPA-None", ssid->mode);
return -1;
@ -257,7 +257,7 @@ void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
struct wpa_ssid *ssid = wpa_s->current_ssid;
#ifdef CONFIG_IBSS_RSN
if (ssid->mode == IEEE80211_MODE_IBSS &&
if (ssid->mode == WPAS_MODE_IBSS &&
wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
/*
@ -990,7 +990,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
int assoc_failed = 0;
struct wpa_ssid *old_ssid;
if (ssid->mode == IEEE80211_MODE_AP) {
if (ssid->mode == WPAS_MODE_AP) {
#ifdef CONFIG_AP
if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
wpa_printf(MSG_INFO, "Driver does not support AP "
@ -1180,7 +1180,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
params.ssid = ssid->ssid;
params.ssid_len = ssid->ssid_len;
}
if (ssid->mode == 1 && ssid->frequency > 0 && params.freq == 0)
if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 &&
params.freq == 0)
params.freq = ssid->frequency; /* Initial channel for IBSS */
params.wpa_ie = wpa_ie;
params.wpa_ie_len = wpa_ie_len;
@ -1253,7 +1254,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
wpa_supplicant_cancel_auth_timeout(wpa_s);
wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
#ifdef CONFIG_IBSS_RSN
} else if (ssid->mode == IEEE80211_MODE_IBSS &&
} else if (ssid->mode == WPAS_MODE_IBSS &&
wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
ibss_rsn_set_psk(wpa_s->ibss_rsn, ssid->psk);
@ -1269,10 +1270,10 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
if (assoc_failed) {
/* give IBSS a bit more time */
timeout = ssid->mode ? 10 : 5;
timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
} else if (wpa_s->conf->ap_scan == 1) {
/* give IBSS a bit more time */
timeout = ssid->mode ? 20 : 10;
timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
}
wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
}
@ -1766,7 +1767,7 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
#ifdef CONFIG_IBSS_RSN
if (wpa_s->current_ssid &&
wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS) {
wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
return;
}