Merge commit 'garage/master'
[wpasupplicant] / wpa_supplicant / ctrl_iface_dbus.c
index 7f2fba4..572f262 100644 (file)
@@ -18,6 +18,8 @@
 #include "eloop.h"
 #include "config.h"
 #include "wpa_supplicant_i.h"
+#include "drivers/driver.h"
+#include "wps/wps.h"
 #include "ctrl_iface_dbus.h"
 #include "ctrl_iface_dbus_handlers.h"
 
@@ -539,15 +541,26 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
                                                                      wpa_s);
                else if (!strcmp(method, "state"))
                        reply = wpas_dbus_iface_get_state(message, wpa_s);
+               else if (!strcmp(method, "scanning"))
+                       reply = wpas_dbus_iface_get_scanning(message, wpa_s);
                else if (!strcmp(method, "setBlobs"))
                        reply = wpas_dbus_iface_set_blobs(message, wpa_s);
                else if (!strcmp(method, "removeBlobs"))
                        reply = wpas_dbus_iface_remove_blobs(message, wpa_s);
+#ifdef CONFIG_WPS
+               else if (!os_strcmp(method, "wpsPbc"))
+                       reply = wpas_dbus_iface_wps_pbc(message, wpa_s);
+               else if (!os_strcmp(method, "wpsPin"))
+                       reply = wpas_dbus_iface_wps_pin(message, wpa_s);
+               else if (!os_strcmp(method, "wpsReg"))
+                       reply = wpas_dbus_iface_wps_reg(message, wpa_s);
+#endif /* CONFIG_WPS */
        }
 
        /* If the message was handled, send back the reply */
        if (reply) {
-               dbus_connection_send(connection, reply, NULL);
+               if (!dbus_message_get_no_reply(message))
+                       dbus_connection_send(connection, reply, NULL);
                dbus_message_unref(reply);
        }
 
@@ -601,12 +614,16 @@ static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
                } else if (!strcmp(method, "getInterface")) {
                        reply = wpas_dbus_global_get_interface(
                                message, ctrl_iface->global);
+               } else if (!strcmp(method, "setDebugParams")) {
+                       reply = wpas_dbus_global_set_debugparams(
+                               message, ctrl_iface->global);
                }
        }
 
        /* If the message was handled, send back the reply */
        if (reply) {
-               dbus_connection_send(connection, reply, NULL);
+               if (!dbus_message_get_no_reply(message))
+                       dbus_connection_send(connection, reply, NULL);
                dbus_message_unref(reply);
        }
 
@@ -739,6 +756,115 @@ out:
 
 
 /**
+ * wpa_supplicant_dbus_notify_scanning - send scanning status
+ * @wpa_s: %wpa_supplicant network interface data
+ * Returns: 0 on success, -1 on failure
+ *
+ * Notify listeners of interface scanning state changes
+ */
+void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
+{
+       struct ctrl_iface_dbus_priv *iface = wpa_s->global->dbus_ctrl_iface;
+       DBusMessage *_signal;
+       const char *path;
+       dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
+
+       /* Do nothing if the control interface is not turned on */
+       if (iface == NULL)
+               return;
+
+       path = wpa_supplicant_get_dbus_path(wpa_s);
+       if (path == NULL) {
+               perror("wpa_supplicant_dbus_notify_scanning[dbus]: interface "
+                      "didn't have a dbus path");
+               wpa_printf(MSG_ERROR,
+                          "%s[dbus]: interface didn't have a dbus path; "
+                          "can't send scanning signal.", __FUNCTION__);
+               return;
+       }
+       _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+                                         "Scanning");
+       if (_signal == NULL) {
+               perror("wpa_supplicant_dbus_notify_scanning[dbus]: couldn't "
+                      "create dbus signal; likely out of memory");
+               wpa_printf(MSG_ERROR, "%s[dbus]: dbus control interface: not "
+                          "enough memory to send scan results signal.",
+                          __FUNCTION__);
+               return;
+       }
+
+       if (dbus_message_append_args(_signal,
+                                    DBUS_TYPE_BOOLEAN, &scanning,
+                                    DBUS_TYPE_INVALID)) {
+               dbus_connection_send(iface->con, _signal, NULL);
+       } else {
+               perror("wpa_supplicant_dbus_notify_scanning[dbus]: not enough "
+                      "memory to construct signal.");
+               wpa_printf(MSG_ERROR, "%s[dbus]: not enough memory to "
+                          "construct signal.", __FUNCTION__);
+       }
+       dbus_message_unref(_signal);
+}
+
+
+#ifdef CONFIG_WPS
+void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
+                                        const struct wps_credential *cred)
+{
+       struct ctrl_iface_dbus_priv *iface;
+       DBusMessage *_signal = NULL;
+       const char *path;
+
+       /* Do nothing if the control interface is not turned on */
+       if (wpa_s->global == NULL)
+               return;
+       iface = wpa_s->global->dbus_ctrl_iface;
+       if (iface == NULL)
+               return;
+
+       path = wpa_supplicant_get_dbus_path(wpa_s);
+       if (path == NULL) {
+               perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                      "interface didn't have a dbus path");
+               wpa_printf(MSG_ERROR,
+                          "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                          "interface didn't have a dbus path; can't send "
+                          "signal.");
+               return;
+       }
+       _signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE,
+                                         "WpsCred");
+       if (_signal == NULL) {
+               perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                      "couldn't create dbus signal; likely out of memory");
+               wpa_printf(MSG_ERROR,
+                          "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                          "couldn't create dbus signal; likely out of "
+                          "memory.");
+               return;
+       }
+
+       if (!dbus_message_append_args(_signal,
+                                     DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+                                     &cred->cred_attr, cred->cred_attr_len,
+                                     DBUS_TYPE_INVALID)) {
+               perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                      "not enough memory to construct signal.");
+               wpa_printf(MSG_ERROR,
+                          "wpa_supplicant_dbus_notify_wps_cred[dbus]: "
+                          "not enough memory to construct signal.");
+               goto out;
+       }
+
+       dbus_connection_send(iface->con, _signal, NULL);
+
+out:
+       dbus_message_unref(_signal);
+}
+#endif /* CONFIG_WPS */
+
+
+/**
  * integrate_with_eloop - Register our mainloop integration with dbus
  * @connection: connection to the system message bus
  * @iface: a dbus control interface data structure