4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hayoon Ko <hayoon.ko@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <sys/utsname.h>
29 #include <core_object.h>
34 #include "imc_network.h"
35 #include "imc_modem.h"
43 #include "imc_phonebook.h"
46 static void on_confirmation_modem_message_send(TcorePending *p,
50 dbg("msg out from queue");
52 dbg("%s", result == FALSE ? "SEND FAIL" : "SEND OK");
55 static void on_response_bootup_subscription(TcorePending *p,
56 int data_len, const void *data, void *user_data)
58 const TcoreATResponse *resp = data;
61 if (resp->success > 0)
64 err("RESULT - ERROR");
67 static void on_response_last_bootup_subscription(TcorePending *p,
68 int data_len, const void *data, void *user_data)
70 const TcoreATResponse *resp = data;
71 TcorePlugin *plugin = tcore_pending_ref_plugin(p);
73 dbg("Last Subscription - COMPLETED");
80 dbg("Boot-up configration completed for IMC modem. %s",
81 "Bring CP to ONLINE state based on Flightmode status");
84 ret = modem_power_on(plugin);
85 dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
87 /* NVM Registration */
88 dbg("Registering modem for NVM manager");
89 modem_register_nvm(tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM));
92 static void _modem_subscribe_events(TcorePlugin *plugin)
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);
104 /* URC Subscriptions per Module */
106 /****** SIM subscriptions ******/
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);
112 /****** CALL subscriptions ******/
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);
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);
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);
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);
133 /****** NETWORK subscriptions ******/
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);
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);
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);
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);
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);
159 /****** PS subscriptions ******/
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);
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);
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);
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);
181 /****** SMS subscriptions ******/
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);
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);
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);
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);
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);
207 /****** SAP subscriptions ******/
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);
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,
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,
246 static gboolean on_load()
253 static gboolean on_init(TcorePlugin *p)
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");
266 /* Subscribe for the Events from CP */
267 _modem_subscribe_events(p);
269 dbg("Init - Successful");
273 static void on_unload(TcorePlugin *p)
280 /* Deinitialize Modules (Core Objects) */
281 tcore_object_deinit_objects(p, &deinit_table);
284 /* IMC - Modem Plug-in Descriptor */
285 struct tcore_plugin_define_desc plugin_define_desc = {
287 .priority = TCORE_PLUGIN_PRIORITY_MID,