FreeCalypso > hg > osmo-playpen
changeset 7:22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 25 Aug 2023 14:47:24 -0800 |
parents | 18b7f75fed9b |
children | 81386a48c463 |
files | smsc-daemon/main.c |
diffstat | 1 files changed, 21 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/smsc-daemon/main.c Fri Aug 25 14:28:54 2023 -0800 +++ b/smsc-daemon/main.c Fri Aug 25 14:47:24 2023 -0800 @@ -23,6 +23,7 @@ #include <osmocom/core/logging.h> #include <osmocom/gsm/gsup.h> +#include <osmocom/gsm/ipa.h> #include <osmocom/gsupclient/gsup_client.h> @@ -30,10 +31,11 @@ extern int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); -char smsc_addr_num[21]; /* maximum of 20 digits per GSM 04.11 */ -uint8_t smsc_addr_ton_npi; +#define MAX_IPA_NAME 31 + FILE *smsc_log_file; -char smsc_gsup_name[26]; +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[] = { @@ -49,44 +51,16 @@ .num_cat = ARRAY_SIZE(default_categories), }; -static void parse_smsc_addr_arg(char *arg) +static void set_ipa_name(const char *arg) { - char *cp, *dp, *endp; - unsigned ndig; - - cp = arg; - dp = smsc_addr_num; - ndig = 0; - while (isdigit(*cp)) { - if (ndig >= 20) { - fprintf(stderr, - "error: SMSC address argument exceeds GSM 04.11 limit of 20 digits\n"); - exit(1); - } - *dp++ = *cp++; - ndig++; - } - if (!ndig) { -invalid: fprintf(stderr, - "error: SMSC address argument \"%s\" is invalid\n", - arg); + if (strlen(arg) > MAX_IPA_NAME) { + fprintf(stderr, "error: IPA name argument is too long\n"); exit(1); } - if (!*cp) { - /* default to TON=1, NPI=1, i.e., a pretend Global Title */ - smsc_addr_ton_npi = 0x91; - return; - } - if (*cp++ != ',') - goto invalid; - if (!*cp) - goto invalid; - smsc_addr_ton_npi = strtoul(cp, &endp, 0); - if (*endp) - goto invalid; + strcpy(smsc_ipa_name, arg); } -static void open_log_file(char *filename) +static void open_log_file(const char *filename) { smsc_log_file = fopen(filename, "a"); if (!smsc_log_file) { @@ -95,6 +69,12 @@ } } +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) { char *server_host = "127.0.0.1"; @@ -104,17 +84,17 @@ osmo_init_logging2(ctx, &smsc_log_info); if (argc != 3) { - fprintf(stderr, "usage: %s smsc-addr logfile\n", argv[0]); + fprintf(stderr, "usage: %s ipa-name logfile\n", argv[0]); exit(1); } - parse_smsc_addr_arg(argv[1]); + set_ipa_name(argv[1]); open_log_file(argv[2]); - sprintf(smsc_gsup_name, "SMSC-%s", smsc_addr_num); - g_gc = osmo_gsup_client_create(ctx, smsc_gsup_name, server_host, + 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_create() failed\n"); + fprintf(stderr, "error: osmo_gsup_client_create2() failed\n"); exit(1); }