The formula is extremely simple and more or less copied verbatim from the obsoleted wireless-utils.
A mac82011 driver usually reports a signal as negative dB value, e.g. -87, the formula used to turn this into a "quality" is:
quality = max(min(signal, -40), -110) + 110
This gives you a range of 0 .. 70 for possible quality values, to turn that into a percentage (mostly used to draw fancy bars or reception strength indicators for UIs) the formula is:
You can obtain those values using the iwinfo program, the libiwinfo C library or the libiwinfo-lua binding.
Example program to print the quality value of "wlan0":
#!/usr/bin/lua
require "iwinfo"
local iface = "wlan0"
local backend = iwinfo.type(iface)
if not backend then
error(iface .. " is not a supported wireless device")
end
local bssid, info
local assoc = iwinfo[backend].assoclist(iface)
for bssid, info in pairs(assoc) do
print(string.format(
"Quality of %s is %.2f%% (Signal: %d dBm)",
bssid,
(100 / 70) * (math.max(math.min(info.signal, -40), -110) + 110),
info.signal
))
end
Note that this will dump all quality values for all stations in AP mode. The OpenWrt LuCI gui simply displays the average of all qualities in AP mode.