blob: 6e11f9416d551c1733e810bb199851d6cce6398a [file] [log] [blame]
Pau Espin Pedrold7a209b2021-02-09 18:28:25 +01001/*
Vadim Yanitskiy03590fc2023-05-18 17:22:26 +07002 * (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Pau Espin Pedrold7a209b2021-02-09 18:28:25 +01003 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
4 * All Rights Reserved
5 *
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.
10 *
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.
15 *
Pau Espin Pedrold7a209b2021-02-09 18:28:25 +010016 */
17
18#include <string.h>
19#include <stdio.h>
20#include <stdlib.h>
21
22#include <osmocom/gsm/protocol/gsm_04_08.h>
23#include <osmocom/gsm/gsm48_rest_octets.h>
24
25struct si13_test {
26 const char *name;
27 const struct osmo_gsm48_si13_info si;
28 int enc_rc;
29 int dec_rc;
30 void (*post_dec_cb)(const struct si13_test *test, const struct osmo_gsm48_si13_info* dec);
31};
32
33void post_dec_cb_test_alpha(const struct si13_test *test, const struct osmo_gsm48_si13_info* dec)
34{
35 OSMO_ASSERT(test->si.pwr_ctrl_pars.alpha == dec->pwr_ctrl_pars.alpha);
36}
37
38static const struct si13_test test_si13_arr[] = {
39 {
40 .name = "test alpha",
41 .si = {
42 .cell_opts = {
43 .nmo = GPRS_NMO_II,
44 .t3168 = 2000,
45 .t3192 = 1500,
46 .drx_timer_max = 3,
47 .bs_cv_max = 15,
48 .ctrl_ack_type_use_block = true,
49 .ext_info_present = 0,
50 .ext_info = {
51 .egprs_supported = 1,
52 .use_egprs_p_ch_req = 1,
53 .bep_period = 5,
54 .pfc_supported = 0,
55 .dtm_supported = 0,
56 .bss_paging_coordination = 0,
57 .ccn_active = true,
58 },
59 },
60 .pwr_ctrl_pars = {
61 .alpha = 5,
62 .t_avg_w = 16,
63 .t_avg_t = 16,
64 .pc_meas_chan = 0,
65 .n_avg_i = 8,
66 },
67 .bcch_change_mark = 1,
68 .si_change_field = 0,
69 .rac = 0x03,
70 .spgc_ccch_sup = 0,
71 .net_ctrl_ord = 0,
72 .prio_acc_thr = 6,
73 },
74 .enc_rc = 20,
75 .dec_rc = 71,
76 .post_dec_cb = post_dec_cb_test_alpha,
77 },
78};
79
Harald Weltee61d4592022-11-03 11:05:58 +010080static void test_si13(void)
Pau Espin Pedrold7a209b2021-02-09 18:28:25 +010081{
82 int i, rc;
83 uint8_t data[GSM_MACBLOCK_LEN];
84 struct osmo_gsm48_si13_info si13;
85
86 for (i = 0; i < ARRAY_SIZE(test_si13_arr); i++) {
87 memset(data, 0, sizeof(data));
88 rc = osmo_gsm48_rest_octets_si13_encode(data, &test_si13_arr[i].si);
89 if (rc >= 0) {
90 printf("si13_encode (%d): %s\n", rc, osmo_hexdump(data, rc));
91 } else {
92 printf("si13_encode failed (%d)\n", rc);
93 }
94 OSMO_ASSERT(rc == test_si13_arr[i].enc_rc);
95 if (rc <= 0)
96 continue;
97 memset(&si13, 0 , sizeof(si13));
98 rc = osmo_gsm48_rest_octets_si13_decode(&si13, data);
99 if (rc >= 0) {
100 printf("si13_decode (%d)\n", rc);
101 } else {
102 printf("si13_decode failed (%d)\n", rc);
103 }
104 OSMO_ASSERT(rc == test_si13_arr[i].dec_rc);
105 if (test_si13_arr[i].post_dec_cb) {
106 test_si13_arr[i].post_dec_cb(&test_si13_arr[i], &si13);
107 }
108 }
109}
110
111int main(int argc, char **argv)
112{
113 test_si13();
114
115 return EXIT_SUCCESS;
116}