5d30f39490990eb4301a7e304291c756b00b331e
[profile/ivi/ofono.git] / plugins / wavecom.c
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <gatchat.h>
31 #include <gattty.h>
32
33 #define OFONO_API_SUBJECT_TO_CHANGE
34 #include <ofono/plugin.h>
35 #include <ofono/log.h>
36 #include <ofono/modem.h>
37 #include <ofono/call-barring.h>
38 #include <ofono/call-forwarding.h>
39 #include <ofono/call-meter.h>
40 #include <ofono/call-settings.h>
41 #include <ofono/devinfo.h>
42 #include <ofono/message-waiting.h>
43 #include <ofono/netreg.h>
44 #include <ofono/phonebook.h>
45 #include <ofono/sim.h>
46 #include <ofono/sms.h>
47 #include <ofono/ussd.h>
48 #include <ofono/voicecall.h>
49
50 #include <drivers/atmodem/vendor.h>
51
52
53 static int wavecom_probe(struct ofono_modem *modem)
54 {
55         return 0;
56 }
57
58 static void wavecom_remove(struct ofono_modem *modem)
59 {
60 }
61
62 static void wavecom_debug(const char *str, void *user_data)
63 {
64         const char *prefix = user_data;
65
66         ofono_info("%s%s", prefix, str);
67 }
68
69 static int wavecom_enable(struct ofono_modem *modem)
70 {
71         GAtChat *chat;
72         GIOChannel *channel;
73         GAtSyntax *syntax;
74         const char *device;
75         GHashTable *options;
76
77         DBG("%p", modem);
78
79         device = ofono_modem_get_string(modem, "Device");
80         if (device == NULL)
81                 return -EINVAL;
82
83         options = g_hash_table_new(g_str_hash, g_str_equal);
84
85         if (options == NULL)
86                 return -ENOMEM;
87
88         g_hash_table_insert(options, "Baud", "115200");
89         g_hash_table_insert(options, "Parity", "none");
90         g_hash_table_insert(options, "StopBits", "1");
91         g_hash_table_insert(options, "DataBits", "8");
92
93         channel = g_at_tty_open(device, options);
94
95         g_hash_table_destroy(options);
96
97         if (channel == NULL)
98                 return -EIO;
99
100         /*
101          * Could not figure out whether it is fully compliant or not, use
102          * permissive for now
103          * */
104         syntax = g_at_syntax_new_gsm_permissive();
105
106         chat = g_at_chat_new(channel, syntax);
107         g_at_syntax_unref(syntax);
108         g_io_channel_unref(channel);
109
110         if (chat == NULL)
111                 return -ENOMEM;
112
113         if (getenv("OFONO_AT_DEBUG"))
114                 g_at_chat_set_debug(chat, wavecom_debug, "");
115
116         ofono_modem_set_data(modem, chat);
117
118         return 0;
119 }
120
121 static int wavecom_disable(struct ofono_modem *modem)
122 {
123         GAtChat *chat = ofono_modem_get_data(modem);
124
125         DBG("%p", modem);
126
127         ofono_modem_set_data(modem, NULL);
128
129         g_at_chat_unref(chat);
130
131         return 0;
132 }
133
134 static void wavecom_pre_sim(struct ofono_modem *modem)
135 {
136         GAtChat *chat = ofono_modem_get_data(modem);
137
138         DBG("%p", modem);
139
140         ofono_devinfo_create(modem, 0, "atmodem", chat);
141         ofono_sim_create(modem, OFONO_VENDOR_WAVECOM, "atmodem", chat);
142         ofono_voicecall_create(modem, 0, "atmodem", chat);
143 }
144
145 static void wavecom_post_sim(struct ofono_modem *modem)
146 {
147         GAtChat *chat = ofono_modem_get_data(modem);
148         struct ofono_message_waiting *mw;
149
150         DBG("%p", modem);
151
152         ofono_ussd_create(modem, 0, "atmodem", chat);
153         ofono_call_forwarding_create(modem, 0, "atmodem", chat);
154         ofono_call_settings_create(modem, 0, "atmodem", chat);
155         ofono_netreg_create(modem, 0, "atmodem", chat);
156         ofono_call_meter_create(modem, 0, "atmodem", chat);
157         ofono_call_barring_create(modem, 0, "atmodem", chat);
158         ofono_sms_create(modem, 0, "atmodem", chat);
159         ofono_phonebook_create(modem, 0, "atmodem", chat);
160
161         mw = ofono_message_waiting_create(modem);
162         if (mw)
163                 ofono_message_waiting_register(mw);
164 }
165
166 static struct ofono_modem_driver wavecom_driver = {
167         .name           = "wavecom",
168         .probe          = wavecom_probe,
169         .remove         = wavecom_remove,
170         .enable         = wavecom_enable,
171         .disable        = wavecom_disable,
172         .pre_sim        = wavecom_pre_sim,
173         .post_sim       = wavecom_post_sim,
174 };
175
176 static int wavecom_init(void)
177 {
178         return ofono_modem_driver_register(&wavecom_driver);
179 }
180
181 static void wavecom_exit(void)
182 {
183         ofono_modem_driver_unregister(&wavecom_driver);
184 }
185
186 OFONO_PLUGIN_DEFINE(wavecom, "Wavecom driver", VERSION,
187                 OFONO_PLUGIN_PRIORITY_DEFAULT, wavecom_init, wavecom_exit)