FreeCalypso > hg > osmo-playpen
annotate smsc-sendmt/smsc_addr.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 | 7543aa173634 |
children |
rev | line source |
---|---|
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
2 * This module handles the parsing and GSUP encoding of our SMSC address, |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
3 * which we need to send to the MSC and ultimately to the MS as SM-RP-OA. |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
9 #include <stdint.h> |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
12 #include <osmocom/gsm/gsm48_ie.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
13 #include <osmocom/gsm/gsup.h> |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
15 static char smsc_addr_num[21]; /* maximum of 20 digits per GSM 04.11 */ |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
16 static uint8_t smsc_addr_ton_npi; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
17 static uint8_t smsc_addr_bcd[12]; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
18 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
19 void parse_smsc_addr_arg(const char *arg) |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
21 const char *cp; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
22 char *dp, *endp; |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned ndig; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cp = arg; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 dp = smsc_addr_num; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ndig = 0; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 while (isdigit(*cp)) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (ndig >= 20) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fprintf(stderr, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 "error: SMSC address argument exceeds GSM 04.11 limit of 20 digits\n"); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 *dp++ = *cp++; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 ndig++; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (!ndig) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 invalid: fprintf(stderr, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 "error: SMSC address argument \"%s\" is invalid\n", |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 arg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (!*cp) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 /* default to TON=1, NPI=1, i.e., a pretend Global Title */ |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 smsc_addr_ton_npi = 0x91; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (*cp++ != ',') |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 goto invalid; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (!*cp) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 goto invalid; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 smsc_addr_ton_npi = strtoul(cp, &endp, 0); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (*endp) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 goto invalid; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
56 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
57 void encode_smsc_addr(struct osmo_gsup_message *gmsg) |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
58 { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
59 gsm48_encode_bcd_number(smsc_addr_bcd, 11, 1, smsc_addr_num); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
60 smsc_addr_bcd[1] = smsc_addr_ton_npi; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
61 gmsg->sm_rp_oa = smsc_addr_bcd + 1; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
62 gmsg->sm_rp_oa_len = smsc_addr_bcd[0]; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
63 } |