Fix and place modem plugin in modems folder
[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 <plugin.h>
28 #include <core_object.h>
29 #include <hal.h>
30 #include <at.h>
31
32 #include "s_network.h"
33 #include "s_modem.h"
34 #include "s_sim.h"
35 #include "s_sap.h"
36 #include "s_ps.h"
37 #include "s_call.h"
38 #include "s_ss.h"
39 #include "s_sms.h"
40 #include "s_sat.h"
41 #include "s_phonebook.h"
42 #include "s_gps.h"
43
44 static gboolean on_load()
45 {
46         dbg("i'm load!");
47
48         return TRUE;
49 }
50
51 static void on_confirmation_modem_message_send(TcorePending *p,
52                                                 gboolean result,
53                                                 void *user_data)
54 {
55         dbg("msg out from queue");
56
57         dbg("%s", result == FALSE ? "SEND FAIL" : "SEND OK");
58 }
59
60 static void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data)
61 {
62         TcorePlugin *plugin = user_data;
63         const TcoreATResponse *resp = data;
64
65         dbg("Entry");
66
67         if (resp->success > 0) {
68                 dbg("result OK");
69         } else {
70                 dbg("result ERROR");
71         }
72
73         if (plugin != NULL)
74                 modem_power_on(plugin);
75 }
76
77 static void modem_subscribe_events(TcorePlugin *plugin)
78 {
79         CoreObject *co_call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
80         CoreObject *co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
81         CoreObject *co_sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
82         CoreObject *co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
83         CoreObject *co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
84         CoreObject *co_ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
85         CoreObject *co_sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
86         CoreObject *co_gps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_GPS);
87
88         dbg("Entry");
89
90         /* XCALLSTAT subscription */
91         tcore_prepare_and_send_at_request(co_call, "at+xcallstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
92                                                 on_response_bootup_subscription, NULL,
93                                                 on_confirmation_modem_message_send, NULL);
94
95         /* XSIMSTATE subscription */
96         tcore_prepare_and_send_at_request(co_sim, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
97                                                 on_response_bootup_subscription, NULL,
98                                                 on_confirmation_modem_message_send, NULL);
99
100         tcore_prepare_and_send_at_request(co_sms, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
101                                                 on_response_bootup_subscription, NULL,
102                                                 on_confirmation_modem_message_send, NULL);
103         tcore_prepare_and_send_at_request(co_modem, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
104                                                 on_response_bootup_subscription, NULL,
105                                                 on_confirmation_modem_message_send, NULL);
106
107         /* CREG subscription */
108         tcore_prepare_and_send_at_request(co_network, "at+creg=2", NULL, TCORE_AT_NO_RESULT, NULL,
109                                                 on_response_bootup_subscription, NULL,
110                                                 on_confirmation_modem_message_send, NULL);
111
112         /* CGREG subscription */
113         tcore_prepare_and_send_at_request(co_network, "at+cgreg=2", NULL, TCORE_AT_NO_RESULT, NULL,
114                                                 on_response_bootup_subscription, NULL,
115                                                 on_confirmation_modem_message_send, NULL);
116
117         /* Allow automatic time Zone updation via NITZ */
118         tcore_prepare_and_send_at_request(co_network, "at+ctzu=1", NULL, TCORE_AT_NO_RESULT, NULL,
119                                                 on_response_bootup_subscription, NULL,
120                                                 on_confirmation_modem_message_send, NULL);
121
122         /* TZ, time & daylight changing event reporting subscription */
123         tcore_prepare_and_send_at_request(co_network, "at+ctzr=1", NULL, TCORE_AT_NO_RESULT, NULL,
124                                                 on_response_bootup_subscription, NULL,
125                                                 on_confirmation_modem_message_send, NULL);
126
127         /* XMER subscription */
128         tcore_prepare_and_send_at_request(co_network, "at+xmer=1", NULL, TCORE_AT_NO_RESULT, NULL,
129                                                 on_response_bootup_subscription, NULL,
130                                                 on_confirmation_modem_message_send, NULL);
131
132         /* CGEREP subscription */
133         tcore_prepare_and_send_at_request(co_ps, "at+cgerep=1", NULL, TCORE_AT_NO_RESULT, NULL,
134                                                 on_response_bootup_subscription, NULL,
135                                                 on_confirmation_modem_message_send, NULL);
136
137         /* XDATASTAT subscription */
138         tcore_prepare_and_send_at_request(co_ps, "at+xdatastat=1", NULL, TCORE_AT_NO_RESULT, NULL,
139                                                 on_response_bootup_subscription, NULL,
140                                                 on_confirmation_modem_message_send, NULL);
141
142         /* CSSN subscription */
143         tcore_prepare_and_send_at_request(co_call, "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
144                                                 on_response_bootup_subscription, NULL,
145                                                 on_confirmation_modem_message_send, NULL);
146
147         /* CUSD subscription */
148         tcore_prepare_and_send_at_request(co_call, "at+cusd=1", NULL, TCORE_AT_NO_RESULT, NULL,
149                                                 on_response_bootup_subscription, NULL,
150                                                 on_confirmation_modem_message_send, NULL);
151
152         /* XDNS subscription */
153         tcore_prepare_and_send_at_request(co_ps, "at+xdns=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
154                                                 on_response_bootup_subscription, NULL,
155                                                 on_confirmation_modem_message_send, NULL);
156
157         /* CLIP subscription */
158         tcore_prepare_and_send_at_request(co_call, "at+clip=1", NULL, TCORE_AT_NO_RESULT, NULL,
159                                                 on_response_bootup_subscription, NULL,
160                                                 on_confirmation_modem_message_send, NULL);
161
162         /*CMEE subscription for ps*/
163         tcore_prepare_and_send_at_request(co_ps, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
164                                                 on_response_bootup_subscription, NULL,
165                                                 on_confirmation_modem_message_send, NULL);
166
167         /*CMEE subscription for sms*/
168         tcore_prepare_and_send_at_request(co_sms, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
169                                                 on_response_bootup_subscription, NULL,
170                                                 on_confirmation_modem_message_send, NULL);
171
172         /*incoming sms,cb,status report subscription*/
173         tcore_prepare_and_send_at_request(co_sms, "at+cnmi=1,2,2,1,0", NULL, TCORE_AT_NO_RESULT, NULL,
174                                                 on_response_bootup_subscription, NULL,
175                                                 on_confirmation_modem_message_send, NULL);
176
177         /* XBCSTAT subscription */
178         tcore_prepare_and_send_at_request(co_sap, "at+xbcstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
179                                                 on_response_bootup_subscription, NULL, 
180                                                 on_confirmation_modem_message_send, NULL);
181         /* AGPS- assist data and reset assist data subscription */
182         tcore_prepare_and_send_at_request(co_gps, "at+cposr=1", NULL, TCORE_AT_NO_RESULT, NULL,
183                                                 on_response_bootup_subscription, NULL,
184                                                 on_confirmation_modem_message_send, NULL);
185
186         tcore_prepare_and_send_at_request(co_gps, "at+xcposr=1", NULL, TCORE_AT_NO_RESULT, NULL,
187                                                 on_response_bootup_subscription, NULL,
188                                                 on_confirmation_modem_message_send, NULL);
189
190         /* text/pdu mode subscription*/
191         tcore_prepare_and_send_at_request(co_sms, "at+cmgf=0", NULL, TCORE_AT_NO_RESULT, NULL,
192                                                 on_response_bootup_subscription, plugin,
193                                                 on_confirmation_modem_message_send, NULL);
194
195         dbg("Exit");
196 }
197
198 struct object_initializer init_table = {
199         .modem_init = s_modem_init,
200         .sim_init = s_sim_init,
201         .sat_init = s_sat_init,
202         .sap_init = s_sap_init,
203         .network_init = s_network_init,
204         .ps_init = s_ps_init,
205         .call_init = s_call_init,
206         .ss_init = s_ss_init,
207         .sms_init = s_sms_init,
208         .phonebook_init = s_phonebook_init,
209         .gps_init = s_gps_init,
210 };
211
212 struct object_deinitializer deinit_table = {
213         .modem_deinit = s_modem_exit,
214         .sim_deinit = s_sim_exit,
215         .sat_deinit = s_sat_exit,
216         .sap_deinit = s_sap_exit,
217         .network_deinit = s_network_exit,
218         .ps_deinit = s_ps_exit,
219         .call_deinit = s_call_exit,
220         .ss_deinit = s_ss_exit,
221         .sms_deinit = s_sms_exit,
222         .phonebook_deinit = s_phonebook_exit,
223         .gps_deinit = s_gps_exit,
224 };
225
226 static gboolean on_init(TcorePlugin *p)
227 {
228         if (!p)
229                 return FALSE;
230
231         if (tcore_object_init_objects(p, &init_table)
232                         != TCORE_RETURN_SUCCESS) {
233                 err("Failed to initialize Core Objects");
234                 return FALSE;
235         }
236
237         dbg("i'm init!");
238
239         modem_subscribe_events(p);
240
241         return TRUE;
242 }
243
244 static void on_unload(TcorePlugin *p)
245 {
246         if (!p)
247                 return;
248
249         tcore_object_deinit_objects(p, &deinit_table);
250
251         dbg("i'm unload");
252 }
253
254 struct tcore_plugin_define_desc plugin_define_desc = {
255         .name = "IMC",
256         .priority = TCORE_PLUGIN_PRIORITY_MID,
257         .version = 1,
258         .load = on_load,
259         .init = on_init,
260         .unload = on_unload
261 };