From 52216037cbb0ed82c3c2bfbd496b456ffd8bdf93 Mon Sep 17 00:00:00 2001
From: James Rayner <james@archlinux.org>
Date: Mon, 14 Jul 2008 21:24:33 +1000
Subject: [PATCH] add some useful error messages to wireless code

---
 network |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/network b/network
index 8c17ee7..a7dd136 100755
--- a/network
+++ b/network
@@ -18,11 +18,9 @@ ifup()
 		echo "usage: $0 ifup <interface_name>"
 		return 1
 	fi
-	eval iwcfg="\$wlan_${1}"
-	if [ "$iwcfg" != "" ]; then
-		/usr/sbin/iwconfig $iwcfg
-		/bin/sleep 2
-	fi
+
+	wi_up $1 || return 1
+
 	eval ifcfg="\$${1}"
 	if [ "$ifcfg" = "dhcp" ]; then
 		# remove the .pid file if it exists
@@ -35,6 +33,23 @@ ifup()
 	return $?
 }
 
+wi_up()
+{
+	eval iwcfg="\$wlan_${1}"
+	[ "$iwcfg" = "" ] && return 0
+
+	/usr/sbin/iwconfig $iwcfg
+	[[ -z "$WIRELESS_TIMEOUT" ]] && WIRELESS_TIMEOUT=2
+	sleep $WIRELESS_TIMEOUT
+
+	bssid=`iwgetid $1 -ra`
+	if [[ "$bssid" = "00:00:00:00:00:00" ]]; then
+		printhl "Could not associate $1 - try increasing WIRELESS_TIMEOUT and check network is WEP or has no security"
+		return 1
+	fi
+	return 0
+}
+
 ifdown()
 {
 	if [ "$1" = "" ]; then
-- 
1.5.6.2

