dbus: Remove GroupMember object type and use Peer instead
[mech_eap.git] / wpa_supplicant / dbus / dbus_new.c
index e9bd51f..7823f3a 100644 (file)
@@ -709,9 +709,9 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
        DBusMessage *msg;
        DBusMessageIter iter, dict_iter;
        struct wpas_dbus_priv *iface;
-       char *auth_type[6]; /* we have six possible authorization types */
+       char *auth_type[5]; /* we have five possible authentication types */
        int at_num = 0;
-       char *encr_type[4]; /* we have four possible encryption types */
+       char *encr_type[3]; /* we have three possible encryption types */
        int et_num = 0;
 
        iface = wpa_s->global->dbus;
@@ -734,20 +734,15 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
                auth_type[at_num++] = "open";
        if (cred->auth_type & WPS_AUTH_WPAPSK)
                auth_type[at_num++] = "wpa-psk";
-       if (cred->auth_type & WPS_AUTH_SHARED)
-               auth_type[at_num++] = "shared";
        if (cred->auth_type & WPS_AUTH_WPA)
                auth_type[at_num++] = "wpa-eap";
        if (cred->auth_type & WPS_AUTH_WPA2)
                auth_type[at_num++] = "wpa2-eap";
        if (cred->auth_type & WPS_AUTH_WPA2PSK)
-               auth_type[at_num++] =
-               "wpa2-psk";
+               auth_type[at_num++] = "wpa2-psk";
 
        if (cred->encr_type & WPS_ENCR_NONE)
                encr_type[et_num++] = "none";
-       if (cred->encr_type & WPS_ENCR_WEP)
-               encr_type[et_num++] = "wep";
        if (cred->encr_type & WPS_ENCR_TKIP)
                encr_type[et_num++] = "tkip";
        if (cred->encr_type & WPS_ENCR_AES)
@@ -869,6 +864,76 @@ nomem:
 }
 
 
+/**
+ * wpas_dbus_signal_sta - Send a station related event signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @sta: station mac address
+ * @sig_name: signal name - StaAuthorized or StaDeauthorized
+ *
+ * Notify listeners about event related with station
+ */
+static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
+                                const u8 *sta, const char *sig_name)
+{
+       struct wpas_dbus_priv *iface;
+       DBusMessage *msg;
+       char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
+       char *dev_mac;
+
+       os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
+       dev_mac = sta_mac;
+
+       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, sig_name);
+       if (msg == NULL)
+               return;
+
+       if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
+                                    DBUS_TYPE_INVALID))
+               dbus_connection_send(iface->con, msg, NULL);
+       else
+               wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
+       dbus_message_unref(msg);
+
+       wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
+                  sta_mac, sig_name);
+}
+
+
+/**
+ * wpas_dbus_signal_sta_authorized - Send a STA authorized signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @sta: station mac address
+ *
+ * Notify listeners a new station has been authorized
+ */
+void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
+                                    const u8 *sta)
+{
+       wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
+}
+
+
+/**
+ * wpas_dbus_signal_sta_deauthorized - Send a STA deauthorized signal
+ * @wpa_s: %wpa_supplicant network interface data
+ * @sta: station mac address
+ *
+ * Notify listeners a station has been deauthorized
+ */
+void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
+                                      const u8 *sta)
+{
+       wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
+}
+
+
 #ifdef CONFIG_P2P
 
 /**
@@ -1104,7 +1169,6 @@ void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
        DBusMessage *msg;
        DBusMessageIter iter, dict_iter;
        struct wpas_dbus_priv *iface;
-       char group_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
 
        iface = wpa_s->parent->global->dbus;
 
@@ -1112,14 +1176,13 @@ void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
        if (iface == NULL)
                return;
 
-       if (wpas_dbus_get_group_obj_path(wpa_s, ssid, group_obj_path) < 0)
+       if (wpa_s->dbus_groupobj_path == NULL)
                return;
 
        /* New interface has been created for this group */
        msg = dbus_message_new_signal(wpa_s->parent->dbus_new_path,
                                      WPAS_DBUS_NEW_IFACE_P2PDEVICE,
                                      "GroupStarted");
-
        if (msg == NULL)
                return;
 
@@ -1142,7 +1205,7 @@ void wpas_dbus_signal_p2p_group_started(struct wpa_supplicant *wpa_s,
                goto nomem;
 
        if (!wpa_dbus_dict_append_object_path(&dict_iter, "group_object",
-                                            group_obj_path) ||
+                                             wpa_s->dbus_groupobj_path) ||
           !wpa_dbus_dict_close_write(&iter, &dict_iter))
                goto nomem;
 
@@ -1155,7 +1218,7 @@ nomem:
 
 /**
  *
- * Method to emit GONeogtiation Success or Failure signals based
+ * Method to emit GONegotiation Success or Failure signals based
  * on status.
  * @status: Status of the GO neg request. 0 for success, other for errors.
  */
@@ -1292,7 +1355,7 @@ void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
        DBusMessageIter iter, dict_iter;
        struct wpas_dbus_priv *iface;
 
-       wpa_printf(MSG_INFO, "%s\n", __func__);
+       wpa_printf(MSG_DEBUG, "%s", __func__);
 
        iface = wpa_s->global->dbus;
        /* Do nothing if the control interface is not turned on */
@@ -1335,15 +1398,15 @@ nomem:
  * constructed using p2p i/f addr used for connecting.
  *
  * @wpa_s: %wpa_supplicant network interface data
- * @member_addr: addr (p2p i/f) of the peer joining the group
+ * @peer_addr: P2P Device Address of the peer joining the group
  */
 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
-                                     const u8 *member)
+                                     const u8 *peer_addr)
 {
        struct wpas_dbus_priv *iface;
        DBusMessage *msg;
        DBusMessageIter iter;
-       char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
+       char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
 
        iface = wpa_s->global->dbus;
 
@@ -1354,10 +1417,10 @@ void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
        if (!wpa_s->dbus_groupobj_path)
                return;
 
-       os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
-                       "%s/"  WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
+       os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+                       "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
                        COMPACT_MACSTR,
-                       wpa_s->dbus_groupobj_path, MAC2STR(member));
+                       wpa_s->parent->dbus_new_path, MAC2STR(peer_addr));
 
        msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
                                      WPAS_DBUS_NEW_IFACE_P2P_GROUP,
@@ -1366,7 +1429,7 @@ void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
                return;
 
        dbus_message_iter_init_append(msg, &iter);
-       path = groupmember_obj_path;
+       path = peer_obj_path;
        if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
                                            &path))
                goto err;
@@ -1386,18 +1449,18 @@ err:
  *
  * Method to emit a signal for a peer disconnecting the group.
  * The signal will carry path to the group member object
- * constructed using p2p i/f addr used for connecting.
+ * constructed using the P2P Device Address of the peer.
  *
  * @wpa_s: %wpa_supplicant network interface data
- * @member_addr: addr (p2p i/f) of the peer joining the group
+ * @peer_addr: P2P Device Address of the peer joining the group
  */
 void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
-                                     const u8 *member)
+                                           const u8 *peer_addr)
 {
        struct wpas_dbus_priv *iface;
        DBusMessage *msg;
        DBusMessageIter iter;
-       char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
+       char peer_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
 
        iface = wpa_s->global->dbus;
 
@@ -1408,10 +1471,10 @@ void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
        if (!wpa_s->dbus_groupobj_path)
                return;
 
-       os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
-                       "%s/"  WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/"
+       os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
+                       "%s/" WPAS_DBUS_NEW_P2P_PEERS_PART "/"
                        COMPACT_MACSTR,
-                       wpa_s->dbus_groupobj_path, MAC2STR(member));
+                       wpa_s->dbus_groupobj_path, MAC2STR(peer_addr));
 
        msg = dbus_message_new_signal(wpa_s->dbus_groupobj_path,
                                      WPAS_DBUS_NEW_IFACE_P2P_GROUP,
@@ -1420,7 +1483,7 @@ void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
                return;
 
        dbus_message_iter_init_append(msg, &iter);
-       path = groupmember_obj_path;
+       path = peer_obj_path;
        if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
                                            &path))
                goto err;
@@ -1920,15 +1983,6 @@ static const struct wpa_dbus_method_desc wpas_dbus_global_methods[] = {
                  END_ARGS
          }
        },
-#ifdef CONFIG_AUTOSCAN
-       { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
-         (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
-         {
-                 { "arg", "s", ARG_IN },
-                 END_ARGS
-         }
-       },
-#endif /* CONFIG_AUTOSCAN */
        { NULL, NULL, NULL, { END_ARGS } }
 };
 
@@ -2401,6 +2455,12 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
                  END_ARGS
          }
        },
+       { "Reattach", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) &wpas_dbus_handler_reattach,
+         {
+                 END_ARGS
+         }
+       },
        { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
          (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
          {
@@ -2455,6 +2515,15 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
          }
        },
 #endif /* CONFIG_NO_CONFIG_BLOBS */
+       { "SetPKCS11EngineAndModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler)
+         &wpas_dbus_handler_set_pkcs11_engine_and_module_path,
+         {
+                 { "pkcs11_engine_path", "s", ARG_IN },
+                 { "pkcs11_module_path", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
 #ifdef CONFIG_WPS
        { "Start", WPAS_DBUS_NEW_IFACE_WPS,
          (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
@@ -2573,6 +2642,7 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
          (WPADBusMethodHandler)wpas_dbus_handler_p2p_service_sd_req,
          {
                  { "args", "a{sv}", ARG_IN },
+                 { "ref", "t", ARG_OUT },
                  END_ARGS
          }
        },
@@ -2603,13 +2673,6 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
                  END_ARGS
          }
        },
-       { "ServiceDiscoveryExternal", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
-         (WPADBusMethodHandler)wpas_dbus_handler_p2p_serv_disc_external,
-         {
-                 { "arg", "i", ARG_IN },
-                 END_ARGS
-         }
-       },
        { "AddPersistentGroup", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
          (WPADBusMethodHandler) wpas_dbus_handler_add_persistent_group,
          {
@@ -2666,6 +2729,46 @@ static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
                  END_ARGS
          }
        },
+#ifdef CONFIG_AUTOSCAN
+       { "AutoScan", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) &wpas_dbus_handler_autoscan,
+         {
+                 { "arg", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
+#endif /* CONFIG_AUTOSCAN */
+#ifdef CONFIG_TDLS
+       { "TDLSDiscover", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_tdls_discover,
+         {
+                 { "peer_address", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
+       { "TDLSSetup", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_tdls_setup,
+         {
+                 { "peer_address", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
+       { "TDLSStatus", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_tdls_status,
+         {
+                 { "peer_address", "s", ARG_IN },
+                 { "status", "s", ARG_OUT },
+                 END_ARGS
+         }
+       },
+       { "TDLSTeardown", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         (WPADBusMethodHandler) wpas_dbus_handler_tdls_teardown,
+         {
+                 { "peer_address", "s", ARG_IN },
+                 END_ARGS
+         }
+       },
+#endif /* CONFIG_TDLS */
        { NULL, NULL, NULL, { END_ARGS } }
 };
 
@@ -2742,6 +2845,14 @@ static const struct wpa_dbus_property_desc wpas_dbus_interface_properties[] = {
          wpas_dbus_getter_scan_interval,
          wpas_dbus_setter_scan_interval
        },
+       { "PKCS11EnginePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+         wpas_dbus_getter_pkcs11_engine_path,
+         NULL
+       },
+       { "PKCS11ModulePath", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
+         wpas_dbus_getter_pkcs11_module_path,
+         NULL
+       },
 #ifdef CONFIG_WPS
        { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
          wpas_dbus_getter_process_credentials,
@@ -2871,7 +2982,6 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
        { "DeviceFound", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
          {
                  { "path", "o", ARG_OUT },
-                 { "properties", "a{sv}", ARG_OUT },
                  END_ARGS
          }
        },
@@ -2934,12 +3044,13 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
        },
        { "GONegotiationSuccess", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
          {
+                 { "properties", "a{sv}", ARG_OUT },
                  END_ARGS
          }
        },
        { "GONegotiationFailure", WPAS_DBUS_NEW_IFACE_P2PDEVICE,
          {
-                 { "status", "i", ARG_OUT },
+                 { "properties", "a{sv}", ARG_OUT },
                  END_ARGS
          }
        },
@@ -3017,6 +3128,18 @@ static const struct wpa_dbus_signal_desc wpas_dbus_interface_signals[] = {
                  END_ARGS
          }
        },
+       { "StaAuthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         {
+                 { "name", "s", ARG_OUT },
+                 END_ARGS
+         }
+       },
+       { "StaDeauthorized", WPAS_DBUS_NEW_IFACE_INTERFACE,
+         {
+                 { "name", "s", ARG_OUT },
+                 END_ARGS
+         }
+       },
        { NULL, NULL, { END_ARGS } }
 };
 
@@ -3144,6 +3267,14 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = {
          wpas_dbus_getter_p2p_peer_ies,
          NULL
        },
+       { "DeviceAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay",
+         wpas_dbus_getter_p2p_peer_device_address,
+         NULL
+       },
+       { "Groups", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ao",
+         wpas_dbus_getter_p2p_peer_groups,
+         NULL
+       },
        { NULL, NULL, NULL, NULL, NULL }
 };
 
@@ -3488,109 +3619,6 @@ void wpas_dbus_unregister_p2p_group(struct wpa_supplicant *wpa_s,
 }
 
 static const struct wpa_dbus_property_desc
-wpas_dbus_p2p_groupmember_properties[] = {
-       { NULL, NULL, NULL, NULL, NULL }
-};
-
-/**
- * wpas_dbus_register_p2p_groupmember - Register a p2p groupmember
- * object with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @p2p_if_addr: i/f addr of the device joining this group
- *
- * Registers p2p groupmember representing object with dbus
- */
-void wpas_dbus_register_p2p_groupmember(struct wpa_supplicant *wpa_s,
-                                       const u8 *p2p_if_addr)
-{
-       struct wpas_dbus_priv *ctrl_iface;
-       struct wpa_dbus_object_desc *obj_desc = NULL;
-       struct groupmember_handler_args *arg;
-       char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
-
-       /* Do nothing if the control interface is not turned on */
-       if (wpa_s == NULL || wpa_s->global == NULL)
-               return;
-
-       ctrl_iface = wpa_s->global->dbus;
-       if (ctrl_iface == NULL)
-               return;
-
-       if (!wpa_s->dbus_groupobj_path)
-               return;
-
-       os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
-               "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
-               wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
-
-       obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
-       if (!obj_desc) {
-               wpa_printf(MSG_ERROR, "Not enough memory "
-                          "to create object description");
-               goto err;
-       }
-
-       /* allocate memory for handlers arguments */
-       arg = os_zalloc(sizeof(struct groupmember_handler_args));
-       if (!arg) {
-               wpa_printf(MSG_ERROR, "Not enough memory "
-                          "to create arguments for method");
-               goto err;
-       }
-
-       arg->wpa_s = wpa_s;
-       os_memcpy(arg->member_addr, p2p_if_addr, ETH_ALEN);
-
-       wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
-                          wpas_dbus_p2p_groupmember_properties, NULL);
-
-       if (wpa_dbus_register_object_per_iface(ctrl_iface, groupmember_obj_path,
-                                              wpa_s->ifname, obj_desc))
-               goto err;
-
-       wpa_printf(MSG_INFO,
-                  "dbus: Registered group member object '%s' successfully",
-                  groupmember_obj_path);
-       return;
-
-err:
-       free_dbus_object_desc(obj_desc);
-}
-
-/**
- * wpas_dbus_unregister_p2p_groupmember - Unregister a p2p groupmember
- * object with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @p2p_if_addr: i/f addr of the device joining this group
- *
- * Unregisters p2p groupmember representing object with dbus
- */
-void wpas_dbus_unregister_p2p_groupmember(struct wpa_supplicant *wpa_s,
-                                         const u8 *p2p_if_addr)
-{
-       struct wpas_dbus_priv *ctrl_iface;
-       char groupmember_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
-
-       /* Do nothing if the control interface is not turned on */
-       if (wpa_s == NULL || wpa_s->global == NULL)
-               return;
-
-       ctrl_iface = wpa_s->global->dbus;
-       if (ctrl_iface == NULL)
-               return;
-
-       if (!wpa_s->dbus_groupobj_path)
-               return;
-
-       os_snprintf(groupmember_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
-               "%s/" WPAS_DBUS_NEW_P2P_GROUPMEMBERS_PART "/" COMPACT_MACSTR,
-               wpa_s->dbus_groupobj_path, MAC2STR(p2p_if_addr));
-
-       wpa_dbus_unregister_object_per_iface(ctrl_iface, groupmember_obj_path);
-}
-
-
-static const struct wpa_dbus_property_desc
        wpas_dbus_persistent_group_properties[] = {
        { "Properties", WPAS_DBUS_NEW_IFACE_PERSISTENT_GROUP, "a{sv}",
          wpas_dbus_getter_persistent_group_properties,