2011-11-13 11:56:26 -05:00
|
|
|
/*
|
|
|
|
* Common driver-related functions
|
|
|
|
* Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
2012-02-11 09:46:35 -05:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2011-11-13 11:56:26 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "driver.h"
|
|
|
|
|
|
|
|
void wpa_scan_results_free(struct wpa_scan_results *res)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < res->num; i++)
|
|
|
|
os_free(res->res[i]);
|
|
|
|
os_free(res->res);
|
|
|
|
os_free(res);
|
|
|
|
}
|
2011-11-13 12:01:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
const char * event_to_string(enum wpa_event_type event)
|
|
|
|
{
|
2011-11-13 12:06:37 -05:00
|
|
|
#define E2S(n) case EVENT_ ## n: return #n
|
2011-11-13 12:01:38 -05:00
|
|
|
switch (event) {
|
2011-11-13 12:06:37 -05:00
|
|
|
E2S(ASSOC);
|
|
|
|
E2S(DISASSOC);
|
|
|
|
E2S(MICHAEL_MIC_FAILURE);
|
|
|
|
E2S(SCAN_RESULTS);
|
|
|
|
E2S(ASSOCINFO);
|
|
|
|
E2S(INTERFACE_STATUS);
|
|
|
|
E2S(PMKID_CANDIDATE);
|
|
|
|
E2S(STKSTART);
|
|
|
|
E2S(TDLS);
|
|
|
|
E2S(FT_RESPONSE);
|
|
|
|
E2S(IBSS_RSN_START);
|
|
|
|
E2S(AUTH);
|
|
|
|
E2S(DEAUTH);
|
|
|
|
E2S(ASSOC_REJECT);
|
|
|
|
E2S(AUTH_TIMED_OUT);
|
|
|
|
E2S(ASSOC_TIMED_OUT);
|
|
|
|
E2S(WPS_BUTTON_PUSHED);
|
|
|
|
E2S(TX_STATUS);
|
|
|
|
E2S(RX_FROM_UNKNOWN);
|
|
|
|
E2S(RX_MGMT);
|
|
|
|
E2S(REMAIN_ON_CHANNEL);
|
|
|
|
E2S(CANCEL_REMAIN_ON_CHANNEL);
|
|
|
|
E2S(RX_PROBE_REQ);
|
|
|
|
E2S(NEW_STA);
|
|
|
|
E2S(EAPOL_RX);
|
|
|
|
E2S(SIGNAL_CHANGE);
|
|
|
|
E2S(INTERFACE_ENABLED);
|
|
|
|
E2S(INTERFACE_DISABLED);
|
|
|
|
E2S(CHANNEL_LIST_CHANGED);
|
|
|
|
E2S(INTERFACE_UNAVAILABLE);
|
|
|
|
E2S(BEST_CHANNEL);
|
|
|
|
E2S(UNPROT_DEAUTH);
|
|
|
|
E2S(UNPROT_DISASSOC);
|
|
|
|
E2S(STATION_LOW_ACK);
|
|
|
|
E2S(IBSS_PEER_LOST);
|
|
|
|
E2S(DRIVER_GTK_REKEY);
|
|
|
|
E2S(SCHED_SCAN_STOPPED);
|
|
|
|
E2S(DRIVER_CLIENT_POLL_OK);
|
2011-11-19 06:00:30 -05:00
|
|
|
E2S(EAPOL_TX_STATUS);
|
2012-06-25 07:45:14 -04:00
|
|
|
E2S(CH_SWITCH);
|
2012-02-26 10:22:02 -05:00
|
|
|
E2S(WNM);
|
2013-02-07 08:24:53 -05:00
|
|
|
E2S(CONNECT_FAILED_REASON);
|
2013-05-09 12:54:18 -04:00
|
|
|
E2S(DFS_RADAR_DETECTED);
|
|
|
|
E2S(DFS_CAC_FINISHED);
|
|
|
|
E2S(DFS_CAC_ABORTED);
|
|
|
|
E2S(DFS_NOP_FINISHED);
|
2013-07-24 02:59:13 -04:00
|
|
|
E2S(SURVEY);
|
2013-12-26 10:33:26 -05:00
|
|
|
E2S(SCAN_STARTED);
|
2014-01-24 09:14:29 -05:00
|
|
|
E2S(AVOID_FREQUENCIES);
|
2014-09-01 00:23:23 -04:00
|
|
|
E2S(NEW_PEER_CANDIDATE);
|
2011-11-13 12:01:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return "UNKNOWN";
|
2011-11-13 12:06:37 -05:00
|
|
|
#undef E2S
|
2011-11-13 12:01:38 -05:00
|
|
|
}
|
2014-09-10 13:34:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
const char * channel_width_to_string(enum chan_width width)
|
|
|
|
{
|
|
|
|
switch (width) {
|
|
|
|
case CHAN_WIDTH_20_NOHT:
|
|
|
|
return "20 MHz (no HT)";
|
|
|
|
case CHAN_WIDTH_20:
|
|
|
|
return "20 MHz";
|
|
|
|
case CHAN_WIDTH_40:
|
|
|
|
return "40 MHz";
|
|
|
|
case CHAN_WIDTH_80:
|
|
|
|
return "80 MHz";
|
|
|
|
case CHAN_WIDTH_80P80:
|
|
|
|
return "80+80 MHz";
|
|
|
|
case CHAN_WIDTH_160:
|
|
|
|
return "160 MHz";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
2014-10-12 10:02:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
int ht_supported(const struct hostapd_hw_modes *mode)
|
|
|
|
{
|
|
|
|
if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
|
|
|
|
/*
|
|
|
|
* The driver did not indicate whether it supports HT. Assume
|
|
|
|
* it does to avoid connection issues.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IEEE Std 802.11n-2009 20.1.1:
|
|
|
|
* An HT non-AP STA shall support all EQM rates for one spatial stream.
|
|
|
|
*/
|
|
|
|
return mode->mcs_set[0] == 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int vht_supported(const struct hostapd_hw_modes *mode)
|
|
|
|
{
|
|
|
|
if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
|
|
|
|
/*
|
|
|
|
* The driver did not indicate whether it supports VHT. Assume
|
|
|
|
* it does to avoid connection issues.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
|
|
|
|
* TODO: Verify if this complies with the standard
|
|
|
|
*/
|
|
|
|
return (mode->vht_mcs_set[0] & 0x3) != 3;
|
|
|
|
}
|
2014-09-03 17:58:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
static int wpa_check_wowlan_trigger(const char *start, const char *trigger,
|
|
|
|
int capa_trigger, u8 *param_trigger)
|
|
|
|
{
|
|
|
|
if (os_strcmp(start, trigger) != 0)
|
|
|
|
return 0;
|
|
|
|
if (!capa_trigger)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*param_trigger = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wowlan_triggers *
|
|
|
|
wpa_get_wowlan_triggers(const char *wowlan_triggers,
|
|
|
|
const struct wpa_driver_capa *capa)
|
|
|
|
{
|
|
|
|
struct wowlan_triggers *triggers;
|
|
|
|
char *start, *end, *buf;
|
|
|
|
int last;
|
|
|
|
|
|
|
|
if (!wowlan_triggers)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buf = os_strdup(wowlan_triggers);
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
triggers = os_zalloc(sizeof(*triggers));
|
|
|
|
if (triggers == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
#define CHECK_TRIGGER(trigger) \
|
|
|
|
wpa_check_wowlan_trigger(start, #trigger, \
|
|
|
|
capa->wowlan_triggers.trigger, \
|
|
|
|
&triggers->trigger)
|
|
|
|
|
|
|
|
start = buf;
|
|
|
|
while (*start != '\0') {
|
|
|
|
while (isblank(*start))
|
|
|
|
start++;
|
|
|
|
if (*start == '\0')
|
|
|
|
break;
|
|
|
|
end = start;
|
|
|
|
while (!isblank(*end) && *end != '\0')
|
|
|
|
end++;
|
|
|
|
last = *end == '\0';
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
if (!CHECK_TRIGGER(any) &&
|
|
|
|
!CHECK_TRIGGER(disconnect) &&
|
|
|
|
!CHECK_TRIGGER(magic_pkt) &&
|
|
|
|
!CHECK_TRIGGER(gtk_rekey_failure) &&
|
|
|
|
!CHECK_TRIGGER(eap_identity_req) &&
|
|
|
|
!CHECK_TRIGGER(four_way_handshake) &&
|
|
|
|
!CHECK_TRIGGER(rfkill_release)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"Unknown/unsupported wowlan trigger '%s'",
|
|
|
|
start);
|
|
|
|
os_free(triggers);
|
|
|
|
triggers = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
break;
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
#undef CHECK_TRIGGER
|
|
|
|
|
|
|
|
out:
|
|
|
|
os_free(buf);
|
|
|
|
return triggers;
|
|
|
|
}
|