OpenWrt on TP-Link TL-WR941ND / TL-WR1043ND / TL-WDR3600 / TL-WDR4300

# 15.05
https://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/

# 18.06.3
https://archive.openwrt.org/releases/18.06.3/targets/ar71xx/generic/

flash tl-wr1043nd

URL=http://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/openwrt-15.05.1-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin
wget ${URL} -P /tmp
scp /tmp/openwrt-15.05-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin root@192.168.1.111:/tmp/
ssh root@192.168.1.111
echo 3 > /proc/sys/vm/drop_caches
mtd -r write /tmp/openwrt-15.05.1-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin firmware

flash tl-wdr4300

URL=http://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/openwrt-15.05.1-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin
wget ${URL} -P /tmp
scp /tmp/openwrt-15.05.1-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin root@192.168.1.111:/tmp
ssh root@192.168.1.1
mtd -r write /tmp/openwrt-15.05.1-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin firmware
telnet 192.168.1.1
passwd
exit

TP-Link TL-WR1043ND OpenWrt
http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd

# OpenWrt Sysupgrade
http://wiki.openwrt.org/doc/howto/generic.sysupgrade

#
# reset settings
#
# failsave
http://wiki.openwrt.org/de/doc/howto/generic.failsafe

#
# flash
#
# configure ip
echo "nameserver 192.168.1.5" > /etc/resolv.conf
ifconfig br-lan 192.168.1.111 up
route add default gw 192.168.1.5

# free memory
echo 3 > /proc/sys/vm/drop_caches

# download
cd /tmp
#wget http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin -P /tmp
wget https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/openwrt-15.05-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin -P /tmp

# flash
#mtd -r write /tmp/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin firmware
mtd -r write /tmp/openwrt-15.05-ar71xx-generic-tl-wdr4300-v1-squashfs-factory.bin firmware

#
# configure
#
telnet 192.168.1.1

# todo (automate)
passwd

# enable DHCP client on lan
# uci show network.lan
uci delete network.lan.ipaddr
uci delete network.lan.netmask
uci set network.lan.proto=dhcp
uci commit network

# remove old nameserver (TODO uci set ?)
echo "nameserver 192.168.1.5" > /etc/resolv.conf

# disable server on lan
# uci show | grep dhcp
uci set dhcp.lan.ignore=1
uci delete dhcp.lan.start
uci delete dhcp.lan.limit
uci delete dhcp.lan.leasetime
uci commit dhcp

reboot

#
# connect over ssh
#
ssh root@192.168.1.111

# opkg install wol
# opkg install etherwake

#
# hostname
#
uci set system.@system[0].hostname=WlanUnten
uci commit

#
# configure ssh
#
[ ! -d ~/.ssh ] && mkdir ~/.ssh
chmod 600 ~/.ssh

# create private key
dropbearkey -t rsa -f ~/.ssh/id_rsa

# create public key
touch ~/.ssh/id_rsa.pub
dropbearkey -y -f ~/.ssh/id_rsa | grep "^ssh-rsa" >> ~/.ssh/id_rsa.pub

# copy public key to host
cat ~/.ssh/id_rsa.pub | ssh root@192.168.1.111 'cat >> /etc/dropbear/authorized_keys'

HOST=192.168.1.1
#scp ~/.ssh/id_rsa.pub root@${HOST}:/tmp/
#ssh root@${HOST} "cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys; rm /tmp/id_rsa.pub"
cat ~/.ssh/id_rsa.pub | ssh root@${HOST} 'cat >> /etc/dropbear/authorized_keys'

# test login with private key
ssh -i ~/.ssh/id_rsa root@${HOST}

# create alias
echo alias ssh=\"ssh -i /root/.ssh/id_rsa\" >> /etc/profile
echo alias rsync=\"rsync -e \'ssh -i /root/.ssh/id_rsa\'\" >> /etc/profile

# show all alias
alias

# create backup with rsync
mount /dev/sda1 /mnt
rsync -av --delete --exclude=dev/* --exclude=proc/* --exclude=sys/* --exclude=tmp/* --exclude=mnt/* --exclude=run/*
--exclude=media/* root@${HOST}:/ /mnt/${HOST}/
umount /mnt

# Links
http://yorkspace.wordpress.com/2009/04/08/using-public-keys-with-dropbear-ssh-client/
http://wiki.openwrt.org/oldwiki/DropbearPublicKeyAuthenticationHowto

#
# timezone
#
http://wiki.openwrt.org/doc/uci/system#time.zones

uci set system.@system[0].timezone=CET-1CEST,M3.5.0,M10.5.0/3
uci commit

#
# swap
#
http://wiki.openwrt.org/doc/howto/usb.storage

opkg update
opkg install swap-utils

dd if=/dev/zero of=/mnt/swapfile bs=1M count=64

mkswap /mnt/swapfile
swapon /mnt/swapfile

#
# uci
#
https://wiki.openwrt.org/de/doc/uci
http://wiki.openwrt.org/doc/uci
http://wiki.openwrt.org/doc/howto/notuci.config

#
# LEDs (dep)
#
http://wiki.openwrt.org/doc/uci/system
# USB led works out of the box under OpenWrt Attitude Adjustment 12.09

echo 1 > /sys/devices/platform/leds-gpio/leds/tl-wr1043nd\:green\:usb/brightness

cat /etc/config/system

config 'led' 'usb_led'
option 'name' 'USB'
option 'sysfs' 'tl-wr1043nd:green:usb'
option 'trigger' 'usbdev'

set system.usb_led=led
set system.usb_led.name='USB'
set system.usb_led.sysfs='tl-wr1043nd:green:usb'
set system.usb_led.trigger='usbdev'
set system.usb_led.dev='1-1'
set system.usb_led.interval='50'
uci commit system

#
# cron
#
http://wiki.openwrt.org/doc/howto/notuci.config#etccrontabsroot
root@WlanUnten:/# cat /etc/crontabs/root
41 14 * * * /bin/mount /dev/sda1 /mnt/; /mnt/backup.sh /mnt/; /bin/umount /mnt
#

#
# wifi
#
http://www.panticz.de/tplink-etc-config-wireless

#
# HDD
#
opkg install hd-idle
uci set hd-idle.@hd-idle[0].idle_time_interval=180
uci commit

http://wiki.openwrt.org/doc/howto/usb.storage

#
# old / test
#
uci set dhcp.ignore=1

uci set wireless.wl0.country=DE

uci set network.lan.type=bridge
uci commit
reboot

uci set network.lan.ifname="eth0.0 eth0.1"
uci commit

uci set network.lan.peerdns=1

uci -P /var/state show network
uci -P /var/state show wireless

# set fixed ip
#uci set network.lan.ipaddr=192.168.1.111
#uci set network.lan.dns=192.168.1.5
#uci set network.lan.gateway=192.168.1.5
#uci commit network

# copy public key to OpenWrt
# http://wiki.openwrt.org/doku.php?id=oldwiki:dropbearpublickeyauthenticationhowto
cat ~/.ssh/id_rsa.pub | ssh root@openwrt 'cat >> /etc/dropbear/authorized_keys'

###########################################################

#
# OLD
#

# neu
http://downloads.openwrt.org/backfire/10.03.1/ar71xx/
http://downloads.openwrt.org/backfire/10.03.1/ar71xx/openwrt-ar71xx-tl-wr1043nd-v1-squashfs-factory.bin

sed -i 's|192.168.1.1|192.168.2.254|g' /etc/config/network

# openvpn
https://forum.openwrt.org/viewtopic.php?pid=8495

Configure OpenWRT
# set ip on localhost
#sudo ifconfig eth0 192.168.1.100 up
dhclient eth0

# change password on web interfece
http://192.168.1.1
System > Admin Password

# ssh login to OpenWRT
ssh root@192.168.1.1

# configure ip network
vi /etc/config/network
config interface lan
option ipaddr 192.168.2.254

# reboot
reboot

# login again
ssh root@192.168.2.254

# install filesystems
opkg install kmod-usb2 kmod-usb-storage kmod-fs-vfat kmod-fs-ext2

# Wake-On-Lan (etherwake -i br-lan 00:11:22:33:44:55)
opkg install etherwake

# OPTIONAL: remove unused packages
opkg remove ppp-mod-pppoe
opkg remove ppp
opkg remove kmod-pppoe
opkg remove kmod-ppp

minicom
# ttyUSB0
opkg install kmod-usb-serial-ftdi minicom

# configure tty device
echo "pu port /dev/ttyUSB0" >> /etc/minirc.dfl

OpenWRT download
http://downloads.openwrt.org/snapshots/trunk/ar71xx/

Buttons
mkdir -p /etc/hotplug.d/button
download 00-button
wget http://dl.panticz.de/openwrt/00-button

WPS on OpenWRT
https://gist.github.com/alghanmi/4de45337ca517ebe3a56

Upstream DNS provider (WAN DNS)
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration

uci -q delete network.wan.dns
uci add_list network.wan.dns="94.140.14.14"
uci add_list network.wan.dns="94.140.15.15"
uci set network.wan.peerdns="0"
uci commit network
 
/etc/init.d/network restart

Wireguard
https://openwrt.org/docs/guide-user/services/vpn/wireguard/client

opkg update
opkg install wireguard

Aircrack
opkg install wireless-tools aircrack-ng

Links
http://www.tp-link.com/en/products/details/?categoryid=2166&model=TL-WDR4300 - TL-WDR4300 (128 MB RAM, 2x USB)
http://www.tp-link.com/en/products/details/?categoryid=238&model=TL-WR1043ND - TL-WR1043ND (32 MB RAM, 1x USB)
http://www.tp-link.com/en/products/details/?categoryid=238&model=TL-WR941ND - TL-WR941ND (no USB)
http://gumstix.org/add-software-packages.html
http://downloads.openwrt.org/backfire/10.03.1/
http://www.kammerath.net/openwrt-tp-link-wr1043nd-installieren.html
http://www.kammerath.net/wlan-sendeleistung-erhoehen.html
http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd
http://wiki.openwrt.org/toh/tp-link/tl-wr941nd
http://wiki.openwrt.org/doc/recipes/bridgedap
http://www.tp-link.com/support/download.asp?a=1&m=TL-WR941ND

http://wiki.openwrt.org/doc/howto/hardware.button?s[]=uci%20add
http://wiki.openwrt.org/doc/uci/network
http://wiki.openwrt.org/doc/techref/uci
http://wiki.openwrt.org/doc/devel/luci