diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index c1a24f7bc85f..507bdf72aecf 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ -665,6 +665,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, { s32 s32Error = 0; u32 i; + u32 sel_bssi_idx = UINT_MAX; u8 u8security = NO_ENCRYPT; enum AUTHTYPE tenuAuth_type = ANY; @@ -688,18 +689,24 @@ static int connect(struct wiphy *wiphy, struct net_device *dev, memcmp(last_scanned_shadow[i].ssid, sme->ssid, sme->ssid_len) == 0) { - if (!sme->bssid) - break; - else + if (!sme->bssid) { + if (sel_bssi_idx == UINT_MAX || + last_scanned_shadow[i].rssi > + last_scanned_shadow[sel_bssi_idx].rssi) + sel_bssi_idx = i; + } else { if (memcmp(last_scanned_shadow[i].bssid, sme->bssid, - ETH_ALEN) == 0) + ETH_ALEN) == 0) { + sel_bssi_idx = i; break; + } + } } } - if (i < last_scanned_cnt) { - pstrNetworkInfo = &last_scanned_shadow[i]; + if (sel_bssi_idx < last_scanned_cnt) { + pstrNetworkInfo = &last_scanned_shadow[sel_bssi_idx]; } else { s32Error = -ENOENT; wilc_connecting = 0;