OpenWRT

From Smithnet Wiki
Jump to navigation Jump to search

Backgrund to setup

OpenWRT setmentation

Regulatory Domains

iw reg set GB
iw reg get

Regulatory domains defined in:

/lib/firmware/regulatory.db

See here for explanation of format.

To build:

  • Install: python-m2crypro
  • Edit db.txt as required
  • python db2bin.py regulatory.db db.txt

Channels

Taken from output of:

iw list

2.4 GHz

CA

  • 2412 MHz [1] (30.0 dBm)
  • 2417 MHz [2] (30.0 dBm)
  • 2422 MHz [3] (30.0 dBm)
  • 2427 MHz [4] (30.0 dBm)
  • 2432 MHz [5] (30.0 dBm)
  • 2437 MHz [6] (30.0 dBm)
  • 2442 MHz [7] (30.0 dBm)
  • 2447 MHz [8] (30.0 dBm)
  • 2452 MHz [9] (30.0 dBm)
  • 2457 MHz [10] (30.0 dBm)
  • 2462 MHz [11] (30.0 dBm)
  • 2467 MHz [12] (disabled)
  • 2472 MHz [13] (disabled)
  • 2484 MHz [14] (disabled)

IN, SA

  • 2412 MHz [1] (20.0 dBm)
  • 2417 MHz [2] (20.0 dBm)
  • 2422 MHz [3] (20.0 dBm)
  • 2427 MHz [4] (20.0 dBm)
  • 2432 MHz [5] (20.0 dBm)
  • 2437 MHz [6] (20.0 dBm)
  • 2442 MHz [7] (20.0 dBm)
  • 2447 MHz [8] (20.0 dBm)
  • 2452 MHz [9] (20.0 dBm)
  • 2457 MHz [10] (20.0 dBm)
  • 2462 MHz [11] (20.0 dBm)
  • 2467 MHz [12] (20.0 dBm)
  • 2472 MHz [13] (20.0 dBm)
  • 2484 MHz [14] (disabled)

PA

  • 2412 MHz [1] (24.0 dBm)
  • 2417 MHz [2] (24.0 dBm)
  • 2422 MHz [3] (24.0 dBm)
  • 2427 MHz [4] (24.0 dBm)
  • 2432 MHz [5] (24.0 dBm)
  • 2437 MHz [6] (24.0 dBm)
  • 2442 MHz [7] (24.0 dBm)
  • 2447 MHz [8] (24.0 dBm)
  • 2452 MHz [9] (24.0 dBm)
  • 2457 MHz [10] (24.0 dBm)
  • 2462 MHz [11] (24.0 dBm)
  • 2467 MHz [12] (24.0 dBm)
  • 2472 MHz [13] (24.0 dBm)
  • 2484 MHz [14] (disabled)

TW

  • 2412 MHz [1] (24.0 dBm)
  • 2417 MHz [2] (24.0 dBm)
  • 2422 MHz [3] (24.0 dBm)
  • 2427 MHz [4] (24.0 dBm)
  • 2432 MHz [5] (24.0 dBm)
  • 2437 MHz [6] (24.0 dBm)
  • 2442 MHz [7] (24.0 dBm)
  • 2447 MHz [8] (24.0 dBm)
  • 2452 MHz [9] (24.0 dBm)
  • 2457 MHz [10] (24.0 dBm)
  • 2462 MHz [11] (24.0 dBm)
  • 2467 MHz [12] (disabled)
  • 2472 MHz [13] (disabled)
  • 2484 MHz [14] (disabled)

UK

  • 2412 MHz [1] (20.0 dBm)
  • 2417 MHz [2] (20.0 dBm)
  • 2422 MHz [3] (20.0 dBm)
  • 2427 MHz [4] (20.0 dBm)
  • 2432 MHz [5] (20.0 dBm)
  • 2437 MHz [6] (20.0 dBm)
  • 2442 MHz [7] (20.0 dBm)
  • 2447 MHz [8] (20.0 dBm)
  • 2452 MHz [9] (20.0 dBm)
  • 2457 MHz [10] (20.0 dBm)
  • 2462 MHz [11] (20.0 dBm)
  • 2467 MHz [12] (20.0 dBm)
  • 2472 MHz [13] (20.0 dBm)
  • 2484 MHz [14] (disabled)

5 GHz

CA

  • 5180 MHz [36] (23.0 dBm)
  • 5200 MHz [40] (23.0 dBm)
  • 5220 MHz [44] (23.0 dBm)
  • 5240 MHz [48] (23.0 dBm)
  • 5260 MHz [52] (24.0 dBm) (radar detection)
  • 5280 MHz [56] (24.0 dBm) (radar detection)
  • 5300 MHz [60] (24.0 dBm) (radar detection)
  • 5320 MHz [64] (24.0 dBm) (radar detection)
  • 5500 MHz [100] (24.0 dBm) (radar detection)
  • 5520 MHz [104] (24.0 dBm) (radar detection)
  • 5540 MHz [108] (24.0 dBm) (radar detection)
  • 5560 MHz [112] (24.0 dBm) (radar detection)
  • 5580 MHz [116] (24.0 dBm) (radar detection)
  • 5600 MHz [120] (disabled)
  • 5620 MHz [124] (disabled)
  • 5640 MHz [128] (disabled)
  • 5660 MHz [132] (24.0 dBm) (radar detection)
  • 5680 MHz [136] (24.0 dBm) (radar detection)
  • 5700 MHz [140] (24.0 dBm) (radar detection)
  • 5720 MHz [144] (24.0 dBm) (radar detection)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

IN

  • 5180 MHz [36] (30.0 dBm)
  • 5200 MHz [40] (30.0 dBm)
  • 5220 MHz [44] (30.0 dBm)
  • 5240 MHz [48] (30.0 dBm)
  • 5260 MHz [52] (24.0 dBm)
  • 5280 MHz [56] (24.0 dBm)
  • 5300 MHz [60] (24.0 dBm)
  • 5320 MHz [64] (24.0 dBm)
  • 5500 MHz [100] (24.0 dBm)
  • 5520 MHz [104] (24.0 dBm)
  • 5540 MHz [108] (24.0 dBm)
  • 5560 MHz [112] (24.0 dBm)
  • 5580 MHz [116] (24.0 dBm)
  • 5600 MHz [120] (24.0 dBm)
  • 5620 MHz [124] (24.0 dBm)
  • 5640 MHz [128] (24.0 dBm)
  • 5660 MHz [132] (24.0 dBm)
  • 5680 MHz [136] (24.0 dBm)
  • 5700 MHz [140] (24.0 dBm)
  • 5720 MHz [144] (24.0 dBm)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (30.0 dBm)
  • 5865 MHz [173] (30.0 dBm)

PA

  • 5180 MHz [36] (30.0 dBm)
  • 5200 MHz [40] (30.0 dBm)
  • 5220 MHz [44] (30.0 dBm)
  • 5240 MHz [48] (30.0 dBm)
  • 5260 MHz [52] (30.0 dBm)
  • 5280 MHz [56] (30.0 dBm)
  • 5300 MHz [60] (30.0 dBm)
  • 5320 MHz [64] (30.0 dBm)
  • 5500 MHz [100] (30.0 dBm)
  • 5520 MHz [104] (30.0 dBm)
  • 5540 MHz [108] (30.0 dBm)
  • 5560 MHz [112] (30.0 dBm)
  • 5580 MHz [116] (30.0 dBm)
  • 5600 MHz [120] (30.0 dBm)
  • 5620 MHz [124] (30.0 dBm)
  • 5640 MHz [128] (30.0 dBm)
  • 5660 MHz [132] (30.0 dBm)
  • 5680 MHz [136] (30.0 dBm)
  • 5700 MHz [140] (30.0 dBm)
  • 5720 MHz [144] (30.0 dBm)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)

UK

  • 5180 MHz [36] (23.0 dBm)
  • 5200 MHz [40] (23.0 dBm)
  • 5220 MHz [44] (23.0 dBm)
  • 5240 MHz [48] (23.0 dBm)
  • 5260 MHz [52] (20.0 dBm) (radar detection)
  • 5280 MHz [56] (20.0 dBm) (radar detection)
  • 5300 MHz [60] (20.0 dBm) (radar detection)
  • 5320 MHz [64] (20.0 dBm) (radar detection)
  • 5500 MHz [100] (26.0 dBm) (radar detection)
  • 5520 MHz [104] (26.0 dBm) (radar detection)
  • 5540 MHz [108] (26.0 dBm) (radar detection)
  • 5560 MHz [112] (26.0 dBm) (radar detection)
  • 5580 MHz [116] (26.0 dBm) (radar detection)
  • 5600 MHz [120] (26.0 dBm) (radar detection)
  • 5620 MHz [124] (26.0 dBm) (radar detection)
  • 5640 MHz [128] (26.0 dBm) (radar detection)
  • 5660 MHz [132] (26.0 dBm) (radar detection)
  • 5680 MHz [136] (26.0 dBm) (radar detection)
  • 5700 MHz [140] (26.0 dBm) (radar detection)
  • 5720 MHz [144] (26.0 dBm) (radar detection)
  • 5745 MHz [149] (20.0 dBm) (radar detection)
  • 5765 MHz [153] (20.0 dBm) (radar detection)
  • 5785 MHz [157] (20.0 dBm) (radar detection)
  • 5805 MHz [161] (20.0 dBm) (radar detection)
  • 5825 MHz [165] (20.0 dBm) (radar detection)
  • 5845 MHz [169] (20.0 dBm) (radar detection)
  • 5865 MHz [173] (20.0 dBm) (radar detection)

Devices

TP-Link Archer C2600

  • Device page
  • 1.4 GHz CPU, 32 MiB flash, 512 MiB RAM
  • Currently Installed: 23.05.3
  • Max Power (2.4/5): 20/26 dBm

TP-Link Archer C7 v4

  • Device page
  • 775 MHz CPU, 16 MiB flash, 128 MiB RAM
  • Currently Installed: 23.05.3
  • Max Power (2.4/5): 24/30 dBm

HooToo TripMate Nano (HT-TM02)

  • Device page
  • 360 MHz CPU, 8 MiB flash, 32 MiB RAM
  • Currently Installed: 19.07.10
  • Initial installation here
  • Can remove kernel PPP packages

Mode on Startup

Read status of buttons:

root@wifi-ht:~# cat /sys/kernel/debug/gpio
 gpiochip0: GPIOs 0-21, parent: platform/10000600.gpio, 10000600.gpio:
 gpio-7   (                    |ht-tm02:blue:wlan   ) out lo    
 gpio-10  (                    |reset               ) in  hi    
 gpio-12  (                    |ht-tm02:green:lan   ) out lo    
 gpio-14  (                    |modeswitch          ) in  lo    
root@wifi-ht:~#

For modeswitch, "lo" is Wired, "hi" is WiFi position.

Could also use slide-switch package. Biggest advantage of this is that it triggers at boot time, not just a switch change.

opkg install slide-switch

On startup On mode (button) change, copy files from /etc/config/config-wired or config-wireless to /etc/config with:

  • etc/rc.d/S15config-mode -> /etc/config/config-mode
#!/bin/sh
#
# Set mode according to slide switch
#

CONFIG=/etc/config

state=$(grep modeswitch /sys/kernel/debug/gpio | sed 's/.*\(lo\|hi\).*/\1/')
case "$state" in
        lo)
                mode="wired"
                ;;
        hi)
                mode="wireless"
                ;;
        *)
                echo "unknown"
                return 1
                ;;
esac

message="Using config mode: $mode"
echo $message
logger $message

config="$CONFIG/config-$mode"
for file in $(ls $config)
do
        echo $file
        cp "$config/$file" $CONFIG
done

Package Management

opkg update
opkg list
opkg list-installed
opkg install blah
opkg remove blah

Useful Additional Packages

  • ?

Reset

  • Controlled by /etc/rc.button/reset
  • Quick press of reset button reboots
  • Failsafe (long press) forces network to:
    • 192.168.1.1 / 255.255.255.0
    • SSH open with root / no password
    • "firstboot" command to revert to factory defaults
    • Hard factory reset (to 192.168.1.1.): umount /overlay && jffs2reset && reboot now
    • "mount_root" to mount root partition

Configuration and Commands

Misc

In /etc/config:

  • wireless
  • dhcp
  • system
  • network
  • firewall

Custom startup scripts:

  • /etc/rc.local

In /etc:

  • sysupgrade.conf

DHCP

Custom options may be given per network, eg: for NTP:

  • 42, 192.168.1.1

DNS

  • resolv.conf symlinked to /tmp/resolv.conf which points to local dnsmasq service which delivers from its cache or via DNS servers pointed to by proxies resolv.conf.auto (DHCP client updated)
  • See also here

Wifi commands

iw phy0 info
iw reg get
iw reg set GB

See other iw commands and Reg Database.

USB and File sharing

Add packages:

opkg install kmod-usb-core kmod-usb-storage usbutils block-mount luci-app-minidlna

Show device:

ls /dev/sd*
lsusb -t

Driver USB 1, 2, 3: uhci/ohci, ehci, xhci

Show device:

# block info /dev/sda1
/dev/sda1: UUID="9814-E49A" LABEL="2" VERSION="FAT16" TYPE="vfat"

Mount FAT32 USB stick:

/sbin/block mount
cd /mnt/sda1

See also here

LEDs

Buttons

procd interface:

root@hootoo:/etc/rc.button# ls
BTN_0     failsafe  power     reset     rfkill
root@hootoo:/etc/rc.button#

scripts need to be named according to the button name, like "BTN_0" or "wps" (see here). They receive values:

  • $BUTTON: Name of button
  • $ACTION: "pressed", "timeout" or "released". For released, script returns timeout seconds (for hold down).
  • $SEEN: number of seconds
root@wifi-ht:/etc/rc.button# cat BTN_0 
#!/bin/sh

logger "Button $BUTTON: $ACTION (Seen $SEEN)"

return 0
root@wifi-ht:/etc/rc.button#

C2600

Has an additional "lights_toggle":

[ "${ACTION}" = "released" ] || exit 0

led="c2600:white:general"
device="wifinet3"

logger "Button $ACTION, will toggle Guest Wifi"
echo 1 > /sys/class/leds/$led/brightness
case $(uci get wireless.$device.disabled) in
    0)
        uci set wireless.$device.disabled=1
        logger "Wifi disabled"
    ;;
    1)
        uci set wireless.$device.disabled=0
        logger "Wifi enabled"
    ;;
esac

wifi reload
service network reload
sleep 1
echo 0 > /sys/class/leds/$led/brightness

return 0

6in4

Requires packages: 6in4 luci-proto-ipv6 and used tunnel from Hurricane Electric.

  • Restart network
  • In LUCI, edit wan6 and change protocol from DHCPv6 to RFC4213
  • Set Remote IPv4 address (eg 74.82.46.6)
  • Set Local IPv6 address
  • Set IPv6 routed prefix (Routed /48)
  • Dynamic tunnel
    • Tunnel ID
    • HE username/password
ping ipv6.google.com

Manual Config:

opkg install 6in4
uci set network.henet=interface
uci set network.henet.proto=6in4
uci set network.henet.peeraddr=[get IPv4 of HE gateway] 
uci set network.henet.ip6addr='[IPv6 from HE]'
uci set network.henet.tunnelid=[HE tunnel ID]
uci set network.henet.username=[HE username]
uci set network.henet.password='[HE password]'
uci commit network

uci set firewall.@zone[1].network='wan henet'
uci commit firewall

ifup henet
/etc/init.d/firewall restart