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