3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include <gatchat/gatserver.h>
39 #define OFONO_SERVICE "org.ofono"
40 #define STKTEST_PATH "/stktest"
41 #define STKTEST_ERROR "org.ofono.stktest.Error"
42 #define OFONO_ERROR "org.ofono.Error"
43 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
44 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
45 #define OFONO_STK_INTERFACE OFONO_SERVICE ".SimToolkit"
46 #define OFONO_STKAGENT_INTERFACE OFONO_SERVICE ".SimToolkitAgent"
48 #define LISTEN_PORT 12765
51 TEST_STATE_POWERING_UP = 1,
52 TEST_STATE_REGISTERING_AGENT,
54 TEST_STATE_POWERING_DOWN,
58 TEST_RESULT_NOT_RUN = 0,
63 typedef DBusMessage *(*display_text_cb_t)(DBusMessage *msg, const char *text,
64 unsigned char icon_id,
66 typedef void (*terminal_response_func)(const unsigned char *pdu,
72 unsigned char *req_pdu;
74 unsigned char *rsp_pdu;
77 terminal_response_func tr_func;
78 enum test_result result;
81 static GMainLoop *main_loop = NULL;
82 static volatile sig_atomic_t __terminated = 0;
84 GList *cur_test = NULL;
87 static DBusConnection *conn;
88 static gboolean ofono_running = FALSE;
89 static guint modem_changed_watch;
90 enum test_state state;
93 static guint server_watch;
94 static GAtServer *emulator;
96 /* Emulated modem state variables */
97 static int modem_mode = 0;
99 void __stktest_test_next();
100 void __stktest_test_finish(gboolean successful);
101 static gboolean create_tcp(void);
103 #define STKTEST_AGENT_ASSERT(expr) \
106 g_printerr("Assertion Failed %s:%d %s\n", \
107 __FILE__, __LINE__, #expr); \
108 __stktest_test_finish(FALSE); \
109 return stktest_error_failed(msg); \
113 #define STKTEST_RESPONSE_ASSERT(expect_pdu, expect_pdu_len, \
114 got_pdu, got_pdu_len) \
116 if ((expect_pdu_len) != (got_pdu_len)) { \
117 g_printerr("Assertion Failed %s:%d" \
118 " Wrong response len" \
119 " want: %d, got: %d\n", \
120 __FILE__, __LINE__, \
121 expect_pdu_len, got_pdu_len); \
122 __stktest_test_finish(FALSE); \
126 if (memcmp(expect_pdu, got_pdu, expect_pdu_len) != 0) { \
127 g_printerr("Assertion Failed %s:%d" \
128 "Wrong response\n", \
129 __FILE__, __LINE__); \
130 __stktest_test_finish(FALSE); \
135 static const char *to_hex(const unsigned char *data, unsigned int len)
137 static char buf[512+1];
140 for (i = 0; i < len; i++)
141 sprintf(buf + i * 2, "%02hhX", data[i]);
148 static void send_proactive_command(const unsigned char *pdu, unsigned int len)
152 sprintf(buf, "+CUSATP: %s", to_hex(pdu, len));
153 g_at_server_send_unsolicited(emulator, buf);
156 static DBusMessage *stktest_error_invalid_args(DBusMessage *msg)
158 return g_dbus_create_error(msg, STKTEST_ERROR ".InvalidArguments",
159 "Invalid arguments provided");
162 static DBusMessage *stktest_error_failed(DBusMessage *msg)
164 return g_dbus_create_error(msg, STKTEST_ERROR ".Failed",
168 static DBusMessage *stktest_error_end_session(DBusMessage *msg)
170 return g_dbus_create_error(msg, OFONO_ERROR ".EndSession",
171 "End Session Request");
174 static DBusMessage *stktest_error_go_back(DBusMessage *msg)
176 return g_dbus_create_error(msg, OFONO_ERROR ".GoBack",
180 static DBusMessage *stktest_error_busy(DBusMessage *msg)
182 return g_dbus_create_error(msg, OFONO_ERROR ".Busy",
186 static DBusMessage *agent_release(DBusConnection *conn, DBusMessage *msg,
189 g_print("Got Release\n");
191 return dbus_message_new_method_return(msg);
194 static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
198 unsigned char icon_id;
201 display_text_cb_t func;
203 if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
204 DBUS_TYPE_BYTE, &icon_id,
205 DBUS_TYPE_BOOLEAN, &urgent,
206 DBUS_TYPE_INVALID) == FALSE)
207 return stktest_error_invalid_args(msg);
209 if (cur_test == NULL)
210 return stktest_error_failed(msg);
212 test = cur_test->data;
213 func = test->agent_func;
215 return func(msg, text, icon_id, urgent);
218 static void server_debug(const char *str, void *data)
220 g_print("%s: %s\n", (char *) data, str);
223 static void cgmi_cb(GAtServer *server, GAtServerRequestType type,
224 GAtResult *cmd, gpointer user)
227 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
228 g_at_server_send_info(server, "oFono", TRUE);
229 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
231 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
232 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
235 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
239 static void cgmm_cb(GAtServer *server, GAtServerRequestType type,
240 GAtResult *cmd, gpointer user)
243 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
244 g_at_server_send_info(server, "oFono pre-1.0", TRUE);
245 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
247 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
248 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
251 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
255 static void cgmr_cb(GAtServer *server, GAtServerRequestType type,
256 GAtResult *cmd, gpointer user)
261 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
262 sprintf(buf, "oFono pre-1.0 version: %s", VERSION);
263 g_at_server_send_info(server, buf, TRUE);
264 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
266 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
267 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
270 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
274 static void cgsn_cb(GAtServer *server, GAtServerRequestType type,
275 GAtResult *cmd, gpointer user)
278 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
279 g_at_server_send_info(server, "123456789", TRUE);
280 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
282 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
283 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
286 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
290 static gboolean send_ok(gpointer user)
292 GAtServer *server = user;
294 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
299 static void cfun_cb(GAtServer *server, GAtServerRequestType type,
300 GAtResult *cmd, gpointer user)
305 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
306 g_at_server_send_info(server, "+CFUN: (0-1,4)", TRUE);
307 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
309 case G_AT_SERVER_REQUEST_TYPE_QUERY:
310 snprintf(buf, sizeof(buf), "+CFUN: %d", modem_mode);
311 g_at_server_send_info(server, buf, TRUE);
312 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
314 case G_AT_SERVER_REQUEST_TYPE_SET:
319 g_at_result_iter_init(&iter, cmd);
320 g_at_result_iter_next(&iter, "");
322 if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
325 if (mode != 0 && mode != 1)
328 if (modem_mode == mode) {
329 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
334 g_timeout_add_seconds(1, send_ok, server);
344 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
347 static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
348 GAtResult *cmd, gpointer user)
351 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
352 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
354 case G_AT_SERVER_REQUEST_TYPE_QUERY:
355 g_at_server_send_ext_final(server, "+CME ERROR: 4");
357 case G_AT_SERVER_REQUEST_TYPE_SET:
360 const unsigned char *pdu;
363 terminal_response_func func;
365 g_at_result_iter_init(&iter, cmd);
366 g_at_result_iter_next(&iter, "");
368 if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
371 if (cur_test == NULL)
374 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
376 test = cur_test->data;
377 func = test->tr_func;
388 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
391 static void listen_again(gpointer user_data)
393 g_at_server_unref(emulator);
396 if (create_tcp() == TRUE)
399 g_print("Error listening to socket\n");
400 g_main_loop_quit(main_loop);
403 static void setup_emulator(GAtServer *server)
405 g_at_server_set_debug(server, server_debug, "Server");
407 g_at_server_register(server, "+CGMI", cgmi_cb, NULL, NULL);
408 g_at_server_register(server, "+CGMM", cgmm_cb, NULL, NULL);
409 g_at_server_register(server, "+CGMR", cgmr_cb, NULL, NULL);
410 g_at_server_register(server, "+CGSN", cgsn_cb, NULL, NULL);
411 g_at_server_register(server, "+CFUN", cfun_cb, NULL, NULL);
412 g_at_server_register(server, "+CUSATT", cusatt_cb, NULL, NULL);
414 g_at_server_set_disconnect_function(server, listen_again, NULL);
417 static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
420 struct sockaddr saddr;
421 unsigned int len = sizeof(saddr);
423 GIOChannel *client_io = NULL;
428 fd = accept(g_io_channel_unix_get_fd(chan), &saddr, &len);
432 client_io = g_io_channel_unix_new(fd);
434 emulator = g_at_server_new(client_io);
435 g_at_server_set_echo(emulator, FALSE);
436 g_io_channel_unref(client_io);
438 if (emulator == NULL)
441 setup_emulator(emulator);
448 static gboolean create_tcp(void)
450 struct sockaddr_in addr;
453 GIOChannel *server_io;
455 sk = socket(PF_INET, SOCK_STREAM, 0);
457 g_print("Can't create tcp/ip socket: %s (%d)\n",
458 strerror(errno), errno);
462 memset(&addr, 0, sizeof(addr));
464 addr.sin_family = AF_INET;
465 addr.sin_addr.s_addr = INADDR_ANY;
466 addr.sin_port = htons(LISTEN_PORT);
468 setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
469 if (bind(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr)) < 0) {
470 g_print("Can't bind socket: %s (%d)", strerror(errno), errno);
475 if (listen(sk, 1) < 0) {
476 g_print("Can't listen on socket: %s (%d)",
477 strerror(errno), errno);
482 g_print("new tcp is created at tcp port %d\n", LISTEN_PORT);
484 server_io = g_io_channel_unix_new(sk);
485 g_io_channel_set_close_on_unref(server_io, TRUE);
487 server_watch = g_io_add_watch_full(server_io,
489 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
490 on_socket_connected, NULL, NULL);
492 g_io_channel_unref(server_io);
497 static gboolean has_stk_interface(DBusMessageIter *iter)
499 DBusMessageIter entry;
501 dbus_message_iter_recurse(iter, &entry);
503 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
504 const char *interface;
506 dbus_message_iter_get_basic(&entry, &interface);
508 if (g_str_equal(interface, OFONO_STK_INTERFACE) == TRUE)
511 dbus_message_iter_next(&entry);
517 static int send_with_reply(const char *path, const char *interface,
518 const char *method, DBusPendingCall **call,
519 DBusPendingCallNotifyFunction cb,
520 void *user_data, DBusFreeFunction free_func,
521 int timeout, int type, ...)
528 msg = dbus_message_new_method_call(OFONO_SERVICE, path,
531 g_printerr("Unable to allocate new D-Bus %s message\n", method);
536 va_start(args, type);
538 if (!dbus_message_append_args_valist(msg, type, args)) {
549 if (!dbus_connection_send_with_reply(conn, msg, &c, timeout)) {
550 g_printerr("Sending %s failed\n", method);
558 dbus_pending_call_set_notify(c, cb, user_data, free_func);
559 dbus_pending_call_unref(c);
561 dbus_message_unref(msg);
566 if (free_func && user_data)
567 free_func(user_data);
570 dbus_message_unref(msg);
575 static void set_property_reply(DBusPendingCall *call, void *user_data)
577 DBusMessage *reply = dbus_pending_call_steal_reply(call);
580 dbus_error_init(&err);
582 if (dbus_set_error_from_message(&err, reply) == TRUE) {
583 g_printerr("%s: %s\n", err.name, err.message);
584 dbus_error_free(&err);
587 dbus_message_unref(reply);
590 static int set_property(const char *path, const char *interface,
591 const char *key, int type, const void *val,
592 DBusPendingCallNotifyFunction notify,
594 DBusFreeFunction destroy)
597 DBusMessageIter iter, value;
598 DBusPendingCall *call;
599 const char *signature;
601 msg = dbus_message_new_method_call(OFONO_SERVICE, path, interface,
606 dbus_message_set_auto_start(msg, FALSE);
608 dbus_message_iter_init_append(msg, &iter);
610 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
613 case DBUS_TYPE_BOOLEAN:
614 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
617 dbus_message_unref(msg);
621 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
623 dbus_message_iter_append_basic(&value, type, val);
624 dbus_message_iter_close_container(&iter, &value);
626 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
627 dbus_message_unref(msg);
631 dbus_message_unref(msg);
636 dbus_pending_call_set_notify(call, notify, user_data, destroy);
638 dbus_pending_call_unref(call);
643 static void register_agent_reply(DBusPendingCall *call, void *user_data)
645 DBusMessage *reply = dbus_pending_call_steal_reply(call);
649 dbus_error_init(&err);
651 if (dbus_set_error_from_message(&err, reply) == TRUE) {
652 g_printerr("%s: %s\n", err.name, err.message);
653 dbus_error_free(&err);
656 dbus_message_unref(reply);
658 state = TEST_STATE_RUNNING;
659 test = cur_test->data;
660 send_proactive_command(test->req_pdu, test->req_len);
663 static void register_agent()
665 const char *path = "/default";
668 g_print("Gained STK interface, registering agent...\n");
670 status = send_with_reply(STKTEST_PATH, OFONO_STK_INTERFACE,
671 "RegisterAgent", NULL,
672 register_agent_reply, NULL, NULL, 1,
673 DBUS_TYPE_OBJECT_PATH, &path,
677 g_printerr("Unable to register agent with oFono\n");
678 g_main_loop_quit(main_loop);
682 state = TEST_STATE_REGISTERING_AGENT;
685 static gboolean modem_changed(DBusConnection *conn,
686 DBusMessage *msg, void *user_data)
688 DBusMessageIter iter, value;
689 const char *path, *key;
692 if (dbus_message_iter_init(msg, &iter) == FALSE)
695 path = dbus_message_get_path(msg);
697 if (g_str_equal(STKTEST_PATH, path) == FALSE)
700 dbus_message_iter_get_basic(&iter, &key);
702 dbus_message_iter_next(&iter);
703 dbus_message_iter_recurse(&iter, &value);
705 if (g_str_equal(key, "Interfaces") == FALSE)
708 has_stk = has_stk_interface(&value);
711 case TEST_STATE_POWERING_UP:
715 case TEST_STATE_REGISTERING_AGENT:
716 case TEST_STATE_RUNNING:
717 if (has_stk == FALSE)
718 g_printerr("Unexpectedly lost STK interface\n");
720 case TEST_STATE_POWERING_DOWN:
727 static void powerup(void)
729 dbus_bool_t powered = TRUE;
731 state = TEST_STATE_POWERING_UP;
732 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
733 DBUS_TYPE_BOOLEAN, &powered,
734 set_property_reply, NULL, NULL);
737 static void get_modems_reply(DBusPendingCall *call, void *user_data)
739 DBusMessage *reply = dbus_pending_call_steal_reply(call);
740 DBusMessageIter iter, list;
742 gboolean found = FALSE;
744 dbus_error_init(&err);
746 if (dbus_set_error_from_message(&err, reply) == TRUE) {
747 g_printerr("%s: %s\n", err.name, err.message);
748 dbus_error_free(&err);
752 if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
755 if (dbus_message_iter_init(reply, &iter) == FALSE)
758 dbus_message_iter_recurse(&iter, &list);
760 while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
761 DBusMessageIter entry;
764 dbus_message_iter_recurse(&list, &entry);
765 dbus_message_iter_get_basic(&entry, &path);
767 if (g_str_equal(path, STKTEST_PATH))
770 dbus_message_iter_next(&list);
774 dbus_message_unref(reply);
776 if (found == FALSE) {
777 g_printerr("STK Test modem not found\n");
778 g_main_loop_quit(main_loop);
782 g_print("Test modem found\n");
784 modem_changed_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
786 OFONO_MODEM_INTERFACE,
791 if (create_tcp() == FALSE) {
792 g_printerr("Unable to listen on modem emulator socket\n");
793 g_main_loop_quit(main_loop);
796 __stktest_test_next();
799 static int get_modems(DBusConnection *conn)
802 DBusPendingCall *call;
804 msg = dbus_message_new_method_call(OFONO_SERVICE, "/",
805 OFONO_MANAGER_INTERFACE, "GetModems");
809 dbus_message_set_auto_start(msg, FALSE);
811 g_print("getting modems\n");
813 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
814 dbus_message_unref(msg);
818 dbus_message_unref(msg);
823 dbus_pending_call_set_notify(call, get_modems_reply, conn, NULL);
825 dbus_pending_call_unref(call);
830 static const GDBusMethodTable agent_methods[] = {
831 { GDBUS_METHOD("Release", NULL, NULL, agent_release) },
832 { GDBUS_METHOD("DisplayText",
833 GDBUS_ARGS({ "text", "s" }, { "icon_id", "y" },
834 { "urgent", "b" }), NULL,
835 agent_display_text) },
839 static void ofono_connect(DBusConnection *conn, void *user_data)
841 g_print("starting telephony interface\n");
843 if (!g_dbus_register_interface(conn, "/default",
844 OFONO_STKAGENT_INTERFACE,
845 agent_methods, NULL, NULL,
847 g_printerr("Unable to register local agent");
848 g_main_loop_quit(main_loop);
851 ofono_running = TRUE;
855 static void ofono_disconnect(DBusConnection *conn, void *user_data)
857 g_print("stopping telephony interface\n");
859 g_dbus_unregister_interface(conn, "/default", OFONO_STKAGENT_INTERFACE);
861 ofono_running = FALSE;
863 g_dbus_remove_watch(conn, modem_changed_watch);
864 modem_changed_watch = 0;
867 g_source_remove(server_watch);
871 g_at_server_unref(emulator);
875 static void sig_term(int sig)
877 if (__terminated > 0)
882 g_print("Terminating\n");
884 g_main_loop_quit(main_loop);
887 static void disconnect_callback(DBusConnection *conn, void *user_data)
889 g_printerr("D-Bus disconnect\n");
891 g_main_loop_quit(main_loop);
894 static void power_down_reply(DBusPendingCall *call, void *user_data)
896 __stktest_test_next();
899 void __stktest_test_finish(gboolean successful)
901 struct test *test = cur_test->data;
902 dbus_bool_t powered = FALSE;
904 test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
906 state = TEST_STATE_POWERING_DOWN;
907 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
908 DBUS_TYPE_BOOLEAN, &powered,
909 power_down_reply, NULL, NULL);
912 void __stktest_test_next()
914 if (cur_test == NULL)
917 cur_test = cur_test->next;
919 if (cur_test == NULL)
920 g_main_loop_quit(main_loop);
925 static void stktest_add_test(const char *name, const char *method,
926 const unsigned char *req, unsigned int req_len,
927 const unsigned char *rsp, unsigned int rsp_len,
929 terminal_response_func tr_func)
931 struct test *test = g_new0(struct test, 1);
933 test->name = g_strdup(name);
934 test->method = g_strdup(method);
935 test->req_pdu = g_memdup(req, req_len);
936 test->req_len = req_len;
937 test->rsp_pdu = g_memdup(rsp, rsp_len);
938 test->rsp_len = rsp_len;
939 test->agent_func = agent_func;
940 test->tr_func = tr_func;
942 tests = g_list_append(tests, test);
945 static void __stktest_test_init(void)
949 static void test_destroy(gpointer user_data)
951 struct test *test = user_data;
954 g_free(test->method);
955 g_free(test->req_pdu);
956 g_free(test->rsp_pdu);
961 static void __stktest_test_summarize(void)
965 g_print("\n\nTest Summary\n");
966 g_print("============\n");
968 for (l = tests; l; l = l->next) {
969 struct test *test = l->data;
971 g_print("%-60s", test->name);
973 switch (test->result) {
974 case TEST_RESULT_NOT_RUN:
975 g_print("Not Run\n");
977 case TEST_RESULT_PASSED:
980 case TEST_RESULT_FAILED:
987 static void __stktest_test_cleanup(void)
989 g_list_free_full(tests, test_destroy);
994 static gboolean option_version = FALSE;
996 static GOptionEntry options[] = {
997 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
998 "Show version information and exit" },
1002 int main(int argc, char **argv)
1004 GOptionContext *context;
1005 GError *error = NULL;
1008 struct sigaction sa;
1010 context = g_option_context_new(NULL);
1011 g_option_context_add_main_entries(context, options, NULL);
1013 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
1014 if (error != NULL) {
1015 g_printerr("%s\n", error->message);
1016 g_error_free(error);
1018 g_printerr("An unknown error occurred\n");
1022 g_option_context_free(context);
1024 if (option_version == TRUE) {
1025 printf("%s\n", VERSION);
1029 __stktest_test_init();
1031 main_loop = g_main_loop_new(NULL, FALSE);
1033 dbus_error_init(&err);
1035 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
1037 if (dbus_error_is_set(&err) == TRUE) {
1038 fprintf(stderr, "%s\n", err.message);
1039 dbus_error_free(&err);
1041 fprintf(stderr, "Can't register with system bus\n");
1045 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1047 memset(&sa, 0, sizeof(sa));
1048 sa.sa_handler = sig_term;
1049 sigaction(SIGINT, &sa, NULL);
1050 sigaction(SIGTERM, &sa, NULL);
1052 watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
1053 ofono_connect, ofono_disconnect, NULL, NULL);
1055 g_main_loop_run(main_loop);
1057 g_dbus_remove_watch(conn, watch);
1059 if (ofono_running == TRUE)
1060 ofono_disconnect(conn, NULL);
1062 dbus_connection_unref(conn);
1064 g_main_loop_unref(main_loop);
1066 __stktest_test_summarize();
1067 __stktest_test_cleanup();