FreeCalypso > hg > osmo-playpen
view smsc-daemon/record_mo.c @ 5:cef4677a4cf8
smsc-daemon: the starting program is called osmo-euse-demo
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 25 Aug 2023 14:07:41 -0800 |
parents | 8680979baeb1 |
children | dfe99a061249 |
line wrap: on
line source
/* * This C module is part of proto-smsc-daemon concoction, a prototype/test * implementation of a GSUP-based GSM SMSC. It is based on the osmo-euse-demo * program from OsmoHLR package. * * proto-smsc-daemon author: Mychaela N. Falconia <falcon@freecalypso.org>, * no copyright. * * osmo-euse-demo author: Harald Welte <laforge@gnumonks.org>, (C) 2018, AGPL3+ */ #include <ctype.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <signal.h> #include <time.h> #include <osmocom/core/msgb.h> #include <osmocom/core/select.h> #include <osmocom/core/application.h> #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> #include <osmocom/gsm/gsup.h> #include <osmocom/gsm/gsm48_ie.h> #include <osmocom/gsupclient/gsup_client.h> #include "logging.h" extern FILE *smsc_log_file; static void format_addr(char *ie_name, enum osmo_gsup_sms_sm_rp_oda_t type, size_t len, const uint8_t *data) { int skip_byte; uint8_t lv_buf[255]; char decode_buf[520]; fprintf(smsc_log_file, "%s: ", ie_name); switch (type) { case OSMO_GSUP_SMS_SM_RP_ODA_IMSI: fputs("IMSI ", smsc_log_file); skip_byte = 0; break; case OSMO_GSUP_SMS_SM_RP_ODA_MSISDN: fprintf(smsc_log_file, "MSISDN TON=%u NPI=%u ", (data[0] & 0x70) >> 4, data[0] & 0x0F); skip_byte = 1; break; case OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR: fprintf(smsc_log_file, "SMSC TON=%u NPI=%u ", (data[0] & 0x70) >> 4, data[0] & 0x0F); skip_byte = 1; break; case OSMO_GSUP_SMS_SM_RP_ODA_NULL: fputs("NULL\n", smsc_log_file); return; default: fputs("Invalid!\n", smsc_log_file); return; } OSMO_ASSERT(len >= 1 && len <= 254); lv_buf[0] = len - skip_byte; memcpy(lv_buf + 1, data + skip_byte, len - skip_byte); gsm48_decode_bcd_number2(decode_buf, sizeof decode_buf, lv_buf, sizeof lv_buf, 0); fprintf(smsc_log_file, "%s\n", decode_buf[0] ? decode_buf : "<empty>"); } void record_mo_sm(struct osmo_gsup_message *gmsg) { time_t curtime; struct tm *tm; const uint8_t *dp, *endp; time(&curtime); tm = gmtime(&curtime); fprintf(smsc_log_file, "\n%d-%02d-%02dT%02d:%02d:%02dZ Rx MO SM\n", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); fprintf(smsc_log_file, "IMSI: %s\n", gmsg->imsi); fprintf(smsc_log_file, "SM-RP-MR: 0x%02X\n", gmsg->sm_rp_mr); format_addr("SM-RP-DA", gmsg->sm_rp_da_type, gmsg->sm_rp_da_len, gmsg->sm_rp_da); format_addr("SM-RP-OA", gmsg->sm_rp_oa_type, gmsg->sm_rp_oa_len, gmsg->sm_rp_oa); fprintf(smsc_log_file, "SM-RP-UI: %u bytes\n", gmsg->sm_rp_ui_len); dp = gmsg->sm_rp_ui; endp = dp + gmsg->sm_rp_ui_len; while (dp < endp) fprintf(smsc_log_file, "%02X", *dp++); putc('\n', smsc_log_file); }