1 --- a/src/drivers/driver_nl80211.c
2 +++ b/src/drivers/driver_nl80211.c
7 + struct wpa_driver_nl80211_data *drv;
10 + char ifname[IFNAMSIZ + 1];
11 unsigned int beacon_set:1;
14 @@ -68,7 +70,6 @@ struct wpa_driver_nl80211_data {
16 struct netlink_data *netlink;
17 int ioctl_sock; /* socket for ioctl() use */
18 - char ifname[IFNAMSIZ + 1];
19 char brname[IFNAMSIZ];
22 @@ -107,6 +108,8 @@ struct wpa_driver_nl80211_data {
24 u64 remain_on_chan_cookie;
26 + struct i802_bss first_bss;
29 int eapol_sock; /* socket for EAPOL frames */
31 @@ -114,8 +117,6 @@ struct wpa_driver_nl80211_data {
35 - struct i802_bss bss;
40 @@ -135,8 +136,6 @@ static void nl80211_remove_monitor_inter
42 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
43 static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
44 -static struct i802_bss * get_bss(struct wpa_driver_nl80211_data *drv,
46 static int i802_set_freq(void *priv, struct hostapd_freq_params *freq);
47 static int wpa_driver_nl80211_if_remove(void *priv,
48 enum wpa_driver_if_type type,
49 @@ -278,7 +277,8 @@ nla_put_failure:
51 static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
53 - struct wpa_driver_nl80211_data *drv = priv;
54 + struct i802_bss *bss = priv;
55 + struct wpa_driver_nl80211_data *drv = bss->drv;
58 os_memcpy(bssid, drv->bssid, ETH_ALEN);
59 @@ -288,7 +288,8 @@ static int wpa_driver_nl80211_get_bssid(
61 static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
63 - struct wpa_driver_nl80211_data *drv = priv;
64 + struct i802_bss *bss = priv;
65 + struct wpa_driver_nl80211_data *drv = bss->drv;
68 os_memcpy(ssid, drv->ssid, drv->ssid_len);
69 @@ -313,7 +314,7 @@ static void wpa_driver_nl80211_event_lin
70 event.interface_status.ifname,
71 del ? "removed" : "added");
73 - if (os_strcmp(drv->ifname, event.interface_status.ifname) == 0) {
74 + if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) {
78 @@ -336,7 +337,7 @@ static int wpa_driver_nl80211_own_ifname
79 rta_len = RTA_ALIGN(sizeof(struct rtattr));
80 while (RTA_OK(attr, attrlen)) {
81 if (attr->rta_type == IFLA_IFNAME) {
82 - if (os_strcmp(((char *) attr) + rta_len, drv->ifname)
83 + if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname)
87 @@ -356,7 +357,7 @@ static int wpa_driver_nl80211_own_ifinde
90 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
91 - drv->ifindex = if_nametoindex(drv->ifname);
92 + drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname);
93 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
95 wpa_driver_nl80211_finish_drv_init(drv);
96 @@ -785,7 +786,7 @@ static int process_event(struct nl_msg *
97 if (drv->ap_scan_as_station &&
98 (gnlh->cmd == NL80211_CMD_NEW_SCAN_RESULTS ||
99 gnlh->cmd == NL80211_CMD_SCAN_ABORTED)) {
100 - wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP);
101 + wpa_driver_nl80211_set_mode(&drv->first_bss, IEEE80211_MODE_AP);
102 drv->ap_scan_as_station = 0;
105 @@ -889,7 +890,8 @@ static void wpa_driver_nl80211_event_rec
107 static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
109 - struct wpa_driver_nl80211_data *drv = priv;
110 + struct i802_bss *bss = priv;
111 + struct wpa_driver_nl80211_data *drv = bss->drv;
115 @@ -978,7 +980,7 @@ static int wpa_driver_nl80211_get_info(s
116 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
117 0, NL80211_CMD_GET_WIPHY, 0);
119 - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
120 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->first_bss.ifindex);
122 if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info) == 0)
124 @@ -1152,15 +1154,18 @@ static void * wpa_driver_nl80211_init(vo
126 struct wpa_driver_nl80211_data *drv;
127 struct netlink_config *cfg;
128 + struct i802_bss *bss;
130 drv = os_zalloc(sizeof(*drv));
134 - os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
135 + bss = &drv->first_bss;
136 + os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
137 drv->monitor_ifidx = -1;
138 drv->monitor_sock = -1;
139 drv->ioctl_sock = -1;
140 + drv->first_bss.drv = drv;
142 if (wpa_driver_nl80211_init_nl(drv, ctx)) {
144 @@ -1187,7 +1192,7 @@ static void * wpa_driver_nl80211_init(vo
145 if (wpa_driver_nl80211_finish_drv_init(drv))
152 netlink_deinit(drv->netlink);
153 @@ -1207,17 +1212,19 @@ failed:
155 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
157 - drv->ifindex = if_nametoindex(drv->ifname);
158 + struct i802_bss *bss = &drv->first_bss;
160 + drv->ifindex = if_nametoindex(drv->first_bss.ifname);
163 - if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA) < 0) {
164 + if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA) < 0) {
165 wpa_printf(MSG_DEBUG, "nl80211: Could not configure driver to "
169 - if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1)) {
170 + if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) {
171 wpa_printf(MSG_ERROR, "Could not set interface '%s' UP",
177 @@ -1232,20 +1239,6 @@ wpa_driver_nl80211_finish_drv_init(struc
182 -static void wpa_driver_nl80211_free_bss(struct wpa_driver_nl80211_data *drv)
184 - struct i802_bss *bss, *prev;
185 - bss = drv->bss.next;
192 -#endif /* HOSTAPD */
195 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
198 @@ -1273,14 +1266,15 @@ static int wpa_driver_nl80211_del_beacon
200 static void wpa_driver_nl80211_deinit(void *priv)
202 - struct wpa_driver_nl80211_data *drv = priv;
203 + struct i802_bss *bss = priv;
204 + struct wpa_driver_nl80211_data *drv = bss->drv;
206 if (drv->added_if_into_bridge) {
207 - if (linux_br_del_if(drv->ioctl_sock, drv->brname, drv->ifname)
208 + if (linux_br_del_if(drv->ioctl_sock, drv->brname, bss->ifname)
210 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
211 "interface %s from bridge %s: %s",
212 - drv->ifname, drv->brname, strerror(errno));
213 + bss->ifname, drv->brname, strerror(errno));
215 if (drv->added_bridge) {
216 if (linux_br_del(drv->ioctl_sock, drv->brname) < 0)
217 @@ -1310,8 +1304,6 @@ static void wpa_driver_nl80211_deinit(vo
219 if (drv->if_indices != drv->default_if_indices)
220 os_free(drv->if_indices);
222 - wpa_driver_nl80211_free_bss(drv);
225 if (drv->disable_11b_rates)
226 @@ -1322,8 +1314,8 @@ static void wpa_driver_nl80211_deinit(vo
228 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
230 - (void) linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0);
231 - wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA);
232 + (void) linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0);
233 + wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA);
235 if (drv->ioctl_sock >= 0)
236 close(drv->ioctl_sock);
237 @@ -1355,7 +1347,7 @@ static void wpa_driver_nl80211_scan_time
239 struct wpa_driver_nl80211_data *drv = eloop_ctx;
240 if (drv->ap_scan_as_station) {
241 - wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP);
242 + wpa_driver_nl80211_set_mode(&drv->first_bss, IEEE80211_MODE_AP);
243 drv->ap_scan_as_station = 0;
245 wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
246 @@ -1372,7 +1364,8 @@ static void wpa_driver_nl80211_scan_time
247 static int wpa_driver_nl80211_scan(void *priv,
248 struct wpa_driver_scan_params *params)
250 - struct wpa_driver_nl80211_data *drv = priv;
251 + struct i802_bss *bss = priv;
252 + struct wpa_driver_nl80211_data *drv = bss->drv;
253 int ret = 0, timeout;
254 struct nl_msg *msg, *ssids, *freqs;
256 @@ -1421,12 +1414,12 @@ static int wpa_driver_nl80211_scan(void
257 * mac80211 does not allow scan requests in AP mode, so
258 * try to do this in station mode.
260 - if (wpa_driver_nl80211_set_mode(drv,
261 + if (wpa_driver_nl80211_set_mode(bss,
262 IEEE80211_MODE_INFRA))
263 goto nla_put_failure;
265 if (wpa_driver_nl80211_scan(drv, params)) {
266 - wpa_driver_nl80211_set_mode(drv,
267 + wpa_driver_nl80211_set_mode(bss,
269 goto nla_put_failure;
271 @@ -1662,7 +1655,8 @@ static void wpa_scan_results_free(struct
272 static struct wpa_scan_results *
273 wpa_driver_nl80211_get_scan_results(void *priv)
275 - struct wpa_driver_nl80211_data *drv = priv;
276 + struct i802_bss *bss = priv;
277 + struct wpa_driver_nl80211_data *drv = bss->drv;
279 struct wpa_scan_results *res;
281 @@ -1701,7 +1695,8 @@ static int wpa_driver_nl80211_set_key(co
282 const u8 *seq, size_t seq_len,
283 const u8 *key, size_t key_len)
285 - struct wpa_driver_nl80211_data *drv = priv;
286 + struct i802_bss *bss = priv;
287 + struct wpa_driver_nl80211_data *drv = bss->drv;
288 int ifindex = if_nametoindex(ifname);
291 @@ -1958,7 +1953,8 @@ static int wpa_driver_nl80211_disconnect
292 static int wpa_driver_nl80211_deauthenticate(void *priv, const u8 *addr,
295 - struct wpa_driver_nl80211_data *drv = priv;
296 + struct i802_bss *bss = priv;
297 + struct wpa_driver_nl80211_data *drv = bss->drv;
298 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
299 return wpa_driver_nl80211_disconnect(drv, addr, reason_code);
300 wpa_printf(MSG_DEBUG, "%s", __func__);
301 @@ -1971,7 +1967,8 @@ static int wpa_driver_nl80211_deauthenti
302 static int wpa_driver_nl80211_disassociate(void *priv, const u8 *addr,
305 - struct wpa_driver_nl80211_data *drv = priv;
306 + struct i802_bss *bss = priv;
307 + struct wpa_driver_nl80211_data *drv = bss->drv;
308 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
309 return wpa_driver_nl80211_disconnect(drv, addr, reason_code);
310 wpa_printf(MSG_DEBUG, "%s", __func__);
311 @@ -1984,7 +1981,8 @@ static int wpa_driver_nl80211_disassocia
312 static int wpa_driver_nl80211_authenticate(
313 void *priv, struct wpa_driver_auth_params *params)
315 - struct wpa_driver_nl80211_data *drv = priv;
316 + struct i802_bss *bss = priv;
317 + struct wpa_driver_nl80211_data *drv = bss->drv;
320 enum nl80211_auth_type type;
321 @@ -1996,7 +1994,7 @@ static int wpa_driver_nl80211_authentica
322 if (drv->nlmode != NL80211_IFTYPE_STATION)
323 wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA);
325 - if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA) < 0)
326 + if (wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA) < 0)
330 @@ -2013,7 +2011,7 @@ retry:
331 for (i = 0; i < 4; i++) {
332 if (!params->wep_key[i])
334 - wpa_driver_nl80211_set_key(drv->ifname, drv, WPA_ALG_WEP, NULL,
335 + wpa_driver_nl80211_set_key(bss->ifname, drv, WPA_ALG_WEP, NULL,
337 i == params->wep_tx_keyidx, NULL, 0,
339 @@ -2348,7 +2346,8 @@ wpa_driver_nl80211_add_11b(struct hostap
340 static struct hostapd_hw_modes *
341 wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
343 - struct wpa_driver_nl80211_data *drv = priv;
344 + struct i802_bss *bss = priv;
345 + struct wpa_driver_nl80211_data *drv = bss->drv;
347 struct phy_info_arg result = {
348 .num_modes = num_modes,
349 @@ -2417,7 +2416,8 @@ static int wpa_driver_nl80211_send_frame
350 static int wpa_driver_nl80211_send_mlme(void *priv, const u8 *data,
353 - struct wpa_driver_nl80211_data *drv = priv;
354 + struct i802_bss *bss = priv;
355 + struct wpa_driver_nl80211_data *drv = bss->drv;
356 struct ieee80211_mgmt *mgmt;
359 @@ -2448,23 +2448,15 @@ static int wpa_driver_nl80211_set_beacon
360 const u8 *tail, size_t tail_len,
361 int dtim_period, int beacon_int)
363 - struct wpa_driver_nl80211_data *drv = priv;
364 + struct i802_bss *bss = priv;
365 + struct wpa_driver_nl80211_data *drv = bss->drv;
367 u8 cmd = NL80211_CMD_NEW_BEACON;
370 int ifindex = if_nametoindex(ifname);
372 - struct i802_bss *bss;
374 - bss = get_bss(drv, ifindex);
377 beacon_set = bss->beacon_set;
379 - beacon_set = drv->beacon_set;
380 -#endif /* HOSTAPD */
385 @@ -2487,11 +2479,7 @@ static int wpa_driver_nl80211_set_beacon
386 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
387 ret, strerror(-ret));
392 - drv->beacon_set = 1;
393 -#endif /* HOSTAPD */
397 @@ -2545,7 +2533,8 @@ nla_put_failure:
398 static int wpa_driver_nl80211_sta_add(const char *ifname, void *priv,
399 struct hostapd_sta_add_params *params)
401 - struct wpa_driver_nl80211_data *drv = priv;
402 + struct i802_bss *bss = priv;
403 + struct wpa_driver_nl80211_data *drv = bss->drv;
407 @@ -2582,7 +2571,8 @@ static int wpa_driver_nl80211_sta_add(co
409 static int wpa_driver_nl80211_sta_remove(void *priv, const u8 *addr)
411 - struct wpa_driver_nl80211_data *drv = priv;
412 + struct i802_bss *bss = priv;
413 + struct wpa_driver_nl80211_data *drv = bss->drv;
417 @@ -2594,7 +2584,7 @@ static int wpa_driver_nl80211_sta_remove
418 0, NL80211_CMD_DEL_STATION, 0);
420 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
421 - if_nametoindex(drv->ifname));
422 + if_nametoindex(bss->ifname));
423 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
425 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
426 @@ -3032,7 +3022,7 @@ nl80211_create_monitor_interface(struct
430 - snprintf(buf, IFNAMSIZ, "mon.%s", drv->ifname);
431 + snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname);
432 buf[IFNAMSIZ - 1] = '\0';
435 @@ -3092,7 +3082,8 @@ static int wpa_driver_nl80211_hapd_send_
436 void *priv, const u8 *addr, const u8 *data,
437 size_t data_len, int encrypt, const u8 *own_addr)
439 - struct wpa_driver_nl80211_data *drv = priv;
440 + struct i802_bss *bss = priv;
441 + struct wpa_driver_nl80211_data *drv = bss->drv;
442 struct ieee80211_hdr *hdr;
445 @@ -3177,7 +3168,8 @@ static int wpa_driver_nl80211_sta_set_fl
446 int total_flags, int flags_or,
449 - struct wpa_driver_nl80211_data *drv = priv;
450 + struct i802_bss *bss = priv;
451 + struct wpa_driver_nl80211_data *drv = bss->drv;
452 struct nl_msg *msg, *flags = NULL;
453 struct nl80211_sta_flag_update upd;
455 @@ -3195,7 +3187,7 @@ static int wpa_driver_nl80211_sta_set_fl
456 0, NL80211_CMD_SET_STATION, 0);
458 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
459 - if_nametoindex(drv->ifname));
460 + if_nametoindex(bss->ifname));
461 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
464 @@ -3234,7 +3226,7 @@ static int wpa_driver_nl80211_sta_set_fl
465 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
466 struct wpa_driver_associate_params *params)
468 - if (wpa_driver_nl80211_set_mode(drv, params->mode) ||
469 + if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode) ||
470 wpa_driver_nl80211_set_freq(drv, params->freq, 0, 0)) {
471 nl80211_remove_monitor_interface(drv);
473 @@ -3285,7 +3277,7 @@ static int wpa_driver_nl80211_ibss(struc
475 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
477 - if (wpa_driver_nl80211_set_mode(drv, params->mode)) {
478 + if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode)) {
479 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
482 @@ -3499,7 +3491,8 @@ nla_put_failure:
483 static int wpa_driver_nl80211_associate(
484 void *priv, struct wpa_driver_associate_params *params)
486 - struct wpa_driver_nl80211_data *drv = priv;
487 + struct i802_bss *bss = priv;
488 + struct wpa_driver_nl80211_data *drv = bss->drv;
492 @@ -3510,7 +3503,7 @@ static int wpa_driver_nl80211_associate(
493 return wpa_driver_nl80211_ibss(drv, params);
495 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
496 - if (wpa_driver_nl80211_set_mode(drv, params->mode) < 0)
497 + if (wpa_driver_nl80211_set_mode(priv, params->mode) < 0)
499 return wpa_driver_nl80211_connect(drv, params);
501 @@ -3611,7 +3604,8 @@ nla_put_failure:
503 static int wpa_driver_nl80211_set_mode(void *priv, int mode)
505 - struct wpa_driver_nl80211_data *drv = priv;
506 + struct i802_bss *bss = priv;
507 + struct wpa_driver_nl80211_data *drv = bss->drv;
511 @@ -3646,10 +3640,10 @@ static int wpa_driver_nl80211_set_mode(v
512 * take the device down, try to set the mode again, and bring the
515 - if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0) == 0) {
516 + if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) == 0) {
517 /* Try to set the mode again while the interface is down */
518 ret = nl80211_set_mode(drv, drv->ifindex, nlmode);
519 - if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1))
520 + if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1))
524 @@ -3684,7 +3678,8 @@ done:
525 static int wpa_driver_nl80211_get_capa(void *priv,
526 struct wpa_driver_capa *capa)
528 - struct wpa_driver_nl80211_data *drv = priv;
529 + struct i802_bss *bss = priv;
530 + struct wpa_driver_nl80211_data *drv = bss->drv;
531 if (!drv->has_capability)
533 os_memcpy(capa, &drv->capa, sizeof(*capa));
534 @@ -3694,7 +3689,8 @@ static int wpa_driver_nl80211_get_capa(v
536 static int wpa_driver_nl80211_set_operstate(void *priv, int state)
538 - struct wpa_driver_nl80211_data *drv = priv;
539 + struct i802_bss *bss = priv;
540 + struct wpa_driver_nl80211_data *drv = bss->drv;
542 wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
543 __func__, drv->operstate, state, state ? "UP" : "DORMANT");
544 @@ -3706,7 +3702,8 @@ static int wpa_driver_nl80211_set_operst
546 static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
548 - struct wpa_driver_nl80211_data *drv = priv;
549 + struct i802_bss *bss = priv;
550 + struct wpa_driver_nl80211_data *drv = bss->drv;
552 struct nl80211_sta_flag_update upd;
554 @@ -3718,7 +3715,7 @@ static int wpa_driver_nl80211_set_supp_p
555 0, NL80211_CMD_SET_STATION, 0);
557 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
558 - if_nametoindex(drv->ifname));
559 + if_nametoindex(bss->ifname));
560 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid);
562 os_memset(&upd, 0, sizeof(upd));
563 @@ -3735,20 +3732,6 @@ static int wpa_driver_nl80211_set_supp_p
567 -static struct i802_bss * get_bss(struct wpa_driver_nl80211_data *drv,
570 - struct i802_bss *bss = &drv->bss;
572 - if (ifindex == bss->ifindex)
576 - wpa_printf(MSG_DEBUG, "nl80211: get_bss(%d) failed", ifindex);
581 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
584 @@ -3842,7 +3825,8 @@ static int get_key_handler(struct nl_msg
585 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
588 - struct wpa_driver_nl80211_data *drv = priv;
589 + struct i802_bss *bss = priv;
590 + struct wpa_driver_nl80211_data *drv = bss->drv;
594 @@ -3868,7 +3852,8 @@ static int i802_get_seqnum(const char *i
595 static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
598 - struct wpa_driver_nl80211_data *drv = priv;
599 + struct i802_bss *bss = priv;
600 + struct wpa_driver_nl80211_data *drv = bss->drv;
602 u8 rates[NL80211_MAX_SUPP_RATES];
604 @@ -3887,7 +3872,7 @@ static int i802_set_rate_sets(void *priv
605 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
607 /* TODO: multi-BSS support */
608 - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
609 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
611 return send_and_recv_msgs(drv, msg, NULL, NULL);
613 @@ -3898,7 +3883,8 @@ static int i802_set_rate_sets(void *priv
614 /* Set kernel driver on given frequency (MHz) */
615 static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
617 - struct wpa_driver_nl80211_data *drv = priv;
618 + struct i802_bss *bss = priv;
619 + struct wpa_driver_nl80211_data *drv = bss->drv;
620 return wpa_driver_nl80211_set_freq(drv, freq->freq, freq->ht_enabled,
621 freq->sec_channel_offset);
623 @@ -3906,7 +3892,8 @@ static int i802_set_freq(void *priv, str
625 static int i802_set_rts(void *priv, int rts)
627 - struct wpa_driver_nl80211_data *drv = priv;
628 + struct i802_bss *bss = priv;
629 + struct wpa_driver_nl80211_data *drv = bss->drv;
633 @@ -3937,7 +3924,8 @@ nla_put_failure:
635 static int i802_set_frag(void *priv, int frag)
637 - struct wpa_driver_nl80211_data *drv = priv;
638 + struct i802_bss *bss = priv;
639 + struct wpa_driver_nl80211_data *drv = bss->drv;
643 @@ -3968,7 +3956,8 @@ nla_put_failure:
645 static int i802_flush(void *priv)
647 - struct wpa_driver_nl80211_data *drv = priv;
648 + struct i802_bss *bss = priv;
649 + struct wpa_driver_nl80211_data *drv = bss->drv;
653 @@ -3982,7 +3971,7 @@ static int i802_flush(void *priv)
654 * XXX: FIX! this needs to flush all VLANs too
656 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
657 - if_nametoindex(drv->ifname));
658 + if_nametoindex(bss->ifname));
660 return send_and_recv_msgs(drv, msg, NULL, NULL);
662 @@ -4044,7 +4033,8 @@ static int get_sta_handler(struct nl_msg
663 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
666 - struct wpa_driver_nl80211_data *drv = priv;
667 + struct i802_bss *bss = priv;
668 + struct wpa_driver_nl80211_data *drv = bss->drv;
671 os_memset(data, 0, sizeof(*data));
672 @@ -4056,7 +4046,7 @@ static int i802_read_sta_data(void *priv
673 0, NL80211_CMD_GET_STATION, 0);
675 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
676 - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
677 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
679 return send_and_recv_msgs(drv, msg, get_sta_handler, data);
681 @@ -4067,7 +4057,8 @@ static int i802_read_sta_data(void *priv
682 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
683 int cw_min, int cw_max, int burst_time)
685 - struct wpa_driver_nl80211_data *drv = priv;
686 + struct i802_bss *bss = priv;
687 + struct wpa_driver_nl80211_data *drv = bss->drv;
689 struct nlattr *txq, *params;
691 @@ -4078,7 +4069,7 @@ static int i802_set_tx_queue_params(void
692 genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
693 0, NL80211_CMD_SET_WIPHY, 0);
695 - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
696 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
698 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
700 @@ -4110,7 +4101,8 @@ static int i802_set_tx_queue_params(void
702 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
704 - struct wpa_driver_nl80211_data *drv = priv;
705 + struct i802_bss *bss = priv;
706 + struct wpa_driver_nl80211_data *drv = bss->drv;
710 @@ -4128,7 +4120,7 @@ static int i802_set_bss(void *priv, int
711 NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
713 /* TODO: multi-BSS support */
714 - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
715 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
717 return send_and_recv_msgs(drv, msg, NULL, NULL);
719 @@ -4157,7 +4149,8 @@ static int i802_set_short_slot_time(void
720 static int i802_set_sta_vlan(void *priv, const u8 *addr,
721 const char *ifname, int vlan_id)
723 - struct wpa_driver_nl80211_data *drv = priv;
724 + struct i802_bss *bss = priv;
725 + struct wpa_driver_nl80211_data *drv = bss->drv;
729 @@ -4168,7 +4161,7 @@ static int i802_set_sta_vlan(void *priv,
730 0, NL80211_CMD_SET_STATION, 0);
732 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
733 - if_nametoindex(drv->ifname));
734 + if_nametoindex(bss->ifname));
735 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
736 NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN,
737 if_nametoindex(ifname));
738 @@ -4181,10 +4174,11 @@ static int i802_set_sta_vlan(void *priv,
740 static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val)
742 - struct wpa_driver_nl80211_data *drv = priv;
743 + struct i802_bss *bss = priv;
744 + struct wpa_driver_nl80211_data *drv = bss->drv;
747 - os_snprintf(name, sizeof(name), "%s.sta%d", drv->ifname, aid);
748 + os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
750 if (nl80211_create_iface(priv, name, NL80211_IFTYPE_AP_VLAN,
752 @@ -4192,7 +4186,7 @@ static int i802_set_wds_sta(void *priv,
753 linux_set_iface_flags(drv->ioctl_sock, name, 1);
754 return i802_set_sta_vlan(priv, addr, name, 0);
756 - i802_set_sta_vlan(priv, addr, drv->ifname, 0);
757 + i802_set_sta_vlan(priv, addr, bss->ifname, 0);
758 return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN,
761 @@ -4244,7 +4238,8 @@ static int i802_sta_clear_stats(void *pr
762 static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
765 - struct wpa_driver_nl80211_data *drv = priv;
766 + struct i802_bss *bss = priv;
767 + struct wpa_driver_nl80211_data *drv = bss->drv;
768 struct ieee80211_mgmt mgmt;
770 memset(&mgmt, 0, sizeof(mgmt));
771 @@ -4254,7 +4249,7 @@ static int i802_sta_deauth(void *priv, c
772 memcpy(mgmt.sa, own_addr, ETH_ALEN);
773 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
774 mgmt.u.deauth.reason_code = host_to_le16(reason);
775 - return wpa_driver_nl80211_send_mlme(drv, (u8 *) &mgmt,
776 + return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
778 sizeof(mgmt.u.deauth));
780 @@ -4263,7 +4258,8 @@ static int i802_sta_deauth(void *priv, c
781 static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
784 - struct wpa_driver_nl80211_data *drv = priv;
785 + struct i802_bss *bss = priv;
786 + struct wpa_driver_nl80211_data *drv = bss->drv;
787 struct ieee80211_mgmt mgmt;
789 memset(&mgmt, 0, sizeof(mgmt));
790 @@ -4273,7 +4269,7 @@ static int i802_sta_disassoc(void *priv,
791 memcpy(mgmt.sa, own_addr, ETH_ALEN);
792 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
793 mgmt.u.disassoc.reason_code = host_to_le16(reason);
794 - return wpa_driver_nl80211_send_mlme(drv, (u8 *) &mgmt,
795 + return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
797 sizeof(mgmt.u.disassoc));
799 @@ -4335,17 +4331,17 @@ static void *i802_init(struct hostapd_da
800 struct wpa_init_params *params)
802 struct wpa_driver_nl80211_data *drv;
803 + struct i802_bss *bss;
805 char brname[IFNAMSIZ];
806 int ifindex, br_ifindex;
809 - drv = wpa_driver_nl80211_init(hapd, params->ifname);
811 + bss = wpa_driver_nl80211_init(hapd, params->ifname);
815 - drv->bss.ifindex = drv->ifindex;
818 if (linux_br_get(brname, params->ifname) == 0) {
819 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
820 params->ifname, brname);
821 @@ -4373,18 +4369,18 @@ static void *i802_init(struct hostapd_da
822 /* start listening for EAPOL on the default AP interface */
823 add_ifidx(drv, drv->ifindex);
825 - if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0))
826 + if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0))
830 - if (linux_set_ifhwaddr(drv->ioctl_sock, drv->ifname,
831 + if (linux_set_ifhwaddr(drv->ioctl_sock, bss->ifname,
836 - if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP)) {
837 + if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_AP)) {
838 wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s "
839 - "into AP mode", drv->ifname);
840 + "into AP mode", bss->ifname);
844 @@ -4392,7 +4388,7 @@ static void *i802_init(struct hostapd_da
845 i802_check_bridge(drv, params->bridge[0], params->ifname) < 0)
848 - if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1))
849 + if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1))
852 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
853 @@ -4407,10 +4403,10 @@ static void *i802_init(struct hostapd_da
857 - if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, params->own_addr))
858 + if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, params->own_addr))
865 nl80211_remove_monitor_interface(drv);
866 @@ -4453,27 +4449,30 @@ static enum nl80211_iftype wpa_driver_nl
867 static int wpa_driver_nl80211_if_add(const char *iface, void *priv,
868 enum wpa_driver_if_type type,
869 const char *ifname, const u8 *addr,
871 + void *bss_ctx, void **drv_priv)
873 - struct wpa_driver_nl80211_data *drv = priv;
874 + struct i802_bss *bss = priv;
875 + struct wpa_driver_nl80211_data *drv = bss->drv;
878 - struct i802_bss *bss = NULL;
879 + struct i802_bss *new_bss = NULL;
881 if (type == WPA_IF_AP_BSS) {
882 - bss = os_zalloc(sizeof(*bss));
884 + new_bss = os_zalloc(sizeof(*new_bss));
885 + if (new_bss == NULL)
888 -#endif /* HOSTAPD */
891 ifidx = nl80211_create_iface(drv, ifname,
892 wpa_driver_nl80211_if_type(type), addr,
898 -#endif /* HOSTAPD */
899 + if (type == WPA_IF_AP_BSS)
905 @@ -4484,9 +4483,12 @@ static int wpa_driver_nl80211_if_add(con
909 - bss->ifindex = ifidx;
910 - bss->next = drv->bss.next;
911 - drv->bss.next = bss;
912 + strncpy(new_bss->ifname, ifname, IFNAMSIZ);
913 + new_bss->ifindex = ifidx;
914 + new_bss->drv = drv;
915 + new_bss->next = drv->first_bss.next;
916 + drv->first_bss.next = new_bss;
917 + *drv_priv = new_bss;
921 @@ -4498,27 +4500,27 @@ static int wpa_driver_nl80211_if_remove(
922 enum wpa_driver_if_type type,
925 - struct wpa_driver_nl80211_data *drv = priv;
926 + struct i802_bss *bss = priv;
927 + struct wpa_driver_nl80211_data *drv = bss->drv;
928 int ifindex = if_nametoindex(ifname);
930 nl80211_remove_iface(drv, ifindex);
933 - if (type == WPA_IF_AP_BSS) {
934 - struct i802_bss *bss, *prev;
936 - bss = drv->bss.next;
938 - if (ifindex == bss->ifindex) {
939 - prev->next = bss->next;
945 + if (type != WPA_IF_AP_BSS)
948 + if (bss != &drv->first_bss) {
949 + struct i802_bss *tbss = &drv->first_bss;
952 + if (tbss->next != bss)
955 + tbss->next = bss->next;
960 -#endif /* HOSTAPD */
964 @@ -4540,7 +4542,8 @@ static int cookie_handler(struct nl_msg
965 static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
966 unsigned int duration)
968 - struct wpa_driver_nl80211_data *drv = priv;
969 + struct i802_bss *bss = priv;
970 + struct wpa_driver_nl80211_data *drv = bss->drv;
974 @@ -4574,7 +4577,8 @@ nla_put_failure:
976 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
978 - struct wpa_driver_nl80211_data *drv = priv;
979 + struct i802_bss *bss = priv;
980 + struct wpa_driver_nl80211_data *drv = bss->drv;
984 @@ -4629,7 +4633,8 @@ static void wpa_driver_nl80211_probe_req
986 static int wpa_driver_nl80211_probe_req_report(void *priv, int report)
988 - struct wpa_driver_nl80211_data *drv = priv;
989 + struct i802_bss *bss = priv;
990 + struct wpa_driver_nl80211_data *drv = bss->drv;
992 if (drv->nlmode != NL80211_IFTYPE_STATION) {
993 wpa_printf(MSG_DEBUG, "nl80211: probe_req_report control only "
994 @@ -4666,9 +4671,10 @@ static int wpa_driver_nl80211_probe_req_
996 static int wpa_driver_nl80211_alloc_interface_addr(void *priv, u8 *addr)
998 - struct wpa_driver_nl80211_data *drv = priv;
999 + struct i802_bss *bss = priv;
1000 + struct wpa_driver_nl80211_data *drv = bss->drv;
1002 - if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, addr) < 0)
1003 + if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, addr) < 0)
1006 if (addr[0] & 0x02) {
1007 @@ -4738,7 +4744,8 @@ nla_put_failure:
1009 static int wpa_driver_nl80211_disable_11b_rates(void *priv, int disabled)
1011 - struct wpa_driver_nl80211_data *drv = priv;
1012 + struct i802_bss *bss = priv;
1013 + struct wpa_driver_nl80211_data *drv = bss->drv;
1014 drv->disable_11b_rates = disabled;
1015 return nl80211_disable_11b_rates(drv, drv->ifindex, disabled);
1017 @@ -4746,11 +4753,12 @@ static int wpa_driver_nl80211_disable_11
1019 static int wpa_driver_nl80211_deinit_ap(void *priv)
1021 - struct wpa_driver_nl80211_data *drv = priv;
1022 + struct i802_bss *bss = priv;
1023 + struct wpa_driver_nl80211_data *drv = bss->drv;
1024 if (drv->nlmode != NL80211_IFTYPE_AP)
1026 wpa_driver_nl80211_del_beacon(drv);
1027 - return wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA);
1028 + return wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA);
1032 --- a/src/drivers/driver.h
1033 +++ b/src/drivers/driver.h
1034 @@ -1472,11 +1472,12 @@ struct wpa_driver_ops {
1035 * @addr: Local address to use for the interface or %NULL to use the
1036 * parent interface address
1037 * @bss_ctx: BSS context for %WPA_IF_AP_BSS interfaces
1038 + * @drv_priv: Pointer for overwriting the driver context
1039 * Returns: 0 on success, -1 on failure
1041 int (*if_add)(const char *iface, void *priv,
1042 enum wpa_driver_if_type type, const char *ifname,
1043 - const u8 *addr, void *bss_ctx);
1044 + const u8 *addr, void *bss_ctx, void **drv_priv);
1047 * if_remove - Remove a virtual interface
1048 --- a/src/drivers/driver_test.c
1049 +++ b/src/drivers/driver_test.c
1050 @@ -1030,7 +1030,7 @@ static int test_driver_bss_remove(void *
1052 static int test_driver_if_add(const char *iface, void *priv,
1053 enum wpa_driver_if_type type, const char *ifname,
1054 - const u8 *addr, void *bss_ctx)
1055 + const u8 *addr, void *bss_ctx, void **drv_priv)
1057 wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s bss_ctx=%p)",
1058 __func__, iface, type, ifname, bss_ctx);
1059 --- a/src/ap/ap_drv_ops.c
1060 +++ b/src/ap/ap_drv_ops.c
1061 @@ -242,7 +242,8 @@ static int hostapd_set_beacon(const char
1063 static int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
1065 - return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL);
1066 + return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL,
1070 static int hostapd_vlan_if_remove(struct hostapd_data *hapd,
1071 @@ -407,12 +408,13 @@ int hostapd_set_ssid(struct hostapd_data
1074 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
1075 - const char *ifname, const u8 *addr, void *bss_ctx)
1076 + const char *ifname, const u8 *addr, void *bss_ctx,
1079 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
1081 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
1082 - ifname, addr, bss_ctx);
1083 + ifname, addr, bss_ctx, drv_priv);
1087 --- a/src/ap/ap_drv_ops.h
1088 +++ b/src/ap/ap_drv_ops.h
1089 @@ -26,7 +26,8 @@ int hostapd_set_generic_elem(struct host
1090 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len);
1091 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len);
1092 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
1093 - const char *ifname, const u8 *addr, void *bss_ctx);
1094 + const char *ifname, const u8 *addr, void *bss_ctx,
1096 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
1097 const char *ifname);
1098 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
1099 --- a/src/ap/hostapd.c
1100 +++ b/src/ap/hostapd.c
1101 @@ -484,7 +484,8 @@ static int hostapd_setup_bss(struct host
1103 hapd->interface_added = 1;
1104 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
1105 - hapd->conf->iface, hapd->own_addr, hapd)) {
1106 + hapd->conf->iface, hapd->own_addr, hapd,
1107 + &hapd->drv_priv)) {
1108 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
1109 MACSTR ")", MAC2STR(hapd->own_addr));