]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
common: Add helper function to convert RSSI to RCPI
authorAvraham Stern <avraham.stern@intel.com>
Wed, 28 Dec 2016 13:06:45 +0000 (15:06 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 3 Jan 2017 13:18:29 +0000 (15:18 +0200)
This conversion will be done several times in the code, so add a helper
function that does this conversion.

Signed-off-by: Avrahams Stern <avraham.stern@intel.com>
src/utils/common.c
src/utils/common.h
wpa_supplicant/rrm.c

index 04a533a05902ff9d9bbde7cea41dea679f40365f..1eb33705bef340b6c3f387760bb5b26a4e605ec7 100644 (file)
@@ -1200,3 +1200,24 @@ int str_starts(const char *str, const char *start)
 {
        return os_strncmp(str, start, os_strlen(start)) == 0;
 }
+
+
+/**
+ * rssi_to_rcpi - Convert RSSI to RCPI
+ * @rssi: RSSI to convert
+ * Returns: RCPI corresponding to the given RSSI value, or 255 if not available.
+ *
+ * It's possible to estimate RCPI based on RSSI in dBm. This calculation will
+ * not reflect the correct value for high rates, but it's good enough for Action
+ * frames which are transmitted with up to 24 Mbps rates.
+ */
+u8 rssi_to_rcpi(int rssi)
+{
+       if (!rssi)
+               return 255; /* not available */
+       if (rssi < -110)
+               return 0;
+       if (rssi > 0)
+               return 220;
+       return (rssi + 110) * 2;
+}
index 77856774d215cf020115f0193403e89ed4e4ef25..88428647ba1b0fa66362899053b69a0fb966bb21 100644 (file)
@@ -552,6 +552,7 @@ int is_ctrl_char(char c);
 
 int str_starts(const char *str, const char *start);
 
+u8 rssi_to_rcpi(int rssi);
 
 /*
  * gcc 4.4 ends up generating strict-aliasing warnings about some very common
index 85c6ed539ed3dcbffab5b344dc6c522754c44bcd..5223e8ef3d89d532101cf405b0acb86773a55a15 100644 (file)
@@ -598,21 +598,7 @@ void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant *wpa_s,
        report.tpc.len = 2;
        report.rsni = 255; /* 255 indicates that RSNI is not available */
        report.dialog_token = req->dialog_token;
-
-       /*
-        * It's possible to estimate RCPI based on RSSI in dBm. This
-        * calculation will not reflect the correct value for high rates,
-        * but it's good enough for Action frames which are transmitted
-        * with up to 24 Mbps rates.
-        */
-       if (!rssi)
-               report.rcpi = 255; /* not available */
-       else if (rssi < -110)
-               report.rcpi = 0;
-       else if (rssi > 0)
-               report.rcpi = 220;
-       else
-               report.rcpi = (rssi + 110) * 2;
+       report.rcpi = rssi_to_rcpi(rssi);
 
        /* action_category + action_code */
        buf = wpabuf_alloc(2 + sizeof(report));