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

PPP network interface for RP2040 / RP2350 (arduino-pico): the TinyPPP engine registered as a point-to-point lwIP netif. More...

#include <TinyPPP_RP2040.h>

Inheritance diagram for TinyPPP_RP2040:
PPPEngine

Public Types

using StateCallback = void(*)(bool up, void *ref)
 Callback for link up/down.
 

Public Member Functions

 TinyPPP_RP2040 ()=default
 
 TinyPPP_RP2040 (const TinyPPP_RP2040 &)=delete
 
 ~TinyPPP_RP2040 ()
 
bool begin (Stream &io)
 
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
 
IPAddress dnsIP (int n=0) const
 The DNS server n (0 or 1) received from the peer.
 
void end ()
 Terminates the link and removes the interface.
 
uint32_t fcsErrors () const
 Number of received frames with a wrong FCS.
 
IPAddress gatewayIP () const
 The IP address of the peer.
 
struct netif * getNetIf ()
 The lwIP netif of the interface.
 
IPAddress localIP () const
 Our IP address.
 
void onStateChange (StateCallback cb, void *ref=nullptr)
 
TinyPPP_RP2040 & operator= (const TinyPPP_RP2040 &)=delete
 
PPPPhase phase () const
 Current link phase.
 
void setCredentials (const char *user, const char *password)
 PAP credentials (used only if the peer requires authentication)
 
void setDefault (bool flag=true)
 Make this interface the default route when the link is up (default true)
 
void setEchoInterval (uint32_t ms, uint8_t maxFailures=3)
 LCP echo keep-alive: 0 disables it.
 
void setLogger (Print &out)
 Debug output e.g. setLogger(Serial1)
 
void setPassive (bool passive)
 Passive: do not send LCP requests before the peer starts negotiating.
 
void setPollingPeriod (int ms)
 
void setRequestDNS (bool flag)
 Request DNS servers from the peer (default true)
 
const PPPStats & stats () const
 Frame and packet counters.
 
wl_status_t status () const
 WL_CONNECTED when the link is up, WL_NO_SHIELD before begin()
 
IPAddress subnetMask () const
 Always 255.255.255.255 (point-to-point link)
 
bool waitConnected (uint32_t timeoutMs=30000)
 Waits until the link is up.
 

Protected Types

enum class  Cmd : uint8_t { None , Start , Stop }
 

Protected Member Functions

bool beginIPv4 ()
 Streaming API for chained buffers (e.g. lwIP pbuf)
 
ip4_t dns1 () const
 First DNS server received from the peer.
 
ip4_t dns2 () const
 Second DNS server received from the peer.
 
bool endIPv4 ()
 Sends the packet started with beginIPv4()
 
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
 
void logf (const char *fmt,...)
 
uint16_t mtu () const
 MTU we may use for sending (peer MRU)
 
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.
 
ip4_t peerIP () const
 IP address of the peer.
 
void poll ()
 
void process ()
 Reads available input and runs the timers: call frequently.
 
void processTimers (uint32_t now)
 Runs the retransmission and keep-alive timers.
 
bool sendIPv4 (const uint8_t *data, size_t len)
 Sends a complete IPv4 packet.
 
void setLocalIP (ip4_t ip)
 Optional static address configuration. 0 = negotiate with the peer.
 
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 setPeerIP (ip4_t ip)
 Address to assign to the peer if it requests one (server role)
 
void start (Stream &io)
 Starts the PPP negotiation on the indicated stream.
 
void stop ()
 Closes the link gracefully (sends LCP Terminate-Request)
 
void writeIPv4 (const uint8_t *data, size_t len)
 Adds data to the packet started with beginIPv4()
 

Static Protected Member Functions

static const char * ipStr (ip4_t ip, char *buf)
 
static err_t netifInit (struct netif *netif)
 
static err_t output4 (struct netif *netif, struct pbuf *p, const ip4_addr_t *addr)
 

Protected Attributes

volatile Cmd _cmd = Cmd::None
 
bool _default = true
 
Stream * _io = nullptr
 
struct netif _netif
 
bool _netifAdded = false
 
int _phID = -1
 
StateCallback _stateCallback = nullptr
 
void * _stateRef = nullptr
 
volatile bool _up = false
 

Detailed Description

PPP network interface for RP2040 / RP2350 (arduino-pico): the TinyPPP engine registered as a point-to-point lwIP netif.

Member Typedef Documentation

◆ StateCallback

Callback for link up/down.

Member Enumeration Documentation

◆ Cmd

enum class Cmd : uint8_t
strongprotected
Enumerator
None 
Start 
Stop 

Constructor & Destructor Documentation

◆ TinyPPP_RP2040() [1/2]

TinyPPP_RP2040 ( )
default

◆ TinyPPP_RP2040() [2/2]

◆ ~TinyPPP_RP2040()

~TinyPPP_RP2040 ( )
inline

Member Function Documentation

◆ begin()

bool begin ( Stream &  io)
inline

Starts PPP over the indicated stream (e.g. Serial, Serial1). The stream must already be opened (Serial.begin()). Returns immediately: use connected() or waitConnected() to wait for the link.

◆ 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

Optional static configuration. local: our address (otherwise assigned by the peer); peer: address assigned to the peer if it asks for one; dns1 and dns2: DNS servers offered to the peer. Call before begin().

◆ connected()

bool connected ( ) const
inline

true when the link is up and has an IP address

◆ 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 and removes the interface.

◆ endIPv4()

bool endIPv4 ( )
inlineinherited

Sends the packet started with beginIPv4()

◆ fcsErrors()

uint32_t fcsErrors ( ) const
inline

Number of received frames with a wrong FCS.

◆ gatewayIP()

IPAddress gatewayIP ( ) const
inline

The IP address of the peer.

◆ getNetIf()

struct netif * getNetIf ( )
inline

The lwIP netif of the interface.

◆ input()

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

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

◆ ipStr()

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

◆ 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

◆ mtu()

uint16_t mtu ( ) const
inlineinherited

MTU we may use for sending (peer MRU)

◆ netifInit()

static err_t netifInit ( struct netif *  netif)
inlinestaticprotected

◆ 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.

◆ onStateChange()

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

Callback for link up/down (called from the lwIP context); ref is passed to the callback

◆ operator=()

◆ output4()

static err_t output4 ( struct netif *  netif,
struct pbuf *  p,
const ip4_addr_t *  addr 
)
inlinestaticprotected

◆ peerIP()

ip4_t peerIP ( ) const
inlineinherited

IP address of the peer.

◆ phase()

PPPPhase phase ( ) const
inline

Current link phase.

◆ poll()

void poll ( )
inlineprotected

◆ 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.

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

PAP credentials (used only if the peer requires authentication)

◆ setDefault()

void setDefault ( bool  flag = true)
inline

Make this interface the default route when the link is up (default true)

◆ setEchoInterval()

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

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

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

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)

◆ setPollingPeriod()

void setPollingPeriod ( int  ms)
inline

Poll interval of the lwIP background task in ms (shared by all polled interfaces). Lower values give more throughput.

◆ setRequestDNS()

void setRequestDNS ( bool  flag)
inline

Request DNS servers from the peer (default true)

◆ start()

void start ( Stream &  io)
inlineinherited

Starts the PPP negotiation on the indicated stream.

◆ stats()

const PPPStats & stats ( ) const
inline

Frame and packet counters.

◆ status()

wl_status_t status ( ) const
inline

WL_CONNECTED when the link is up, WL_NO_SHIELD before begin()

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

◆ waitConnected()

bool waitConnected ( uint32_t  timeoutMs = 30000)
inline

Waits until the link is up.

◆ writeIPv4()

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

Adds data to the packet started with beginIPv4()

Member Data Documentation

◆ _cmd

volatile Cmd _cmd = Cmd::None
protected

◆ _default

bool _default = true
protected

◆ _io

Stream* _io = nullptr
protected

◆ _netif

struct netif _netif
protected

◆ _netifAdded

bool _netifAdded = false
protected

◆ _phID

int _phID = -1
protected

◆ _stateCallback

StateCallback _stateCallback = nullptr
protected

◆ _stateRef

void* _stateRef = nullptr
protected

◆ _up

volatile bool _up = false
protected

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