2009-09-10 21:10:14 +00:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
|
*
|
2011-10-10 20:39:42 +00:00
|
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2009-09-10 21:10:14 +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 <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <gdbus.h>
|
|
|
|
|
|
|
|
|
|
#include "ofono.h"
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "smsutil.h"
|
2009-09-15 19:35:39 +00:00
|
|
|
|
#include "simutil.h"
|
2009-12-17 20:54:07 +00:00
|
|
|
|
#include "storage.h"
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
#define SETTINGS_STORE "cbs"
|
|
|
|
|
#define SETTINGS_GROUP "Settings"
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
static GSList *g_drivers = NULL;
|
|
|
|
|
|
|
|
|
|
enum etws_topic_type {
|
2011-02-02 08:46:44 +00:00
|
|
|
|
ETWS_TOPIC_TYPE_EARTHQUAKE = 4352,
|
|
|
|
|
ETWS_TOPIC_TYPE_TSUNAMI = 4353,
|
|
|
|
|
ETWS_TOPIC_TYPE_EARTHQUAKE_TSUNAMI = 4354,
|
|
|
|
|
ETWS_TOPIC_TYPE_TEST = 4355,
|
|
|
|
|
ETWS_TOPIC_TYPE_EMERGENCY = 4356,
|
2009-09-10 21:10:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ofono_cbs {
|
|
|
|
|
DBusMessage *pending;
|
|
|
|
|
struct cbs_assembly *assembly;
|
|
|
|
|
GSList *topics;
|
|
|
|
|
GSList *new_topics;
|
|
|
|
|
struct ofono_sim *sim;
|
2011-02-03 07:37:37 +00:00
|
|
|
|
struct ofono_sim_context *sim_context;
|
2010-04-09 06:49:01 +00:00
|
|
|
|
struct ofono_stk *stk;
|
2009-09-11 21:25:30 +00:00
|
|
|
|
struct ofono_netreg *netreg;
|
|
|
|
|
unsigned int netreg_watch;
|
|
|
|
|
unsigned int location_watch;
|
2009-09-15 19:35:39 +00:00
|
|
|
|
unsigned short efcbmi_length;
|
|
|
|
|
GSList *efcbmi_contents;
|
|
|
|
|
unsigned short efcbmir_length;
|
|
|
|
|
GSList *efcbmir_contents;
|
|
|
|
|
unsigned short efcbmid_length;
|
|
|
|
|
GSList *efcbmid_contents;
|
2011-02-15 07:58:56 +00:00
|
|
|
|
gboolean efcbmid_update;
|
2009-09-12 02:38:08 +00:00
|
|
|
|
guint reset_source;
|
2009-09-11 21:25:30 +00:00
|
|
|
|
int lac;
|
|
|
|
|
int ci;
|
|
|
|
|
char mnc[OFONO_MAX_MNC_LENGTH + 1];
|
|
|
|
|
char mcc[OFONO_MAX_MCC_LENGTH + 1];
|
2009-12-17 20:54:07 +00:00
|
|
|
|
ofono_bool_t powered;
|
|
|
|
|
GKeyFile *settings;
|
|
|
|
|
char *imsi;
|
2009-09-10 21:10:14 +00:00
|
|
|
|
const struct ofono_cbs_driver *driver;
|
|
|
|
|
void *driver_data;
|
|
|
|
|
struct ofono_atom *atom;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void cbs_dispatch_base_station_id(struct ofono_cbs *cbs, const char *id)
|
|
|
|
|
{
|
2009-09-11 21:25:30 +00:00
|
|
|
|
DBG("Base station id: %s", id);
|
|
|
|
|
|
|
|
|
|
if (cbs->netreg == NULL)
|
|
|
|
|
return;
|
2009-09-12 02:38:08 +00:00
|
|
|
|
|
|
|
|
|
if (cbs->reset_source) {
|
|
|
|
|
g_source_remove(cbs->reset_source);
|
|
|
|
|
cbs->reset_source = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__ofono_netreg_set_base_station_name(cbs->netreg, id);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cbs_dispatch_emergency(struct ofono_cbs *cbs, const char *message,
|
|
|
|
|
enum etws_topic_type topic,
|
|
|
|
|
gboolean alert, gboolean popup)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
DBusMessage *signal;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusMessageIter dict;
|
|
|
|
|
dbus_bool_t boolean;
|
|
|
|
|
const char *emergency_str;
|
|
|
|
|
|
|
|
|
|
if (topic == ETWS_TOPIC_TYPE_TEST) {
|
|
|
|
|
ofono_error("Explicitly ignoring ETWS Test messages");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (topic) {
|
|
|
|
|
case ETWS_TOPIC_TYPE_EARTHQUAKE:
|
|
|
|
|
emergency_str = "Earthquake";
|
|
|
|
|
break;
|
|
|
|
|
case ETWS_TOPIC_TYPE_TSUNAMI:
|
|
|
|
|
emergency_str = "Tsunami";
|
|
|
|
|
break;
|
|
|
|
|
case ETWS_TOPIC_TYPE_EARTHQUAKE_TSUNAMI:
|
|
|
|
|
emergency_str = "Earthquake+Tsunami";
|
|
|
|
|
break;
|
|
|
|
|
case ETWS_TOPIC_TYPE_EMERGENCY:
|
|
|
|
|
emergency_str = "Other";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
2010-06-10 03:07:11 +00:00
|
|
|
|
signal = dbus_message_new_signal(path, OFONO_CELL_BROADCAST_INTERFACE,
|
2009-09-10 21:10:14 +00:00
|
|
|
|
"EmergencyBroadcast");
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (signal == NULL)
|
2009-09-10 21:10:14 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(signal, &iter);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &message);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
|
OFONO_PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
|
&dict);
|
|
|
|
|
|
|
|
|
|
ofono_dbus_dict_append(&dict, "EmergencyType",
|
|
|
|
|
DBUS_TYPE_STRING, &emergency_str);
|
|
|
|
|
|
|
|
|
|
boolean = alert;
|
|
|
|
|
ofono_dbus_dict_append(&dict, "EmergencyAlert",
|
|
|
|
|
DBUS_TYPE_BOOLEAN, &boolean);
|
|
|
|
|
|
|
|
|
|
boolean = popup;
|
|
|
|
|
ofono_dbus_dict_append(&dict, "Popup", DBUS_TYPE_BOOLEAN, &boolean);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(&iter, &dict);
|
|
|
|
|
g_dbus_send_message(conn, signal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cbs_dispatch_text(struct ofono_cbs *cbs, enum sms_class cls,
|
|
|
|
|
unsigned short channel, const char *message)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
|
2010-06-10 03:07:11 +00:00
|
|
|
|
g_dbus_emit_signal(conn, path, OFONO_CELL_BROADCAST_INTERFACE,
|
2009-09-10 21:10:14 +00:00
|
|
|
|
"IncomingBroadcast",
|
|
|
|
|
DBUS_TYPE_STRING, &message,
|
|
|
|
|
DBUS_TYPE_UINT16, &channel,
|
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ofono_cbs_notify(struct ofono_cbs *cbs, const unsigned char *pdu,
|
|
|
|
|
int pdu_len)
|
|
|
|
|
{
|
|
|
|
|
struct cbs c;
|
|
|
|
|
enum sms_class cls;
|
|
|
|
|
gboolean udhi;
|
|
|
|
|
gboolean comp;
|
|
|
|
|
GSList *cbs_list;
|
|
|
|
|
enum sms_charset charset;
|
|
|
|
|
char *message;
|
|
|
|
|
char iso639_lang[3];
|
|
|
|
|
|
|
|
|
|
if (cbs->assembly == NULL)
|
|
|
|
|
return;
|
2009-12-18 03:23:20 +00:00
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
if (!cbs_decode(pdu, pdu_len, &c)) {
|
|
|
|
|
ofono_error("Unable to decode CBS PDU");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
if (cbs_topic_in_range(c.message_identifier, cbs->efcbmid_contents)) {
|
2012-01-18 18:52:01 +00:00
|
|
|
|
if (cbs->sim == NULL)
|
2010-11-10 03:27:52 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2012-01-18 18:52:01 +00:00
|
|
|
|
if (!__ofono_sim_service_available(cbs->sim,
|
2010-11-10 03:27:52 +00:00
|
|
|
|
SIM_UST_SERVICE_DATA_DOWNLOAD_SMS_CB,
|
|
|
|
|
SIM_SST_SERVICE_DATA_DOWNLOAD_SMS_CB))
|
|
|
|
|
return;
|
|
|
|
|
|
2010-04-15 18:12:24 +00:00
|
|
|
|
if (cbs->stk)
|
2010-06-07 10:08:27 +00:00
|
|
|
|
__ofono_cbs_sim_download(cbs->stk, &c);
|
2010-11-10 15:15:51 +00:00
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 10:08:28 +00:00
|
|
|
|
if (!cbs->powered) {
|
|
|
|
|
ofono_error("Ignoring CBS because powered is off");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
if (!cbs_dcs_decode(c.dcs, &udhi, &cls, &charset, &comp, NULL, NULL)) {
|
|
|
|
|
ofono_error("Unknown / Reserved DCS. Ignoring");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (udhi) {
|
|
|
|
|
ofono_error("CBS messages with UDH not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (charset == SMS_CHARSET_8BIT) {
|
|
|
|
|
ofono_error("Datagram CBS not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comp) {
|
|
|
|
|
ofono_error("CBS messages with compression not supported");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs_list = cbs_assembly_add_page(cbs->assembly, &c);
|
|
|
|
|
|
|
|
|
|
if (cbs_list == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
message = cbs_decode_text(cbs_list, iso639_lang);
|
|
|
|
|
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (c.message_identifier >= ETWS_TOPIC_TYPE_EARTHQUAKE &&
|
|
|
|
|
c.message_identifier <= ETWS_TOPIC_TYPE_EMERGENCY) {
|
|
|
|
|
gboolean alert = FALSE;
|
|
|
|
|
gboolean popup = FALSE;
|
|
|
|
|
|
|
|
|
|
/* 3GPP 23.041 9.4.1.2.1: Alert is encoded in bit 9 */
|
|
|
|
|
if (c.message_code & (1 << 9))
|
|
|
|
|
alert = TRUE;
|
|
|
|
|
|
|
|
|
|
/* 3GPP 23.041 9.4.1.2.1: Popup is encoded in bit 8 */
|
|
|
|
|
if (c.message_code & (1 << 8))
|
|
|
|
|
popup = TRUE;
|
|
|
|
|
|
|
|
|
|
cbs_dispatch_emergency(cbs, message,
|
|
|
|
|
c.message_identifier, alert, popup);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-21 19:18:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* 3GPP 23.041: NOTE 5: Code 00 is intended for use by the
|
2009-09-10 21:10:14 +00:00
|
|
|
|
* network operators for base station IDs.
|
|
|
|
|
*/
|
|
|
|
|
if (c.gs == CBS_GEO_SCOPE_CELL_IMMEDIATE) {
|
|
|
|
|
cbs_dispatch_base_station_id(cbs, message);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs_dispatch_text(cbs, cls, c.message_identifier, message);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_free(message);
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs_list, g_free);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusMessage *cbs_get_properties(DBusConnection *conn,
|
|
|
|
|
DBusMessage *msg, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusMessageIter iter, dict;
|
|
|
|
|
char *topics;
|
|
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (reply == NULL)
|
2009-09-10 21:10:14 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
|
OFONO_PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
|
&dict);
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
ofono_dbus_dict_append(&dict, "Powered", DBUS_TYPE_BOOLEAN,
|
|
|
|
|
&cbs->powered);
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
topics = cbs_topic_ranges_to_string(cbs->topics);
|
|
|
|
|
ofono_dbus_dict_append(&dict, "Topics", DBUS_TYPE_STRING, &topics);
|
|
|
|
|
g_free(topics);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(&iter, &dict);
|
|
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
static char *cbs_topics_to_str(struct ofono_cbs *cbs, GSList *user_topics)
|
|
|
|
|
{
|
|
|
|
|
GSList *topics = NULL;
|
|
|
|
|
char *topic_str;
|
|
|
|
|
struct cbs_topic_range etws_range = { 4352, 4356 };
|
|
|
|
|
|
|
|
|
|
if (user_topics != NULL)
|
|
|
|
|
topics = g_slist_concat(topics,
|
|
|
|
|
g_slist_copy(user_topics));
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmid_contents != NULL)
|
|
|
|
|
topics = g_slist_concat(topics,
|
|
|
|
|
g_slist_copy(cbs->efcbmid_contents));
|
|
|
|
|
|
2010-06-07 20:08:58 +00:00
|
|
|
|
topics = g_slist_append(topics, &etws_range);
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
topic_str = cbs_topic_ranges_to_string(topics);
|
|
|
|
|
g_slist_free(topics);
|
|
|
|
|
|
|
|
|
|
return topic_str;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
static void cbs_set_topics_cb(const struct ofono_error *error, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
char *topics;
|
|
|
|
|
|
|
|
|
|
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->new_topics, g_free);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
cbs->new_topics = NULL;
|
|
|
|
|
|
2010-02-08 17:54:03 +00:00
|
|
|
|
DBG("Setting Cell Broadcast topics failed");
|
2009-09-10 21:10:14 +00:00
|
|
|
|
__ofono_dbus_pending_reply(&cbs->pending,
|
|
|
|
|
__ofono_error_failed(cbs->pending));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->topics, g_free);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
cbs->topics = cbs->new_topics;
|
|
|
|
|
cbs->new_topics = NULL;
|
|
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(cbs->pending);
|
|
|
|
|
__ofono_dbus_pending_reply(&cbs->pending, reply);
|
|
|
|
|
|
|
|
|
|
topics = cbs_topic_ranges_to_string(cbs->topics);
|
|
|
|
|
ofono_dbus_signal_property_changed(conn, path,
|
2010-06-10 03:07:11 +00:00
|
|
|
|
OFONO_CELL_BROADCAST_INTERFACE,
|
2009-09-10 21:10:14 +00:00
|
|
|
|
"Topics",
|
|
|
|
|
DBUS_TYPE_STRING, &topics);
|
2010-01-11 16:30:35 +00:00
|
|
|
|
|
|
|
|
|
if (cbs->settings) {
|
|
|
|
|
g_key_file_set_string(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Topics", topics);
|
|
|
|
|
storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
|
|
|
|
|
}
|
2009-09-10 21:10:14 +00:00
|
|
|
|
g_free(topics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusMessage *cbs_set_topics(struct ofono_cbs *cbs, const char *value,
|
|
|
|
|
DBusMessage *msg)
|
|
|
|
|
{
|
|
|
|
|
GSList *topics;
|
|
|
|
|
char *topic_str;
|
2009-12-17 20:54:07 +00:00
|
|
|
|
struct ofono_error error;
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
|
|
|
|
topics = cbs_extract_topic_ranges(value);
|
|
|
|
|
|
|
|
|
|
if (topics == NULL && value[0] != '\0')
|
|
|
|
|
return __ofono_error_invalid_format(msg);
|
|
|
|
|
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (cbs->driver->set_topics == NULL)
|
2009-09-10 21:10:14 +00:00
|
|
|
|
return __ofono_error_not_implemented(msg);
|
|
|
|
|
|
|
|
|
|
cbs->new_topics = topics;
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
cbs->pending = dbus_message_ref(msg);
|
2009-12-17 18:52:32 +00:00
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
if (!cbs->powered) {
|
|
|
|
|
error.type = OFONO_ERROR_TYPE_NO_ERROR;
|
|
|
|
|
cbs_set_topics_cb(&error, cbs);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
topic_str = cbs_topics_to_str(cbs, topics);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
cbs->driver->set_topics(cbs, topic_str, cbs_set_topics_cb, cbs);
|
|
|
|
|
g_free(topic_str);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
static void cbs_set_powered_cb(const struct ofono_error *error, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
|
|
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
|
2010-01-21 03:34:19 +00:00
|
|
|
|
ofono_error("Setting Cell Broadcast topics failed");
|
|
|
|
|
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (cbs->pending == NULL)
|
2009-12-17 20:54:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__ofono_dbus_pending_reply(&cbs->pending,
|
|
|
|
|
__ofono_error_failed(cbs->pending));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs->powered = !cbs->powered;
|
|
|
|
|
|
|
|
|
|
if (cbs->settings) {
|
|
|
|
|
g_key_file_set_boolean(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Powered", cbs->powered);
|
|
|
|
|
storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofono_dbus_signal_property_changed(conn, path,
|
2010-06-10 03:07:11 +00:00
|
|
|
|
OFONO_CELL_BROADCAST_INTERFACE,
|
2009-12-17 20:54:07 +00:00
|
|
|
|
"Powered",
|
|
|
|
|
DBUS_TYPE_BOOLEAN,
|
|
|
|
|
&cbs->powered);
|
|
|
|
|
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (cbs->pending == NULL)
|
2009-12-17 20:54:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(cbs->pending);
|
|
|
|
|
__ofono_dbus_pending_reply(&cbs->pending, reply);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusMessage *cbs_set_powered(struct ofono_cbs *cbs, gboolean value,
|
|
|
|
|
DBusMessage *msg)
|
|
|
|
|
{
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
char *topic_str;
|
|
|
|
|
|
|
|
|
|
if (cbs->powered == value)
|
|
|
|
|
goto reply;
|
|
|
|
|
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (cbs->driver->set_topics == NULL ||
|
|
|
|
|
cbs->driver->clear_topics == NULL)
|
2009-12-17 20:54:07 +00:00
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
|
cbs->pending = dbus_message_ref(msg);
|
|
|
|
|
|
2009-12-18 03:25:15 +00:00
|
|
|
|
if (value) {
|
2009-12-17 20:54:07 +00:00
|
|
|
|
topic_str = cbs_topics_to_str(cbs, cbs->topics);
|
|
|
|
|
cbs->driver->set_topics(cbs, topic_str,
|
|
|
|
|
cbs_set_powered_cb, cbs);
|
|
|
|
|
g_free(topic_str);
|
2009-12-18 03:25:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
cbs->driver->clear_topics(cbs, cbs_set_powered_cb, cbs);
|
2009-12-17 20:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2009-12-18 03:23:20 +00:00
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
done:
|
|
|
|
|
cbs->powered = value;
|
|
|
|
|
|
|
|
|
|
if (cbs->settings) {
|
|
|
|
|
g_key_file_set_boolean(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Powered", cbs->powered);
|
|
|
|
|
storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofono_dbus_signal_property_changed(conn, path,
|
2010-06-10 03:07:11 +00:00
|
|
|
|
OFONO_CELL_BROADCAST_INTERFACE,
|
2009-12-17 20:54:07 +00:00
|
|
|
|
"Powered",
|
|
|
|
|
DBUS_TYPE_BOOLEAN,
|
|
|
|
|
&cbs->powered);
|
|
|
|
|
|
|
|
|
|
reply:
|
|
|
|
|
if (msg)
|
|
|
|
|
return dbus_message_new_method_return(msg);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
static DBusMessage *cbs_set_property(DBusConnection *conn, DBusMessage *msg,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusMessageIter var;
|
|
|
|
|
const char *property;
|
|
|
|
|
|
|
|
|
|
if (cbs->pending)
|
|
|
|
|
return __ofono_error_busy(msg);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_init(msg, &iter))
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&iter, &property);
|
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&iter, &var);
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
if (!strcmp(property, "Powered")) {
|
|
|
|
|
dbus_bool_t value;
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&var, &value);
|
|
|
|
|
|
|
|
|
|
return cbs_set_powered(cbs, value, msg);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
if (!strcmp(property, "Topics")) {
|
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&var, &value);
|
|
|
|
|
|
|
|
|
|
return cbs_set_topics(cbs, value, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-20 05:07:25 +00:00
|
|
|
|
static const GDBusMethodTable cbs_methods[] = {
|
2012-05-20 05:07:32 +00:00
|
|
|
|
{ GDBUS_METHOD("GetProperties",
|
2012-05-20 05:07:29 +00:00
|
|
|
|
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
|
|
|
|
|
cbs_get_properties) },
|
2012-05-20 05:07:32 +00:00
|
|
|
|
{ GDBUS_ASYNC_METHOD("SetProperty",
|
|
|
|
|
GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
|
|
|
|
|
NULL, cbs_set_property) },
|
2009-09-10 21:10:14 +00:00
|
|
|
|
{ }
|
|
|
|
|
};
|
|
|
|
|
|
2012-05-20 05:07:26 +00:00
|
|
|
|
static const GDBusSignalTable cbs_signals[] = {
|
2012-05-20 05:07:32 +00:00
|
|
|
|
{ GDBUS_SIGNAL("PropertyChanged",
|
2012-05-20 05:07:29 +00:00
|
|
|
|
GDBUS_ARGS({ "property", "s" }, { "value", "v" })) },
|
2012-05-20 05:07:32 +00:00
|
|
|
|
{ GDBUS_SIGNAL("IncomingBroadcast",
|
2012-05-20 05:07:29 +00:00
|
|
|
|
GDBUS_ARGS({ "message", "s" }, { "channel", "q" })) },
|
2012-05-20 05:07:32 +00:00
|
|
|
|
{ GDBUS_SIGNAL("EmergencyBroadcast",
|
2012-05-20 05:07:29 +00:00
|
|
|
|
GDBUS_ARGS({ "message", "s" }, { "dict", "a{sv}" })) },
|
2009-09-10 21:10:14 +00:00
|
|
|
|
{ }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int ofono_cbs_driver_register(const struct ofono_cbs_driver *d)
|
|
|
|
|
{
|
|
|
|
|
DBG("driver: %p, name: %s", d, d->name);
|
|
|
|
|
|
|
|
|
|
if (d->probe == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2010-11-19 13:57:22 +00:00
|
|
|
|
g_drivers = g_slist_prepend(g_drivers, (void *) d);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ofono_cbs_driver_unregister(const struct ofono_cbs_driver *d)
|
|
|
|
|
{
|
|
|
|
|
DBG("driver: %p, name: %s", d, d->name);
|
|
|
|
|
|
2010-11-19 13:57:22 +00:00
|
|
|
|
g_drivers = g_slist_remove(g_drivers, (void *) d);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cbs_unregister(struct ofono_atom *atom)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = __ofono_atom_get_data(atom);
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
struct ofono_modem *modem = __ofono_atom_get_modem(atom);
|
|
|
|
|
const char *path = __ofono_atom_get_path(atom);
|
|
|
|
|
|
2010-06-10 03:07:11 +00:00
|
|
|
|
g_dbus_unregister_interface(conn, path, OFONO_CELL_BROADCAST_INTERFACE);
|
|
|
|
|
ofono_modem_remove_interface(modem, OFONO_CELL_BROADCAST_INTERFACE);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2009-09-15 19:35:09 +00:00
|
|
|
|
if (cbs->topics) {
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->topics, g_free);
|
2009-09-15 19:35:09 +00:00
|
|
|
|
cbs->topics = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->new_topics) {
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->new_topics, g_free);
|
2009-09-15 19:35:09 +00:00
|
|
|
|
cbs->new_topics = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
if (cbs->efcbmid_length) {
|
|
|
|
|
cbs->efcbmid_length = 0;
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->efcbmid_contents, g_free);
|
2009-12-17 18:52:32 +00:00
|
|
|
|
cbs->efcbmid_contents = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 07:37:37 +00:00
|
|
|
|
if (cbs->sim_context) {
|
|
|
|
|
ofono_sim_context_free(cbs->sim_context);
|
|
|
|
|
cbs->sim_context = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 16:53:19 +00:00
|
|
|
|
cbs->sim = NULL;
|
2010-04-09 06:49:01 +00:00
|
|
|
|
cbs->stk = NULL;
|
2009-09-11 21:25:30 +00:00
|
|
|
|
|
2009-09-12 02:38:08 +00:00
|
|
|
|
if (cbs->reset_source) {
|
|
|
|
|
g_source_remove(cbs->reset_source);
|
|
|
|
|
cbs->reset_source = 0;
|
|
|
|
|
|
|
|
|
|
if (cbs->netreg)
|
|
|
|
|
__ofono_netreg_set_base_station_name(cbs->netreg, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
cbs->powered = FALSE;
|
|
|
|
|
|
|
|
|
|
if (cbs->settings) {
|
|
|
|
|
storage_close(cbs->imsi, SETTINGS_STORE, cbs->settings, TRUE);
|
|
|
|
|
|
|
|
|
|
g_free(cbs->imsi);
|
|
|
|
|
cbs->imsi = NULL;
|
|
|
|
|
cbs->settings = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-11 21:25:30 +00:00
|
|
|
|
if (cbs->netreg_watch) {
|
|
|
|
|
if (cbs->location_watch) {
|
|
|
|
|
__ofono_netreg_remove_status_watch(cbs->netreg,
|
|
|
|
|
cbs->location_watch);
|
|
|
|
|
cbs->location_watch = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__ofono_modem_remove_atom_watch(modem, cbs->netreg_watch);
|
|
|
|
|
cbs->netreg_watch = 0;
|
|
|
|
|
cbs->netreg = NULL;
|
2009-09-10 21:10:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cbs_remove(struct ofono_atom *atom)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = __ofono_atom_get_data(atom);
|
|
|
|
|
|
|
|
|
|
DBG("atom: %p", atom);
|
|
|
|
|
|
|
|
|
|
if (cbs == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-02 08:46:44 +00:00
|
|
|
|
if (cbs->driver != NULL && cbs->driver->remove != NULL)
|
2009-09-10 21:10:14 +00:00
|
|
|
|
cbs->driver->remove(cbs);
|
|
|
|
|
|
2009-09-11 20:18:27 +00:00
|
|
|
|
cbs_assembly_free(cbs->assembly);
|
|
|
|
|
cbs->assembly = NULL;
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
|
|
|
|
g_free(cbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ofono_cbs *ofono_cbs_create(struct ofono_modem *modem,
|
|
|
|
|
unsigned int vendor,
|
|
|
|
|
const char *driver,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs;
|
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
|
|
if (driver == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
cbs = g_try_new0(struct ofono_cbs, 1);
|
|
|
|
|
|
|
|
|
|
if (cbs == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
cbs->assembly = cbs_assembly_new();
|
|
|
|
|
cbs->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_CBS,
|
|
|
|
|
cbs_remove, cbs);
|
|
|
|
|
|
|
|
|
|
for (l = g_drivers; l; l = l->next) {
|
|
|
|
|
const struct ofono_cbs_driver *drv = l->data;
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0(drv->name, driver))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (drv->probe(cbs, vendor, data) < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
cbs->driver = drv;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cbs;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 16:30:35 +00:00
|
|
|
|
static void cbs_got_file_contents(struct ofono_cbs *cbs)
|
|
|
|
|
{
|
|
|
|
|
gboolean powered;
|
|
|
|
|
GSList *initial_topics = NULL;
|
|
|
|
|
char *topics_str;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
if (cbs->topics == NULL) {
|
|
|
|
|
if (cbs->efcbmi_contents != NULL)
|
|
|
|
|
initial_topics = g_slist_concat(initial_topics,
|
|
|
|
|
g_slist_copy(cbs->efcbmi_contents));
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmir_contents != NULL)
|
|
|
|
|
initial_topics = g_slist_concat(initial_topics,
|
|
|
|
|
g_slist_copy(cbs->efcbmir_contents));
|
|
|
|
|
|
|
|
|
|
cbs->topics = cbs_optimize_ranges(initial_topics);
|
|
|
|
|
g_slist_free(initial_topics);
|
|
|
|
|
|
|
|
|
|
topics_str = cbs_topic_ranges_to_string(cbs->topics);
|
|
|
|
|
g_key_file_set_string(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Topics", topics_str);
|
|
|
|
|
g_free(topics_str);
|
|
|
|
|
storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmi_length) {
|
|
|
|
|
cbs->efcbmi_length = 0;
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->efcbmi_contents, g_free);
|
2010-01-11 16:30:35 +00:00
|
|
|
|
cbs->efcbmi_contents = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmir_length) {
|
|
|
|
|
cbs->efcbmir_length = 0;
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->efcbmir_contents, g_free);
|
2010-01-11 16:30:35 +00:00
|
|
|
|
cbs->efcbmir_contents = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
powered = g_key_file_get_boolean(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Powered", &error);
|
2010-01-20 16:26:02 +00:00
|
|
|
|
|
|
|
|
|
if (error) {
|
2011-02-08 22:26:20 +00:00
|
|
|
|
g_error_free(error);
|
2010-01-21 03:03:17 +00:00
|
|
|
|
powered = TRUE;
|
2010-01-20 16:26:02 +00:00
|
|
|
|
g_key_file_set_boolean(cbs->settings, SETTINGS_GROUP,
|
2010-01-21 03:03:17 +00:00
|
|
|
|
"Powered", powered);
|
2010-01-20 16:26:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 16:30:35 +00:00
|
|
|
|
cbs_set_powered(cbs, powered, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 19:02:28 +00:00
|
|
|
|
static void sim_cbmi_read_cb(int ok, int length, int record,
|
2009-09-15 19:35:39 +00:00
|
|
|
|
const unsigned char *data,
|
|
|
|
|
int record_length, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = userdata;
|
|
|
|
|
unsigned short mi;
|
|
|
|
|
int i;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((length % 2) == 1 || length < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cbs->efcbmi_length = length;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i += 2) {
|
|
|
|
|
struct cbs_topic_range *range;
|
|
|
|
|
|
|
|
|
|
if (data[i] == 0xff && data[i+1] == 0xff)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
mi = (data[i] << 8) + data[i+1];
|
|
|
|
|
|
|
|
|
|
if (mi > 999)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
range = g_new0(struct cbs_topic_range, 1);
|
|
|
|
|
range->min = mi;
|
|
|
|
|
range->max = mi;
|
|
|
|
|
|
|
|
|
|
cbs->efcbmi_contents = g_slist_prepend(cbs->efcbmi_contents,
|
|
|
|
|
range);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmi_contents == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
str = cbs_topic_ranges_to_string(cbs->efcbmi_contents);
|
2010-02-08 17:54:03 +00:00
|
|
|
|
DBG("Got cbmi: %s", str);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
g_free(str);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 19:02:28 +00:00
|
|
|
|
static void sim_cbmir_read_cb(int ok, int length, int record,
|
2009-09-15 19:35:39 +00:00
|
|
|
|
const unsigned char *data,
|
|
|
|
|
int record_length, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = userdata;
|
|
|
|
|
int i;
|
|
|
|
|
unsigned short min;
|
|
|
|
|
unsigned short max;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((length % 4) != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cbs->efcbmir_length = length;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i += 4) {
|
|
|
|
|
struct cbs_topic_range *range;
|
|
|
|
|
|
|
|
|
|
if (data[i] == 0xff && data[i+1] == 0xff &&
|
|
|
|
|
data[i+2] == 0xff && data[i+3] == 0xff)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
min = (data[i] << 8) + data[i+1];
|
|
|
|
|
max = (data[i+2] << 8) + data[i+3];
|
|
|
|
|
|
|
|
|
|
if (min > 999 || max > 999 || min > max)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
range = g_new0(struct cbs_topic_range, 1);
|
|
|
|
|
range->min = min;
|
|
|
|
|
range->max = max;
|
|
|
|
|
|
|
|
|
|
cbs->efcbmir_contents = g_slist_prepend(cbs->efcbmir_contents,
|
|
|
|
|
range);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmir_contents == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
str = cbs_topic_ranges_to_string(cbs->efcbmir_contents);
|
2010-02-08 17:54:03 +00:00
|
|
|
|
DBG("Got cbmir: %s", str);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
g_free(str);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-02 19:02:28 +00:00
|
|
|
|
static void sim_cbmid_read_cb(int ok, int length, int record,
|
2009-09-15 19:35:39 +00:00
|
|
|
|
const unsigned char *data,
|
|
|
|
|
int record_length, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = userdata;
|
|
|
|
|
unsigned short mi;
|
|
|
|
|
int i;
|
|
|
|
|
char *str;
|
2009-12-17 18:52:32 +00:00
|
|
|
|
GSList *contents = NULL;
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
|
|
|
|
if (!ok)
|
2010-01-21 03:35:33 +00:00
|
|
|
|
goto done;
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
|
|
|
|
if ((length % 2) == 1 || length < 2)
|
2010-01-21 03:35:33 +00:00
|
|
|
|
goto done;
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
|
|
|
|
cbs->efcbmid_length = length;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i += 2) {
|
|
|
|
|
struct cbs_topic_range *range;
|
|
|
|
|
|
|
|
|
|
if (data[i] == 0xff && data[i+1] == 0xff)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
mi = (data[i] << 8) + data[i+1];
|
|
|
|
|
|
|
|
|
|
range = g_new0(struct cbs_topic_range, 1);
|
|
|
|
|
range->min = mi;
|
|
|
|
|
range->max = mi;
|
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
contents = g_slist_prepend(contents, range);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
if (contents == NULL)
|
2010-01-21 03:35:33 +00:00
|
|
|
|
goto done;
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
2009-12-17 18:52:32 +00:00
|
|
|
|
cbs->efcbmid_contents = g_slist_reverse(contents);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
|
|
|
|
str = cbs_topic_ranges_to_string(cbs->efcbmid_contents);
|
2010-02-08 17:54:03 +00:00
|
|
|
|
DBG("Got cbmid: %s", str);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
g_free(str);
|
2010-01-11 16:30:35 +00:00
|
|
|
|
|
2010-01-21 03:35:33 +00:00
|
|
|
|
done:
|
2011-02-15 07:58:56 +00:00
|
|
|
|
if (cbs->efcbmid_update) {
|
2011-02-17 20:49:03 +00:00
|
|
|
|
if (cbs->powered == TRUE) {
|
|
|
|
|
char *topic_str = cbs_topics_to_str(cbs, cbs->topics);
|
|
|
|
|
cbs->driver->set_topics(cbs, topic_str,
|
|
|
|
|
cbs_set_powered_cb, cbs);
|
|
|
|
|
g_free(topic_str);
|
|
|
|
|
}
|
2011-02-15 07:58:56 +00:00
|
|
|
|
|
|
|
|
|
cbs->efcbmid_update = FALSE;
|
|
|
|
|
} else
|
|
|
|
|
cbs_got_file_contents(cbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cbs_efcbmid_changed(int id, void *userdata)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = userdata;
|
|
|
|
|
|
|
|
|
|
if (cbs->efcbmid_length) {
|
|
|
|
|
cbs->efcbmid_length = 0;
|
2016-04-22 13:10:06 +00:00
|
|
|
|
g_slist_free_full(cbs->efcbmid_contents, g_free);
|
2011-02-15 07:58:56 +00:00
|
|
|
|
cbs->efcbmid_contents = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs->efcbmid_update = TRUE;
|
|
|
|
|
|
|
|
|
|
ofono_sim_read(cbs->sim_context, SIM_EFCBMID_FILEID,
|
|
|
|
|
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
|
|
|
|
|
sim_cbmid_read_cb, cbs);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 16:53:19 +00:00
|
|
|
|
static void cbs_got_imsi(struct ofono_cbs *cbs)
|
2009-09-10 21:10:14 +00:00
|
|
|
|
{
|
|
|
|
|
const char *imsi = ofono_sim_get_imsi(cbs->sim);
|
2010-01-11 16:30:35 +00:00
|
|
|
|
char *topics_str;
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2010-02-08 17:54:03 +00:00
|
|
|
|
DBG("Got IMSI: %s", imsi);
|
2009-09-15 19:35:39 +00:00
|
|
|
|
|
2009-12-17 20:54:07 +00:00
|
|
|
|
cbs->settings = storage_open(imsi, SETTINGS_STORE);
|
|
|
|
|
if (cbs->settings == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cbs->imsi = g_strdup(imsi);
|
|
|
|
|
|
2010-01-11 16:30:35 +00:00
|
|
|
|
cbs->topics = NULL;
|
|
|
|
|
|
|
|
|
|
topics_str = g_key_file_get_string(cbs->settings, SETTINGS_GROUP,
|
|
|
|
|
"Topics", NULL);
|
|
|
|
|
if (topics_str)
|
|
|
|
|
cbs->topics = cbs_extract_topic_ranges(topics_str);
|
|
|
|
|
|
2010-09-21 19:18:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* If stored value is invalid or no stored value, bootstrap
|
|
|
|
|
* topics list from SIM contents
|
|
|
|
|
*/
|
2010-01-11 16:30:35 +00:00
|
|
|
|
if (topics_str == NULL ||
|
|
|
|
|
(cbs->topics == NULL && topics_str[0] != '\0')) {
|
2011-02-03 07:37:37 +00:00
|
|
|
|
ofono_sim_read(cbs->sim_context, SIM_EFCBMI_FILEID,
|
2010-01-11 16:30:35 +00:00
|
|
|
|
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
|
|
|
|
|
sim_cbmi_read_cb, cbs);
|
2011-02-03 07:37:37 +00:00
|
|
|
|
ofono_sim_read(cbs->sim_context, SIM_EFCBMIR_FILEID,
|
2010-01-11 16:30:35 +00:00
|
|
|
|
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
|
|
|
|
|
sim_cbmir_read_cb, cbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (topics_str)
|
|
|
|
|
g_free(topics_str);
|
2009-12-17 20:54:07 +00:00
|
|
|
|
|
2011-02-03 07:37:37 +00:00
|
|
|
|
ofono_sim_read(cbs->sim_context, SIM_EFCBMID_FILEID,
|
2009-10-02 19:02:28 +00:00
|
|
|
|
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
|
|
|
|
|
sim_cbmid_read_cb, cbs);
|
2011-02-15 07:58:56 +00:00
|
|
|
|
ofono_sim_add_file_watch(cbs->sim_context, SIM_EFCBMID_FILEID,
|
|
|
|
|
cbs_efcbmid_changed, cbs, NULL);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-12 02:38:08 +00:00
|
|
|
|
static gboolean reset_base_station_name(gpointer user)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = user;
|
|
|
|
|
|
|
|
|
|
cbs->reset_source = 0;
|
|
|
|
|
|
|
|
|
|
if (cbs->netreg == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
__ofono_netreg_set_base_station_name(cbs->netreg, NULL);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-11 21:25:30 +00:00
|
|
|
|
static void cbs_location_changed(int status, int lac, int ci, int tech,
|
2009-10-29 20:28:26 +00:00
|
|
|
|
const char *mcc, const char *mnc,
|
2009-09-11 21:25:30 +00:00
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
|
|
|
|
gboolean plmn_changed = FALSE;
|
|
|
|
|
gboolean lac_changed = FALSE;
|
|
|
|
|
gboolean ci_changed = FALSE;
|
|
|
|
|
|
2009-10-29 20:28:26 +00:00
|
|
|
|
DBG("%d, %d, %d, %d, %s%s", status, lac, ci, tech, mcc, mnc);
|
2009-09-11 21:25:30 +00:00
|
|
|
|
|
2010-11-27 19:39:03 +00:00
|
|
|
|
if (mcc == NULL || mnc == NULL) {
|
2009-09-11 21:25:30 +00:00
|
|
|
|
if (cbs->mcc[0] == '\0' && cbs->mnc[0] == '\0')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
memset(cbs->mcc, 0, sizeof(cbs->mcc));
|
|
|
|
|
memset(cbs->mnc, 0, sizeof(cbs->mnc));
|
|
|
|
|
|
|
|
|
|
plmn_changed = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-29 20:28:26 +00:00
|
|
|
|
if (strcmp(cbs->mcc, mcc) || strcmp(cbs->mnc, mnc)) {
|
|
|
|
|
memcpy(cbs->mcc, mcc, sizeof(cbs->mcc));
|
|
|
|
|
memcpy(cbs->mnc, mnc, sizeof(cbs->mnc));
|
2009-09-11 21:25:30 +00:00
|
|
|
|
|
|
|
|
|
plmn_changed = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->lac != lac) {
|
|
|
|
|
cbs->lac = lac;
|
|
|
|
|
|
|
|
|
|
lac_changed = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbs->ci != ci) {
|
|
|
|
|
cbs->ci = ci;
|
|
|
|
|
|
|
|
|
|
ci_changed = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
DBG("%d, %d, %d", plmn_changed, lac_changed, ci_changed);
|
|
|
|
|
|
2010-09-21 19:18:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* In order to minimize signal transmissions we wait about X seconds
|
2015-12-21 10:03:49 +00:00
|
|
|
|
* before resetting the base station id. The hope is that we receive
|
2009-09-12 02:38:08 +00:00
|
|
|
|
* another cell broadcast with the new base station name within
|
|
|
|
|
* that time
|
|
|
|
|
*/
|
|
|
|
|
if (lac_changed || ci_changed) {
|
2015-12-21 10:03:49 +00:00
|
|
|
|
if(cbs->reset_source)
|
|
|
|
|
g_source_remove(cbs->reset_source);
|
|
|
|
|
|
2010-01-12 16:28:37 +00:00
|
|
|
|
cbs->reset_source =
|
2009-09-12 02:38:08 +00:00
|
|
|
|
g_timeout_add_seconds(3, reset_base_station_name, cbs);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-11 21:25:30 +00:00
|
|
|
|
cbs_assembly_location_changed(cbs->assembly, plmn_changed,
|
|
|
|
|
lac_changed, ci_changed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void netreg_watch(struct ofono_atom *atom,
|
|
|
|
|
enum ofono_atom_watch_condition cond,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_cbs *cbs = data;
|
2009-10-28 00:47:52 +00:00
|
|
|
|
const char *mcc;
|
|
|
|
|
const char *mnc;
|
2009-09-11 21:25:30 +00:00
|
|
|
|
|
|
|
|
|
if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
|
|
|
|
|
cbs->location_watch = 0;
|
2009-10-26 21:18:17 +00:00
|
|
|
|
cbs->netreg = 0;
|
2009-09-11 21:25:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs->netreg = __ofono_atom_get_data(atom);
|
|
|
|
|
cbs->location_watch = __ofono_netreg_add_status_watch(cbs->netreg,
|
|
|
|
|
cbs_location_changed, cbs, NULL);
|
|
|
|
|
|
2009-10-28 00:47:52 +00:00
|
|
|
|
mcc = ofono_netreg_get_mcc(cbs->netreg);
|
|
|
|
|
mnc = ofono_netreg_get_mnc(cbs->netreg);
|
2009-09-11 21:25:30 +00:00
|
|
|
|
|
2009-10-28 00:47:52 +00:00
|
|
|
|
if (mcc && mnc) {
|
|
|
|
|
memcpy(cbs->mcc, mcc, sizeof(cbs->mcc));
|
|
|
|
|
memcpy(cbs->mnc, mnc, sizeof(cbs->mnc));
|
2009-09-11 21:25:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
memset(cbs->mcc, 0, sizeof(cbs->mcc));
|
|
|
|
|
memset(cbs->mnc, 0, sizeof(cbs->mnc));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbs->lac = ofono_netreg_get_location(cbs->netreg);
|
|
|
|
|
cbs->ci = ofono_netreg_get_cellid(cbs->netreg);
|
|
|
|
|
|
2010-09-21 19:18:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* Clear out the cbs assembly just in case, worst case
|
2009-09-11 21:25:30 +00:00
|
|
|
|
* we will receive the cell broadcasts again
|
|
|
|
|
*/
|
|
|
|
|
cbs_assembly_location_changed(cbs->assembly, TRUE, TRUE, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
void ofono_cbs_register(struct ofono_cbs *cbs)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
struct ofono_modem *modem = __ofono_atom_get_modem(cbs->atom);
|
|
|
|
|
const char *path = __ofono_atom_get_path(cbs->atom);
|
|
|
|
|
|
|
|
|
|
if (!g_dbus_register_interface(conn, path,
|
2010-06-10 03:07:11 +00:00
|
|
|
|
OFONO_CELL_BROADCAST_INTERFACE,
|
|
|
|
|
cbs_methods, cbs_signals,
|
2009-09-10 21:10:14 +00:00
|
|
|
|
NULL, cbs, NULL)) {
|
|
|
|
|
ofono_error("Could not create %s interface",
|
2010-06-10 03:07:11 +00:00
|
|
|
|
OFONO_CELL_BROADCAST_INTERFACE);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 03:07:11 +00:00
|
|
|
|
ofono_modem_add_interface(modem, OFONO_CELL_BROADCAST_INTERFACE);
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2012-01-18 17:29:12 +00:00
|
|
|
|
cbs->sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
|
|
|
|
|
if (cbs->sim) {
|
2011-02-03 07:37:37 +00:00
|
|
|
|
cbs->sim_context = ofono_sim_context_create(cbs->sim);
|
|
|
|
|
|
2010-04-09 06:48:34 +00:00
|
|
|
|
if (ofono_sim_get_state(cbs->sim) == OFONO_SIM_STATE_READY)
|
2009-09-17 16:53:19 +00:00
|
|
|
|
cbs_got_imsi(cbs);
|
|
|
|
|
}
|
2009-09-10 21:10:14 +00:00
|
|
|
|
|
2012-01-18 17:29:12 +00:00
|
|
|
|
cbs->stk = __ofono_atom_find(OFONO_ATOM_TYPE_STK, modem);
|
2010-04-09 06:49:01 +00:00
|
|
|
|
|
2009-09-11 21:25:30 +00:00
|
|
|
|
cbs->netreg_watch = __ofono_modem_add_atom_watch(modem,
|
|
|
|
|
OFONO_ATOM_TYPE_NETREG,
|
|
|
|
|
netreg_watch, cbs, NULL);
|
|
|
|
|
|
2009-09-10 21:10:14 +00:00
|
|
|
|
__ofono_atom_register(cbs->atom, cbs_unregister);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ofono_cbs_remove(struct ofono_cbs *cbs)
|
|
|
|
|
{
|
|
|
|
|
__ofono_atom_free(cbs->atom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ofono_cbs_set_data(struct ofono_cbs *cbs, void *data)
|
|
|
|
|
{
|
|
|
|
|
cbs->driver_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *ofono_cbs_get_data(struct ofono_cbs *cbs)
|
|
|
|
|
{
|
|
|
|
|
return cbs->driver_data;
|
|
|
|
|
}
|