Implement to request for SIM authentication
[platform/core/telephony/tel-plugin-imc.git] / src / desc.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 "s_network.h"
35 #include "s_modem.h"
36 #include "s_sim.h"
37 #include "s_sap.h"
38 #include "s_ps.h"
39 #include "s_call.h"
40 #include "s_ss.h"
41 #include "s_sms.h"
42 #include "s_sat.h"
43 #include "s_phonebook.h"
44 #include "s_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
68 static void on_response_last_bootup_subscription(TcorePending *p,
69                                                         int data_len, const void *data, void *user_data)
70 {
71         const TcoreATResponse *resp = data;
72         TcorePlugin *plugin = tcore_pending_ref_plugin(p);
73         gboolean ret;
74         dbg("Last Subscription - COMPLETED");
75
76         if (resp->success) {
77                 dbg("RESULT - OK");
78         } else {
79                 err("RESULT - FAIL");
80         }
81
82         dbg("Boot-up configration completed for IMC modem. %s",
83                                 "Bring CP to ONLINE state based on Flightmode status");
84
85         /* Modem Power */
86         ret = modem_power_on(plugin);
87         dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
88
89         /* NVM Registration */
90         dbg("Registering modem for NVM manager");
91         modem_register_nvm(tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM));
92 }
93
94 static void _modem_subscribe_events(TcorePlugin *plugin)
95 {
96         CoreObject *co_call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
97         CoreObject *co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
98         CoreObject *co_sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
99         CoreObject *co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
100         CoreObject *co_ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
101         CoreObject *co_sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
102         CoreObject *co_gps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_GPS);
103
104         dbg("Entry");
105
106         /* URC Subscriptions per Module */
107
108         /****** SIM subscriptions ******/
109         /* XSIMSTATE  */
110         tcore_prepare_and_send_at_request(co_sim, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
111                                                 on_response_bootup_subscription, NULL,
112                                                 on_confirmation_modem_message_send, NULL);
113
114         /****** CALL subscriptions ******/
115         /* XCALLSTAT */
116         tcore_prepare_and_send_at_request(co_call, "at+xcallstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
117                                                 on_response_bootup_subscription, NULL,
118                                                 on_confirmation_modem_message_send, NULL);
119
120         /* CSSN */
121         tcore_prepare_and_send_at_request(co_call, "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
122                                                 on_response_bootup_subscription, NULL,
123                                                 on_confirmation_modem_message_send, NULL);
124
125         /* CUSD */
126         tcore_prepare_and_send_at_request(co_call, "at+cusd=1", NULL, TCORE_AT_NO_RESULT, NULL,
127                                                 on_response_bootup_subscription, NULL,
128                                                 on_confirmation_modem_message_send, NULL);
129
130         /* CLIP */
131         tcore_prepare_and_send_at_request(co_call, "at+clip=1", NULL, TCORE_AT_NO_RESULT, NULL,
132                                                 on_response_bootup_subscription, NULL,
133                                                 on_confirmation_modem_message_send, NULL);
134
135         /****** NETWORK subscriptions ******/
136         /* CREG */
137         tcore_prepare_and_send_at_request(co_network, "at+creg=2", NULL, TCORE_AT_NO_RESULT, NULL,
138                                                 on_response_bootup_subscription, NULL,
139                                                 on_confirmation_modem_message_send, NULL);
140
141         /* CGREG */
142         tcore_prepare_and_send_at_request(co_network, "at+cgreg=2", NULL, TCORE_AT_NO_RESULT, NULL,
143                                                 on_response_bootup_subscription, NULL,
144                                                 on_confirmation_modem_message_send, NULL);
145
146         /* Allow Automatic Time Zone updation via NITZ */
147         tcore_prepare_and_send_at_request(co_network, "at+ctzu=1", NULL, TCORE_AT_NO_RESULT, NULL,
148                                                 on_response_bootup_subscription, NULL,
149                                                 on_confirmation_modem_message_send, NULL);
150
151         /* TZ, Time & Daylight changing event reporting Subscription */
152         tcore_prepare_and_send_at_request(co_network, "at+ctzr=1", NULL, TCORE_AT_NO_RESULT, NULL,
153                                                 on_response_bootup_subscription, NULL,
154                                                 on_confirmation_modem_message_send, NULL);
155
156         /* XMER */
157         tcore_prepare_and_send_at_request(co_network, "at+xmer=1", NULL, TCORE_AT_NO_RESULT, NULL,
158                                                 on_response_bootup_subscription, NULL,
159                                                 on_confirmation_modem_message_send, NULL);
160
161         /****** PS subscriptions ******/
162         /* CGEREP */
163         tcore_prepare_and_send_at_request(co_ps, "at+cgerep=1", NULL, TCORE_AT_NO_RESULT, NULL,
164                                                 on_response_bootup_subscription, NULL,
165                                                 on_confirmation_modem_message_send, NULL);
166
167         /* XDATASTAT */
168         tcore_prepare_and_send_at_request(co_ps, "at+xdatastat=1", NULL, TCORE_AT_NO_RESULT, NULL,
169                                                 on_response_bootup_subscription, NULL,
170                                                 on_confirmation_modem_message_send, NULL);
171
172
173         /* XDNS */
174         tcore_prepare_and_send_at_request(co_ps, "at+xdns=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
175                                                 on_response_bootup_subscription, NULL,
176                                                 on_confirmation_modem_message_send, NULL);
177
178         /* CMEE */
179         tcore_prepare_and_send_at_request(co_ps, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
180                                                 on_response_bootup_subscription, NULL,
181                                                 on_confirmation_modem_message_send, NULL);
182
183         /****** SMS subscriptions ******/
184         /* CMEE */
185         tcore_prepare_and_send_at_request(co_sms, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
186                                                 on_response_bootup_subscription, NULL,
187                                                 on_confirmation_modem_message_send, NULL);
188
189         /* Incoming SMS, Cell Broadcast, Status Report Subscription */
190         tcore_prepare_and_send_at_request(co_sms, "at+cnmi=1,2,2,1,0", NULL, TCORE_AT_NO_RESULT, NULL,
191                                                 on_response_bootup_subscription, NULL,
192                                                 on_confirmation_modem_message_send, NULL);
193
194         /* Text/PDU mode Subscription */
195         tcore_prepare_and_send_at_request(co_sms, "at+cmgf=0", NULL, TCORE_AT_NO_RESULT, NULL,
196                                                 on_response_bootup_subscription, NULL,
197                                                 on_confirmation_modem_message_send, NULL);
198
199         /****** GPS subscriptions ******/
200         /* AGPS- Assist Data and Reset Assist Data Subscription */
201         tcore_prepare_and_send_at_request(co_gps, "at+cposr=1", NULL, TCORE_AT_NO_RESULT, NULL,
202                                                 on_response_bootup_subscription, NULL,
203                                                 on_confirmation_modem_message_send, NULL);
204
205         tcore_prepare_and_send_at_request(co_gps, "at+xcposr=1", NULL, TCORE_AT_NO_RESULT, NULL,
206                                                 on_response_bootup_subscription, NULL,
207                                                 on_confirmation_modem_message_send, NULL);
208
209         /****** SAP subscriptions ******/
210         /* XBCSTAT */
211         tcore_prepare_and_send_at_request(co_sap, "at+xbcstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
212                                                 on_response_last_bootup_subscription, NULL,
213                                                 on_confirmation_modem_message_send, NULL);
214
215         dbg("Exit");
216 }
217
218 /* Initializer Table */
219 struct object_initializer init_table = {
220         .modem_init = s_modem_init,
221         .sim_init = s_sim_init,
222         .sat_init = s_sat_init,
223         .sap_init = s_sap_init,
224         .network_init = s_network_init,
225         .ps_init = s_ps_init,
226         .call_init = s_call_init,
227         .ss_init = s_ss_init,
228         .sms_init = s_sms_init,
229         .phonebook_init = s_phonebook_init,
230         .gps_init = s_gps_init,
231 };
232
233 /* Deinitializer Table */
234 struct object_deinitializer deinit_table = {
235         .modem_deinit = s_modem_exit,
236         .sim_deinit = s_sim_exit,
237         .sat_deinit = s_sat_exit,
238         .sap_deinit = s_sap_exit,
239         .network_deinit = s_network_exit,
240         .ps_deinit = s_ps_exit,
241         .call_deinit = s_call_exit,
242         .ss_deinit = s_ss_exit,
243         .sms_deinit = s_sms_exit,
244         .phonebook_deinit = s_phonebook_exit,
245         .gps_deinit = s_gps_exit,
246 };
247
248 static gboolean on_load()
249 {
250         dbg("Load!!!");
251
252         return TRUE;
253 }
254
255 static gboolean on_init(TcorePlugin *p)
256 {
257         dbg("Init!!!");
258         if (p == NULL)
259                 return FALSE;
260
261         /* Initialize Modules (Core Objects) */
262         if (tcore_object_init_objects(p, &init_table)
263                         != TCORE_RETURN_SUCCESS) {
264                 err("Failed to initialize Core Objects");
265                 return FALSE;
266         }
267
268         /* Subscribe for the Events from CP */
269         _modem_subscribe_events(p);
270
271         dbg("Init - Successful");
272         return TRUE;
273 }
274
275 static void on_unload(TcorePlugin *p)
276 {
277         dbg("Unload!!!");
278
279         if (p == NULL)
280                 return;
281
282         /* Deinitialize Modules (Core Objects) */
283         tcore_object_deinit_objects(p, &deinit_table);
284 }
285
286 /* IMC - Modem Plug-in Descriptor */
287 struct tcore_plugin_define_desc plugin_define_desc = {
288         .name = "IMC",
289         .priority = TCORE_PLUGIN_PRIORITY_MID,
290         .version = 1,
291         .load = on_load,
292         .init = on_init,
293         .unload = on_unload
294 };