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