DFS: Print error in case CAC fails
[mech_eap.git] / src / ap / ap_drv_ops.c
1 /*
2  * hostapd - Driver operations
3  * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "wps/wps.h"
14 #include "p2p/p2p.h"
15 #include "hostapd.h"
16 #include "ieee802_11.h"
17 #include "sta_info.h"
18 #include "ap_config.h"
19 #include "p2p_hostapd.h"
20 #include "hs20.h"
21 #include "ap_drv_ops.h"
22
23
24 u32 hostapd_sta_flags_to_drv(u32 flags)
25 {
26         int res = 0;
27         if (flags & WLAN_STA_AUTHORIZED)
28                 res |= WPA_STA_AUTHORIZED;
29         if (flags & WLAN_STA_WMM)
30                 res |= WPA_STA_WMM;
31         if (flags & WLAN_STA_SHORT_PREAMBLE)
32                 res |= WPA_STA_SHORT_PREAMBLE;
33         if (flags & WLAN_STA_MFP)
34                 res |= WPA_STA_MFP;
35         return res;
36 }
37
38
39 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
40                                struct wpabuf **beacon_ret,
41                                struct wpabuf **proberesp_ret,
42                                struct wpabuf **assocresp_ret)
43 {
44         struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
45         u8 buf[200], *pos;
46
47         *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
48
49         pos = buf;
50         pos = hostapd_eid_time_adv(hapd, pos);
51         if (pos != buf) {
52                 if (wpabuf_resize(&beacon, pos - buf) != 0)
53                         goto fail;
54                 wpabuf_put_data(beacon, buf, pos - buf);
55         }
56         pos = hostapd_eid_time_zone(hapd, pos);
57         if (pos != buf) {
58                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
59                         goto fail;
60                 wpabuf_put_data(proberesp, buf, pos - buf);
61         }
62
63         pos = buf;
64         pos = hostapd_eid_ext_capab(hapd, pos);
65         if (pos != buf) {
66                 if (wpabuf_resize(&assocresp, pos - buf) != 0)
67                         goto fail;
68                 wpabuf_put_data(assocresp, buf, pos - buf);
69         }
70         pos = hostapd_eid_interworking(hapd, pos);
71         pos = hostapd_eid_adv_proto(hapd, pos);
72         pos = hostapd_eid_roaming_consortium(hapd, pos);
73         if (pos != buf) {
74                 if (wpabuf_resize(&beacon, pos - buf) != 0)
75                         goto fail;
76                 wpabuf_put_data(beacon, buf, pos - buf);
77
78                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
79                         goto fail;
80                 wpabuf_put_data(proberesp, buf, pos - buf);
81         }
82
83         if (hapd->wps_beacon_ie) {
84                 if (wpabuf_resize(&beacon, wpabuf_len(hapd->wps_beacon_ie)) <
85                     0)
86                         goto fail;
87                 wpabuf_put_buf(beacon, hapd->wps_beacon_ie);
88         }
89
90         if (hapd->wps_probe_resp_ie) {
91                 if (wpabuf_resize(&proberesp,
92                                   wpabuf_len(hapd->wps_probe_resp_ie)) < 0)
93                         goto fail;
94                 wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie);
95         }
96
97 #ifdef CONFIG_P2P
98         if (hapd->p2p_beacon_ie) {
99                 if (wpabuf_resize(&beacon, wpabuf_len(hapd->p2p_beacon_ie)) <
100                     0)
101                         goto fail;
102                 wpabuf_put_buf(beacon, hapd->p2p_beacon_ie);
103         }
104
105         if (hapd->p2p_probe_resp_ie) {
106                 if (wpabuf_resize(&proberesp,
107                                   wpabuf_len(hapd->p2p_probe_resp_ie)) < 0)
108                         goto fail;
109                 wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie);
110         }
111 #endif /* CONFIG_P2P */
112
113 #ifdef CONFIG_P2P_MANAGER
114         if (hapd->conf->p2p & P2P_MANAGE) {
115                 if (wpabuf_resize(&beacon, 100) == 0) {
116                         u8 *start, *p;
117                         start = wpabuf_put(beacon, 0);
118                         p = hostapd_eid_p2p_manage(hapd, start);
119                         wpabuf_put(beacon, p - start);
120                 }
121
122                 if (wpabuf_resize(&proberesp, 100) == 0) {
123                         u8 *start, *p;
124                         start = wpabuf_put(proberesp, 0);
125                         p = hostapd_eid_p2p_manage(hapd, start);
126                         wpabuf_put(proberesp, p - start);
127                 }
128         }
129 #endif /* CONFIG_P2P_MANAGER */
130
131 #ifdef CONFIG_WPS2
132         if (hapd->conf->wps_state) {
133                 struct wpabuf *a = wps_build_assoc_resp_ie();
134                 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
135                         wpabuf_put_buf(assocresp, a);
136                 wpabuf_free(a);
137         }
138 #endif /* CONFIG_WPS2 */
139
140 #ifdef CONFIG_P2P_MANAGER
141         if (hapd->conf->p2p & P2P_MANAGE) {
142                 if (wpabuf_resize(&assocresp, 100) == 0) {
143                         u8 *start, *p;
144                         start = wpabuf_put(assocresp, 0);
145                         p = hostapd_eid_p2p_manage(hapd, start);
146                         wpabuf_put(assocresp, p - start);
147                 }
148         }
149 #endif /* CONFIG_P2P_MANAGER */
150
151 #ifdef CONFIG_WIFI_DISPLAY
152         if (hapd->p2p_group) {
153                 struct wpabuf *a;
154                 a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
155                 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
156                         wpabuf_put_buf(assocresp, a);
157                 wpabuf_free(a);
158         }
159 #endif /* CONFIG_WIFI_DISPLAY */
160
161 #ifdef CONFIG_HS20
162         pos = buf;
163         pos = hostapd_eid_hs20_indication(hapd, pos);
164         if (pos != buf) {
165                 if (wpabuf_resize(&beacon, pos - buf) != 0)
166                         goto fail;
167                 wpabuf_put_data(beacon, buf, pos - buf);
168
169                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
170                         goto fail;
171                 wpabuf_put_data(proberesp, buf, pos - buf);
172         }
173
174         pos = hostapd_eid_osen(hapd, buf);
175         if (pos != buf) {
176                 if (wpabuf_resize(&beacon, pos - buf) != 0)
177                         goto fail;
178                 wpabuf_put_data(beacon, buf, pos - buf);
179
180                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
181                         goto fail;
182                 wpabuf_put_data(proberesp, buf, pos - buf);
183         }
184 #endif /* CONFIG_HS20 */
185
186         if (hapd->conf->vendor_elements) {
187                 size_t add = wpabuf_len(hapd->conf->vendor_elements);
188                 if (wpabuf_resize(&beacon, add) == 0)
189                         wpabuf_put_buf(beacon, hapd->conf->vendor_elements);
190                 if (wpabuf_resize(&proberesp, add) == 0)
191                         wpabuf_put_buf(proberesp, hapd->conf->vendor_elements);
192         }
193
194         *beacon_ret = beacon;
195         *proberesp_ret = proberesp;
196         *assocresp_ret = assocresp;
197
198         return 0;
199
200 fail:
201         wpabuf_free(beacon);
202         wpabuf_free(proberesp);
203         wpabuf_free(assocresp);
204         return -1;
205 }
206
207
208 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
209                                struct wpabuf *beacon,
210                                struct wpabuf *proberesp,
211                                struct wpabuf *assocresp)
212 {
213         wpabuf_free(beacon);
214         wpabuf_free(proberesp);
215         wpabuf_free(assocresp);
216 }
217
218
219 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
220 {
221         struct wpabuf *beacon, *proberesp, *assocresp;
222         int ret;
223
224         if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
225                 return 0;
226
227         if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
228             0)
229                 return -1;
230
231         ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
232                                           assocresp);
233
234         hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
235
236         return ret;
237 }
238
239
240 int hostapd_set_authorized(struct hostapd_data *hapd,
241                            struct sta_info *sta, int authorized)
242 {
243         if (authorized) {
244                 return hostapd_sta_set_flags(hapd, sta->addr,
245                                              hostapd_sta_flags_to_drv(
246                                                      sta->flags),
247                                              WPA_STA_AUTHORIZED, ~0);
248         }
249
250         return hostapd_sta_set_flags(hapd, sta->addr,
251                                      hostapd_sta_flags_to_drv(sta->flags),
252                                      0, ~WPA_STA_AUTHORIZED);
253 }
254
255
256 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
257 {
258         int set_flags, total_flags, flags_and, flags_or;
259         total_flags = hostapd_sta_flags_to_drv(sta->flags);
260         set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
261         if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
262              sta->auth_alg == WLAN_AUTH_FT) &&
263             sta->flags & WLAN_STA_AUTHORIZED)
264                 set_flags |= WPA_STA_AUTHORIZED;
265         flags_or = total_flags & set_flags;
266         flags_and = total_flags | ~set_flags;
267         return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
268                                      flags_or, flags_and);
269 }
270
271
272 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
273                               int enabled)
274 {
275         struct wpa_bss_params params;
276         os_memset(&params, 0, sizeof(params));
277         params.ifname = ifname;
278         params.enabled = enabled;
279         if (enabled) {
280                 params.wpa = hapd->conf->wpa;
281                 params.ieee802_1x = hapd->conf->ieee802_1x;
282                 params.wpa_group = hapd->conf->wpa_group;
283                 params.wpa_pairwise = hapd->conf->wpa_pairwise;
284                 params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
285                 params.rsn_preauth = hapd->conf->rsn_preauth;
286 #ifdef CONFIG_IEEE80211W
287                 params.ieee80211w = hapd->conf->ieee80211w;
288 #endif /* CONFIG_IEEE80211W */
289         }
290         return hostapd_set_ieee8021x(hapd, &params);
291 }
292
293
294 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
295 {
296         char force_ifname[IFNAMSIZ];
297         u8 if_addr[ETH_ALEN];
298         return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
299                               NULL, NULL, force_ifname, if_addr, NULL, 0);
300 }
301
302
303 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
304 {
305         return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
306 }
307
308
309 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
310                         const u8 *addr, int aid, int val)
311 {
312         const char *bridge = NULL;
313
314         if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
315                 return -1;
316         if (hapd->conf->wds_bridge[0])
317                 bridge = hapd->conf->wds_bridge;
318         else if (hapd->conf->bridge[0])
319                 bridge = hapd->conf->bridge;
320         return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
321                                          bridge, ifname_wds);
322 }
323
324
325 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
326                          u16 auth_alg)
327 {
328         if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
329                 return 0;
330         return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
331 }
332
333
334 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
335                      u16 seq, u16 status, const u8 *ie, size_t len)
336 {
337         if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
338                 return 0;
339         return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr,
340                                       seq, status, ie, len);
341 }
342
343
344 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
345                       int reassoc, u16 status, const u8 *ie, size_t len)
346 {
347         if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
348                 return 0;
349         return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
350                                        reassoc, status, ie, len);
351 }
352
353
354 int hostapd_sta_add(struct hostapd_data *hapd,
355                     const u8 *addr, u16 aid, u16 capability,
356                     const u8 *supp_rates, size_t supp_rates_len,
357                     u16 listen_interval,
358                     const struct ieee80211_ht_capabilities *ht_capab,
359                     const struct ieee80211_vht_capabilities *vht_capab,
360                     u32 flags, u8 qosinfo, u8 vht_opmode)
361 {
362         struct hostapd_sta_add_params params;
363
364         if (hapd->driver == NULL)
365                 return 0;
366         if (hapd->driver->sta_add == NULL)
367                 return 0;
368
369         os_memset(&params, 0, sizeof(params));
370         params.addr = addr;
371         params.aid = aid;
372         params.capability = capability;
373         params.supp_rates = supp_rates;
374         params.supp_rates_len = supp_rates_len;
375         params.listen_interval = listen_interval;
376         params.ht_capabilities = ht_capab;
377         params.vht_capabilities = vht_capab;
378         params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
379         params.vht_opmode = vht_opmode;
380         params.flags = hostapd_sta_flags_to_drv(flags);
381         params.qosinfo = qosinfo;
382         return hapd->driver->sta_add(hapd->drv_priv, &params);
383 }
384
385
386 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
387                       u8 *tspec_ie, size_t tspec_ielen)
388 {
389         if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
390                 return 0;
391         return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
392                                        tspec_ielen);
393 }
394
395
396 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
397 {
398         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
399                 return 0;
400         return hapd->driver->set_privacy(hapd->drv_priv, enabled);
401 }
402
403
404 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
405                              size_t elem_len)
406 {
407         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
408                 return 0;
409         return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
410 }
411
412
413 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
414 {
415         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
416                 return 0;
417         return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
418 }
419
420
421 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
422 {
423         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
424                 return 0;
425         return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
426 }
427
428
429 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
430                    const char *ifname, const u8 *addr, void *bss_ctx,
431                    void **drv_priv, char *force_ifname, u8 *if_addr,
432                    const char *bridge, int use_existing)
433 {
434         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
435                 return -1;
436         return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
437                                     bss_ctx, drv_priv, force_ifname, if_addr,
438                                     bridge, use_existing);
439 }
440
441
442 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
443                       const char *ifname)
444 {
445         if (hapd->driver == NULL || hapd->drv_priv == NULL ||
446             hapd->driver->if_remove == NULL)
447                 return -1;
448         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
449 }
450
451
452 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
453                           struct wpa_bss_params *params)
454 {
455         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
456                 return 0;
457         return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
458 }
459
460
461 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
462                        const u8 *addr, int idx, u8 *seq)
463 {
464         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
465                 return 0;
466         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
467                                         seq);
468 }
469
470
471 int hostapd_flush(struct hostapd_data *hapd)
472 {
473         if (hapd->driver == NULL || hapd->driver->flush == NULL)
474                 return 0;
475         return hapd->driver->flush(hapd->drv_priv);
476 }
477
478
479 int hostapd_set_freq_params(struct hostapd_freq_params *data, int mode,
480                             int freq, int channel, int ht_enabled,
481                             int vht_enabled, int sec_channel_offset,
482                             int vht_oper_chwidth, int center_segment0,
483                             int center_segment1, u32 vht_caps)
484 {
485         int tmp;
486
487         os_memset(data, 0, sizeof(*data));
488         data->mode = mode;
489         data->freq = freq;
490         data->channel = channel;
491         data->ht_enabled = ht_enabled;
492         data->vht_enabled = vht_enabled;
493         data->sec_channel_offset = sec_channel_offset;
494         data->center_freq1 = freq + sec_channel_offset * 10;
495         data->center_freq2 = 0;
496         data->bandwidth = sec_channel_offset ? 40 : 20;
497
498         /*
499          * This validation code is probably misplaced, maybe it should be
500          * in src/ap/hw_features.c and check the hardware support as well.
501          */
502         if (data->vht_enabled) switch (vht_oper_chwidth) {
503         case VHT_CHANWIDTH_USE_HT:
504                 if (center_segment1)
505                         return -1;
506                 if (5000 + center_segment0 * 5 != data->center_freq1 &&
507                     2407 + center_segment0 * 5 != data->center_freq1)
508                         return -1;
509                 break;
510         case VHT_CHANWIDTH_80P80MHZ:
511                 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) {
512                         wpa_printf(MSG_ERROR,
513                                    "80+80 channel width is not supported!");
514                         return -1;
515                 }
516                 if (center_segment1 == center_segment0 + 4 ||
517                     center_segment1 == center_segment0 - 4)
518                         return -1;
519                 data->center_freq2 = 5000 + center_segment1 * 5;
520                 /* fall through */
521         case VHT_CHANWIDTH_80MHZ:
522                 data->bandwidth = 80;
523                 if (vht_oper_chwidth == 1 && center_segment1)
524                         return -1;
525                 if (vht_oper_chwidth == 3 && !center_segment1)
526                         return -1;
527                 if (!sec_channel_offset)
528                         return -1;
529                 /* primary 40 part must match the HT configuration */
530                 tmp = (30 + freq - 5000 - center_segment0 * 5)/20;
531                 tmp /= 2;
532                 if (data->center_freq1 != 5000 +
533                                          center_segment0 * 5 - 20 + 40 * tmp)
534                         return -1;
535                 data->center_freq1 = 5000 + center_segment0 * 5;
536                 break;
537         case VHT_CHANWIDTH_160MHZ:
538                 data->bandwidth = 160;
539                 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
540                                   VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
541                         wpa_printf(MSG_ERROR,
542                                    "160MHZ channel width is not supported!");
543                         return -1;
544                 }
545                 if (center_segment1)
546                         return -1;
547                 if (!sec_channel_offset)
548                         return -1;
549                 /* primary 40 part must match the HT configuration */
550                 tmp = (70 + freq - 5000 - center_segment0 * 5)/20;
551                 tmp /= 2;
552                 if (data->center_freq1 != 5000 +
553                                          center_segment0 * 5 - 60 + 40 * tmp)
554                         return -1;
555                 data->center_freq1 = 5000 + center_segment0 * 5;
556                 break;
557         }
558
559         return 0;
560 }
561
562
563 int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
564                      int channel, int ht_enabled, int vht_enabled,
565                      int sec_channel_offset, int vht_oper_chwidth,
566                      int center_segment0, int center_segment1)
567 {
568         struct hostapd_freq_params data;
569
570         if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
571                                     vht_enabled, sec_channel_offset,
572                                     vht_oper_chwidth,
573                                     center_segment0, center_segment1,
574                                     hapd->iface->current_mode->vht_capab))
575                 return -1;
576
577         if (hapd->driver == NULL)
578                 return 0;
579         if (hapd->driver->set_freq == NULL)
580                 return 0;
581         return hapd->driver->set_freq(hapd->drv_priv, &data);
582 }
583
584 int hostapd_set_rts(struct hostapd_data *hapd, int rts)
585 {
586         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
587                 return 0;
588         return hapd->driver->set_rts(hapd->drv_priv, rts);
589 }
590
591
592 int hostapd_set_frag(struct hostapd_data *hapd, int frag)
593 {
594         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
595                 return 0;
596         return hapd->driver->set_frag(hapd->drv_priv, frag);
597 }
598
599
600 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
601                           int total_flags, int flags_or, int flags_and)
602 {
603         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
604                 return 0;
605         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
606                                            flags_or, flags_and);
607 }
608
609
610 int hostapd_set_country(struct hostapd_data *hapd, const char *country)
611 {
612         if (hapd->driver == NULL ||
613             hapd->driver->set_country == NULL)
614                 return 0;
615         return hapd->driver->set_country(hapd->drv_priv, country);
616 }
617
618
619 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
620                                 int cw_min, int cw_max, int burst_time)
621 {
622         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
623                 return 0;
624         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
625                                                  cw_min, cw_max, burst_time);
626 }
627
628
629 struct hostapd_hw_modes *
630 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
631                             u16 *flags)
632 {
633         if (hapd->driver == NULL ||
634             hapd->driver->get_hw_feature_data == NULL)
635                 return NULL;
636         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
637                                                  flags);
638 }
639
640
641 int hostapd_driver_commit(struct hostapd_data *hapd)
642 {
643         if (hapd->driver == NULL || hapd->driver->commit == NULL)
644                 return 0;
645         return hapd->driver->commit(hapd->drv_priv);
646 }
647
648
649 int hostapd_drv_none(struct hostapd_data *hapd)
650 {
651         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
652 }
653
654
655 int hostapd_driver_scan(struct hostapd_data *hapd,
656                         struct wpa_driver_scan_params *params)
657 {
658         if (hapd->driver && hapd->driver->scan2)
659                 return hapd->driver->scan2(hapd->drv_priv, params);
660         return -1;
661 }
662
663
664 struct wpa_scan_results * hostapd_driver_get_scan_results(
665         struct hostapd_data *hapd)
666 {
667         if (hapd->driver && hapd->driver->get_scan_results2)
668                 return hapd->driver->get_scan_results2(hapd->drv_priv);
669         return NULL;
670 }
671
672
673 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
674                            int duration)
675 {
676         if (hapd->driver && hapd->driver->set_noa)
677                 return hapd->driver->set_noa(hapd->drv_priv, count, start,
678                                              duration);
679         return -1;
680 }
681
682
683 int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
684                         enum wpa_alg alg, const u8 *addr,
685                         int key_idx, int set_tx,
686                         const u8 *seq, size_t seq_len,
687                         const u8 *key, size_t key_len)
688 {
689         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
690                 return 0;
691         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
692                                      key_idx, set_tx, seq, seq_len, key,
693                                      key_len);
694 }
695
696
697 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
698                           const void *msg, size_t len, int noack)
699 {
700         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
701                 return 0;
702         return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack);
703 }
704
705
706 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
707                            const u8 *addr, int reason)
708 {
709         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
710                 return 0;
711         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
712                                         reason);
713 }
714
715
716 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
717                              const u8 *addr, int reason)
718 {
719         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
720                 return 0;
721         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
722                                           reason);
723 }
724
725
726 int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
727                          const u8 *peer, u8 *buf, u16 *buf_len)
728 {
729         if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
730                 return -1;
731         return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
732                                       buf_len);
733 }
734
735
736 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
737                             unsigned int wait, const u8 *dst, const u8 *data,
738                             size_t len)
739 {
740         if (hapd->driver == NULL || hapd->driver->send_action == NULL)
741                 return 0;
742         return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
743                                          hapd->own_addr, hapd->own_addr, data,
744                                          len, 0);
745 }
746
747
748 int hostapd_start_dfs_cac(struct hostapd_iface *iface, int mode, int freq,
749                           int channel, int ht_enabled, int vht_enabled,
750                           int sec_channel_offset, int vht_oper_chwidth,
751                           int center_segment0, int center_segment1)
752 {
753         struct hostapd_data *hapd = iface->bss[0];
754         struct hostapd_freq_params data;
755         int res;
756
757         if (!hapd->driver || !hapd->driver->start_dfs_cac)
758                 return 0;
759
760         if (!iface->conf->ieee80211h) {
761                 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
762                            "is not enabled");
763                 return -1;
764         }
765
766         if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
767                                     vht_enabled, sec_channel_offset,
768                                     vht_oper_chwidth, center_segment0,
769                                     center_segment1,
770                                     iface->current_mode->vht_capab)) {
771                 wpa_printf(MSG_ERROR, "Can't set freq params");
772                 return -1;
773         }
774
775         res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
776         if (!res)
777                 iface->cac_started = 1;
778
779         return res;
780 }
781
782
783 int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
784                             const u8 *qos_map_set, u8 qos_map_set_len)
785 {
786         if (hapd->driver == NULL || hapd->driver->set_qos_map == NULL)
787                 return 0;
788         return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
789                                          qos_map_set_len);
790 }