2009-09-03 07:22:06 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-07-28 20:06:29 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2009-09-03 07:22:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-06 21:31:38 +00:00
|
|
|
#include <string.h>
|
2009-09-03 07:22:06 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gatchat.h>
|
2009-10-01 22:01:15 +00:00
|
|
|
#include <gattty.h>
|
2009-09-03 07:22:06 +00:00
|
|
|
|
|
|
|
#define OFONO_API_SUBJECT_TO_CHANGE
|
|
|
|
#include <ofono/plugin.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/devinfo.h>
|
|
|
|
#include <ofono/netreg.h>
|
2009-10-02 11:23:26 +00:00
|
|
|
#include <ofono/sim.h>
|
2010-06-06 22:52:02 +00:00
|
|
|
#include <ofono/cbs.h>
|
2009-09-03 07:22:06 +00:00
|
|
|
#include <ofono/sms.h>
|
2010-06-06 22:52:02 +00:00
|
|
|
#include <ofono/ussd.h>
|
2010-01-18 14:30:13 +00:00
|
|
|
#include <ofono/gprs.h>
|
2010-05-20 10:53:28 +00:00
|
|
|
#include <ofono/gprs-context.h>
|
2010-09-29 15:01:14 +00:00
|
|
|
#include <ofono/audio-settings.h>
|
2010-12-09 16:43:37 +00:00
|
|
|
#include <ofono/radio-settings.h>
|
2010-07-02 03:04:34 +00:00
|
|
|
#include <ofono/voicecall.h>
|
|
|
|
#include <ofono/call-forwarding.h>
|
|
|
|
#include <ofono/call-settings.h>
|
|
|
|
#include <ofono/call-barring.h>
|
|
|
|
#include <ofono/phonebook.h>
|
|
|
|
#include <ofono/message-waiting.h>
|
2012-01-07 03:08:13 +00:00
|
|
|
#include <ofono/cdma-netreg.h>
|
|
|
|
#include <ofono/cdma-connman.h>
|
2010-06-06 22:52:02 +00:00
|
|
|
#include <ofono/log.h>
|
2009-09-03 07:22:06 +00:00
|
|
|
|
2010-05-20 10:53:28 +00:00
|
|
|
#include <drivers/atmodem/atutil.h>
|
2009-10-02 11:23:26 +00:00
|
|
|
#include <drivers/atmodem/vendor.h>
|
|
|
|
|
2010-05-25 14:23:26 +00:00
|
|
|
static const char *none_prefix[] = { NULL };
|
2012-01-06 21:31:38 +00:00
|
|
|
static const char *gcap_prefix[] = { "+GCAP:", NULL };
|
2011-08-04 12:01:03 +00:00
|
|
|
static const char *rfswitch_prefix[] = { "^RFSWITCH:", NULL };
|
2010-05-25 14:23:26 +00:00
|
|
|
static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
|
2010-08-19 19:01:21 +00:00
|
|
|
static const char *ussdmode_prefix[] = { "^USSDMODE:", NULL };
|
2012-01-11 15:33:02 +00:00
|
|
|
static const char *dialmode_prefix[] = { "^DIALMODE:", NULL };
|
2010-09-04 21:43:59 +00:00
|
|
|
static const char *cvoice_prefix[] = { "^CVOICE:", NULL };
|
2010-05-25 14:23:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
enum {
|
|
|
|
SIM_STATE_INVALID_OR_LOCKED = 0,
|
|
|
|
SIM_STATE_VALID = 1,
|
|
|
|
SIM_STATE_INVALID_CS = 2,
|
|
|
|
SIM_STATE_INVALID_PS = 3,
|
|
|
|
SIM_STATE_INVALID_PS_AND_CS = 4,
|
2012-01-07 03:11:03 +00:00
|
|
|
SIM_STATE_ROMSIM = 240,
|
2011-07-28 20:06:29 +00:00
|
|
|
SIM_STATE_NOT_EXISTENT = 255,
|
2010-08-05 19:13:08 +00:00
|
|
|
};
|
|
|
|
|
2009-09-03 07:22:06 +00:00
|
|
|
struct huawei_data {
|
2010-06-08 00:07:05 +00:00
|
|
|
GAtChat *modem;
|
|
|
|
GAtChat *pcui;
|
2017-02-21 10:37:29 +00:00
|
|
|
struct ofono_gprs *gprs;
|
|
|
|
struct ofono_gprs_context *gc;
|
2011-07-28 20:06:29 +00:00
|
|
|
gboolean have_sim;
|
|
|
|
int sim_state;
|
|
|
|
guint sysinfo_poll_source;
|
|
|
|
guint sysinfo_poll_count;
|
|
|
|
struct cb_data *online_cbd;
|
|
|
|
const char *offline_command;
|
2012-01-06 21:19:30 +00:00
|
|
|
gboolean have_voice;
|
2012-01-06 21:31:38 +00:00
|
|
|
gboolean have_gsm;
|
2012-01-07 03:08:13 +00:00
|
|
|
gboolean have_cdma;
|
2012-01-11 20:35:25 +00:00
|
|
|
gboolean have_ndis;
|
2012-01-12 05:02:27 +00:00
|
|
|
gboolean have_ussdmode;
|
2009-09-03 07:22:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int huawei_probe(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data;
|
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
|
|
|
data = g_try_new0(struct huawei_data, 1);
|
2010-11-27 19:39:02 +00:00
|
|
|
if (data == NULL)
|
2009-09-03 07:22:06 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ofono_modem_set_data(modem, data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void huawei_remove(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
|
|
|
ofono_modem_set_data(modem, NULL);
|
|
|
|
|
2011-08-03 12:26:23 +00:00
|
|
|
/* Cleanup after potential enable polling */
|
|
|
|
if (data->sysinfo_poll_source > 0)
|
|
|
|
g_source_remove(data->sysinfo_poll_source);
|
|
|
|
|
2011-07-29 13:12:59 +00:00
|
|
|
/* Cleanup after hot-unplug */
|
|
|
|
g_at_chat_unref(data->pcui);
|
|
|
|
|
2009-09-03 07:22:06 +00:00
|
|
|
g_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void huawei_debug(const char *str, void *user_data)
|
|
|
|
{
|
2010-05-20 10:53:15 +00:00
|
|
|
const char *prefix = user_data;
|
2010-09-24 05:14:04 +00:00
|
|
|
|
2010-05-20 10:53:15 +00:00
|
|
|
ofono_info("%s%s", prefix, str);
|
2009-09-03 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 19:01:21 +00:00
|
|
|
static void ussdmode_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
gint ussdmode;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^USSDMODE:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &ussdmode))
|
|
|
|
return;
|
|
|
|
|
2012-01-12 05:02:27 +00:00
|
|
|
if (ussdmode == 1)
|
|
|
|
data->have_ussdmode = TRUE;
|
2010-08-19 19:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ussdmode_support_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^USSDMODE:"))
|
|
|
|
return;
|
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Query current USSD mode */
|
2010-08-19 19:01:21 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^USSDMODE?", ussdmode_prefix,
|
|
|
|
ussdmode_query_cb, data, NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-11 15:33:02 +00:00
|
|
|
static void dialmode_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-01-11 20:35:25 +00:00
|
|
|
struct huawei_data *data = user_data;
|
2012-01-11 15:33:02 +00:00
|
|
|
GAtResultIter iter;
|
2012-01-11 20:35:25 +00:00
|
|
|
gint dialmode, cdc_spec;
|
|
|
|
const char *str = "unknown";
|
2012-01-11 15:33:02 +00:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^DIALMODE:"))
|
|
|
|
return;
|
2012-01-11 20:35:25 +00:00
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &dialmode))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_at_result_iter_next_number(&iter, &cdc_spec)) {
|
|
|
|
switch (cdc_spec) {
|
|
|
|
case 0:
|
|
|
|
str = "none";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
str = "Modem port";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
str = "NDIS port";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
str = "Modem and NDIS port";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dialmode) {
|
|
|
|
case 0:
|
|
|
|
ofono_info("Modem support (CDC support: %s)", str);
|
|
|
|
data->have_ndis = FALSE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ofono_info("NDIS support (CDC support: %s)", str);
|
|
|
|
data->have_ndis = TRUE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ofono_info("Modem and NDIS support (CDC support: %s)", str);
|
|
|
|
data->have_ndis = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-11 15:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dialmode_support_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^DIALMODE:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Query current NDIS mode */
|
|
|
|
g_at_chat_send(data->pcui, "AT^DIALMODE?", dialmode_prefix,
|
|
|
|
dialmode_query_cb, data, NULL);
|
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static void cvoice_query_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
2010-09-20 12:40:33 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2011-07-28 20:06:29 +00:00
|
|
|
GAtResultIter iter;
|
|
|
|
gint mode, rate, bits, period;
|
2010-09-20 12:40:33 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!ok)
|
2010-09-20 12:40:33 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
2010-06-07 01:22:03 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next(&iter, "^CVOICE:"))
|
|
|
|
return;
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &mode))
|
|
|
|
return;
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &rate))
|
|
|
|
return;
|
2010-09-20 12:40:33 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &bits))
|
|
|
|
return;
|
2010-12-20 21:51:08 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &period))
|
|
|
|
return;
|
2010-09-20 12:40:33 +00:00
|
|
|
|
2012-01-06 21:19:30 +00:00
|
|
|
data->have_voice = TRUE;
|
2010-09-20 12:40:33 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
ofono_info("Voice channel: %d Hz, %d bits, %dms period",
|
|
|
|
rate, bits, period);
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Check available voice ports */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^DDSETEX=?", none_prefix,
|
|
|
|
NULL, NULL, NULL);
|
huawei: properly notify sim state to ofono
Instead of using ofono_modem_set_powered(), use ofono_sim_inserted_notify()
which is the proper way to notify about sim state changes.
Now the problem is that voicecall commands fail with my Huawei E1552:
ofonod[12395]: > AT+CRC=1\r
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CLIP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+COLP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CCWA=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: drivers/atmodem/voicecall.c:at_voicecall_initialized()
voicecall_init: registering to notifications
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: > AT^SYSINFO\r
ofonod[12395]: < \r\n^SYSINFO:0,0,0,0,255,,0\r\n\r\nOK\r\n
ofonod[12395]: > AT+CGMI\r
ofonod[12395]: < \r\nhuawei\r\n\r\nOK\r\n
ofonod[12395]: EventChannel: < \r\n^STIN:0,0,0\r\n
ofonod[12395]: > AT+CLCC\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
But as I can't make voice calls with this modem anyway, I don't worry
about them right now.
2010-05-25 14:23:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static void cvoice_support_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
2010-12-21 19:27:10 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
2011-07-28 20:06:29 +00:00
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
GAtResultIter iter;
|
2010-12-21 19:27:10 +00:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^CVOICE:"))
|
|
|
|
return;
|
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Query current voice setting */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^CVOICE?", cvoice_prefix,
|
|
|
|
cvoice_query_cb, modem, NULL);
|
2010-12-21 19:27:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static void simst_notify(GAtResult *result, gpointer user_data)
|
2010-12-21 19:27:10 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2011-07-28 20:06:29 +00:00
|
|
|
GAtResultIter iter;
|
|
|
|
int sim_state;
|
2010-12-21 19:27:10 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_result_iter_init(&iter, result);
|
2010-12-21 19:27:10 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next(&iter, "^SIMST:"))
|
|
|
|
return;
|
2010-12-21 19:27:10 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, &sim_state))
|
|
|
|
return;
|
|
|
|
|
|
|
|
DBG("%d -> %d", data->sim_state, sim_state);
|
|
|
|
|
|
|
|
data->sim_state = sim_state;
|
2010-12-21 19:27:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static gboolean parse_sysinfo_result(GAtResult *result, int *srv_status,
|
|
|
|
int *srv_domain, int *sim_state)
|
2010-05-25 08:48:57 +00:00
|
|
|
{
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "^SYSINFO:"))
|
2011-07-28 20:06:29 +00:00
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, srv_status))
|
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, srv_domain))
|
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2010-05-25 14:23:13 +00:00
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
2011-07-28 20:06:29 +00:00
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2010-05-25 14:23:13 +00:00
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
2011-07-28 20:06:29 +00:00
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!g_at_result_iter_next_number(&iter, sim_state))
|
|
|
|
return FALSE;
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
return TRUE;
|
2010-09-20 12:40:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static void shutdown_device(struct huawei_data *data)
|
2010-09-20 12:40:26 +00:00
|
|
|
{
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_cancel_all(data->modem);
|
|
|
|
g_at_chat_unregister_all(data->modem);
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_unref(data->modem);
|
|
|
|
data->modem = NULL;
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_cancel_all(data->pcui);
|
|
|
|
g_at_chat_unregister_all(data->pcui);
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_unref(data->pcui);
|
|
|
|
data->pcui = NULL;
|
2010-05-25 08:48:57 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static void cfun_offline(gboolean ok, GAtResult *result, gpointer user_data)
|
2010-05-25 08:48:57 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
2011-07-28 20:06:29 +00:00
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
DBG("");
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (!ok) {
|
|
|
|
shutdown_device(data);
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
2010-05-25 08:48:57 +00:00
|
|
|
return;
|
2011-07-28 20:06:29 +00:00
|
|
|
}
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
ofono_modem_set_powered(modem, TRUE);
|
2010-05-25 08:48:57 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static gboolean sysinfo_enable_check(gpointer user_data);
|
|
|
|
|
|
|
|
static void sysinfo_enable_cb(gboolean ok, GAtResult *result,
|
2010-09-04 21:43:59 +00:00
|
|
|
gpointer user_data)
|
2009-09-03 07:22:06 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
2010-05-25 08:48:57 +00:00
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2011-07-28 20:06:29 +00:00
|
|
|
int srv_status, srv_domain, sim_state;
|
2009-09-03 07:22:06 +00:00
|
|
|
|
2010-09-04 21:43:59 +00:00
|
|
|
if (!ok)
|
2011-07-28 20:06:29 +00:00
|
|
|
goto failure;
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (parse_sysinfo_result(result, &srv_status, &srv_domain,
|
|
|
|
&sim_state) == FALSE)
|
|
|
|
goto failure;
|
2009-09-03 07:22:06 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
DBG("%d -> %d", data->sim_state, sim_state);
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
data->sim_state = sim_state;
|
2010-09-05 18:50:30 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (sim_state == SIM_STATE_NOT_EXISTENT) {
|
|
|
|
data->sysinfo_poll_count++;
|
2010-09-05 18:50:30 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (data->sysinfo_poll_count > 5)
|
|
|
|
goto failure;
|
2010-09-05 18:50:30 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
data->sysinfo_poll_source = g_timeout_add_seconds(1,
|
|
|
|
sysinfo_enable_check, modem);
|
2010-09-20 12:40:33 +00:00
|
|
|
return;
|
2011-07-28 20:06:29 +00:00
|
|
|
}
|
2010-09-05 18:50:30 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
data->have_sim = TRUE;
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Switch data carrier detect signal off */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->modem, "AT&C0", NULL, NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(data->pcui, "AT&C0", NULL, NULL, NULL, NULL);
|
2010-09-05 18:50:30 +00:00
|
|
|
|
2020-06-25 09:29:54 +00:00
|
|
|
/* Restore settings after restart */
|
|
|
|
g_at_chat_send(data->modem, "AT&F0", NULL, NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(data->pcui, "AT&F0", NULL, NULL, NULL, NULL);
|
|
|
|
|
2012-01-12 03:37:03 +00:00
|
|
|
/*
|
|
|
|
* Ensure that the modem is using GSM character set and not IRA,
|
|
|
|
* otherwise weirdness with umlauts and other non-ASCII characters
|
|
|
|
* can result
|
|
|
|
*/
|
|
|
|
g_at_chat_send(data->modem, "AT+CSCS=\"GSM\"", none_prefix,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(data->pcui, "AT+CSCS=\"GSM\"", none_prefix,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Query current device settings */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^U2DIAG?", none_prefix,
|
2010-09-05 18:50:30 +00:00
|
|
|
NULL, NULL, NULL);
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Query current port settings */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^GETPORTMODE", none_prefix,
|
|
|
|
NULL, NULL, NULL);
|
huawei: properly notify sim state to ofono
Instead of using ofono_modem_set_powered(), use ofono_sim_inserted_notify()
which is the proper way to notify about sim state changes.
Now the problem is that voicecall commands fail with my Huawei E1552:
ofonod[12395]: > AT+CRC=1\r
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CLIP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+COLP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CCWA=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: drivers/atmodem/voicecall.c:at_voicecall_initialized()
voicecall_init: registering to notifications
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: > AT^SYSINFO\r
ofonod[12395]: < \r\n^SYSINFO:0,0,0,0,255,,0\r\n\r\nOK\r\n
ofonod[12395]: > AT+CGMI\r
ofonod[12395]: < \r\nhuawei\r\n\r\nOK\r\n
ofonod[12395]: EventChannel: < \r\n^STIN:0,0,0\r\n
ofonod[12395]: > AT+CLCC\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
But as I can't make voice calls with this modem anyway, I don't worry
about them right now.
2010-05-25 14:23:19 +00:00
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Check USSD mode support */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^USSDMODE=?", ussdmode_prefix,
|
|
|
|
ussdmode_support_cb, data, NULL);
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2012-01-11 15:33:02 +00:00
|
|
|
/* Check NDIS mode support */
|
|
|
|
g_at_chat_send(data->pcui, "AT^DIALMODE=?", dialmode_prefix,
|
|
|
|
dialmode_support_cb, data, NULL);
|
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Check for voice support */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^CVOICE=?", cvoice_prefix,
|
|
|
|
cvoice_support_cb, modem, NULL);
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2013-03-28 21:00:40 +00:00
|
|
|
/* For CDMA we use AlwaysOnline so we leave the modem online. */
|
|
|
|
if (data->have_gsm == FALSE && data->have_cdma == TRUE) {
|
|
|
|
ofono_modem_set_boolean(modem, "AlwaysOnline", TRUE);
|
|
|
|
ofono_modem_set_powered(modem, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (g_at_chat_send(data->pcui, data->offline_command, none_prefix,
|
|
|
|
cfun_offline, modem, NULL) > 0)
|
2010-09-20 12:40:33 +00:00
|
|
|
return;
|
2010-09-04 21:43:59 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
failure:
|
|
|
|
shutdown_device(data);
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
2010-09-04 21:43:59 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static gboolean sysinfo_enable_check(gpointer user_data)
|
2011-07-24 20:31:15 +00:00
|
|
|
{
|
2011-07-28 20:06:29 +00:00
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2011-07-24 20:31:15 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
data->sysinfo_poll_source = 0;
|
2011-07-24 20:31:15 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
|
|
|
|
sysinfo_enable_cb, modem, NULL);
|
2011-07-24 20:31:15 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
return FALSE;
|
2011-07-24 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-09-04 21:43:59 +00:00
|
|
|
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
if (!ok) {
|
2011-07-24 20:31:15 +00:00
|
|
|
shutdown_device(data);
|
2010-09-04 21:43:59 +00:00
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
2010-05-25 08:48:57 +00:00
|
|
|
return;
|
2010-09-04 21:43:59 +00:00
|
|
|
}
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-29 13:14:30 +00:00
|
|
|
/* Follow sim state changes */
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_register(data->pcui, "^SIMST:", simst_notify,
|
|
|
|
FALSE, modem, NULL);
|
|
|
|
|
|
|
|
data->sysinfo_poll_count = 0;
|
|
|
|
|
|
|
|
sysinfo_enable_check(modem);
|
2011-07-24 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 12:01:03 +00:00
|
|
|
static void rfswitch_support(gboolean ok, GAtResult *result, gpointer user_data)
|
2011-07-24 20:31:15 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
2012-01-07 03:16:43 +00:00
|
|
|
if (data->have_gsm == FALSE && data->have_cdma == TRUE) {
|
|
|
|
data->offline_command = "AT+CFUN=5";
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-08-04 12:01:03 +00:00
|
|
|
if (!ok)
|
|
|
|
data->offline_command = "AT+CFUN=5";
|
|
|
|
else
|
|
|
|
data->offline_command = "AT+CFUN=7";
|
huawei: properly notify sim state to ofono
Instead of using ofono_modem_set_powered(), use ofono_sim_inserted_notify()
which is the proper way to notify about sim state changes.
Now the problem is that voicecall commands fail with my Huawei E1552:
ofonod[12395]: > AT+CRC=1\r
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CLIP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+COLP=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: > AT+CCWA=1\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
ofonod[12395]: drivers/atmodem/voicecall.c:at_voicecall_initialized()
voicecall_init: registering to notifications
ofonod[12395]: src/sim.c:ofono_sim_add_state_watch() 0x1bf8e50
ofonod[12395]: > AT^SYSINFO\r
ofonod[12395]: < \r\n^SYSINFO:0,0,0,0,255,,0\r\n\r\nOK\r\n
ofonod[12395]: > AT+CGMI\r
ofonod[12395]: < \r\nhuawei\r\n\r\nOK\r\n
ofonod[12395]: EventChannel: < \r\n^STIN:0,0,0\r\n
ofonod[12395]: > AT+CLCC\r
ofonod[12395]: < \r\n+CME ERROR: SIM busy\r\n
But as I can't make voice calls with this modem anyway, I don't worry
about them right now.
2010-05-25 14:23:19 +00:00
|
|
|
|
2012-01-07 03:16:43 +00:00
|
|
|
done:
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT+CFUN=1", none_prefix,
|
2011-07-24 20:31:15 +00:00
|
|
|
cfun_enable, modem, NULL);
|
2009-09-03 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:31:38 +00:00
|
|
|
static void gcap_support(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *gcap;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+GCAP:"))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_unquoted_string(&iter, &gcap)) {
|
|
|
|
if (*gcap == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!strcmp(gcap, "+CGSM"))
|
|
|
|
data->have_gsm = TRUE;
|
2012-01-07 03:08:13 +00:00
|
|
|
else if (!strcmp(gcap, "+CIS707-A"))
|
|
|
|
data->have_cdma = TRUE;
|
2012-01-06 21:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_at_chat_send(data->pcui, "AT^RFSWITCH=?", rfswitch_prefix,
|
|
|
|
rfswitch_support, modem, NULL);
|
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static GAtChat *open_device(struct ofono_modem *modem,
|
|
|
|
const char *key, char *debug)
|
2009-09-03 07:22:06 +00:00
|
|
|
{
|
2019-05-31 16:50:03 +00:00
|
|
|
GAtChat *chat = at_util_open_device(modem, key, huawei_debug, debug,
|
|
|
|
NULL);
|
2009-09-03 07:22:06 +00:00
|
|
|
|
2019-05-31 16:50:03 +00:00
|
|
|
if (!chat)
|
2010-06-29 07:59:31 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_at_chat_add_terminator(chat, "COMMAND NOT SUPPORT", -1, FALSE);
|
2011-08-04 11:27:29 +00:00
|
|
|
g_at_chat_add_terminator(chat, "TOO MANY PARAMETERS", -1, FALSE);
|
2010-06-29 07:59:31 +00:00
|
|
|
|
|
|
|
return chat;
|
|
|
|
}
|
|
|
|
|
2017-02-21 10:37:29 +00:00
|
|
|
static void modem_disconnect(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
DBG("Modem has already been removed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_warn("Modem channel disconnected");
|
|
|
|
|
|
|
|
/* clean and close modem device */
|
|
|
|
g_at_chat_cancel_all(data->modem);
|
|
|
|
g_at_chat_unregister_all(data->modem);
|
|
|
|
g_at_chat_unref(data->modem);
|
|
|
|
data->modem = NULL;
|
|
|
|
|
|
|
|
/* reopen modem channel */
|
|
|
|
data->modem = open_device(modem, "Modem", "Modem: ");
|
|
|
|
|
|
|
|
if (data->modem == NULL) {
|
|
|
|
DBG("Can't reopen device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 10:53:20 +00:00
|
|
|
/* close previous gprs context driver */
|
|
|
|
if (data->gc)
|
|
|
|
ofono_gprs_context_remove(data->gc);
|
|
|
|
|
2017-02-21 10:37:29 +00:00
|
|
|
/* configure modem channel */
|
|
|
|
g_at_chat_set_disconnect_function(data->modem, modem_disconnect, modem);
|
|
|
|
g_at_chat_set_slave(data->modem, data->pcui);
|
|
|
|
g_at_chat_send(data->modem, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* reopen gprs context driver */
|
|
|
|
data->gc = ofono_gprs_context_create(modem, OFONO_VENDOR_HUAWEI,
|
|
|
|
"atmodem", data->modem);
|
|
|
|
|
|
|
|
if (data->gprs && data->gc)
|
|
|
|
ofono_gprs_add_context(data->gprs, data->gc);
|
|
|
|
}
|
|
|
|
|
2010-06-29 07:59:31 +00:00
|
|
|
static int huawei_enable(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
2011-07-24 23:34:41 +00:00
|
|
|
data->modem = open_device(modem, "Modem", "Modem: ");
|
|
|
|
if (data->modem == NULL)
|
|
|
|
return -EINVAL;
|
2010-05-20 10:53:15 +00:00
|
|
|
|
2017-02-21 10:37:29 +00:00
|
|
|
g_at_chat_set_disconnect_function(data->modem, modem_disconnect, modem);
|
|
|
|
|
2010-09-24 05:14:04 +00:00
|
|
|
data->pcui = open_device(modem, "Pcui", "PCUI: ");
|
2010-06-08 00:07:05 +00:00
|
|
|
if (data->pcui == NULL) {
|
|
|
|
g_at_chat_unref(data->modem);
|
|
|
|
data->modem = NULL;
|
2010-05-20 10:53:15 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2011-07-24 12:50:12 +00:00
|
|
|
g_at_chat_set_slave(data->modem, data->pcui);
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->modem, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(data->pcui, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
|
2010-05-25 08:48:57 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
data->sim_state = SIM_STATE_NOT_EXISTENT;
|
2009-09-03 07:22:06 +00:00
|
|
|
|
2012-01-06 21:31:38 +00:00
|
|
|
/* Check for GSM capabilities */
|
|
|
|
g_at_chat_send(data->pcui, "ATI", gcap_prefix,
|
|
|
|
gcap_support, modem, NULL);
|
2010-09-20 12:40:26 +00:00
|
|
|
|
2010-05-25 08:48:57 +00:00
|
|
|
return -EINPROGRESS;
|
2009-09-03 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
2009-11-18 18:08:14 +00:00
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2009-09-03 07:22:06 +00:00
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
2011-07-29 12:56:41 +00:00
|
|
|
g_at_chat_unref(data->pcui);
|
|
|
|
data->pcui = NULL;
|
2009-11-18 18:08:14 +00:00
|
|
|
|
2009-09-03 07:22:06 +00:00
|
|
|
if (ok)
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int huawei_disable(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
2011-07-24 23:34:41 +00:00
|
|
|
g_at_chat_cancel_all(data->modem);
|
|
|
|
g_at_chat_unregister_all(data->modem);
|
2010-05-20 10:53:15 +00:00
|
|
|
|
2011-07-29 12:56:41 +00:00
|
|
|
g_at_chat_unref(data->modem);
|
|
|
|
data->modem = NULL;
|
|
|
|
|
2010-06-08 00:07:05 +00:00
|
|
|
g_at_chat_cancel_all(data->pcui);
|
|
|
|
g_at_chat_unregister_all(data->pcui);
|
2011-07-24 10:59:14 +00:00
|
|
|
|
2011-08-03 12:23:21 +00:00
|
|
|
/* Cleanup potential online enable polling */
|
|
|
|
if (data->sysinfo_poll_source > 0) {
|
|
|
|
g_source_remove(data->sysinfo_poll_source);
|
|
|
|
data->sysinfo_poll_source = 0;
|
|
|
|
|
|
|
|
g_free(data->online_cbd);
|
|
|
|
data->online_cbd = NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_at_chat_send(data->pcui, "AT+CFUN=0", none_prefix,
|
2009-09-03 07:22:06 +00:00
|
|
|
cfun_disable, modem, NULL);
|
|
|
|
|
2009-11-18 18:08:14 +00:00
|
|
|
return -EINPROGRESS;
|
2009-09-03 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
static gboolean sysinfo_online_check(gpointer user_data);
|
|
|
|
|
|
|
|
static void sysinfo_online_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = user_data;
|
|
|
|
ofono_modem_online_cb_t cb = data->online_cbd->cb;
|
|
|
|
int srv_status, srv_domain, sim_state;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
if (parse_sysinfo_result(result, &srv_status, &srv_domain,
|
|
|
|
&sim_state) == FALSE)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
DBG("%d -> %d", data->sim_state, sim_state);
|
|
|
|
|
|
|
|
data->sim_state = sim_state;
|
|
|
|
|
|
|
|
/* Valid service status and at minimum PS domain */
|
|
|
|
if (srv_status > 0 && srv_domain > 1) {
|
|
|
|
CALLBACK_WITH_SUCCESS(cb, data->online_cbd->data);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sim_state) {
|
|
|
|
case SIM_STATE_VALID:
|
|
|
|
case SIM_STATE_INVALID_CS:
|
|
|
|
case SIM_STATE_INVALID_PS:
|
|
|
|
case SIM_STATE_INVALID_PS_AND_CS:
|
2012-01-07 03:11:03 +00:00
|
|
|
case SIM_STATE_ROMSIM:
|
2011-07-28 20:06:29 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, data->online_cbd->data);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->sysinfo_poll_count++;
|
|
|
|
|
|
|
|
if (data->sysinfo_poll_count > 15)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
data->sysinfo_poll_source = g_timeout_add_seconds(2,
|
|
|
|
sysinfo_online_check, data);
|
|
|
|
return;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data->online_cbd->data);
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_free(data->online_cbd);
|
|
|
|
data->online_cbd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean sysinfo_online_check(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = user_data;
|
|
|
|
|
|
|
|
data->sysinfo_poll_source = 0;
|
|
|
|
|
|
|
|
g_at_chat_send(data->pcui, "AT^SYSINFO", sysinfo_prefix,
|
|
|
|
sysinfo_online_cb, data, NULL);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-06 18:46:15 +00:00
|
|
|
static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
2011-07-28 20:06:29 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
ofono_modem_online_cb_t cb = data->online_cbd->cb;
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data->online_cbd->data);
|
|
|
|
|
|
|
|
g_free(data->online_cbd);
|
|
|
|
data->online_cbd = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->sysinfo_poll_count = 0;
|
|
|
|
|
|
|
|
sysinfo_online_check(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_offline_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
2010-09-06 18:46:15 +00:00
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_modem_online_cb_t cb = cbd->cb;
|
2011-03-09 05:27:22 +00:00
|
|
|
struct ofono_error error;
|
2010-09-06 18:46:15 +00:00
|
|
|
|
2011-03-09 05:27:22 +00:00
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
}
|
|
|
|
|
2010-09-06 18:46:15 +00:00
|
|
|
static void huawei_set_online(struct ofono_modem *modem, ofono_bool_t online,
|
|
|
|
ofono_modem_online_cb_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("modem %p %s", modem, online ? "online" : "offline");
|
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (online == TRUE) {
|
|
|
|
data->online_cbd = cb_data_new(cb, user_data);
|
2010-09-06 18:46:15 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
if (g_at_chat_send(data->pcui, "AT+CFUN=1", none_prefix,
|
|
|
|
set_online_cb, modem, NULL) > 0)
|
|
|
|
return;
|
2011-07-24 10:59:14 +00:00
|
|
|
|
2011-07-28 20:06:29 +00:00
|
|
|
g_free(data->online_cbd);
|
|
|
|
data->online_cbd = NULL;
|
|
|
|
} else {
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, user_data);
|
|
|
|
|
|
|
|
if (g_at_chat_send(data->pcui, data->offline_command,
|
|
|
|
none_prefix, set_offline_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, user_data);
|
2010-09-06 18:46:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:15:34 +00:00
|
|
|
static void huawei_pre_sim(struct ofono_modem *modem)
|
2009-09-03 07:22:06 +00:00
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
2012-01-11 12:49:46 +00:00
|
|
|
struct ofono_sim *sim = NULL;
|
2009-09-03 07:22:06 +00:00
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
2012-01-07 02:30:12 +00:00
|
|
|
if (data->have_gsm == TRUE) {
|
|
|
|
ofono_devinfo_create(modem, 0, "atmodem", data->pcui);
|
|
|
|
sim = ofono_sim_create(modem, OFONO_VENDOR_HUAWEI,
|
|
|
|
"atmodem", data->pcui);
|
2012-01-07 03:08:13 +00:00
|
|
|
} else if (data->have_cdma == TRUE) {
|
|
|
|
ofono_devinfo_create(modem, 0, "cdmamodem", data->pcui);
|
2012-01-11 16:28:34 +00:00
|
|
|
|
|
|
|
/* Create SIM atom only if SIM is not embedded */
|
2012-01-11 12:49:46 +00:00
|
|
|
if (data->sim_state != SIM_STATE_ROMSIM)
|
2012-01-11 16:28:34 +00:00
|
|
|
sim = ofono_sim_create(modem, OFONO_VENDOR_HUAWEI,
|
|
|
|
"atmodem-noef", data->pcui);
|
2012-01-07 02:30:12 +00:00
|
|
|
}
|
2012-01-11 12:49:46 +00:00
|
|
|
|
|
|
|
if (sim && data->have_sim == TRUE)
|
|
|
|
ofono_sim_inserted_notify(sim, TRUE);
|
2010-05-20 10:53:28 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:15:34 +00:00
|
|
|
static void huawei_post_sim(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
DBG("%p", modem);
|
|
|
|
|
2012-01-06 21:19:30 +00:00
|
|
|
if (data->have_voice == TRUE) {
|
2010-09-29 14:59:50 +00:00
|
|
|
ofono_voicecall_create(modem, 0, "huaweimodem", data->pcui);
|
2010-09-29 15:01:14 +00:00
|
|
|
ofono_audio_settings_create(modem, 0,
|
|
|
|
"huaweimodem", data->pcui);
|
|
|
|
}
|
2010-09-26 15:05:52 +00:00
|
|
|
|
2012-01-07 02:30:12 +00:00
|
|
|
if (data->have_gsm == TRUE) {
|
|
|
|
ofono_phonebook_create(modem, 0, "atmodem", data->pcui);
|
|
|
|
ofono_radio_settings_create(modem, 0,
|
|
|
|
"huaweimodem", data->pcui);
|
2011-07-28 20:06:29 +00:00
|
|
|
|
2012-01-07 02:30:12 +00:00
|
|
|
ofono_sms_create(modem, OFONO_VENDOR_HUAWEI,
|
2011-07-28 20:06:29 +00:00
|
|
|
"atmodem", data->pcui);
|
|
|
|
|
2017-02-21 10:37:29 +00:00
|
|
|
data->gprs = ofono_gprs_create(modem, OFONO_VENDOR_HUAWEI,
|
2012-01-07 02:30:12 +00:00
|
|
|
"atmodem", data->pcui);
|
2018-07-25 13:45:14 +00:00
|
|
|
data->gc = ofono_gprs_context_create(modem, OFONO_VENDOR_HUAWEI,
|
2012-01-07 02:30:12 +00:00
|
|
|
"atmodem", data->modem);
|
|
|
|
|
2017-02-21 10:37:29 +00:00
|
|
|
if (data->gprs && data->gc)
|
|
|
|
ofono_gprs_add_context(data->gprs, data->gc);
|
2012-01-07 02:30:12 +00:00
|
|
|
}
|
2010-09-06 18:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void huawei_post_online(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct huawei_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
2011-07-27 12:02:19 +00:00
|
|
|
DBG("%p", modem);
|
|
|
|
|
2012-01-07 02:30:12 +00:00
|
|
|
if (data->have_gsm == TRUE) {
|
|
|
|
ofono_netreg_create(modem, OFONO_VENDOR_HUAWEI,
|
|
|
|
"atmodem", data->pcui);
|
2010-06-06 22:52:02 +00:00
|
|
|
|
2012-01-07 02:30:12 +00:00
|
|
|
ofono_cbs_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
|
2010-08-19 19:01:21 +00:00
|
|
|
"atmodem", data->pcui);
|
2012-01-12 05:02:27 +00:00
|
|
|
if (data->have_ussdmode == TRUE)
|
|
|
|
ofono_ussd_create(modem, 0, "huaweimodem", data->pcui);
|
|
|
|
else
|
|
|
|
ofono_ussd_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
|
|
|
|
"atmodem", data->pcui);
|
2012-01-07 03:08:13 +00:00
|
|
|
} else if (data->have_cdma == TRUE) {
|
2012-01-07 03:55:34 +00:00
|
|
|
ofono_cdma_netreg_create(modem, 0, "huaweimodem", data->pcui);
|
2012-01-07 03:08:13 +00:00
|
|
|
|
|
|
|
ofono_cdma_connman_create(modem, OFONO_VENDOR_HUAWEI,
|
|
|
|
"cdmamodem", data->modem);
|
2012-01-07 02:30:12 +00:00
|
|
|
}
|
2010-05-20 10:53:28 +00:00
|
|
|
|
2012-01-06 21:19:30 +00:00
|
|
|
if (data->have_voice == TRUE) {
|
2011-07-24 10:59:14 +00:00
|
|
|
struct ofono_message_waiting *mw;
|
|
|
|
|
2010-07-02 03:04:34 +00:00
|
|
|
ofono_call_forwarding_create(modem, 0, "atmodem", data->pcui);
|
|
|
|
ofono_call_settings_create(modem, 0, "atmodem", data->pcui);
|
|
|
|
ofono_call_barring_create(modem, 0, "atmodem", data->pcui);
|
|
|
|
|
|
|
|
mw = ofono_message_waiting_create(modem);
|
|
|
|
if (mw)
|
|
|
|
ofono_message_waiting_register(mw);
|
|
|
|
}
|
2009-09-03 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_modem_driver huawei_driver = {
|
|
|
|
.name = "huawei",
|
|
|
|
.probe = huawei_probe,
|
|
|
|
.remove = huawei_remove,
|
|
|
|
.enable = huawei_enable,
|
|
|
|
.disable = huawei_disable,
|
2011-07-28 20:06:29 +00:00
|
|
|
.set_online = huawei_set_online,
|
2009-09-17 15:15:34 +00:00
|
|
|
.pre_sim = huawei_pre_sim,
|
|
|
|
.post_sim = huawei_post_sim,
|
2011-07-28 20:06:29 +00:00
|
|
|
.post_online = huawei_post_online,
|
2009-09-03 07:22:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int huawei_init(void)
|
|
|
|
{
|
|
|
|
return ofono_modem_driver_register(&huawei_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void huawei_exit(void)
|
|
|
|
{
|
|
|
|
ofono_modem_driver_unregister(&huawei_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
OFONO_PLUGIN_DEFINE(huawei, "HUAWEI Mobile modem driver", VERSION,
|
|
|
|
OFONO_PLUGIN_PRIORITY_DEFAULT, huawei_init, huawei_exit)
|