
#ifndef	_SMPP_MSG_h
#define	_SMPP_MSG_h


typedef struct SMPP_HEAD
{
	DWORD	command_length;
	DWORD	command_id;
	DWORD	command_status;
	DWORD	sequence_number;
}SMPP_HEAD;

typedef struct SMPP_GENERAL
{
	SMPP_HEAD	head;
	BYTE		msg[SMPP_MSG_LEN];
}SMPP_GENERAL;

typedef struct PDU_BIND
{
	SMPP_HEAD	head;
	char		system_id[16];
	char		password[9];
	char		system_type[13];
	BYTE		interface_version;
	BYTE		addr_ton;
	BYTE		addr_npi;
	char		address_range[41];
}PDU_BIND;

typedef struct PDU_BIND_RESP
{
	SMPP_HEAD	head;
	char		system_id[16];
	/* optional parameter */
	BYTE		sc_interface_version;
}PDU_BIND_RESP;

typedef struct PDU_OUTBIND
{
	SMPP_HEAD	head;
	char		system_id[16];
	char		password[9];
}PDU_OUTBIND;

typedef struct PDU_UNBIND
{
	SMPP_HEAD	head;
}PDU_UNBIND;

typedef struct PDU_UNBIND_RESP
{
	SMPP_HEAD	head;
}PDU_UNBIND_RESP;

typedef struct PDU_GENERIC_NACK
{
	SMPP_HEAD	head;
}PDU_GENERIC_NACK;

typedef struct PDU_SUBMIT_SM
{
	SMPP_HEAD	head;

	/* define mandatory parameters */
	char		service_type[6];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
	BYTE		dest_addr_ton;
	BYTE		dest_addr_npi;
	char		destination_addr[21];
	BYTE		esm_class;
	BYTE		protocol_id;
	BYTE		priority_flag;
	char		schedule_delivery_time[17];
	char		validity_period[17];
	BYTE		registered_delivery;
	BYTE		replace_if_present_flag;
	BYTE		data_coding;
	BYTE		sm_default_msg_id;
	BYTE		sm_length;
	BYTE		short_message[254];

	/* define optional parameters */
	/* total: 28 parameters. */					/* param_flag1 */
	WORD		user_message_reference;			/* 0x0000 0001 */
	WORD		source_port;					/* 0x0000 0002 */
	BYTE		source_addr_subunit;			/* 0x0000 0004 */
	WORD		destination_port;				/* 0x0000 0008 */
	BYTE		dest_addr_subunit;				/* 0x0000 0010 */
	WORD		sar_msg_ref_num;				/* 0x0000 0020 */
	BYTE		sar_total_segments;				/* 0x0000 0040 */
	BYTE		sar_segment_seqnum;				/* 0x0000 0080 */
	BYTE		more_messages_to_send;			/* 0x0000 0100 */
	BYTE		payload_type;					/* 0x0000 0200 */
	char		message_payload[MAX_MSG_SIZE];	/* 0x0000 0400 */
	BYTE		privacy_indicator;				/* 0x0000 0800 */
	char		callback_num[19];				/* 0x0000 1000 */
	BYTE		callback_num_pres_ind;			/* 0x0000 2000 */
	char		callback_num_atag[65];			/* 0x0000 4000 */
	char		source_subaddress[23];			/* 0x0000 8000 */
	char		dest_subaddress[23];			/* 0x0001 0000 */
	BYTE		user_response_code;				/* 0x0002 0000 */
	BYTE		display_time;					/* 0x0004 0000 */
	WORD		sms_signal;						/* 0x0008 0000 */
	BYTE		ms_validity;					/* 0x0010 0000 */
	BYTE		ms_msg_wait_facilities;			/* 0x0020 0000 */
	BYTE		number_of_messages;				/* 0x0040 0000 */
	BYTE		alert_on_message_delivery; /* 0 byte. */	/* 0x0080 0000 */
	BYTE		language_indicator;				/* 0x0100 0000 */
	BYTE		its_reply_type;					/* 0x0200 0000 */
	BYTE		its_session_info[2];			/* 0x0400 0000 */
	BYTE		ussd_service_op;				/* 0x0800 0000 */
	BYTE		dest_network_type;				/* 0x1000 0000 */	/* smpp v5.0 */
}PDU_SUBMIT_SM;

typedef struct PDU_SUBMIT_SM_RESP
{
	SMPP_HEAD	head;
	char		message_id[65];
}PDU_SUBMIT_SM_RESP;

typedef struct SME_DEST_ADDRESS
{
	BYTE	dest_addr_ton;
	BYTE	dest_addr_npi;
	char	destination_addr[21];
}SME_DEST_ADDRESS;

typedef struct DL_NAME
{
	char	dl_name[21];
}DL_NAME;

typedef union DEST_ADDR
{
	SME_DEST_ADDRESS	sme_dest_address;
	DL_NAME				dl_name;
}DEST_ADDR;

typedef struct DESTINATION_ADDRESS_DEFINITION
{
	BYTE		dest_flag;  
	DEST_ADDR	dest_addr;
}DESTINATION_ADDRESS_DEFINITIAON;

typedef struct PDU_SUBMIT_MULTI
{
	SMPP_HEAD	head;

	/* define mandatory parameters */
	char		service_type[6];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
	BYTE		number_of_dests;
	DESTINATION_ADDRESS_DEFINITIAON		dest_address[SMPP_MAX_MULTI_ADDRESS];
	BYTE		esm_class;
	BYTE		protocol_id;
	BYTE		priority_flag;
	char		schedule_delivery_time[17];
	char		validity_period[17];
	BYTE		registered_delivery;
	BYTE		replace_if_present_flag;		/* set to NULL */
	BYTE		data_coding;
	BYTE		sm_default_msg_id;
	BYTE		sm_length;
	BYTE		short_message[254];

	/* define optional parameters */
	/* total: 22 parameters. */					/* param_flag1	*/
	WORD		user_message_reference;			/* 0x0000 0001 */
	WORD		source_port;					/* 0x0000 0002 */
	BYTE		source_addr_subunit;			/* 0x0000 0004 */
	WORD		destination_port;				/* 0x0000 0008 */
	BYTE		dest_addr_subunit;				/* 0x0000 0010 */
	WORD		sar_msg_ref_num;				/* 0x0000 0020 */
	BYTE		sar_total_segments;				/* 0x0000 0040 */
	BYTE		sar_segment_seqnum;				/* 0x0000 0080 */
	BYTE		payload_type;					/* 0x0000 0100 */
	char		message_payload[MAX_MSG_SIZE];	/* 0x0000 0200 */
	BYTE		privacy_indicator;				/* 0x0000 0400 */
	char		callback_num[19];				/* 0x0000 0800 */
	BYTE		callback_num_pres_ind;			/* 0x0000 1000 */
	char		callback_num_atag[65];			/* 0x0000 2000 */
	char		source_subaddress[23];			/* 0x0000 4000 */
	char		dest_subaddress[23];			/* 0x0000 8000 */
	BYTE		display_time;					/* 0x0001 0000 */
	WORD		sms_signal;						/* 0x0002 0000 */
	BYTE		ms_validity;					/* 0x0004 0000 */
	BYTE		ms_msg_wait_facilities;			/* 0x0008 0000 */
	BYTE		alert_on_message_delivery;/* 0byte */	/* 0x0010 0000 */
	BYTE		language_indicator;				/* 0x0020 0000 */
	BYTE		dest_network_type;				/* 0x0040 0000 */
}PDU_SUBMIT_MULTI;

typedef struct UNSUCCESS_SME
{
	BYTE		dest_addr_ton;
	BYTE		dest_addr_npi;
	char		destination_addr[21];
	DWORD		error_status_code;
}UNSUCCESS_SME;

typedef struct PDU_SUBMIT_MULTI_RESP
{
	SMPP_HEAD	head;
	char		message_id[65];
	BYTE		no_unsuccess;
	UNSUCCESS_SME	unsuccess_sme[MAX_SME];
}PDU_SUBMIT_MULTI_RESP;

typedef struct PDU_DELIVER_SM
{
	SMPP_HEAD	head;

	/* define mandatory parameter. */
	char		service_type[6];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
	BYTE		dest_addr_ton;
	BYTE		dest_addr_npi;
	char		destination_addr[21];
	BYTE		esm_class;
	BYTE		protocol_id;
	BYTE		priority_flag;
	char		schedule_delivery_time;			/* set to NULL */
	char		validity_period;				/* set to NULL */
	BYTE		registered_delivery;
	BYTE		replace_if_present_flag;		/* set to NULL */
	BYTE		data_coding;
	BYTE		sm_default_msg_id;				/* set to NULL */
	BYTE		sm_length;
	BYTE		short_message[254];

	/* define optional parameter. */
	/* total: 19 parameters. */					/* param_flag1	*/
	WORD		user_message_reference;			/* 0x0000 0001	*/
	WORD		source_port;					/* 0x0000 0002	*/
	WORD		destination_port;				/* 0x0000 0004	*/
	WORD		sar_msg_ref_num;				/* 0x0000 0008	*/
	BYTE		sar_total_segments;				/* 0x0000 0010	*/
	BYTE		sar_segment_seqnum;				/* 0x0000 0020	*/
	BYTE		user_response_code;				/* 0x0000 0040	*/
	BYTE		privacy_indicator;				/* 0x0000 0080	*/
	BYTE		payload_type;					/* 0x0000 0100	*/
	char		message_payload[MAX_MSG_SIZE];	/* 0x0000 0200	*/
	char		callback_num[49];				/* 0x0000 0400	*/
	char		source_subaddress[23];			/* 0x0000 0800	*/
	char		dest_subaddress[23];			/* 0x0000 1000	*/
	BYTE		language_indicator;				/* 0x0000 2000	*/
	BYTE		its_session_info[2];			/* 0x0000 4000	*/
	char		network_error_code[3];			/* 0x0000 8000	*/
	BYTE		message_state;					/* 0x0001 0000	*/
	char		receipted_message_id[65];		/* 0x0002 0000	*/
	BYTE		ussd_service_op;				/* 0x0004 0000 */ /* smpp v5.0 */
}PDU_DELIVER_SM;

typedef struct PDU_DELIVER_SM_RESP
{
	SMPP_HEAD	head;
	char		message_id;
}PDU_DELIVER_SM_RESP;

typedef struct PDU_DATA_SM
{
	SMPP_HEAD	head;

	/* define mandatory paramter. */
	char		service_type[6];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[65];
	BYTE		dest_addr_ton;
	BYTE		dest_addr_npi;
	char		destination_addr[65];
	BYTE		esm_class;
	BYTE		registered_delivery;
	BYTE		data_coding;

	/* define optional parameter. */
	/* total: 38 paramters. */					/* param_flag	*/
	WORD		source_port;					/* 0x0000 0001	*/	/* param_flag1 start. */
	BYTE		source_addr_subunit;			/* 0x0000 0002	*/
	BYTE		source_network_type;			/* 0x0000 0004	*/
	BYTE		source_bearer_type;				/* 0x0000 0008	*/
	WORD		source_telematics_id;			/* 0x0000 0010	*/
	WORD		destination_port;				/* 0x0000 0020	*/
	BYTE		dest_addr_subunit;				/* 0x0000 0040	*/
	BYTE		dest_network_type;				/* 0x0000 0080	*/
	BYTE		dest_bearer_type;				/* 0x0000 0100	*/
	WORD		dest_telematics_id;				/* 0x0000 0200	*/
	WORD		sar_msg_ref_num;				/* 0x0000 0400	*/
	BYTE		sar_total_segments;				/* 0x0000 0800	*/
	BYTE		sar_segment_seqnum;				/* 0x0000 1000	*/
	BYTE		more_messages_to_send;			/* 0x0000 2000	*/
	DWORD		qos_time_to_live;				/* 0x0000 4000	*/
	BYTE		payload_type;					/* 0x0000 8000	*/
	char		message_payload[MAX_MSG_SIZE];	/* 0x0001 0000	*/
	BYTE		set_dpf;						/* 0x0002 0000	*/
	char		receipted_message_id[65];		/* 0x0004 0000	*/
	BYTE		message_state;					/* 0x0008 0000	*/
	char		network_error_code[3];			/* 0x0010 0000	*/
	WORD		user_message_reference;			/* 0x0020 0000	*/
	BYTE		privacy_indicator;				/* 0x0040 0000	*/
	char		callback_num[19];				/* 0x0080 0000	*/
	BYTE		callback_num_pres_ind;			/* 0x0100 0000	*/
	char		callback_num_atag[65];			/* 0x0200 0000	*/
	char		source_subaddress[23];			/* 0x0400 0000	*/
	char		dest_subaddress[23];			/* 0x0800 0000	*/
	BYTE		user_response_code;				/* 0x1000 0000	*/
	BYTE		display_time;					/* 0x2000 0000	*/
	WORD		sms_signal;						/* 0x4000 0000	*/
	BYTE		ms_validity;					/* 0x8000 0000	*/	/* param_flag1 end. */
	BYTE		ms_msg_wait_facilities;			/* 0x0000 0001	*/	/* param_flag2 start. */
	BYTE		number_of_messages;				/* 0x0000 0002	*/
	BYTE		alert_on_message_delivery;/* 0byte	*/	/* 0x0000 0004	*/
	BYTE		language_indicator;				/* 0x0000 0008	*/
	BYTE		its_reply_type;					/* 0x0000 0010	*/
	BYTE		its_session_info[2];			/* 0x0000 0020	*/
}PDU_DATA_SM;

typedef struct PDU_DATA_SM_RESP
{
	SMPP_HEAD	head;
	char		message_id[65];
}PDU_DATA_SM_RESP;

typedef struct PDU_QUERY_SM
{
	SMPP_HEAD	head;
	char		message_id[65];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
}PDU_QUERY_SM;

typedef struct PDU_QUERY_SM_RESP
{
	SMPP_HEAD	head;
	char		message_id[65];
	char		final_date[17];
	BYTE		message_state;
	BYTE		error_code;
}PDU_QUERY_SM_RESP;

typedef struct PDU_CANCEL_SM
{
	SMPP_HEAD	head;
	char		service_type[6];
	char		message_id[65];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
	BYTE		dest_addr_ton;
	BYTE		dest_addr_npi;
	char		destination_addr[21];
}PDU_CANCEL_SM;

typedef struct PDU_CANCEL_SM_RESP
{
	SMPP_HEAD	head;
}PDU_CANCEL_SM_RESP;

typedef struct PDU_REPLACE_SM
{
	SMPP_HEAD	head;

	/* define mandatory parameter */
	char		message_id[65];
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	char		source_addr[21];
	char		schedule_delivery_time[17];
	char		validity_period[17];
	BYTE		registered_delivery;
	BYTE		sm_default_msg_id;
	BYTE		sm_length;
	BYTE		short_message[254];
}PDU_REPLACE_SM;

typedef struct PDU_REPLACE_SM_RESP
{
	SMPP_HEAD	head;
}PDU_REPLACE_SM_RESP;

typedef struct PDU_ENQUIRE_LINK
{
	SMPP_HEAD	head;
}PDU_ENQUIRE_LINK;

typedef struct PDU_ENQUIRE_LINK_RESP
{
	SMPP_HEAD	head;
}PDU_ENQUIRE_LINK_RESP;

typedef struct PDU_ALERT_NOTIFICATION
{
	SMPP_HEAD	head;
	BYTE		source_addr_ton;
	BYTE		source_addr_npi;
	BYTE		source_addr[65];
	BYTE		esme_addr_ton;
	BYTE		esme_addr_npi;
	BYTE		esme_addr[65];
	BYTE		ms_availability_status;
}PDU_ALERT_NOTIFICATION;

typedef union SMPP_PDU
{
	PDU_BIND					bind_transmitter;		/* message_type	= 0x01	*/
	PDU_BIND_RESP				bind_transmitter_resp;	/* message_type	= 0x02	*/
	PDU_BIND					bind_receiver;			/* message_type	= 0x03	*/
	PDU_BIND_RESP				bind_receiver_resp;		/* message_type	= 0x04	*/
	PDU_BIND					bind_transceiver;		/* message_type	= 0x05	*/
	PDU_BIND_RESP				bind_transceiver_resp;	/* message_type	= 0x06	*/
	PDU_OUTBIND					outbind;				/* message_type	= 0x07	*/
	PDU_UNBIND					unbind;					/* message_type	= 0x08	*/
	PDU_UNBIND_RESP				unbind_resp;			/* message_type	= 0x09	*/
	PDU_GENERIC_NACK			generic_nack;			/* message_type	= 0x0A	*/
	PDU_SUBMIT_SM				submit_sm;				/* message_type	= 0x0B	*/
	PDU_SUBMIT_SM_RESP			submit_sm_resp;			/* message_type	= 0x0C	*/
	PDU_SUBMIT_MULTI			submit_multi;			/* message_type	= 0x0D	*/
	PDU_SUBMIT_MULTI_RESP		submit_multi_resp;		/* message_type	= 0x0E	*/
	PDU_DELIVER_SM				deliver_sm;				/* message_type	= 0x0F	*/
	PDU_DELIVER_SM_RESP			deliver_sm_resp;		/* message_type	= 0x10	*/
	PDU_DATA_SM					data_sm;				/* message_type	= 0x11	*/
	PDU_DATA_SM_RESP			data_sm_resp;			/* message_type	= 0x12	*/
	PDU_QUERY_SM				query_sm;				/* message_type	= 0x13	*/
	PDU_QUERY_SM_RESP			query_sm_resp;			/* message_type	= 0x14	*/
	PDU_CANCEL_SM				cancel_sm;				/* message_type	= 0x15	*/
	PDU_CANCEL_SM_RESP			cancel_sm_resp;			/* message_type	= 0x16	*/
	PDU_REPLACE_SM				replace_sm;				/* message_type	= 0x17	*/
	PDU_REPLACE_SM_RESP			replace_sm_resp;		/* message_type	= 0x18	*/
	PDU_ENQUIRE_LINK			enquire_link;			/* message_type	= 0x19	*/
	PDU_ENQUIRE_LINK_RESP		enquire_link_resp;		/* message_type	= 0x1A	*/
	PDU_ALERT_NOTIFICATION		alert_notification;		/* message_type	= 0x1B	*/
}SMPP_PDU;

typedef struct SMPP_MSG
{
	BYTE		message_type;
	DWORD		optional_param_flag1;		/* for optional parameter 1~32	*/
	DWORD		optional_param_flag2;		/* for optional parameter 33~64	*/
	SMPP_PDU	pdu;
}SMPP_MSG;

typedef struct SMPP_OPTIONAL_PARAMETER
{
	WORD	tag;
	WORD	len;
	BYTE	value[MAX_MSG_SIZE];
}SMPP_OPTIONAL_PARAMETER;

/* by simon at 23/9/26 */
// BYTE    smpp_msg_buf[MAX_SMPP_LINK][MAX_PACKET_SIZE];
// int     smpp_msg_buf_len[MAX_SMPP_LINK];

#endif




