2 * hostapd / Hardware feature query and different modes
3 * Copyright 2002-2003, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
20 #include "hw_features.h"
25 void hostapd_free_hw_features(struct hostapd_hw_modes
*hw_features
,
26 size_t num_hw_features
)
30 if (hw_features
== NULL
)
33 for (i
= 0; i
< num_hw_features
; i
++) {
34 os_free(hw_features
[i
].channels
);
35 os_free(hw_features
[i
].rates
);
42 int hostapd_get_hw_features(struct hostapd_iface
*iface
)
44 struct hostapd_data
*hapd
= iface
->bss
[0];
47 struct hostapd_hw_modes
*modes
;
49 if (hostapd_drv_none(hapd
))
51 modes
= hostapd_get_hw_feature_data(hapd
, &num_modes
, &flags
);
53 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
55 "Fetching hardware channel/rate support not "
60 iface
->hw_flags
= flags
;
62 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
63 iface
->hw_features
= modes
;
64 iface
->num_hw_features
= num_modes
;
66 for (i
= 0; i
< num_modes
; i
++) {
67 struct hostapd_hw_modes
*feature
= &modes
[i
];
68 /* set flag for channels we can use in current regulatory
70 for (j
= 0; j
< feature
->num_channels
; j
++) {
72 * Disable all channels that are marked not to allow
73 * IBSS operation or active scanning. In addition,
74 * disable all channels that require radar detection,
75 * since that (in addition to full DFS) is not yet
78 if (feature
->channels
[j
].flag
&
79 (HOSTAPD_CHAN_NO_IBSS
|
80 HOSTAPD_CHAN_PASSIVE_SCAN
|
82 feature
->channels
[j
].flag
|=
83 HOSTAPD_CHAN_DISABLED
;
84 if (feature
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
86 wpa_printf(MSG_MSGDUMP
, "Allowed channel: mode=%d "
87 "chan=%d freq=%d MHz max_tx_power=%d dBm",
89 feature
->channels
[j
].chan
,
90 feature
->channels
[j
].freq
,
91 feature
->channels
[j
].max_tx_power
);
99 static int hostapd_prepare_rates(struct hostapd_data
*hapd
,
100 struct hostapd_hw_modes
*mode
)
102 int i
, num_basic_rates
= 0;
103 int basic_rates_a
[] = { 60, 120, 240, -1 };
104 int basic_rates_b
[] = { 10, 20, -1 };
105 int basic_rates_g
[] = { 10, 20, 55, 110, -1 };
108 if (hapd
->iconf
->basic_rates
)
109 basic_rates
= hapd
->iconf
->basic_rates
;
110 else switch (mode
->mode
) {
111 case HOSTAPD_MODE_IEEE80211A
:
112 basic_rates
= basic_rates_a
;
114 case HOSTAPD_MODE_IEEE80211B
:
115 basic_rates
= basic_rates_b
;
117 case HOSTAPD_MODE_IEEE80211G
:
118 basic_rates
= basic_rates_g
;
124 if (hostapd_set_rate_sets(hapd
, hapd
->iconf
->supported_rates
,
125 basic_rates
, mode
->mode
)) {
126 wpa_printf(MSG_ERROR
, "Failed to update rate sets in kernel "
130 os_free(hapd
->iface
->current_rates
);
131 hapd
->iface
->num_rates
= 0;
133 hapd
->iface
->current_rates
=
134 os_malloc(mode
->num_rates
* sizeof(struct hostapd_rate_data
));
135 if (!hapd
->iface
->current_rates
) {
136 wpa_printf(MSG_ERROR
, "Failed to allocate memory for rate "
141 for (i
= 0; i
< mode
->num_rates
; i
++) {
142 struct hostapd_rate_data
*rate
;
144 if (hapd
->iconf
->supported_rates
&&
145 !hostapd_rate_found(hapd
->iconf
->supported_rates
,
146 mode
->rates
[i
].rate
))
149 rate
= &hapd
->iface
->current_rates
[hapd
->iface
->num_rates
];
150 os_memcpy(rate
, &mode
->rates
[i
],
151 sizeof(struct hostapd_rate_data
));
152 if (hostapd_rate_found(basic_rates
, rate
->rate
)) {
153 rate
->flags
|= HOSTAPD_RATE_BASIC
;
156 rate
->flags
&= ~HOSTAPD_RATE_BASIC
;
157 wpa_printf(MSG_DEBUG
, "RATE[%d] rate=%d flags=0x%x",
158 hapd
->iface
->num_rates
, rate
->rate
, rate
->flags
);
159 hapd
->iface
->num_rates
++;
162 if (hapd
->iface
->num_rates
== 0 || num_basic_rates
== 0) {
163 wpa_printf(MSG_ERROR
, "No rates remaining in supported/basic "
164 "rate sets (%d,%d).",
165 hapd
->iface
->num_rates
, num_basic_rates
);
173 #ifdef CONFIG_IEEE80211N
174 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface
*iface
)
176 int sec_chan
, ok
, j
, first
;
177 int allowed
[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
181 if (!iface
->conf
->secondary_channel
)
182 return 1; /* HT40 not used */
184 sec_chan
= iface
->conf
->channel
+ iface
->conf
->secondary_channel
* 4;
185 wpa_printf(MSG_DEBUG
, "HT40: control channel: %d "
186 "secondary channel: %d",
187 iface
->conf
->channel
, sec_chan
);
189 /* Verify that HT40 secondary channel is an allowed 20 MHz
192 for (j
= 0; j
< iface
->current_mode
->num_channels
; j
++) {
193 struct hostapd_channel_data
*chan
=
194 &iface
->current_mode
->channels
[j
];
195 if (!(chan
->flag
& HOSTAPD_CHAN_DISABLED
) &&
196 chan
->chan
== sec_chan
) {
202 wpa_printf(MSG_ERROR
, "HT40 secondary channel %d not allowed",
208 * Verify that HT40 primary,secondary channel pair is allowed per
209 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
210 * 2.4 GHz rules allow all cases where the secondary channel fits into
211 * the list of allowed channels (already checked above).
213 if (iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
216 if (iface
->conf
->secondary_channel
> 0)
217 first
= iface
->conf
->channel
;
222 for (k
= 0; k
< sizeof(allowed
) / sizeof(allowed
[0]); k
++) {
223 if (first
== allowed
[k
]) {
229 wpa_printf(MSG_ERROR
, "HT40 channel pair (%d, %d) not allowed",
230 iface
->conf
->channel
,
231 iface
->conf
->secondary_channel
);
239 static int ieee80211n_supported_ht_capab(struct hostapd_iface
*iface
)
241 u16 hw
= iface
->current_mode
->ht_capab
;
242 u16 conf
= iface
->conf
->ht_capab
;
244 if (!iface
->conf
->ieee80211n
)
247 if ((conf
& HT_CAP_INFO_LDPC_CODING_CAP
) &&
248 !(hw
& HT_CAP_INFO_LDPC_CODING_CAP
)) {
249 wpa_printf(MSG_ERROR
, "Driver does not support configured "
250 "HT capability [LDPC]");
254 if ((conf
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
) &&
255 !(hw
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
)) {
256 wpa_printf(MSG_ERROR
, "Driver does not support configured "
257 "HT capability [HT40*]");
261 if ((conf
& HT_CAP_INFO_SMPS_MASK
) != (hw
& HT_CAP_INFO_SMPS_MASK
) &&
262 (conf
& HT_CAP_INFO_SMPS_MASK
) != HT_CAP_INFO_SMPS_DISABLED
) {
263 wpa_printf(MSG_ERROR
, "Driver does not support configured "
264 "HT capability [SMPS-*]");
268 if ((conf
& HT_CAP_INFO_GREEN_FIELD
) &&
269 !(hw
& HT_CAP_INFO_GREEN_FIELD
)) {
270 wpa_printf(MSG_ERROR
, "Driver does not support configured "
271 "HT capability [GF]");
275 if ((conf
& HT_CAP_INFO_SHORT_GI20MHZ
) &&
276 !(hw
& HT_CAP_INFO_SHORT_GI20MHZ
)) {
277 wpa_printf(MSG_ERROR
, "Driver does not support configured "
278 "HT capability [SHORT-GI-20]");
282 if ((conf
& HT_CAP_INFO_SHORT_GI40MHZ
) &&
283 !(hw
& HT_CAP_INFO_SHORT_GI40MHZ
)) {
284 wpa_printf(MSG_ERROR
, "Driver does not support configured "
285 "HT capability [SHORT-GI-40]");
289 if ((conf
& HT_CAP_INFO_TX_STBC
) && !(hw
& HT_CAP_INFO_TX_STBC
)) {
290 wpa_printf(MSG_ERROR
, "Driver does not support configured "
291 "HT capability [TX-STBC]");
295 if ((conf
& HT_CAP_INFO_RX_STBC_MASK
) >
296 (hw
& HT_CAP_INFO_RX_STBC_MASK
)) {
297 wpa_printf(MSG_ERROR
, "Driver does not support configured "
298 "HT capability [RX-STBC*]");
302 if ((conf
& HT_CAP_INFO_DELAYED_BA
) &&
303 !(hw
& HT_CAP_INFO_DELAYED_BA
)) {
304 wpa_printf(MSG_ERROR
, "Driver does not support configured "
305 "HT capability [DELAYED-BA]");
309 if ((conf
& HT_CAP_INFO_MAX_AMSDU_SIZE
) &&
310 !(hw
& HT_CAP_INFO_MAX_AMSDU_SIZE
)) {
311 wpa_printf(MSG_ERROR
, "Driver does not support configured "
312 "HT capability [MAX-AMSDU-7935]");
316 if ((conf
& HT_CAP_INFO_DSSS_CCK40MHZ
) &&
317 !(hw
& HT_CAP_INFO_DSSS_CCK40MHZ
)) {
318 wpa_printf(MSG_ERROR
, "Driver does not support configured "
319 "HT capability [DSSS_CCK-40]");
323 if ((conf
& HT_CAP_INFO_PSMP_SUPP
) && !(hw
& HT_CAP_INFO_PSMP_SUPP
)) {
324 wpa_printf(MSG_ERROR
, "Driver does not support configured "
325 "HT capability [PSMP]");
329 if ((conf
& HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT
) &&
330 !(hw
& HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT
)) {
331 wpa_printf(MSG_ERROR
, "Driver does not support configured "
332 "HT capability [LSIG-TXOP-PROT]");
338 #endif /* CONFIG_IEEE80211N */
342 * hostapd_select_hw_mode - Select the hardware mode
343 * @iface: Pointer to interface data.
344 * Returns: 0 on success, -1 on failure
346 * Sets up the hardware mode, channel, rates, and passive scanning
347 * based on the configuration.
349 int hostapd_select_hw_mode(struct hostapd_iface
*iface
)
353 if (iface
->num_hw_features
< 1)
356 iface
->current_mode
= NULL
;
357 for (i
= 0; i
< iface
->num_hw_features
; i
++) {
358 struct hostapd_hw_modes
*mode
= &iface
->hw_features
[i
];
359 if (mode
->mode
== (int) iface
->conf
->hw_mode
) {
360 iface
->current_mode
= mode
;
365 if (iface
->current_mode
== NULL
) {
366 wpa_printf(MSG_ERROR
, "Hardware does not support configured "
368 hostapd_logger(iface
->bss
[0], NULL
, HOSTAPD_MODULE_IEEE80211
,
369 HOSTAPD_LEVEL_WARNING
,
370 "Hardware does not support configured mode "
371 "(%d)", (int) iface
->conf
->hw_mode
);
376 for (j
= 0; j
< iface
->current_mode
->num_channels
; j
++) {
377 struct hostapd_channel_data
*chan
=
378 &iface
->current_mode
->channels
[j
];
379 if (!(chan
->flag
& HOSTAPD_CHAN_DISABLED
) &&
380 (chan
->chan
== iface
->conf
->channel
)) {
385 if (iface
->conf
->channel
== 0) {
386 /* TODO: could request a scan of neighboring BSSes and select
387 * the channel automatically */
388 wpa_printf(MSG_ERROR
, "Channel not configured "
389 "(hw_mode/channel in hostapd.conf)");
392 if (ok
== 0 && iface
->conf
->channel
!= 0) {
393 hostapd_logger(iface
->bss
[0], NULL
,
394 HOSTAPD_MODULE_IEEE80211
,
395 HOSTAPD_LEVEL_WARNING
,
396 "Configured channel (%d) not found from the "
397 "channel list of current mode (%d) %s",
398 iface
->conf
->channel
,
399 iface
->current_mode
->mode
,
400 hostapd_hw_mode_txt(iface
->current_mode
->mode
));
401 iface
->current_mode
= NULL
;
404 if (iface
->current_mode
== NULL
) {
405 hostapd_logger(iface
->bss
[0], NULL
, HOSTAPD_MODULE_IEEE80211
,
406 HOSTAPD_LEVEL_WARNING
,
407 "Hardware does not support configured channel");
411 #ifdef CONFIG_IEEE80211N
412 if (!ieee80211n_allowed_ht40_channel_pair(iface
))
414 if (!ieee80211n_supported_ht_capab(iface
))
416 #endif /* CONFIG_IEEE80211N */
418 if (hostapd_prepare_rates(iface
->bss
[0], iface
->current_mode
)) {
419 wpa_printf(MSG_ERROR
, "Failed to prepare rates table.");
420 hostapd_logger(iface
->bss
[0], NULL
, HOSTAPD_MODULE_IEEE80211
,
421 HOSTAPD_LEVEL_WARNING
,
422 "Failed to prepare rates table.");
426 ret
= hostapd_passive_scan(iface
->bss
[0], 0,
427 iface
->conf
->passive_scan_mode
,
428 iface
->conf
->passive_scan_interval
,
429 iface
->conf
->passive_scan_listen
,
433 wpa_printf(MSG_DEBUG
, "Passive scanning not "
436 wpa_printf(MSG_ERROR
, "Could not set passive "
437 "scanning: %s", strerror(ret
));
446 const char * hostapd_hw_mode_txt(int mode
)
449 case HOSTAPD_MODE_IEEE80211A
:
450 return "IEEE 802.11a";
451 case HOSTAPD_MODE_IEEE80211B
:
452 return "IEEE 802.11b";
453 case HOSTAPD_MODE_IEEE80211G
:
454 return "IEEE 802.11g";
461 int hostapd_hw_get_freq(struct hostapd_data
*hapd
, int chan
)
465 if (!hapd
->iface
->current_mode
)
468 for (i
= 0; i
< hapd
->iface
->current_mode
->num_channels
; i
++) {
469 struct hostapd_channel_data
*ch
=
470 &hapd
->iface
->current_mode
->channels
[i
];
471 if (ch
->chan
== chan
)
479 int hostapd_hw_get_channel(struct hostapd_data
*hapd
, int freq
)
483 if (!hapd
->iface
->current_mode
)
486 for (i
= 0; i
< hapd
->iface
->current_mode
->num_channels
; i
++) {
487 struct hostapd_channel_data
*ch
=
488 &hapd
->iface
->current_mode
->channels
[i
];
489 if (ch
->freq
== freq
)