2 * Common driver-related functions
3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
10 #include "utils/common.h"
13 void wpa_scan_results_free(struct wpa_scan_results
*res
)
20 for (i
= 0; i
< res
->num
; i
++)
27 const char * event_to_string(enum wpa_event_type event
)
29 #define E2S(n) case EVENT_ ## n: return #n
33 E2S(MICHAEL_MIC_FAILURE
);
36 E2S(INTERFACE_STATUS
);
47 E2S(WPS_BUTTON_PUSHED
);
51 E2S(REMAIN_ON_CHANNEL
);
52 E2S(CANCEL_REMAIN_ON_CHANNEL
);
57 E2S(INTERFACE_ENABLED
);
58 E2S(INTERFACE_DISABLED
);
59 E2S(CHANNEL_LIST_CHANGED
);
60 E2S(INTERFACE_UNAVAILABLE
);
66 E2S(DRIVER_GTK_REKEY
);
67 E2S(SCHED_SCAN_STOPPED
);
68 E2S(DRIVER_CLIENT_POLL_OK
);
72 E2S(CONNECT_FAILED_REASON
);
73 E2S(DFS_RADAR_DETECTED
);
74 E2S(DFS_CAC_FINISHED
);
76 E2S(DFS_NOP_FINISHED
);
79 E2S(AVOID_FREQUENCIES
);
80 E2S(NEW_PEER_CANDIDATE
);
81 E2S(ACS_CHANNEL_SELECTED
);
91 const char * channel_width_to_string(enum chan_width width
)
94 case CHAN_WIDTH_20_NOHT
:
95 return "20 MHz (no HT)";
102 case CHAN_WIDTH_80P80
:
112 int ht_supported(const struct hostapd_hw_modes
*mode
)
114 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
116 * The driver did not indicate whether it supports HT. Assume
117 * it does to avoid connection issues.
123 * IEEE Std 802.11n-2009 20.1.1:
124 * An HT non-AP STA shall support all EQM rates for one spatial stream.
126 return mode
->mcs_set
[0] == 0xff;
130 int vht_supported(const struct hostapd_hw_modes
*mode
)
132 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN
)) {
134 * The driver did not indicate whether it supports VHT. Assume
135 * it does to avoid connection issues.
141 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
142 * TODO: Verify if this complies with the standard
144 return (mode
->vht_mcs_set
[0] & 0x3) != 3;
148 static int wpa_check_wowlan_trigger(const char *start
, const char *trigger
,
149 int capa_trigger
, u8
*param_trigger
)
151 if (os_strcmp(start
, trigger
) != 0)
161 struct wowlan_triggers
*
162 wpa_get_wowlan_triggers(const char *wowlan_triggers
,
163 const struct wpa_driver_capa
*capa
)
165 struct wowlan_triggers
*triggers
;
166 char *start
, *end
, *buf
;
169 if (!wowlan_triggers
)
172 buf
= os_strdup(wowlan_triggers
);
176 triggers
= os_zalloc(sizeof(*triggers
));
177 if (triggers
== NULL
)
180 #define CHECK_TRIGGER(trigger) \
181 wpa_check_wowlan_trigger(start, #trigger, \
182 capa->wowlan_triggers.trigger, \
186 while (*start
!= '\0') {
187 while (isblank((unsigned char) *start
))
192 while (!isblank((unsigned char) *end
) && *end
!= '\0')
197 if (!CHECK_TRIGGER(any
) &&
198 !CHECK_TRIGGER(disconnect
) &&
199 !CHECK_TRIGGER(magic_pkt
) &&
200 !CHECK_TRIGGER(gtk_rekey_failure
) &&
201 !CHECK_TRIGGER(eap_identity_req
) &&
202 !CHECK_TRIGGER(four_way_handshake
) &&
203 !CHECK_TRIGGER(rfkill_release
)) {
204 wpa_printf(MSG_DEBUG
,
205 "Unknown/unsupported wowlan trigger '%s'",