lcp.h
Go to the documentation of this file.
1 /**
2  * @file lcp.h
3  * @brief LCP (PPP Link Control Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _LCP_H
32 #define _LCP_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ppp/ppp.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
44 /**
45  * @brief LCP option types
46  **/
47 
48 typedef enum
49 {
50  LCP_OPTION_MRU = 1, ///<Maximum-Receive-Unit
51  LCP_OPTION_ACCM = 2, ///<Async-Control-Character-Map
52  LCP_OPTION_AUTH_PROTOCOL = 3, ///<Authentication-Protocol
53  LCP_OPTION_QUALITY_PROTOCOL = 4, ///<Quality-Protocol
54  LCP_OPTION_MAGIC_NUMBER = 5, ///<Magic-Number
55  LCP_OPTION_PFC = 7, ///<Protocol-Field-Compression
56  LCP_OPTION_ACFC = 8 ///<Address-and-Control-Field-Compression
58 
59 
60 //CC-RX, CodeWarrior or Win32 compiler?
61 #if defined(__CCRX__)
62  #pragma pack
63 #elif defined(__CWCC__) || defined(_WIN32)
64  #pragma pack(push, 1)
65 #endif
66 
67 
68 /**
69  * @brief Maximum-Receive-Unit option
70  **/
71 
73 {
74  uint8_t type; //0
75  uint8_t length; //1
76  uint16_t mru; //2-3
78 
79 
80 /**
81  * @brief Async-Control-Character-Map option
82  **/
83 
84 typedef __packed_struct
85 {
86  uint8_t type; //0
87  uint8_t length; //1
88  uint32_t accm; //2-5
90 
91 
92 /**
93  * @brief Authentication-Protocol option
94  **/
95 
96 typedef __packed_struct
97 {
98  uint8_t type; //0
99  uint8_t length; //1
100  uint16_t protocol; //2-3
101  uint8_t data[]; //4
103 
104 
105 /**
106  * @brief Quality-Protocol option
107  **/
108 
109 typedef __packed_struct
110 {
111  uint8_t type; //0
112  uint8_t length; //1
113  uint16_t protocol; //2-3
114  uint8_t data[]; //4
116 
117 
118 /**
119  * @brief Magic-Number option
120  **/
121 
122 typedef __packed_struct
123 {
124  uint8_t type; //0
125  uint8_t length; //1
126  uint32_t magicNumber; //2-5
128 
129 
130 /**
131  * @brief Protocol-Field-Compression option
132  **/
133 
134 typedef __packed_struct
135 {
136  uint8_t type; //0
137  uint8_t length; //1
139 
140 
141 /**
142  * @brief Address-and-Control-Field-Compression option
143  **/
144 
145 typedef __packed_struct
146 {
147  uint8_t type; //0
148  uint8_t length; //1
150 
151 
152 //CC-RX, CodeWarrior or Win32 compiler?
153 #if defined(__CCRX__)
154  #pragma unpack
155 #elif defined(__CWCC__) || defined(_WIN32)
156  #pragma pack(pop)
157 #endif
158 
159 //LCP FSM events
160 error_t lcpOpen(PppContext *context);
161 error_t lcpClose(PppContext *context);
162 
163 void lcpTick(PppContext *context);
164 
165 void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
166 
168  const PppConfigurePacket *configureReqPacket);
169 
171  const PppConfigurePacket *configureAckPacket);
172 
174  const PppConfigurePacket *configureNakPacket);
175 
177  const PppConfigurePacket *configureRejPacket);
178 
180  const PppTerminatePacket *terminateReqPacket);
181 
183  const PppTerminatePacket *terminateAckPacket);
184 
186  const PppCodeRejPacket *codeRejPacket);
187 
189  const PppProtocolRejPacket *protocolRejPacket);
190 
192  const PppEchoPacket *echoReqPacket);
193 
195  const PppEchoPacket *echoRepPacket);
196 
198  const PppDiscardReqPacket *discardReqPacket);
199 
201  const PppPacket *packet);
202 
204  uint16_t protocol, const uint8_t *information, size_t length);
205 
206 //LCP FSM callback functions
207 void lcpThisLayerUp(PppContext *context);
208 void lcpThisLayerDown(PppContext *context);
209 void lcpThisLayerStarted(PppContext *context);
210 void lcpThisLayerFinished(PppContext *context);
211 
213 void lcpZeroRestartCount(PppContext *context);
214 
216 
218  const PppConfigurePacket *configureReqPacket);
219 
221  const PppConfigurePacket *configureReqPacket);
222 
224  const PppConfigurePacket *configureReqPacket);
225 
227 
229  const PppTerminatePacket *terminateReqPacket);
230 
231 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet);
232 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket);
233 
234 //LCP options checking
235 error_t lcpParseOption(PppContext *context, PppOption *option,
236  size_t inPacketLen, PppConfigurePacket *outPacket);
237 
239  LcpMruOption *option, PppConfigurePacket *outPacket);
240 
242  LcpAccmOption *option, PppConfigurePacket *outPacket);
243 
245  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket);
246 
248  LcpMagicNumberOption *option, PppConfigurePacket *outPacket);
249 
251  LcpPfcOption *option, PppConfigurePacket *outPacket);
252 
254  LcpAcfcOption *option, PppConfigurePacket *outPacket);
255 
256 //C++ guard
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 #endif
#define PppPacket
Definition: ppp.h:37
void lcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: lcp.c:929
@ LCP_OPTION_ACCM
Async-Control-Character-Map.
Definition: lcp.h:51
uint16_t protocol
Definition: lcp.h:100
LcpPfcOption
Definition: lcp.h:138
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1168
error_t lcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: lcp.c:249
void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming LCP packet.
Definition: lcp.c:155
error_t lcpProcessUnknownProtocol(PppContext *context, uint16_t protocol, const uint8_t *information, size_t length)
Process PPP frame with unknown protocol.
Definition: lcp.c:830
PppConfigurePacket
Definition: ppp.h:274
uint8_t type
Definition: coap_common.h:176
PppDiscardReqPacket
Definition: ppp.h:342
void lcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: lcp.c:975
LcpAcfcOption
Definition: lcp.h:149
#define PppContext
Definition: ppp.h:38
error_t lcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: lcp.c:1224
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1206
PppCodeRejPacket
Definition: ppp.h:300
error_t lcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: lcp.c:590
LcpQualityProtocolOption
Definition: lcp.h:115
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1657
error_t lcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: lcp.c:492
error_t
Error codes.
Definition: error.h:43
LcpAccmOption
Definition: lcp.h:89
void lcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: lcp.c:996
error_t lcpOpen(PppContext *context)
LCP Open event.
Definition: lcp.c:79
error_t lcpParseMruOption(PppContext *context, LcpMruOption *option, PppConfigurePacket *outPacket)
Parse Maximum-Receive-Unit option.
Definition: lcp.c:1401
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:345
LcpMruOption
Definition: lcp.h:77
@ LCP_OPTION_ACFC
Address-and-Control-Field-Compression.
Definition: lcp.h:56
error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: lcp.c:1290
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1511
error_t lcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: lcp.c:806
error_t lcpProcessDiscardReq(PppContext *context, const PppDiscardReqPacket *discardReqPacket)
Process Discard-Request packet.
Definition: lcp.c:788
error_t lcpParseAccmOption(PppContext *context, LcpAccmOption *option, PppConfigurePacket *outPacket)
Parse Async-Control-Character-Map option.
Definition: lcp.c:1467
error_t lcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse LCP configuration option.
Definition: lcp.c:1329
LcpOptionType
LCP option types.
Definition: lcp.h:49
void lcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: lcp.c:1011
error_t lcpParseAcfcOption(PppContext *context, LcpAcfcOption *option, PppConfigurePacket *outPacket)
Parse Address-and-Control-Field-Compression option.
Definition: lcp.c:1744
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1256
@ LCP_OPTION_PFC
Protocol-Field-Compression.
Definition: lcp.h:55
uint32_t magicNumber
Definition: lcp.h:126
error_t lcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: lcp.c:371
error_t lcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: lcp.c:1187
error_t lcpProcessEchoRep(PppContext *context, const PppEchoPacket *echoRepPacket)
Process Echo-Reply packet.
Definition: lcp.c:770
uint32_t accm
Definition: lcp.h:88
LcpMagicNumberOption
Definition: lcp.h:127
PppEchoPacket
Definition: ppp.h:328
@ LCP_OPTION_QUALITY_PROTOCOL
Quality-Protocol.
Definition: lcp.h:53
void lcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: lcp.c:963
uint8_t data[]
Definition: lcp.h:101
LcpAuthProtocolOption
Definition: lcp.h:102
PppTerminatePacket
Definition: ppp.h:287
uint8_t length
Definition: lcp.h:75
uint8_t value[]
Definition: tcp.h:369
@ LCP_OPTION_AUTH_PROTOCOL
Authentication-Protocol.
Definition: lcp.h:52
@ LCP_OPTION_MRU
Maximum-Receive-Unit.
Definition: lcp.h:50
uint16_t mru
Definition: lcp.h:76
PPP (Point-to-Point Protocol)
@ LCP_OPTION_MAGIC_NUMBER
Magic-Number.
Definition: lcp.h:54
error_t lcpParsePfcOption(PppContext *context, LcpPfcOption *option, PppConfigurePacket *outPacket)
Parse Protocol-Field-Compression option.
Definition: lcp.c:1701
void lcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: lcp.c:858
error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
Send-Echo-Reply callback function.
Definition: lcp.c:1310
void lcpTick(PppContext *context)
LCP timer handler.
Definition: lcp.c:125
PppOption
Definition: ppp.h:354
error_t lcpProcessEchoReq(PppContext *context, const PppEchoPacket *echoReqPacket)
Process Echo-Request packet.
Definition: lcp.c:747
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
typedef __packed_struct
Maximum-Receive-Unit option.
Definition: lcp.h:73
error_t lcpProcessProtocolRej(PppContext *context, const PppProtocolRejPacket *protocolRejPacket)
Process Protocol-Reject packet.
Definition: lcp.c:682
error_t lcpClose(PppContext *context)
LCP Close event.
Definition: lcp.c:103
error_t lcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: lcp.c:1032
error_t lcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: lcp.c:635
error_t lcpProcessTerminateAck(PppContext *context, const PppTerminatePacket *terminateAckPacket)
Process Terminate-Ack packet.
Definition: lcp.c:612
PppProtocolRejPacket
Definition: ppp.h:314