From f2f36ffa7b99af758fd63e99bd27353045758910 Mon Sep 17 00:00:00 2001 From: Tambet Ingo Date: Thu, 6 Dec 2007 15:55:52 +0000 Subject: [PATCH] 2007-12-06 Tambet Ingo * src/nm-umts-device.c (real_act_stage1_prepare): Flash the * modem (drop DTR) before doing anything else. (init_modem): Move modem initialization here. * src/nm-serial-device.c (ppp_state_changed): React on pppd * state changes. (nm_serial_device_flash): Implement. * src/ppp-manager/nm-ppp-manager.c (name_owner_changed): Fix the * typoes: the state changes signal is "StateChanged" and not "Status". (ppp_exit_code, ppp_status_changed): Remove the debug output, it's working fine now. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3146 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 13 +++++ src/nm-serial-device.c | 84 +++++++++++++++++++++----------- src/nm-serial-device.h | 2 +- src/nm-umts-device.c | 21 ++++++-- src/ppp-manager/nm-ppp-manager.c | 4 +- src/ppp-manager/nm-pppd-plugin.c | 3 -- 6 files changed, 88 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66697b2b2a..3de3530d59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-12-06 Tambet Ingo + + * src/nm-umts-device.c (real_act_stage1_prepare): Flash the modem (drop DTR) + before doing anything else. + (init_modem): Move modem initialization here. + + * src/nm-serial-device.c (ppp_state_changed): React on pppd state changes. + (nm_serial_device_flash): Implement. + + * src/ppp-manager/nm-ppp-manager.c (name_owner_changed): Fix the typoes: the state + changes signal is "StateChanged" and not "Status". + (ppp_exit_code, ppp_status_changed): Remove the debug output, it's working fine now. + 2007-12-06 Dan Williams * src/supplicant-manager/nm-supplicant-config.c diff --git a/src/nm-serial-device.c b/src/nm-serial-device.c index 969e4c1931..850877674e 100644 --- a/src/nm-serial-device.c +++ b/src/nm-serial-device.c @@ -697,67 +697,93 @@ nm_serial_device_wait_quiet (NMSerialDevice *device, wait_quiet_info_destroy); } +#endif + typedef struct { NMSerialDevice *device; - int current_speed; + speed_t current_speed; NMSerialFlashFn callback; gpointer user_data; } FlashInfo; -static gboolean -flash_done (gpointer user_data) +static speed_t +get_speed (NMSerialDevice *device) { - FlashInfo *info = (FlashInfo *) user_data; + struct termios options; - /* FIXME: Restore the speed */ - info->current_speed; + tcgetattr (NM_SERIAL_DEVICE_GET_PRIVATE (device)->fd, &options); + return cfgetospeed (&options); +} + +static void +set_speed (NMSerialDevice *device, speed_t speed) +{ + struct termios options; + int fd; + + fd = NM_SERIAL_DEVICE_GET_PRIVATE (device)->fd; + tcgetattr (fd, &options); + + cfsetispeed (&options, speed); + cfsetospeed (&options, speed); + + options.c_cflag |= (CLOCAL | CREAD); + tcsetattr (fd, TCSANOW, &options); +} + +static gboolean +flash_done (gpointer data) +{ + FlashInfo *info = (FlashInfo *) data; + + set_speed (info->device, info->current_speed); info->callback (info->device, info->user_data); return FALSE; } -void +guint nm_serial_device_flash (NMSerialDevice *device, guint32 flash_time, NMSerialFlashFn callback, gpointer user_data) { - int fd; - struct termio stbuf; - int speed; FlashInfo *info; - g_return_if_fail (NM_IS_SERIAL_DEVICE (device)); - g_return_if_fail (callback != NULL); - - fd = NM_SERIAL_DEVICE_GET_PRIVATE (device)->fd; - - ioctl (fd, TCGETA, &stbuf); - speed = stbuf.c_cflags & CBAUD; - - /* FIXME: Set speed to 0 */ + g_return_val_if_fail (NM_IS_SERIAL_DEVICE (device), 0); + g_return_val_if_fail (callback != NULL, 0); info = g_new (FlashInfo, 1); info->device = device; - info->current_speed = speed; + info->current_speed = get_speed (device); info->callback = callback; info->user_data = user_data; - g_timeout_add_full (G_PRIORITY_DEFAULT, - flash_time, - flash_done, - info, - g_free); -} + set_speed (device, B0); -#endif + return g_timeout_add_full (G_PRIORITY_DEFAULT, + flash_time, + flash_done, + info, + g_free); +} static void ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) { - nm_debug ("ppp state changed: %d", status); - /* FIXME */ + NMDevice *device = NM_DEVICE (user_data); + + switch (status) { + case NM_PPP_STATUS_NETWORK: + nm_device_state_changed (device, NM_DEVICE_STATE_IP_CONFIG); + break; + case NM_PPP_STATUS_DISCONNECT: + nm_device_state_changed (device, NM_DEVICE_STATE_FAILED); + break; + default: + break; + } } static void diff --git a/src/nm-serial-device.h b/src/nm-serial-device.h index 68e62025f3..782787fa3c 100644 --- a/src/nm-serial-device.h +++ b/src/nm-serial-device.h @@ -67,7 +67,7 @@ void nm_serial_device_wait_quiet (NMSerialDevice *device, NMSerialWaitQuietFn callback, gpointer user_data); -void nm_serial_device_flash (NMSerialDevice *device, +guint nm_serial_device_flash (NMSerialDevice *device, guint32 flash_time, NMSerialFlashFn callback, gpointer user_data); diff --git a/src/nm-umts-device.c b/src/nm-umts-device.c index 684faa2532..d62d6a9757 100644 --- a/src/nm-umts-device.c +++ b/src/nm-umts-device.c @@ -421,20 +421,33 @@ init_done (NMSerialDevice *device, } } +static void +init_modem (NMSerialDevice *device, gpointer user_data) +{ + guint id; + char *responses[] = { "OK", "ERR", NULL }; + + nm_serial_device_send_command_string (device, "ATZ E0"); + id = nm_serial_device_wait_for_reply (device, 10, responses, init_done, NULL); + + if (id) + umts_device_set_pending (NM_UMTS_DEVICE (device), id); + else + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); +} + static NMActStageReturn real_act_stage1_prepare (NMDevice *device) { NMUmtsDevicePrivate *priv = NM_UMTS_DEVICE_GET_PRIVATE (device); NMSerialDevice *serial_device = NM_SERIAL_DEVICE (device); - char *responses[] = { "OK", "ERR", NULL }; priv->need_secret = NM_UMTS_SECRET_NONE; - if (!nm_serial_device_open (NM_SERIAL_DEVICE (device))) + if (!nm_serial_device_open (serial_device)) return NM_ACT_STAGE_RETURN_FAILURE; - nm_serial_device_send_command_string (serial_device, "ATZ E0"); - priv->pending_id = nm_serial_device_wait_for_reply (serial_device, 10, responses, init_done, NULL); + priv->pending_id = nm_serial_device_flash (serial_device, 100, init_modem, NULL); return priv->pending_id ? NM_ACT_STAGE_RETURN_POSTPONE : NM_ACT_STAGE_RETURN_FAILURE; } diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index ed35fd0578..a3b4aef3c9 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -381,8 +381,8 @@ name_owner_changed (NMDBusManager *dbus_manager, NM_DBUS_PATH_PPP, NM_DBUS_INTERFACE_PPP); - dbus_g_proxy_add_signal (priv->proxy, "Status", G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Status", + dbus_g_proxy_add_signal (priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", G_CALLBACK (ppp_status_changed), manager, NULL); diff --git a/src/ppp-manager/nm-pppd-plugin.c b/src/ppp-manager/nm-pppd-plugin.c index 80922304c9..144d086d1d 100644 --- a/src/ppp-manager/nm-pppd-plugin.c +++ b/src/ppp-manager/nm-pppd-plugin.c @@ -197,8 +197,6 @@ nm_phasechange (void *data, int arg) break; } - g_message ("pppd reported new phase: %s", ppp_phase); - if (ppp_status != NM_PPP_STATUS_UNKNOWN) nm_pppd_plugin_state_changed (plugin, ppp_status); } @@ -301,7 +299,6 @@ nm_exit_notify (void *data, int arg) { NMPppdPlugin *plugin = NM_PPPD_PLUGIN (data); - g_message ("exiting"); g_object_unref (plugin); }