mirror of
https://github.com/sailfishos/ofono
synced 2025-12-02 15:41:03 +08:00
Add ofono_sim_inserted_notify function to notify the core of SIM insertion / removal. Make every plugin generate a sim inserted event on start. For devices with removable card, the event should be emitted after the plugin detects such event. For devices that need to wait for SIM card initialization, they can emit this event later.
253 lines
5.4 KiB
C
253 lines
5.4 KiB
C
/*
|
|
*
|
|
* oFono - Open Source Telephony
|
|
*
|
|
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
|
|
*
|
|
* 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 <stdio.h>
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
|
#include <gatchat.h>
|
|
#include <gattty.h>
|
|
|
|
#define OFONO_API_SUBJECT_TO_CHANGE
|
|
#include <ofono/plugin.h>
|
|
#include <ofono/modem.h>
|
|
#include <ofono/devinfo.h>
|
|
#include <ofono/netreg.h>
|
|
#include <ofono/sim.h>
|
|
#include <ofono/sms.h>
|
|
#include <ofono/gprs.h>
|
|
#include <ofono/gprs-context.h>
|
|
#include <ofono/log.h>
|
|
|
|
#include <drivers/atmodem/vendor.h>
|
|
|
|
static const char *none_prefix[] = { NULL };
|
|
|
|
struct hso_data {
|
|
GAtChat *app;
|
|
GAtChat *control;
|
|
};
|
|
|
|
static int hso_probe(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data;
|
|
|
|
DBG("%p", modem);
|
|
|
|
data = g_try_new0(struct hso_data, 1);
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
ofono_modem_set_data(modem, data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hso_remove(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
|
|
DBG("%p", modem);
|
|
|
|
ofono_modem_set_data(modem, NULL);
|
|
|
|
g_at_chat_unref(data->control);
|
|
g_free(data);
|
|
}
|
|
|
|
static void hso_debug(const char *str, void *user_data)
|
|
{
|
|
const char *prefix = user_data;
|
|
ofono_info("%s%s", prefix, str);
|
|
}
|
|
|
|
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
|
|
{
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
DBG("");
|
|
|
|
if (ok)
|
|
ofono_modem_set_powered(modem, TRUE);
|
|
}
|
|
|
|
static GAtChat *create_port(const char *device)
|
|
{
|
|
GAtSyntax *syntax;
|
|
GIOChannel *channel;
|
|
GAtChat *chat;
|
|
|
|
channel = g_at_tty_open(device, NULL);
|
|
if (!channel)
|
|
return NULL;
|
|
|
|
syntax = g_at_syntax_new_gsm_permissive();
|
|
chat = g_at_chat_new(channel, syntax);
|
|
g_at_syntax_unref(syntax);
|
|
g_io_channel_unref(channel);
|
|
|
|
if (!chat)
|
|
return NULL;
|
|
|
|
return chat;
|
|
}
|
|
|
|
static int hso_enable(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
const char *app;
|
|
const char *control;
|
|
|
|
DBG("%p", modem);
|
|
|
|
control = ofono_modem_get_string(modem, "ControlPort");
|
|
app = ofono_modem_get_string(modem, "ApplicationPort");
|
|
|
|
if (!app || !control)
|
|
return -EINVAL;
|
|
|
|
data->control = create_port(control);
|
|
|
|
if (data->control == NULL)
|
|
return -EIO;
|
|
|
|
if (getenv("OFONO_AT_DEBUG"))
|
|
g_at_chat_set_debug(data->control, hso_debug, "Control:");
|
|
|
|
data->app = create_port(app);
|
|
|
|
if (data->app == NULL) {
|
|
g_at_chat_unref(data->control);
|
|
data->control = NULL;
|
|
|
|
return -EIO;
|
|
}
|
|
|
|
if (getenv("OFONO_AT_DEBUG"))
|
|
g_at_chat_set_debug(data->app, hso_debug, "App:");
|
|
|
|
g_at_chat_send(data->control, "ATE0", none_prefix, NULL, NULL, NULL);
|
|
g_at_chat_send(data->app, "ATE0", none_prefix, NULL, NULL, NULL);
|
|
|
|
g_at_chat_send(data->control, "AT+CFUN=1", none_prefix,
|
|
cfun_enable, modem, NULL);
|
|
|
|
return -EINPROGRESS;
|
|
}
|
|
|
|
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
|
|
{
|
|
struct ofono_modem *modem = user_data;
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
|
|
DBG("");
|
|
|
|
g_at_chat_shutdown(data->control);
|
|
g_at_chat_unref(data->control);
|
|
data->control = NULL;
|
|
|
|
if (ok)
|
|
ofono_modem_set_powered(modem, FALSE);
|
|
}
|
|
|
|
static int hso_disable(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
|
|
DBG("%p", modem);
|
|
|
|
if (!data->control)
|
|
return 0;
|
|
|
|
g_at_chat_cancel_all(data->control);
|
|
g_at_chat_unregister_all(data->control);
|
|
|
|
g_at_chat_shutdown(data->app);
|
|
g_at_chat_unref(data->app);
|
|
data->app = NULL;
|
|
|
|
g_at_chat_send(data->control, "AT+CFUN=0", none_prefix,
|
|
cfun_disable, modem, NULL);
|
|
|
|
return -EINPROGRESS;
|
|
}
|
|
|
|
static void hso_pre_sim(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
struct ofono_sim *sim;
|
|
|
|
DBG("%p", modem);
|
|
|
|
ofono_devinfo_create(modem, 0, "atmodem", data->control);
|
|
sim = ofono_sim_create(modem, 0, "atmodem", data->control);
|
|
|
|
if (sim)
|
|
ofono_sim_inserted_notify(sim, TRUE);
|
|
}
|
|
|
|
static void hso_post_sim(struct ofono_modem *modem)
|
|
{
|
|
struct hso_data *data = ofono_modem_get_data(modem);
|
|
struct ofono_gprs *gprs;
|
|
struct ofono_gprs_context *gc;
|
|
|
|
DBG("%p", modem);
|
|
|
|
ofono_netreg_create(modem, OFONO_VENDOR_OPTION_HSO,
|
|
"atmodem", data->app);
|
|
ofono_sms_create(modem, 0, "atmodem", data->app);
|
|
|
|
gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
|
|
gc = ofono_gprs_context_create(modem, 0, "hso", data->control);
|
|
|
|
if (gprs && gc)
|
|
ofono_gprs_add_context(gprs, gc);
|
|
}
|
|
|
|
static struct ofono_modem_driver hso_driver = {
|
|
.name = "hso",
|
|
.probe = hso_probe,
|
|
.remove = hso_remove,
|
|
.enable = hso_enable,
|
|
.disable = hso_disable,
|
|
.pre_sim = hso_pre_sim,
|
|
.post_sim = hso_post_sim,
|
|
};
|
|
|
|
static int hso_init(void)
|
|
{
|
|
return ofono_modem_driver_register(&hso_driver);
|
|
}
|
|
|
|
static void hso_exit(void)
|
|
{
|
|
ofono_modem_driver_unregister(&hso_driver);
|
|
}
|
|
|
|
OFONO_PLUGIN_DEFINE(hso, "Option HSO modem driver", VERSION,
|
|
OFONO_PLUGIN_PRIORITY_DEFAULT, hso_init, hso_exit)
|