mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
add tcpip stack framework
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 commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package tcpip
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/netdev"
|
||||
)
|
||||
|
||||
func (s *Stack) GetHostByName(name string) (net.IP, error) {
|
||||
return net.IP{}, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) GetIPAddr() (net.IP, error) {
|
||||
return net.IP{}, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Socket(domain int, stype int, protocol int) (int, error) {
|
||||
return -1, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Bind(sockfd int, ip net.IP, port int) error {
|
||||
return netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Connect(sockfd int, host string, ip net.IP, port int) error {
|
||||
return netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Listen(sockfd int, backlog int) error {
|
||||
return netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Accept(sockfd int, ip net.IP, port int) (int, error) {
|
||||
return -1, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Send(sockfd int, buf []byte, flags int, deadline time.Time) (int, error) {
|
||||
return 0, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Recv(sockfd int, buf []byte, flags int, deadline time.Time) (int, error) {
|
||||
return 0, netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) Close(sockfd int) error {
|
||||
return netdev.ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *Stack) SetSockOpt(sockfd int, level int, opt int, value interface{}) error {
|
||||
return netdev.ErrNotSupported
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package tcpip
|
||||
|
||||
import (
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
)
|
||||
|
||||
type Stack struct {
|
||||
link netlink.Netlinker
|
||||
}
|
||||
|
||||
func NewStack(link netlink.Netlinker) *Stack {
|
||||
s := Stack{link: link}
|
||||
s.link.RecvEthFunc(s.recvEth)
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s *Stack) recvEth(pkt []byte) error {
|
||||
println("recvEth", len(pkt))
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user