lowered forking, cleaner approach, faster.

a loop of 1000 calls, works nearly
twice as fast, as the old code.

anyway:
would'nt it be better to have a case-table, which
can translate (phyX, band, channel) -> freq?

Signed-off-by: Bastian Bittorf <bitt...@bluebottle.com>
>From e681b67765ddfd9264205f8444b1e999ccc6b6a1 Mon Sep 17 00:00:00 2001
From: Bastian Bittorf <bitt...@bluebottle.com>
Date: Thu, 27 Jan 2011 17:31:44 +0100
Subject: [PATCH] refactoring get_freq, lowered forks, cleaner

---
 package/mac80211/files/lib/wifi/mac80211.sh |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/package/mac80211/files/lib/wifi/mac80211.sh b/package/mac80211/files/lib/wifi/mac80211.sh
index 13d6584..e51aa8f 100644
--- a/package/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/mac80211/files/lib/wifi/mac80211.sh
@@ -227,11 +227,31 @@ disable_mac80211() (
 
 	return 0
 )
-get_freq() {
+
+get_freq()
+{
 	local phy="$1"
-	local chan="$2"
-	iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
+	local channel="$2"
+	local freq line startparse
+
+	iw "$phy" info | while read line; do {
+
+		[ -n "$startparse" ] && {
+			case "$line" in
+				*" [$channel] "*)
+					set $line	# e.g. '* 2442 MHz [7] (27.0 dBm)'
+					echo $2
+					return
+				;;
+			esac
+		}
+
+		case "$line" in
+			*"Frequencies:"*) startparse=1 ;;
+		esac
+	} done
 }
+
 enable_mac80211() {
 	local device="$1"
 	config_get channel "$device" channel
-- 
1.6.3.3

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to