LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking
User Name
Password
Linux - Wireless Networking This forum is for the discussion of wireless networking in Linux.

Notices



Reply
 
Search this Thread
Old 12-02-2007, 06:00 PM   #1
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
wpa-connect script for Broadcom BCM4318 (AKA AirForce One 54g) for Ubuntu


The following init script will setup your Broadcom BCM4318 using WPA, assuming you have a wpa_supplicant.conf script in /etc.

Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          wpa-connect
# Required-Start:    networking
# Required-Stop:     networking
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Connects a wireless interface to an access point using WPA
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: David Cullen <dcullen@kerneldriver.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
INTERFACE="eth1"
DESC="wpa-connect"
NAME="${DESC}-${INTERFACE}"
LOGFILE="/var/log/wpa-connect.log"

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
wpa_connect()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started

	echo "Connecting to access point using WPA..." >> ${LOGFILE}
	if ! /sbin/wpa_supplicant -Dwext -i${INTERFACE} -c/etc/wpa_supplicant/wpa_supplicant.conf -B >> ${LOGFILE} 2>&1 ; then
		echo "Could not configure WPA for ${INTERFACE}" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}

	echo "Starting DHCP..." >> ${LOGFILE}
	if ! dhclient ${INTERFACE} >> ${LOGFILE} 2>&1 ; then
		echo "Could start DHCP for ${INTERFACE}" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	return $RETVAL
}

wpa_disconnect()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred

	echo "Stopping DHCP..." >> ${LOGFILE}
	if ! skill dhclient >> ${LOGFILE} 2>&1 ; then
		echo "Could not stop DHCP" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}

	echo "Disconnecting WPA..." >> ${LOGFILE}
	if ! skill wpa_supplicant >> ${LOGFILE} 2>&1 ; then
		echo "Could not disconnect WPA" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	return $RETVAL
}

start()
{
        log_begin_msg "Connecting ${INTERFACE} to access point using WPA..."
        wpa_connect
	RETVAL=$?
	[ $RETVAL -eq 0 ] && log_end_msg 0 || log_end_msg 1
	echo
	return $RETVAL
}

stop()
{
        log_begin_msg "Disconnection  ${INTERFACE} from access point using WPA..."
	wpa_disconnect
	RETVAL=$?
	[ $RETVAL -eq 0 ] && log_end_msg 0 || log_end_msg 1
	echo
	return $RETVAL
}

case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  #reload|force-reload)
	#
	# If do_reload() is not implemented then leave this commented out
	# and leave 'force-reload' as an alias for 'restart'.
	#
	#log_daemon_msg "Reloading $DESC" "$NAME"
	#do_reload
	#log_end_msg $?
	#;;
  restart|force-reload)
	#
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	#
	log_daemon_msg "Restarting $DESC" "$NAME"
	stop
	case "$?" in
	  0|1)
		start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac
:
You will need a wpa_supplicant.conf file that looks like this:
Code:
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="Your SSID"
    psk="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    key_mgmt=WPA-PSK
    proto=WPA
    pairwise=TKIP
    group=TKIP
}
You install it using

# update-rc.d wlan-config defaults
You uninstall it using

# update-rc.d -f wlan-config remove
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me with Broadcom Corporation BCM4318 [AirForce One 54g] 802.11g Wireless LAN Con julian.osorio Linux - Wireless Networking 13 08-01-2007 09:02 AM
SUSE 10.1+Airforce One 54g=AP visible but cant connect rh-penguin Linux - Wireless Networking 1 09-11-2006 04:47 PM
wlan belkin 54g pcmcia (f5d7010) broadcom airforce chipset + linuxant driverloader MmiB Linux - Hardware 7 11-11-2003 05:28 PM
wlan belkin 54g pcmcia (f5d7010) broadcom airforce chipset + linuxant driverloader MmiB Linux - Newbie 1 11-08-2003 02:44 AM
wlan belkin 54g pcmcia (f5d7010) broadcom airforce chipset + linuxant driverloader MmiB Linux - Wireless Networking 1 11-07-2003 03:28 AM


All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration