view smpp-send/build_pdu.c @ 256:63252528a56c

sip-out: add CDR log line
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 15 Aug 2023 10:11:51 -0800
parents 243ed87880a1
children
line wrap: on
line source

/*
 * The function in this module constructs SMPP submit_sm PDUs
 * from input messages.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "error.h"

extern char src_addr[21], dest_addr[21];
extern u_char src_ton, src_npi, dest_ton, dest_npi;
extern u_char esm_class, pid_byte, dcs_byte;
extern u_char prio_flag, reg_deliv, replace_flag;

extern int input_lineno;
extern char *trx_socket;

void
build_submit_sm(payload, payload_len, udhi)
	u_char *payload;
	unsigned payload_len;
{
	u_char pdu[512], *dp, esm_class_inst;
	unsigned pdu_len, slen;

	/* sanity checks first */
	if (!src_addr[0]) {
		fprintf(stderr, ERR_PREFIX "src address is not set\n",
			input_lineno);
		exit(1);
	}
	if (!dest_addr[0]) {
		fprintf(stderr, ERR_PREFIX "dest address is not set\n",
			input_lineno);
		exit(1);
	}
	/* proceed */
	dp = pdu + 4;		/* length will be filled last */
	/* command_id */
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0x04;		/* submit_sm */
	/* empty command_status */
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0;
	/* dummy sequence_number (will be overwritten by smpp-trx-sa) */
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0;
	*dp++ = 0;
	/* mandatory params */
	*dp++ = 0;		/* empty service_type */
	*dp++ = src_ton;
	*dp++ = src_npi;
	slen = strlen(src_addr) + 1;
	bcopy(src_addr, dp, slen);
	dp += slen;
	*dp++ = dest_ton;
	*dp++ = dest_npi;
	slen = strlen(dest_addr) + 1;
	bcopy(dest_addr, dp, slen);
	dp += slen;
	esm_class_inst = esm_class;
	if (udhi)
		esm_class_inst |= 0x40;
	*dp++ = esm_class_inst;
	*dp++ = pid_byte;
	*dp++ = prio_flag;
	*dp++ = 0;		/* empty schedule_delivery_time */
	*dp++ = 0;		/* empty validity_period */
	*dp++ = reg_deliv;
	*dp++ = replace_flag;
	*dp++ = dcs_byte;
	*dp++ = 0;		/* no canned messages */
	*dp++ = payload_len;
	bcopy(payload, dp, payload_len);
	dp += payload_len;
	pdu_len = dp - pdu;
	pdu[0] = pdu_len >> 24;
	pdu[1] = pdu_len >> 16;
	pdu[2] = pdu_len >> 8;
	pdu[3] = pdu_len;
	/* local datagram socket output to be implemented */
	if (trx_socket)
		send_pdu_via_socket(pdu, pdu_len);
	else
		hex_dump_output(pdu, pdu_len);
}