annotate smsc-daemon/record_mo.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 f9a83463ab52
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include <time.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>
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include <osmocom/gsm/gsm48_ie.h>
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 FILE *smsc_log_file;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 static void format_addr(char *ie_name, enum osmo_gsup_sms_sm_rp_oda_t type,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 size_t len, const uint8_t *data)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 int skip_byte;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 uint8_t lv_buf[255];
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char decode_buf[520];
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(smsc_log_file, "%s: ", ie_name);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 switch (type) {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case OSMO_GSUP_SMS_SM_RP_ODA_IMSI:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fputs("IMSI ", smsc_log_file);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 skip_byte = 0;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case OSMO_GSUP_SMS_SM_RP_ODA_MSISDN:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(smsc_log_file, "MSISDN TON=%u NPI=%u ",
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 (data[0] & 0x70) >> 4, data[0] & 0x0F);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 skip_byte = 1;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fprintf(smsc_log_file, "SMSC TON=%u NPI=%u ",
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 (data[0] & 0x70) >> 4, data[0] & 0x0F);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 skip_byte = 1;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 break;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case OSMO_GSUP_SMS_SM_RP_ODA_NULL:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fputs("NULL\n", smsc_log_file);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 default:
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fputs("Invalid!\n", smsc_log_file);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return;
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 OSMO_ASSERT(len >= 1 && len <= 254);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 lv_buf[0] = len - skip_byte;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 memcpy(lv_buf + 1, data + skip_byte, len - skip_byte);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 gsm48_decode_bcd_number2(decode_buf, sizeof decode_buf,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 lv_buf, sizeof lv_buf, 0);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 fprintf(smsc_log_file, "%s\n", decode_buf[0] ? decode_buf : "<empty>");
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 void record_mo_sm(struct osmo_gsup_message *gmsg)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 {
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 time_t curtime;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 struct tm *tm;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 const uint8_t *dp, *endp;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 time(&curtime);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 tm = gmtime(&curtime);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fprintf(smsc_log_file, "\n%d-%02d-%02dT%02d:%02d:%02dZ Rx MO SM\n",
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 tm->tm_hour, tm->tm_min, tm->tm_sec);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 fprintf(smsc_log_file, "IMSI: %s\n", gmsg->imsi);
10
f9a83463ab52 smsc-daemon: receiving MO SMS actually works
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
85 fprintf(smsc_log_file, "SM-RP-MR: 0x%02X\n", *gmsg->sm_rp_mr);
3
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 format_addr("SM-RP-DA", gmsg->sm_rp_da_type, gmsg->sm_rp_da_len,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 gmsg->sm_rp_da);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 format_addr("SM-RP-OA", gmsg->sm_rp_oa_type, gmsg->sm_rp_oa_len,
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 gmsg->sm_rp_oa);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 fprintf(smsc_log_file, "SM-RP-UI: %u bytes\n", gmsg->sm_rp_ui_len);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 dp = gmsg->sm_rp_ui;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 endp = dp + gmsg->sm_rp_ui_len;
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 while (dp < endp)
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 fprintf(smsc_log_file, "%02X", *dp++);
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 putc('\n', smsc_log_file);
10
f9a83463ab52 smsc-daemon: receiving MO SMS actually works
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
96 fflush(smsc_log_file);
3
8680979baeb1 smsc-daemon: first version put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }