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