blob: dfc43cf70858e76d601a9f815325c8a353fe21d8 [file] [log] [blame]
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +00001/*
2 * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdio.h>
Holger Freyther59da07b2009-02-23 00:50:38 +000022#include <stdlib.h>
23#include <string.h>
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000024#include <sys/types.h>
25#include <openbsc/debug.h>
26#include <openbsc/msgb.h>
27#include <openbsc/gsm_04_11.h>
28#include <openbsc/gsm_04_08.h>
Holger Freyther59da07b2009-02-23 00:50:38 +000029#include <openbsc/gsm_utils.h>
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000030
31/* SMS data from MS starting with layer 3 header */
Daniel Willmann6e6143e2008-12-28 21:38:26 +000032static u_int8_t sms1[] = {
33 0x39, 0x01, 0x1a, 0x00, 0x01, 0x00, 0x07, 0x91, 0x55, 0x11,
34 0x18, 0x31, 0x28, 0x00, 0x0e, 0x31, 0x20, 0x04, 0x81, 0x21,
35 0x43, 0x00, 0x00, 0xff, 0x04, 0xd4, 0xf2, 0x9c, 0x0e
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000036};
37
Daniel Willmann6e6143e2008-12-28 21:38:26 +000038static u_int8_t sms2[] = {
39 0x09, 0x01, 0x9c, 0x00, 0xda, 0x00, 0x07, 0x91, 0x88, 0x96, 0x13,
40 0x00, 0x00, 0x99, 0x90, 0x11, 0x7b, 0x04, 0x81, 0x22, 0x22, 0x00,
41 0x08, 0xff, 0x86, 0x6c, 0x38, 0x8c, 0x50, 0x92, 0x80, 0x88, 0x4c,
42 0x00, 0x4d, 0x00, 0x4d, 0x00, 0x41, 0x6a, 0x19, 0x67, 0x03, 0x74,
43 0x06, 0x8c, 0xa1, 0x7d, 0xb2, 0x00, 0x20, 0x00, 0x20, 0x51, 0x68,
44 0x74, 0x03, 0x99, 0x96, 0x52, 0x75, 0x7d, 0xb2, 0x8d, 0xef, 0x6a,
45 0x19, 0x67, 0x03, 0xff, 0x0c, 0x6a, 0x19, 0x67, 0x03, 0x96, 0xf6,
46 0x98, 0xa8, 0x96, 0xaa, 0xff, 0x01, 0x8b, 0x93, 0x60, 0xa8, 0x80,
47 0x70, 0x66, 0x0e, 0x51, 0x32, 0x84, 0xc4, 0xff, 0x0c, 0x97, 0x48,
48 0x6d, 0x3b, 0x62, 0x95, 0x8c, 0xc7, 0xff, 0x01, 0x73, 0xfe, 0x57,
49 0x28, 0x52, 0xa0, 0x51, 0x65, 0x90, 0x01, 0x96, 0x50, 0x91, 0xcf,
50 0x59, 0x27, 0x80, 0x6f, 0x76, 0xdf, 0x6d, 0x0b, 0x57, 0xfa, 0x96,
51 0x8a, 0x91, 0x77, 0x5e, 0x63, 0x53, 0x61, 0xff, 0x0c, 0x8a, 0xcb,
52 0x4e, 0x0a, 0x7d, 0xb2, 0x64, 0x1c, 0x5c, 0x0b, 0x30, 0x0c, 0x6a,
53 0x19, 0x67, 0x03, 0x30, 0x0d
54};
55
56struct sms_datum {
57 u_int8_t len;
58 u_int8_t *data;
59};
60
61static struct sms_datum sms_data[] = {
62 {
63 .len = sizeof(sms1),
64 .data = sms1,
65 }, {
66 .len = sizeof(sms2),
67 .data = sms2,
68 }
69};
70
Holger Freyther73e61c42009-02-23 00:50:34 +000071#define SMS_NUM (sizeof(sms_data)/sizeof(sms_data[0]))
Daniel Willmann6e6143e2008-12-28 21:38:26 +000072
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000073int main(int argc, char** argv)
74{
75 DEBUGP(DSMS, "SMS testing\n");
76 struct msgb *msg;
77 u_int8_t *sms;
Daniel Willmann6e6143e2008-12-28 21:38:26 +000078 u_int8_t i;
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000079
Holger Freyther59da07b2009-02-23 00:50:38 +000080 /* test 7-bit coding/decoding */
81 const char *input = "test text";
82 u_int8_t length;
Harald Welte7e310b12009-03-30 20:56:32 +000083 u_int8_t coded[256];
84 char result[256];
85
86 length = gsm_7bit_encode(coded, input);
87 gsm_7bit_decode(result, coded, length);
Holger Freyther59da07b2009-02-23 00:50:38 +000088 if (strcmp(result, input) != 0) {
89 printf("7 Bit coding failed... life sucks\n");
90 printf("Wanted: '%s' got '%s'\n", input, result);
91 }
92
Daniel Willmann6e6143e2008-12-28 21:38:26 +000093 for(i=0;i<SMS_NUM;i++) {
94 /* Setup SMS msgb */
95 msg = msgb_alloc(sms_data[i].len);
96 sms = msgb_put(msg, sms_data[i].len);
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +000097
Daniel Willmann6e6143e2008-12-28 21:38:26 +000098 memcpy(sms, sms_data[i].data, sms_data[i].len);
99 msg->l3h = sms;
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +0000100
Daniel Willmann6e6143e2008-12-28 21:38:26 +0000101 gsm0411_rcv_sms(msg);
102 msgb_free(msg);
103 }
Daniel Willmann6fe997e2008-12-29 04:20:41 +0000104
105 gsm0411_send_sms(0, 0);
Daniel Willmannfdd0a6c2008-12-28 01:51:14 +0000106}
Holger Freyther0df0f872009-02-11 00:33:51 +0000107
108/* stubs */
109void input_event(void) {}
Holger Freyther3281f6e2009-02-20 18:33:00 +0000110void nm_state_event(void) {}