2004-10-14 Dan Williams <dcbw@redhat.com>
* src/NetworkManager.c - Only accept and manager 802.3 and 802.11 devices * src/NetworkManagerDbus.[ch] - (nm_dbus_nm_set_active_device): move most of the actual activation logic into NetworkManagerDevice.c - (nm_dbus_network_status_from_data): new function - (nm_dbus_signal_network_status_change): new function, unused for now - (nm_dbus_nm_message_handler): use nm_dbus_network_status_from_data () now * src/NetworkManagerDevice.[ch] - (nm_device_find_and_use_essid): new function. Search for, and if found use, a random ESSID. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@231 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
||||
2004-10-14 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManager.c
|
||||
- Only accept and manager 802.3 and 802.11 devices
|
||||
|
||||
* src/NetworkManagerDbus.[ch]
|
||||
- (nm_dbus_nm_set_active_device): move most of the actual activation
|
||||
logic into NetworkManagerDevice.c
|
||||
- (nm_dbus_network_status_from_data): new function
|
||||
- (nm_dbus_signal_network_status_change): new function, unused for now
|
||||
- (nm_dbus_nm_message_handler): use nm_dbus_network_status_from_data () now
|
||||
|
||||
* src/NetworkManagerDevice.[ch]
|
||||
- (nm_device_find_and_use_essid): new function. Search for, and if found use,
|
||||
a random ESSID.
|
||||
|
||||
2004-10-14 John (J5) Palmieri <johnp@redhat.com>
|
||||
|
||||
* info-daemon/NetworkManagerInfo.c
|
||||
|
@@ -63,11 +63,20 @@ static char *nm_get_device_interface_from_hal (LibHalContext *ctx, const char *u
|
||||
char *iface = NULL;
|
||||
|
||||
if (hal_device_property_exists (ctx, udi, "net.interface"))
|
||||
{
|
||||
/* Only use Ethernet and Wireless devices for now (ie not Sharp Zaurus IP-over-USB connections) */
|
||||
if (hal_device_property_exists (ctx, udi, "info.category"))
|
||||
{
|
||||
char *category = hal_device_get_property_string (ctx, udi, "info.category");
|
||||
if (category && (!strcmp (category, "net.80203") || !strcmp (category, "net.80211")))
|
||||
{
|
||||
char *temp = hal_device_get_property_string (ctx, udi, "net.interface");
|
||||
iface = g_strdup (temp);
|
||||
hal_free_string (temp);
|
||||
}
|
||||
hal_free_string (category);
|
||||
}
|
||||
}
|
||||
|
||||
return (iface);
|
||||
}
|
||||
|
@@ -254,8 +254,7 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
||||
"NetworkManager::setActiveDevice called with invalid arguments.");
|
||||
return (reply_message);
|
||||
} else syslog (LOG_INFO, "FORCE: device '%s'", dev_path);
|
||||
}
|
||||
else syslog (LOG_INFO, "FORCE: device '%s', network '%s'", dev_path, network);
|
||||
} else syslog (LOG_INFO, "FORCE: device '%s', network '%s'", dev_path, network);
|
||||
|
||||
/* So by now we have a valid device and possibly a network as well */
|
||||
|
||||
@@ -267,61 +266,48 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
||||
"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::setActiveDevice called with invalid arguments.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(reply_message = dbus_message_new_method_return (message)))
|
||||
return (NULL);
|
||||
goto out;
|
||||
|
||||
/* Notify the state modification handler that we'd like to lock on a specific device */
|
||||
if (nm_try_acquire_mutex (data->user_device_mutex, __FUNCTION__))
|
||||
{
|
||||
if (data->user_device)
|
||||
nm_device_unref (data->user_device);
|
||||
|
||||
nm_device_ref (dev);
|
||||
data->user_device = dev;
|
||||
gboolean success = TRUE;
|
||||
|
||||
/* If the user specificed a wireless network too, force that as well */
|
||||
if (network && nm_device_is_wireless (dev))
|
||||
{
|
||||
NMAccessPoint *ap;
|
||||
|
||||
if ((ap = nm_ap_list_get_ap_by_essid (nm_device_ap_list_get (dev), network)))
|
||||
syslog (LOG_DEBUG, "Forcing AP '%s'", nm_ap_get_essid (ap));
|
||||
else
|
||||
{
|
||||
struct ether_addr ap_addr;
|
||||
|
||||
syslog (LOG_DEBUG, "Forcing non-scanned AP '%s'", network);
|
||||
/* If the network exists, make sure it has the correct ESSID set
|
||||
* (it might have been a blank ESSID up to this point) and use it.
|
||||
*/
|
||||
nm_device_deactivate (dev, FALSE);
|
||||
if (nm_device_wireless_network_exists (dev, network, &ap_addr))
|
||||
{
|
||||
if ((ap = nm_device_ap_list_get_ap_by_address (dev, &ap_addr)))
|
||||
nm_ap_set_essid (ap, network);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we found a valid access point, use it */
|
||||
if (ap)
|
||||
{
|
||||
nm_device_set_best_ap (dev, ap);
|
||||
nm_device_freeze_best_ap (dev);
|
||||
nm_device_activation_cancel (dev);
|
||||
}
|
||||
else
|
||||
if (nm_device_is_wireless (dev) && !nm_device_find_and_use_essid (dev, network))
|
||||
{
|
||||
reply_message = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "NetworkNotFound",
|
||||
"The requested wireless network is not in range.");
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
dbus_free (network);
|
||||
|
||||
if (success)
|
||||
{
|
||||
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__);
|
||||
|
||||
if (success)
|
||||
nm_data_mark_state_changed (data);
|
||||
}
|
||||
|
||||
out:
|
||||
dbus_free (network);
|
||||
nm_device_unref (dev);
|
||||
return (reply_message);
|
||||
}
|
||||
|
||||
@@ -452,6 +438,69 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_network_status_from_data
|
||||
*
|
||||
* Return a network status string based on our network data
|
||||
*
|
||||
* Caller MUST free returned value
|
||||
*
|
||||
*/
|
||||
static char *nm_dbus_network_status_from_data (NMData *data)
|
||||
{
|
||||
char *status = NULL;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
|
||||
if (data->active_device && nm_device_is_activating (data->active_device))
|
||||
{
|
||||
if (nm_device_is_wireless (data->active_device) && nm_device_is_scanning (data->active_device))
|
||||
status = g_strdup ("scanning");
|
||||
else
|
||||
status = g_strdup ("connecting");
|
||||
}
|
||||
else if (data->active_device)
|
||||
status = g_strdup ("connected");
|
||||
else
|
||||
status = g_strdup ("disconnected");
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_signal_network_status_change
|
||||
*
|
||||
* Signal a change in general network status.
|
||||
*
|
||||
*/
|
||||
void nm_dbus_signal_network_status_change (DBusConnection *connection, NMData *data)
|
||||
{
|
||||
DBusMessage *message;
|
||||
char *status = NULL;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "NetworkStatusChange")))
|
||||
{
|
||||
syslog (LOG_ERR, "nm_dbus_signal_device_status_change(): Not enough memory for new dbus message!");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((status = nm_dbus_network_status_from_data (data)))
|
||||
{
|
||||
dbus_message_append_args (message, DBUS_TYPE_STRING, status, DBUS_TYPE_INVALID);
|
||||
|
||||
if (!dbus_connection_send (connection, message, NULL))
|
||||
syslog (LOG_WARNING, "nm_dbus_signal_device_status_change(): Could not raise the signal!");
|
||||
g_free (status);
|
||||
}
|
||||
|
||||
dbus_message_unref (message);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_dbus_signal_device_ip4_address_change
|
||||
*
|
||||
@@ -1278,20 +1327,10 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
|
||||
nm_dbus_set_user_key_for_network (connection, message, data);
|
||||
else if (strcmp ("status", method) == 0)
|
||||
{
|
||||
if ((reply_message = dbus_message_new_method_return (message)))
|
||||
{
|
||||
if (data->active_device && nm_device_is_activating (data->active_device))
|
||||
{
|
||||
if (nm_device_is_wireless (data->active_device) && nm_device_is_scanning (data->active_device))
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "scanning", DBUS_TYPE_INVALID);
|
||||
else
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connecting", DBUS_TYPE_INVALID);
|
||||
}
|
||||
else if (data->active_device)
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connected", DBUS_TYPE_INVALID);
|
||||
else
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "disconnected", DBUS_TYPE_INVALID);
|
||||
}
|
||||
char *status = nm_dbus_network_status_from_data (data);
|
||||
if (status && (reply_message = dbus_message_new_method_return (message)))
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, status, DBUS_TYPE_INVALID);
|
||||
g_free (status);
|
||||
}
|
||||
else if (strcmp ("createTestDevice", method) == 0)
|
||||
{
|
||||
@@ -1399,7 +1438,7 @@ static DBusHandlerResult nm_dbus_devices_message_handler (DBusConnection *connec
|
||||
|
||||
/*syslog (LOG_DEBUG, "nm_dbus_devices_message_handler() got method %s for path %s", method, path);*/
|
||||
|
||||
if ((reply_message = nm_dbus_devices_handle_request (connection, data, message, path, method)))
|
||||
if (method && path && (reply_message = nm_dbus_devices_handle_request (connection, data, message, path, method)))
|
||||
{
|
||||
dbus_connection_send (connection, reply_message, NULL);
|
||||
dbus_message_unref (reply_message);
|
||||
|
@@ -54,6 +54,8 @@ gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection);
|
||||
|
||||
void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *dev, DeviceStatus status);
|
||||
|
||||
void nm_dbus_signal_network_status_change (DBusConnection *connection, NMData *data);
|
||||
|
||||
void nm_dbus_signal_devices_changed (DBusConnection *connection);
|
||||
|
||||
void nm_dbus_signal_device_ip4_address_change(DBusConnection *connection, NMDevice *dev);
|
||||
|
@@ -1298,7 +1298,7 @@ inline gboolean HAVE_LINK (NMDevice *dev, guint32 bad_crypt_packets)
|
||||
g_return_val_if_fail (dev != NULL, FALSE);
|
||||
g_return_val_if_fail (nm_device_is_wireless (dev), FALSE);
|
||||
|
||||
fprintf (stderr, "HAVELINK: act=%d && (dev_crypt=%d <= prev_crypt=%d)\n", nm_device_get_link_active (dev), nm_device_get_bad_crypt_packets (dev), bad_crypt_packets);
|
||||
syslog (LOG_NOTICE, "HAVELINK: act=%d && (dev_crypt=%d <= prev_crypt=%d)\n", nm_device_get_link_active (dev), nm_device_get_bad_crypt_packets (dev), bad_crypt_packets);
|
||||
return (nm_device_get_link_active (dev) && (nm_device_get_bad_crypt_packets (dev) <= bad_crypt_packets));
|
||||
}
|
||||
|
||||
@@ -1368,9 +1368,10 @@ void nm_device_activate_wireless_wait_for_link (NMDevice *dev)
|
||||
|| (best_ap && (nm_ap_get_encrypted (best_ap) &&
|
||||
(!nm_ap_get_enc_key_source (best_ap) || !strlen (nm_ap_get_enc_key_source (best_ap))))))
|
||||
{
|
||||
fprintf (stderr, "LINK: !HAVE=%d, (best_ap=0x%X && (is_enc=%d && (!source=%d || !len_source=%d)))\n",
|
||||
!HAVE_LINK (dev, bad_crypt_packets), best_ap, nm_ap_get_encrypted (best_ap), !nm_ap_get_enc_key_source (best_ap),
|
||||
nm_ap_get_enc_key_source (best_ap) ? !strlen (nm_ap_get_enc_key_source (best_ap)) : 0);
|
||||
syslog (LOG_NOTICE, "LINK: !HAVE=%d, (best_ap=0x%X && (is_enc=%d && (!source=%d || !len_source=%d)))\n",
|
||||
!HAVE_LINK (dev, bad_crypt_packets), best_ap, nm_ap_get_encrypted (best_ap), !nm_ap_get_enc_key_source (best_ap),
|
||||
nm_ap_get_enc_key_source (best_ap) ? !strlen (nm_ap_get_enc_key_source (best_ap)) : 0);
|
||||
|
||||
if ((best_ap = nm_device_get_best_ap (dev)))
|
||||
{
|
||||
dev->options.wireless.now_scanning = FALSE;
|
||||
@@ -2034,9 +2035,6 @@ gboolean nm_device_wireless_network_exists (NMDevice *dev, const char *network,
|
||||
/* Force the card into Managed/Infrastructure mode */
|
||||
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.
|
||||
*/
|
||||
nm_device_set_enc_key (dev, NULL);
|
||||
nm_device_set_essid (dev, network);
|
||||
|
||||
@@ -2060,6 +2058,66 @@ gboolean nm_device_wireless_network_exists (NMDevice *dev, const char *network,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_device_find_and_use_essid
|
||||
*
|
||||
* Given an essid, attempt to associate with that ESSID even if we can't
|
||||
* see it in our scan. If we successfully find it, mark that network as
|
||||
* our "best" and use it during the next activation.
|
||||
*
|
||||
* Returns: TRUE on success
|
||||
* FALSE on failure
|
||||
*/
|
||||
gboolean nm_device_find_and_use_essid (NMDevice *dev, const char *essid)
|
||||
{
|
||||
struct ether_addr ap_addr;
|
||||
NMAccessPoint *ap = NULL;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (dev != NULL, FALSE);
|
||||
g_return_val_if_fail (nm_device_is_wireless (dev), FALSE);
|
||||
g_return_val_if_fail (dev->app_data != NULL, FALSE);
|
||||
g_return_val_if_fail (essid != NULL, FALSE);
|
||||
|
||||
syslog (LOG_DEBUG, "Forcing AP '%s'", essid);
|
||||
/* If the network exists, make sure it has the correct ESSID set
|
||||
* (it might have been a blank ESSID up to this point) and use it.
|
||||
*/
|
||||
nm_device_deactivate (dev, FALSE);
|
||||
if (nm_device_wireless_network_exists (dev, essid, &ap_addr))
|
||||
{
|
||||
if (!(ap = nm_ap_list_get_ap_by_essid (nm_device_ap_list_get (dev), essid)))
|
||||
{
|
||||
if ((ap = nm_device_ap_list_get_ap_by_address (dev, &ap_addr)))
|
||||
{
|
||||
NMAccessPoint *tmp_ap;
|
||||
|
||||
nm_ap_set_essid (ap, essid);
|
||||
|
||||
/* Now that this AP has an essid, copy over encryption keys and whatnot */
|
||||
if ((tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->allowed_ap_list, essid)))
|
||||
{
|
||||
nm_ap_set_invalid (ap, nm_ap_get_invalid (tmp_ap));
|
||||
nm_ap_set_enc_key_source (ap, nm_ap_get_enc_key_source (tmp_ap), nm_ap_get_enc_method (tmp_ap));
|
||||
nm_ap_set_timestamp (ap, nm_ap_get_timestamp (tmp_ap));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we found a valid access point, use it */
|
||||
if (ap)
|
||||
{
|
||||
nm_device_set_best_ap (dev, ap);
|
||||
nm_device_freeze_best_ap (dev);
|
||||
nm_device_activation_cancel (dev);
|
||||
success = TRUE;
|
||||
}
|
||||
|
||||
return (success);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nm_device_do_normal_scan
|
||||
*
|
||||
|
@@ -74,6 +74,7 @@ NMAccessPoint *nm_device_get_best_ap (NMDevice *dev);
|
||||
void nm_device_set_best_ap (NMDevice *dev, NMAccessPoint *ap);
|
||||
void nm_device_update_best_ap (NMDevice *dev);
|
||||
gboolean nm_device_need_ap_switch (NMDevice *dev);
|
||||
|
||||
void nm_device_freeze_best_ap (NMDevice *dev);
|
||||
void nm_device_unfreeze_best_ap (NMDevice *dev);
|
||||
gboolean nm_device_is_best_ap_frozen (NMDevice *dev);
|
||||
@@ -91,6 +92,8 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added);
|
||||
|
||||
gboolean nm_device_is_scanning (NMDevice *dev);
|
||||
|
||||
gboolean nm_device_find_and_use_essid (NMDevice *dev, const char *essid);
|
||||
|
||||
void nm_device_set_user_key_for_network (NMDevice *dev, struct NMAccessPointList *invalid_list,
|
||||
unsigned char *network, unsigned char *key,
|
||||
NMAPEncMethod enc_method);
|
||||
|
@@ -282,7 +282,7 @@ gboolean nm_state_modification_monitor (gpointer user_data)
|
||||
syslog (LOG_INFO, " SWITCH: need to associate with new access point");
|
||||
do_switch = TRUE;
|
||||
}
|
||||
else if (!nm_device_is_activating (best_dev) && (nm_device_get_ip4_address (best_dev) == 0))
|
||||
else if (!nm_device_is_activating (best_dev) && !nm_device_get_ip4_address (best_dev))
|
||||
{
|
||||
syslog (LOG_INFO, " SWITCH: need to get an IP address");
|
||||
do_switch = TRUE;
|
||||
|
Reference in New Issue
Block a user