mikroSDK Reference Manual
pap.h
Go to the documentation of this file.
1
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
61extern "C" {
62#endif
63
64
69typedef enum
70{
71 PAP_STATE_0_INITIAL = 0,
72 PAP_STATE_1_STARTED = 1,
73 PAP_STATE_2_REQ_SENT = 2,
74 PAP_STATE_3_REQ_RCVD = 3,
75 PAP_STATE_4_ACK_SENT = 4,
76 PAP_STATE_5_ACK_RCVD = 5,
77 PAP_STATE_6_NAK_SENT = 6,
78 PAP_STATE_7_NAK_RCVD = 7
79} PapState;
80
81
92
93
94//CodeWarrior or Win32 compiler?
95#if defined(__CWCC__) || defined(_WIN32)
96 #pragma pack(push, 1)
97#endif
98
99
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
111} PapAuthReqPacket;
112
113
118typedef __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
125} PapAuthAckPacket;
126
127
132typedef __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
139} PapAuthNakPacket;
140
141
142//CodeWarrior or Win32 compiler?
143#if defined(__CWCC__) || defined(_WIN32)
144 #pragma pack(pop)
145#endif
146
147
152typedef struct
153{
154 uint_t localState;
155 uint_t peerState;
156 uint8_t identifier;
159 const uint8_t *password;
160 size_t passwordLen;
161} PapFsm;
162
163
164//PAP related functions
165error_t papStartAuth(PppContext *context);
166error_t papAbortAuth(PppContext *context);
167
168void papTick(PppContext *context);
169
170void papProcessPacket(PppContext *context,
171 const PppPacket *packet, size_t length);
172
173error_t papProcessAuthReq(PppContext *context,
174 const PapAuthReqPacket *authReqPacket, size_t length);
175
176error_t papProcessAuthAck(PppContext *context,
177 const PapAuthAckPacket *authAckPacket, size_t length);
178
179error_t papProcessAuthNak(PppContext *context,
180 const PapAuthNakPacket *authNakPacket, size_t length);
181
182error_t papSendAuthReq(PppContext *context);
183error_t papSendAuthAck(PppContext *context, uint8_t identifier);
184error_t papSendAuthNak(PppContext *context, uint8_t identifier);
185
186bool_t papCheckPassword(PppContext *context, const char_t *password);
187
188//C++ guard
189#ifdef __cplusplus
190}
191#endif
192
193#endif
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
PapCode
Code field values.
Definition pap.h:87
@ PAP_CODE_AUTH_REQ
Authenticate-Request.
Definition pap.h:88
@ PAP_CODE_AUTH_NAK
Authenticate-Nak.
Definition pap.h:90
@ PAP_CODE_AUTH_ACK
Authenticate-Ack.
Definition pap.h:89
PapState
PAP states.
Definition pap.h:70
typedef __packed_struct
Authenticate-Request packet.
Definition pap.h:105
PPP (Point-to-Point Protocol)
PAP finite state machine.
Definition pap.h:153
uint_t peerState
Peer state.
Definition pap.h:155
size_t passwordLen
Length of the password in bytes.
Definition pap.h:160
uint_t restartCounter
Restart counter.
Definition pap.h:157
systime_t timestamp
Timestamp to manage retransmissions.
Definition pap.h:158
const uint8_t * password
Peer's password.
Definition pap.h:159
uint_t localState
Local state.
Definition pap.h:154
uint8_t identifier
Identifier used to match requests and replies.
Definition pap.h:156