aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-11-07 08:32:31 +0100
committerHarald Welte <laforge@gnumonks.org>2012-11-07 08:32:31 +0100
commit4b233b4f3b22f79c2bdd60703d309c9929f74ab6 (patch)
tree91b2622eb54d509b5c78896aca56babc120f1b7b /src
initial import of libsmpp34-1.101.10
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am28
-rw-r--r--src/smpp34.h207
-rw-r--r--src/smpp34_dumpBuf.c117
-rw-r--r--src/smpp34_dumpPdu.c245
-rw-r--r--src/smpp34_pack.c234
-rw-r--r--src/smpp34_params.c244
-rw-r--r--src/smpp34_params.h49
-rw-r--r--src/smpp34_structs.c43
-rw-r--r--src/smpp34_structs.h261
-rw-r--r--src/smpp34_unpack.c255
10 files changed, 1683 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..940fd0a
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,28 @@
+
+# src/Makefile.am #
+lib_LTLIBRARIES = libsmpp34.la
+
+LIBRARY_SOURCE_DIR = $(top_srcdir)/src
+libsmpp34_la_SOURCES = \
+ $(LIBRARY_SOURCE_DIR)/smpp34.h \
+ $(LIBRARY_SOURCE_DIR)/smpp34_dumpBuf.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_dumpPdu.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_pack.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_unpack.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_structs.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_structs.h \
+ $(LIBRARY_SOURCE_DIR)/smpp34_params.c \
+ $(LIBRARY_SOURCE_DIR)/smpp34_params.h
+
+include_HEADERS = \
+ $(LIBRARY_SOURCE_DIR)/smpp34.h \
+ $(LIBRARY_SOURCE_DIR)/smpp34_structs.h \
+ $(LIBRARY_SOURCE_DIR)/smpp34_params.h
+
+libsmpp34_la_CFLAGS = @CFLAGS@ -Wall
+libsmpp34_la_CFLAGS += -D_REENTRANT -DBSD_COMP -D_POSIX_PTHREAD_SEMANTICS
+libsmpp34_la_INCLUDES = -I. -I..
+libsmpp34_la_LDFLAGS = @LDFLAGS@ -version-info 0:1:0
+libsmpp34_la_LDFLAGS += -lrt -lpthread
+
+
diff --git a/src/smpp34.h b/src/smpp34.h
new file mode 100644
index 0000000..5fb6395
--- /dev/null
+++ b/src/smpp34.h
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34.h
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _SMPP_H_
+#define _SMPP_H_
+
+/* SMPP Version ***************************************************************/
+#define SMPP_VERSION 0x34
+/* Command Id *****************************************************************/
+#define GENERIC_NACK 0x80000000
+#define BIND_RECEIVER 0x00000001
+#define BIND_RECEIVER_RESP 0x80000001
+#define BIND_TRANSMITTER 0x00000002
+#define BIND_TRANSMITTER_RESP 0x80000002
+#define QUERY_SM 0x00000003
+#define QUERY_SM_RESP 0x80000003
+#define SUBMIT_SM 0x00000004
+#define SUBMIT_SM_RESP 0x80000004
+#define DELIVER_SM 0x00000005
+#define DELIVER_SM_RESP 0x80000005
+#define UNBIND 0x00000006
+#define UNBIND_RESP 0x80000006
+#define REPLACE_SM 0x00000007
+#define REPLACE_SM_RESP 0x80000007
+#define CANCEL_SM 0x00000008
+#define CANCEL_SM_RESP 0x80000008
+#define BIND_TRANSCEIVER 0x00000009
+#define BIND_TRANSCEIVER_RESP 0x80000009
+/* Reserved 0x0000000A 0x8000000A */
+#define OUTBIND 0x0000000B
+/* Reserved 0x0000000C - 0x00000014 0x8000000B - 0x80000014 */
+#define ENQUIRE_LINK 0x00000015
+#define ENQUIRE_LINK_RESP 0x80000015
+/* Reserved 0x00000016 - 0x00000020 0x80000016 - 0x80000020*/
+#define SUBMIT_MULTI 0x00000021
+#define SUBMIT_MULTI_RESP 0x80000021
+/* Reserved 0x00000022 - 0x000000FF 0x80000022 - 0x800000FF */
+/* Reserved 0x00000100 */
+#define Reserved 0x80000100
+/* Reserved 0x00000101 0x80000101 */
+#define ALERT_NOTIFICATION 0x00000102
+/* Reserved 0x80000102 */
+#define DATA_SM 0x00000103
+#define DATA_SM_RESP 0x80000103
+/* Reserved for SMPP extension 0x00000104 - 0x0000FFFF 0x80000104 - 0x8000FFFF */
+/* Reserved 0x00010000 - 0x000101FF 0x80010000 - 0x800101FF */
+/* Reserved for SMSC Vendor 0x00010200 - 0x000102FF 0x80010200 - 0x800102FF */
+/* Reserved 0x00010300 - 0xFFFFFFFF*/
+
+
+/* Command status *************************************************************/
+#define ESME_ROK 0x00000000 /* No Error */
+#define ESME_RINVMSGLEN 0x00000001 /* Message Length is invalid */
+#define ESME_RINVCMDLEN 0x00000002 /* Command Length is invalid */
+#define ESME_RINVCMDID 0x00000003 /* Invalid Command ID */
+#define ESME_RINVBNDSTS 0x00000004 /* Incorrect BIND Status for given command */
+#define ESME_RALYBND 0x00000005 /* ESME Already in Bound State */
+#define ESME_RINVPRTFLG 0x00000006 /* Invalid Priority Flag */
+#define ESME_RINVREGDLVFLG 0x00000007 /* Invalid Registered Delivery Flag */
+#define ESME_RSYSERR 0x00000008 /* System Error */
+/* Reserved 0x00000009 Reserved */
+#define ESME_RINVSRCADR 0x0000000A /* Invalid Source Address */
+#define ESME_RINVDSTADR 0x0000000B /* Invalid Dest Addr */
+#define ESME_RINVMSGID 0x0000000C /* Message ID is invalid */
+#define ESME_RBINDFAIL 0x0000000D /* Bind Failed */
+#define ESME_RINVPASWD 0x0000000E /* Invalid Password */
+#define ESME_RINVSYSID 0x0000000F /* Invalid System ID */
+/* Reserved 0x00000010 Reserved */
+#define ESME_RCANCELFAIL 0x00000011 /* Cancel SM Failed */
+/* Reserved 0x00000012 Reserved */
+#define ESME_RREPLACEFAIL 0x00000013 /* Replace SM Failed*/
+#define ESME_RMSGQFUL 0x00000014 /* Message Queue Full */
+#define ESME_RINVSERTYP 0x00000015 /* Invalid Service Type */
+/* Reserved 0x00000016- 0x00000032 Reserved */
+#define ESME_RINVNUMDESTS 0x00000033 /* Invalid number of destinations */
+#define ESME_RINVDLNAME 0x00000034 /* Invalid Distribution List name */
+/* Reserved 0x00000035- 0x0000003F Reserved */
+#define ESME_RINVDESTFLAG 0x00000040 /* Destination flag is invalid (submit_multi) */
+/* Reserved 0x00000041 Reserved */
+#define ESME_RINVSUBREP 0x00000042 /* Invalid submit with replace request (i.e. submit_sm with replace_if_present_flag set) */
+#define ESME_RINVESMCLASS 0x00000043 /* Invalid esm_class field data */
+#define ESME_RCNTSUBDL 0x00000044 /* Cannot Submit to Distribution List */
+#define ESME_RSUBMITFAIL 0x00000045 /* submit_sm or submit_multi failed */
+/* Reserved 0x00000046- 0x00000047 Reserved */
+#define ESME_RINVSRCTON 0x00000048 /* Invalid Source address TON */
+#define ESME_RINVSRCNPI 0x00000049 /* Invalid Source address NPI */
+#define ESME_RINVDSTTON 0x00000050 /* Invalid Destination address TON */
+#define ESME_RINVDSTNPI 0x00000051 /* Invalid Destination address NPI */
+/* Reserved 0x00000052 Reserved */
+#define ESME_RINVSYSTYP 0x00000053 /* Invalid system_type field */
+#define ESME_RINVREPFLAG 0x00000054 /* Invalid replace_if_present flag */
+#define ESME_RINVNUMMSGS 0x00000055 /* Invalid number of messages */
+/* Reserved 0x00000056- 0x00000057 Reserved */
+#define ESME_RTHROTTLED 0x00000058 /* Throttling error (ESME has exceeded allowed message limits) */
+/* Reserved 0x00000059- 0x00000060 Reserved*/
+#define ESME_RINVSCHED 0x00000061 /* Invalid Scheduled Delivery Time */
+#define ESME_RINVEXPIRY 0x00000062 /* Invalid message validity period (Expiry time) */
+#define ESME_RINVDFTMSGID 0x00000063 /* Predefined Message Invalid or Not Found */
+#define ESME_RX_T_APPN 0x00000064 /* ESME Receiver Temporary App Error Code */
+#define ESME_RX_P_APPN 0x00000065 /* ESME Receiver Permanent App Error Code */
+#define ESME_RX_R_APPN 0x00000066 /* ESME Receiver Reject Message Error Code */
+#define ESME_RQUERYFAIL 0x00000067 /* query_sm request failed */
+/* Reserved 0x00000068 - 0x000000BF Reserved */
+#define ESME_RINVOPTPARSTREAM 0x000000C0 /* Error in the optional part of the PDU Body. */
+#define ESME_ROPTPARNOTALLWD 0x000000C1 /* Optional Parameter not allowed */
+#define ESME_RINVPARLEN 0x000000C2 /* Invalid Parameter Length. */
+#define ESME_RMISSINGOPTPARAM 0x000000C3 /* Expected Optional Parameter missing */
+#define ESME_RINVOPTPARAMVAL 0x000000C4 /* Invalid Optional Parameter Value */
+/* Reserved 0x000000C5 - 0x000000FD Reserved */
+#define ESME_RDELIVERYFAILURE 0x000000FE /* Delivery Failure (used for data_sm_resp) */
+#define ESME_RUNKNOWNERR 0x000000FF /* Unknown Error */
+/* Reserved for SMPP extension 0x00000100- 0x000003FF Reserved for SMPP extension */
+/* Reserved for SMSC vendor specific errors 0x00000400- 0x000004FF Reserved for SMSC vendor specific errors */
+/* Reserved 0x00000500- 0xFFFFFFFF Reserved */
+
+/* ADDR_TON Values ************************************************************/
+#define TON_Unknown 0
+#define TON_International 1
+#define TON_National 2
+#define TON_Network_Specific 3
+#define TON_Subscriber_Number 4
+#define TON_Alphanumeric 5
+#define TON_Abbreviated 6
+
+/* ADDR_NPI Values ************************************************************/
+#define NPI_Unknown 0
+#define NPI_ISDN_E163_E164 1
+#define NPI_Data_X121 3
+#define NPI_Telex_F69 4
+#define NPI_Land_Mobile_E212 6
+#define NPI_National 8
+#define NPI_Private 9
+#define NPI_ERMES 10
+#define NPI_Internet_IP 14
+#define NPI_WAP_Client_Id 18
+
+
+/* Flag which will identify whether destination address is a DL or SME Addr ***/
+#define DFID_SME_Address 1
+#define DFID_Distribution_List_Name 2
+
+/* SMPP Optional Parameter Tag definitions ************************************/
+#define TLVID_dest_addr_subunit 0x0005 /* GSM */
+#define TLVID_dest_network_type 0x0006 /* Generic */
+#define TLVID_dest_bearer_type 0x0007 /* Generic */
+#define TLVID_dest_telematics_id 0x0008 /* GSM */
+#define TLVID_source_addr_subunit 0x000D /* GSM */
+#define TLVID_source_network_type 0x000E /* Generic */
+#define TLVID_source_bearer_type 0x000F /* Generic */
+#define TLVID_source_telematics_id 0x0010 /* GSM */
+#define TLVID_qos_time_to_live 0x0017 /* Generic */
+#define TLVID_payload_type 0x0019 /* Generic */
+#define TLVID_additional_status_info_text 0x001D /* Generic */
+#define TLVID_receipted_message_id 0x001E /* Generic */
+#define TLVID_ms_msg_wait_facilities 0x0030 /* GSM */
+#define TLVID_privacy_indicator 0x0201 /* CDMA, TDMA */
+#define TLVID_source_subaddress 0x0202 /* CDMA, TDMA */
+#define TLVID_dest_subaddress 0x0203 /* CDMA, TDMA */
+#define TLVID_user_message_reference 0x0204 /* Generic */
+#define TLVID_user_response_code 0x0205 /* CDMA, TDMA */
+#define TLVID_source_port 0x020A /* Generic */
+#define TLVID_destination_port 0x020B /* Generic */
+#define TLVID_sar_msg_ref_num 0x020C /* Generic */
+#define TLVID_language_indicator 0x020D /* CDMA, TDMA */
+#define TLVID_sar_total_segments 0x020E /* Generic */
+#define TLVID_sar_segment_seqnum 0x020F /* Generic */
+#define TLVID_sc_interface_version 0x0210 /* Generic */
+#define TLVID_callback_num_pres_ind 0x0302 /* TDMA */
+#define TLVID_callback_num_atag 0x0303 /* TDMA */
+#define TLVID_number_of_messages 0x0304 /* CDMA */
+#define TLVID_callback_num 0x0381 /* CDMA, TDMA, GSM, iDEN */
+#define TLVID_dpf_result 0x0420 /* Generic */
+#define TLVID_set_dpf 0x0421 /* Generic */
+#define TLVID_ms_availability_status 0x0422 /* Generic */
+#define TLVID_network_error_code 0x0423 /* Generic */
+#define TLVID_message_payload 0x0424 /* Generic */
+#define TLVID_delivery_failure_reason 0x0425 /* Generic */
+#define TLVID_more_messages_to_send 0x0426 /* GSM */
+#define TLVID_message_state 0x0427 /* Generic */
+#define TLVID_ussd_service_op 0x0501 /* GSM (USSD) */
+#define TLVID_display_time 0x1201 /* CDMA, TDMA */
+#define TLVID_sms_signal 0x1203 /* TDMA */
+#define TLVID_ms_validity 0x1204 /* CDMA, TDMA */
+#define TLVID_alert_on_message_delivery 0x130C /* CDMA */
+#define TLVID_its_reply_type 0x1380 /* CDMA */
+#define TLVID_its_session_info 0x1383 /* CDMA */
+
+#endif
diff --git a/src/smpp34_dumpBuf.c b/src/smpp34_dumpBuf.c
new file mode 100644
index 0000000..9d8e1b9
--- /dev/null
+++ b/src/smpp34_dumpBuf.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_dumpBuf.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+#include "smpp34_params.h"
+
+
+/* GLOBALS ********************************************************************/
+/* EXTERN *********************************************************************/
+extern int smpp34_errno;
+extern char smpp34_strerror[2048];
+extern char *ptrerror;
+
+/* FUNCTIONS ******************************************************************/
+int
+smpp34_dumpBuf(uint8_t *dest, int destL, uint8_t *src, int srcL)
+{
+
+ int i;
+ int j;
+ int size;
+ uint8_t ind = 3;
+ uint8_t *buffer = NULL;
+ int lefterror = 0;
+
+ size = srcL;
+ buffer = src;
+
+ memset(smpp34_strerror, 0, sizeof(smpp34_strerror));
+ ptrerror = smpp34_strerror;
+ lefterror = sizeof(smpp34_strerror);
+
+ /* dump buffer character by character until size is reached */
+ for(i = 0; i < size; i++){
+ switch( i % 16 ) {
+ case 0:
+ dest += sprintf((char*)dest, "%*c%02X ", ind, ' ', (uint8_t)buffer[i]);
+ break;
+
+ case 7:
+ dest += sprintf((char*)dest, "%02X ", (uint8_t)buffer[i]);
+ break;
+
+ case 15:
+ dest += sprintf((char*)dest, "%02X ", (uint8_t)buffer[i]);
+ for(j = (i - 15); j <= i; j++) {
+ if ( (buffer[j] < ' ') || (buffer[j] > '~') )
+ dest += sprintf((char*)dest, ".");
+ else
+ dest += sprintf((char*)dest, "%c", buffer[j]);
+ if ( (j % 16) == 7 )
+ dest += sprintf((char*)dest, " ");
+ }
+ dest += sprintf((char*)dest, "\n");
+ break;
+
+ default:
+ dest += sprintf((char*)dest, "%02X ", (uint8_t)buffer[i]);
+ break;
+ }
+ };
+
+ /* if the line is not completed, we have to fill it */
+ if ( (size % 16) != 0 ) {
+ for (i = (size % 16); i < 16; i++) {
+ dest += sprintf((char*)dest, " ");
+ if ( (i % 16) == 7 )
+ dest += sprintf((char*)dest, " ");
+ }
+ dest += sprintf((char*)dest, " ");
+ for (j = size - (size % 16); j < size; j++) {
+ /* check if character is printable */
+ if ( (buffer[j] < ' ') || (buffer[j] > '~') )
+ dest += sprintf((char*)dest, ".");
+ else
+ dest += sprintf((char*)dest, "%c", (char) buffer[j]);
+ if ( (j % 16) == 7 )
+ dest += sprintf((char*)dest, " ");
+ }
+ dest += sprintf((char*)dest, "\n");
+ }
+
+ *dest = '\0';
+ return( 0 );
+};
+
+
diff --git a/src/smpp34_dumpPdu.c b/src/smpp34_dumpPdu.c
new file mode 100644
index 0000000..cff0300
--- /dev/null
+++ b/src/smpp34_dumpPdu.c
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_dumpPdu.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+#include "smpp34_params.h"
+
+/* GLOBALS ********************************************************************/
+/* EXTERN *********************************************************************/
+extern int smpp34_errno;
+extern char smpp34_strerror[2048];
+extern char *ptrerror;
+
+/* FUNCTIONS ******************************************************************/
+int
+smpp34_dumpPdu(uint32_t type, uint8_t *dest, int size_dest, void* tt)
+{
+
+ char dummy_b[SMALL_BUFF];
+ int left = size_dest;
+ int lenval = 0;
+ uint8_t l_dest[512];
+ int lefterror = 0;
+
+ memset(smpp34_strerror, 0, sizeof(smpp34_strerror));
+ ptrerror = smpp34_strerror;
+ lefterror = sizeof(smpp34_strerror);
+ memset(l_dest, 0, sizeof(l_dest));
+
+
+#define instancia t1->
+
+#define U32( inst, par, _str ){\
+ _str(inst par, dummy_b);\
+ if( strcmp( dummy_b, "" ) == 0 ){\
+ PUTLOG("[%s:%08X(%s)]", par, inst par, "Value is invalid");\
+ } else {\
+ PUTLOG("[%s:%08X(%s)]", par, inst par, "OK");\
+ };\
+ lenval = snprintf((char*)l_dest, sizeof(l_dest), "%-30s[%08X] - [%s]\n",\
+ #par,inst par,dummy_b);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%08X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ snprintf((char*)dest, left, "%s", l_dest);\
+ left -= lenval; dest += lenval;\
+}
+
+#define U16( inst, par, _str ){\
+ _str(inst par, dummy_b);\
+ if( strcmp( dummy_b, "" ) == 0 ){\
+ PUTLOG("[%s:%04X(%s)]", par, inst par, "Value is invalid");\
+ } else {\
+ PUTLOG("[%s:%04X(%s)]", par, inst par, "OK");\
+ };\
+ lenval = snprintf((char*)l_dest, sizeof(l_dest),\
+ "%-30s[%04X] [%s]\n",#par,inst par,dummy_b);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%04X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ snprintf((char*)dest, left, "%s", l_dest);\
+ left -= (uint8_t)lenval; dest += (uint8_t) lenval;\
+}
+
+#define U08( inst, par, _str ){\
+ _str(inst par, dummy_b);\
+ if( strcmp( dummy_b, "" ) == 0 ){\
+ PUTLOG("[%s:%02X(%s)]", par, inst par, "Value is invalid");\
+ } else {\
+ PUTLOG("[%s:%02X(%s)]", par, inst par, "OK");\
+ };\
+ lenval = snprintf((char*)l_dest, sizeof(l_dest), "%-30s[%02X] - [%s]\n",\
+ #par,inst par, dummy_b);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%02X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ snprintf((char*)dest, left, "%s", l_dest);\
+ left -= lenval; dest += lenval;\
+}
+
+#define _op(inst, par, size ){\
+ lenval = snprintf((char*)l_dest, sizeof(l_dest), "%-30s[%."#size"s]\n",\
+ #par, inst par);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%s(%s)]", par, inst par, \
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ snprintf((char*)dest, left, "%s", l_dest);\
+ left -= lenval; dest += lenval;\
+}
+
+#define O_C_OCTET( inst, par, sizeval ){\
+ if( !(inst command_status) ){\
+ C_OCTET( inst, par, sizeval );\
+ } else {\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ };\
+}
+
+#define C_OCTET( inst, par, size ) {\
+ _op(inst, par, size )\
+}
+
+#define OCTET8( inst, par, size ){\
+ int i = 0;\
+ uint8_t *p = l_dest;\
+ int dummy = 0;\
+ lenval = *((inst par) - 1);\
+ if( (lenval + 33) >= left ){\
+ PUTLOG("[%s:%s(%s)]", par, inst par, \
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), "%-30s[", #par);\
+ for(i = 0 ; i < lenval; i++){\
+ if( *((inst par)+i) < ' ' || *((inst par)+i) > '~' ){\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), ".");\
+ } else {\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), "%c",\
+ *((inst par)+i));\
+ };\
+ };\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), "]\n");\
+ dummy = snprintf((char*)dest, left, "%s", l_dest);\
+ left -= dummy; dest += dummy;\
+};
+
+
+#define OCTET16( inst, par, size ){\
+ int i = 0;\
+ uint8_t *p = l_dest;\
+ int dummy = 0;\
+ uint16_t l_lenval = 0;\
+ memcpy(&l_lenval, ((inst par) - sizeof(uint16_t)), sizeof(uint16_t));\
+ if( (l_lenval + 33) >= left ){\
+ PUTLOG("[%s:%s(%s)]", par, inst par, \
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+ p += snprintf((char*)p, (sizeof(l_dest) - (p - l_dest)), "%-30s[", #par);\
+ for( i = 0; i < l_lenval; i++){\
+ if( *((inst par)+i) < ' ' || *((inst par)+i) > '~' ){\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), ".");\
+ } else {\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), "%c",\
+ *((inst par)+i));\
+ };\
+ };\
+ p += snprintf((char*)p, (sizeof(l_dest)-(p-l_dest)), "]\n");\
+ dummy = snprintf((char*)dest, left, "%s", l_dest);\
+ left -= dummy; dest += dummy;\
+};
+
+
+#define TLV( inst, tlv1, do_tlv ){\
+ tlv_t *aux_tlv = inst tlv1;\
+ while( aux_tlv != NULL ){\
+ do_tlv( aux_tlv );\
+ aux_tlv = aux_tlv->next;\
+ };\
+};
+
+#define DAD( inst, dad1, do_dad ){\
+ dad_t *aux_dad = inst dad1;\
+ while( aux_dad != NULL ){\
+ do_dad( aux_dad );\
+ aux_dad = aux_dad->next;\
+ };\
+};
+
+#define UDAD( inst, udad1, do_udad ){\
+ udad_t *aux_udad = inst udad1;\
+ while( aux_udad != NULL ){\
+ do_udad( aux_udad );\
+ aux_udad = aux_udad->next;\
+ };\
+};
+
+#include "def_frame/alert_notification.tlv"
+#include "def_frame/bind_receiver_resp.tlv"
+#include "def_frame/bind_transceiver_resp.tlv"
+#include "def_frame/bind_transmitter_resp.tlv"
+#include "def_frame/data_sm.tlv"
+#include "def_frame/data_sm_resp.tlv"
+#include "def_frame/deliver_sm.tlv"
+#include "def_frame/submit_multi_resp.udad"
+#include "def_frame/submit_multi.dad"
+#include "def_frame/submit_multi.tlv"
+#include "def_frame/submit_sm.tlv"
+#include "def_list/smpp34_protocol.def"
+
+#include "def_frame/clean.frame"
+
+ return( 0 );
+};
+
+
+
+int
+smpp34_dumpPdu2(uint8_t *dest, int size_dest, void* tt)
+{
+ uint32_t cmdid;
+ memcpy(&cmdid, tt+4, sizeof(uint32_t));
+ return( smpp34_dumpPdu(cmdid, dest, size_dest, tt) );
+};
+
diff --git a/src/smpp34_pack.c b/src/smpp34_pack.c
new file mode 100644
index 0000000..0974da6
--- /dev/null
+++ b/src/smpp34_pack.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_pack.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+#include "smpp34_params.h"
+
+/* GLOBALS ********************************************************************/
+/* EXTERN *********************************************************************/
+extern int smpp34_errno;
+extern char smpp34_strerror[2048];
+extern char *ptrerror;
+
+/* FUNCTIONS ******************************************************************/
+int
+smpp34_pack(uint32_t type, uint8_t *ptrBuf, int ptrSize, int *ptrLen, void* tt)
+{
+
+ char dummy_b[SMALL_BUFF];
+ uint32_t v = 0;
+ uint32_t *dd = (uint32_t*)tt;
+ uint8_t *aux = ptrBuf;
+ uint8_t *aux2 = ptrBuf;
+ int lenval = 0;
+ int left = ptrSize;
+ int lefterror = 0;
+
+ memset(smpp34_strerror, 0, sizeof(smpp34_strerror));
+ ptrerror = smpp34_strerror;
+ lefterror = sizeof(smpp34_strerror);
+
+#define instancia t1->
+
+#define U32( inst, par, _str ){\
+ uint32_t v32 = htonl(inst par);\
+ lenval = sizeof(uint32_t);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%08X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ _str(inst par,dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG( "[%s:%08X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ }\
+ PUTLOG("[%s:%08X(%s)]", par, inst par, "OK");\
+ memcpy(aux, &v32, lenval);\
+ left -= lenval; aux += lenval;\
+};
+
+#define U16( inst, par, _str ) {\
+ uint16_t v16 = htons(inst par);\
+ lenval = sizeof(uint16_t);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%04X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ _str(inst par,dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG( "[%s:%04X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ }\
+ PUTLOG("[%s:%04X(%s)]", par, inst par, "OK");\
+ memcpy(aux, &v16, lenval);\
+ left -= lenval; aux += lenval;\
+};
+
+#define U08( inst, par, _str ){\
+ lenval = sizeof(uint8_t);\
+ if( lenval >= left ){\
+ PUTLOG("[%s:%02X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ _str(inst par,dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG( "[%s:%02X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ }\
+ PUTLOG("[%s:%02X(%s)]", par, inst par, "OK");\
+ memcpy(aux,&inst par, sizeof(inst par));\
+ left -= lenval; aux += lenval;\
+};
+
+#define O_C_OCTET( inst, par, sizeval ){\
+ if( !(inst command_status) ){\
+ C_OCTET( inst, par, sizeval );\
+ } else {\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ };\
+}
+
+#define C_OCTET( inst, par, sizeval ){\
+ lenval = strlen((char*)inst par) + 1;\
+ if( lenval > left ){\
+ PUTLOG("[len(%s):%d(%s)]", par, lenval, \
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( lenval > sizeval ){\
+ memcpy(aux, &inst par, sizeval);\
+ *(inst par + sizeval-1) = *(aux+sizeval-1) = '\0';\
+ left -= sizeval; aux += sizeval;\
+ PUTLOG("[%s:%s(%s)]", par, inst par, \
+ "Data length is invalid (truncate)");\
+ } else {\
+ memcpy(aux, &inst par, lenval);\
+ left -= lenval; aux += lenval;\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ }\
+};
+
+#define OCTET8( inst, par, sizeval ){\
+ lenval = *((inst par) - 1);\
+ if( lenval >= left ){\
+ PUTLOG("[leng %s:%d(%s)]", par, lenval,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( lenval >= sizeval ){\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>",\
+ "Data length is invalid (truncate)");\
+ return( -1 );\
+ };\
+ memcpy(aux, &inst par, (lenval > sizeval)?sizeval:lenval);\
+ left -= (lenval > sizeval)?sizeval:lenval;\
+ aux += (lenval > sizeval)?sizeval:lenval;\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+};
+
+#define OCTET16( inst, par, sizeval ){\
+ uint16_t l_lenval = 0;\
+ memcpy(&l_lenval, ((inst par) - sizeof(uint16_t)), sizeof(uint16_t));\
+ if( l_lenval >= left ){\
+ PUTLOG("[leng %s:%d(%s)]", par, l_lenval,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( l_lenval > sizeval ){\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "Data length is invalid");\
+ return( -1 );\
+ };\
+ memcpy(aux, &inst par, (l_lenval > sizeval)?sizeval:l_lenval);\
+ left -= (l_lenval > sizeval)?sizeval:l_lenval;\
+ aux += (l_lenval > sizeval)?sizeval:l_lenval;\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+}
+
+#define TLV( inst, tlv2, do_tlv ) {\
+ tlv_t *aux_tlv = inst tlv2;\
+ while( aux_tlv != NULL ){\
+ do_tlv( aux_tlv );\
+ aux_tlv = aux_tlv->next;\
+ };\
+};
+
+#define UDAD( inst, udad2, do_udad ) {\
+ udad_t *aux_udad = inst udad2;\
+ while( aux_udad != NULL ){\
+ do_udad( aux_udad );\
+ aux_udad = aux_udad->next;\
+ };\
+};
+
+#define DAD( inst, dad2, do_dad ) {\
+ dad_t *aux_dad = inst dad2;\
+ while( aux_dad != NULL ){\
+ do_dad( aux_dad );\
+ aux_dad = aux_dad->next;\
+ };\
+};
+
+#include "def_frame/alert_notification.tlv"
+#include "def_frame/bind_receiver_resp.tlv"
+#include "def_frame/bind_transceiver_resp.tlv"
+#include "def_frame/bind_transmitter_resp.tlv"
+#include "def_frame/data_sm.tlv"
+#include "def_frame/data_sm_resp.tlv"
+#include "def_frame/deliver_sm.tlv"
+#include "def_frame/submit_multi_resp.udad"
+#include "def_frame/submit_multi.dad"
+#include "def_frame/submit_multi.tlv"
+#include "def_frame/submit_sm.tlv"
+#include "def_list/smpp34_protocol.def"
+
+ /* Hace algunas correcciones ******************************************/
+ *dd = aux - aux2; /* Escribe largo en el source */
+ v = htonl(aux - aux2); /* Calcula largo del PDU */
+ memcpy(aux2, &v, sizeof(uint32_t)); /* escribe largo en el dest */
+ *ptrLen = (int) (aux - aux2);
+
+#include "def_frame/clean.frame"
+ return( 0 );
+};
+
+
+int
+smpp34_pack2(uint8_t *ptrBuf, int ptrSize, int *ptrLen, void* tt)
+{
+ uint32_t cmdid;
+ memcpy(&cmdid, tt+4, sizeof(uint32_t));
+ return( smpp34_pack(cmdid, ptrBuf, ptrSize, ptrLen, tt) );
+};
diff --git a/src/smpp34_params.c b/src/smpp34_params.c
new file mode 100644
index 0000000..73943a5
--- /dev/null
+++ b/src/smpp34_params.c
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_params.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h>
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+
+int
+build_udad( udad_t **dest, udad_t *source )
+{
+
+ /* Build new DAD-Chain ************************************************/
+ udad_t *dummy = (udad_t*)malloc(sizeof( udad_t ));
+ if( dummy == NULL ){
+ printf("Error in malloc()\n" );
+ return( -1 );
+ };
+ memcpy(dummy, source, sizeof( udad_t ));
+
+ dummy->next = (*dest);
+ (*dest) = dummy;
+
+ return( 0 );
+};
+
+int
+destroy_udad( udad_t *sourceList )
+{
+
+ udad_t *i = NULL;
+ /* Destroy DAD-Chain **************************************************/
+ while( sourceList != NULL ){
+ i = sourceList->next;
+ free((void*)sourceList);
+ sourceList = i;
+ };
+
+ return( 0 );
+};
+
+
+
+int
+build_dad( dad_t **dest, dad_t *source )
+{
+
+ /* Build new DAD-Chain ************************************************/
+ dad_t *dummy = (dad_t*)malloc(sizeof( dad_t ));
+ if( dummy == NULL ){
+ printf("Error in malloc()\n" );
+ return( -1 );
+ };
+ memcpy(dummy, source, sizeof( dad_t ));
+
+ dummy->next = (*dest);
+ (*dest) = dummy;
+
+ return( 0 );
+};
+
+int
+destroy_dad( dad_t *sourceList )
+{
+
+ dad_t *i = NULL;
+ /* Destroy DAD-Chain **************************************************/
+ while( sourceList != NULL ){
+ i = sourceList->next;
+ free((void*)sourceList);
+ sourceList = i;
+ };
+
+ return( 0 );
+};
+
+
+int
+build_tlv( tlv_t **dest, tlv_t *source )
+{
+
+ /* Build new TLV-Chain ************************************************/
+ tlv_t *dummy = (tlv_t*)malloc(sizeof( tlv_t ));
+ if( dummy == NULL ){
+ printf("Error in malloc()\n" );
+ return( -1 );
+ };
+ memcpy(dummy, source, sizeof( tlv_t ));
+
+ dummy->next = (*dest);
+ (*dest) = dummy;
+
+ return( 0 );
+};
+
+int
+destroy_tlv( tlv_t *sourceList )
+{
+
+ tlv_t *i = NULL;
+ /* Destroy TLV-Chain **************************************************/
+ while( sourceList != NULL ){
+ i = sourceList->next;
+ free((void*)sourceList);
+ sourceList = i;
+ };
+
+ return( 0 );
+};
+
+
+char* str_tlv_id( uint16_t tlv_id, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_tlv_id ) (tlv_id == p_tlv_id)?#p_tlv_id:
+#include "def_list/tlv_id.list"
+ "Reserved"
+#undef OPERACION
+ );
+ return( buff );
+};
+
+
+char* str_command_id( uint32_t command, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_command ) (command == p_command)?#p_command:
+#include "def_list/command_id.list"
+ ""
+#undef OPERACION
+ );
+ return( buff );
+};
+
+
+char* str_addr_ton( uint8_t ton, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_command ) (ton == p_command)?#p_command:
+#include "def_list/addr_ton.list"
+ ""
+#undef OPERACION
+ );
+ return( buff );
+};
+
+
+char* str_addr_npi( uint8_t npi, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_command ) (npi == p_command)?#p_command:
+#include "def_list/addr_npi.list"
+ ""
+#undef OPERACION
+ );
+ return( buff );
+};
+
+
+char* str_command_status( uint32_t command, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_command ) (command == p_command)?#p_command:
+#include "def_list/command_status.list"
+ ""
+#undef OPERACION
+ );
+ return( buff );
+};
+
+char *test_interface_version( uint8_t interface_version, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s", (interface_version==0x34)?"OK":"" );
+ return( buff );
+};
+
+char *test_dest_flag( uint8_t dest_flag, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s",
+#define OPERACION( p_command ) (dest_flag == p_command)?#p_command:
+#include "def_list/dest_flag.list"
+ ""
+#undef OPERACION
+ );
+ return( buff );
+};
+
+char *test_sequence_number( uint32_t sequence_number, char* buff )
+{
+ char numero[20];
+ snprintf(numero, sizeof(numero), "%d", sequence_number);
+ snprintf(buff, SMALL_BUFF, "%s", (sequence_number>0)?numero:"" );
+ return( buff );
+};
+
+char *nothing( uint32_t var, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%s", "OK" );
+ return( buff );
+};
+
+char *valueDec_32( uint32_t var, char *buff )
+{
+ snprintf(buff, SMALL_BUFF, "%d", var);
+ return( buff );
+};
+
+char *valueDec_16( uint16_t var, char *buff )
+{
+ snprintf(buff, SMALL_BUFF, "%d", var);
+ return( buff );
+};
+
+char *valueDec_08( uint8_t var, char* buff )
+{
+ snprintf(buff, SMALL_BUFF, "%d", var);
+ return( buff );
+};
+
+
diff --git a/src/smpp34_params.h b/src/smpp34_params.h
new file mode 100644
index 0000000..91b2ffc
--- /dev/null
+++ b/src/smpp34_params.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_params.h
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _TEST_PARAM_H_
+#define _TEST_PARAM_H_
+
+int destroy_udad( udad_t *sourceList );
+int build_udad( udad_t **dest, udad_t *source );
+
+int destroy_dad( dad_t *sourceList );
+int build_dad( dad_t **dest, dad_t *source );
+
+int destroy_tlv( tlv_t *sourceList );
+int build_tlv( tlv_t **dest, tlv_t *source );
+
+char* str_tlv_id( uint16_t tlv_id, char* buff );
+char* str_command_id( uint32_t command, char* buff );
+char* str_command_status( uint32_t command, char* buff );
+char *test_sequence_number( uint32_t sequence_number, char* buff );
+char *test_interface_version( uint8_t interface_version, char* buff );
+char *test_dest_flag( uint8_t dest_flag, char* buff );
+
+char* str_addr_ton( uint8_t ton, char *buff);
+char* str_addr_npi( uint8_t npi, char *buff);
+
+char *valueDec_32( uint32_t var, char *buff );
+char *valueDec_16( uint16_t var, char *buff );
+char *valueDec_08( uint8_t var, char *buff );
+char *nothing( uint32_t var, char *buff );
+#endif
diff --git a/src/smpp34_structs.c b/src/smpp34_structs.c
new file mode 100644
index 0000000..f043613
--- /dev/null
+++ b/src/smpp34_structs.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_structs.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+#include "smpp34_params.h"
+
+/* GLOBALS ********************************************************************/
+int smpp34_errno;
+char smpp34_strerror[2048];
+char *ptrerror = NULL;
+
+/* EXTERN *********************************************************************/
+/* FUNCTIONS ******************************************************************/
diff --git a/src/smpp34_structs.h b/src/smpp34_structs.h
new file mode 100644
index 0000000..d2cc1d3
--- /dev/null
+++ b/src/smpp34_structs.h
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_structs.h
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _STB_H_
+#define _STB_H_
+
+#define SMALL_BUFF 30
+/* Identify PDUs ident ********************************************************/
+#define MAX_TLV_SIZE 1024
+#define MAX_DAD_SIZE 21
+#define SERVICE_TYPE_LENGTH 6
+#define ADDRESS_LENGTH 21
+#define TIME_LENGTH 17
+#define SHORT_MESSAGE_LENGTH 255
+
+/* Globals for definitions ****************************************************/
+extern int smpp34_errno;
+extern char smpp34_strerror[2048];
+
+/* Define structures **********************************************************/
+typedef struct tlv_t tlv_t;
+typedef struct dad_t dad_t;
+typedef struct udad_t udad_t;
+typedef struct bind_transmitter_t bind_transmitter_t;
+typedef struct bind_transmitter_resp_t bind_transmitter_resp_t;
+typedef struct bind_receiver_t bind_receiver_t;
+typedef struct bind_receiver_resp_t bind_receiver_resp_t;
+typedef struct bind_transceiver_t bind_transceiver_t;
+typedef struct bind_transceiver_resp_t bind_transceiver_resp_t;
+typedef struct outbind_t outbind_t;
+typedef struct unbind_t unbind_t;
+typedef struct unbind_resp_t unbind_resp_t;
+typedef struct generic_nack_t generic_nack_t;
+typedef struct submit_sm_t submit_sm_t;
+typedef struct submit_sm_resp_t submit_sm_resp_t;
+typedef struct submit_multi_t submit_multi_t;
+typedef struct submit_multi_resp_t submit_multi_resp_t;
+typedef struct deliver_sm_t deliver_sm_t;
+typedef struct deliver_sm_resp_t deliver_sm_resp_t;
+typedef struct data_sm_t data_sm_t;
+typedef struct data_sm_resp_t data_sm_resp_t;
+typedef struct query_sm_t query_sm_t;
+typedef struct query_sm_resp_t query_sm_resp_t;
+typedef struct cancel_sm_t cancel_sm_t;
+typedef struct cancel_sm_resp_t cancel_sm_resp_t;
+typedef struct replace_sm_t replace_sm_t;
+typedef struct replace_sm_resp_t replace_sm_resp_t;
+typedef struct enquire_link_t enquire_link_t;
+typedef struct alert_notification_t alert_notification_t;
+
+/* TYPEDEFs structs ***********************************************************/
+#define instancia 0
+#define U32( inst, par, _str ) uint32_t par;
+#define U16( inst, par, _str ) uint16_t par;
+#define U08( inst, par, _str ) uint8_t par;
+
+#define O_C_OCTET( inst, par, size ) uint8_t par[ size ];
+#define C_OCTET( inst, par, size ) uint8_t par[ size ];
+#define OCTET8( inst, par, size ) uint8_t par[ size ];
+#define OCTET16( inst, par, size ) uint8_t par[ size ];
+
+#define TLV( inst, par, do_tlv ) tlv_t *par;
+#define UUU( inst, par, size ) union { \
+ U08( inst, val08, valueDec_08 ); \
+ U16( inst, val16, valueDec_16 ); \
+ U32( inst, val32, valueDec_32 ); \
+ OCTET16( inst, octet, size ); \
+} par;
+
+#define DAD( inst, par, do_dest_address ) dad_t *par;
+#define UU2( inst, par, size ) union { \
+ struct { \
+ U08( instancia, dest_addr_ton, str_addr_ton ); \
+ U08( instancia, dest_addr_npi, str_addr_npi ); \
+ C_OCTET( instancia, destination_addr, size ); \
+ } sme; \
+ C_OCTET( instancia, dl_name, size ); \
+} par;
+
+#define UDAD( inst, par, do_dest_address ) udad_t *par;
+
+struct dad_t {
+ #include "def_frame/dad.frame"
+};
+
+struct udad_t {
+ #include "def_frame/udad.frame"
+};
+
+struct tlv_t {
+ #include "def_frame/tlv.frame"
+};
+
+struct bind_transmitter_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_transmitter.frame"
+};
+
+struct bind_transmitter_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_transmitter_resp.frame"
+};
+
+struct bind_receiver_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_receiver.frame"
+};
+
+struct bind_receiver_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_receiver_resp.frame"
+};
+
+struct bind_transceiver_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_transceiver.frame"
+};
+
+struct bind_transceiver_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/bind_transceiver_resp.frame"
+};
+
+struct outbind_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/outbind.frame"
+};
+
+struct unbind_t {
+ #include "def_frame/header.frame"
+};
+
+struct unbind_resp_t {
+ #include "def_frame/header.frame"
+};
+
+struct generic_nack_t {
+ #include "def_frame/header.frame"
+};
+
+struct submit_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/submit_sm.frame"
+};
+
+struct submit_sm_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/submit_sm_resp.frame"
+};
+
+struct submit_multi_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/submit_multi.frame"
+};
+
+struct submit_multi_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/submit_multi_resp.frame"
+};
+
+struct deliver_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/deliver_sm.frame"
+};
+
+struct deliver_sm_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/deliver_sm_resp.frame"
+};
+
+struct data_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/data_sm.frame"
+};
+
+struct data_sm_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/data_sm_resp.frame"
+};
+
+struct query_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/query_sm.frame"
+};
+
+struct query_sm_resp_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/query_sm_resp.frame"
+};
+
+struct cancel_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/cancel_sm.frame"
+};
+
+struct cancel_sm_resp_t {
+ #include "def_frame/header.frame"
+};
+
+struct replace_sm_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/replace_sm.frame"
+};
+
+struct replace_sm_resp_t {
+ #include "def_frame/header.frame"
+};
+
+struct enquire_link_t {
+ #include "def_frame/header.frame"
+};
+
+typedef struct enquire_link_resp_t enquire_link_resp_t;
+struct enquire_link_resp_t {
+ #include "def_frame/header.frame"
+};
+
+struct alert_notification_t {
+ #include "def_frame/header.frame"
+ #include "def_frame/alert_notification.frame"
+};
+
+#include "def_frame/clean.frame"
+
+#define PUTLOG( format, param, value, parse ){\
+ int lenerror = 0;\
+ lenerror = snprintf((char*)ptrerror,lefterror,format,#param,value,parse);\
+ ptrerror += lenerror; lefterror -= lenerror;\
+}
+
+/* Prototypes *****************************************************************/
+int smpp34_dumpBuf(uint8_t *dest, int destL, uint8_t *src, int srcL);
+
+int smpp34_dumpPdu(uint32_t type, uint8_t *dest, int size_dest, void* tt);
+int smpp34_dumpPdu2(uint8_t *dest, int size_dest, void* tt);
+
+int smpp34_pack(uint32_t type,uint8_t *ptrBuf,int ptrSize,int *ptrLen,void* tt);
+int smpp34_pack2(uint8_t *ptrBuf,int ptrSize,int *ptrLen,void* tt);
+
+int smpp34_unpack(uint32_t type, void* tt, uint8_t *ptrBuf, int ptrLen);
+int smpp34_unpack2(void* tt, uint8_t *ptrBuf, int ptrLen);
+#endif /* _STB_H_ */
diff --git a/src/smpp34_unpack.c b/src/smpp34_unpack.c
new file mode 100644
index 0000000..9f7934c
--- /dev/null
+++ b/src/smpp34_unpack.c
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2006 Raul Tremsal
+ * File : smpp34_unpack.c
+ * Author: Raul Tremsal <ultraismo@yahoo.com>
+ *
+ * This file is part of libsmpp34 (c-open-smpp3.4 library).
+ *
+ * The libsmpp34 library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#endif
+
+#include "smpp34.h"
+#include "smpp34_structs.h"
+#include "smpp34_params.h"
+
+/* GLOBALS ********************************************************************/
+/* EXTERN *********************************************************************/
+extern int smpp34_errno;
+extern char smpp34_strerror[2048];
+extern char *ptrerror;
+
+/* FUNCTIONS ******************************************************************/
+int
+smpp34_unpack(uint32_t type, void* tt, uint8_t *ptrBuf, int ptrLen)
+{
+
+ char dummy_b[SMALL_BUFF];
+ uint8_t *ini = ptrBuf;
+ uint8_t *aux = ptrBuf;
+ int lenval = 0;
+ int left = ptrLen;
+ int lefterror = 0;
+
+ memset(smpp34_strerror, 0, sizeof(smpp34_strerror));
+ ptrerror = smpp34_strerror;
+ lefterror = sizeof(smpp34_strerror);
+
+#define instancia t1->
+
+#define U32( inst, par, _str ){\
+ lenval = sizeof( uint32_t );\
+ if( lenval > left ){\
+ PUTLOG("[%s:%08X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ memcpy(&inst par, aux, lenval);\
+ left -= lenval; aux += lenval;\
+ inst par = ntohl( inst par );\
+ _str(inst par, dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG( "[%s:%08X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%08X(%s)]", par, inst par, "OK");\
+};
+
+#define U16( inst, par, _str ){\
+ lenval = sizeof( uint16_t );\
+ if( lenval > left ){\
+ PUTLOG("[%s:%04X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ }\
+ memcpy(&inst par, aux, lenval);\
+ left -= lenval; aux += lenval;\
+ inst par = ntohs( inst par );\
+ _str(inst par, dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG("[%s:%04X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%04X(%s)]", par, inst par, "OK");\
+};
+
+#define U08( inst, par, _str ){\
+ lenval = sizeof( uint8_t );\
+ if( lenval > left ){\
+ PUTLOG("[%s:%02X(%s)]", par, inst par,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ memcpy(&inst par, aux, lenval);\
+ left -= lenval; aux += lenval;\
+ _str(inst par, dummy_b);\
+ if( strcmp("", dummy_b) == 0 ){\
+ PUTLOG( "[%s:%02X(%s)]", par, inst par, "Invalid value");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%02X(%s)]", par, inst par, "OK");\
+};
+
+/* NOTA: Importante, Los WARNINGs de los octetos, advierten de una
+ * inconsistencia de largo en los octets/c_octets recibidos, segun se
+ * decida el grado de restriccion estos pueden ser errores graves.
+ * La accion a tomar es truncar estos datos a los largos permitidos en la
+ * especicacion, pero seguir parseando (saltando segun los largos
+ * invalidos) los datos recibidos.
+ */
+#define O_C_OCTET( inst, par, sizeval ){\
+ if( !(inst command_status) ){\
+ C_OCTET( inst, par, sizeval );\
+ } else {\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ };\
+}
+
+
+#define C_OCTET( inst, par, size ){\
+ lenval = strlen( (char*) aux ) + 1;\
+ if( lenval > left ){\
+ PUTLOG("[len(%s):%d(%s)]", par, lenval, \
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( lenval > size ){\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "Data length is invalid");\
+ return( -1 );\
+ } else {\
+ /*snprintf(inst par, (lenval>size)?size:lenval, "%s", aux); */ \
+ memcpy(inst par, aux, lenval);\
+ left -= lenval; aux += lenval;\
+ PUTLOG("[%s:%s(%s)]", par, inst par, "OK");\
+ };\
+}
+
+#define OCTET8( inst, par, size ){\
+ lenval = *((inst par) - 1);\
+ if( lenval > left ){\
+ PUTLOG("[leng %s:%d(%s)]", par, lenval,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( lenval > size ){\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>",\
+ "Data length is invalid (truncate)");\
+ return( -1 );\
+ };\
+ memcpy(&inst par, aux, (lenval>size)?size:lenval);\
+ left -= lenval; aux += lenval;\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+}
+
+#define OCTET16( inst, par, size ){\
+ uint16_t l_lenval = 0; /* VERIFICAR ESTO */\
+ memcpy(&l_lenval, (inst par - sizeof(uint16_t)), sizeof(uint16_t));\
+ if( l_lenval > left ){\
+ PUTLOG("[leng %s:%d(%s)]", par, l_lenval,\
+ "Value lenght exceed buffer lenght");\
+ return( -1 );\
+ };\
+ if( l_lenval > size ){\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "Data length is invalid");\
+ return( -1 );\
+ };\
+ PUTLOG("[%s:%s(%s)]", par, "<bin>", "OK");\
+ memcpy(&(inst par), aux, (l_lenval>size)?size:l_lenval);\
+ left -= l_lenval; aux += l_lenval;\
+}
+
+#define TLV( inst, tlv3, do_tlv ){\
+ tlv_t *aux_tlv = NULL;\
+ while( (aux - ini) < t1->command_length ){\
+ aux_tlv = (tlv_t *) malloc(sizeof( tlv_t ));\
+ memset(aux_tlv, 0, sizeof(tlv_t));\
+ do_tlv( aux_tlv );\
+ aux_tlv->next = inst tlv3;\
+ inst tlv3 = aux_tlv;\
+ };\
+};
+
+#define UDAD( inst, udad3, do_udad ){\
+ udad_t *aux_udad = NULL;\
+ int c = 0;\
+ while( c < t1->no_unsuccess ){\
+ aux_udad = (udad_t *) malloc(sizeof( udad_t ));\
+ memset(aux_udad, 0, sizeof(udad_t));\
+ do_udad( aux_udad );\
+ aux_udad->next = inst udad3;\
+ inst udad3 = aux_udad;\
+ c++;\
+ };\
+};
+
+#define DAD( inst, dad3, do_dad ){\
+ dad_t *aux_dad = NULL;\
+ int c = 0;\
+ while( c < t1->number_of_dests ){\
+ aux_dad = (dad_t *) malloc(sizeof( dad_t ));\
+ memset(aux_dad, 0, sizeof(dad_t));\
+ do_dad( aux_dad );\
+ aux_dad->next = inst dad3;\
+ inst dad3 = aux_dad;\
+ c++;\
+ };\
+};
+
+#include "def_frame/alert_notification.tlv"
+#include "def_frame/bind_receiver_resp.tlv"
+#include "def_frame/bind_transceiver_resp.tlv"
+#include "def_frame/bind_transmitter_resp.tlv"
+#include "def_frame/data_sm.tlv"
+#include "def_frame/data_sm_resp.tlv"
+#include "def_frame/deliver_sm.tlv"
+#include "def_frame/submit_multi_resp.udad"
+#include "def_frame/submit_multi.dad"
+#include "def_frame/submit_multi.tlv"
+#include "def_frame/submit_sm.tlv"
+#include "def_list/smpp34_protocol.def"
+
+ { /* Hace algunas Verificaciones **************************************/
+ uint32_t len_orig;
+ uint32_t l;
+ memcpy(&len_orig, tt, sizeof(uint32_t));
+ l = ntohl( len_orig );
+ if( len_orig != (aux - ini) ){
+ PUTLOG("[%s:(Error in PDU length %d!=%d)]",PDU,len_orig,(uint32_t)(aux-ini));
+ return( -1 );
+ };
+ };
+
+#include "def_frame/clean.frame"
+ return( 0 );
+};
+
+int
+smpp34_unpack2(void* tt, uint8_t *ptrBuf, int ptrLen)
+{
+ uint32_t cmdid;
+ uint32_t tempo;
+ memcpy(&tempo, ptrBuf + 4, sizeof(uint32_t)); /* get command_id PDU */
+ cmdid = ntohl( tempo );
+ return( smpp34_unpack(cmdid, tt, ptrBuf, ptrLen) );
+};