Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
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

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 }
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",
125  octstr_get_cstr(emimsg->fields[E01_ADC]));
126  printf("E01_OADC \t%s\n",
127  octstr_get_cstr(emimsg->fields[E01_OADC]));
128  printf("E01_AC \t%s\n",
129  octstr_get_cstr(emimsg->fields[E01_AC]));
130  printf("E01_ADC \t%s\n",
131  octstr_get_cstr(emimsg->fields[E01_ADC]));
132  printf("E01_MT \t%s\n",
133  octstr_get_cstr(emimsg->fields[E01_MT]));
134  if (octstr_get_char(emimsg->fields[E01_MT], 0) == '3') {
136  }
137  printf("E01_AMSG \t%s\n",
138  octstr_get_cstr(emimsg->fields[E01_AMSG]));
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,
146  octstr_get_cstr(emimsg->fields[E50_ADC]));
147  printf("E%d_SM \t%s\n", emimsg->ot,
148  octstr_get_cstr(emimsg->fields[E50_OADC]));
149  }
150 
151  if (emimsg->ot == 31 && emimsg->or == 'O') {
152  printf("E50_ADC \t%s\n",
153  octstr_get_cstr(emimsg->fields[E50_ADC]));
154  printf("E50_PID \t%s\n",
155  octstr_get_cstr(emimsg->fields[E50_OADC]));
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",
162  octstr_get_cstr(emimsg->fields[E50_ADC]));
163  printf("E50_OADC \t%s\n",
164  octstr_get_cstr(emimsg->fields[E50_OADC]));
165  printf("E50_AC \t%s\n",
166  octstr_get_cstr(emimsg->fields[E50_AC]));
167  printf("E50_NRQ \t%s\n",
168  octstr_get_cstr(emimsg->fields[E50_NRQ]));
169  printf("E50_NADC \t%s\n",
170  octstr_get_cstr(emimsg->fields[E50_NADC]));
171  printf("E50_NT \t%s\n",
172  octstr_get_cstr(emimsg->fields[E50_NT]));
173  printf("E50_NPID \t%s\n",
174  octstr_get_cstr(emimsg->fields[E50_NPID]));
175  printf("E50_LRQ \t%s\n",
176  octstr_get_cstr(emimsg->fields[E50_LRQ]));
177  printf("E50_LRAD \t%s\n",
178  octstr_get_cstr(emimsg->fields[E50_LRAD]));
179  printf("E50_LPID \t%s\n",
180  octstr_get_cstr(emimsg->fields[E50_LPID]));
181  printf("E50_DD \t%s\n",
182  octstr_get_cstr(emimsg->fields[E50_DD]));
183  printf("E50_DDT \t%s\n",
184  octstr_get_cstr(emimsg->fields[E50_DDT]));
185  printf("E50_VP \t%s\n",
186  octstr_get_cstr(emimsg->fields[E50_VP]));
187  printf("E50_RPID \t%s\n",
188  octstr_get_cstr(emimsg->fields[E50_RPID]));
189  printf("E50_SCTS \t%s\n",
190  octstr_get_cstr(emimsg->fields[E50_SCTS]));
191  printf("E50_DST \t%s\n",
192  octstr_get_cstr(emimsg->fields[E50_DST]));
193  printf("E50_RSN \t%s\n",
194  octstr_get_cstr(emimsg->fields[E50_RSN]));
195  printf("E50_DSCTS\t%s\n",
196  octstr_get_cstr(emimsg->fields[E50_DSCTS]));
197  printf("E50_MT \t%s\n",
198  octstr_get_cstr(emimsg->fields[E50_MT]));
199  printf("E50_NB \t%s\n",
200  octstr_get_cstr(emimsg->fields[E50_NB]));
201  printf("E50_NMSG \t%s\n",
202  octstr_get_cstr(emimsg->fields[E50_NMSG]));
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",
210  octstr_get_cstr(emimsg->fields[E50_AMSG]));
211  printf("E50_TMSG \t%s\n",
212  octstr_get_cstr(emimsg->fields[E50_TMSG]));
213  printf("E50_MMS \t%s\n",
214  octstr_get_cstr(emimsg->fields[E50_MMS]));
215  printf("E50_PR \t%s\n",
216  octstr_get_cstr(emimsg->fields[E50_PR]));
217  printf("E50_DCS \t%s\n",
218  octstr_get_cstr(emimsg->fields[E50_DCS]));
219  printf("E50_MCLS \t%s\n",
220  octstr_get_cstr(emimsg->fields[E50_MCLS]));
221  printf("E50_RPI \t%s\n",
222  octstr_get_cstr(emimsg->fields[E50_RPI]));
223  printf("E50_CPG \t%s\n",
224  octstr_get_cstr(emimsg->fields[E50_CPG]));
225  printf("E50_RPLY \t%s\n",
226  octstr_get_cstr(emimsg->fields[E50_RPLY]));
227  printf("E50_OTOA \t%s\n",
228  octstr_get_cstr(emimsg->fields[E50_OTOA]));
229  printf("E50_HPLMN\t%s\n",
230  octstr_get_cstr(emimsg->fields[E50_HPLMN]));
231  printf("E50_XSER \t%s\n",
232  octstr_get_cstr(emimsg->fields[E50_XSER]));
233  printf("E50_RES4 \t%s\n",
234  octstr_get_cstr(emimsg->fields[E50_RES4]));
235  printf("E50_RES5 \t%s\n",
236  octstr_get_cstr(emimsg->fields[E50_RES5]));
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",
243  octstr_get_cstr(emimsg->fields[E60_OADC]));
244  printf("E60_OTON \t%s\n",
245  octstr_get_cstr(emimsg->fields[E60_OTON]));
246  printf("E60_ONPI \t%s\n",
247  octstr_get_cstr(emimsg->fields[E60_ONPI]));
248  printf("E60_STYP \t%s\n",
249  octstr_get_cstr(emimsg->fields[E60_STYP]));
250  if (emimsg->fields[E60_PWD])
252  printf("E60_PWD \t%s\n",
253  octstr_get_cstr(emimsg->fields[E60_PWD]));
254  printf("E60_NPWD \t%s\n",
255  octstr_get_cstr(emimsg->fields[E60_NPWD]));
256  printf("E60_VERS \t%s\n",
257  octstr_get_cstr(emimsg->fields[E60_VERS]));
258  printf("E60_LADC \t%s\n",
259  octstr_get_cstr(emimsg->fields[E60_LADC]));
260  printf("E60_LTON \t%s\n",
261  octstr_get_cstr(emimsg->fields[E60_LTON]));
262  printf("E60_LNPI \t%s\n",
263  octstr_get_cstr(emimsg->fields[E60_LNPI]));
264  printf("E60_OPID \t%s\n",
265  octstr_get_cstr(emimsg->fields[E60_OPID]));
266  printf("E60_RES1 \t%s\n",
267  octstr_get_cstr(emimsg->fields[E60_RES1]));
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:2462
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#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:492
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:404
Definition: emimsg.h:89
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.