icera: add complete support for generic Icera devices
Implement connect, disconnect, and IP4 config stuff. Also fix handling of Icera private data. After creation we need to use MM_MODEM_ICERA_GET_INTERFACE(m)->priv to get the private data instead of just dereferencing the MMModemIcera, for reasons that I don't know. If this isn't done, data gets silently corrupted because writes to the private data are going into a random location in the object. This a side-effect of the slightly hack-ish way that MMModemIcera is a GInterface with private data.
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
******************************************/
|
||||
|
||||
#include <config.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "mm-modem-icera.h"
|
||||
|
||||
@@ -31,6 +33,19 @@
|
||||
#include "mm-generic-gsm.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
|
||||
struct _MMModemIceraPrivate {
|
||||
/* Pending connection attempt */
|
||||
MMCallbackInfo *connect_pending_data;
|
||||
guint connect_pending_id;
|
||||
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
MMModemGsmAccessTech last_act;
|
||||
};
|
||||
|
||||
#define MM_MODEM_ICERA_GET_PRIVATE(m) (MM_MODEM_ICERA_GET_INTERFACE(m)->priv)
|
||||
|
||||
static void
|
||||
get_allowed_mode_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
@@ -195,31 +210,16 @@ nwstate_changed (MMAtSerialPort *port,
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
self->last_act = act;
|
||||
MM_MODEM_ICERA_GET_PRIVATE (self)->last_act = act;
|
||||
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self,
|
||||
MMAtSerialPort *port)
|
||||
static void
|
||||
pacsp_received (MMAtSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
GRegex *regex;
|
||||
|
||||
/* %NWSTATE: <rssi>,<mccmnc>,<tech>,<connected>,<regulation> */
|
||||
regex = g_regex_new ("\\r\\n%NWSTATE:\\s*(\\d+),(\\d+),([^,]*),([^,]*),(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, nwstate_changed, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_change_unsolicited_messages (MMModemIcera *self, gboolean enabled)
|
||||
{
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
mm_at_serial_port_queue_command (primary, enabled ? "%NWSTATE=1" : "%NWSTATE=0", 3, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -233,12 +233,13 @@ get_nwstate_done (MMAtSerialPort *port,
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (!info->error) {
|
||||
MMModemIcera *self = MM_MODEM_ICERA (info->modem);
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
|
||||
/* The unsolicited message handler will already have run and
|
||||
* removed the NWSTATE response, so we have to work around that.
|
||||
*/
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (self->last_act), NULL);
|
||||
self->last_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->last_act), NULL);
|
||||
priv->last_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
@@ -263,11 +264,444 @@ mm_modem_icera_get_access_technology (MMModemIcera *self,
|
||||
mm_at_serial_port_queue_command (port, "%NWSTATE=1", 3, get_nwstate_done, info);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static void
|
||||
icera_check_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
disconnect_ipdpact_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_callback_info_schedule ((MMCallbackInfo *) user_data);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_do_disconnect (MMGenericGsm *gsm,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *primary;
|
||||
char *command;
|
||||
|
||||
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);
|
||||
|
||||
command = g_strdup_printf ("%%IPDPACT=%d,0", cid);
|
||||
mm_at_serial_port_queue_command (primary, command, 3, disconnect_ipdpact_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
connect_pending_done (MMModemIcera *self)
|
||||
{
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_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
|
||||
icera_disconnect_done (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_message ("Modem signaled disconnection from the network");
|
||||
}
|
||||
|
||||
static void
|
||||
connection_enabled (MMAtSerialPort *port,
|
||||
GMatchInfo *match_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemIcera *self = MM_MODEM_ICERA (user_data);
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info = priv->connect_pending_data;
|
||||
char *str;
|
||||
int status, cid, tmp;
|
||||
|
||||
cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self));
|
||||
if (cid < 0)
|
||||
return;
|
||||
|
||||
str = g_match_info_fetch (match_info, 1);
|
||||
g_return_if_fail (str != NULL);
|
||||
tmp = atoi (str);
|
||||
g_free (str);
|
||||
|
||||
/* Make sure the unsolicited message's CID matches the current CID */
|
||||
if (tmp != cid)
|
||||
return;
|
||||
|
||||
str = g_match_info_fetch (match_info, 2);
|
||||
g_return_if_fail (str != NULL);
|
||||
status = atoi (str);
|
||||
g_free (str);
|
||||
|
||||
switch (status) {
|
||||
case 0:
|
||||
/* Disconnected */
|
||||
if (mm_modem_get_state (MM_MODEM (self)) >= MM_MODEM_STATE_CONNECTED)
|
||||
mm_modem_disconnect (MM_MODEM (self), icera_disconnect_done, NULL);
|
||||
break;
|
||||
case 1:
|
||||
/* Connected */
|
||||
connect_pending_done (self);
|
||||
break;
|
||||
case 2:
|
||||
/* Connecting */
|
||||
break;
|
||||
case 3:
|
||||
/* Call setup failure? */
|
||||
if (info) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Call setup failed");
|
||||
}
|
||||
connect_pending_done (self);
|
||||
break;
|
||||
default:
|
||||
g_warning ("Unknown Icera connect status %d", status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static gint
|
||||
_get_cid (MMModemIcera *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
|
||||
icera_call_control (MMModemIcera *self,
|
||||
gboolean activate,
|
||||
MMAtSerialResponseFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
char *command;
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
command = g_strdup_printf ("%%IPDPACT=%d,%d", _get_cid (self), activate ? 1 : 0);
|
||||
mm_at_serial_port_queue_command (primary, command, 3, callback, user_data);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static void
|
||||
timeout_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
connect_pending_done (MM_MODEM_ICERA (user_data));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
icera_connect_timed_out (gpointer data)
|
||||
{
|
||||
MMModemIcera *self = MM_MODEM_ICERA (data);
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info = priv->connect_pending_data;
|
||||
|
||||
priv->connect_pending_id = 0;
|
||||
|
||||
if (info) {
|
||||
info->error = g_error_new_literal (MM_SERIAL_ERROR,
|
||||
MM_SERIAL_ERROR_RESPONSE_TIMEOUT,
|
||||
"Connection timed out");
|
||||
}
|
||||
|
||||
icera_call_control (self, FALSE, timeout_done, self);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
icera_enabled (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
if (error) {
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||
} else {
|
||||
MMModemIcera *self = MM_MODEM_ICERA (info->modem);
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
|
||||
g_warn_if_fail (priv->connect_pending_id == 0);
|
||||
if (priv->connect_pending_id)
|
||||
g_source_remove (priv->connect_pending_id);
|
||||
|
||||
priv->connect_pending_data = info;
|
||||
priv->connect_pending_id = g_timeout_add_seconds (30, icera_connect_timed_out, self);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
old_context_clear_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
/* Activate the PDP context and start the data session */
|
||||
icera_call_control (MM_MODEM_ICERA (info->modem), TRUE, icera_enabled, info);
|
||||
}
|
||||
|
||||
static void
|
||||
auth_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
if (error)
|
||||
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||
else {
|
||||
/* Ensure the PDP context is deactivated */
|
||||
icera_call_control (MM_MODEM_ICERA (info->modem), FALSE, old_context_clear_done, info);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_do_connect (MMModemIcera *self,
|
||||
const char *number,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModem *modem = MM_MODEM (self);
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *primary;
|
||||
gint cid;
|
||||
char *command;
|
||||
|
||||
mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
cid = _get_cid (self);
|
||||
|
||||
|
||||
/* Both user and password are required; otherwise firmware returns an error */
|
||||
if (!priv->username || !priv->password)
|
||||
command = g_strdup_printf ("%%IPDPCFG=%d,0,0,\"\",\"\"", cid);
|
||||
else {
|
||||
command = g_strdup_printf ("%%IPDPCFG=%d,0,1,\"%s\",\"%s\"",
|
||||
cid,
|
||||
priv->password ? priv->password : "",
|
||||
priv->username ? priv->username : "");
|
||||
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (primary, command, 3, auth_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
||||
static void
|
||||
free_dns_array (gpointer data)
|
||||
{
|
||||
g_array_free ((GArray *) data, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
ip4_config_invoke (MMCallbackInfo *info)
|
||||
{
|
||||
MMModemIp4Fn callback = (MMModemIp4Fn) info->callback;
|
||||
|
||||
callback (info->modem,
|
||||
GPOINTER_TO_UINT (mm_callback_info_get_data (info, "ip4-address")),
|
||||
(GArray *) mm_callback_info_get_data (info, "ip4-dns"),
|
||||
info->error, info->user_data);
|
||||
}
|
||||
|
||||
#define IPDPADDR_TAG "%IPDPADDR: "
|
||||
|
||||
static void
|
||||
get_ip4_config_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
char **items, **iter;
|
||||
GArray *dns_array;
|
||||
int i;
|
||||
guint32 tmp;
|
||||
gint cid;
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
goto out;
|
||||
} else if (!g_str_has_prefix (response->str, IPDPADDR_TAG)) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Retrieving failed: invalid response.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
cid = _get_cid (MM_MODEM_ICERA (info->modem));
|
||||
dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2);
|
||||
|
||||
/* %IPDPADDR: <cid>,<ip>,<gw>,<dns1>,<dns2>[,<nbns1>,<nbns2>] */
|
||||
items = g_strsplit (response->str + strlen (IPDPADDR_TAG), ", ", 0);
|
||||
|
||||
for (iter = items, i = 0; *iter; iter++, i++) {
|
||||
if (i == 0) { /* CID */
|
||||
long int num;
|
||||
|
||||
errno = 0;
|
||||
num = strtol (*iter, NULL, 10);
|
||||
if (errno != 0 || num < 0 || (gint) num != cid) {
|
||||
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Unknown CID in IPDPADDR response ("
|
||||
"got %d, expected %d)", (guint) num, cid);
|
||||
break;
|
||||
}
|
||||
} else if (i == 1) { /* IP address */
|
||||
if (inet_pton (AF_INET, *iter, &tmp) > 0)
|
||||
mm_callback_info_set_data (info, "ip4-address", GUINT_TO_POINTER (tmp), NULL);
|
||||
} else if (i == 3) { /* DNS 1 */
|
||||
if (inet_pton (AF_INET, *iter, &tmp) > 0)
|
||||
g_array_append_val (dns_array, tmp);
|
||||
} else if (i == 4) { /* DNS 2 */
|
||||
if (inet_pton (AF_INET, *iter, &tmp) > 0)
|
||||
g_array_append_val (dns_array, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (items);
|
||||
mm_callback_info_set_data (info, "ip4-dns", dns_array, free_dns_array);
|
||||
|
||||
out:
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_get_ip4_config (MMModemIcera *self,
|
||||
MMModemIp4Fn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
char *command;
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new_full (MM_MODEM (self),
|
||||
ip4_config_invoke,
|
||||
G_CALLBACK (callback),
|
||||
user_data);
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
command = g_strdup_printf ("%%IPDPADDR=%d", _get_cid (self));
|
||||
mm_at_serial_port_queue_command (primary, command, 3, get_ip4_config_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static const char *
|
||||
get_string_property (GHashTable *properties, const char *name)
|
||||
{
|
||||
GValue *value;
|
||||
|
||||
value = (GValue *) g_hash_table_lookup (properties, name);
|
||||
if (value && G_VALUE_HOLDS_STRING (value))
|
||||
return g_value_get_string (value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_simple_connect (MMModemIcera *self, GHashTable *properties)
|
||||
{
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
|
||||
g_free (priv->username);
|
||||
priv->username = g_strdup (get_string_property (properties, "username"));
|
||||
g_free (priv->password);
|
||||
priv->password = g_strdup (get_string_property (properties, "password"));
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
void
|
||||
mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self,
|
||||
MMAtSerialPort *port)
|
||||
{
|
||||
GRegex *regex;
|
||||
|
||||
/* %NWSTATE: <rssi>,<mccmnc>,<tech>,<connected>,<regulation> */
|
||||
regex = g_regex_new ("\\r\\n%NWSTATE:\\s*(\\d+),(\\d+),([^,]*),([^,]*),(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, nwstate_changed, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\+PACSP(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, pacsp_received, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* %IPDPACT: <cid>,<status>,0 */
|
||||
regex = g_regex_new ("\\r\\n%IPDPACT:\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, connection_enabled, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_change_unsolicited_messages (MMModemIcera *self, gboolean enabled)
|
||||
{
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
mm_at_serial_port_queue_command (primary, enabled ? "%NWSTATE=1" : "%NWSTATE=0", 3, NULL, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static void
|
||||
is_icera_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = user_data;
|
||||
|
||||
@@ -278,29 +712,45 @@ icera_check_done (MMAtSerialPort *port,
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_is_icera (MMGenericGsm *modem,
|
||||
mm_modem_icera_is_icera (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMAtSerialPort *port;
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
port = mm_generic_gsm_get_best_at_port (modem, &info->error);
|
||||
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error);
|
||||
if (!port) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 5, icera_check_done, info);
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 5, is_icera_done, info);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
void
|
||||
mm_modem_icera_dispose (MMModemIcera *self)
|
||||
mm_modem_icera_prepare (MMModemIcera *self)
|
||||
{
|
||||
self->priv = g_malloc0 (sizeof (MMModemIceraPrivate));
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_cleanup (MMModemIcera *self)
|
||||
{
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
|
||||
/* Clear the pending connection if necessary */
|
||||
connect_pending_done (self);
|
||||
|
||||
g_free (priv->username);
|
||||
g_free (priv->password);
|
||||
|
||||
memset (priv, 0, sizeof (MMModemIceraPrivate));
|
||||
g_free (priv);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -335,9 +785,7 @@ mm_modem_icera_get_type (void)
|
||||
"MMModemIcera",
|
||||
&icera_info, 0);
|
||||
|
||||
g_type_interface_add_prerequisite (icera_type, G_TYPE_OBJECT);
|
||||
g_type_interface_add_prerequisite (icera_type, MM_TYPE_MODEM);
|
||||
g_type_interface_add_prerequisite (icera_type, MM_TYPE_GENERIC_GSM);
|
||||
}
|
||||
|
||||
return icera_type;
|
||||
|
@@ -30,17 +30,21 @@
|
||||
#define MM_IS_MODEM_ICERA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ICERA))
|
||||
#define MM_MODEM_ICERA_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_ICERA, MMModemIcera))
|
||||
|
||||
typedef struct _MMModemIceraPrivate MMModemIceraPrivate;
|
||||
|
||||
typedef struct _MMModemIcera MMModemIcera;
|
||||
|
||||
struct _MMModemIcera {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
MMModemGsmAccessTech last_act;
|
||||
MMModemIceraPrivate *priv;
|
||||
};
|
||||
|
||||
GType mm_modem_icera_get_type (void);
|
||||
|
||||
void mm_modem_icera_dispose (MMModemIcera *self);
|
||||
void mm_modem_icera_prepare (MMModemIcera *self);
|
||||
|
||||
void mm_modem_icera_cleanup (MMModemIcera *self);
|
||||
|
||||
void mm_modem_icera_get_allowed_mode (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
@@ -61,9 +65,25 @@ void mm_modem_icera_get_access_technology (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_icera_is_icera (MMGenericGsm *modem,
|
||||
void mm_modem_icera_is_icera (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_icera_do_disconnect (MMGenericGsm *gsm,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_icera_simple_connect (MMModemIcera *self, GHashTable *properties);
|
||||
|
||||
void mm_modem_icera_do_connect (MMModemIcera *self,
|
||||
const char *number,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_icera_get_ip4_config (MMModemIcera *self,
|
||||
MMModemIp4Fn callback,
|
||||
gpointer user_data);
|
||||
|
||||
#endif /* MM_MODEM_ICERA_H */
|
||||
|
||||
|
@@ -24,14 +24,17 @@
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-simple.h"
|
||||
#include "mm-modem-icera.h"
|
||||
|
||||
static void modem_init (MMModem *modem_class);
|
||||
static void modem_icera_init (MMModemIcera *icera_class);
|
||||
static void modem_simple_init (MMModemSimple *simple_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMModemZte, mm_modem_zte, MM_TYPE_GENERIC_GSM, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_ICERA, modem_icera_init))
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_ICERA, modem_icera_init)
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_SIMPLE, modem_simple_init))
|
||||
|
||||
#define MM_MODEM_ZTE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_ZTE, MMModemZtePrivate))
|
||||
|
||||
@@ -288,6 +291,21 @@ get_access_technology (MMGenericGsm *gsm,
|
||||
mm_at_serial_port_queue_command (port, "+ZPAS?", 3, get_act_request_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
do_disconnect (MMGenericGsm *gsm,
|
||||
gint cid,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemZte *self = MM_MODEM_ZTE (gsm);
|
||||
MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (self);
|
||||
|
||||
if (priv->is_icera)
|
||||
mm_modem_icera_do_disconnect (gsm, cid, callback, user_data);
|
||||
else
|
||||
MM_GENERIC_GSM_CLASS (mm_modem_zte_parent_class)->do_disconnect (gsm, cid, callback, user_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Modem class override functions */
|
||||
/*****************************************************************************/
|
||||
@@ -404,7 +422,7 @@ pre_init_done (MMAtSerialPort *port,
|
||||
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (self), error, info);
|
||||
} else {
|
||||
/* Finish the initialization */
|
||||
mm_modem_icera_is_icera (MM_GENERIC_GSM (self), icera_check_cb, self);
|
||||
mm_modem_icera_is_icera (MM_MODEM_ICERA (self), icera_check_cb, self);
|
||||
mm_at_serial_port_queue_command (port, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info);
|
||||
}
|
||||
}
|
||||
@@ -436,6 +454,8 @@ do_enable (MMGenericGsm *modem, MMModemFn callback, gpointer user_data)
|
||||
mm_serial_port_flash (MM_SERIAL_PORT (primary), 100, FALSE, enable_flash_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
MMModem *modem;
|
||||
MMModemFn callback;
|
||||
@@ -477,13 +497,69 @@ disable (MMModem *modem,
|
||||
g_assert (primary);
|
||||
|
||||
/* Turn off unsolicited responses */
|
||||
if (priv->is_icera)
|
||||
if (priv->is_icera) {
|
||||
mm_modem_icera_cleanup (MM_MODEM_ICERA (modem));
|
||||
mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (modem), FALSE);
|
||||
}
|
||||
|
||||
/* Random command to ensure unsolicited message disable completes */
|
||||
mm_at_serial_port_queue_command (primary, "E0", 5, disable_unsolicited_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
do_connect (MMModem *modem,
|
||||
const char *number,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModem *parent_iface;
|
||||
|
||||
if (MM_MODEM_ZTE_GET_PRIVATE (modem)->is_icera)
|
||||
mm_modem_icera_do_connect (MM_MODEM_ICERA (modem), number, callback, user_data);
|
||||
else {
|
||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
||||
parent_iface->connect (MM_MODEM (modem), number, callback, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_ip4_config (MMModem *modem,
|
||||
MMModemIp4Fn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModem *parent_iface;
|
||||
|
||||
if (MM_MODEM_ZTE_GET_PRIVATE (modem)->is_icera) {
|
||||
mm_modem_icera_get_ip4_config (MM_MODEM_ICERA (modem), callback, user_data);
|
||||
} else {
|
||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
||||
parent_iface->get_ip4_config (MM_MODEM (modem), callback, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
simple_connect (MMModemSimple *simple,
|
||||
GHashTable *properties,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (simple);
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemSimple *parent_iface;
|
||||
|
||||
if (priv->is_icera)
|
||||
mm_modem_icera_simple_connect (MM_MODEM_ICERA (simple), properties);
|
||||
|
||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple));
|
||||
parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
@@ -547,12 +623,21 @@ static void
|
||||
modem_init (MMModem *modem_class)
|
||||
{
|
||||
modem_class->disable = disable;
|
||||
modem_class->connect = do_connect;
|
||||
modem_class->get_ip4_config = get_ip4_config;
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
modem_icera_init (MMModemIcera *icera_class)
|
||||
{
|
||||
mm_modem_icera_prepare (icera_class);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_simple_init (MMModemSimple *class)
|
||||
{
|
||||
class->connect = simple_connect;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -569,7 +654,7 @@ dispose (GObject *object)
|
||||
if (priv->cpms_timeout)
|
||||
g_source_remove (priv->cpms_timeout);
|
||||
|
||||
mm_modem_icera_dispose (MM_MODEM_ICERA (self));
|
||||
mm_modem_icera_cleanup (MM_MODEM_ICERA (self));
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_zte_parent_class)->dispose (object);
|
||||
}
|
||||
@@ -585,6 +670,7 @@ mm_modem_zte_class_init (MMModemZteClass *klass)
|
||||
|
||||
object_class->dispose = dispose;
|
||||
gsm_class->do_enable = do_enable;
|
||||
gsm_class->do_disconnect = do_disconnect;
|
||||
gsm_class->set_allowed_mode = set_allowed_mode;
|
||||
gsm_class->get_allowed_mode = get_allowed_mode;
|
||||
gsm_class->get_access_technology = get_access_technology;
|
||||
|
Reference in New Issue
Block a user