platform/wifi: turn NMWifiUtils into a GObject

This commit is contained in:
Lubomir Rintel
2018-06-09 15:50:56 +02:00
parent 91c82cc465
commit 787dc484b3
8 changed files with 202 additions and 124 deletions

View File

@@ -5993,14 +5993,14 @@ wifi_get_wifi_data (NMPlatform *platform, int ifindex)
if (!wifi_data) { if (!wifi_data) {
if (pllink) { if (pllink) {
if (pllink->type == NM_LINK_TYPE_WIFI) if (pllink->type == NM_LINK_TYPE_WIFI)
wifi_data = nm_wifi_utils_init (ifindex, TRUE); wifi_data = nm_wifi_utils_new (ifindex, TRUE);
else if (pllink->type == NM_LINK_TYPE_OLPC_MESH) { else if (pllink->type == NM_LINK_TYPE_OLPC_MESH) {
/* The kernel driver now uses nl80211, but we force use of WEXT because /* The kernel driver now uses nl80211, but we force use of WEXT because
* the cfg80211 interactions are not quite ready to support access to * the cfg80211 interactions are not quite ready to support access to
* mesh control through nl80211 just yet. * mesh control through nl80211 just yet.
*/ */
#if HAVE_WEXT #if HAVE_WEXT
wifi_data = nm_wifi_utils_wext_init (ifindex, FALSE); wifi_data = nm_wifi_utils_wext_new (ifindex, FALSE);
#endif #endif
} }
@@ -6096,7 +6096,7 @@ static NMSettingWirelessWakeOnWLan
wifi_get_wake_on_wlan (NMPlatform *platform, int ifindex) wifi_get_wake_on_wlan (NMPlatform *platform, int ifindex)
{ {
WIFI_GET_WIFI_DATA_NETNS (wifi_data, platform, ifindex, FALSE); WIFI_GET_WIFI_DATA_NETNS (wifi_data, platform, ifindex, FALSE);
return wifi_utils_get_wake_on_wlan (wifi_data); return nm_wifi_utils_get_wake_on_wlan (wifi_data);
} }
static gboolean static gboolean
@@ -6104,7 +6104,7 @@ wifi_set_wake_on_wlan (NMPlatform *platform, int ifindex,
NMSettingWirelessWakeOnWLan wowl) NMSettingWirelessWakeOnWLan wowl)
{ {
WIFI_GET_WIFI_DATA_NETNS (wifi_data, platform, ifindex, FALSE); WIFI_GET_WIFI_DATA_NETNS (wifi_data, platform, ifindex, FALSE);
return wifi_utils_set_wake_on_wlan (wifi_data, wowl); return nm_wifi_utils_set_wake_on_wlan (wifi_data, wowl);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -7013,7 +7013,7 @@ nm_linux_platform_init (NMLinuxPlatform *self)
priv->delayed_action.list_master_connected = g_ptr_array_new (); priv->delayed_action.list_master_connected = g_ptr_array_new ();
priv->delayed_action.list_refresh_link = g_ptr_array_new (); priv->delayed_action.list_refresh_link = g_ptr_array_new ();
priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData)); priv->delayed_action.list_wait_for_nl_response = g_array_new (FALSE, TRUE, sizeof (DelayedActionWaitForNlResponseData));
priv->wifi_data = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) nm_wifi_utils_unref); priv->wifi_data = g_hash_table_new_full (nm_direct_hash, NULL, NULL, g_object_unref);
} }
static void static void

View File

@@ -56,6 +56,12 @@ typedef struct {
bool can_wowlan:1; bool can_wowlan:1;
} NMWifiUtilsNl80211; } NMWifiUtilsNl80211;
typedef struct {
NMWifiUtilsClass parent;
} NMWifiUtilsNl80211Class;
G_DEFINE_TYPE (NMWifiUtilsNl80211, nm_wifi_utils_nl80211, NM_TYPE_WIFI_UTILS)
static int static int
ack_handler (struct nl_msg *msg, void *arg) ack_handler (struct nl_msg *msg, void *arg)
{ {
@@ -164,13 +170,15 @@ nl80211_send_and_recv (NMWifiUtilsNl80211 *nl80211,
} }
static void static void
wifi_nl80211_deinit (NMWifiUtils *parent) dispose (GObject *object)
{ {
NMWifiUtilsNl80211 *nl80211 = (NMWifiUtilsNl80211 *) parent; NMWifiUtilsNl80211 *nl80211 = NM_WIFI_UTILS_NL80211 (object);
if (nl80211->nl_sock) if (nl80211->nl_sock) {
nl_socket_free (nl80211->nl_sock); nl_socket_free (nl80211->nl_sock);
g_free (nl80211->freqs); nl80211->nl_sock = NULL;
}
g_clear_pointer (&nl80211->freqs, g_free);
} }
struct nl80211_iface_info { struct nl80211_iface_info {
@@ -312,9 +320,9 @@ nl80211_get_wake_on_wlan_handler (struct nl_msg *msg, void *arg)
} }
static NMSettingWirelessWakeOnWLan static NMSettingWirelessWakeOnWLan
wifi_nl80211_get_wake_on_wlan (WifiData *data) wifi_nl80211_get_wake_on_wlan (NMWifiUtils *data)
{ {
WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data; NMWifiUtilsNl80211 *nl80211 = (NMWifiUtilsNl80211 *) data;
NMSettingWirelessWakeOnWLan wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; NMSettingWirelessWakeOnWLan wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE;
nm_auto_nlmsg struct nl_msg *msg = NULL; nm_auto_nlmsg struct nl_msg *msg = NULL;
@@ -326,9 +334,9 @@ wifi_nl80211_get_wake_on_wlan (WifiData *data)
} }
static gboolean static gboolean
wifi_nl80211_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl) wifi_nl80211_set_wake_on_wlan (NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl)
{ {
WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data; NMWifiUtilsNl80211 *nl80211 = (NMWifiUtilsNl80211 *) data;
nm_auto_nlmsg struct nl_msg *msg = NULL; nm_auto_nlmsg struct nl_msg *msg = NULL;
struct nlattr *triggers; struct nlattr *triggers;
int err; int err;
@@ -896,24 +904,35 @@ static int nl80211_wiphy_info_handler (struct nl_msg *msg, void *arg)
return NL_SKIP; return NL_SKIP;
} }
NMWifiUtils * static void
nm_wifi_utils_nl80211_init (int ifindex) nm_wifi_utils_nl80211_init (NMWifiUtilsNl80211 *self)
{
}
static void
nm_wifi_utils_nl80211_class_init (NMWifiUtilsNl80211Class *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMWifiUtilsClass *wifi_utils_class = NM_WIFI_UTILS_CLASS (klass);
object_class->dispose = dispose;
wifi_utils_class->get_mode = wifi_nl80211_get_mode;
wifi_utils_class->set_mode = wifi_nl80211_set_mode;
wifi_utils_class->set_powersave = wifi_nl80211_set_powersave;
wifi_utils_class->get_wake_on_wlan = wifi_nl80211_get_wake_on_wlan,
wifi_utils_class->set_wake_on_wlan = wifi_nl80211_set_wake_on_wlan,
wifi_utils_class->get_freq = wifi_nl80211_get_freq;
wifi_utils_class->find_freq = wifi_nl80211_find_freq;
wifi_utils_class->get_bssid = wifi_nl80211_get_bssid;
wifi_utils_class->get_rate = wifi_nl80211_get_rate;
wifi_utils_class->get_qual = wifi_nl80211_get_qual;
wifi_utils_class->indicate_addressing_running = wifi_nl80211_indicate_addressing_running;
}
NMWifiUtils *
nm_wifi_utils_nl80211_new (int ifindex)
{ {
static const NMWifiUtilsClass klass = {
.struct_size = sizeof (NMWifiUtilsNl80211),
.get_mode = wifi_nl80211_get_mode,
.set_mode = wifi_nl80211_set_mode,
.set_powersave = wifi_nl80211_set_powersave,
.get_wake_on_wlan = wifi_nl80211_get_wake_on_wlan,
.set_wake_on_wlan = wifi_nl80211_set_wake_on_wlan,
.get_freq = wifi_nl80211_get_freq,
.find_freq = wifi_nl80211_find_freq,
.get_bssid = wifi_nl80211_get_bssid,
.get_rate = wifi_nl80211_get_rate,
.get_qual = wifi_nl80211_get_qual,
.indicate_addressing_running = wifi_nl80211_indicate_addressing_running,
.deinit = wifi_nl80211_deinit,
};
NMWifiUtilsNl80211 *nl80211; NMWifiUtilsNl80211 *nl80211;
nm_auto_nlmsg struct nl_msg *msg = NULL; nm_auto_nlmsg struct nl_msg *msg = NULL;
struct nl80211_device_info device_info = {}; struct nl80211_device_info device_info = {};
@@ -925,8 +944,9 @@ nm_wifi_utils_nl80211_init (int ifindex)
nm_sprintf_buf (ifname, "if %d", ifindex); nm_sprintf_buf (ifname, "if %d", ifindex);
} }
nl80211 = nm_wifi_utils_new (&klass, ifindex); nl80211 = g_object_new (NM_TYPE_WIFI_UTILS_NL80211, NULL);
nl80211->parent.ifindex = ifindex;
nl80211->nl_sock = nl_socket_alloc (); nl80211->nl_sock = nl_socket_alloc ();
if (nl80211->nl_sock == NULL) if (nl80211->nl_sock == NULL)
goto error; goto error;
@@ -999,7 +1019,6 @@ nm_wifi_utils_nl80211_init (int ifindex)
return (NMWifiUtils *) nl80211; return (NMWifiUtils *) nl80211;
error: error:
nm_wifi_utils_unref ((NMWifiUtils *) nl80211); g_object_unref (nl80211);
return NULL; return NULL;
} }

View File

@@ -24,6 +24,15 @@
#include "nm-wifi-utils.h" #include "nm-wifi-utils.h"
NMWifiUtils *nm_wifi_utils_nl80211_init (int ifindex); #define NM_TYPE_WIFI_UTILS_NL80211 (nm_wifi_utils_nl80211_get_type ())
#define NM_WIFI_UTILS_NL80211(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_UTILS_NL80211, NMWifiUtilsNl80211))
#define NM_WIFI_UTILS_NL80211_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_WIFI_UTILS_NL80211, NMWifiUtilsNl80211Class))
#define NM_IS_WIFI_UTILS_NL80211(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_WIFI_UTILS_NL80211))
#define NM_IS_WIFI_UTILS_NL80211_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_WIFI_UTILS_NL80211))
#define NM_WIFI_UTILS_NL80211_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_WIFI_UTILS_NL80211, NMWifiUtilsNl80211Class))
GType nm_wifi_utils_nl80211_get_type (void);
NMWifiUtils *nm_wifi_utils_nl80211_new (int ifindex);
#endif /* __WIFI_UTILS_NL80211_H__ */ #endif /* __WIFI_UTILS_NL80211_H__ */

View File

@@ -25,7 +25,7 @@
#include "nm-wifi-utils.h" #include "nm-wifi-utils.h"
typedef struct { typedef struct {
gsize struct_size; GObjectClass parent;
NM80211Mode (*get_mode) (NMWifiUtils *data); NM80211Mode (*get_mode) (NMWifiUtils *data);
@@ -35,10 +35,10 @@ typedef struct {
gboolean (*set_powersave) (NMWifiUtils *data, guint32 powersave); gboolean (*set_powersave) (NMWifiUtils *data, guint32 powersave);
/* Get WakeOnWLAN configuration on an interface */ /* Get WakeOnWLAN configuration on an interface */
NMSettingWirelessWakeOnWLan (*get_wake_on_wlan) (WifiData *data); NMSettingWirelessWakeOnWLan (*get_wake_on_wlan) (NMWifiUtils *data);
/* Set WakeOnWLAN mode on an interface */ /* Set WakeOnWLAN mode on an interface */
gboolean (*set_wake_on_wlan) (WifiData *data, NMSettingWirelessWakeOnWLan wowl); gboolean (*set_wake_on_wlan) (NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl);
/* Return current frequency in MHz (really associated BSS frequency) */ /* Return current frequency in MHz (really associated BSS frequency) */
guint32 (*get_freq) (NMWifiUtils *data); guint32 (*get_freq) (NMWifiUtils *data);
@@ -56,8 +56,6 @@ typedef struct {
*/ */
int (*get_qual) (NMWifiUtils *data); int (*get_qual) (NMWifiUtils *data);
void (*deinit) (NMWifiUtils *data);
/* OLPC Mesh-only functions */ /* OLPC Mesh-only functions */
guint32 (*get_mesh_channel) (NMWifiUtils *data); guint32 (*get_mesh_channel) (NMWifiUtils *data);
@@ -72,11 +70,10 @@ typedef struct {
} NMWifiUtilsClass; } NMWifiUtilsClass;
struct NMWifiUtils { struct NMWifiUtils {
const NMWifiUtilsClass *klass; GObject parent;
int ifindex; int ifindex;
NMDeviceWifiCapabilities caps; NMDeviceWifiCapabilities caps;
}; };
gpointer nm_wifi_utils_new (const NMWifiUtilsClass *klass, int ifindex);
#endif /* __WIFI_UTILS_PRIVATE_H__ */ #endif /* __WIFI_UTILS_PRIVATE_H__ */

View File

@@ -50,6 +50,12 @@ typedef struct {
guint32 freqs[IW_MAX_FREQUENCIES]; guint32 freqs[IW_MAX_FREQUENCIES];
} NMWifiUtilsWext; } NMWifiUtilsWext;
typedef struct {
NMWifiUtilsClass parent;
} NMWifiUtilsWextClass;
G_DEFINE_TYPE (NMWifiUtilsWext, nm_wifi_utils_wext, NM_TYPE_WIFI_UTILS)
/* Until a new wireless-tools comes out that has the defs and the structure, /* Until a new wireless-tools comes out that has the defs and the structure,
* need to copy them here. * need to copy them here.
*/ */
@@ -94,11 +100,11 @@ iw_freq_to_uint32 (const struct iw_freq *freq)
} }
static void static void
wifi_wext_deinit (NMWifiUtils *parent) dispose (GObject *object)
{ {
NMWifiUtilsWext *wext = (NMWifiUtilsWext *) parent; NMWifiUtilsWext *wext = NM_WIFI_UTILS_WEXT (object);
nm_close (wext->fd); wext->fd = nm_close (wext->fd);
} }
static gboolean static gboolean
@@ -626,24 +632,37 @@ wext_get_caps (NMWifiUtilsWext *wext, const char *ifname, struct iw_range *range
return caps; return caps;
} }
NMWifiUtils * /*****************************************************************************/
nm_wifi_utils_wext_init (int ifindex, gboolean check_scan)
static void
nm_wifi_utils_wext_init (NMWifiUtilsWext *self)
{
}
static void
nm_wifi_utils_wext_class_init (NMWifiUtilsWextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMWifiUtilsClass *wifi_utils_class = NM_WIFI_UTILS_CLASS (klass);
object_class->dispose = dispose;
wifi_utils_class->get_mode = wifi_wext_get_mode;
wifi_utils_class->set_mode = wifi_wext_set_mode;
wifi_utils_class->set_powersave = wifi_wext_set_powersave;
wifi_utils_class->get_freq = wifi_wext_get_freq;
wifi_utils_class->find_freq = wifi_wext_find_freq;
wifi_utils_class->get_bssid = wifi_wext_get_bssid;
wifi_utils_class->get_rate = wifi_wext_get_rate;
wifi_utils_class->get_qual = wifi_wext_get_qual;
wifi_utils_class->get_mesh_channel = wifi_wext_get_mesh_channel;
wifi_utils_class->set_mesh_channel = wifi_wext_set_mesh_channel;
wifi_utils_class->set_mesh_ssid = wifi_wext_set_mesh_ssid;
}
NMWifiUtils *
nm_wifi_utils_wext_new (int ifindex, gboolean check_scan)
{ {
static const NMWifiUtilsClass klass = {
.struct_size = sizeof (NMWifiUtilsWext),
.get_mode = wifi_wext_get_mode,
.set_mode = wifi_wext_set_mode,
.set_powersave = wifi_wext_set_powersave,
.get_freq = wifi_wext_get_freq,
.find_freq = wifi_wext_find_freq,
.get_bssid = wifi_wext_get_bssid,
.get_rate = wifi_wext_get_rate,
.get_qual = wifi_wext_get_qual,
.deinit = wifi_wext_deinit,
.get_mesh_channel = wifi_wext_get_mesh_channel,
.set_mesh_channel = wifi_wext_set_mesh_channel,
.set_mesh_ssid = wifi_wext_set_mesh_ssid,
};
NMWifiUtilsWext *wext; NMWifiUtilsWext *wext;
struct iw_range range; struct iw_range range;
guint32 response_len = 0; guint32 response_len = 0;
@@ -658,8 +677,9 @@ nm_wifi_utils_wext_init (int ifindex, gboolean check_scan)
return NULL; return NULL;
} }
wext = nm_wifi_utils_new (&klass, ifindex); wext = g_object_new (NM_TYPE_WIFI_UTILS_WEXT, NULL);
wext->parent.ifindex = ifindex;
wext->fd = socket (PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); wext->fd = socket (PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (wext->fd < 0) if (wext->fd < 0)
goto error; goto error;
@@ -734,7 +754,7 @@ nm_wifi_utils_wext_init (int ifindex, gboolean check_scan)
return (NMWifiUtils *) wext; return (NMWifiUtils *) wext;
error: error:
nm_wifi_utils_unref ((NMWifiUtils *) wext); g_object_unref (wext);
return NULL; return NULL;
} }

View File

@@ -23,7 +23,16 @@
#include "nm-wifi-utils.h" #include "nm-wifi-utils.h"
NMWifiUtils *nm_wifi_utils_wext_init (int ifindex, gboolean check_scan); #define NM_TYPE_WIFI_UTILS_WEXT (nm_wifi_utils_wext_get_type ())
#define NM_WIFI_UTILS_WEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_UTILS_WEXT, NMWifiUtilsWext))
#define NM_WIFI_UTILS_WEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_WIFI_UTILS_WEXT, NMWifiUtilsWextClass))
#define NM_IS_WIFI_UTILS_WEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_WIFI_UTILS_WEXT))
#define NM_IS_WIFI_UTILS_WEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_WIFI_UTILS_WEXT))
#define NM_WIFI_UTILS_WEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_WIFI_UTILS_WEXT, NMWifiUtilsWextClass))
GType nm_wifi_utils_wext_get_type (void);
NMWifiUtils *nm_wifi_utils_wext_new (int ifindex, gboolean check_scan);
gboolean nm_wifi_utils_wext_is_wifi (const char *iface); gboolean nm_wifi_utils_wext_is_wifi (const char *iface);

View File

@@ -37,35 +37,34 @@
#include "platform/nm-platform-utils.h" #include "platform/nm-platform-utils.h"
gpointer G_DEFINE_ABSTRACT_TYPE (NMWifiUtils, nm_wifi_utils, G_TYPE_OBJECT)
nm_wifi_utils_new (const NMWifiUtilsClass *klass, int ifindex)
{
NMWifiUtils *data;
nm_assert (klass);
nm_assert (klass->struct_size > sizeof (NMWifiUtils));
data = g_malloc0 (klass->struct_size);
data->klass = klass;
data->ifindex = ifindex;
return data;
}
/*****************************************************************************/ /*****************************************************************************/
static void
nm_wifi_utils_init (NMWifiUtils *self)
{
}
static void
nm_wifi_utils_class_init (NMWifiUtilsClass *klass)
{
}
NMWifiUtils * NMWifiUtils *
nm_wifi_utils_init (int ifindex, gboolean check_scan) nm_wifi_utils_new (int ifindex, gboolean check_scan)
{ {
NMWifiUtils *ret; NMWifiUtils *ret;
g_return_val_if_fail (ifindex > 0, NULL); g_return_val_if_fail (ifindex > 0, NULL);
ret = nm_wifi_utils_nl80211_init (ifindex); ret = nm_wifi_utils_nl80211_new (ifindex);
if (ret == NULL) {
#if HAVE_WEXT #if HAVE_WEXT
ret = nm_wifi_utils_wext_init (ifindex, check_scan); if (ret == NULL)
ret = nm_wifi_utils_wext_new (ifindex, check_scan);
#endif #endif
}
return ret; return ret;
} }
@@ -81,53 +80,64 @@ NM80211Mode
nm_wifi_utils_get_mode (NMWifiUtils *data) nm_wifi_utils_get_mode (NMWifiUtils *data)
{ {
g_return_val_if_fail (data != NULL, NM_802_11_MODE_UNKNOWN); g_return_val_if_fail (data != NULL, NM_802_11_MODE_UNKNOWN);
return data->klass->get_mode (data); return NM_WIFI_UTILS_GET_CLASS (data)->get_mode (data);
} }
gboolean gboolean
nm_wifi_utils_set_mode (NMWifiUtils *data, const NM80211Mode mode) nm_wifi_utils_set_mode (NMWifiUtils *data, const NM80211Mode mode)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail ( (mode == NM_802_11_MODE_INFRA) g_return_val_if_fail ( (mode == NM_802_11_MODE_INFRA)
|| (mode == NM_802_11_MODE_AP) || (mode == NM_802_11_MODE_AP)
|| (mode == NM_802_11_MODE_ADHOC), FALSE); || (mode == NM_802_11_MODE_ADHOC), FALSE);
klass = NM_WIFI_UTILS_GET_CLASS (data);
/* nl80211 probably doesn't need this */ /* nl80211 probably doesn't need this */
return data->klass->set_mode ? data->klass->set_mode (data, mode) : TRUE; return klass->set_mode ? klass->set_mode (data, mode) : TRUE;
} }
gboolean gboolean
nm_wifi_utils_set_powersave (NMWifiUtils *data, guint32 powersave) nm_wifi_utils_set_powersave (NMWifiUtils *data, guint32 powersave)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
return data->klass->set_powersave ? data->klass->set_powersave (data, powersave) : TRUE; klass = NM_WIFI_UTILS_GET_CLASS (data);
return klass->set_powersave ? klass->set_powersave (data, powersave) : TRUE;
} }
NMSettingWirelessWakeOnWLan NMSettingWirelessWakeOnWLan
wifi_utils_get_wake_on_wlan (WifiData *data) nm_wifi_utils_get_wake_on_wlan (NMWifiUtils *data)
{ {
g_return_val_if_fail (data != NULL, FALSE); NMWifiUtilsClass *klass;
return data->klass->get_wake_on_wlan g_return_val_if_fail (data != NULL, NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE);
? data->klass->get_wake_on_wlan (data)
: NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; klass = NM_WIFI_UTILS_GET_CLASS (data);
return klass->get_wake_on_wlan ? klass->get_wake_on_wlan (data) : NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE;
} }
gboolean gboolean
wifi_utils_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl) nm_wifi_utils_set_wake_on_wlan (NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
return data->klass->set_wake_on_wlan ? klass = NM_WIFI_UTILS_GET_CLASS (data);
data->klass->set_wake_on_wlan (data, wowl) : FALSE; return klass->set_wake_on_wlan ? klass->set_wake_on_wlan (data, wowl) : FALSE;
} }
guint32 guint32
nm_wifi_utils_get_freq (NMWifiUtils *data) nm_wifi_utils_get_freq (NMWifiUtils *data)
{ {
g_return_val_if_fail (data != NULL, 0); g_return_val_if_fail (data != NULL, 0);
return data->klass->get_freq (data); return NM_WIFI_UTILS_GET_CLASS (data)->get_freq (data);
} }
guint32 guint32
@@ -135,7 +145,7 @@ nm_wifi_utils_find_freq (NMWifiUtils *data, const guint32 *freqs)
{ {
g_return_val_if_fail (data != NULL, 0); g_return_val_if_fail (data != NULL, 0);
g_return_val_if_fail (freqs != NULL, 0); g_return_val_if_fail (freqs != NULL, 0);
return data->klass->find_freq (data, freqs); return NM_WIFI_UTILS_GET_CLASS (data)->find_freq (data, freqs);
} }
gboolean gboolean
@@ -145,30 +155,21 @@ nm_wifi_utils_get_bssid (NMWifiUtils *data, guint8 *out_bssid)
g_return_val_if_fail (out_bssid != NULL, FALSE); g_return_val_if_fail (out_bssid != NULL, FALSE);
memset (out_bssid, 0, ETH_ALEN); memset (out_bssid, 0, ETH_ALEN);
return data->klass->get_bssid (data, out_bssid); return NM_WIFI_UTILS_GET_CLASS (data)->get_bssid (data, out_bssid);
} }
guint32 guint32
nm_wifi_utils_get_rate (NMWifiUtils *data) nm_wifi_utils_get_rate (NMWifiUtils *data)
{ {
g_return_val_if_fail (data != NULL, 0); g_return_val_if_fail (data != NULL, 0);
return data->klass->get_rate (data); return NM_WIFI_UTILS_GET_CLASS (data)->get_rate (data);
} }
int int
nm_wifi_utils_get_qual (NMWifiUtils *data) nm_wifi_utils_get_qual (NMWifiUtils *data)
{ {
g_return_val_if_fail (data != NULL, 0); g_return_val_if_fail (data != NULL, 0);
return data->klass->get_qual (data); return NM_WIFI_UTILS_GET_CLASS (data)->get_qual (data);
}
void
nm_wifi_utils_unref (NMWifiUtils *data)
{
g_return_if_fail (data != NULL);
data->klass->deinit (data);
g_free (data);
} }
gboolean gboolean
@@ -190,34 +191,50 @@ nm_wifi_utils_is_wifi (int dirfd, const char *ifname)
guint32 guint32
nm_wifi_utils_get_mesh_channel (NMWifiUtils *data) nm_wifi_utils_get_mesh_channel (NMWifiUtils *data)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (data->klass->get_mesh_channel != NULL, FALSE);
return data->klass->get_mesh_channel (data); klass = NM_WIFI_UTILS_GET_CLASS (data);
g_return_val_if_fail (klass->get_mesh_channel != NULL, FALSE);
return klass->get_mesh_channel (data);
} }
gboolean gboolean
nm_wifi_utils_set_mesh_channel (NMWifiUtils *data, guint32 channel) nm_wifi_utils_set_mesh_channel (NMWifiUtils *data, guint32 channel)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (channel <= 13, FALSE); g_return_val_if_fail (channel <= 13, FALSE);
g_return_val_if_fail (data->klass->set_mesh_channel != NULL, FALSE);
return data->klass->set_mesh_channel (data, channel); klass = NM_WIFI_UTILS_GET_CLASS (data);
g_return_val_if_fail (klass->set_mesh_channel != NULL, FALSE);
return klass->set_mesh_channel (data, channel);
} }
gboolean gboolean
nm_wifi_utils_set_mesh_ssid (NMWifiUtils *data, const guint8 *ssid, gsize len) nm_wifi_utils_set_mesh_ssid (NMWifiUtils *data, const guint8 *ssid, gsize len)
{ {
NMWifiUtilsClass *klass;
g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (data->klass->set_mesh_ssid != NULL, FALSE);
return data->klass->set_mesh_ssid (data, ssid, len); klass = NM_WIFI_UTILS_GET_CLASS (data);
g_return_val_if_fail (klass->set_mesh_ssid != NULL, FALSE);
return klass->set_mesh_ssid (data, ssid, len);
} }
gboolean gboolean
nm_wifi_utils_indicate_addressing_running (NMWifiUtils *data, gboolean running) nm_wifi_utils_indicate_addressing_running (NMWifiUtils *data, gboolean running)
{ {
g_return_val_if_fail (data != NULL, FALSE); NMWifiUtilsClass *klass;
if (data->klass->indicate_addressing_running)
return data->klass->indicate_addressing_running (data, running);
return FALSE;
}
g_return_val_if_fail (data != NULL, FALSE);
klass = NM_WIFI_UTILS_GET_CLASS (data);
return klass->indicate_addressing_running ? klass->indicate_addressing_running (data, running) : FALSE;
}

View File

@@ -29,11 +29,18 @@
typedef struct NMWifiUtils NMWifiUtils; typedef struct NMWifiUtils NMWifiUtils;
#define NM_TYPE_WIFI_UTILS (nm_wifi_utils_get_type ())
#define NM_WIFI_UTILS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_UTILS, NMWifiUtils))
#define NM_WIFI_UTILS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_WIFI_UTILS, NMWifiUtilsClass))
#define NM_IS_WIFI_UTILS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_WIFI_UTILS))
#define NM_IS_WIFI_UTILS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_WIFI_UTILS))
#define NM_WIFI_UTILS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_WIFI_UTILS, NMWifiUtilsClass))
GType nm_wifi_utils_get_type (void);
gboolean nm_wifi_utils_is_wifi (int dirfd, const char *ifname); gboolean nm_wifi_utils_is_wifi (int dirfd, const char *ifname);
NMWifiUtils *nm_wifi_utils_init (int ifindex, gboolean check_scan); NMWifiUtils *nm_wifi_utils_new (int ifindex, gboolean check_scan);
void nm_wifi_utils_unref (NMWifiUtils *data);
NMDeviceWifiCapabilities nm_wifi_utils_get_caps (NMWifiUtils *data); NMDeviceWifiCapabilities nm_wifi_utils_get_caps (NMWifiUtils *data);
@@ -62,9 +69,9 @@ gboolean nm_wifi_utils_indicate_addressing_running (NMWifiUtils *data, gboolean
gboolean nm_wifi_utils_set_powersave (NMWifiUtils *data, guint32 powersave); gboolean nm_wifi_utils_set_powersave (NMWifiUtils *data, guint32 powersave);
NMSettingWirelessWakeOnWLan wifi_utils_get_wake_on_wlan (WifiData *data); NMSettingWirelessWakeOnWLan nm_wifi_utils_get_wake_on_wlan (NMWifiUtils *data);
gboolean wifi_utils_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl); gboolean nm_wifi_utils_set_wake_on_wlan (NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl);
/* OLPC Mesh-only functions */ /* OLPC Mesh-only functions */
guint32 nm_wifi_utils_get_mesh_channel (NMWifiUtils *data); guint32 nm_wifi_utils_get_mesh_channel (NMWifiUtils *data);