summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/event.c33
-rw-r--r--src/util/event.h1
-rw-r--r--src/util/libgsmd-tool.c3
3 files changed, 37 insertions, 0 deletions
diff --git a/src/util/event.c b/src/util/event.c
index ae5ca7b..e19fe28 100644
--- a/src/util/event.c
+++ b/src/util/event.c
@@ -22,12 +22,15 @@
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <common/linux_list.h>
#include <libgsmd/libgsmd.h>
#include <libgsmd/event.h>
#include <libgsmd/sms.h>
+#define STDIN_BUF_SIZE 1024
+
static int incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
printf("EVENT: Incoming call type = %u\n", aux->u.call.type);
@@ -288,3 +291,33 @@ int event_init(struct lgsm_handle *lh)
return rc;
}
+int event_main(struct lgsm_handle *lgsmh)
+{
+ int rc;
+ char buf[STDIN_BUF_SIZE+1];
+ fd_set readset;
+ int gsm_fd = lgsm_fd(lgsmh);
+
+ FD_ZERO(&readset);
+
+ while (1) {
+ FD_SET(gsm_fd, &readset);
+
+ rc = select(gsm_fd+1, &readset, NULL, NULL, NULL);
+ if (rc <= 0)
+ break;
+ if (FD_ISSET(gsm_fd, &readset)) {
+ /* we've received something on the gsmd socket, pass it
+ * on to the library */
+ rc = read(gsm_fd, buf, sizeof(buf));
+ if (rc <= 0) {
+ printf("ERROR reading from gsm_fd\n");
+ break;
+ }
+ rc = lgsm_handle_packet(lgsmh, buf, rc);
+ if (rc < 0)
+ printf("ERROR processing packet: %d(%s)\n", rc, strerror(-rc));
+ }
+ }
+ return 0;
+}
diff --git a/src/util/event.h b/src/util/event.h
index 6901a2d..5caaaba 100644
--- a/src/util/event.h
+++ b/src/util/event.h
@@ -1,2 +1,3 @@
extern int event_init(struct lgsm_handle *lh);
+extern int event_main(struct lgsm_handle *lh);
diff --git a/src/util/libgsmd-tool.c b/src/util/libgsmd-tool.c
index 5fb1eca..2d34c3a 100644
--- a/src/util/libgsmd-tool.c
+++ b/src/util/libgsmd-tool.c
@@ -156,6 +156,9 @@ int main(int argc, char **argv)
case MODE_SHELL:
shell_main(lgsmh, shellwait);
break;
+ case MODE_EVENTLOG:
+ event_main(lgsmh);
+ break;
}
exit(0);
personal git repositories of Harald Welte. Your mileage may vary