Webserver+3d print
cyclone_tcp/ppp/chap.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file chap.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief CHAP (Challenge Handshake Authentication Protocol) |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _CHAP_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _CHAP_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "ppp/ppp.h" |
Sergunb | 0:8918a71cdbe9 | 35 | |
Sergunb | 0:8918a71cdbe9 | 36 | //CHAP authentication support |
Sergunb | 0:8918a71cdbe9 | 37 | #ifndef CHAP_SUPPORT |
Sergunb | 0:8918a71cdbe9 | 38 | #define CHAP_SUPPORT DISABLED |
Sergunb | 0:8918a71cdbe9 | 39 | #elif (CHAP_SUPPORT != ENABLED && CHAP_SUPPORT != DISABLED) |
Sergunb | 0:8918a71cdbe9 | 40 | #error CHAP_SUPPORT parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 41 | #endif |
Sergunb | 0:8918a71cdbe9 | 42 | |
Sergunb | 0:8918a71cdbe9 | 43 | //Restart timer |
Sergunb | 0:8918a71cdbe9 | 44 | #ifndef CHAP_RESTART_TIMER |
Sergunb | 0:8918a71cdbe9 | 45 | #define CHAP_RESTART_TIMER 3000 |
Sergunb | 0:8918a71cdbe9 | 46 | #elif (CHAP_RESTART_TIMER < 1000) |
Sergunb | 0:8918a71cdbe9 | 47 | #error CHAP_RESTART_TIMER parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 48 | #endif |
Sergunb | 0:8918a71cdbe9 | 49 | |
Sergunb | 0:8918a71cdbe9 | 50 | //Maximum number of retransmissions for Challenge packets |
Sergunb | 0:8918a71cdbe9 | 51 | #ifndef CHAP_MAX_CHALLENGES |
Sergunb | 0:8918a71cdbe9 | 52 | #define CHAP_MAX_CHALLENGES 5 |
Sergunb | 0:8918a71cdbe9 | 53 | #elif (CHAP_MAX_CHALLENGES < 1) |
Sergunb | 0:8918a71cdbe9 | 54 | #error CHAP_MAX_CHALLENGES parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 55 | #endif |
Sergunb | 0:8918a71cdbe9 | 56 | |
Sergunb | 0:8918a71cdbe9 | 57 | |
Sergunb | 0:8918a71cdbe9 | 58 | /** |
Sergunb | 0:8918a71cdbe9 | 59 | * @brief CHAP states |
Sergunb | 0:8918a71cdbe9 | 60 | **/ |
Sergunb | 0:8918a71cdbe9 | 61 | |
Sergunb | 0:8918a71cdbe9 | 62 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 63 | { |
Sergunb | 0:8918a71cdbe9 | 64 | CHAP_STATE_0_INITIAL = 0, |
Sergunb | 0:8918a71cdbe9 | 65 | CHAP_STATE_1_STARTED = 1, |
Sergunb | 0:8918a71cdbe9 | 66 | CHAP_STATE_2_CHALLENGE_SENT = 2, |
Sergunb | 0:8918a71cdbe9 | 67 | CHAP_STATE_3_CHALLENGE_RCVD = 3, |
Sergunb | 0:8918a71cdbe9 | 68 | CHAP_STATE_4_RESPONSE_SENT = 4, |
Sergunb | 0:8918a71cdbe9 | 69 | CHAP_STATE_5_RESPONSE_RCVD = 5, |
Sergunb | 0:8918a71cdbe9 | 70 | CHAP_STATE_6_SUCCESS_SENT = 6, |
Sergunb | 0:8918a71cdbe9 | 71 | CHAP_STATE_7_SUCCESS_RCVD = 7, |
Sergunb | 0:8918a71cdbe9 | 72 | CHAP_STATE_8_FAILURE_SENT = 8, |
Sergunb | 0:8918a71cdbe9 | 73 | CHAP_STATE_9_FAILURE_RCVD = 9 |
Sergunb | 0:8918a71cdbe9 | 74 | } ChapState; |
Sergunb | 0:8918a71cdbe9 | 75 | |
Sergunb | 0:8918a71cdbe9 | 76 | |
Sergunb | 0:8918a71cdbe9 | 77 | /** |
Sergunb | 0:8918a71cdbe9 | 78 | * @brief Code field values |
Sergunb | 0:8918a71cdbe9 | 79 | **/ |
Sergunb | 0:8918a71cdbe9 | 80 | |
Sergunb | 0:8918a71cdbe9 | 81 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 82 | { |
Sergunb | 0:8918a71cdbe9 | 83 | CHAP_CODE_CHALLENGE = 1, ///<Challenge |
Sergunb | 0:8918a71cdbe9 | 84 | CHAP_CODE_RESPONSE = 2, ///<Response |
Sergunb | 0:8918a71cdbe9 | 85 | CHAP_CODE_SUCCESS = 3, ///<Success |
Sergunb | 0:8918a71cdbe9 | 86 | CHAP_CODE_FAILURE = 4 ///<Failure |
Sergunb | 0:8918a71cdbe9 | 87 | } ChapCode; |
Sergunb | 0:8918a71cdbe9 | 88 | |
Sergunb | 0:8918a71cdbe9 | 89 | |
Sergunb | 0:8918a71cdbe9 | 90 | /** |
Sergunb | 0:8918a71cdbe9 | 91 | * @brief CHAP algorithm identifiers |
Sergunb | 0:8918a71cdbe9 | 92 | **/ |
Sergunb | 0:8918a71cdbe9 | 93 | |
Sergunb | 0:8918a71cdbe9 | 94 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 95 | { |
Sergunb | 0:8918a71cdbe9 | 96 | CHAP_ALGO_ID_CHAP_MD5 = 5, //CHAP with MD5 |
Sergunb | 0:8918a71cdbe9 | 97 | CHAP_ALGO_ID_MS_CHAP = 128, //MS-CHAP |
Sergunb | 0:8918a71cdbe9 | 98 | CHAP_ALGO_ID_MS_CHAP_V2 = 129 //MS-CHAP-2 |
Sergunb | 0:8918a71cdbe9 | 99 | } ChapAlgoId; |
Sergunb | 0:8918a71cdbe9 | 100 | |
Sergunb | 0:8918a71cdbe9 | 101 | |
Sergunb | 0:8918a71cdbe9 | 102 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 103 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 104 | #pragma pack(push, 1) |
Sergunb | 0:8918a71cdbe9 | 105 | #endif |
Sergunb | 0:8918a71cdbe9 | 106 | |
Sergunb | 0:8918a71cdbe9 | 107 | |
Sergunb | 0:8918a71cdbe9 | 108 | /** |
Sergunb | 0:8918a71cdbe9 | 109 | * @brief Challenge packet |
Sergunb | 0:8918a71cdbe9 | 110 | **/ |
Sergunb | 0:8918a71cdbe9 | 111 | |
Sergunb | 0:8918a71cdbe9 | 112 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 113 | { |
Sergunb | 0:8918a71cdbe9 | 114 | uint8_t code; //0 |
Sergunb | 0:8918a71cdbe9 | 115 | uint8_t identifier; //1 |
Sergunb | 0:8918a71cdbe9 | 116 | uint16_t length; //2-3 |
Sergunb | 0:8918a71cdbe9 | 117 | uint8_t valueSize; //4 |
Sergunb | 0:8918a71cdbe9 | 118 | uint8_t value[]; //5 |
Sergunb | 0:8918a71cdbe9 | 119 | } __end_packed ChapChallengePacket; |
Sergunb | 0:8918a71cdbe9 | 120 | |
Sergunb | 0:8918a71cdbe9 | 121 | |
Sergunb | 0:8918a71cdbe9 | 122 | /** |
Sergunb | 0:8918a71cdbe9 | 123 | * @brief Response packet |
Sergunb | 0:8918a71cdbe9 | 124 | **/ |
Sergunb | 0:8918a71cdbe9 | 125 | |
Sergunb | 0:8918a71cdbe9 | 126 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 127 | { |
Sergunb | 0:8918a71cdbe9 | 128 | uint8_t code; //0 |
Sergunb | 0:8918a71cdbe9 | 129 | uint8_t identifier; //1 |
Sergunb | 0:8918a71cdbe9 | 130 | uint16_t length; //2-3 |
Sergunb | 0:8918a71cdbe9 | 131 | uint8_t valueSize; //4 |
Sergunb | 0:8918a71cdbe9 | 132 | uint8_t value[]; //5 |
Sergunb | 0:8918a71cdbe9 | 133 | } __end_packed ChapResponsePacket; |
Sergunb | 0:8918a71cdbe9 | 134 | |
Sergunb | 0:8918a71cdbe9 | 135 | |
Sergunb | 0:8918a71cdbe9 | 136 | /** |
Sergunb | 0:8918a71cdbe9 | 137 | * @brief Success packet |
Sergunb | 0:8918a71cdbe9 | 138 | **/ |
Sergunb | 0:8918a71cdbe9 | 139 | |
Sergunb | 0:8918a71cdbe9 | 140 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 141 | { |
Sergunb | 0:8918a71cdbe9 | 142 | uint8_t code; //0 |
Sergunb | 0:8918a71cdbe9 | 143 | uint8_t identifier; //1 |
Sergunb | 0:8918a71cdbe9 | 144 | uint16_t length; //2-3 |
Sergunb | 0:8918a71cdbe9 | 145 | uint8_t message[]; //4 |
Sergunb | 0:8918a71cdbe9 | 146 | } __end_packed ChapSuccessPacket; |
Sergunb | 0:8918a71cdbe9 | 147 | |
Sergunb | 0:8918a71cdbe9 | 148 | |
Sergunb | 0:8918a71cdbe9 | 149 | /** |
Sergunb | 0:8918a71cdbe9 | 150 | * @brief Failure packet |
Sergunb | 0:8918a71cdbe9 | 151 | **/ |
Sergunb | 0:8918a71cdbe9 | 152 | |
Sergunb | 0:8918a71cdbe9 | 153 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 154 | { |
Sergunb | 0:8918a71cdbe9 | 155 | uint8_t code; //0 |
Sergunb | 0:8918a71cdbe9 | 156 | uint8_t identifier; //1 |
Sergunb | 0:8918a71cdbe9 | 157 | uint16_t length; //2-3 |
Sergunb | 0:8918a71cdbe9 | 158 | uint8_t message[]; //4 |
Sergunb | 0:8918a71cdbe9 | 159 | } __end_packed ChapFailurePacket; |
Sergunb | 0:8918a71cdbe9 | 160 | |
Sergunb | 0:8918a71cdbe9 | 161 | |
Sergunb | 0:8918a71cdbe9 | 162 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 163 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 164 | #pragma pack(pop) |
Sergunb | 0:8918a71cdbe9 | 165 | #endif |
Sergunb | 0:8918a71cdbe9 | 166 | |
Sergunb | 0:8918a71cdbe9 | 167 | |
Sergunb | 0:8918a71cdbe9 | 168 | /** |
Sergunb | 0:8918a71cdbe9 | 169 | * @brief CHAP finite state machine |
Sergunb | 0:8918a71cdbe9 | 170 | **/ |
Sergunb | 0:8918a71cdbe9 | 171 | |
Sergunb | 0:8918a71cdbe9 | 172 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 173 | { |
Sergunb | 0:8918a71cdbe9 | 174 | uint_t localState; ///<Local state |
Sergunb | 0:8918a71cdbe9 | 175 | uint8_t localIdentifier; ///<Identifier used to match requests and replies |
Sergunb | 0:8918a71cdbe9 | 176 | uint_t peerState; ///<Peer state |
Sergunb | 0:8918a71cdbe9 | 177 | uint8_t peerIdentifier; ///<Identifier used to match requests and replies |
Sergunb | 0:8918a71cdbe9 | 178 | uint_t restartCounter; ///<Restart counter |
Sergunb | 0:8918a71cdbe9 | 179 | systime_t timestamp; ///<Timestamp to manage retransmissions |
Sergunb | 0:8918a71cdbe9 | 180 | uint8_t challenge[16]; ///<Challenge value sent to the peer |
Sergunb | 0:8918a71cdbe9 | 181 | const uint8_t *response; ///<Response value from the peer |
Sergunb | 0:8918a71cdbe9 | 182 | } ChapFsm; |
Sergunb | 0:8918a71cdbe9 | 183 | |
Sergunb | 0:8918a71cdbe9 | 184 | |
Sergunb | 0:8918a71cdbe9 | 185 | //CHAP related functions |
Sergunb | 0:8918a71cdbe9 | 186 | error_t chapStartAuth(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 187 | error_t chapAbortAuth(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 188 | |
Sergunb | 0:8918a71cdbe9 | 189 | void chapTick(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 190 | |
Sergunb | 0:8918a71cdbe9 | 191 | void chapProcessPacket(PppContext *context, |
Sergunb | 0:8918a71cdbe9 | 192 | const PppPacket *packet, size_t length); |
Sergunb | 0:8918a71cdbe9 | 193 | |
Sergunb | 0:8918a71cdbe9 | 194 | error_t chapProcessChallenge(PppContext *context, |
Sergunb | 0:8918a71cdbe9 | 195 | const ChapChallengePacket *challengePacket, size_t length); |
Sergunb | 0:8918a71cdbe9 | 196 | |
Sergunb | 0:8918a71cdbe9 | 197 | error_t chapProcessResponse(PppContext *context, |
Sergunb | 0:8918a71cdbe9 | 198 | const ChapResponsePacket *responsePacket, size_t length); |
Sergunb | 0:8918a71cdbe9 | 199 | |
Sergunb | 0:8918a71cdbe9 | 200 | error_t chapProcessSuccess(PppContext *context, |
Sergunb | 0:8918a71cdbe9 | 201 | const ChapSuccessPacket *successPacket, size_t length); |
Sergunb | 0:8918a71cdbe9 | 202 | |
Sergunb | 0:8918a71cdbe9 | 203 | error_t chapProcessFailure(PppContext *context, |
Sergunb | 0:8918a71cdbe9 | 204 | const ChapFailurePacket *failurePacket, size_t length); |
Sergunb | 0:8918a71cdbe9 | 205 | |
Sergunb | 0:8918a71cdbe9 | 206 | error_t chapSendChallenge(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 207 | error_t chapSendResponse(PppContext *context, const uint8_t *value); |
Sergunb | 0:8918a71cdbe9 | 208 | error_t chapSendSuccess(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 209 | error_t chapSendFailure(PppContext *context); |
Sergunb | 0:8918a71cdbe9 | 210 | |
Sergunb | 0:8918a71cdbe9 | 211 | bool_t chapCheckPassword(PppContext *context, const char_t *password); |
Sergunb | 0:8918a71cdbe9 | 212 | |
Sergunb | 0:8918a71cdbe9 | 213 | #endif |
Sergunb | 0:8918a71cdbe9 | 214 |