|
TinyPPP
PPP networking over any Arduino Stream
|
PPP network interface for platforms without lwIP: the PPP engine combined with the TinyPPP IPStack (TCP, UDP, ICMP echo and DNS). More...
#include <TinyPPP_Generic.h>
Public Types | |
| using | IdleCallback = void(*)(void *ref) |
| Callback that is called while a socket method waits. | |
| using | PacketCallback = void(*)(const uint8_t *data, size_t len, void *ref) |
| Callback for received raw IPv4 packets. | |
| using | StateCallback = void(*)(bool up, void *ref) |
| Callback for link up/down. | |
Public Member Functions | |
| bool | begin (Stream &io) |
| Starts the PPP negotiation over the indicated (already opened) stream. | |
| bool | beginIPv4 () |
| Streaming API for chained buffers (e.g. lwIP pbuf) | |
| bool | config (IPAddress local, IPAddress peer=IPAddress(0, 0, 0, 0), IPAddress dns1=IPAddress(0, 0, 0, 0), IPAddress dns2=IPAddress(0, 0, 0, 0)) |
| bool | connected () const |
| true when the link is up and has an IP address | |
| ip4_t | dns1 () const |
| First DNS server received from the peer. | |
| ip4_t | dns2 () const |
| Second DNS server received from the peer. | |
| IPAddress | dnsIP (int n=0) const |
| The DNS server n (0 or 1) received from the peer. | |
| void | end () |
| Terminates the link. | |
| bool | endIPv4 () |
| Sends the packet started with beginIPv4() | |
| uint32_t | fcsErrors () const |
| Number of received frames with a wrong FCS. | |
| IPAddress | gatewayIP () const |
| The IP address of the peer. | |
| bool | hostByName (const char *host, IPAddress &result, uint32_t timeoutMs=5000) |
| Resolves a host name (or a dotted IP address) via DNS. | |
| void | input (const uint8_t *data, size_t len) |
| bool | isStarted () const |
| true after start() until stop() | |
| bool | isUp () const |
| true when IPCP is open and IPv4 packets can be exchanged | |
| IPAddress | localIP () const |
| Our IP address. | |
| void | loop () |
| Processes input and timers: call regularly. | |
| uint16_t | mtu () const |
| MTU we may use for sending (peer MRU) | |
| void | onIdle (IdleCallback cb, void *ref=nullptr) |
| void | onReceive (PacketCallback cb, void *ref=nullptr) |
| void | onStateChange (StateCallback cb, void *ref=nullptr) |
| Callback for link up/down; ref is passed to the callback. | |
| ip4_t | peerIP () const |
| IP address of the peer. | |
| PPPPhase | phase () const |
| Current link phase. | |
| void | poll () |
| Processes the link (input and timers): called by all socket methods. | |
| void | process () |
| Reads available input and runs the timers: call frequently. | |
| void | processTimers (uint32_t now) |
| Runs the retransmission and keep-alive timers. | |
| bool | send (const uint8_t *data, size_t len) |
| Sends a raw IPv4 packet. | |
| bool | sendIPv4 (const uint8_t *data, size_t len) |
| Sends a complete IPv4 packet. | |
| void | setCredentials (const char *user, const char *password) |
| PAP credentials (used only if the peer requires authentication) | |
| void | setEchoInterval (uint32_t ms, uint8_t maxFailures=3) |
| LCP echo keep-alive: 0 disables it. | |
| void | setLocalIP (ip4_t ip) |
| Optional static address configuration. 0 = negotiate with the peer. | |
| void | setLogger (Print &out) |
| Debug output, e.g. setLogger(Serial1) | |
| void | setLogger (Print *log) |
| Debug output (nullptr to disable) | |
| void | setOfferedDNS (ip4_t dns1, ip4_t dns2=0) |
| DNS servers to offer the peer if it asks for them (server role) | |
| void | setPassive (bool passive) |
| Passive: do not send LCP requests before the peer starts negotiating. | |
| void | setPeerIP (ip4_t ip) |
| Address to assign to the peer if it requests one (server role) | |
| void | setRequestDNS (bool flag) |
| Request DNS servers from the peer (default true) | |
| void | setRespondToPing (bool flag) |
| Answer ICMP echo requests addressed to us (default true) | |
| void | start (Stream &io) |
| Starts the PPP negotiation on the indicated stream. | |
| const PPPStats & | stats () const |
| Frame and packet counters. | |
| void | stop () |
| Closes the link gracefully (sends LCP Terminate-Request) | |
| IPAddress | subnetMask () const |
| Always 255.255.255.255 (point-to-point link) | |
| int | tcpAccept (uint16_t port, bool withData) |
| int | tcpAvailable (int s) |
| Number of received bytes that can be read from socket s. | |
| void | tcpClose (int s, uint32_t timeoutMs) |
| int | tcpConnect (ip4_t ip, uint16_t port, uint32_t timeoutMs) |
| Opens a connection: returns the socket number or -1. | |
| void | tcpFlush (int s, uint32_t timeoutMs) |
| Waits until all queued data was acknowledged. | |
| uint8_t | tcpGen (int s) const |
| Generation of socket s: changes each time the socket is reused. | |
| bool | tcpListen (uint16_t port) |
| Starts listening on a port. | |
| uint16_t | tcpLocalPort (int s) const |
| Local port of socket s. | |
| int | tcpPeek (int s) |
| Next received byte of socket s without removing it (-1 if none) | |
| int | tcpRead (int s, uint8_t *data, size_t len) |
| Reads up to len received bytes from socket s. | |
| ip4_t | tcpRemoteIP (int s) const |
| Remote address of socket s. | |
| uint16_t | tcpRemotePort (int s) const |
| Remote port of socket s. | |
| TCPState | tcpState (int s) const |
| Connection state of socket s. | |
| void | tcpUnlisten (uint16_t port) |
| Stops listening on a port. | |
| bool | tcpValid (int s, uint8_t gen) const |
| true if socket s is open and still has the generation gen | |
| size_t | tcpWrite (int s, const uint8_t *data, size_t len, uint32_t timeoutMs) |
| Queues data for sending (waits for buffer space up to timeoutMs) | |
| size_t | tcpWriteAll (uint16_t port, const uint8_t *data, size_t len, uint32_t timeoutMs) |
| Sends data to all connected clients of a server port. | |
| int | udpAvailable (int s) const |
| Unread bytes of the current datagram. | |
| void | udpClose (int s) |
| Closes UDP socket s. | |
| void | udpDiscard (int s) |
| Discards the rest of the current datagram. | |
| uint16_t | udpLocalPort (int s) const |
| Local port of UDP socket s. | |
| int | udpOpen (uint16_t port) |
| Opens a UDP socket on the port (0: ephemeral): returns it or -1. | |
| int | udpParsePacket (int s, ip4_t &ip, uint16_t &port) |
| Moves to the next datagram: returns its size (0 if none) | |
| int | udpPeek (int s) const |
| Next byte of the current datagram without removing it (-1 if none) | |
| int | udpRead (int s, uint8_t *data, size_t len) |
| Reads from the current datagram. | |
| bool | udpSend (int s, ip4_t ip, uint16_t port, const uint8_t *data, size_t len) |
| Sends a datagram. | |
| bool | waitConnected (uint32_t timeoutMs=30000) |
| Waits (while processing the link) until IPCP is up. | |
| void | writeIPv4 (const uint8_t *data, size_t len) |
| Adds data to the packet started with beginIPv4() | |
Static Public Member Functions | |
| static IPStack *& | current () |
| The stack used by sockets that were created without an explicit stack. | |
Static Public Attributes | |
| static constexpr uint8_t | IP_ICMP = 1 |
| static constexpr uint8_t | IP_TCP = 6 |
| static constexpr uint8_t | IP_UDP = 17 |
| static constexpr uint8_t | TCP_ACK = 0x10 |
| static constexpr uint8_t | TCP_FIN = 0x01 |
| static constexpr uint8_t | TCP_PSH = 0x08 |
| static constexpr uint8_t | TCP_RST = 0x04 |
| static constexpr uint8_t | TCP_SYN = 0x02 |
Protected Member Functions | |
| bool | ipBegin () override |
| Starts an outgoing IPv4 packet. | |
| ip4_t | ipDns (int n) const override |
| bool | ipEnd () override |
| Sends the packet. | |
| bool | ipInput (const uint8_t *data, size_t len, bool reply=true) |
| bool | ipIsUp () const override |
| void | ipLinkDown () |
| Called when the link goes down: all connections are reset. | |
| ip4_t | ipLocal () const override |
| uint16_t | ipMtu () const override |
| void | ipPoll () override |
| Processes link input: received packets are passed to ipInput() | |
| void | ipWrite (const uint8_t *data, size_t len) override |
| Adds data to the outgoing packet. | |
| void | logf (const char *fmt,...) |
| void | onIPv4Packet (const uint8_t *data, size_t len) override |
| Called for each received IPv4 packet. | |
| void | onLinkDown () override |
| Called when the IP link goes down. | |
| void | onLinkUp () override |
| Called when IPCP is opened: addresses are available. | |
| virtual void | onPhase (PPPPhase phase) |
| Called on phase changes. | |
Static Protected Member Functions | |
| static const char * | ipStr (ip4_t ip, char *buf) |
Protected Attributes | |
| PacketCallback | _rxCallback = nullptr |
| void * | _rxRef = nullptr |
| StateCallback | _stateCallback = nullptr |
| void * | _stateRef = nullptr |
PPP network interface for platforms without lwIP: the PPP engine combined with the TinyPPP IPStack (TCP, UDP, ICMP echo and DNS).
|
inherited |
Callback that is called while a socket method waits.
Callback for received raw IPv4 packets.
Starts the PPP negotiation over the indicated (already opened) stream.
|
inlineinherited |
Streaming API for chained buffers (e.g. lwIP pbuf)
|
inline |
Static configuration: our address, the peer address and the DNS servers we offer to the peer. Unset values are negotiated.
|
inline |
true when the link is up and has an IP address
The stack used by sockets that were created without an explicit stack.
|
inlineinherited |
First DNS server received from the peer.
|
inlineinherited |
Second DNS server received from the peer.
|
inline |
Terminates the link.
|
inlineinherited |
Sends the packet started with beginIPv4()
|
inlineinherited |
Number of received frames with a wrong FCS.
|
inline |
The IP address of the peer.
|
inlineinherited |
Resolves a host name (or a dotted IP address) via DNS.
Feeds raw bytes (alternative to process() when you read the stream yourself)
Processes a received IPv4 packet: returns false if it was not consumed by the stack (the caller can handle it). With reply set to false, unconsumed packets are not answered with TCP reset.
|
inlineprotectedinherited |
Called when the link goes down: all connections are reset.
|
inlineoverrideprotectedvirtual |
Adds data to the outgoing packet.
Implements IPStack.
|
inlineinherited |
true when IPCP is open and IPv4 packets can be exchanged
|
inline |
Our IP address.
|
inline |
Processes input and timers: call regularly.
|
inlineinherited |
MTU we may use for sending (peer MRU)
|
inlineinherited |
Called while a socket method waits (e.g. to run other tasks); ref is passed to the callback
Called for each received IPv4 packet.
Reimplemented from PPPEngine.
|
inlineoverrideprotectedvirtual |
Called when the IP link goes down.
Reimplemented from PPPEngine.
|
inlineoverrideprotectedvirtual |
Called when IPCP is opened: addresses are available.
Reimplemented from PPPEngine.
|
inline |
Callback for received IPv4 packets that are not handled by the stack; ref is passed to the callback
|
inline |
Callback for link up/down; ref is passed to the callback.
|
inlineinherited |
IP address of the peer.
|
inlineinherited |
Current link phase.
|
inlineinherited |
Processes the link (input and timers): called by all socket methods.
|
inlineinherited |
Reads available input and runs the timers: call frequently.
PAP credentials (used only if the peer requires authentication)
LCP echo keep-alive: 0 disables it.
Optional static address configuration. 0 = negotiate with the peer.
DNS servers to offer the peer if it asks for them (server role)
Passive: do not send LCP requests before the peer starts negotiating.
Address to assign to the peer if it requests one (server role)
Answer ICMP echo requests addressed to us (default true)
|
inlineinherited |
Closes the link gracefully (sends LCP Terminate-Request)
|
inline |
Always 255.255.255.255 (point-to-point link)
Returns a new connection on the port or -1. With withData only connections that have data are returned (also already accepted ones).
Closes the connection: waits up to timeoutMs for the close handshake, the rest is completed in the background.
Opens a connection: returns the socket number or -1.
Waits until all queued data was acknowledged.
Generation of socket s: changes each time the socket is reused.
Next received byte of socket s without removing it (-1 if none)
Reads up to len received bytes from socket s.
true if socket s is open and still has the generation gen
Queues data for sending (waits for buffer space up to timeoutMs)
|
inlineinherited |
Sends data to all connected clients of a server port.
Opens a UDP socket on the port (0: ephemeral): returns it or -1.
Moves to the next datagram: returns its size (0 if none)
Next byte of the current datagram without removing it (-1 if none)
Sends a datagram.
Waits (while processing the link) until IPCP is up.
Adds data to the packet started with beginIPv4()
|
protected |
|
protected |