+ if (stats.qual.level != 0 || (stats.qual.updated & (IW_QUAL_DBM | IW_QUAL_RCPI))) {
+ if (!(stats.qual.updated & IW_QUAL_QUAL_INVALID)) {
+ info->quality = stats.qual.qual;
+ info->quality_max = range.max_qual.qual;
+ info->quality_average = range.avg_qual.qual;
+ info->flags |= WIRELESS_INFO_FLAG_HAS_QUALITY;
+ }
+
+ 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
+}
+
+void print_wireless_info(const char *interface, const char *format_up, const char *format_down) {
+ const char *walk;
+ wireless_info_t info;
+ if (get_wireless_info(interface, &info)) {