On 11/23/2011 10:52 AM, Jan Dvořák wrote:
On Wed, 23 Nov 2011 16:51:09 +0100
Stanislaw Gruszka<sgruszka@xxxxxxxxxx> wrote:
Could you confirm that on previous kernel client mode does not
work, and work with that new kernel?
I'll try it when I get home or first thing yesterday.
I can't still use hostapd, however.
Hmm, I'm not sure if rtl92c works in AP mode, Larry?
When I try it, I get rtl8192cu to beacon, and it is possible to authenticate and
associate, but the second computer never gets an IP number. I think my script to
set up dhcpd is faulty, but I cannot find the problem. I attached it - perhaps
one of you can find what I'm doing wrong. BTW, the script also fails when I try
to use b43 as an AP, and I know it works.
Larry
#!/bin/sh
# Script to start/stop a hostapd-based access point
#
# Sample start call "control_ap start wlan0 eth0"
# Stop with "control_ap stop"
#
case "$1" in
start)
if [ $# -ne 3 ]
then
echo "Usage: $0 start AP_iface NET_iface"
exit 1
fi
;;
stop)
if [ $# -ne 1 ]
then
echo "Usage: $0 stop"
exit 1
fi
;;
*)
echo "Usage:"
echo "$0 start AP-iface net_iface"
echo "or"
echo "$0 stop"
exit 1
;;
esac
# Symbols for needed programs
IPTABLES=/usr/sbin/iptables
IFCONFIG=/sbin/ifconfig
DHCPD=/usr/sbin/dhcpd
HOSTAPD=/usr/sbin/hostapd
# Symbols for AP and external interfaces
NET_AP=$2
NET_EXT=$3
# First 3 octets of IP address for the AP
AP_ADDR=192.168.0
# IP address for nameserver
NAME_SERVER=8.8.8.8
# AP Channel, SSID, Encryption method, and Encryption secret
AP_CHANNEL=1
AP_SSID=test
WPA_SECRET="\"123456789\""
ENCRYPT_MODE=2
case "$1" in
start)
echo "Starting AP mode for $NET_AP at address $AP_ADDR"
# Disable packet forwarding
echo 0 > /proc/sys/net/ipv4/ip_forward
# Stop any existing hostapd and dhcpd daemons
killproc hostapd
killproc dhcpd
#Set up forwarding
$IPTABLES -t nat -A POSTROUTING -o $NET_EXT -j MASQUERADE
$IPTABLES -A FORWARD -i $NET_EXT -o $NET_AP -m state \
--state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -i $NET_AP -o $NET_EXT -j ACCEPT
# Enable packet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Get the AP interface in the right state
$IFCONFIG $NET_AP down
$IFCONFIG $NET_AP up
$IFCONFIG $NET_AP $AP_ADDR.1
# dhcpd needs to have a leases file available - create it if needed
if [ ! -f /var/lib/dhcp/db/dhcpd.leases ]; then
touch /var/lib/dhcp/db/dhcpd.leases
fi
# Write the DHCP server configuration file
echo "option domain-name-servers $NAME_SERVER;" > ~/dhcpd.conf
echo "default-lease-time 600;" >> ~/dhcpd.conf
echo "max-lease-time 7200;" >> ~/dhcpd.conf
echo "ddns-update-style none; ddns-updates off;" >> ~/dhcpd.conf
echo "subnet $AP_ADDR.0 netmask 255.255.255.0 {" >> ~/dhcpd.conf
echo " range $AP_ADDR.200 $AP_ADDR.229;" >> ~/dhcpd.conf
# echo " option subnet-mask 255.255.255.0;" >> ~/dhcpd.conf
echo " option broadcast-address $AP_ADDR.255;" >> ~/dhcpd.conf
echo " option routers $AP_ADDR.1;" >> ~/dhcpd.conf
echo "}" >> ~/dhcpd.conf
# Write the hostapd configuration file
echo "interface=$NET_AP" > ~/hostapd.conf
echo "driver=nl80211" >> ~/hostapd.conf
echo "hw_mode=g" >> ~/hostapd.conf
echo "channel=$AP_CHANNEL" >> ~/hostapd.conf
echo "ssid=$AP_SSID" >> ~/hostapd.conf
echo "wpa=ENCRYPT_MODE" >> ~/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> ~/hostapd.conf
echo "wpa_pairwise=CCMP" >> ~/hostapd.conf
echo "wpa_passphrase=$WPA_SECRET" >> ~/hostapd.conf
# Bring up hostapd
$HOSTAPD -B ~/hostapd.conf
# Bring up the DHCP server
$DHCPD -cf ~/dhcpd.conf $NET_AP
;;
stop)
echo "Stopping AP mode"
# Stop hostapd and dhcpd daemons
killproc hostapd
killproc dhcpd
rm -f ~/hostapd.conf
rm -f ~/dhcpd.conf
;;
esac