Browse Source

Add BSS flags to scan results to indicate signal quality validity

These flags are used to mark which values (level, noise, qual) are
invalid (not available from the driver) and whether level is using dBm.
D-Bus interface will now only report the values that were available.
Jouni Malinen 16 years ago
parent
commit
7c2849d2a0

+ 7 - 0
src/drivers/driver.h

@@ -81,8 +81,14 @@ struct wpa_scan_result {
 };
 
 
+#define WPA_SCAN_QUAL_INVALID		BIT(0)
+#define WPA_SCAN_NOISE_INVALID		BIT(1)
+#define WPA_SCAN_LEVEL_INVALID		BIT(2)
+#define WPA_SCAN_LEVEL_DBM		BIT(3)
+
 /**
  * struct wpa_scan_res - Scan result for an BSS/IBSS
+ * @flags: information flags about the BSS/IBSS (WPA_SCAN_*)
  * @bssid: BSSID
  * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
  * @beacon_int: beacon interval in TUs (host byte order)
@@ -103,6 +109,7 @@ struct wpa_scan_result {
  * report all IEs to make it easier to support future additions.
  */
 struct wpa_scan_res {
+	unsigned int flags;
 	u8 bssid[ETH_ALEN];
 	int freq;
 	u16 beacon_int;

+ 9 - 3
src/drivers/driver_nl80211.c

@@ -1769,10 +1769,16 @@ static int bss_info_handler(struct nl_msg *msg, void *arg)
 		r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]);
 	if (bss[NL80211_BSS_CAPABILITY])
 		r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]);
-	if (bss[NL80211_BSS_SIGNAL_UNSPEC])
-		r->qual = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]);
-	if (bss[NL80211_BSS_SIGNAL_MBM])
+	r->flags |= WPA_SCAN_NOISE_INVALID;
+	if (bss[NL80211_BSS_SIGNAL_MBM]) {
 		r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]);
+		r->level /= 100; /* mBm to dBm */
+		r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID;
+	} else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) {
+		r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]);
+		r->flags |= WPA_SCAN_LEVEL_INVALID;
+	} else
+		r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID;
 	if (bss[NL80211_BSS_TSF])
 		r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]);
 	r->ie_len = ie_len;

+ 8 - 0
src/drivers/driver_wext.c

@@ -1267,6 +1267,14 @@ static void wext_get_scan_qual(struct iw_event *iwe,
 	res->res.qual = iwe->u.qual.qual;
 	res->res.noise = iwe->u.qual.noise;
 	res->res.level = iwe->u.qual.level;
+	if (iwe->u.qual.updated & IW_QUAL_QUAL_INVALID)
+		res->res.flags |= WPA_SCAN_QUAL_INVALID;
+	if (iwe->u.qual.updated & IW_QUAL_LEVEL_INVALID)
+		res->res.flags |= WPA_SCAN_LEVEL_INVALID;
+	if (iwe->u.qual.updated & IW_QUAL_NOISE_INVALID)
+		res->res.flags |= WPA_SCAN_NOISE_INVALID;
+	if (iwe->u.qual.updated & IW_QUAL_DBM)
+		res->res.flags |= WPA_SCAN_LEVEL_DBM;
 }
 
 

+ 6 - 3
wpa_supplicant/ctrl_iface_dbus_handlers.c

@@ -436,11 +436,14 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 	if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities",
 					 res->caps))
 		goto error;
-	if (!wpa_dbus_dict_append_int32(&iter_dict, "quality", res->qual))
+	if (!(res->flags & WPA_SCAN_QUAL_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "quality", res->qual))
 		goto error;
-	if (!wpa_dbus_dict_append_int32(&iter_dict, "noise", res->noise))
+	if (!(res->flags & WPA_SCAN_NOISE_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "noise", res->noise))
 		goto error;
-	if (!wpa_dbus_dict_append_int32(&iter_dict, "level", res->level))
+	if (!(res->flags & WPA_SCAN_LEVEL_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "level", res->level))
 		goto error;
 	if (!wpa_dbus_dict_append_int32(&iter_dict, "maxrate",
 					wpa_scan_get_max_rate(res) * 500000))