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