Fix: Make GSM BS compile without SIP support
[lcr.git] / sip.cpp
diff --git a/sip.cpp b/sip.cpp
index c6ddde3..c6670fc 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -24,8 +24,8 @@ su_home_t     sip_home[1];
 
 struct sip_inst {
        char                    interface_name[64];
-       char                    local_ip[16];
-       char                    remote_ip[16];
+       char                    local_peer[32];
+       char                    remote_peer[32];
        su_root_t               *root;
        nua_t                   *nua;
 };
@@ -62,6 +62,8 @@ Psip::Psip(int type, char *portname, struct port_settings *settings, struct inte
        p_s_rtp_tx_action = 0;
 
        PDEBUG(DEBUG_SIP, "Created new Psip(%s).\n", portname);
+       if (!p_s_sip_inst)
+               FATAL("No SIP instance for interface\n");
 }
 
 
@@ -77,7 +79,7 @@ Psip::~Psip()
        rtp_close();
 }
 
-const char *media_type2name(uint8_t media_type) {
+static const char *media_type2name(uint8_t media_type) {
        switch (media_type) {
        case MEDIA_TYPE_ULAW:
                return "PCMU";
@@ -256,6 +258,11 @@ we only support alaw and ulaw!
        n = payload_len;
        from = payload;
        to = payload;
+       if (psip->p_echotest) {
+               /* echo rtp data we just received */
+               psip->rtp_send_frame(from, n, (options.law=='a')?PAYLOAD_TYPE_ALAW:PAYLOAD_TYPE_ULAW);
+               return 0;
+       }
        while(n--)
                *to++ = flip[*from++];
        psip->bridge_tx(payload, payload_len);
@@ -278,7 +285,8 @@ static int rtp_sock_callback(struct lcr_fd *fd, unsigned int what, void *instanc
 //                     psip->rtp_shutdown();
                        return len;
                }
-               rc = rtp_decode(psip, buffer, len);
+               if (psip->p_s_rtp_is_connected)
+                       rc = rtp_decode(psip, buffer, len);
        }
 
        return rc;
@@ -872,8 +880,9 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
        char from[128];
        char to[128];
-       const char *local = inst->local_ip;
-       const char *remote = inst->remote_ip;
+       const char *local = inst->local_peer;
+       char local_ip[16];
+       const char *remote = inst->remote_peer;
        char sdp_str[512], pt_str[32];
        struct in_addr ia;
        struct epoint_list *epointlist;
@@ -941,8 +950,15 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
        end_trace();
 
        if (!p_s_rtp_ip_local) {
-               PDEBUG(DEBUG_SIP, "RTP local IP not known, so we use our local SIP ip %s\n", local);
-               inet_pton(AF_INET, local, &p_s_rtp_ip_local);
+               char *p;
+
+               /* extract IP from local peer */
+               SCPY(local_ip, local);
+               p = strchr(local_ip, ':');
+               if (p)
+                       *p = '\0';
+               PDEBUG(DEBUG_SIP, "RTP local IP not known, so we use our local SIP ip %s\n", local_ip);
+               inet_pton(AF_INET, local_ip, &p_s_rtp_ip_local);
                p_s_rtp_ip_local = ntohl(p_s_rtp_ip_local);
        }
        ia.s_addr = htonl(p_s_rtp_ip_local);
@@ -1810,11 +1826,12 @@ void Psip::rtp_shutdown(void)
 int sip_init_inst(struct interface *interface)
 {
        struct sip_inst *inst = (struct sip_inst *) MALLOC(sizeof(*inst));
+       char local[64];
 
        interface->sip_inst = inst;
        SCPY(inst->interface_name, interface->name);
-       SCPY(inst->local_ip, interface->sip_local_ip);
-       SCPY(inst->remote_ip, interface->sip_remote_ip);
+       SCPY(inst->local_peer, interface->sip_local_peer);
+       SCPY(inst->remote_peer, interface->sip_remote_peer);
 
        /* init root object */
        inst->root = su_root_create(inst);
@@ -1824,7 +1841,10 @@ int sip_init_inst(struct interface *interface)
                return -EINVAL;
        }
 
-       inst->nua = nua_create(inst->root, sip_callback, inst, TAG_NULL());
+       SPRINT(local, "sip:%s",inst->local_peer);
+       if (!strchr(inst->local_peer, ':'))
+               SCAT(local, ":5060");
+       inst->nua = nua_create(inst->root, sip_callback, inst, NUTAG_URL(local), TAG_END());
        if (!inst->nua) {
                PERROR("Failed to create SIP stack object\n");
                sip_exit_inst(interface);