From b0fc81d6e8626611ef30dcfa92458ab882138d0a Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 24 Jul 2017 18:26:11 +0900 Subject: [PATCH] Remove Telephony Dependency for IoT_Core/Headless devices I created a sub-package and moved all the Telephony-related parts. Change-Id: I8810b06f2fa5ca286114fed5a015dd7bef4f96a7 --- CMakeLists.txt | 3 +- include/neterror.h | 4 + include/plugin.h | 35 +++ include/util.h | 15 +- include/wifi-tel-intf.h | 38 --- packaging/net-config.spec | 14 +- plugin/telephony/CMakeLists.txt | 42 +++ plugin/telephony/telephony.c | 642 ++++++++++++++++++++++++++++++++++++++++ src/neterror.c | 10 +- src/network-state.c | 15 +- src/utils/log.c | 5 +- src/utils/util.c | 135 ++++++++- src/wifi-eap.c | 437 ++------------------------- src/wifi-power.c | 66 ----- src/wifi-tel-intf.c | 108 ------- 15 files changed, 912 insertions(+), 657 deletions(-) delete mode 100755 include/wifi-tel-intf.h create mode 100755 plugin/telephony/CMakeLists.txt create mode 100755 plugin/telephony/telephony.c delete mode 100755 src/wifi-tel-intf.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 350148c..233e35d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ SET(SRCS src/network-statistics.c src/dbus/netsupplicant.c src/wifi-background-scan.c - src/wifi-tel-intf.c src/wifi-config.c ) @@ -75,7 +74,6 @@ ENDIF(TIZEN_WEARABLE) INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(pkgs REQUIRED dlog - tapi vconf gio-2.0 glib-2.0 @@ -131,3 +129,4 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) INSTALL(FILES ${CMAKE_SOURCE_DIR}/config/security-network-config.conf DESTINATION /usr/lib/tmpfiles.d/) ADD_SUBDIRECTORY(plugin/headed) +ADD_SUBDIRECTORY(plugin/telephony) diff --git a/include/neterror.h b/include/neterror.h index df6247b..5e5fccd 100755 --- a/include/neterror.h +++ b/include/neterror.h @@ -28,6 +28,10 @@ extern "C" { #include #include +#ifndef EXPORT_SYM +#define EXPORT_SYM __attribute__((__visibility__("default"))) +#endif + #define NETCONFIG_ERROR_QUARK (netconfig_error_quark()) #define NETCONFIG_CONNMAN_AGENT_ERROR_QUARK (netconfig_connman_agent_error_quark()) diff --git a/include/plugin.h b/include/plugin.h index 5b72d99..e68db58 100755 --- a/include/plugin.h +++ b/include/plugin.h @@ -25,12 +25,28 @@ extern "C" { #endif #include +#include +#include + +#include "neterror.h" #define NETCONFIG_ADD_FOUND_AP_NOTI "add_found_ap_noti" #define NETCONFIG_DEL_FOUND_AP_NOTI "del_found_ap_noti" #define NETCONFIG_ADD_PORTAL_NOTI "add_portal_noti" #define NETCONFIG_DEL_PORTAL_NOTI "del_portal_noti" +struct wifi_authentication_data { + int auth_result; + int resp_length; + int authentication_key_length; + int cipher_length; + int integrity_length; + char *resp_data; + char *authentication_key; + char *cipher_data; + char *integrity_data; +}; + struct netconfig_headed_plugin_t { void(*pop_device_picker) (void); gboolean(*send_notification_to_net_popup) (const char *, const char *); @@ -40,6 +56,20 @@ struct netconfig_headed_plugin_t { void(*pop_wifi_connected_poppup) (const char *); }; +struct netconfig_telephony_plugin_t { + void(*get_telephony_network_type) (int *svctype, int *pstype); + gboolean(*wifi_get_sim_imsi) (void *wifi, GDBusMethodInvocation *context); + netconfig_error_e(*wifi_req_aka_auth) (GArray *rand_data, GArray *autn_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); + gboolean(*wifi_req_sim_auth) (GArray *rand_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); + gboolean(*tapi_check_sim_state) (void); + gboolean(*wifi_get_aka_authdata) (void *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); + gboolean(*wifi_get_sim_authdata) (void *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); +}; + typedef enum { SYS_EVT_NETWORK_STATUS = 0, SYS_EVT_WIFI_STATE = 1, @@ -55,6 +85,11 @@ typedef enum { EVAL_WIFI_OFF = 27, } sys_evt_t; +void netconfig_complete_get_sim_imsi(void *wifi, GDBusMethodInvocation *context, char *imsi); +void netconfig_complete_get_aka_auth(void *wifi, GDBusMethodInvocation *context, GArray *array); +void netconfig_complete_get_sim_auth(void *wifi, GDBusMethodInvocation *context, GArray *array); +void netconfig_wifi_power_on(); + #ifdef __cplusplus } #endif diff --git a/include/util.h b/include/util.h index 3070cf4..b1dc6f5 100755 --- a/include/util.h +++ b/include/util.h @@ -76,11 +76,24 @@ int netconfig_vconf_get_int(const char * key, int *value); int netconfig_vconf_get_bool(const char * key, int *value); char* netconfig_get_env(const char *key); void netconfig_set_mac_address_from_file(void); - void __netconfig_pop_wifi_connected_poppup(const char *ssid); + +void netconfig_get_telephony_network_type(int *svctype, int *pstype); +gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context); +netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); +gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); +gboolean netconfig_tapi_check_sim_state(void); +gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); +gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data); + void netconfig_plugin_init(); void netconfig_plugin_deinit(); gboolean netconfig_get_headed_plugin_flag(); +gboolean netconfig_get_telephony_plugin_flag(); #ifdef __cplusplus } diff --git a/include/wifi-tel-intf.h b/include/wifi-tel-intf.h deleted file mode 100755 index 749b815..0000000 --- a/include/wifi-tel-intf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef __NETCONFIG_WIFI_TEL_INTF_H__ -#define __NETCONFIG_WIFI_TEL_INTF_H__ - -#ifdef __cplusplus - extern "C" { -#endif - -#include -#include -#include "wifi.h" - -TapiHandle * netconfig_tel_init(void); -void netconfig_tel_deinit(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __NETCONFIG_WIFI_TEL_INTERFACE_H__ */ - diff --git a/packaging/net-config.spec b/packaging/net-config.spec index f12d8a7..cb61ec9 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,12 +1,11 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.110 +Version: 1.1.111 Release: 2 Group: System/Network License: Apache-2.0 Source0: %{name}-%{version}.tar.gz BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) @@ -49,6 +48,13 @@ Requires: %{name} = %{version}-%{release} %description plugin-headed TIZEN Network Configuration service extension for headed profile. +%package plugin-telephony +Summary: net-config extension for telephony FW +BuildRequires: pkgconfig(tapi) +Requires: %{name} = %{version}-%{release} +%description plugin-telephony +TIZEN Network Configuration service extension for telephony FW. + %prep %setup -q @@ -203,3 +209,7 @@ mv %{_unitdir}/net-config.service.tv %{_unitdir}/net-config.service %manifest net-config.manifest %attr(500,network_fw,network_fw) %{_libdir}/net-config-plugin-headed.so %attr(644,network_fw,network_fw) /usr/lib/tmpfiles.d/security-network-config.conf + +%files plugin-telephony +%manifest net-config.manifest +%attr(500,network_fw,network_fw) %{_libdir}/net-config-plugin-telephony.so diff --git a/plugin/telephony/CMakeLists.txt b/plugin/telephony/CMakeLists.txt new file mode 100755 index 0000000..950623e --- /dev/null +++ b/plugin/telephony/CMakeLists.txt @@ -0,0 +1,42 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(net-config-plugin-telephony C) + +IF(TIZEN_WEARABLE) + ADD_DEFINITIONS(-DTIZEN_WEARABLE) +ENDIF(TIZEN_WEARABLE) + +ADD_DEFINITIONS(-DUSE_NETCONFIG_LOG) + +# Set required packages +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(pkgs_telephony REQUIRED + dlog + vconf + gio-2.0 + gio-unix-2.0 + glib-2.0 + tapi + ) + +FOREACH(flag ${pkgs_telephony_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +# INCLUDE_DIRECTORIES(SRCS include) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(SRCS_TELEPHONY + telephony.c + ) + +# library build +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS_TELEPHONY}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_telephony_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME}) + +# install +INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR}) diff --git a/plugin/telephony/telephony.c b/plugin/telephony/telephony.c new file mode 100755 index 0000000..0e89abb --- /dev/null +++ b/plugin/telephony/telephony.c @@ -0,0 +1,642 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "plugin.h" + +#ifdef USE_NETCONFIG_LOG +#include "log.h" +#else +#include + +#define NETCONFIG_TAG "NETCONFIG" +#define __LOG(level, format, arg...) \ + do { \ + SLOG(level, NETCONFIG_TAG, format, ## arg); \ + } while (0) + +#define DBG(format, arg...) __LOG(LOG_DEBUG, format, ## arg) +#define ERR(format, arg...) __LOG(LOG_ERROR, format, ## arg) +#endif + +#define TAPI_HANDLE_MAX 2 + +/* #define SIM_SLOT_DUAL 2 */ +#define SIM_SLOT_SINGLE 1 + +#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE "db/telephony/dualsim/default_data_service" +/* +#define DEFAULT_DATA_SERVICE_SIM1 0 +#define DEFAULT_DATA_SERVICE_SIM2 1 +*/ +#define SIM_RAND_DATA_LEN 16 +#define SIM_AUTH_MAX_RESP_DATA_LEN 128 +#define SIM_AUTH_SRES_LEN 4 +#define SIM_AUTH_KC_LEN 8 + +#define AKA_RAND_DATA_LEN 16 +#define AKA_AUTN_DATA_LEN 16 +#define AKA_AUTH_RES_MAX_LEN 16 +#define AKA_AUTH_RES_MIN_LEN 4 +#define AKA_AUTH_CK_LEN 16 +#define AKA_AUTH_IK_LEN 16 + +static TapiHandle *tapi_handle_dual[TAPI_HANDLE_MAX+1]; +static TapiHandle *tapi_handle = NULL; +struct wifi_authentication_data **wifi_authdata_p = NULL; + +#define wifi_authdata (*wifi_authdata_p) + +static int _check_current_sim() +{ +#if defined TIZEN_WEARABLE + return -1; +#else + int current_sim = 0; + int sim_slot_count = 0; + + if ((vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) + || sim_slot_count == SIM_SLOT_SINGLE) { + ERR("failed to get sim slot count (%d)", sim_slot_count); + return -1; + } + + if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) { + ERR("failed to get default data service = %d\n", current_sim); + return 0; + } + + DBG("default data service [SIM%d]", current_sim); + return current_sim; +#endif +} + +static TapiHandle * netconfig_tel_init(void) +{ + char **cp_list = NULL; + int current_sim = _check_current_sim(); + + if (current_sim < 0) { + if (tapi_handle == NULL) { + tapi_handle = tel_init(NULL); + if (tapi_handle == NULL) + ERR("tel_init() Failed - modem %d", current_sim); + } + return tapi_handle; + } else { + if (tapi_handle_dual[current_sim] == NULL) { + cp_list = tel_get_cp_name_list(); + if (!cp_list) { + ERR("tel_get_cp_name_list() Failed"); + return NULL; + } + + tapi_handle_dual[current_sim] = tel_init(cp_list[current_sim]); + if (tapi_handle_dual[current_sim] == NULL) + ERR("tel_init() Failed - modem %d", current_sim); + + g_strfreev(cp_list); + } + return tapi_handle_dual[current_sim]; + } +} + +static void netconfig_tel_deinit(void) +{ + int current_sim = _check_current_sim(); + + if (current_sim < 0) { + if (tapi_handle) + tel_deinit(tapi_handle); + + tapi_handle = NULL; + } else { + unsigned int i = 0; + while (tapi_handle_dual[i]) { + tel_deinit(tapi_handle_dual[i]); + tapi_handle_dual[i] = NULL; + i++; + } + } +} + +void telephony_get_network_type(int *svctype, int *pstype) +{ + TapiHandle *tapi_handle = NULL; + int telephony_svctype = 0, telephony_pstype = 0; + + tapi_handle = (TapiHandle *)netconfig_tel_init(); + + if (NULL != tapi_handle) { + tel_get_property_int(tapi_handle, + TAPI_PROP_NETWORK_SERVICE_TYPE, + &telephony_svctype); + tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PS_TYPE, + &telephony_pstype); + netconfig_tel_deinit(); + } + + *svctype = telephony_svctype; + *pstype = telephony_pstype; +} + +gboolean telephony_wifi_get_sim_imsi(void *wifi, GDBusMethodInvocation *context) +{ + int ret; + TapiHandle *handle; + TelSimImsiInfo_t imsi_info; + char *imsi; + + handle = (TapiHandle *)netconfig_tel_init(); + if (handle == NULL) { + ERR("tapi_init failed"); + netconfig_error_fail_get_imsi(context); + return FALSE; + } + + ERR("before tel_get_sim_imsi"); + ret = tel_get_sim_imsi(handle, &imsi_info); + ERR("after tel_get_sim_imsi"); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_get_sim_imsi() : [%d]", ret); + netconfig_error_fail_get_imsi(context); + return FALSE; + } + + imsi = g_strdup_printf("%s%s%s", imsi_info.szMcc, + imsi_info.szMnc, imsi_info.szMsin); + + netconfig_complete_get_sim_imsi(wifi, context, imsi); + g_free(imsi); + + return TRUE; +} + +static void *__telephony_wifi_free_wifi_authdata( + struct wifi_authentication_data *data) +{ + if (data != NULL) { + if (data->resp_data) + g_free(data->resp_data); + if (data->authentication_key) + g_free(data->authentication_key); + if (data->cipher_data) + g_free(data->cipher_data); + if (data->integrity_data) + g_free(data->integrity_data); + + g_free(data); + data = NULL; + } + + return NULL; +} + +static void __telephony_response_aka_authentication(TapiHandle *handle, + int result, void *data, void *user_data) +{ + if (wifi_authdata != NULL) + wifi_authdata = __telephony_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifi_authentication_data, 1); + + if (wifi_authdata == NULL) { + ERR("Out of Memory!"); + return; + } + + TelSimAuthenticationResponse_t *auth_resp = + (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + + wifi_authdata->auth_result = -1; + return; + } else + wifi_authdata->auth_result = auth_resp->auth_result; + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->cipher_length = auth_resp->cipher_length; + wifi_authdata->integrity_length = auth_resp->integrity_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->cipher_data != NULL) + g_free(wifi_authdata->cipher_data); + + wifi_authdata->cipher_data = g_strdup(auth_resp->cipher_data); + + if (wifi_authdata->integrity_data != NULL) + g_free(wifi_authdata->integrity_data); + + wifi_authdata->integrity_data = g_strdup(auth_resp->integrity_data); + } else { + ERR("the result error for aka auth : [%d]", auth_resp->auth_result); + + if (auth_resp->auth_result == TAPI_SIM_AUTH_SQN_FAILURE || + auth_resp->auth_result == TAPI_SIM_AUTH_SYNCH_FAILURE) { + wifi_authdata->resp_length = auth_resp->resp_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + } + } +} + +netconfig_error_e telephony_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + int i; + int ret; + TapiHandle *handle; + TelSimAuthenticationData_t auth_data; + + if (!wifi_authdata_p) + wifi_authdata_p = data; + + if (rand_data == NULL || autn_data == NULL) + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; + + if (rand_data->len != AKA_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; + } + + if (autn_data->len != AKA_AUTN_DATA_LEN) { + ERR("wrong autn data len : [%d]", autn_data->len); + + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; + } + + if ((ret = g_array_get_element_size(autn_data)) != 1) { + ERR("wrong autn data size : [%d]", ret); + + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; + } + + memset(&auth_data, 0, sizeof(auth_data)); + + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_3G; + auth_data.rand_length = AKA_RAND_DATA_LEN; + auth_data.autn_length = AKA_AUTN_DATA_LEN; + + for (i = 0; i < rand_data->len; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + + for (i = 0; i < autn_data->len; i++) + auth_data.autn_data[i] = g_array_index(autn_data, guint8, i); + + handle = (TapiHandle *)netconfig_tel_init(); + if (handle == NULL) + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; + + ret = tel_req_sim_authentication(handle, &auth_data, + __telephony_response_aka_authentication, NULL); + + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + + return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; + } + return NETCONFIG_NO_ERROR; +} + +static void telephony_response_sim_authentication(TapiHandle *handle, + int result, void *data, void *user_data) +{ + if (wifi_authdata != NULL) + wifi_authdata = __telephony_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifi_authentication_data, 1); + + if (wifi_authdata == NULL) { + ERR("Out of Memory!"); + return; + } + + TelSimAuthenticationResponse_t *auth_resp = + (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + + wifi_authdata->auth_result = -1; + return; + } else + wifi_authdata->auth_result = auth_resp->auth_result; + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->authentication_key_length = + auth_resp->authentication_key_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->authentication_key != NULL) + g_free(wifi_authdata->authentication_key); + + wifi_authdata->authentication_key = g_strdup(auth_resp->authentication_key); + } else { + ERR("the result error for sim auth : [%d]", auth_resp->auth_result); + + wifi_authdata->resp_length = 0; + wifi_authdata->authentication_key_length = 0; + } +} + +gboolean telephony_wifi_req_sim_auth(GArray *rand_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + int i; + int ret; + TapiHandle *handle; + TelSimAuthenticationData_t auth_data; + + if (!wifi_authdata_p) + wifi_authdata_p = data; + + if (rand_data == NULL) + return FALSE; + + if (rand_data->len != SIM_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + + netconfig_error_fail_req_sim_auth_wrong_param(context); + return FALSE; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + + netconfig_error_fail_req_sim_auth_wrong_param(context); + return FALSE; + } + + memset(&auth_data, 0, sizeof(auth_data)); + + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_GSM; + auth_data.rand_length = SIM_RAND_DATA_LEN; + + for (i = 0; i < rand_data->len; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + + handle = (TapiHandle *)netconfig_tel_init(); + if (handle == NULL) { + netconfig_error_fail_req_sim_auth(context); + return FALSE; + } + + ret = tel_req_sim_authentication(handle, + &auth_data, telephony_response_sim_authentication, NULL); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + + netconfig_error_fail_req_sim_auth(context); + return FALSE; + } + + return TRUE; +} + +static void telephony_noti_sim_status_cb(TapiHandle *handle, const char *noti_id, + void *data, void *user_data) +{ + TelSimCardStatus_t *status = data; + + if (*status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + DBG("Turn Wi-Fi on automatically"); + + netconfig_wifi_power_on(); + netconfig_tel_deinit(); + } +} + +gboolean telephony_tapi_check_sim_state(void) +{ + int ret, card_changed; + TelSimCardStatus_t status = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_handle = NULL; + + tapi_handle = (TapiHandle *)netconfig_tel_init(); + if (tapi_handle == NULL) { + ERR("Failed to tapi init"); + return FALSE; + } + + ret = tel_get_sim_init_info(tapi_handle, &status, &card_changed); + if (ret != TAPI_API_SUCCESS) { + ERR("tel_get_sim_init_info() Failed : [%d]", ret); + netconfig_tel_deinit(); + return FALSE; + } + + switch (status) { + case TAPI_SIM_STATUS_UNKNOWN: + case TAPI_SIM_STATUS_CARD_ERROR: + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + case TAPI_SIM_STATUS_CARD_BLOCKED: + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + case TAPI_SIM_STATUS_SIM_INITIALIZING: + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: + tel_register_noti_event(tapi_handle, TAPI_NOTI_SIM_STATUS, + telephony_noti_sim_status_cb, NULL); + return FALSE; + default: + ERR("not defined status(%d)", status); + break; + } + + netconfig_tel_deinit(); + + return TRUE; +} + +static void __telephony_wifi_clean_authentication(void) +{ + netconfig_tel_deinit(); + + wifi_authdata = __telephony_wifi_free_wifi_authdata(wifi_authdata); +} + +gboolean telephony_wifi_get_aka_authdata(void *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + GArray *array = NULL; + guchar res_len; + + if (!wifi_authdata_p) + wifi_authdata_p = data; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + netconfig_error_fail_get_sim_auth_delay(context); + return FALSE; + } + + switch (wifi_authdata->auth_result) { + case TAPI_SIM_AUTH_NO_ERROR: + break; + + case TAPI_SIM_AUTH_SQN_FAILURE: + case TAPI_SIM_AUTH_SYNCH_FAILURE: + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + wifi_authdata->resp_length+1); + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, + wifi_authdata->resp_length); + + netconfig_complete_get_aka_auth(wifi, context, array); + g_array_free(array, TRUE); + + __telephony_wifi_clean_authentication(); + + return TRUE; + + default: + netconfig_error_fail_get_sim_auth_wrong_data(context); + __telephony_wifi_clean_authentication(); + return FALSE; + } + + if ((wifi_authdata->resp_length >= AKA_AUTH_RES_MIN_LEN || + wifi_authdata->resp_length <= AKA_AUTH_RES_MAX_LEN) && + wifi_authdata->cipher_length == AKA_AUTH_CK_LEN && + wifi_authdata->integrity_length == AKA_AUTH_IK_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + wifi_authdata->resp_length+AKA_AUTH_CK_LEN+AKA_AUTH_IK_LEN+1); + + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, + wifi_authdata->resp_length); + g_array_append_vals(array, wifi_authdata->cipher_data, + AKA_AUTH_CK_LEN); + g_array_append_vals(array, wifi_authdata->integrity_data, + AKA_AUTH_IK_LEN); + } else { + ERR("auth data length is wrong, res = [%d], Kc = [%d], Ki = [%d]", + wifi_authdata->resp_length, wifi_authdata->cipher_length, + wifi_authdata->integrity_length); + + netconfig_error_fail_get_sim_auth_wrong_data(context); + __telephony_wifi_clean_authentication(); + return FALSE; + } + + netconfig_complete_get_aka_auth(wifi, context, array); + g_array_free(array, TRUE); + __telephony_wifi_clean_authentication(); + + return TRUE; +} + +gboolean telephony_wifi_get_sim_authdata(void *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + GArray *array = NULL; + + if (!wifi_authdata_p) + wifi_authdata_p = data; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + netconfig_error_fail_get_sim_auth_delay(context); + return FALSE; + } + + if (wifi_authdata->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + if (wifi_authdata->resp_length == SIM_AUTH_SRES_LEN && + wifi_authdata->authentication_key_length == SIM_AUTH_KC_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + SIM_AUTH_SRES_LEN+SIM_AUTH_KC_LEN); + g_array_append_vals(array, wifi_authdata->resp_data, + SIM_AUTH_SRES_LEN); + g_array_append_vals(array, wifi_authdata->authentication_key, + SIM_AUTH_KC_LEN); + } else { + ERR("auth data length is wrong, SRES = [%d], Kc = [%d]", + wifi_authdata->resp_length, + wifi_authdata->authentication_key_length); + netconfig_error_fail_get_sim_auth_wrong_data(context); + __telephony_wifi_clean_authentication(); + return FALSE; + } + } else { + ERR("failed auth result = [%d]", wifi_authdata->auth_result); + netconfig_error_fail_get_sim_auth_wrong_data(context); + __telephony_wifi_clean_authentication(); + return FALSE; + } + + netconfig_complete_get_sim_auth(wifi, context, array); + g_array_free(array, TRUE); + __telephony_wifi_clean_authentication(); + return TRUE; +} + + +extern struct netconfig_telephony_plugin_t netconfig_telephony_plugin + __attribute__ ((visibility("default"))); +struct netconfig_telephony_plugin_t netconfig_telephony_plugin = { + telephony_get_network_type, + telephony_wifi_get_sim_imsi, + telephony_wifi_req_aka_auth, + telephony_wifi_req_sim_auth, + telephony_tapi_check_sim_state, + telephony_wifi_get_aka_authdata, + telephony_wifi_get_sim_authdata +}; + diff --git a/src/neterror.c b/src/neterror.c index 0e3113d..bcec816 100755 --- a/src/neterror.c +++ b/src/neterror.c @@ -102,7 +102,7 @@ void netconfig_error_wifi_direct_failed(GDBusMethodInvocation *context) NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed"); } -void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context) +EXPORT_SYM void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context) { ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), @@ -110,7 +110,7 @@ void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context) NETCONFIG_ERROR_INTERFACE".FailGetSimImsi"); } -void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context) +EXPORT_SYM void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context) { ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), @@ -118,7 +118,7 @@ void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context) NETCONFIG_ERROR_INTERFACE".FailReqSimAuth"); } -void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context) +EXPORT_SYM void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context) { ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), @@ -126,7 +126,7 @@ void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *contex NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam"); } -void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context) +EXPORT_SYM void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context) { ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), @@ -134,7 +134,7 @@ void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData"); } -void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context) +EXPORT_SYM void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context) { ERR("dbus method return error"); g_dbus_method_invocation_return_error(context, netconfig_error_quark(), diff --git a/src/network-state.c b/src/network-state.c index 00c8cc2..cc6a608 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include "log.h" #include "util.h" @@ -40,7 +38,6 @@ #include "network-dpm.h" #include "network-monitor.h" #include "netsupplicant.h" -#include "wifi-tel-intf.h" #include "generated-code.h" /* Define TCP buffer sizes for various networks */ @@ -322,19 +319,9 @@ static void __netconfig_adjust_tcp_buffer_size(void) rmax_size = NET_TCP_BUFFERSIZE_WIFI_RMEM_MAX; wmax_size = NET_TCP_BUFFERSIZE_WIFI_WMEM_MAX; } else if (netconfig_is_cellular_profile(profile) == TRUE) { - TapiHandle *tapi_handle = NULL; int telephony_svctype = 0, telephony_pstype = 0; - tapi_handle = (TapiHandle *)netconfig_tel_init(); - if (NULL != tapi_handle) { - tel_get_property_int(tapi_handle, - TAPI_PROP_NETWORK_SERVICE_TYPE, - &telephony_svctype); - tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PS_TYPE, - &telephony_pstype); - netconfig_tel_deinit(); - } - + netconfig_get_telephony_network_type(&telephony_svctype, &telephony_pstype); DBG("Default cellular %d, %d", telephony_svctype, telephony_pstype); switch (telephony_pstype) { diff --git a/src/utils/log.c b/src/utils/log.c index 0564afb..a93c677 100755 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -26,6 +26,7 @@ #include #include "log.h" +#include "neterror.h" #define LOG_FILE_PATH "/opt/usr/data/network/netconfig.log" #define MAX_LOG_SIZE 1 * 1024 * 1024 @@ -87,7 +88,7 @@ static inline void __netconfig_log_get_local_time(char *strtime, const int size) strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm); } -void netconfig_log(const char *format, ...) +EXPORT_SYM void netconfig_log(const char *format, ...) { va_list ap; int log_size = 0; @@ -128,7 +129,7 @@ void netconfig_log(const char *format, ...) va_end(ap); } -void log_cleanup(void) +EXPORT_SYM void log_cleanup(void) { if (log_file == NULL) return; diff --git a/src/utils/util.c b/src/utils/util.c index 495567d..107b86f 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -46,6 +46,7 @@ #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address" #define MAC_ADDRESS_MAX_LEN 18 #define HEADED_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-headed.so" +#define TELEPHONY_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-telephony.so" static gboolean netconfig_device_picker_test = FALSE; static int mdnsd_ref_count = 0; @@ -55,8 +56,11 @@ typedef struct { } dnssd_conn_destroy_data; static gboolean netconfig_plugin_headed_enabled = FALSE; +static gboolean netconfig_plugin_telephony_enabled = FALSE; static void *handle_headed; +static void *handle_telephony; static struct netconfig_headed_plugin_t *headed_plugin; +static struct netconfig_telephony_plugin_t *telephony_plugin; GKeyFile *netconfig_keyfile_load(const char *pathname) { @@ -861,6 +865,12 @@ static void register_dnssd_conn_destroy_signal(gchar *name) } data = g_try_malloc0(sizeof(dnssd_conn_destroy_data)); + + if (data == NULL) { + ERR("Out of Memory!"); + return; + } + data->conn_name = g_strdup(name); data->conn_id = g_dbus_connection_signal_subscribe(connection, @@ -947,6 +957,87 @@ void __netconfig_pop_wifi_connected_poppup(const char *ssid) headed_plugin->pop_wifi_connected_poppup(ssid); } +void netconfig_get_telephony_network_type(int *svctype, int *pstype) +{ + if (!netconfig_plugin_telephony_enabled) + return; + + if (!telephony_plugin) + return; + + telephony_plugin->get_telephony_network_type(svctype, pstype); +} + +gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context) +{ + if (!netconfig_plugin_telephony_enabled) + return FALSE; + + if (!telephony_plugin) + return FALSE; + + return telephony_plugin->wifi_get_sim_imsi(wifi, context); +} + +netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + if (!netconfig_plugin_telephony_enabled) + return NETCONFIG_ERROR_INTERNAL; + + if (!telephony_plugin) + return NETCONFIG_ERROR_INTERNAL; + + return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data); +} + +gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + if (!netconfig_plugin_telephony_enabled) + return FALSE; + + if (!telephony_plugin) + return FALSE; + + return telephony_plugin->wifi_req_sim_auth(rand_data, context, data); +} + +gboolean netconfig_tapi_check_sim_state(void) +{ + if (!netconfig_plugin_telephony_enabled) + return FALSE; + + if (!telephony_plugin) + return FALSE; + + return telephony_plugin->tapi_check_sim_state(); +} + +gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + if (!netconfig_plugin_telephony_enabled) + return FALSE; + + if (!telephony_plugin) + return FALSE; + + return telephony_plugin->wifi_get_aka_authdata(wifi, context, data); +} + +gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi, + GDBusMethodInvocation *context, struct wifi_authentication_data **data) +{ + if (!netconfig_plugin_telephony_enabled) + return FALSE; + + if (!telephony_plugin) + return FALSE; + + return telephony_plugin->wifi_get_sim_authdata(wifi, context, data); +} + void netconfig_set_vconf_int(const char * key, int value) { int ret = 0; @@ -1105,26 +1196,41 @@ void netconfig_plugin_init() handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW); if (!handle_headed) { ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror()); - return; + } else { + headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin"); + if (!headed_plugin) { + ERR("Can't load symbol: %s", dlerror()); + dlclose(handle_headed); + } else { + netconfig_plugin_headed_enabled = TRUE; + } } - headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin"); - if (!headed_plugin) { - ERR("Can't load symbol: %s", dlerror()); - dlclose(handle_headed); - return; + handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW); + if (!handle_telephony) { + ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror()); + } else { + telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin"); + if (!telephony_plugin) { + ERR("Can't load symbol: %s", dlerror()); + dlclose(handle_telephony); + } else { + netconfig_plugin_telephony_enabled = TRUE; + } } - - netconfig_plugin_headed_enabled = TRUE; } void netconfig_plugin_deinit() { - if (!netconfig_plugin_headed_enabled) - return; + if (netconfig_plugin_headed_enabled) { + netconfig_plugin_headed_enabled = FALSE; + dlclose(handle_headed); + } - netconfig_plugin_headed_enabled = FALSE; - dlclose(handle_headed); + if (netconfig_plugin_telephony_enabled) { + netconfig_plugin_telephony_enabled = FALSE; + dlclose(handle_telephony); + } } gboolean netconfig_get_headed_plugin_flag() @@ -1132,3 +1238,8 @@ gboolean netconfig_get_headed_plugin_flag() return netconfig_plugin_headed_enabled; } +gboolean netconfig_get_telephony_plugin_flag() +{ + return netconfig_plugin_telephony_enabled; +} + diff --git a/src/wifi-eap.c b/src/wifi-eap.c index 24dc0de..f71b35c 100755 --- a/src/wifi-eap.c +++ b/src/wifi-eap.c @@ -21,412 +21,11 @@ #include "util.h" #include "netdbus.h" #include "neterror.h" -#include "wifi-tel-intf.h" #include "network-state.h" #include "wifi-eap.h" +#include "wifi-power.h" -#define SIM_RAND_DATA_LEN 16 -#define SIM_AUTH_MAX_RESP_DATA_LEN 128 -#define SIM_AUTH_SRES_LEN 4 -#define SIM_AUTH_KC_LEN 8 - -#define AKA_RAND_DATA_LEN 16 -#define AKA_AUTN_DATA_LEN 16 -#define AKA_AUTH_RES_MAX_LEN 16 -#define AKA_AUTH_RES_MIN_LEN 4 -#define AKA_AUTH_CK_LEN 16 -#define AKA_AUTH_IK_LEN 16 - -struct wifii_authentication_data { - int auth_result; - int resp_length; - int authentication_key_length; - int cipher_length; - int integrity_length; - char *resp_data; - char *authentication_key; - char *cipher_data; - char *integrity_data; -}; - -static struct wifii_authentication_data *wifi_authdata; - -static void *__netconfig_wifi_free_wifi_authdata( - struct wifii_authentication_data *data) -{ - if (data != NULL) { - if (data->resp_data) - g_free(data->resp_data); - if (data->authentication_key) - g_free(data->authentication_key); - if (data->cipher_data) - g_free(data->cipher_data); - if (data->integrity_data) - g_free(data->integrity_data); - - g_free(data); - data = NULL; - } - - return NULL; -} - -static void __netconfig_wifi_clean_authentication(void) -{ - netconfig_tel_deinit(); - - wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); -} - -static gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, - GDBusMethodInvocation *context) -{ - int ret; - TapiHandle *handle; - TelSimImsiInfo_t imsi_info; - char *imsi; - - handle = (TapiHandle *)netconfig_tel_init(); - if (handle == NULL) { - ERR("tapi_init failed"); - netconfig_error_fail_get_imsi(context); - return FALSE; - } - - ERR("before tel_get_sim_imsi"); - ret = tel_get_sim_imsi(handle, &imsi_info); - ERR("after tel_get_sim_imsi"); - if (ret != TAPI_API_SUCCESS) { - ERR("Failed tel_get_sim_imsi() : [%d]", ret); - netconfig_error_fail_get_imsi(context); - return FALSE; - } - - imsi = g_strdup_printf("%s%s%s", imsi_info.szMcc, - imsi_info.szMnc, imsi_info.szMsin); - - wifi_complete_get_sim_imsi(wifi, context, imsi); - g_free(imsi); - - return TRUE; -} - -void __netconfig_response_sim_authentication(TapiHandle *handle, - int result, void *data, void *user_data) -{ - if (wifi_authdata != NULL) - wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); - - wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); - - TelSimAuthenticationResponse_t *auth_resp = - (TelSimAuthenticationResponse_t *) data; - if (auth_resp == NULL) { - ERR("the auth response is NULL"); - - wifi_authdata->auth_result = -1; - return; - } else - wifi_authdata->auth_result = auth_resp->auth_result; - - if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { - wifi_authdata->resp_length = auth_resp->resp_length; - wifi_authdata->authentication_key_length = - auth_resp->authentication_key_length; - - if (wifi_authdata->resp_data != NULL) - g_free(wifi_authdata->resp_data); - - wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); - - if (wifi_authdata->authentication_key != NULL) - g_free(wifi_authdata->authentication_key); - - wifi_authdata->authentication_key = - g_strdup(auth_resp->authentication_key); - } else { - ERR("the result error for sim auth : [%d]", auth_resp->auth_result); - - wifi_authdata->resp_length = 0; - wifi_authdata->authentication_key_length = 0; - } -} - -void __netconfig_response_aka_authentication(TapiHandle *handle, - int result, void *data, void *user_data) -{ - if (wifi_authdata != NULL) - wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); - - wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); - - TelSimAuthenticationResponse_t *auth_resp = - (TelSimAuthenticationResponse_t *) data; - if (auth_resp == NULL) { - ERR("the auth response is NULL"); - - wifi_authdata->auth_result = -1; - return; - } else - wifi_authdata->auth_result = auth_resp->auth_result; - - if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { - wifi_authdata->resp_length = auth_resp->resp_length; - wifi_authdata->cipher_length = auth_resp->cipher_length; - wifi_authdata->integrity_length = auth_resp->integrity_length; - - if (wifi_authdata->resp_data != NULL) - g_free(wifi_authdata->resp_data); - - wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); - - if (wifi_authdata->cipher_data != NULL) - g_free(wifi_authdata->cipher_data); - - wifi_authdata->cipher_data = g_strdup(auth_resp->cipher_data); - - if (wifi_authdata->integrity_data != NULL) - g_free(wifi_authdata->integrity_data); - - wifi_authdata->integrity_data = g_strdup(auth_resp->integrity_data); - } else { - ERR("the result error for aka auth : [%d]", auth_resp->auth_result); - - if (auth_resp->auth_result == TAPI_SIM_AUTH_SQN_FAILURE || - auth_resp->auth_result == TAPI_SIM_AUTH_SYNCH_FAILURE) { - wifi_authdata->resp_length = auth_resp->resp_length; - - if (wifi_authdata->resp_data != NULL) - g_free(wifi_authdata->resp_data); - - wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); - } - } -} - -static gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, - GDBusMethodInvocation *context) -{ - int i; - int ret; - TapiHandle *handle; - TelSimAuthenticationData_t auth_data; - - if (rand_data == NULL) - return FALSE; - - if (rand_data->len != SIM_RAND_DATA_LEN) { - ERR("wrong rand data len : [%d]", rand_data->len); - - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; - } - - if ((ret = g_array_get_element_size(rand_data)) != 1) { - ERR("wrong rand data size : [%d]", ret); - - netconfig_error_fail_req_sim_auth_wrong_param(context); - return FALSE; - } - - memset(&auth_data, 0, sizeof(auth_data)); - - auth_data.auth_type = TAPI_SIM_AUTH_TYPE_GSM; - auth_data.rand_length = SIM_RAND_DATA_LEN; - - for (i = 0; i < rand_data->len; i++) - auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); - - handle = (TapiHandle *)netconfig_tel_init(); - if (handle == NULL) { - netconfig_error_fail_req_sim_auth(context); - return FALSE; - } - - ret = tel_req_sim_authentication(handle, - &auth_data, __netconfig_response_sim_authentication, NULL); - if (ret != TAPI_API_SUCCESS) { - ERR("Failed tel_req_sim_authentication() : [%d]", ret); - - netconfig_error_fail_req_sim_auth(context); - return FALSE; - } - - return TRUE; -} - -static netconfig_error_e __netconfig_wifi_req_aka_auth( - GArray *rand_data, GArray *autn_data, GDBusMethodInvocation *context) -{ - int i; - int ret; - TapiHandle *handle; - TelSimAuthenticationData_t auth_data; - - if (rand_data == NULL || autn_data == NULL) - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; - - if (rand_data->len != AKA_RAND_DATA_LEN) { - ERR("wrong rand data len : [%d]", rand_data->len); - - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; - } - - if (autn_data->len != AKA_AUTN_DATA_LEN) { - ERR("wrong autn data len : [%d]", autn_data->len); - - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; - } - - if ((ret = g_array_get_element_size(rand_data)) != 1) { - ERR("wrong rand data size : [%d]", ret); - - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; - } - - if ((ret = g_array_get_element_size(autn_data)) != 1) { - ERR("wrong autn data size : [%d]", ret); - - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM; - } - - memset(&auth_data, 0, sizeof(auth_data)); - - auth_data.auth_type = TAPI_SIM_AUTH_TYPE_3G; - auth_data.rand_length = AKA_RAND_DATA_LEN; - auth_data.autn_length = AKA_AUTN_DATA_LEN; - - for (i = 0; i < rand_data->len; i++) - auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); - - for (i = 0; i < autn_data->len; i++) - auth_data.autn_data[i] = g_array_index(autn_data, guint8, i); - - handle = (TapiHandle *)netconfig_tel_init(); - if (handle == NULL) - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; - - ret = tel_req_sim_authentication(handle, &auth_data, - __netconfig_response_aka_authentication, NULL); - - if (ret != TAPI_API_SUCCESS) { - ERR("Failed tel_req_sim_authentication() : [%d]", ret); - - return NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH; - } - return NETCONFIG_NO_ERROR; -} - -static gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi, - GDBusMethodInvocation *context) -{ - GArray *array = NULL; - - if (wifi_authdata == NULL) { - DBG("the status error : no response yet"); - netconfig_error_fail_get_sim_auth_delay(context); - return FALSE; - } - - if (wifi_authdata->auth_result == TAPI_SIM_AUTH_NO_ERROR) { - if (wifi_authdata->resp_length == SIM_AUTH_SRES_LEN && - wifi_authdata->authentication_key_length == SIM_AUTH_KC_LEN) { - array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), - SIM_AUTH_SRES_LEN+SIM_AUTH_KC_LEN); - g_array_append_vals(array, wifi_authdata->resp_data, - SIM_AUTH_SRES_LEN); - g_array_append_vals(array, wifi_authdata->authentication_key, - SIM_AUTH_KC_LEN); - } else { - ERR("auth data length is wrong, SRES = [%d], Kc = [%d]", - wifi_authdata->resp_length, - wifi_authdata->authentication_key_length); - netconfig_error_fail_get_sim_auth_wrong_data(context); - __netconfig_wifi_clean_authentication(); - return FALSE; - } - } else { - ERR("failed auth result = [%d]", wifi_authdata->auth_result); - netconfig_error_fail_get_sim_auth_wrong_data(context); - __netconfig_wifi_clean_authentication(); - return FALSE; - } - - wifi_complete_get_sim_auth(wifi, context, array->data); - g_array_free(array, TRUE); - __netconfig_wifi_clean_authentication(); - return TRUE; -} - -static gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi, GDBusMethodInvocation *context) -{ - GArray *array = NULL; - guchar res_len; - - if (wifi_authdata == NULL) { - DBG("the status error : no response yet"); - netconfig_error_fail_get_sim_auth_delay(context); - return FALSE; - } - - switch (wifi_authdata->auth_result) { - case TAPI_SIM_AUTH_NO_ERROR: - break; - - case TAPI_SIM_AUTH_SQN_FAILURE: - case TAPI_SIM_AUTH_SYNCH_FAILURE: - array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), - wifi_authdata->resp_length+1); - res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); - - g_array_append_vals(array, &res_len, 1); - g_array_append_vals(array, wifi_authdata->resp_data, - wifi_authdata->resp_length); - - wifi_complete_get_aka_auth(wifi, context, array->data); - g_array_free(array, TRUE); - - __netconfig_wifi_clean_authentication(); - - return TRUE; - - default: - netconfig_error_fail_get_sim_auth_wrong_data(context); - __netconfig_wifi_clean_authentication(); - return FALSE; - } - - if ((wifi_authdata->resp_length >= AKA_AUTH_RES_MIN_LEN || - wifi_authdata->resp_length <= AKA_AUTH_RES_MAX_LEN) && - wifi_authdata->cipher_length == AKA_AUTH_CK_LEN && - wifi_authdata->integrity_length == AKA_AUTH_IK_LEN) { - array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), - wifi_authdata->resp_length+AKA_AUTH_CK_LEN+AKA_AUTH_IK_LEN+1); - - res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); - g_array_append_vals(array, &res_len, 1); - g_array_append_vals(array, wifi_authdata->resp_data, - wifi_authdata->resp_length); - g_array_append_vals(array, wifi_authdata->cipher_data, - AKA_AUTH_CK_LEN); - g_array_append_vals(array, wifi_authdata->integrity_data, - AKA_AUTH_IK_LEN); - } else { - ERR("auth data length is wrong, res = [%d], Kc = [%d], Ki = [%d]", - wifi_authdata->resp_length, wifi_authdata->cipher_length, - wifi_authdata->integrity_length); - - netconfig_error_fail_get_sim_auth_wrong_data(context); - __netconfig_wifi_clean_authentication(); - return FALSE; - } - - wifi_complete_get_aka_auth(wifi, context, array->data); - g_array_free(array, TRUE); - __netconfig_wifi_clean_authentication(); - - return TRUE; -} +static struct wifi_authentication_data *wifi_authdata; gboolean handle_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context) { @@ -470,7 +69,7 @@ gboolean handle_req_sim_auth(Wifi *wifi, GDBusMethodInvocation *context, GVarian g_free(out_auth_data); rand_data_garray->len = length; - result = __netconfig_wifi_req_sim_auth(rand_data_garray, context); + result = __netconfig_wifi_req_sim_auth(rand_data_garray, context, &wifi_authdata); g_array_free(rand_data_garray, FALSE); if (result) @@ -524,7 +123,7 @@ gboolean handle_req_aka_auth(Wifi *wifi, GDBusMethodInvocation *context, GVarian g_free(out_auth_data); autn_data_garray->len = length; - ret = __netconfig_wifi_req_aka_auth(rand_data_garray, autn_data_garray, context); + ret = __netconfig_wifi_req_aka_auth(rand_data_garray, autn_data_garray, context, &wifi_authdata); if (ret == NETCONFIG_NO_ERROR) { result = TRUE; wifi_complete_req_aka_auth(wifi, context, result); @@ -550,7 +149,7 @@ gboolean handle_get_sim_auth(Wifi *wifi, GDBusMethodInvocation *context) g_return_val_if_fail(wifi != NULL, FALSE); - ret = __netconfig_wifi_get_sim_authdata(wifi, context); + ret = __netconfig_wifi_get_sim_authdata(wifi, context, &wifi_authdata); return ret; } @@ -562,7 +161,31 @@ gboolean handle_get_aka_auth(Wifi *wifi, GDBusMethodInvocation *context) g_return_val_if_fail(wifi != NULL, FALSE); - ret = __netconfig_wifi_get_aka_authdata(wifi, context); + ret = __netconfig_wifi_get_aka_authdata(wifi, context, &wifi_authdata); return ret; } + +EXPORT_SYM void netconfig_complete_get_sim_imsi(void *wifi, GDBusMethodInvocation *context, char *imsi) +{ + wifi_complete_get_sim_imsi((Wifi*)wifi, context, imsi); +} + +EXPORT_SYM void netconfig_complete_get_aka_auth(void *wifi, GDBusMethodInvocation *context, GArray *array) +{ + wifi_complete_get_aka_auth((Wifi*)wifi, context, array->data); +} + +EXPORT_SYM void netconfig_complete_get_sim_auth(void *wifi, GDBusMethodInvocation *context, GArray *array) +{ + wifi_complete_get_sim_auth((Wifi*)wifi, context, array->data); +} + +EXPORT_SYM void netconfig_wifi_power_on() +{ +#if defined TIZEN_WEARABLE + wifi_power_on_wearable(TRUE); +#else + wifi_power_on(); +#endif +} diff --git a/src/wifi-power.c b/src/wifi-power.c index da4a615..72b8673 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -20,8 +20,6 @@ #include #include #include -#include -#include #include #include #include @@ -38,7 +36,6 @@ #include "wifi-wps.h" #include "wifi-power.h" #include "wifi-state.h" -#include "wifi-tel-intf.h" #include "netsupplicant.h" #include "network-state.h" #include "network-dpm.h" @@ -634,69 +631,6 @@ static void __pm_state_changed_cb(keynode_t* node, void* user_data) prev_state = new_state; } -static void _tapi_noti_sim_status_cb(TapiHandle *handle, const char *noti_id, - void *data, void *user_data) -{ - TelSimCardStatus_t *status = data; - - if (*status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { - DBG("Turn Wi-Fi on automatically"); -#if defined TIZEN_WEARABLE - wifi_power_on_wearable(TRUE); -#else - wifi_power_on(); -#endif - netconfig_tel_deinit(); - } -} - -static gboolean netconfig_tapi_check_sim_state(void) -{ - int ret, card_changed; - TelSimCardStatus_t status = TAPI_SIM_STATUS_UNKNOWN; - TapiHandle *tapi_handle = NULL; - - tapi_handle = (TapiHandle *)netconfig_tel_init(); - if (tapi_handle == NULL) { - ERR("Failed to tapi init"); - return FALSE; - } - - ret = tel_get_sim_init_info(tapi_handle, &status, &card_changed); - if (ret != TAPI_API_SUCCESS) { - ERR("tel_get_sim_init_info() Failed : [%d]", ret); - netconfig_tel_deinit(); - return FALSE; - } - - switch (status) { - case TAPI_SIM_STATUS_UNKNOWN: - case TAPI_SIM_STATUS_CARD_ERROR: - case TAPI_SIM_STATUS_CARD_NOT_PRESENT: - case TAPI_SIM_STATUS_CARD_BLOCKED: - case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: - break; - case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: - case TAPI_SIM_STATUS_SIM_INITIALIZING: - case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: - case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: - case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: - case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: - case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: - case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: - tel_register_noti_event(tapi_handle, TAPI_NOTI_SIM_STATUS, - _tapi_noti_sim_status_cb, NULL); - return FALSE; - default: - ERR("not defined status(%d)", status); - break; - } - - netconfig_tel_deinit(); - - return TRUE; -} - static void __netconfig_telephony_ready_changed_cb(keynode_t * node, void *data) { int telephony_ready = 0; diff --git a/src/wifi-tel-intf.c b/src/wifi-tel-intf.c deleted file mode 100755 index 8a74aa9..0000000 --- a/src/wifi-tel-intf.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include - -#include "log.h" -#include "wifi-tel-intf.h" - -#define TAPI_HANDLE_MAX 2 - -#define SIM_SLOT_DUAL 2 -#define SIM_SLOT_SINGLE 1 - -#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE "db/telephony/dualsim/default_data_service" -#define DEFAULT_DATA_SERVICE_SIM1 0 -#define DEFAULT_DATA_SERVICE_SIM2 1 - -static TapiHandle *tapi_handle_dual[TAPI_HANDLE_MAX+1]; -static TapiHandle *tapi_handle = NULL; - -static int _check_current_sim() -{ -#if defined TIZEN_WEARABLE - return -1; -#else - int current_sim = 0; - int sim_slot_count = 0; - - if ((vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) - || sim_slot_count == SIM_SLOT_SINGLE) { - ERR("failed to get sim slot count (%d)", sim_slot_count); - return -1; - } - - if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, ¤t_sim) != 0) { - ERR("failed to get default data service = %d\n", current_sim); - return 0; - } - - DBG("default data service [SIM%d]", current_sim); - return current_sim; -#endif -} - -TapiHandle * netconfig_tel_init(void) -{ - char **cp_list = NULL; - int current_sim = _check_current_sim(); - - if (current_sim < 0) { - if (tapi_handle == NULL) { - tapi_handle = tel_init(NULL); - if (tapi_handle == NULL) - ERR("tel_init() Failed - modem %d", current_sim); - } - return tapi_handle; - } else { - if (tapi_handle_dual[current_sim] == NULL) { - cp_list = tel_get_cp_name_list(); - if (!cp_list) { - ERR("tel_get_cp_name_list() Failed"); - return NULL; - } - - tapi_handle_dual[current_sim] = tel_init(cp_list[current_sim]); - if (tapi_handle_dual[current_sim] == NULL) - ERR("tel_init() Failed - modem %d", current_sim); - - g_strfreev(cp_list); - } - return tapi_handle_dual[current_sim]; - } -} - -void netconfig_tel_deinit(void) -{ - int current_sim = _check_current_sim(); - - if (current_sim < 0) { - if (tapi_handle) - tel_deinit(tapi_handle); - - tapi_handle = NULL; - } else { - unsigned int i = 0; - while (tapi_handle_dual[i]) { - tel_deinit(tapi_handle_dual[i]); - tapi_handle_dual[i] = NULL; - i++; - } - } -} - -- 2.7.4