ipcp.h
Go to the documentation of this file.
1 /**
2  * @file ipcp.h
3  * @brief IPCP (PPP Internet Protocol 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 _IPCP_H
32 #define _IPCP_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ppp/ppp.h"
37 
38 //Subnet mask
39 #define IPCP_DEFAULT_SUBNET_MASK IPV4_ADDR(255, 255, 255, 255)
40 
41 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 
47 /**
48  * @brief IPCP option types
49  **/
50 
51 typedef enum
52 {
53  IPCP_OPTION_IP_ADDRESSES = 1, ///<IP-Addresses
54  IPCP_OPTION_IP_COMP_PROTOCOL = 2, ///<IP-Compression-Protocol
55  IPCP_OPTION_IP_ADDRESS = 3, ///<IP-Address
56  IPCP_OPTION_PRIMARY_DNS = 129, ///<Primary-DNS-Server-Address
57  IPCP_OPTION_PRIMARY_NBNS = 130, ///<Primary-NBNS-Server-Address
58  IPCP_OPTION_SECONDARY_DNS = 131, ///<Secondary-DNS-Server-Address
59  IPCP_OPTION_SECONDARY_NBNS = 132 ///<Secondary-NBNS-Server-Address
61 
62 
63 //CC-RX, CodeWarrior or Win32 compiler?
64 #if defined(__CCRX__)
65  #pragma pack
66 #elif defined(__CWCC__) || defined(_WIN32)
67  #pragma pack(push, 1)
68 #endif
69 
70 
71 /**
72  * @brief IP-Addresses option
73  **/
74 
76 {
77  uint8_t type; //0
78  uint8_t length; //1
82 
83 
84 /**
85  * @brief IP-Compression-Protocol option
86  **/
87 
88 typedef __packed_struct
89 {
90  uint8_t type; //0
91  uint8_t length; //1
92  uint16_t protocol; //2-3
93  uint8_t data[]; //4
95 
96 
97 /**
98  * @brief IP-Address option
99  **/
100 
101 typedef __packed_struct
102 {
103  uint8_t type; //0
104  uint8_t length; //1
107 
108 
109 /**
110  * @brief Primary-DNS-Server-Address option
111  **/
112 
113 typedef __packed_struct
114 {
115  uint8_t type; //0
116  uint8_t length; //1
117  Ipv4Addr ipAddr; //2-5
119 
120 
121 /**
122  * @brief Primary-NBNS-Server-Address option
123  **/
124 
125 typedef __packed_struct
126 {
127  uint8_t type; //0
128  uint8_t length; //1
129  Ipv4Addr ipAddr; //2-5
131 
132 
133 /**
134  * @brief Secondary-DNS-Server-Address option
135  **/
136 
137 typedef __packed_struct
138 {
139  uint8_t type; //0
140  uint8_t length; //1
141  Ipv4Addr ipAddr; //2-5
143 
144 
145 /**
146  * @brief Secondary-NBNS-Server-Address option
147  **/
148 
149 typedef __packed_struct
150 {
151  uint8_t type; //0
152  uint8_t length; //1
153  Ipv4Addr ipAddr; //2-5
155 
156 
157 //CC-RX, CodeWarrior or Win32 compiler?
158 #if defined(__CCRX__)
159  #pragma unpack
160 #elif defined(__CWCC__) || defined(_WIN32)
161  #pragma pack(pop)
162 #endif
163 
164 //IPCP FSM events
165 error_t ipcpOpen(PppContext *context);
166 error_t ipcpClose(PppContext *context);
167 
168 void ipcpTick(PppContext *context);
169 
170 void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
171 
173  const PppConfigurePacket *configureReqPacket);
174 
176  const PppConfigurePacket *configureAckPacket);
177 
179  const PppConfigurePacket *configureNakPacket);
180 
182  const PppConfigurePacket *configureRejPacket);
183 
185  const PppTerminatePacket *terminateReqPacket);
186 
188  const PppTerminatePacket *terminateAckPacket);
189 
191  const PppCodeRejPacket *codeRejPacket);
192 
194  const PppPacket *packet);
195 
196 //IPCP FSM callback functions
197 void ipcpThisLayerUp(PppContext *context);
198 void ipcpThisLayerDown(PppContext *context);
199 void ipcpThisLayerStarted(PppContext *context);
200 void ipcpThisLayerFinished(PppContext *context);
201 
203 void ipcpZeroRestartCount(PppContext *context);
204 
206 
208  const PppConfigurePacket *configureReqPacket);
209 
211  const PppConfigurePacket *configureReqPacket);
212 
214  const PppConfigurePacket *configureReqPacket);
215 
217 
219  const PppTerminatePacket *terminateReqPacket);
220 
221 error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet);
222 
223 //IPCP options checking
224 error_t ipcpParseOption(PppContext *context, PppOption *option,
225  size_t inPacketLen, PppConfigurePacket *outPacket);
226 
228  IpcpIpAddressOption *option, PppConfigurePacket *outPacket);
229 
230 //C++ guard
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif
#define PppPacket
Definition: ppp.h:37
IpcpSecondaryDnsOption
Definition: ipcp.h:142
void ipcpTick(PppContext *context)
IPCP timer handler.
Definition: ipcp.c:121
void ipcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: ipcp.c:702
@ IPCP_OPTION_PRIMARY_DNS
Primary-DNS-Server-Address.
Definition: ipcp.h:56
PppConfigurePacket
Definition: ppp.h:274
uint8_t type
Definition: coap_common.h:176
void ipcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: ipcp.c:616
@ IPCP_OPTION_IP_COMP_PROTOCOL
IP-Compression-Protocol.
Definition: ipcp.h:54
void ipcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: ipcp.c:690
typedef __packed_struct
IP-Addresses option.
Definition: ipcp.h:76
Ipv4Addr srcIpAddr
Definition: ipcp.h:79
error_t ipcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: ipcp.c:878
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
#define PppContext
Definition: ppp.h:38
PppCodeRejPacket
Definition: ppp.h:300
@ IPCP_OPTION_IP_ADDRESSES
IP-Addresses.
Definition: ipcp.h:53
error_t
Error codes.
Definition: error.h:43
void ipcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: ipcp.c:663
error_t ipcpOpen(PppContext *context)
IPCP Open event.
Definition: ipcp.c:76
error_t ipcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: ipcp.c:751
error_t ipcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: ipcp.c:928
IpcpPrimaryDnsOption
Definition: ipcp.h:118
error_t ipcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: ipcp.c:549
error_t ipcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse IPCP configuration option.
Definition: ipcp.c:984
error_t ipcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: ipcp.c:321
IpcpPrimaryNbnsOption
Definition: ipcp.h:130
IpcpIpAddressesOption
Definition: ipcp.h:81
error_t ipcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: ipcp.c:859
@ IPCP_OPTION_PRIMARY_NBNS
Primary-NBNS-Server-Address.
Definition: ipcp.h:57
IpcpSecondaryNbnsOption
Definition: ipcp.h:154
IpcpIpAddressOption
Definition: ipcp.h:106
error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: ipcp.c:962
error_t ipcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: ipcp.c:436
IpcpOptionType
IPCP option types.
Definition: ipcp.h:52
@ IPCP_OPTION_SECONDARY_NBNS
Secondary-NBNS-Server-Address.
Definition: ipcp.h:59
PppTerminatePacket
Definition: ppp.h:287
error_t ipcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: ipcp.c:896
uint8_t value[]
Definition: tcp.h:369
error_t ipcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: ipcp.c:596
error_t ipcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: ipcp.c:225
error_t ipcpParseIpAddressOption(PppContext *context, IpcpIpAddressOption *option, PppConfigurePacket *outPacket)
Parse IP-Address option.
Definition: ipcp.c:1036
uint8_t length
Definition: ipcp.h:78
PPP (Point-to-Point Protocol)
error_t ipcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: ipcp.c:840
error_t ipcpClose(PppContext *context)
IPCP Close event.
Definition: ipcp.c:97
Ipv4Addr ipAddr
Definition: ipcp.h:105
uint16_t protocol
Definition: ipcp.h:92
error_t ipcpProcessTerminateAck(PppContext *context, const PppTerminatePacket *terminateAckPacket)
Process Terminate-Ack packet.
Definition: ipcp.c:526
@ IPCP_OPTION_SECONDARY_DNS
Secondary-DNS-Server-Address.
Definition: ipcp.h:58
void ipcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: ipcp.c:730
void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming IPCP packet.
Definition: ipcp.c:151
PppOption
Definition: ppp.h:354
error_t ipcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: ipcp.c:504
unsigned int uint_t
Definition: compiler_port.h:50
@ IPCP_OPTION_IP_ADDRESS
IP-Address.
Definition: ipcp.h:55
TCP/IP stack core.
uint8_t data[]
Definition: ipcp.h:93
void ipcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: ipcp.c:715
IpcpIpCompProtocolOption
Definition: ipcp.h:94
error_t ipcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: ipcp.c:347
Ipv4Addr destIpAddr
Definition: ipcp.h:80