comparison smsc-daemon/record_mo.c @ 3:8680979baeb1

smsc-daemon: first version put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 17 Aug 2023 22:56:49 -0800
parents
children cef4677a4cf8
comparison
equal deleted inserted replaced
2:2067c55e2c79 3:8680979baeb1
1 /*
2 * This C module is part of proto-smsc-daemon concoction, a prototype/test
3 * implementation of a GSUP-based GSM SMSC. It is based on the osmo-demo-euse
4 * program from OsmoHLR package.
5 *
6 * proto-smsc-daemon author: Mychaela N. Falconia <falcon@freecalypso.org>,
7 * no copyright.
8 *
9 * osmo-demo-euse author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+
10 */
11
12 #include <ctype.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <errno.h>
17 #include <signal.h>
18 #include <time.h>
19
20 #include <osmocom/core/msgb.h>
21 #include <osmocom/core/select.h>
22 #include <osmocom/core/application.h>
23 #include <osmocom/core/utils.h>
24 #include <osmocom/core/logging.h>
25
26 #include <osmocom/gsm/gsup.h>
27 #include <osmocom/gsm/gsm48_ie.h>
28
29 #include <osmocom/gsupclient/gsup_client.h>
30
31 #include "logging.h"
32
33 extern FILE *smsc_log_file;
34
35 static void format_addr(char *ie_name, enum osmo_gsup_sms_sm_rp_oda_t type,
36 size_t len, const uint8_t *data)
37 {
38 int skip_byte;
39 uint8_t lv_buf[255];
40 char decode_buf[520];
41
42 fprintf(smsc_log_file, "%s: ", ie_name);
43 switch (type) {
44 case OSMO_GSUP_SMS_SM_RP_ODA_IMSI:
45 fputs("IMSI ", smsc_log_file);
46 skip_byte = 0;
47 break;
48 case OSMO_GSUP_SMS_SM_RP_ODA_MSISDN:
49 fprintf(smsc_log_file, "MSISDN TON=%u NPI=%u ",
50 (data[0] & 0x70) >> 4, data[0] & 0x0F);
51 skip_byte = 1;
52 break;
53 case OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR:
54 fprintf(smsc_log_file, "SMSC TON=%u NPI=%u ",
55 (data[0] & 0x70) >> 4, data[0] & 0x0F);
56 skip_byte = 1;
57 break;
58 case OSMO_GSUP_SMS_SM_RP_ODA_NULL:
59 fputs("NULL\n", smsc_log_file);
60 return;
61 default:
62 fputs("Invalid!\n", smsc_log_file);
63 return;
64 }
65 OSMO_ASSERT(len >= 1 && len <= 254);
66 lv_buf[0] = len - skip_byte;
67 memcpy(lv_buf + 1, data + skip_byte, len - skip_byte);
68 gsm48_decode_bcd_number2(decode_buf, sizeof decode_buf,
69 lv_buf, sizeof lv_buf, 0);
70 fprintf(smsc_log_file, "%s\n", decode_buf[0] ? decode_buf : "<empty>");
71 }
72
73 void record_mo_sm(struct osmo_gsup_message *gmsg)
74 {
75 time_t curtime;
76 struct tm *tm;
77 const uint8_t *dp, *endp;
78
79 time(&curtime);
80 tm = gmtime(&curtime);
81 fprintf(smsc_log_file, "\n%d-%02d-%02dT%02d:%02d:%02dZ Rx MO SM\n",
82 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
83 tm->tm_hour, tm->tm_min, tm->tm_sec);
84 fprintf(smsc_log_file, "IMSI: %s\n", gmsg->imsi);
85 fprintf(smsc_log_file, "SM-RP-MR: 0x%02X\n", gmsg->sm_rp_mr);
86 format_addr("SM-RP-DA", gmsg->sm_rp_da_type, gmsg->sm_rp_da_len,
87 gmsg->sm_rp_da);
88 format_addr("SM-RP-OA", gmsg->sm_rp_oa_type, gmsg->sm_rp_oa_len,
89 gmsg->sm_rp_oa);
90 fprintf(smsc_log_file, "SM-RP-UI: %u bytes\n", gmsg->sm_rp_ui_len);
91 dp = gmsg->sm_rp_ui;
92 endp = dp + gmsg->sm_rp_ui_len;
93 while (dp < endp)
94 fprintf(smsc_log_file, "%02X", *dp++);
95 putc('\n', smsc_log_file);
96 }