2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <system_info.h>
26 #include <system_info_private.h>
32 #define LOG_TAG "CAPI_SYSTEM_INFO"
34 int system_info_get_value_from_cpuinfo(char *field, char **value)
39 char str[MAXBUFSIZE] = "";
40 char tmpStr[MAXBUFSIZE] = "";
42 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
43 if (NULL == cpuinfo) {
44 LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH);
45 return SYSTEM_INFO_ERROR_IO_ERROR;
48 while (fgets(str, MAXBUFSIZE, cpuinfo)) {
49 if (!strncmp(field, str, strlen(field))) {
50 name = strchr(str, ':');
51 tmpStrlen = strlen(name+2);
52 strncpy(tmpStr, name+2, tmpStrlen);
53 tmpStr[tmpStrlen-1] = '\0';
54 *value = strdup(tmpStr);
56 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
58 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
63 if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR)
64 *value = strdup("default");
67 LOGE("cannot get %s in cpuinfo", field);
69 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
74 return SYSTEM_INFO_ERROR_NONE;
77 int system_info_get_bsp_info(const char *key, char **value)
82 char *revision = NULL;
83 char Rrevision[MAXBUFSIZE] = "";
84 char file_path[MAXBUFSIZE] = "";
86 if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
87 LOGE("cannot get Hardware info in emulator!!!");
88 return SYSTEM_INFO_ERROR_IO_ERROR;
91 if (system_info_get_value_from_cpuinfo("Hardware", &model)) {
92 LOGE("cannot get Hardware info from cpuinfo file!!!");
93 return SYSTEM_INFO_ERROR_IO_ERROR;
96 if (system_info_get_value_from_cpuinfo("Revision", &revision)) {
97 LOGE("cannot get Hardware info from cpuinfo file!!!");
98 return SYSTEM_INFO_ERROR_IO_ERROR;
101 if (!revision || !strcmp(revision, "default")) {
102 LOGE("cannot get revision info from cpuinfo file!!!");
103 return SYSTEM_INFO_ERROR_IO_ERROR;
106 snprintf(Rrevision, MAXBUFSIZE, "R%s", revision);
107 snprintf(file_path, MAXBUFSIZE, "/etc/config/board-config-%s.xml", model);
109 if (access(file_path, R_OK)) {
110 LOGE("cannot find file %s!!!", file_path);
111 return SYSTEM_INFO_ERROR_IO_ERROR;
114 id_field = strdup(key);
116 if (system_info_get_value_from_xml(file_path, Rrevision, id_field, &string)) {
120 LOGE("cannot get aud_amrwb info from %s!!!", file_path);
121 return SYSTEM_INFO_ERROR_IO_ERROR;
130 return SYSTEM_INFO_ERROR_NONE;