blob: 6806f20e130131efeb47bd64a2503f16c482d3b4 [file] [log] [blame]
Oliver Smithcfb63212019-09-05 17:13:33 +02001/* Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Oliver Smithcfb63212019-09-05 17:13:33 +020012 */
13
14#include <cstdlib>
15#include <cstring>
16#include <assert.h>
17#include "gprs_rlcmac.h"
18#include "bts.h"
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010019#include "tbf_dl.h"
Oliver Smithcfb63212019-09-05 17:13:33 +020020
21extern "C" {
22#include <osmocom/vty/telnet_interface.h>
23#include <osmocom/vty/logging.h>
24#include <osmocom/core/utils.h>
25#include <osmocom/core/msgb.h>
26#include <osmocom/core/application.h>
27}
28
29using namespace std;
30gprs_rlcmac_dl_tbf *tbf1, *tbf2;
31GprsMs *ms1, *ms2;
32struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf);
33
34/* globals used by the code */
35void *tall_pcu_ctx;
36int16_t spoof_mnc = 0, spoof_mcc = 0;
37bool spoof_mnc_3_digits = false;
38
39void test_enc_zero_len() {
40 struct gsm_pcu_if_app_info_req req = {0, 0, {0}};
41
42 fprintf(stderr, "--- %s ---\n", __func__);
43 assert(gprs_rlcmac_app_info_msg(&req) == NULL);
44 fprintf(stderr, "\n");
45}
46
Oliver Smith2beb1b82019-09-18 13:47:25 +020047void test_enc(const struct gsm_pcu_if_app_info_req *req)
48{
Oliver Smithcfb63212019-09-05 17:13:33 +020049 const char *exp = "03 fc 03 fc 00 00 00 00 00 00 00 00 00 00 00 00 "; /* shifted by two bits to the right */
50 struct msgb *msg;
51 char *msg_dump;
52
53 fprintf(stderr, "--- %s ---\n", __func__);
Oliver Smith2beb1b82019-09-18 13:47:25 +020054 msg = gprs_rlcmac_app_info_msg(req);
Oliver Smithcfb63212019-09-05 17:13:33 +020055 msg_dump = msgb_hexdump_c(tall_pcu_ctx, msg);
56
57 fprintf(stderr, "exp: %s\n", exp);
58 fprintf(stderr, "msg: %s\n", msg_dump);
59 assert(strcmp(msg_dump, exp) == 0);
60
61 msgb_free(msg);
62 talloc_free(msg_dump);
63 fprintf(stderr, "\n");
64}
65
66void test_pcu_rx_no_subscr_with_active_tbf()
67{
68 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
69
70 fprintf(stderr, "--- %s ---\n", __func__);
Pau Espin Pedrol1989a192021-06-23 19:46:07 +020071 pcu_rx(&pcu_prim, sizeof(struct gsm_pcu_if));
Oliver Smithcfb63212019-09-05 17:13:33 +020072 fprintf(stderr, "\n");
73}
74
75void prepare_bts_with_two_dl_tbf_subscr()
76{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010077 struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
Oliver Smithcfb63212019-09-05 17:13:33 +020078 struct gprs_rlcmac_trx *trx;
79
80 fprintf(stderr, "--- %s ---\n", __func__);
81
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010082 the_pcu->alloc_algorithm = alloc_algorithm_b;
Oliver Smithcfb63212019-09-05 17:13:33 +020083
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010084 trx = bts->trx;
Oliver Smithcfb63212019-09-05 17:13:33 +020085 trx->pdch[4].enable();
86 trx->pdch[5].enable();
87 trx->pdch[6].enable();
88 trx->pdch[7].enable();
89
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010090 ms1 = bts_alloc_ms(bts, 10, 11);
Pau Espin Pedrol87573842022-10-26 20:23:45 +020091 tbf1 = dl_tbf_alloc(bts, ms1, 0, false);
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010092 ms2 = bts_alloc_ms(bts, 12, 13);
Pau Espin Pedrol87573842022-10-26 20:23:45 +020093 tbf2 = dl_tbf_alloc(bts, ms2, 0, false);
Oliver Smithcfb63212019-09-05 17:13:33 +020094
95 fprintf(stderr, "\n");
96}
97
Oliver Smith2beb1b82019-09-18 13:47:25 +020098void test_sched_app_info_ok(const struct gsm_pcu_if_app_info_req *req)
Oliver Smithcfb63212019-09-05 17:13:33 +020099{
100 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
101 struct msgb *msg;
102
103 fprintf(stderr, "--- %s ---\n", __func__);
Oliver Smith2beb1b82019-09-18 13:47:25 +0200104 pcu_prim.u.app_info_req = *req;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +0200105 pcu_rx(&pcu_prim, sizeof(struct gsm_pcu_if));
Oliver Smithcfb63212019-09-05 17:13:33 +0200106
107 msg = sched_app_info(tbf1);
108 assert(msg);
109 msgb_free(msg);
110
111 msg = sched_app_info(tbf2);
112 assert(msg);
113 msgb_free(msg);
114
115 fprintf(stderr, "\n");
116}
117
Oliver Smith2beb1b82019-09-18 13:47:25 +0200118void test_sched_app_info_missing_app_info_in_bts(const struct gsm_pcu_if_app_info_req *req)
Oliver Smithcfb63212019-09-05 17:13:33 +0200119{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100120 struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
Oliver Smithcfb63212019-09-05 17:13:33 +0200121 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
122
123 fprintf(stderr, "--- %s ---\n", __func__);
Oliver Smith2beb1b82019-09-18 13:47:25 +0200124 pcu_prim.u.app_info_req = *req;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +0200125 pcu_rx(&pcu_prim, sizeof(struct gsm_pcu_if));
Oliver Smithcfb63212019-09-05 17:13:33 +0200126
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100127 msgb_free(bts->app_info);
128 bts->app_info = NULL;
Oliver Smithcfb63212019-09-05 17:13:33 +0200129
130 assert(sched_app_info(tbf1) == NULL);
131
132 fprintf(stderr, "\n");
133}
134
Oliver Smith2beb1b82019-09-18 13:47:25 +0200135void test_pcu_rx_overwrite_app_info(const struct gsm_pcu_if_app_info_req *req)
Oliver Smithcfb63212019-09-05 17:13:33 +0200136{
137 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
138
139 fprintf(stderr, "--- %s ---\n", __func__);
Oliver Smith2beb1b82019-09-18 13:47:25 +0200140 pcu_prim.u.app_info_req = *req;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +0200141 pcu_rx(&pcu_prim, sizeof(struct gsm_pcu_if));
142 pcu_rx(&pcu_prim, sizeof(struct gsm_pcu_if));
Oliver Smithcfb63212019-09-05 17:13:33 +0200143 fprintf(stderr, "\n");
144}
145
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100146extern "C" void cleanup()
Oliver Smithcfb63212019-09-05 17:13:33 +0200147{
148 fprintf(stderr, "--- %s ---\n", __func__);
149
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100150 struct gprs_rlcmac_bts *bts;
151
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100152 tbf_free(tbf1);
153 tbf_free(tbf2);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100154
155 bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
156 talloc_free(bts);
157
Pau Espin Pedrol2182e622021-01-14 16:48:38 +0100158 /* FIXME: talloc report disabled, because bts_alloc_ms(bts, ) in prepare_bts_with_two_dl_tbf_subscr() causes leak */
Oliver Smithcfb63212019-09-05 17:13:33 +0200159 /* talloc_report_full(tall_pcu_ctx, stderr); */
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100160 talloc_free(the_pcu);
Oliver Smithcfb63212019-09-05 17:13:33 +0200161 talloc_free(tall_pcu_ctx);
162}
163
164int main(int argc, char *argv[])
165{
Oliver Smith2beb1b82019-09-18 13:47:25 +0200166 struct gsm_pcu_if_app_info_req req = {0, 15, {0}};
167 const uint8_t req_data[] = {0xff, 0x00, 0xff};
168 memcpy(req.data, req_data, 3);
169
Oliver Smithcfb63212019-09-05 17:13:33 +0200170 tall_pcu_ctx = talloc_named_const(NULL, 1, "AppInfoTest");
171 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
172 log_set_use_color(osmo_stderr_target, 0);
Pau Espin Pedrol00f52cc2021-02-19 14:01:52 +0100173 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
Pau Espin Pedrolb18d2a52021-02-19 14:00:48 +0100174 log_set_print_category(osmo_stderr_target, 0);
175 log_set_print_category_hex(osmo_stderr_target, 0);
Oliver Smithcfb63212019-09-05 17:13:33 +0200176 log_parse_category_mask(osmo_stderr_target, "DL1IF,1:DRLCMAC,3:DRLCMACSCHED,1");
177
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100178 the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100179 bts_alloc(the_pcu, 0);
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100180
Oliver Smithcfb63212019-09-05 17:13:33 +0200181 test_enc_zero_len();
Oliver Smith2beb1b82019-09-18 13:47:25 +0200182 test_enc(&req);
Oliver Smithcfb63212019-09-05 17:13:33 +0200183 test_pcu_rx_no_subscr_with_active_tbf();
184
185 prepare_bts_with_two_dl_tbf_subscr();
Oliver Smith2beb1b82019-09-18 13:47:25 +0200186 test_sched_app_info_ok(&req);
187 test_sched_app_info_missing_app_info_in_bts(&req);
188 test_pcu_rx_overwrite_app_info(&req);
Oliver Smithcfb63212019-09-05 17:13:33 +0200189
190 cleanup();
191}
192
193/*
194 * stubs that should not be reached
195 */
196extern "C" {
197void l1if_pdch_req() { abort(); }
198void l1if_connect_pdch() { abort(); }
199void l1if_close_pdch() { abort(); }
200void l1if_open_pdch() { abort(); }
201}