5 * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 * Copyright (C) 2011-2014 BMW Car IT GmbH.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #define CONNMAN_API_SUBJECT_TO_CHANGE
36 #include <connman/plugin.h>
37 #include <connman/device.h>
38 #include <connman/network.h>
39 #include <connman/inet.h>
40 #include <connman/dbus.h>
41 #include <connman/log.h>
42 #include <connman/technology.h>
46 #define OFONO_SERVICE "org.ofono"
48 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
49 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
50 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
51 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
52 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
53 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
54 #define OFONO_CDMA_CM_INTERFACE OFONO_SERVICE ".cdma.ConnectionManager"
55 #define OFONO_CDMA_NETREG_INTERFACE OFONO_SERVICE ".cdma.NetworkRegistration"
57 #define MODEM_ADDED "ModemAdded"
58 #define MODEM_REMOVED "ModemRemoved"
59 #define PROPERTY_CHANGED "PropertyChanged"
60 #define CONTEXT_ADDED "ContextAdded"
61 #define CONTEXT_REMOVED "ContextRemoved"
63 #define GET_PROPERTIES "GetProperties"
64 #define SET_PROPERTY "SetProperty"
65 #define GET_MODEMS "GetModems"
66 #define GET_CONTEXTS "GetContexts"
72 OFONO_API_NETREG = 0x2,
74 OFONO_API_CDMA_NETREG = 0x8,
75 OFONO_API_CDMA_CM = 0x10,
79 * The way this plugin works is following:
81 * powered -> SubscriberIdentity or Online = True -> gprs, context ->
82 * attached -> netreg -> ready
84 * Depending on the modem type, this plugin will behave differently.
88 * When a new modem appears, the plugin always powers it up. This
89 * allows the plugin to create a connman_device. The core will call
90 * modem_enable() if the technology is enabled. modem_enable() will
91 * then set the modem online. If the technology is disabled then
92 * modem_disable() will just set the modem offline. The modem is
93 * always kept powered all the time.
95 * After setting the modem online the plugin waits for the
96 * ConnectionManager and ConnectionContext to appear. When the context
97 * signals that it is attached and the NetworkRegistration interface
98 * appears, a new Service will be created and registered at the core.
100 * When asked to connect to the network (network_connect()) the plugin
101 * will set the Active property on the context. If this operation is
102 * successful the modem is connected to the network. oFono will inform
103 * the plugin about IP configuration through the updating the context's
108 * When a new modem appears, the plugin always powers it up. This
109 * allows the plugin to create connman_device either using IMSI either
110 * using modem Serial if the modem got a SIM interface or not.
112 * As for GSM, the core will call modem_enable() if the technology
113 * is enabled. modem_enable() will then set the modem online.
114 * If the technology is disabled then modem_disable() will just set the
115 * modem offline. The modem is always kept powered all the time.
117 * After setting the modem online the plugin waits for CdmaConnectionManager
118 * interface to appear. Then, once CdmaNetworkRegistration appears, a new
119 * Service will be created and registered at the core.
121 * When asked to connect to the network (network_connect()) the plugin
122 * will power up the CdmaConnectionManager interface.
123 * If the operation is successful the modem is connected to the network.
124 * oFono will inform the plugin about IP configuration through the
125 * updating CdmaConnectionManager settings properties.
128 static DBusConnection *connection;
130 static GHashTable *modem_hash;
131 static GHashTable *context_hash;
133 struct network_context {
136 struct connman_network *network;
138 enum connman_ipconfig_method ipv4_method;
139 struct connman_ipaddress *ipv4_address;
140 char *ipv4_nameservers;
142 enum connman_ipconfig_method ipv6_method;
143 struct connman_ipaddress *ipv6_address;
144 char *ipv6_nameservers;
149 bool valid_apn; /* APN is 'valid' if length > 0 */
155 struct connman_device *device;
157 GSList *context_list;
159 /* Modem Interface */
168 /* CDMA ConnectionManager Interface */
169 bool cdma_cm_powered;
171 /* ConnectionManager Interface */
175 /* SimManager Interface */
178 /* Netreg Interface */
181 uint8_t data_strength; /* 1xEVDO signal strength */
186 DBusPendingCall *call_set_property;
187 DBusPendingCall *call_get_properties;
188 DBusPendingCall *call_get_contexts;
191 static const char *api2string(enum ofono_api api)
196 case OFONO_API_NETREG:
200 case OFONO_API_CDMA_NETREG:
201 return "cdma-netreg";
202 case OFONO_API_CDMA_CM:
209 static char *get_ident(const char *path)
216 pos = strrchr(path, '/');
223 static struct network_context *get_context_with_path(GSList *context_list,
228 DBG("path %s", path);
230 for (list = context_list; list; list = list->next) {
231 struct network_context *context = list->data;
233 if (g_strcmp0(context->path, path) == 0)
240 static struct network_context *get_context_with_network(GSList *context_list,
241 const struct connman_network *network)
245 DBG("network %p", network);
247 for (list = context_list; list; list = list->next) {
248 struct network_context *context = list->data;
250 if (context->network == network)
257 static struct network_context *network_context_alloc(const char *path)
259 struct network_context *context;
261 context = g_try_new0(struct network_context, 1);
265 context->path = g_strdup(path);
268 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
269 context->ipv4_address = NULL;
270 context->ipv4_nameservers = NULL;
272 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
273 context->ipv6_address = NULL;
274 context->ipv6_nameservers = NULL;
276 context->refcount = 1;
281 static void network_context_ref(struct network_context *context)
283 DBG("%p ref %d", context, context->refcount + 1);
285 __sync_fetch_and_add(&context->refcount, 1);
288 static void network_context_unref(struct network_context *context)
290 DBG("%p ref %d", context, context->refcount - 1);
292 if (__sync_fetch_and_sub(&context->refcount, 1) != 1)
295 g_free(context->path);
297 connman_ipaddress_free(context->ipv4_address);
298 g_free(context->ipv4_nameservers);
300 connman_ipaddress_free(context->ipv6_address);
301 g_free(context->ipv6_nameservers);
306 static void set_connected(struct modem_data *modem,
307 struct network_context *context)
309 struct connman_service *service;
311 enum connman_ipconfig_method method;
315 DBG("%s", modem->path);
317 index = context->index;
319 method = context->ipv4_method;
320 if (index < 0 || (!context->ipv4_address &&
321 method == CONNMAN_IPCONFIG_METHOD_FIXED)) {
322 connman_error("Invalid index and/or address");
326 service = connman_service_lookup_from_network(context->network);
330 connman_service_create_ip4config(service, index);
331 connman_network_set_ipv4_method(context->network, method);
333 if (method == CONNMAN_IPCONFIG_METHOD_FIXED ||
334 method == CONNMAN_IPCONFIG_METHOD_DHCP) {
338 if (method == CONNMAN_IPCONFIG_METHOD_FIXED) {
339 connman_network_set_ipaddress(context->network,
340 context->ipv4_address);
343 method = context->ipv6_method;
344 connman_service_create_ip6config(service, index);
345 connman_network_set_ipv6_method(context->network, method);
347 if (method == CONNMAN_IPCONFIG_METHOD_AUTO) {
351 /* Set the nameservers */
352 if (context->ipv4_nameservers &&
353 context->ipv6_nameservers) {
354 nameservers = g_strdup_printf("%s %s",
355 context->ipv4_nameservers,
356 context->ipv6_nameservers);
357 connman_network_set_nameservers(context->network, nameservers);
359 } else if (context->ipv4_nameservers) {
360 connman_network_set_nameservers(context->network,
361 context->ipv4_nameservers);
362 } else if (context->ipv6_nameservers) {
363 connman_network_set_nameservers(context->network,
364 context->ipv6_nameservers);
368 connman_network_set_index(context->network, index);
369 connman_network_set_connected(context->network, true);
373 static void set_disconnected(struct network_context *context)
375 DBG("%s", context->path);
377 if (context->network)
378 connman_network_set_connected(context->network, false);
380 g_free(context->ipv4_nameservers);
381 context->ipv4_nameservers = NULL;
382 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_OFF)
383 context->ipv4_method =
384 CONNMAN_IPCONFIG_METHOD_UNKNOWN;
386 g_free(context->ipv6_nameservers);
387 context->ipv6_nameservers = NULL;
388 if (context->ipv6_method != CONNMAN_IPCONFIG_METHOD_OFF)
389 context->ipv6_method =
390 CONNMAN_IPCONFIG_METHOD_UNKNOWN;
393 typedef void (*set_property_cb)(struct modem_data *data,
394 struct network_context *context, bool success);
395 typedef void (*get_properties_cb)(struct modem_data *data,
396 DBusMessageIter *dict);
398 struct property_info {
399 struct modem_data *modem;
400 struct network_context *context;
402 const char *interface;
403 const char *property;
404 set_property_cb set_property_cb;
405 get_properties_cb get_properties_cb;
408 static void free_property_info(void * memory)
410 struct property_info * info = memory;
413 network_context_unref(info->context);
418 static void set_property_reply(DBusPendingCall *call, void *user_data)
420 struct property_info *info = user_data;
425 DBG("%s path %s %s.%s", info->modem->path,
426 info->path, info->interface, info->property);
428 info->modem->call_set_property = NULL;
430 dbus_error_init(&error);
432 reply = dbus_pending_call_steal_reply(call);
434 if (dbus_set_error_from_message(&error, reply)) {
435 connman_error("Failed to change property: %s %s.%s: %s %s",
436 info->path, info->interface, info->property,
437 error.name, error.message);
438 dbus_error_free(&error);
442 if (info->set_property_cb)
443 (*info->set_property_cb)(info->modem, info->context,
446 dbus_message_unref(reply);
448 dbus_pending_call_unref(call);
451 static int set_property(struct modem_data *modem,
452 struct network_context *context,
453 const char *path, const char *interface,
454 const char *property, int type, void *value,
455 set_property_cb notify)
457 DBusMessage *message;
458 DBusMessageIter iter;
459 struct property_info *info;
461 DBG("%s path %s %s.%s", modem->path, path, interface, property);
463 if (modem->call_set_property) {
464 DBG("Cancel pending SetProperty");
465 dbus_pending_call_cancel(modem->call_set_property);
466 dbus_pending_call_unref(modem->call_set_property);
467 modem->call_set_property = NULL;
470 message = dbus_message_new_method_call(OFONO_SERVICE, path,
471 interface, SET_PROPERTY);
475 dbus_message_iter_init_append(message, &iter);
476 connman_dbus_property_append_basic(&iter, property, type, value);
478 if (!dbus_connection_send_with_reply(connection, message,
479 &modem->call_set_property, TIMEOUT)) {
480 connman_error("Failed to change property: %s %s.%s",
481 path, interface, property);
482 dbus_message_unref(message);
486 if (!modem->call_set_property) {
487 connman_error("D-Bus connection not available");
488 dbus_message_unref(message);
492 info = g_try_new0(struct property_info, 1);
494 dbus_message_unref(message);
499 info->context = context;
501 info->interface = interface;
502 info->property = property;
503 info->set_property_cb = notify;
506 network_context_ref(info->context);
508 dbus_pending_call_set_notify(modem->call_set_property,
509 set_property_reply, info, free_property_info);
511 dbus_message_unref(message);
516 static void get_properties_reply(DBusPendingCall *call, void *user_data)
518 struct property_info *info = user_data;
519 DBusMessageIter array, dict;
523 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
525 info->modem->call_get_properties = NULL;
527 dbus_error_init(&error);
529 reply = dbus_pending_call_steal_reply(call);
531 if (dbus_set_error_from_message(&error, reply)) {
532 connman_error("Failed to get properties: %s %s: %s %s",
533 info->path, info->interface,
534 error.name, error.message);
535 dbus_error_free(&error);
540 if (!dbus_message_iter_init(reply, &array))
543 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
546 dbus_message_iter_recurse(&array, &dict);
548 if (info->get_properties_cb)
549 (*info->get_properties_cb)(info->modem, &dict);
553 dbus_message_unref(reply);
555 dbus_pending_call_unref(call);
558 static int get_properties(const char *path, const char *interface,
559 get_properties_cb notify,
560 struct modem_data *modem)
562 DBusMessage *message;
563 struct property_info *info;
565 DBG("%s path %s %s", modem->path, path, interface);
567 if (modem->call_get_properties) {
568 connman_error("Pending GetProperties");
572 message = dbus_message_new_method_call(OFONO_SERVICE, path,
573 interface, GET_PROPERTIES);
577 if (!dbus_connection_send_with_reply(connection, message,
578 &modem->call_get_properties, TIMEOUT)) {
579 connman_error("Failed to call %s.GetProperties()", interface);
580 dbus_message_unref(message);
584 if (!modem->call_get_properties) {
585 connman_error("D-Bus connection not available");
586 dbus_message_unref(message);
590 info = g_try_new0(struct property_info, 1);
592 dbus_message_unref(message);
598 info->interface = interface;
599 info->get_properties_cb = notify;
601 dbus_pending_call_set_notify(modem->call_get_properties,
602 get_properties_reply, info, g_free);
604 dbus_message_unref(message);
609 static void context_set_active_reply(struct modem_data *modem,
610 struct network_context *context, bool success)
612 DBG("%s", context->path);
616 * Don't handle do anything on success here. oFono will send
617 * the change via PropertyChanged singal.
623 * Active = True might fail due a timeout. That means oFono
624 * still tries to go online. If we retry to set Active = True,
625 * we just get a InProgress error message. Should we power
626 * cycle the modem in such cases?
629 if (!context->network) {
631 * In the case where we power down the device
632 * we don't wait for the reply, therefore the network
633 * might already be gone.
638 connman_network_set_error(context->network,
639 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
642 static int context_set_active(struct modem_data *modem,
643 struct network_context *context,
648 DBG("%s active %d", modem->path, active);
650 err = set_property(modem, context, context->path,
651 OFONO_CONTEXT_INTERFACE,
652 "Active", DBUS_TYPE_BOOLEAN,
654 context_set_active_reply);
656 if (!active && err == -EINPROGRESS)
662 static void cdma_cm_set_powered_reply(struct modem_data *modem,
663 struct network_context *context, bool success)
665 DBG("%s", context->path);
669 * Don't handle do anything on success here. oFono will send
670 * the change via PropertyChanged singal.
676 * Powered = True might fail due a timeout. That means oFono
677 * still tries to go online. If we retry to set Powered = True,
678 * we just get a InProgress error message. Should we power
679 * cycle the modem in such cases?
682 if (!context->network) {
684 * In the case where we power down the device
685 * we don't wait for the reply, therefore the network
686 * might already be gone.
691 connman_network_set_error(context->network,
692 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
695 static int cdma_cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
698 struct network_context *context = NULL;
700 if (!modem->context_list)
703 DBG("%s powered %d", modem->path, powered);
705 /* In case of CDMA, there is only one context */
706 context = modem->context_list->data;
707 err = set_property(modem, context, modem->path,
708 OFONO_CDMA_CM_INTERFACE,
709 "Powered", DBUS_TYPE_BOOLEAN,
711 cdma_cm_set_powered_reply);
713 if (!powered && err == -EINPROGRESS)
719 static int modem_set_online(struct modem_data *modem, dbus_bool_t online)
721 DBG("%s online %d", modem->path, online);
723 return set_property(modem, NULL, modem->path,
724 OFONO_MODEM_INTERFACE,
725 "Online", DBUS_TYPE_BOOLEAN,
730 static int cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
734 DBG("%s powered %d", modem->path, powered);
736 err = set_property(modem, NULL, modem->path,
738 "Powered", DBUS_TYPE_BOOLEAN,
742 if (!powered && err == -EINPROGRESS)
748 static int modem_set_powered(struct modem_data *modem, dbus_bool_t powered)
752 DBG("%s powered %d", modem->path, powered);
754 modem->set_powered = powered;
756 err = set_property(modem, NULL, modem->path,
757 OFONO_MODEM_INTERFACE,
758 "Powered", DBUS_TYPE_BOOLEAN,
762 if (!powered && err == -EINPROGRESS)
768 static bool has_interface(uint8_t interfaces,
771 if ((interfaces & api) == api)
777 static uint8_t extract_interfaces(DBusMessageIter *array)
779 DBusMessageIter entry;
780 uint8_t interfaces = 0;
782 dbus_message_iter_recurse(array, &entry);
784 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
787 dbus_message_iter_get_basic(&entry, &name);
789 if (g_str_equal(name, OFONO_SIM_INTERFACE))
790 interfaces |= OFONO_API_SIM;
791 else if (g_str_equal(name, OFONO_NETREG_INTERFACE))
792 interfaces |= OFONO_API_NETREG;
793 else if (g_str_equal(name, OFONO_CM_INTERFACE))
794 interfaces |= OFONO_API_CM;
795 else if (g_str_equal(name, OFONO_CDMA_CM_INTERFACE))
796 interfaces |= OFONO_API_CDMA_CM;
797 else if (g_str_equal(name, OFONO_CDMA_NETREG_INTERFACE))
798 interfaces |= OFONO_API_CDMA_NETREG;
800 dbus_message_iter_next(&entry);
806 static char *extract_nameservers(DBusMessageIter *array)
808 DBusMessageIter entry;
809 char *nameservers = NULL;
812 dbus_message_iter_recurse(array, &entry);
814 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
815 const char *nameserver;
817 dbus_message_iter_get_basic(&entry, &nameserver);
820 nameservers = g_strdup(nameserver);
823 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
827 dbus_message_iter_next(&entry);
833 static void extract_ipv4_settings(DBusMessageIter *array,
834 struct network_context *context)
836 DBusMessageIter dict;
837 char *address = NULL, *netmask = NULL, *gateway = NULL;
838 char *nameservers = NULL;
839 const char *interface = NULL;
842 connman_ipaddress_free(context->ipv4_address);
843 context->ipv4_address = NULL;
845 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
848 dbus_message_iter_recurse(array, &dict);
850 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
851 DBusMessageIter entry, value;
852 const char *key, *val;
854 dbus_message_iter_recurse(&dict, &entry);
855 dbus_message_iter_get_basic(&entry, &key);
857 dbus_message_iter_next(&entry);
858 dbus_message_iter_recurse(&entry, &value);
860 if (g_str_equal(key, "Interface")) {
861 dbus_message_iter_get_basic(&value, &interface);
863 DBG("Interface %s", interface);
865 index = connman_inet_ifindex(interface);
867 DBG("index %d", index);
868 } else if (g_str_equal(key, "Method")) {
869 dbus_message_iter_get_basic(&value, &val);
871 DBG("Method %s", val);
873 if (g_strcmp0(val, "static") == 0)
874 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
875 else if (g_strcmp0(val, "dhcp") == 0)
876 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
878 } else if (g_str_equal(key, "Address")) {
879 dbus_message_iter_get_basic(&value, &val);
881 address = g_strdup(val);
883 DBG("Address %s", address);
884 } else if (g_str_equal(key, "Netmask")) {
885 dbus_message_iter_get_basic(&value, &val);
887 netmask = g_strdup(val);
889 DBG("Netmask %s", netmask);
890 } else if (g_str_equal(key, "DomainNameServers")) {
891 nameservers = extract_nameservers(&value);
893 DBG("Nameservers %s", nameservers);
894 } else if (g_str_equal(key, "Gateway")) {
895 dbus_message_iter_get_basic(&value, &val);
897 gateway = g_strdup(val);
899 DBG("Gateway %s", gateway);
902 dbus_message_iter_next(&dict);
908 context->index = index;
910 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
913 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
914 if (!context->ipv4_address) {
919 connman_ipaddress_set_ipv4(context->ipv4_address, address,
922 g_free(context->ipv4_nameservers);
923 context->ipv4_nameservers = nameservers;
926 if (context->ipv4_nameservers != nameservers)
934 static void extract_ipv6_settings(DBusMessageIter *array,
935 struct network_context *context)
937 DBusMessageIter dict;
938 char *address = NULL, *gateway = NULL;
939 unsigned char prefix_length = 0;
940 char *nameservers = NULL;
941 const char *interface = NULL;
944 connman_ipaddress_free(context->ipv6_address);
945 context->ipv6_address = NULL;
947 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
950 dbus_message_iter_recurse(array, &dict);
952 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
953 DBusMessageIter entry, value;
954 const char *key, *val;
956 dbus_message_iter_recurse(&dict, &entry);
957 dbus_message_iter_get_basic(&entry, &key);
959 dbus_message_iter_next(&entry);
960 dbus_message_iter_recurse(&entry, &value);
962 if (g_str_equal(key, "Interface")) {
963 dbus_message_iter_get_basic(&value, &interface);
965 DBG("Interface %s", interface);
967 index = connman_inet_ifindex(interface);
969 DBG("index %d", index);
970 } else if (g_str_equal(key, "Address")) {
971 dbus_message_iter_get_basic(&value, &val);
973 address = g_strdup(val);
975 DBG("Address %s", address);
976 } else if (g_str_equal(key, "PrefixLength")) {
977 dbus_message_iter_get_basic(&value, &prefix_length);
979 DBG("prefix length %d", prefix_length);
980 } else if (g_str_equal(key, "DomainNameServers")) {
981 nameservers = extract_nameservers(&value);
983 DBG("Nameservers %s", nameservers);
984 } else if (g_str_equal(key, "Gateway")) {
985 dbus_message_iter_get_basic(&value, &val);
987 gateway = g_strdup(val);
989 DBG("Gateway %s", gateway);
992 dbus_message_iter_next(&dict);
998 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_AUTO;
1000 context->ipv6_address =
1001 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
1002 if (!context->ipv6_address)
1005 context->index = index;
1006 connman_ipaddress_set_ipv6(context->ipv6_address, address,
1007 prefix_length, gateway);
1009 g_free(context->ipv6_nameservers);
1010 context->ipv6_nameservers = nameservers;
1013 if (context->ipv6_nameservers != nameservers)
1014 g_free(nameservers);
1020 static bool ready_to_create_device(struct modem_data *modem)
1023 * There are three different modem types which behave slightly
1025 * - GSM modems will expose the SIM interface then the
1027 * - CDMA modems will expose CM first and sometime later
1028 * a unique serial number.
1030 * This functions tests if we have the necessary information gathered
1031 * before we are able to create a device.
1037 if (modem->imsi || modem->serial)
1043 static void create_device(struct modem_data *modem)
1045 struct connman_device *device;
1048 DBG("%s", modem->path);
1051 ident = modem->imsi;
1052 else if (modem->serial)
1053 ident = modem->serial;
1055 if (!connman_dbus_validate_ident(ident))
1056 ident = connman_dbus_encode_string(ident);
1058 ident = g_strdup(ident);
1060 device = connman_device_create("ofono", CONNMAN_DEVICE_TYPE_CELLULAR);
1064 DBG("device %p", device);
1066 connman_device_set_ident(device, ident);
1068 connman_device_set_string(device, "Path", modem->path);
1070 connman_device_set_data(device, modem);
1072 if (connman_device_register(device) < 0) {
1073 connman_error("Failed to register cellular device");
1074 connman_device_unref(device);
1078 modem->device = device;
1080 connman_device_set_powered(modem->device, modem->online);
1085 static void destroy_device(struct modem_data *modem)
1087 DBG("%s", modem->path);
1089 connman_device_set_powered(modem->device, false);
1091 connman_device_unregister(modem->device);
1092 connman_device_unref(modem->device);
1094 modem->device = NULL;
1097 static void add_network(struct modem_data *modem,
1098 struct network_context *context)
1102 DBG("%s", modem->path);
1104 if (context->network)
1107 context->network = connman_network_create(context->path,
1108 CONNMAN_NETWORK_TYPE_CELLULAR);
1109 if (!context->network)
1112 DBG("network %p", context->network);
1114 connman_network_set_data(context->network, modem);
1116 connman_network_set_string(context->network, "Path",
1120 connman_network_set_name(context->network, modem->name);
1122 connman_network_set_name(context->network, "");
1124 connman_network_set_strength(context->network, modem->strength);
1126 group = get_ident(context->path);
1127 connman_network_set_group(context->network, group);
1129 connman_network_set_bool(context->network, "Roaming",
1132 if (connman_device_add_network(modem->device, context->network) < 0) {
1133 connman_network_unref(context->network);
1134 context->network = NULL;
1139 static void remove_network(struct modem_data *modem,
1140 struct network_context *context)
1142 DBG("%s", modem->path);
1144 if (!context || !context->network)
1147 DBG("network %p", context->network);
1150 connman_device_remove_network(modem->device, context->network);
1151 connman_network_unref(context->network);
1152 context->network = NULL;
1155 static int set_context_ipconfig(struct network_context *context,
1156 const char *protocol)
1158 DBG("context %p protocol %s", context, protocol);
1160 if (!context || !protocol)
1163 if (g_str_equal(protocol, "ip")) {
1164 if (context->ipv4_method == CONNMAN_IPCONFIG_METHOD_OFF)
1165 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1167 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_OFF;
1169 connman_ipaddress_free(context->ipv6_address);
1170 context->ipv6_address = NULL;
1172 } else if (g_str_equal(protocol, "ipv6")) {
1173 if (context->ipv6_method == CONNMAN_IPCONFIG_METHOD_OFF)
1174 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1176 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_OFF;
1178 connman_ipaddress_free(context->ipv4_address);
1179 context->ipv4_address = NULL;
1181 } else if (g_str_equal(protocol, "dual")) {
1182 if (context->ipv4_method == CONNMAN_IPCONFIG_METHOD_OFF)
1183 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1185 if (context->ipv6_method == CONNMAN_IPCONFIG_METHOD_OFF)
1186 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1189 DBG("ipv4 method %d ipv6 method %d", context->ipv4_method,
1190 context->ipv6_method);
1195 static int add_cm_context(struct modem_data *modem, const char *context_path,
1196 DBusMessageIter *dict)
1198 const char *context_type = NULL;
1199 struct network_context *context = NULL;
1200 dbus_bool_t active = FALSE;
1201 const char *ip_protocol = NULL;
1203 DBG("%s context path %s", modem->path, context_path);
1205 context = network_context_alloc(context_path);
1209 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1210 DBusMessageIter entry, value;
1213 dbus_message_iter_recurse(dict, &entry);
1214 dbus_message_iter_get_basic(&entry, &key);
1216 dbus_message_iter_next(&entry);
1217 dbus_message_iter_recurse(&entry, &value);
1219 if (g_str_equal(key, "Type")) {
1220 dbus_message_iter_get_basic(&value, &context_type);
1222 DBG("%s context %s type %s", modem->path,
1223 context_path, context_type);
1224 } else if (g_str_equal(key, "Settings")) {
1225 DBG("%s Settings", modem->path);
1227 extract_ipv4_settings(&value, context);
1228 } else if (g_str_equal(key, "IPv6.Settings")) {
1229 DBG("%s IPv6.Settings", modem->path);
1231 extract_ipv6_settings(&value, context);
1232 } else if (g_str_equal(key, "Active")) {
1233 dbus_message_iter_get_basic(&value, &active);
1235 DBG("%s Active %d", modem->path, active);
1236 } else if (g_str_equal(key, "AccessPointName")) {
1239 dbus_message_iter_get_basic(&value, &apn);
1240 if (apn && strlen(apn) > 0)
1241 context->valid_apn = true;
1243 context->valid_apn = false;
1245 DBG("%s AccessPointName '%s'", modem->path, apn);
1246 } else if (g_str_equal(key, "Protocol") &&
1247 dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING ) {
1249 dbus_message_iter_get_basic(&value, &ip_protocol);
1251 DBG("%s Protocol %s", modem->path, ip_protocol);
1254 dbus_message_iter_next(dict);
1257 if (g_strcmp0(context_type, "internet") != 0) {
1258 network_context_unref(context);
1263 set_context_ipconfig(context, ip_protocol);
1265 context->active = active;
1267 modem->context_list = g_slist_prepend(modem->context_list, context);
1268 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
1270 if (context->valid_apn && modem->attached &&
1271 has_interface(modem->interfaces, OFONO_API_NETREG))
1272 add_network(modem, context);
1277 static void remove_cm_context(struct modem_data *modem,
1278 struct network_context *context)
1280 if (!modem->context_list)
1285 g_hash_table_remove(context_hash, context->path);
1287 if (context->network)
1288 remove_network(modem, context);
1289 modem->context_list = g_slist_remove(modem->context_list, context);
1291 network_context_unref(context);
1295 static void remove_all_contexts(struct modem_data *modem)
1297 GSList *list = NULL;
1301 if (modem->context_list == NULL)
1304 list = modem->context_list;
1306 struct network_context *context = list->data;
1308 remove_cm_context(modem, context);
1310 list = modem->context_list;
1312 g_slist_free(modem->context_list);
1313 modem->context_list = NULL;
1316 static void remove_all_networks(struct modem_data *modem)
1320 for (list = modem->context_list; list; list = list->next) {
1321 struct network_context *context = list->data;
1323 remove_network(modem, context);
1327 static gboolean context_changed(DBusConnection *conn,
1328 DBusMessage *message,
1331 struct network_context *context = NULL;
1332 const char *context_path = dbus_message_get_path(message);
1333 struct modem_data *modem = NULL;
1334 DBusMessageIter iter, value;
1337 DBG("context_path %s", context_path);
1339 modem = g_hash_table_lookup(context_hash, context_path);
1343 context = get_context_with_path(modem->context_list, context_path);
1347 if (!dbus_message_iter_init(message, &iter))
1350 dbus_message_iter_get_basic(&iter, &key);
1352 dbus_message_iter_next(&iter);
1353 dbus_message_iter_recurse(&iter, &value);
1356 * oFono guarantees the ordering of Settings and
1357 * Active. Settings will always be send before Active = True.
1358 * That means we don't have to order here.
1360 if (g_str_equal(key, "Settings")) {
1361 DBG("%s Settings", modem->path);
1363 extract_ipv4_settings(&value, context);
1364 } else if (g_str_equal(key, "IPv6.Settings")) {
1365 DBG("%s IPv6.Settings", modem->path);
1367 extract_ipv6_settings(&value, context);
1368 } else if (g_str_equal(key, "Active")) {
1371 dbus_message_iter_get_basic(&value, &active);
1372 context->active = active;
1374 DBG("%s Active %d", modem->path, context->active);
1376 if (context->active)
1377 set_connected(modem, context);
1379 set_disconnected(context);
1380 } else if (g_str_equal(key, "AccessPointName")) {
1383 dbus_message_iter_get_basic(&value, &apn);
1385 DBG("%s AccessPointName %s", modem->path, apn);
1387 if (apn && strlen(apn) > 0) {
1388 context->valid_apn = true;
1390 if (context->network)
1393 if (!modem->attached)
1396 if (!has_interface(modem->interfaces,
1400 add_network(modem, context);
1402 if (context->active)
1403 set_connected(modem, context);
1405 context->valid_apn = false;
1407 if (!context->network)
1410 remove_network(modem, context);
1413 } else if (g_str_equal(key, "Protocol") &&
1414 dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING ) {
1415 const char *ip_protocol;
1417 dbus_message_iter_get_basic(&value, &ip_protocol);
1419 set_context_ipconfig(context, ip_protocol);
1425 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
1427 struct modem_data *modem = user_data;
1428 DBusMessageIter array, dict, entry, value;
1432 DBG("%s", modem->path);
1434 modem->call_get_contexts = NULL;
1436 reply = dbus_pending_call_steal_reply(call);
1438 dbus_error_init(&error);
1440 if (dbus_set_error_from_message(&error, reply)) {
1441 connman_error("%s", error.message);
1442 dbus_error_free(&error);
1446 if (!dbus_message_iter_init(reply, &array))
1449 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1452 dbus_message_iter_recurse(&array, &dict);
1454 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1455 const char *context_path;
1457 dbus_message_iter_recurse(&dict, &entry);
1458 dbus_message_iter_get_basic(&entry, &context_path);
1460 dbus_message_iter_next(&entry);
1461 dbus_message_iter_recurse(&entry, &value);
1463 if (add_cm_context(modem, context_path, &value))
1466 dbus_message_iter_next(&dict);
1470 dbus_message_unref(reply);
1472 dbus_pending_call_unref(call);
1475 static int cm_get_contexts(struct modem_data *modem)
1477 DBusMessage *message;
1479 DBG("%s", modem->path);
1481 if (modem->call_get_contexts)
1484 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1485 OFONO_CM_INTERFACE, GET_CONTEXTS);
1489 if (!dbus_connection_send_with_reply(connection, message,
1490 &modem->call_get_contexts, TIMEOUT)) {
1491 connman_error("Failed to call GetContexts()");
1492 dbus_message_unref(message);
1496 if (!modem->call_get_contexts) {
1497 connman_error("D-Bus connection not available");
1498 dbus_message_unref(message);
1502 dbus_pending_call_set_notify(modem->call_get_contexts,
1503 cm_get_contexts_reply,
1506 dbus_message_unref(message);
1508 return -EINPROGRESS;
1511 static gboolean cm_context_added(DBusConnection *conn,
1512 DBusMessage *message,
1515 const char *path = dbus_message_get_path(message);
1517 struct modem_data *modem;
1518 DBusMessageIter iter, properties, dict;
1522 modem = g_hash_table_lookup(modem_hash, path);
1526 if (!dbus_message_iter_init(message, &iter))
1529 dbus_message_iter_get_basic(&iter, &context_path);
1531 dbus_message_iter_next(&iter);
1532 dbus_message_iter_recurse(&iter, &properties);
1534 /* Sometimes, we get an array instead of dict */
1535 if (dbus_message_iter_get_arg_type(&properties) == DBUS_TYPE_ARRAY) {
1536 /* Must recurse again */
1537 dbus_message_iter_recurse(&properties, &dict);
1538 if (add_cm_context(modem, context_path, &dict) != 0)
1541 if (add_cm_context(modem, context_path, &properties) != 0)
1547 static gboolean cm_context_removed(DBusConnection *conn,
1548 DBusMessage *message,
1551 const char *path = dbus_message_get_path(message);
1552 const char *context_path;
1553 struct modem_data *modem;
1554 struct network_context *context;
1555 DBusMessageIter iter;
1557 DBG("context path %s", path);
1559 if (!dbus_message_iter_init(message, &iter))
1562 dbus_message_iter_get_basic(&iter, &context_path);
1564 modem = g_hash_table_lookup(context_hash, context_path);
1568 context = get_context_with_path(modem->context_list, context_path);
1569 remove_cm_context(modem, context);
1574 static void netreg_update_name(struct modem_data *modem,
1575 DBusMessageIter* value)
1580 dbus_message_iter_get_basic(value, &name);
1582 DBG("%s Name %s", modem->path, name);
1584 g_free(modem->name);
1585 modem->name = g_strdup(name);
1587 if (!modem->context_list)
1590 /* For all the context */
1591 for (list = modem->context_list; list; list = list->next) {
1592 struct network_context *context = list->data;
1594 if (context->network) {
1595 connman_network_set_name(context->network, modem->name);
1596 connman_network_update(context->network);
1601 static void netreg_update_strength(struct modem_data *modem,
1602 DBusMessageIter *value)
1606 dbus_message_iter_get_basic(value, &modem->strength);
1608 DBG("%s Strength %d", modem->path, modem->strength);
1610 if (!modem->context_list)
1615 * We don't have 2 signal notifications we always report the strength
1616 * signal. data_strength is always equal to 0.
1619 * In the case we have a data_strength signal (from 1xEVDO network)
1620 * we don't need to update the value with strength signal (from 1xCDMA)
1621 * because the modem is registered to 1xEVDO network for data call.
1622 * In case we have no data_strength signal (not registered to 1xEVDO
1623 * network), we must report the strength signal (registered to 1xCDMA
1624 * network e.g slow mode).
1626 if (modem->data_strength != 0)
1629 /* For all the context */
1630 for (list = modem->context_list; list; list = list->next) {
1631 struct network_context *context = list->data;
1633 if (context->network) {
1634 connman_network_set_strength(context->network,
1636 connman_network_update(context->network);
1641 /* Retrieve 1xEVDO Data Strength signal */
1642 static void netreg_update_datastrength(struct modem_data *modem,
1643 DBusMessageIter *value)
1647 dbus_message_iter_get_basic(value, &modem->data_strength);
1649 DBG("%s Data Strength %d", modem->path, modem->data_strength);
1651 if (!modem->context_list)
1655 * CDMA modem is not registered to 1xEVDO network, let
1656 * update_signal_strength() reporting the value on the Strength signal
1659 if (modem->data_strength == 0)
1662 /* For all the context */
1663 for (list = modem->context_list; list; list = list->next) {
1664 struct network_context *context = list->data;
1666 if (context->network) {
1667 connman_network_set_strength(context->network,
1668 modem->data_strength);
1669 connman_network_update(context->network);
1674 static void netreg_update_status(struct modem_data *modem,
1675 DBusMessageIter *value)
1681 dbus_message_iter_get_basic(value, &status);
1683 roaming = g_str_equal(status, "roaming");
1684 modem->registered = roaming || g_str_equal(status, "registered");
1686 if (roaming == modem->roaming)
1689 modem->roaming = roaming;
1691 if (!modem->context_list)
1694 /* For all the context */
1695 for (list = modem->context_list; list; list = list->next) {
1696 struct network_context *context = list->data;
1698 if (context->network) {
1699 connman_network_set_bool(context->network,
1700 "Roaming", modem->roaming);
1701 connman_network_update(context->network);
1706 static void netreg_update_regdom(struct modem_data *modem,
1707 DBusMessageIter *value)
1709 char *mobile_country_code;
1713 dbus_message_iter_get_basic(value, &mobile_country_code);
1715 DBG("%s MobileContryCode %s", modem->path, mobile_country_code);
1718 mcc = atoi(mobile_country_code);
1719 if (mcc > 799 || mcc < 200)
1722 alpha2 = mcc_country_codes[mcc - 200];
1724 connman_technology_set_regdom(alpha2);
1727 static gboolean netreg_changed(DBusConnection *conn, DBusMessage *message,
1730 const char *path = dbus_message_get_path(message);
1731 struct modem_data *modem;
1732 DBusMessageIter iter, value;
1735 modem = g_hash_table_lookup(modem_hash, path);
1742 if (!dbus_message_iter_init(message, &iter))
1745 dbus_message_iter_get_basic(&iter, &key);
1747 dbus_message_iter_next(&iter);
1748 dbus_message_iter_recurse(&iter, &value);
1750 if (g_str_equal(key, "Name"))
1751 netreg_update_name(modem, &value);
1752 else if (g_str_equal(key, "Strength"))
1753 netreg_update_strength(modem, &value);
1754 else if (g_str_equal(key, "Status"))
1755 netreg_update_status(modem, &value);
1756 else if (g_str_equal(key, "MobileCountryCode"))
1757 netreg_update_regdom(modem, &value);
1762 static void netreg_properties_reply(struct modem_data *modem,
1763 DBusMessageIter *dict)
1765 GSList *list = NULL;
1767 DBG("%s", modem->path);
1769 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1770 DBusMessageIter entry, value;
1773 dbus_message_iter_recurse(dict, &entry);
1774 dbus_message_iter_get_basic(&entry, &key);
1776 dbus_message_iter_next(&entry);
1777 dbus_message_iter_recurse(&entry, &value);
1779 if (g_str_equal(key, "Name"))
1780 netreg_update_name(modem, &value);
1781 else if (g_str_equal(key, "Strength"))
1782 netreg_update_strength(modem, &value);
1783 else if (g_str_equal(key, "Status"))
1784 netreg_update_status(modem, &value);
1785 else if (g_str_equal(key, "MobileCountryCode"))
1786 netreg_update_regdom(modem, &value);
1788 dbus_message_iter_next(dict);
1791 if (!modem->context_list) {
1793 * netgreg_get_properties() was issued after we got
1794 * cm_get_contexts_reply() where we create the
1795 * context. Though before we got the
1796 * netreg_properties_reply the context was removed
1797 * again. Therefore we have to skip the network
1802 /* Check for all contexts if they are valids and/or actives */
1803 for (list = modem->context_list; list; list = list->next) {
1804 struct network_context *context = list->data;
1806 if (context->valid_apn)
1807 add_network(modem, context);
1808 if (context->active)
1809 set_connected(modem, context);
1813 static int netreg_get_properties(struct modem_data *modem)
1815 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1816 netreg_properties_reply, modem);
1819 static void add_cdma_network(struct modem_data *modem)
1821 struct network_context *context = NULL;
1822 /* Be sure that device is created before adding CDMA network */
1827 * CDMA modems don't need contexts for data call, however the current
1828 * add_network() logic needs one, so we create one to proceed.
1830 if (!modem->context_list) {
1831 context = network_context_alloc(modem->path);
1832 modem->context_list = g_slist_prepend(modem->context_list,
1835 context = modem->context_list->data;
1838 modem->name = g_strdup("CDMA Network");
1840 add_network(modem, context);
1842 if (modem->cdma_cm_powered)
1843 set_connected(modem, context);
1846 static gboolean cdma_netreg_changed(DBusConnection *conn,
1847 DBusMessage *message,
1850 const char *path = dbus_message_get_path(message);
1851 struct modem_data *modem;
1852 DBusMessageIter iter, value;
1857 modem = g_hash_table_lookup(modem_hash, path);
1864 if (!dbus_message_iter_init(message, &iter))
1867 dbus_message_iter_get_basic(&iter, &key);
1869 dbus_message_iter_next(&iter);
1870 dbus_message_iter_recurse(&iter, &value);
1872 if (g_str_equal(key, "Name"))
1873 netreg_update_name(modem, &value);
1874 else if (g_str_equal(key, "Strength"))
1875 netreg_update_strength(modem, &value);
1876 else if (g_str_equal(key, "DataStrength"))
1877 netreg_update_datastrength(modem, &value);
1878 else if (g_str_equal(key, "Status"))
1879 netreg_update_status(modem, &value);
1881 if (modem->registered)
1882 add_cdma_network(modem);
1884 remove_all_networks(modem);
1889 static void cdma_netreg_properties_reply(struct modem_data *modem,
1890 DBusMessageIter *dict)
1892 DBG("%s", modem->path);
1894 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1895 DBusMessageIter entry, value;
1898 dbus_message_iter_recurse(dict, &entry);
1899 dbus_message_iter_get_basic(&entry, &key);
1901 dbus_message_iter_next(&entry);
1902 dbus_message_iter_recurse(&entry, &value);
1904 if (g_str_equal(key, "Name"))
1905 netreg_update_name(modem, &value);
1906 else if (g_str_equal(key, "Strength"))
1907 netreg_update_strength(modem, &value);
1908 else if (g_str_equal(key, "DataStrength"))
1909 netreg_update_datastrength(modem, &value);
1910 else if (g_str_equal(key, "Status"))
1911 netreg_update_status(modem, &value);
1913 dbus_message_iter_next(dict);
1916 if (modem->registered)
1917 add_cdma_network(modem);
1919 remove_all_networks(modem);
1922 static int cdma_netreg_get_properties(struct modem_data *modem)
1924 return get_properties(modem->path, OFONO_CDMA_NETREG_INTERFACE,
1925 cdma_netreg_properties_reply, modem);
1928 static void cm_update_attached(struct modem_data *modem,
1929 DBusMessageIter *value)
1931 dbus_bool_t attached;
1933 dbus_message_iter_get_basic(value, &attached);
1934 modem->attached = attached;
1936 DBG("%s Attached %d", modem->path, modem->attached);
1938 if (!modem->attached) {
1939 remove_all_networks(modem);
1943 if (!has_interface(modem->interfaces, OFONO_API_NETREG))
1946 netreg_get_properties(modem);
1949 static void cm_update_powered(struct modem_data *modem,
1950 DBusMessageIter *value)
1952 dbus_bool_t cm_powered;
1954 dbus_message_iter_get_basic(value, &cm_powered);
1955 modem->cm_powered = cm_powered;
1957 DBG("%s ConnnectionManager Powered %d", modem->path,
1960 if (modem->cm_powered)
1963 cm_set_powered(modem, TRUE);
1966 static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,
1969 const char *path = dbus_message_get_path(message);
1970 struct modem_data *modem;
1971 DBusMessageIter iter, value;
1974 modem = g_hash_table_lookup(modem_hash, path);
1981 if (!dbus_message_iter_init(message, &iter))
1984 dbus_message_iter_get_basic(&iter, &key);
1986 dbus_message_iter_next(&iter);
1987 dbus_message_iter_recurse(&iter, &value);
1989 if (g_str_equal(key, "Attached"))
1990 cm_update_attached(modem, &value);
1991 else if (g_str_equal(key, "Powered"))
1992 cm_update_powered(modem, &value);
1997 static void cdma_cm_update_powered(struct modem_data *modem,
1998 DBusMessageIter *value)
2000 struct network_context *context = NULL;
2001 dbus_bool_t cdma_cm_powered;
2003 dbus_message_iter_get_basic(value, &cdma_cm_powered);
2004 modem->cdma_cm_powered = cdma_cm_powered;
2006 DBG("%s CDMA cm Powered %d", modem->path, modem->cdma_cm_powered);
2008 if (!modem->context_list)
2011 /* In case of CDMA, there is only one context */
2012 context = modem->context_list->data;
2013 if (modem->cdma_cm_powered)
2014 set_connected(modem, context);
2016 set_disconnected(context);
2019 static void cdma_cm_update_settings(struct modem_data *modem,
2020 DBusMessageIter *value)
2022 DBG("%s Settings", modem->path);
2024 extract_ipv4_settings(value, modem->context_list->data);
2027 static gboolean cdma_cm_changed(DBusConnection *conn,
2028 DBusMessage *message, void *user_data)
2030 const char *path = dbus_message_get_path(message);
2031 struct modem_data *modem;
2032 DBusMessageIter iter, value;
2035 modem = g_hash_table_lookup(modem_hash, path);
2039 if (modem->online && !modem->context_list)
2040 cdma_netreg_get_properties(modem);
2042 if (!dbus_message_iter_init(message, &iter))
2045 dbus_message_iter_get_basic(&iter, &key);
2047 dbus_message_iter_next(&iter);
2048 dbus_message_iter_recurse(&iter, &value);
2050 if (g_str_equal(key, "Powered"))
2051 cdma_cm_update_powered(modem, &value);
2052 if (g_str_equal(key, "Settings"))
2053 cdma_cm_update_settings(modem, &value);
2058 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
2060 DBG("%s", modem->path);
2062 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
2063 DBusMessageIter entry, value;
2066 dbus_message_iter_recurse(dict, &entry);
2067 dbus_message_iter_get_basic(&entry, &key);
2069 dbus_message_iter_next(&entry);
2070 dbus_message_iter_recurse(&entry, &value);
2072 if (g_str_equal(key, "Attached"))
2073 cm_update_attached(modem, &value);
2074 else if (g_str_equal(key, "Powered"))
2075 cm_update_powered(modem, &value);
2077 dbus_message_iter_next(dict);
2081 static int cm_get_properties(struct modem_data *modem)
2083 return get_properties(modem->path, OFONO_CM_INTERFACE,
2084 cm_properties_reply, modem);
2087 static void cdma_cm_properties_reply(struct modem_data *modem,
2088 DBusMessageIter *dict)
2090 DBG("%s", modem->path);
2093 cdma_netreg_get_properties(modem);
2095 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
2096 DBusMessageIter entry, value;
2099 dbus_message_iter_recurse(dict, &entry);
2100 dbus_message_iter_get_basic(&entry, &key);
2102 dbus_message_iter_next(&entry);
2103 dbus_message_iter_recurse(&entry, &value);
2105 if (g_str_equal(key, "Powered"))
2106 cdma_cm_update_powered(modem, &value);
2107 if (g_str_equal(key, "Settings"))
2108 cdma_cm_update_settings(modem, &value);
2110 dbus_message_iter_next(dict);
2114 static int cdma_cm_get_properties(struct modem_data *modem)
2116 return get_properties(modem->path, OFONO_CDMA_CM_INTERFACE,
2117 cdma_cm_properties_reply, modem);
2120 static void sim_update_imsi(struct modem_data *modem,
2121 DBusMessageIter *value)
2125 dbus_message_iter_get_basic(value, &imsi);
2127 DBG("%s imsi %s", modem->path, imsi);
2129 g_free(modem->imsi);
2130 modem->imsi = g_strdup(imsi);
2133 static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,
2136 const char *path = dbus_message_get_path(message);
2137 struct modem_data *modem;
2138 DBusMessageIter iter, value;
2141 modem = g_hash_table_lookup(modem_hash, path);
2148 if (!dbus_message_iter_init(message, &iter))
2151 dbus_message_iter_get_basic(&iter, &key);
2153 dbus_message_iter_next(&iter);
2154 dbus_message_iter_recurse(&iter, &value);
2156 if (g_str_equal(key, "SubscriberIdentity")) {
2157 sim_update_imsi(modem, &value);
2159 if (!ready_to_create_device(modem))
2163 * This is a GSM modem. Create the device and
2164 * register it at the core. Enabling (setting
2165 * it online is done through the
2166 * modem_enable() callback.
2168 create_device(modem);
2174 static void sim_properties_reply(struct modem_data *modem,
2175 DBusMessageIter *dict)
2177 DBG("%s", modem->path);
2179 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
2180 DBusMessageIter entry, value;
2183 dbus_message_iter_recurse(dict, &entry);
2184 dbus_message_iter_get_basic(&entry, &key);
2186 dbus_message_iter_next(&entry);
2187 dbus_message_iter_recurse(&entry, &value);
2189 if (g_str_equal(key, "SubscriberIdentity")) {
2190 sim_update_imsi(modem, &value);
2192 if (!ready_to_create_device(modem))
2196 * This is a GSM modem. Create the device and
2197 * register it at the core. Enabling (setting
2198 * it online is done through the
2199 * modem_enable() callback.
2201 create_device(modem);
2207 * The modem is already online and we have the CM interface.
2208 * There will be no interface update and therefore our
2209 * state machine will not go to next step. We have to
2210 * trigger it from here.
2212 if (has_interface(modem->interfaces, OFONO_API_CM)) {
2213 cm_get_properties(modem);
2214 cm_get_contexts(modem);
2219 dbus_message_iter_next(dict);
2223 static int sim_get_properties(struct modem_data *modem)
2225 return get_properties(modem->path, OFONO_SIM_INTERFACE,
2226 sim_properties_reply, modem);
2229 static bool api_added(uint8_t old_iface, uint8_t new_iface,
2232 if (!has_interface(old_iface, api) &&
2233 has_interface(new_iface, api)) {
2234 DBG("%s added", api2string(api));
2241 static bool api_removed(uint8_t old_iface, uint8_t new_iface,
2244 if (has_interface(old_iface, api) &&
2245 !has_interface(new_iface, api)) {
2246 DBG("%s removed", api2string(api));
2253 static void modem_update_interfaces(struct modem_data *modem,
2257 DBG("%s", modem->path);
2259 if (api_added(old_ifaces, new_ifaces, OFONO_API_SIM)) {
2261 !modem->set_powered) {
2263 * Only use do GetProperties() when
2264 * device has not been powered up.
2266 sim_get_properties(modem);
2270 if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
2271 if (modem->device) {
2272 cm_get_properties(modem);
2273 cm_get_contexts(modem);
2277 if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_CM)) {
2278 if (ready_to_create_device(modem)) {
2279 create_device(modem);
2280 if (modem->registered)
2281 add_cdma_network(modem);
2285 cdma_cm_get_properties(modem);
2288 if (api_added(old_ifaces, new_ifaces, OFONO_API_NETREG)) {
2289 if (modem->attached)
2290 netreg_get_properties(modem);
2293 if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
2294 cdma_netreg_get_properties(modem);
2296 if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM)) {
2297 if (modem->call_get_contexts) {
2298 DBG("cancelling pending GetContexts call");
2299 dbus_pending_call_cancel(modem->call_get_contexts);
2300 dbus_pending_call_unref(modem->call_get_contexts);
2301 modem->call_get_contexts = NULL;
2303 remove_all_contexts(modem);
2306 if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_CM))
2307 remove_all_contexts(modem);
2309 if (api_removed(old_ifaces, new_ifaces, OFONO_API_NETREG))
2310 remove_all_networks(modem);
2312 if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
2313 remove_all_networks(modem);
2316 static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
2319 const char *path = dbus_message_get_path(message);
2320 struct modem_data *modem;
2321 DBusMessageIter iter, value;
2324 modem = g_hash_table_lookup(modem_hash, path);
2331 if (!dbus_message_iter_init(message, &iter))
2334 dbus_message_iter_get_basic(&iter, &key);
2336 dbus_message_iter_next(&iter);
2337 dbus_message_iter_recurse(&iter, &value);
2339 if (g_str_equal(key, "Powered")) {
2340 dbus_bool_t powered;
2342 dbus_message_iter_get_basic(&value, &powered);
2343 modem->powered = powered;
2345 DBG("%s Powered %d", modem->path, modem->powered);
2347 /* Set the powered according to the value */
2348 modem_set_powered(modem, powered);
2349 } else if (g_str_equal(key, "Online")) {
2352 dbus_message_iter_get_basic(&value, &online);
2353 modem->online = online;
2355 DBG("%s Online %d", modem->path, modem->online);
2360 connman_device_set_powered(modem->device, modem->online);
2361 } else if (g_str_equal(key, "Interfaces")) {
2364 interfaces = extract_interfaces(&value);
2366 if (interfaces == modem->interfaces)
2369 DBG("%s Interfaces 0x%02x", modem->path, interfaces);
2371 modem_update_interfaces(modem, modem->interfaces, interfaces);
2373 modem->interfaces = interfaces;
2374 } else if (g_str_equal(key, "Serial")) {
2377 dbus_message_iter_get_basic(&value, &serial);
2379 g_free(modem->serial);
2380 modem->serial = g_strdup(serial);
2382 DBG("%s Serial %s", modem->path, modem->serial);
2384 if (has_interface(modem->interfaces,
2385 OFONO_API_CDMA_CM)) {
2386 if (ready_to_create_device(modem)) {
2387 create_device(modem);
2388 if (modem->registered)
2389 add_cdma_network(modem);
2397 static void add_modem(const char *path, DBusMessageIter *prop)
2399 struct modem_data *modem;
2403 modem = g_hash_table_lookup(modem_hash, path);
2406 * When oFono powers up we ask for the modems and oFono is
2407 * reporting with modem_added signal the modems. Only
2413 modem = g_try_new0(struct modem_data, 1);
2417 modem->path = g_strdup(path);
2419 g_hash_table_insert(modem_hash, g_strdup(path), modem);
2421 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
2422 DBusMessageIter entry, value;
2425 dbus_message_iter_recurse(prop, &entry);
2426 dbus_message_iter_get_basic(&entry, &key);
2428 dbus_message_iter_next(&entry);
2429 dbus_message_iter_recurse(&entry, &value);
2431 if (g_str_equal(key, "Powered")) {
2432 dbus_bool_t powered;
2434 dbus_message_iter_get_basic(&value, &powered);
2435 modem->powered = powered;
2437 DBG("%s Powered %d", modem->path, modem->powered);
2438 } else if (g_str_equal(key, "Online")) {
2441 dbus_message_iter_get_basic(&value, &online);
2442 modem->online = online;
2444 DBG("%s Online %d", modem->path, modem->online);
2445 } else if (g_str_equal(key, "Interfaces")) {
2446 modem->interfaces = extract_interfaces(&value);
2448 DBG("%s Interfaces 0x%02x", modem->path,
2450 } else if (g_str_equal(key, "Serial")) {
2453 dbus_message_iter_get_basic(&value, &serial);
2454 modem->serial = g_strdup(serial);
2456 DBG("%s Serial %s", modem->path, modem->serial);
2457 } else if (g_str_equal(key, "Type")) {
2460 dbus_message_iter_get_basic(&value, &type);
2462 DBG("%s Type %s", modem->path, type);
2463 if (g_strcmp0(type, "hardware") != 0) {
2464 DBG("%s Ignore this modem", modem->path);
2465 modem->ignore = true;
2469 dbus_message_iter_next(prop);
2475 if (!modem->powered) {
2476 modem_set_powered(modem, TRUE);
2480 modem_update_interfaces(modem, 0, modem->interfaces);
2483 static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
2485 struct modem_data *modem = value;
2487 DBG("%s", modem->path);
2492 modem_set_powered(modem, FALSE);
2495 static void remove_modem(gpointer data)
2497 struct modem_data *modem = data;
2499 DBG("%s", modem->path);
2501 if (modem->call_set_property) {
2502 dbus_pending_call_cancel(modem->call_set_property);
2503 dbus_pending_call_unref(modem->call_set_property);
2504 modem->call_set_property = NULL;
2507 if (modem->call_get_properties) {
2508 dbus_pending_call_cancel(modem->call_get_properties);
2509 dbus_pending_call_unref(modem->call_get_properties);
2510 modem->call_get_properties = NULL;
2513 if (modem->call_get_contexts) {
2514 dbus_pending_call_cancel(modem->call_get_contexts);
2515 dbus_pending_call_unref(modem->call_get_contexts);
2516 modem->call_get_contexts = NULL;
2519 /* Must remove the contexts before the device */
2520 if (modem->context_list)
2521 remove_all_contexts(modem);
2524 destroy_device(modem);
2526 g_free(modem->serial);
2527 g_free(modem->name);
2528 g_free(modem->imsi);
2529 g_free(modem->path);
2534 static gboolean modem_added(DBusConnection *conn,
2535 DBusMessage *message, void *user_data)
2537 DBusMessageIter iter, properties;
2542 if (!dbus_message_iter_init(message, &iter))
2545 dbus_message_iter_get_basic(&iter, &path);
2547 dbus_message_iter_next(&iter);
2548 dbus_message_iter_recurse(&iter, &properties);
2550 add_modem(path, &properties);
2555 static gboolean modem_removed(DBusConnection *conn,
2556 DBusMessage *message, void *user_data)
2558 DBusMessageIter iter;
2563 if (!dbus_message_iter_init(message, &iter))
2566 dbus_message_iter_get_basic(&iter, &path);
2568 g_hash_table_remove(modem_hash, path);
2573 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
2577 DBusMessageIter array, dict;
2581 reply = dbus_pending_call_steal_reply(call);
2583 dbus_error_init(&error);
2585 if (dbus_set_error_from_message(&error, reply)) {
2586 connman_error("%s", error.message);
2587 dbus_error_free(&error);
2591 if (!dbus_message_iter_init(reply, &array))
2594 dbus_message_iter_recurse(&array, &dict);
2596 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
2597 DBusMessageIter value, properties;
2600 dbus_message_iter_recurse(&dict, &value);
2601 dbus_message_iter_get_basic(&value, &path);
2603 dbus_message_iter_next(&value);
2604 dbus_message_iter_recurse(&value, &properties);
2606 add_modem(path, &properties);
2608 dbus_message_iter_next(&dict);
2612 dbus_message_unref(reply);
2614 dbus_pending_call_unref(call);
2617 static int manager_get_modems(void)
2619 DBusMessage *message;
2620 DBusPendingCall *call;
2624 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
2625 OFONO_MANAGER_INTERFACE, GET_MODEMS);
2629 if (!dbus_connection_send_with_reply(connection, message,
2631 connman_error("Failed to call GetModems()");
2632 dbus_message_unref(message);
2637 connman_error("D-Bus connection not available");
2638 dbus_message_unref(message);
2642 dbus_pending_call_set_notify(call, manager_get_modems_reply,
2645 dbus_message_unref(message);
2647 return -EINPROGRESS;
2650 static void ofono_connect(DBusConnection *conn, void *user_data)
2654 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
2655 g_free, remove_modem);
2659 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
2661 if (!context_hash) {
2662 g_hash_table_destroy(modem_hash);
2666 manager_get_modems();
2669 static void ofono_disconnect(DBusConnection *conn, void *user_data)
2673 if (!modem_hash || !context_hash)
2676 g_hash_table_destroy(modem_hash);
2679 g_hash_table_destroy(context_hash);
2680 context_hash = NULL;
2683 static int network_probe(struct connman_network *network)
2685 struct modem_data *modem = connman_network_get_data(network);
2687 DBG("%s network %p", modem->path, network);
2692 static void network_remove(struct connman_network *network)
2694 struct modem_data *modem = connman_network_get_data(network);
2696 DBG("%s network %p", modem->path, network);
2699 static int network_connect(struct connman_network *network)
2701 struct network_context *context;
2702 struct modem_data *modem = connman_network_get_data(network);
2704 DBG("%s network %p", modem->path, network);
2706 if (!g_hash_table_lookup(modem_hash, modem->path))
2709 context = get_context_with_network(modem->context_list, network);
2713 if (has_interface(modem->interfaces, OFONO_API_CM))
2714 return context_set_active(modem, context, TRUE);
2715 else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
2716 return cdma_cm_set_powered(modem, TRUE);
2718 connman_error("Connection manager interface not available");
2723 static int network_disconnect(struct connman_network *network)
2725 struct network_context *context;
2726 struct modem_data *modem = connman_network_get_data(network);
2728 DBG("%s network %p", modem->path, network);
2730 if (!g_hash_table_lookup(modem_hash, modem->path))
2733 context = get_context_with_network(modem->context_list, network);
2737 if (has_interface(modem->interfaces, OFONO_API_CM))
2738 return context_set_active(modem, context, FALSE);
2739 else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
2740 return cdma_cm_set_powered(modem, FALSE);
2742 connman_error("Connection manager interface not available");
2747 static struct connman_network_driver network_driver = {
2749 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
2750 .probe = network_probe,
2751 .remove = network_remove,
2752 .connect = network_connect,
2753 .disconnect = network_disconnect,
2756 static int modem_probe(struct connman_device *device)
2758 struct modem_data *modem = connman_device_get_data(device);
2760 DBG("%s device %p", modem->path, device);
2765 static void modem_remove(struct connman_device *device)
2767 struct modem_data *modem = connman_device_get_data(device);
2769 DBG("%s device %p", modem->path, device);
2772 static int modem_enable(struct connman_device *device)
2774 struct modem_data *modem = connman_device_get_data(device);
2776 DBG("%s device %p", modem->path, device);
2781 return modem_set_online(modem, TRUE);
2784 static int modem_disable(struct connman_device *device)
2786 struct modem_data *modem = connman_device_get_data(device);
2788 DBG("%s device %p", modem->path, device);
2793 return modem_set_online(modem, FALSE);
2796 static struct connman_device_driver modem_driver = {
2798 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
2799 .probe = modem_probe,
2800 .remove = modem_remove,
2801 .enable = modem_enable,
2802 .disable = modem_disable,
2805 static int tech_probe(struct connman_technology *technology)
2810 static void tech_remove(struct connman_technology *technology)
2814 static struct connman_technology_driver tech_driver = {
2816 .type = CONNMAN_SERVICE_TYPE_CELLULAR,
2817 .probe = tech_probe,
2818 .remove = tech_remove,
2822 static guint modem_added_watch;
2823 static guint modem_removed_watch;
2824 static guint modem_watch;
2825 static guint cm_watch;
2826 static guint sim_watch;
2827 static guint context_added_watch;
2828 static guint context_removed_watch;
2829 static guint netreg_watch;
2830 static guint context_watch;
2831 static guint cdma_cm_watch;
2832 static guint cdma_netreg_watch;
2834 static int ofono_init(void)
2840 connection = connman_dbus_get_connection();
2844 watch = g_dbus_add_service_watch(connection,
2845 OFONO_SERVICE, ofono_connect,
2846 ofono_disconnect, NULL, NULL);
2848 modem_added_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
2849 NULL, OFONO_MANAGER_INTERFACE,
2854 modem_removed_watch = g_dbus_add_signal_watch(connection,
2855 OFONO_SERVICE, NULL,
2856 OFONO_MANAGER_INTERFACE,
2861 modem_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
2862 OFONO_MODEM_INTERFACE,
2867 cm_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
2873 sim_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
2874 OFONO_SIM_INTERFACE,
2879 context_added_watch = g_dbus_add_signal_watch(connection,
2880 OFONO_SERVICE, NULL,
2886 context_removed_watch = g_dbus_add_signal_watch(connection,
2887 OFONO_SERVICE, NULL,
2893 context_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
2894 NULL, OFONO_CONTEXT_INTERFACE,
2899 netreg_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE, NULL,
2900 OFONO_NETREG_INTERFACE,
2905 cdma_cm_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
2906 NULL, OFONO_CDMA_CM_INTERFACE,
2911 cdma_netreg_watch = g_dbus_add_signal_watch(connection, OFONO_SERVICE,
2912 NULL, OFONO_CDMA_NETREG_INTERFACE,
2914 cdma_netreg_changed,
2918 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
2919 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
2920 context_added_watch == 0 ||
2921 context_removed_watch == 0 ||
2922 context_watch == 0 || netreg_watch == 0 ||
2923 cdma_cm_watch == 0 || cdma_netreg_watch == 0) {
2928 err = connman_network_driver_register(&network_driver);
2932 err = connman_device_driver_register(&modem_driver);
2934 connman_network_driver_unregister(&network_driver);
2938 err = connman_technology_driver_register(&tech_driver);
2940 connman_device_driver_unregister(&modem_driver);
2941 connman_network_driver_unregister(&network_driver);
2948 g_dbus_remove_watch(connection, cdma_netreg_watch);
2949 g_dbus_remove_watch(connection, cdma_cm_watch);
2950 g_dbus_remove_watch(connection, netreg_watch);
2951 g_dbus_remove_watch(connection, context_watch);
2952 g_dbus_remove_watch(connection, context_removed_watch);
2953 g_dbus_remove_watch(connection, context_added_watch);
2954 g_dbus_remove_watch(connection, sim_watch);
2955 g_dbus_remove_watch(connection, cm_watch);
2956 g_dbus_remove_watch(connection, modem_watch);
2957 g_dbus_remove_watch(connection, modem_removed_watch);
2958 g_dbus_remove_watch(connection, modem_added_watch);
2959 g_dbus_remove_watch(connection, watch);
2960 dbus_connection_unref(connection);
2965 static void ofono_exit(void)
2971 * We should propably wait for the SetProperty() reply
2972 * message, because ...
2974 g_hash_table_foreach(modem_hash, modem_power_down, NULL);
2977 * ... here we will cancel the call.
2979 g_hash_table_destroy(modem_hash);
2984 g_hash_table_destroy(context_hash);
2985 context_hash = NULL;
2988 connman_technology_driver_unregister(&tech_driver);
2989 connman_device_driver_unregister(&modem_driver);
2990 connman_network_driver_unregister(&network_driver);
2992 g_dbus_remove_watch(connection, cdma_netreg_watch);
2993 g_dbus_remove_watch(connection, cdma_cm_watch);
2994 g_dbus_remove_watch(connection, netreg_watch);
2995 g_dbus_remove_watch(connection, context_watch);
2996 g_dbus_remove_watch(connection, context_removed_watch);
2997 g_dbus_remove_watch(connection, context_added_watch);
2998 g_dbus_remove_watch(connection, sim_watch);
2999 g_dbus_remove_watch(connection, cm_watch);
3000 g_dbus_remove_watch(connection, modem_watch);
3001 g_dbus_remove_watch(connection, modem_added_watch);
3002 g_dbus_remove_watch(connection, modem_removed_watch);
3003 g_dbus_remove_watch(connection, watch);
3005 dbus_connection_unref(connection);
3008 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
3009 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)