+
+ if (stats.qual.updated & IW_QUAL_RCPI) {
+ if (!(stats.qual.updated & IW_QUAL_LEVEL_INVALID)) {
+ info->signal_level = stats.qual.level / 2.0 - 110 + 0.5;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
+ }
+ if (!(stats.qual.updated & IW_QUAL_NOISE_INVALID)) {
+ info->noise_level = stats.qual.noise / 2.0 - 110 + 0.5;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ }
+ } else {
+ if ((stats.qual.updated & IW_QUAL_DBM) || stats.qual.level > range.max_qual.level) {
+ if (!(stats.qual.updated & IW_QUAL_LEVEL_INVALID)) {
+ info->signal_level = stats.qual.level;
+ if (info->signal_level > 63)
+ info->signal_level -= 256;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
+ }
+ if (!(stats.qual.updated & IW_QUAL_NOISE_INVALID)) {
+ info->noise_level = stats.qual.noise;
+ if (info->noise_level > 63)
+ info->noise_level -= 256;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ }
+ } else {
+ if (!(stats.qual.updated & IW_QUAL_LEVEL_INVALID)) {
+ info->signal_level = stats.qual.level;
+ info->signal_level_max = range.max_qual.level;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
+ }
+ if (!(stats.qual.updated & IW_QUAL_NOISE_INVALID)) {
+ info->noise_level = stats.qual.noise;
+ info->noise_level_max = range.max_qual.noise;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ }
+ }
+ }
+ } else {
+ if (!(stats.qual.updated & IW_QUAL_QUAL_INVALID)) {
+ info->quality = stats.qual.qual;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_QUALITY;
+ }
+ if (!(stats.qual.updated & IW_QUAL_LEVEL_INVALID)) {
+ info->quality = stats.qual.level;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
+ }
+ if (!(stats.qual.updated & IW_QUAL_NOISE_INVALID)) {
+ info->quality = stats.qual.noise;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ }
+ }
+
+ struct iwreq wrq;
+ if (iw_get_ext(skfd, interface, SIOCGIWRATE, &wrq) >= 0)
+ info->bitrate = wrq.u.bitrate.value;
+
+ close(skfd);
+ return 1;
+#endif
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+ int s, len, inwid;
+ uint8_t buf[24 * 1024], *cp;
+ struct ieee80211req na;
+ char network_id[IEEE80211_NWID_LEN + 1];
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ return (0);
+
+ memset(&na, 0, sizeof(na));
+ strlcpy(na.i_name, interface, sizeof(na.i_name));
+ na.i_type = IEEE80211_IOC_SSID;
+ na.i_data = &info->essid[0];
+ na.i_len = IEEE80211_NWID_LEN + 1;
+ if ((inwid = ioctl(s, SIOCG80211, (caddr_t)&na)) == -1) {
+ close(s);
+ return (0);
+ }
+ if (inwid == 0) {
+ if (na.i_len <= IEEE80211_NWID_LEN)
+ len = na.i_len + 1;
+ else
+ len = IEEE80211_NWID_LEN + 1;
+ info->essid[len - 1] = '\0';
+ } else {
+ close(s);
+ return (0);
+ }
+ info->flags |= WIRELESS_INFO_FLAG_HAS_ESSID;
+
+ memset(&na, 0, sizeof(na));
+ strlcpy(na.i_name, interface, sizeof(na.i_name));
+ na.i_type = IEEE80211_IOC_SCAN_RESULTS;
+ na.i_data = buf;
+ na.i_len = sizeof(buf);
+
+ if (ioctl(s, SIOCG80211, (caddr_t)&na) == -1) {
+ printf("fail\n");
+ close(s);
+ return (0);
+ }
+
+ close(s);
+ len = na.i_len;
+ cp = buf;
+ struct ieee80211req_scan_result *sr;
+ uint8_t *vp;
+ sr = (struct ieee80211req_scan_result *)cp;
+ vp = (u_int8_t *)(sr + 1);
+ strlcpy(network_id, (const char *)vp, sr->isr_ssid_len + 1);
+ if (!strcmp(network_id, &info->essid[0])) {
+ info->signal_level = sr->isr_rssi;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_SIGNAL;
+ info->noise_level = sr->isr_noise;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_NOISE;
+ info->quality = sr->isr_intval;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_QUALITY;
+ }
+
+ return 1;