platform: add support for wake-on-wlan

Co-authored-by: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
This commit is contained in:
Simon Fels 2018-05-25 17:43:54 +02:00 committed by Thomas Haller
parent 58cdc7b550
commit 1621c79e7b
8 changed files with 82 additions and 0 deletions

View file

@ -6092,6 +6092,14 @@ wifi_indicate_addressing_running (NMPlatform *platform, int ifindex, gboolean ru
wifi_utils_indicate_addressing_running (wifi_data, running);
}
static gboolean
wifi_set_wake_on_wlan (NMPlatform *platform, int ifindex,
NMSettingWirelessWakeOnWLan wowl)
{
WIFI_GET_WIFI_DATA_NETNS (wifi_data, platform, ifindex, FALSE);
return wifi_utils_set_wake_on_wlan (wifi_data, wowl);
}
/*****************************************************************************/
static gboolean
@ -7230,6 +7238,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->wifi_set_powersave = wifi_set_powersave;
platform_class->wifi_find_frequency = wifi_find_frequency;
platform_class->wifi_indicate_addressing_running = wifi_indicate_addressing_running;
platform_class->wifi_set_wake_on_wlan = wifi_set_wake_on_wlan;
platform_class->mesh_get_channel = mesh_get_channel;
platform_class->mesh_set_channel = mesh_set_channel;

View file

@ -244,6 +244,9 @@ nla_put_string (struct nl_msg *msg, int attrtype, const char *str)
#define NLA_PUT_STRING(msg, attrtype, value) \
NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)
#define NLA_PUT_FLAG(msg, attrtype) \
NLA_PUT(msg, attrtype, 0, NULL)
struct nlattr *nla_find (const struct nlattr *head, int len, int attrtype);
static inline int

View file

@ -2888,6 +2888,16 @@ nm_platform_wifi_indicate_addressing_running (NMPlatform *self, int ifindex, gbo
klass->wifi_indicate_addressing_running (self, ifindex, running);
}
gboolean
nm_platform_wifi_set_wake_on_wlan (NMPlatform *self, int ifindex, NMSettingWirelessWakeOnWLan wowl)
{
_CHECK_SELF (self, klass, FALSE);
g_return_val_if_fail (ifindex > 0, FALSE);
return klass->wifi_set_wake_on_wlan (self, ifindex, wowl);
}
guint32
nm_platform_mesh_get_channel (NMPlatform *self, int ifindex)
{

View file

@ -33,6 +33,7 @@
#include "nm-core-utils.h"
#include "nm-setting-vlan.h"
#include "nm-setting-wired.h"
#include "nm-setting-wireless.h"
#include "nm-setting-ip-tunnel.h"
#define NM_TYPE_PLATFORM (nm_platform_get_type ())
@ -867,6 +868,7 @@ typedef struct {
void (*wifi_set_powersave) (NMPlatform *, int ifindex, guint32 powersave);
guint32 (*wifi_find_frequency) (NMPlatform *, int ifindex, const guint32 *freqs);
void (*wifi_indicate_addressing_running) (NMPlatform *, int ifindex, gboolean running);
gboolean (*wifi_set_wake_on_wlan) (NMPlatform *, int ifindex, NMSettingWirelessWakeOnWLan wowl);
guint32 (*mesh_get_channel) (NMPlatform *, int ifindex);
gboolean (*mesh_set_channel) (NMPlatform *, int ifindex, guint32 channel);
@ -1245,6 +1247,7 @@ void nm_platform_wifi_set_mode (NMPlatform *self, int ifindex, NM
void nm_platform_wifi_set_powersave (NMPlatform *self, int ifindex, guint32 powersave);
guint32 nm_platform_wifi_find_frequency (NMPlatform *self, int ifindex, const guint32 *freqs);
void nm_platform_wifi_indicate_addressing_running (NMPlatform *self, int ifindex, gboolean running);
gboolean nm_platform_wifi_set_wake_on_wlan (NMPlatform *self, int ifindex, NMSettingWirelessWakeOnWLan wowl);
guint32 nm_platform_mesh_get_channel (NMPlatform *self, int ifindex);
gboolean nm_platform_mesh_set_channel (NMPlatform *self, int ifindex, guint32 channel);

View file

@ -271,6 +271,47 @@ nla_put_failure:
return FALSE;
}
static gboolean
wifi_nl80211_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl)
{
WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) data;
nm_auto_nlmsg struct nl_msg *msg = NULL;
struct nlattr *triggers;
int err;
if (wowl == NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE)
return TRUE;
msg = nl80211_alloc_msg(nl80211, NL80211_CMD_SET_WOWLAN, 0);
if (!msg)
return FALSE;
triggers = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_ANY);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_DISCONNECT);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
if (NM_FLAGS_HAS (wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE))
NLA_PUT_FLAG (msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
nla_nest_end(msg, triggers);
err = nl80211_send_and_recv (nl80211, msg, NULL, NULL);
return err ? FALSE : TRUE;
nla_put_failure:
return FALSE;
}
/* @divisor: pass what value @xbm should be divided by to get dBm */
static guint32
nl80211_xbm_to_percent (gint32 xbm, guint32 divisor)
@ -846,6 +887,7 @@ wifi_nl80211_init (int ifindex)
.get_mode = wifi_nl80211_get_mode,
.set_mode = wifi_nl80211_set_mode,
.set_powersave = wifi_nl80211_set_powersave,
.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,

View file

@ -34,6 +34,9 @@ typedef struct {
/* Set power saving mode on an interface */
gboolean (*set_powersave) (WifiData *data, guint32 powersave);
/* Set WakeOnWLAN mode on an interface */
gboolean (*set_wake_on_wlan) (WifiData *data, NMSettingWirelessWakeOnWLan wowl);
/* Return current frequency in MHz (really associated BSS frequency) */
guint32 (*get_freq) (WifiData *data);

View file

@ -112,6 +112,15 @@ wifi_utils_set_powersave (WifiData *data, guint32 powersave)
return data->klass->set_powersave ? data->klass->set_powersave (data, powersave) : TRUE;
}
gboolean
wifi_utils_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl)
{
g_return_val_if_fail (data != NULL, FALSE);
return data->klass->set_wake_on_wlan ?
data->klass->set_wake_on_wlan (data, wowl) : FALSE;
}
guint32
wifi_utils_get_freq (WifiData *data)
{

View file

@ -25,6 +25,7 @@
#include <net/ethernet.h>
#include "nm-dbus-interface.h"
#include "nm-setting-wireless.h"
typedef struct WifiData WifiData;
@ -66,6 +67,8 @@ gboolean wifi_utils_get_wowlan (WifiData *data);
gboolean wifi_utils_set_powersave (WifiData *data, guint32 powersave);
gboolean wifi_utils_set_wake_on_wlan (WifiData *data, NMSettingWirelessWakeOnWLan wowl);
/* OLPC Mesh-only functions */
guint32 wifi_utils_get_mesh_channel (WifiData *data);