Fix null dereferencing and unchecked return value
[platform/core/api/connection.git] / include / net_connection_private.h
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __NET_CONNECTION_PRIVATE_H__
18 #define __NET_CONNECTION_PRIVATE_H__
19
20 #include <dlog.h>
21 #include <network-cm-intf.h>
22 #include <network-wifi-intf.h>
23
24 #include "net_connection.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30 #undef LOG_TAG
31 #define LOG_TAG "CAPI_NETWORK_CONNECTION"
32
33 #define CONNECTION_INFO         1
34 #define CONNECTION_ERROR        2
35 #define CONNECTION_WARN         3
36
37 #define CONNECTION_MAC_INFO_LENGTH      17
38 #define ETHERNET_MAC_INFO_FILE          "/sys/class/net/eth0/address"
39 #define WIFI_MAC_INFO_FILE                      "/sys/class/net/wlan0/address"
40
41 #define TELEPHONY_FEATURE                       "http://tizen.org/feature/network.telephony"
42 #define WIFI_FEATURE                            "http://tizen.org/feature/network.wifi"
43 #define TETHERING_BLUETOOTH_FEATURE     "http://tizen.org/feature/network.tethering.bluetooth"
44 #define ETHERNET_FEATURE                        "http://tizen.org/feature/network.ethernet"
45 #define ROUTE_FEATURE                           "http://tizen.org/feature/network.route"
46
47 typedef enum {
48         CONNECTION_CELLULAR_SUBSCRIBER_1 = 0x00,
49         CONNECTION_CELLULAR_SUBSCRIBER_2 = 0x01,
50 } connection_cellular_subscriber_id_e;
51
52 typedef enum {
53         CONNECTION_SUPPORTED_FEATURE_TELEPHONY,
54         CONNECTION_SUPPORTED_FEATURE_WIFI,
55         CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH,
56         CONNECTION_SUPPORTED_FEATURE_ETHERNET,
57         CONNECTION_SUPPORTED_FEATURE_ROUTE,
58         CONNECTION_SUPPORTED_FEATURE_MAX,
59 } connection_supported_feature_e;
60
61 #define CONN_LOCK \
62         do { \
63                 _connection_lock(); \
64         } while (0)
65
66 #define CONN_UNLOCK \
67         do { \
68                 _connection_unlock(); \
69         } while (0)
70
71 #define CHECK_FEATURE_SUPPORTED(...) \
72         do { \
73                 int rv = _connection_check_feature_supported(__VA_ARGS__, NULL); \
74                 if (rv != CONNECTION_ERROR_NONE) { \
75                         CONN_UNLOCK; \
76                         return rv; \
77                 } \
78         } while (0)
79
80 #define DEPRECATED_LOG(origin, substitution) \
81         do { \
82                 LOGW("DEPRECATION WARNING: %s() is deprecated and will be removed " \
83                                 "from next release. Use %s() instead", origin, substitution); \
84         } while (0)
85
86 #define CONNECTION_LOG(log_level, format, args...) \
87         do { \
88                 switch (log_level) { \
89                 case CONNECTION_ERROR: \
90                         LOGE(format, ## args); \
91                         break; \
92                 case CONNECTION_WARN: \
93                         LOGW(format, ## args); \
94                         break; \
95                 default: \
96                         LOGI(format, ## args); \
97                 } \
98         } while (0)
99
100 #define SECURE_CONNECTION_LOG(log_level, format, args...) \
101         do { \
102                 switch (log_level) { \
103                 case CONNECTION_ERROR: \
104                         SECURE_LOGE(format, ## args); \
105                         break; \
106                 case CONNECTION_WARN: \
107                         SECURE_LOGW(format, ## args); \
108                         break; \
109                 default: \
110                         SECURE_LOGI(format, ## args); \
111                 } \
112         } while (0)
113
114 #define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE \
115                         "db/telephony/dualsim/default_data_service"
116
117 typedef struct _connection_handle_s {
118         connection_type_changed_cb type_changed_callback;
119         connection_address_changed_cb ip_changed_callback;
120         connection_address_changed_cb proxy_changed_callback;
121         connection_internet_state_changed_cb internet_state_changed_callback;
122         connection_ethernet_cable_state_changed_cb ethernet_cable_state_changed_callback;
123         connection_dhcp_state_changed_cb dhcp_state_changed_callback;
124         connection_set_default_cb set_default_callback;
125         connection_opened_cb opened_callback;
126         connection_closed_cb closed_callback;
127         connection_opened_cb reset_callback;
128         void *type_changed_user_data;
129         void *ip_changed_user_data;
130         void *proxy_changed_user_data;
131         void *internet_state_changed_user_data;
132         void *ethernet_cable_state_changed_user_data;
133         void *dhcp_state_changed_user_data;
134         void *set_default_user_data;
135         void *opened_user_data;
136         void *closed_user_data;
137         void *reset_user_data;
138
139         void *network_info_handle;
140         int refcount;
141 } connection_handle_s;
142
143 char *_connection_vconf_get_str(connection_handle_s *conn_handle, const char *key);
144 int _connection_vconf_get_int(connection_handle_s *conn_handle, const char *key, int *value);
145 int _connection_vconf_get_bool(connection_handle_s *conn_handle, const char *key, int *value);
146
147 int _connection_libnet_init(connection_handle_s *conn_handle);
148 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty);
149 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle);
150 void _connection_unset_cs_tid(int tid, connection_handle_s *conn_handle);
151 int _connection_libnet_get_metered_state(connection_handle_s *conn_handle, bool* is_metered);
152 int _connection_libnet_get_wifi_state(connection_handle_s *conn_handle, connection_wifi_state_e *state);
153 int _connection_libnet_get_ethernet_state(connection_handle_s *conn_handle,
154                         connection_ethernet_state_e *state);
155 int _connection_libnet_get_ethernet_cable_state(connection_handle_s *conn_handle,
156                         connection_ethernet_cable_state_e* state);
157 int _connection_libnet_get_dhcp_state(connection_handle_s *conn_handle,
158                         const char *interface_name, connection_dhcp_state_e *state);
159 int _connection_libnet_get_bluetooth_state(connection_handle_s *conn_handle, connection_bt_state_e* state);
160 bool _connection_libnet_check_profile_validity(connection_profile_h profile);
161 int _connection_libnet_get_profile_iterator(connection_handle_s *conn_handle,
162                         connection_iterator_type_e type, connection_profile_iterator_h *profile_iterator);
163 bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iterator);
164 int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h,
165                         connection_profile_h *profile);
166 int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h);
167 int _connection_libnet_get_current_profile(connection_handle_s *conn_handle,
168                         connection_profile_h *profile);
169 int _connection_libnet_reset_profile(connection_handle_s *conn_handle,
170                         connection_reset_option_e type, connection_cellular_subscriber_id_e id);
171 int _connection_libnet_open_profile(connection_handle_s *conn_handle,
172                         connection_profile_h profile);
173 int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_handle,
174                         connection_cellular_service_type_e type, connection_profile_h *profile);
175 int _connection_libnet_set_cellular_service_profile_sync(connection_handle_s *conn_handle,
176                         connection_cellular_service_type_e type, connection_profile_h profile);
177 int _connection_libnet_set_cellular_service_profile_async(connection_handle_s *conn_handle,
178                         connection_cellular_service_type_e type, connection_profile_h profile);
179 int _connection_libnet_close_profile(connection_handle_s *conn_handle, connection_profile_h profile);
180 int _connection_libnet_add_route(connection_handle_s *conn_handle,
181                         const char *interface_name, const char *host_address);
182 int _connection_libnet_remove_route(connection_handle_s *conn_handle,
183                         const char *interface_name, const char *host_address);
184 int _connection_libnet_add_route_ipv6(connection_handle_s *conn_handle,
185                         const char *interface_name, const char *host_address, const char * gateway);
186 int _connection_libnet_remove_route_ipv6(connection_handle_s *conn_handle,
187                         const char *interface_name, const char *host_address, const char * gateway);
188 int _connection_libnet_add_route_entry(connection_handle_s *conn_handle,
189                         connection_address_family_e address_family, const char *interface_name,
190                         const char *host_address, const char * gateway);
191 int _connection_libnet_remove_route_entry(connection_handle_s *conn_handle,
192                         connection_address_family_e address_family, const char *interface_name,
193                         const char *host_address, const char * gateway);
194 void _connection_libnet_add_to_profile_list(connection_profile_h profile);
195 void _connection_libnet_remove_from_profile_list(connection_profile_h profile);
196 bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile,
197                         connection_profile_state_changed_cb callback, void *user_data);
198 bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile);
199 int _connection_libnet_set_statistics(connection_handle_s *conn_handle,
200                         net_device_t device_type, net_statistics_type_e statistics_type);
201 int _connection_libnet_get_statistics(connection_handle_s *conn_handle,
202                         net_statistics_type_e statistics_type, unsigned long long *size);
203 int _connection_libnet_check_get_privilege(void);
204 int _connection_libnet_check_profile_privilege(void);
205
206 int _connection_check_feature_supported(const char *feature_name, ...);
207
208 connection_cellular_service_type_e _profile_convert_to_connection_cellular_service_type(net_service_type_t svc_type);
209 connection_profile_state_e _profile_convert_to_cp_state(net_state_type_t state);
210 net_service_type_t _connection_profile_convert_to_libnet_cellular_service_type(connection_cellular_service_type_e svc_type);
211 net_state_type_t _connection_profile_convert_to_net_state(connection_profile_state_e state);
212
213 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
214                         connection_cellular_subscriber_id_e sim_id);
215
216 int _connection_libnet_enable_ethernet_eap(bool enable, const char *profilename);
217 int _connection_libnet_ethernet_eap_enabled(const char *profilename, bool *enabled);
218 int _connection_libnet_profile_save_ethernet_eap_config(connection_handle_s *conn_handle,
219                         connection_profile_h profile);
220
221 int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle);
222 int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle);
223 int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle,
224                         gboolean *tcpdump_state);
225 int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool *updated);
226 int _connection_libnet_get_ntp_server(connection_handle_s *conn_handle, char **ntp_server);
227 int _connection_libnet_set_ntp_server(connection_handle_s *conn_handle, const char *ntp_server);
228 int _connection_libnet_clear_ntp_server(connection_handle_s *conn_handle);
229
230 void _connection_lock(void);
231 void _connection_unlock(void);
232
233 bool _connection_check_handle_validity(connection_h connection);
234 void *_connection_get_default_handle(void);
235 void _connection_handle_ref(connection_handle_s *handle);
236 void _connection_handle_unref(connection_handle_s *handle);
237 #ifdef __cplusplus
238 }
239 #endif /* __cplusplus */
240
241 #endif