radius.h

Go to the documentation of this file.
00001 
00016 #ifndef RADIUS_H
00017 #define RADIUS_H
00018 
00019 /* RFC 2865 - RADIUS */
00020 
00021 #ifdef _MSC_VER
00022 #pragma pack(push, 1)
00023 #endif /* _MSC_VER */
00024 
00025 struct radius_hdr {
00026         u8 code;
00027         u8 identifier;
00028         u16 length; /* including this header */
00029         u8 authenticator[16];
00030         /* followed by length-20 octets of attributes */
00031 } STRUCT_PACKED;
00032 
00033 enum { RADIUS_CODE_ACCESS_REQUEST = 1,
00034        RADIUS_CODE_ACCESS_ACCEPT = 2,
00035        RADIUS_CODE_ACCESS_REJECT = 3,
00036        RADIUS_CODE_ACCOUNTING_REQUEST = 4,
00037        RADIUS_CODE_ACCOUNTING_RESPONSE = 5,
00038        RADIUS_CODE_ACCESS_CHALLENGE = 11,
00039        RADIUS_CODE_STATUS_SERVER = 12,
00040        RADIUS_CODE_STATUS_CLIENT = 13,
00041        RADIUS_CODE_RESERVED = 255
00042 };
00043 
00044 struct radius_attr_hdr {
00045         u8 type;
00046         u8 length; /* including this header */
00047         /* followed by length-2 octets of attribute value */
00048 } STRUCT_PACKED;
00049 
00050 #define RADIUS_MAX_ATTR_LEN (255 - sizeof(struct radius_attr_hdr))
00051 
00052 enum { RADIUS_ATTR_USER_NAME = 1,
00053        RADIUS_ATTR_USER_PASSWORD = 2,
00054        RADIUS_ATTR_NAS_IP_ADDRESS = 4,
00055        RADIUS_ATTR_NAS_PORT = 5,
00056        RADIUS_ATTR_FRAMED_MTU = 12,
00057        RADIUS_ATTR_REPLY_MESSAGE = 18,
00058        RADIUS_ATTR_STATE = 24,
00059        RADIUS_ATTR_CLASS = 25,
00060        RADIUS_ATTR_VENDOR_SPECIFIC = 26,
00061        RADIUS_ATTR_SESSION_TIMEOUT = 27,
00062        RADIUS_ATTR_IDLE_TIMEOUT = 28,
00063        RADIUS_ATTR_TERMINATION_ACTION = 29,
00064        RADIUS_ATTR_CALLED_STATION_ID = 30,
00065        RADIUS_ATTR_CALLING_STATION_ID = 31,
00066        RADIUS_ATTR_NAS_IDENTIFIER = 32,
00067        RADIUS_ATTR_PROXY_STATE = 33,
00068        RADIUS_ATTR_ACCT_STATUS_TYPE = 40,
00069        RADIUS_ATTR_ACCT_DELAY_TIME = 41,
00070        RADIUS_ATTR_ACCT_INPUT_OCTETS = 42,
00071        RADIUS_ATTR_ACCT_OUTPUT_OCTETS = 43,
00072        RADIUS_ATTR_ACCT_SESSION_ID = 44,
00073        RADIUS_ATTR_ACCT_AUTHENTIC = 45,
00074        RADIUS_ATTR_ACCT_SESSION_TIME = 46,
00075        RADIUS_ATTR_ACCT_INPUT_PACKETS = 47,
00076        RADIUS_ATTR_ACCT_OUTPUT_PACKETS = 48,
00077        RADIUS_ATTR_ACCT_TERMINATE_CAUSE = 49,
00078        RADIUS_ATTR_ACCT_MULTI_SESSION_ID = 50,
00079        RADIUS_ATTR_ACCT_LINK_COUNT = 51,
00080        RADIUS_ATTR_ACCT_INPUT_GIGAWORDS = 52,
00081        RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS = 53,
00082        RADIUS_ATTR_EVENT_TIMESTAMP = 55,
00083        RADIUS_ATTR_NAS_PORT_TYPE = 61,
00084        RADIUS_ATTR_TUNNEL_TYPE = 64,
00085        RADIUS_ATTR_TUNNEL_MEDIUM_TYPE = 65,
00086        RADIUS_ATTR_CONNECT_INFO = 77,
00087        RADIUS_ATTR_EAP_MESSAGE = 79,
00088        RADIUS_ATTR_MESSAGE_AUTHENTICATOR = 80,
00089        RADIUS_ATTR_TUNNEL_PRIVATE_GROUP_ID = 81,
00090        RADIUS_ATTR_ACCT_INTERIM_INTERVAL = 85,
00091        RADIUS_ATTR_CHARGEABLE_USER_IDENTITY = 89,
00092        RADIUS_ATTR_NAS_IPV6_ADDRESS = 95
00093 };
00094 
00095 
00096 /* Termination-Action */
00097 #define RADIUS_TERMINATION_ACTION_DEFAULT 0
00098 #define RADIUS_TERMINATION_ACTION_RADIUS_REQUEST 1
00099 
00100 /* NAS-Port-Type */
00101 #define RADIUS_NAS_PORT_TYPE_IEEE_802_11 19
00102 
00103 /* Acct-Status-Type */
00104 #define RADIUS_ACCT_STATUS_TYPE_START 1
00105 #define RADIUS_ACCT_STATUS_TYPE_STOP 2
00106 #define RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE 3
00107 #define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON 7
00108 #define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF 8
00109 
00110 /* Acct-Authentic */
00111 #define RADIUS_ACCT_AUTHENTIC_RADIUS 1
00112 #define RADIUS_ACCT_AUTHENTIC_LOCAL 2
00113 #define RADIUS_ACCT_AUTHENTIC_REMOTE 3
00114 
00115 /* Acct-Terminate-Cause */
00116 #define RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST 1
00117 #define RADIUS_ACCT_TERMINATE_CAUSE_LOST_CARRIER 2
00118 #define RADIUS_ACCT_TERMINATE_CAUSE_LOST_SERVICE 3
00119 #define RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT 4
00120 #define RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT 5
00121 #define RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_RESET 6
00122 #define RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_REBOOT 7
00123 #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_ERROR 8
00124 #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_ERROR 9
00125 #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_REQUEST 10
00126 #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_REBOOT 11
00127 #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_UNNEEDED 12
00128 #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_PREEMPTED 13
00129 #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_SUSPENDED 14
00130 #define RADIUS_ACCT_TERMINATE_CAUSE_SERVICE_UNAVAILABLE 15
00131 #define RADIUS_ACCT_TERMINATE_CAUSE_CALLBACK 16
00132 #define RADIUS_ACCT_TERMINATE_CAUSE_USER_ERROR 17
00133 #define RADIUS_ACCT_TERMINATE_CAUSE_HOST_REQUEST 18
00134 
00135 #define RADIUS_TUNNEL_TAGS 32
00136 
00137 /* Tunnel-Type */
00138 #define RADIUS_TUNNEL_TYPE_PPTP 1
00139 #define RADIUS_TUNNEL_TYPE_L2TP 3
00140 #define RADIUS_TUNNEL_TYPE_IPIP 7
00141 #define RADIUS_TUNNEL_TYPE_GRE 10
00142 #define RADIUS_TUNNEL_TYPE_VLAN 13
00143 
00144 /* Tunnel-Medium-Type */
00145 #define RADIUS_TUNNEL_MEDIUM_TYPE_IPV4 1
00146 #define RADIUS_TUNNEL_MEDIUM_TYPE_IPV6 2
00147 #define RADIUS_TUNNEL_MEDIUM_TYPE_802 6
00148 
00149 
00150 struct radius_attr_vendor {
00151         u8 vendor_type;
00152         u8 vendor_length;
00153 } STRUCT_PACKED;
00154 
00155 #define RADIUS_VENDOR_ID_CISCO 9
00156 #define RADIUS_CISCO_AV_PAIR 1
00157 
00158 /* RFC 2548 - Microsoft Vendor-specific RADIUS Attributes */
00159 #define RADIUS_VENDOR_ID_MICROSOFT 311
00160 
00161 enum { RADIUS_VENDOR_ATTR_MS_MPPE_SEND_KEY = 16,
00162        RADIUS_VENDOR_ATTR_MS_MPPE_RECV_KEY = 17
00163 };
00164 
00165 #ifdef _MSC_VER
00166 #pragma pack(pop)
00167 #endif /* _MSC_VER */
00168 
00169 struct radius_ms_mppe_keys {
00170         u8 *send;
00171         size_t send_len;
00172         u8 *recv;
00173         size_t recv_len;
00174 };
00175 
00176 
00177 /* RADIUS message structure for new and parsed messages */
00178 struct radius_msg {
00179         unsigned char *buf;
00180         size_t buf_size; /* total size allocated for buf */
00181         size_t buf_used; /* bytes used in buf */
00182 
00183         struct radius_hdr *hdr;
00184 
00185         size_t *attr_pos; /* array of indexes to attributes (number of bytes
00186                            * from buf to the beginning of
00187                            * struct radius_attr_hdr). */
00188         size_t attr_size; /* total size of the attribute pointer array */
00189         size_t attr_used; /* total number of attributes in the array */
00190 };
00191 
00192 
00193 /* Default size to be allocated for new RADIUS messages */
00194 #define RADIUS_DEFAULT_MSG_SIZE 1024
00195 
00196 /* Default size to be allocated for attribute array */
00197 #define RADIUS_DEFAULT_ATTR_COUNT 16
00198 
00199 
00200 /* MAC address ASCII format for IEEE 802.1X use
00201  * (draft-congdon-radius-8021x-20.txt) */
00202 #define RADIUS_802_1X_ADDR_FORMAT "%02X-%02X-%02X-%02X-%02X-%02X"
00203 /* MAC address ASCII format for non-802.1X use */
00204 #define RADIUS_ADDR_FORMAT "%02x%02x%02x%02x%02x%02x"
00205 
00206 struct radius_msg *radius_msg_new(u8 code, u8 identifier);
00207 int radius_msg_initialize(struct radius_msg *msg, size_t init_len);
00208 void radius_msg_set_hdr(struct radius_msg *msg, u8 code, u8 identifier);
00209 void radius_msg_free(struct radius_msg *msg);
00210 void radius_msg_dump(struct radius_msg *msg);
00211 int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
00212                       size_t secret_len);
00213 int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
00214                           size_t secret_len, const u8 *req_authenticator);
00215 void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
00216                             size_t secret_len);
00217 struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
00218                                             const u8 *data, size_t data_len);
00219 struct radius_msg *radius_msg_parse(const u8 *data, size_t len);
00220 int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
00221                        size_t data_len);
00222 u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *len);
00223 int radius_msg_verify(struct radius_msg *msg, const u8 *secret,
00224                       size_t secret_len, struct radius_msg *sent_msg,
00225                       int auth);
00226 int radius_msg_verify_msg_auth(struct radius_msg *msg, const u8 *secret,
00227                                size_t secret_len, const u8 *req_auth);
00228 int radius_msg_copy_attr(struct radius_msg *dst, struct radius_msg *src,
00229                          u8 type);
00230 void radius_msg_make_authenticator(struct radius_msg *msg,
00231                                    const u8 *data, size_t len);
00232 struct radius_ms_mppe_keys *
00233 radius_msg_get_ms_keys(struct radius_msg *msg, struct radius_msg *sent_msg,
00234                        const u8 *secret, size_t secret_len);
00235 struct radius_ms_mppe_keys *
00236 radius_msg_get_cisco_keys(struct radius_msg *msg, struct radius_msg *sent_msg,
00237                           const u8 *secret, size_t secret_len);
00238 int radius_msg_add_mppe_keys(struct radius_msg *msg,
00239                              const u8 *req_authenticator,
00240                              const u8 *secret, size_t secret_len,
00241                              const u8 *send_key, size_t send_key_len,
00242                              const u8 *recv_key, size_t recv_key_len);
00243 struct radius_attr_hdr *
00244 radius_msg_add_attr_user_password(struct radius_msg *msg,
00245                                   const u8 *data, size_t data_len,
00246                                   const u8 *secret, size_t secret_len);
00247 int radius_msg_get_attr(struct radius_msg *msg, u8 type, u8 *buf, size_t len);
00248 int radius_msg_get_vlanid(struct radius_msg *msg);
00249 
00250 static inline int radius_msg_add_attr_int32(struct radius_msg *msg, u8 type,
00251                                             u32 value)
00252 {
00253         u32 val = htonl(value);
00254         return radius_msg_add_attr(msg, type, (u8 *) &val, 4) != NULL;
00255 }
00256 
00257 static inline int radius_msg_get_attr_int32(struct radius_msg *msg, u8 type,
00258                                             u32 *value)
00259 {
00260         u32 val;
00261         int res;
00262         res = radius_msg_get_attr(msg, type, (u8 *) &val, 4);
00263         if (res != 4)
00264                 return -1;
00265 
00266         *value = ntohl(val);
00267         return 0;
00268 }
00269 int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf,
00270                             size_t *len, const u8 *start);
00271 int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len);
00272 
00273 
00274 struct radius_attr_data {
00275         u8 *data;
00276         size_t len;
00277 };
00278 
00279 struct radius_class_data {
00280         struct radius_attr_data *attr;
00281         size_t count;
00282 };
00283 
00284 #ifndef CONFIG_NO_RADIUS
00285 void radius_free_class(struct radius_class_data *c);
00286 int radius_copy_class(struct radius_class_data *dst,
00287                       const struct radius_class_data *src);
00288 #else /* CONFIG_NO_RADIUS */
00289 static inline void radius_free_class(struct radius_class_data *c)
00290 {
00291 }
00292 
00293 static inline int radius_copy_class(struct radius_class_data *dst,
00294                                     const struct radius_class_data *src)
00295 {
00296         return -1;
00297 }
00298 #endif /* CONFIG_NO_RADIUS */
00299 
00300 #endif /* RADIUS_H */
00301 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:52 2009 for hostapd by  doxygen 1.6.1