Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / plugins / dm-private / slp-device-dm / src / plugin_interface_devinfo.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <glib-object.h>
23
24 #include <vconf.h>
25 #include <vconf-keys.h>
26
27 /*sync-agent*/
28 #include <sync_agent.h>
29
30 #include "plugin_slp_device_info.h"
31
32 #ifndef EXPORT_API
33 #define EXPORT_API __attribute__ ((visibility("default")))
34 #endif
35
36 #ifndef OMADM_AGENT_LOG
37 #undef LOG_TAG
38 #define LOG_TAG "PLUGIN_DEVICE_SLP_DM"
39 #endif
40
41 #define IMEI_LEN                                        5
42 #define FW_VERSION_LEN          20
43 #define BUFF_SIZE                                       1000
44
45 /* todo : temporary definition */
46 #define HW_VERSION                              "1.0"
47
48 typedef struct {
49         char *info_name;
50         char *vconf_key;
51 } dici_name_key_map;
52
53 dici_name_key_map dev_key_map[] = {
54         {"SwV", VCONFKEY_TELEPHONY_SWVERSION},
55         {"HwV", VCONFKEY_TELEPHONY_HWVERSION},
56         /*{"Lang", "db/menu_widget/language"}, */
57         {"Lang", VCONFKEY_LANGSET},
58         {NULL, NULL},
59 };
60
61 static GList *devInfo;
62 static sync_agent_get_devinfo_cb func_get_dev_info_common = 0;
63
64 static char *_get_dev_info_common(char *key);
65
66 EXPORT_API int sync_agent_plugin_load_devinfo()
67 {
68         _EXTERN_FUNC_ENTER;
69
70         g_type_init();
71
72         int res = 1;
73
74         devInfo = NULL;
75
76         /* get SwV */
77         sync_agent_plugin_device_info_s *swv = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
78         if (swv == NULL) {
79                 _EXTERN_FUNC_EXIT;
80                 return 0;
81         }
82         memset(swv, 0x00, sizeof(sync_agent_plugin_device_info_s));
83         swv->info_name = strdup("SwV");
84         swv->value = _get_dev_info_common(swv->info_name);
85         devInfo = g_list_append(devInfo, swv);
86
87         /* get HwV */
88         sync_agent_plugin_device_info_s *hwv = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
89         if (hwv == NULL) {
90                 _EXTERN_FUNC_EXIT;
91                 return 0;
92         }
93         memset(hwv, 0x00, sizeof(sync_agent_plugin_device_info_s));
94         hwv->info_name = strdup("HwV");
95         hwv->value = _get_dev_info_common(hwv->info_name);
96         devInfo = g_list_append(devInfo, hwv);
97
98         /* get Lang */
99         sync_agent_plugin_device_info_s *lang = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
100         if (lang == NULL) {
101                 _EXTERN_FUNC_EXIT;
102                 return 0;
103         }
104         memset(lang, 0x00, sizeof(sync_agent_plugin_device_info_s));
105         lang->info_name = strdup("Lang");
106         lang->value = _get_dev_info_common(lang->info_name);
107         devInfo = g_list_append(devInfo, lang);
108
109         /* get DevID */
110         sync_agent_plugin_device_info_s *devId = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
111         if (devId == NULL) {
112                 _EXTERN_FUNC_EXIT;
113                 return 0;
114         }
115         memset(devId, 0x00, sizeof(sync_agent_plugin_device_info_s));
116         devId->info_name = strdup("DevID");
117         devId->value = _get_dev_info_common(devId->info_name);
118         devInfo = g_list_append(devInfo, devId);
119         _DEBUG_INFO("mdi ============= \n");
120
121         /* get Manufacture */
122         sync_agent_plugin_device_info_s *man = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
123         if (man == NULL) {
124                 _EXTERN_FUNC_EXIT;
125                 return 0;
126         }
127         memset(man, 0x00, sizeof(sync_agent_plugin_device_info_s));
128         man->info_name = strdup("Man");
129         man->value = _get_dev_info_common(man->info_name);
130         devInfo = g_list_append(devInfo, man);
131
132         /* get Model info */
133         sync_agent_plugin_device_info_s *mod = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
134         if (mod == NULL) {
135                 _EXTERN_FUNC_EXIT;
136                 return 0;
137         }
138         memset(mod, 0x00, sizeof(sync_agent_plugin_device_info_s));
139         mod->info_name = strdup("Mod");
140         mod->value = _get_dev_info_common(mod->info_name);
141         devInfo = g_list_append(devInfo, mod);
142
143         /* get FwV */
144         sync_agent_plugin_device_info_s *fw = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
145         if (fw == NULL) {
146                 _EXTERN_FUNC_EXIT;
147                 return 0;
148         }
149         memset(fw, 0x00, sizeof(sync_agent_plugin_device_info_s));
150         fw->info_name = strdup("FwV");
151         fw->value = _get_dev_info_common(fw->info_name);
152         devInfo = g_list_append(devInfo, fw);
153
154         /* get OEM */
155         sync_agent_plugin_device_info_s *oem = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
156         if (oem == NULL) {
157                 _EXTERN_FUNC_EXIT;
158                 return 0;
159         }
160         memset(oem, 0x00, sizeof(sync_agent_plugin_device_info_s));
161         oem->info_name = strdup("OEM");
162         oem->value = _get_dev_info_common(oem->info_name);
163         devInfo = g_list_append(devInfo, oem);
164
165         /* get DevTyp */
166         sync_agent_plugin_device_info_s *dev_type = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
167         if (dev_type == NULL) {
168                 _EXTERN_FUNC_EXIT;
169                 return 0;
170         }
171         memset(dev_type, 0x00, sizeof(sync_agent_plugin_device_info_s));
172         dev_type->info_name = strdup("DevTyp");
173         dev_type->value = _get_dev_info_common(dev_type->info_name);
174         devInfo = g_list_append(devInfo, dev_type);
175
176         /* get Modem version */
177         sync_agent_plugin_device_info_s *modem_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
178         if (modem_version == NULL) {
179                 _EXTERN_FUNC_EXIT;
180                 return 0;
181         }
182         memset(modem_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
183         modem_version->info_name = strdup("ModemV");
184         modem_version->value = _get_dev_info_common(modem_version->info_name);
185         devInfo = g_list_append(devInfo, modem_version);
186
187         /* get PDA version */
188         sync_agent_plugin_device_info_s *pda_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
189         if (pda_version == NULL) {
190                 _EXTERN_FUNC_EXIT;
191                 return 0;
192         }
193         memset(pda_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
194         pda_version->info_name = strdup("PDAV");
195         pda_version->value = _get_dev_info_common(pda_version->info_name);
196         devInfo = g_list_append(devInfo, pda_version);
197
198         /* get CSC version */
199         sync_agent_plugin_device_info_s *csc_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
200         if (csc_version == NULL) {
201                 _EXTERN_FUNC_EXIT;
202                 return 0;
203         }
204         memset(csc_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
205         csc_version->info_name = strdup("CSCV");
206         csc_version->value = _get_dev_info_common(csc_version->info_name);
207         devInfo = g_list_append(devInfo, csc_version);
208
209         /* get kernel version */
210         sync_agent_plugin_device_info_s *kernel_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
211         if (kernel_version == NULL) {
212                 _EXTERN_FUNC_EXIT;
213                 return 0;
214         }
215         memset(kernel_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
216         kernel_version->info_name = strdup("KernelV");
217         kernel_version->value = slp_device_info_get_kernel_version();
218         devInfo = g_list_append(devInfo, kernel_version);
219
220         /* get FOTA_download dir */
221         sync_agent_plugin_device_info_s *fota_download_dir = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
222         if (fota_download_dir == NULL) {
223                 _EXTERN_FUNC_EXIT;
224                 return 0;
225         }
226         memset(fota_download_dir, 0x00, sizeof(sync_agent_plugin_device_info_s));
227         fota_download_dir->info_name = strdup("FOTADownDir");
228         fota_download_dir->value = slp_device_info_get_fota_download_dir();
229         devInfo = g_list_append(devInfo, fota_download_dir);
230
231         /* get FOTA save dir */
232         sync_agent_plugin_device_info_s *fota_save_dir = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
233         if (fota_save_dir == NULL) {
234                 _EXTERN_FUNC_EXIT;
235                 return 0;
236         }
237         memset(fota_save_dir, 0x00, sizeof(sync_agent_plugin_device_info_s));
238         fota_save_dir->info_name = strdup("FOTASaveDir");
239         fota_save_dir->value = slp_device_info_get_fota_save_dir();
240         devInfo = g_list_append(devInfo, fota_save_dir);
241
242         /* get SD_FOTA_download dir */
243         sync_agent_plugin_device_info_s *fota_sd_download_dir = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
244         if (fota_sd_download_dir == NULL) {
245                 _EXTERN_FUNC_EXIT;
246                 return 0;
247         }
248         memset(fota_sd_download_dir, 0x00, sizeof(sync_agent_plugin_device_info_s));
249         fota_sd_download_dir->info_name = strdup("FOTA_SD_DownDir");
250         fota_sd_download_dir->value = slp_device_info_get_fota_sd_download_dir();
251         devInfo = g_list_append(devInfo, fota_sd_download_dir);
252
253         /* get SD_FOTA save dir */
254         sync_agent_plugin_device_info_s *fota_sd_save_dir = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
255         if (fota_sd_save_dir == NULL) {
256                 _EXTERN_FUNC_EXIT;
257                 return 0;
258         }
259         memset(fota_sd_save_dir, 0x00, sizeof(sync_agent_plugin_device_info_s));
260         fota_sd_save_dir->info_name = strdup("FOTA_SD_SaveDir");
261         fota_sd_save_dir->value = slp_device_info_get_fota_sd_save_dir();
262         devInfo = g_list_append(devInfo, fota_sd_save_dir);
263
264         /* get DTD version */
265         sync_agent_plugin_device_info_s *dtd_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
266         if (dtd_version == NULL) {
267                 _EXTERN_FUNC_EXIT;
268                 return 0;
269         }
270         memset(dtd_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
271         dtd_version->info_name = strdup("DTDV");
272         dtd_version->value = slp_device_info_get_dtd_version();
273         devInfo = g_list_append(devInfo, dtd_version);
274
275         /* get OPCO info */
276         sync_agent_plugin_device_info_s *opco_info = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
277         if (opco_info == NULL) {
278                 _EXTERN_FUNC_EXIT;
279                 return 0;
280         }
281         memset(opco_info, 0x00, sizeof(sync_agent_plugin_device_info_s));
282         opco_info->info_name = strdup("OPCO");
283         opco_info->value = slp_device_info_get_opco_info();
284         devInfo = g_list_append(devInfo, opco_info);
285
286         /* get PHONE_NUM info */
287         sync_agent_plugin_device_info_s *phone_num = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
288         if (phone_num == NULL) {
289                 _EXTERN_FUNC_EXIT;
290                 return 0;
291         }
292         memset(phone_num, 0x00, sizeof(sync_agent_plugin_device_info_s));
293         phone_num->info_name = strdup("PHONE_NUM");
294         phone_num->value = slp_device_info_get_msisdn_number();
295         devInfo = g_list_append(devInfo, phone_num);
296
297         /* get IMSI */
298         sync_agent_plugin_device_info_s *imsi_value = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
299         if (imsi_value == NULL) {
300                 _EXTERN_FUNC_EXIT;
301                 return 0;
302         }
303         memset(imsi_value, 0x00, sizeof(sync_agent_plugin_device_info_s));
304         imsi_value->info_name = strdup("IMSI");
305         imsi_value->value = slp_device_info_get_imsi_info();
306         devInfo = g_list_append(devInfo, imsi_value);
307
308         /* get CSC */
309         sync_agent_plugin_device_info_s *csc_value = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
310         if (csc_value == NULL) {
311                 _EXTERN_FUNC_EXIT;
312                 return 0;
313         }
314         memset(csc_value, 0x00, sizeof(sync_agent_plugin_device_info_s));
315         csc_value->info_name = strdup("CSC");
316         csc_value->value = slp_device_info_get_csc();
317         devInfo = g_list_append(devInfo, csc_value);
318
319         /* get MCC */
320         sync_agent_plugin_device_info_s *mcc_value = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
321         if (mcc_value == NULL) {
322                 _EXTERN_FUNC_EXIT;
323                 return 0;
324         }
325         memset(mcc_value, 0x00, sizeof(sync_agent_plugin_device_info_s));
326         mcc_value->info_name = strdup("MCC");
327         mcc_value->value = slp_device_info_get_mcc();
328         devInfo = g_list_append(devInfo, mcc_value);
329
330         /* for test */
331         int cnt = 0;
332         GList *iter = NULL;
333         for (iter = devInfo; iter != NULL; iter = g_list_next(iter)) {
334                 _DEBUG_INFO("[devInfo_slp_plugIn] cnt : %d,  info_name : %s, value : %s\n", cnt, ((sync_agent_plugin_device_info_s *) (iter->data))->info_name, ((sync_agent_plugin_device_info_s *) (iter->data))->value);
335                 cnt++;
336         }
337
338         _EXTERN_FUNC_EXIT;
339         return res;
340 }
341
342 EXPORT_API int sync_agent_plugin_get_devinfo(char *info_name, char **value)
343 {
344         _EXTERN_FUNC_ENTER;;
345
346         retvm_if((info_name) == NULL, 0, "info_name is NULL!!");
347
348         int res = 1;
349         int is_exist = 0;
350         GList *iter = NULL;
351         sync_agent_plugin_device_info_s *iter_data;
352
353         for (iter = devInfo; iter != NULL; iter = g_list_next(iter)) {
354                 iter_data = NULL;
355                 iter_data = (sync_agent_plugin_device_info_s *) (iter->data);
356                 if (iter_data->info_name != NULL) {
357                         if (!strcmp(iter_data->info_name, info_name)) {
358                                 if (iter_data->value != NULL) {
359
360                                         *value = strdup(iter_data->value);
361
362                                         is_exist = 1;
363                                         break;
364                                 } else {
365                                         _DEBUG_INFO("[devInfo_slp_plugIn] %s  value is NULL !!\n", info_name);
366                                         res = 0;
367                                         _EXTERN_FUNC_EXIT;
368                                         return res;
369                                 }
370                         }
371                 }
372         }
373
374         if (strcmp("Battery", info_name) == 0) {
375                 *value = _get_dev_info_common(info_name);
376                 if (*value != NULL)
377                         is_exist = 1;
378         }
379
380         if (is_exist != 1) {
381                 _DEBUG_INFO("[devInfo_slp_plugIn] not exist  %s  information !!\n", info_name);
382                 res = -1;
383                 _EXTERN_FUNC_EXIT;
384                 return res;
385         }
386
387         _EXTERN_FUNC_EXIT;
388         return res;
389 }
390
391 EXPORT_API int sync_agent_plugin_clear_devinfo()
392 {
393         _EXTERN_FUNC_ENTER;;
394
395         int res = 1;
396
397         GList *iter = NULL;
398         sync_agent_plugin_device_info_s *iter_data;
399
400         if (devInfo != NULL) {
401                 for (iter = devInfo; iter != NULL;) {
402                         iter_data = NULL;
403                         iter_data = ((sync_agent_plugin_device_info_s *) (iter->data));
404                         iter = g_list_next(iter);
405                         devInfo = g_list_remove(devInfo, iter_data);
406
407                         if (iter_data != NULL) {
408                                 if (((sync_agent_plugin_device_info_s *) (iter_data))->info_name != NULL)
409                                         free(((sync_agent_plugin_device_info_s *) (iter_data))->info_name);
410                                 if (((sync_agent_plugin_device_info_s *) (iter_data))->value != NULL)
411                                         free(((sync_agent_plugin_device_info_s *) (iter_data))->value);
412                                 free((sync_agent_plugin_device_info_s *) (iter_data));
413                         }
414                 }
415
416                 g_list_free(devInfo);
417         }
418
419         _EXTERN_FUNC_EXIT;
420         return res;
421 }
422
423 EXPORT_API void sync_agent_plugin_set_common_devinfo_function(sync_agent_get_devinfo_cb func)
424 {
425         _EXTERN_FUNC_ENTER;
426
427         func_get_dev_info_common = func;
428
429         _EXTERN_FUNC_EXIT;
430 }
431
432 static char *_get_dev_info_common(char *key)
433 {
434         _INNER_FUNC_ENTER;
435
436         if (key == NULL) {
437                 _DEBUG_TRACE("KEY name is NULL !!!");
438                 _INNER_FUNC_EXIT;
439                 return NULL;
440         }
441
442         char *value = 0;
443         sync_agent_dev_return_e ret = SYNC_AGENT_DEV_RETURN_SUCCESS;
444
445         ret = func_get_dev_info_common(1, key, &value);
446         if (ret == SYNC_AGENT_DEV_RETURN_SUCCESS) {
447                 _DEBUG_TRACE(" key = %s, value = %s", key, value);
448                 _INNER_FUNC_EXIT;
449                 return value;
450         } else {
451                 _DEBUG_TRACE(" key = %s has NULL value !!!", key, value);
452                 _INNER_FUNC_EXIT;
453                 return NULL;
454         }
455 }