Code Cleanup and new header inclusion.
[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 "conffile.h"
26 #include "libradius.h"
27 #include "radiusd.h"
28
29 #if HAVE_NETINET_IN_H
30 #include <netinet/in.h>
31 #endif
32
33 #include <string.h>
34
35 #define PW_EAP_REQUEST          1
36 #define PW_EAP_RESPONSE         2
37 #define PW_EAP_SUCCESS          3
38 #define PW_EAP_FAILURE          4
39 #define PW_EAP_MAX_CODES        4
40
41 #define PW_EAP_IDENTITY         1
42 #define PW_EAP_NOTIFICATION     2
43 #define PW_EAP_NAK              3
44 #define PW_EAP_MD5              4
45 #define PW_EAP_OTP              5
46 #define PW_EAP_GTC              6
47 #define PW_EAP_TLS              13
48 #define PW_EAP_MAX_TYPES        13
49
50 #define EAP_HEADER_LEN          4
51
52 /*
53  * EAP-Type specific data.
54  */
55 typedef struct eaptype_t {
56         unsigned char   type;
57         unsigned int    length;
58         unsigned char   *data;
59 } eaptype_t;
60
61 /*
62  * Structure to hold EAP data.
63  *
64  * length = code + id + length + type + type.data
65  *        =  1   +  1 +   2    +  1   +  X
66  */
67 typedef struct eap_packet {
68         unsigned char   code;
69         unsigned char   id;
70         unsigned int    length;
71         eaptype_t       type;
72
73         unsigned char   *packet;
74 } EAP_PACKET;
75
76 /*
77  * EAP_DS contains all the received/sending information
78  * response = Received EAP packet
79  * request = Sending EAP packet
80  *
81  * Note: We are authentication server, 
82  *  we get ONLY EAP-Responses and 
83  *  we send EAP-Request/EAP-success/EAP-failure
84  */
85 typedef struct eap_ds {
86         EAP_PACKET      *response;
87         EAP_PACKET      *request;
88 } EAP_DS;
89
90 /*
91  * EAP_HANDLER is the interface for any EAP-Type.
92  * Each handler contains information for one specific EAP-Type.
93  * This way we don't need to change any interfaces in future.
94  * It is also a list of EAP-request handlers waiting for EAP-response
95  *
96  * id = Length + Request-ID + State + (NAS-IP-Address|NAS-Identifier)
97  * identity = Identity, as obtained, from EAP-Identity response.
98  * username = as obtained in Radius request, It might differ from identity.
99  * configured = List of configured values for this user.
100  * prev_eapds = Previous EAP request, for which eap_ds contains the response.
101  * eap_ds   = Current EAP response.
102  * opaque   = EAP-Type holds some data that corresponds to the current
103  *              EAP-request/response
104  * free_opaque = To release memory held by opaque, 
105  *              when this handler is timedout & needs to be deleted.
106  *              It is the responsibility of the specific EAP-TYPE 
107  *              to avoid any memory leaks in opaque
108  *              Hence this pointer should be provided by the EAP-Type
109  *              if opaque is not NULL
110  * timestamp  = timestamp when this handler is created.
111  * status   = finished/onhold/..
112  */
113 typedef struct _eap_handler {
114         unsigned char   *id;
115
116         VALUE_PAIR      *username;
117         VALUE_PAIR      *configured;
118
119         char    *identity;
120
121         EAP_DS  *prev_eapds;
122         EAP_DS  *eap_ds;
123
124         void    *opaque;
125         void    (*free_opaque)(void **opaque);
126
127         time_t  timestamp;
128         int     status;
129
130         struct _eap_handler *next;
131 } EAP_HANDLER;
132
133 /* 
134  * Interface to call EAP sub mdoules
135  */
136 typedef struct eap_type_t {
137         const   char *name;
138         int     (*attach)(CONF_SECTION *conf, void **type_arg);
139         int     (*initiate)(void *type_arg, EAP_HANDLER *handler);
140         int     (*authenticate)(void *type_arg, EAP_HANDLER *handler);
141         int     (*detach)(void **type_arg);
142 } EAP_TYPE;
143
144 #endif /*_EAP_H*/