Merge remote branch 'origin/master' into qcdm
This commit is contained in:
@@ -63,6 +63,9 @@ typedef struct {
|
||||
MMCallbackInfo *connect_pending_data;
|
||||
guint connect_pending_id;
|
||||
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
guint32 auth_idx;
|
||||
} MMModemHsoPrivate;
|
||||
|
||||
@@ -85,6 +88,157 @@ mm_modem_hso_new (const char *device,
|
||||
NULL));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gint
|
||||
hso_get_cid (MMModemHso *self)
|
||||
{
|
||||
gint cid;
|
||||
|
||||
cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self));
|
||||
if (cid < 0) {
|
||||
g_warn_if_fail (cid >= 0);
|
||||
cid = 0;
|
||||
}
|
||||
|
||||
return cid;
|
||||
}
|
||||
|
||||
static void
|
||||
auth_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemHso *self = MM_MODEM_HSO (info->modem);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
|
||||
if (error) {
|
||||
priv->auth_idx++;
|
||||
if (auth_commands[priv->auth_idx]) {
|
||||
/* Try the next auth command */
|
||||
_internal_hso_modem_authenticate (self, info);
|
||||
return;
|
||||
} else
|
||||
info->error = g_error_copy (error);
|
||||
}
|
||||
|
||||
/* Reset to 0 so something gets tried the next connection */
|
||||
priv->auth_idx = 0;
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
_internal_hso_modem_authenticate (MMModemHso *self, MMCallbackInfo *info)
|
||||
{
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
MMAtSerialPort *primary;
|
||||
gint cid;
|
||||
char *command;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
cid = hso_get_cid (self);
|
||||
|
||||
if (!priv->username && !priv->password)
|
||||
command = g_strdup_printf ("%s=%d,0", auth_commands[priv->auth_idx], cid);
|
||||
else {
|
||||
command = g_strdup_printf ("%s=%d,1,\"%s\",\"%s\"",
|
||||
auth_commands[priv->auth_idx],
|
||||
cid,
|
||||
priv->password ? priv->password : "",
|
||||
priv->username ? priv->username : "");
|
||||
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (primary, command, 3, auth_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
void
|
||||
mm_hso_modem_authenticate (MMModemHso *self,
|
||||
const char *username,
|
||||
const char *password,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHsoPrivate *priv;
|
||||
MMCallbackInfo *info;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (MM_IS_MODEM_HSO (self));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
|
||||
g_free (priv->username);
|
||||
priv->username = (username && strlen (username)) ? g_strdup (username) : NULL;
|
||||
|
||||
g_free (priv->password);
|
||||
priv->password = (password && strlen (password)) ? g_strdup (password) : NULL;
|
||||
|
||||
_internal_hso_modem_authenticate (self, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
connect_pending_done (MMModemHso *self)
|
||||
{
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
GError *error = NULL;
|
||||
|
||||
if (priv->connect_pending_data) {
|
||||
if (priv->connect_pending_data->error) {
|
||||
error = priv->connect_pending_data->error;
|
||||
priv->connect_pending_data->error = NULL;
|
||||
}
|
||||
|
||||
/* Complete the connect */
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (self), error, priv->connect_pending_data);
|
||||
priv->connect_pending_data = NULL;
|
||||
}
|
||||
|
||||
if (priv->connect_pending_id) {
|
||||
g_source_remove (priv->connect_pending_id);
|
||||
priv->connect_pending_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
connection_enabled (MMAtSerialPort *port,
|
||||
GMatchInfo *match_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (user_data);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
char *str;
|
||||
|
||||
str = g_match_info_fetch (match_info, 2);
|
||||
if (str[0] == '1')
|
||||
connect_pending_done (self);
|
||||
else if (str[0] == '3') {
|
||||
MMCallbackInfo *info = priv->connect_pending_data;
|
||||
|
||||
if (info) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Call setup failed");
|
||||
}
|
||||
|
||||
connect_pending_done (self);
|
||||
} else if (str[0] == '0') {
|
||||
/* FIXME: disconnected. do something when we have modem status signals */
|
||||
}
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define IGNORE_ERRORS_TAG "ignore-errors"
|
||||
|
||||
static void
|
||||
@@ -101,18 +255,6 @@ hso_call_control_done (MMAtSerialPort *port,
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static guint32
|
||||
hso_get_cid (MMModemHso *self)
|
||||
{
|
||||
guint32 cid;
|
||||
|
||||
cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self));
|
||||
if (cid == 0)
|
||||
cid = 1;
|
||||
|
||||
return cid;
|
||||
}
|
||||
|
||||
static void
|
||||
hso_call_control (MMModemHso *self,
|
||||
gboolean activate,
|
||||
@@ -135,31 +277,30 @@ hso_call_control (MMModemHso *self,
|
||||
}
|
||||
|
||||
static void
|
||||
connect_pending_done (MMModemHso *self)
|
||||
timeout_done (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
|
||||
if (priv->connect_pending_data) {
|
||||
mm_callback_info_schedule (priv->connect_pending_data);
|
||||
priv->connect_pending_data = NULL;
|
||||
}
|
||||
|
||||
if (priv->connect_pending_id) {
|
||||
g_source_remove (priv->connect_pending_id);
|
||||
priv->connect_pending_id = 0;
|
||||
}
|
||||
if (modem)
|
||||
connect_pending_done (MM_MODEM_HSO (modem));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hso_connect_timed_out (gpointer data)
|
||||
{
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (data);
|
||||
MMModemHso *self = MM_MODEM_HSO (data);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info = priv->connect_pending_data;
|
||||
|
||||
priv->connect_pending_data->error = g_error_new_literal (MM_SERIAL_ERROR,
|
||||
MM_SERIAL_RESPONSE_TIMEOUT,
|
||||
"Connection timed out");
|
||||
connect_pending_done (MM_MODEM_HSO (data));
|
||||
priv->connect_pending_id = 0;
|
||||
|
||||
if (info) {
|
||||
info->error = g_error_new_literal (MM_SERIAL_ERROR,
|
||||
MM_SERIAL_RESPONSE_TIMEOUT,
|
||||
"Connection timed out");
|
||||
}
|
||||
|
||||
hso_call_control (self, FALSE, TRUE, timeout_done, self);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -169,33 +310,32 @@ hso_enabled (MMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
GError *tmp_error;
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
mm_callback_info_schedule (info);
|
||||
tmp_error = mm_modem_check_removed (modem, error);
|
||||
if (tmp_error) {
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), tmp_error, info);
|
||||
g_clear_error (&tmp_error);
|
||||
} else {
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (modem);
|
||||
GSource *source;
|
||||
|
||||
source = g_timeout_source_new_seconds (30);
|
||||
g_source_set_closure (source, g_cclosure_new_object (G_CALLBACK (hso_connect_timed_out), G_OBJECT (modem)));
|
||||
g_source_attach (source, NULL);
|
||||
priv->connect_pending_data = info;
|
||||
priv->connect_pending_id = g_source_get_id (source);
|
||||
g_source_unref (source);
|
||||
priv->connect_pending_id = g_timeout_add_seconds (30, hso_connect_timed_out, modem);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clear_old_context (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
old_context_clear_done (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
GError *tmp_error;
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
mm_callback_info_schedule (info);
|
||||
tmp_error = mm_modem_check_removed (modem, error);
|
||||
if (tmp_error) {
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), tmp_error, info);
|
||||
g_clear_error (&tmp_error);
|
||||
} else {
|
||||
/* Success, activate the PDP context and start the data session */
|
||||
hso_call_control (MM_MODEM_HSO (modem), TRUE, FALSE, hso_enabled, info);
|
||||
@@ -203,86 +343,38 @@ clear_old_context (MMModem *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
auth_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
connect_auth_done (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemHso *self = MM_MODEM_HSO (info->modem);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
GError *tmp_error;
|
||||
|
||||
if (error) {
|
||||
priv->auth_idx++;
|
||||
if (auth_commands[priv->auth_idx]) {
|
||||
/* Try the next auth command */
|
||||
_internal_hso_modem_authenticate (self, info);
|
||||
} else {
|
||||
/* Reset to 0 so that something gets tried for the next connection */
|
||||
priv->auth_idx = 0;
|
||||
|
||||
info->error = g_error_copy (error);
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
tmp_error = mm_modem_check_removed (modem, error);
|
||||
if (tmp_error) {
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), tmp_error, info);
|
||||
g_clear_error (&tmp_error);
|
||||
} else {
|
||||
priv->auth_idx = 0;
|
||||
|
||||
/* success, kill any existing connections first */
|
||||
hso_call_control (self, FALSE, TRUE, clear_old_context, info);
|
||||
/* Now connect; kill any existing connections first */
|
||||
hso_call_control (MM_MODEM_HSO (modem), FALSE, TRUE, old_context_clear_done, info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_internal_hso_modem_authenticate (MMModemHso *self, MMCallbackInfo *info)
|
||||
do_connect (MMModem *modem,
|
||||
const char *number,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (modem);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
MMAtSerialPort *primary;
|
||||
guint32 cid;
|
||||
char *command;
|
||||
const char *username, *password;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
cid = hso_get_cid (self);
|
||||
|
||||
username = mm_callback_info_get_data (info, "username");
|
||||
password = mm_callback_info_get_data (info, "password");
|
||||
|
||||
if (!username && !password)
|
||||
command = g_strdup_printf ("%s=%d,0", auth_commands[priv->auth_idx], cid);
|
||||
else {
|
||||
command = g_strdup_printf ("%s=%d,1,\"%s\",\"%s\"",
|
||||
auth_commands[priv->auth_idx],
|
||||
cid,
|
||||
password ? password : "",
|
||||
username ? username : "");
|
||||
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (primary, command, 3, auth_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
void
|
||||
mm_hso_modem_authenticate (MMModemHso *self,
|
||||
const char *username,
|
||||
const char *password,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
|
||||
g_return_if_fail (MM_IS_MODEM_HSO (self));
|
||||
g_return_if_fail (callback != NULL);
|
||||
mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
if (username)
|
||||
mm_callback_info_set_data (info, "username", g_strdup (username), g_free);
|
||||
if (password)
|
||||
mm_callback_info_set_data (info, "password", g_strdup (password), g_free);
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
|
||||
_internal_hso_modem_authenticate (self, info);
|
||||
mm_hso_modem_authenticate (self, priv->username, priv->password, connect_auth_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -315,9 +407,16 @@ disable (MMModem *modem,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (modem);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info;
|
||||
|
||||
mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (modem));
|
||||
mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (self));
|
||||
|
||||
g_free (priv->username);
|
||||
priv->username = NULL;
|
||||
g_free (priv->password);
|
||||
priv->password = NULL;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
|
||||
@@ -325,18 +424,7 @@ disable (MMModem *modem,
|
||||
hso_call_control (MM_MODEM_HSO (modem), FALSE, TRUE, disable_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
do_connect (MMModem *modem,
|
||||
const char *number,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
free_dns_array (gpointer data)
|
||||
@@ -366,7 +454,7 @@ get_ip4_config_done (MMAtSerialPort *port,
|
||||
GArray *dns_array;
|
||||
int i;
|
||||
guint32 tmp;
|
||||
guint cid;
|
||||
gint cid;
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
@@ -387,7 +475,7 @@ get_ip4_config_done (MMAtSerialPort *port,
|
||||
|
||||
errno = 0;
|
||||
num = strtol (*iter, NULL, 10);
|
||||
if (errno != 0 || num < 0 || (guint) num != cid) {
|
||||
if (errno != 0 || num < 0 || (gint) num != cid) {
|
||||
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Unknown CID in OWANDATA response ("
|
||||
"got %d, expected %d)", (guint) num, cid);
|
||||
@@ -429,18 +517,35 @@ get_ip4_config (MMModem *modem,
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
disconnect (MMModem *modem,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
disconnect_owancall_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_callback_info_schedule ((MMCallbackInfo *) user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
do_disconnect (MMGenericGsm *gsm,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *primary;
|
||||
char *command;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data);
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_at_serial_port_queue_command (primary, "AT_OWANCALL=1,0,0", 3, NULL, info);
|
||||
|
||||
command = g_strdup_printf ("AT_OWANCALL=%d,0,0", cid);
|
||||
mm_at_serial_port_queue_command (primary, command, 3, disconnect_owancall_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -473,47 +578,11 @@ impl_hso_authenticate (MMModemHso *self,
|
||||
mm_hso_modem_authenticate (self, username, password, impl_hso_auth_done, context);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_enabled (MMAtSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (user_data);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
char *str;
|
||||
|
||||
str = g_match_info_fetch (info, 2);
|
||||
if (str[0] == '1')
|
||||
connect_pending_done (self);
|
||||
else if (str[0] == '3') {
|
||||
MMCallbackInfo *cb_info = priv->connect_pending_data;
|
||||
|
||||
if (cb_info)
|
||||
cb_info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Call setup failed");
|
||||
|
||||
connect_pending_done (self);
|
||||
} else if (str[0] == '0')
|
||||
/* FIXME: disconnected. do something when we have modem status signals */
|
||||
;
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MMModemSimple interface */
|
||||
|
||||
typedef enum {
|
||||
SIMPLE_STATE_BEGIN = 0,
|
||||
SIMPLE_STATE_PARENT_CONNECT,
|
||||
SIMPLE_STATE_AUTHENTICATE,
|
||||
SIMPLE_STATE_DONE
|
||||
} SimpleState;
|
||||
|
||||
static const char *
|
||||
simple_get_string_property (MMCallbackInfo *info, const char *name, GError **error)
|
||||
hso_simple_get_string_property (GHashTable *properties, const char *name, GError **error)
|
||||
{
|
||||
GHashTable *properties = (GHashTable *) mm_callback_info_get_data (info, "simple-connect-properties");
|
||||
GValue *value;
|
||||
|
||||
value = (GValue *) g_hash_table_lookup (properties, name);
|
||||
@@ -530,61 +599,21 @@ simple_get_string_property (MMCallbackInfo *info, const char *name, GError **err
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemSimple *parent_iface;
|
||||
const char *username;
|
||||
const char *password;
|
||||
GHashTable *properties = (GHashTable *) mm_callback_info_get_data (info, "simple-connect-properties");
|
||||
SimpleState state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "simple-connect-state"));
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case SIMPLE_STATE_BEGIN:
|
||||
state = SIMPLE_STATE_PARENT_CONNECT;
|
||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (modem));
|
||||
parent_iface->connect (MM_MODEM_SIMPLE (modem), properties, simple_state_machine, info);
|
||||
break;
|
||||
case SIMPLE_STATE_PARENT_CONNECT:
|
||||
state = SIMPLE_STATE_AUTHENTICATE;
|
||||
username = simple_get_string_property (info, "username", &info->error);
|
||||
password = simple_get_string_property (info, "password", &info->error);
|
||||
mm_hso_modem_authenticate (MM_MODEM_HSO (modem), username, password, simple_state_machine, info);
|
||||
break;
|
||||
case SIMPLE_STATE_AUTHENTICATE:
|
||||
state = SIMPLE_STATE_DONE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
if (info->error || state == SIMPLE_STATE_DONE)
|
||||
mm_callback_info_schedule (info);
|
||||
else
|
||||
mm_callback_info_set_data (info, "simple-connect-state", GUINT_TO_POINTER (state), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
simple_connect (MMModemSimple *simple,
|
||||
GHashTable *properties,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (simple);
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemSimple *parent_iface;
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (simple), callback, user_data);
|
||||
mm_callback_info_set_data (info, "simple-connect-properties",
|
||||
g_hash_table_ref (properties),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
priv->username = g_strdup (hso_simple_get_string_property (properties, "username", NULL));
|
||||
priv->password = g_strdup (hso_simple_get_string_property (properties, "password", NULL));
|
||||
|
||||
simple_state_machine (MM_MODEM (simple), NULL, info);
|
||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple));
|
||||
parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -679,15 +708,20 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->disable = disable;
|
||||
modem_class->connect = do_connect;
|
||||
modem_class->get_ip4_config = get_ip4_config;
|
||||
modem_class->disconnect = disconnect;
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (object);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
|
||||
/* Clear the pending connection if necessary */
|
||||
connect_pending_done (MM_MODEM_HSO (object));
|
||||
connect_pending_done (self);
|
||||
|
||||
g_free (priv->username);
|
||||
g_free (priv->password);
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_hso_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -696,11 +730,13 @@ static void
|
||||
mm_modem_hso_class_init (MMModemHsoClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
|
||||
|
||||
mm_modem_hso_parent_class = g_type_class_peek_parent (klass);
|
||||
g_type_class_add_private (object_class, sizeof (MMModemHsoPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->finalize = finalize;
|
||||
gsm_class->do_disconnect = do_disconnect;
|
||||
}
|
||||
|
||||
|
@@ -494,23 +494,18 @@ do_connect (MMModem *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect (MMModem *modem,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
do_disconnect (MMGenericGsm *gsm,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
mm_modem_set_state (modem, MM_MODEM_STATE_DISCONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_at_serial_port_queue_command (primary, "*ENAP=0", 3, NULL, NULL);
|
||||
|
||||
mm_generic_gsm_update_enabled_state (MM_GENERIC_GSM (modem), FALSE, MM_MODEM_STATE_REASON_NONE);
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_callback_info_schedule (info);
|
||||
MM_GENERIC_GSM_CLASS (mm_modem_mbm_parent_class)->do_disconnect (gsm, cid, callback, user_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -838,7 +833,6 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->grab_port = grab_port;
|
||||
modem_class->disable = disable;
|
||||
modem_class->connect = do_connect;
|
||||
modem_class->disconnect = disconnect;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -872,6 +866,7 @@ mm_modem_mbm_class_init (MMModemMbmClass *klass)
|
||||
object_class->finalize = finalize;
|
||||
|
||||
gsm_class->do_enable = do_enable;
|
||||
gsm_class->do_disconnect = do_disconnect;
|
||||
gsm_class->get_allowed_mode = get_allowed_mode;
|
||||
gsm_class->set_allowed_mode = set_allowed_mode;
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ typedef struct {
|
||||
guint signal_quality_id;
|
||||
time_t signal_quality_timestamp;
|
||||
guint32 signal_quality;
|
||||
guint32 cid;
|
||||
gint cid;
|
||||
|
||||
MMAtSerialPort *primary;
|
||||
MMAtSerialPort *secondary;
|
||||
@@ -142,15 +142,7 @@ mm_generic_gsm_new (const char *device,
|
||||
NULL));
|
||||
}
|
||||
|
||||
void
|
||||
mm_generic_gsm_set_cid (MMGenericGsm *modem, guint32 cid)
|
||||
{
|
||||
g_return_if_fail (MM_IS_GENERIC_GSM (modem));
|
||||
|
||||
MM_GENERIC_GSM_GET_PRIVATE (modem)->cid = cid;
|
||||
}
|
||||
|
||||
guint32
|
||||
gint
|
||||
mm_generic_gsm_get_cid (MMGenericGsm *modem)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_GENERIC_GSM (modem), 0);
|
||||
@@ -822,7 +814,7 @@ enable (MMModem *modem,
|
||||
}
|
||||
|
||||
/* First, reset the previously used CID */
|
||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
||||
priv->cid = -1;
|
||||
|
||||
if (!mm_serial_port_open (MM_SERIAL_PORT (priv->primary), &error)) {
|
||||
MMCallbackInfo *info;
|
||||
@@ -908,7 +900,9 @@ disable (MMModem *modem,
|
||||
MMModemState state;
|
||||
|
||||
/* First, reset the previously used CID and clean up registration */
|
||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
||||
g_warn_if_fail (priv->cid == -1);
|
||||
priv->cid = -1;
|
||||
|
||||
mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (modem));
|
||||
|
||||
if (priv->poll_id) {
|
||||
@@ -1924,16 +1918,16 @@ connect (MMModem *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_flash_done (MMSerialPort *port,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
disconnect_done (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemState prev_state;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
info->error = mm_modem_check_removed (modem, error);
|
||||
if (info->error) {
|
||||
if (info->modem) {
|
||||
if (info->modem && modem) {
|
||||
/* Reset old state since the operation failed */
|
||||
prev_state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, MM_GENERIC_GSM_PREV_STATE_TAG));
|
||||
mm_modem_set_state (MM_MODEM (info->modem),
|
||||
@@ -1941,28 +1935,77 @@ disconnect_flash_done (MMSerialPort *port,
|
||||
MM_MODEM_STATE_REASON_NONE);
|
||||
}
|
||||
} else {
|
||||
MMGenericGsm *self = MM_GENERIC_GSM (info->modem);
|
||||
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
|
||||
mm_port_set_connected (priv->data, FALSE);
|
||||
priv->cid = -1;
|
||||
mm_generic_gsm_update_enabled_state (self, FALSE, MM_MODEM_STATE_REASON_NONE);
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_cgact_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_callback_info_schedule ((MMCallbackInfo *) user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_flash_done (MMSerialPort *port,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMGenericGsmPrivate *priv;
|
||||
char *command;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Disconnect the PDP context */
|
||||
priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
|
||||
if (priv->cid >= 0)
|
||||
command = g_strdup_printf ("+CGACT=0,%d", priv->cid);
|
||||
else {
|
||||
/* Disable all PDP contexts */
|
||||
command = g_strdup_printf ("+CGACT=0");
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port), command, 60, disconnect_cgact_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static void
|
||||
real_do_disconnect (MMGenericGsm *self,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
mm_serial_port_flash (MM_SERIAL_PORT (priv->primary), 1000, disconnect_flash_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect (MMModem *modem,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
||||
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info;
|
||||
MMModemState state;
|
||||
|
||||
/* First, reset the previously used CID */
|
||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
|
||||
/* Cache the previous state so we can reset it if the operation fails */
|
||||
@@ -1973,7 +2016,9 @@ disconnect (MMModem *modem,
|
||||
NULL);
|
||||
|
||||
mm_modem_set_state (modem, MM_MODEM_STATE_DISCONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||
mm_serial_port_flash (MM_SERIAL_PORT (priv->primary), 1000, disconnect_flash_done, info);
|
||||
|
||||
g_assert (MM_GENERIC_GSM_GET_CLASS (self)->do_disconnect);
|
||||
MM_GENERIC_GSM_GET_CLASS (self)->do_disconnect (self, priv->cid, disconnect_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2025,6 +2070,8 @@ scan (MMModemGsmNetwork *modem,
|
||||
|
||||
/* SetApn */
|
||||
|
||||
#define APN_CID_TAG "generic-gsm-cid"
|
||||
|
||||
static void
|
||||
set_apn_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
@@ -2033,11 +2080,12 @@ set_apn_done (MMAtSerialPort *port,
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
if (error)
|
||||
info->error = g_error_copy (error);
|
||||
else
|
||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (info->modem),
|
||||
GPOINTER_TO_UINT (mm_callback_info_get_data (info, "cid")));
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (!info->error) {
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
|
||||
|
||||
priv->cid = GPOINTER_TO_INT (mm_callback_info_get_data (info, APN_CID_TAG));
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
@@ -2100,7 +2148,7 @@ cid_range_read (MMAtSerialPort *port,
|
||||
const char *apn = (const char *) mm_callback_info_get_data (info, "apn");
|
||||
char *command;
|
||||
|
||||
mm_callback_info_set_data (info, "cid", GUINT_TO_POINTER (cid), NULL);
|
||||
mm_callback_info_set_data (info, APN_CID_TAG, GINT_TO_POINTER (cid), NULL);
|
||||
|
||||
command = g_strdup_printf ("+CGDCONT=%d,\"IP\",\"%s\"", cid, apn);
|
||||
mm_at_serial_port_queue_command (port, command, 3, set_apn_done, info);
|
||||
@@ -2117,8 +2165,9 @@ existing_apns_read (MMAtSerialPort *port,
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
gboolean found = FALSE;
|
||||
|
||||
if (error)
|
||||
info->error = g_error_copy (error);
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error)
|
||||
goto done;
|
||||
else if (g_str_has_prefix (response->str, "+CGDCONT: ")) {
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
@@ -2142,7 +2191,7 @@ existing_apns_read (MMAtSerialPort *port,
|
||||
apn = g_match_info_fetch (match_info, 3);
|
||||
|
||||
if (!strcmp (apn, new_apn)) {
|
||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (info->modem), (guint32) num_cid);
|
||||
MM_GENERIC_GSM_GET_PRIVATE (info->modem)->cid = num_cid;
|
||||
found = TRUE;
|
||||
}
|
||||
|
||||
@@ -2170,11 +2219,13 @@ existing_apns_read (MMAtSerialPort *port,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Could not parse the response");
|
||||
|
||||
done:
|
||||
if (found || info->error)
|
||||
mm_callback_info_schedule (info);
|
||||
else
|
||||
else {
|
||||
/* APN not configured on the card. Get the allowed CID range */
|
||||
mm_at_serial_port_queue_command_cached (port, "+CGDCONT=?", 3, cid_range_read, info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2988,6 +3039,7 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass)
|
||||
|
||||
klass->do_enable = real_do_enable;
|
||||
klass->do_enable_power_up_done = real_do_enable_power_up_done;
|
||||
klass->do_disconnect = real_do_disconnect;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_override_property (object_class,
|
||||
|
@@ -79,6 +79,14 @@ typedef struct {
|
||||
GError *error,
|
||||
MMCallbackInfo *info);
|
||||
|
||||
/* Called to terminate the active data call and deactivate the given PDP
|
||||
* context.
|
||||
*/
|
||||
void (*do_disconnect) (MMGenericGsm *self,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
/* Called by the generic class to set the allowed operating mode of the device */
|
||||
void (*set_allowed_mode) (MMGenericGsm *self,
|
||||
MMModemGsmAllowedMode mode,
|
||||
@@ -110,10 +118,8 @@ MMModem *mm_generic_gsm_new (const char *device,
|
||||
|
||||
void mm_generic_gsm_pending_registration_stop (MMGenericGsm *modem);
|
||||
|
||||
void mm_generic_gsm_set_cid (MMGenericGsm *modem,
|
||||
guint32 cid);
|
||||
gint mm_generic_gsm_get_cid (MMGenericGsm *modem);
|
||||
|
||||
guint32 mm_generic_gsm_get_cid (MMGenericGsm *modem);
|
||||
void mm_generic_gsm_set_reg_status (MMGenericGsm *modem,
|
||||
MMModemGsmNetworkRegStatus status);
|
||||
|
||||
|
Reference in New Issue
Block a user