2 // Tizen Web Device API
3 // Copyright (c) 2013 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 <ITapiModem.h>
22 #include <net_connection.h>
23 #include <ITapiNetwork.h>
24 #include "SystemInfoCellularNetwork.h"
25 #include "SystemInfoUtil.h"
27 #include <PlatformException.h>
31 namespace SystemInfo {
34 const char* CONNECTION_OFF = "OFF";
35 const char* CONNECTION_ON = "ON";
38 SystemInfoCellularNetwork::SystemInfoCellularNetwork(TapiHandle **tapi_handle) :
44 m_is_flight_mode(false)
49 fetchConnection(tapi_handle);
52 SystemInfoCellularNetwork::~SystemInfoCellularNetwork()
57 std::string SystemInfoCellularNetwork::getStatus() const
62 std::string SystemInfoCellularNetwork::getApn() const
67 std::string SystemInfoCellularNetwork::getIpAddress() const
72 std::string SystemInfoCellularNetwork::getIpv6Address() const
74 return m_ipv6_address;
77 unsigned short SystemInfoCellularNetwork::getMcc() const
82 unsigned short SystemInfoCellularNetwork::getMnc() const
87 unsigned short SystemInfoCellularNetwork::getCellId() const
92 unsigned short SystemInfoCellularNetwork::getLac() const
97 bool SystemInfoCellularNetwork::isRoaming() const
102 bool SystemInfoCellularNetwork::isFlightMode() const
104 return m_is_flight_mode;
107 std::string SystemInfoCellularNetwork::getImei() const
112 void SystemInfoCellularNetwork::fetchVconfSettings()
117 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result);
118 if (ret != VCONF_OK) {
119 LOGE("Failed to get is_flight_mode value");
121 m_is_flight_mode = (0 != result) ? true : false;
124 void SystemInfoCellularNetwork::fetchConnection(TapiHandle **tapi_handle)
126 connection_type_e connection_type;
127 connection_profile_h profile_handle = NULL;
129 char* ip_addr = NULL;
131 connection_h connection_handle;
132 TelNetworkDefaultDataSubs_t default_subs = TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM1;
134 TelSimImsiInfo_t imsi;
140 unsigned short mcc_devider = 1000;
141 char **cp_list = NULL;
144 //capi network doesn't support using connection handle created in
145 //other thread, so we need to create it here
146 ret = connection_create(&connection_handle);
147 if (ret != CONNECTION_ERROR_NONE) {
148 LOGE("Failed to create connection: %d, %s", ret,
149 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
153 ret = connection_get_type(connection_handle, &connection_type);
154 if (ret != CONNECTION_ERROR_NONE) {
155 LOGE("Failed to get connection type: %d, %s", ret,
156 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
159 if (CONNECTION_TYPE_CELLULAR == connection_type) {
160 m_status = CONNECTION_ON;
162 ret = connection_get_current_profile(connection_handle, &profile_handle);
163 if (ret != CONNECTION_ERROR_NONE) {
164 LOGE("Failed to get profile: %d, %s", ret,
165 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
168 ret = connection_profile_get_cellular_apn(profile_handle, &apn);
169 if (ret != CONNECTION_ERROR_NONE) {
170 LOGE("Failed to get apn name: %d, %s", ret,
171 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
176 ret = connection_profile_get_ip_address(profile_handle, CONNECTION_ADDRESS_FAMILY_IPV4,
178 if (ret == CONNECTION_ERROR_NONE) {
179 LOGD("Success to get ipv4");
180 m_ip_address = ip_addr;
183 LOGE("Failed to get ip address: %d, %s", ret,
184 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
188 ret = connection_profile_get_ip_address(profile_handle, CONNECTION_ADDRESS_FAMILY_IPV6,
190 if (ret == CONNECTION_ERROR_NONE) {
191 LOGD("Success to get ipv6");
192 m_ipv6_address = ip_addr;
194 } else if (CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED != ret) {
195 LOGE("Failed to get ipv6 address: %d, %s", ret,
196 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
199 m_status = CONNECTION_OFF;
201 ret = connection_get_default_cellular_service_profile(connection_handle,
202 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profile_handle);
203 if (ret == CONNECTION_ERROR_NONE) {
204 ret = connection_profile_get_cellular_apn(profile_handle, &apn);
205 if (ret == CONNECTION_ERROR_NONE) {
206 LOGD("Success to get apn");
210 LOGE("Failed to get default apn name: %d, %s", ret,
211 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
214 LOGE("Failed to get default profile: %d, %s", ret,
215 SystemInfoUtil::getConnectionErrorMessage(ret).c_str());
219 handle = tel_init(NULL);
220 ret = tel_get_network_default_data_subscription(handle, &default_subs);
221 if (ret != TAPI_API_SUCCESS) {
222 LOGE("Failed to get default subscriber: %d, %s", ret,
223 SystemInfoUtil::getTapiErrorMessage(ret).c_str());
225 LOGD("Success to get default subscription");
229 cp_list = tel_get_cp_name_list();
230 handle = tel_init(cp_list[default_subs]);
233 if (handle == NULL) {
234 LOGE("It's failed to get handle");
237 imei = tel_get_misc_me_imei_sync(handle);
239 LOGD("Success to get imei");
243 LOGE("Failed to get imei, NULL pointer. Setting empty value.");
247 ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_PLMN, &plmn);
248 if (ret != TAPI_API_SUCCESS) {
249 LOGE("Failed to get plmn value, %d, %s", ret,
250 SystemInfoUtil::getTapiErrorMessage(ret).c_str());
252 LOGD("plmn : %s", plmn);
253 plmnValue = atoi(plmn);
254 if (plmnValue < 100000) {
257 m_mcc = plmnValue / mcc_devider;
258 m_mnc = plmnValue % mcc_devider;
259 LOGD("mcc : %d, mnc : %d", m_mcc, m_mnc);
262 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &roam);
263 if (ret != TAPI_API_SUCCESS) {
264 LOGE("Failed to get roaming status, %d, %s", ret,
265 SystemInfoUtil::getTapiErrorMessage(ret).c_str());
267 LOGD("roaming : %d", roam);
268 m_is_roaming = (0 != roam) ? true : false;
271 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_CELLID, &cellid);
272 if (ret != TAPI_API_SUCCESS) {
273 LOGE("Failed to get cell id, %d, %s", ret,
274 SystemInfoUtil::getTapiErrorMessage(ret).c_str());
276 LOGD("cellid : %d", cellid);
280 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_LAC, &lac);
281 if (ret != TAPI_API_SUCCESS) {
282 LOGE("Failed to get lac, %d, %s", ret,
283 SystemInfoUtil::getTapiErrorMessage(ret).c_str());
285 LOGD("lac : %d", lac);
290 if (NULL != profile_handle) {
291 connection_profile_destroy(profile_handle);
293 connection_destroy(connection_handle);
297 if (NULL != profile_handle) {
298 connection_profile_destroy(profile_handle);
300 connection_destroy(connection_handle);