8-Openwrt config wifi

1.Wifi 驱动检测

https://oldwiki.archive.openwrt.org/doc/howto/wireless.overview

/package/base-files/files/etc/init.d/boot

 /sbin/wifi detect > /tmp/wireless.tmp
        [ -s /tmp/wireless.tmp ] && {
                cat /tmp/wireless.tmp >> /etc/config/wireless
        }
        rm -f /tmp/wireless.tmp

在LEDE版本里面没有这一段话,没有wifi detect这个接口,而是使用wifi config这个接口,也不知道为什么

wifi_detect_notice() {
        >&2 echo "WARNING: Wifi detect is deprecated. Use wifi config instead"
        >&2 echo "For more information, see commit 5f8f8a366136a07df661e31decce2458357c167a"
        exit 1
}

wifi_config() {
        [ ! -f /etc/config/wireless ] && touch /etc/config/wireless

        for driver in $DRIVERS; do (
                if eval "type detect_$driver" 2>/dev/null >/dev/null; then
                        eval "detect_$driver" || echo "$driver: Detect failed" >&2
                else
                        echo "$driver: Hardware detection not supported" >&2
                fi
        ); done
}

如果没办法detect到,说明wifi的驱动有问题,在openwrt中,wifi的驱动有开源的和厂家提供的闭源的,一般闭源的比较稳定,但是功能会被裁剪,开源的可能会不稳定,容易crash。

dts里面需要将驱动使能。

&wmac {
    status = "okay";
};

platform下面会出现10300000.wmac的设备。

root@LEDE:/sys/devices/platform# ls
10000000.palmbus   101c1000.ohci      gpio-keys-polled   rstctrl
10100000.ethernet  10300000.wmac      gpio-leds          serial8250
10110000.esw       alarmtimer         gpio_export        uevent
10120000.usbphy    clkctrl            pinctrl
101c0000.ehci      cpuintc@0          regulatory.0

/package/base-files/files/sbin/wifi

wifi_detect() {
        for driver in ${2:-$DRIVERS}; do (
                if eval "type detect_$driver" 2>/dev/null >/dev/null; then
                        eval "detect_$driver" || echo "$driver: Detect failed" >&2
                else
                        echo "$driver: Hardware detection not supported" >&2
                fi
        ); done
}

package/kernel/mac80211/files/lib/wifi/mac80211.sh

detect_mac80211() {  
        set wireless.radio${devidx}.hwmode=11${mode_band}  
        ${dev_id}  
        ${ht_capab}  
        set wireless.radio${devidx}.disabled=1  
   
        set wireless.default_radio${devidx}=wifi-iface  
        set wireless.default_radio${devidx}.device=radio${devidx}  
        set wireless.default_radio${devidx}.network=lan  
        set wireless.default_radio${devidx}.mode=ap  
        set wireless.default_radio${devidx}.ssid=LEDE  
        set wireless.default_radio${devidx}.encryption=none  
}

2.Wifi配置

https://oldwiki.archive.openwrt.org/doc/uci/wireless

有关wifi的脚本位于/sbin/wifi中,有关wifi的配置信息位于/etc/config/wireless中,下面分别查看:

root@OpenWrt:/# cat etc/config/wireless 

config wifi-device 'mt7628'
        option type 'mt7628'
        option vendor 'ralink'
        option band '2.4G'
        option channel  0
        option auotch '2'

config wifi-iface
        option device 'mt7628'
        option ifname 'ra0'
        option network 'lan'
        option mode 'ap'
        option ssid  NiuFi-1000AA
        option key  12345678
        option encryption 'psk2'
uci set wireless.@wifi-device[0].channel=%d && uci commit
uci set wireless.@wifi-iface[0].ssid=%s && uci commit
uci set wireless.@wifi-iface[0].key=%s && uci commit
uci set wireless.@wifi-iface[0].hidden=1 && uci commit

修改完配置参数,通过wifi down && wifi up或wifi reload进行重新生效

获取wifi的连接用户信息
root@OpenWrt:/# cat /proc/net/arp
IP address       HW type     Flags       HW address            Mask     Device
192.168.1.136    0x1         0x2         58:44:98:b9:94:44     *        br-lan
192.168.1.230    0x1         0x2         30:b4:9e:1d:da:76     *        br-lan  
192.168.1.100    0x1         0x2         20:ab:37:8d:c2:f6     *        br-lan  
wifi过滤器,只允许某些mac链接
config wifi-iface
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt'
        option network 'lan'
        option encryption 'psk'
        option key '12345678'
        option macfilter 'allow'
        list maclist '20:AB:37:8D:C2:F6'
        list maclist 'A8:02:C4:00:75:3D'
不允许某些mac链接
config wifi-iface
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt'
        option network 'lan'
        option encryption 'psk'
        option key '12345678'
        option macfilter 'deny'
        list maclist '00:05:15:0B:02:11'
        list maclist 'A8:02:C4:00:75:3D'

vi /etc/firewall.user,然后按照这个格式添加,mac地址替换为实际地址。

iptables -I FORWARD -m mac --mac-source 11:22:33:44:55:66 -j DROP
iptables -D forwarding_rule -m mac --mac-source 78:d7:5f:20:e2:9c -j ACCEPT
iptables -t nat -D prerouting_rule -p tcp -m mac --mac-source 78:d7:5f:20:e2:9c --dport 80 -j ACCEPT

3、使用AP+STA模式

https://oldwiki.archive.openwrt.org/doc/recipes/ap_sta

发布了106 篇原创文章 · 获赞 76 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/Creator_Ly/article/details/86084486
今日推荐