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 static gboolean option_debug = FALSE;
34 static gchar *option_device = NULL;
36 static GMainLoop *event_loop;
47 guint16 mob_firmware_rev;
48 guint8 slot_cycle_index;
51 } __attribute__ ((packed));
53 static void parse_qcdm(const unsigned char *buf, gsize len)
55 struct version_info *verinfo;
61 g_print("==> Version information\n");
62 verinfo = (struct version_info *) (buf + 1);
63 snprintf(str, 12, "%s", verinfo->comp_date);
64 g_print("Compiled Date: %s\n", str);
65 snprintf(str, 9, "%s", verinfo->comp_time);
66 g_print("Compiled Time: %s\n", str);
67 snprintf(str, 12, "%s", verinfo->rel_date);
68 g_print("Release Date: %s\n", str);
69 snprintf(str, 9, "%s", verinfo->rel_time);
70 g_print("Release Time: %s\n", str);
71 snprintf(str, 9, "%s", verinfo->model);
72 g_print("Model: %s\n", str);
73 g_print("MSM version: %d\n", verinfo->msm_ver);
76 g_print("==> Invalid command response\n");
79 g_print("==> Subsystem response\n");
82 g_print("==> Features response\n");
85 g_print("==> Unknown command 0x%02x\n", cmd);
90 static void hdlc_debug(const char *str, void *data)
92 g_print("%s: %s\n", (const char *) data, str);
95 static void hdlc_receive(const unsigned char *buf, gsize len, void *data)
100 static void send_command(GAtHDLC *hdlc, guint8 cmd)
102 unsigned char cmdbuf[1];
106 g_at_hdlc_send(hdlc, cmdbuf, sizeof(cmdbuf));
109 static void send_subsys_command(GAtHDLC *hdlc, guint8 id, guint16 cmd)
111 unsigned char cmdbuf[4];
115 cmdbuf[2] = cmd & 0xff;
116 cmdbuf[3] = cmd >> 8;
118 g_at_hdlc_send(hdlc, cmdbuf, sizeof(cmdbuf));
121 static GOptionEntry options[] = {
122 { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
123 "Enable debugging" },
124 { "device", 'n', 0, G_OPTION_ARG_STRING, &option_device,
129 int main(int argc, char **argv)
131 GOptionContext *context;
136 context = g_option_context_new(NULL);
137 g_option_context_add_main_entries(context, options, NULL);
139 if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
141 g_printerr("%s\n", err->message);
146 g_printerr("An unknown error occurred\n");
150 g_option_context_free(context);
152 if (option_device == NULL)
153 option_device = g_strdup("/dev/ttyUSB1");
155 g_print("Device: %s\n", option_device);
157 channel = g_at_tty_open_qcdm(option_device);
158 if (channel == NULL) {
159 g_printerr("Failed to open QCDM device\n");
163 event_loop = g_main_loop_new(NULL, FALSE);
165 hdlc = g_at_hdlc_new(channel);
167 g_io_channel_unref(channel);
172 if (option_debug == TRUE)
173 g_at_hdlc_set_debug(hdlc, hdlc_debug, "HDLC");
175 g_at_hdlc_set_xmit_accm(hdlc, 0);
176 g_at_hdlc_set_recv_accm(hdlc, 0);
178 g_at_hdlc_set_receive(hdlc, hdlc_receive, NULL);
180 send_command(hdlc, 0x00); /* Version info */
181 send_command(hdlc, 0x51); /* Features query */
183 send_subsys_command(hdlc, 250, 7); /* Novatel modem status */
185 g_main_loop_run(event_loop);
187 g_at_hdlc_unref(hdlc);
189 g_main_loop_unref(event_loop);
191 g_free(option_device);