4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>,
7 * Injun Yang <injun.yang@samsung.com>,
8 * Seungyoun Ju <sy39.ju@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #ifndef __MOBILEAP_AGENT_H__
25 #define __MOBILEAP_AGENT_H__
27 #include <dbus/dbus.h>
28 #include <dbus/dbus-glib.h>
29 #include <dbus/dbus-glib-lowlevel.h>
32 #include <netinet/in.h>
36 #define MH_MID "mh_agent"
37 #define DBG(fmt, args...) LOG(LOG_DEBUG, MH_MID, "[%s()][Ln:%d] "fmt, \
38 __func__, __LINE__, ##args)
39 #define ERR(fmt, args...) LOG(LOG_ERROR, MH_MID, "[%s()][Ln:%d] "fmt, \
40 __func__, __LINE__, ##args)
42 #define DRIVER_DELAY 250000 /* micro seconds */
45 #define NET_BUF_LEN 12
46 #define INTERFACE_NAME_LEN 12
47 #define SECURITY_TYPE_LEN 32
49 /* Network Interface */
50 #define IP_SUBNET_MASK "255.255.255.0"
52 #define WIFI_IF "wlan0"
53 #define IP_ADDRESS_WIFI 0xC0A83D02 /* 192.168.61.2 */
55 #define SOFTAP_IF "wl0.1"
56 #define IP_ADDRESS_SOFTAP 0xC0A83D01 /* 192.168.61.1 */
59 #define IP_ADDRESS_USB 0xC0A88103 /* 192.168.129.3 */
61 #define BT_IF_PREFIX "bnep"
62 #define BT_IF_ALL BT_IF_PREFIX"+"
63 #define IP_ADDRESS_BT_1 0xC0A88201 /* 192.168.130.1 */
64 #define IP_ADDRESS_BT_2 0xC0A88301 /* 192.168.131.1 */
65 #define IP_ADDRESS_BT_3 0xC0A88401 /* 192.168.132.1 */
66 #define IP_ADDRESS_BT_4 0xC0A88501 /* 192.168.133.1 */
67 #define IP_ADDRESS_BT_5 0xC0A88601 /* 192.168.134.1 */
68 #define IP_ADDRESS_BT_6 0xC0A88701 /* 192.168.135.1 */
69 #define IP_ADDRESS_BT_7 0xC0A88801 /* 192.168.136.1 */
71 #define RET_FAILURE (-1)
72 #define RET_SUCCESS (0)
73 #define MAX_BUF_SIZE (256u)
75 #define DNSMASQ_CONF_LEN 1024
76 #define DNSMASQ_CONF "dhcp-range=192.168.61.3,192.168.61.150,255.255.255.0\n" \
77 "dhcp-range=192.168.130.2,192.168.130.150,255.255.255.0\n" \
78 "dhcp-range=192.168.131.2,192.168.131.150,255.255.255.0\n" \
79 "dhcp-range=192.168.132.2,192.168.132.150,255.255.255.0\n" \
80 "dhcp-range=192.168.133.2,192.168.133.150,255.255.255.0\n" \
81 "dhcp-range=192.168.134.2,192.168.134.150,255.255.255.0\n" \
82 "dhcp-range=192.168.135.2,192.168.135.150,255.255.255.0\n" \
83 "dhcp-range=192.168.136.2,192.168.136.150,255.255.255.0\n" \
84 "dhcp-range=192.168.137.2,192.168.137.150,255.255.255.0\n" \
85 "dhcp-range=set:blue,192.168.129.4,192.168.129.150,255.255.255.0\n"\
86 "dhcp-option=option:dns-server,%s\n" \
88 "dhcp-option=tag:blue,option:router,192.168.129.3\n"
89 #define DNSMASQ_CONF_FILE "/tmp/dnsmasq.conf"
91 /* Start of hostapd configuration */
92 #define MH_CTRL_INTF "/tmp/mh_wpa_ctrl"
93 #define MH_MONITOR_INTF "/tmp/mh_wpa_monitor"
95 #define HOSTAPD_BIN "/usr/sbin/hostapd"
96 #define HOSTAPD_ENTROPY_FILE "/opt/var/lib/misc/hostapd.bin"
97 #define HOSTAPD_CONF_FILE "/opt/var/lib/misc/hostapd.conf"
98 #define HOSTAPD_CTRL_INTF_DIR "/opt/var/lib/misc/hostapd"
99 #define HOSTAPD_CONF_LEN 1024
100 #define HOSTAPD_CONF "interface=%s\n" \
102 "ctrl_interface=%s\n" \
105 "ignore_broadcast_ssid=%d\n" \
108 #define HOSTAPD_DEBUG_FILE "/tmp/hostapd.log"
109 #define HOSTAPD_REQ_MAX_LEN 128
110 #define HOSTAPD_RETRY_MAX 5
111 #define HOSTAPD_RETRY_DELAY 500000 /* us */
112 #define HOSTAPD_STA_DISCONN "AP-STA-DISCONNECTED " /* from wpa_ctrl.h */
113 #define HOSTAPD_MONITOR_ATTACH "ATTACH"
114 #define HOSTAPD_MONITOR_DETACH "DETACH"
115 /* End of hostapd configuration */
117 #define WLAN_SCRIPT "/usr/bin/wlan.sh"
119 #define IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
120 #define IPTABLES "/usr/sbin/iptables"
121 #define GREP "/bin/grep"
122 #define AWK "/usr/bin/awk"
123 #define DATA_USAGE_FILE "/tmp/tethering_data_usage.txt"
124 #define MASQUERADE_RULE "-o %s -j MASQUERADE"
125 #define DNS_FORWARD_RULE "-p udp -i %s --dport 53 -j DNAT --to %s"
126 #define FORWARD_RULE "-i %s -o %s"
127 #ifndef __USE_CONNMAN_DNS_ADDR__
128 #define GOOGLE_PUBLIC_DNS "8.8.8.8"
129 #endif /* __USE_CONNMAN_DNS_ADDR__ */
131 #define MOBILE_AP_STATE_NONE 0
132 #define MOBILE_AP_STATE_WIFI 1
133 #define MOBILE_AP_STATE_USB 2
134 #define MOBILE_AP_STATE_BT 4
135 #define MOBILE_AP_STATE_ALL 7
137 #define DNSMASQ_DBUS_INTERFACE "uk.org.thekelleys.dnsmasq"
139 #define PROC_NET_DEV "/proc/net/dev"
140 #define MAX_TRANSFER_CHECK_COUNT 180 /* 30 minutes */
141 #define CHECK_NET_STATE_RETRY_COUNT 5
142 #define PSK_ITERATION_COUNT 4096
145 /* The parent class object state. */
148 /* instance member */
149 DBusGMethodInvocation *bt_context;
150 DBusGMethodInvocation *usb_context;
156 int transfer_check_count;
157 unsigned long long rx_bytes;
158 unsigned long long tx_bytes;
160 char ssid[MOBILE_AP_WIFI_SSID_MAX_LEN + 1];
161 char key[MOBILE_AP_WIFI_KEY_MAX_LEN + 1];
162 char security_type[SECURITY_TYPE_LEN];
166 /* The parent class state. */
170 guint signals[E_SIGNAL_MAX];
171 } MobileAPObjectClass;
174 unsigned int number; /* Number of connected device */
175 /* BSSID list of connected device */
176 char bssid[MOBILE_AP_MAX_WIFI_STA][MOBILE_AP_STR_INFO_LEN];
177 } softap_device_info_t;
181 vconf_callback_fn cb;
187 MOBILE_AP_DRV_INTERFACE_NONE,
190 } mobile_ap_drv_interface_e;
192 /* ssid : 32 key : 64 */
193 int _mh_core_enable_softap(const char *ssid, const char *security,
194 const char *key, int hide_mode);
195 int _mh_core_disable_softap(void);
196 int _mh_core_get_device_info(softap_device_info_t *di);
197 int _mh_core_execute_dhcp_server(void);
198 int _mh_core_terminate_dhcp_server(void);
199 int _mh_core_enable_masquerade(const char *ext_if);
200 int _mh_core_disable_masquerade(const char *ext_if);
201 void _mh_core_add_data_to_array(GPtrArray *array, guint type, gchar *dev_name);
202 int _mh_core_set_ip_address(const char *if_name, const in_addr_t ip);
205 gboolean _init_tethering(MobileAPObject *obj);
206 gboolean _deinit_tethering(MobileAPObject *obj);
207 gboolean _mobileap_clear_state(int state);
210 gboolean _mobileap_is_disabled(void);
211 gboolean _mobileap_is_enabled(int state);
212 gboolean _mobileap_is_enabled_by_type(mobile_ap_type_e type);
213 gboolean _mobileap_set_state(int state);