From 37fa2d08a44dea243b10baadc55259c02e821eb8 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 27 Jan 2005 20:14:12 +0000 Subject: [PATCH] 2005-01-27 Dan Williams * info-daemon/NetworkManagerInfoDbus.c - (nmi_dbus_add_network_address): if the network doesn't yet exist in GConf, make a minimal entry for it (essid & timestamp) * src/NetworkManagerAPList.c - (nm_ap_list_populate_from_nmi): Don't try to grab network data if NetworkManagerInfo isn't running * src/NetworkManagerDbus.[ch] - (nm_dbus_nmi_is_running): new function * src/NetworkManagerDevice.c - (nm_device_wireless_force_use): Don't set the created AP's MAC address to garbage. * src/NetworkManagerPolicy.c - (nm_policy_activation_finish): On successful activation, make sure the "best" AP has a MAC address, and don't tell NMI to add the current AP's MAC address to GConf if the AP is an Ad-hoc AP. - (nm_policy_allowed_ap_list_update): Update a wireless card's "best" access point after refreshing our allowed list if it doesn't already have a "best" access point. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@400 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 25 +++++++++++++++++++ info-daemon/NetworkManagerInfoDbus.c | 27 +++++++++++++++++---- src/NetworkManagerAPList.c | 4 ++++ src/NetworkManagerDbus.c | 21 ++++++++++++++++ src/NetworkManagerDbus.h | 2 ++ src/NetworkManagerDevice.c | 4 +--- src/NetworkManagerPolicy.c | 36 ++++++++++++++++++++++++---- 7 files changed, 108 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31827b91d..2718fee6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2005-01-27 Dan Williams + + * info-daemon/NetworkManagerInfoDbus.c + - (nmi_dbus_add_network_address): if the network doesn't yet exist in + GConf, make a minimal entry for it (essid & timestamp) + + * src/NetworkManagerAPList.c + - (nm_ap_list_populate_from_nmi): Don't try to grab network data if + NetworkManagerInfo isn't running + + * src/NetworkManagerDbus.[ch] + - (nm_dbus_nmi_is_running): new function + + * src/NetworkManagerDevice.c + - (nm_device_wireless_force_use): Don't set the created AP's MAC + address to garbage. + + * src/NetworkManagerPolicy.c + - (nm_policy_activation_finish): On successful activation, make sure + the "best" AP has a MAC address, and don't tell NMI to add the + current AP's MAC address to GConf if the AP is an Ad-hoc AP. + - (nm_policy_allowed_ap_list_update): Update a wireless card's "best" + access point after refreshing our allowed list if it doesn't already + have a "best" access point. + 2005-01-25 Dan Williams * panel-applet/NMWirelessAppletDbus.c diff --git a/info-daemon/NetworkManagerInfoDbus.c b/info-daemon/NetworkManagerInfoDbus.c index d1e17e529..6b8a919c2 100644 --- a/info-daemon/NetworkManagerInfoDbus.c +++ b/info-daemon/NetworkManagerInfoDbus.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "NetworkManagerInfo.h" #include "NetworkManagerInfoDbus.h" @@ -580,12 +581,29 @@ static DBusMessage *nmi_dbus_add_network_address (NMIAppInfo *info, DBusMessage return (reply_message); } - /* Grab user-key key for our access point from GConf */ + /* Force-set the essid too so that we have a semi-complete network entry */ escaped_network = gconf_escape_key (network, strlen (network)); - key = g_strdup_printf ("%s/%s/addresses", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); - g_free (escaped_network); + key = g_strdup_printf ("%s/%s/essid", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); value = gconf_client_get (info->gconf_client, key, NULL); + /* If the network doesn't already exist in GConf, add it and set its timestamp to now. */ + if (!value || (!value && (value->type == GCONF_VALUE_STRING))) + { + /* Set the essid of the network. */ + gconf_client_set_string (info->gconf_client, key, network, NULL); + g_free (key); + + /* Update timestamp on network */ + key = g_strdup_printf ("%s/%s/timestamp", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); + gconf_client_set_int (info->gconf_client, key, time (NULL), NULL); + } + g_free (key); + + /* Get current list of access point MAC addresses for this AP from GConf */ + key = g_strdup_printf ("%s/%s/addresses", NMI_GCONF_WIRELESS_NETWORKS_PATH, escaped_network); + value = gconf_client_get (info->gconf_client, key, NULL); + g_free (escaped_network); + if (value && (value->type == GCONF_VALUE_LIST) && (gconf_value_get_list_type (value) == GCONF_VALUE_STRING)) { GSList *elem; @@ -671,6 +689,7 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio GtkDialog *dialog; char *text; + dbus_error_free (&error); text = g_strdup_printf ( "The requested wireless network '%s' does not appear to be in range. " "A different wireless network will be used if any are available.", network); dbus_free (network); @@ -678,7 +697,6 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio dialog = GTK_DIALOG (gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, text, NULL)); gtk_dialog_run (dialog); gtk_widget_destroy (GTK_WIDGET (dialog)); - dbus_error_free (&error); } } else if (strcmp ("getNetworks", method) == 0) @@ -790,6 +808,7 @@ static gboolean nmi_dbus_nm_is_running (DBusConnection *connection) return (exists); } + /* * nmi_dbus_service_init * diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index bf46dac72..9844bcb3e 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -347,6 +347,10 @@ void nm_ap_list_populate_from_nmi (NMAccessPointList *list, NMData *data) g_return_if_fail (data != NULL); g_return_if_fail (list->type == NETWORK_TYPE_ALLOWED); + /* If NMI isn't running, don't try to talk to it. */ + if (!nm_dbus_nmi_is_running (data->dbus_connection)) + return; + networks = nm_dbus_get_networks (data->dbus_connection, list->type, &num_networks); if (networks && (num_networks > 0)) { diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index d3889a874..dfb2ba9a0 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -1124,6 +1124,27 @@ char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, in } +/* + * nm_dbus_nmi_is_running + * + * Ask dbus whether or not NetworkManagerInfo is running + * + */ +gboolean nm_dbus_nmi_is_running (DBusConnection *connection) +{ + DBusError error; + gboolean exists; + + g_return_val_if_fail (connection != NULL, FALSE); + + dbus_error_init (&error); + exists = dbus_bus_service_exists (connection, NMI_DBUS_SERVICE, &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (exists); +} + + /* * nm_dbus_nmi_filter * diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h index aa16d4358..bd84587bd 100644 --- a/src/NetworkManagerDbus.h +++ b/src/NetworkManagerDbus.h @@ -66,6 +66,8 @@ gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkTy gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const char *network, const NMDeviceAuthMethod auth_method); +gboolean nm_dbus_nmi_is_running (DBusConnection *connection); + char ** nm_dbus_get_networks (DBusConnection *connection, NMNetworkType type, int *num_networks); #endif diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index c642cbfb5..ec7f3e695 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -2945,7 +2945,6 @@ typedef struct NMDeviceForceData static gboolean nm_device_wireless_force_use (NMDevice *dev, const char *essid, const char *key, NMEncKeyType key_type) { - struct ether_addr ap_addr; gboolean encrypted = FALSE; NMAccessPoint *ap = NULL; NMAccessPoint *tmp_ap = NULL; @@ -2982,7 +2981,6 @@ static gboolean nm_device_wireless_force_use (NMDevice *dev, const char *essid, else nm_ap_set_auth_method (ap, NM_DEVICE_AUTH_METHOD_NONE); nm_ap_set_artificial (ap, TRUE); - nm_ap_set_address (ap, &ap_addr); nm_ap_list_append_ap (nm_device_ap_list_get (dev), ap); nm_ap_unref (ap); } @@ -3192,7 +3190,7 @@ static void nm_device_fake_ap_list (NMDevice *dev) nm_ap_set_strength (nm_ap, fake_qualities[i]); nm_ap_set_freq (nm_ap, fake_freqs[i]); - /* Merge settings from wireless networks, mainly Keys */ + /* Merge settings from wireless networks, mainly keys */ if ((list_ap = nm_ap_list_get_ap_by_essid (dev->app_data->allowed_ap_list, nm_ap_get_essid (nm_ap)))) { nm_ap_set_timestamp (nm_ap, nm_ap_get_timestamp (list_ap)); diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index e603ad769..c841e7819 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -249,10 +249,22 @@ gboolean nm_policy_activation_finish (gpointer user_data) /* Tell NetworkManagerInfo to store the MAC address of the active device's AP */ if (nm_device_is_wireless (dev)) { - struct ether_addr addr; + NMAccessPoint *ap = NULL; - nm_device_get_ap_address (dev, &addr); - nm_dbus_add_network_address (data->dbus_connection, NETWORK_TYPE_ALLOWED, nm_device_get_essid (dev), &addr); + if ((ap = nm_device_get_best_ap (dev))) + { + struct ether_addr addr; + + nm_device_get_ap_address (dev, &addr); + if (!nm_ethernet_address_is_valid (nm_ap_get_address (ap))) + nm_ap_set_address (ap, &addr); + + /* Don't store MAC addresses for non-infrastructure networks */ + if (nm_ap_get_mode (ap) == NETWORK_MODE_INFRA) + nm_dbus_add_network_address (data->dbus_connection, NETWORK_TYPE_ALLOWED, nm_ap_get_essid (ap), &addr); + + nm_ap_unref (ap); + } } syslog (LOG_INFO, "Activation (%s) successful, device activated.", nm_device_get_iface (data->active_device)); break; @@ -458,7 +470,7 @@ void nm_policy_schedule_device_switch (NMDevice *switch_to_dev, NMData *app_data */ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data) { - NMData *data = (NMData *)user_data; + NMData *data = (NMData *)user_data; g_return_val_if_fail (data != NULL, FALSE); @@ -471,6 +483,22 @@ static gboolean nm_policy_allowed_ap_list_update (gpointer user_data) if (data->allowed_ap_list) nm_ap_list_populate_from_nmi (data->allowed_ap_list, data); + /* If the active device doesn't have a best_ap already, make it update to + * get the new data. + */ + if ( data->active_device + && nm_device_is_activating (data->active_device) + && nm_device_is_wireless (data->active_device)) + { + NMAccessPoint *best_ap; + + best_ap = nm_device_get_best_ap (data->active_device); + if (!best_ap) + nm_device_update_best_ap (data->active_device); + else + nm_ap_unref (best_ap); + } + return (FALSE); }