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