åç½®ã
RSSI (åä¿¡ä¿¡å·å¼·åº¦)ã§æ¤ç´¢ããã¦æ¥ã¦ããæ¹ãããã£ããã£ãã®ã§ãä¿¡å·å¼·åº¦ãåå¾ããæ¹æ³ãã¾ãã¯æ¸ãã¦ã¿ããã¨æãã¾ãã
å®ã¯ããããã®NICã®ä¿¡å·å¼·åº¦ã¯ãããã°ã©ã ããç¹å¥ãªAPIãå¼ã¶ã¾ã§ããªãåå¾ã§ãã¦ãã¾ã£ãããã¾ãã/proc/net/wirelessã®ä¸ãè¦ã¦ã¿ãã¨ã
$ cat /proc/net/wireless Inter-| sta-| Quality | Discarded packets | Missed | WE face | tus | link level noise | nwid crypt frag retry misc | beacon | 22 wlan0: 0000 100. -32 -88. 0 0 0 0 0 0
ã¨ãããããªåºåãå¾ããã¾ããããã®"Quality"æ¬ãä¿¡å·å¼·åº¦ã表ãã¦ãã¾ããå¾ã¯ãããé å¼µã£ã¦æåå解æããã°ããæã¿ã®å¤ãå¾ããã¾ããã
ããã«åºã¦ããæ°å¤ã¯ãã¡ããiwconfigã³ãã³ãã§ãå¾ããã¨ãåºæ¥ã¦ã
wlan0 IEEE 802.11abgn ESSID:"hogefuga" Mode:Managed Frequency:2.462 GHz Access Point: 00:11:22:33:44:55 Bit Rate=54 Mb/s Tx-Power=15 dBm Retry min limit:7 RTS thr:off Fragment thr=2352 B Power Management:off Link Quality=100/100 Signal level:-32 dBm Noise level=-88 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:0 Missed beacon:0
ããã®"Link Quality", "Signal level", "Noise level"ãã/proc/net/wirelessã®Qualityæ¬ã®ããããã«å¯¾å¿ãã¾ãã
ãã¦ãã¦ãããããæããåå¾ãã¦ãããã¼ã¿ãé å¼µã£ã¦æåå解æãã¦ã¿ã¦ãããã®ã§ãããããã°ã©ã ãããããããã¼ã¿ãæ±ãæã¯APIã使ã£ãæ¹ããæ軽ãã¤éãåãã¾ãããªã®ã§ãAPIçµç±ã§ä¿¡å·å¼·åº¦ãåå¾ãã¦ã¿ã¾ãããã
ã³ã¼ã
åç½®ããé·ãã£ãã§ãããããããå®éã®ã½ã¼ã¹ã³ã¼ãã§ããä»åã¯ioctlã使ãã¾ãã
#include <string.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <linux/wireless.h> #include <stdio.h> int main(void) { struct iwreq iwr; struct iw_statistics stat; int sk = socket(AF_INET, SOCK_DGRAM, 0); memset(&iwr, 0, sizeof(iwr)); memset(&stat, 0, sizeof(stat)); strncpy(iwr.ifr_name, "wlan0", IFNAMSIZ); iwr.u.data.pointer = &stat; iwr.u.data.length = sizeof(stat); ioctl(sk, SIOCGIWSTATS, &iwr); close(sk); printf("link quality: %d\n", stat.qual.qual); if(stat.qual.updated & IW_QUAL_DBM) { printf("link level %d dBm\n", (char)stat.qual.level); printf("noise %d dBm\n", (char)stat.qual.noise); } else { printf("link level %d\n", (char)stat.qual.level); printf("noise %d\n", (char)stat.qual.noise); } return 0; }
iwlibã¯ä½¿ã£ã¦ããªãã®ã§ãã³ã³ãã¤ã«ã¯åç´ã«ã
$ gcc sig.c
ã§ããã¾ãã
説æ
SIOCGIWSTATSãæå®ãã¦ioctlãå¼ã³åºãã¨ããã®æã®NICã®ç¶æ ãè¦ããã¾ããiwreqæ§é ä½ã®ifr_nameã¡ã³ãã«ã¯ãç¶æ ãè¦ããNICåãæå®ãã¾ããiwreqæ§é ä½ã¯ãµã¤ãºã«å¶éããã£ã¦ããã®ã¾ã¾ã§ã¯ç¶æ æ å ±ãå ¨ã¦æ ¼ç´åºæ¥ãªãã®ã§ãç¶æ æ å ±ãæ ¼ç´ããçºã®æ§é ä½iw_statisticsã®å¤æ°ãå¥ã«å®ç¾©ãã¦ããã®ãã¤ã³ã¿ã渡ãã¾ããu.data.pointerããã®çºã®å¤æ°ã§ãã