Added wifi formware download for sprd board
[platform/core/connectivity/net-config.git] / src / wifi-tel-intf.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include <vconf.h>
20
21 #include "log.h"
22 #include "wifi-tel-intf.h"
23
24 #define TAPI_HANDLE_MAX 2
25
26 #define SIM_SLOT_DUAL 2
27 #define SIM_SLOT_SINGLE 1
28
29 #define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE    "db/telephony/dualsim/default_data_service"
30 #define DEFAULT_DATA_SERVICE_SIM1 0
31 #define DEFAULT_DATA_SERVICE_SIM2 1
32
33 static TapiHandle *tapi_handle_dual[TAPI_HANDLE_MAX+1];
34 static TapiHandle *tapi_handle = NULL;
35
36 static int _check_current_sim()
37 {
38 #if defined TIZEN_WEARABLE
39         return -1;
40 #else
41         int current_sim = 0;
42         int sim_slot_count = 0;
43
44         if ((vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0)
45                 || sim_slot_count == SIM_SLOT_SINGLE) {
46                 ERR("failed to get sim slot count (%d)", sim_slot_count);
47                 return -1;
48         }
49
50         if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &current_sim) != 0) {
51                 ERR("failed to get default data service = %d\n", current_sim);
52                 return 0;
53         }
54
55         DBG("default data service [SIM%d]", current_sim);
56         return current_sim;
57 #endif
58 }
59
60 TapiHandle * netconfig_tel_init(void)
61 {
62         char **cp_list = NULL;
63         int current_sim = _check_current_sim();
64
65         if (current_sim < 0) {
66                 if (tapi_handle == NULL) {
67                         tapi_handle = tel_init(NULL);
68                         if (tapi_handle == NULL)
69                                 ERR("tel_init() Failed - modem %d", current_sim);
70                 }
71                 return tapi_handle;
72         } else {
73                 if (tapi_handle_dual[current_sim] == NULL) {
74                         cp_list = tel_get_cp_name_list();
75                         if (!cp_list) {
76                                 ERR("tel_get_cp_name_list() Failed");
77                                 return NULL;
78                         }
79
80                         tapi_handle_dual[current_sim] = tel_init(cp_list[current_sim]);
81                         if (tapi_handle_dual[current_sim] == NULL)
82                                 ERR("tel_init() Failed - modem %d", current_sim);
83
84                         g_strfreev(cp_list);
85                 }
86                 return tapi_handle_dual[current_sim];
87         }
88 }
89
90 void netconfig_tel_deinit(void)
91 {
92         int current_sim = _check_current_sim();
93
94         if (current_sim < 0) {
95                 if (tapi_handle)
96                         tel_deinit(tapi_handle);
97
98                 tapi_handle = NULL;
99         } else {
100                 unsigned int i = 0;
101                 while (tapi_handle_dual[i]) {
102                         tel_deinit(tapi_handle_dual[i]);
103                         tapi_handle_dual[i] = NULL;
104                         i++;
105                 }
106         }
107 }
108