/** * wpas_dbus_ctrl_iface_init - Initialize dbus control interface * @global: Pointer to global data from wpa_supplicant_init() * Returns: 0 on success or -1 on failure * * Initialize the dbus control interface for wpa_supplicantand and start * receiving commands from external programs over the bus. */ int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv) { struct wpa_dbus_object_desc *obj_desc; int ret; obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc)); if (!obj_desc) { wpa_printf(MSG_ERROR, "Not enough memory " "to create object description"); return -1; } wpas_dbus_register(obj_desc, priv->global, NULL, wpas_dbus_global_methods, wpas_dbus_global_properties, wpas_dbus_global_signals); wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'", WPAS_DBUS_NEW_PATH); ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH, WPAS_DBUS_NEW_SERVICE, obj_desc); if (ret < 0) free_dbus_object_desc(obj_desc); else priv->dbus_new_initialized = 1; return ret; }
/** * wpas_dbus_register_bss - Register a scanned BSS with dbus * @wpa_s: wpa_supplicant interface structure * @bssid: scanned network bssid * @id: unique BSS identifier * Returns: 0 on success, -1 on failure * * Registers BSS representing object with dbus */ int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s, u8 bssid[ETH_ALEN], unsigned int id) { struct wpas_dbus_priv *ctrl_iface; struct wpa_dbus_object_desc *obj_desc; char bss_obj_path[WPAS_DBUS_OBJECT_PATH_MAX]; struct bss_handler_args *arg; /* Do nothing if the control interface is not turned on */ if (wpa_s == NULL || wpa_s->global == NULL) return 0; ctrl_iface = wpa_s->global->dbus; if (ctrl_iface == NULL) return 0; os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u", wpa_s->dbus_new_path, id); 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; } arg = os_zalloc(sizeof(struct bss_handler_args)); if (!arg) { wpa_printf(MSG_ERROR, "Not enough memory " "to create arguments for handler"); goto err; } arg->wpa_s = wpa_s; arg->id = id; wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL, wpas_dbus_bss_properties, wpas_dbus_bss_signals); wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'", bss_obj_path); if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path, wpa_s->ifname, obj_desc)) { wpa_printf(MSG_ERROR, "Cannot register BSSID dbus object %s.", bss_obj_path); goto err; } wpas_dbus_signal_bss_added(wpa_s, bss_obj_path); wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSSS); return 0; err: free_dbus_object_desc(obj_desc); return -1; }
/** * wpas_dbus_register_network - Register a configured network with dbus * @wpa_s: wpa_supplicant interface structure * @ssid: network configuration data * Returns: 0 on success, -1 on failure * * Registers network representing object with dbus */ int wpas_dbus_register_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) { struct wpas_dbus_priv *ctrl_iface; struct wpa_dbus_object_desc *obj_desc; struct network_handler_args *arg; char net_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 0; ctrl_iface = wpa_s->global->dbus; if (ctrl_iface == NULL) return 0; os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", wpa_s->dbus_new_path, ssid->id); wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'", net_obj_path); 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 network_handler_args)); if (!arg) { wpa_printf(MSG_ERROR, "Not enough memory " "to create arguments for method"); goto err; } arg->wpa_s = wpa_s; arg->ssid = ssid; wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL, wpas_dbus_network_properties, wpas_dbus_network_signals); if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path, wpa_s->ifname, obj_desc)) goto err; wpas_dbus_signal_network_added(wpa_s, ssid->id); return 0; err: free_dbus_object_desc(obj_desc); return -1; }
int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s) { struct wpa_dbus_object_desc *obj_desc = NULL; struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus; int next; /* Do nothing if the control interface is not turned on */ if (ctrl_iface == NULL) return 0; /* Create and set the interface's object path */ wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX); if (wpa_s->dbus_new_path == NULL) return -1; next = ctrl_iface->next_objid++; os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX, WPAS_DBUS_NEW_PATH_INTERFACES "/%u", next); 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; } wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods, wpas_dbus_interface_properties, wpas_dbus_interface_signals); wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'", wpa_s->dbus_new_path); if (wpa_dbus_register_object_per_iface(ctrl_iface, wpa_s->dbus_new_path, wpa_s->ifname, obj_desc)) goto err; wpas_dbus_signal_interface_added(wpa_s); return 0; err: os_free(wpa_s->dbus_new_path); wpa_s->dbus_new_path = NULL; free_dbus_object_desc(obj_desc); return -1; }
static void free_dbus_object_desc_cb(DBusConnection *connection, void *obj_dsc) { free_dbus_object_desc(obj_dsc); }