64c24ac4951989944c8fbc93397a5e476141e544
[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  * Copyright 2003  Alan DeKok <aland@freeradius.org>
22  */
23 #ifndef _EAP_H
24 #define _EAP_H
25
26 #include <freeradius-devel/autoconf.h>
27
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31
32 #ifdef HAVE_NETINET_IN_H
33 #include <netinet/in.h>
34 #endif
35
36 #include <string.h>
37 #include <stdlib.h>
38
39 #include <freeradius-devel/radiusd.h>
40 #include <freeradius-devel/modules.h>
41
42 #include <freeradius-devel/rad_assert.h>
43
44 #include "eap_types.h"
45
46 /*
47  * EAP_DS contains all the received/sending information
48  * response = Received EAP packet
49  * request = Sending EAP packet
50  *
51  * Note: We are authentication server,
52  *  we get ONLY EAP-Responses and
53  *  we send EAP-Request/EAP-success/EAP-failure
54  */
55 typedef struct eap_ds {
56         EAP_PACKET      *response;
57         EAP_PACKET      *request;
58         int             set_request_id;
59 } EAP_DS;
60
61 /*
62  * Currently there are only 2 types
63  * of operations defined,
64  * apart from attach & detach for each EAP-Type.
65  */
66 typedef enum operation_t {
67         INITIATE = 0,
68         AUTHORIZE,
69         AUTHENTICATE
70 } operation_t;
71
72
73 /*
74  * EAP_HANDLER is the interface for any EAP-Type.
75  * Each handler contains information for one specific EAP-Type.
76  * This way we don't need to change any interfaces in future.
77  * It is also a list of EAP-request handlers waiting for EAP-response
78  * eap_id = copy of the eap packet we sent to the
79  *
80  * next = pointer to next
81  * state = state attribute from the reply we sent
82  * state_len = length of data in the state attribute.
83  * src_ipaddr = client which sent us the RADIUS request containing
84  *              this EAP conversation.
85  * eap_id = copy of EAP id we sent to the client.
86  * timestamp  = timestamp when this handler was last used.
87  * identity = Identity, as obtained, from EAP-Identity response.
88  * request = RADIUS request data structure
89  * prev_eapds = Previous EAP request, for which eap_ds contains the response.
90  * eap_ds   = Current EAP response.
91  * opaque   = EAP-Type holds some data that corresponds to the current
92  *              EAP-request/response
93  * free_opaque = To release memory held by opaque,
94  *              when this handler is timedout & needs to be deleted.
95  *              It is the responsibility of the specific EAP-TYPE
96  *              to avoid any memory leaks in opaque
97  *              Hence this pointer should be provided by the EAP-Type
98  *              if opaque is not NULL
99  * status   = finished/onhold/..
100  */
101 #define EAP_STATE_LEN (AUTH_VECTOR_LEN)
102 typedef struct _eap_handler {
103         struct _eap_handler *prev, *next;
104         uint8_t         state[EAP_STATE_LEN];
105         lrad_ipaddr_t   src_ipaddr;
106         unsigned int    eap_id;
107         unsigned int    eap_type;
108
109         time_t          timestamp;
110
111         REQUEST         *request;
112
113         char            *identity; /* User name from EAP-Identity */
114
115         EAP_DS          *prev_eapds;
116         EAP_DS          *eap_ds;
117
118         void            *opaque;
119         void            (*free_opaque)(void *opaque);
120
121         int             status;
122
123         int             stage;
124 } EAP_HANDLER;
125
126 /*
127  * Interface to call EAP sub mdoules
128  */
129 typedef struct eap_type_t {
130         const   char *name;
131         int     (*attach)(CONF_SECTION *conf, void **type_data);
132         int     (*initiate)(void *type_data, EAP_HANDLER *handler);
133         int     (*authorize)(void *type_data, EAP_HANDLER *handler);
134         int     (*authenticate)(void *type_data, EAP_HANDLER *handler);
135         int     (*detach)(void *type_data);
136 } EAP_TYPE;
137
138 #define REQUEST_DATA_EAP_HANDLER         (1)
139 #define REQUEST_DATA_EAP_TUNNEL_CALLBACK PW_EAP_MESSAGE
140 #define REQUEST_DATA_EAP_MSCHAP_TUNNEL_CALLBACK ((PW_EAP_MESSAGE << 16) | PW_EAP_MSCHAPV2)
141 #define RAD_REQUEST_OPTION_PROXY_EAP    (1 << 16)
142
143 /*
144  *      This is for tunneled callbacks
145  */
146 typedef int (*eap_tunnel_callback_t)(EAP_HANDLER *handler, void *tls_session);
147 typedef struct eap_tunnel_data_t {
148   void                  *tls_session;
149   eap_tunnel_callback_t callback;
150 } eap_tunnel_data_t;
151
152 #endif /*_EAP_H*/