FreeCalypso > hg > osmo-playpen
annotate smsc-daemon/main.c @ 14:d9db8661d9f3
smsc-daemon: add local socket for sendmt
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 17:15:30 -0800 |
parents | 22ddb71f6883 |
children | 9ff041d85da5 |
rev | line source |
---|---|
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This C module is part of proto-smsc-daemon concoction, a prototype/test |
5
cef4677a4cf8
smsc-daemon: the starting program is called osmo-euse-demo
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
3 * implementation of a GSUP-based GSM SMSC. It is based on the osmo-euse-demo |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * program from OsmoHLR package. |
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 * proto-smsc-daemon author: Mychaela N. Falconia <falcon@freecalypso.org>, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * no copyright. |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * |
5
cef4677a4cf8
smsc-daemon: the starting program is called osmo-euse-demo
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
9 * osmo-euse-demo author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+ |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 */ |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <ctype.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdio.h> |
14
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
15 #include <stdint.h> |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <stdlib.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <errno.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <signal.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include <osmocom/core/msgb.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include <osmocom/core/select.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include <osmocom/core/application.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include <osmocom/core/utils.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include <osmocom/core/logging.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #include <osmocom/gsm/gsup.h> |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
27 #include <osmocom/gsm/ipa.h> |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include <osmocom/gsupclient/gsup_client.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "logging.h" |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 extern int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); |
14
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
34 extern void setup_local_socket(const char *pathname); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
36 #define MAX_IPA_NAME 31 |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
37 |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 FILE *smsc_log_file; |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
39 char smsc_ipa_name[MAX_IPA_NAME+1]; |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
40 struct ipaccess_unit gsup_ipa_dev; |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 struct osmo_gsup_client *g_gc; |
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 static struct log_info_cat default_categories[] = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 [DMAIN] = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 .name = "DMAIN", |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 .description = "Main Program", |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 .enabled = 1, .loglevel = LOGL_DEBUG, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 }, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 }; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 static const struct log_info smsc_log_info = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 .cat = default_categories, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 .num_cat = ARRAY_SIZE(default_categories), |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 }; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
56 static void set_ipa_name(const char *arg) |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
58 if (strlen(arg) > MAX_IPA_NAME) { |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
59 fprintf(stderr, "error: IPA name argument is too long\n"); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
62 strcpy(smsc_ipa_name, arg); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
65 static void open_log_file(const char *filename) |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 smsc_log_file = fopen(filename, "a"); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (!smsc_log_file) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 perror(filename); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
74 static void build_ipa_dev(void) |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
75 { |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
76 gsup_ipa_dev.unit_name = "SMSC"; |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
77 gsup_ipa_dev.serno = smsc_ipa_name; |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
78 } |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
79 |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 int main(int argc, char **argv) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 char *server_host = "127.0.0.1"; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 uint16_t server_port = OSMO_GSUP_PORT; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 void *ctx = talloc_named_const(NULL, 0, "proto-smsc"); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 osmo_init_logging2(ctx, &smsc_log_info); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
14
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
88 if (argc < 3 || argc > 4) { |
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
89 fprintf(stderr, "usage: %s ipa-name logfile [local-socket]\n", |
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
90 argv[0]); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
93 set_ipa_name(argv[1]); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 open_log_file(argv[2]); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
96 build_ipa_dev(); |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
97 g_gc = osmo_gsup_client_create2(ctx, &gsup_ipa_dev, server_host, |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 server_port, gsupc_read_cb, NULL); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (!g_gc) { |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
100 fprintf(stderr, "error: osmo_gsup_client_create2() failed\n"); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
14
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
103 if (argv[3]) |
d9db8661d9f3
smsc-daemon: add local socket for sendmt
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
104 setup_local_socket(argv[3]); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 while (1) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 osmo_select_main(0); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 exit(0); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |