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  * 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 _IPCP_H
30 #define _IPCP_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "ppp/ppp.h"
35 
36 //Subnet mask
37 #define IPCP_DEFAULT_SUBNET_MASK IPV4_ADDR(255, 255, 255, 255)
38 
39 //C++ guard
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 
45 /**
46  * @brief IPCP option types
47  **/
48 
49 typedef enum
50 {
51  IPCP_OPTION_IP_ADDRESSES = 1, ///<IP-Addresses
52  IPCP_OPTION_IP_COMP_PROTOCOL = 2, ///<IP-Compression-Protocol
53  IPCP_OPTION_IP_ADDRESS = 3, ///<IP-Address
54  IPCP_OPTION_PRIMARY_DNS = 129, ///<Primary-DNS-Server-Address
55  IPCP_OPTION_PRIMARY_NBNS = 130, ///<Primary-NBNS-Server-Address
56  IPCP_OPTION_SECONDARY_DNS = 131, ///<Secondary-DNS-Server-Address
57  IPCP_OPTION_SECONDARY_NBNS = 132 ///<Secondary-NBNS-Server-Address
59 
60 
61 //CodeWarrior or Win32 compiler?
62 #if defined(__CWCC__) || defined(_WIN32)
63  #pragma pack(push, 1)
64 #endif
65 
66 
67 /**
68  * @brief IP-Addresses option
69  **/
70 
71 typedef __start_packed struct
72 {
73  uint8_t type; //0
74  uint8_t length; //1
78 
79 
80 /**
81  * @brief IP-Compression-Protocol option
82  **/
83 
84 typedef __start_packed struct
85 {
86  uint8_t type; //0
87  uint8_t length; //1
88  uint16_t protocol; //2-3
89  uint8_t data[]; //4
91 
92 
93 /**
94  * @brief IP-Address option
95  **/
96 
97 typedef __start_packed struct
98 {
99  uint8_t type; //0
100  uint8_t length; //1
103 
104 
105 /**
106  * @brief Primary-DNS-Server-Address option
107  **/
108 
109 typedef __start_packed struct
110 {
111  uint8_t type; //0
112  uint8_t length; //1
113  Ipv4Addr ipAddr; //2-5
115 
116 
117 /**
118  * @brief Primary-NBNS-Server-Address option
119  **/
120 
121 typedef __start_packed struct
122 {
123  uint8_t type; //0
124  uint8_t length; //1
125  Ipv4Addr ipAddr; //2-5
127 
128 
129 /**
130  * @brief Secondary-DNS-Server-Address option
131  **/
132 
133 typedef __start_packed struct
134 {
135  uint8_t type; //0
136  uint8_t length; //1
137  Ipv4Addr ipAddr; //2-5
139 
140 
141 /**
142  * @brief Secondary-NBNS-Server-Address option
143  **/
144 
145 typedef __start_packed struct
146 {
147  uint8_t type; //0
148  uint8_t length; //1
149  Ipv4Addr ipAddr; //2-5
151 
152 
153 //CodeWarrior or Win32 compiler?
154 #if defined(__CWCC__) || defined(_WIN32)
155  #pragma pack(pop)
156 #endif
157 
158 
159 //IPCP FSM events
160 error_t ipcpOpen(PppContext *context);
161 error_t ipcpClose(PppContext *context);
162 
163 void ipcpTick(PppContext *context);
164 
165 void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length);
166 
168  const PppConfigurePacket *configureReqPacket);
169 
171  const PppConfigurePacket *configureAckPacket);
172 
174  const PppConfigurePacket *configureNakPacket);
175 
177  const PppConfigurePacket *configureRejPacket);
178 
180  const PppTerminatePacket *terminateReqPacket);
181 
183  const PppTerminatePacket *terminateAckPacket);
184 
186  const PppCodeRejPacket *codeRejPacket);
187 
189  const PppPacket *packet);
190 
191 //IPCP FSM callback functions
192 void ipcpThisLayerUp(PppContext *context);
193 void ipcpThisLayerDown(PppContext *context);
194 void ipcpThisLayerStarted(PppContext *context);
195 void ipcpThisLayerFinished(PppContext *context);
196 
198 void ipcpZeroRestartCount(PppContext *context);
199 
201 
203  const PppConfigurePacket *configureReqPacket);
204 
206  const PppConfigurePacket *configureReqPacket);
207 
209  const PppConfigurePacket *configureReqPacket);
210 
212 
214  const PppTerminatePacket *terminateReqPacket);
215 
216 error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet);
217 
218 //IPCP options checking
219 error_t ipcpParseOption(PppContext *context, PppOption *option,
220  size_t inPacketLen, PppConfigurePacket *outPacket);
221 
223  IpcpIpAddressOption *option, PppConfigurePacket *outPacket);
224 
225 //C++ guard
226 #ifdef __cplusplus
227  }
228 #endif
229 
230 #endif
error_t ipcpProcessTerminateAck(PppContext *context, const PppTerminatePacket *terminateAckPacket)
Process Terminate-Ack packet.
Definition: ipcp.c:524
__start_packed struct @289 PppTerminatePacket
Terminate-Request and Terminate-Ack packet.
PPP (Point-to-Point Protocol)
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:232
uint8_t type
Definition: ipcp.h:73
uint8_t length
Definition: ipcp.h:74
error_t ipcpParseIpAddressOption(PppContext *context, IpcpIpAddressOption *option, PppConfigurePacket *outPacket)
Parse IP-Address option.
Definition: ipcp.c:1033
__start_packed struct @275 IpcpSecondaryNbnsOption
Secondary-NBNS-Server-Address option.
void ipcpThisLayerDown(PppContext *context)
This-Layer-Down callback function.
Definition: ipcp.c:661
TCP/IP stack core.
void ipcpZeroRestartCount(PppContext *context)
Zero-Restart-Count callback function.
Definition: ipcp.c:728
error_t ipcpClose(PppContext *context)
IPCP Close event.
Definition: ipcp.c:95
error_t ipcpOpen(PppContext *context)
IPCP Open event.
Definition: ipcp.c:74
error_t ipcpParseOption(PppContext *context, PppOption *option, size_t inPacketLen, PppConfigurePacket *outPacket)
Parse IPCP configuration option.
Definition: ipcp.c:981
__start_packed struct @290 PppCodeRejPacket
Code-Reject packet.
void ipcpInitRestartCount(PppContext *context, uint_t value)
Initialize-Restart-Count callback function.
Definition: ipcp.c:713
error_t ipcpSendTerminateAck(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Send-Terminate-Ack callback function.
Definition: ipcp.c:925
__start_packed struct @274 IpcpSecondaryDnsOption
Secondary-DNS-Server-Address option.
error_t ipcpProcessConfigureNak(PppContext *context, const PppConfigurePacket *configureNakPacket)
Process Configure-Nak packet.
Definition: ipcp.c:345
error_t ipcpProcessConfigureAck(PppContext *context, const PppConfigurePacket *configureAckPacket)
Process Configure-Ack packet.
Definition: ipcp.c:319
__start_packed struct @272 IpcpPrimaryDnsOption
Primary-DNS-Server-Address option.
#define PppPacket
Definition: ppp.h:35
__start_packed struct @294 PppOption
LCP/NCP option.
void ipcpTick(PppContext *context)
IPCP timer handler.
Definition: ipcp.c:119
__start_packed struct @270 IpcpIpCompProtocolOption
IP-Compression-Protocol option.
error_t ipcpSendCodeRej(PppContext *context, const PppPacket *packet)
Send-Code-Reject callback function.
Definition: ipcp.c:959
IP-Compression-Protocol.
Definition: ipcp.h:52
error_t ipcpProcessUnknownCode(PppContext *context, const PppPacket *packet)
Process packet with unknown code.
Definition: ipcp.c:594
void ipcpThisLayerUp(PppContext *context)
This-Layer-Up callback function.
Definition: ipcp.c:614
Secondary-NBNS-Server-Address.
Definition: ipcp.h:57
__start_packed struct @271 IpcpIpAddressOption
IP-Address option.
error_t ipcpProcessConfigureReject(PppContext *context, const PppConfigurePacket *configureRejPacket)
Process Configure-Reject packet.
Definition: ipcp.c:434
error_t ipcpSendConfigureAck(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Ack callback function.
Definition: ipcp.c:837
error_t ipcpSendConfigureRej(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Reject callback function.
Definition: ipcp.c:875
IpcpOptionType
IPCP option types.
Definition: ipcp.h:49
void ipcpProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming IPCP packet.
Definition: ipcp.c:149
__start_packed struct @269 IpcpIpAddressesOption
IP-Addresses option.
#define PppContext
Definition: ppp.h:36
IP-Addresses.
Definition: ipcp.h:51
Ipv4Addr srcIpAddr
Definition: ipcp.h:75
__start_packed struct _Ipv4Header __end_packed
Ipv4Addr ipAddr
Definition: ipcp.h:101
error_t
Error codes.
Definition: error.h:40
uint8_t data[]
Definition: ipcp.h:89
uint16_t protocol
Definition: ipcp.h:88
Secondary-DNS-Server-Address.
Definition: ipcp.h:56
Ipv4Addr destIpAddr
Definition: ipcp.h:76
unsigned int uint_t
Definition: compiler_port.h:43
error_t ipcpProcessTerminateReq(PppContext *context, const PppTerminatePacket *terminateReqPacket)
Process Terminate-Request packet.
Definition: ipcp.c:502
IP-Address.
Definition: ipcp.h:53
uint8_t value[]
Definition: dtls_misc.h:141
Primary-NBNS-Server-Address.
Definition: ipcp.h:55
error_t ipcpProcessCodeRej(PppContext *context, const PppCodeRejPacket *codeRejPacket)
Process Code-Reject packet.
Definition: ipcp.c:547
void ipcpThisLayerStarted(PppContext *context)
This-Layer-Started callback function.
Definition: ipcp.c:688
void ipcpThisLayerFinished(PppContext *context)
This-Layer-Finished callback function.
Definition: ipcp.c:700
error_t ipcpSendConfigureReq(PppContext *context)
Send-Configure-Request callback function.
Definition: ipcp.c:749
error_t ipcpSendConfigureNak(PppContext *context, const PppConfigurePacket *configureReqPacket)
Send-Configure-Nak callback function.
Definition: ipcp.c:856
Primary-DNS-Server-Address.
Definition: ipcp.h:54
__start_packed struct @273 IpcpPrimaryNbnsOption
Primary-NBNS-Server-Address option.
error_t ipcpProcessConfigureReq(PppContext *context, const PppConfigurePacket *configureReqPacket)
Process Configure-Request packet.
Definition: ipcp.c:223
__start_packed struct @288 PppConfigurePacket
Configure-Request, Configure-Ack, Configure-Nak and Configure-Reject packets.
error_t ipcpSendTerminateReq(PppContext *context)
Send-Terminate-Request callback function.
Definition: ipcp.c:893