[PATCH] supplicant: add dbus getter method for nl80211 iftype

Dan Williams dcbw at redhat.com
Tue Nov 4 10:59:20 EST 2014


On Tue, 2014-11-04 at 14:21 +0530, Avinash Patil wrote:
> This patch adds dbus getter method for nl80211 iftype.
> This is required by certain applications which intend to start
> AP operations only if current interface type is AP.
> Getter method for capabilities cannot be used for this purpose as
> this enumerates all the supported interface types.
> 
> Signed-off-by: Avinash Patil <avinashapatil at gmail.com>
> ---
>  src/common/defs.h                       | 18 ++++++++++++++++
>  src/drivers/driver.h                    | 12 +++++++++++
>  src/drivers/driver_nl80211.c            | 11 ++++++++++
>  wpa_supplicant/dbus/dbus_new.c          |  4 ++++
>  wpa_supplicant/dbus/dbus_new_handlers.c | 38 +++++++++++++++++++++++++++++++++
>  wpa_supplicant/dbus/dbus_new_handlers.h |  4 ++++
>  wpa_supplicant/driver_i.h               |  8 +++++++
>  wpa_supplicant/wpa_supplicant.c         | 33 ++++++++++++++++++++++++++++
>  wpa_supplicant/wpa_supplicant_i.h       |  1 +
>  9 files changed, 129 insertions(+)
> 
> diff --git a/src/common/defs.h b/src/common/defs.h
> index d4091e3..b5e5a77 100644
> --- a/src/common/defs.h
> +++ b/src/common/defs.h
> @@ -297,6 +297,24 @@ enum wpa_ctrl_req_type {
>         NUM_WPA_CTRL_REQS
>  };
> 
> +enum wpa_nl80211_iftype {
> +       WPA_IFTYPE_UNSPECIFIED,
> +       WPA_IFTYPE_ADHOC,
> +       WPA_IFTYPE_STATION,
> +       WPA_IFTYPE_AP,
> +       WPA_IFTYPE_AP_VLAN,
> +       WPA_IFTYPE_WDS,
> +       WPA_IFTYPE_MONITOR,
> +       WPA_IFTYPE_MESH_POINT,
> +       WPA_IFTYPE_P2P_CLIENT,
> +       WPA_IFTYPE_P2P_GO,
> +       WPA_IFTYPE_P2P_DEVICE,
> +
> +       /* keep last */
> +       WPA_NL80211_IFTYPES,
> +       WPA_IFTYPE_MAX = WPA_NL80211_IFTYPES - 1
> +};
> +
>  /* Maximum number of EAP methods to store for EAP server user information */
>  #define EAP_MAX_METHODS 8
> 
> diff --git a/src/drivers/driver.h b/src/drivers/driver.h
> index 6e47b86..6833d32 100644
> --- a/src/drivers/driver.h
> +++ b/src/drivers/driver.h
> @@ -1358,6 +1358,18 @@ struct wpa_driver_ops {
>         int (*get_ssid)(void *priv, u8 *ssid);
> 
>         /**
> +        * get_iftype - Get the current NL80211 iftype
> +        * @priv: private driver interface data
> +        * @iftype: buffer for storing iftype
> +        *
> +        * Returns: 0 on success, -1 on failure
> +        *
> +        * Query kernel driver for the current NL80211 mode and copy it to
> +        * iftype.
> +        */
> +       int (*get_iftype)(void *priv, u8 *iftype);
> +
> +       /**
>          * set_key - Configure encryption key
>          * @ifname: Interface name (for multi-SSID/VLAN support)
>          * @priv: private driver interface data
> diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
> index 5d31018..15fa461 100644
> --- a/src/drivers/driver_nl80211.c
> +++ b/src/drivers/driver_nl80211.c
> @@ -1063,6 +1063,16 @@ static int wpa_driver_nl80211_get_bssid(void
> *priv, u8 *bssid)
>         return 0;
>  }
> 
> +static int wpa_driver_nl80211_get_nl80211_iftype(void *priv, u8 *iftype)
> +{
> +       struct i802_bss *bss = priv;
> +       if (!bss)
> +               return -1;
> +
> +       *iftype = (u8)nl80211_get_ifmode(bss);
> +
> +       return 0;
> +}
> 
>  static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
>  {
> @@ -12293,6 +12303,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
>         .desc = "Linux nl80211/cfg80211",
>         .get_bssid = wpa_driver_nl80211_get_bssid,
>         .get_ssid = wpa_driver_nl80211_get_ssid,
> +       .get_iftype = wpa_driver_nl80211_get_nl80211_iftype,
>         .set_key = driver_nl80211_set_key,
>         .scan2 = driver_nl80211_scan2,
>         .sched_scan = wpa_driver_nl80211_sched_scan,
> diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
> index 6bd2a40..67238e7 100644
> --- a/wpa_supplicant/dbus/dbus_new.c
> +++ b/wpa_supplicant/dbus/dbus_new.c
> @@ -2809,6 +2809,10 @@ static const struct wpa_dbus_property_desc
> wpas_dbus_interface_properties[] = {
>           wpas_dbus_getter_driver,
>           NULL
>         },
> +       { "CurrentIfType", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
> +         wpas_dbus_getter_current_iftype,
> +         NULL
> +       },

I would just call this "IfType".  "Current" is redundant, because the
property only ever reports the current Iftype.

Second, I don't see any notification handling code.  When the iftype is
changed, something needs to emit property notifications for the IfType
property so that listeners know that the interface type is now
different.

Dan

>         { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
>           wpas_dbus_getter_bridge_ifname,
>           NULL
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c
> b/wpa_supplicant/dbus/dbus_new_handlers.c
> index f5efd8b..755f902 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers.c
> +++ b/wpa_supplicant/dbus/dbus_new_handlers.c
> @@ -3083,6 +3083,44 @@ dbus_bool_t
> wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
>                                                 &driver, error);
>  }
> 
> +/**
> + * wpas_dbus_getter_current_mode -
> + * Get current NL mode
> + * @iter: Pointer to incoming dbus message iter
> + * @error: Location to store error on failure
> + * @user_data: Function specific data
> + * Returns: TRUE on success, FALSE on failure
> + *
> + * Getter for "Current IF type" property.
> + */
> +dbus_bool_t wpas_dbus_getter_current_iftype(DBusMessageIter *iter,
> +                                         DBusError *error, void *user_data)
> +{
> +       struct wpa_supplicant *wpa_s = user_data;
> +       u8 iftype;
> +       const char *char_iftype;
> +
> +       if (wpa_s->driver == NULL) {
> +               wpa_printf(MSG_DEBUG, "wpas_dbus_getter_current_iftype[dbus]: "
> +                          "wpa_s has no driver set");
> +               dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
> +                              __func__);
> +               return FALSE;
> +       }
> +
> +       if(wpa_drv_get_iftype(wpa_s, &iftype)) {
> +               wpa_printf(MSG_DEBUG, "wpas_dbus_getter_current_iftype[dbus]: "
> +                          "failed");
> +               dbus_set_error(error, DBUS_ERROR_FAILED, "%s: failed",
> +                              __func__);
> +               return FALSE;
> +       }
> +       char_iftype =  wpa_supplicant_iftype_txt(iftype);
> +
> +       wpa_printf(MSG_DEBUG, "dbus: Get interface type: %s", char_iftype);
> +       return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
> +                                               &char_iftype, error);
> +}
> 
>  /**
>   * wpas_dbus_getter_current_bss - Get current bss object path
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h
> b/wpa_supplicant/dbus/dbus_new_handlers.h
> index 461970d..51f0332 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers.h
> +++ b/wpa_supplicant/dbus/dbus_new_handlers.h
> @@ -202,6 +202,10 @@ dbus_bool_t
> wpas_dbus_getter_ifname(DBusMessageIter *iter, DBusError *error,
>  dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
>                                     void *user_data);
> 
> +dbus_bool_t wpas_dbus_getter_current_iftype(DBusMessageIter *iter,
> +                                           DBusError *error,
> +                                           void *user_data);
> +
>  dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter,
>                                            DBusError *error,
>                                            void *user_data);
> diff --git a/wpa_supplicant/driver_i.h b/wpa_supplicant/driver_i.h
> index 00703d9..c10ae25 100644
> --- a/wpa_supplicant/driver_i.h
> +++ b/wpa_supplicant/driver_i.h
> @@ -114,6 +114,14 @@ static inline int wpa_drv_get_ssid(struct
> wpa_supplicant *wpa_s, u8 *ssid)
>         return -1;
>  }
> 
> +static inline int wpa_drv_get_iftype(struct wpa_supplicant *wpa_s, u8 *iftype)
> +{
> +       if (wpa_s->driver->get_iftype) {
> +               return wpa_s->driver->get_iftype(wpa_s->drv_priv, iftype);
> +       }
> +       return -1;
> +}
> +
>  static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s,
>                                   enum wpa_alg alg, const u8 *addr,
>                                   int key_idx, int set_tx,
> diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
> index 28d763c..16519d9 100644
> --- a/wpa_supplicant/wpa_supplicant.c
> +++ b/wpa_supplicant/wpa_supplicant.c
> @@ -573,6 +573,39 @@ const char * wpa_supplicant_state_txt(enum
> wpa_states state)
>         }
>  }
> 
> +/**
> + * wpa_supplicant_iftype_txt - Get the NL80211 iftype as a text string
> + * Returns: The iftype name as a printable text string
> + */
> +const char * wpa_supplicant_iftype_txt(u8 iftype)
> +{
> +       switch (iftype) {
> +       case WPA_IFTYPE_UNSPECIFIED:
> +               return "UNSPECIFIED";
> +       case WPA_IFTYPE_ADHOC:
> +               return "ADHOC";
> +       case WPA_IFTYPE_STATION:
> +               return "STATION";
> +       case WPA_IFTYPE_AP:
> +               return "AP";
> +       case WPA_IFTYPE_AP_VLAN:
> +               return "AP_VLAN";
> +       case WPA_IFTYPE_WDS:
> +               return "WDS";
> +       case WPA_IFTYPE_MONITOR:
> +               return "MONITOR";
> +       case WPA_IFTYPE_MESH_POINT:
> +               return "MESH_POINT";
> +       case WPA_IFTYPE_P2P_CLIENT:
> +               return "P2P_CLIENT";
> +       case WPA_IFTYPE_P2P_GO:
> +               return "P2P_GO";
> +       case WPA_IFTYPE_P2P_DEVICE:
> +               return "P2P_DEVICE";
> +       default:
> +               return "UNKNOWN";
> +       }
> +}
> 
>  #ifdef CONFIG_BGSCAN
> 
> diff --git a/wpa_supplicant/wpa_supplicant_i.h
> b/wpa_supplicant/wpa_supplicant_i.h
> index c51a703..9138630 100644
> --- a/wpa_supplicant/wpa_supplicant_i.h
> +++ b/wpa_supplicant/wpa_supplicant_i.h
> @@ -874,6 +874,7 @@ int wpa_supplicant_set_wpa_none_key(struct
> wpa_supplicant *wpa_s,
>  int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
> 
>  const char * wpa_supplicant_state_txt(enum wpa_states state);
> +const char * wpa_supplicant_iftype_txt(u8 iftype);
>  int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s);
>  int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);
>  int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
> --
> 1.8.1.4
> _______________________________________________
> HostAP mailing list
> HostAP at lists.shmoo.com
> http://lists.shmoo.com/mailman/listinfo/hostap




More information about the HostAP mailing list