Commit 154a0425 authored by Dan Williams's avatar Dan Williams

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

	* panel-applet/NMWirelessAppletDbus.c
		- New functions:
			wireless_network_new
			wireless_network_copy
			network_device_new
			network_device_copy

	* src/NetworkManagerDevice.[ch]
		- New functions:
			nm_device_set_mode_managed
			nm_device_set_mode_adhoc
		- Use these functions where appropriate
		- When creating a new wireless device, force the card
			to managed/Infrastructure mode as soon as possible


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@216 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent d952218b
2004-10-12 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessAppletDbus.c
- New functions:
wireless_network_new
wireless_network_copy
network_device_new
network_device_copy
* src/NetworkManagerDevice.[ch]
- New functions:
nm_device_set_mode_managed
nm_device_set_mode_adhoc
- Use these functions where appropriate
- When creating a new wireless device, force the card
to managed/Infrastructure mode as soon as possible
2004-10-12 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerDevice.c
......
......@@ -796,6 +796,50 @@ static void wireless_network_unref (WirelessNetwork *net)
}
}
/*
* wireless_network_new
*
* Create a new wireless network structure
*
*/
WirelessNetwork *wireless_network_new (void)
{
WirelessNetwork *net = NULL;
if ((net = g_new0 (WirelessNetwork, 1)))
wireless_network_ref (net);
return (net);
}
/*
* wireless_network_copy
*
* Create a new wireless network structure from an existing one
*
*/
WirelessNetwork *wireless_network_copy (WirelessNetwork *src)
{
WirelessNetwork *net = NULL;
g_return_val_if_fail (src != NULL, NULL);
if ((net = g_new0 (WirelessNetwork, 1)))
{
wireless_network_ref (net);
net->nm_name = g_strdup (src->nm_name);
net->essid = g_strdup (src->essid);
net->active = src->active;
net->encrypted = src->encrypted;
net->strength = src->strength;
}
return (net);
}
/*
* network_device_free_wireless_network_list
*
......@@ -847,6 +891,67 @@ static void network_device_unref (NetworkDevice *dev)
}
/*
* network_device_new
*
* Create a new network device representation
*
*/
NetworkDevice *network_device_new (void)
{
NetworkDevice *dev = NULL;
if ((dev = g_new0 (NetworkDevice, 1)))
network_device_ref (dev);
return (dev);
}
/*
* network_device_copy
*
* Create a new network device representation, filling its
* data in from an already existing one. Deep-copies the
* wireless networks too.
*
*/
NetworkDevice *network_device_copy (NetworkDevice *src)
{
NetworkDevice *dev = NULL;
g_return_val_if_fail (src != NULL, NULL);
if ((dev = g_new0 (NetworkDevice, 1)))
{
GSList *elem;
network_device_ref (dev);
dev->nm_device = g_strdup (src->nm_device);
dev->type = src->type;
dev->nm_name = g_strdup (src->nm_name);
dev->hal_name = g_strdup (src->hal_name);
dev->udi = g_strdup (src->udi);
dev->strength = src->strength;
elem = src->networks;
while (elem)
{
WirelessNetwork *net = (WirelessNetwork *)elem->data;
if (net)
{
WirelessNetwork *copy = wireless_network_copy (net);
dev->networks = g_slist_append (dev->networks, copy);
}
elem = g_slist_next (elem);
}
}
return (dev);
}
/*
* nmwa_dbus_update_device_wireless_networks
*
......@@ -904,8 +1009,8 @@ static void nmwa_dbus_update_device_wireless_networks (NetworkDevice *dev, NMWir
if (found)
continue;
net = g_new0 (WirelessNetwork, 1);
wireless_network_ref (net);
net = wireless_network_new ();
/* FIXME: what if net == NULL? */
net->nm_name = g_strdup (networks[i]);
net->essid = g_strdup (name);
net->active = active_network ? (strcmp (net->nm_name, active_network) == 0) : FALSE;
......@@ -1091,9 +1196,8 @@ static void nmwa_dbus_update_devices (NMWirelessApplet *applet)
{
NetworkDevice *dev;
if ((dev = g_new0 (NetworkDevice, 1)))
if ((dev = network_device_new ()))
{
network_device_ref (dev);
dev->nm_device = g_strdup (devices[i]);
dev->type = nmwa_dbus_get_device_type (applet, devices[i], APPLET_STATE_NO_CONNECTION);
dev->nm_name = g_strdup (name);
......
......@@ -335,6 +335,7 @@ NMDevice *nm_device_new (const char *iface, gboolean test_dev, NMDeviceType test
dev->options.wireless.supports_wireless_scan = nm_device_supports_wireless_scan (dev);
/* Perform an initial wireless scan */
nm_device_set_mode_managed (dev);
nm_device_do_wireless_scan (dev);
nm_device_update_best_ap (dev);
}
......@@ -1100,6 +1101,62 @@ gboolean nm_device_is_up (NMDevice *dev)
}
/*
* nm_device_set_mode_managed
*
* Set managed/infrastructure mode on a device (currently wireless only)
*
*/
void nm_device_set_mode_managed (NMDevice *dev)
{
int sk;
struct iwreq wreq;
g_return_if_fail (dev != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
/* Force the card into Managed/Infrastructure mode */
sk = iw_sockets_open ();
if (sk >= 0)
{
int err;
wreq.u.mode = IW_MODE_INFRA;
err = iw_set_ext (sk, nm_device_get_iface (dev), SIOCSIWMODE, &wreq);
if (err == -1)
syslog (LOG_ERR, "nm_device_set_mode_managed (%s): error setting card to Infrastructure mode. errno = %d", nm_device_get_iface (dev), errno);
close (sk);
}
}
/*
* nm_device_set_mode_adhoc
*
* Set Ad Hoc mode on a device (currently wireless only)
*
*/
void nm_device_set_mode_adhoc (NMDevice *dev)
{
int sk;
struct iwreq wreq;
g_return_if_fail (dev != NULL);
g_return_if_fail (nm_device_is_wireless (dev));
/* Force the card into Managed/Infrastructure mode */
sk = iw_sockets_open ();
if (sk >= 0)
{
int err;
wreq.u.mode = IW_MODE_ADHOC;
err = iw_set_ext (sk, nm_device_get_iface (dev), SIOCSIWMODE, &wreq);
if (err == -1)
syslog (LOG_ERR, "nm_device_set_mode_adhoc (%s): error setting card to Ad Hoc mode. errno = %d", nm_device_get_iface (dev), errno);
close (sk);
}
}
/*
* nm_device_activation_begin
*
......@@ -1203,22 +1260,10 @@ static gboolean nm_device_activate_wireless (NMDevice *dev, guint *bad_crypt_pac
/* If there is a desired AP to connect to, use that essid and possible WEP key */
if ((best_ap = nm_device_get_best_ap (dev)) && nm_ap_get_essid (best_ap))
{
int sk;
struct iwreq wreq;
nm_device_bring_down (dev);
/* Force the card into Managed/Infrastructure mode */
sk = iw_sockets_open ();
if (sk >= 0)
{
int err;
wreq.u.mode = IW_MODE_INFRA;
err = iw_set_ext (sk, nm_device_get_iface (dev), SIOCSIWMODE, &wreq);
if (err == -1)
syslog (LOG_ERR, "nm_device_activate_wireless(%s): error setting card to Infrastructure mode. errno = %d", nm_device_get_iface (dev), errno);
close (sk);
}
nm_device_set_mode_managed (dev);
/* Disable encryption, then re-enable and set correct key on the card
* if we are going to encrypt traffic.
......
......@@ -60,6 +60,9 @@ void nm_device_get_ip6_address (NMDevice *dev);
gboolean nm_device_get_supports_wireless_scan (NMDevice *dev);
void nm_device_do_wireless_scan (NMDevice *dev);
void nm_device_set_mode_managed (NMDevice *dev);
void nm_device_set_mode_adhoc (NMDevice *dev);
gint8 nm_device_get_signal_strength (NMDevice *dev);
void nm_device_update_signal_strength (NMDevice *dev);
guint8 nm_device_get_noise (NMDevice *dev);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment