00001
00061 #include "cx_avp.h"
00062 #include "../../mem/shm_mem.h"
00063 #include <stdio.h>
00064
00065 extern struct cdp_binds cdpb;
00079 static inline int Cx_add_avp(AAAMessage *m,char *d,int len,int avp_code,
00080 int flags,int vendorid,int data_do,const char *func)
00081 {
00082 AAA_AVP *avp;
00083 if (vendorid!=0) flags |= AAA_AVP_FLAG_VENDOR_SPECIFIC;
00084 avp = cdpb.AAACreateAVP(avp_code,flags,vendorid,d,len,data_do);
00085 if (!avp) {
00086 LOG(L_ERR,"ERR:"M_NAME":%s: Failed creating avp\n",func);
00087 return 0;
00088 }
00089 if (cdpb.AAAAddAVPToMessage(m,avp,m->avpList.tail)!=AAA_ERR_SUCCESS) {
00090 LOG(L_ERR,"ERR:"M_NAME":%s: Failed adding avp to message\n",func);
00091 cdpb.AAAFreeAVP(&avp);
00092 return 0;
00093 }
00094 return 1;
00095 }
00096
00109 static inline int Cx_add_avp_list(AAA_AVP_LIST *list,char *d,int len,int avp_code,
00110 int flags,int vendorid,int data_do,const char *func)
00111 {
00112 AAA_AVP *avp;
00113 if (vendorid!=0) flags |= AAA_AVP_FLAG_VENDOR_SPECIFIC;
00114 avp = cdpb.AAACreateAVP(avp_code,flags,vendorid,d,len,data_do);
00115 if (!avp) {
00116 LOG(L_ERR,"ERR:"M_NAME":%s: Failed creating avp\n",func);
00117 return 0;
00118 }
00119 if (list->tail) {
00120 avp->prev=list->tail;
00121 avp->next=0;
00122 list->tail->next = avp;
00123 list->tail=avp;
00124 } else {
00125 list->head = avp;
00126 list->tail = avp;
00127 avp->next=0;
00128 avp->prev=0;
00129 }
00130
00131 return 1;
00132 }
00133
00142 static inline str Cx_get_avp(AAAMessage *msg,int avp_code,int vendor_id,
00143 const char *func)
00144 {
00145 AAA_AVP *avp;
00146 str r={0,0};
00147
00148 avp = cdpb.AAAFindMatchingAVP(msg,0,avp_code,vendor_id,0);
00149 if (avp==0){
00150 LOG(L_INFO,"INFO:"M_NAME":%s: Failed finding avp\n",func);
00151 return r;
00152 }
00153 else
00154 return avp->data;
00155 }
00156
00157
00158
00159
00166 inline int Cx_add_user_name(AAAMessage *msg,str data)
00167 {
00168 return
00169 Cx_add_avp(msg,data.s,data.len,
00170 AVP_User_Name,
00171 AAA_AVP_FLAG_MANDATORY,
00172 0,
00173 AVP_DUPLICATE_DATA,
00174 __FUNCTION__);
00175 }
00176
00183 inline int Cx_add_public_identity(AAAMessage *msg,str data)
00184 {
00185 return
00186 Cx_add_avp(msg,data.s,data.len,
00187 AVP_IMS_Public_Identity,
00188 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00189 IMS_vendor_id_3GPP,
00190 AVP_DUPLICATE_DATA,
00191 __FUNCTION__);
00192 }
00193
00200 inline int Cx_add_visited_network_id(AAAMessage *msg,str data)
00201 {
00202 return
00203 Cx_add_avp(msg,data.s,data.len,
00204 AVP_IMS_Visited_Network_Identifier,
00205 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00206 IMS_vendor_id_3GPP,
00207 AVP_DUPLICATE_DATA,
00208 __FUNCTION__);
00209 }
00210
00217 inline int Cx_add_authorization_type(AAAMessage *msg,unsigned int data)
00218 {
00219 char x[4];
00220 set_4bytes(x,data);
00221 return
00222 Cx_add_avp(msg,x,4,
00223 AVP_IMS_User_Authorization_Type,
00224 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00225 IMS_vendor_id_3GPP,
00226 AVP_DUPLICATE_DATA,
00227 __FUNCTION__);
00228 }
00229
00230
00237 inline int Cx_add_server_name(AAAMessage *msg,str data)
00238 {
00239 return
00240 Cx_add_avp(msg,data.s,data.len,
00241 AVP_IMS_Server_Name,
00242 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00243 IMS_vendor_id_3GPP,
00244 AVP_DUPLICATE_DATA,
00245 __FUNCTION__);
00246 }
00247
00254 inline int Cx_add_sip_number_auth_items(AAAMessage *msg,unsigned int data)
00255 {
00256 char x[4];
00257 set_4bytes(x,data);
00258 return
00259 Cx_add_avp(msg,x,4,
00260 AVP_IMS_SIP_Number_Auth_Items,
00261 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00262 IMS_vendor_id_3GPP,
00263 AVP_DUPLICATE_DATA,
00264 __FUNCTION__);
00265 }
00266
00267
00268 static str s_empty = {0, 0};
00276 inline int Cx_add_sip_auth_data_item_request(AAAMessage *msg, str auth_scheme, str auth, str username, str realm,str method, str server_name)
00277 {
00278 AAA_AVP_LIST list;
00279 str group;
00280 str etsi_authorization = {0, 0};
00281 list.head=0;list.tail=0;
00282
00283 if (auth_scheme.len){
00284 Cx_add_avp_list(&list,
00285 auth_scheme.s,auth_scheme.len,
00286 AVP_IMS_SIP_Authentication_Scheme,
00287 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00288 IMS_vendor_id_3GPP,
00289 AVP_DONT_FREE_DATA,
00290 __FUNCTION__);
00291 }
00292 if (auth.len){
00293 Cx_add_avp_list(&list,
00294 auth.s,auth.len,
00295 AVP_IMS_SIP_Authorization,
00296 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00297 IMS_vendor_id_3GPP,
00298 AVP_DONT_FREE_DATA,
00299 __FUNCTION__);
00300 }
00301
00302 if (server_name.len)
00303 {
00304 etsi_authorization = Cx_ETSI_sip_authorization(username, realm, s_empty, server_name, s_empty, s_empty, method, s_empty);
00305
00306 if (etsi_authorization.len){
00307 Cx_add_avp_list(&list,
00308 etsi_authorization.s,etsi_authorization.len,
00309 AVP_ETSI_SIP_Authorization,
00310 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00311 IMS_vendor_id_ETSI,
00312 AVP_FREE_DATA,
00313 __FUNCTION__);
00314 }
00315 }
00316
00317 if (!list.head) return 1;
00318 group = cdpb.AAAGroupAVPS(list);
00319
00320 cdpb.AAAFreeAVPList(&list);
00321
00322 return
00323 Cx_add_avp(msg,group.s,group.len,
00324 AVP_IMS_SIP_Auth_Data_Item,
00325 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00326 IMS_vendor_id_3GPP,
00327 AVP_FREE_DATA,
00328 __FUNCTION__);
00329 }
00330
00343 str Cx_ETSI_sip_authorization(str username, str realm, str nonce, str URI, str response, str algorithm, str method, str hash)
00344 {
00345 AAA_AVP_LIST list;
00346 str group = {0, 0};
00347 list.head=0;list.tail=0;
00348
00349 if (username.len){
00350 Cx_add_avp_list(&list,
00351 username.s,username.len,
00352 AVP_ETSI_Digest_Username,
00353 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00354 IMS_vendor_id_ETSI,
00355 AVP_DONT_FREE_DATA,
00356 __FUNCTION__);
00357 }
00358
00359 if (realm.len){
00360 Cx_add_avp_list(&list,
00361 realm.s,realm.len,
00362 AVP_ETSI_Digest_Realm,
00363 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00364 IMS_vendor_id_ETSI,
00365 AVP_DONT_FREE_DATA,
00366 __FUNCTION__);
00367 }
00368
00369 if (nonce.len){
00370 Cx_add_avp_list(&list,
00371 nonce.s,nonce.len,
00372 AVP_ETSI_Digest_Nonce,
00373 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00374 IMS_vendor_id_ETSI,
00375 AVP_DONT_FREE_DATA,
00376 __FUNCTION__);
00377 }
00378
00379 if (URI.len){
00380 Cx_add_avp_list(&list,
00381 URI.s,URI.len,
00382 AVP_ETSI_Digest_URI,
00383 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00384 IMS_vendor_id_ETSI,
00385 AVP_DONT_FREE_DATA,
00386 __FUNCTION__);
00387 }
00388
00389 if (response.len){
00390 Cx_add_avp_list(&list,
00391 response.s,response.len,
00392 AVP_ETSI_Digest_Response,
00393 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00394 IMS_vendor_id_ETSI,
00395 AVP_DONT_FREE_DATA,
00396 __FUNCTION__);
00397 }
00398
00399 if (algorithm.len){
00400 Cx_add_avp_list(&list,
00401 algorithm.s,algorithm.len,
00402 AVP_ETSI_Digest_Algorithm,
00403 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00404 IMS_vendor_id_ETSI,
00405 AVP_DONT_FREE_DATA,
00406 __FUNCTION__);
00407 }
00408
00409 if (method.len){
00410 Cx_add_avp_list(&list,
00411 method.s,method.len,
00412 AVP_ETSI_Digest_Method,
00413 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00414 IMS_vendor_id_ETSI,
00415 AVP_DONT_FREE_DATA,
00416 __FUNCTION__);
00417 }
00418
00419 if (hash.len){
00420 Cx_add_avp_list(&list,
00421 hash.s,hash.len,
00422 AVP_ETSI_Digest_Entity_Body_Hash,
00423 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00424 IMS_vendor_id_ETSI,
00425 AVP_DONT_FREE_DATA,
00426 __FUNCTION__);
00427 }
00428
00429 if (!list.head) return group;
00430 group = cdpb.AAAGroupAVPS(list);
00431
00432 cdpb.AAAFreeAVPList(&list);
00433
00434 return group;
00435 }
00436
00443 inline int Cx_add_server_assignment_type(AAAMessage *msg,unsigned int data)
00444 {
00445 char x[4];
00446 set_4bytes(x,data);
00447 return
00448 Cx_add_avp(msg,x,4,
00449 AVP_IMS_Server_Assignment_Type,
00450 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00451 IMS_vendor_id_3GPP,
00452 AVP_DUPLICATE_DATA,
00453 __FUNCTION__);
00454 }
00455
00462 inline int Cx_add_userdata_available(AAAMessage *msg,unsigned int data)
00463 {
00464 char x[4];
00465 set_4bytes(x,data);
00466 return
00467 Cx_add_avp(msg,x,4,
00468 AVP_IMS_User_Data_Already_Available,
00469 AAA_AVP_FLAG_MANDATORY|AAA_AVP_FLAG_VENDOR_SPECIFIC,
00470 IMS_vendor_id_3GPP,
00471 AVP_DUPLICATE_DATA,
00472 __FUNCTION__);
00473 }
00474
00481 inline int Cx_add_result_code(AAAMessage *msg,unsigned int data)
00482 {
00483 char x[4];
00484 set_4bytes(x,data);
00485 return
00486 Cx_add_avp(msg,x,4,
00487 AVP_Result_Code,
00488 AAA_AVP_FLAG_MANDATORY,
00489 0,
00490 AVP_DUPLICATE_DATA,
00491 __FUNCTION__);
00492 }
00493
00500 inline int Cx_add_experimental_result_code(AAAMessage *msg,unsigned int data)
00501 {
00502 AAA_AVP_LIST list;
00503 str group;
00504 char x[4];
00505 list.head=0;list.tail=0;
00506
00507 set_4bytes(x,data);
00508 Cx_add_avp_list(&list,
00509 x,4,
00510 AVP_IMS_Experimental_Result_Code,
00511 AAA_AVP_FLAG_MANDATORY,
00512 0,
00513 AVP_DUPLICATE_DATA,
00514 __FUNCTION__);
00515
00516 set_4bytes(x,IMS_vendor_id_3GPP);
00517 Cx_add_avp_list(&list,
00518 x,4,
00519 AVP_IMS_Vendor_Id,
00520 AAA_AVP_FLAG_MANDATORY,
00521 0,
00522 AVP_DUPLICATE_DATA,
00523 __FUNCTION__);
00524
00525
00526 group = cdpb.AAAGroupAVPS(list);
00527
00528 cdpb.AAAFreeAVPList(&list);
00529
00530 return
00531 Cx_add_avp(msg,group.s,group.len,
00532 AVP_IMS_Experimental_Result,
00533 AAA_AVP_FLAG_MANDATORY,
00534 0,
00535 AVP_FREE_DATA,
00536 __FUNCTION__);
00537 }
00538
00547 inline int Cx_add_vendor_specific_appid(AAAMessage *msg,unsigned int vendor_id,
00548 unsigned int auth_id,unsigned int acct_id)
00549 {
00550 AAA_AVP_LIST list;
00551 str group;
00552 char x[4];
00553
00554 list.head=0;list.tail=0;
00555
00556 set_4bytes(x,vendor_id);
00557 Cx_add_avp_list(&list,
00558 x,4,
00559 AVP_Vendor_Id,
00560 AAA_AVP_FLAG_MANDATORY,
00561 0,
00562 AVP_DUPLICATE_DATA,
00563 __FUNCTION__);
00564
00565 if (auth_id) {
00566 set_4bytes(x,auth_id);
00567 Cx_add_avp_list(&list,
00568 x,4,
00569 AVP_Auth_Application_Id,
00570 AAA_AVP_FLAG_MANDATORY,
00571 0,
00572 AVP_DUPLICATE_DATA,
00573 __FUNCTION__);
00574 }
00575 if (acct_id) {
00576 set_4bytes(x,acct_id);
00577 Cx_add_avp_list(&list,
00578 x,4,
00579 AVP_Acct_Application_Id,
00580 AAA_AVP_FLAG_MANDATORY,
00581 0,
00582 AVP_DUPLICATE_DATA,
00583 __FUNCTION__);
00584 }
00585
00586 group = cdpb.AAAGroupAVPS(list);
00587
00588 cdpb.AAAFreeAVPList(&list);
00589
00590 return
00591 Cx_add_avp(msg,group.s,group.len,
00592 AVP_Vendor_Specific_Application_Id,
00593 AAA_AVP_FLAG_MANDATORY,
00594 0,
00595 AVP_FREE_DATA,
00596 __FUNCTION__);
00597 }
00598
00599
00606 inline int Cx_add_auth_session_state(AAAMessage *msg,unsigned int data)
00607 {
00608 char x[4];
00609 set_4bytes(x,data);
00610 return
00611 Cx_add_avp(msg,x,4,
00612 AVP_Auth_Session_State,
00613 AAA_AVP_FLAG_MANDATORY,
00614 0,
00615 AVP_DUPLICATE_DATA,
00616 __FUNCTION__);
00617 }
00618
00625 inline int Cx_add_destination_realm(AAAMessage *msg,str data)
00626 {
00627 return
00628 Cx_add_avp(msg,data.s,data.len,
00629 AVP_Destination_Realm,
00630 AAA_AVP_FLAG_MANDATORY,
00631 0,
00632 AVP_DUPLICATE_DATA,
00633 __FUNCTION__);
00634 }
00635
00636
00642 inline str Cx_get_session_id(AAAMessage *msg)
00643 {
00644 return Cx_get_avp(msg,
00645 AVP_Session_Id,
00646 0,
00647 __FUNCTION__);
00648 }
00649
00650
00656 inline str Cx_get_user_name(AAAMessage *msg)
00657 {
00658 return Cx_get_avp(msg,
00659 AVP_User_Name,
00660 0,
00661 __FUNCTION__);
00662 }
00663
00669 inline str Cx_get_public_identity(AAAMessage *msg)
00670 {
00671 return Cx_get_avp(msg,
00672 AVP_IMS_Public_Identity,
00673 IMS_vendor_id_3GPP,
00674 __FUNCTION__);
00675 }
00676
00686 inline AAA_AVP* Cx_get_next_public_identity(AAAMessage *msg,AAA_AVP* pos,int avp_code,int vendor_id,const char *func)
00687 {
00688 AAA_AVP *avp;
00689
00690 avp = cdpb.AAAFindMatchingAVP(msg,pos,avp_code,vendor_id,0);
00691 if (avp==0){
00692 LOG(L_INFO,"INFO:"M_NAME":%s: Failed finding avp\n",func);
00693 return avp;
00694 }
00695 else
00696 return avp;
00697 }
00698
00704 inline str Cx_get_visited_network_id(AAAMessage *msg)
00705 {
00706 return Cx_get_avp(msg,
00707 AVP_IMS_Visited_Network_Identifier,
00708 IMS_vendor_id_3GPP,
00709 __FUNCTION__);
00710 }
00711
00717 inline int Cx_get_authorization_type(AAAMessage *msg, int *data)
00718 {
00719 str s;
00720 s = Cx_get_avp(msg,
00721 AVP_IMS_User_Authorization_Type,
00722 IMS_vendor_id_3GPP,
00723 __FUNCTION__);
00724 if (!s.s) return 0;
00725 *data = get_4bytes(s.s);
00726 return 1;
00727 }
00728
00734 inline int Cx_get_server_assignment_type(AAAMessage *msg, int *data)
00735 {
00736 str s;
00737 s = Cx_get_avp(msg,
00738 AVP_IMS_Server_Assignment_Type,
00739 IMS_vendor_id_3GPP,
00740 __FUNCTION__);
00741 if (!s.s) return 0;
00742 *data = get_4bytes(s.s);
00743 return 1;
00744 }
00745
00751 inline int Cx_get_userdata_available(AAAMessage *msg, int *data)
00752 {
00753 str s;
00754 s = Cx_get_avp(msg,
00755 AVP_IMS_User_Data_Already_Available,
00756 IMS_vendor_id_3GPP,
00757 __FUNCTION__);
00758 if (!s.s) return 0;
00759 *data = get_4bytes(s.s);
00760 return 1;
00761 }
00762
00763
00769 inline int Cx_get_result_code(AAAMessage *msg, int *data)
00770 {
00771 str s;
00772 s = Cx_get_avp(msg,
00773 AVP_Result_Code,
00774 0,
00775 __FUNCTION__);
00776 if (!s.s) return 0;
00777 *data = get_4bytes(s.s);
00778 return 1;
00779 }
00780
00786 inline int Cx_get_experimental_result_code(AAAMessage *msg, int *data)
00787 {
00788 AAA_AVP_LIST list;
00789 AAA_AVP *avp;
00790 str grp;
00791 grp = Cx_get_avp(msg,
00792 AVP_IMS_Experimental_Result,
00793 0,
00794 __FUNCTION__);
00795 if (!grp.s) return 0;
00796
00797 list = cdpb.AAAUngroupAVPS(grp);
00798
00799 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_Experimental_Result_Code,0,0);
00800 if (!avp||!avp->data.s) {
00801 cdpb.AAAFreeAVPList(&list);
00802 return 0;
00803 }
00804
00805 *data = get_4bytes(avp->data.s);
00806 cdpb.AAAFreeAVPList(&list);
00807
00808 return 1;
00809 }
00810
00816 inline str Cx_get_server_name(AAAMessage *msg)
00817 {
00818 return Cx_get_avp(msg,
00819 AVP_IMS_Server_Name,
00820 IMS_vendor_id_3GPP,
00821 __FUNCTION__);
00822 }
00823
00824
00834 inline int Cx_get_capabilities(AAAMessage *msg,int **m,int *m_cnt,int **o,int *o_cnt,
00835 str **p,int *p_cnt)
00836 {
00837 AAA_AVP_LIST list;
00838 AAA_AVP *avp;
00839 str grp;
00840 grp = Cx_get_avp(msg,
00841 AVP_IMS_Server_Capabilities,
00842 IMS_vendor_id_3GPP,
00843 __FUNCTION__);
00844 if (!grp.s) return 0;
00845
00846 list = cdpb.AAAUngroupAVPS(grp);
00847
00848 avp = list.head;
00849 *m_cnt=0;
00850 *o_cnt=0;
00851 *p_cnt=0;
00852 while(avp){
00853 if (avp->code == AVP_IMS_Mandatory_Capability) (*m_cnt)++;
00854 if (avp->code == AVP_IMS_Optional_Capability) (*o_cnt)++;
00855 if (avp->code == AVP_IMS_Server_Name) (*p_cnt)++;
00856 avp = avp->next;
00857 }
00858 avp = list.head;
00859 *m=shm_malloc(sizeof(int)*(*m_cnt));
00860 if (!*m){
00861 LOG(L_ERR,"ERROR:"M_NAME":Cx_get_capabilities(): cannot allocated %d bytes of shm.\n",
00862 sizeof(int)*(*m_cnt));
00863 goto error;
00864 }
00865 *o=shm_malloc(sizeof(int)*(*o_cnt));
00866 if (!*o){
00867 LOG(L_ERR,"ERROR:"M_NAME":Cx_get_capabilities(): cannot allocated %d bytes of shm.\n",
00868 sizeof(int)*(*o_cnt));
00869 goto error;
00870 }
00871 *p=shm_malloc(sizeof(str)*(*p_cnt));
00872 if (!*p){
00873 LOG(L_ERR,"ERROR:"M_NAME":Cx_get_capabilities(): cannot allocated %d bytes of shm.\n",
00874 sizeof(str)*(*p_cnt));
00875 goto error;
00876 }
00877
00878 *m_cnt=0;
00879 *o_cnt=0;
00880 *p_cnt=0;
00881 while(avp){
00882 if (avp->code == AVP_IMS_Mandatory_Capability)
00883 (*m)[(*m_cnt)++]=get_4bytes(avp->data.s);
00884 if (avp->code == AVP_IMS_Optional_Capability)
00885 (*o)[(*o_cnt)++]=get_4bytes(avp->data.s);
00886 if (avp->code == AVP_IMS_Server_Name)
00887 (*p)[(*p_cnt)++]=avp->data;
00888 avp = avp->next;
00889 }
00890 cdpb.AAAFreeAVPList(&list);
00891 return 1;
00892
00893 error:
00894 cdpb.AAAFreeAVPList(&list);
00895 if (*m) shm_free(*m);
00896 if (*o) shm_free(*o);
00897 if (*p) shm_free(*p);
00898 *m_cnt=0;
00899 *o_cnt=0;
00900 *p_cnt=0;
00901 return 0;
00902 }
00903
00909 inline int Cx_get_sip_number_auth_items(AAAMessage *msg, int *data)
00910 {
00911 str s;
00912 s = Cx_get_avp(msg,
00913 AVP_IMS_SIP_Number_Auth_Items,
00914 IMS_vendor_id_3GPP,
00915 __FUNCTION__);
00916 if (!s.s) return 0;
00917 *data = get_4bytes(s.s);
00918 return 1;
00919 }
00920
00921
00929 inline int Cx_get_auth_data_item_request(AAAMessage *msg,
00930 str *auth_scheme, str *authorization)
00931 {
00932 AAA_AVP_LIST list;
00933 AAA_AVP *avp;
00934 str grp;
00935 grp = Cx_get_avp(msg,
00936 AVP_IMS_SIP_Auth_Data_Item,
00937 IMS_vendor_id_3GPP,
00938 __FUNCTION__);
00939 if (!grp.s) return 0;
00940
00941 list = cdpb.AAAUngroupAVPS(grp);
00942
00943 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Authentication_Scheme,
00944 IMS_vendor_id_3GPP,0);
00945 if (!avp||!avp->data.s) {
00946 cdpb.AAAFreeAVPList(&list);
00947 return 0;
00948 }
00949 *auth_scheme = avp->data;
00950
00951 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Authorization,
00952 IMS_vendor_id_3GPP,0);
00953 if (avp) *authorization = avp->data;
00954 else {authorization->s=0;authorization->len=0;}
00955
00956 cdpb.AAAFreeAVPList(&list);
00957 return 1;
00958 }
00959
00972 int Cx_get_auth_data_item_answer(AAAMessage *msg, AAA_AVP **auth_data,
00973 int *item_number,str *auth_scheme,str *authenticate,str *authorization,
00974 str *ck,str *ik,
00975 str *ip,
00976 str *ha1, str *response_auth, str *digest_realm,
00977 str *line_identifier)
00978 {
00979 AAA_AVP_LIST list;
00980 AAA_AVP_LIST list2;
00981 AAA_AVP *avp;
00982 AAA_AVP *avp2;
00983 str grp;
00984 ha1->s = 0; ha1->len = 0;
00985 *auth_data = cdpb.AAAFindMatchingAVP(msg,*auth_data,AVP_IMS_SIP_Auth_Data_Item,
00986 IMS_vendor_id_3GPP,0);
00987 if (!*auth_data) return 0;
00988
00989 grp = (*auth_data)->data;
00990 if (!grp.len) return 0;
00991
00992 list = cdpb.AAAUngroupAVPS(grp);
00993
00994 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Item_Number,
00995 IMS_vendor_id_3GPP,0);
00996 if (!avp||!avp->data.len==4) *item_number=0;
00997 else *item_number = get_4bytes(avp->data.s);
00998
00999 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Authentication_Scheme,
01000 IMS_vendor_id_3GPP,0);
01001 if (!avp||!avp->data.s) {auth_scheme->s=0;auth_scheme->len=0;}
01002 else *auth_scheme = avp->data;
01003
01004
01005 ip->s=0;ip->len=0;
01006 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_Framed_IP_Address,0,0);
01007 if (avp && avp->data.s){
01008 if (avp->data.len!=4){
01009 LOG(L_ERR,"ERROR:"M_NAME":Cx_get_capabilities(): Invalid length of AVP Framed IP Address (should be 4 for AVP_Framed_IP_Address) >%d.\n",
01010 avp->data.len);
01011 }
01012 ip->len = 4;
01013 ip->s = avp->data.s;
01014 } else {
01015 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_Framed_IPv6_Prefix,0,0);
01016 if (avp && avp->data.s){
01017 if (avp->data.len==0){
01018 LOG(L_ERR,"ERROR:"M_NAME":Cx_get_capabilities(): Invalid length of AVP Framed IPv6 Prefix (should be >0 for AVP_Framed_IPv6_Prefix) >%d.\n",
01019 avp->data.len);
01020 }
01021 ip->len = avp->data.len;
01022 ip->s = avp->data.s;
01023 }
01024 }
01025
01026
01027
01028 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_CableLabs_SIP_Digest_Authenticate,IMS_vendor_id_CableLabs,0);
01029 if (avp && avp->data.s)
01030 {
01031 list2 = cdpb.AAAUngroupAVPS(avp->data);
01032
01033 avp2 = cdpb.AAAFindMatchingAVPList(list2,0,AVP_CableLabs_Digest_HA1,IMS_vendor_id_CableLabs,0);
01034 if (!avp2||!avp2->data.s) {
01035 ha1->s = 0; ha1->len = 0;
01036 cdpb.AAAFreeAVPList(&list2);
01037 return 0;
01038 }
01039 *ha1 = avp2->data;
01040 cdpb.AAAFreeAVPList(&list2);
01041 }
01042
01043
01044
01045 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Authenticate,
01046 IMS_vendor_id_3GPP,0);
01047 if (!avp||!avp->data.s) {authenticate->s=0;authenticate->len=0;}
01048 else *authenticate = avp->data;
01049
01050 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_SIP_Authorization,
01051 IMS_vendor_id_3GPP,0);
01052 if (!avp||!avp->data.s) {authorization->s=0;authorization->len=0;}
01053 else *authorization = avp->data;
01054
01055 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_Confidentiality_Key,
01056 IMS_vendor_id_3GPP,0);
01057 if (!avp||!avp->data.s) {ck->s=0;ck->len=0;}
01058 else *ck = avp->data;
01059
01060 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_IMS_Integrity_Key,
01061 IMS_vendor_id_3GPP,0);
01062 if (!avp||!avp->data.s) {ik->s=0;ik->len=0;}
01063 else *ik = avp->data;
01064
01065
01066
01067 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_ETSI_SIP_Authenticate,IMS_vendor_id_ETSI,0);
01068 if (avp && avp->data.s)
01069 {
01070 list2 = cdpb.AAAUngroupAVPS(avp->data);
01071
01072 avp2 = cdpb.AAAFindMatchingAVPList(list2,0,AVP_ETSI_Digest_Realm, IMS_vendor_id_ETSI,0);
01073 if (!avp2||!avp2->data.s) {
01074 digest_realm->s=0;digest_realm->len=0;
01075 cdpb.AAAFreeAVPList(&list2);
01076 return 0;
01077 }
01078 *digest_realm = avp2->data;
01079
01080 avp2 = cdpb.AAAFindMatchingAVPList(list2,0,AVP_ETSI_Digest_Nonce, IMS_vendor_id_ETSI,0);
01081 if (!avp2||!avp2->data.s) {
01082 authenticate->s=0;authenticate->len=0;
01083 cdpb.AAAFreeAVPList(&list2);
01084 return 0;
01085 }
01086 *authenticate = avp2->data;
01087
01088 avp2 = cdpb.AAAFindMatchingAVPList(list2,0,AVP_ETSI_Digest_HA1, IMS_vendor_id_ETSI,0);
01089 if (!avp2||!avp2->data.s) {
01090 ha1->s = 0; ha1->len = 0;
01091 cdpb.AAAFreeAVPList(&list2);
01092 return 0;
01093 }
01094 *ha1 = avp2->data;
01095
01096 cdpb.AAAFreeAVPList(&list2);
01097 }
01098
01099 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_ETSI_SIP_Authentication_Info,IMS_vendor_id_ETSI,0);
01100 if (avp && avp->data.s)
01101 {
01102 list2 = cdpb.AAAUngroupAVPS(avp->data);
01103
01104 avp2 = cdpb.AAAFindMatchingAVPList(list2,0,AVP_ETSI_Digest_Response_Auth, IMS_vendor_id_ETSI,0);
01105 if (!avp2||!avp2->data.s) {
01106 response_auth->s=0;response_auth->len=0;
01107 cdpb.AAAFreeAVPList(&list2);
01108 return 0;
01109 }
01110 *response_auth = avp2->data;
01111 cdpb.AAAFreeAVPList(&list2);
01112 }
01113 else
01114 {
01115 response_auth->s=0;response_auth->len=0;
01116 }
01117
01118
01119 avp = cdpb.AAAFindMatchingAVPList(list,0,AVP_Line_Identifier, IMS_vendor_id_ETSI,0);
01120 if (!avp||!avp->data.s) {line_identifier->s=0;line_identifier->len=0;}
01121 else *line_identifier = avp->data;
01122
01123 cdpb.AAAFreeAVPList(&list);
01124 return 1;
01125 }
01126
01127
01133 inline str Cx_get_destination_host(AAAMessage *msg)
01134 {
01135 return Cx_get_avp(msg,
01136 AVP_Destination_Host,
01137 0,
01138 __FUNCTION__);
01139 }
01140
01146 inline str Cx_get_user_data(AAAMessage *msg)
01147 {
01148 return Cx_get_avp(msg,
01149 AVP_IMS_User_Data,