diff options
Diffstat (limited to 'src/modemman.c')
-rw-r--r-- | src/modemman.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/modemman.c b/src/modemman.c index a2fbf12..8fefbfa 100644 --- a/src/modemman.c +++ b/src/modemman.c @@ -27,11 +27,13 @@ #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <libdaemon/dlog.h> #include "modemman.h" #include "modem.h" +#include "main.h" #define MAX_CHANNELS 10 #define TTY_START 12 @@ -44,10 +46,10 @@ struct llist { static struct llist *llist = NULL; static int n_llist = 0; -static void modem_try_open(const char *dev) { +static void modem_try_open(const char *dev, const char *msn) { struct modem *m; - if ((m = modem_open(dev))) { + if ((m = modem_open(dev, msn))) { struct llist *l = malloc(sizeof(struct llist)); assert(l); @@ -58,6 +60,47 @@ static void modem_try_open(const char *dev) { } } +const char *get_listen_msn(int i) { + static int buf_valid = 0; + static char buf[256]; + static char *buf_ptr[MAX_CHANNELS]; + static int n_buf_ptr; + + if (!args.listen_arg) + return "*"; + + if (!buf_valid) { + char *p; + + strncpy(buf, args.listen_arg, sizeof(buf)-1); + buf[sizeof(buf)-1] = 0; + + for (p = buf; *p; p++) + if (*p == ',') + *p = ';'; + + for (p = buf, n_buf_ptr = 0; n_buf_ptr < MAX_CHANNELS;) { + int l; + buf_ptr[n_buf_ptr++] = p; + l = strcspn(p, ":"); + if (p[l] == 0) + break; + + p[l] = 0; + p+=l+1; + } + + buf_valid = 1; + } + + assert(n_buf_ptr > 0); + + if (i >= n_buf_ptr) + i = n_buf_ptr -1; + + return buf_ptr[i]; +} + int modem_manager_init(int channels) { int i; @@ -69,7 +112,7 @@ int modem_manager_init(int channels) { for (i = TTY_START; i < TTY_START+MAX_CHANNELS && n_llist < channels; i++) { char d[PATH_MAX]; snprintf(d, sizeof(d), "/dev/ttyI%i", i); - modem_try_open(d); + modem_try_open(d, get_listen_msn(n_llist)); } if (n_llist < channels) { |