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-2019 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 1.9.6
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 
70 typedef __start_packed struct
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 __start_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 __start_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 __start_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 __start_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 __start_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 __start_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 
156 //LCP FSM events
157 error_t lcpOpen(PppContext *context);
158 error_t lcpClose(PppContext *context);
159 
160 void lcpTick(PppContext *context);
161 
162 void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
163 
165  const PppConfigurePacket *configureReqPacket);
166 
168  const PppConfigurePacket *configureAckPacket);
169 
171  const PppConfigurePacket *configureNakPacket);
172 
174  const PppConfigurePacket *configureRejPacket);
175 
177  const PppTerminatePacket *terminateReqPacket);
178 
180  const PppTerminatePacket *terminateAckPacket);
181 
183  const PppCodeRejPacket *codeRejPacket);
184 
186  const PppProtocolRejPacket *protocolRejPacket);
187 
189  const PppEchoPacket *echoReqPacket);
190 
192  const PppEchoPacket *echoRepPacket);
193 
195  const PppDiscardReqPacket *discardReqPacket);
196 
198  const PppPacket *packet);
199 
201  uint16_t protocol, const uint8_t *information, size_t length);
202 
203 //LCP FSM callback functions
204 void lcpThisLayerUp(PppContext *context);
205 void lcpThisLayerDown(PppContext *context);
206 void lcpThisLayerStarted(PppContext *context);
207 void lcpThisLayerFinished(PppContext *context);
208 
210 void lcpZeroRestartCount(PppContext *context);
211 
213 
215  const PppConfigurePacket *configureReqPacket);
216 
218  const PppConfigurePacket *configureReqPacket);
219 
221  const PppConfigurePacket *configureReqPacket);
222 
224 
226  const PppTerminatePacket *terminateReqPacket);
227 
228 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet);
229 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket);
230 
231 //LCP options checking
232 error_t lcpParseOption(PppContext *context, PppOption *option,
233  size_t inPacketLen, PppConfigurePacket *outPacket);
234 
236  LcpMruOption *option, PppConfigurePacket *outPacket);
237 
239  LcpAccmOption *option, PppConfigurePacket *outPacket);
240 
242  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket);
243 
245  LcpMagicNumberOption *option, PppConfigurePacket *outPacket);
246 
248  LcpPfcOption *option, PppConfigurePacket *outPacket);
249 
251  LcpAcfcOption *option, PppConfigurePacket *outPacket);
252 
253 //C++ guard
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif
#define PppPacket
Definition: ppp.h:37
void lcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: lcp.c:921
@ LCP_OPTION_ACCM
Async-Control-Character-Map.
Definition: lcp.h:51
__start_packed struct @286 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
uint16_t protocol
Definition: lcp.h:98
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1159
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
__start_packed struct @291 PppOption
LCP/NCP option.
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
__start_packed struct @289 PppEchoPacket
Echo-Request and Echo-Reply packet.
void lcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: lcp.c:967
#define PppContext
Definition: ppp.h:38
error_t lcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: lcp.c:1215
__start_packed struct @277 LcpAuthProtocolOption
Authentication-Protocol option.
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1197
__start_packed struct @280 LcpPfcOption
Protocol-Field-Compression option.
__start_packed struct @281 LcpAcfcOption
Address-and-Control-Field-Compression option.
error_t lcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: lcp.c:590
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1648
error_t lcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: lcp.c:492
error_t
Error codes.
Definition: error.h:42
void lcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: lcp.c:988
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:1392
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:345
@ 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:1281
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1502
error_t lcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: lcp.c:806
__start_packed struct @290 PppDiscardReqPacket
PPP Discard-Request packet.
__start_packed struct _Ipv4Header __end_packed
error_t lcpProcessDiscardReq(PppContext *context, const PppDiscardReqPacket *discardReqPacket)
Process Discard-Request packet.
Definition: lcp.c:788
__start_packed struct @288 PppProtocolRejPacket
Protocol-Reject packet.
error_t lcpParseAccmOption(PppContext *context, LcpAccmOption *option, PppConfigurePacket *outPacket)
Parse Async-Control-Character-Map option.
Definition: lcp.c:1458
error_t lcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse LCP configuration option.
Definition: lcp.c:1320
LcpOptionType
LCP option types.
Definition: lcp.h:48
void lcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: lcp.c:1003
error_t lcpParseAcfcOption(PppContext *context, LcpAcfcOption *option, PppConfigurePacket *outPacket)
Parse Address-and-Control-Field-Compression option.
Definition: lcp.c:1735
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1247
@ LCP_OPTION_PFC
Protocol-Field-Compression.
Definition: lcp.h:55
__start_packed struct @276 LcpAccmOption
Async-Control-Character-Map option.
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:1178
__start_packed struct @278 LcpQualityProtocolOption
Quality-Protocol option.
error_t lcpProcessEchoRep(PppContext *context, const PppEchoPacket *echoRepPacket)
Process Echo-Reply packet.
Definition: lcp.c:770
uint32_t accm
Definition: lcp.h:86
__start_packed struct @285 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
@ LCP_OPTION_QUALITY_PROTOCOL
Quality-Protocol.
Definition: lcp.h:53
void lcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: lcp.c:955
uint8_t data[]
Definition: lcp.h:99
__start_packed struct @279 LcpMagicNumberOption
Magic-Number option.
uint8_t length
Definition: lcp.h:73
@ 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
__start_packed struct @275 LcpMruOption
Maximum-Receive-Unit option.
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:1692
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:1301
void lcpTick(PppContext *context)
LCP timer handler.
Definition: lcp.c:125
uint8_t type
Definition: lcp.h:72
error_t lcpProcessEchoReq(PppContext *context, const PppEchoPacket *echoReqPacket)
Process Echo-Request packet.
Definition: lcp.c:747
uint8_t value[]
Definition: dtls_misc.h:150
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
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:1024
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
__start_packed struct @287 PppCodeRejPacket
Code-Reject packet.