4 * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include <core_object.h>
32 #include "imc_modem.h"
36 #include "imc_network.h"
41 #include "imc_phonebook.h"
44 #include "imc_common.h"
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,
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,
76 static void __send_request(CoreObject *co, const gchar *at_cmd,
77 TcorePendingResponseCallback resp_cb, void *resp_cb_data)
79 (void)tcore_at_prepare_and_send_request(co, at_cmd, NULL,
80 TCORE_AT_COMMAND_TYPE_NO_RESULT,
82 resp_cb, resp_cb_data,
83 on_send_imc_request, NULL);
86 static void __on_response_subscribe_bootup_notification(TcorePending *p,
87 guint data_len, const void *data, void *user_data)
89 const TcoreAtResponse *at_resp = data;
92 if (at_resp && at_resp->success) {
93 dbg("Subscription for '%s' - [OK]", (gchar *)user_data);
95 err("Subscription for '%s' - [NOK]", (gchar *)user_data);
99 tcore_free(user_data);
102 static void __on_response_subscribe_bootup_notification_last(TcorePending *p,
103 guint data_len, const void *data, void *user_data)
105 const TcoreAtResponse *at_resp = data;
106 TcorePlugin *plugin = tcore_pending_ref_plugin(p);
109 if (at_resp && at_resp->success) {
110 dbg("[Last] Subscription for '%s' - [OK]", (gchar *)user_data);
112 err("[Last] Subscription for '%s' - [NOK]", (gchar *)user_data);
116 tcore_free(user_data);
118 dbg("Boot-up configration completed for IMC modem, "
119 "Bring CP to ONLINE state based on Flight mode status");
122 ret = imc_modem_power_on_modem(plugin);
123 dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
125 /* NVM Registration */
126 dbg("Registering modem for NVM manager");
127 imc_modem_register_nvm(tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM));
130 static void __subscribe_modem_notifications(TcorePlugin *plugin)
132 CoreObject *call, *sim, *sms, *network, *ps, *gps;
138 /****** SIM subscriptions ******/
139 sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
141 __send_request(sim, "AT+XSIMSTATE=1",
142 __on_response_subscribe_bootup_notification,
143 tcore_strdup("AT+XSIMSTATE=1"));
145 /****** CALL subscriptions ******/
146 call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
148 __send_request(call, "AT+XCALLSTAT=1",
149 __on_response_subscribe_bootup_notification,
150 tcore_strdup("AT+XCALLSTAT=1"));
153 __send_request(call, "AT+CSSN=1,1",
154 __on_response_subscribe_bootup_notification,
155 tcore_strdup("AT+CSSN=1,1"));
158 __send_request(call, "AT+CUSD=1",
159 __on_response_subscribe_bootup_notification,
160 tcore_strdup("AT+CUSD=1"));
163 __send_request(call, "AT+CLIP=1",
164 __on_response_subscribe_bootup_notification,
165 tcore_strdup("AT+CLIP=1"));
167 /****** NETWORK subscriptions ******/
168 network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
170 __send_request(network, "AT+CREG=2",
171 __on_response_subscribe_bootup_notification,
172 tcore_strdup("AT+CREG=2"));
175 __send_request(network, "AT+CGREG=2",
176 __on_response_subscribe_bootup_notification,
177 tcore_strdup("AT+CGREG=2"));
179 /* Allow Automatic Time Zone updation via NITZ */
180 __send_request(network, "AT+CTZU=1",
181 __on_response_subscribe_bootup_notification,
182 tcore_strdup("AT+CTZU=1"));
184 /* TZ, Time & Daylight changing event reporting Subscription */
185 __send_request(network, "AT+CTZR=1",
186 __on_response_subscribe_bootup_notification,
187 tcore_strdup("AT+CTZR=1"));
190 __send_request(network, "AT+XMER=1",
191 __on_response_subscribe_bootup_notification,
192 tcore_strdup("AT+XMER=1"));
194 /****** PS subscriptions ******/
195 ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
197 __send_request(ps, "AT+CGEREP=1",
198 __on_response_subscribe_bootup_notification,
199 tcore_strdup("AT+CGEREP=1"));
202 __send_request(ps, "AT+XDATASTAT=1",
203 __on_response_subscribe_bootup_notification,
204 tcore_strdup("AT+XDATASTAT=1"));
207 __send_request(ps, "AT+XDNS=1,1",
208 __on_response_subscribe_bootup_notification,
209 tcore_strdup("AT+XDNS=1,1"));
212 __send_request(ps, "AT+CMEE=2",
213 __on_response_subscribe_bootup_notification,
214 tcore_strdup("AT+CMEE=2"));
216 /****** SMS subscriptions ******/
217 sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
219 __send_request(sms, "AT+CMEE=2",
220 __on_response_subscribe_bootup_notification,
221 tcore_strdup("AT+CMEE=2"));
223 /* Incoming SMS, Cell Broadcast, Status Report Subscription */
224 __send_request(sms, "AT+CNMI=1,2,2,1,0",
225 __on_response_subscribe_bootup_notification,
226 tcore_strdup("AT+CNMI=1,2,2,1,0"));
228 /* Text/PDU mode Subscription */
229 __send_request(sms, "AT+CMGF=0",
230 __on_response_subscribe_bootup_notification,
231 tcore_strdup("AT+CMGF=0"));
233 #if 0 /* Temporarily Blocking as modem doesn't support */
234 /****** SAP subscriptions ******/
235 sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
237 __send_request(sap, "AT+XBCSTAT=1",
238 __on_response_subscribe_bootup_notification,
239 tcore_strdup("AT+XBCSTAT=1"));
240 #endif /* Temporarily Blocking as modem doesn't support */
242 /****** GPS subscriptions ******/
243 gps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_GPS);
244 /* AGPS- Assist Data and Reset Assist Data Subscription */
245 __send_request(gps, "AT+CPOSR=1",
246 __on_response_subscribe_bootup_notification,
247 tcore_strdup("AT+CPOSR=1"));
249 __send_request(gps, "AT+XCPOSR=1",
250 __on_response_subscribe_bootup_notification_last,
251 tcore_strdup("AT+XCPOSR=1"));
256 static gboolean on_load()
263 static gboolean on_init(TcorePlugin *p)
266 tcore_check_return_value(p != NULL, FALSE);
268 /* Initialize Modules (Core Objects) */
269 if (tcore_object_init_objects(p, &imc_init_table)
270 != TEL_RETURN_SUCCESS) {
271 err("Failed to initialize Core Objects");
275 /* Subscribe for the Events from CP */
276 __subscribe_modem_notifications(p);
278 dbg("Init - Successful");
282 static void on_unload(TcorePlugin *p)
285 tcore_check_return(p != NULL);
287 /* Deinitialize Modules (Core Objects) */
288 tcore_object_deinit_objects(p, &imc_deinit_table);
291 /* IMC - Modem Plug-in Descriptor */
292 struct tcore_plugin_define_desc plugin_define_desc = {
294 .priority = TCORE_PLUGIN_PRIORITY_MID,