TinyPPP
PPP networking over any Arduino Stream
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
TinyPPP_Generic Class Reference

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>

Inheritance diagram for TinyPPP_Generic:
PPPEngine IPStack

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
 

Detailed Description

PPP network interface for platforms without lwIP: the PPP engine combined with the TinyPPP IPStack (TCP, UDP, ICMP echo and DNS).

Member Typedef Documentation

◆ IdleCallback

using IdleCallback = void (*)(void *ref)
inherited

Callback that is called while a socket method waits.

◆ PacketCallback

Callback for received raw IPv4 packets.

◆ StateCallback

Callback for link up/down.

Member Function Documentation

◆ begin()

bool begin ( Stream &  io)
inline

Starts the PPP negotiation over the indicated (already opened) stream.

◆ beginIPv4()

bool beginIPv4 ( )
inlineinherited

Streaming API for chained buffers (e.g. lwIP pbuf)

◆ config()

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) 
)
inline

Static configuration: our address, the peer address and the DNS servers we offer to the peer. Unset values are negotiated.

◆ connected()

bool connected ( ) const
inline

true when the link is up and has an IP address

◆ current()

static IPStack *& current ( )
inlinestaticinherited

The stack used by sockets that were created without an explicit stack.

◆ dns1()

ip4_t dns1 ( ) const
inlineinherited

First DNS server received from the peer.

◆ dns2()

ip4_t dns2 ( ) const
inlineinherited

Second DNS server received from the peer.

◆ dnsIP()

IPAddress dnsIP ( int  n = 0) const
inline

The DNS server n (0 or 1) received from the peer.

◆ end()

void end ( )
inline

Terminates the link.

◆ endIPv4()

bool endIPv4 ( )
inlineinherited

Sends the packet started with beginIPv4()

◆ fcsErrors()

uint32_t fcsErrors ( ) const
inlineinherited

Number of received frames with a wrong FCS.

◆ gatewayIP()

IPAddress gatewayIP ( ) const
inline

The IP address of the peer.

◆ hostByName()

bool hostByName ( const char *  host,
IPAddress &  result,
uint32_t  timeoutMs = 5000 
)
inlineinherited

Resolves a host name (or a dotted IP address) via DNS.

◆ input()

void input ( const uint8_t *  data,
size_t  len 
)
inlineinherited

Feeds raw bytes (alternative to process() when you read the stream yourself)

◆ ipBegin()

bool ipBegin ( )
inlineoverrideprotectedvirtual

Starts an outgoing IPv4 packet.

Implements IPStack.

◆ ipDns()

ip4_t ipDns ( int  n) const
inlineoverrideprotectedvirtual

Implements IPStack.

◆ ipEnd()

bool ipEnd ( )
inlineoverrideprotectedvirtual

Sends the packet.

Implements IPStack.

◆ ipInput()

bool ipInput ( const uint8_t *  data,
size_t  len,
bool  reply = true 
)
inlineprotectedinherited

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.

◆ ipIsUp()

bool ipIsUp ( ) const
inlineoverrideprotectedvirtual

Implements IPStack.

◆ ipLinkDown()

void ipLinkDown ( )
inlineprotectedinherited

Called when the link goes down: all connections are reset.

◆ ipLocal()

ip4_t ipLocal ( ) const
inlineoverrideprotectedvirtual

Implements IPStack.

◆ ipMtu()

uint16_t ipMtu ( ) const
inlineoverrideprotectedvirtual

Implements IPStack.

◆ ipPoll()

void ipPoll ( )
inlineoverrideprotectedvirtual

Processes link input: received packets are passed to ipInput()

Implements IPStack.

◆ ipStr()

static const char * ipStr ( ip4_t  ip,
char *  buf 
)
inlinestaticprotectedinherited

◆ ipWrite()

void ipWrite ( const uint8_t *  data,
size_t  len 
)
inlineoverrideprotectedvirtual

Adds data to the outgoing packet.

Implements IPStack.

◆ isStarted()

bool isStarted ( ) const
inlineinherited

true after start() until stop()

◆ isUp()

bool isUp ( ) const
inlineinherited

true when IPCP is open and IPv4 packets can be exchanged

◆ localIP()

IPAddress localIP ( ) const
inline

Our IP address.

◆ logf()

void logf ( const char *  fmt,
  ... 
)
inlineprotectedinherited

◆ loop()

void loop ( )
inline

Processes input and timers: call regularly.

◆ mtu()

uint16_t mtu ( ) const
inlineinherited

MTU we may use for sending (peer MRU)

◆ onIdle()

void onIdle ( IdleCallback  cb,
void *  ref = nullptr 
)
inlineinherited

Called while a socket method waits (e.g. to run other tasks); ref is passed to the callback

◆ onIPv4Packet()

void onIPv4Packet ( const uint8_t *  data,
size_t  len 
)
inlineoverrideprotectedvirtual

Called for each received IPv4 packet.

Reimplemented from PPPEngine.

◆ onLinkDown()

void onLinkDown ( )
inlineoverrideprotectedvirtual

Called when the IP link goes down.

Reimplemented from PPPEngine.

◆ onLinkUp()

void onLinkUp ( )
inlineoverrideprotectedvirtual

Called when IPCP is opened: addresses are available.

Reimplemented from PPPEngine.

◆ onPhase()

virtual void onPhase ( PPPPhase  phase)
inlineprotectedvirtualinherited

Called on phase changes.

◆ onReceive()

void onReceive ( PacketCallback  cb,
void *  ref = nullptr 
)
inline

Callback for received IPv4 packets that are not handled by the stack; ref is passed to the callback

◆ onStateChange()

void onStateChange ( StateCallback  cb,
void *  ref = nullptr 
)
inline

Callback for link up/down; ref is passed to the callback.

◆ peerIP()

ip4_t peerIP ( ) const
inlineinherited

IP address of the peer.

◆ phase()

PPPPhase phase ( ) const
inlineinherited

Current link phase.

◆ poll()

void poll ( )
inlineinherited

Processes the link (input and timers): called by all socket methods.

◆ process()

void process ( )
inlineinherited

Reads available input and runs the timers: call frequently.

◆ processTimers()

void processTimers ( uint32_t  now)
inlineinherited

Runs the retransmission and keep-alive timers.

◆ send()

bool send ( const uint8_t *  data,
size_t  len 
)
inline

Sends a raw IPv4 packet.

◆ sendIPv4()

bool sendIPv4 ( const uint8_t *  data,
size_t  len 
)
inlineinherited

Sends a complete IPv4 packet.

◆ setCredentials()

void setCredentials ( const char *  user,
const char *  password 
)
inlineinherited

PAP credentials (used only if the peer requires authentication)

◆ setEchoInterval()

void setEchoInterval ( uint32_t  ms,
uint8_t  maxFailures = 3 
)
inlineinherited

LCP echo keep-alive: 0 disables it.

◆ setLocalIP()

void setLocalIP ( ip4_t  ip)
inlineinherited

Optional static address configuration. 0 = negotiate with the peer.

◆ setLogger() [1/2]

void setLogger ( Print &  out)
inline

Debug output, e.g. setLogger(Serial1)

◆ setLogger() [2/2]

void setLogger ( Print *  log)
inline

Debug output (nullptr to disable)

◆ setOfferedDNS()

void setOfferedDNS ( ip4_t  dns1,
ip4_t  dns2 = 0 
)
inlineinherited

DNS servers to offer the peer if it asks for them (server role)

◆ setPassive()

void setPassive ( bool  passive)
inlineinherited

Passive: do not send LCP requests before the peer starts negotiating.

◆ setPeerIP()

void setPeerIP ( ip4_t  ip)
inlineinherited

Address to assign to the peer if it requests one (server role)

◆ setRequestDNS()

void setRequestDNS ( bool  flag)
inlineinherited

Request DNS servers from the peer (default true)

◆ setRespondToPing()

void setRespondToPing ( bool  flag)
inlineinherited

Answer ICMP echo requests addressed to us (default true)

◆ start()

void start ( Stream &  io)
inlineinherited

Starts the PPP negotiation on the indicated stream.

◆ stats()

const PPPStats & stats ( ) const
inlineinherited

Frame and packet counters.

◆ stop()

void stop ( )
inlineinherited

Closes the link gracefully (sends LCP Terminate-Request)

◆ subnetMask()

IPAddress subnetMask ( ) const
inline

Always 255.255.255.255 (point-to-point link)

◆ tcpAccept()

int tcpAccept ( uint16_t  port,
bool  withData 
)
inlineinherited

Returns a new connection on the port or -1. With withData only connections that have data are returned (also already accepted ones).

◆ tcpAvailable()

int tcpAvailable ( int  s)
inlineinherited

Number of received bytes that can be read from socket s.

◆ tcpClose()

void tcpClose ( int  s,
uint32_t  timeoutMs 
)
inlineinherited

Closes the connection: waits up to timeoutMs for the close handshake, the rest is completed in the background.

◆ tcpConnect()

int tcpConnect ( ip4_t  ip,
uint16_t  port,
uint32_t  timeoutMs 
)
inlineinherited

Opens a connection: returns the socket number or -1.

◆ tcpFlush()

void tcpFlush ( int  s,
uint32_t  timeoutMs 
)
inlineinherited

Waits until all queued data was acknowledged.

◆ tcpGen()

uint8_t tcpGen ( int  s) const
inlineinherited

Generation of socket s: changes each time the socket is reused.

◆ tcpListen()

bool tcpListen ( uint16_t  port)
inlineinherited

Starts listening on a port.

◆ tcpLocalPort()

uint16_t tcpLocalPort ( int  s) const
inlineinherited

Local port of socket s.

◆ tcpPeek()

int tcpPeek ( int  s)
inlineinherited

Next received byte of socket s without removing it (-1 if none)

◆ tcpRead()

int tcpRead ( int  s,
uint8_t *  data,
size_t  len 
)
inlineinherited

Reads up to len received bytes from socket s.

◆ tcpRemoteIP()

ip4_t tcpRemoteIP ( int  s) const
inlineinherited

Remote address of socket s.

◆ tcpRemotePort()

uint16_t tcpRemotePort ( int  s) const
inlineinherited

Remote port of socket s.

◆ tcpState()

TCPState tcpState ( int  s) const
inlineinherited

Connection state of socket s.

◆ tcpUnlisten()

void tcpUnlisten ( uint16_t  port)
inlineinherited

Stops listening on a port.

◆ tcpValid()

bool tcpValid ( int  s,
uint8_t  gen 
) const
inlineinherited

true if socket s is open and still has the generation gen

◆ tcpWrite()

size_t tcpWrite ( int  s,
const uint8_t *  data,
size_t  len,
uint32_t  timeoutMs 
)
inlineinherited

Queues data for sending (waits for buffer space up to timeoutMs)

◆ tcpWriteAll()

size_t tcpWriteAll ( uint16_t  port,
const uint8_t *  data,
size_t  len,
uint32_t  timeoutMs 
)
inlineinherited

Sends data to all connected clients of a server port.

◆ udpAvailable()

int udpAvailable ( int  s) const
inlineinherited

Unread bytes of the current datagram.

◆ udpClose()

void udpClose ( int  s)
inlineinherited

Closes UDP socket s.

◆ udpDiscard()

void udpDiscard ( int  s)
inlineinherited

Discards the rest of the current datagram.

◆ udpLocalPort()

uint16_t udpLocalPort ( int  s) const
inlineinherited

Local port of UDP socket s.

◆ udpOpen()

int udpOpen ( uint16_t  port)
inlineinherited

Opens a UDP socket on the port (0: ephemeral): returns it or -1.

◆ udpParsePacket()

int udpParsePacket ( int  s,
ip4_t &  ip,
uint16_t &  port 
)
inlineinherited

Moves to the next datagram: returns its size (0 if none)

◆ udpPeek()

int udpPeek ( int  s) const
inlineinherited

Next byte of the current datagram without removing it (-1 if none)

◆ udpRead()

int udpRead ( int  s,
uint8_t *  data,
size_t  len 
)
inlineinherited

Reads from the current datagram.

◆ udpSend()

bool udpSend ( int  s,
ip4_t  ip,
uint16_t  port,
const uint8_t *  data,
size_t  len 
)
inlineinherited

Sends a datagram.

◆ waitConnected()

bool waitConnected ( uint32_t  timeoutMs = 30000)
inline

Waits (while processing the link) until IPCP is up.

◆ writeIPv4()

void writeIPv4 ( const uint8_t *  data,
size_t  len 
)
inlineinherited

Adds data to the packet started with beginIPv4()

Member Data Documentation

◆ _rxCallback

PacketCallback _rxCallback = nullptr
protected

◆ _rxRef

void* _rxRef = nullptr
protected

◆ _stateCallback

StateCallback _stateCallback = nullptr
protected

◆ _stateRef

void* _stateRef = nullptr
protected

◆ IP_ICMP

constexpr uint8_t IP_ICMP = 1
staticconstexprinherited

◆ IP_TCP

constexpr uint8_t IP_TCP = 6
staticconstexprinherited

◆ IP_UDP

constexpr uint8_t IP_UDP = 17
staticconstexprinherited

◆ TCP_ACK

constexpr uint8_t TCP_ACK = 0x10
staticconstexprinherited

◆ TCP_FIN

constexpr uint8_t TCP_FIN = 0x01
staticconstexprinherited

◆ TCP_PSH

constexpr uint8_t TCP_PSH = 0x08
staticconstexprinherited

◆ TCP_RST

constexpr uint8_t TCP_RST = 0x04
staticconstexprinherited

◆ TCP_SYN

constexpr uint8_t TCP_SYN = 0x02
staticconstexprinherited

The documentation for this class was generated from the following file: