D-Bus: Write Get/Set property name in debug log
[mech_eap.git] / wpa_supplicant / dbus / dbus_old.c
index 0d47142..055809c 100644 (file)
@@ -2,14 +2,8 @@
  * WPA Supplicant / dbus-based control interface
  * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "includes.h"
 
 #include "common.h"
 #include "eloop.h"
-#include "drivers/driver.h"
 #include "wps/wps.h"
 #include "../config.h"
 #include "../wpa_supplicant_i.h"
+#include "../bss.h"
 #include "dbus_old.h"
 #include "dbus_old_handlers.h"
-#include "dbus_common.h"
 #include "dbus_common_i.h"
 
 
@@ -176,45 +169,23 @@ static DBusMessage * wpas_dispatch_network_method(DBusMessage *message,
  */
 static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message,
                                                struct wpa_supplicant *wpa_s,
-                                               const char *bssid)
+                                               const char *bssid_txt)
 {
-       DBusMessage *reply = NULL;
-       const char *method = dbus_message_get_member(message);
-       struct wpa_scan_res *res = NULL;
-       size_t i;
+       u8 bssid[ETH_ALEN];
+       struct wpa_bss *bss;
 
-       /* Ensure we actually have scan data */
-       if (wpa_s->scan_res == NULL &&
-           wpa_supplicant_get_scan_results(wpa_s) < 0) {
-               reply = wpas_dbus_new_invalid_bssid_error(message);
-               goto out;
-       }
+       if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0)
+               return wpas_dbus_new_invalid_bssid_error(message);
 
-       /* Find the bssid's scan data */
-       for (i = 0; i < wpa_s->scan_res->num; i++) {
-               struct wpa_scan_res *search_res = wpa_s->scan_res->res[i];
-               char mac_str[18];
-
-               memset(mac_str, 0, sizeof(mac_str));
-               snprintf(mac_str, sizeof(mac_str) - 1, WPAS_DBUS_BSSID_FORMAT,
-                        MAC2STR(search_res->bssid));
-               if (!strcmp(bssid, mac_str)) {
-                       res = search_res;
-                       break;
-               }
-       }
-
-       if (!res) {
-               reply = wpas_dbus_new_invalid_bssid_error(message);
-               goto out;
-       }
+       bss = wpa_bss_get_bssid(wpa_s, bssid);
+       if (bss == NULL)
+               return wpas_dbus_new_invalid_bssid_error(message);
 
        /* Dispatch the method call against the scanned bssid */
-       if (!strcmp(method, "properties"))
-               reply = wpas_dbus_bssid_properties(message, wpa_s, res);
+       if (os_strcmp(dbus_message_get_member(message), "properties") == 0)
+               return wpas_dbus_bssid_properties(message, wpa_s, bss);
 
-out:
-       return reply;
+       return NULL;
 }
 
 
@@ -245,6 +216,10 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
        if (!msg_interface)
                goto out;
 
+       wpa_printf(MSG_MSGDUMP, "dbus[old/iface]: %s.%s (%s) [%s]",
+                  msg_interface, method, path,
+                  dbus_message_get_signature(message));
+
        iface_obj_path = wpas_dbus_decompose_object_path(path, &network,
                                                         &bssid);
        if (iface_obj_path == NULL) {
@@ -297,10 +272,12 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
                        reply = wpas_dbus_iface_get_state(message, wpa_s);
                else if (!strcmp(method, "scanning"))
                        reply = wpas_dbus_iface_get_scanning(message, wpa_s);
+#ifndef CONFIG_NO_CONFIG_BLOBS
                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);
+#endif /* CONFIG_NO_CONFIG_BLOBS */
 #ifdef CONFIG_WPS
                else if (!os_strcmp(method, "wpsPbc"))
                        reply = wpas_dbus_iface_wps_pbc(message, wpa_s);
@@ -309,6 +286,8 @@ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection,
                else if (!os_strcmp(method, "wpsReg"))
                        reply = wpas_dbus_iface_wps_reg(message, wpa_s);
 #endif /* CONFIG_WPS */
+               else if (!os_strcmp(method, "flush"))
+                       reply = wpas_dbus_iface_flush(message, wpa_s);
        }
 
        /* If the message was handled, send back the reply */
@@ -353,6 +332,10 @@ static DBusHandlerResult wpas_message_handler(DBusConnection *connection,
        if (!method || !path || !ctrl_iface || !msg_interface)
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
+       wpa_printf(MSG_MSGDUMP, "dbus[old]: %s.%s (%s) [%s]",
+                  msg_interface, method, path,
+                  dbus_message_get_signature(message));
+
        /* Validate the method interface */
        if (strcmp(msg_interface, WPAS_DBUS_INTERFACE) != 0)
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -432,6 +415,9 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
        DBusMessage *_signal = NULL;
        const char *new_state_str, *old_state_str;
 
+       if (wpa_s->dbus_path == NULL)
+               return; /* Skip signal since D-Bus setup is not yet ready */
+
        /* Do nothing if the control interface is not turned on */
        if (wpa_s->global == NULL)
                return;
@@ -456,12 +442,6 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
 
        new_state_str = wpa_supplicant_state_txt(new_state);
        old_state_str = wpa_supplicant_state_txt(old_state);
-       if (new_state_str == NULL || old_state_str == NULL) {
-               wpa_printf(MSG_ERROR,
-                          "dbus: wpa_supplicant_dbus_notify_state_change: "
-                          "Could not convert state strings");
-               goto out;
-       }
 
        if (!dbus_message_append_args(_signal,
                                      DBUS_TYPE_STRING, &new_state_str,
@@ -566,6 +546,59 @@ void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
 }
 #endif /* CONFIG_WPS */
 
+void wpa_supplicant_dbus_notify_certification(struct wpa_supplicant *wpa_s,
+                                             int depth, const char *subject,
+                                             const char *cert_hash,
+                                             const struct wpabuf *cert)
+{
+       struct wpas_dbus_priv *iface;
+       DBusMessage *_signal = NULL;
+       const char *hash;
+       const char *cert_hex;
+       int cert_hex_len;
+
+       /* Do nothing if the control interface is not turned on */
+       if (wpa_s->global == NULL)
+               return;
+       iface = wpa_s->global->dbus;
+       if (iface == NULL)
+               return;
+
+       _signal = dbus_message_new_signal(wpa_s->dbus_path,
+                                         WPAS_DBUS_IFACE_INTERFACE,
+                                         "Certification");
+       if (_signal == NULL) {
+               wpa_printf(MSG_ERROR,
+                          "dbus: wpa_supplicant_dbus_notify_certification: "
+                          "Could not create dbus signal; likely out of "
+                          "memory");
+               return;
+       }
+
+       hash = cert_hash ? cert_hash : "";
+       cert_hex = cert ? wpabuf_head(cert) : "";
+       cert_hex_len = cert ? wpabuf_len(cert) : 0;
+
+       if (!dbus_message_append_args(_signal,
+                                     DBUS_TYPE_INT32,&depth,
+                                     DBUS_TYPE_STRING, &subject,
+                                     DBUS_TYPE_STRING, &hash,
+                                     DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+                                     &cert_hex, cert_hex_len,
+                                     DBUS_TYPE_INVALID)) {
+               wpa_printf(MSG_ERROR,
+                          "dbus: wpa_supplicant_dbus_notify_certification: "
+                          "Not enough memory to construct signal");
+               goto out;
+       }
+
+       dbus_connection_send(iface->con, _signal, NULL);
+
+out:
+       dbus_message_unref(_signal);
+
+}
+
 
 /**
  * wpa_supplicant_dbus_ctrl_iface_init - Initialize dbus control interface