summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Pryor <profjim@jimpryor.net>2009-08-11 14:05:10 +0200
committerJames Rayner <james@archlinux.org>2009-08-15 04:28:29 +0200
commit9578dda45b86acf3bd25def5de8f1d51f2ec22b2 (patch)
tree214394f032dc086c0c63befc8e22fffc80d16403
parentc37f2081157b15be719ce8afb0e8e15afbf24253 (diff)
downloadnetctl-9578dda45b86acf3bd25def5de8f1d51f2ec22b2.tar.gz
netctl-9578dda45b86acf3bd25def5de8f1d51f2ec22b2.tar.xz
Add AP argument to profile, also let ESSID arguments be regexps
* AP= arguments in profiles take precedence over ESSID= arguments * ESSID= arguments regexps instead of literals. To avoid screwing up any currently working profiles, I restricted the interpretation as a regexp to just the new wireless-dbus connection types. * But a global change involved in implementing this is that the connection up/down calls will be passed a literal ESSID (which of the local networks matches the regexp) as an additional argument. Signed-off-by: Jim Pryor <profjim@jimpryor.net>
-rw-r--r--doc/wireless4
-rw-r--r--doc/wireless-dbus6
-rw-r--r--src-wireless/netcfg-auto-wireless57
-rw-r--r--src-wireless/wireless-dbus15
-rw-r--r--src/connections/wireless48
-rw-r--r--src/wireless27
6 files changed, 119 insertions, 38 deletions
diff --git a/doc/wireless b/doc/wireless
index 9f8087e..e1f649e 100644
--- a/doc/wireless
+++ b/doc/wireless
@@ -17,8 +17,10 @@ SECURITY (required for security of 'wep', 'wpa' or 'wpa-config')
: One of 'wpa', 'wep', 'none' or 'wpa-config'. Defaults to 'none'
KEY (required for SECURITY of 'wpa' or 'wep' only)
: Wireless encryption key.
-ESSID (required)
+ESSID (this or AP is required)
: Name of network to connect to.
+AP (this or ESSID is required)
+: AP of the network to connect to.
TIMEOUT (optional)
: Time to wait for association. Defaults to 15 seconds.
SCAN (optional)
diff --git a/doc/wireless-dbus b/doc/wireless-dbus
index 918256d..bddd565 100644
--- a/doc/wireless-dbus
+++ b/doc/wireless-dbus
@@ -15,8 +15,10 @@ SECURITY (required)
: One of 'wpa', 'wep', 'none' or 'wpa-config'
KEY (required for SECURITY of 'wpa' or 'wep' only)
: Wireless encryption key.
-ESSID (required)
-: Name of network to connect to.
+ESSID (this or AP is required)
+: Name of network to connect to. Note that for "wireless-dbus" profiles this is always a Gnu regexp (as interpreted by "expr").
+AP (this or ESSID is required)
+: AP of the network to connect to.
TIMEOUT
: Time to wait for association. Defaults to 15 seconds.
diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless
index 50d49be..aa2590f 100644
--- a/src-wireless/netcfg-auto-wireless
+++ b/src-wireless/netcfg-auto-wireless
@@ -20,25 +20,58 @@ wifi_auto()
fi
# Loop through all the found essid's, then find a matching profile.
- while read essid; do
- for network in $(list_profiles); do
- load_profile $network
+
+ local found_profile found_essid
+
+ # JP: add ability to use AP instead of ESSID
+ # JP: also, make ESSIDs in wireless-dbus CONNECTIONS a regexp instead of a literal
+ while read ap essid; do
+ while read network; do
+ (
+ unset CONNECTION INTERFACE AP
+ load_profile "$network"
case "$CONNECTION" in
wireless-old|wireless|wireless-dbus)
- if [[ "$essid" = "$ESSID" && "$interface" = "$INTERFACE" ]]; then
- found=$network
+ if [[ "$interface" = "$INTERFACE" ]]; then
+ if [[ "$ap" == "$AP" ]]; then
+ exit 2
+ elif [[ -z "$found_profile" ]]; then
+ if [[ "$CONNECTION" == wireless-dbus ]]; then
+ if expr match "$essid" "^$ESSID\$" 1>/dev/null; then
+ exit 1
fi
+ elif [[ "$essid" == "$ESSID" ]]; then
+ exit 1
+ fi
+ fi
+ fi
;;
esac
- done
- done < $networks
-
- if [[ "$found" ]]; then
- netcfg $found
- exit $?
+ exit 0
+ )
+ case $? in
+ 2) found_profile="$network"
+ found_essid="$essid"
+ break 2;;
+ 1) found_profile="$network"
+ found_essid="$essid"
+ ;;
+ esac
+ done < <(list_profiles) # avoid subshell we'd get by piping list_profiles to while read
+ done < "$networks" # avoid subshell; list_networks returns name of a tmp file
+ rm -f "$networks" # shouldn't we delete the tmp file?
+
+ if [[ -n "$found_profile" ]]; then
+ report_success
+ if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2
+ exit 0
+ else
+ exit_fail "Couldn't connect profile $found_profile."
+ fi
+ else
+ exit_fail "No profiles matched the local networks."
fi
- exit_fail "- No profiles matched the found networks"
}
if [[ $(id -u) -ne 0 ]]; then
diff --git a/src-wireless/wireless-dbus b/src-wireless/wireless-dbus
index d30eb21..838609d 100644
--- a/src-wireless/wireless-dbus
+++ b/src-wireless/wireless-dbus
@@ -61,7 +61,7 @@ def fail(msg=None, report_type="fail"):
sys.exit(1)
-def start(profile):
+def start(profile, essid):
# TODO: Add check if it's even a wireless interface
# Interface up - probably redundant, should be 'ip' instead.
#try:
@@ -128,9 +128,11 @@ def start(profile):
rnet = dbus.Interface(net_obj, WPAS_DBUS_NETWORKS_INTERFACE)
iface.selectNetwork(rnet)
+ if not essid:
+ essid = profile["ESSID"]
if profile['SECURITY'] == "wpa":
- opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID']),
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid),
"psk": dbus.String(profile['KEY'])},
signature="sv")
report('debug', 'wireless_dbus', 'connect to network with security=wpa')
@@ -145,7 +147,7 @@ def start(profile):
for l in key:
keydbus+=chr(l)
- opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID']),
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid),
"key_mgmt": dbus.String("NONE"),
"wep_tx_keyidx": dbus.Int32(1),
"wep_key0": dbus.ByteArray(keydbus)},
@@ -153,7 +155,7 @@ def start(profile):
report('debug', 'wireless_dbus', 'connect to network with security=wep')
rnet.set(opts)
elif profile['SECURITY'] == "none":
- opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID'])},
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(essid)},
signature="sv")
report('debug', 'wireless_dbus', 'connect to network with security=none')
rnet.set(opts)
@@ -201,9 +203,10 @@ if __name__ == "__main__":
try:
profile_name = sys.argv[2]
profile = read_config("/etc/network.d/"+profile_name)
-
+
+ essid = sys.argv[3] if len(sys.argv)>3 else "" # JP: pass literal ESSID as an argument, so that we can have entry in profile be a regexp
if sys.argv[1] == "up":
- start(profile)
+ start(profile, essid)
elif sys.argv[1] == "down":
stop(profile)
diff --git a/src/connections/wireless b/src/connections/wireless
index 644b002..430f0ab 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -17,6 +17,8 @@ rfkill_from_name() {
wireless_up() {
load_profile $1
+ [[ -n "$2" ]] && ESSID="$2" # JP: use the literal ESSID (though currently we only interpret wireless-dbus ESSIDs as regexps)
+
. ${SUBR_DIR}/8021x
. ${SUBR_DIR}/wireless
@@ -51,14 +53,28 @@ wireless_up() {
report_debug wireless_up ifup
set_interface up $INTERFACE || return 1
-
- quirk "prescan" && iwlist $INTERFACE scan &> /dev/null # bcm43xx
- quirk "preessid" && eval "iwconfig $INTERFACE mode managed essid \"$ESSID\"" # ipw3945
+ ## wireless_control "$INTERFACE" up || return 1
+
+ quirk prescan && iwlist "$INTERFACE" scan &> /dev/null # bcm43xx
+ if quirk preessid; then # ipw3945
+ if [[ -n "$AP" ]]; then # JP: enable use of AP
+ iwconfig "$INTERFACE" mode managed ap "$AP"
+ else
+ eval "iwconfig \"$INTERFACE\" mode managed essid \"$ESSID\""
+ fi
+ fi
if checkyesno ${SCAN:-no}; then
report_debug wireless_up scanning
- if ! find_essid $INTERFACE "$ESSID"; then
- report_fail "Network not present."
+ local OLDESSID="$ESSID"
+ if [[ -n "$AP" ]]; then
+ ESSID=$(find_ap "$INTERFACE" "$AP")
+ else
+ ESSID=$(find_essid "$INTERFACE" "$ESSID" "$CONNECTION") # JP: we could have left $3 null for default of treating ESSID as literal
+ # but instead we explicitly pass $CONNECTION
+ fi
+ if [[ $? -gt 0 ]]; then
+ report_fail "Network \"$OLDESSID\" not present."
return 1
fi
fi
@@ -77,9 +93,17 @@ wireless_up() {
# 'none' uses iwconfig like wep. Use sane default if WEP_OPTS=""
if [[ -z "$WEP_OPTS" ]]; then
if [[ "$SECURITY" = "wep" ]]; then
- WEP_OPTS="essid \"$ESSID\" key $KEY"
+ if [[ -n "$AP" ]]; then
+ WEP_OPTS="ap \"$AP\" key $KEY"
+ else
+ WEP_OPTS="essid \"$ESSID\" key $KEY"
+ fi
elif [[ "$SECURITY" = "none" ]]; then
- WEP_OPTS="essid \"$ESSID\""
+ if [[ -n "$AP" ]]; then
+ WEP_OPTS="ap \"$AP\""
+ else
+ WEP_OPTS="essid \"$ESSID\""
+ fi
fi
fi
@@ -102,7 +126,13 @@ wireless_up() {
wpa)
# Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384
- quirk "wpaessid" && eval iwconfig $INTERFACE essid "\"$ESSID\""
+ if quirk "wpaessid"; then
+ if [[ -n "$AP" ]]; then
+ iwconfig "$INTERFACE" ap "$AP"
+ else
+ eval "iwconfig \"$INTERFACE\" essid \"$ESSID\""
+ fi
+ fi
local WPA_CONF="${TMPDIR:-/tmp}/wpa.${1// /}" # substitute spaces out
# make empty tmp dir with correct permissions, rename it
@@ -196,6 +226,6 @@ wireless_status() {
}
-wireless_$1 $2
+wireless_$1 "$2" "$3"
exit $?
# vim: set ts=4 et sw=4:
diff --git a/src/wireless b/src/wireless
index 883ea0b..99c146d 100644
--- a/src/wireless
+++ b/src/wireless
@@ -14,24 +14,35 @@ wep_check()
}
# Check if a particular network is within range
-# find_essid interface essid
+# find_essid interface essid connection (we treat ESSID as regexp when CONNECTION=wireless-dbus)
find_essid() {
- local INTERFACE="$1" ESSID="$2" RETRIES=20 try=0 res scanned
+ local INTERFACE="$1" ESSID="$2" CONNECTION="$3" RETRIES=20 try=0 res scanned
while [[ "$try" -lt "$RETRIES" ]]; do
sleep 0.5
let try++
- found=$(
- res=$(iwlist "$INTERFACE" scan 2>/dev/null)
- [[ -z "$res" ]] && exit 1
- # if results were non-null, process them and exit 0
- echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID"
- ) && {
+ if [[ "$CONNECTION" == wireless-dbus ]]; then
+ # JP: ESSID is a regexp
+ found=$(
+ res=$(iwlist "$INTERFACE" scan 2>/dev/null)
+ [[ -z "$res" ]] && exit 1
+ # if results were non-null, process them and exit 0
+ echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | egrep -xm1 "$ESSID"
+ )
+ else
+ found=$(
+ res=$(iwlist "$INTERFACE" scan 2>/dev/null)
+ [[ -z "$res" ]] && exit 1
+ # if results were non-null, process them and exit 0
+ echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID"
+ )
+ fi && {
scanned=1
report_debug find_essid "\"$found\""
# we only bother with at most 5 successful scans
if (( try < RETRIES-4 )); then try=$((RETRIES-4)); fi
}
if [[ -n "$found" ]]; then
+ echo "$found" # JP: echo literal ESSID
return 0 # network found
fi
done