port fix from branch_1_1
[freeradius.git] / src / modules / rlm_eap / types / rlm_eap_psk / eap_psk_ssm.h
1 /* $Id$ */
2
3 /*
4  * eap_psk_ssm.h
5  *
6  * Implementation of the Server State Machine (SSM)
7  *
8  * 
9  * Copyright (C) France Télécom R&D (DR&D/MAPS/NSS)
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24  *
25  * Copyright 2006 The FreeRADIUS server project
26  *
27  */
28
29 #ifndef _EAP_PSK_SSM_H
30 #define _EAP_PSK_SSM_H
31
32 #include <freeradius-devel/ident.h>
33 RCSIDH(eap_psk_ssm_h, "$Id$")
34
35 #include "eap_psk.h"
36 #include "eap.h"
37
38 #if defined(__cplusplus)
39 extern "C"
40 {
41 #endif
42
43
44 // server states
45 typedef enum {
46   INIT,       // the server state machine starts in the INIT state
47   RANDSENT,
48   PCHANNEL              
49 }PSK_STATE;
50
51
52 // information which must be kept during the EAP-PSK session
53 typedef struct psk_session_t {
54   PSK_STATE state;                                       // state of the server state machine
55   unsigned char rand_s[PSK_RANDOM_NUMBER_SIZE];          // random number generated by the server
56   unsigned char *id_p;                                   // peer identity
57   unsigned char ak[PSK_AK_SIZE];                         // authentication key
58   unsigned char kdk[PSK_KDK_SIZE];                       // derivation key
59   unsigned char tek[PSK_TEK_SIZE];                       // TEK key
60   unsigned char msk[PSK_MSK_SIZE];                       // MSK key
61   unsigned char emsk[PSK_EMSK_SIZE];                     // EMSK key
62   unsigned int nbRetry;                                  // the current number of request re emissions
63   unsigned long int pChannelReplayCounter;               // the p-channel replay counter
64   unsigned char extType;                                // the extension type if evolved authentication is used, else 0
65   unsigned char authStatus;                             // the latest R flag sent by the server
66   unsigned char isSupportedExt;                          // 0 if the peer doesn't support the specified extension
67 }PSK_SESSION;
68
69
70 /** 
71  *@memo         this function is the entry point of the server state machine
72  *@param        conf, pointer to the current configuration of EAP-PSK
73  *@param        session, pointer to a structure which contains information session
74  *@param        recvPacket, pointer to a received EAP_PACKET
75  *@param        sentPacket, pointer to the EAP_PACKET to send
76  *@return       0 if an error has occured
77  */
78   int pskProcess(PSK_CONF *conf, PSK_SESSION *session, EAP_PACKET *recvPacket, EAP_PACKET *sentPacket);
79
80
81 /** 
82  *@memo         this function corresponds to the first state of the server state machine
83  *@param        conf, pointer to the current configuration of EAP-PSK
84  *@param        session, pointer to a structure which contains information session
85  *@param        sentPacket, pointer to the EAP_PACKET to send
86  *@return       0 if an error has occured
87  */
88   int pskInit(PSK_CONF *conf, PSK_SESSION *session, EAP_PACKET *sentPacket);
89
90
91 /** 
92  *@memo         this function corresponds to the second state of the server state machine
93  *@param        conf, pointer to the current configuration of EAP-PSK
94  *@param        session, pointer to a structure which contains information session
95  *@param        recvPacket, pointer to a received EAP_PACKET
96  *@param        sentPacket, pointer to the EAP_PACKET to send
97  *@return       0 if an error has occured
98  */
99   int pskRandSent(PSK_CONF *conf, PSK_SESSION *session, EAP_PACKET *recvPacket, EAP_PACKET *sentPacket);
100
101
102 /** 
103  *@memo         this function corresponds to the third state of the server state machine
104  *@param        conf, pointer to the current configuration of EAP-PSK
105  *@param        session, pointer to a structure which contains information session
106  *@param        recvPacket, pointer to a received EAP_PACKET
107  *@param        sentPacket, pointer to the EAP_PACKET to send
108  *@return       0 if no error has occured
109  */
110   int pskPChannel(PSK_CONF *conf, PSK_SESSION *session, EAP_PACKET *recvPacket, EAP_PACKET *sentPacket);                        
111
112
113 /** 
114  *@memo         this function contains the extension to EAP-PSK
115  *@param        conf, pointer to the current configuration of EAP-PSK
116  *@param        session, pointer to a structure which contains information session
117  *@param        receivedStatus, the latest R flag sent by the peer
118  *@param        dataIn, pointer to the received data
119  *@param        sizeDataIn, size of the received data
120  *@param        dataOut, pointer to a pointer that points data to send
121  *@param        sizeDataOut, pointer to the size of data to be sent (sizeDataOut must be at most equal to EXT_PAYLAOD_MAX_LEN)
122  *@return       0 if an error has occured
123  */
124   int pskExtension(PSK_CONF *conf, PSK_SESSION *session, unsigned short receivedStatus, void *dataIn, int sizeDataIn, void **dataOut, int *sizeDataOut);
125
126
127 /** 
128  *@memo         this function frees an existing session from memory
129  *@param        opaque, pointer to a structure which contains information session
130  */
131   void pskFreeSession(void *opaque);
132   
133
134
135 #if defined(__cplusplus)
136 }
137 #endif
138
139 #endif /*_EAP_PSK_SSM_H*/