3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/utsname.h>
23 #include <vconf-keys.h>
25 #include <tapi_common.h>
26 #include <ITapiModem.h>
30 #include <sync_agent.h>
32 #include "plugin_slp_device_info.h"
34 #ifndef OMADM_AGENT_LOG
36 #define LOG_TAG "PLUGIN_DEVICE_SLP_DM"
39 #define _D_MSC_FIRMWARE_MAXSTRING_ 40
40 #define _D_SIZE_64_ 64
41 #define _D_SIZE_128_ 128
43 /* todo : temporary definition */
44 #define DTD_VERSION "1.2"
48 #define FOTA_DOWNLOAD_DIR "/opt/data/fota/download"
49 #define FOTA_SAVE_DIR "/opt/data/fota/save"
50 #define FOTA_SD_DOWNLOAD_DIR "/opt/storage/sdcard/data/fota/download"
51 #define FOTA_SD_SAVE_DIR "/opt/storage/sdcard/data/fota/save"
53 /* ========================================*/
54 /* version information
58 /* ========================================*/
60 char *slp_device_info_get_dtd_version()
64 char *dtd_version = (char *)calloc(_D_SIZE_128_, sizeof(char));
65 if (dtd_version == NULL) {
66 _DEBUG_INFO("CALLOC failed !!!");
70 /*snprintf(dtd_version, _D_SIZE_128_ - 1, DTD_VERSION, strlen(DTD_VERSION)); */
71 snprintf(dtd_version, _D_SIZE_128_ - 1, "%s", DTD_VERSION);
72 _DEBUG_INFO("DTD version = %s\n", dtd_version);
78 char *slp_device_info_get_kernel_version()
82 char *kernel_version = (char *)calloc(_D_SIZE_128_, sizeof(char));
83 if (kernel_version == NULL) {
84 _DEBUG_INFO("CALLOC failed !!!");
92 snprintf(kernel_version, _D_SIZE_128_ - 1, "%s.%s", "K", buf.release);
94 _DEBUG_INFO("sysname[%s], nodename[%s], release[%s], version[%s], machine[%s] \n", buf.sysname, buf.nodename, buf.release, buf.version, buf.machine);
96 return kernel_version;
99 char *slp_device_info_get_msisdn_number()
104 char str_key_name[_D_SIZE_128_ * 2] = { 0, };
105 snprintf(str_key_name, _D_SIZE_128_ * 2, "%s", VCONFKEY_TELEPHONY_SUBSCRIBER_NUMBER);
106 get_str = vconf_get_str(str_key_name);
107 _DEBUG_INFO("MSISDN_number = %s\n", get_str);
111 // char *out_msisdn = 0;
112 // int MSISDN_LEN = 20;
113 // int err = SIM_ERROR_NONE;
116 // out_msisdn = (char*)calloc(MSISDN_LEN, sizeof(char));
117 // if (out_msisdn == NULL)
120 // err = sim_get_subscriber_number(&msisdn);
121 // if (!err && msisdn == NULL) {
122 // strncpy(out_msisdn, msisdn, MSISDN_LEN-1);
125 // strncpy(out_msisdn, "", MSISDN_LEN-1);
129 // _DEBUG_INFO("MSISDN = %s", msisdn);
133 char *slp_device_info_get_mcc()
139 mcc = (char *)calloc(mcc_len, sizeof(char));
144 int b_card_changed = 0;
146 handle = tel_init(NULL);
147 if (handle == NULL) {
148 _DEBUG_INFO("handle is NULL !!");
154 TelSimImsiInfo_t imsi;
155 TapiResult_t err_code = TAPI_API_SUCCESS;
156 TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
158 err_code = (TapiResult_t) tel_get_sim_init_info(handle, &status, &b_card_changed);
159 if (err_code == TAPI_API_SUCCESS && status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
160 err_code = (TapiResult_t) tel_get_sim_imsi(handle, &imsi);
161 if (err_code == TAPI_API_SUCCESS) {
162 strncpy(mcc, imsi.szMcc, mcc_len);
163 _DEBUG_INFO("MCC = %s", mcc);
169 strncpy(mcc, "0", mcc_len);
170 _DEBUG_INFO("MCC = %s", mcc);
180 char *slp_device_info_get_csc()
185 return strdup("VD2");
188 /* ====================================
189 * device directory information
190 * fota download directory
191 * fota save directory
192 * =====================================*/
194 char *slp_device_info_get_fota_download_dir()
198 int ret = sync_agent_create_directory(FOTA_DOWNLOAD_DIR);
200 _DEBUG_INFO("existed foler or create foler error");
203 char *fota_download_dir = (char *)calloc(_D_SIZE_128_, sizeof(char));
204 if (fota_download_dir == NULL) {
205 _DEBUG_INFO("CALLOC failed !!!");
209 /*snprintf(FOTA_Download_Dir, _D_SIZE_128_ - 1, FOTA_DOWNLOAD_DIR, strlen(FOTA_DOWNLOAD_DIR)); */
210 snprintf(fota_download_dir, _D_SIZE_128_ - 1, "%s", FOTA_DOWNLOAD_DIR);
212 _DEBUG_INFO("FOTA Download dir = %s\n", fota_download_dir);
214 return fota_download_dir;
218 char *slp_device_info_get_fota_save_dir()
222 int ret = sync_agent_create_directory(FOTA_SAVE_DIR);
224 _DEBUG_INFO("existed foler or create foler error");
227 char *fota_save_dir = (char *)calloc(_D_SIZE_128_, sizeof(char));
228 if (fota_save_dir == NULL) {
229 _DEBUG_INFO("CALLOC failed !!!");
233 /*snprintf(FOTA_Save_Dir, _D_SIZE_128_ - 1, FOTA_SAVE_DIR, strlen(FOTA_SAVE_DIR)); */
234 snprintf(fota_save_dir, _D_SIZE_128_ - 1, "%s", FOTA_SAVE_DIR);
236 _DEBUG_INFO("FOTA save dir = %s\n", fota_save_dir);
238 return fota_save_dir;
241 /* ====================================
242 * device directory information
243 * fota sd card download directory
244 * fota sd card save directory
245 * =====================================*/
247 char *slp_device_info_get_fota_sd_download_dir()
251 int ret = sync_agent_create_directory(FOTA_SD_DOWNLOAD_DIR);
253 _DEBUG_INFO("existed foler or create foler error");
256 char *fota_sd_download_dir = (char *)calloc(_D_SIZE_128_, sizeof(char));
257 if (fota_sd_download_dir == NULL) {
258 _DEBUG_INFO("CALLOC failed !!!");
262 /*snprintf(FOTA_SD_Download_Dir, _D_SIZE_128_ - 1, FOTA_SD_DOWNLOAD_DIR, strlen(FOTA_SD_DOWNLOAD_DIR)); */
263 snprintf(fota_sd_download_dir, _D_SIZE_128_ - 1, "%s", FOTA_SD_DOWNLOAD_DIR);
265 _DEBUG_INFO("FOTA SD CARD Download dir = %s\n", fota_sd_download_dir);
267 return fota_sd_download_dir;
270 char *slp_device_info_get_fota_sd_save_dir()
274 int ret = sync_agent_create_directory(FOTA_SD_SAVE_DIR);
276 _DEBUG_INFO("existed foler or create foler error");
279 char *fota_sd_save_dir = (char *)calloc(_D_SIZE_128_, sizeof(char));
280 if (fota_sd_save_dir == NULL) {
281 _DEBUG_INFO("CALLOC failed !!!");
285 /*snprintf(FOTA_SD_Save_Dir, _D_SIZE_128_ - 1, FOTA_SD_SAVE_DIR, strlen(FOTA_SD_SAVE_DIR)); */
286 snprintf(fota_sd_save_dir, _D_SIZE_128_ - 1, "%s", FOTA_SD_SAVE_DIR);
288 _DEBUG_INFO("FOTA SD CARD save dir = %s\n", fota_sd_save_dir);
290 return fota_sd_save_dir;
293 /* ====================================
294 * device etc information
295 * =====================================*/
297 char *slp_device_info_get_opco_info()
301 char *opcoInfo = (char *)calloc(_D_SIZE_128_, sizeof(char));
302 if (opcoInfo == NULL) {
303 _DEBUG_INFO("CALLOC failed !!!");
307 snprintf(opcoInfo, _D_SIZE_128_ - 1, "%s", OPCO);
308 _DEBUG_INFO("Opco Info = %s\n", opcoInfo);
310 return opcoInfo; /* prevent */
313 char *slp_device_info_get_imsi_info()
317 _DEBUG_INFO("Start !!");
319 TelSimImsiInfo_t sim_imsi_info;
322 char imsi_value[30] = { 0, };
325 handle = tel_init(NULL);
326 if (handle == NULL) {
327 _DEBUG_INFO("handle is NULL !!");
328 _DEBUG_INFO("End !!");
332 _DEBUG_INFO("handle : %d", handle);
333 err_code = tel_get_sim_imsi(handle, &sim_imsi_info);
336 if (err_code != TAPI_API_SUCCESS) {
337 _DEBUG_INFO("tel_get_sim_imsi() failed !!, err_code : 0x%02x", err_code);
341 _DEBUG_INFO("tel_get_sim_imsi() success !!");
343 if (!strcmp(sim_imsi_info.szMcc, " ") && !strcmp(sim_imsi_info.szMnc, " ") && !strcmp(sim_imsi_info.szMsin, " ")) {
344 _DEBUG_INFO("mcc : %s", sim_imsi_info.szMcc);
345 _DEBUG_INFO("mnc : %s", sim_imsi_info.szMnc);
346 _DEBUG_INFO("msin : %s", sim_imsi_info.szMsin);
348 snprintf(imsi_value, sizeof(imsi_value), "%s%s%s", sim_imsi_info.szMcc, sim_imsi_info.szMnc, sim_imsi_info.szMsin);
349 _DEBUG_INFO("IMSI : %s ( %d )", imsi_value, strlen(imsi_value));
353 _DEBUG_INFO("End !!");
354 return strdup(imsi_value);
356 _DEBUG_INFO("invalid IMSI value !!");