Add ifup-pre-local script to correctly set the mode for madwifi.
[madwifi.git] / ifup-pre-local
diff --git a/ifup-pre-local b/ifup-pre-local
new file mode 100755 (executable)
index 0000000..c7c7a89
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# $Id$
+# Script to set the mode for MADWIFI. Should be called by ifup.
+# Copyright (C) 2007 The Trustees of Princeton University
+
+. /etc/sysconfig/network-scripts/network-functions
+CONFIG="$1"
+source_config
+
+WLANDEV=$(basename $(readlink -e /sys/class/net/$DEVICE/device/net:wifi* 2>/dev/null) 2>/dev/null)
+if [ -n "$MODE$WLANDEV" ]; then
+    wlanconfig "$DEVICE" destroy &> /dev/null
+    m=$( echo "$MODE" | tr '[A-Z]' '[a-z]' | tr -d - )
+    case "$m" in
+      managed)
+        m=sta
+        ;;
+      master)
+        m=ap
+        ;;
+      repeater)
+        m=wds
+        ;;
+    esac
+    wlanconfig "$DEVICE" create wlandev $WLANDEV wlanmode "$m"
+fi