00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _AAA_DIAMETER_MSG_H
00028 #define _AAA_DIAMETER_MSG_H
00029
00030 #include "../../str.h"
00031 #include "../../mem/mem.h"
00032
00033 #define ad_malloc pkg_malloc
00034 #define ad_free pkg_free
00035
00036
00037
00038 #define AAA_NO_VENDOR_ID 0
00039
00040 #define VER_SIZE 1
00041 #define MESSAGE_LENGTH_SIZE 3
00042 #define FLAGS_SIZE 1
00043 #define COMMAND_CODE_SIZE 3
00044 #define APPLICATION_ID_SIZE 4
00045 #define HOP_BY_HOP_IDENTIFIER_SIZE 4
00046 #define END_TO_END_IDENTIFIER_SIZE 4
00047 #define AVP_CODE_SIZE 4
00048 #define AVP_FLAGS_SIZE 1
00049 #define AVP_LENGTH_SIZE 3
00050 #define AVP_VENDOR_ID_SIZE 4
00051
00052 #define AAA_MSG_HDR_SIZE \
00053 (VER_SIZE + MESSAGE_LENGTH_SIZE + FLAGS_SIZE + COMMAND_CODE_SIZE +\
00054 APPLICATION_ID_SIZE+HOP_BY_HOP_IDENTIFIER_SIZE+END_TO_END_IDENTIFIER_SIZE)
00055
00056 #define AVP_HDR_SIZE(_flags_) \
00057 (AVP_CODE_SIZE+AVP_FLAGS_SIZE+AVP_LENGTH_SIZE+\
00058 AVP_VENDOR_ID_SIZE*(((_flags_)&AAA_AVP_FLAG_VENDOR_SPECIFIC)!=0) )
00059
00060
00061
00062 #ifndef WORDS_BIGENDIAN
00063 #define AS_MSG_CODE 0x12010000
00064 #define AC_MSG_CODE 0x0f010000
00065 #define CE_MSG_CODE 0x01010000
00066 #define DW_MSG_CODE 0x18010000
00067 #define DP_MSG_CODE 0x1a010000
00068 #define RA_MSG_CODE 0x02010000
00069 #define ST_MSG_CODE 0x13010000
00070 #define MASK_MSG_CODE 0xffffff00
00071 #else
00072 #error BIG endian detected!!
00073 #define AS_MSG_CODE 0x00000112
00074 #define AC_MSG_CODE 0x0000010f
00075 #define CE_MSG_CODE 0x00000101
00076 #define DW_MSG_CODE 0x00000118
00077 #define DP_MSG_CODE 0x0000011a
00078 #define RA_MSG_CODE 0x00000102
00079 #define ST_MSG_CODE 0x00000113
00080 #define MASK_MSG_CODE 0x00ffffff
00081 #endif
00082
00083
00084
00085 typedef unsigned int AAACommandCode;
00086 typedef unsigned int AAAVendorId;
00087 typedef unsigned int AAAExtensionId;
00088 typedef unsigned int AAA_AVPCode;
00089 typedef unsigned int AAAValue;
00090 typedef unsigned int AAAApplicationId;
00091 typedef void* AAAApplicationRef;
00092 typedef str AAASessionId;
00093 typedef unsigned int AAAMsgIdentifier;
00094 typedef unsigned char AAAMsgFlag;
00095
00096
00097
00098
00099 typedef enum {
00100 AAA_ERR_NOT_FOUND = -2,
00101 AAA_ERR_FAILURE = -1,
00102 AAA_ERR_SUCCESS = 0,
00103 AAA_ERR_NOMEM,
00104 AAA_ERR_PROTO,
00105 AAA_ERR_SECURITY,
00106 AAA_ERR_PARAMETER,
00107 AAA_ERR_CONFIG,
00108 AAA_ERR_UNKNOWN_CMD,
00109 AAA_ERR_MISSING_AVP,
00110 AAA_ERR_ALREADY_INIT,
00111 AAA_ERR_TIMED_OUT,
00112 AAA_ERR_CANNOT_SEND_MSG,
00113 AAA_ERR_ALREADY_REGISTERED,
00114 AAA_ERR_CANNOT_REGISTER,
00115 AAA_ERR_NOT_INITIALIZED,
00116 AAA_ERR_NETWORK_ERROR,
00117 } AAAReturnCode;
00118
00119
00120
00121
00122 typedef enum {
00123 AAA_AVP_DATA_TYPE,
00124 AAA_AVP_STRING_TYPE,
00125 AAA_AVP_ADDRESS_TYPE,
00126 AAA_AVP_INTEGER32_TYPE,
00127 AAA_AVP_INTEGER64_TYPE,
00128 AAA_AVP_TIME_TYPE,
00129 } AAA_AVPDataType;
00130
00131
00132
00133
00134 typedef enum {
00135 AAA_AVP_FLAG_NONE = 0x00,
00136 AAA_AVP_FLAG_MANDATORY = 0x40,
00137 AAA_AVP_FLAG_RESERVED = 0x1F,
00138 AAA_AVP_FLAG_VENDOR_SPECIFIC = 0x80,
00139 AAA_AVP_FLAG_END_TO_END_ENCRYPT = 0x20,
00140 } AAA_AVPFlag;
00141
00142
00143
00144 typedef enum {
00145 AAA_APP_DIAMETER_COMMON_MSG = 0,
00146 AAA_APP_NASREQ = 1,
00147 AAA_APP_MOBILE_IP = 2,
00148 AAA_APP_DIAMETER_BASE_ACC = 3,
00149 AAA_APP_RELAY = (int)0xffffffff,
00150 }AAA_APP_IDS;
00151
00152
00153
00154
00155 typedef enum {
00156 AAA_MUTI_ROUND_AUTH = 1001,
00157 AAA_SUCCESS = 2001,
00158 AAA_COMMAND_UNSUPPORTED = 3001,
00159 AAA_UNABLE_TO_DELIVER = 3002,
00160 AAA_REALM_NOT_SERVED = 3003,
00161 AAA_TOO_BUSY = 3004,
00162 AAA_LOOP_DETECTED = 3005,
00163 AAA_REDIRECT_INDICATION = 3006,
00164 AAA_APPLICATION_UNSUPPORTED = 3007,
00165 AAA_INVALID_HDR_BITS = 3008,
00166 AAA_INVALID_AVP_BITS = 3009,
00167 AAA_UNKNOWN_PEER = 3010,
00168 AAA_AUTHENTICATION_REJECTED = 4001,
00169 AAA_OUT_OF_SPACE = 4002,
00170 AAA_ELECTION_LOST = 4003,
00171 AAA_AVP_UNSUPPORTED = 5001,
00172 AAA_UNKNOWN_SESSION_ID = 5002,
00173 AAA_AUTHORIZATION_REJECTED = 5003,
00174 AAA_INVALID_AVP_VALUE = 5004,
00175 AAA_MISSING_AVP = 5005,
00176 AAA_RESOURCES_EXCEEDED = 5006,
00177 AAA_CONTRADICTING_AVPS = 5007,
00178 AAA_AVP_NOT_ALLOWED = 5008,
00179 AAA_AVP_OCCURS_TOO_MANY_TIMES = 5009,
00180 AAA_NO_COMMON_APPLICATION = 5010,
00181 AAA_UNSUPPORTED_VERSION = 5011,
00182 AAA_UNABLE_TO_COMPLY = 5012,
00183 AAA_INVALID_BIT_IN_HEADER = 5013,
00184 AAA_INVALIS_AVP_LENGTH = 5014,
00185 AAA_INVALID_MESSGE_LENGTH = 5015,
00186 AAA_INVALID_AVP_BIT_COMBO = 5016,
00187 AAA_NO_COMMON_SECURITY = 5017,
00188 } AAAResultCode;
00189
00190
00191 typedef enum {
00192 AVP_User_Name = 1,
00193 AVP_Class = 25,
00194 AVP_Session_Timeout = 27,
00195 AVP_Proxy_State = 33,
00196 AVP_Host_IP_Address = 257,
00197 AVP_Auth_Application_Id = 258,
00198 AVP_Vendor_Specific_Application_Id= 260,
00199 AVP_Redirect_Max_Cache_Time = 262,
00200 AVP_Session_Id = 263,
00201 AVP_Origin_Host = 264,
00202 AVP_Supported_Vendor_Id = 265,
00203 AVP_Vendor_Id = 266,
00204 AVP_Result_Code = 268,
00205 AVP_Product_Name = 269,
00206 AVP_Session_Binding = 270,
00207 AVP_Disconnect_Cause = 273,
00208 AVP_Auth_Request_Type = 274,
00209 AVP_Auth_Grace_Period = 276,
00210 AVP_Auth_Session_State = 277,
00211 AVP_Origin_State_Id = 278,
00212 AVP_Proxy_Host = 280,
00213 AVP_Error_Message = 281,
00214 AVP_Record_Route = 282,
00215 AVP_Destination_Realm = 283,
00216 AVP_Proxy_Info = 284,
00217 AVP_Re_Auth_Request_Type = 285,
00218 AVP_Authorization_Lifetime = 291,
00219 AVP_Redirect_Host = 292,
00220 AVP_Destination_Host = 293,
00221 AVP_Termination_Cause = 295,
00222 AVP_Origin_Realm = 296,
00223
00224 AVP_Resource = 400,
00225 AVP_Response = 401,
00226 AVP_Challenge = 402,
00227 AVP_Method = 403,
00228 AVP_Service_Type = 404,
00229 AVP_User_Group = 405,
00230 AVP_SIP_MSGID = 406
00231
00232
00233 }AAA_AVPCodeNr;
00234
00235
00236
00237
00238 typedef enum {
00239 AAA_FORWARD_SEARCH = 0,
00240 AAA_BACKWARD_SEARCH
00241 } AAASearchType;
00242
00243
00244
00245 typedef enum {
00246 AAA_ACCT_EVENT = 1,
00247 AAA_ACCT_START = 2,
00248 AAA_ACCT_INTERIM = 3,
00249 AAA_ACCT_STOP = 4
00250 } AAAAcctMessageType;
00251
00252
00253 typedef enum {
00254 AVP_DUPLICATE_DATA,
00255 AVP_DONT_FREE_DATA,
00256 AVP_FREE_DATA,
00257 } AVPDataStatus;
00258
00259
00260 typedef struct avp {
00261 struct avp *next;
00262 struct avp *prev;
00263 enum {
00264 AAA_RADIUS,
00265 AAA_DIAMETER
00266 } packetType;
00267 AAA_AVPCode code;
00268 AAA_AVPFlag flags;
00269 AAA_AVPDataType type;
00270 AAAVendorId vendorId;
00271 str data;
00272 unsigned char free_it;
00273 } AAA_AVP;
00274
00275
00276
00277
00278 typedef struct _avp_list_t {
00279 AAA_AVP *head;
00280 AAA_AVP *tail;
00281 } AAA_AVP_LIST;
00282
00283
00284
00285 typedef struct _message_t {
00286 AAAMsgFlag flags;
00287 AAACommandCode commandCode;
00288 AAAApplicationId applicationId;
00289 AAAMsgIdentifier endtoendId;
00290 AAAMsgIdentifier hopbyhopId;
00291 AAASessionId *sId;
00292 AAA_AVP *sessionId;
00293 AAA_AVP *orig_host;
00294 AAA_AVP *orig_realm;
00295 AAA_AVP *dest_host;
00296 AAA_AVP *dest_realm;
00297 AAA_AVP *res_code;
00298 AAA_AVP *auth_ses_state;
00299 AAA_AVP_LIST avpList;
00300 str buf;
00301 void *in_peer;
00302 } AAAMessage;
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 #define is_req(_msg_) \
00313 (((_msg_)->flags)&0x80)
00314
00315 AAAMessage *AAAInMessage(
00316 AAACommandCode commandCode,
00317 AAAApplicationId appId);
00318
00319 AAAReturnCode AAAFreeMessage(
00320 AAAMessage **message);
00321
00322 AAAReturnCode AAASetMessageResultCode(
00323 AAAMessage *message,
00324 AAAResultCode resultCode);
00325
00326 void AAAPrintMessage(
00327 AAAMessage *msg);
00328
00329 AAAReturnCode AAABuildMsgBuffer(
00330 AAAMessage *msg );
00331
00332 AAAMessage* AAATranslateMessage(
00333 unsigned char* source,
00334 unsigned int sourceLen,
00335 int attach_buf );
00336
00337
00338
00339
00340
00341 #define AAACreateAndAddAVPToMessage(_msg_,_code_,_flags_,_vdr_,_data_,_len_) \
00342 ( AAAAddAVPToMessage(_msg_, \
00343 AAACreateAVP(_code_,_flags_,_vdr_,_data_,_len_, AVP_DUPLICATE_DATA),\
00344 (_msg_)->avpList.tail) )
00345
00346 AAA_AVP* AAACreateAVP(
00347 AAA_AVPCode code,
00348 AAA_AVPFlag flags,
00349 AAAVendorId vendorId,
00350 char *data,
00351 unsigned int length,
00352 AVPDataStatus data_status);
00353
00354 AAA_AVP* AAACloneAVP(
00355 AAA_AVP *avp,
00356 unsigned char duplicate_data );
00357
00358 AAAReturnCode AAAAddAVPToMessage(
00359 AAAMessage *msg,
00360 AAA_AVP *avp,
00361 AAA_AVP *position);
00362
00363 AAA_AVP *AAAFindMatchingAVP(
00364 AAAMessage *msg,
00365 AAA_AVP *startAvp,
00366 AAA_AVPCode avpCode,
00367 AAAVendorId vendorId,
00368 AAASearchType searchType);
00369
00370 AAAReturnCode AAARemoveAVPFromMessage(
00371 AAAMessage *msg,
00372 AAA_AVP *avp);
00373
00374 AAAReturnCode AAAFreeAVP(
00375 AAA_AVP **avp);
00376
00377 AAA_AVP* AAAGetFirstAVP(
00378 AAA_AVP_LIST *avpList);
00379
00380 AAA_AVP* AAAGetLastAVP(
00381 AAA_AVP_LIST *avpList);
00382
00383 AAA_AVP* AAAGetNextAVP(
00384 AAA_AVP *avp);
00385
00386 AAA_AVP* AAAGetPrevAVP(
00387 AAA_AVP *avp);
00388
00389 char *AAAConvertAVPToString(
00390 AAA_AVP *avp,
00391 char *dest,
00392 unsigned int destLen);
00393
00394
00395 #endif