huawei: simplify setting allowed mode

This commit is contained in:
Dan Williams
2010-03-16 11:42:57 -07:00
parent 8af469ccad
commit eff1bcc7f3

View File

@@ -168,30 +168,34 @@ set_allowed_mode_done (MMAtSerialPort *port,
} }
static void static void
set_allowed_mode_get_done (MMAtSerialPort *port, set_allowed_mode (MMGenericGsm *gsm,
GString *response, MMModemGsmAllowedMode mode,
GError *error, MMModemFn callback,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info = (MMCallbackInfo *) user_data; MMCallbackInfo *info;
MMAtSerialPort *port, *primary, *secondary;
if (error) { int a, b;
info->error = g_error_copy (error);
mm_callback_info_schedule (info);
} else {
int a, b, u1, u2;
guint32 band;
if (parse_syscfg (MM_MODEM_HUAWEI_GSM (info->modem), response->str, &a, &b, &band, &u1, &u2, NULL)) {
MMModemGsmAllowedMode mode;
char *command; char *command;
mode = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mode")); info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data);
port = primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY);
if (mm_port_get_connected (MM_PORT (primary))) {
secondary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_SECONDARY);
if (!secondary) {
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_CONNECTED,
"Cannot set allowed mode while connected");
mm_callback_info_schedule (info);
return;
}
/* Use secondary port if primary is connected */
port = secondary;
}
g_assert (port);
switch (mode) { switch (mode) {
case MM_MODEM_GSM_ALLOWED_MODE_ANY:
a = 2;
b = 0;
break;
case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY: case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY:
a = 13; a = 13;
b = 1; b = 1;
@@ -208,37 +212,17 @@ set_allowed_mode_get_done (MMAtSerialPort *port,
a = 2; a = 2;
b = 2; b = 2;
break; break;
case MM_MODEM_GSM_ALLOWED_MODE_ANY:
default: default:
a = 2;
b = 0;
break; break;
} }
command = g_strdup_printf ("AT^SYSCFG=%d,%d,%X,%d,%d", a, b, band, u1, u2); command = g_strdup_printf ("AT^SYSCFG=%d,%d,40000000,2,4", a, b);
mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info); mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info);
g_free (command); g_free (command);
} }
}
}
static void
set_allowed_mode (MMGenericGsm *gsm,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMAtSerialPort *primary;
info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data);
mm_callback_info_set_data (info, "mode", GUINT_TO_POINTER (mode), NULL);
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (gsm), MM_PORT_TYPE_PRIMARY);
g_assert (primary);
/* Get current configuration first so we don't change band and other
* stuff when updating the mode.
*/
mm_at_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_allowed_mode_get_done, info);
}
static void static void
get_allowed_mode_done (MMAtSerialPort *port, get_allowed_mode_done (MMAtSerialPort *port,