FreeCalypso > hg > osmo-playpen
view smsc-sendmt/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 | 7543aa173634 |
children |
line wrap: on
line source
/* * This C module is the main for proto-smsc-sendmt, a command line utility * that constructs an MT-forwardSM.req GSUP message and shoots it over to * proto-smsc-daemon for feeding to OsmoHLR. */ #include <sys/types.h> #include <sys/socket.h> #include <ctype.h> #include <string.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <osmocom/core/msgb.h> #include <osmocom/core/utils.h> #include <osmocom/core/socket.h> #include <osmocom/gsm/gsup.h> extern void parse_smsc_addr_arg(const char *arg); extern void encode_smsc_addr(struct osmo_gsup_message *gmsg); extern int grok_imsi_user_arg(const char *arg, char *dest); extern void read_pdu_from_stdin(void); extern uint8_t tpdu_buf[]; extern unsigned tpdu_len; static const uint8_t sm_rp_mr = 0xFF; int main(int argc, char **argv) { struct osmo_gsup_message gmsg; struct msgb *msgb; int rc, sock; if (argc != 4) { fprintf(stderr, "usage: %s smsc-addr imsi socket-path\n", argv[0]); exit(1); } parse_smsc_addr_arg(argv[1]); memset(&gmsg, 0, sizeof(gmsg)); rc = grok_imsi_user_arg(argv[2], gmsg.imsi); if (rc < 0) { fprintf(stderr, "error: invalid IMSI argument\n"); exit(1); } read_pdu_from_stdin(); /* fill out the rest of GSUP msg */ gmsg.message_type = OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST; gmsg.message_class = OSMO_GSUP_MESSAGE_CLASS_SMS; gmsg.sm_rp_mr = &sm_rp_mr; gmsg.sm_rp_da_type = OSMO_GSUP_SMS_SM_RP_ODA_NULL; gmsg.sm_rp_oa_type = OSMO_GSUP_SMS_SM_RP_ODA_SMSC_ADDR; encode_smsc_addr(&gmsg); gmsg.sm_rp_ui = tpdu_buf; gmsg.sm_rp_ui_len = tpdu_len; /* pack it into an msgb */ msgb = msgb_alloc_headroom(4000, 64, "sendmt"); if (!msgb) { fprintf(stderr, "error: unable to allocate msgb\n"); exit(1); } rc = osmo_gsup_encode(msgb, &gmsg); if (rc < 0) { fprintf(stderr, "error: osmo_gsup_encode() failed\n"); exit(1); } /* send it off via UNIX socket */ sock = osmo_sock_unix_init(SOCK_DGRAM, 0, argv[3], OSMO_SOCK_F_CONNECT); if (sock < 0) { fprintf(stderr, "error connecting to %s\n", argv[3]); exit(1); } rc = send(sock, msgb->data, msgb->len, 0); if (rc < 0) { perror("sending dgram on socket"); exit(1); } exit(0); }