Skip to content

Instantly share code, notes, and snippets.

@olivierlacan
Last active July 8, 2019 06:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivierlacan/13a4c5c710beba6ee0fc20fdba8d29df to your computer and use it in GitHub Desktop.
Save olivierlacan/13a4c5c710beba6ee0fc20fdba8d29df to your computer and use it in GitHub Desktop.
Version légèrement modifiée du Startup script créé par bob62 sur https://lafibre.info/remplacer-livebox/tuto-remplacer-la-livebox-par-un-routeur-dd-wrt-internet-tv
### Version 16 20181010
### https://lafibre.info/remplacer-livebox/tuto-remplacer-la-livebox-par-un-routeur-dd-wrt-internet-tv/
### Informations utilisateur
user=fti/abcdefg
pass=hijklmn
maclivebox=01:23:45:67:89:AB
verlivebox=3
serlivebox=ABCDE0123456789
# macdecodeur inutile si aucun décodeur n'est utilisé donc commenté
# macdecodeur=01:23:45:67:89:CD,01:23:45:67:89:EF
dnsorange=80.10.246.3,81.253.149.10
### Detection switch Atheros / Broadcom et port WAN
wanif=eth0
swconfswitch=$(swconfig list | awk '/^Found:/ {print $2}')
if [[ "$swconfswitch" ]]
then
wanport=$(swconfig dev $swconfswitch show |
awk '/^\s*ports:/ {p=substr($2,1,1)"t "substr($3,1,1)"t"} END {print p}')
else
wanport=/proc/switch/$wanif/vlan/2/ports
wanport=$(awk '/\d/ {p=substr($1,1,1)"t "substr($2,1,1)"t"} END {print p}' $wanport)
fi
### VLAN Internet
# VLAN 832 (Internet) sur le port WAN
if [[ "$swconfswitch" ]]
then
swconfig dev $swconfswitch vlan 2 set vid 832
swconfig dev $swconfswitch vlan 2 set ports "$wanport"
swconfig dev $swconfswitch set apply
else
echo "$wanport" > /proc/switch/$wanif/vlan/832/ports
echo "" > /proc/switch/$wanif/vlan/2/ports
fi
# VLAN sur le systeme
vconfig set_name_type VLAN_PLUS_VID_NO_PAD
vconfig add $wanif 832
vconfig rem vlan2
### Support TV, VLAN flux
# VLAN 840 (flux) sur le port WAN
if [[ "$swconfswitch" ]]
then
swconfig dev $swconfswitch vlan 4 set vid 840
swconfig dev $swconfswitch vlan 4 set ports "$wanport"
swconfig dev $swconfswitch set apply
else
echo "$wanport" > /proc/switch/$wanif/vlan/840/ports
fi
# VLAN sur le systeme
vconfig add $wanif 840
# Ajout du VLAN 840 au bridge LAN deja up
brctl addif $(nvram get lan_ifname) vlan840
### Modification du client DHCP pour prise en compte des options Orange
cp -a /sbin /tmp/sbin_rw
mkdir /tmp/sbin
ln -s /bin/busybox /tmp/sbin/udhcpc
rm /tmp/sbin_rw/udhcpc
cat << \EOF > /tmp/sbin_rw/tohex
#!/bin/sh
for h in $(echo $1 | sed "s/\(.\)/\1 /g")
do
printf "%02x$2" \'$h
done | sed "s/$2$//"
EOF
maclivebox=$(echo $maclivebox | tr '[a-z]' '[A-Z]')
cat << EOF > /tmp/sbin_rw/udhcpc
#!/bin/sh
if echo \$* | grep -q vlan832
then
r=\$(openssl rand -base64 12)
s=3c12\$(tohex \$r)0313\$(tohex \${r:15})
h=\$(echo -n \${r:15}$pass\$r | md5sum | cut -c1-32)
exec /tmp/sbin/udhcpc \$* \\
-x 0x3c:\$(tohex sagem) \\
-x 0x3d:01${maclivebox//:/} \\
-x 0x4d:\$(tohex +FSVDSL_livebox.Internet.softathome.Livebox$verlivebox) \\
-x 0x5a:00000000000000000000001a0900000558010341010d\$(tohex $user)\$s\$h
fi
exec /tmp/sbin/udhcpc \$*
EOF
chmod +x /tmp/sbin_rw/tohex
chmod +x /tmp/sbin_rw/udhcpc
mount -o bind /tmp/sbin_rw /sbin
### Support TV, options DHCP
f=/tmp/dnsmasq.livebox.conf
echo dhcp-option=tag:decodeur,option:dns-server,$dnsorange > $f
if [[ "$serlivebox" ]]
then
echo -n dhcp-option=tag:decodeur,125,00:00:0d:e9:24: >> $f
echo -n 04:06:$(tohex ${maclivebox//:/} : | cut -c 1-17): >> $f
echo -n 05:0f:$(tohex ${serlivebox} :): >> $f
echo 06:09:$(tohex Livebox :):20:$(tohex $verlivebox) >> $f
fi
# macdecodeur inutile si aucun décodeur n'est utilisé donc commenté
# for mac in ${macdecodeur//,/ }
# do
# echo dhcp-host=$mac,set:decodeur >> $f
# done
### Restart du client DHCP sur le VLAN 832 (et de dnsmasq)
stopservice wan
sleep 5
startservice wan
### Support TV, start du VLAN 840
ifconfig vlan840 up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment