Kannel: Open Source WAP and SMS gateway  svn-r5335
decode_emimsg.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2018 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",
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
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: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.