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-2023 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.3.0
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 //CodeWarrior or Win32 compiler?
61 #if defined(__CWCC__) || defined(_WIN32)
62  #pragma pack(push, 1)
63 #endif
64 
65 
66 /**
67  * @brief Maximum-Receive-Unit option
68  **/
69 
71 {
72  uint8_t type; //0
73  uint8_t length; //1
74  uint16_t mru; //2-3
76 
77 
78 /**
79  * @brief Async-Control-Character-Map option
80  **/
81 
82 typedef __packed_struct
83 {
84  uint8_t type; //0
85  uint8_t length; //1
86  uint32_t accm; //2-5
88 
89 
90 /**
91  * @brief Authentication-Protocol option
92  **/
93 
94 typedef __packed_struct
95 {
96  uint8_t type; //0
97  uint8_t length; //1
98  uint16_t protocol; //2-3
99  uint8_t data[]; //4
101 
102 
103 /**
104  * @brief Quality-Protocol option
105  **/
106 
107 typedef __packed_struct
108 {
109  uint8_t type; //0
110  uint8_t length; //1
111  uint16_t protocol; //2-3
112  uint8_t data[]; //4
114 
115 
116 /**
117  * @brief Magic-Number option
118  **/
119 
120 typedef __packed_struct
121 {
122  uint8_t type; //0
123  uint8_t length; //1
124  uint32_t magicNumber; //2-5
126 
127 
128 /**
129  * @brief Protocol-Field-Compression option
130  **/
131 
132 typedef __packed_struct
133 {
134  uint8_t type; //0
135  uint8_t length; //1
137 
138 
139 /**
140  * @brief Address-and-Control-Field-Compression option
141  **/
142 
143 typedef __packed_struct
144 {
145  uint8_t type; //0
146  uint8_t length; //1
148 
149 
150 //CodeWarrior or Win32 compiler?
151 #if defined(__CWCC__) || defined(_WIN32)
152  #pragma pack(pop)
153 #endif
154 
155 //LCP FSM events
156 error_t lcpOpen(PppContext *context);
157 error_t lcpClose(PppContext *context);
158 
159 void lcpTick(PppContext *context);
160 
161 void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
162 
164  const PppConfigurePacket *configureReqPacket);
165 
167  const PppConfigurePacket *configureAckPacket);
168 
170  const PppConfigurePacket *configureNakPacket);
171 
173  const PppConfigurePacket *configureRejPacket);
174 
176  const PppTerminatePacket *terminateReqPacket);
177 
179  const PppTerminatePacket *terminateAckPacket);
180 
182  const PppCodeRejPacket *codeRejPacket);
183 
185  const PppProtocolRejPacket *protocolRejPacket);
186 
188  const PppEchoPacket *echoReqPacket);
189 
191  const PppEchoPacket *echoRepPacket);
192 
194  const PppDiscardReqPacket *discardReqPacket);
195 
197  const PppPacket *packet);
198 
200  uint16_t protocol, const uint8_t *information, size_t length);
201 
202 //LCP FSM callback functions
203 void lcpThisLayerUp(PppContext *context);
204 void lcpThisLayerDown(PppContext *context);
205 void lcpThisLayerStarted(PppContext *context);
206 void lcpThisLayerFinished(PppContext *context);
207 
209 void lcpZeroRestartCount(PppContext *context);
210 
212 
214  const PppConfigurePacket *configureReqPacket);
215 
217  const PppConfigurePacket *configureReqPacket);
218 
220  const PppConfigurePacket *configureReqPacket);
221 
223 
225  const PppTerminatePacket *terminateReqPacket);
226 
227 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet);
228 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket);
229 
230 //LCP options checking
231 error_t lcpParseOption(PppContext *context, PppOption *option,
232  size_t inPacketLen, PppConfigurePacket *outPacket);
233 
235  LcpMruOption *option, PppConfigurePacket *outPacket);
236 
238  LcpAccmOption *option, PppConfigurePacket *outPacket);
239 
241  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket);
242 
244  LcpMagicNumberOption *option, PppConfigurePacket *outPacket);
245 
247  LcpPfcOption *option, PppConfigurePacket *outPacket);
248 
250  LcpAcfcOption *option, PppConfigurePacket *outPacket);
251 
252 //C++ guard
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #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:98
LcpPfcOption
Definition: lcp.h:136
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1167
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:272
PppDiscardReqPacket
Definition: ppp.h:340
void lcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: lcp.c:975
LcpAcfcOption
Definition: lcp.h:147
#define PppContext
Definition: ppp.h:38
error_t lcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: lcp.c:1223
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1205
PppCodeRejPacket
Definition: ppp.h:298
error_t lcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: lcp.c:590
LcpQualityProtocolOption
Definition: lcp.h:113
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1656
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:87
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:1400
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:345
LcpMruOption
Definition: lcp.h:75
@ 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:1289
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1510
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:1466
error_t lcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse LCP configuration option.
Definition: lcp.c:1328
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:1743
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1255
@ LCP_OPTION_PFC
Protocol-Field-Compression.
Definition: lcp.h:55
uint8_t type
Definition: coap_common.h:174
uint32_t magicNumber
Definition: lcp.h:124
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:1186
error_t lcpProcessEchoRep(PppContext *context, const PppEchoPacket *echoRepPacket)
Process Echo-Reply packet.
Definition: lcp.c:770
uint32_t accm
Definition: lcp.h:86
LcpMagicNumberOption
Definition: lcp.h:125
PppEchoPacket
Definition: ppp.h:326
@ 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:99
LcpAuthProtocolOption
Definition: lcp.h:100
PppTerminatePacket
Definition: ppp.h:285
uint8_t length
Definition: lcp.h:73
uint8_t value[]
Definition: tcp.h:367
@ 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:74
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:1700
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:1309
void lcpTick(PppContext *context)
LCP timer handler.
Definition: lcp.c:125
PppOption
Definition: ppp.h:352
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:71
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:312