wpa_supplicant: Report EAP connection progress to DBus
[mech_eap.git] / wpa_supplicant / dbus / dbus_new.c
index a240649..f7393d9 100644 (file)
 #include "dbus_new_handlers_p2p.h"
 #include "p2p/p2p.h"
 
+#ifdef CONFIG_AP /* until needed by something else */
+
+/*
+ * NameOwnerChanged handling
+ *
+ * Some services we provide allow an application to register for
+ * a signal that it needs. While it can also unregister, we must
+ * be prepared for the case where the application simply crashes
+ * and thus doesn't clean up properly. The way to handle this in
+ * DBus is to register for the NameOwnerChanged signal which will
+ * signal an owner change to NULL if the peer closes the socket
+ * for whatever reason.
+ *
+ * Handle this signal via a filter function whenever necessary.
+ * The code below also handles refcounting in case in the future
+ * there will be multiple instances of this subscription scheme.
+ */
+static const char wpas_dbus_noc_filter_str[] =
+       "interface=org.freedesktop.DBus,member=NameOwnerChanged";
+
+
+static DBusHandlerResult noc_filter(DBusConnection *conn,
+                                   DBusMessage *message, void *data)
+{
+       struct wpas_dbus_priv *priv = data;
+
+       if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+       if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
+                                  "NameOwnerChanged")) {
+               const char *name;
+               const char *prev_owner;
+               const char *new_owner;
+               DBusError derr;
+               struct wpa_supplicant *wpa_s;
+
+               dbus_error_init(&derr);
+
+               if (!dbus_message_get_args(message, &derr,
+                                          DBUS_TYPE_STRING, &name,
+                                          DBUS_TYPE_STRING, &prev_owner,
+                                          DBUS_TYPE_STRING, &new_owner,
+                                          DBUS_TYPE_INVALID)) {
+                       /* Ignore this error */
+                       dbus_error_free(&derr);
+                       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               }
+
+               for (wpa_s = priv->global->ifaces; wpa_s; wpa_s = wpa_s->next)
+               {
+                       if (wpa_s->preq_notify_peer != NULL &&
+                           os_strcmp(name, wpa_s->preq_notify_peer) == 0 &&
+                           (new_owner == NULL || os_strlen(new_owner) == 0)) {
+                               /* probe request owner disconnected */
+                               os_free(wpa_s->preq_notify_peer);
+                               wpa_s->preq_notify_peer = NULL;
+                               wpas_dbus_unsubscribe_noc(priv);
+                       }
+               }
+       }
+
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+
+void wpas_dbus_subscribe_noc(struct wpas_dbus_priv *priv)
+{
+       priv->dbus_noc_refcnt++;
+       if (priv->dbus_noc_refcnt > 1)
+               return;
+
+       if (!dbus_connection_add_filter(priv->con, noc_filter, priv, NULL)) {
+               wpa_printf(MSG_ERROR, "dbus: failed to add filter");
+               return;
+       }
+
+       dbus_bus_add_match(priv->con, wpas_dbus_noc_filter_str, NULL);
+}
+
+
+void wpas_dbus_unsubscribe_noc(struct wpas_dbus_priv *priv)
+{
+       priv->dbus_noc_refcnt--;
+       if (priv->dbus_noc_refcnt > 0)
+               return;
+
+       dbus_bus_remove_match(priv->con, wpas_dbus_noc_filter_str, NULL);
+       dbus_connection_remove_filter(priv->con, noc_filter, priv);
+}
+
+#endif /* CONFIG_AP */
+
 
 /**
  * wpas_dbus_signal_interface - Send a interface related event signal
@@ -747,6 +840,41 @@ nomem:
        dbus_message_unref(msg);
 }
 
+
+void wpas_dbus_signal_eap_status(struct wpa_supplicant *wpa_s,
+                                const char *status, const char *parameter)
+{
+       struct wpas_dbus_priv *iface;
+       DBusMessage *msg;
+       DBusMessageIter iter;
+
+       iface = wpa_s->global->dbus;
+
+       /* Do nothing if the control interface is not turned on */
+       if (iface == NULL)
+               return;
+
+       msg = dbus_message_new_signal(wpa_s->dbus_new_path,
+                                     WPAS_DBUS_NEW_IFACE_INTERFACE,
+                                     "EAP");
+       if (msg == NULL)
+               return;
+
+       dbus_message_iter_init_append(msg, &iter);
+
+       if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &status)
+           ||
+           !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+                                           &parameter))
+               goto nomem;
+
+       dbus_connection_send(iface->con, msg, NULL);
+
+nomem:
+       dbus_message_unref(msg);
+}
+
+
 #ifdef CONFIG_P2P
 
 /**
@@ -953,7 +1081,7 @@ static int wpas_dbus_get_group_obj_path(struct wpa_supplicant *wpa_s,
        if (os_memcmp(ssid->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN))
                return -1;
 
-       memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
+       os_memcpy(group_name, ssid->ssid + P2P_WILDCARD_SSID_LEN, 2);
        group_name[2] = '\0';
 
        os_snprintf(group_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
@@ -2029,11 +2157,11 @@ int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
        struct wpas_dbus_priv *ctrl_iface;
        char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
        int ret;
+#ifdef CONFIG_P2P
        struct wpa_ssid *ssid;
 
        ssid = wpa_config_get_network(wpa_s->conf, nid);
 
-#ifdef CONFIG_P2P
        /* If it is a persistent group unregister it as such */
        if (ssid && network_is_persistent_group(ssid))
                return wpas_dbus_unregister_persistent_group(wpa_s, nid);
@@ -2487,6 +2615,20 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
                  END_ARGS
          }
        },
+#ifdef CONFIG_AP
+       { "SubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_subscribe_preq,
+         {
+                 END_ARGS
+         }
+       },
+       { "UnsubscribeProbeReq", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_unsubscribe_preq,
+         {
+                 END_ARGS
+         }
+       },
+#endif /* CONFIG_AP */
        { NULL, NULL, NULL, { END_ARGS } }
 };
 
@@ -2559,6 +2701,10 @@ static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
          wpas_dbus_getter_fast_reauth,
          wpas_dbus_setter_fast_reauth
        },
+       { "ScanInterval", WPAS_DBUS_NEW_IFACE_INTERFACE, "i",
+         wpas_dbus_getter_scan_interval,
+         wpas_dbus_setter_scan_interval
+       },
 #ifdef CONFIG_WPS
        { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
          wpas_dbus_getter_process_credentials,
@@ -2566,9 +2712,9 @@ static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
        },
 #endif /* CONFIG_WPS */
 #ifdef CONFIG_P2P
-       { "P2PDeviceProperties", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
-         wpas_dbus_getter_p2p_device_properties,
-         wpas_dbus_setter_p2p_device_properties
+       { "P2PDeviceConfig", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "a{sv}",
+         wpas_dbus_getter_p2p_device_config,
+         wpas_dbus_setter_p2p_device_config
        },
        { "Peers", WPAS_DBUS_NEW_IFACE_P2PDEVICE, "ao",
          wpas_dbus_getter_p2p_peers,
@@ -2809,12 +2955,27 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
          }
        },
 #endif /* CONFIG_P2P */
+#ifdef CONFIG_AP
+       { "ProbeRequest", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         {
+                 { "args", "a{sv}", ARG_OUT },
+                 END_ARGS
+         }
+       },
+#endif /* CONFIG_AP */
        { "Certification", WPAS_DBUS_NEW_IFACE_INTERFACE,
          {
                  { "certification", "a{sv}", ARG_OUT },
                  END_ARGS
          }
        },
+       { "EAP", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         {
+                 { "status", "s", ARG_OUT },
+                 { "parameter", "s", ARG_OUT },
+                 END_ARGS
+         }
+       },
        { NULL, NULL, { END_ARGS } }
 };
 
@@ -2882,6 +3043,15 @@ int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
 
        wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
                   wpa_s->dbus_new_path);
+
+#ifdef CONFIG_AP
+       if (wpa_s->preq_notify_peer) {
+               wpas_dbus_unsubscribe_noc(ctrl_iface);
+               os_free(wpa_s->preq_notify_peer);
+               wpa_s->preq_notify_peer = NULL;
+       }
+#endif /* CONFIG_AP */
+
        if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
                                                 wpa_s->dbus_new_path))
                return -1;
@@ -3126,10 +3296,37 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_group_properties[] = {
          wpas_dbus_getter_p2p_group_members,
          NULL
        },
-       { "Properties",
-         WPAS_DBUS_NEW_IFACE_P2P_GROUP, "a{sv}",
-         wpas_dbus_getter_p2p_group_properties,
-         wpas_dbus_setter_p2p_group_properties
+       { "Group", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "o",
+         wpas_dbus_getter_p2p_group,
+         NULL
+       },
+       { "Role", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
+         wpas_dbus_getter_p2p_role,
+         NULL
+       },
+       { "SSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
+         wpas_dbus_getter_p2p_group_ssid,
+         NULL
+       },
+       { "BSSID", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
+         wpas_dbus_getter_p2p_group_bssid,
+         NULL
+       },
+       { "Frequency", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "q",
+         wpas_dbus_getter_p2p_group_frequency,
+         NULL
+       },
+       { "Passphrase", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "s",
+         wpas_dbus_getter_p2p_group_passphrase,
+         NULL
+       },
+       { "PSK", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "ay",
+         wpas_dbus_getter_p2p_group_psk,
+         NULL
+       },
+       { "WPSVendorExtensions", WPAS_DBUS_NEW_IFACE_P2P_GROUP, "aay",
+         wpas_dbus_getter_p2p_group_vendor_ext,
+         wpas_dbus_setter_p2p_group_vendor_ext
        },
        { NULL, NULL, NULL, NULL, NULL }
 };
@@ -3251,10 +3448,6 @@ void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
 
 static const struct wpa_dbus_property_desc
 wpas_dbus_p2p_groupmember_properties[] = {
-       { "Properties", WPAS_DBUS_NEW_IFACE_P2P_GROUPMEMBER, "a{sv}",
-         wpas_dbus_getter_p2p_group_properties,
-         NULL
-       },
        { NULL, NULL, NULL, NULL, NULL }
 };