00001
00056 #ifndef DIAMETER_H_
00057 #define DIAMETER_H_
00058
00059
00060 #include "utils.h"
00061 #include <ctype.h>
00062
00063 #define get_2bytes(_b) \
00064 ((((unsigned char)(_b)[0])<<8)|\
00065 (((unsigned char)(_b)[1])))
00066
00067 #define get_3bytes(_b) \
00068 ((((unsigned char)(_b)[0])<<16)|(((unsigned char)(_b)[1])<<8)|\
00069 (((unsigned char)(_b)[2])))
00070
00071 #define get_4bytes(_b) \
00072 ((((unsigned char)(_b)[0])<<24)|(((unsigned char)(_b)[1])<<16)|\
00073 (((unsigned char)(_b)[2])<<8)|(((unsigned char)(_b)[3])))
00074
00075 #define set_2bytes(_b,_v) \
00076 {(_b)[0]=((_v)&0x0000ff00)>>8;\
00077 (_b)[1]=((_v)&0x000000ff);}
00078
00079 #define set_3bytes(_b,_v) \
00080 {(_b)[0]=((_v)&0x00ff0000)>>16;(_b)[1]=((_v)&0x0000ff00)>>8;\
00081 (_b)[2]=((_v)&0x000000ff);}
00082
00083 #define set_4bytes(_b,_v) \
00084 {(_b)[0]=((_v)&0xff000000)>>24;(_b)[1]=((_v)&0x00ff0000)>>16;\
00085 (_b)[2]=((_v)&0x0000ff00)>>8;(_b)[3]=((_v)&0x000000ff);}
00086
00087 #define to_32x_len( _len_ ) \
00088 ( (_len_)+(((_len_)&3)?4-((_len_)&3):0) )
00089
00090
00091
00092
00093 #define AAA_NO_VENDOR_ID 0
00094
00095 #define VER_SIZE 1
00096 #define MESSAGE_LENGTH_SIZE 3
00097 #define FLAGS_SIZE 1
00098 #define COMMAND_CODE_SIZE 3
00099 #define APPLICATION_ID_SIZE 4
00100 #define HOP_BY_HOP_IDENTIFIER_SIZE 4
00101 #define END_TO_END_IDENTIFIER_SIZE 4
00102 #define AVP_CODE_SIZE 4
00103 #define AVP_FLAGS_SIZE 1
00104 #define AVP_LENGTH_SIZE 3
00105 #define AVP_VENDOR_ID_SIZE 4
00106
00107 #define AAA_MSG_HDR_SIZE \
00108 (VER_SIZE + MESSAGE_LENGTH_SIZE + FLAGS_SIZE + COMMAND_CODE_SIZE +\
00109 APPLICATION_ID_SIZE+HOP_BY_HOP_IDENTIFIER_SIZE+END_TO_END_IDENTIFIER_SIZE)
00110
00111 #define AVP_HDR_SIZE(_flags_) \
00112 (AVP_CODE_SIZE+AVP_FLAGS_SIZE+AVP_LENGTH_SIZE+\
00113 AVP_VENDOR_ID_SIZE*(((_flags_)&AAA_AVP_FLAG_VENDOR_SPECIFIC)!=0) )
00114
00115
00116 #ifndef WORDS_BIGENDIAN
00117 #define AS_MSG_CODE 0x12010000
00118 #define AC_MSG_CODE 0x0f010000
00119 #define CE_MSG_CODE 0x01010000
00120 #define DW_MSG_CODE 0x18010000
00121 #define DP_MSG_CODE 0x1a010000
00122 #define RA_MSG_CODE 0x02010000
00123 #define ST_MSG_CODE 0x13010000
00124 #define MASK_MSG_CODE 0xffffff00
00125 #else
00126 #error BIG endian detected!!
00127 #define AS_MSG_CODE 0x00000112
00128 #define AC_MSG_CODE 0x0000010f
00129 #define CE_MSG_CODE 0x00000101
00130 #define DW_MSG_CODE 0x00000118
00131 #define DP_MSG_CODE 0x0000011a
00132 #define RA_MSG_CODE 0x00000102
00133 #define ST_MSG_CODE 0x00000113
00134 #define MASK_MSG_CODE 0x00ffffff
00135 #endif
00136
00137
00138 typedef unsigned int AAACommandCode;
00139 typedef unsigned int AAAVendorId;
00140 typedef unsigned int AAAExtensionId;
00141 typedef unsigned int AAA_AVPCode;
00142 typedef unsigned int AAAValue;
00143 typedef unsigned int AAAApplicationId;
00144 typedef void* AAAApplicationRef;
00145 typedef str AAASessionId;
00146 typedef unsigned int AAAMsgIdentifier;
00147 typedef unsigned char AAAMsgFlag;
00149 #define Flag_Request 0x80
00150 #define Flag_Proxyable 0x40
00151
00152 #define Code_CE 257
00153 #define Code_DW 280
00154 #define Code_DP 282
00155
00156
00158 typedef enum {
00159 AAA_ERR_NOT_FOUND = -2,
00160 AAA_ERR_FAILURE = -1,
00161 AAA_ERR_SUCCESS = 0,
00162 AAA_ERR_NOMEM,
00163 AAA_ERR_PROTO,
00164 AAA_ERR_SECURITY,
00165 AAA_ERR_PARAMETER,
00166 AAA_ERR_CONFIG,
00167 AAA_ERR_UNKNOWN_CMD,
00168 AAA_ERR_MISSING_AVP,
00169 AAA_ERR_ALREADY_INIT,
00170 AAA_ERR_TIMED_OUT,
00171 AAA_ERR_CANNOT_SEND_MSG,
00172 AAA_ERR_ALREADY_REGISTERED,
00173 AAA_ERR_CANNOT_REGISTER,
00174 AAA_ERR_NOT_INITIALIZED,
00175 AAA_ERR_NETWORK_ERROR,
00176 } AAAReturnCode;
00177
00178
00181 typedef enum {
00182 AAA_AVP_DATA_TYPE,
00183 AAA_AVP_STRING_TYPE,
00184 AAA_AVP_ADDRESS_TYPE,
00185 AAA_AVP_INTEGER32_TYPE,
00186 AAA_AVP_INTEGER64_TYPE,
00187 AAA_AVP_TIME_TYPE,
00188 } AAA_AVPDataType;
00189
00190
00193 typedef enum {
00194 AAA_AVP_FLAG_NONE = 0x00,
00195 AAA_AVP_FLAG_MANDATORY = 0x40,
00196 AAA_AVP_FLAG_RESERVED = 0x1F,
00197 AAA_AVP_FLAG_VENDOR_SPECIFIC = 0x80,
00198 AAA_AVP_FLAG_END_TO_END_ENCRYPT = 0x20,
00199 } AAA_AVPFlag;
00200
00201
00203 typedef enum {
00204 AAA_APP_DIAMETER_COMMON_MSG = 0,
00205 AAA_APP_NASREQ = 1,
00206 AAA_APP_MOBILE_IP = 2,
00207 AAA_APP_DIAMETER_BASE_ACC = 3,
00208 AAA_APP_RELAY = 0xffffffff,
00209 }AAA_APP_IDS;
00210
00211
00214 typedef enum {
00215 AAA_MULTI_ROUND_AUTH = 1001,
00216 AAA_SUCCESS = 2001,
00217 AAA_COMMAND_UNSUPPORTED = 3001,
00218 AAA_UNABLE_TO_DELIVER = 3002,
00219 AAA_REALM_NOT_SERVED = 3003,
00220 AAA_TOO_BUSY = 3004,
00221 AAA_LOOP_DETECTED = 3005,
00222 AAA_REDIRECT_INDICATION = 3006,
00223 AAA_APPLICATION_UNSUPPORTED = 3007,
00224 AAA_INVALID_HDR_BITS = 3008,
00225 AAA_INVALID_AVP_BITS = 3009,
00226 AAA_UNKNOWN_PEER = 3010,
00227 AAA_AUTHENTICATION_REJECTED = 4001,
00228 AAA_OUT_OF_SPACE = 4002,
00229 AAA_ELECTION_LOST = 4003,
00230 AAA_AVP_UNSUPPORTED = 5001,
00231 AAA_UNKNOWN_SESSION_ID = 5002,
00232 AAA_AUTHORIZATION_REJECTED = 5003,
00233 AAA_INVALID_AVP_VALUE = 5004,
00234 AAA_MISSING_AVP = 5005,
00235 AAA_RESOURCES_EXCEEDED = 5006,
00236 AAA_CONTRADICTING_AVPS = 5007,
00237 AAA_AVP_NOT_ALLOWED = 5008,
00238 AAA_AVP_OCCURS_TOO_MANY_TIMES = 5009,
00239 AAA_NO_COMMON_APPLICATION = 5010,
00240 AAA_UNSUPPORTED_VERSION = 5011,
00241 AAA_UNABLE_TO_COMPLY = 5012,
00242 AAA_INVALID_BIT_IN_HEADER = 5013,
00243 AAA_INVALIS_AVP_LENGTH = 5014,
00244 AAA_INVALID_MESSGE_LENGTH = 5015,
00245 AAA_INVALID_AVP_BIT_COMBO = 5016,
00246 AAA_NO_COMMON_SECURITY = 5017,
00247 } AAAResultCode;
00248
00250 typedef enum {
00251 AVP_User_Name = 1,
00252 AVP_Framed_IP_Address = 8,
00253 AVP_Class = 25,
00254 AVP_Session_Timeout = 27,
00255 AVP_Proxy_State = 33,
00256 AVP_NAS_Port_Type = 61,
00257 AVP_Framed_Interface_Id = 96,
00258 AVP_Framed_IPv6_Prefix = 97,
00259 AVP_Host_IP_Address = 257,
00260 AVP_Auth_Application_Id = 258,
00261 AVP_Acct_Application_Id = 259,
00262 AVP_Vendor_Specific_Application_Id= 260,
00263 AVP_Redirect_Max_Cache_Time = 262,
00264 AVP_Session_Id = 263,
00265 AVP_Origin_Host = 264,
00266 AVP_Supported_Vendor_Id = 265,
00267 AVP_Vendor_Id = 266,
00268 AVP_Result_Code = 268,
00269 AVP_Product_Name = 269,
00270 AVP_Session_Binding = 270,
00271 AVP_Disconnect_Cause = 273,
00272 AVP_Auth_Request_Type = 274,
00273 AVP_Auth_Grace_Period = 276,
00274 AVP_Auth_Session_State = 277,
00275 AVP_Origin_State_Id = 278,
00276 AVP_Proxy_Host = 280,
00277 AVP_Error_Message = 281,
00278 AVP_Record_Route = 282,
00279 AVP_Destination_Realm = 283,
00280 AVP_Proxy_Info = 284,
00281 AVP_Re_Auth_Request_Type = 285,
00282 AVP_Authorization_Lifetime = 291,
00283 AVP_Redirect_Host = 292,
00284 AVP_Destination_Host = 293,
00285 AVP_Termination_Cause = 295,
00286 AVP_Origin_Realm = 296,
00287 }AAA_AVPCodeNr;
00288
00289
00290 typedef enum {
00291 Permanent_Termination = 0,
00292 New_Server_Assigned = 1,
00293 Server_Change = 2,
00294 Remove_S_CSCF = 3,
00295 }AAA_AVPReasonCode;
00296
00297
00298
00301 typedef enum {
00302 AAA_FORWARD_SEARCH = 0,
00303 AAA_BACKWARD_SEARCH
00304 } AAASearchType;
00305
00306
00308 typedef enum {
00309 AAA_ACCT_EVENT = 1,
00310 AAA_ACCT_START = 2,
00311 AAA_ACCT_INTERIM = 3,
00312 AAA_ACCT_STOP = 4
00313 } AAAAcctMessageType;
00314
00316 typedef enum {
00317 AVP_DUPLICATE_DATA,
00318 AVP_DONT_FREE_DATA,
00319 AVP_FREE_DATA,
00320 } AVPDataStatus;
00321
00323 typedef struct avp {
00324 struct avp *next;
00325 struct avp *prev;
00326 AAA_AVPCode code;
00327 AAA_AVPFlag flags;
00328 AAA_AVPDataType type;
00329 AAAVendorId vendorId;
00330 str data;
00331 unsigned char free_it;
00332 } AAA_AVP;
00333
00334
00338 typedef struct _avp_list_t {
00339 AAA_AVP *head;
00340 AAA_AVP *tail;
00341 } AAA_AVP_LIST;
00342
00343
00345 typedef struct _message_t {
00346 AAACommandCode commandCode;
00347 AAAMsgFlag flags;
00348 AAAApplicationId applicationId;
00349 AAAMsgIdentifier endtoendId;
00350 AAAMsgIdentifier hopbyhopId;
00351 AAASessionId *sId;
00352 AAA_AVP *sessionId;
00353 AAA_AVP *orig_host;
00354 AAA_AVP *orig_realm;
00355 AAA_AVP *dest_host;
00356 AAA_AVP *dest_realm;
00357 AAA_AVP *res_code;
00358 AAA_AVP *auth_ses_state;
00359 AAA_AVP_LIST avpList;
00360 str buf;
00361 void *in_peer;
00362 } AAAMessage;
00363
00364
00365
00366
00367
00368
00369
00370
00372 #define is_req(_msg_) \
00373 (((_msg_)->flags)&0x80)
00374
00375
00376
00377
00382 typedef struct _AAATransaction{
00383 unsigned int hash,label;
00384 AAAApplicationId application_id;
00385 AAACommandCode command_code;
00386 } AAATransaction;
00387
00388
00390 typedef void (AAATransactionCallback_f)(int is_timeout,void *param,AAAMessage *ans);
00392 typedef AAAMessage* (AAARequestHandler_f)(AAAMessage *req, void *param);
00394 typedef void (AAAResponseHandler_f)(AAAMessage *res, void *param);
00395
00396
00397 #endif