diff options
Diffstat (limited to 'src/platform/wifi')
| -rw-r--r-- | src/platform/wifi/wifi-utils-nl80211.c | 59 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils-nl80211.h | 8 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils-private.h | 12 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils-wext.c | 19 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils-wext.h | 6 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils.c | 23 | ||||
| -rw-r--r-- | src/platform/wifi/wifi-utils.h | 16 |
7 files changed, 54 insertions, 89 deletions
diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c index 25ebd1b3..752da926 100644 --- a/src/platform/wifi/wifi-utils-nl80211.c +++ b/src/platform/wifi/wifi-utils-nl80211.c @@ -20,7 +20,8 @@ * Copyright (C) 2011 Intel Corporation. All rights reserved. */ -#include <config.h> +#include "config.h" + #include <errno.h> #include <string.h> #include <sys/ioctl.h> @@ -442,7 +443,7 @@ wifi_nl80211_get_ssid (WifiData *data) } static gboolean -wifi_nl80211_get_bssid (WifiData *data, struct ether_addr *out_bssid) +wifi_nl80211_get_bssid (WifiData *data, guint8 *out_bssid) { WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data; struct nl80211_bss_info bss_info; @@ -679,11 +680,20 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg) static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, +#ifdef NL80211_FREQUENCY_ATTR_NO_IR + [NL80211_FREQUENCY_ATTR_NO_IR] = { .type = NLA_FLAG }, +#else [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, +#endif [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, }; +#ifdef NL80211_FREQUENCY_ATTR_NO_IR + G_STATIC_ASSERT (NL80211_FREQUENCY_ATTR_PASSIVE_SCAN == NL80211_FREQUENCY_ATTR_NO_IR && NL80211_FREQUENCY_ATTR_NO_IBSS == NL80211_FREQUENCY_ATTR_NO_IR); +#else + G_STATIC_ASSERT (NL80211_FREQUENCY_ATTR_PASSIVE_SCAN != NL80211_FREQUENCY_ATTR_NO_IBSS); +#endif if (nla_parse (tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen (gnlh, 0), NULL) < 0) @@ -924,48 +934,3 @@ error: return NULL; } -gboolean -wifi_nl80211_is_wifi (const char *iface) -{ - struct nl_sock *nl_sock; - struct nl_cb *nl_cb = NULL; - struct nl_msg *msg = NULL; - int id, ifindex; - struct nl80211_iface_info iface_info = { - .mode = NM_802_11_MODE_UNKNOWN, - }; - gboolean is_wifi = FALSE; - - nl_sock = nl_socket_alloc (); - if (nl_sock == NULL) - return FALSE; - - if (genl_connect (nl_sock)) - goto error; - - ifindex = nm_platform_link_get_ifindex (iface); - if (ifindex < 0) - goto error; - - id = genl_ctrl_resolve (nl_sock, "nl80211"); - if (id < 0) - goto error; - - nl_cb = nl_cb_alloc (NL_CB_DEFAULT); - if (nl_cb) { - msg = _nl80211_alloc_msg (id, ifindex, -1, NL80211_CMD_GET_INTERFACE, 0); - if (_nl80211_send_and_recv (nl_sock, - nl_cb, - msg, - nl80211_iface_info_handler, - &iface_info) >= 0) - is_wifi = (iface_info.mode != NM_802_11_MODE_UNKNOWN); - } - - error: - if (nl_cb) - nl_cb_put (nl_cb); - nl_socket_free (nl_sock); - return is_wifi; -} - diff --git a/src/platform/wifi/wifi-utils-nl80211.h b/src/platform/wifi/wifi-utils-nl80211.h index 2a7fe874..b3e8c897 100644 --- a/src/platform/wifi/wifi-utils-nl80211.h +++ b/src/platform/wifi/wifi-utils-nl80211.h @@ -18,13 +18,11 @@ * Copyright (C) 2011 Intel Corporation. All rights reserved. */ -#ifndef WIFI_UTILS_NL80211_H -#define WIFI_UTILS_NL80211_H +#ifndef __WIFI_UTILS_NL80211_H__ +#define __WIFI_UTILS_NL80211_H__ #include "wifi-utils.h" WifiData *wifi_nl80211_init (const char *iface, int ifindex); -gboolean wifi_nl80211_is_wifi (const char *iface); - -#endif /* WIFI_UTILS_NL80211_H */ +#endif /* __WIFI_UTILS_NL80211_H__ */ diff --git a/src/platform/wifi/wifi-utils-private.h b/src/platform/wifi/wifi-utils-private.h index e7601752..aaedd5b7 100644 --- a/src/platform/wifi/wifi-utils-private.h +++ b/src/platform/wifi/wifi-utils-private.h @@ -18,12 +18,12 @@ * Copyright (C) 2011 Red Hat, Inc. */ -#ifndef WIFI_UTILS_PRIVATE_H -#define WIFI_UTILS_PRIVATE_H +#ifndef __WIFI_UTILS_PRIVATE_H__ +#define __WIFI_UTILS_PRIVATE_H__ #include <glib.h> -#include "NetworkManager.h" +#include "nm-dbus-interface.h" #include "wifi-utils.h" struct WifiData { @@ -47,7 +47,7 @@ struct WifiData { /* Return current bitrate in Kbps */ guint32 (*get_rate) (WifiData *data); - gboolean (*get_bssid) (WifiData *data, struct ether_addr *out_bssid); + gboolean (*get_bssid) (WifiData *data, guint8 *out_bssid); /* Return a signal strength percentage 0 - 100% for the current BSSID; * return -1 on errors or if not associated. @@ -66,7 +66,7 @@ struct WifiData { gboolean (*set_mesh_channel) (WifiData *data, guint32 channel); /* ssid == NULL means "auto SSID" */ - gboolean (*set_mesh_ssid) (WifiData *data, const GByteArray *ssid); + gboolean (*set_mesh_ssid) (WifiData *data, const guint8 *ssid, gsize len); gboolean (*indicate_addressing_running) (WifiData *data, gboolean running); }; @@ -74,4 +74,4 @@ struct WifiData { gpointer wifi_data_new (const char *iface, int ifindex, gsize len); void wifi_data_free (WifiData *data); -#endif /* WIFI_UTILS_PRIVATE_H */ +#endif /* __WIFI_UTILS_PRIVATE_H__ */ diff --git a/src/platform/wifi/wifi-utils-wext.c b/src/platform/wifi/wifi-utils-wext.c index cc94b69a..e0331de7 100644 --- a/src/platform/wifi/wifi-utils-wext.c +++ b/src/platform/wifi/wifi-utils-wext.c @@ -19,7 +19,8 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#include <config.h> +#include "config.h" + #include <errno.h> #include <string.h> #include <sys/ioctl.h> @@ -41,7 +42,6 @@ #include <sys/types.h> #include <linux/types.h> #include <sys/socket.h> -#include <linux/if.h> #include <linux/wireless.h> @@ -230,7 +230,7 @@ wifi_wext_get_ssid (WifiData *data) } static gboolean -wifi_wext_get_bssid (WifiData *data, struct ether_addr *out_bssid) +wifi_wext_get_bssid (WifiData *data, guint8 *out_bssid) { WifiDataWext *wext = (WifiDataWext *) data; struct iwreq wrq; @@ -243,7 +243,7 @@ wifi_wext_get_bssid (WifiData *data, struct ether_addr *out_bssid) wext->parent.iface, strerror (errno)); return FALSE; } - memcpy (out_bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN); + memcpy (out_bssid, &(wrq.u.ap_addr.sa_data), ETH_ALEN); return TRUE; } @@ -421,18 +421,15 @@ wifi_wext_set_mesh_channel (WifiData *data, guint32 channel) } static gboolean -wifi_wext_set_mesh_ssid (WifiData *data, const GByteArray *ssid) +wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len) { WifiDataWext *wext = (WifiDataWext *) data; struct iwreq wrq; - guint32 len = 0; char buf[IW_ESSID_MAX_SIZE + 1]; memset (buf, 0, sizeof (buf)); - if (ssid) { - len = ssid->len; - memcpy (buf, ssid->data, MIN (sizeof (buf) - 1, len)); - } + memcpy (buf, ssid, MIN (sizeof (buf) - 1, len)); + wrq.u.essid.pointer = (caddr_t) buf; wrq.u.essid.length = len; wrq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable SSID, 0=disable/any */ @@ -445,7 +442,7 @@ wifi_wext_set_mesh_ssid (WifiData *data, const GByteArray *ssid) nm_log_err (LOGD_HW | LOGD_WIFI | LOGD_OLPC, "(%s): error setting SSID to '%s': %s", wext->parent.iface, - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(null)", + ssid ? nm_utils_escape_ssid (ssid, len) : "(null)", strerror (errno)); } diff --git a/src/platform/wifi/wifi-utils-wext.h b/src/platform/wifi/wifi-utils-wext.h index 96ad74eb..e168fe28 100644 --- a/src/platform/wifi/wifi-utils-wext.h +++ b/src/platform/wifi/wifi-utils-wext.h @@ -18,8 +18,8 @@ * Copyright (C) 2011 Red Hat, Inc. */ -#ifndef WIFI_UTILS_WEXT_H -#define WIFI_UTILS_WEXT_H +#ifndef __WIFI_UTILS_WEXT_H__ +#define __WIFI_UTILS_WEXT_H__ #include "wifi-utils.h" @@ -27,4 +27,4 @@ WifiData *wifi_wext_init (const char *iface, int ifindex, gboolean check_scan); gboolean wifi_wext_is_wifi (const char *iface); -#endif /* WIFI_UTILS_WEXT_H */ +#endif /* __WIFI_UTILS_WEXT_H__ */ diff --git a/src/platform/wifi/wifi-utils.c b/src/platform/wifi/wifi-utils.c index ff480275..daef881b 100644 --- a/src/platform/wifi/wifi-utils.c +++ b/src/platform/wifi/wifi-utils.c @@ -19,7 +19,8 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#include <config.h> +#include "config.h" + #include <sys/stat.h> #include <stdio.h> #include <string.h> @@ -120,12 +121,12 @@ wifi_utils_get_ssid (WifiData *data) } gboolean -wifi_utils_get_bssid (WifiData *data, struct ether_addr *out_bssid) +wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid) { g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (out_bssid != NULL, FALSE); - memset (out_bssid, 0, sizeof (*out_bssid)); + memset (out_bssid, 0, ETH_ALEN); return data->get_bssid (data, out_bssid); } @@ -161,13 +162,20 @@ wifi_utils_deinit (WifiData *data) } gboolean -wifi_utils_is_wifi (const char *iface, const char *sysfs_path) +wifi_utils_is_wifi (const char *iface, const char *sysfs_path, const char *devtype) { char phy80211_path[255]; struct stat s; g_return_val_if_fail (iface != NULL, FALSE); + if (g_strcmp0 (devtype, "wlan") == 0) { + /* All Wi-Fi drivers should set DEVTYPE=wlan. Since the kernel's + * cfg80211/nl80211 stack does, this check should match any nl80211 + * capable driver (including mac82011-based ones). */ + return TRUE; + } + if (sysfs_path) { /* Check for nl80211 sysfs paths */ g_snprintf (phy80211_path, sizeof (phy80211_path), "%s/phy80211", sysfs_path); @@ -175,9 +183,6 @@ wifi_utils_is_wifi (const char *iface, const char *sysfs_path) return TRUE; } - if (wifi_nl80211_is_wifi (iface)) - return TRUE; - #if HAVE_WEXT if (wifi_wext_is_wifi (iface)) return TRUE; @@ -207,11 +212,11 @@ wifi_utils_set_mesh_channel (WifiData *data, guint32 channel) } gboolean -wifi_utils_set_mesh_ssid (WifiData *data, const GByteArray *ssid) +wifi_utils_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len) { g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data->set_mesh_ssid != NULL, FALSE); - return data->set_mesh_ssid (data, ssid); + return data->set_mesh_ssid (data, ssid, len); } gboolean diff --git a/src/platform/wifi/wifi-utils.h b/src/platform/wifi/wifi-utils.h index 455e075f..f1b57ace 100644 --- a/src/platform/wifi/wifi-utils.h +++ b/src/platform/wifi/wifi-utils.h @@ -19,17 +19,17 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#ifndef WIFI_UTILS_H -#define WIFI_UTILS_H +#ifndef __WIFI_UTILS_H__ +#define __WIFI_UTILS_H__ #include <net/ethernet.h> #include <glib.h> -#include "NetworkManager.h" +#include "nm-dbus-interface.h" typedef struct WifiData WifiData; -gboolean wifi_utils_is_wifi (const char *iface, const char *sysfs_path); +gboolean wifi_utils_is_wifi (const char *iface, const char *sysfs_path, const char *devtype); WifiData *wifi_utils_init (const char *iface, int ifindex, gboolean check_scan); @@ -50,8 +50,8 @@ guint32 wifi_utils_find_freq (WifiData *data, const guint32 *freqs); /* Caller must free returned byte array */ GByteArray *wifi_utils_get_ssid (WifiData *data); -/* Caller must free returned byte array */ -gboolean wifi_utils_get_bssid (WifiData *data, struct ether_addr *out_bssid); +/* out_bssid must be ETH_ALEN bytes */ +gboolean wifi_utils_get_bssid (WifiData *data, guint8 *out_bssid); /* Returns current bitrate in Kbps */ guint32 wifi_utils_get_rate (WifiData *data); @@ -71,6 +71,6 @@ guint32 wifi_utils_get_mesh_channel (WifiData *data); gboolean wifi_utils_set_mesh_channel (WifiData *data, guint32 channel); -gboolean wifi_utils_set_mesh_ssid (WifiData *data, const GByteArray *ssid); +gboolean wifi_utils_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len); -#endif /* WIFI_UTILS_H */ +#endif /* __WIFI_UTILS_H__ */ |