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-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 _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 //CodeWarrior or Win32 compiler?
64 #if defined(__CWCC__) || defined(_WIN32)
65  #pragma pack(push, 1)
66 #endif
67 
68 
69 /**
70  * @brief IP-Addresses option
71  **/
72 
73 typedef __start_packed struct
74 {
75  uint8_t type; //0
76  uint8_t length; //1
80 
81 
82 /**
83  * @brief IP-Compression-Protocol option
84  **/
85 
86 typedef __start_packed struct
87 {
88  uint8_t type; //0
89  uint8_t length; //1
90  uint16_t protocol; //2-3
91  uint8_t data[]; //4
93 
94 
95 /**
96  * @brief IP-Address option
97  **/
98 
99 typedef __start_packed struct
100 {
101  uint8_t type; //0
102  uint8_t length; //1
105 
106 
107 /**
108  * @brief Primary-DNS-Server-Address option
109  **/
110 
111 typedef __start_packed struct
112 {
113  uint8_t type; //0
114  uint8_t length; //1
115  Ipv4Addr ipAddr; //2-5
117 
118 
119 /**
120  * @brief Primary-NBNS-Server-Address option
121  **/
122 
123 typedef __start_packed struct
124 {
125  uint8_t type; //0
126  uint8_t length; //1
127  Ipv4Addr ipAddr; //2-5
129 
130 
131 /**
132  * @brief Secondary-DNS-Server-Address option
133  **/
134 
135 typedef __start_packed struct
136 {
137  uint8_t type; //0
138  uint8_t length; //1
139  Ipv4Addr ipAddr; //2-5
141 
142 
143 /**
144  * @brief Secondary-NBNS-Server-Address option
145  **/
146 
147 typedef __start_packed struct
148 {
149  uint8_t type; //0
150  uint8_t length; //1
151  Ipv4Addr ipAddr; //2-5
153 
154 
155 //CodeWarrior or Win32 compiler?
156 #if defined(__CWCC__) || defined(_WIN32)
157  #pragma pack(pop)
158 #endif
159 
160 
161 //IPCP FSM events
162 error_t ipcpOpen(PppContext *context);
163 error_t ipcpClose(PppContext *context);
164 
165 void ipcpTick(PppContext *context);
166 
167 void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
168 
170  const PppConfigurePacket *configureReqPacket);
171 
173  const PppConfigurePacket *configureAckPacket);
174 
176  const PppConfigurePacket *configureNakPacket);
177 
179  const PppConfigurePacket *configureRejPacket);
180 
182  const PppTerminatePacket *terminateReqPacket);
183 
185  const PppTerminatePacket *terminateAckPacket);
186 
188  const PppCodeRejPacket *codeRejPacket);
189 
191  const PppPacket *packet);
192 
193 //IPCP FSM callback functions
194 void ipcpThisLayerUp(PppContext *context);
195 void ipcpThisLayerDown(PppContext *context);
196 void ipcpThisLayerStarted(PppContext *context);
197 void ipcpThisLayerFinished(PppContext *context);
198 
200 void ipcpZeroRestartCount(PppContext *context);
201 
203 
205  const PppConfigurePacket *configureReqPacket);
206 
208  const PppConfigurePacket *configureReqPacket);
209 
211  const PppConfigurePacket *configureReqPacket);
212 
214 
216  const PppTerminatePacket *terminateReqPacket);
217 
218 error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet);
219 
220 //IPCP options checking
221 error_t ipcpParseOption(PppContext *context, PppOption *option,
222  size_t inPacketLen, PppConfigurePacket *outPacket);
223 
225  IpcpIpAddressOption *option, PppConfigurePacket *outPacket);
226 
227 //C++ guard
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif
#define PppPacket
Definition: ppp.h:37
__start_packed struct @286 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
void ipcpTick(PppContext *context)
IPCP timer handler.
Definition: ipcp.c:121
void ipcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: ipcp.c:702
__start_packed struct @266 IpcpIpAddressesOption
IP-Addresses option.
@ IPCP_OPTION_PRIMARY_DNS
Primary-DNS-Server-Address.
Definition: ipcp.h:56
__start_packed struct @291 PppOption
LCP/NCP option.
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
Ipv4Addr srcIpAddr
Definition: ipcp.h:77
error_t ipcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: ipcp.c:877
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:239
#define PppContext
Definition: ppp.h:38
uint8_t type
Definition: ipcp.h:75
__start_packed struct @271 IpcpSecondaryDnsOption
Secondary-DNS-Server-Address option.
__start_packed struct @269 IpcpPrimaryDnsOption
Primary-DNS-Server-Address option.
@ IPCP_OPTION_IP_ADDRESSES
IP-Addresses.
Definition: ipcp.h:53
error_t
Error codes.
Definition: error.h:42
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
__start_packed struct _Ipv4Header __end_packed
error_t ipcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: ipcp.c:751
__start_packed struct @270 IpcpPrimaryNbnsOption
Primary-NBNS-Server-Address option.
error_t ipcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: ipcp.c:927
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:983
error_t ipcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: ipcp.c:321
error_t ipcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: ipcp.c:858
@ IPCP_OPTION_PRIMARY_NBNS
Primary-NBNS-Server-Address.
Definition: ipcp.h:57
__start_packed struct @285 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: ipcp.c:961
error_t ipcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: ipcp.c:436
__start_packed struct @268 IpcpIpAddressOption
IP-Address option.
IpcpOptionType
IPCP option types.
Definition: ipcp.h:51
@ IPCP_OPTION_SECONDARY_NBNS
Secondary-NBNS-Server-Address.
Definition: ipcp.h:59
error_t ipcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: ipcp.c:895
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:1035
uint8_t length
Definition: ipcp.h:76
PPP (Point-to-Point Protocol)
__start_packed struct @272 IpcpSecondaryNbnsOption
Secondary-NBNS-Server-Address option.
error_t ipcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: ipcp.c:839
error_t ipcpClose(PppContext *context)
IPCP Close event.
Definition: ipcp.c:97
Ipv4Addr ipAddr
Definition: ipcp.h:103
uint16_t protocol
Definition: ipcp.h:90
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
error_t ipcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: ipcp.c:504
__start_packed struct @267 IpcpIpCompProtocolOption
IP-Compression-Protocol option.
uint8_t value[]
Definition: dtls_misc.h:150
unsigned int uint_t
Definition: compiler_port.h:45
@ IPCP_OPTION_IP_ADDRESS
IP-Address.
Definition: ipcp.h:55
TCP/IP stack core.
uint8_t data[]
Definition: ipcp.h:91
void ipcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: ipcp.c:715
__start_packed struct @287 PppCodeRejPacket
Code-Reject packet.
error_t ipcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: ipcp.c:347
Ipv4Addr destIpAddr
Definition: ipcp.h:78