From 7350d55936ffcc4a0b1b0eb08a60a3433e74fc5a Mon Sep 17 00:00:00 2001 From: Jose A Ortega Ruiz Date: Mon, 22 Feb 2010 17:47:29 +0100 Subject: Wireless monitor: correctly computing link qualities Ignore-this: d03b31a12d52cf482841aae0fcf6829b darcs-hash:20100222164729-748be-ba76d94a4870bab3b9d8e7957af4d3097677dc0a.gz --- IWlib.hsc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/IWlib.hsc b/IWlib.hsc index f0bc655..c7c0555 100644 --- a/IWlib.hsc +++ b/IWlib.hsc @@ -56,7 +56,7 @@ getWirelessInfo iface = str <- c_iw_stats i istr stats rng 1 rgr <- c_iw_range i istr rng c_iw_close i - if (bcr < 0) then return $WirelessInfo {wiEssid = "", wiQuality = -1} else + if (bcr < 0) then return nullInfo else do hase <- (#peek struct wireless_config, has_essid) wc :: IO CInt eon <- (#peek struct wireless_config, essid_on) wc :: IO CInt essid <- if hase > 0 && eon > 0 then @@ -65,12 +65,13 @@ getWirelessInfo iface = peekCStringLen (e, fromIntegral (l :: CInt)) else return "" q <- if str >= 0 && rgr >=0 then - do let qual = (#ptr struct iw_statistics, qual) stats - qualv <- (#peek struct iw_param, value) qual :: IO CInt - let qualm = (#ptr struct iw_range, max_qual) rng - mv <- (#peek struct iw_param, value) qualm :: IO CInt + do qualv <- xqual $ (#ptr struct iw_statistics, qual) stats + mv <- xqual $ (#ptr struct iw_range, max_qual) rng let mxv = if mv > 0 then fromIntegral mv else 1 return $ fromIntegral qualv / mxv else return (-1) let qv = round (100 * (q :: Double)) return $ WirelessInfo { wiEssid = essid, wiQuality = min 100 qv } + where nullInfo = WirelessInfo { wiEssid = "", wiQuality = -1 } + xqual p = let qp = (#ptr struct iw_param, value) p in + (#peek struct iw_quality, qual) qp :: IO CChar -- cgit v1.2.3