move netdev and netlink into their own packages and out of drivers

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.
This commit is contained in:
Scott Feldman
2023-06-09 14:03:03 -07:00
committed by Ron Evans
parent e7d51d3c73
commit 8238f96319
64 changed files with 628 additions and 1419 deletions
+12 -2
View File
@@ -6,6 +6,8 @@
// Note: It may be necessary to increase the stack size when using
// "golang.org/x/net/websocket". Use the -stack-size=4KB command line option.
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal
package main
import (
@@ -16,6 +18,8 @@ import (
"time"
"golang.org/x/net/websocket"
"tinygo.org/x/drivers/netlink"
"tinygo.org/x/drivers/netlink/probe"
)
var (
@@ -40,12 +44,18 @@ func waitSerial() {
func main() {
waitSerial()
if err := netdev.NetConnect(); err != nil {
link, _ := probe.Probe()
err := link.NetConnect(&netlink.ConnectParams{
Ssid: ssid,
Passphrase: pass,
})
if err != nil {
log.Fatal(err)
}
http.Handle("/echo", websocket.Handler(EchoServer))
err := http.ListenAndServe(port, nil)
err = http.ListenAndServe(port, nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
@@ -1,29 +0,0 @@
//go:build wioterminal
// +build: wioterminal
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var cfg = rtl8720dn.Config{
// WiFi AP credentials
Ssid: ssid,
Passphrase: pass,
// Device
En: machine.RTL8720D_CHIP_PU,
// UART
Uart: machine.UART3,
Tx: machine.PB24,
Rx: machine.PC24,
Baudrate: 614400,
// Watchdog (set to 0 to disable)
WatchdogTimeout: time.Duration(20 * time.Second),
}
var netdev = rtl8720dn.New(&cfg)
@@ -1,33 +0,0 @@
//go:build pyportal || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
// +build: pyportal nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/wifinina"
)
var cfg = wifinina.Config{
// WiFi AP credentials
Ssid: ssid,
Passphrase: pass,
// Configure SPI for 8Mhz, Mode 0, MSB First
Spi: machine.NINA_SPI,
Freq: 8 * 1e6,
Sdo: machine.NINA_SDO,
Sdi: machine.NINA_SDI,
Sck: machine.NINA_SCK,
// Device pins
Cs: machine.NINA_CS,
Ack: machine.NINA_ACK,
Gpio0: machine.NINA_GPIO0,
Resetn: machine.NINA_RESETN,
// Watchdog (set to 0 to disable)
WatchdogTimeout: time.Duration(20 * time.Second),
}
var netdev = wifinina.New(&cfg)