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