Commit e96c5c29 authored by Dan Williams's avatar Dan Williams
Browse files

2004-12-17 Dan Williams <dcbw@redhat.com>

	* Ad Ad-Hoc networking mode support.  In Ad-Hoc mode, we only try to get
		link-local addresses instead of doing DHCP.

	* In the panel applet, there's a new "Create new Wireless Network..." item

	* The panel applet also sticks around now even if NetworkManager dies, but
		it doesn't hide its icon when NM isn't around.  Not hiding the icon is
		a bug, I'll fix that later.

	* We also don't use 'nscd' anymore in the RH backend, it was impeding name
		lookups after a switch rather than actually doing them.

	* Clean up some of those warnings in nm_ap_list_* functions

	* Delay between scans changed to 15s instead of 10s


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@342 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent cd475e6d
2004-12-17 Dan Williams <dcbw@redhat.com>
* Ad Ad-Hoc networking mode support. In Ad-Hoc mode, we only try to get
link-local addresses instead of doing DHCP.
* In the panel applet, there's a new "Create new Wireless Network..." item
* The panel applet also sticks around now even if NetworkManager dies, but
it doesn't hide its icon when NM isn't around. Not hiding the icon is
a bug, I'll fix that later.
* We also don't use 'nscd' anymore in the RH backend, it was impeding name
lookups after a switch rather than actually doing them.
* Clean up some of those warnings in nm_ap_list_* functions
* Delay between scans changed to 15s instead of 10s
2004-12-15 Dan Williams <dcbw@redhat.com>
Patch from Tom Parker
......
......@@ -822,6 +822,35 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag
appeared = TRUE;
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkDisappeared"))
disappeared = TRUE;
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivationFailed"))
{
char *dev = NULL;
char *net = NULL;
DBusError error;
dbus_error_init (&error);
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_STRING, &net, DBUS_TYPE_INVALID))
{
if (dbus_error_is_set (&error))
dbus_error_free (&error);
dbus_error_init (&error);
dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_INVALID);
}
if (dbus_error_is_set (&error))
dbus_error_free (&error);
if (dev && net)
{
char *string = g_strdup_printf ("Connection to the wireless network '%s' failed.\n", net);
nmi_show_warning_dialog (TRUE, string);
g_free (string);
}
else if (dev)
nmi_show_warning_dialog (TRUE, "Connection to the wired network failed.\n");
dbus_free (dev);
dbus_free (net);
}
#if 0
else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceDeleted"))
{
char *service;
......@@ -870,56 +899,8 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag
if (dbus_error_is_set (&error))
dbus_error_free (&error);
}
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivationFailed"))
{
char *dev = NULL;
char *net = NULL;
DBusError error;
dbus_error_init (&error);
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_STRING, &net, DBUS_TYPE_INVALID))
{
if (dbus_error_is_set (&error))
dbus_error_free (&error);
dbus_error_init (&error);
dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev, DBUS_TYPE_INVALID);
}
if (dbus_error_is_set (&error))
dbus_error_free (&error);
if (dev && net)
{
char *string = g_strdup_printf ("Connection to the wireless network '%s' failed.\n", net);
nmi_show_warning_dialog (TRUE, string);
g_free (string);
}
else if (dev)
nmi_show_warning_dialog (TRUE, "Connection to the wired network failed.\n");
dbus_free (dev);
dbus_free (net);
}
if (appeared || disappeared)
{
dbus_error_init (&error);
if (dbus_message_get_args (message, &error,
DBUS_TYPE_STRING, &dev_path,
DBUS_TYPE_STRING, &ap_path,
DBUS_TYPE_INVALID))
{
#if 0
if (appeared)
nmi_new_networks_dialog_add_network (ap_path, info);
else if (disappeared)
nmi_new_networks_dialog_add_network (ap_path, info);
#endif
dbus_free (dev_path);
dbus_free (ap_path);
handled = TRUE;
}
}
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
}
......@@ -969,8 +950,10 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
exit (0);
}
#if 0
if (!nmi_dbus_nm_is_running (dbus_connection))
return (-1);
#endif
if (!dbus_connection_register_object_path (dbus_connection, NMI_DBUS_PATH, &nmi_vtable, info))
{
......
......@@ -640,14 +640,12 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, g
}
/* FIXME: We really should break this dialog into its own file. This function is too long.
*/
static void
custom_essid_item_selected (GtkWidget *menu_item, NMWirelessApplet *applet)
static void custom_essid_item_selected (GtkWidget *menu_item, NMWirelessApplet *applet)
{
nmwa_other_network_dialog_run (applet);
nmwa_other_network_dialog_run (applet, FALSE);
}
static void nmwa_menu_add_custom_essid_item (GtkWidget *menu, NMWirelessApplet *applet)
{
GtkWidget *menu_item;
......@@ -663,6 +661,26 @@ static void nmwa_menu_add_custom_essid_item (GtkWidget *menu, NMWirelessApplet *
}
static void new_network_item_selected (GtkWidget *menu_item, NMWirelessApplet *applet)
{
nmwa_other_network_dialog_run (applet, TRUE);
}
static void nmwa_menu_add_create_network_item (GtkWidget *menu, NMWirelessApplet *applet)
{
GtkWidget *menu_item;
GtkWidget *label;
menu_item = gtk_menu_item_new ();
label = gtk_label_new (_("Create new Wireless Network..."));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (menu_item), label);
gtk_widget_show_all (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
g_signal_connect (menu_item, "activate", G_CALLBACK (new_network_item_selected), applet);
}
/*
* nmwa_menu_device_add_networks
*
......@@ -813,9 +831,10 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet)
if (n_wireless_interfaces > 0)
{
/* Add the 'Select a custom esssid entry */
/* Add the "Other wireless network..." entry */
nmwa_menu_add_separator_item (menu);
nmwa_menu_add_custom_essid_item (menu, applet);
nmwa_menu_add_create_network_item (menu, applet);
}
g_mutex_unlock (applet->data_mutex);
......
......@@ -548,6 +548,39 @@ void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev,
}
/*
* nmwa_dbus_create_network
*
* Tell NetworkManager to create an Ad-Hoc wireless network
*
*/
void nmwa_dbus_create_network (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network,
NMEncKeyType key_type, const char *passphrase)
{
DBusMessage *message;
g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "createWirelessNetwork")))
{
if (network && network->essid)
{
fprintf (stderr, "Creating network '%s' %s passphrase on device '%s'.\n", network->essid, passphrase ? "with" : "without", dev->nm_device);
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device,
DBUS_TYPE_STRING, network->essid,
DBUS_TYPE_STRING, (passphrase ? passphrase : ""),
DBUS_TYPE_INT32, key_type,
DBUS_TYPE_INVALID);
}
dbus_connection_send (connection, message, NULL);
}
else
fprintf (stderr, "nm_dbus_set_device(): Couldn't allocate the dbus message\n");
}
/*
* wireless_network_ref
*
......
......@@ -42,6 +42,10 @@ void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice
const WirelessNetwork *network, NMEncKeyType key_type,
const char *passphrase);
void nmwa_dbus_create_network (DBusConnection *connection, const NetworkDevice *dev,
const WirelessNetwork *network, NMEncKeyType key_type,
const char *passphrase);
WirelessNetwork * wireless_network_new_with_essid (const char *essid);
void wireless_network_unref (WirelessNetwork *net);
......
......@@ -193,7 +193,7 @@ void nmwa_other_network_dialog_enc_check_toggled (GtkWidget *enc_check_button, g
}
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, NetworkDevice **def_dev)
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, NetworkDevice **def_dev, gboolean create_network)
{
GtkDialog *dialog = NULL;
GtkWidget *essid_entry;
......@@ -220,9 +220,18 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
gtk_widget_set_sensitive (button, FALSE);
g_signal_connect (essid_entry, "changed", G_CALLBACK (update_button_cb), xml);
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
if (create_network)
{
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Create new wireless network"),
_("Enter the ESSID and security settings of the wireless network you wish to create."));
}
else
{
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Custom wireless network"),
_("Enter the ESSID of the wireless network to which you wish to connect."));
}
gtk_label_set_markup (GTK_LABEL (glade_xml_get_widget (xml, "essid_label")), label);
/* Do we have multiple Network cards? */
......@@ -287,7 +296,7 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
}
void nmwa_other_network_dialog_run (NMWirelessApplet *applet)
void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_network)
{
gchar *glade_file;
GtkDialog *dialog;
......@@ -315,7 +324,7 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet)
return;
}
if (!(dialog = nmwa_other_network_dialog_init (xml, applet, &def_dev)))
if (!(dialog = nmwa_other_network_dialog_init (xml, applet, &def_dev, create_network)))
return;
/* Run the dialog */
......@@ -375,7 +384,10 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet)
}
applet->applet_state = APPLET_STATE_WIRELESS_CONNECTING;
applet->forcing_device = TRUE;
nmwa_dbus_set_device (applet->connection, def_dev, net, nm_key_type, passphrase);
if (create_network)
nmwa_dbus_create_network (applet->connection, def_dev, net, nm_key_type, passphrase);
else
nmwa_dbus_set_device (applet->connection, def_dev, net, nm_key_type, passphrase);
network_device_unref (def_dev);
wireless_network_unref (net);
}
......
......@@ -26,6 +26,6 @@
#ifndef NM_WIRELESS_APPLET_OTHER_NETWORK_DIALOG_H
#define NM_WIRELESS_APPLET_OTHER_NETWORK_DIALOG_H
void nmwa_other_network_dialog_run (NMWirelessApplet *applet);
void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_network);
#endif
......@@ -727,7 +727,7 @@ int main( int argc, char *argv[] )
policy_source_id = g_source_attach (policy_source, nm_data->main_context);
/* Keep a current list of access points */
wscan_source = g_timeout_source_new (10000);
wscan_source = g_timeout_source_new (15000);
g_source_set_callback (wscan_source, nm_wireless_scan_monitor, nm_data, NULL);
wscan_source_id = g_source_attach (wscan_source, nm_data->main_context);
......
......@@ -41,6 +41,7 @@ struct NMAccessPoint
gboolean matched; /* used in ap list diffing */
gboolean trusted;
gboolean artificial; /* Whether or not the AP is from a scan */
gboolean user_created; /* Whether or not the AP was created by the user with "Create network..." */
/* Things from user prefs */
char *enc_key;
......@@ -104,7 +105,7 @@ NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap)
memcpy (new_addr, src_ap->address, sizeof (struct ether_addr));
new_ap->address = new_addr;
}
new_ap->mode = NETWORK_MODE_INFRA;
new_ap->mode = src_ap->mode;
new_ap->strength = src_ap->strength;
new_ap->freq = src_ap->freq;
new_ap->rate = src_ap->rate;
......@@ -456,6 +457,28 @@ void nm_ap_set_artificial (NMAccessPoint *ap, gboolean artificial)
}
/*
* Get/Set functions to indicate that an access point is
* user-created, ie whether or not its a network filled with
* information from the user and intended to create a new Ad-Hoc
* wireless network.
*
*/
gboolean nm_ap_get_user_created (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, FALSE);
return (ap->user_created);
}
void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created)
{
g_return_if_fail (ap != NULL);
ap->user_created = user_created;
}
/*
* Return the encryption method the user specified for this access point.
*
......
......@@ -74,6 +74,9 @@ void nm_ap_set_trusted (NMAccessPoint *ap, gboolean trusted);
gboolean nm_ap_get_artificial (NMAccessPoint *ap);
void nm_ap_set_artificial (NMAccessPoint *ap, gboolean artificial);
gboolean nm_ap_get_user_created (NMAccessPoint *ap);
void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created);
const NMEncKeyType nm_ap_get_enc_method (NMAccessPoint *ap);
GSList * nm_ap_get_user_addresses (NMAccessPoint *ap);
......
......@@ -477,8 +477,8 @@ void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *sou
NMAPListIter *iter;
NMAccessPoint *dest_ap;
g_return_if_fail (dest != NULL);
g_return_if_fail (source != NULL);
if (!dest || !source)
return;
if ((iter = nm_ap_list_iter_new (dest)))
{
......@@ -511,8 +511,8 @@ void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointLi
NMAPListIter *iter;
NMAccessPoint *dest_ap;
g_return_if_fail (dest != NULL);
g_return_if_fail (source != NULL);
if (!dest || !source)
return;
if ((iter = nm_ap_list_iter_new (dest)))
{
......
......@@ -79,6 +79,39 @@ static void nm_device_dhcp_configure (NMDevice *dev)
}
/*
* nm_device_do_autoip
*
* Get and assign a Link Local Address.
*
*/
gboolean nm_device_do_autoip (NMDevice *dev)
{
struct in_addr ip;
gboolean success = FALSE;
g_return_val_if_fail (dev != NULL, FALSE);
if ((success = get_autoip (dev, &ip)))
{
#define LINKLOCAL_BCAST 0xa9feffff
int temp = ip.s_addr;
nm_system_device_set_ip4_address (dev, temp);
temp = ntohl (0xFFFF0000);
nm_system_device_set_ip4_netmask (dev, temp);
temp = ntohl (LINKLOCAL_BCAST);
nm_system_device_set_ip4_broadcast (dev, temp);
/* Set all traffic to go through the device */
nm_system_flush_loopback_routes ();
nm_system_device_add_default_route_via_device (dev);
}
return (success);
}
/*
* nm_device_dhcp_request
*
......@@ -89,7 +122,6 @@ int nm_device_dhcp_request (NMDevice *dev)
{
dhcp_client_options opts;
int err;
struct in_addr ip;
g_return_val_if_fail (dev != NULL, RET_DHCP_ERROR);
......@@ -107,32 +139,16 @@ int nm_device_dhcp_request (NMDevice *dev)
/* Start off in DHCP INIT state, get a completely new IP address
* and settings.
*/
err = dhcp_init (dev->dhcp_iface);
switch (err)
if ((err = dhcp_init (dev->dhcp_iface)) == RET_DHCP_BOUND)
{
case RET_DHCP_BOUND:
nm_device_dhcp_configure (dev);
nm_device_update_ip4_address (dev);
nm_device_dhcp_setup_timeouts (dev);
break;
default:
/* DHCP didn't work, so use Link Local addressing */
dhcp_interface_free (dev->dhcp_iface);
dev->dhcp_iface = NULL;
if (get_autoip (dev, &ip))
{
#define LINKLOCAL_BCAST 0xa9feffff
int temp = ip.s_addr;
nm_system_device_set_ip4_address (dev, temp);
temp = ntohl (0xFFFF0000);
nm_system_device_set_ip4_netmask (dev, temp);
temp = ntohl (LINKLOCAL_BCAST);
nm_system_device_set_ip4_broadcast (dev, temp);
err = RET_DHCP_BOUND;
}
break;
nm_device_dhcp_configure (dev);
nm_device_update_ip4_address (dev);
nm_device_dhcp_setup_timeouts (dev);
}
else
{
dhcp_interface_free (dev->dhcp_iface);
dev->dhcp_iface = NULL;
}
return (err);
......
......@@ -29,5 +29,6 @@ void nm_device_dhcp_cease (NMDevice *dev);
gboolean nm_device_dhcp_setup_timeouts (NMDevice *dev);
gboolean nm_device_dhcp_renew (gpointer user_data);
gboolean nm_device_dhcp_rebind (gpointer user_data);
gboolean nm_device_do_autoip (NMDevice *dev);
#endif
......@@ -298,7 +298,9 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
/* If the user specificed a wireless network too, force that as well */
if (nm_device_is_wireless (dev) && !nm_device_find_and_use_essid (dev, network, key, key_type))
{
nm_dbus_send_network_not_found (data->dbus_connection, network);
}
else
{
if (nm_try_acquire_mutex (data->user_device_mutex, __FUNCTION__))
......@@ -326,6 +328,98 @@ out:
}
/*
* nm_dbus_nm_create_wireless_network
*
* Create a new wireless network and
*
*/
static DBusMessage *nm_dbus_nm_create_wireless_network (DBusConnection *connection, DBusMessage *message, NMData *data)
{
NMDevice *dev = NULL;
DBusMessage *reply_message = NULL;
char *dev_path = NULL;
char *network = NULL;
char *key = NULL;
int key_type = -1;
DBusError error;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
g_return_val_if_fail (data != NULL, NULL);
/* Try to grab both device _and_ network first, and if that fails then just the device. */
dbus_error_init (&error);
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &dev_path,
DBUS_TYPE_STRING, &network, DBUS_TYPE_STRING, &key,
DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments",
"NetworkManager::createWirelessNetwork called with invalid arguments.");
return (reply_message);
} else syslog (LOG_INFO, "Creating network '%s' on device '%s'.", network, dev_path);
dev = nm_dbus_get_device_from_object_path (data, dev_path);
dbus_free (dev_path);
if (!dev || (nm_device_get_driver_support_level (dev) == NM_DRIVER_UNSUPPORTED))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotFound",
"The requested network device does not exist.");
return (reply_message);
}
nm_device_ref (dev);
/* Make sure network is valid and device is wireless */
if (!nm_device_is_wireless (dev) || !network)
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments",
"NetworkManager::createWirelessNetwork called with invalid arguments.");
goto out;
}
if (!(reply_message = dbus_message_new_method_return (message)))
goto out;
/* If the user specificed a wireless network too, force that as well */
if (nm_try_acquire_mutex (data->user_device_mutex, __FUNCTION__))
{
NMAccessPoint *ap = nm_ap_new ();
/* Fill in the description of the network to create */
nm_ap_set_essid (ap, network);
if (key && strlen (key))
{
nm_ap_set_encrypted (ap, TRUE);
nm_ap_set_enc_key_source (ap, key, key_type);
}
nm_ap_set_mode (ap, NETWORK_MODE_ADHOC);
nm_ap_set_user_created (ap, TRUE);
nm_device_set_best_ap (dev, ap);
nm_device_freeze_best_ap (dev);
nm_device_activation_cancel (dev);
if (data->user_device)
nm_device_unref (data->user_device);
data->user_device = dev;
nm_device_ref (data->user_device);
nm_unlock_mutex (data->user_device_mutex, __FUNCTION__);
}
/* Have to mark our state changed since we blew away our connection trying out
* the user-requested network.
*/
nm_data_mark_state_changed (data);
out:
dbus_free (network);
dbus_free (key);
nm_device_unref (dev);
return (reply_message);
}
/*
* nm_dbus_nm_get_devices
*
......@@ -1467,6 +1561,8 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
reply_message = nm_dbus_nm_get_devices (connection, message, data);
else if (strcmp ("setActiveDevice", method) == 0)
nm_dbus_nm_set_active_device (connection, message, data);
else if (strcmp ("createWirelessNetwork", method) == 0)
nm_dbus_nm_create_wireless_network (connection, message, data);
else if (strcmp ("setKeyForNetwork", method) == 0)
nm_dbus_set_user_key_for_network (connection, message, data);
else if (strcmp ("status", method) == 0)
......
This diff is collapsed.
......@@ -42,7 +42,7 @@ typedef struct NMDeviceWirelessOptions
guint8 noise;
gint8 strength;
gint8 invalid_strength_counter;
gint8 num_freqs;
struct iw_range range_info;