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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _LCP_H
30 #define _LCP_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "ppp/ppp.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 
42 /**
43  * @brief LCP option types
44  **/
45 
46 typedef enum
47 {
48  LCP_OPTION_MRU = 1, ///<Maximum-Receive-Unit
49  LCP_OPTION_ACCM = 2, ///<Async-Control-Character-Map
50  LCP_OPTION_AUTH_PROTOCOL = 3, ///<Authentication-Protocol
51  LCP_OPTION_QUALITY_PROTOCOL = 4, ///<Quality-Protocol
52  LCP_OPTION_MAGIC_NUMBER = 5, ///<Magic-Number
53  LCP_OPTION_PFC = 7, ///<Protocol-Field-Compression
54  LCP_OPTION_ACFC = 8 ///<Address-and-Control-Field-Compression
56 
57 
58 //CodeWarrior or Win32 compiler?
59 #if defined(__CWCC__) || defined(_WIN32)
60  #pragma pack(push, 1)
61 #endif
62 
63 
64 /**
65  * @brief Maximum-Receive-Unit option
66  **/
67 
68 typedef __start_packed struct
69 {
70  uint8_t type; //0
71  uint8_t length; //1
72  uint16_t mru; //2-3
74 
75 
76 /**
77  * @brief Async-Control-Character-Map option
78  **/
79 
80 typedef __start_packed struct
81 {
82  uint8_t type; //0
83  uint8_t length; //1
84  uint32_t accm; //2-5
86 
87 
88 /**
89  * @brief Authentication-Protocol option
90  **/
91 
92 typedef __start_packed struct
93 {
94  uint8_t type; //0
95  uint8_t length; //1
96  uint16_t protocol; //2-3
97  uint8_t data[]; //4
99 
100 
101 /**
102  * @brief Quality-Protocol option
103  **/
104 
105 typedef __start_packed struct
106 {
107  uint8_t type; //0
108  uint8_t length; //1
109  uint16_t protocol; //2-3
110  uint8_t data[]; //4
112 
113 
114 /**
115  * @brief Magic-Number option
116  **/
117 
118 typedef __start_packed struct
119 {
120  uint8_t type; //0
121  uint8_t length; //1
122  uint32_t magicNumber; //2-5
124 
125 
126 /**
127  * @brief Protocol-Field-Compression option
128  **/
129 
130 typedef __start_packed struct
131 {
132  uint8_t type; //0
133  uint8_t length; //1
135 
136 
137 /**
138  * @brief Address-and-Control-Field-Compression option
139  **/
140 
141 typedef __start_packed struct
142 {
143  uint8_t type; //0
144  uint8_t length; //1
146 
147 
148 //CodeWarrior or Win32 compiler?
149 #if defined(__CWCC__) || defined(_WIN32)
150  #pragma pack(pop)
151 #endif
152 
153 
154 //LCP FSM events
155 error_t lcpOpen(PppContext *context);
156 error_t lcpClose(PppContext *context);
157 
158 void lcpTick(PppContext *context);
159 
160 void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
161 
163  const PppConfigurePacket *configureReqPacket);
164 
166  const PppConfigurePacket *configureAckPacket);
167 
169  const PppConfigurePacket *configureNakPacket);
170 
172  const PppConfigurePacket *configureRejPacket);
173 
175  const PppTerminatePacket *terminateReqPacket);
176 
178  const PppTerminatePacket *terminateAckPacket);
179 
181  const PppCodeRejPacket *codeRejPacket);
182 
184  const PppProtocolRejPacket *protocolRejPacket);
185 
187  const PppEchoPacket *echoReqPacket);
188 
190  const PppEchoPacket *echoRepPacket);
191 
193  const PppDiscardReqPacket *discardReqPacket);
194 
196  const PppPacket *packet);
197 
199  uint16_t protocol, const uint8_t *information, size_t length);
200 
201 //LCP FSM callback functions
202 void lcpThisLayerUp(PppContext *context);
203 void lcpThisLayerDown(PppContext *context);
204 void lcpThisLayerStarted(PppContext *context);
205 void lcpThisLayerFinished(PppContext *context);
206 
208 void lcpZeroRestartCount(PppContext *context);
209 
211 
213  const PppConfigurePacket *configureReqPacket);
214 
216  const PppConfigurePacket *configureReqPacket);
217 
219  const PppConfigurePacket *configureReqPacket);
220 
222 
224  const PppTerminatePacket *terminateReqPacket);
225 
226 error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet);
227 error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket);
228 
229 //LCP options checking
230 error_t lcpParseOption(PppContext *context, PppOption *option,
231  size_t inPacketLen, PppConfigurePacket *outPacket);
232 
234  LcpMruOption *option, PppConfigurePacket *outPacket);
235 
237  LcpAccmOption *option, PppConfigurePacket *outPacket);
238 
240  LcpAuthProtocolOption *option, PppConfigurePacket *outPacket);
241 
243  LcpMagicNumberOption *option, PppConfigurePacket *outPacket);
244 
246  LcpPfcOption *option, PppConfigurePacket *outPacket);
247 
249  LcpAcfcOption *option, PppConfigurePacket *outPacket);
250 
251 //C++ guard
252 #ifdef __cplusplus
253  }
254 #endif
255 
256 #endif
error_t lcpParseMruOption(PppContext *context, LcpMruOption *option, PppConfigurePacket *outPacket)
Parse Maximum-Receive-Unit option.
Definition: lcp.c:1390
error_t lcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: lcp.c:343
uint32_t magicNumber
Definition: lcp.h:122
__start_packed struct @289 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
PPP (Point-to-Point Protocol)
error_t lcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: lcp.c:369
void lcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: lcp.c:1001
error_t lcpParsePfcOption(PppContext *context, LcpPfcOption *option, PppConfigurePacket *outPacket)
Parse Protocol-Field-Compression option.
Definition: lcp.c:1690
void lcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: lcp.c:953
error_t lcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: lcp.c:1157
TCP/IP stack core.
void lcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming LCP packet.
Definition: lcp.c:153
error_t lcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: lcp.c:1176
uint32_t accm
Definition: lcp.h:84
void lcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: lcp.c:919
__start_packed struct @292 PppEchoPacket
Echo-Request and Echo-Reply packet.
__start_packed struct @290 PppCodeRejPacket
Code-Reject packet.
error_t lcpProcessEchoReq(PppContext *context, const PppEchoPacket *echoReqPacket)
Process Echo-Request packet.
Definition: lcp.c:745
uint16_t mru
Definition: lcp.h:72
__start_packed struct @280 LcpAuthProtocolOption
Authentication-Protocol option.
error_t lcpClose(PppContext *context)
LCP Close event.
Definition: lcp.c:101
void lcpTick(PppContext *context)
LCP timer handler.
Definition: lcp.c:123
error_t lcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: lcp.c:804
error_t lcpProcessTerminateAck(PppContext *context, const PppTerminatePacket *terminateAckPacket)
Process Terminate-Ack packet.
Definition: lcp.c:610
error_t lcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: lcp.c:1022
#define PppPacket
Definition: ppp.h:35
__start_packed struct @293 PppDiscardReqPacket
PPP Discard-Request packet.
void lcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: lcp.c:965
uint8_t length
Definition: lcp.h:71
__start_packed struct @294 PppOption
LCP/NCP option.
Async-Control-Character-Map.
Definition: lcp.h:49
void lcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: lcp.c:986
error_t lcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: lcp.c:1279
error_t lcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: lcp.c:633
Protocol-Field-Compression.
Definition: lcp.h:53
error_t lcpProcessUnknownProtocol(PppContext *context, uint16_t protocol, const uint8_t *information, size_t length)
Process PPP frame with unknown protocol.
Definition: lcp.c:828
error_t lcpSendEchoRep(PppContext *context, const PppEchoPacket *echoReqPacket)
Send-Echo-Reply callback function.
Definition: lcp.c:1299
error_t lcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: lcp.c:1245
LcpOptionType
LCP option types.
Definition: lcp.h:46
error_t lcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: lcp.c:588
Maximum-Receive-Unit.
Definition: lcp.h:48
Address-and-Control-Field-Compression.
Definition: lcp.h:54
Quality-Protocol.
Definition: lcp.h:51
void lcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: lcp.c:856
error_t lcpParseAccmOption(PppContext *context, LcpAccmOption *option, PppConfigurePacket *outPacket)
Parse Async-Control-Character-Map option.
Definition: lcp.c:1456
error_t lcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: lcp.c:490
__start_packed struct @279 LcpAccmOption
Async-Control-Character-Map option.
__start_packed struct @282 LcpMagicNumberOption
Magic-Number option.
#define PppContext
Definition: ppp.h:36
__start_packed struct @281 LcpQualityProtocolOption
Quality-Protocol option.
__start_packed struct @278 LcpMruOption
Maximum-Receive-Unit option.
uint16_t protocol
Definition: lcp.h:96
__start_packed struct _Ipv4Header __end_packed
Magic-Number.
Definition: lcp.h:52
error_t lcpProcessProtocolRej(PppContext *context, const PppProtocolRejPacket *protocolRejPacket)
Process Protocol-Reject packet.
Definition: lcp.c:680
error_t
Error codes.
Definition: error.h:40
error_t lcpParseMagicNumberOption(PppContext *context, LcpMagicNumberOption *option, PppConfigurePacket *outPacket)
Parse Magic-Number option.
Definition: lcp.c:1646
error_t lcpProcessEchoRep(PppContext *context, const PppEchoPacket *echoRepPacket)
Process Echo-Reply packet.
Definition: lcp.c:768
uint8_t type
Definition: lcp.h:70
unsigned int uint_t
Definition: compiler_port.h:43
error_t lcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: lcp.c:247
error_t lcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse LCP configuration option.
Definition: lcp.c:1318
__start_packed struct @284 LcpAcfcOption
Address-and-Control-Field-Compression option.
error_t lcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: lcp.c:1213
uint8_t value[]
Definition: dtls_misc.h:141
error_t lcpParseAuthProtocolOption(PppContext *context, LcpAuthProtocolOption *option, PppConfigurePacket *outPacket)
Parse Authentication-Protocol option.
Definition: lcp.c:1500
__start_packed struct @283 LcpPfcOption
Protocol-Field-Compression option.
error_t lcpParseAcfcOption(PppContext *context, LcpAcfcOption *option, PppConfigurePacket *outPacket)
Parse Address-and-Control-Field-Compression option.
Definition: lcp.c:1733
uint8_t data[]
Definition: lcp.h:97
error_t lcpOpen(PppContext *context)
LCP Open event.
Definition: lcp.c:77
error_t lcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: lcp.c:1195
__start_packed struct @288 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
error_t lcpProcessDiscardReq(PppContext *context, const PppDiscardReqPacket *discardReqPacket)
Process Discard-Request packet.
Definition: lcp.c:786
__start_packed struct @291 PppProtocolRejPacket
Protocol-Reject packet.
Authentication-Protocol.
Definition: lcp.h:50