FreeCalypso > hg > osmo-playpen
annotate smsc-sendmt/main.c @ 12:7543aa173634
proto-smsc-sendmt program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 16:36:28 -0800 |
parents | |
children |
rev | line source |
---|---|
12
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C module is the main for proto-smsc-sendmt, a command line utility |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * that constructs an MT-forwardSM.req GSUP message and shoots it over to |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * proto-smsc-daemon for feeding to OsmoHLR. |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <ctype.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <unistd.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <errno.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <osmocom/core/msgb.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <osmocom/core/utils.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include <osmocom/core/socket.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include <osmocom/gsm/gsup.h> |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern void parse_smsc_addr_arg(const char *arg); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 extern void encode_smsc_addr(struct osmo_gsup_message *gmsg); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 extern int grok_imsi_user_arg(const char *arg, char *dest); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern void read_pdu_from_stdin(void); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 extern uint8_t tpdu_buf[]; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 extern unsigned tpdu_len; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static const uint8_t sm_rp_mr = 0xFF; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int main(int argc, char **argv) |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 struct osmo_gsup_message gmsg; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 struct msgb *msgb; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 int rc, sock; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (argc != 4) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 fprintf(stderr, "usage: %s smsc-addr imsi socket-path\n", |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 argv[0]); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 parse_smsc_addr_arg(argv[1]); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 memset(&gmsg, 0, sizeof(gmsg)); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rc = grok_imsi_user_arg(argv[2], gmsg.imsi); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc < 0) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(stderr, "error: invalid IMSI argument\n"); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 read_pdu_from_stdin(); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 /* fill out the rest of GSUP msg */ |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 gmsg.message_type = OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 gmsg.message_class = OSMO_GSUP_MESSAGE_CLASS_SMS; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 gmsg.sm_rp_mr = &sm_rp_mr; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 gmsg.sm_rp_da_type = OSMO_GSUP_SMS_SM_RP_ODA_NULL; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 gmsg.sm_rp_oa_type = OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 encode_smsc_addr(&gmsg); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 gmsg.sm_rp_ui = tpdu_buf; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 gmsg.sm_rp_ui_len = tpdu_len; |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /* pack it into an msgb */ |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 msgb = msgb_alloc_headroom(4000, 64, "sendmt"); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (!msgb) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 fprintf(stderr, "error: unable to allocate msgb\n"); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 rc = osmo_gsup_encode(msgb, &gmsg); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (rc < 0) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 fprintf(stderr, "error: osmo_gsup_encode() failed\n"); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 /* send it off via UNIX socket */ |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 sock = osmo_sock_unix_init(SOCK_DGRAM, 0, argv[3], OSMO_SOCK_F_CONNECT); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (sock < 0) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, "error connecting to %s\n", argv[3]); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 rc = send(sock, msgb->data, msgb->len, 0); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (rc < 0) { |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 perror("sending dgram on socket"); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 exit(1); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(0); |
7543aa173634
proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |