Added GSM IMSI dialing by using dialing "imsi-<number>".
[lcr.git] / main.c
diff --git a/main.c b/main.c
index 0a85f46..522b214 100644 (file)
--- a/main.c
+++ b/main.c
@@ -314,6 +314,7 @@ int main(int argc, char *argv[])
        if (!(strcasecmp(argv[1],"fork")))
        {
                pid_t pid;
+               FILE *pidfile;
 
                /* do daemon fork */
                pid = fork();
@@ -344,6 +345,14 @@ int main(int argc, char *argv[])
                        exit(0);
                }
                nooutput = 1;
+
+               /* write pid file */
+               pidfile = fopen("/var/run/lcr.pid","w");
+               if (pidfile)
+               {
+                       fprintf(pidfile, "%d\n", getpid());
+                       fclose(pidfile);
+               }
        } else
        /* if not start */
        if (!!strcasecmp(argv[1],"start"))
@@ -385,6 +394,21 @@ int main(int argc, char *argv[])
                goto free;
        }
 
+#ifdef WITH_GSM
+       /* handle gsm */
+       if (options.gsm && gsm_init())
+       {
+               fprintf(stderr, "GSM initialization failed.\n");
+               goto free;
+       }
+#else
+       if (options.gsm)
+       {
+               fprintf(stderr, "GSM is enabled, but not compiled. Use --with-gsm while configure!\n");
+               goto free;
+       }
+#endif
+
        /* read interfaces and open ports */
        if (!read_interfaces())
        {
@@ -605,6 +629,15 @@ BUDETECT
                        all_idle = 0;
 BUDETECT
 
+#ifdef WITH_GSM
+               /* handle gsm */
+               if (options.gsm)
+                       while(handle_gsm())
+                               all_idle = 0;
+#endif
+
+BUDETECT
+
 #if 0
                /* check for child to exit (eliminate zombies) */
                if (waitpid(-1, NULL, WNOHANG) > 0)
@@ -737,6 +770,12 @@ free:
        if (created_misdn)
                mISDN_deinitialize();
 
+#ifdef WITH_GSM
+       /* free gsm */
+       if (options.gsm)
+               gsm_exit(0);
+#endif
+
        /* display memory leak */
 #define MEMCHECK(a, b) \
        if (b) \