void nm_supplicant_manager_iface_release (NMSupplicantManager *self, NMSupplicantInterface *iface) { NMSupplicantManagerPrivate *priv; const char *ifname, *op; g_return_if_fail (NM_IS_SUPPLICANT_MANAGER (self)); g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (iface)); ifname = nm_supplicant_interface_get_ifname (iface); g_assert (ifname); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); g_return_if_fail (g_hash_table_lookup (priv->ifaces, ifname) == iface); /* Ask wpa_supplicant to remove this interface */ op = nm_supplicant_interface_get_object_path (iface); if (priv->running && priv->proxy && op) { g_dbus_proxy_call (priv->proxy, "RemoveInterface", g_variant_new ("(o)", op), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL, NULL); } g_hash_table_remove (priv->ifaces, ifname); }
NMSupplicantInterface * nm_supplicant_interface_new (NMSupplicantManager *smgr, const char *ifname, gboolean is_wireless, gboolean start_now) { NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; guint id; g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (smgr), NULL); g_return_val_if_fail (ifname != NULL, NULL); self = g_object_new (NM_TYPE_SUPPLICANT_INTERFACE, NULL); if (self) { priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); priv->smgr = g_object_ref (smgr); id = g_signal_connect (priv->smgr, "notify::" NM_SUPPLICANT_MANAGER_AVAILABLE, G_CALLBACK (smgr_avail_cb), self); priv->smgr_avail_id = id; priv->dev = g_strdup (ifname); priv->is_wireless = is_wireless; if (start_now) interface_add (self, priv->is_wireless); } return self; }
void nm_supplicant_manager_iface_release (NMSupplicantManager *self, NMSupplicantInterface *iface) { NMSupplicantManagerPrivate *priv; const char *ifname, *op; g_return_if_fail (NM_IS_SUPPLICANT_MANAGER (self)); g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (iface)); ifname = nm_supplicant_interface_get_ifname (iface); g_assert (ifname); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); g_return_if_fail (g_hash_table_lookup (priv->ifaces, ifname) == iface); /* Ask wpa_supplicant to remove this interface */ op = nm_supplicant_interface_get_object_path (iface); if (priv->running && priv->proxy && op) { dbus_g_proxy_call_no_reply (priv->proxy, "RemoveInterface", DBUS_TYPE_G_OBJECT_PATH, op, G_TYPE_INVALID); } g_hash_table_remove (priv->ifaces, ifname); }
NMSupplicantInterface * nm_supplicant_manager_iface_get (NMSupplicantManager * self, const char *ifname, gboolean is_wireless) { NMSupplicantManagerPrivate *priv; NMSupplicantInterface *iface = NULL; gboolean start_now; g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), NULL); g_return_val_if_fail (ifname != NULL, NULL); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); iface = g_hash_table_lookup (priv->ifaces, ifname); if (!iface) { /* If we're making the supplicant take a time out for a bit, don't * let the supplicant interface start immediately, just let it hang * around in INIT state until we're ready to talk to the supplicant * again. */ start_now = !die_count_exceeded (priv->die_count); nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname); iface = nm_supplicant_interface_new (self, ifname, is_wireless, start_now); if (iface) g_hash_table_insert (priv->ifaces, g_strdup (ifname), iface); } else { nm_log_dbg (LOGD_SUPPLICANT, "(%s): returning existing supplicant interface", ifname); } return iface; }
static gboolean is_available (NMSupplicantManager *self) { g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), FALSE); if (die_count_exceeded (NM_SUPPLICANT_MANAGER_GET_PRIVATE (self)->die_count)) return FALSE; return NM_SUPPLICANT_MANAGER_GET_PRIVATE (self)->running; }
NMSupplicantInterface * nm_supplicant_interface_new (NMSupplicantManager * smgr, const char *ifname, gboolean is_wireless) { NMSupplicantInterface * iface; g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (smgr), NULL); g_return_val_if_fail (ifname != NULL, NULL); iface = g_object_new (NM_TYPE_SUPPLICANT_INTERFACE, "supplicant-manager", smgr, "device", ifname, NULL); if (iface) { NM_SUPPLICANT_INTERFACE_GET_PRIVATE (iface)->is_wireless = is_wireless; nm_supplicant_interface_start (iface); } return iface; }
/** * nm_supplicant_manager_create_interface: * @self: the #NMSupplicantManager * @ifname: the interface for which to obtain the supplicant interface * @is_wireless: whether the interface is supposed to be wireless. * * Note: the manager owns a reference to the instance and the only way to * get the manager to release it, is by dropping all other references * to the supplicant-interface (or destroying the manager). * * Retruns: (transfer-full): returns a #NMSupplicantInterface or %NULL. * Must be unrefed at the end. * */ NMSupplicantInterface * nm_supplicant_manager_create_interface (NMSupplicantManager *self, const char *ifname, gboolean is_wireless) { NMSupplicantManagerPrivate *priv; NMSupplicantInterface *iface; GSList *ifaces; g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), NULL); g_return_val_if_fail (ifname != NULL, NULL); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname); /* assert against not requesting duplicate interfaces. */ for (ifaces = priv->ifaces; ifaces; ifaces = ifaces->next) { if (g_strcmp0 (nm_supplicant_interface_get_ifname (ifaces->data), ifname) == 0) g_return_val_if_reached (NULL); } iface = nm_supplicant_interface_new (ifname, is_wireless, priv->fast_supported, priv->ap_support); priv->ifaces = g_slist_prepend (priv->ifaces, iface); g_object_add_toggle_ref ((GObject *) iface, _sup_iface_last_ref, self); /* If we're making the supplicant take a time out for a bit, don't * let the supplicant interface start immediately, just let it hang * around in INIT state until we're ready to talk to the supplicant * again. */ if (is_available (self)) nm_supplicant_interface_set_supplicant_available (iface, TRUE); return iface; }
static void _sup_iface_last_ref (gpointer data, GObject *object, gboolean is_last_ref) { NMSupplicantManager *self = data; NMSupplicantManagerPrivate *priv; NMSupplicantInterface *sup_iface = (NMSupplicantInterface *) object; const char *op; g_return_if_fail (NM_IS_SUPPLICANT_MANAGER (self)); g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (sup_iface)); g_return_if_fail (is_last_ref); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); if (!g_slist_find (priv->ifaces, sup_iface)) g_return_if_reached (); /* Ask wpa_supplicant to remove this interface */ if ( priv->running && priv->proxy && (op = nm_supplicant_interface_get_object_path (sup_iface))) { g_dbus_proxy_call (priv->proxy, "RemoveInterface", g_variant_new ("(o)", op), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL, NULL); } priv->ifaces = g_slist_remove (priv->ifaces, sup_iface); g_object_remove_toggle_ref ((GObject *) sup_iface, _sup_iface_last_ref, self); }