s_modem: Make "AT+CGMR" response parsing be compatible with the modem only return...
[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 <hal.h>
29 #include <server.h>
30 #include <at.h>
31 #include <core_object.h>
32
33 #include "s_common.h"
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 char *cp_name;
47 static int cp_count = 0;
48
49 #define MAX_CP_QUERY_COUNT 60
50
51 static gboolean _query_cp_state(gpointer data)
52 {
53         gboolean power_state = FALSE;
54         TcorePlugin *p = NULL;
55         CoreObject* obj = NULL;
56         TcoreHal* h = NULL;
57
58         p = (TcorePlugin *) data;
59
60         if (cp_count > MAX_CP_QUERY_COUNT) {
61                 dbg("cp query counter exceeds MAX_CP_QUERY_COUNT");
62                 return FALSE;
63         }
64         obj = tcore_plugin_ref_core_object(p, "modem");
65         h = tcore_object_get_hal(obj);
66         power_state = tcore_hal_get_power_state(h);
67
68         if (TRUE == power_state) {
69                 dbg("CP READY");
70                 s_modem_send_poweron(p);
71                 return FALSE;
72         } else {
73                 dbg("CP NOT READY, cp_count :%d", cp_count);
74                 cp_count++;
75                 return TRUE;
76         }
77 }
78
79 static enum tcore_hook_return on_hal_send(TcoreHal *hal, unsigned int data_len, void *data, void *user_data)
80 {
81         hook_hex_dump(TX, data_len, data);
82         return TCORE_HOOK_RETURN_CONTINUE;
83 }
84
85 static void on_hal_recv(TcoreHal *hal, unsigned int data_len, const void *data, void *user_data)
86 {
87         msg("=== RX data DUMP =====");
88         util_hex_dump("          ", data_len, data);
89         msg("=== RX data DUMP =====");
90 }
91
92 static gboolean on_load()
93 {
94         dbg("i'm load!");
95
96         return TRUE;
97 }
98
99 static int _get_cp_name(char **name)
100 {
101         struct utsname u;
102
103         char *svnet1_models[] = {
104                 "F1", "S1", "M2", "H2", "H2_SDK",
105                 "CRESPO", "STEALTHV", "SLP45", "Kessler", "P1P2",
106                 "U1SLP", "U1HD", "SLP7_C210", "SLP10_C210", NULL
107         };
108
109         char *svnet2_models[] = { "SMDK4410", "SMDK4212", "TRATS2", "SLP_PQ_LTE", "SLP_NAPLES", "REDWOOD", "TRATS", NULL };
110
111         char *tty_models[] = { "QCT MSM8X55 SURF", "QCT MSM7x27a FFA", NULL };
112
113         int i = 0;
114
115         if (*name) {
116                 dbg("[ error ] name is not empty");
117                 return FALSE;
118         }
119
120         memset(&u, '\0', sizeof(struct utsname));
121
122         uname(&u);
123
124         dbg("u.nodename : [ %s ]", u.nodename);
125
126         for (i = 0; svnet1_models[i]; i++) {
127                 if (!strcmp(u.nodename, svnet1_models[i])) {
128                         *name = g_new0(char, 5);
129                         strcpy(*name, "6260");
130                         return 5;
131                 }
132         }
133
134         for (i = 0; svnet2_models[i]; i++) {
135                 if (!strcmp(u.nodename, svnet2_models[i])) {
136                         *name = g_new0(char, 5);
137                         strcpy(*name, "6262");
138                         return 5;
139                 }
140         }
141
142         for (i = 0; tty_models[i]; i++) {
143                 if (!strcmp(u.nodename, tty_models[i])) {
144                         *name = g_new0(char, 6);
145                         strcpy(*name, "dpram");
146                         return 6;
147                 }
148         }
149
150         dbg("[ error ] unknown model : (%s)", u.nodename);
151
152         return 0;
153 }
154
155 static gboolean on_init(TcorePlugin *p)
156 {
157         TcoreHal *h;
158         struct global_data *gd;
159         // char *cp_name = 0;
160         int len = 0;
161
162         if (!p)
163                 return FALSE;
164
165         gd = calloc(sizeof(struct global_data), 1);
166         if (!gd)
167                 return FALSE;
168
169         dbg("i'm init!");
170
171         gd->msg_auto_id_current = 0;
172         gd->msg_auto_id_start = 1;
173         gd->msg_auto_id_end = 255;
174
175         len = _get_cp_name(&cp_name);
176         if (!len) {
177                 dbg("[ error ] unsupport cp (name : %s)", cp_name);
178                 free(gd);
179                 return FALSE;
180         }
181
182         /* FIXME: HAL will reside in Co-object.
183          * This HAL is just used as default before MUX setup.
184          * Each HAL has AT pasre functionality.
185          */
186         h = tcore_server_find_hal(tcore_plugin_ref_server(p), cp_name);
187         if (!h) {
188                 g_free(cp_name);
189                 free(gd);
190                 return FALSE;
191         }
192
193         // set physical hal into plugin's userdata
194         gd->hal = h;
195
196         tcore_plugin_link_user_data(p, gd);
197
198         tcore_hal_add_send_hook(h, on_hal_send, p);
199         tcore_hal_add_recv_callback(h, on_hal_recv, p);
200
201         s_modem_init(p, h);
202         s_sim_init(p, h);
203         s_sat_init(p, h);
204         s_network_init(p, h);
205         s_ps_init(p, h);
206         s_call_init(p, h);
207         s_ss_init(p, h);
208         s_sms_init(p, h);
209         s_phonebook_init(p, h);
210         s_sap_init(p, h);
211         s_gps_init(p, h);
212
213         g_free(cp_name);
214
215         tcore_hal_set_power(h, TRUE);
216         //wait until CP is ready
217         g_timeout_add_full(G_PRIORITY_HIGH,500,_query_cp_state, p, 0 );
218         return TRUE;
219 }
220
221 static void on_unload(TcorePlugin *p)
222 {
223         struct global_data *gd;
224
225         if (!p)
226                 return;
227
228         dbg("i'm unload");
229
230         gd = tcore_plugin_ref_user_data(p);
231         if (gd) {
232                 free(gd);
233         }
234 }
235
236 struct tcore_plugin_define_desc plugin_define_desc = {
237         .name = "IMC",
238         .priority = TCORE_PLUGIN_PRIORITY_MID,
239         .version = 1,
240         .load = on_load,
241         .init = on_init,
242         .unload = on_unload
243 };