gsm: Verify the MNCC_VERSION of the BSC/MS and close the socket on mismatch
[lcr.git] / gsm.cpp
diff --git a/gsm.cpp b/gsm.cpp
index a4a220e..ee46ff6 100644 (file)
--- a/gsm.cpp
+++ b/gsm.cpp
@@ -20,7 +20,6 @@ extern "C" {
 #include "gsm_audio.h"
 }
 
-#include <mISDN/mISDNcompat.h>
 #include <assert.h>
 
 #define SOCKET_RETRY_TIMER     5
@@ -140,10 +139,10 @@ void Pgsm::send_mncc_rtp_connect(void)
                nrtp->payload_msg_type = GSM_TCHF_FRAME_EFR;
                break;
        case MEDIA_TYPE_AMR:
-               nrtp->payload_msg_type = GSM_TCHF_FRAME_AMR;
+               nrtp->payload_msg_type = GSM_TCH_FRAME_AMR;
                break;
        case MEDIA_TYPE_GSM_HR:
-               nrtp->payload_msg_type = GSM_TCHF_FRAME_HR;
+               nrtp->payload_msg_type = GSM_TCHH_FRAME;
                break;
        }
        nrtp->payload_type = p_g_payload_type;
@@ -230,7 +229,7 @@ void Pgsm::frame_receive(void *arg)
        if (!p_g_decoder)
                return;
 
-       if (frame->msg_type != GSM_TCHF_BAD_FRAME) {
+       if (frame->msg_type != GSM_BAD_FRAME) {
                if ((frame->data[0]>>4) != 0xd)
                        PERROR("received GSM frame with wrong magig 0x%x\n", frame->data[0]>>4);
        
@@ -376,12 +375,8 @@ void Pgsm::modify_lchan(int media_type)
                add_trace("speech", "version", "AMR given");
                mode->lchan_mode = 0x41; /* GSM V3 */
                break;
-       case MEDIA_TYPE_GSM_HR:
-               add_trace("speech", "version", "Half Rate given");
-               mode->lchan_mode = 0x05; /* GSM V1 HR */
-               break;
        default:
-               add_trace("speech", "version", "Full Rate given");
+               add_trace("speech", "version", "Full/Half Rate given");
                mode->lchan_mode = 0x01; /* GSM V1 */
        }
        mode->lchan_type = 0x02; /* FIXME: unused */
@@ -1114,6 +1109,7 @@ static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
        int rc;
        static char buf[sizeof(struct gsm_mncc)+1024];
        struct gsm_mncc *mncc_prim = (struct gsm_mncc *) buf;
+       struct gsm_mncc_hello *hello = (struct gsm_mncc_hello *) buf;
 
        memset(buf, 0, sizeof(buf));
        rc = recv(lfd->fd, buf, sizeof(buf), 0);
@@ -1122,6 +1118,17 @@ static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
        if (rc < 0)
                return rc;
 
+       /* TODO: size check? */
+       switch (mncc_prim->msg_type) {
+       case MNCC_SOCKET_HELLO:
+               if (hello->version != MNCC_SOCK_VERSION) {
+                       PERROR("MNCC version different. BSC version is %u\n", hello->version);
+                       mncc_fd_close(lcr_gsm, lfd);
+                       return 0;
+               }
+               break;
+       }
+
        /* Hand the MNCC message into LCR */
        switch (lcr_gsm->type) {
 #ifdef WITH_GSM_BS