Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pap.h Source File

pap.h

Go to the documentation of this file.
00001 /**
00002  * @file pap.h
00003  * @brief PAP (Password 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 _PAP_H
00030 #define _PAP_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "ppp/ppp.h"
00035 
00036 //PAP authentication support
00037 #ifndef PAP_SUPPORT
00038    #define PAP_SUPPORT ENABLED
00039 #elif (PAP_SUPPORT != ENABLED && PAP_SUPPORT != DISABLED)
00040    #error PAP_SUPPORT parameter is not valid
00041 #endif
00042 
00043 //Restart timer
00044 #ifndef PAP_RESTART_TIMER
00045    #define PAP_RESTART_TIMER 3000
00046 #elif (PAP_RESTART_TIMER < 1000)
00047    #error PAP_RESTART_TIMER parameter is not valid
00048 #endif
00049 
00050 //Maximum number of retransmissions for Authenticate-Request packets
00051 #ifndef PAP_MAX_REQUESTS
00052    #define PAP_MAX_REQUESTS 5
00053 #elif (PAP_MAX_REQUESTS < 1)
00054    #error PAP_MAX_REQUESTS parameter is not valid
00055 #endif
00056 
00057 
00058 /**
00059  * @brief PAP states
00060  **/
00061 
00062 typedef enum
00063 {
00064    PAP_STATE_0_INITIAL  = 0,
00065    PAP_STATE_1_STARTED  = 1,
00066    PAP_STATE_2_REQ_SENT = 2,
00067    PAP_STATE_3_REQ_RCVD = 3,
00068    PAP_STATE_4_ACK_SENT = 4,
00069    PAP_STATE_5_ACK_RCVD = 5,
00070    PAP_STATE_6_NAK_SENT = 6,
00071    PAP_STATE_7_NAK_RCVD = 7
00072 } PapState;
00073 
00074 
00075 /**
00076  * @brief Code field values
00077  **/
00078 
00079 typedef enum
00080 {
00081    PAP_CODE_AUTH_REQ = 1, ///<Authenticate-Request
00082    PAP_CODE_AUTH_ACK = 2, ///<Authenticate-Ack
00083    PAP_CODE_AUTH_NAK = 3  ///<Authenticate-Nak
00084 } PapCode;
00085 
00086 
00087 //CodeWarrior or Win32 compiler?
00088 #if defined(__CWCC__) || defined(_WIN32)
00089    #pragma pack(push, 1)
00090 #endif
00091 
00092 
00093 /**
00094  * @brief Authenticate-Request packet
00095  **/
00096 
00097 typedef __start_packed struct
00098 {
00099    uint8_t code;         //0
00100    uint8_t identifier;   //1
00101    uint16_t length;      //2-3
00102    uint8_t peerIdLength; //4
00103    uint8_t peerId[];     //5
00104 } __end_packed PapAuthReqPacket;
00105 
00106 
00107 /**
00108  * @brief Authenticate-Ack packet
00109  **/
00110 
00111 typedef __start_packed struct
00112 {
00113    uint8_t code;       //0
00114    uint8_t identifier; //1
00115    uint16_t length;    //2-3
00116    uint8_t msgLength;  //4
00117    uint8_t message[];  //5
00118 } __end_packed PapAuthAckPacket;
00119 
00120 
00121 /**
00122  * @brief Authenticate-Nak packet
00123  **/
00124 
00125 typedef __start_packed struct
00126 {
00127    uint8_t code;       //0
00128    uint8_t identifier; //1
00129    uint16_t length;    //2-3
00130    uint8_t msgLength;  //4
00131    uint8_t message[];  //5
00132 } __end_packed PapAuthNakPacket;
00133 
00134 
00135 //CodeWarrior or Win32 compiler?
00136 #if defined(__CWCC__) || defined(_WIN32)
00137    #pragma pack(pop)
00138 #endif
00139 
00140 
00141 /**
00142  * @brief PAP finite state machine
00143  **/
00144 
00145 typedef struct
00146 {
00147    uint_t localState;       ///<Local state
00148    uint_t peerState;        ///<Peer state
00149    uint8_t identifier;      ///<Identifier used to match requests and replies
00150    uint_t restartCounter;   ///<Restart counter
00151    systime_t timestamp;     ///<Timestamp to manage retransmissions
00152    const uint8_t *password; ///<Peer's password
00153    size_t passwordLen;      ///<Length of the password in bytes
00154 } PapFsm;
00155 
00156 
00157 //PAP related functions
00158 error_t papStartAuth(PppContext *context);
00159 error_t papAbortAuth(PppContext *context);
00160 
00161 void papTick(PppContext *context);
00162 
00163 void papProcessPacket(PppContext *context,
00164    const PppPacket *packet, size_t length);
00165 
00166 error_t papProcessAuthReq(PppContext *context,
00167    const PapAuthReqPacket *authReqPacket, size_t length);
00168 
00169 error_t papProcessAuthAck(PppContext *context,
00170    const PapAuthAckPacket *authAckPacket, size_t length);
00171 
00172 error_t papProcessAuthNak(PppContext *context,
00173    const PapAuthNakPacket *authNakPacket, size_t length);
00174 
00175 error_t papSendAuthReq(PppContext *context);
00176 error_t papSendAuthAck(PppContext *context, uint8_t identifier);
00177 error_t papSendAuthNak(PppContext *context, uint8_t identifier);
00178 
00179 bool_t papCheckPassword(PppContext *context, const char_t *password);
00180 
00181 #endif
00182