ims_pm_scscf.c

Go to the documentation of this file.
00001 /*
00002  * $Id: ims_pm_scscf.c 432 2007-08-02 16:27:30Z vingarzan $
00003  *  
00004  * Copyright (C) 2004-2006 FhG Fokus
00005  *
00006  * This file is part of Open IMS Core - an open source IMS CSCFs & HSS
00007  * implementation
00008  *
00009  * Open IMS Core is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * For a license to use the Open IMS Core software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact Fraunhofer FOKUS by e-mail at the following
00017  * addresses:
00018  *     info@open-ims.org
00019  *
00020  * Open IMS Core is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  * 
00025  * It has to be noted that this Open Source IMS Core System is not 
00026  * intended to become or act as a product in a commercial context! Its 
00027  * sole purpose is to provide an IMS core reference implementation for 
00028  * IMS technology testing and IMS application prototyping for research 
00029  * purposes, typically performed in IMS test-beds.
00030  * 
00031  * Users of the Open Source IMS Core System have to be aware that IMS
00032  * technology may be subject of patents and licence terms, as being 
00033  * specified within the various IMS-related IETF, ITU-T, ETSI, and 3GPP
00034  * standards. Thus all Open IMS Core users have to take notice of this 
00035  * fact and have to agree to check out carefully before installing, 
00036  * using and extending the Open Source IMS Core System, if related 
00037  * patents and licences may become applicable to the intended usage 
00038  * context.  
00039  *
00040  * You should have received a copy of the GNU General Public License
00041  * along with this program; if not, write to the Free Software
00042  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00043  * 
00044  */
00045  
00046 
00058 #include "ims_pm_scscf.h"
00059 
00060 #ifdef WITH_IMS_PM
00061 
00062 #include <unistd.h>
00063 #include <fcntl.h>
00064 #include <time.h>
00065 
00066 #include "../../script_cb.h"
00067 #include "../tm/tm_load.h"
00068 
00069 #include "mod.h"
00070 #include "sip.h"
00071 #include "registrar.h"
00072 #include "cx_avp.h"
00073 
00074 
00075 extern struct tm_binds tmb;                         
00077 static str zero={0,0};
00078 
00079 void ims_pm_init_scscf()
00080 {
00081     register_script_cb(ims_pm_pre_script,PRE_SCRIPT_CB|REQ_TYPE_CB|RPL_TYPE_CB,0);
00082     register_script_cb(ims_pm_post_script,POST_SCRIPT_CB|REQ_TYPE_CB|RPL_TYPE_CB,0);    
00083 }
00084 
00085 
00086 
00087 
00088 int ims_pm_get_registration_type(struct sip_msg *msg)
00089 {
00090     str public_identity = cscf_get_public_identity(msg);
00091     if (r_is_registered_id(public_identity)){
00092         if (cscf_get_expires_hdr(msg)>0) return 1;
00093         else return 2;      
00094     }
00095     else
00096         return 0;
00097 }
00098 
00099 void ims_pm_register_cb(struct cell* t, int type, struct tmcb_params* ps)
00100 {
00101     int k = (int) *ps->param;
00102     int code = ps->code; 
00103     switch(k){
00104         case 0:
00105             if (code>=200 && code<300) 
00106                 IMS_PM_LOG12(UR_SuccInitReg,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00107             else if (code>=300) IMS_PM_LOG12(UR_FailInitReg,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00108             break;
00109         case 1:
00110             if (code>=200 && code<300) IMS_PM_LOG12(UR_SuccReReg,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00111             else if (code>=300) IMS_PM_LOG12(UR_FailReReg,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00112             break;
00113         case 2:
00114             if (code>=200 && code<300) IMS_PM_LOG12(UR_SuccDeRegUe,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00115             else if (code>=300) IMS_PM_LOG12(UR_FailDeRegUe,cscf_get_call_id(ps->req,0),cscf_get_cseq(ps->req,0),code);
00116             break;
00117     }
00118 }
00119 
00120 static str s_register={"REGISTER",8};
00121 static str s_invite={"INVITE",6};
00122 
00123 int ims_pm_pre_script(struct sip_msg *msg,void *param)
00124 {
00125     int k;
00126     str method={0,0};
00127     unsigned int x,y;
00128     if (msg->first_line.type == SIP_REQUEST){
00129         method = msg->first_line.u.request.method;
00130         /* REGISTER */
00131         if (method.len==s_register.len && strncasecmp(method.s,s_register.s,s_register.len)==0){
00132                 k = ims_pm_get_registration_type(msg);
00133                 switch(k){
00134                     case 0:
00135                         IMS_PM_LOG11(UR_AttInitReg,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0));
00136                         IMS_PM_LOG21(RU_RmgUsersOut,cscf_get_call_id(msg,0),
00137                             cscf_get_visited_network_id(msg,0),cscf_get_cseq(msg,0));
00138                         break;
00139                     case 1:
00140                         IMS_PM_LOG11(UR_AttReReg,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0));
00141                         break;
00142                     case 2:
00143                         IMS_PM_LOG11(UR_AttDeRegUe,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0));
00144                         break;
00145                 }
00146                 //cscf_get_transaction(msg,&x,&y);
00147                 //tmb.register_tmcb(msg,0,TMCB_RESPONSE_OUT,ims_pm_register_cb,(void*)k);
00148         }
00149         /* INVITE */
00150         else if (method.len==s_invite.len && strncasecmp(method.s,s_invite.s,s_invite.len)==0){
00151             IMS_PM_LOG11(SC_AttSession,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0));
00152             IMS_PM_LOG21(IC_AttSessionFromOtherNtwkDmn,cscf_get_call_id(msg,0),
00153                 cscf_get_asserted_identity_domain(msg),
00154                 cscf_get_cseq(msg,0));
00155             IMS_PM_LOG21(IC_AttSessionToOtherNtwkDmn,cscf_get_call_id(msg,0),
00156                 cscf_get_realm_from_ruri(msg),
00157                 cscf_get_cseq(msg,0));
00158         }else{
00159             /* Other requests */
00160             IMS_PM_LOG21(OTHER_Att,cscf_get_call_id(msg,0),method,cscf_get_cseq(msg,0));
00161         }               
00162     }else{
00163         unsigned int code = msg->first_line.u.reply.statuscode;
00164         method = cscf_get_cseq_method(msg,0);           
00165         if (method.len==s_invite.len && strncasecmp(method.s,s_invite.s,s_invite.len)==0){
00166             /* INVITE response */
00167             if (code<300) IMS_PM_LOG12(SC_SuccSession,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0),code);
00168             else if (code>=300) {
00169                 IMS_PM_LOG12(SC_FailSession,cscf_get_call_id(msg,0),cscf_get_cseq(msg,0),code);         
00170                 if (code==403) {
00171                     IMS_PM_LOG22(IC_403SessionFromOtherNtwkDmn,cscf_get_call_id(msg,0),
00172                         cscf_get_asserted_identity_domain(msg),cscf_get_cseq(msg,0),code);
00173                     IMS_PM_LOG22(IC_403SessionToOtherNtwkDmn,cscf_get_call_id(msg,0),
00174                         cscf_get_realm_from_ruri(msg),cscf_get_cseq(msg,0),code);
00175                 }                       
00176             }                   
00177         }else{  
00178             /* Other responses */
00179             if (code>=200 && code<300) IMS_PM_LOG22(OTHER_Succ,cscf_get_call_id(msg,0),method,cscf_get_cseq(msg,0),code);
00180             else if (code>=300) IMS_PM_LOG22(OTHER_Fail,cscf_get_call_id(msg,0),method,cscf_get_cseq(msg,0),code);
00181         }       
00182     }
00183     return 1;
00184 }
00185 
00186 
00187 
00188 int ims_pm_post_script(struct sip_msg *msg,void *param)
00189 {
00190     return 1;
00191 }
00192 
00193 
00194 void ims_pm_diameter_request(AAAMessage *msg)
00195 {   
00196     if (!msg) return;   
00197     switch(msg->applicationId){
00198         case IMS_Cx:
00199             switch(msg->commandCode){               
00200                 case IMS_RTR:                                                       
00201                     IMS_PM_LOG11(UR_AttDeRegHss,Cx_get_session_id(msg),msg->endtoendId);
00202                     return ;
00203                     break;
00204                 case IMS_PPR:                                                       
00205                     IMS_PM_LOG11(UP_AttPPR,Cx_get_session_id(msg),msg->endtoendId);
00206                     return ;
00207                     break;
00208                 case IMS_SAR:                                                       
00209                     IMS_PM_LOG11(UR_AttSAR,Cx_get_session_id(msg),msg->endtoendId);
00210                     return ;
00211                     break;
00212                 case IMS_MAR:                                                       
00213                     IMS_PM_LOG11(MA_AttMAR,Cx_get_session_id(msg),msg->endtoendId);
00214                     return ;
00215                     break;
00216             }
00217     }   
00218 }
00219 
00220 void ims_pm_diameter_answer(AAAMessage *msg)
00221 {
00222     if (!msg) return;   
00223     int code=-1;
00224     if (!Cx_get_result_code(msg,&code)) 
00225         Cx_get_experimental_result_code(msg,&code);
00226     switch(msg->applicationId){
00227         case IMS_Cx:
00228             switch(msg->commandCode){               
00229                 case IMS_RTA:
00230                     if (code>=2000 && code<3000) IMS_PM_LOG12(UR_SuccDeRegHss,Cx_get_session_id(msg),msg->endtoendId,code);
00231                     else IMS_PM_LOG12(UR_FailDeRegHss,Cx_get_session_id(msg),msg->endtoendId,code);
00232                     break;
00233                 case IMS_PPA:
00234                     if (code>=2000 && code<3000) IMS_PM_LOG12(UP_SuccPPA,Cx_get_session_id(msg),msg->endtoendId,code);
00235                     else IMS_PM_LOG12(UP_FailPPA,Cx_get_session_id(msg),msg->endtoendId,code);
00236                     break;
00237                 case IMS_SAA:
00238                     if (code>=2000 && code<3000) IMS_PM_LOG12(UR_SuccSAA,Cx_get_session_id(msg),msg->endtoendId,code);
00239                     else IMS_PM_LOG12(UR_FailSAA,Cx_get_session_id(msg),msg->endtoendId,code);
00240                     break;
00241                 case IMS_MAA:
00242                     if (code>=2000 && code<3000) IMS_PM_LOG12(MA_SuccMAA,Cx_get_session_id(msg),msg->endtoendId,code);
00243                     else IMS_PM_LOG12(MA_FailMAA,Cx_get_session_id(msg),msg->endtoendId,code);
00244                     break;
00245             }
00246     }
00247 }
00248 
00249 #endif /* WITH_IMS_PM */

Generated on Thu Oct 23 04:14:39 2008 for Open IMS Core CSCFs by  doxygen 1.5.2