openwrt之wifi 脚本指令与 uci 指令/ ap + sta / 配置连接上级路由器

root@xxx:~# wifi help
Usage: /sbin/wifi [down|detect|reload|status]

enables (default), disables or detects a wifi configuration

root@xxx:~# wifi up/down  //打开、关闭wifi 接口(包括ap、sta),但是不写会存储(重启设备,恢复默认值)

root@xxx:~# wifi detects > /etc/config/wireless   // 生成无线配置文件(uci get / set 获取/设置此配置文件内的值)

root@xxx:~# wifi status

{
"radio0": {
"up": false,
"pending": true,
"autostart": true,
"disabled": false,
"config": {
"channel": "auto",
"hwmode": "11ng",
"path": "platform\/qca953x_wmac",
"ht_capab": [
"LDPC",
"SHORT-GI-20",
"SHORT-GI-40",
"TX-STBC",
"RX-STBC1",
"DSSS_CCK-40"
],
"htmode": "HT20",
"country": "CN",
"txpower": 15,
"disabled": false
},
"interfaces": [
{
"section": "@wifi-iface[0]",
"config": {
"mode": "ap",
"ssid": "Leedarson_9A1462",
"encryption": "psk-mixed",
"ifname": "wlan0",
"key": "12345678",
"wps_pushbutton": true,
"network": [
"lan"
],
"mode": "ap"
}
},
{
"section": "@wifi-iface[1]",
"config": {
"encryption": "psk-mixed",
"ssid": "Leedarson",
"mode": "sta",
"bssid": "B8:55:10:17:55:68",
"ifname": "wlan0-1",
"key": "12345678",
"wps_pushbutton": true,
"mode": "sta",
"network": [
"wwan"
],
"disabled": false
}
}
]
}

}

root@xxxx:~# uci 
Usage: uci [<options>] <command> [<arguments>]
Commands:
batch
export     [<config>]
import     [<config>]
changes    [<config>]
commit     [<config>]
add        <config> <section-type>
add_list   <config>.<section>.<option>=<string>
del_list   <config>.<section>.<option>=<string>
show       [<config>[.<section>[.<option>]]]
get        <config>.<section>[.<option>]
set        <config>.<section>[.<option>]=<value>
delete     <config>[.<section>[[.<option>][=<id>]]]
rename     <config>.<section>[.<option>]=<name>
revert     <config>[.<section>[.<option>]]

reorder    <config>.<section>=<position>

root@xxxx:~# uci get wireless.@wifi-iface[1].ifname   //获取 wifi interface 1 的名称

wlan0-1

root@Leedarson:~# uci set wireless.@wifi-iface[1].disabled=0    //设置 打开wifi interface 1

每次设置参数后都需要提交回写uci commit 更改/etc/config/wireless配置文件内容,然后执行/etc/init.d/network restart 后方能生效。

总结 : 

    wifi up 会启动wifi内的所有接口(ap、sta),  uci set wireless.@wifi-iface[1].disabled=0 能打开某个接口,ap 或者sta ,需要执行uci commit 回写,而后执行wifi up生效,并不会重启网卡!

    连接上级路由器配置:  

        root@xx:~# uci set wireless.@wifi-iface[1].ssid=TP-LINK_EE520F                 //wifi 名称
        root@xx:~# uci set wireless.@wifi-iface[1].bssid=8A:25:93:F2:52:0F             //wifi mac 地址
        root@xx:~# uci set wireless.@wifi-iface[1].key=abcd@1234                         //wifi 密码

        root@xx:~# uci commit                                                                                  

        root@xx:~# wifi up        



展开阅读全文

没有更多推荐了,返回首页