fix SPN display issue
[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                 TCORE_PENDING_PRIORITY_DEFAULT,
82                 NULL,
83                 resp_cb, resp_cb_data,
84                 on_send_imc_request, NULL,
85                 0, NULL, NULL);
86 }
87
88 static void __on_response_subscribe_bootup_notification(TcorePending *p,
89         guint data_len, const void *data, void *user_data)
90 {
91         const TcoreAtResponse *at_resp = data;
92         dbg("Entry");
93
94         if (at_resp && at_resp->success) {
95                 dbg("Subscription for '%s' - [OK]", (gchar *)user_data);
96         } else {
97                 err("Subscription for '%s' - [NOK]", (gchar *)user_data);
98         }
99
100         /* Free resource */
101         tcore_free(user_data);
102 }
103
104 static void __on_response_subscribe_bootup_notification_last(TcorePending *p,
105         guint data_len, const void *data, void *user_data)
106 {
107         const TcoreAtResponse *at_resp = data;
108         TcorePlugin *plugin = tcore_pending_ref_plugin(p);
109         gboolean ret;
110
111         if (at_resp && at_resp->success) {
112                 dbg("[Last] Subscription for '%s' - [OK]", (gchar *)user_data);
113         } else {
114                 err("[Last] Subscription for '%s' - [NOK]", (gchar *)user_data);
115         }
116
117         /* Free resource */
118         tcore_free(user_data);
119
120         dbg("Boot-up configration completed for IMC modem, "
121                 "Bring CP to ONLINE state based on Flight mode status");
122
123         /* Modem Power */
124         ret = imc_modem_power_on_modem(plugin);
125         dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
126
127         /* NVM Registration */
128         dbg("Registering modem for NVM manager");
129         imc_modem_register_nvm(tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM));
130 }
131
132 static void __subscribe_modem_notifications(TcorePlugin *plugin)
133 {
134         CoreObject *call, *sim, *sms, *network, *ps, *gps;
135         dbg("Entry");
136
137         /*
138          * URC Subscriptions
139          */
140         /****** SIM subscriptions ******/
141         sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
142         /* XSIMSTATE  */
143         __send_request(sim, "AT+XSIMSTATE=1",
144                 __on_response_subscribe_bootup_notification,
145                 tcore_strdup("AT+XSIMSTATE=1"));
146
147         /****** CALL subscriptions ******/
148         call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
149         /* XCALLSTAT */
150         __send_request(call, "AT+XCALLSTAT=1",
151                 __on_response_subscribe_bootup_notification,
152                 tcore_strdup("AT+XCALLSTAT=1"));
153
154         /* CSSN */
155         __send_request(call, "AT+CSSN=1,1",
156                 __on_response_subscribe_bootup_notification,
157                 tcore_strdup("AT+CSSN=1,1"));
158
159         /* CUSD */
160         __send_request(call, "AT+CUSD=1",
161                 __on_response_subscribe_bootup_notification,
162                 tcore_strdup("AT+CUSD=1"));
163
164         /* CLIP */
165         __send_request(call, "AT+CLIP=1",
166                 __on_response_subscribe_bootup_notification,
167                 tcore_strdup("AT+CLIP=1"));
168
169         /****** NETWORK subscriptions ******/
170         network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
171         /* CREG */
172         __send_request(network, "AT+CREG=2",
173                 __on_response_subscribe_bootup_notification,
174                 tcore_strdup("AT+CREG=2"));
175
176         /* CGREG */
177         __send_request(network, "AT+CGREG=2",
178                 __on_response_subscribe_bootup_notification,
179                 tcore_strdup("AT+CGREG=2"));
180
181         /* Allow Automatic Time Zone updation via NITZ */
182         __send_request(network, "AT+CTZU=1",
183                 __on_response_subscribe_bootup_notification,
184                 tcore_strdup("AT+CTZU=1"));
185
186         /* TZ, Time & Daylight changing event reporting Subscription */
187         __send_request(network, "AT+CTZR=1",
188                 __on_response_subscribe_bootup_notification,
189                 tcore_strdup("AT+CTZR=1"));
190
191         /* XMER */
192         __send_request(network, "AT+XMER=1",
193                 __on_response_subscribe_bootup_notification,
194                 tcore_strdup("AT+XMER=1"));
195
196         /****** PS subscriptions ******/
197         ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
198         /* CGEREP */
199         __send_request(ps, "AT+CGEREP=1",
200                 __on_response_subscribe_bootup_notification,
201                 tcore_strdup("AT+CGEREP=1"));
202
203         /* XDATASTAT */
204         __send_request(ps, "AT+XDATASTAT=1",
205                 __on_response_subscribe_bootup_notification,
206                 tcore_strdup("AT+XDATASTAT=1"));
207
208         /* XDNS */
209         __send_request(ps, "AT+XDNS=1,1",
210                 __on_response_subscribe_bootup_notification,
211                 tcore_strdup("AT+XDNS=1,1"));
212
213         /* CMEE */
214         __send_request(ps, "AT+CMEE=2",
215                 __on_response_subscribe_bootup_notification,
216                 tcore_strdup("AT+CMEE=2"));
217
218         /****** SMS subscriptions ******/
219         sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
220         /* CMEE */
221         __send_request(sms, "AT+CMEE=2",
222                 __on_response_subscribe_bootup_notification,
223                 tcore_strdup("AT+CMEE=2"));
224
225         /* Incoming SMS, Cell Broadcast, Status Report Subscription */
226         __send_request(sms, "AT+CNMI=1,2,2,1,0",
227                 __on_response_subscribe_bootup_notification,
228                 tcore_strdup("AT+CNMI=1,2,2,1,0"));
229
230         /* Text/PDU mode Subscription */
231         __send_request(sms, "AT+CMGF=0",
232                 __on_response_subscribe_bootup_notification,
233                 tcore_strdup("AT+CMGF=0"));
234
235 #if 0   /* Temporarily Blocking as modem doesn't support */
236         /****** SAP subscriptions ******/
237         sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
238         /* XBCSTAT */
239         __send_request(sap, "AT+XBCSTAT=1",
240                 __on_response_subscribe_bootup_notification,
241                 tcore_strdup("AT+XBCSTAT=1"));
242 #endif  /* Temporarily Blocking as modem doesn't support */
243
244         /****** GPS subscriptions ******/
245         gps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_GPS);
246         /* AGPS- Assist Data and Reset Assist Data Subscription */
247         __send_request(gps, "AT+CPOSR=1",
248                 __on_response_subscribe_bootup_notification,
249                 tcore_strdup("AT+CPOSR=1"));
250
251         __send_request(gps, "AT+XCPOSR=1",
252                 __on_response_subscribe_bootup_notification_last,
253                 tcore_strdup("AT+XCPOSR=1"));
254
255         dbg("Exit");
256 }
257
258 static gboolean on_load()
259 {
260         dbg("Load!!!");
261
262         return TRUE;
263 }
264
265 static gboolean on_init(TcorePlugin *p)
266 {
267         dbg("Init!!!");
268         tcore_check_return_value(p != NULL, FALSE);
269
270         /* Initialize Modules (Core Objects) */
271         if (tcore_object_init_objects(p, &imc_init_table)
272                         != TEL_RETURN_SUCCESS) {
273                 err("Failed to initialize Core Objects");
274                 return FALSE;
275         }
276
277         /* Subscribe for the Events from CP */
278         __subscribe_modem_notifications(p);
279
280         dbg("Init - Successful");
281         return TRUE;
282 }
283
284 static void on_unload(TcorePlugin *p)
285 {
286         dbg("Unload!!!");
287         tcore_check_return(p != NULL);
288
289         /* Deinitialize Modules (Core Objects) */
290         tcore_object_deinit_objects(p, &imc_deinit_table);
291 }
292
293 /* IMC - Modem Plug-in Descriptor */
294 struct tcore_plugin_define_desc plugin_define_desc = {
295         .name = "imc",
296         .priority = TCORE_PLUGIN_PRIORITY_MID,
297         .version = 1,
298         .load = on_load,
299         .init = on_init,
300         .unload = on_unload
301 };