/* Find the best AP. 
Used from association worker. */
static int lbs_find_best_network_ssid(struct lbs_private *priv, uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode, uint8_t *out_mode)
/* Find the best AP. 
Used from association worker. */
static int lbs_find_best_network_ssid(struct lbs_private *priv, uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode, uint8_t *out_mode)
{
	int ret = -1;
	struct bss_descriptor *found;
	lbs_deb_enter(LBS_DEB_SCAN);
	priv->scan_ssid_len = 0;
	lbs_scan_networks(priv, 1);
	if (priv->surpriseremoved)
		goto out;
	found = lbs_find_best_ssid_in_list(priv, preferred_mode);
	if (found && (found->ssid_len > 0)) {
		memcpy(out_ssid, &found->ssid, IEEE80211_MAX_SSID_LEN);
		*out_ssid_len = found->ssid_len;
		*out_mode = found->mode;
		ret = 0;
	}
out:
	lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
	return ret;
}