Make Alive the 4-Year-Not-Maintained Sip2IMS Gateway Open-source Code

For product verification purpose, I need to use a Sip2IMS gateway and found a well-respected one developed by Joseph Johnson. Following the procedures posted in “this post“, I was blocked for quite a long time in finding out the old version of libosip (2.2.3) needed for this Sip2IMS Gateway that has not been updated for more than 4 years. Struggled  for almost a whole day on Google, I was fortunately able to find a version 2.2.1 over “here“.

1. Down loaded the lib0sip2.2.2 tarball, and followed the instructions in the INSTALL file to install the package as follows:

  • ./configure
  • make
  • make install

The package is installed in “/usr/local” directory.

2. Then started making Sip2IMS gateway as below:

First saw errors like below

sip2ims_db.c:1076:14: error: ‘ULONG_MAX’ undeclared (first use in this function)
sip2ims_db.c:1076:14: note: each undeclared identifier is reported only once for each function it appears in
sip2ims_db.c:1077:13: error: ‘INT_MIN’ undeclared (first use in this function)
sip2ims_db.c:1077:32: error: ‘UINT_MAX’ undeclared (first use in this function)

Solution:  include “/usr/include/limits.h” in “sip2ims_common.h” .

Then saw the following errors

/usr/bin/ld: sip2ims.o: undefined reference to symbol ‘osip_atoi’
/usr/bin/ld: note: ‘osip_atoi’ is defined in DSO /usr/local/lib/libosipparser2.so.3 so try adding it to the linker command line
/usr/local/lib/libosipparser2.so.3: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Solution: add “-losipparser2” in the Makefile to like the needed library in.

Then the executable “sip2ims” is made successfully.

3. Configure the gateway as follows

MySQL Database. The Open IMS Core sip2ims database must be created and a default username/password created using the following command, and need to be modified for our purposes.

  • $mysql –p < osims_sip2ims.sql
  • $mysql –p < modify_osims.sql

After this you need to do some modification to the “credentials” table to adjust corresponding values if you do not use openIMS defaults. The server is running on default port 3060/4060.

4. Run the gateway:  Go to the directory with run.sh

  • Use the command
  • ./run.sh
if you see errors like below when run,
./src/sip2ims: error while loading shared libraries: libosip2.so.3: cannot open shared object file: No such file or directory
you need to add libosip path into LD_LIBRARY_PATH using command or you can put this command in your for example “.bashrc” file.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH :/usr/local/lib
Saw the following error at the first run
sip2ims: no process found

Error: Cannot open main configuration file ‘sip2ims.cfg’ for reading!

Solution: found a configuration file from here. Below is the content of this file. You need to do some modifications to it before use if you do not use the openIMS defaults.

#
# $Id$
#
# SIP2IMS Gateway configuration script
#
# ———– global configuration parameters ————————
debug=3
 log_stderror=yes
memlog=4
sip_warning=yes
fork=yes
children=4
listen=127.0.0.1
port=3060
alias=sip2ims.open-ims.test
check_via=no    # (cmd. line: -v)
dns=no                  # (cmd. line: -r)
rev_dns=no              # (cmd. line: -R)
# —————— module loading ———————————-
# Uncomment this if you want to use SQL database
loadmodule “/opt/OpenIMSCore/ser_ims/modules/mysql/mysql.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/sl/sl.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/tm/tm.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/maxfwd/maxfwd.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/textops/textops.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/auth/auth.so”
loadmodule “/opt/OpenIMSCore/ser_ims/modules/auth_db/auth_db.so”
modparam(“auth_db”,”db_url”,”mysql://sip2ims:heslo@localhost/sip2ims”)
modparam(“auth_db”,”use_did”,0)
loadmodule “/opt/OpenIMSCore/ser_ims/modules/rr/rr.so”
modparam(“rr”, “enable_full_lr”, 1)
loadmodule “/opt/OpenIMSCore/ser_ims/modules/sip2ims/sip2ims.so”
modparam(“sip2ims”,”db_url”,”mysql://sip2ims:heslo@localhost/sip2ims”)
modparam(“sip2ims”,”db_table”,”credentials”)
#modparam(“sip2ims”,”secret”,”alabala”)
modparam(“sip2ims”,”nonce_expire”,300)
# ————————-  request routing logic ——————-
# main routing logic
route{
        route(Sanity_Checks);
#       if (uri==myself){
#               sl_send_reply(“400″,”The SIP-to-IMS Gateway only works in proxy mode (no UAC/S)”);
#               break;
#       }
        if (method==REGISTER){
                route(REGISTER);
        }
        route(PCSCF);
}
route[Sanity_Checks]
{
        # initial sanity checks — messages with
        # max_forwards==0, or excessively long requests
        if (!mf_process_maxfwd_header(“11”)) {
                sl_send_reply(“483″,”Too Many Hops”);
                exit;
        };
        if (msg:len >=  max_len ) {
                sl_send_reply(“513”, “Message too big”);
                exit;
        };
}
route[REGISTER]
{
        if (www_authorize(“open-ims.test”,”credentials”)) {
                if (!Gw_MD5_to_AKA(“1”)){
                        sl_send_reply(“500″,”Error translating MD5->AKA authorized REGISTER”);
                        exit;
                }
        }else{
                if (!Gw_MD5_to_AKA(“0”)){
                        sl_send_reply(“500″,”Error translating MD5->AKA unauthorized REGISTER”);
                        exit;
                }
        }
        t_on_reply(“REGISTER_reply”);
        #t_on_failure(“REGISTER_failure”);
        route(PCSCF);
        exit;
}
onreply_route[REGISTER_reply]
{
        if (t_check_status(“401”)){
                if (!Gw_AKA_to_MD5()){
                        log(1,”Error translating from AKA to MD5″);
                        #sl_send_reply(“500″,”Error translating AKA->MD5 challenge”);
                        break;
                }
        }
}
route[PCSCF]
{
    if (method==”INVITE” ||method==”SUBCRIBE”){
                record_route();
        }
        if (method==”ACK”||method==”BYE”||method==”NOTIFY”){
                loose_route();
                t_relay();
                exit;
        }
        loose_route();
        if (!search(“.*sip:127.0.0.1:3060.*”)||method==”REGISTER”) {
                if (!t_relay_to_udp(“127.0.0.1″,”4060”)) {
                    sl_send_reply(“500″,”Error forwarding to P-CSCF”);
                }
        } else {
            if (!t_relay()) {
             sl_reply_error();
        }
    }
    exit;
}