Developing lightweight computation at the DSG edge

Commit 291368e8 authored by p4u's avatar p4u
Browse files

Added Txpower function for Web Interface. qmp_control now in PATH. Some changes in qmp_common.sh

parent c6adde79
......@@ -28,6 +28,7 @@ configure() {
echo "[Configuring wireless]"
. $QMP_DIR/qmp_wireless.sh
qmp_configure_wifi_driver
qmp_configure_wifi_initial
qmp_configure_wifi
wifi
......@@ -43,6 +44,7 @@ configure() {
/etc/init.d/olsrd restart
/etc/init.d/bmx6 restart
ifup -a
/etc/init.d/dnsmasq restart
touch "$CONTROL_FILE"
# echo "Done, rebooting system to complete configuration"
# reboot
......
......@@ -18,6 +18,8 @@
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
SOURCE_COMMON=1
#DEBUG="/tmp/qmp_common.debug"
DEBUG=""
#######################
# UCI related commands
......@@ -29,6 +31,7 @@ qmp_uci_get() {
echo "$u"
echo "$u" >> /tmp/uci_get
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci get qmp.$1)"
qmp_debug "qmp_uci_get: uci -q get qmp.$1"
return $r
}
......@@ -37,6 +40,7 @@ qmp_uci_get_raw() {
r=$?
echo "$u"
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci get $@)"
qmp_debug "qmp_uci_get_raw: uci -q get $@"
return $r
}
......@@ -46,6 +50,7 @@ qmp_uci_set() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci set qmp.$1=$2)"
qmp_debug "qmp_uci_set: uci -q set qmp.$1=$2"
return $r
}
......@@ -55,6 +60,7 @@ qmp_uci_set_raw() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci set $@)"
qmp_debug "qmp_uci_set_raw: uci -q set $@"
return $r
}
......@@ -64,6 +70,7 @@ qmp_uci_del() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci del qmp.$1)"
qmp_debug "qmp_uci_del: uci -q del qmp.$1"
return $r
}
......@@ -73,6 +80,7 @@ qmp_uci_del_raw() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci del $@)"
qmp_debug "qmp_uci_del_raw uci -q del $@"
return $r
}
......@@ -82,6 +90,7 @@ qmp_uci_add() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci add qmp $1)"
qmp_debug "qmp_uci_add: uci -q add qmp $1"
return $r
}
......@@ -90,11 +99,13 @@ qmp_uci_add_raw_get_cfg() {
r=$?
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci add $@)"
echo "$cfg"
qmp_debug "qmp_uci_add_raw_get_cfg: uci -q add $@"
return $r
}
qmp_uci_set_cfg() {
uci -q set $@ >/dev/null
qmp_debug "qmp_uci_set_cfg: uci -q set $@"
return $?
}
......@@ -102,6 +113,7 @@ qmp_uci_commit() {
uci commit $1
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci commit $1)"
qmp_debug "qmp_uci_commit: uci commit $1"
return $r
}
......@@ -111,6 +123,7 @@ qmp_uci_add_raw() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci add $@)"
qmp_debug "qmp_uci_add_raw: uci -q add $@"
return $r
}
......@@ -120,12 +133,13 @@ qmp_uci_add_list_raw() {
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci add_list $@)"
qmp_debug "qmp_uci_add_list_raw: uci -q add_list $@"
return $r
}
qmp_uci_import() {
cat "$1" | while read v; do
[ ! -z "$v" ] && uci set $v
[ ! -z "$v" ] && { uci set $v; qmp_debug "qmp_uci_import: uci set $v"; }
done
uci commit
return $?
......@@ -133,10 +147,9 @@ qmp_uci_import() {
qmp_uci_test() {
option=$1
if uci get $option > /dev/null 2>&1 ; then
return 0
fi
return 1
u="$(uci get $option > /dev/null 2>&1)"
r=$?
return $r
}
##################################
......@@ -156,6 +169,10 @@ qmp_log() {
logger -s -t qMp "$@"
}
qmp_debug() {
[ ! -z "$DEBUG" ] && echo "$@" >> $DEBUG
}
#######################################
# Networking and Wifi related commands
#######################################
......@@ -176,6 +193,10 @@ qmp_get_dev_from_mac() {
ip l | grep $1 -i -B1 | grep -v \@ | grep -v ether | awk '{print $2}' | tr -d : | awk NR==1
}
qmp_get_mac_for_dev() {
ip addr show dev $1 | grep -m 1 "link/ether" | awk '{print $2}'
}
#########################
# Other kind of commands
#########################
......@@ -190,11 +211,6 @@ qmp_tac() {
$@ | awk '{a[NR]=$0} END {for(i=NR;i>0;i--)print a[i]}'
}
qmp_get_mac_for_dev() {
dev=$1
ip addr show dev $dev | grep -m 1 "link/ether" | awk '{print $2}'
}
qmp_get_dec_node_id() {
PRIMARY_MESH_DEVICE="$(uci get qmp.interfaces.mesh_devices | awk '{print $1}')"
LSB_PRIM_MAC="$( qmp_get_mac_for_dev $PRIMARY_MESH_DEVICE | awk -F':' '{print $6}' )"
......@@ -205,5 +221,5 @@ qmp_get_dec_node_id() {
COMMUNITY_NODE_ID=$LSB_PRIM_MAC
fi
echo $(printf %d 0x$COMMUNITY_NODE_ID)
}
......@@ -35,9 +35,9 @@ search_default_gw() {
}
apply_wifi() {
qmp_configure_wifi >/dev/null
qmp_configure_wifi_initial
qmp_configure_wifi
wifi
}
apply_network() {
......@@ -46,7 +46,8 @@ apply_network() {
/etc/init.d/olsrd restart
/etc/init.d/bmx6 restart
ifup -a
/etc/init.d/dnsmasq restart
/etc/init.d/firewall restart
}
help() {
......
......@@ -156,6 +156,7 @@ qmp_configure_wifi_device() {
driver="$(qmp_uci_get wireless.driver)"
country="$(qmp_uci_get wireless.country)"
bssid="$(qmp_uci_get wireless.bssid)"
txpower="$(qmp_uci_get @wireless[$id].txpower)"
echo "------------------------"
echo "Mac: $mac"
......@@ -181,6 +182,7 @@ qmp_configure_wifi_device() {
-e s/"#QMP_SSID"/"$name"/ \
-e s/"#QMP_HTMODE"/"$htmode"/ \
-e s/"#QMP_BSSID"/"$bssid"/ \
-e s/"#QMP_TXPOWER"/"$txpower"/ \
-e s/"#QMP_INDEX"/"$index"/ \
-e s/"#QMP_MODE"/"$mode"/ > $TMP/qmp_wireless_temp
......@@ -204,9 +206,6 @@ qmp_configure_wifi_device() {
qmp_configure_wifi() {
echo "Configuring driver..."
qmp_configure_wifi_driver
echo "Backuping wireless config file to: $OWRT_WIRELESS_CONFIG.qmp_backup"
cp $OWRT_WIRELESS_CONFIG $OWRT_WIRELESS_CONFIG.qmp_backup 2>/dev/null
echo "" > $OWRT_WIRELESS_CONFIG
......@@ -313,6 +312,7 @@ qmp_configure_wifi_initial() {
echo "Found configured device: $m"
[ -z "$(qmp_uci_get @wireless[$j].mode)" ] && qmp_uci_set @wireless[$j].mode $(qmp_wifi_get_default mode $device)
[ -z "$(qmp_uci_get @wireless[$j].name)" ] && qmp_uci_set @wireless[$j].name $(qmp_wifi_get_default name)
[ -z "$(qmp_uci_get @wireless[$j].txpower)" ] && qmp_uci_set @wireless[$j].txpower $(qmp_wifi_get_default txpower)
# If channel is configured, we are going to check it
# if not, using default one
......
......@@ -56,6 +56,13 @@ function print_channels()
end
end
function print_txpower()
local data = qmp.get_txpower(dev)
for _,v in ipairs(data) do
print(v)
end
end
if #arg ~= 2 then
print_help()
os.exit(1)
......@@ -69,6 +76,8 @@ if question == "modes" then
elseif question == "channels" then
print_channels()
elseif question == "txpower" then
print_txpower()
else
print_help()
end
......
......@@ -31,6 +31,18 @@ function qmpinfo.get_modes(dev)
end
function qmpinfo.get_txpower(dev)
local iw = iwinfo[iwinfo.type(dev)]
local txp = iw.txpwrlist(dev)
local txpower_supported = {}
for _,v in ipairs(txp) do
table.insert(txpower_supported,v.dbm)
end
return txpower_supported
end
function qmpinfo.get_channels(dev)
local clist = {} -- output channel list
local iw = iwinfo[iwinfo.type(dev)]
......
......@@ -2,3 +2,4 @@ driver mac80211
country UZ
bssid 02:CA:FF:EE:BA:BE
name qmp
txpower 20
......@@ -12,3 +12,4 @@ wireless.#QMP_DEVICE.txantenna=0
wireless.#QMP_DEVICE.rxantenna=0
wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
......@@ -9,6 +9,7 @@ wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.hwmode=auto
wireless.#QMP_DEVICE.htmode=#QMP_HTMODE
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
list wireless.#QMP_DEVICE.ht_capab=SHORT-GI-40
list wireless.#QMP_DEVICE.ht_capab=TX-STBC
list wireless.#QMP_DEVICE.ht_capab=RX-STBC1
......
......@@ -11,3 +11,4 @@ wireless.#QMP_DEVICE.txantenna=0
wireless.#QMP_DEVICE.rxantenna=0
wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
......@@ -9,6 +9,7 @@ wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.hwmode=auto
wireless.#QMP_DEVICE.htmode=#QMP_HTMODE
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
list wireless.#QMP_DEVICE.ht_capab=SHORT-GI-40
list wireless.#QMP_DEVICE.ht_capab=TX-STBC
list wireless.#QMP_DEVICE.ht_capab=RX-STBC1
......
......@@ -12,3 +12,4 @@ wireless.#QMP_DEVICE.txantenna=0
wireless.#QMP_DEVICE.rxantenna=0
wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
......@@ -11,3 +11,4 @@ wireless.#QMP_DEVICE.txantenna=0
wireless.#QMP_DEVICE.rxantenna=0
wireless.#QMP_DEVICE.country=#QMP_COUNTRY
wireless.#QMP_DEVICE.outdoor=1
wireless.#QMP_DEVICE.txpower=#QMP_TXPOWER
/etc/qmp/qmp_control.sh
\ No newline at end of file
......@@ -80,7 +80,6 @@ for _,wdev in ipairs(wdevs) do
s_wireless:option(Value,"name","Wireless name")
-- Channel
channel = s_wireless:option(ListValue,"channel","Channel")
mymode = m.uci:get("qmp",wdev,"mode")
......@@ -92,6 +91,11 @@ for _,wdev in ipairs(wdevs) do
end
end
-- Txpower
txpower = s_wireless:option(ListValue,"txpower","Power")
for _,t in ipairs(qmp.get_txpower(mydev)) do
txpower:value(t,t)
end
end
function m.on_commit(self,map)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment