Kannel: Open Source WAP and SMS gateway  svn-r5335
decode_emimsg.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"
#include "gw/smsc/emimsg.c"
#include "gw/alt_charsets.h"

Go to the source code of this file.

Functions

static char * emi_typeop (int typeop)
 
int main (int argc, char **argv)
 

Function Documentation

◆ emi_typeop()

static char* emi_typeop ( int  typeop)
static

Definition at line 70 of file decode_emimsg.c.

Referenced by main().

71 {
72  switch (typeop) {
73  case 31:
74  return "Alert Operation";
75  case 51:
76  return "Submit Short Message operation";
77  case 52:
78  return "Delivery Short Message operation";
79  case 53:
80  return "Delivery notification operation";
81  case 54:
82  return "Modify Short Message operation";
83  case 55:
84  return "Inquiry message operation";
85  case 56:
86  return "Delete message operation";
87  case 57:
88  return "Response Inquiry message operation";
89  case 58:
90  return "Response delete message operation";
91  case 60:
92  return "Session management operation";
93  case 61:
94  return "Provisioning actions operation";
95  default:
96  return "!UNRECOGNIZED CODE!";
97  }
98 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 100 of file decode_emimsg.c.

References charset_gsm_to_latin1(), E01_AC, E01_ADC, E01_AMSG, E01_MT, E01_OADC, E50_AC, E50_ADC, E50_AMSG, E50_CPG, E50_DCS, E50_DD, E50_DDT, E50_DSCTS, E50_DST, E50_HPLMN, E50_LPID, E50_LRAD, E50_LRQ, E50_MCLS, E50_MMS, E50_MT, E50_NADC, E50_NB, E50_NMSG, E50_NPID, E50_NRQ, E50_NT, E50_OADC, E50_OTOA, E50_PR, E50_RES4, E50_RES5, E50_RPI, E50_RPID, E50_RPLY, E50_RSN, E50_SCTS, E50_TMSG, E50_VP, E50_XSER, E60_LADC, E60_LNPI, E60_LTON, E60_NPWD, E60_OADC, E60_ONPI, E60_OPID, E60_OTON, E60_PWD, E60_RES1, E60_STYP, E60_VERS, emi_typeop(), emimsg::fields, get_fields(), gwlib_init(), gwlib_shutdown(), octstr_create, octstr_destroy(), octstr_format(), octstr_get_char(), octstr_get_cstr, octstr_hex_to_binary(), emimsg::or, emimsg::ot, panic, and emimsg::trn.

101 {
102  Octstr *message, *whoami;
103  struct emimsg *emimsg;
104 
105  printf("/* This tool can decode an UCP/EMI packet. <v.chavanis@telemaque.fr> */\n\n");
106 
107  gwlib_init();
108 
109  if (argc < 2)
110  panic(0, "Syntax: %s <packet_without_STX/ETX>\n", argv[0]);
111 
112  message = octstr_format("\02%s\03", argv[1]); // fit the UCP specs.
113  whoami = octstr_create("DECODE");
114 
115  emimsg = get_fields(message, whoami);
116 
117  if (emimsg != NULL) {
118  printf("\n");
119  printf("TRN \t%d\n", emimsg->trn);
120  printf("TYPE \t%c (%s)\n", emimsg->or, emimsg->or == 'R' ? "Result" : "Operation");
121  printf("OPERATION\t%d (%s)\n", emimsg->ot, emi_typeop (emimsg->ot));
122 
123  if (emimsg->ot == 01) {
124  printf("E01_ADC \t%s\n",
126  printf("E01_OADC \t%s\n",
128  printf("E01_AC \t%s\n",
130  printf("E01_ADC \t%s\n",
132  printf("E01_MT \t%s\n",
134  if (octstr_get_char(emimsg->fields[E01_MT], 0) == '3') {
136  }
137  printf("E01_AMSG \t%s\n",
139  }
140 
141  if ((emimsg->ot == 31 || (emimsg->ot >= 50 && emimsg->ot <= 60))
142  && emimsg->or == 'R' &&
143  (octstr_get_char(emimsg->fields[E50_ADC], 0) == 'A' ||
144  octstr_get_char(emimsg->fields[E50_ADC], 0) == 'N')) {
145  printf("E%d_ACK \t%s\n", emimsg->ot,
147  printf("E%d_SM \t%s\n", emimsg->ot,
149  }
150 
151  if (emimsg->ot == 31 && emimsg->or == 'O') {
152  printf("E50_ADC \t%s\n",
154  printf("E50_PID \t%s\n",
156  }
157 
158  if (emimsg->ot >= 50 && emimsg->ot <= 59 &&
159  octstr_get_char(emimsg->fields[E50_ADC], 0) != 'A' &&
160  octstr_get_char(emimsg->fields[E50_ADC], 0) != 'N') {
161  printf("E50_ADC \t%s\n",
163  printf("E50_OADC \t%s\n",
165  printf("E50_AC \t%s\n",
167  printf("E50_NRQ \t%s\n",
169  printf("E50_NADC \t%s\n",
171  printf("E50_NT \t%s\n",
173  printf("E50_NPID \t%s\n",
175  printf("E50_LRQ \t%s\n",
177  printf("E50_LRAD \t%s\n",
179  printf("E50_LPID \t%s\n",
181  printf("E50_DD \t%s\n",
183  printf("E50_DDT \t%s\n",
185  printf("E50_VP \t%s\n",
187  printf("E50_RPID \t%s\n",
189  printf("E50_SCTS \t%s\n",
191  printf("E50_DST \t%s\n",
193  printf("E50_RSN \t%s\n",
195  printf("E50_DSCTS\t%s\n",
197  printf("E50_MT \t%s\n",
199  printf("E50_NB \t%s\n",
201  printf("E50_NMSG \t%s\n",
203  if (emimsg->fields[E50_AMSG])
205  if (octstr_get_char(emimsg->fields[E50_MT], 0) == '3') {
207  }
208 
209  printf("E50_AMSG \t%s\n",
211  printf("E50_TMSG \t%s\n",
213  printf("E50_MMS \t%s\n",
215  printf("E50_PR \t%s\n",
217  printf("E50_DCS \t%s\n",
219  printf("E50_MCLS \t%s\n",
221  printf("E50_RPI \t%s\n",
223  printf("E50_CPG \t%s\n",
225  printf("E50_RPLY \t%s\n",
227  printf("E50_OTOA \t%s\n",
229  printf("E50_HPLMN\t%s\n",
231  printf("E50_XSER \t%s\n",
233  printf("E50_RES4 \t%s\n",
235  printf("E50_RES5 \t%s\n",
237  }
238 
239  if ((emimsg->ot == 60 || emimsg->ot == 61) &&
240  (octstr_get_char(emimsg->fields[E50_ADC], 0) != 'A' &&
241  octstr_get_char(emimsg->fields[E50_ADC], 0) != 'N')) {
242  printf("E60_OADC \t%s\n",
244  printf("E60_OTON \t%s\n",
246  printf("E60_ONPI \t%s\n",
248  printf("E60_STYP \t%s\n",
250  if (emimsg->fields[E60_PWD])
252  printf("E60_PWD \t%s\n",
254  printf("E60_NPWD \t%s\n",
256  printf("E60_VERS \t%s\n",
258  printf("E60_LADC \t%s\n",
260  printf("E60_LTON \t%s\n",
262  printf("E60_LNPI \t%s\n",
264  printf("E60_OPID \t%s\n",
266  printf("E60_RES1 \t%s\n",
268  }
269  }
270 
271  octstr_destroy(message);
272  octstr_destroy(whoami);
273  gwlib_shutdown();
274 
275  return 0;
276 }
Definition: emimsg.h:87
Definition: emimsg.h:81
Definition: emimsg.h:87
Definition: emimsg.h:89
Definition: emimsg.h:90
char or
Definition: emimsg.h:72
Definition: emimsg.h:96
int trn
Definition: emimsg.h:71
Definition: emimsg.h:88
Definition: emimsg.h:70
struct emimsg * get_fields(Octstr *message, Octstr *whoami)
Definition: emimsg.c:290
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Definition: emimsg.h:89
Definition: emimsg.h:88
Definition: emimsg.h:87
Definition: emimsg.h:81
Definition: emimsg.h:88
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: emimsg.h:87
Definition: emimsg.h:90
void charset_gsm_to_latin1(Octstr *ostr)
Definition: charset.c:394
int ot
Definition: emimsg.h:73
Definition: octstr.c:118
Definition: emimsg.h:88
Definition: emimsg.h:81
#define panic
Definition: log.h:87
Octstr ** fields
Definition: emimsg.h:75
int octstr_hex_to_binary(Octstr *ostr)
Definition: octstr.c:494
Definition: emimsg.h:90
static char * emi_typeop(int typeop)
Definition: decode_emimsg.c:70
void gwlib_shutdown(void)
Definition: gwlib.c:94
Definition: emimsg.h:90
Definition: emimsg.h:87
void gwlib_init(void)
Definition: gwlib.c:78
Definition: emimsg.h:90
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
Definition: emimsg.h:89
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.