view smsc-sendmt/smsc_addr.c @ 18:9c2c1444dca9

doc/Proto-SMSC-testing: OS#6135 patches have been merged
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 12:47:12 -0800
parents 7543aa173634
children
line wrap: on
line source

/*
 * This module handles the parsing and GSUP encoding of our SMSC address,
 * which we need to send to the MSC and ultimately to the MS as SM-RP-OA.
 */

#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/gsup.h>

static char smsc_addr_num[21];	/* maximum of 20 digits per GSM 04.11 */
static uint8_t smsc_addr_ton_npi;
static uint8_t smsc_addr_bcd[12];

void parse_smsc_addr_arg(const char *arg)
{
	const char *cp;
	char *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);
		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;
}

void encode_smsc_addr(struct osmo_gsup_message *gmsg)
{
	gsm48_encode_bcd_number(smsc_addr_bcd, 11, 1, smsc_addr_num);
	smsc_addr_bcd[1] = smsc_addr_ton_npi;
	gmsg->sm_rp_oa = smsc_addr_bcd + 1;
	gmsg->sm_rp_oa_len = smsc_addr_bcd[0];
}