2 * (C) 2010 by Holger Hans Peter Freyther
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <osmocom/core/application.h>
23 #include <osmocom/core/logging.h>
24 #include <osmocom/gsm/gsm0480.h>
29 static const uint8_t ussd_request
[] = {
30 0x0b, 0x7b, 0x1c, 0x15, 0xa1, 0x13, 0x02, 0x01,
31 0x03, 0x02, 0x01, 0x3b, 0x30, 0x0b, 0x04, 0x01,
32 0x0f, 0x04, 0x06, 0x2a, 0xd5, 0x4c, 0x16, 0x1b,
33 0x01, 0x7f, 0x01, 0x00
36 static int parse_ussd(const uint8_t *_data
, int len
)
40 struct ussd_request req
;
41 struct gsm48_hdr
*hdr
;
44 memcpy(data
, _data
, len
);
45 hdr
= (struct gsm48_hdr
*) &data
[0];
46 rc
= gsm0480_decode_ussd_request(hdr
, len
, &req
);
52 static int parse_mangle_ussd(const uint8_t *_data
, int len
)
56 struct ussd_request req
;
57 struct gsm48_hdr
*hdr
;
60 memcpy(data
, _data
, len
);
61 hdr
= (struct gsm48_hdr
*) &data
[0];
62 hdr
->data
[1] = len
- sizeof(*hdr
) - 2;
63 rc
= gsm0480_decode_ussd_request(hdr
, len
, &req
);
69 struct log_info info
= {};
71 int main(int argc
, char **argv
)
73 struct ussd_request req
;
74 const int size
= sizeof(ussd_request
);
77 osmo_init_logging(&info
);
79 gsm0480_decode_ussd_request((struct gsm48_hdr
*) ussd_request
, size
, &req
);
80 printf("Tested if it still works. Text was: %s\n", req
.text
);
83 printf("Testing parsing a USSD request and truncated versions\n");
85 for (i
= size
; i
> sizeof(struct gsm48_hdr
); --i
) {
86 int rc
= parse_ussd(&ussd_request
[0], i
);
87 printf("Result for %d is %d\n", rc
, i
);
90 printf("Mangling the container now\n");
91 for (i
= size
; i
> sizeof(struct gsm48_hdr
) + 2; --i
) {
92 int rc
= parse_mangle_ussd(&ussd_request
[0], i
);
93 printf("Result for %d is %d\n", rc
, i
);