summaryrefslogtreecommitdiff
path: root/package/hostapd/patches/150-mbss_driver_handling.patch
blob: 412dc1cce98edc33903cb9f35f9197c36f1ea0c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -59,8 +59,10 @@
 #endif
 
 struct i802_bss {
+	struct wpa_driver_nl80211_data *drv;
 	struct i802_bss *next;
 	int ifindex;
+	char ifname[IFNAMSIZ + 1];
 	unsigned int beacon_set:1;
 };
 
@@ -68,7 +70,6 @@ struct wpa_driver_nl80211_data {
 	void *ctx;
 	struct netlink_data *netlink;
 	int ioctl_sock; /* socket for ioctl() use */
-	char ifname[IFNAMSIZ + 1];
 	char brname[IFNAMSIZ];
 	int ifindex;
 	int if_removed;
@@ -107,6 +108,8 @@ struct wpa_driver_nl80211_data {
 
 	u64 remain_on_chan_cookie;
 
+	struct i802_bss first_bss;
+
 #ifdef HOSTAPD
 	int eapol_sock; /* socket for EAPOL frames */
 
@@ -114,8 +117,6 @@ struct wpa_driver_nl80211_data {
 	int *if_indices;
 	int num_if_indices;
 
-	struct i802_bss bss;
-
 	int last_freq;
 	int last_freq_ht;
 #endif /* HOSTAPD */
@@ -135,8 +136,6 @@ static void nl80211_remove_monitor_inter
 #ifdef HOSTAPD
 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
 static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
-static struct i802_bss * get_bss(struct wpa_driver_nl80211_data *drv,
-				 int ifindex);
 static int i802_set_freq(void *priv, struct hostapd_freq_params *freq);
 static int wpa_driver_nl80211_if_remove(void *priv,
 					enum wpa_driver_if_type type,
@@ -278,7 +277,8 @@ nla_put_failure:
 
 static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (!drv->associated)
 		return -1;
 	os_memcpy(bssid, drv->bssid, ETH_ALEN);
@@ -288,7 +288,8 @@ static int wpa_driver_nl80211_get_bssid(
 
 static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (!drv->associated)
 		return -1;
 	os_memcpy(ssid, drv->ssid, drv->ssid_len);
@@ -313,7 +314,7 @@ static void wpa_driver_nl80211_event_lin
 		   event.interface_status.ifname,
 		   del ? "removed" : "added");
 
-	if (os_strcmp(drv->ifname, event.interface_status.ifname) == 0) {
+	if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) {
 		if (del)
 			drv->if_removed = 1;
 		else
@@ -336,7 +337,7 @@ static int wpa_driver_nl80211_own_ifname
 	rta_len = RTA_ALIGN(sizeof(struct rtattr));
 	while (RTA_OK(attr, attrlen)) {
 		if (attr->rta_type == IFLA_IFNAME) {
-			if (os_strcmp(((char *) attr) + rta_len, drv->ifname)
+			if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname)
 			    == 0)
 				return 1;
 			else
@@ -356,7 +357,7 @@ static int wpa_driver_nl80211_own_ifinde
 		return 1;
 
 	if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
-		drv->ifindex = if_nametoindex(drv->ifname);
+		drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname);
 		wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
 			   "interface");
 		wpa_driver_nl80211_finish_drv_init(drv);
@@ -785,7 +786,7 @@ static int process_event(struct nl_msg *
 	if (drv->ap_scan_as_station &&
 	    (gnlh->cmd == NL80211_CMD_NEW_SCAN_RESULTS ||
 	     gnlh->cmd == NL80211_CMD_SCAN_ABORTED)) {
-		wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP);
+		wpa_driver_nl80211_set_mode(&drv->first_bss, IEEE80211_MODE_AP);
 		drv->ap_scan_as_station = 0;
 	}
 
@@ -889,7 +890,8 @@ static void wpa_driver_nl80211_event_rec
  */
 static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	char alpha2[3];
 	struct nl_msg *msg;
 
@@ -978,7 +980,7 @@ static int wpa_driver_nl80211_get_info(s
 	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
 		    0, NL80211_CMD_GET_WIPHY, 0);
 
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->first_bss.ifindex);
 
 	if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info) == 0)
 		return 0;
@@ -1152,15 +1154,18 @@ static void * wpa_driver_nl80211_init(vo
 {
 	struct wpa_driver_nl80211_data *drv;
 	struct netlink_config *cfg;
+	struct i802_bss *bss;
 
 	drv = os_zalloc(sizeof(*drv));
 	if (drv == NULL)
 		return NULL;
 	drv->ctx = ctx;
-	os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
+	bss = &drv->first_bss;
+	os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
 	drv->monitor_ifidx = -1;
 	drv->monitor_sock = -1;
 	drv->ioctl_sock = -1;
+	drv->first_bss.drv = drv;
 
 	if (wpa_driver_nl80211_init_nl(drv, ctx)) {
 		os_free(drv);
@@ -1187,7 +1192,7 @@ static void * wpa_driver_nl80211_init(vo
 	if (wpa_driver_nl80211_finish_drv_init(drv))
 		goto failed;
 
-	return drv;
+	return bss;
 
 failed:
 	netlink_deinit(drv->netlink);
@@ -1207,17 +1212,19 @@ failed:
 static int
 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
 {
-	drv->ifindex = if_nametoindex(drv->ifname);
+	struct i802_bss *bss = &drv->first_bss;
+
+	drv->ifindex = if_nametoindex(drv->first_bss.ifname);
 
 #ifndef HOSTAPD
-	if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA) < 0) {
+	if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA) < 0) {
 		wpa_printf(MSG_DEBUG, "nl80211: Could not configure driver to "
 			   "use managed mode");
 	}
 
-	if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1)) {
+	if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1)) {
 		wpa_printf(MSG_ERROR, "Could not set interface '%s' UP",
-			   drv->ifname);
+			   bss->ifname);
 		return -1;
 	}
 
@@ -1232,20 +1239,6 @@ wpa_driver_nl80211_finish_drv_init(struc
 }
 
 
-#ifdef HOSTAPD
-static void wpa_driver_nl80211_free_bss(struct wpa_driver_nl80211_data *drv)
-{
-	struct i802_bss *bss, *prev;
-	bss = drv->bss.next;
-	while (bss) {
-		prev = bss;
-		bss = bss->next;
-		os_free(bss);
-	}
-}
-#endif /* HOSTAPD */
-
-
 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
 {
 	struct nl_msg *msg;
@@ -1273,14 +1266,15 @@ static int wpa_driver_nl80211_del_beacon
  */
 static void wpa_driver_nl80211_deinit(void *priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 
 	if (drv->added_if_into_bridge) {
-		if (linux_br_del_if(drv->ioctl_sock, drv->brname, drv->ifname)
+		if (linux_br_del_if(drv->ioctl_sock, drv->brname, bss->ifname)
 		    < 0)
 			wpa_printf(MSG_INFO, "nl80211: Failed to remove "
 				   "interface %s from bridge %s: %s",
-				   drv->ifname, drv->brname, strerror(errno));
+				   bss->ifname, drv->brname, strerror(errno));
 	}
 	if (drv->added_bridge) {
 		if (linux_br_del(drv->ioctl_sock, drv->brname) < 0)
@@ -1310,8 +1304,6 @@ static void wpa_driver_nl80211_deinit(vo
 
 	if (drv->if_indices != drv->default_if_indices)
 		os_free(drv->if_indices);
-
-	wpa_driver_nl80211_free_bss(drv);
 #endif /* HOSTAPD */
 
 	if (drv->disable_11b_rates)
@@ -1322,8 +1314,8 @@ static void wpa_driver_nl80211_deinit(vo
 
 	eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
 
-	(void) linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0);
-	wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA);
+	(void) linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0);
+	wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_INFRA);
 
 	if (drv->ioctl_sock >= 0)
 		close(drv->ioctl_sock);
@@ -1355,7 +1347,7 @@ static void wpa_driver_nl80211_scan_time
 {
 	struct wpa_driver_nl80211_data *drv = eloop_ctx;
 	if (drv->ap_scan_as_station) {
-		wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP);
+		wpa_driver_nl80211_set_mode(&drv->first_bss, IEEE80211_MODE_AP);
 		drv->ap_scan_as_station = 0;
 	}
 	wpa_printf(MSG_DEBUG, "Scan timeout - try to get results");
@@ -1372,7 +1364,8 @@ static void wpa_driver_nl80211_scan_time
 static int wpa_driver_nl80211_scan(void *priv,
 				   struct wpa_driver_scan_params *params)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ret = 0, timeout;
 	struct nl_msg *msg, *ssids, *freqs;
 	size_t i;
@@ -1421,12 +1414,12 @@ static int wpa_driver_nl80211_scan(void 
 			 * mac80211 does not allow scan requests in AP mode, so
 			 * try to do this in station mode.
 			 */
-			if (wpa_driver_nl80211_set_mode(drv,
+			if (wpa_driver_nl80211_set_mode(bss,
 							IEEE80211_MODE_INFRA))
 				goto nla_put_failure;
 
 			if (wpa_driver_nl80211_scan(drv, params)) {
-				wpa_driver_nl80211_set_mode(drv,
+				wpa_driver_nl80211_set_mode(bss,
 							    IEEE80211_MODE_AP);
 				goto nla_put_failure;
 			}
@@ -1662,7 +1655,8 @@ static void wpa_scan_results_free(struct
 static struct wpa_scan_results *
 wpa_driver_nl80211_get_scan_results(void *priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	struct wpa_scan_results *res;
 	int ret;
@@ -1701,7 +1695,8 @@ static int wpa_driver_nl80211_set_key(co
 				      const u8 *seq, size_t seq_len,
 				      const u8 *key, size_t key_len)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ifindex = if_nametoindex(ifname);
 	struct nl_msg *msg;
 	int ret;
@@ -1958,7 +1953,8 @@ static int wpa_driver_nl80211_disconnect
 static int wpa_driver_nl80211_deauthenticate(void *priv, const u8 *addr,
 					     int reason_code)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
 		return wpa_driver_nl80211_disconnect(drv, addr, reason_code);
 	wpa_printf(MSG_DEBUG, "%s", __func__);
@@ -1971,7 +1967,8 @@ static int wpa_driver_nl80211_deauthenti
 static int wpa_driver_nl80211_disassociate(void *priv, const u8 *addr,
 					   int reason_code)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
 		return wpa_driver_nl80211_disconnect(drv, addr, reason_code);
 	wpa_printf(MSG_DEBUG, "%s", __func__);
@@ -1984,7 +1981,8 @@ static int wpa_driver_nl80211_disassocia
 static int wpa_driver_nl80211_authenticate(
 	void *priv, struct wpa_driver_auth_params *params)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ret = -1, i;
 	struct nl_msg *msg;
 	enum nl80211_auth_type type;
@@ -1996,7 +1994,7 @@ static int wpa_driver_nl80211_authentica
 	if (drv->nlmode != NL80211_IFTYPE_STATION)
 		wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA);
 
-	if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA) < 0)
+	if (wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA) < 0)
 		return -1;
 
 retry:
@@ -2013,7 +2011,7 @@ retry:
 	for (i = 0; i < 4; i++) {
 		if (!params->wep_key[i])
 			continue;
-		wpa_driver_nl80211_set_key(drv->ifname, drv, WPA_ALG_WEP, NULL,
+		wpa_driver_nl80211_set_key(bss->ifname, drv, WPA_ALG_WEP, NULL,
 					   i,
 					   i == params->wep_tx_keyidx, NULL, 0,
 					   params->wep_key[i],
@@ -2348,7 +2346,8 @@ wpa_driver_nl80211_add_11b(struct hostap
 static struct hostapd_hw_modes *
 wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	struct phy_info_arg result = {
 		.num_modes = num_modes,
@@ -2417,7 +2416,8 @@ static int wpa_driver_nl80211_send_frame
 static int wpa_driver_nl80211_send_mlme(void *priv, const u8 *data,
 					size_t data_len)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct ieee80211_mgmt *mgmt;
 	int encrypt = 1;
 	u16 fc;
@@ -2448,23 +2448,15 @@ static int wpa_driver_nl80211_set_beacon
 					 const u8 *tail, size_t tail_len,
 					 int dtim_period, int beacon_int)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	u8 cmd = NL80211_CMD_NEW_BEACON;
 	int ret;
 	int beacon_set;
 	int ifindex = if_nametoindex(ifname);
-#ifdef HOSTAPD
-	struct i802_bss *bss;
 
-	bss = get_bss(drv, ifindex);
-	if (bss == NULL)
-		return -ENOENT;
 	beacon_set = bss->beacon_set;
-#else /* HOSTAPD */
-	beacon_set = drv->beacon_set;
-#endif /* HOSTAPD */
-
 	msg = nlmsg_alloc();
 	if (!msg)
 		return -ENOMEM;
@@ -2487,11 +2479,7 @@ static int wpa_driver_nl80211_set_beacon
 		wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
 			   ret, strerror(-ret));
 	} else {
-#ifdef HOSTAPD
 		bss->beacon_set = 1;
-#else /* HOSTAPD */
-		drv->beacon_set = 1;
-#endif /* HOSTAPD */
 	}
 	return ret;
  nla_put_failure:
@@ -2545,7 +2533,8 @@ nla_put_failure:
 static int wpa_driver_nl80211_sta_add(const char *ifname, void *priv,
 				      struct hostapd_sta_add_params *params)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret = -ENOBUFS;
 
@@ -2582,7 +2571,8 @@ static int wpa_driver_nl80211_sta_add(co
 
 static int wpa_driver_nl80211_sta_remove(void *priv, const u8 *addr)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret;
 
@@ -2594,7 +2584,7 @@ static int wpa_driver_nl80211_sta_remove
 		    0, NL80211_CMD_DEL_STATION, 0);
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->ifname));
+		    if_nametoindex(bss->ifname));
 	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
 
 	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
@@ -3032,7 +3022,7 @@ nl80211_create_monitor_interface(struct 
 	int optval;
 	socklen_t optlen;
 
-	snprintf(buf, IFNAMSIZ, "mon.%s", drv->ifname);
+	snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname);
 	buf[IFNAMSIZ - 1] = '\0';
 
 	drv->monitor_ifidx =
@@ -3092,7 +3082,8 @@ static int wpa_driver_nl80211_hapd_send_
 	void *priv, const u8 *addr, const u8 *data,
 	size_t data_len, int encrypt, const u8 *own_addr)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct ieee80211_hdr *hdr;
 	size_t len;
 	u8 *pos;
@@ -3177,7 +3168,8 @@ static int wpa_driver_nl80211_sta_set_fl
 					    int total_flags, int flags_or,
 					    int flags_and)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg, *flags = NULL;
 	struct nl80211_sta_flag_update upd;
 
@@ -3195,7 +3187,7 @@ static int wpa_driver_nl80211_sta_set_fl
 		    0, NL80211_CMD_SET_STATION, 0);
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->ifname));
+		    if_nametoindex(bss->ifname));
 	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
 
 	/*
@@ -3234,7 +3226,7 @@ static int wpa_driver_nl80211_sta_set_fl
 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
 				 struct wpa_driver_associate_params *params)
 {
-	if (wpa_driver_nl80211_set_mode(drv, params->mode) ||
+	if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode) ||
 	    wpa_driver_nl80211_set_freq(drv, params->freq, 0, 0)) {
 		nl80211_remove_monitor_interface(drv);
 		return -1;
@@ -3285,7 +3277,7 @@ static int wpa_driver_nl80211_ibss(struc
 
 	wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
 
-	if (wpa_driver_nl80211_set_mode(drv, params->mode)) {
+	if (wpa_driver_nl80211_set_mode(&drv->first_bss, params->mode)) {
 		wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
 			   "IBSS mode");
 		return -1;
@@ -3499,7 +3491,8 @@ nla_put_failure:
 static int wpa_driver_nl80211_associate(
 	void *priv, struct wpa_driver_associate_params *params)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ret = -1;
 	struct nl_msg *msg;
 
@@ -3510,7 +3503,7 @@ static int wpa_driver_nl80211_associate(
 		return wpa_driver_nl80211_ibss(drv, params);
 
 	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
-		if (wpa_driver_nl80211_set_mode(drv, params->mode) < 0)
+		if (wpa_driver_nl80211_set_mode(priv, params->mode) < 0)
 			return -1;
 		return wpa_driver_nl80211_connect(drv, params);
 	}
@@ -3611,7 +3604,8 @@ nla_put_failure:
 
 static int wpa_driver_nl80211_set_mode(void *priv, int mode)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ret = -1;
 	int nlmode;
 
@@ -3646,10 +3640,10 @@ static int wpa_driver_nl80211_set_mode(v
 	 * take the device down, try to set the mode again, and bring the
 	 * device back up.
 	 */
-	if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0) == 0) {
+	if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) == 0) {
 		/* Try to set the mode again while the interface is down */
 		ret = nl80211_set_mode(drv, drv->ifindex, nlmode);
-		if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1))
+		if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1))
 			ret = -1;
 	}
 
@@ -3684,7 +3678,8 @@ done:
 static int wpa_driver_nl80211_get_capa(void *priv,
 				       struct wpa_driver_capa *capa)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (!drv->has_capability)
 		return -1;
 	os_memcpy(capa, &drv->capa, sizeof(*capa));
@@ -3694,7 +3689,8 @@ static int wpa_driver_nl80211_get_capa(v
 
 static int wpa_driver_nl80211_set_operstate(void *priv, int state)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 
 	wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
 		   __func__, drv->operstate, state, state ? "UP" : "DORMANT");
@@ -3706,7 +3702,8 @@ static int wpa_driver_nl80211_set_operst
 
 static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	struct nl80211_sta_flag_update upd;
 
@@ -3718,7 +3715,7 @@ static int wpa_driver_nl80211_set_supp_p
 		    0, NL80211_CMD_SET_STATION, 0);
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->ifname));
+		    if_nametoindex(bss->ifname));
 	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid);
 
 	os_memset(&upd, 0, sizeof(upd));
@@ -3735,20 +3732,6 @@ static int wpa_driver_nl80211_set_supp_p
 
 #ifdef HOSTAPD
 
-static struct i802_bss * get_bss(struct wpa_driver_nl80211_data *drv,
-				 int ifindex)
-{
-	struct i802_bss *bss = &drv->bss;
-	while (bss) {
-		if (ifindex == bss->ifindex)
-			return bss;
-		bss = bss->next;
-	}
-	wpa_printf(MSG_DEBUG, "nl80211: get_bss(%d) failed", ifindex);
-	return NULL;
-}
-
-
 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
 {
 	int i;
@@ -3842,7 +3825,8 @@ static int get_key_handler(struct nl_msg
 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
 			   int idx, u8 *seq)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 
 	msg = nlmsg_alloc();
@@ -3868,7 +3852,8 @@ static int i802_get_seqnum(const char *i
 static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
 			      int mode)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	u8 rates[NL80211_MAX_SUPP_RATES];
 	u8 rates_len = 0;
@@ -3887,7 +3872,7 @@ static int i802_set_rate_sets(void *priv
 	NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
 
 	/* TODO: multi-BSS support */
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
 
 	return send_and_recv_msgs(drv, msg, NULL, NULL);
  nla_put_failure:
@@ -3898,7 +3883,8 @@ static int i802_set_rate_sets(void *priv
 /* Set kernel driver on given frequency (MHz) */
 static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	return wpa_driver_nl80211_set_freq(drv, freq->freq, freq->ht_enabled,
 					   freq->sec_channel_offset);
 }
@@ -3906,7 +3892,8 @@ static int i802_set_freq(void *priv, str
 
 static int i802_set_rts(void *priv, int rts)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret = -ENOBUFS;
 	u32 val;
@@ -3937,7 +3924,8 @@ nla_put_failure:
 
 static int i802_set_frag(void *priv, int frag)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret = -ENOBUFS;
 	u32 val;
@@ -3968,7 +3956,8 @@ nla_put_failure:
 
 static int i802_flush(void *priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 
 	msg = nlmsg_alloc();
@@ -3982,7 +3971,7 @@ static int i802_flush(void *priv)
 	 * XXX: FIX! this needs to flush all VLANs too
 	 */
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->ifname));
+		    if_nametoindex(bss->ifname));
 
 	return send_and_recv_msgs(drv, msg, NULL, NULL);
  nla_put_failure:
@@ -4044,7 +4033,8 @@ static int get_sta_handler(struct nl_msg
 static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
 			      const u8 *addr)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 
 	os_memset(data, 0, sizeof(*data));
@@ -4056,7 +4046,7 @@ static int i802_read_sta_data(void *priv
 		    0, NL80211_CMD_GET_STATION, 0);
 
 	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
 
 	return send_and_recv_msgs(drv, msg, get_sta_handler, data);
  nla_put_failure:
@@ -4067,7 +4057,8 @@ static int i802_read_sta_data(void *priv
 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
 				    int cw_min, int cw_max, int burst_time)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	struct nlattr *txq, *params;
 
@@ -4078,7 +4069,7 @@ static int i802_set_tx_queue_params(void
 	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
 		    0, NL80211_CMD_SET_WIPHY, 0);
 
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
 
 	txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
 	if (!txq)
@@ -4110,7 +4101,8 @@ static int i802_set_tx_queue_params(void
 
 static int i802_set_bss(void *priv, int cts, int preamble, int slot)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 
 	msg = nlmsg_alloc();
@@ -4128,7 +4120,7 @@ static int i802_set_bss(void *priv, int 
 		NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
 
 	/* TODO: multi-BSS support */
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->ifname));
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname));
 
 	return send_and_recv_msgs(drv, msg, NULL, NULL);
  nla_put_failure:
@@ -4157,7 +4149,8 @@ static int i802_set_short_slot_time(void
 static int i802_set_sta_vlan(void *priv, const u8 *addr,
 			     const char *ifname, int vlan_id)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 
 	msg = nlmsg_alloc();
@@ -4168,7 +4161,7 @@ static int i802_set_sta_vlan(void *priv,
 		    0, NL80211_CMD_SET_STATION, 0);
 
 	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->ifname));
+		    if_nametoindex(bss->ifname));
 	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
 	NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN,
 		    if_nametoindex(ifname));
@@ -4181,18 +4174,19 @@ static int i802_set_sta_vlan(void *priv,
 
 static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	char name[16];
 
-	os_snprintf(name, sizeof(name), "%s.sta%d", drv->ifname, aid);
+	os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
 	if (val) {
-		if (nl80211_create_iface(priv, name, NL80211_IFTYPE_AP_VLAN,
+		if (nl80211_create_iface(drv, name, NL80211_IFTYPE_AP_VLAN,
 					 NULL, 1) < 0)
 			return -1;
 		linux_set_iface_flags(drv->ioctl_sock, name, 1);
 		return i802_set_sta_vlan(priv, addr, name, 0);
 	} else {
-		i802_set_sta_vlan(priv, addr, drv->ifname, 0);
+		i802_set_sta_vlan(priv, addr, bss->ifname, 0);
 		return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN,
 						    name);
 	}
@@ -4244,7 +4238,8 @@ static int i802_sta_clear_stats(void *pr
 static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
 			   int reason)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct ieee80211_mgmt mgmt;
 
 	memset(&mgmt, 0, sizeof(mgmt));
@@ -4254,7 +4249,7 @@ static int i802_sta_deauth(void *priv, c
 	memcpy(mgmt.sa, own_addr, ETH_ALEN);
 	memcpy(mgmt.bssid, own_addr, ETH_ALEN);
 	mgmt.u.deauth.reason_code = host_to_le16(reason);
-	return wpa_driver_nl80211_send_mlme(drv, (u8 *) &mgmt,
+	return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
 					    IEEE80211_HDRLEN +
 					    sizeof(mgmt.u.deauth));
 }
@@ -4263,7 +4258,8 @@ static int i802_sta_deauth(void *priv, c
 static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
 			     int reason)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct ieee80211_mgmt mgmt;
 
 	memset(&mgmt, 0, sizeof(mgmt));
@@ -4273,7 +4269,7 @@ static int i802_sta_disassoc(void *priv,
 	memcpy(mgmt.sa, own_addr, ETH_ALEN);
 	memcpy(mgmt.bssid, own_addr, ETH_ALEN);
 	mgmt.u.disassoc.reason_code = host_to_le16(reason);
-	return wpa_driver_nl80211_send_mlme(drv, (u8 *) &mgmt,
+	return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
 					    IEEE80211_HDRLEN +
 					    sizeof(mgmt.u.disassoc));
 }
@@ -4335,17 +4331,17 @@ static void *i802_init(struct hostapd_da
 		       struct wpa_init_params *params)
 {
 	struct wpa_driver_nl80211_data *drv;
+	struct i802_bss *bss;
 	size_t i;
 	char brname[IFNAMSIZ];
 	int ifindex, br_ifindex;
 	int br_added = 0;
 
-	drv = wpa_driver_nl80211_init(hapd, params->ifname);
-	if (drv == NULL)
+	bss = wpa_driver_nl80211_init(hapd, params->ifname);
+	if (bss == NULL)
 		return NULL;
 
-	drv->bss.ifindex = drv->ifindex;
-
+	drv = bss->drv;
 	if (linux_br_get(brname, params->ifname) == 0) {
 		wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
 			   params->ifname, brname);
@@ -4373,18 +4369,18 @@ static void *i802_init(struct hostapd_da
 	/* start listening for EAPOL on the default AP interface */
 	add_ifidx(drv, drv->ifindex);
 
-	if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0))
+	if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0))
 		goto failed;
 
 	if (params->bssid) {
-		if (linux_set_ifhwaddr(drv->ioctl_sock, drv->ifname,
+		if (linux_set_ifhwaddr(drv->ioctl_sock, bss->ifname,
 				       params->bssid))
 			goto failed;
 	}
 
-	if (wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_AP)) {
+	if (wpa_driver_nl80211_set_mode(bss, IEEE80211_MODE_AP)) {
 		wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s "
-			   "into AP mode", drv->ifname);
+			   "into AP mode", bss->ifname);
 		goto failed;
 	}
 
@@ -4392,7 +4388,7 @@ static void *i802_init(struct hostapd_da
 	    i802_check_bridge(drv, params->bridge[0], params->ifname) < 0)
 		goto failed;
 
-	if (linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1))
+	if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1))
 		goto failed;
 
 	drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
@@ -4407,10 +4403,10 @@ static void *i802_init(struct hostapd_da
 		goto failed;
 	}
 
-	if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, params->own_addr))
+	if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, params->own_addr))
 		goto failed;
 
-	return drv;
+	return bss;
 
 failed:
 	nl80211_remove_monitor_interface(drv);
@@ -4453,27 +4449,30 @@ static enum nl80211_iftype wpa_driver_nl
 static int wpa_driver_nl80211_if_add(const char *iface, void *priv,
 				     enum wpa_driver_if_type type,
 				     const char *ifname, const u8 *addr,
-				     void *bss_ctx)
+				     void *bss_ctx, void **drv_priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ifidx;
 #ifdef HOSTAPD
-	struct i802_bss *bss = NULL;
+	struct i802_bss *new_bss = NULL;
 
 	if (type == WPA_IF_AP_BSS) {
-		bss = os_zalloc(sizeof(*bss));
-		if (bss == NULL)
+		new_bss = os_zalloc(sizeof(*new_bss));
+		if (new_bss == NULL)
 			return -1;
 	}
-#endif /* HOSTAPD */
+#endif
 
 	ifidx = nl80211_create_iface(drv, ifname,
 				     wpa_driver_nl80211_if_type(type), addr,
 				     0);
+
 	if (ifidx < 0) {
 #ifdef HOSTAPD
-		os_free(bss);
-#endif /* HOSTAPD */
+		if (type == WPA_IF_AP_BSS)
+			os_free(new_bss);
+#endif
 		return -1;
 	}
 
@@ -4484,9 +4483,12 @@ static int wpa_driver_nl80211_if_add(con
 			os_free(bss);
 			return -1;
 		}
-		bss->ifindex = ifidx;
-		bss->next = drv->bss.next;
-		drv->bss.next = bss;
+		strncpy(new_bss->ifname, ifname, IFNAMSIZ);
+		new_bss->ifindex = ifidx;
+		new_bss->drv = drv;
+		new_bss->next = drv->first_bss.next;
+		drv->first_bss.next = new_bss;
+		*drv_priv = new_bss;
 	}
 #endif /* HOSTAPD */
 
@@ -4498,27 +4500,27 @@ static int wpa_driver_nl80211_if_remove(
 					enum wpa_driver_if_type type,
 					const char *ifname)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	int ifindex = if_nametoindex(ifname);
 
 	nl80211_remove_iface(drv, ifindex);
 
-#ifdef HOSTAPD
-	if (type == WPA_IF_AP_BSS) {
-		struct i802_bss *bss, *prev;
-		prev = &drv->bss;
-		bss = drv->bss.next;
-		while (bss) {
-			if (ifindex == bss->ifindex) {
-				prev->next = bss->next;
-				os_free(bss);
-				break;
-			}
-			prev = bss;
-			bss = bss->next;
+	if (type != WPA_IF_AP_BSS)
+		return 0;
+
+	if (bss != &drv->first_bss) {
+		struct i802_bss *tbss = &drv->first_bss;
+
+		while (tbss) {
+			if (tbss->next != bss)
+				continue;
+
+			tbss->next = bss->next;
+			os_free(bss);
+			break;
 		}
 	}
-#endif /* HOSTAPD */
 
 	return 0;
 }
@@ -4540,7 +4542,8 @@ static int cookie_handler(struct nl_msg 
 static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
 						unsigned int duration)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret;
 	u64 cookie;
@@ -4574,7 +4577,8 @@ nla_put_failure:
 
 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	struct nl_msg *msg;
 	int ret;
 
@@ -4629,7 +4633,8 @@ static void wpa_driver_nl80211_probe_req
 
 static int wpa_driver_nl80211_probe_req_report(void *priv, int report)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 
 	if (drv->nlmode != NL80211_IFTYPE_STATION) {
 		wpa_printf(MSG_DEBUG, "nl80211: probe_req_report control only "
@@ -4666,9 +4671,10 @@ static int wpa_driver_nl80211_probe_req_
 
 static int wpa_driver_nl80211_alloc_interface_addr(void *priv, u8 *addr)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 
-	if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, addr) < 0)
+	if (linux_get_ifhwaddr(drv->ioctl_sock, bss->ifname, addr) < 0)
 		return -1;
 
 	if (addr[0] & 0x02) {
@@ -4738,7 +4744,8 @@ nla_put_failure:
 
 static int wpa_driver_nl80211_disable_11b_rates(void *priv, int disabled)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	drv->disable_11b_rates = disabled;
 	return nl80211_disable_11b_rates(drv, drv->ifindex, disabled);
 }
@@ -4746,11 +4753,12 @@ static int wpa_driver_nl80211_disable_11
 
 static int wpa_driver_nl80211_deinit_ap(void *priv)
 {
-	struct wpa_driver_nl80211_data *drv = priv;
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
 	if (drv->nlmode != NL80211_IFTYPE_AP)
 		return -1;
 	wpa_driver_nl80211_del_beacon(drv);
-	return wpa_driver_nl80211_set_mode(drv, IEEE80211_MODE_INFRA);
+	return wpa_driver_nl80211_set_mode(priv, IEEE80211_MODE_INFRA);
 }
 
 
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -1472,11 +1472,12 @@ struct wpa_driver_ops {
 	 * @addr: Local address to use for the interface or %NULL to use the
 	 *	parent interface address
 	 * @bss_ctx: BSS context for %WPA_IF_AP_BSS interfaces
+	 * @drv_priv: Pointer for overwriting the driver context
 	 * Returns: 0 on success, -1 on failure
 	 */
 	int (*if_add)(const char *iface, void *priv,
 		      enum wpa_driver_if_type type, const char *ifname,
-		      const u8 *addr, void *bss_ctx);
+		      const u8 *addr, void *bss_ctx, void **drv_priv);
 
 	/**
 	 * if_remove - Remove a virtual interface
--- a/src/drivers/driver_test.c
+++ b/src/drivers/driver_test.c
@@ -1030,7 +1030,7 @@ static int test_driver_bss_remove(void *
 
 static int test_driver_if_add(const char *iface, void *priv,
 			      enum wpa_driver_if_type type, const char *ifname,
-			      const u8 *addr, void *bss_ctx)
+			      const u8 *addr, void *bss_ctx, void **drv_priv)
 {
 	wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s bss_ctx=%p)",
 		   __func__, iface, type, ifname, bss_ctx);
--- a/src/ap/ap_drv_ops.c
+++ b/src/ap/ap_drv_ops.c
@@ -242,7 +242,8 @@ static int hostapd_set_beacon(const char
 
 static int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
 {
-	return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL);
+	return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL,
+			      &hapd->drv_priv);
 }
 
 static int hostapd_vlan_if_remove(struct hostapd_data *hapd,
@@ -407,12 +408,13 @@ int hostapd_set_ssid(struct hostapd_data
 
 
 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
-		   const char *ifname, const u8 *addr, void *bss_ctx)
+		   const char *ifname, const u8 *addr, void *bss_ctx,
+		   void **drv_priv)
 {
 	if (hapd->driver == NULL || hapd->driver->if_add == NULL)
 		return -1;
 	return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
-				    ifname, addr, bss_ctx);
+				    ifname, addr, bss_ctx, drv_priv);
 }
 
 
--- a/src/ap/ap_drv_ops.h
+++ b/src/ap/ap_drv_ops.h
@@ -26,7 +26,8 @@ int hostapd_set_generic_elem(struct host
 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len);
 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len);
 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
-		   const char *ifname, const u8 *addr, void *bss_ctx);
+		   const char *ifname, const u8 *addr, void *bss_ctx,
+		   void **drv_priv);
 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
 		      const char *ifname);
 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -484,7 +484,8 @@ static int hostapd_setup_bss(struct host
 
 		hapd->interface_added = 1;
 		if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
-				   hapd->conf->iface, hapd->own_addr, hapd)) {
+				   hapd->conf->iface, hapd->own_addr, hapd,
+				   &hapd->drv_priv)) {
 			wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
 				   MACSTR ")", MAC2STR(hapd->own_addr));
 			return -1;