Updated as per tcore_at_prepare_and_send_request() API change
[platform/core/telephony/tel-plugin-imc.git] / src / desc-imc.c
1 /*
2  * tel-plugin-imc
3  *
4  * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <glib.h>
24
25 #include <tcore.h>
26 #include <server.h>
27 #include <plugin.h>
28 #include <core_object.h>
29 #include <hal.h>
30 #include <at.h>
31
32 #include "imc_modem.h"
33 #include "imc_sim.h"
34 #include "imc_sat.h"
35 #include "imc_sap.h"
36 #include "imc_network.h"
37 #include "imc_ps.h"
38 #include "imc_call.h"
39 #include "imc_ss.h"
40 #include "imc_sms.h"
41 #include "imc_phonebook.h"
42 #include "imc_gps.h"
43
44 #include "imc_common.h"
45
46 /* Initializer Table */
47 TcoreObjectInitializer imc_init_table = {
48         .modem_init = imc_modem_init,
49         .sim_init = imc_sim_init,
50         .sat_init = imc_sat_init,
51         .sap_init = imc_sap_init,
52         .network_init = imc_network_init,
53         .ps_init = imc_ps_init,
54         .call_init = imc_call_init,
55         .ss_init = imc_ss_init,
56         .sms_init = imc_sms_init,
57         .phonebook_init = imc_phonebook_init,
58         .gps_init = imc_gps_init,
59 };
60
61 /* Deinitializer Table */
62 TcoreObjectDeinitializer imc_deinit_table = {
63         .modem_deinit = imc_modem_exit,
64         .sim_deinit = imc_sim_exit,
65         .sat_deinit = imc_sat_exit,
66         .sap_deinit = imc_sap_exit,
67         .network_deinit = imc_network_exit,
68         .ps_deinit = imc_ps_exit,
69         .call_deinit = imc_call_exit,
70         .ss_deinit = imc_ss_exit,
71         .sms_deinit = imc_sms_exit,
72         .phonebook_deinit = imc_phonebook_exit,
73         .gps_deinit = imc_gps_exit,
74 };
75
76 static void __send_request(CoreObject *co, const gchar *at_cmd,
77         TcorePendingResponseCallback resp_cb, void *resp_cb_data)
78 {
79         (void)tcore_at_prepare_and_send_request(co, at_cmd, NULL,
80                 TCORE_AT_COMMAND_TYPE_NO_RESULT,
81                 NULL,
82                 resp_cb, resp_cb_data,
83                 on_send_imc_request, NULL);
84 }
85
86 static void __on_response_subscribe_bootup_notification(TcorePending *p,
87         guint data_len, const void *data, void *user_data)
88 {
89         const TcoreAtResponse *at_resp = data;
90         dbg("Entry");
91
92         if (at_resp && at_resp->success) {
93                 dbg("Subscription for '%s' - [OK]", (gchar *)user_data);
94         } else {
95                 err("Subscription for '%s' - [NOK]", (gchar *)user_data);
96         }
97
98         /* Free resource */
99         tcore_free(user_data);
100 }
101
102 static void __on_response_subscribe_bootup_notification_last(TcorePending *p,
103         guint data_len, const void *data, void *user_data)
104 {
105         const TcoreAtResponse *at_resp = data;
106         TcorePlugin *plugin = tcore_pending_ref_plugin(p);
107         gboolean ret;
108
109         if (at_resp && at_resp->success) {
110                 dbg("[Last] Subscription for '%s' - [OK]", (gchar *)user_data);
111         } else {
112                 err("[Last] Subscription for '%s' - [NOK]", (gchar *)user_data);
113         }
114
115         /* Free resource */
116         tcore_free(user_data);
117
118         dbg("Boot-up configration completed for IMC modem, "
119                 "Bring CP to ONLINE state based on Flight mode status");
120
121         /* Modem Power */
122         ret = imc_modem_power_on_modem(plugin);
123         dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
124
125         /* NVM Registration */
126         dbg("Registering modem for NVM manager");
127         imc_modem_register_nvm(tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM));
128 }
129
130 static void __subscribe_modem_notifications(TcorePlugin *plugin)
131 {
132         CoreObject *call, *sim, *sms, *network, *ps, *gps;
133         dbg("Entry");
134
135         /*
136          * URC Subscriptions
137          */
138         /****** SIM subscriptions ******/
139         sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
140         /* XSIMSTATE  */
141         __send_request(sim, "AT+XSIMSTATE=1",
142                 __on_response_subscribe_bootup_notification,
143                 tcore_strdup("AT+XSIMSTATE=1"));
144
145         /****** CALL subscriptions ******/
146         call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
147         /* XCALLSTAT */
148         __send_request(call, "AT+XCALLSTAT=1",
149                 __on_response_subscribe_bootup_notification,
150                 tcore_strdup("AT+XCALLSTAT=1"));
151
152         /* CSSN */
153         __send_request(call, "AT+CSSN=1,1",
154                 __on_response_subscribe_bootup_notification,
155                 tcore_strdup("AT+CSSN=1,1"));
156
157         /* CUSD */
158         __send_request(call, "AT+CUSD=1",
159                 __on_response_subscribe_bootup_notification,
160                 tcore_strdup("AT+CUSD=1"));
161
162         /* CLIP */
163         __send_request(call, "AT+CLIP=1",
164                 __on_response_subscribe_bootup_notification,
165                 tcore_strdup("AT+CLIP=1"));
166
167         /****** NETWORK subscriptions ******/
168         network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
169         /* CREG */
170         __send_request(network, "AT+CREG=2",
171                 __on_response_subscribe_bootup_notification,
172                 tcore_strdup("AT+CREG=2"));
173
174         /* CGREG */
175         __send_request(network, "AT+CGREG=2",
176                 __on_response_subscribe_bootup_notification,
177                 tcore_strdup("AT+CGREG=2"));
178
179         /* Allow Automatic Time Zone updation via NITZ */
180         __send_request(network, "AT+CTZU=1",
181                 __on_response_subscribe_bootup_notification,
182                 tcore_strdup("AT+CTZU=1"));
183
184         /* TZ, Time & Daylight changing event reporting Subscription */
185         __send_request(network, "AT+CTZR=1",
186                 __on_response_subscribe_bootup_notification,
187                 tcore_strdup("AT+CTZR=1"));
188
189         /* XMER */
190         __send_request(network, "AT+XMER=1",
191                 __on_response_subscribe_bootup_notification,
192                 tcore_strdup("AT+XMER=1"));
193
194         /****** PS subscriptions ******/
195         ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
196         /* CGEREP */
197         __send_request(ps, "AT+CGEREP=1",
198                 __on_response_subscribe_bootup_notification,
199                 tcore_strdup("AT+CGEREP=1"));
200
201         /* XDATASTAT */
202         __send_request(ps, "AT+XDATASTAT=1",
203                 __on_response_subscribe_bootup_notification,
204                 tcore_strdup("AT+XDATASTAT=1"));
205
206         /* XDNS */
207         __send_request(ps, "AT+XDNS=1,1",
208                 __on_response_subscribe_bootup_notification,
209                 tcore_strdup("AT+XDNS=1,1"));
210
211         /* CMEE */
212         __send_request(ps, "AT+CMEE=2",
213                 __on_response_subscribe_bootup_notification,
214                 tcore_strdup("AT+CMEE=2"));
215
216         /****** SMS subscriptions ******/
217         sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
218         /* CMEE */
219         __send_request(sms, "AT+CMEE=2",
220                 __on_response_subscribe_bootup_notification,
221                 tcore_strdup("AT+CMEE=2"));
222
223         /* Incoming SMS, Cell Broadcast, Status Report Subscription */
224         __send_request(sms, "AT+CNMI=1,2,2,1,0",
225                 __on_response_subscribe_bootup_notification,
226                 tcore_strdup("AT+CNMI=1,2,2,1,0"));
227
228         /* Text/PDU mode Subscription */
229         __send_request(sms, "AT+CMGF=0",
230                 __on_response_subscribe_bootup_notification,
231                 tcore_strdup("AT+CMGF=0"));
232
233 #if 0   /* Temporarily Blocking as modem doesn't support */
234         /****** SAP subscriptions ******/
235         sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
236         /* XBCSTAT */
237         __send_request(sap, "AT+XBCSTAT=1",
238                 __on_response_subscribe_bootup_notification,
239                 tcore_strdup("AT+XBCSTAT=1"));
240 #endif  /* Temporarily Blocking as modem doesn't support */
241
242         /****** GPS subscriptions ******/
243         gps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_GPS);
244         /* AGPS- Assist Data and Reset Assist Data Subscription */
245         __send_request(gps, "AT+CPOSR=1",
246                 __on_response_subscribe_bootup_notification,
247                 tcore_strdup("AT+CPOSR=1"));
248
249         __send_request(gps, "AT+XCPOSR=1",
250                 __on_response_subscribe_bootup_notification_last,
251                 tcore_strdup("AT+XCPOSR=1"));
252
253         dbg("Exit");
254 }
255
256 static gboolean on_load()
257 {
258         dbg("Load!!!");
259
260         return TRUE;
261 }
262
263 static gboolean on_init(TcorePlugin *p)
264 {
265         dbg("Init!!!");
266         tcore_check_return_value(p != NULL, FALSE);
267
268         /* Initialize Modules (Core Objects) */
269         if (tcore_object_init_objects(p, &imc_init_table)
270                         != TEL_RETURN_SUCCESS) {
271                 err("Failed to initialize Core Objects");
272                 return FALSE;
273         }
274
275         /* Subscribe for the Events from CP */
276         __subscribe_modem_notifications(p);
277
278         dbg("Init - Successful");
279         return TRUE;
280 }
281
282 static void on_unload(TcorePlugin *p)
283 {
284         dbg("Unload!!!");
285         tcore_check_return(p != NULL);
286
287         /* Deinitialize Modules (Core Objects) */
288         tcore_object_deinit_objects(p, &imc_deinit_table);
289 }
290
291 /* IMC - Modem Plug-in Descriptor */
292 struct tcore_plugin_define_desc plugin_define_desc = {
293         .name = "imc",
294         .priority = TCORE_PLUGIN_PRIORITY_MID,
295         .version = 1,
296         .load = on_load,
297         .init = on_init,
298         .unload = on_unload
299 };