207
struct ofono_atom *__ofono_modem_add_atom_offline(struct ofono_modem *modem,
208
enum ofono_atom_type type,
209
void (*destruct)(struct ofono_atom *),
212
struct ofono_atom *atom;
214
atom = __ofono_modem_add_atom(modem, type, destruct, data);
216
atom->modem_state = MODEM_STATE_OFFLINE;
190
221
void *__ofono_atom_get_data(struct ofono_atom *atom)
192
223
return atom->data;
266
300
watch->item.destroy = destroy;
267
301
watch->item.notify_data = data;
269
return __ofono_watchlist_add_item(modem->atom_watches,
303
id = __ofono_watchlist_add_item(modem->atom_watches,
270
304
(struct ofono_watchlist_item *)watch);
306
for (l = modem->atoms; l; l = l->next) {
309
if (atom->type != type || atom->unregister == NULL)
312
notify(atom, OFONO_ATOM_WATCH_CONDITION_REGISTERED, data);
273
318
gboolean __ofono_modem_remove_atom_watch(struct ofono_modem *modem,
363
void __ofono_modem_foreach_registered_atom(struct ofono_modem *modem,
364
enum ofono_atom_type type,
365
ofono_atom_func callback,
369
struct ofono_atom *atom;
374
for (l = modem->atoms; l; l = l->next) {
377
if (atom->type != type)
380
if (atom->unregister == NULL)
383
callback(atom, data);
318
387
void __ofono_atom_free(struct ofono_atom *atom)
320
389
struct ofono_modem *modem = atom->modem;
379
448
for (l = modem->online_watches->items; l; l = l->next) {
381
450
notify = item->notify;
382
notify(modem->online, item->notify_data);
451
notify(modem, modem->online, item->notify_data);
455
static void notify_powered_watches(struct ofono_modem *modem)
457
struct ofono_watchlist_item *item;
459
ofono_modem_powered_notify_func notify;
461
if (modem->powered_watches == NULL)
464
for (l = modem->powered_watches->items; l; l = l->next) {
466
notify = item->notify;
467
notify(modem, modem->powered, item->notify_data);
471
static void set_online(struct ofono_modem *modem, ofono_bool_t new_online)
473
DBusConnection *conn = ofono_dbus_get_connection();
475
if (new_online == modem->online)
478
modem->online = new_online;
480
ofono_dbus_signal_property_changed(conn, modem->path,
481
OFONO_MODEM_INTERFACE,
482
"Online", DBUS_TYPE_BOOLEAN,
485
notify_online_watches(modem);
386
488
static void modem_change_state(struct ofono_modem *modem,
389
491
struct ofono_modem_driver const *driver = modem->driver;
390
492
enum modem_state old_state = modem->modem_state;
391
ofono_bool_t new_online = new_state == MODEM_STATE_ONLINE;
393
494
DBG("old state: %d, new state: %d", old_state, new_state);
395
496
if (old_state == new_state)
398
if (new_online != modem->online) {
399
DBusConnection *conn = ofono_dbus_get_connection();
400
modem->online = new_online;
401
ofono_dbus_signal_property_changed(conn, modem->path,
402
OFONO_MODEM_INTERFACE, "Online",
403
DBUS_TYPE_BOOLEAN, &modem->online);
406
499
modem->modem_state = new_state;
408
501
if (old_state > new_state)
462
554
__ofono_watchlist_remove_item(modem->online_watches, id);
557
unsigned int __ofono_modem_add_powered_watch(struct ofono_modem *modem,
558
ofono_modem_powered_notify_func notify,
559
void *data, ofono_destroy_func destroy)
561
struct ofono_watchlist_item *item;
563
if (modem == NULL || notify == NULL)
566
item = g_new0(struct ofono_watchlist_item, 1);
568
item->notify = notify;
569
item->destroy = destroy;
570
item->notify_data = data;
572
return __ofono_watchlist_add_item(modem->powered_watches, item);
575
void __ofono_modem_remove_powered_watch(struct ofono_modem *modem,
578
__ofono_watchlist_remove_item(modem->powered_watches, id);
581
static gboolean modem_has_sim(struct ofono_modem *modem)
584
struct ofono_atom *atom;
586
for (l = modem->atoms; l; l = l->next) {
589
if (atom->type == OFONO_ATOM_TYPE_SIM)
465
596
static void common_online_cb(const struct ofono_error *error, void *data)
467
598
struct ofono_modem *modem = data;
485
616
switch (modem->modem_state) {
486
617
case MODEM_STATE_OFFLINE:
618
set_online(modem, TRUE);
620
/* Will this increase emergency call setup time??? */
487
621
modem_change_state(modem, MODEM_STATE_ONLINE);
489
623
case MODEM_STATE_POWER_OFF:
490
624
/* The powered operation is pending */
492
626
case MODEM_STATE_PRE_SIM:
493
/* Go back offline if the sim was removed */
494
modem->driver->set_online(modem, 0, NULL, NULL);
628
* Its valid to be in online even without a SIM/SIM being
629
* PIN locked. e.g.: Emergency mode
631
DBG("Online in PRE SIM state");
633
set_online(modem, TRUE);
496
635
case MODEM_STATE_ONLINE:
497
636
ofono_error("Online called when the modem is already online!");
532
670
__ofono_dbus_pending_reply(&modem->pending, reply);
534
if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
535
modem->modem_state == MODEM_STATE_ONLINE)
536
modem_change_state(modem, MODEM_STATE_OFFLINE);
672
if (error->type == OFONO_ERROR_TYPE_NO_ERROR) {
673
switch (modem->modem_state) {
674
case MODEM_STATE_PRE_SIM:
675
set_online(modem, FALSE);
677
case MODEM_STATE_ONLINE:
678
set_online(modem, FALSE);
679
modem_change_state(modem, MODEM_STATE_OFFLINE);
539
687
static void sim_state_watch(enum ofono_sim_state new_state, void *user)
543
691
switch (new_state) {
544
692
case OFONO_SIM_STATE_NOT_PRESENT:
545
693
modem_change_state(modem, MODEM_STATE_PRE_SIM);
547
694
case OFONO_SIM_STATE_INSERTED:
696
case OFONO_SIM_STATE_LOCKED_OUT:
697
modem_change_state(modem, MODEM_STATE_PRE_SIM);
549
699
case OFONO_SIM_STATE_READY:
550
700
modem_change_state(modem, MODEM_STATE_OFFLINE);
583
739
if (modem->online == online)
584
740
return dbus_message_new_method_return(msg);
742
if (ofono_modem_get_emergency_mode(modem) == TRUE)
743
return __ofono_error_emergency_active(msg);
586
745
if (driver->set_online == NULL)
587
746
return __ofono_error_not_implemented(msg);
589
if (modem->modem_state < MODEM_STATE_OFFLINE)
590
return __ofono_error_not_available(msg);
592
748
modem->pending = dbus_message_ref(msg);
594
750
driver->set_online(modem, online,
623
781
ofono_dbus_dict_append(dict, "Lockdown", DBUS_TYPE_BOOLEAN,
624
782
&modem->lockdown);
626
devinfo_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_DEVINFO);
628
/* We cheat a little here and don't check the registered status */
630
struct ofono_devinfo *info;
632
info = __ofono_atom_get_data(devinfo_atom);
784
ofono_dbus_dict_append(dict, "Emergency", DBUS_TYPE_BOOLEAN,
787
info = __ofono_atom_find(OFONO_ATOM_TYPE_DEVINFO, modem);
634
789
if (info->manufacturer)
635
790
ofono_dbus_dict_append(dict, "Manufacturer",
636
791
DBUS_TYPE_STRING,
936
1107
modem_change_state(modem, MODEM_STATE_PRE_SIM);
938
1109
/* Force SIM Ready for devies with no sim atom */
939
if (__ofono_modem_find_atom(modem,
940
OFONO_ATOM_TYPE_SIM) == NULL)
1110
if (modem_has_sim(modem) == FALSE)
941
1111
sim_state_watch(OFONO_SIM_STATE_READY, modem);
1113
set_online(modem, FALSE);
943
1114
modem_change_state(modem, MODEM_STATE_POWER_OFF);
951
1123
return __ofono_error_invalid_args(msg);
954
static GDBusMethodTable modem_methods[] = {
955
{ "GetProperties", "", "a{sv}", modem_get_properties },
956
{ "SetProperty", "sv", "", modem_set_property,
957
G_DBUS_METHOD_FLAG_ASYNC },
1126
static const GDBusMethodTable modem_methods[] = {
1127
{ GDBUS_METHOD("GetProperties",
1128
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
1129
modem_get_properties) },
1130
{ GDBUS_ASYNC_METHOD("SetProperty",
1131
GDBUS_ARGS({ "property", "s" }, { "value", "v" }),
1132
NULL, modem_set_property) },
961
static GDBusSignalTable modem_signals[] = {
962
{ "PropertyChanged", "sv" },
1136
static const GDBusSignalTable modem_signals[] = {
1137
{ GDBUS_SIGNAL("PropertyChanged",
1138
GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
1014
1191
modem_change_state(modem, MODEM_STATE_PRE_SIM);
1016
1193
/* Force SIM Ready for devices with no sim atom */
1017
if (__ofono_modem_find_atom(modem,
1018
OFONO_ATOM_TYPE_SIM) == NULL)
1194
if (modem_has_sim(modem) == FALSE)
1019
1195
sim_state_watch(OFONO_SIM_STATE_READY, modem);
1197
set_online(modem, FALSE);
1021
1199
modem_change_state(modem, MODEM_STATE_POWER_OFF);
1024
1203
if (powering_down && powered == FALSE) {
1460
static void attr_template(struct ofono_emulator *em,
1461
struct ofono_emulator_request *req,
1464
struct ofono_error result;
1471
switch (ofono_emulator_request_get_type(req)) {
1472
case OFONO_EMULATOR_REQUEST_TYPE_COMMAND_ONLY:
1473
ofono_emulator_send_info(em, attr, TRUE);
1474
result.type = OFONO_ERROR_TYPE_NO_ERROR;
1475
ofono_emulator_send_final(em, &result);
1477
case OFONO_EMULATOR_REQUEST_TYPE_SUPPORT:
1478
result.type = OFONO_ERROR_TYPE_NO_ERROR;
1479
ofono_emulator_send_final(em, &result);
1482
result.type = OFONO_ERROR_TYPE_FAILURE;
1483
ofono_emulator_send_final(em, &result);
1487
static void gmi_cb(struct ofono_emulator *em,
1488
struct ofono_emulator_request *req, void *userdata)
1490
struct ofono_devinfo *info = userdata;
1492
attr_template(em, req, info->manufacturer);
1495
static void gmm_cb(struct ofono_emulator *em,
1496
struct ofono_emulator_request *req, void *userdata)
1498
struct ofono_devinfo *info = userdata;
1500
attr_template(em, req, info->model);
1503
static void gmr_cb(struct ofono_emulator *em,
1504
struct ofono_emulator_request *req, void *userdata)
1506
struct ofono_devinfo *info = userdata;
1508
attr_template(em, req, info->revision);
1511
static void gcap_cb(struct ofono_emulator *em,
1512
struct ofono_emulator_request *req, void *userdata)
1514
attr_template(em, req, "+GCAP: +CGSM");
1517
static void dun_watch(struct ofono_atom *atom,
1518
enum ofono_atom_watch_condition cond, void *data)
1520
struct ofono_emulator *em = __ofono_atom_get_data(atom);
1522
if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED)
1525
ofono_emulator_add_handler(em, "+GMI", gmi_cb, data, NULL);
1526
ofono_emulator_add_handler(em, "+GMM", gmm_cb, data, NULL);
1527
ofono_emulator_add_handler(em, "+GMR", gmr_cb, data, NULL);
1528
ofono_emulator_add_handler(em, "+GCAP", gcap_cb, data, NULL);
1279
1531
int ofono_devinfo_driver_register(const struct ofono_devinfo_driver *d)
1281
1533
DBG("driver: %p, name: %s", d, d->name);
1596
static void devinfo_unregister(struct ofono_atom *atom)
1598
struct ofono_devinfo *info = __ofono_atom_get_data(atom);
1600
g_free(info->manufacturer);
1601
info->manufacturer = NULL;
1603
g_free(info->model);
1606
g_free(info->revision);
1607
info->revision = NULL;
1609
g_free(info->serial);
1610
info->serial = NULL;
1349
1613
void ofono_devinfo_register(struct ofono_devinfo *info)
1615
struct ofono_modem *modem = __ofono_atom_get_modem(info->atom);
1617
__ofono_atom_register(info->atom, devinfo_unregister);
1619
info->dun_watch = __ofono_modem_add_atom_watch(modem,
1620
OFONO_ATOM_TYPE_EMULATOR_DUN,
1621
dun_watch, info, NULL);
1351
1623
query_manufacturer(info);
1890
2195
func(modem, userdata);
2199
ofono_bool_t ofono_modem_get_emergency_mode(struct ofono_modem *modem)
2201
return modem->emergency != 0;
2204
void __ofono_modem_inc_emergency_mode(struct ofono_modem *modem)
2206
DBusConnection *conn = ofono_dbus_get_connection();
2207
dbus_bool_t emergency = TRUE;
2209
if (++modem->emergency > 1)
2212
ofono_dbus_signal_property_changed(conn, modem->path,
2213
OFONO_MODEM_INTERFACE,
2214
"Emergency", DBUS_TYPE_BOOLEAN,
2218
void __ofono_modem_dec_emergency_mode(struct ofono_modem *modem)
2220
DBusConnection *conn = ofono_dbus_get_connection();
2221
dbus_bool_t emergency = FALSE;
2223
if (modem->emergency == 0) {
2224
ofono_error("emergency mode is already deactivated!!!");
2228
if (modem->emergency > 1)
2231
ofono_dbus_signal_property_changed(conn, modem->path,
2232
OFONO_MODEM_INTERFACE,
2233
"Emergency", DBUS_TYPE_BOOLEAN,