3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef __MOBILEAP_AGENT_H__
19 #define __MOBILEAP_AGENT_H__
21 #include <dbus/dbus.h>
22 #include <dbus/dbus-glib.h>
23 #include <dbus/dbus-glib-lowlevel.h>
26 #include <netinet/in.h>
30 #define MH_MID "mh_agent"
31 #define DBG(fmt, args...) LOG(LOG_DEBUG, MH_MID, "[%s()][Ln:%d] "fmt, \
32 __func__, __LINE__, ##args)
33 #define ERR(fmt, args...) LOG(LOG_ERROR, MH_MID, "[%s()][Ln:%d] "fmt, \
34 __func__, __LINE__, ##args)
36 #define DRIVER_DELAY 250000 /* micro seconds */
39 #define NET_BUF_LEN 12
40 #define INTERFACE_NAME_LEN 12
41 #define SECURITY_TYPE_LEN 32
43 /* Network Interface */
44 #define IP_SUBNET_MASK "255.255.255.0"
46 #define WIFI_IF "wlan0"
47 #define IP_ADDRESS_WIFI 0xC0A83D02 /* 192.168.61.2 */
49 #define SOFTAP_IF "wl0.1"
50 #define IP_ADDRESS_SOFTAP 0xC0A83D01 /* 192.168.61.1 */
53 #define IP_ADDRESS_USB 0xC0A88103 /* 192.168.129.3 */
55 #define BT_IF_PREFIX "bnep"
56 #define BT_IF_ALL BT_IF_PREFIX"+"
57 #define IP_ADDRESS_BT_1 0xC0A88201 /* 192.168.130.1 */
58 #define IP_ADDRESS_BT_2 0xC0A88301 /* 192.168.131.1 */
59 #define IP_ADDRESS_BT_3 0xC0A88401 /* 192.168.132.1 */
60 #define IP_ADDRESS_BT_4 0xC0A88501 /* 192.168.133.1 */
61 #define IP_ADDRESS_BT_5 0xC0A88601 /* 192.168.134.1 */
62 #define IP_ADDRESS_BT_6 0xC0A88701 /* 192.168.135.1 */
63 #define IP_ADDRESS_BT_7 0xC0A88801 /* 192.168.136.1 */
65 #define RET_FAILURE (-1)
66 #define RET_SUCCESS (0)
67 #define MAX_BUF_SIZE (256u)
69 #define DNSMASQ_CONF_LEN 1024
70 #define DNSMASQ_CONF "dhcp-range=192.168.61.3,192.168.61.150,255.255.255.0\n" \
71 "dhcp-range=192.168.130.2,192.168.130.150,255.255.255.0\n" \
72 "dhcp-range=192.168.131.2,192.168.131.150,255.255.255.0\n" \
73 "dhcp-range=192.168.132.2,192.168.132.150,255.255.255.0\n" \
74 "dhcp-range=192.168.133.2,192.168.133.150,255.255.255.0\n" \
75 "dhcp-range=192.168.134.2,192.168.134.150,255.255.255.0\n" \
76 "dhcp-range=192.168.135.2,192.168.135.150,255.255.255.0\n" \
77 "dhcp-range=192.168.136.2,192.168.136.150,255.255.255.0\n" \
78 "dhcp-range=192.168.137.2,192.168.137.150,255.255.255.0\n" \
79 "dhcp-range=set:blue,192.168.129.4,192.168.129.150,255.255.255.0\n"\
81 "dhcp-option=tag:blue,option:router,192.168.129.3\n"
82 #define DNSMASQ_CONF_FILE "/tmp/dnsmasq.conf"
84 /* Start of hostapd configuration */
85 #define MH_CTRL_INTF "/tmp/mh_wpa_ctrl"
86 #define MH_MONITOR_INTF "/tmp/mh_wpa_monitor"
88 #define HOSTAPD_BIN "/usr/sbin/hostapd"
89 #define HOSTAPD_ENTROPY_FILE "/opt/var/lib/misc/hostapd.bin"
90 #define HOSTAPD_CONF_FILE "/opt/var/lib/misc/hostapd.conf"
91 #define HOSTAPD_CTRL_INTF_DIR "/opt/var/lib/misc/hostapd"
92 #define HOSTAPD_CONF_LEN 1024
93 #define HOSTAPD_CONF "interface=%s\n" \
95 "ctrl_interface=%s\n" \
98 "ignore_broadcast_ssid=%d\n" \
102 #define HOSTAPD_DEBUG_FILE "/tmp/hostapd.log"
103 #define HOSTAPD_REQ_MAX_LEN 128
104 #define HOSTAPD_RETRY_MAX 5
105 #define HOSTAPD_RETRY_DELAY 500000 /* us */
106 #define HOSTAPD_STA_DISCONN "AP-STA-DISCONNECTED " /* from wpa_ctrl.h */
107 #define HOSTAPD_MONITOR_ATTACH "ATTACH"
108 #define HOSTAPD_MONITOR_DETACH "DETACH"
109 /* End of hostapd configuration */
111 #define WLAN_SCRIPT "/usr/bin/wlan.sh"
113 #define IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
114 #define IPTABLES "/usr/sbin/iptables"
115 #define GREP "/bin/grep"
116 #define AWK "/usr/bin/awk"
117 #define DATA_USAGE_FILE "/tmp/tethering_data_usage.txt"
118 #define MASQUERADE_RULE "-o %s -j MASQUERADE"
120 #define TCP_DNS_FORWARD_RULE "-i %s -p tcp --dport 53 -j DNAT --to %s:53"
121 #define UDP_DNS_FORWARD_RULE "-i %s -p udp --dport 53 -j DNAT --to %s:53"
122 #define FORWARD_RULE "-i %s -o %s"
124 #define MOBILE_AP_STATE_NONE 0
125 #define MOBILE_AP_STATE_WIFI 1
126 #define MOBILE_AP_STATE_USB 2
127 #define MOBILE_AP_STATE_BT 4
128 #define MOBILE_AP_STATE_ALL 7
130 #define DNSMASQ_DBUS_INTERFACE "uk.org.thekelleys.dnsmasq"
132 #define PROC_NET_DEV "/proc/net/dev"
133 #define TETHERING_CONN_TIMEOUT (1200000) /* 20 Mins */
134 #define CHECK_NET_STATE_RETRY_COUNT 5
135 #define PSK_ITERATION_COUNT 4096
138 /* The parent class object state. */
141 /* instance member */
142 DBusGMethodInvocation *bt_context;
143 DBusGMethodInvocation *usb_context;
149 int transfer_check_count;
150 unsigned long long rx_bytes;
151 unsigned long long tx_bytes;
153 char ssid[MOBILE_AP_WIFI_SSID_MAX_LEN + 1];
154 char key[MOBILE_AP_WIFI_KEY_MAX_LEN + 1];
155 char security_type[SECURITY_TYPE_LEN];
159 /* The parent class state. */
163 guint signals[E_SIGNAL_MAX];
164 } TetheringObjectClass;
167 unsigned int number; /* Number of connected device */
168 /* BSSID list of connected device */
169 char bssid[MOBILE_AP_MAX_WIFI_STA][MOBILE_AP_STR_INFO_LEN];
170 } softap_device_info_t;
174 vconf_callback_fn cb;
180 MOBILE_AP_DRV_INTERFACE_NONE,
183 } mobile_ap_drv_interface_e;
185 /* ssid : 32 key : 64 */
186 int _mh_core_enable_softap(const char *ssid, const char *security,
187 const char *key, int hide_mode);
188 int _mh_core_disable_softap(void);
189 int _mh_core_get_device_info(softap_device_info_t *di);
190 int _mh_core_execute_dhcp_server(void);
191 int _mh_core_terminate_dhcp_server(void);
192 int _mh_core_enable_masquerade(const char *ext_if);
193 int _mh_core_disable_masquerade(const char *ext_if);
194 void _mh_core_add_data_to_array(GPtrArray *array, guint type, gchar *dev_name);
195 int _mh_core_set_ip_address(const char *if_name, const in_addr_t ip);
198 gboolean _init_tethering(TetheringObject *obj);
199 gboolean _deinit_tethering(TetheringObject *obj);
200 gboolean _mobileap_clear_state(int state);
203 gboolean _mobileap_is_disabled(void);
204 gboolean _mobileap_is_enabled(int state);
205 gboolean _mobileap_is_enabled_by_type(mobile_ap_type_e type);
206 gboolean _mobileap_set_state(int state);