Hi DV
Please find the details below.
I am trying to change tx power of wireless interface using netlink
sockets. I am using libnl python library to achieve this. Please find
the script attached.
When this python program is executed in ash shell (My Openwrt has this
shell) it works fine.
***@OpenWrt:~# iwinfo
wlan0 ESSID: unknown
Access Point: 00:00:00:00:00:00
Mode: Mesh Point Channel: 11 (2.462 GHz)
Tx-Power: 10 dBm Link Quality: unknown/70
Signal: unknown Noise: -95 dBm
Bit Rate: unknown
Encryption: unknown
Type: nl80211 HW Mode(s): 802.11bgn
Hardware: unknown [Generic MAC80211]
TX power offset: unknown
Frequency offset: unknown
Supports VAPs: yes PHY name: phy0
***@OpenWrt:~# python change_wifi_tx_power.py wlan0 5
Tx Power 5
Sent 44 bytes to the kernel.
***@OpenWrt:~# iwinfo
wlan0 ESSID: unknown
Access Point: 00:00:00:00:00:00
Mode: Mesh Point Channel: 11 (2.462 GHz)
Tx-Power: 5 dBm Link Quality: unknown/70
Signal: unknown Noise: -95 dBm
Bit Rate: unknown
Encryption: unknown
Type: nl80211 HW Mode(s): 802.11bgn
Hardware: unknown [Generic MAC80211]
TX power offset: unknown
Frequency offset: unknown
Supports VAPs: yes PHY name: phy0
I am trying to change the tx power parameter without login to the
router. So, I thought of using ubus over http to configure the
parameter. So, inorder to execue my python code, I wrote a rpc shell
script ( foo ) and made it available via ubus.
***@OpenWrt:~# cat /usr/libexec/rpcd/foo
#!/bin/sh
#!/usr/bin/python
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "bar": { "arg1": true, "arg2": 32, "arg3":
"str" }, "toto": {"arg1": true }, "tx_power": {"interface":"value",
"tx_power":10} }'
;;
call)
case "$2" in
bar)
# read the arguments
read input;
json_load "$input"
# optionally log the call
logger -t "foo" "call" "$2" "$input"
# return json object or an array
echo '{ "hello":
"aaaaaaaaaaaaaaaaaaaaaaaaaaa" }'
;;
toto)
# return json object or an array
echo '[ "item1", "item2", "item3" ]'
;;
tx_power)
# read the arguments
read input;
json_load "$input"
json_get_var $interface "interface"
json_get_var $tx_power "tx_power"
/usr/bin/python
/root/change_wifi_tx_power.py $interface $tx_power > /root/file 2>&1
echo '{ "hello": "yyyyyyyyyyyyyyyyyyy" }'
;;
esac
;;
esac
***@OpenWrt:~#
***@OpenWrt:~# ubus list -v | grep -A3 foo
'foo' @d222a4a9
"bar":{"arg1":"Boolean","arg2":"Integer","arg3":"String"}
"toto":{"arg1":"Boolean"}
"tx_power":{"interface":"String","tx_power":"Integer"}
When I tried to change the parameter using ubus, I am seeing the import errors.
***@OpenWrt:~# ubus call foo tx_power '{"interface":"wlan0", "tx_power":10}'
{
"hello": "yyyyyyyyyyyyyyyyyyy"
}
Error file:
=======
***@OpenWrt:~# cat file
Traceback (most recent call last):
File "/root/change_wifi_tx_power.py", line 41, in <module>
from libnl.attr import nla_data, nla_get_string, nla_get_u32,
nla_parse, nla_put_u32, nla_get_u64
File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/attr.py", line
15, in <module>
from libnl.linux_private.netlink import NLA_ALIGN, NLA_F_NESTED,
NLA_HDRLEN, NLA_TYPE_MASK, nlattr, NLMSG_ALIGN
File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/linux_private/netlink.py",
line 10, in <module>
from libnl.misc import (bytearray_ptr, c_int, c_uint, c_uint16,
c_uint32, c_ushort, SIZEOF_INT, SIZEOF_U16, SIZEOF_U32,
File "/mnt/usb/usr/lib/python2.7/site-packages/libnl/misc.py", line
3, in <module>
import ctypes
File "/mnt/usb/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: File not found
***@OpenWrt:~#
***@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 4.5M 332.0K 4.2M 7% /
/dev/root 2.3M 2.3M 0 100% /rom
tmpfs 61.6M 64.0K 61.5M 0% /tmp
/dev/mtdblock3 4.5M 332.0K 4.2M 7% /overlay
overlayfs:/overlay 4.5M 332.0K 4.2M 7% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda1 29.2G 68.6M 27.6G 0% /mnt/usb
***@OpenWrt:~# which python
/usr/bin/python
***@OpenWrt:~# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 23 Apr 4 17:42
/usr/bin/python -> /mnt/usb/usr/bin/python
***@OpenWrt:~# ldd python
libpython2.7.so.1.0 => /mnt/usb/usr/lib/libpython2.7.so.1.0 (0x77270000)
libpthread.so.0 => /mnt/usb/lib/libpthread.so.0 (0x7724a000)
libdl.so.0 => /lib/libdl.so.0 (0x77236000)
libutil.so.0 => /lib/libutil.so.0 (0x77225000)
libz.so.1 => /mnt/usb/usr/lib/libz.so.1 (0x77207000)
libm.so.0 => /lib/libm.so.0 (0x771e1000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x771bd000)
libc.so.0 => /lib/libc.so.0 (0x77150000)
ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x77406000)
***@OpenWrt:~# env
SSH_CLIENT=192.168.1.121 49290 22
USER=root
LD_LIBRARY_PATH=/mnt/usb/lib:/mnt/usb/usr/lib
SHLVL=1
HOME=/root
SSH_TTY=/dev/pts/0
PS1=\u@\h:\w\$
LOGNAME=root
TERM=xterm-256color
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/usb/usr/bin:/mnt/usb/usr/sbin
SHELL=/bin/ash
PWD=/root
USB=/mnt/usb
SSH_CONNECTION=192.168.1.121 49290 192.168.1.1 22
***@OpenWrt:~# ls /mnt/usb/usr/lib/python2.7/lib-dynload/_ctypes.so
/mnt/usb/usr/lib/python2.7/lib-dynload/_ctypes.so
Best Regards
Phani
Post by Damiano VerzulliPost by Phani Siriki...
I am unable to import the ctypes library while executing python script
in rpc shell script.
Please, provide details: cut&paste of terminal session, detailed command launched and error messages, screenshot, ...whatever.
Without details, I can't get a clear figure of your scenario.
Post by Phani SirikiWhen I run the same script in bash it works fine.
Are you sure it's a full BASH Shell?
Post by Phani SirikiEven without three
symbolic links.
I have created all the env variables and sourced
profile before running the script.
Again: details regarding the script!
Bye,
DV
--
Sent via my new (unlocked) Xiaomi Redmi Note 4
_______________________________________________
openwrt-users mailing list
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users