blob: 077063bed04f8d986d12500c1b3fbefd5bb31967 [file] [log] [blame]
Harald Weltec8a0b932012-08-24 21:27:26 +02001/*
2 * (C) 2012 by Harald Welte <laforge@gnumonks.org>
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 <string.h>
22#include <stdio.h>
23
24#include <osmocom/gsm/protocol/gsm_04_08.h>
25#include <osmocom/gsm/gsm48_ie.h>
26#include <osmocom/gsm/mncc.h>
27#include <osmocom/core/utils.h>
28#include <osmocom/core/msgb.h>
29
30
31static const uint8_t csd_9600_v110_lv[] = { 0x07, 0xa1, 0xb8, 0x89, 0x21, 0x15, 0x63, 0x80 };
32
33static const struct gsm_mncc_bearer_cap bcap_csd_9600_v110 = {
34 .transfer = GSM48_BCAP_ITCAP_UNR_DIG_INF,
35 .mode = GSM48_BCAP_TMOD_CIRCUIT,
36 .coding = GSM48_BCAP_CODING_GSM_STD,
37 .radio = GSM48_BCAP_RRQ_FR_ONLY,
38 .speech_ver[0]= -1,
39 .data = {
40 .rate_adaption = GSM48_BCAP_RA_V110_X30,
41 .sig_access = GSM48_BCAP_SA_I440_I450,
42 .async = 1,
43 .nr_stop_bits = 1,
44 .nr_data_bits = 8,
45 .user_rate = GSM48_BCAP_UR_9600,
46 .parity = GSM48_BCAP_PAR_NONE,
47 .interm_rate = GSM48_BCAP_IR_16k,
48 .transp = GSM48_BCAP_TR_TRANSP,
49 .modem_type = GSM48_BCAP_MT_NONE,
50 },
51};
52
53static const uint8_t speech_all_lv[] = { 0x06, 0x60, 0x04, 0x02, 0x00, 0x05, 0x81 };
54
55static const struct gsm_mncc_bearer_cap bcap_speech_all = {
56 .transfer = GSM48_BCAP_ITCAP_SPEECH,
57 .mode = GSM48_BCAP_TMOD_CIRCUIT,
58 .coding = GSM48_BCAP_CODING_GSM_STD,
59 .radio = GSM48_BCAP_RRQ_DUAL_FR,
60 .speech_ver = {
61 4, 2, 0, 5, 1, -1,
62 },
63};
64
65
66struct bcap_test {
67 const uint8_t *lv;
68 const struct gsm_mncc_bearer_cap *bc;
69 const char *name;
70};
71
72static const struct bcap_test bcap_tests[] = {
73 { csd_9600_v110_lv, &bcap_csd_9600_v110, "CSD 9600/V.110/transparent" },
74 { speech_all_lv, &bcap_speech_all, "Speech, all codecs" },
75};
76
77static int test_bearer_cap()
78{
79 struct gsm_mncc_bearer_cap bc;
80 int i, rc;
81
82 for (i = 0; i < ARRAY_SIZE(bcap_tests); i++) {
83 struct msgb *msg = msgb_alloc(100, "test");
84 int lv_len;
85
86 memset(&bc, 0, sizeof(bc));
87
88 /* test decoding */
89 rc = gsm48_decode_bearer_cap(&bc, bcap_tests[i].lv);
90 if (rc < 0) {
91 fprintf(stderr, "Error decoding %s\n",
92 bcap_tests[i].name);
93 return rc;
94 }
95 if (memcmp(&bc, bcap_tests[i].bc, sizeof(bc))) {
96 fprintf(stderr, "Incorrect decoded result of %s:\n",
97 bcap_tests[i].name);
98 fprintf(stderr, " should: %s\n",
99 osmo_hexdump((uint8_t *) bcap_tests[i].bc, sizeof(bc)));
100 fprintf(stderr, " is: %s\n",
101 osmo_hexdump((uint8_t *) &bc, sizeof(bc)));
102 return -1;
103 }
104
105 /* also test re-encode? */
106 rc = gsm48_encode_bearer_cap(msg, 1, &bc);
107 if (rc < 0) {
108 fprintf(stderr, "Error encoding %s\n",
109 bcap_tests[i].name);
110 return rc;
111 }
112 lv_len = bcap_tests[i].lv[0]+1;
113 if (memcmp(msg->data, bcap_tests[i].lv, lv_len)) {
114 fprintf(stderr, "Incorrect encoded result of %s:\n",
115 bcap_tests[i].name);
116 fprintf(stderr, " should: %s\n",
117 osmo_hexdump(bcap_tests[i].lv, lv_len));
118 fprintf(stderr, " is: %s\n",
119 osmo_hexdump(msg->data, msg->len));
120 return -1;
121 }
122
123 printf("Test `%s' passed\n", bcap_tests[i].name);
124 msgb_free(msg);
125 }
126
127 return 0;
128}
129
130int main(int argc, char **argv)
131{
132 test_bearer_cap();
133}