rpc_wifi_connect() will return 0 on successful connection, so check for
that. Also, check that if passphrase is given, that it's the minimum 8
chars per WPA Wifi.
Fix an error I introduced in porting wifinina to netdev. The driver was
starting a client on the socket once, during Connect. The first UDP
send on the socket would succeed, any subsequent sends would fail. The
fix is to start the client on the socket for each UDP send.
I think I see the logic in this design, so the fix makes sense. If the
device was sending to many UDP clients, it could use a single socket,
but change the dst addr for each send. The pkt data would be queued to
hw just once, and then sent from hw to each client dst addr. This would
be a real efficient way to multicast to many clients.
According to man page accept(2), accept returns new client sockfd and
remote peer ip:port. This patch corrects the Accept() prototype in the
netdever interface to not take in an ip:port arg, but rather return an
ip:port for remote peer.
Tested with examples/net/tcpecho on wioterminal and nano-rp2040. Here's
a run with wioterminal:
SERVER
============
sfeldma@nuc:~/work/drivers$ tinygo flash -monitor -target wioterminal -size short -stack-size=8kb ./examples/net/tcpecho
code data bss | flash ram
110876 2552 11212 | 113428 13764
Connected to /dev/ttyACM2. Press Ctrl-C to exit.
Realtek rtl8720dn Wifi network device driver (rtl8720dn)
Driver version : 0.0.1
RTL8720 firmware version : 2.1.2
MAC address : 2c:f7:f1:1c:9b:2f
Connecting to Wifi SSID 'test'...CONNECTED
DHCP-assigned IP : 10.0.0.140
DHCP-assigned subnet : 255.255.255.0
DHCP-assigned gateway : 10.0.0.1
Starting TCP server listening on :8080
Client 10.0.0.190:50000 connected
Client 10.0.0.190:50000 closed
CLIENT
=============
nc -p 50000 10.0.0.140 8080
Add basis for TCP/IP stack. The stack implements Netdever interface for
the top-end, and calls into a Netlinker interface on the bottom-end.
Each TCP/IP stack instance represents a L3/L4 endpoint with an IP
address. The Netlinker is bound when creating the stack. E.g.:
spi, cs, wlreg, irq := cyw43439.PicoWSpi(0)
cyw43 := cyw43439.NewDevice(spi, cs, wlreg, irq, irq)
stack := tcpip.NewStack(cyw43)
netdev.UseNetdev(stack)
Here, the cyw43439 driver is the Netlinker for the stack. The new stack
is a Netdever, so we tell the "net" package to use the stack as the
netdev. The stack manages L3/L4 socket connections, ultimately calling
into the Netlinker to send/recv L2 Ethernet pkts.
This adds three new L2 (intermediate) drivers for bridge/bond/vlan.
Theses drivers are incomplete but illustrate how to stack L2 drivers.
Here are some examples of how these driver would stack with the cy243439
driver:
Bridge: bridge two cyw43 devices together, connecting the two LANs:
cyw43_0 := cyw43439.NewDevice(...)
cyw43_1 := cyw43439.NewDevice(...)
bridge := NewBridge([]netlink.Netlinker{cyw43_0, cyw43_1})
stack := tcpip.NewStack(bridge)
netdev.UseNetdev(stack)
Bond: bond two cyw43 devices together, creating one logical device.
The first physical device is primary, the second is backup (fail-over)
device:
cyw43_0 := cyw43439.NewDevice(...) // primary
cyw43_1 := cyw43439.NewDevice(...) // secondary (backup)
bond := NewBond([]netlink.Netlinker{cyw43_0, cyw43_1})
stack := tcpip.NewStack(bond)
netdev.UseNetdev(stack)
Vlan: add tagged VLAN ID=100 to cyw43:
cyw43 := cyw43439.NewDevice(...)
vlan100 := NewVlan(100, cyw43)
stack := tcpip.NewStack(vlan100)
netdev.UseNetdev(stack)
This moves the netdev/netlink namespace out of drivers and into their
own packages. Also, defines netdev and netlink as L3/L4 and L2 OSI
layers, respectively. Move some L3 functionality from netlink to
netdev (GetIPAddr).
For netlink, add ConnectParams for NetConnect to pass in L2 connection
parameters (ssid, pass, auth_type, etc). Also adds connection mode
(STA, AP, etc).
For netlink, add SendEth and RecvEthFunc funcs to handle L2 send/recv of
Ethernet pkts.
Tested with a rp2040.
TODO: add the ability to set the absolute humidity for more accurate
sensor details. The formula for that is rather complex, so I've left
this as a future addition.
Replace DrawRGBBitmap8 with DrawBitmap, following the change in the
previous commit.
This improves performance from 86fps to 100fps! I didn't investigate
why, but I suspect it's because it now needs only a single store instead
of two to update a pixel.