Massive changes to clean up the EAP module, in preparation for
[freeradius.git] / src / modules / rlm_eap / eap.h
1 /*
2  * eap.h    Header file containing the interfaces for all EAP types.
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
21  */
22 #ifndef _EAP_H
23 #define _EAP_H
24
25 #include "autoconf.h"
26
27 #if HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
30
31 #if HAVE_NETINET_IN_H
32 #include <netinet/in.h>
33 #endif
34
35 #include <string.h>
36 #include <stdlib.h>
37
38 #include "radiusd.h"
39 #include "modules.h"
40
41 #include "rad_assert.h"
42
43 #define PW_EAP_REQUEST          1
44 #define PW_EAP_RESPONSE         2
45 #define PW_EAP_SUCCESS          3
46 #define PW_EAP_FAILURE          4
47 #define PW_EAP_MAX_CODES        4
48
49 #define PW_EAP_IDENTITY         1
50 #define PW_EAP_NOTIFICATION     2
51 #define PW_EAP_NAK              3
52 #define PW_EAP_MD5              4
53 #define PW_EAP_OTP              5
54 #define PW_EAP_GTC              6
55 #define PW_EAP_TLS              13
56 #define PW_EAP_LEAP             17
57 #define PW_EAP_MAX_TYPES        17
58
59 #define EAP_HEADER_LEN          4
60
61 /*
62  * EAP-Type specific data.
63  */
64 typedef struct eaptype_t {
65         unsigned char   type;
66         unsigned int    length;
67         unsigned char   *data;
68 } eaptype_t;
69
70 /*
71  * Structure to hold EAP data.
72  *
73  * length = code + id + length + type + type.data
74  *        =  1   +  1 +   2    +  1   +  X
75  */
76 typedef struct eap_packet {
77         unsigned char   code;
78         unsigned char   id;
79         unsigned int    length;
80         eaptype_t       type;
81
82         unsigned char   *packet;
83 } EAP_PACKET;
84
85 /*
86  * EAP_DS contains all the received/sending information
87  * response = Received EAP packet
88  * request = Sending EAP packet
89  *
90  * Note: We are authentication server, 
91  *  we get ONLY EAP-Responses and 
92  *  we send EAP-Request/EAP-success/EAP-failure
93  */
94 typedef struct eap_ds {
95         EAP_PACKET      *response;
96         EAP_PACKET      *request;
97         int             set_request_id;
98 } EAP_DS;
99
100 /*
101  * Currently there are only 2 types
102  * of operations defined, 
103  * apart from attach & detach for each EAP-Type.
104  */
105 typedef enum operation_t {
106         INITIATE = 0,
107         AUTHORIZE,
108         AUTHENTICATE
109 } operation_t;
110
111
112 /*
113  * EAP_HANDLER is the interface for any EAP-Type.
114  * Each handler contains information for one specific EAP-Type.
115  * This way we don't need to change any interfaces in future.
116  * It is also a list of EAP-request handlers waiting for EAP-response
117  * eap_id = copy of the eap packet we sent to the 
118  *
119  * next = pointer to next
120  * state = state attribute from the reply we sent
121  * state_len = length of data in the state attribute.
122  * src_ipaddr = client which sent us the RADIUS request containing
123  *              this EAP conversation.
124  * eap_id = copy of EAP id we sent to the client.
125  * timestamp  = timestamp when this handler was last used.
126  * identity = Identity, as obtained, from EAP-Identity response.
127  * username = as obtained in Radius request, It might differ from identity.
128  * request = RADIUS request data structure
129  * prev_eapds = Previous EAP request, for which eap_ds contains the response.
130  * eap_ds   = Current EAP response.
131  * opaque   = EAP-Type holds some data that corresponds to the current
132  *              EAP-request/response
133  * free_opaque = To release memory held by opaque, 
134  *              when this handler is timedout & needs to be deleted.
135  *              It is the responsibility of the specific EAP-TYPE 
136  *              to avoid any memory leaks in opaque
137  *              Hence this pointer should be provided by the EAP-Type
138  *              if opaque is not NULL
139  * status   = finished/onhold/..
140  */
141 #define EAP_STATE_LEN (AUTH_VECTOR_LEN)
142 typedef struct _eap_handler {
143         struct _eap_handler *next;
144
145         uint8_t         state[EAP_STATE_LEN];
146         uint32_t        src_ipaddr;
147         int             eap_id;
148
149         time_t          timestamp;
150
151         VALUE_PAIR      *username; /* SHOULD get rid of this! */
152         REQUEST         *request;
153
154         char            *identity; /* user identity? Huh? */
155
156         EAP_DS          *prev_eapds;
157         EAP_DS          *eap_ds;
158
159         void            *opaque;
160         void            (*free_opaque)(void *opaque);
161
162         int             status;
163
164         int             stage;
165 } EAP_HANDLER;
166
167 /* 
168  * Interface to call EAP sub mdoules
169  */
170 typedef struct eap_type_t {
171         const   char *name;
172         int     (*attach)(CONF_SECTION *conf, void **type_data);
173         int     (*initiate)(void *type_data, EAP_HANDLER *handler);
174         int     (*authorize)(void *type_data, EAP_HANDLER *handler);
175         int     (*authenticate)(void *type_data, EAP_HANDLER *handler);
176         int     (*detach)(void *type_data);
177 } EAP_TYPE;
178
179 #endif /*_EAP_H*/