PPP Over a WiFi232 (PPP Over TCP)

Now that my Mac 512Ke is able to use PPP for native TCP/IP, I wanted an easy way to do PPP between it and an OpenBSD server on my network. I initially did this with a physical serial cable, but was later able to do it over TCP so I could retain the use of my WiFi232.

PPP Over Serial

I'll first explain how to do PPP with a physical serial cable connected between my Mac and an OpenBSD server. You can skip to the TCP section if this is not relevant to you.

For the Mac 128K/512K/Plus, this cable needs to have an RS422 DB9 pin-out on the Mac side and RS232 on the OpenBSD side with a null modem adapter on the RS232 side. On the Mac Plus you'll also need a DB9-to-DIN8 connector for the RS422 side. For any other computer, this would be an RS232-to-RS232 cable with a null modem adapter or wiring.

db9 breakout board with wires connected about
Note: typical "RS232 to RS485/RS422" adapters sold on Amazon do not work as-is and require a custom pin-out on the RS422 side. I recommend wiring them as straight-through and using a null modem adapter just when you need one.

Once the cable is in place, connectivity can be verified with cu on the OpenBSD side and something like MacTerminal (or my preferred terminal, ZTerm) on the Mac. Make sure you have the baud rate set to the same on both sides.

On OpenBSD, serving PPP is as easy as first creating a ppp0 interface:

# echo up > /etc/hostname.ppp0
# sh /etc/netstart ppp0

Then create a pppd line in /etc/ttys for the appropriate serial port (commenting out an existing disabled line for getty if needed):

tty07   "/usr/sbin/pppd 192.168.3.1:192.168.3.2 local nodetach noauth passive 57600" unknown on

This sets up pppd to listen passively on tty07 (com7 on my server) waiting for the Mac to attempt PPP negotiation at 57,600 baud. It disables authentication since there is no point in having it on a physical connection that goes directly to the Mac. Once established, the server will assign 192.168.3.1 to its ppp0 interface and 192.168.3.2 to the Mac.

After editing /etc/ttys, give init a SIGHUP to reload the file and pppd should start up momentarily.

# kill -HUP 1

On the Mac side, open the Config PPP applet in the Control Panel and set the "Port Speed" in the Config screen to match the OpenBSD side and everything else can be left to the defaults.

screenshot of macintosh MacPPP control panel
another screenshot of macintosh MacPPP control panel settings

In the MacTCP applet, you should see a PPP option. Click "Moreā€¦" and set the "Obtain Address" option to "Server" and specify the Domain Name Server Information such as a Domain of . and an IP address of your DNS server. If the "Open" button is disabled in the Config PPP section, you probably don't have the MacTCP settings correct.

screenshot of macintosh MacTCP settings
another screenshot of macintosh MacTCP settings

Once the "Open" button is enabled, click it and it should quickly negotiate with the OpenBSD server.

pppd[97688]: pppd 2.3.5 started by root, uid 0
pppd[97688]: Using interface ppp0
pppd[97688]: Connect: ppp0 <--> /dev/tty07
pppd[97688]: LCP: timeout sending Config-Requests
pppd[97688]: local  IP address 192.168.3.1
pppd[97688]: remote IP address 192.168.3.2
The LCP timeout is normal, it just means it didn't detect a response when it first started, but then went into passive mode waiting for the Mac to attempt negotiation rather than exiting.

If you want the Mac to actually be able to route out to the internet, enable routing and NAT in /etc/pf.conf on the OpenBSD side:

# echo net.inet.ip.forwarding=1 >> /etc/sysctl.conf
# sysctl net.inet.ip.forwarding=1
net.inet.ip.forwarding: 0 -> 1

# cat >> /etc/pf.conf
pass in on ppp0 to !(ppp0) scrub (random-id) tag "ok-to-nat"
pass out on egress tagged "ok-to-nat" modulate state nat-to (egress)
^D
# pfctl -f /etc/pf.conf

PPP Over TCP

While the physical serial cable worked well, I still want to keep my Mac connected to my WiFi232 so I can choose whether to use it to telnet to BBSes in programs like ZTerm which don't support telnet/MacTCP, or to establish a PPP connection. You know, just like a real modem would when dialing into a BBS or dialing into an ISP.

The first step is to get the OpenBSD server to bind pppd to a TCP socket. I'll use socat (available via pkg_add socat) to do this, binding to the server's LAN IP (not its PPP server IP) which the WiFi232 will be able to reach on port 1000:

#!/bin/sh

ptydir=`mktemp -d /tmp/socat.XXXXXXX`

while true; do
	pty=""
	socat_pid=0

	rm -f ${ptydir}/tcp_pppd

	socat pty,raw,echo=0,link=${ptydir}/tcp_pppd \
		tcp-listen:1000,bind=192.168.1.4 &
	socat_pid=$!

	sleep 1
	pty=`readlink ${ptydir}/tcp_pppd`
	if [ "$pty" = "" ]; then
		echo "can't find pty link, did socat fail to start?"
		break
	fi

	/usr/sbin/pppd ${pty} 57600 192.168.3.1:192.168.3.2 \
		local nodetach noauth passive \
		lcp-echo-interval 10 lcp-echo-failure 2
	sleep 1

	kill -9 $socat_pid 2>/dev/null
done

if [ ! "${ptydir}" = "" ]; then
	rm -rf ${ptydir}
fi

This script will run socat in the background, listening on a local Unix socket in /tmp, and then run pppd in passive mode waiting for a negotiation on that socket. When socat receives a TCP connection on port 1000, it will connect the I/O of that TCP connection to the I/O of pppd.

If we connect to the server on port 1000, we should see PPP negotiation chatter:

$ nc 192.168.1.4 1000
~y}#A!}!}!}[...]

Now on the Mac, we just need to adjust the settings (or create a new PPP Server profile) in the Config PPP applet. For the "Phone num", specify the IP and port where socat is listening, and in the "Modem Init" box, enter ATNET0. This instructs the WiFi232 to disable processing and escaping telnet negotiation characters, since we're not actually connecting to a telnet server.

screenshot of macintosh PPP server settings

Sending Files With socat

A convenient way to transfer files between a computer on your network and your WiFi232-enabled Mac is to plumb lrzsz to socat. lsz is a simple utility to send a file with ZMODEM and lsx does it with XMODEM.

To send a file macpaint.sea.hqx from the computer at 192.168.1.4, run:

$ socat tcp-listen:1234 system:"lsz macpaint.sea.hqx"

Now on the Mac, open a terminal program that supports ZMODEM (or use lsx if your program only supports XMODEM) and issue:

ATDT 192.168.1.4:1234

As soon as the WiFi232 connects, socat will start lsz and connect its I/O to the TCP socket, and the file should automatically start downloading over ZMODEM on the Mac.

Questions or comments?
Please feel free to contact me.