FreeCalypso > hg > osmo-playpen
annotate smsc-daemon/main.c @ 8:81386a48c463
smsc-daemon: set source_name in GSUP replies
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 25 Aug 2023 14:56:52 -0800 |
parents | 22ddb71f6883 |
children | d9db8661d9f3 |
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> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <stdlib.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <errno.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <signal.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include <osmocom/core/msgb.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include <osmocom/core/select.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include <osmocom/core/application.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include <osmocom/core/utils.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include <osmocom/core/logging.h> |
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 #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
|
26 #include <osmocom/gsm/ipa.h> |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include <osmocom/gsupclient/gsup_client.h> |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "logging.h" |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 extern int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
34 #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
|
35 |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 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
|
37 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
|
38 struct ipaccess_unit gsup_ipa_dev; |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 struct osmo_gsup_client *g_gc; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static struct log_info_cat default_categories[] = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 [DMAIN] = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 .name = "DMAIN", |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 .description = "Main Program", |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 .enabled = 1, .loglevel = LOGL_DEBUG, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 }, |
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 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 static const struct log_info smsc_log_info = { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 .cat = default_categories, |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 .num_cat = ARRAY_SIZE(default_categories), |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 }; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
54 static void set_ipa_name(const char *arg) |
3
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 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
|
57 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
|
58 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
60 strcpy(smsc_ipa_name, arg); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
63 static void open_log_file(const char *filename) |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 smsc_log_file = fopen(filename, "a"); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!smsc_log_file) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 perror(filename); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
72 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
|
73 { |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
74 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
|
75 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
|
76 } |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
77 |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 int main(int argc, char **argv) |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 char *server_host = "127.0.0.1"; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 uint16_t server_port = OSMO_GSUP_PORT; |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 void *ctx = talloc_named_const(NULL, 0, "proto-smsc"); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 osmo_init_logging2(ctx, &smsc_log_info); |
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 if (argc != 3) { |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
87 fprintf(stderr, "usage: %s ipa-name logfile\n", argv[0]); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
7
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
90 set_ipa_name(argv[1]); |
3
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 open_log_file(argv[2]); |
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 build_ipa_dev(); |
22ddb71f6883
smsc-daemon: convert to setting IPA name on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
94 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
|
95 server_port, gsupc_read_cb, NULL); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 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
|
97 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
|
98 exit(1); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 while (1) { |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 osmo_select_main(0); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 exit(0); |
8680979baeb1
smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |