FreeCalypso > hg > osmo-playpen
view smsc-daemon/main.c @ 22:7bfe3e21eaae default tip
top Makefile: add ctrl-client
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 17 Dec 2023 08:53:35 +0000 |
parents | 9ff041d85da5 |
children |
line wrap: on
line source
/* * This C module is part of proto-smsc-daemon concoction, a prototype/test * implementation of a GSUP-based GSM SMSC. It is based on the osmo-euse-demo * program from OsmoHLR package. * * proto-smsc-daemon author: Mychaela N. Falconia <falcon@freecalypso.org>, * no copyright. * * osmo-euse-demo author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+ */ #include <ctype.h> #include <string.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <errno.h> #include <signal.h> #include <osmocom/core/msgb.h> #include <osmocom/core/select.h> #include <osmocom/core/application.h> #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> #include <osmocom/gsm/gsup.h> #include <osmocom/gsm/ipa.h> #include <osmocom/gsupclient/gsup_client.h> #include "logging.h" extern int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); extern void setup_local_socket(const char *pathname); #define MAX_IPA_NAME 31 FILE *smsc_log_file; char smsc_ipa_name[MAX_IPA_NAME+1]; struct ipaccess_unit gsup_ipa_dev; struct osmo_gsup_client *g_gc; static struct log_info_cat default_categories[] = { [DMAIN] = { .name = "DMAIN", .description = "Main Program", .enabled = 1, .loglevel = LOGL_DEBUG, }, }; static const struct log_info smsc_log_info = { .cat = default_categories, .num_cat = ARRAY_SIZE(default_categories), }; static void set_ipa_name(const char *arg) { if (strlen(arg) > MAX_IPA_NAME) { fprintf(stderr, "error: IPA name argument is too long\n"); exit(1); } strcpy(smsc_ipa_name, arg); } static void open_log_file(const char *filename) { smsc_log_file = fopen(filename, "a"); if (!smsc_log_file) { perror(filename); exit(1); } } static void build_ipa_dev(void) { gsup_ipa_dev.unit_name = "SMSC"; gsup_ipa_dev.serno = smsc_ipa_name; } int main(int argc, char **argv) { const char *server_host; uint16_t server_port = OSMO_GSUP_PORT; void *ctx = talloc_named_const(NULL, 0, "proto-smsc"); osmo_init_logging2(ctx, &smsc_log_info); if (argc < 4 || argc > 5) { fprintf(stderr, "usage: %s hlr-ip ipa-name logfile [local-socket]\n", argv[0]); exit(1); } server_host = argv[1]; set_ipa_name(argv[2]); open_log_file(argv[3]); build_ipa_dev(); g_gc = osmo_gsup_client_create2(ctx, &gsup_ipa_dev, server_host, server_port, gsupc_read_cb, NULL); if (!g_gc) { fprintf(stderr, "error: osmo_gsup_client_create2() failed\n"); exit(1); } if (argv[4]) setup_local_socket(argv[4]); while (1) { osmo_select_main(0); } exit(0); }