common: Add helper function to convert RSSI to RCPI

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>
This commit is contained in:
Avraham Stern 2016-12-28 15:06:45 +02:00 committed by Jouni Malinen
parent 1ac4dba31a
commit b3060bf99f
3 changed files with 23 additions and 15 deletions

View 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;
}