mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-21 19:40:11 +00:00
commit
f2b9d47d86
@ -62,6 +62,8 @@ usage() {
|
||||
echo " --mac <MAC> Set MAC address"
|
||||
echo " --dhcp-dns <IP1[,IP2]> Set DNS returned by DHCP"
|
||||
echo " --daemon Run create_ap in the background"
|
||||
echo " --pidfile <pidfile> Save daemon PID to file"
|
||||
echo " --logfile <logfile> Save daemon messages to file"
|
||||
echo " --stop <id> Send stop command to an already running create_ap. For an <id>"
|
||||
echo " you can put the PID of create_ap or the WiFi interface. You can"
|
||||
echo " get them with --list-running"
|
||||
@ -101,6 +103,17 @@ usage() {
|
||||
echo " "$PROGNAME" --stop wlan0"
|
||||
}
|
||||
|
||||
# Busybox polyfills
|
||||
if cp --help 2>&1 | grep -q -- --no-clobber; then
|
||||
cp_n() {
|
||||
cp -n "$@"
|
||||
}
|
||||
else
|
||||
cp_n() {
|
||||
yes n | cp -i "$@"
|
||||
}
|
||||
fi
|
||||
|
||||
# on success it echos a non-zero unused FD
|
||||
# on error it echos 0
|
||||
get_avail_fd() {
|
||||
@ -300,26 +313,6 @@ can_be_ap() {
|
||||
return 1
|
||||
}
|
||||
|
||||
get_avail_channel_list() {
|
||||
AVAIL_CH_LIST=$(\
|
||||
get_adapter_info ${IFACE} | \
|
||||
grep "\* [0-9]* MHz \[[0-9]*\]" | \
|
||||
while read l; do\
|
||||
[[ $l != *disabled* ]] && [[ $l != *no\ IR* ]] && echo "$l";\
|
||||
done | \
|
||||
sed 's/^* //'
|
||||
)
|
||||
|
||||
if [[ -z "$AVAIL_CH_LIST" ]]; then
|
||||
echo "Cannot determine which channels are supported"
|
||||
return 1
|
||||
# else
|
||||
# echo "$AVAIL_CH_LIST"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
can_transmit_to_channel() {
|
||||
local IFACE CHANNEL_NUM CHANNEL_INFO
|
||||
IFACE=$1
|
||||
@ -374,10 +367,6 @@ is_wifi_connected() {
|
||||
return 1
|
||||
}
|
||||
|
||||
#is_wifi_connected() {
|
||||
# return 1
|
||||
#}
|
||||
|
||||
is_macaddr() {
|
||||
echo "$1" | grep -E "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$" > /dev/null 2>&1
|
||||
}
|
||||
@ -488,8 +477,15 @@ networkmanager_is_running() {
|
||||
[[ -n "$NMCLI_OUT" ]]
|
||||
}
|
||||
|
||||
networkmanager_knows_iface() {
|
||||
# check if the interface $1 is known to NetworkManager
|
||||
# an interface may exist but may not be known to NetworkManager if it is in a different network namespace than NetworkManager
|
||||
nmcli -t -f DEVICE d 2>&1 | grep -Fxq "$1"
|
||||
}
|
||||
|
||||
networkmanager_iface_is_unmanaged() {
|
||||
is_interface "$1" || return 2
|
||||
networkmanager_knows_iface "$1" || return 0
|
||||
(nmcli -t -f DEVICE,STATE d 2>&1 | grep -E "^$1:unmanaged$" > /dev/null 2>&1) || return 1
|
||||
}
|
||||
|
||||
@ -649,10 +645,11 @@ VHT_CAPAB=
|
||||
DRIVER=nl80211
|
||||
NO_VIRT=0
|
||||
COUNTRY=
|
||||
FREQ_BAND_SET=0
|
||||
FREQ_BAND=2.4
|
||||
NEW_MACADDR=
|
||||
DAEMONIZE=0
|
||||
DAEMON_PIDFILE=
|
||||
DAEMON_LOGFILE=/dev/null
|
||||
NO_HAVEGED=0
|
||||
USE_PSK=0
|
||||
|
||||
@ -661,7 +658,7 @@ REDIRECT_TO_LOCALHOST=0
|
||||
|
||||
CONFIG_OPTS=(CHANNEL GATEWAY WPA_VERSION ETC_HOSTS DHCP_DNS NO_DNS NO_DNSMASQ HIDDEN MAC_FILTER MAC_FILTER_ACCEPT ISOLATE_CLIENTS
|
||||
SHARE_METHOD IEEE80211N IEEE80211AC HT_CAPAB VHT_CAPAB DRIVER NO_VIRT COUNTRY FREQ_BAND
|
||||
NEW_MACADDR DAEMONIZE NO_HAVEGED WIFI_IFACE INTERNET_IFACE
|
||||
NEW_MACADDR DAEMONIZE DAEMON_PIDFILE DAEMON_LOGFILE NO_HAVEGED WIFI_IFACE INTERNET_IFACE
|
||||
SSID PASSPHRASE USE_PSK)
|
||||
|
||||
FIX_UNMANAGED=0
|
||||
@ -815,6 +812,10 @@ _cleanup() {
|
||||
|
||||
mutex_unlock
|
||||
cleanup_lock
|
||||
|
||||
if [[ $RUNNING_AS_DAEMON -eq 1 && -n "$DAEMON_PIDFILE" && -f "$DAEMON_PIDFILE" ]]; then
|
||||
rm $DAEMON_PIDFILE
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
@ -894,7 +895,7 @@ print_client() {
|
||||
if [[ -f $CONFDIR/dnsmasq.leases ]]; then
|
||||
line=$(grep " $mac " $CONFDIR/dnsmasq.leases | tail -n 1)
|
||||
ipaddr=$(echo $line | cut -d' ' -f3)
|
||||
hostname=$(echo $line | cut -d' ' -f4)
|
||||
hostname=$(echo "$line" | cut -d' ' -f4)
|
||||
fi
|
||||
|
||||
[[ -z "$ipaddr" ]] && ipaddr="*"
|
||||
@ -1005,8 +1006,6 @@ write_config() {
|
||||
eval echo $config_opt=\$$config_opt
|
||||
done >> "$STORE_CONFIG"
|
||||
|
||||
chmod 600 $STORE_CONFIG
|
||||
chown $(logname):$(logname) $STORE_CONFIG
|
||||
echo -e "Config options written to '$STORE_CONFIG'"
|
||||
exit 0
|
||||
}
|
||||
@ -1055,7 +1054,7 @@ for ((i=0; i<$#; i++)); do
|
||||
fi
|
||||
done
|
||||
|
||||
GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:" -n "$PROGNAME" -- "$@")
|
||||
GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","pidfile:","logfile:","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:" -n "$PROGNAME" -- "$@")
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
eval set -- "$GETOPT_ARGS"
|
||||
|
||||
@ -1176,6 +1175,16 @@ while :; do
|
||||
shift
|
||||
DAEMONIZE=1
|
||||
;;
|
||||
--pidfile)
|
||||
shift
|
||||
DAEMON_PIDFILE="$1"
|
||||
shift
|
||||
;;
|
||||
--logfile)
|
||||
shift
|
||||
DAEMON_LOGFILE="$1"
|
||||
shift
|
||||
;;
|
||||
--stop)
|
||||
shift
|
||||
STOP_ID="$1"
|
||||
@ -1258,7 +1267,8 @@ if [[ -n "$LOAD_CONFIG" && $# -eq 0 ]]; then
|
||||
fi
|
||||
|
||||
# Check if required number of positional args are present
|
||||
if [[ $# -lt 1 && $FIX_UNMANAGED -eq 0 && -z "$STOP_ID" && $LIST_RUNNING -eq 0 && -z "$LIST_CLIENTS_ID" ]]; then
|
||||
if [[ $# -lt 1 && $FIX_UNMANAGED -eq 0 && -z "$STOP_ID" &&
|
||||
$LIST_RUNNING -eq 0 && -z "$LIST_CLIENTS_ID" ]]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
@ -1270,11 +1280,6 @@ fi
|
||||
|
||||
trap "cleanup_lock" EXIT
|
||||
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
echo "You must run it as root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! init_lock; then
|
||||
echo "ERROR: Failed to initialize lock" >&2
|
||||
exit 1
|
||||
@ -1299,6 +1304,11 @@ if [[ -n "$LIST_CLIENTS_ID" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
echo "You must run it as root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$STOP_ID" ]]; then
|
||||
echo "Trying to kill $PROGNAME instance associated with $STOP_ID..."
|
||||
send_stop "$STOP_ID"
|
||||
@ -1312,10 +1322,16 @@ if [[ $FIX_UNMANAGED -eq 1 ]]; then
|
||||
fi
|
||||
|
||||
if [[ $DAEMONIZE -eq 1 && $RUNNING_AS_DAEMON -eq 0 ]]; then
|
||||
echo "Running as Daemon..."
|
||||
# Assume we're running underneath a service manager if PIDFILE is set
|
||||
# and don't clobber it's output with a useless message
|
||||
if [ -z "$DAEMON_PIDFILE" ]; then
|
||||
echo "Running as Daemon..."
|
||||
fi
|
||||
# run a detached create_ap
|
||||
RUNNING_AS_DAEMON=1 setsid "$0" "${ARGS[@]}" &
|
||||
RUNNING_AS_DAEMON=1 setsid "$0" "${ARGS[@]}" >>$DAEMON_LOGFILE 2>&1 &
|
||||
exit 0
|
||||
elif [[ $RUNNING_AS_DAEMON -eq 1 && -n "$DAEMON_PIDFILE" ]]; then
|
||||
echo $$ >$DAEMON_PIDFILE
|
||||
fi
|
||||
|
||||
if [[ $FREQ_BAND != 2.4 && $FREQ_BAND != 5 ]]; then
|
||||
@ -1521,12 +1537,12 @@ mkdir -p $COMMON_CONFDIR
|
||||
|
||||
if [[ "$SHARE_METHOD" == "nat" ]]; then
|
||||
echo $INTERNET_IFACE > $CONFDIR/nat_internet_iface
|
||||
cp -n /proc/sys/net/ipv4/conf/$INTERNET_IFACE/forwarding \
|
||||
cp_n /proc/sys/net/ipv4/conf/$INTERNET_IFACE/forwarding \
|
||||
$COMMON_CONFDIR/${INTERNET_IFACE}_forwarding
|
||||
fi
|
||||
cp -n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR
|
||||
cp_n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR
|
||||
if [[ -e /proc/sys/net/bridge/bridge-nf-call-iptables ]]; then
|
||||
cp -n /proc/sys/net/bridge/bridge-nf-call-iptables $COMMON_CONFDIR
|
||||
cp_n /proc/sys/net/bridge/bridge-nf-call-iptables $COMMON_CONFDIR
|
||||
fi
|
||||
mutex_unlock
|
||||
|
||||
@ -1582,7 +1598,6 @@ if [[ $NO_VIRT -eq 0 ]]; then
|
||||
fi
|
||||
|
||||
|
||||
|
||||
VIRTDIEMSG="Maybe your WiFi adapter does not fully support virtual interfaces.
|
||||
Try again with --no-virt."
|
||||
echo -n "Creating a virtual WiFi interface... "
|
||||
@ -1795,7 +1810,7 @@ if [[ "$SHARE_METHOD" != "none" ]]; then
|
||||
ip link add name $BRIDGE_IFACE type bridge || die
|
||||
ip link set dev $BRIDGE_IFACE up || die
|
||||
# set 0ms forward delay
|
||||
echo 0 > /sys/class/net/$BRIDGE_IFACE/bridge/forward_delay
|
||||
echo -n 0 > /sys/class/net/$BRIDGE_IFACE/bridge/forward_delay
|
||||
|
||||
# attach internet interface to bridge interface
|
||||
ip link set dev $INTERNET_IFACE promisc on || die
|
||||
|
Loading…
Reference in New Issue
Block a user