Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
decode_emimsg.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * decode_emimsg.c - This tool can decode an UCP/EMI packet. <v.chavanis@telemaque.fr>
59  *
60  */
61 
62 #include <string.h>
63 #include <unistd.h>
64 #include <signal.h>
65 
66 #include "gwlib/gwlib.h"
67 #include "gw/smsc/emimsg.c"
68 #include "gw/alt_charsets.h"
69 
70 static char *emi_typeop(int typeop)
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 }
99 
100 int main (int argc, char **argv)
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
int main(int argc, char **argv)
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.