LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 08-04-2007, 06:26 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,300
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Init script for ndiswrapper with WPA support


Dear Folks,

I created an init script for Fedora Core 4 that should work on all Red Hat distros. It loads the ndiswrapper driver, initializes the wlan interface, and starts wpa_supplicant. You will need to put the script in

/etc/rc.d/init.d

and run

# chkconfig --add wlan
# chkconfig --level 345 wlan on

to get it to start at boot. It will start right after network is started and will stop right before network is stopped. You can control the wlan script using the usual Red Hat syntax:

# service wlan start
# service wlan stop
# service wlan restart

You may need to massage the script to handle any idiosyncrasies of your setup (e.g. change wlan0 to wlan1). E-mail me if you have an questions.

Code:
#!/bin/bash
#
# wlan		This shell script takes care of starting and stopping
#		the wlan interface.
#
# Copyright: (C) 2007 David Cullen  dcullen@kerneldriver.org
#
# License: GPLv3
#
# chkconfig: - 11 89
# description: wlan starts the wlan interface.

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

RETVAL=0
INTERFACE="wlan0"
LOGFILE="/var/log/${INTERFACE}.log"

wlanup()
{
	echo "Loading ndiswrapper..." > ${LOGFILE}
	if ! modprobe ndiswrapper >> ${LOGFILE} 2>&1 ; then
		echo "Could not load ndiswrapper" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Configuring ${INTERFACE}..." >> ${LOGFILE}
	if ! ifconfig ${INTERFACE} 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 >> ${LOGFILE} 2>&1 ; then
		echo "Could not configure ${INTERFACE}" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Bringing up ${INTERFACE}..." >> ${LOGFILE}
	if ! ifconfig wlan0 up >> ${LOGFILE} 2>&1 ; then
		echo "Could not bring up ${INTERFACE}" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Sleeping for one second..." >> ${LOGFILE}
	if ! sleep 1 >> ${LOGFILE} 2>&1 ; then
		echo "Could not sleep" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Configuring WPA..." >> ${LOGFILE}
	if ! /usr/local/sbin/wpa_supplicant -Dwext -i${INTERFACE} -c/etc/wpa_supplicant.conf -B 2>&1 >> ${LOGFILE} ; then
		echo "Could not configure WPA" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Configuring default route..." >> ${LOGFILE}
	if ! route add -net default gw 192.168.1.254 dev ${INTERFACE} >> ${LOGFILE} 2>&1 ; then
		echo "Could not configure default route" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	return $RETVAL
}

wlandown()
{
	echo "Stopping WPA..." >> ${LOGFILE}
	if ! killproc wpa_supplicant >> ${LOGFILE} 2>&1 ; then
		echo "Could not stop WPA" >> ${LOGFILE}
		return 1;
	fi
	echo "Bringing down ${INTERFACE}..." >> ${LOGFILE}
	if ! ifconfig ${INTERFACE} down >> ${LOGFILE} 2>&1 ; then
		echo "Could not bring down ${INTERFACE}" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	echo "Unloading ndiswrapper..." >> ${LOGFILE}
	if ! rmmod ndiswrapper >> ${LOGFILE} 2>&1 ; then
		echo "Could not unload ndiswrapper" >> ${LOGFILE}
		return 1;
	fi
	echo "Done." >> ${LOGFILE}
	return $RETVAL
}

start()
{
        echo -n $"Bringing up ${INTERFACE}: "
        wlanup
	RETVAL=$?
	[ $RETVAL -eq 0 ] && echo_success || echo_failure
	echo
	return $RETVAL
}

stop()
{
        echo -n $"Bringing down ${INTERFACE}: "
	wlandown
	RETVAL=$?
	[ $RETVAL -eq 0 ] && echo_success || echo_failure
	echo
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
        ;;
  stop)
	stop
        ;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload}"
        exit 1
esac

exit $RETVAL

Last edited by David1357; 05-16-2009 at 10:38 AM. Reason: Updated e-mail address; Put script inside code tags.
 
  


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
usb network adapter with ndiswrapper can't connect to wpa with wpa-supplicant AceofSpades19 Linux - Wireless Networking 8 03-30-2008 05:13 PM
wpa with ndiswrapper? darkangel29 Linux - Wireless Networking 5 02-19-2007 03:43 PM
WPA support through 'ndiswrapper' interface is deprecated; use 'wext' interface lavie Linux - Wireless Networking 1 12-04-2006 11:13 AM
WPA and ndiswrapper lordpeter Linux - Wireless Networking 4 02-07-2005 08:25 PM
ndiswrapper and WPA biastoch Linux - Wireless Networking 2 10-12-2004 07:43 AM


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

Main Menu
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