Skip to content

Commit 1478e90

Browse files
teknoravergregkh
authored andcommitted
virt_wifi: fix error on connect
[ Upstream commit 17109e9 ] When connecting without first doing a scan, the BSS list is empty and __cfg80211_connect_result() generates this warning: $ iw dev wlan0 connect -w VirtWifi [ 15.371989] ------------[ cut here ]------------ [ 15.372179] WARNING: CPU: 0 PID: 92 at net/wireless/sme.c:756 __cfg80211_connect_result+0x402/0x440 [ 15.372383] CPU: 0 PID: 92 Comm: kworker/u2:2 Not tainted 5.13.0-kvm #444 [ 15.372512] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-3.fc34 04/01/2014 [ 15.372597] Workqueue: cfg80211 cfg80211_event_work [ 15.372756] RIP: 0010:__cfg80211_connect_result+0x402/0x440 [ 15.372818] Code: 48 2b 04 25 28 00 00 00 75 59 48 8b 3b 48 8b 76 10 48 8d 65 e0 5b 41 5c 41 5d 41 5e 5d 49 8d 65 f0 41 5d e9 d0 d4 fd ff 0f 0b <0f> 0b e9 f6 fd ff ff e8 f2 4a b4 ff e9 ec fd ff ff 0f 0b e9 19 fd [ 15.372966] RSP: 0018:ffffc900005cbdc0 EFLAGS: 00010246 [ 15.373022] RAX: 0000000000000000 RBX: ffff8880028e2400 RCX: ffff8880028e2472 [ 15.373088] RDX: 0000000000000002 RSI: 00000000fffffe01 RDI: ffffffff815335ba [ 15.373149] RBP: ffffc900005cbe00 R08: 0000000000000008 R09: ffff888002bdf8b8 [ 15.373209] R10: ffff88803ec208f0 R11: ffffffffffffe9ae R12: ffff88801d687d98 [ 15.373280] R13: ffff88801b5fe000 R14: ffffc900005cbdc0 R15: dead000000000100 [ 15.373330] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 15.373382] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 15.373425] CR2: 000056421c468958 CR3: 000000001b458001 CR4: 0000000000170eb0 [ 15.373478] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 15.373529] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 15.373580] Call Trace: [ 15.373611] ? cfg80211_process_wdev_events+0x10e/0x170 [ 15.373743] cfg80211_process_wdev_events+0x10e/0x170 [ 15.373783] cfg80211_process_rdev_events+0x21/0x40 [ 15.373846] cfg80211_event_work+0x20/0x30 [ 15.373892] process_one_work+0x1e9/0x340 [ 15.373956] worker_thread+0x4b/0x3f0 [ 15.374017] ? process_one_work+0x340/0x340 [ 15.374053] kthread+0x11f/0x140 [ 15.374089] ? set_kthread_struct+0x30/0x30 [ 15.374153] ret_from_fork+0x1f/0x30 [ 15.374187] ---[ end trace 321ef0cb7e9c0be1 ]--- wlan0 (phy #0): connected to 00:00:00:00:00:00 Add the fake bss just before the connect so that cfg80211_get_bss() finds the virtual network. As some code was duplicated, move it in a common function. Signed-off-by: Matteo Croce <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ecd8614 commit 1478e90

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

drivers/net/wireless/virt_wifi.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ static struct ieee80211_supported_band band_5ghz = {
136136
/* Assigned at module init. Guaranteed locally-administered and unicast. */
137137
static u8 fake_router_bssid[ETH_ALEN] __ro_after_init = {};
138138

139+
static void virt_wifi_inform_bss(struct wiphy *wiphy)
140+
{
141+
u64 tsf = div_u64(ktime_get_boottime_ns(), 1000);
142+
struct cfg80211_bss *informed_bss;
143+
static const struct {
144+
u8 tag;
145+
u8 len;
146+
u8 ssid[8];
147+
} __packed ssid = {
148+
.tag = WLAN_EID_SSID,
149+
.len = 8,
150+
.ssid = "VirtWifi",
151+
};
152+
153+
informed_bss = cfg80211_inform_bss(wiphy, &channel_5ghz,
154+
CFG80211_BSS_FTYPE_PRESP,
155+
fake_router_bssid, tsf,
156+
WLAN_CAPABILITY_ESS, 0,
157+
(void *)&ssid, sizeof(ssid),
158+
DBM_TO_MBM(-50), GFP_KERNEL);
159+
cfg80211_put_bss(wiphy, informed_bss);
160+
}
161+
139162
/* Called with the rtnl lock held. */
140163
static int virt_wifi_scan(struct wiphy *wiphy,
141164
struct cfg80211_scan_request *request)
@@ -156,28 +179,13 @@ static int virt_wifi_scan(struct wiphy *wiphy,
156179
/* Acquires and releases the rdev BSS lock. */
157180
static void virt_wifi_scan_result(struct work_struct *work)
158181
{
159-
struct {
160-
u8 tag;
161-
u8 len;
162-
u8 ssid[8];
163-
} __packed ssid = {
164-
.tag = WLAN_EID_SSID, .len = 8, .ssid = "VirtWifi",
165-
};
166-
struct cfg80211_bss *informed_bss;
167182
struct virt_wifi_wiphy_priv *priv =
168183
container_of(work, struct virt_wifi_wiphy_priv,
169184
scan_result.work);
170185
struct wiphy *wiphy = priv_to_wiphy(priv);
171186
struct cfg80211_scan_info scan_info = { .aborted = false };
172-
u64 tsf = div_u64(ktime_get_boottime_ns(), 1000);
173187

174-
informed_bss = cfg80211_inform_bss(wiphy, &channel_5ghz,
175-
CFG80211_BSS_FTYPE_PRESP,
176-
fake_router_bssid, tsf,
177-
WLAN_CAPABILITY_ESS, 0,
178-
(void *)&ssid, sizeof(ssid),
179-
DBM_TO_MBM(-50), GFP_KERNEL);
180-
cfg80211_put_bss(wiphy, informed_bss);
188+
virt_wifi_inform_bss(wiphy);
181189

182190
/* Schedules work which acquires and releases the rtnl lock. */
183191
cfg80211_scan_done(priv->scan_request, &scan_info);
@@ -225,10 +233,12 @@ static int virt_wifi_connect(struct wiphy *wiphy, struct net_device *netdev,
225233
if (!could_schedule)
226234
return -EBUSY;
227235

228-
if (sme->bssid)
236+
if (sme->bssid) {
229237
ether_addr_copy(priv->connect_requested_bss, sme->bssid);
230-
else
238+
} else {
239+
virt_wifi_inform_bss(wiphy);
231240
eth_zero_addr(priv->connect_requested_bss);
241+
}
232242

233243
wiphy_debug(wiphy, "connect\n");
234244

@@ -241,11 +251,13 @@ static void virt_wifi_connect_complete(struct work_struct *work)
241251
struct virt_wifi_netdev_priv *priv =
242252
container_of(work, struct virt_wifi_netdev_priv, connect.work);
243253
u8 *requested_bss = priv->connect_requested_bss;
244-
bool has_addr = !is_zero_ether_addr(requested_bss);
245254
bool right_addr = ether_addr_equal(requested_bss, fake_router_bssid);
246255
u16 status = WLAN_STATUS_SUCCESS;
247256

248-
if (!priv->is_up || (has_addr && !right_addr))
257+
if (is_zero_ether_addr(requested_bss))
258+
requested_bss = NULL;
259+
260+
if (!priv->is_up || (requested_bss && !right_addr))
249261
status = WLAN_STATUS_UNSPECIFIED_FAILURE;
250262
else
251263
priv->is_connected = true;

0 commit comments

Comments
 (0)