[wifi-direct-manager]Merge Tizen 2.4 for sync
[platform/core/connectivity/wifi-direct-manager.git] / files / wifi-direct-dhcp.sh
1 #!/bin/sh
2 #INTERFACE_NAME="p2p-wlan0-0"
3 #INTERFACE_PREFIX="p2p"
4 INTERFACE_NAME="wlan0"
5 INTERFACE_PREFIX="p2p"
6 TARGET="REDWOOD"
7 DEFAULT_IP="192.168.49.1"
8 DEFAULT_NET="192.168.49.1/24"
9 DEFAULT_BRD="192.168.49.255"
10
11 val=`/bin/uname -a | /bin/grep PQ | /usr/bin/wc -l`
12 if [ "${val}" -eq "1" ]; then
13         TARGET="PQ"
14 fi
15
16 val=`/bin/uname -a | /bin/grep U1HD | /usr/bin/wc -l`
17 if [ "${val}" -eq "1" ]; then
18         INTERFACE_PREFIX="wl0"
19         TARGET="U1HD"
20 fi
21
22 val=`/bin/uname -a | /bin/grep U1SLP | /usr/bin/wc -l`
23 if [ "${val}" -eq "1" ]; then
24         INTERFACE_PREFIX="wl0"
25         TARGET="U1SLP"
26 fi
27
28 val=`/bin/uname -a | /bin/grep i686  | /usr/bin/wc -l`
29 if [ "${val}" -eq "1" ]; then
30         INTERFACE_PREFIX="eth"
31         TARGET="EMUL"
32 fi
33
34
35 #interface=`/sbin/ifconfig|/bin/grep ^${INTERFACE_NAME}|/usr/bin/cut -d" " -f1`
36 interface=`/sbin/ifconfig|/bin/grep ^${INTERFACE_NAME}|/usr/bin/cut -d":" -f1`
37 #interface=`/usr/sbin/ip link|/bin/grep ^${INTERFACE_NAME}|/usr/bin/cut -d":" -f2`
38 echo "Target is ${TARGET} and interface ${INTERFACE_PREFIX}: ${interface}."
39
40 start_dhcp_server()
41 {
42         if [ "X${interface}" == "X" ]; then
43                 echo "interface(${INTERFACE_PREFIX}) is not up"
44                 return 0
45         fi
46
47         /sbin/ifconfig ${interface} ${DEFAULT_IP} up
48         /usr/bin/udhcpd /usr/etc/wifi-direct/dhcpd.${INTERFACE_PREFIX}.conf -f &
49
50         route=`/bin/cat /usr/etc/wifi-direct/dhcpd.${INTERFACE_PREFIX}.conf | /bin/grep router | /bin/awk '{print $3}'`
51         if [ -z $route ]; then
52                 route="192.168.49.1"
53         fi
54         subnet=`/bin/cat /usr/etc/wifi-direct/dhcpd.${INTERFACE_PREFIX}.conf | /bin/grep subnet | /bin/awk '{print $3}'`
55
56         if [ -z $subnet ]; then
57                 subnet="255.255.255.0"
58         fi
59
60         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_ifname ${interface} -f
61         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_subnet_mask ${subnet} -f
62         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_gateway ${route} -f
63         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_local_ip ${DEFAULT_IP} -f
64 }
65
66 start_dhcp_client()
67 {
68         if [ "X${interface}" == "X" ]; then
69                 echo "interface(${INTERFACE_PREFIX}) is not up"
70                 return 0
71         fi
72         /usr/bin/udhcpc -i $interface -s /usr/etc/wifi-direct/udhcp_script.non-autoip &
73 }
74
75
76 stop_dhcp()
77 {
78         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_ifname "" -f
79         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_subnet_mask "" -f
80         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_gateway "" -f
81         /usr/bin/vconftool set -t string memory/private/wifi_direct_manager/p2p_local_ip "" -f
82
83         /usr/bin/killall /usr/bin/udhcpc
84         /usr/bin/killall /usr/bin/udhcpd
85         /sbin/ifconfig ${interface} 0.0.0.0
86 }
87
88 is_running()
89 {
90         program=$1
91         run=`/bin/ps -eo comm|/bin/grep ${program}`
92         if [ "X${run}" == "X" ]; then
93                 echo "${program} is not running"
94         else
95                 echo "${program} is already running"
96         fi
97 }
98
99 status_dhcp()
100 {
101         is_running /usr/bin/udhcpc
102         is_running /usr/bin/udhcpd
103 }
104
105
106 case $1 in
107 "server")
108 stop_dhcp
109 start_dhcp_server
110 ;;
111 "client")
112 stop_dhcp
113 start_dhcp_client
114 ;;
115 "stop")
116 stop_dhcp
117 ;;
118 "status")
119 status_dhcp
120 ;;
121 *)
122 /bin/echo wifi-direct-dhcp.sh [server] [client] [stop] [status]
123 exit 1
124 ;;
125 esac
126