Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
chap.h
00001 /** 00002 * @file chap.h 00003 * @brief CHAP (Challenge Handshake Authentication Protocol) 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _CHAP_H 00030 #define _CHAP_H 00031 00032 //Dependencies 00033 #include "core/net.h" 00034 #include "ppp/ppp.h" 00035 00036 //CHAP authentication support 00037 #ifndef CHAP_SUPPORT 00038 #define CHAP_SUPPORT DISABLED 00039 #elif (CHAP_SUPPORT != ENABLED && CHAP_SUPPORT != DISABLED) 00040 #error CHAP_SUPPORT parameter is not valid 00041 #endif 00042 00043 //Restart timer 00044 #ifndef CHAP_RESTART_TIMER 00045 #define CHAP_RESTART_TIMER 3000 00046 #elif (CHAP_RESTART_TIMER < 1000) 00047 #error CHAP_RESTART_TIMER parameter is not valid 00048 #endif 00049 00050 //Maximum number of retransmissions for Challenge packets 00051 #ifndef CHAP_MAX_CHALLENGES 00052 #define CHAP_MAX_CHALLENGES 5 00053 #elif (CHAP_MAX_CHALLENGES < 1) 00054 #error CHAP_MAX_CHALLENGES parameter is not valid 00055 #endif 00056 00057 00058 /** 00059 * @brief CHAP states 00060 **/ 00061 00062 typedef enum 00063 { 00064 CHAP_STATE_0_INITIAL = 0, 00065 CHAP_STATE_1_STARTED = 1, 00066 CHAP_STATE_2_CHALLENGE_SENT = 2, 00067 CHAP_STATE_3_CHALLENGE_RCVD = 3, 00068 CHAP_STATE_4_RESPONSE_SENT = 4, 00069 CHAP_STATE_5_RESPONSE_RCVD = 5, 00070 CHAP_STATE_6_SUCCESS_SENT = 6, 00071 CHAP_STATE_7_SUCCESS_RCVD = 7, 00072 CHAP_STATE_8_FAILURE_SENT = 8, 00073 CHAP_STATE_9_FAILURE_RCVD = 9 00074 } ChapState; 00075 00076 00077 /** 00078 * @brief Code field values 00079 **/ 00080 00081 typedef enum 00082 { 00083 CHAP_CODE_CHALLENGE = 1, ///<Challenge 00084 CHAP_CODE_RESPONSE = 2, ///<Response 00085 CHAP_CODE_SUCCESS = 3, ///<Success 00086 CHAP_CODE_FAILURE = 4 ///<Failure 00087 } ChapCode; 00088 00089 00090 /** 00091 * @brief CHAP algorithm identifiers 00092 **/ 00093 00094 typedef enum 00095 { 00096 CHAP_ALGO_ID_CHAP_MD5 = 5, //CHAP with MD5 00097 CHAP_ALGO_ID_MS_CHAP = 128, //MS-CHAP 00098 CHAP_ALGO_ID_MS_CHAP_V2 = 129 //MS-CHAP-2 00099 } ChapAlgoId; 00100 00101 00102 //CodeWarrior or Win32 compiler? 00103 #if defined(__CWCC__) || defined(_WIN32) 00104 #pragma pack(push, 1) 00105 #endif 00106 00107 00108 /** 00109 * @brief Challenge packet 00110 **/ 00111 00112 typedef __start_packed struct 00113 { 00114 uint8_t code; //0 00115 uint8_t identifier; //1 00116 uint16_t length; //2-3 00117 uint8_t valueSize; //4 00118 uint8_t value[]; //5 00119 } __end_packed ChapChallengePacket; 00120 00121 00122 /** 00123 * @brief Response packet 00124 **/ 00125 00126 typedef __start_packed struct 00127 { 00128 uint8_t code; //0 00129 uint8_t identifier; //1 00130 uint16_t length; //2-3 00131 uint8_t valueSize; //4 00132 uint8_t value[]; //5 00133 } __end_packed ChapResponsePacket; 00134 00135 00136 /** 00137 * @brief Success packet 00138 **/ 00139 00140 typedef __start_packed struct 00141 { 00142 uint8_t code; //0 00143 uint8_t identifier; //1 00144 uint16_t length; //2-3 00145 uint8_t message[]; //4 00146 } __end_packed ChapSuccessPacket; 00147 00148 00149 /** 00150 * @brief Failure packet 00151 **/ 00152 00153 typedef __start_packed struct 00154 { 00155 uint8_t code; //0 00156 uint8_t identifier; //1 00157 uint16_t length; //2-3 00158 uint8_t message[]; //4 00159 } __end_packed ChapFailurePacket; 00160 00161 00162 //CodeWarrior or Win32 compiler? 00163 #if defined(__CWCC__) || defined(_WIN32) 00164 #pragma pack(pop) 00165 #endif 00166 00167 00168 /** 00169 * @brief CHAP finite state machine 00170 **/ 00171 00172 typedef struct 00173 { 00174 uint_t localState; ///<Local state 00175 uint8_t localIdentifier; ///<Identifier used to match requests and replies 00176 uint_t peerState; ///<Peer state 00177 uint8_t peerIdentifier; ///<Identifier used to match requests and replies 00178 uint_t restartCounter; ///<Restart counter 00179 systime_t timestamp; ///<Timestamp to manage retransmissions 00180 uint8_t challenge[16]; ///<Challenge value sent to the peer 00181 const uint8_t *response; ///<Response value from the peer 00182 } ChapFsm; 00183 00184 00185 //CHAP related functions 00186 error_t chapStartAuth(PppContext *context); 00187 error_t chapAbortAuth(PppContext *context); 00188 00189 void chapTick(PppContext *context); 00190 00191 void chapProcessPacket(PppContext *context, 00192 const PppPacket *packet, size_t length); 00193 00194 error_t chapProcessChallenge(PppContext *context, 00195 const ChapChallengePacket *challengePacket, size_t length); 00196 00197 error_t chapProcessResponse(PppContext *context, 00198 const ChapResponsePacket *responsePacket, size_t length); 00199 00200 error_t chapProcessSuccess(PppContext *context, 00201 const ChapSuccessPacket *successPacket, size_t length); 00202 00203 error_t chapProcessFailure(PppContext *context, 00204 const ChapFailurePacket *failurePacket, size_t length); 00205 00206 error_t chapSendChallenge(PppContext *context); 00207 error_t chapSendResponse(PppContext *context, const uint8_t *value); 00208 error_t chapSendSuccess(PppContext *context); 00209 error_t chapSendFailure(PppContext *context); 00210 00211 bool_t chapCheckPassword(PppContext *context, const char_t *password); 00212 00213 #endif 00214
Generated on Tue Jul 12 2022 17:10:12 by
1.7.2