about summary refs log tree commit diff
path: root/src/platform/wifi/wifi-utils-nl80211.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/wifi/wifi-utils-nl80211.c')
-rw-r--r--src/platform/wifi/wifi-utils-nl80211.c81
1 files changed, 50 insertions, 31 deletions
diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c
index ac51678f..06eb7cb9 100644
--- a/src/platform/wifi/wifi-utils-nl80211.c
+++ b/src/platform/wifi/wifi-utils-nl80211.c
@@ -27,7 +27,6 @@
 #include <sys/ioctl.h>
 #include <net/ethernet.h>
 #include <unistd.h>
-#include <math.h>
 #include <netlink/netlink.h>
 #include <netlink/msg.h>
 #include <linux/nl80211.h>
@@ -35,8 +34,17 @@
 #include "wifi-utils-private.h"
 #include "wifi-utils-nl80211.h"
 #include "platform/nm-platform.h"
+#include "platform/nm-platform-utils.h"
 #include "nm-utils.h"
 
+#define _NMLOG_PREFIX_NAME      "wifi-nl80211"
+#define _NMLOG(level, domain, ...) \
+	G_STMT_START { \
+		nm_log ((level), (domain), NULL, NULL, \
+		        "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+		        _NMLOG_PREFIX_NAME \
+		        _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+	} G_STMT_END
 
 /*****************************************************************************
  * Copied from libnl3/genl:
@@ -219,9 +227,9 @@ out_cb_free:
 	nl_cb_put (cb);
 out:
 	if (result >= 0)
-		nm_log_dbg (LOGD_WIFI, "genl_ctrl_resolve: resolved \"%s\" as 0x%x", name, result);
+		_LOGD (LOGD_WIFI, "genl_ctrl_resolve: resolved \"%s\" as 0x%x", name, result);
 	else
-		nm_log_err (LOGD_WIFI, "genl_ctrl_resolve: failed resolve \"%s\"", name);
+		_LOGE (LOGD_WIFI, "genl_ctrl_resolve: failed resolve \"%s\"", name);
 	return result;
 }
 
@@ -333,8 +341,8 @@ _nl80211_send_and_recv (struct nl_sock *nl_sock,
 			    genlmsg_hdr (nlmsg_hdr (msg))->cmd == NL80211_CMD_GET_SCAN)
 				break;
 
-			nm_log_warn (LOGD_WIFI, "nl_recvmsgs() error: (%d) %s",
-			             err, nl_geterror (err));
+			_LOGW (LOGD_WIFI, "nl_recvmsgs() error: (%d) %s",
+			       err, nl_geterror (err));
 			break;
 		}
 	}
@@ -934,8 +942,9 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg)
 
 		nla_for_each_nested (nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
 		                     rem_freq) {
-			nla_parse_nested (tb_freq, NL80211_FREQUENCY_ATTR_MAX,
-			                  nl_freq, freq_policy);
+			if (nla_parse_nested (tb_freq, NL80211_FREQUENCY_ATTR_MAX,
+			                      nl_freq, freq_policy) < 0)
+				continue;
 
 			if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
 				continue;
@@ -955,8 +964,9 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg)
 
 		nla_for_each_nested (nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
 		                    rem_freq) {
-			nla_parse_nested (tb_freq, NL80211_FREQUENCY_ATTR_MAX,
-			                  nl_freq, freq_policy);
+			if (nla_parse_nested (tb_freq, NL80211_FREQUENCY_ATTR_MAX,
+			                      nl_freq, freq_policy) < 0)
+				continue;
 
 			if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
 				continue;
@@ -1003,7 +1013,9 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg)
 			case WLAN_CIPHER_SUITE_SMS4:
 				break;
 			default:
-				nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI, "Don't know the meaning of NL80211_ATTR_CIPHER_SUITE %#8.8x.", ciphers[i]);
+				_LOGD (LOGD_PLATFORM | LOGD_WIFI,
+				       "don't know the meaning of NL80211_ATTR_CIPHER_SUITE %#8.8x.",
+				       ciphers[i]);
 				break;
 			}
 		}
@@ -1030,13 +1042,20 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg)
 }
 
 WifiData *
-wifi_nl80211_init (const char *iface, int ifindex)
+wifi_nl80211_init (int ifindex)
 {
 	WifiDataNl80211 *nl80211;
 	struct nl_msg *msg;
 	struct nl80211_device_info device_info = {};
+	char ifname[IFNAMSIZ];
+
+	if (!nmp_utils_if_indextoname (ifindex, ifname)) {
+		_LOGW (LOGD_PLATFORM | LOGD_WIFI,
+		       "can't determine interface name for ifindex %d", ifindex);
+		nm_sprintf_buf (ifname, "if %d", ifindex);
+	}
 
-	nl80211 = wifi_data_new (iface, ifindex, sizeof (*nl80211));
+	nl80211 = wifi_data_new (ifindex, sizeof (*nl80211));
 	nl80211->parent.get_mode = wifi_nl80211_get_mode;
 	nl80211->parent.set_mode = wifi_nl80211_set_mode;
 	nl80211->parent.set_powersave = wifi_nl80211_set_powersave;
@@ -1071,44 +1090,44 @@ wifi_nl80211_init (const char *iface, int ifindex)
 
 	if (nl80211_send_and_recv (nl80211, msg, nl80211_wiphy_info_handler,
 	                           &device_info) < 0) {
-		nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI,
-		            "(%s): NL80211_CMD_GET_WIPHY request failed",
-		            nl80211->parent.iface);
+		_LOGD (LOGD_PLATFORM | LOGD_WIFI,
+		       "(%s): NL80211_CMD_GET_WIPHY request failed",
+		       ifname);
 		goto error;
 	}
 
 	if (!device_info.success) {
-		nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI,
-		            "(%s): NL80211_CMD_GET_WIPHY request indicated failure",
-		            nl80211->parent.iface);
+		_LOGD (LOGD_PLATFORM | LOGD_WIFI,
+		       "(%s): NL80211_CMD_GET_WIPHY request indicated failure",
+		       ifname);
 		goto error;
 	}
 
 	if (!device_info.supported) {
-		nm_log_dbg (LOGD_PLATFORM | LOGD_WIFI,
-		            "(%s): driver does not fully support nl80211, falling back to WEXT",
-		            nl80211->parent.iface);
+		_LOGD (LOGD_PLATFORM | LOGD_WIFI,
+		       "(%s): driver does not fully support nl80211, falling back to WEXT",
+		       ifname);
 		goto error;
 	}
 
 	if (!device_info.can_scan_ssid) {
-		nm_log_err (LOGD_PLATFORM | LOGD_WIFI,
-		            "(%s): driver does not support SSID scans",
-		            nl80211->parent.iface);
+		_LOGE (LOGD_PLATFORM | LOGD_WIFI,
+		       "(%s): driver does not support SSID scans",
+		       ifname);
 		goto error;
 	}
 
 	if (device_info.num_freqs == 0 || device_info.freqs == NULL) {
 		nm_log_err (LOGD_PLATFORM | LOGD_WIFI,
 		            "(%s): driver reports no supported frequencies",
-		            nl80211->parent.iface);
+		            ifname);
 		goto error;
 	}
 
 	if (device_info.caps == 0) {
-		nm_log_err (LOGD_PLATFORM | LOGD_WIFI,
-		            "(%s): driver doesn't report support of any encryption",
-		            nl80211->parent.iface);
+		_LOGE (LOGD_PLATFORM | LOGD_WIFI,
+		       "(%s): driver doesn't report support of any encryption",
+		       ifname);
 		goto error;
 	}
 
@@ -1120,9 +1139,9 @@ wifi_nl80211_init (const char *iface, int ifindex)
 	if (device_info.can_wowlan)
 		nl80211->parent.get_wowlan = wifi_nl80211_get_wowlan;
 
-	nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
-	             "(%s): using nl80211 for WiFi device control",
-	             nl80211->parent.iface);
+	_LOGI (LOGD_PLATFORM | LOGD_WIFI,
+	       "(%s): using nl80211 for WiFi device control",
+	       ifname);
 
 	return (WifiData *) nl80211;