Navigation


Changeset 419:9cc48cd22e67 in freeDiameter


Ignore:
Timestamp:
Jul 12, 2010, 10:56:33 PM (14 years ago)
Author:
Alexandre Westfahl <awestfahl@freediameter.net>
Branch:
default
Phase:
public
Message:

Finished RTR on Diameter-SIP

Location:
extensions/app_sip
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_sip/CMakeLists.txt

    r392 r419  
    2020        md5.c
    2121        multimediaauth.c
     22        registrationtermination.c
    2223)
    2324
  • extensions/app_sip/diamsip.c

    r409 r419  
    9090        struct dict_object * app=NULL;
    9191        struct disp_when data;
     92        pthread_t rtr_thread;
    9293       
    9394        /* Initialize configuration */
     
    115116        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &sip_dict.Auth_Session_State, ENOENT) );
    116117        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &sip_dict.Auth_Application_Id, ENOENT) );
     118        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &sip_dict.Destination_Host, ENOENT) );
     119        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) );
    117120        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Auth-Data-Item", &sip_dict.SIP_Auth_Data_Item, ENOENT) );
    118121        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) );
     
    124127        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) );
    125128        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) );
     129        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Deregistration-Reason", &sip_dict.SIP_Deregistration_Reason, ENOENT) );
     130        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) );
     131        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) );
    126132        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) );
    127133        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) );
     
    164170        CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free));
    165171       
     172        //Creation of thread for Registration Termination       
     173        if(pthread_create(&rtr_thread, NULL,rtr_socket, NULL))
     174        {
     175                TRACE_DEBUG(INFO,"Creation of thread failed, abort!");
     176                return 1;
     177        }
     178               
     179
     180       
     181       
     182       
     183       
    166184        return 0;
    167185}
  • extensions/app_sip/diamsip.h

    r409 r419  
    8888int fd_avp_search_avp ( struct avp * groupedavp, struct dict_object * what, struct avp ** avp );
    8989
     90//thread procedure
     91void *rtr_socket(void *);
     92
     93struct rtrsipaor
     94{
     95        char username[200];
     96        char sip_aor1[200];
     97        char sip_aor2[200];
     98        char sip_aor3[200];
     99        char strreason[200];
     100        char desthost[200];
     101        int reason;
     102};
     103int diamsip_RTR_cb(struct rtrsipaor structure);
     104#define PORT 666 //TODO:put in conf file
     105
    90106int ds_entry();
    91107void fd_ext_fini(void);
     
    121137        struct dict_object * Auth_Session_State;
    122138        struct dict_object * Auth_Application_Id;
     139        struct dict_object * Destination_Host;
    123140        struct dict_object * User_Name;
     141        struct dict_object * Session_Id;
    124142        struct dict_object * SIP_Auth_Data_Item;
    125143        struct dict_object * SIP_Authorization;
     
    131149        struct dict_object * SIP_Method;
    132150        struct dict_object * SIP_AOR;
     151        struct dict_object * SIP_Deregistration_Reason;
     152        struct dict_object * SIP_Reason_Code;
     153        struct dict_object * SIP_Reason_Info;
    133154        struct dict_object * Digest_URI;               
    134155        struct dict_object * Digest_Nonce;
  • extensions/app_sip/registrationtermination.c

    r409 r419  
    3535*********************************************************************************************************/
    3636#include "diamsip.h"
    37 
    38 
     37#include <sys/types.h>
     38#include <sys/socket.h>
     39#include <netinet/in.h>
     40#include <arpa/inet.h>
     41#include <unistd.h>
     42typedef int SOCKET;
     43typedef struct sockaddr_in SOCKADDR_IN;
     44typedef struct sockaddr SOCKADDR;
     45
     46//Procedure which always wait for data on socket
     47void *rtr_socket(void *arg)
     48{
     49        SOCKET sock;
     50    SOCKADDR_IN sin, csin;
     51    struct rtrsipaor rtrsip;
     52    int rcvbytes=0;
     53        sock = socket(AF_INET, SOCK_STREAM, 0);
     54        sin.sin_addr.s_addr = inet_addr("127.0.0.1");
     55    sin.sin_family = AF_INET;
     56    sin.sin_port = htons(PORT);
     57    socklen_t sinsize = sizeof(csin);
     58        int accepted=0;
     59
     60    TRACE_DEBUG(INFO,"############********************THREAD OPEN \n********************\n********************\n");
     61   
     62        if(!bind(sock, (SOCKADDR*)&sin, sizeof(sin)))
     63        {
     64                if(listen(sock,1))
     65                {
     66                        TRACE_DEBUG(INFO,"ERROR on listen!");
     67                }
     68               
     69                while(1)
     70                {
     71                        accepted=accept(sock, (struct sockaddr *)&csin,&sinsize);
     72                        if(accepted>-1)
     73                        {
     74                                rcvbytes=recv(accepted, &rtrsip, sizeof(struct rtrsipaor),0);
     75       
     76                               
     77                                if(rcvbytes>-1)
     78                                {
     79                                        diamsip_RTR_cb(rtrsip);
     80                                       
     81                                       
     82                                }
     83                        }
     84                }
     85               
     86               
     87        }
     88        else
     89                TRACE_DEBUG(INFO,"Can't create socket!");
     90
     91       
     92       
     93       
     94       
     95        TRACE_DEBUG(INFO,"############********************THREAD CLOSED \n********************\n********************\n");
     96        pthread_exit(NULL);
     97       
     98}
     99//Called to send a RTR
     100int diamsip_RTR_cb(struct rtrsipaor structure)
     101{
     102        TRACE_ENTRY("%p", structure);
     103       
     104        int got_username=0;
     105        int got_streason=0;
     106        int num_aor=0;//How many SIP-AOR?
     107        struct dict_object * rtr_model=NULL;
     108        struct msg * message=NULL;
     109        struct avp *groupedavp=NULL, *avp=NULL;
     110        struct session *sess=NULL;
     111        union avp_value value;
     112       
     113        //We must check that we have all needed value in structure
     114        if(structure.username[0]!='\0')
     115                got_username=1;
     116       
     117        if(structure.sip_aor1[0]!='\0')
     118        {       
     119                num_aor++;
     120                if(structure.sip_aor2[0]!='\0')
     121                {
     122                        num_aor++;
     123                        if(structure.sip_aor3[0]!='\0')
     124                                num_aor++;
     125                }
     126        }
     127       
     128        if(structure.strreason!='\0')
     129                got_streason=1;
     130       
     131       
     132        TRACE_DEBUG(INFO,"We have %d SIP_AOR",num_aor);
     133       
     134        if((got_username + num_aor)==0)
     135        {
     136                //We must have a least a SIP_AOR or a Username
     137                TRACE_DEBUG(INFO,"Can not proceed because there is no SIP_AOR or Username");
     138                return EINVAL;
     139        }
     140        if(structure.reason<0)
     141        {
     142                //We must have a least a SIP_AOR or a Username
     143                TRACE_DEBUG(INFO,"Incorrect Reason-Code");
     144                return EINVAL;
     145        }
     146       
     147        if(structure.desthost[0]=='\0')
     148        {
     149                //We must have a least a SIP_AOR or a Username
     150                TRACE_DEBUG(INFO,"No Destination_Host was provided!");
     151                return EINVAL;
     152        }
     153        //Create the base message for an RTR
     154        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Request", &rtr_model, ENOENT) );
     155        CHECK_FCT( fd_msg_new (rtr_model, 0, &message));
     156       
     157        // Create a new session
     158        {
     159                CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, "app_sip", 7 ));
     160                char * sid;
     161                CHECK_FCT( fd_sess_getsid ( sess, &sid ));
     162                CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp ));
     163                value.os.data = (uint8_t *)sid;
     164                value.os.len  = strlen(sid);
     165                CHECK_FCT( fd_msg_avp_setvalue( avp, &value ));
     166                CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp ));
     167        }
     168       
     169       
     170        //Auth_Session_State
     171        {
     172                CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Session_State, 0, &avp ) );
     173                value.i32=1;
     174                CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     175                CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     176        }
     177       
     178        //Origin_Host & Origin_Realm
     179        CHECK_FCT( fd_msg_add_origin ( message, 0 ));
     180       
     181        //Destination_Host
     182        {
     183                CHECK_FCT( fd_msg_avp_new ( sip_dict.Destination_Host, 0, &avp ) );
     184                value.os.data=(unsigned char *)structure.desthost;
     185                value.os.len=(size_t)strlen(structure.desthost);
     186                CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     187                CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     188        }
     189       
     190       
     191        //SIP Deregistration Reason (Grouped AVP)
     192        {
     193                CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Deregistration_Reason, 0, &groupedavp ) );
     194               
     195                //Reason Code
     196                CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Reason_Code, 0, &avp ) );
     197                value.i32=structure.reason;
     198                CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     199                CHECK_FCT( fd_msg_avp_add( groupedavp, MSG_BRW_LAST_CHILD, avp ) );
     200               
     201                if(got_streason)
     202                {
     203                        //Reason Info
     204                        CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Reason_Info, 0, &avp ) );
     205                        value.os.data=(unsigned char *)structure.strreason;
     206                        value.os.len=(size_t)strlen(structure.strreason);
     207                        CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     208                        CHECK_FCT( fd_msg_avp_add( groupedavp, MSG_BRW_LAST_CHILD, avp ) );
     209                }
     210               
     211                //We add the grouped AVP to the message
     212                CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, groupedavp ) );
     213        }
     214       
     215        //Username
     216        {
     217                if(got_username)
     218                {
     219                        CHECK_FCT( fd_msg_avp_new ( sip_dict.User_Name, 0, &avp ) );
     220                        value.os.data=(unsigned char *)structure.username;
     221                        value.os.len=(size_t)strlen(structure.username);
     222                        CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     223                        CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     224                }
     225        }
     226       
     227        //SIP_AOR
     228        {
     229                if(num_aor>0)
     230                {
     231                        CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
     232                        value.os.data=(unsigned char *)structure.sip_aor1;
     233                        value.os.len=(size_t)strlen(structure.sip_aor1);
     234                        CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     235                        CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     236                        if(num_aor>1)
     237                        {
     238                                CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
     239                                value.os.data=(unsigned char *)structure.sip_aor2;
     240                                value.os.len=(size_t)strlen(structure.sip_aor2);
     241                                CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     242                                CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     243                                if(num_aor>2)
     244                                {
     245                                        CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_AOR, 0, &avp ) );
     246                                        value.os.data=(unsigned char *)structure.sip_aor3;
     247                                        value.os.len=(size_t)strlen(structure.sip_aor3);
     248                                        CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) );
     249                                        CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) );
     250                                }
     251                        }
     252                }
     253        }
     254       
     255        fd_msg_dump_walk(INFO,message);
     256        CHECK_FCT( fd_msg_send( &message, NULL, NULL ));
     257       
     258        return 0;
     259}
     260
     261//Called when an RTA arrive
    39262int diamsip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
    40263{
     264        //TODO: RTA reception
     265/*
    41266        //TODO:remove unused variables
    42267        struct msg *ans, *qry;
     
    61286       
    62287       
    63         /* Create answer header */
     288        // Create answer header
    64289        qry = *msg;
    65290        CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
     
    67292       
    68293       
    69         /* Add the Auth-Session-State AVP */
     294        // Add the Auth-Session-State AVP
    70295        {
    71296               
     
    93318       
    94319       
    95        
     320        */
    96321        return 0;
     322       
    97323}
    98324
Note: See TracChangeset for help on using the changeset viewer.