mikroSDK Reference Manual
chap.h
Go to the documentation of this file.
1
31#ifndef _CHAP_H
32#define _CHAP_H
33
34//Dependencies
35#include "core/net.h"
36#include "ppp/ppp.h"
37
38//CHAP authentication support
39#ifndef CHAP_SUPPORT
40 #define CHAP_SUPPORT DISABLED
41#elif (CHAP_SUPPORT != ENABLED && CHAP_SUPPORT != DISABLED)
42 #error CHAP_SUPPORT parameter is not valid
43#endif
44
45//Restart timer
46#ifndef CHAP_RESTART_TIMER
47 #define CHAP_RESTART_TIMER 3000
48#elif (CHAP_RESTART_TIMER < 1000)
49 #error CHAP_RESTART_TIMER parameter is not valid
50#endif
51
52//Maximum number of retransmissions for Challenge packets
53#ifndef CHAP_MAX_CHALLENGES
54 #define CHAP_MAX_CHALLENGES 5
55#elif (CHAP_MAX_CHALLENGES < 1)
56 #error CHAP_MAX_CHALLENGES parameter is not valid
57#endif
58
59//C++ guard
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64
69typedef enum
70{
71 CHAP_STATE_0_INITIAL = 0,
72 CHAP_STATE_1_STARTED = 1,
73 CHAP_STATE_2_CHALLENGE_SENT = 2,
74 CHAP_STATE_3_CHALLENGE_RCVD = 3,
75 CHAP_STATE_4_RESPONSE_SENT = 4,
76 CHAP_STATE_5_RESPONSE_RCVD = 5,
77 CHAP_STATE_6_SUCCESS_SENT = 6,
78 CHAP_STATE_7_SUCCESS_RCVD = 7,
79 CHAP_STATE_8_FAILURE_SENT = 8,
80 CHAP_STATE_9_FAILURE_RCVD = 9
81} ChapState;
82
83
95
96
101typedef enum
102{
103 CHAP_ALGO_ID_CHAP_MD5 = 5, //CHAP with MD5
104 CHAP_ALGO_ID_MS_CHAP = 128, //MS-CHAP
105 CHAP_ALGO_ID_MS_CHAP_V2 = 129 //MS-CHAP-2
106} ChapAlgoId;
107
108
109//CodeWarrior or Win32 compiler?
110#if defined(__CWCC__) || defined(_WIN32)
111 #pragma pack(push, 1)
112#endif
113
114
120{
121 uint8_t code; //0
122 uint8_t identifier; //1
123 uint16_t length; //2-3
124 uint8_t valueSize; //4
125 uint8_t value[]; //5
126} ChapChallengePacket;
127
128
133typedef __packed_struct
134{
135 uint8_t code; //0
136 uint8_t identifier; //1
137 uint16_t length; //2-3
138 uint8_t valueSize; //4
139 uint8_t value[]; //5
140} ChapResponsePacket;
141
142
147typedef __packed_struct
148{
149 uint8_t code; //0
150 uint8_t identifier; //1
151 uint16_t length; //2-3
152 uint8_t message[]; //4
153} ChapSuccessPacket;
154
155
160typedef __packed_struct
161{
162 uint8_t code; //0
163 uint8_t identifier; //1
164 uint16_t length; //2-3
165 uint8_t message[]; //4
166} ChapFailurePacket;
167
168
169//CodeWarrior or Win32 compiler?
170#if defined(__CWCC__) || defined(_WIN32)
171 #pragma pack(pop)
172#endif
173
174
179typedef struct
180{
181 uint_t localState;
183 uint_t peerState;
187 uint8_t challenge[16];
188 const uint8_t *response;
189} ChapFsm;
190
191
192//CHAP related functions
193error_t chapStartAuth(PppContext *context);
194error_t chapAbortAuth(PppContext *context);
195
196void chapTick(PppContext *context);
197
198void chapProcessPacket(PppContext *context,
199 const PppPacket *packet, size_t length);
200
201error_t chapProcessChallenge(PppContext *context,
202 const ChapChallengePacket *challengePacket, size_t length);
203
204error_t chapProcessResponse(PppContext *context,
205 const ChapResponsePacket *responsePacket, size_t length);
206
207error_t chapProcessSuccess(PppContext *context,
208 const ChapSuccessPacket *successPacket, size_t length);
209
210error_t chapProcessFailure(PppContext *context,
211 const ChapFailurePacket *failurePacket, size_t length);
212
213error_t chapSendChallenge(PppContext *context);
214error_t chapSendResponse(PppContext *context, const uint8_t *value);
215error_t chapSendSuccess(PppContext *context);
216error_t chapSendFailure(PppContext *context);
217
218bool_t chapCheckPassword(PppContext *context, const char_t *password);
219
220//C++ guard
221#ifdef __cplusplus
222}
223#endif
224
225#endif
ChapState
CHAP states.
Definition chap.h:70
ChapCode
Code field values.
Definition chap.h:89
@ CHAP_CODE_RESPONSE
Response.
Definition chap.h:91
@ CHAP_CODE_SUCCESS
Success.
Definition chap.h:92
@ CHAP_CODE_CHALLENGE
Challenge.
Definition chap.h:90
@ CHAP_CODE_FAILURE
Failure.
Definition chap.h:93
ChapAlgoId
CHAP algorithm identifiers.
Definition chap.h:102
typedef __packed_struct
Challenge packet.
Definition chap.h:120
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
PPP (Point-to-Point Protocol)
CHAP finite state machine.
Definition chap.h:180
uint8_t localIdentifier
Identifier used to match requests and replies.
Definition chap.h:182
uint_t localState
Local state.
Definition chap.h:181
systime_t timestamp
Timestamp to manage retransmissions.
Definition chap.h:186
uint_t peerState
Peer state.
Definition chap.h:183
uint_t restartCounter
Restart counter.
Definition chap.h:185
uint8_t peerIdentifier
Identifier used to match requests and replies.
Definition chap.h:184
const uint8_t * response
Response value from the peer.
Definition chap.h:188