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
32 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
35 #include <glib/gprintf.h>
39 #include <drivers/stemodem/caif_socket.h>
40 #include <drivers/stemodem/if_caif.h>
42 static GMainLoop *mainloop;
44 static int do_open(void)
48 fd = open("/dev/chnlat11", O_RDWR);
50 g_printerr("Open of chnlat11 failed (%d)\n", errno);
57 static int do_connect(void)
59 struct sockaddr_caif addr;
62 /* Create a CAIF socket for AT Service */
63 sk = socket(AF_CAIF, SOCK_SEQPACKET, CAIFPROTO_AT);
65 g_printerr("CAIF socket creation failed (%d)\n", errno);
69 memset(&addr, 0, sizeof(addr));
70 addr.family = AF_CAIF;
71 addr.u.at.type = CAIF_ATTYPE_PLAIN;
73 /* Connect to the AT Service at the modem */
74 err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
76 g_printerr("CAIF socket connect failed (%d)\n", errno);
84 static void caif_debug(const char *str, void *data)
89 static void caif_init(gboolean ok, GAtResult *result, gpointer data)
93 g_print("caif_init: %d\n", ok);
96 g_at_chat_unref(chat);
97 g_main_loop_quit(mainloop);
101 g_at_chat_unref(chat);
102 g_main_loop_quit(mainloop);
105 static void test_connect(gboolean use_socket)
112 if (use_socket == TRUE)
120 io = g_io_channel_unix_new(fd);
121 g_io_channel_set_close_on_unref(io, TRUE);
123 syntax = g_at_syntax_new_gsm_permissive();
124 chat = g_at_chat_new_blocking(io, syntax);
125 g_at_syntax_unref(syntax);
127 g_io_channel_unref(io);
130 g_printerr("Chat creation failed\n");
134 g_at_chat_set_debug(chat, caif_debug, NULL);
135 g_at_chat_send(chat, "ATE0 +CMEE=1", NULL, caif_init, chat, NULL);
137 mainloop = g_main_loop_new(NULL, FALSE);
139 g_main_loop_run(mainloop);
140 g_main_loop_unref(mainloop);
143 static void test_basic(void)
145 if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
150 g_test_trap_assert_passed();
151 //g_test_trap_assert_stderr("failed");
154 static void test_chnlat(void)
156 if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
161 g_test_trap_assert_passed();
162 //g_test_trap_assert_stderr("failed");
165 int main(int argc, char **argv)
167 g_test_init(&argc, &argv, NULL);
169 g_test_add_func("/testcaif/basic", test_basic);
170 g_test_add_func("/testcaif/chnlat", test_chnlat);