1 AUTHOR: Eloi Primaux eloi@bliscat.org
3 LICENSE: GNU Free Documentation License Version 2
4 SYNOPSIS: Setting a wireless network with WPA and dhcpcd
6 This hint purpose a way to set wireless networks using wpa_supplicant and dhcpcd
12 A full LFS-6.1 and BLFS-6.1 system already configured with a standart lan network
13 The chipset driver of your wireless card (ex: madwifi http://madwifi.org/wiki/)
14 wireless tools available at http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html
15 wpa_supplicant available at http://hostap.epitest.fi/wpa_supplicant/ (latest stable release)
16 dhcpcd installed from the blfs book
19 note you will also require and access point which use wpa encryption and dhcp service
23 this hint is mainly based on what has already been done in the blfs book for the dhcpcd service
25 install chipset driver, wireless tools, and wpa_supplicant
26 both of them have fully explanaited documentations to build them
27 If you still in trouble, have a look to http://madwifi.org/wiki
29 Now you need to create 2 files,
30 1) /etc/sysconfig/network-devices/service/wpa-dhcpcd
31 2) /etc/sysconfig/network-devices/ifconfig.XX/wpa-dhcpcd
33 XX is the name of your device, eth0,wlan0,ath0...
37 ####### 1) wpa-dhcpcd service script ########
39 # /etc/sysconfig/network-devices/service/wpa-dhcpcd
41 ####### start here ######
44 # Begin $network-devices/services/wpa-dhcpcd
46 # Based on dhcpcd script adapted for wpa networks
47 # Rewritten by Eloi Primaux - eloi@bliscat.org
54 DHCPCD_PIDFILE="/var/run/dhcpcd-$1.pid"
55 DHCPCD_LEASEINFO="/var/lib/dhcpc/dhcpcd-$1.info"
56 WPA_PIDFILE="/var/run/wpa_supplicant-$1.pid"
57 #WPA_CONFIGFILE="/etc/sysconfig/network-devices/ifconfig.$1/wpa-dhcpcd"
59 WPA_SCRP="/etc/sysconfig/network-devices/wpa-script.$1"
65 echo "" # due to the pre ifconfig process
66 # Start wpa_supplicant in the background
67 wpa_supplicant -g/var/run/wpa_supplicant-$1-global -P$WPA_PIDFILE -B
68 #We must check if our requested SSID is available...
69 boot_mesg "Scanning for available Access Points..."
70 iwlist ath0 scan | grep "ESSID"
71 SSID_AVAILABLE=$(iwlist ath0 scan | grep "$WPA_SSID")
72 if [ -n "$SSID_AVAILABLE" ]; then
73 boot_mesg "The Access Point "$WPA_SSID" is available, connecting"
75 # Add a new interface (no configuration file and
76 # enable control interface)
77 echo "wpa_cli -g/var/run/wpa_supplicant-$1-global interface_add $1 \"\" $WPA_DRIVER /var/run/wpa_supplicant" > $WPA_SCRP
78 # Configure a network using the newly added network interface:
79 echo "wpa_cli -i$1 add_network" >> $WPA_SCRP
80 echo "wpa_cli -i$1 set_network 0 ssid '\"$WPA_SSID\"'" >> $WPA_SCRP
81 echo "wpa_cli -i$1 set_network 0 key_mgmt WPA-PSK" >> $WPA_SCRP
82 echo "wpa_cli -i$1 set_network 0 psk '\"$WPA_PASS\"'" >> $WPA_SCRP
83 echo "wpa_cli -i$1 set_network 0 pairwise $WPA_PAIRWISE" >> $WPA_SCRP
84 echo "wpa_cli -i$1 set_network 0 group $WPA_GROUP" >> $WPA_SCRP
85 echo "wpa_cli -i$1 set_network 0 proto $WPA_PROTO" >> $WPA_SCRP
86 echo "wpa_cli -i$1 enable_network 0" >> $WPA_SCRP
87 #Now we run the little script created above
88 boot_mesg -n "Booting wpa_supplicant on the $1 interface..."
89 . $WPA_SCRP > /dev/null
92 #Now we overwrite the last script by one which request the wpa status
93 # When the network is ready it will answer "wpa_state=COMPLETED"
94 echo "wpa_cli -i$1 status | grep 'wpa_state' | sed 's,wpa_state=,,g'" > $WPA_SCRP
95 # we run a little loop to wait for wpa_supplicant being ready
96 boot_mesg "Please wait while the daemon is connecting to $WPA_SSID..."
98 COUNTER=0 # to not loop undefinetly at boot time if the network is down...
99 while [ "$RET" != "COMPLETED" ]; do
100 if [ "$COUTER" = "$WPA_MAXCYCLE" ]; then
101 boot_mesg "The Access Point $WPA_SSID is available" ${WARNING}
102 boot_mesg "But the connecting time is over . This is" ${WARNING}
103 boot_mesg "Mostly due to a misconfigurated network." ${WARNING}
104 boot_mesg "Please check your configuration" ${WARNING}
115 # At this point, the new network interface should start trying to associate
116 # with the WPA-PSK network using SSID.
119 boot_mesg "Starting dhcpcd on the $1 interface..."
120 # Test to see if there is a stale pid file
121 if [ -f "$DHCPCD_PIDFILE" ]
123 ps `cat "$DHCPCD_PIDFILE"` | grep dhcpcd > /dev/null
126 rm -f $DHCPCD_PIDFILE > /dev/null
128 boot_mesg "dhcpcd already running!" ${WARNING}
133 /sbin/dhcpcd $1 $DHCP_START
134 # Save the return value
136 # Print the assigned settings if requested
137 if [ "$RET" = "0" -a "$PRINTIP" = "yes" ]; then
138 . /var/lib/dhcpc/dhcpcd-$1.info
139 if [ "$PRINTALL" = "yes" ]; then
142 boot_mesg " DHCP Assigned Settings for $1:"
144 boot_mesg " IP Address: $IPADDR"
146 boot_mesg " Subnet Mask: $NETMASK"
148 boot_mesg " Default Gateway: $GATEWAY"
150 boot_mesg " DNS Server: $DNS"
153 boot_mesg " IP Addresss: ""$IPADDR"
162 boot_mesg "The Access Point "$WPA_SSID" is not available" ${WARNING}
163 boot_mesg "Please check your configuration" ${WARNING}
171 boot_mesg -n "Stopping dhcpcd on the $1 interface..."
172 # Do nothing with the client daemon if we have an infinate
173 # lease time as the client exits when started in this case,
175 if [ -e $DHCPCD_LEASEINFO ]
179 if [ "$DHCPCD_LEASETIME" = "4294967295" ]
181 # do nothing, just echo ok
185 if [ -n "$DHCP_STOP" ]
187 /sbin/dhcpcd $1 $DHCP_STOP &> /dev/null
189 if [ "$RET" -eq 0 ]; then
192 elif [ "$RET" -eq 1 ]; then
193 boot_mesg "dhcpcd not running!" ${WARNING}
205 boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
206 boot_mesg "dhcpcd is not running!" ${WARNING}
210 boot_mesg "Stopping wpa_supplicant on the $1 interface..."
211 killproc -p $WPA_PIDFILE wpa_supplicant
217 echo "Usage: $0 [interface] {up|down}"
222 # End $network_devices/services/wpa-dhcpcd
230 ####### 2) wpa-dhcpcd config file ########
232 # /etc/sysconfig/network-devices/ifconfig.XX/wpa-dhcpcd
233 # XX is the name of your device, eth0,wlan0,ath0...
235 #### start here #####
237 #This config file is mostly based of the
242 DHCP_START="-d " # to print some debug informations
245 WPA_DRIVER="Your Driver"
246 WPA_PROTO="Your Proto" # WPA2 for WPA2-PSK check the wpa-supplicant readme
247 WPA_PAIRWISE="Your Pairwise" # CCMP for AES
248 WPA_GROUP="Your Group" # CCMP for AES
249 WPA_PASS="Your very secret WPA password"
251 #one cycle each 5 seconds
252 WPA_MAXCYCLE=24 # 120s
253 # Set PRINTIP="yes" to have the script print
254 # the DHCP assigned IP address
257 # Set PRINTALL="yes" to print the DHCP assigned values for
258 # IP, SM, DG, and 1st NS. This requires PRINTIP="yes".
265 do a chmod 755 /etc/sysconfig/network-devices/service/wpa-dhcpcd
266 and if you correctly set the config file, just type
267 /etc/rc.d/init.d/network restart if you can use the connection then
268 your wireless network will be set at boot time
276 http://linuxfromscratch.org/mailman/listinfo/hints
277 FAQ: http://www.linuxfromscratch.org/faq/
278 Unsubscribe: See the above information page