Re: [PATCH 2/4 v3] cli: add support for wake-on-wlan properties



On Wed, 2017-01-18 at 17:32 +0100, Simon Fels wrote:
---
 clients/cli/settings.c | 66
+++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 40cf975..7cb2d3e 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -214,6 +214,8 @@ NmcOutputField nmc_fields_setting_wireless[] = {
      SETTING_FIELD
(NM_SETTING_WIRELESS_SEEN_BSSIDS),               /* 14 */
      SETTING_FIELD
(NM_SETTING_WIRELESS_HIDDEN),                    /* 15 */
      SETTING_FIELD
(NM_SETTING_WIRELESS_POWERSAVE),                 /* 16 */
+     SETTING_FIELD
(NM_SETTING_WIRELESS_WAKE_ON_WLAN),              /* 17 */
+     SETTING_FIELD
(NM_SETTING_WIRELESS_WAKE_ON_WLAN_PASSWORD),     /* 18 */
      {NULL, NULL, 0, NULL, FALSE, FALSE, 0}
 };
 #define NMC_FIELDS_SETTING_WIRELESS_ALL     "name"","\
@@ -232,7 +234,10 @@ NmcOutputField nmc_fields_setting_wireless[] = {
                                             NM_SETTING_WIRELESS_MTU"
,"\
                                             NM_SETTING_WIRELESS_SEEN
_BSSIDS","\
                                             NM_SETTING_WIRELESS_HIDD
EN"," \
-                                            NM_SETTING_WIRELESS_POWE
RSAVE
+                                            NM_SETTING_WIRELESS_POWE
RSAVE"," \
+                                            NM_SETTING_WIRELESS_WAKE
_ON_WLAN"," \
+                                            NM_SETTING_WIRELESS_WAKE
_ON_WLAN_PASSWORD
+
 
 /* Available fields for NM_SETTING_WIRELESS_SECURITY_SETTING_NAME */
 NmcOutputField nmc_fields_setting_wireless_security[] = {
@@ -2088,6 +2093,24 @@
nmc_property_wireless_get_mac_address_randomization (NMSetting
*setting, NmcProp
              return g_strdup_printf (_("unknown"));
 }
 
+static char *
+nmc_property_wireless_get_wake_on_wlan (NMSetting *setting,
NmcPropertyGetType get_type)
+{
+     NMSettingWireless *s_wireless = NM_SETTING_WIRELESS
(setting);
+     NMSettingWirelessWakeOnWLan wowl;
+     gs_free char *str = NULL;
+     char *ret;
+
+     wowl = nm_setting_wireless_get_wake_on_wlan (s_wireless);
+     str = nm_utils_enum_to_str
(nm_setting_wireless_wake_on_wlan_get_type (), wowl);
+
+     if (get_type == NMC_PROPERTY_GET_PARSABLE) {
+             ret = str;
+             str = NULL;
+             return ret;

return g_steal_pointer (&str);
?

+     } else
+             return g_strdup_printf ("%s (%u)", str, wowl);

let's cast "wowl" to (guint)? Yes, it is correct as-is on probably
every architecture we support. Just to be explicit about it.

+}
 
 /* --- NM_SETTING_WIRELESS_SECURITY_SETTING_NAME property get
functions --- */
 DEFINE_GETTER (nmc_property_wifi_sec_get_key_mgmt,
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)
@@ -5469,6 +5492,39 @@
nmc_property_wireless_set_mac_address_randomization (NMSetting
*setting,
      return TRUE;
 }
 
+static gboolean
+nmc_property_wireless_set_wake_on_wlan (NMSetting *setting, const
char *prop, const char *val, GError **error)

in a follow up, we really need to refactor all this code-duplication
(but fine for now).

+{
+     NMSettingWirelessWakeOnWLan wowl;
+     gs_free const char **options = NULL;
+     gs_free char *options_str = NULL;
+     long int t;
+     gboolean ret;
+
+     if (nmc_string_to_int_base (val, 0, TRUE,
+                                 NM_SETTING_WIRELESS_WAKE_ON_WLAN
_DEFAULT,
+                                 NM_SETTING_WIRELESS_WAKE_ON_WLAN
_LAST,
+                                 &t))
+             wowl = (NMSettingWirelessWakeOnWLan) t;
+     else {
+             ret = nm_utils_enum_from_str
(nm_setting_wireless_wake_on_wlan_get_type (),
+                                           val,
+                                           (int *) &wowl,

+                                           NULL);
+             if (!ret) {
+                     options = nm_utils_enum_get_values
(nm_setting_wireless_wake_on_wlan_get_type (),
+                                                         NM_SETTI
NG_WIRELESS_WAKE_ON_WLAN_DEFAULT,
+                                                         NM_SETTI
NG_WIRELESS_WAKE_ON_WLAN_LAST);
+                     options_str = g_strjoinv (",", (char **)
options);
+                     g_set_error (error, 1, 0, _("invalid option
'%s', use one of [%s]"), val, options_str);
+                     return FALSE;
+             }
+     }
+
+     g_object_set (setting, prop, (guint) wowl, NULL);
+     return TRUE;
+}
+
 /* --- NM_SETTING_WIRELESS_SECURITY_SETTING_NAME property setter
functions --- */
 /* 'key-mgmt' */
 static const char *wifi_sec_valid_key_mgmts[] = { "none",
"ieee8021x", "wpa-none", "wpa-psk", "wpa-eap", NULL };
@@ -7707,6 +7763,13 @@ nmc_properties_init (void)
                          NULL,
                          NULL,
                          NULL);
+     nmc_add_prop_funcs (GLUE (WIRELESS, WAKE_ON_WLAN),
+                         nmc_property_wireless_get_wake_on_wlan,
+                         nmc_property_wireless_set_wake_on_wlan,
+                         NULL,
+                         NULL,
+                         NULL,
+                         NULL);
 
      /* Add editable properties for
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME */
      nmc_add_prop_funcs (GLUE (WIRELESS_SECURITY, KEY_MGMT),
@@ -8657,6 +8720,7 @@ setting_wireless_details (NMSetting *setting,
NmCli *nmc,  const char *one_prop,
      set_val_str (arr, 14, nmc_property_wireless_get_seen_bssids
(setting, NMC_PROPERTY_GET_PRETTY));
      set_val_str (arr, 15, nmc_property_wireless_get_hidden
(setting, NMC_PROPERTY_GET_PRETTY));
      set_val_str (arr, 16, nmc_property_wireless_get_powersave
(setting, NMC_PROPERTY_GET_PRETTY));
+     set_val_str (arr, 17, nmc_property_wireless_get_wake_on_wlan
(setting, NMC_PROPERTY_GET_PRETTY));
      g_ptr_array_add (nmc->output_data, arr);
 
      print_data (nmc);  /* Print all data */

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]