2004-07-15 Dan Williams <dcbw@redhat.com>
* src/Makefile.am - Turn on warnings * src/NetworkManager.c - nm_create_device_and_add_to_list(): call nm_device_deactivate() rather that doing the deactivation ourselves - Cancel an pending actions on a device if its being removed - Break up link state checking a bit, make non-active wireless cards deactivated to save power - Remove unused variables * src/NetworkManager.h - Add support for "pending" device * src/NetworkManagerAP.h src/NetworkManagerAP.c - Add support for determining whether and AP has encryption enabled or not - AP address is now "struct ether_addr" rather than a string * src/NetworkManagerDbus.h src/NetworkManagerDbus.c - Add signal NeedKeyForNetwork, method SetKeyForNetwork (testing only) - Changes for AP address from struct ether_addr->string * src/NetworkManagerDevice.h src/NetworkManagerDevice.c - Remove unused variables, fix warnings - Add support for Pending Actions (things that block a device from being "active" until they are completed). - First pending action: Get a WEP key from the user - Add nm_device_is_wire[d|less](), rename nm_device_is_wireless() - Clean up explicit testing of dev->iface_type to use nm_device_is_wireless() - Update wireless link checking to try to determine if the AP we are associated with is correct, but the WEP key we are using is just wrong. If its wrong, trigger the GetUserKey pending action on the device - If dhclient can't get an IP address, it brings the device down. Bring it back up in that case, otherwise we can't scan or link-check on it - Add IP address change notifications at appropriate points (still needs some work) - Add nm_device_need_ap_switch(), checks whether we need to switch access points or not * src/NetworkManagerPolicy.h src/NetworkManagerPolicy.c - Split out "best" access point determiniation into separate function - Make device activation 2-stage: first the device is pending, then in the next iteration through it becomes "active" unless it has pending actions * src/NetworkManagerUtils.h src/NetworkManagerUtils.c - Clean up unused variables and warnings - Wrap our debug macros in {} to prevent possible confusion * src/NetworkManagerWireless.c - Forgot to return current best priority, which lead to last available AP always being chosen no matter what its priority was. Corrected. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@15 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -90,56 +90,28 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi)
|
||||
*/
|
||||
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||
{
|
||||
unsigned char buf[500];
|
||||
|
||||
NM_DEBUG_PRINT_3( "nm_create_device_and_add_to_list() adding udi='%s', iface='%s', iface_type=%s\n",
|
||||
nm_device_get_udi (dev), nm_device_get_iface (dev), nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET ? "wireless" : "wired" );
|
||||
|
||||
data->dev_list = g_slist_append (data->dev_list, dev);
|
||||
|
||||
/* Initialize and bring up all new devices */
|
||||
if (nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET)
|
||||
{
|
||||
/* Disable WEP, take device down */
|
||||
nm_device_bring_down (dev);
|
||||
nm_device_set_wep_key (dev, NULL);
|
||||
nm_device_set_essid (dev, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!nm_device_is_up (dev))
|
||||
nm_device_bring_up (dev);
|
||||
}
|
||||
|
||||
/* Remove routing table entries */
|
||||
snprintf (buf, 500, "/sbin/ip route flush dev %s", nm_device_get_iface (dev));
|
||||
system (buf);
|
||||
|
||||
/* Remove ip address */
|
||||
snprintf (buf, 500, "/sbin/ip address flush dev %s", nm_device_get_iface (dev));
|
||||
system (buf);
|
||||
|
||||
nm_device_deactivate (dev, TRUE);
|
||||
success = TRUE;
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
else
|
||||
NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not acquire device list mutex.\n" );
|
||||
}
|
||||
else
|
||||
NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not allocate device data.\n" );
|
||||
} else NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not acquire device list mutex.\n" );
|
||||
} else NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not allocate device data.\n" );
|
||||
|
||||
hal_free_string (iface_name);
|
||||
|
||||
if (!success)
|
||||
if (success)
|
||||
nm_data_set_state_modified (data, TRUE);
|
||||
else
|
||||
{
|
||||
/* If we couldn't add the device to our list, free its data. */
|
||||
nm_device_unref (dev);
|
||||
dev = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
NM_DEBUG_PRINT_1( "nm_create_device_and_add_to_list(): device %s does not have 'net.interface' property\n", udi );
|
||||
} else NM_DEBUG_PRINT_1( "nm_create_device_and_add_to_list(): device %s does not have 'net.interface' property\n", udi );
|
||||
|
||||
return (dev);
|
||||
}
|
||||
@@ -173,29 +145,27 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
|
||||
{
|
||||
if (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0)
|
||||
{
|
||||
if ( data->active_device
|
||||
&& (dev == data->active_device))
|
||||
{
|
||||
nm_device_unref (data->active_device);
|
||||
if (data->active_device && (dev == data->active_device))
|
||||
data->active_device = NULL;
|
||||
}
|
||||
else if (data->pending_device && (dev == data->pending_device))
|
||||
data->pending_device = NULL;
|
||||
|
||||
nm_device_pending_action_cancel (dev);
|
||||
nm_device_unref (dev);
|
||||
|
||||
/* Remove the device entry from the device list and free its data */
|
||||
data->dev_list = g_slist_remove_link (data->dev_list, element);
|
||||
nm_device_unref (element->data);
|
||||
g_slist_free (element);
|
||||
|
||||
nm_data_set_state_modified (data, TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
else
|
||||
NM_DEBUG_PRINT( "nm_remove_device_from_list() could not acquire device list mutex.\n" );
|
||||
} else NM_DEBUG_PRINT( "nm_remove_device_from_list() could not acquire device list mutex.\n" );
|
||||
}
|
||||
|
||||
|
||||
@@ -333,40 +303,47 @@ gboolean nm_link_state_monitor (gpointer user_data)
|
||||
|
||||
if (dev)
|
||||
{
|
||||
if ( dev != data->active_device
|
||||
&& (nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET))
|
||||
{
|
||||
/* If its a wireless card, make sure its down. Saves power. */
|
||||
if (nm_device_is_up (dev))
|
||||
nm_device_bring_down (dev);
|
||||
}
|
||||
|
||||
if ((nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRED_ETHERNET))
|
||||
{
|
||||
/* Make sure the device is up first. It doesn't have to have
|
||||
* an IP address or anything, but most wired devices cannot do link
|
||||
* detection when they are down.
|
||||
*/
|
||||
if (!nm_device_is_up (dev))
|
||||
nm_device_bring_up (dev);
|
||||
|
||||
nm_device_update_link_active (dev, FALSE);
|
||||
}
|
||||
|
||||
/* Check if the device's IP address has changed
|
||||
* (ie dhcp lease renew/address change)
|
||||
/* Wired cards are always up and active, because otherwise we cannot do
|
||||
* link detection on them. A wireless card is only up if it's the active
|
||||
* device, since we only do scanning and link detection on the active device
|
||||
* anyway.
|
||||
*/
|
||||
switch (nm_device_get_iface_type (dev))
|
||||
{
|
||||
case NM_IFACE_TYPE_WIRELESS_ETHERNET:
|
||||
if (dev != data->active_device)
|
||||
{
|
||||
if (nm_device_is_up (dev))
|
||||
nm_device_bring_down (dev);
|
||||
}
|
||||
else
|
||||
nm_device_update_link_active (dev, FALSE);
|
||||
break;
|
||||
|
||||
case NM_IFACE_TYPE_WIRED_ETHERNET:
|
||||
if (!nm_device_is_up (dev))
|
||||
nm_device_bring_up (dev);
|
||||
nm_device_update_link_active (dev, FALSE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (dev == data->active_device)
|
||||
{
|
||||
/* Check if the device's IP address has changed
|
||||
* (ie dhcp lease renew/address change)
|
||||
*/
|
||||
nm_device_update_ip4_address (dev);
|
||||
}
|
||||
}
|
||||
|
||||
element = g_slist_next (element);
|
||||
}
|
||||
|
||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||
}
|
||||
else
|
||||
NM_DEBUG_PRINT( "nm_link_state_monitor() could not acquire device list mutex.\n" );
|
||||
} else NM_DEBUG_PRINT( "nm_link_state_monitor() could not acquire device list mutex.\n" );
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
@@ -496,6 +473,7 @@ static void nm_data_free (NMData *data)
|
||||
g_slist_free (data->dev_list);
|
||||
g_mutex_free (data->dev_list_mutex);
|
||||
nm_device_unref (data->active_device);
|
||||
nm_device_unref (data->pending_device);
|
||||
|
||||
nm_data_allowed_ap_list_free (data);
|
||||
}
|
||||
@@ -613,7 +591,6 @@ int main( int argc, char *argv[] )
|
||||
if (become_daemon)
|
||||
{
|
||||
int child_pid;
|
||||
int dev_null_fd;
|
||||
|
||||
if (chdir ("/") < 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user