Merge "Rectify gvariant type for frequency" into tizen
[platform/core/connectivity/net-config.git] / include / util.h
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
20 #ifndef __NETCONFIG_UTIL_H__
21 #define __NETCONFIG_UTIL_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <glib.h>
28 #include <stdbool.h>
29
30 #include "wifi.h"
31 #include "plugin.h"
32
33 #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
34
35 #define NETCONFIG_TIZEN_SYSTEM_ENV "/run/tizen-system-env"
36
37 #define MAC_ADDRESS_MAX_LEN   18
38 #define MAX_SIZE_ERROR_BUFFER 256
39 #define VCONF_ETH_MAC_ADDRESS  "db/dnet/mac_address"
40
41 #define ETHERNET_FEATURE "http://tizen.org/feature/network.ethernet"
42 #define TETHERING_FEATURE "http://tizen.org/feature/network.tethering"
43 #define WIFI_DIRECT_FEATURE "http://tizen.org/feature/network.wifi.direct"
44 #define WIFI_SOFTAP_FEATURE "http://tizen.org/feature/network.wifi.softap"
45
46 typedef enum {
47         NETCONFIG_SUPPORTED_FEATURE_ETHERNET = 0,
48         NETCONFIG_SUPPORTED_FEATURE_TETHERING,
49         NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT,
50         NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP,
51         NETCONFIG_SUPPORTED_FEATURE_MAX,
52 } netconfig_supported_feature_e;
53
54 bool netconfig_check_feature_supported(netconfig_supported_feature_e feature);
55
56 gboolean netconfig_check_mac_address(const char *service, const char *mac_address);
57 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase);
58
59 GKeyFile *netconfig_keyfile_load(const char *pathname);
60 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname);
61
62 void netconfig_start_timer_seconds(guint secs,
63                 gboolean(*callback) (gpointer), void *user_data, guint *timer_id);
64 void netconfig_start_timer(guint msecs,
65                 gboolean(*callback) (gpointer), void *user_data, guint *timer_id);
66 void netconfig_stop_timer(guint *timer_id);
67
68 void netconfig_wifi_enable_device_picker_test(void);
69 void netconfig_wifi_device_picker_service_start(void);
70 void netconfig_wifi_device_picker_service_stop(void);
71
72 gboolean netconfig_is_wifi_direct_on(void);
73 gboolean netconfig_is_wifi_tethering_on(void);
74
75 gboolean netconfig_interface_up(const char *ifname);
76 gboolean netconfig_interface_down(const char *ifname);
77 int __netconfig_get_interface_index(const char *interface_name);
78
79 int netconfig_execute_cmd(const char *cmd);
80 int netconfig_execute_file(const char *file_path, char *const args[], char *const env[]);
81 int netconfig_execute_file_no_wait(const char *file_path,
82                 char *const args[]);
83 int netconfig_execute_clatd(const char *file_path, char *const args[]);
84 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len);
85 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len);
86 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family);
87 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family);
88
89 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context);
90
91 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * data);
92 int netconfig_send_message_to_net_popup(const char *title,
93                 const char *content, const char *type, const char *ssid);
94 int netconfig_send_restriction_to_net_popup(const char *title,
95                 const char *type, const char *restriction);
96 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val);
97 void netconfig_set_vconf_int(const char *key, int value, gboolean log);
98 void netconfig_set_vconf_str(const char *key, const char *value, gboolean log);
99 int netconfig_vconf_get_int(const char *key, int *value);
100 int netconfig_vconf_get_bool(const char *key, int *value);
101
102 char *netconfig_vconf_get_str_dbus(const char *key);
103 int netconfig_vconf_get_int_dbus(const char *key, int *value);
104 int netconfig_vconf_get_bool_dbus(const char *key, int *value);
105
106 char* netconfig_get_env(const char *key);
107 void netconfig_set_mac_address_to_vconf(const char *def_mac);
108 void netconfig_set_mac_address_from_file(void);
109 char *netconfig_get_mac_address_from_file(const char *ifname);
110 char *netconfig_get_default_ifname_from_file(void);
111 int netconfig_freq_to_channel(int freq);
112 int netconfig_get_operating_class(int freq);
113 void __netconfig_pop_wifi_connected_poppup(const char *ssid);
114
115 void netconfig_get_telephony_network_type(int *svctype, int *pstype);
116 gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context);
117 netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
118                 GDBusMethodInvocation *context, struct wifi_authentication_data **data);
119 gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
120                 GDBusMethodInvocation *context, struct wifi_authentication_data **data);
121 gboolean netconfig_tapi_check_sim_state(void);
122 gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
123                 GDBusMethodInvocation *context, struct wifi_authentication_data **data);
124 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
125                 GDBusMethodInvocation *context, struct wifi_authentication_data **data);
126
127 void netconfig_battery_start_dn(void);
128 void netconfig_battery_end_dn(void);
129 void netconfig_battery_update_dn_rssi(int rssi);
130 void netconfig_battery_start_wifi(void);
131 void netconfig_battery_end_wifi(void);
132 void netconfig_battery_update_wifi_scan(int state);
133 void netconfig_battery_update_wifi_rssi(int rssi);
134 void netconfig_battery_get_dn_list(void *data);
135 void netconfig_battery_get_wifi_list(void *data);
136
137 void netconfig_plugin_init();
138 void netconfig_plugin_deinit();
139 gboolean netconfig_get_headed_plugin_flag();
140 gboolean netconfig_get_telephony_plugin_flag();
141 void netconfig_notify_online_state(char *ifname, gboolean online_state);
142
143 void netconfig_convert_bytes_to_hexstr(const char* bin, int blen, gchar* hexstr);
144
145 int get_files_count(const char* path);
146 char *get_least_recently_profile(const char* path);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 typedef enum {
153         TIZEN_PROFILE_UNKNOWN = 0,
154         TIZEN_PROFILE_MOBILE = 0x1,
155         TIZEN_PROFILE_WEARABLE = 0x2,
156         TIZEN_PROFILE_TV = 0x4,
157         TIZEN_PROFILE_IVI = 0x8,
158         TIZEN_PROFILE_COMMON = 0x10,
159 } tizen_profile_t;
160 extern tizen_profile_t _get_tizen_profile();
161
162 #define TIZEN_TELEPHONY_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
163 #define TIZEN_WLAN_BOARD_SPRD (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
164 #define TIZEN_TV (_get_tizen_profile() == TIZEN_PROFILE_TV)
165 #define TIZEN_NTP_ENABLE 1 /* 1: enable, 0: disable */
166
167 #endif /* __NETCONFIG_UTIL_H__ */