summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-03-21 18:51:38 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2017-03-21 18:51:38 +0100
commitd3b1e08c9abde0448a6304f90e888207e08f55e1 (patch)
tree527ff4cc9b3bf9caa705f44e1810404d56744f58
parent7de4912ff05ef291f54d87c2ad5edc5c2d193f49 (diff)
parentc26471e7dee5cd5f9f6576272bdf92ca22b8d44e (diff)
downloadNetworkManager-d3b1e08c9abde0448a6304f90e888207e08f55e1.tar.gz
Merge branch 'bg/wext-refresh-ifname-bgo779788'
https://bugzilla.gnome.org/show_bug.cgi?id=779788
-rw-r--r--shared/nm-utils/nm-macros-internal.h6
-rw-r--r--src/platform/nm-linux-platform.c21
-rw-r--r--src/platform/wifi/wifi-utils-nl80211.c70
-rw-r--r--src/platform/wifi/wifi-utils-nl80211.h2
-rw-r--r--src/platform/wifi/wifi-utils-private.h3
-rw-r--r--src/platform/wifi/wifi-utils-wext.c270
-rw-r--r--src/platform/wifi/wifi-utils-wext.h2
-rw-r--r--src/platform/wifi/wifi-utils.c19
-rw-r--r--src/platform/wifi/wifi-utils.h4
9 files changed, 234 insertions, 163 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 90f4e8533d..3147f58c2b 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -106,12 +106,14 @@ _nm_auto_protect_errno (int *p_saved_errno)
#define __NM_UTILS_MACRO_REST_HELPER_ONE(first)
#define __NM_UTILS_MACRO_REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__
#define __NM_UTILS_MACRO_REST_NUM(...) \
- __NM_UTILS_MACRO_REST_SELECT_20TH(__VA_ARGS__, \
+ __NM_UTILS_MACRO_REST_SELECT_30TH(__VA_ARGS__, \
+ TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
+ TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway)
-#define __NM_UTILS_MACRO_REST_SELECT_20TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, ...) a20
+#define __NM_UTILS_MACRO_REST_SELECT_30TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, ...) a30
/*****************************************************************************/
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index efb4221f0a..6b91cf4c80 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -5503,34 +5503,17 @@ wifi_get_wifi_data (NMPlatform *platform, int ifindex)
wifi_data = g_hash_table_lookup (priv->wifi_data, GINT_TO_POINTER (ifindex));
pllink = nm_platform_link_get (platform, ifindex);
- /* @wifi_data contains an interface name which is used for WEXT queries. If
- * the interface name changes we should at least replace the name in the
- * existing structure; but probably a complete reinitialization is better
- * because during the initial creation there can be race conditions while
- * the interface is renamed by udev.
- */
- if (wifi_data && pllink) {
- if (!nm_streq (wifi_utils_get_iface (wifi_data), pllink->name)) {
- _LOGD ("wifi: interface %s renamed to %s, dropping old data for ifindex %d",
- wifi_utils_get_iface (wifi_data),
- pllink->name,
- ifindex);
- g_hash_table_remove (priv->wifi_data, GINT_TO_POINTER (ifindex));
- wifi_data = NULL;
- }
- }
-
if (!wifi_data) {
if (pllink) {
if (pllink->type == NM_LINK_TYPE_WIFI)
- wifi_data = wifi_utils_init (pllink->name, ifindex, TRUE);
+ wifi_data = wifi_utils_init (ifindex, TRUE);
else if (pllink->type == NM_LINK_TYPE_OLPC_MESH) {
/* The kernel driver now uses nl80211, but we force use of WEXT because
* the cfg80211 interactions are not quite ready to support access to
* mesh control through nl80211 just yet.
*/
#if HAVE_WEXT
- wifi_data = wifi_wext_init (pllink->name, ifindex, FALSE);
+ wifi_data = wifi_wext_init (ifindex, FALSE);
#endif
}
diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c
index 63ea070277..0356f59c3e 100644
--- a/src/platform/wifi/wifi-utils-nl80211.c
+++ b/src/platform/wifi/wifi-utils-nl80211.c
@@ -35,8 +35,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), \
+ "%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 +228,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 +342,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;
}
}
@@ -1005,7 +1014,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;
}
}
@@ -1032,13 +1043,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];
- nl80211 = wifi_data_new (iface, ifindex, sizeof (*nl80211));
+ 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 (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;
@@ -1073,44 +1091,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;
}
@@ -1122,9 +1140,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;
diff --git a/src/platform/wifi/wifi-utils-nl80211.h b/src/platform/wifi/wifi-utils-nl80211.h
index b3e8c8976d..aff24555fc 100644
--- a/src/platform/wifi/wifi-utils-nl80211.h
+++ b/src/platform/wifi/wifi-utils-nl80211.h
@@ -23,6 +23,6 @@
#include "wifi-utils.h"
-WifiData *wifi_nl80211_init (const char *iface, int ifindex);
+WifiData *wifi_nl80211_init (int ifindex);
#endif /* __WIFI_UTILS_NL80211_H__ */
diff --git a/src/platform/wifi/wifi-utils-private.h b/src/platform/wifi/wifi-utils-private.h
index ebe76f1b6a..11a0f060dc 100644
--- a/src/platform/wifi/wifi-utils-private.h
+++ b/src/platform/wifi/wifi-utils-private.h
@@ -25,7 +25,6 @@
#include "wifi-utils.h"
struct WifiData {
- char *iface;
int ifindex;
NMDeviceWifiCapabilities caps;
@@ -69,7 +68,7 @@ struct WifiData {
gboolean (*indicate_addressing_running) (WifiData *data, gboolean running);
};
-gpointer wifi_data_new (const char *iface, int ifindex, gsize len);
+gpointer wifi_data_new (int ifindex, gsize len);
void wifi_data_free (WifiData *data);
#endif /* __WIFI_UTILS_PRIVATE_H__ */
diff --git a/src/platform/wifi/wifi-utils-wext.c b/src/platform/wifi/wifi-utils-wext.c
index af8cf2dee6..bd326a47e8 100644
--- a/src/platform/wifi/wifi-utils-wext.c
+++ b/src/platform/wifi/wifi-utils-wext.c
@@ -69,6 +69,15 @@ struct iw_range_with_scan_capa
/* don't need the rest... */
};
+#define _NMLOG_PREFIX_NAME "wifi-wext"
+#define _NMLOG(level, domain, ...) \
+ G_STMT_START { \
+ nm_log ((level), (domain), \
+ "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+ _NMLOG_PREFIX_NAME \
+ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+ } G_STMT_END
+
static guint32
iw_freq_to_uint32 (struct iw_freq *freq)
{
@@ -94,20 +103,36 @@ wifi_wext_deinit (WifiData *parent)
close (wext->fd);
}
+static gboolean
+get_ifname (int ifindex, char *buffer, const char *op)
+{
+ int errsv;
+
+ if (!nmp_utils_if_indextoname (ifindex, buffer)) {
+ errsv = errno;
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "error getting interface name for ifindex %d, operation '%s': %s (%d)",
+ ifindex, op, g_strerror (errsv), errsv);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static NM80211Mode
-wifi_wext_get_mode (WifiData *data)
+wifi_wext_get_mode_ifname (WifiData *data, const char *ifname)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
memset (&wrq, 0, sizeof (struct iwreq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCGIWMODE, &wrq) < 0) {
if (errno != ENODEV) {
- nm_log_warn (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): error %d getting card mode",
- wext->parent.iface, errno);
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error %d getting card mode",
+ ifname, errno);
}
return NM_802_11_MODE_UNKNOWN;
}
@@ -126,13 +151,28 @@ wifi_wext_get_mode (WifiData *data)
return NM_802_11_MODE_UNKNOWN;
}
+static NM80211Mode
+wifi_wext_get_mode (WifiData *data)
+{
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "get-mode"))
+ return FALSE;
+
+ return wifi_wext_get_mode_ifname (data, ifname);
+}
+
static gboolean
wifi_wext_set_mode (WifiData *data, const NM80211Mode mode)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
+ char ifname[IFNAMSIZ];
- if (wifi_wext_get_mode (data) == mode)
+ if (!get_ifname (data->ifindex, ifname, "set-mode"))
+ return FALSE;
+
+ if (wifi_wext_get_mode_ifname (data, ifname) == mode)
return TRUE;
memset (&wrq, 0, sizeof (struct iwreq));
@@ -151,11 +191,12 @@ wifi_wext_set_mode (WifiData *data, const NM80211Mode mode)
return FALSE;
}
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCSIWMODE, &wrq) < 0) {
if (errno != ENODEV) {
- nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): error setting mode %d",
- wext->parent.iface, mode);
+ _LOGE (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error setting mode %d",
+ ifname, mode);
}
return FALSE;
}
@@ -168,6 +209,10 @@ wifi_wext_set_powersave (WifiData *data, guint32 powersave)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "set-powersave"))
+ return FALSE;
memset (&wrq, 0, sizeof (struct iwreq));
if (powersave == 1) {
@@ -175,11 +220,12 @@ wifi_wext_set_powersave (WifiData *data, guint32 powersave)
} else
wrq.u.power.disabled = 1;
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCSIWPOWER, &wrq) < 0) {
if (errno != ENODEV) {
- nm_log_err (LOGD_PLATFORM | LOGD_WIFI, "(%s): error setting powersave %" G_GUINT32_FORMAT,
- wext->parent.iface, powersave);
+ _LOGE (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error setting powersave %" G_GUINT32_FORMAT,
+ ifname, powersave);
}
return FALSE;
}
@@ -192,13 +238,17 @@ wifi_wext_get_freq (WifiData *data)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "get-freq"))
+ return FALSE;
memset (&wrq, 0, sizeof (struct iwreq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCGIWFREQ, &wrq) < 0) {
- nm_log_warn (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): error getting frequency: %s",
- wext->parent.iface, strerror (errno));
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error getting frequency: %s",
+ ifname, strerror (errno));
return 0;
}
@@ -226,13 +276,17 @@ wifi_wext_get_bssid (WifiData *data, guint8 *out_bssid)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "get-bssid"))
+ return FALSE;
memset (&wrq, 0, sizeof (wrq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCGIWAP, &wrq) < 0) {
- nm_log_warn (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): error getting associated BSSID: %s",
- wext->parent.iface, strerror (errno));
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error getting associated BSSID: %s",
+ ifname, strerror (errno));
return FALSE;
}
memcpy (out_bssid, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
@@ -245,9 +299,13 @@ wifi_wext_get_rate (WifiData *data)
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
int err;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "get-rate"))
+ return FALSE;
memset (&wrq, 0, sizeof (wrq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
err = ioctl (wext->fd, SIOCGIWRATE, &wrq);
return ((err == 0) ? wrq.u.bitrate.value / 1000 : 0);
}
@@ -264,16 +322,16 @@ wext_qual_to_percent (const struct iw_quality *qual,
/* Magically convert the many different WEXT quality representations to a percentage */
- nm_log_dbg (LOGD_WIFI,
- "QL: qual %d/%u/0x%X, level %d/%u/0x%X, noise %d/%u/0x%X, updated: 0x%X ** MAX: qual %d/%u/0x%X, level %d/%u/0x%X, noise %d/%u/0x%X, updated: 0x%X",
- (__s8) qual->qual, qual->qual, qual->qual,
- (__s8) qual->level, qual->level, qual->level,
- (__s8) qual->noise, qual->noise, qual->noise,
- qual->updated,
- (__s8) max_qual->qual, max_qual->qual, max_qual->qual,
- (__s8) max_qual->level, max_qual->level, max_qual->level,
- (__s8) max_qual->noise, max_qual->noise, max_qual->noise,
- max_qual->updated);
+ _LOGD (LOGD_WIFI,
+ "QL: qual %d/%u/0x%X, level %d/%u/0x%X, noise %d/%u/0x%X, updated: 0x%X ** MAX: qual %d/%u/0x%X, level %d/%u/0x%X, noise %d/%u/0x%X, updated: 0x%X",
+ (__s8) qual->qual, qual->qual, qual->qual,
+ (__s8) qual->level, qual->level, qual->level,
+ (__s8) qual->noise, qual->noise, qual->noise,
+ qual->updated,
+ (__s8) max_qual->qual, max_qual->qual, max_qual->qual,
+ (__s8) max_qual->level, max_qual->level, max_qual->level,
+ (__s8) max_qual->noise, max_qual->noise, max_qual->noise,
+ max_qual->updated);
/* Try using the card's idea of the signal quality first as long as it tells us what the max quality is.
* Drivers that fill in quality values MUST treat them as percentages, ie the "Link Quality" MUST be
@@ -319,8 +377,8 @@ wext_qual_to_percent (const struct iw_quality *qual,
/* A sort of signal-to-noise ratio calculation */
level_percent = (int) (100 - 70 * (((double)max_level - (double)level) /
((double)max_level - (double)noise)));
- nm_log_dbg (LOGD_WIFI, "QL1: level_percent is %d. max_level %d, level %d, noise_floor %d.",
- level_percent, max_level, level, noise);
+ _LOGD (LOGD_WIFI, "QL1: level_percent is %d. max_level %d, level %d, noise_floor %d.",
+ level_percent, max_level, level, noise);
} else if ( (max_qual->level != 0)
&& !(max_qual->updated & IW_QUAL_LEVEL_INVALID) /* Valid max_qual->level as upper bound */
&& !(qual->updated & IW_QUAL_LEVEL_INVALID)) {
@@ -331,18 +389,18 @@ wext_qual_to_percent (const struct iw_quality *qual,
/* Signal level is relavtive (0 -> max_qual->level) */
level = CLAMP (level, 0, max_qual->level);
level_percent = (int)(100 * ((double)level / (double)max_qual->level));
- nm_log_dbg (LOGD_WIFI, "QL2: level_percent is %d. max_level %d, level %d.",
- level_percent, max_qual->level, level);
+ _LOGD (LOGD_WIFI, "QL2: level_percent is %d. max_level %d, level %d.",
+ level_percent, max_qual->level, level);
} else if (percent == -1) {
- nm_log_dbg (LOGD_WIFI, "QL: Could not get quality %% value from driver. Driver is probably buggy.");
+ _LOGD (LOGD_WIFI, "QL: Could not get quality %% value from driver. Driver is probably buggy.");
}
/* If the quality percent was 0 or doesn't exist, then try to use signal levels instead */
if ((percent < 1) && (level_percent >= 0))
percent = level_percent;
- nm_log_dbg (LOGD_WIFI, "QL: Final quality percent is %d (%d).",
- percent, CLAMP (percent, 0, 100));
+ _LOGD (LOGD_WIFI, "QL: Final quality percent is %d (%d).",
+ percent, CLAMP (percent, 0, 100));
return (CLAMP (percent, 0, 100));
}
@@ -352,17 +410,21 @@ wifi_wext_get_qual (WifiData *data)
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
struct iw_statistics stats;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "get-qual"))
+ return FALSE;
memset (&stats, 0, sizeof (stats));
wrq.u.data.pointer = &stats;
wrq.u.data.length = sizeof (stats);
wrq.u.data.flags = 1; /* Clear updated flag */
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCGIWSTATS, &wrq) < 0) {
- nm_log_warn (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): error getting signal strength: %s",
- wext->parent.iface, strerror (errno));
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): error getting signal strength: %s",
+ ifname, strerror (errno));
return -1;
}
@@ -392,9 +454,13 @@ wifi_wext_set_mesh_channel (WifiData *data, guint32 channel)
{
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
+ char ifname[IFNAMSIZ];
+
+ if (!get_ifname (data->ifindex, ifname, "set-mesh-channel"))
+ return FALSE;
memset (&wrq, 0, sizeof (struct iwreq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (channel > 0) {
wrq.u.freq.flags = IW_FREQ_FIXED;
@@ -403,9 +469,9 @@ wifi_wext_set_mesh_channel (WifiData *data, guint32 channel)
}
if (ioctl (wext->fd, SIOCSIWFREQ, &wrq) < 0) {
- nm_log_err (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
- "(%s): error setting channel to %d: %s",
- wext->parent.iface, channel, strerror (errno));
+ _LOGE (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
+ "(%s): error setting channel to %d: %s",
+ ifname, channel, strerror (errno));
return FALSE;
}
@@ -418,6 +484,11 @@ wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len)
WifiDataWext *wext = (WifiDataWext *) data;
struct iwreq wrq;
char buf[IW_ESSID_MAX_SIZE + 1];
+ char ifname[IFNAMSIZ];
+ int errsv;
+
+ if (!get_ifname (data->ifindex, ifname, "set-mesh-ssid"))
+ return FALSE;
memset (buf, 0, sizeof (buf));
memcpy (buf, ssid, MIN (sizeof (buf) - 1, len));
@@ -426,16 +497,17 @@ wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len)
wrq.u.essid.length = len;
wrq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable SSID, 0=disable/any */
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCSIWESSID, &wrq) == 0)
return TRUE;
if (errno != ENODEV) {
- nm_log_err (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
- "(%s): error setting SSID to '%s': %s",
- wext->parent.iface,
- ssid ? nm_utils_escape_ssid (ssid, len) : "(null)",
- strerror (errno));
+ errsv = errno;
+ _LOGE (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
+ "(%s): error setting SSID to '%s': %s",
+ ifname,
+ ssid ? nm_utils_escape_ssid (ssid, len) : "(null)",
+ strerror (errsv));
}
return FALSE;
@@ -444,12 +516,12 @@ wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len)
/*****************************************************************************/
static gboolean
-wext_can_scan (WifiDataWext *wext)
+wext_can_scan_ifname (WifiDataWext *wext, const char *ifname)
{
struct iwreq wrq;
memset (&wrq, 0, sizeof (struct iwreq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCSIWSCAN, &wrq) < 0) {
if (errno == EOPNOTSUPP)
return FALSE;
@@ -458,16 +530,17 @@ wext_can_scan (WifiDataWext *wext)
}
static gboolean
-wext_get_range (WifiDataWext *wext,
- struct iw_range *range,
- guint32 *response_len)
+wext_get_range_ifname (WifiDataWext *wext,
+ const char *ifname,
+ struct iw_range *range,
+ guint32 *response_len)
{
int i = 26;
gboolean success = FALSE;
struct iwreq wrq;
memset (&wrq, 0, sizeof (struct iwreq));
- nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface);
+ nm_utils_ifname_cpy (wrq.ifr_name, ifname);
wrq.u.data.pointer = (caddr_t) range;
wrq.u.data.length = sizeof (struct iw_range);
@@ -482,9 +555,9 @@ wext_get_range (WifiDataWext *wext,
success = TRUE;
break;
} else if (errno != EAGAIN) {
- nm_log_err (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): couldn't get driver range information (%d).",
- wext->parent.iface, errno);
+ _LOGE (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): couldn't get driver range information (%d).",
+ ifname, errno);
break;
}
@@ -492,9 +565,9 @@ wext_get_range (WifiDataWext *wext,
}
if (i <= 0) {
- nm_log_warn (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): driver took too long to respond to IWRANGE query.",
- wext->parent.iface);
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): driver took too long to respond to IWRANGE query.",
+ ifname);
}
return success;
@@ -506,7 +579,7 @@ wext_get_range (WifiDataWext *wext,
NM_WIFI_DEVICE_CAP_RSN)
static guint32
-wext_get_caps (WifiDataWext *wext, struct iw_range *range)
+wext_get_caps (WifiDataWext *wext, const char *ifname, struct iw_range *range)
{
guint32 caps = NM_WIFI_DEVICE_CAP_NONE;
@@ -531,16 +604,18 @@ wext_get_caps (WifiDataWext *wext, struct iw_range *range)
/* Check for cipher support but not WPA support */
if ( (caps & (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP))
&& !(caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN))) {
- nm_log_warn (LOGD_WIFI, "%s: device supports WPA ciphers but not WPA protocol; "
- "WPA unavailable.", wext->parent.iface);
+ _LOGW (LOGD_WIFI,
+ "%s: device supports WPA ciphers but not WPA protocol; WPA unavailable.",
+ ifname);
caps &= ~WPA_CAPS;
}
/* Check for WPA support but not cipher support */
if ( (caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN))
&& !(caps & (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP))) {
- nm_log_warn (LOGD_WIFI, "%s: device supports WPA protocol but not WPA ciphers; "
- "WPA unavailable.", wext->parent.iface);
+ _LOGW (LOGD_WIFI,
+ "%s: device supports WPA protocol but not WPA ciphers; WPA unavailable.",
+ ifname);
caps &= ~WPA_CAPS;
}
@@ -554,7 +629,7 @@ wext_get_caps (WifiDataWext *wext, struct iw_range *range)
}
WifiData *
-wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
+wifi_wext_init (int ifindex, gboolean check_scan)
{
WifiDataWext *wext;
struct iw_range range;
@@ -562,8 +637,15 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
struct iw_range_with_scan_capa *scan_capa_range;
int i;
gboolean freq_valid = FALSE, has_5ghz = FALSE, has_2ghz = FALSE;
+ char ifname[IFNAMSIZ];
+
+ if (!nmp_utils_if_indextoname (ifindex, ifname)) {
+ _LOGW (LOGD_PLATFORM | LOGD_WIFI,
+ "can't determine interface name for ifindex %d", ifindex);
+ return NULL;
+ }
- wext = wifi_data_new (iface, ifindex, sizeof (*wext));
+ wext = wifi_data_new (ifindex, sizeof (*wext));
wext->parent.get_mode = wifi_wext_get_mode;
wext->parent.set_mode = wifi_wext_set_mode;
wext->parent.set_powersave = wifi_wext_set_powersave;
@@ -582,17 +664,17 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
goto error;
memset (&range, 0, sizeof (struct iw_range));
- if (wext_get_range (wext, &range, &response_len) == FALSE) {
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver WEXT range request failed",
- wext->parent.iface);
+ if (wext_get_range_ifname (wext, ifname, &range, &response_len) == FALSE) {
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI, "(%s): driver WEXT range request failed",
+ ifname);
goto error;
}
if ((response_len < 300) || (range.we_version_compiled < 21)) {
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): driver WEXT version too old (got %d, expected >= 21)",
- wext->parent.iface,
- range.we_version_compiled);
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): driver WEXT version too old (got %d, expected >= 21)",
+ ifname,
+ range.we_version_compiled);
goto error;
}
@@ -612,10 +694,10 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
}
/* Check for scanning capability; cards that can't scan are not supported */
- if (check_scan && (wext_can_scan (wext) == FALSE)) {
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): drivers that cannot scan are unsupported",
- wext->parent.iface);
+ if (check_scan && (wext_can_scan_ifname (wext, ifname) == FALSE)) {
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): drivers that cannot scan are unsupported",
+ ifname);
goto error;
}
@@ -625,18 +707,18 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
*/
scan_capa_range = (struct iw_range_with_scan_capa *) &range;
if (scan_capa_range->scan_capa & NM_IW_SCAN_CAPA_ESSID) {
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): driver supports SSID scans (scan_capa 0x%02X).",
- wext->parent.iface,
- scan_capa_range->scan_capa);
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): driver supports SSID scans (scan_capa 0x%02X).",
+ ifname,
+ scan_capa_range->scan_capa);
} else {
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): driver does not support SSID scans (scan_capa 0x%02X).",
- wext->parent.iface,
- scan_capa_range->scan_capa);
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): driver does not support SSID scans (scan_capa 0x%02X).",
+ ifname,
+ scan_capa_range->scan_capa);
}
- wext->parent.caps = wext_get_caps (wext, &range);
+ wext->parent.caps = wext_get_caps (wext, ifname, &range);
if (freq_valid)
wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_VALID;
if (has_2ghz)
@@ -644,9 +726,9 @@ wifi_wext_init (const char *iface, int ifindex, gboolean check_scan)
if (has_5ghz)
wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_5GHZ;
- nm_log_info (LOGD_PLATFORM | LOGD_WIFI,
- "(%s): using WEXT for WiFi device control",
- wext->parent.iface);
+ _LOGI (LOGD_PLATFORM | LOGD_WIFI,
+ "(%s): using WEXT for WiFi device control",
+ ifname);
return (WifiData *) wext;
diff --git a/src/platform/wifi/wifi-utils-wext.h b/src/platform/wifi/wifi-utils-wext.h
index e168fe28ad..3ef5a173ab 100644
--- a/src/platform/wifi/wifi-utils-wext.h
+++ b/src/platform/wifi/wifi-utils-wext.h
@@ -23,7 +23,7 @@
#include "wifi-utils.h"
-WifiData *wifi_wext_init (const char *iface, int ifindex, gboolean check_scan);
+WifiData *wifi_wext_init (int ifindex, gboolean check_scan);
gboolean wifi_wext_is_wifi (const char *iface);
diff --git a/src/platform/wifi/wifi-utils.c b/src/platform/wifi/wifi-utils.c
index b8da02c15e..d005212125 100644
--- a/src/platform/wifi/wifi-utils.c
+++ b/src/platform/wifi/wifi-utils.c
@@ -38,12 +38,11 @@
#include "platform/nm-platform-utils.h"
gpointer
-wifi_data_new (const char *iface, int ifindex, gsize len)
+wifi_data_new (int ifindex, gsize len)
{
WifiData *data;
data = g_malloc0 (len);
- data->iface = g_strdup (iface);
data->ifindex = ifindex;
return data;
}
@@ -51,7 +50,6 @@ wifi_data_new (const char *iface, int ifindex, gsize len)
void
wifi_data_free (WifiData *data)
{
- g_free (data->iface);
memset (data, 0, sizeof (*data));
g_free (data);
}
@@ -59,17 +57,16 @@ wifi_data_free (WifiData *data)
/*****************************************************************************/
WifiData *
-wifi_utils_init (const char *iface, int ifindex, gboolean check_scan)
+wifi_utils_init (int ifindex, gboolean check_scan)
{
WifiData *ret;
- g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (ifindex > 0, NULL);
- ret = wifi_nl80211_init (iface, ifindex);
+ ret = wifi_nl80211_init (ifindex);
if (ret == NULL) {
#if HAVE_WEXT
- ret = wifi_wext_init (iface, ifindex, check_scan);
+ ret = wifi_wext_init (ifindex, check_scan);
#endif
}
return ret;
@@ -83,14 +80,6 @@ wifi_utils_get_ifindex (WifiData *data)
return data->ifindex;
}
-const char *
-wifi_utils_get_iface (WifiData *data)
-{
- g_return_val_if_fail (data != NULL, NULL);
-
- return data->iface;
-}
-
NMDeviceWifiCapabilities
wifi_utils_get_caps (WifiData *data)
{
diff --git a/src/platform/wifi/wifi-utils.h b/src/platform/wifi/wifi-utils.h
index 4fd5a80bbe..705717b078 100644
--- a/src/platform/wifi/wifi-utils.h
+++ b/src/platform/wifi/wifi-utils.h
@@ -30,12 +30,10 @@ typedef struct WifiData WifiData;
gboolean wifi_utils_is_wifi (int dirfd, const char *ifname);
-WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan);
+WifiData *wifi_utils_init (int ifindex, gboolean check_scan);
int wifi_utils_get_ifindex (WifiData *data);
-const char *wifi_utils_get_iface (WifiData *data);
-
void wifi_utils_deinit (WifiData *data);
NMDeviceWifiCapabilities wifi_utils_get_caps (WifiData *data);