pap.h
Go to the documentation of this file.
1 /**
2  * @file pap.h
3  * @brief PAP (Password Authentication 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 _PAP_H
32 #define _PAP_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ppp/ppp.h"
37 
38 //PAP authentication support
39 #ifndef PAP_SUPPORT
40  #define PAP_SUPPORT ENABLED
41 #elif (PAP_SUPPORT != ENABLED && PAP_SUPPORT != DISABLED)
42  #error PAP_SUPPORT parameter is not valid
43 #endif
44 
45 //Restart timer
46 #ifndef PAP_RESTART_TIMER
47  #define PAP_RESTART_TIMER 3000
48 #elif (PAP_RESTART_TIMER < 1000)
49  #error PAP_RESTART_TIMER parameter is not valid
50 #endif
51 
52 //Maximum number of retransmissions for Authenticate-Request packets
53 #ifndef PAP_MAX_REQUESTS
54  #define PAP_MAX_REQUESTS 5
55 #elif (PAP_MAX_REQUESTS < 1)
56  #error PAP_MAX_REQUESTS parameter is not valid
57 #endif
58 
59 //C++ guard
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 
65 /**
66  * @brief PAP states
67  **/
68 
69 typedef enum
70 {
79 } PapState;
80 
81 
82 /**
83  * @brief Code field values
84  **/
85 
86 typedef enum
87 {
88  PAP_CODE_AUTH_REQ = 1, ///<Authenticate-Request
89  PAP_CODE_AUTH_ACK = 2, ///<Authenticate-Ack
90  PAP_CODE_AUTH_NAK = 3 ///<Authenticate-Nak
91 } PapCode;
92 
93 
94 //CodeWarrior or Win32 compiler?
95 #if defined(__CWCC__) || defined(_WIN32)
96  #pragma pack(push, 1)
97 #endif
98 
99 
100 /**
101  * @brief Authenticate-Request packet
102  **/
103 
104 typedef __start_packed struct
105 {
106  uint8_t code; //0
107  uint8_t identifier; //1
108  uint16_t length; //2-3
109  uint8_t peerIdLength; //4
110  uint8_t peerId[]; //5
112 
113 
114 /**
115  * @brief Authenticate-Ack packet
116  **/
117 
118 typedef __start_packed struct
119 {
120  uint8_t code; //0
121  uint8_t identifier; //1
122  uint16_t length; //2-3
123  uint8_t msgLength; //4
124  uint8_t message[]; //5
126 
127 
128 /**
129  * @brief Authenticate-Nak packet
130  **/
131 
132 typedef __start_packed struct
133 {
134  uint8_t code; //0
135  uint8_t identifier; //1
136  uint16_t length; //2-3
137  uint8_t msgLength; //4
138  uint8_t message[]; //5
140 
141 
142 //CodeWarrior or Win32 compiler?
143 #if defined(__CWCC__) || defined(_WIN32)
144  #pragma pack(pop)
145 #endif
146 
147 
148 /**
149  * @brief PAP finite state machine
150  **/
151 
152 typedef struct
153 {
154  uint_t localState; ///<Local state
155  uint_t peerState; ///<Peer state
156  uint8_t identifier; ///<Identifier used to match requests and replies
157  uint_t restartCounter; ///<Restart counter
158  systime_t timestamp; ///<Timestamp to manage retransmissions
159  const uint8_t *password; ///<Peer's password
160  size_t passwordLen; ///<Length of the password in bytes
161 } PapFsm;
162 
163 
164 //PAP related functions
167 
168 void papTick(PppContext *context);
169 
170 void papProcessPacket(PppContext *context,
171  const PppPacket *packet, size_t length);
172 
174  const PapAuthReqPacket *authReqPacket, size_t length);
175 
177  const PapAuthAckPacket *authAckPacket, size_t length);
178 
180  const PapAuthNakPacket *authNakPacket, size_t length);
181 
183 error_t papSendAuthAck(PppContext *context, uint8_t identifier);
184 error_t papSendAuthNak(PppContext *context, uint8_t identifier);
185 
186 bool_t papCheckPassword(PppContext *context, const char_t *password);
187 
188 //C++ guard
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif
@ PAP_STATE_1_STARTED
Definition: pap.h:72
systime_t timestamp
Timestamp to manage retransmissions.
Definition: pap.h:158
int bool_t
Definition: compiler_port.h:49
#define PppPacket
Definition: ppp.h:37
PapState
PAP states.
Definition: pap.h:69
error_t papSendAuthAck(PppContext *context, uint8_t identifier)
Send Authenticate-Ack packet.
Definition: pap.c:500
@ PAP_STATE_0_INITIAL
Definition: pap.h:71
@ PAP_STATE_6_NAK_SENT
Definition: pap.h:77
PAP finite state machine.
Definition: pap.h:152
uint8_t msgLength
Definition: pap.h:123
#define PppContext
Definition: ppp.h:38
error_t papSendAuthNak(PppContext *context, uint8_t identifier)
Send Authenticate-Nak packet.
Definition: pap.c:551
uint8_t identifier
Definition: pap.h:107
PapCode
Code field values.
Definition: pap.h:86
@ PAP_STATE_3_REQ_RCVD
Definition: pap.h:74
@ PAP_CODE_AUTH_REQ
Authenticate-Request.
Definition: pap.h:88
bool_t papCheckPassword(PppContext *context, const char_t *password)
Password verification.
Definition: pap.c:602
error_t
Error codes.
Definition: error.h:42
size_t passwordLen
Length of the password in bytes.
Definition: pap.h:160
@ PAP_STATE_7_NAK_RCVD
Definition: pap.h:78
uint_t peerState
Peer state.
Definition: pap.h:155
__start_packed struct _Ipv4Header __end_packed
uint8_t code
Definition: pap.h:106
@ PAP_STATE_5_ACK_RCVD
Definition: pap.h:76
__start_packed struct @284 PapAuthNakPacket
Authenticate-Nak packet.
@ PAP_STATE_4_ACK_SENT
Definition: pap.h:75
uint_t restartCounter
Restart counter.
Definition: pap.h:157
@ PAP_CODE_AUTH_ACK
Authenticate-Ack.
Definition: pap.h:89
error_t papProcessAuthReq(PppContext *context, const PapAuthReqPacket *authReqPacket, size_t length)
Process Authenticate-Request packet.
Definition: pap.c:214
uint8_t message[]
Definition: pap.h:124
error_t papStartAuth(PppContext *context)
Start PAP authentication.
Definition: pap.c:53
uint_t localState
Local state.
Definition: pap.h:154
__start_packed struct @283 PapAuthAckPacket
Authenticate-Ack packet.
uint8_t peerId[]
Definition: pap.h:110
char char_t
Definition: compiler_port.h:43
const uint8_t * password
Peer's password.
Definition: pap.h:159
error_t papProcessAuthNak(PppContext *context, const PapAuthNakPacket *authNakPacket, size_t length)
Process Authenticate-Nak packet.
Definition: pap.c:387
PPP (Point-to-Point Protocol)
error_t papProcessAuthAck(PppContext *context, const PapAuthAckPacket *authAckPacket, size_t length)
Process Authenticate-Ack packet.
Definition: pap.c:330
__start_packed struct @282 PapAuthReqPacket
Authenticate-Request packet.
uint8_t peerIdLength
Definition: pap.h:109
uint16_t length
Definition: pap.h:108
void papTick(PppContext *context)
PAP timer handler.
Definition: pap.c:110
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
error_t papAbortAuth(PppContext *context)
Abort PAP authentication.
Definition: pap.c:87
uint32_t systime_t
Definition: compiler_port.h:46
@ PAP_STATE_2_REQ_SENT
Definition: pap.h:73
@ PAP_CODE_AUTH_NAK
Authenticate-Nak.
Definition: pap.h:90
uint8_t identifier
Identifier used to match requests and replies.
Definition: pap.h:156
error_t papSendAuthReq(PppContext *context)
Send Authenticate-Request packet.
Definition: pap.c:422
void papProcessPacket(PppContext *context, const PppPacket *packet, size_t length)
Process an incoming PAP packet.
Definition: pap.c:149