32 #define TRACE_LEVEL PPP_TRACE_LEVEL
50 #if (PPP_SUPPORT == ENABLED)
56 static const uint16_t fcsTable[256] =
58 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
59 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
60 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
61 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
62 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
63 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
64 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
65 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
66 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
67 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
68 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
69 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
70 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
71 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
72 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
73 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
74 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
75 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
76 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
77 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
78 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
79 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
80 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
81 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
82 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
83 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
84 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
85 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
86 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
87 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
88 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
89 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
133 interface = settings->interface;
139 context->settings = *settings;
141 #if (PAP_SUPPORT == DISABLED)
146 #if (PAP_SUPPORT == DISABLED)
152 interface->pppContext = context;
155 context->interface = interface;
162 #if (IPV4_SUPPORT == ENABLED)
167 #if (IPV6_SUPPORT == ENABLED)
172 #if (PAP_SUPPORT == ENABLED)
178 #if (CHAP_SUPPORT == ENABLED)
204 if(interface == NULL)
208 if(interface->pppContext == NULL)
212 context = interface->pppContext;
218 context->timeout = timeout;
242 if(interface == NULL || username == NULL || password == NULL)
254 if(interface->pppContext == NULL)
258 context = interface->pppContext;
264 osStrcpy(context->username, username);
266 osStrcpy(context->password, password);
295 context = interface->pppContext;
303 #if (PAP_SUPPORT == ENABLED)
311 #if (CHAP_SUPPORT == ENABLED)
337 if(interface == NULL)
341 if(interface->pppContext == NULL)
345 context = interface->pppContext;
348 status =
osWaitForEvent(&interface->nicTxEvent, context->timeout);
402 if(interface == NULL ||
data == NULL || size == 0)
406 if(interface->pppContext == NULL)
410 context = interface->pppContext;
479 #if (NET_RTOS_SUPPORT == ENABLED)
485 if(interface == NULL)
489 if(interface->pppContext == NULL)
493 context = interface->pppContext;
503 context->lcpFsm.identifier = 0;
504 context->lcpFsm.restartCounter = 0;
505 context->lcpFsm.failureCounter = 0;
507 #if (IPV4_SUPPORT == ENABLED)
510 context->ipcpFsm.identifier = 0;
511 context->ipcpFsm.restartCounter = 0;
512 context->ipcpFsm.failureCounter = 0;
515 #if (IPV6_SUPPORT == ENABLED)
518 context->ipv6cpFsm.identifier = 0;
519 context->ipv6cpFsm.restartCounter = 0;
520 context->ipv6cpFsm.failureCounter = 0;
524 context->localAuthDone =
FALSE;
525 context->peerAuthDone =
FALSE;
527 #if (PAP_SUPPORT == ENABLED)
531 context->papFsm.identifier = 0;
532 context->papFsm.restartCounter = 0;
535 #if (CHAP_SUPPORT == ENABLED)
538 context->chapFsm.localIdentifier = 0;
540 context->chapFsm.peerIdentifier = 0;
544 context->localConfig.mru = context->settings.mru;
545 context->localConfig.mruRejected =
FALSE;
546 context->localConfig.accm = context->settings.accm;
547 context->localConfig.accmRejected =
FALSE;
548 context->localConfig.authProtocol = 0;
549 context->localConfig.authAlgo = 0;
550 context->localConfig.authProtocolRejected =
FALSE;
552 context->localConfig.magicNumberRejected =
FALSE;
553 context->localConfig.pfc =
TRUE;
554 context->localConfig.pfcRejected =
FALSE;
555 context->localConfig.acfc =
TRUE;
556 context->localConfig.acfcRejected =
FALSE;
559 if(context->settings.authCallback != NULL)
561 #if (PAP_SUPPORT == ENABLED)
569 #if (CHAP_SUPPORT == ENABLED)
583 context->peerConfig.authProtocol = 0;
585 context->peerConfig.pfc =
FALSE;
586 context->peerConfig.acfc =
FALSE;
588 #if (IPV4_SUPPORT == ENABLED)
590 context->localConfig.ipAddr = interface->ipv4Context.addrList[0].addr;
591 context->localConfig.ipAddrRejected =
FALSE;
592 context->localConfig.primaryDns = interface->ipv4Context.dnsServerList[0];
593 context->localConfig.primaryDnsRejected =
FALSE;
595 #if (IPV4_DNS_SERVER_LIST_SIZE >= 2)
596 context->localConfig.secondaryDns = interface->ipv4Context.dnsServerList[1];
597 context->localConfig.secondaryDnsRejected =
FALSE;
600 context->localConfig.secondaryDnsRejected =
FALSE;
605 context->localConfig.primaryDnsRejected =
TRUE;
609 context->localConfig.secondaryDnsRejected =
TRUE;
612 context->peerConfig.ipAddr = interface->ipv4Context.addrList[0].defaultGateway;
615 #if (IPV6_SUPPORT == ENABLED)
618 interface->ipv6Context.addrList[0].addr.b + 8);
620 context->localConfig.interfaceIdRejected =
FALSE;
624 interface->ipv6Context.routerList[0].addr.b + 8);
637 #if (NET_RTOS_SUPPORT == ENABLED)
647 #if (IPV4_SUPPORT == ENABLED)
657 #if (IPV6_SUPPORT == ENABLED)
706 #if (IPV4_SUPPORT == ENABLED)
711 #if (IPV6_SUPPORT == ENABLED)
716 #if (PAP_SUPPORT == ENABLED)
722 #if (CHAP_SUPPORT == ENABLED)
748 #if (NET_RTOS_SUPPORT == ENABLED)
754 if(interface == NULL)
758 if(interface->pppContext == NULL)
762 context = interface->pppContext;
777 #if (NET_RTOS_SUPPORT == ENABLED)
823 #if (IPV4_SUPPORT == ENABLED)
828 #if (IPV6_SUPPORT == ENABLED)
833 #if (PAP_SUPPORT == ENABLED)
839 #if (CHAP_SUPPORT == ENABLED)
872 context = interface->pppContext;
877 #if (IPV4_SUPPORT == ENABLED)
882 #if (IPV6_SUPPORT == ENABLED)
887 #if (PAP_SUPPORT == ENABLED)
892 #if (CHAP_SUPPORT == ENABLED)
915 #if (IPV6_SUPPORT == ENABLED)
920 context = interface->pppContext;
966 #if (IPV4_SUPPORT == ENABLED)
980 #if (IPV6_SUPPORT == ENABLED)
1001 #if (PAP_SUPPORT == ENABLED)
1009 #if (CHAP_SUPPORT == ENABLED)
1046 context = interface->pppContext;
1132 error =
nicSendPacket(interface, buffer, offset, &ancillary);
1229 for(i = 0; i <
length; i++)
1232 fcs = (fcs >> 8) ^ fcsTable[(fcs & 0xFF) ^
data[i]];
1262 if(offset < buffer->chunk[i].
length)
1275 fcs = (fcs >> 8) ^ fcsTable[(fcs & 0xFF) ^ *
p];
void chapProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming CHAP packet.
bool_t chapCheckPassword(PppContext *context, const char_t *password)
Password verification.
void chapTick(PppContext *context)
CHAP timer handler.
CHAP (Challenge Handshake Authentication Protocol)
#define TRACE_WARNING(...)
@ ERROR_CONNECTION_FAILED
@ ERROR_FAILURE
Generic error code.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
@ ERROR_ALREADY_CONNECTED
#define eui64CopyAddr(destEui64Addr, srcEui64Addr)
Interfaces Group MIB module.
#define IF_MIB_INC_COUNTER32(name, value)
#define IF_MIB_INC_COUNTER64(name, value)
void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming IPCP packet.
void ipcpTick(PppContext *context)
IPCP timer handler.
IPCP (PPP Internet Protocol Control Protocol)
void ipv4ProcessPacket(NetInterface *interface, Ipv4Header *packet, size_t length, NetRxAncillary *ancillary)
Incoming IPv4 packet processing.
#define IPV4_UNSPECIFIED_ADDR
void ipv6ProcessPacket(NetInterface *interface, NetBuffer *ipPacket, size_t ipPacketOffset, NetRxAncillary *ancillary)
Incoming IPv6 packet processing.
void ipv6cpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming IPV6CP packet.
void ipv6cpTick(PppContext *context)
IPV6CP timer handler.
IPV6CP (PPP IPv6 Control Protocol)
error_t lcpClose(PppContext *context)
LCP Close event.
error_t lcpProcessUnknownProtocol(PppContext *context, uint16_t protocol, const uint8_t *information, size_t length)
Process PPP frame with unknown protocol.
error_t lcpOpen(PppContext *context)
LCP Open event.
void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming LCP packet.
void lcpTick(PppContext *context)
LCP timer handler.
LCP (PPP Link Control Protocol)
#define MIB2_IF_INC_COUNTER32(name, value)
error_t netSetDriver(NetInterface *interface, const NicDriver *driver)
Set Ethernet MAC driver.
NetInterface * netGetDefaultInterface(void)
Get default network interface.
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
NetBuffer * netBufferAlloc(size_t length)
Allocate a multi-part buffer.
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
error_t netBufferAppend(NetBuffer *dest, const void *src, size_t length)
Append data a multi-part buffer.
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
error_t nicSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet to the network controller.
@ NIC_TYPE_PPP
PPP interface.
#define osMemset(p, value, length)
#define timeCompare(t1, t2)
bool_t osWaitForEvent(OsEvent *event, systime_t timeout)
Wait until the specified event is in the signaled state.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osDelayTask(systime_t delay)
Delay routine.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
systime_t osGetSystemTime(void)
Retrieve system time.
uint32_t systime_t
System time.
void papProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming PAP packet.
void papTick(PppContext *context)
PAP timer handler.
bool_t papCheckPassword(PppContext *context, const char_t *password)
Password verification.
PAP (Password Authentication Protocol)
error_t pppSendAtCommand(NetInterface *interface, const char_t *data)
Send AT command.
error_t pppClose(NetInterface *interface)
Close a PPP connection.
bool_t pppCheckPassword(NetInterface *interface, const char_t *password)
Password verification.
error_t pppSetTimeout(NetInterface *interface, systime_t timeout)
Set timeout value for blocking operations.
error_t pppConnect(NetInterface *interface)
Establish a PPP connection.
uint16_t pppCalcFcs(const uint8_t *data, size_t length)
FCS calculation.
void pppGetDefaultSettings(PppSettings *settings)
Initialize settings with default values.
uint16_t pppCalcFcsEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate FCS over a multi-part buffer.
error_t pppSetAuthInfo(NetInterface *interface, const char_t *username, const char_t *password)
Set PPP authentication information.
void pppTick(NetInterface *interface)
PPP timer handler.
NetBuffer * pppAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a PPP frame.
error_t pppSendFrame(NetInterface *interface, NetBuffer *buffer, size_t offset, uint16_t protocol)
Send a PPP frame.
void pppProcessFrame(NetInterface *interface, uint8_t *frame, size_t length, NetRxAncillary *ancillary)
Process an incoming PPP frame.
error_t pppReceiveAtCommand(NetInterface *interface, char_t *data, size_t size)
Wait for an incoming AT command.
size_t pppParseFrameHeader(const uint8_t *frame, size_t length, uint16_t *protocol)
Parse PPP frame header.
error_t pppInit(PppContext *context, const PppSettings *settings)
PPP initialization.
PPP (Point-to-Point Protocol)
#define PPP_FRAME_HEADER_SIZE
#define PPP_CTRL_FIELD
PPP Control field.
@ PPP_PROTOCOL_IPCP
IP Control Protocol.
@ PPP_PROTOCOL_LCP
Link Control Protocol.
@ PPP_PROTOCOL_IP
Internet Protocol.
@ PPP_PROTOCOL_IPV6CP
IPv6 Control Protocol.
@ PPP_PROTOCOL_CHAP
Challenge Handshake Authentication Protocol.
@ PPP_PROTOCOL_PAP
Password Authentication Protocol.
@ PPP_PROTOCOL_IPV6
Internet Protocol version 6.
@ PPP_AUTH_PROTOCOL_CHAP_MD5
@ PPP_PHASE_DEAD
Link dead.
@ PPP_PHASE_NETWORK
Network-layer protocol phase.
#define PPP_POLLING_INTERVAL
#define PPP_MAX_USERNAME_LEN
#define PPP_MAX_PASSWORD_LEN
#define PPP_DEFAULT_MAGIC_NUMBER
Data logging functions for debugging purpose (PPP)
error_t pppHdlcDriverSendAtCommand(NetInterface *interface, const char_t *data)
Send AT command.
error_t pppHdlcDriverPurgeRxBuffer(PppContext *context)
Purge RX buffer.
error_t pppHdlcDriverReceiveAtCommand(NetInterface *interface, char_t *data, size_t size)
Wait for an incoming AT command.
const NicDriver pppHdlcDriver
PPP HDLC driver.
String manipulation helper functions.
Structure describing a buffer that spans multiple chunks.
uint32_t accm
Default async control character map.
uint_t authProtocol
Allowed authentication protocols.
PppRandCallback randCallback
Random data generation callback function.
PppAuthCallback authCallback
PPP authentication callback function.
NetInterface * interface
Underlying network interface.