Due to being locked down over the Christmas and New Year period, I've had a lot of spare time to continue this, and I have eventually made it work. My Asus router is now connected to the ONT and is acting as the router and the SH2 is connected to one of the LAN ports on the Asus router and is only used for Digital Voice phone and I am able to make phone calls.
I worked out that the SH2 makes a call to
https://linediscovery.hub.bt.com/ and passes the PPPoE Host-Uniq tag value and the PPPoE Session ID and it is returned the SIP details which it then uses to initiate the SIP connection for phone calls. The local and remote IP addresses and MAC addresses, and the AC Name are not important. The SH2 changes the Host-Uniq value every time it makes a new connection which makes it more difficult to get this to work.
The Asus router is running a version of linux, the source code is freely available on the Asus web site, and it is possible to configure SSH access in order to run commands on the Asus router in order to reconfigure things.
I downloaded a copy of the open source PPPoE server
https://dianne.skoll.ca/projects/rp-pppoe/ I changed it so that on receipt of the PADI message, it extracts the Host-Uniq tag, and reconfigures the Asus router to use this value on it's external PPPoE connection, and then makes the Asus router re-establish the PPPoE session. Once it is re-established, it gets the PPPoE Session ID and uses that later in the PADS message sent back to the SH2 so that the SH2 will use that, along with the host-Uniq value, when making a call to
https://linediscovery.hub.bt.com/
In order to change the Host-Uniq tag on the Asus router and cause it to reconnect the following commands can be run on the Asus router:
nvram set wan0_pppoe_hostuniq=20EF000
nvram set rc_service="restart_wan_if 0"
kill -SIGUSR1 1
In order to get the PPPoE session ID on the Asus router, the following command can be run:
cat /proc/net/pppoe|cut -d" " -f1
A linux server (Raspberry Pi or other), needs to be running on the same LAN as the SH2. On this server, the changed RP-PPPOE needs to be installed and the file /etc/ppp/pppoe-server-options needs to contain the following (192.168.0.1 is the Asus LAN IP Address):
noauth
noproxyarp
ms-dns 192.168.0.1
lcp-echo-interval 10
lcp-echo-failure 2
IP forwarding needs to be enabled on the linux server :
echo 1 > /proc/sys/net/ipv4/ip_forward
A NAT rule needs to be added on the linux server to NAT the data coming from the SH2 to the internet. I use a bridge interface br0, but for most servers it will be eth0 or similar:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o br0 -j MASQUERADE
The Asus router needs to be configured to forward UDP traffic on port 5050 to an additional IP address which will be assigned to the linux server. The linux server will have 2 IP addresses - it's main one and the one used for PPP. I assigned 192.168.0.11 for this purpose.
A NAT rule needs to be added to the linux server to forward the voice data from the internet through the PPP connection to the SH2:
iptables -t nat -A PREROUTING -d 192.168.0.11 -p udp --dport 5050 -j DNAT --to-destination 192.168.1.1:5050
The hacked PPPoE server needs to be run (the -o 1 is ignored in my hacked server and be replaced with the Session ID):
pppoe-server -C acc-aln2.l-zzz -I br0 -L 192.168.0.11 -R 192.168.1.1 -o 1 -N 1 -k
The SH2 will then think it's connected to the ONT and connect the Digital Voice even though it's running on the LAN.