Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1 | /* 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. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | */ |
| 17 | |
| 18 | #include <cstdlib> |
| 19 | #include <cstring> |
| 20 | #include <assert.h> |
| 21 | #include "gprs_rlcmac.h" |
| 22 | #include "bts.h" |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 23 | #include "tbf_dl.h" |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 24 | |
| 25 | extern "C" { |
| 26 | #include <osmocom/vty/telnet_interface.h> |
| 27 | #include <osmocom/vty/logging.h> |
| 28 | #include <osmocom/core/utils.h> |
| 29 | #include <osmocom/core/msgb.h> |
| 30 | #include <osmocom/core/application.h> |
| 31 | } |
| 32 | |
| 33 | using namespace std; |
| 34 | gprs_rlcmac_dl_tbf *tbf1, *tbf2; |
| 35 | GprsMs *ms1, *ms2; |
| 36 | struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf); |
| 37 | |
| 38 | /* globals used by the code */ |
| 39 | void *tall_pcu_ctx; |
| 40 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 41 | bool spoof_mnc_3_digits = false; |
| 42 | |
| 43 | void test_enc_zero_len() { |
| 44 | struct gsm_pcu_if_app_info_req req = {0, 0, {0}}; |
| 45 | |
| 46 | fprintf(stderr, "--- %s ---\n", __func__); |
| 47 | assert(gprs_rlcmac_app_info_msg(&req) == NULL); |
| 48 | fprintf(stderr, "\n"); |
| 49 | } |
| 50 | |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 51 | void test_enc(const struct gsm_pcu_if_app_info_req *req) |
| 52 | { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 53 | 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 */ |
| 54 | struct msgb *msg; |
| 55 | char *msg_dump; |
| 56 | |
| 57 | fprintf(stderr, "--- %s ---\n", __func__); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 58 | msg = gprs_rlcmac_app_info_msg(req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 59 | msg_dump = msgb_hexdump_c(tall_pcu_ctx, msg); |
| 60 | |
| 61 | fprintf(stderr, "exp: %s\n", exp); |
| 62 | fprintf(stderr, "msg: %s\n", msg_dump); |
| 63 | assert(strcmp(msg_dump, exp) == 0); |
| 64 | |
| 65 | msgb_free(msg); |
| 66 | talloc_free(msg_dump); |
| 67 | fprintf(stderr, "\n"); |
| 68 | } |
| 69 | |
| 70 | void test_pcu_rx_no_subscr_with_active_tbf() |
| 71 | { |
| 72 | struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, }; |
| 73 | |
| 74 | fprintf(stderr, "--- %s ---\n", __func__); |
| 75 | pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim); |
| 76 | fprintf(stderr, "\n"); |
| 77 | } |
| 78 | |
| 79 | void prepare_bts_with_two_dl_tbf_subscr() |
| 80 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 81 | struct gprs_rlcmac_bts *bts = the_pcu->bts; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 82 | struct gprs_rlcmac_trx *trx; |
| 83 | |
| 84 | fprintf(stderr, "--- %s ---\n", __func__); |
| 85 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 86 | the_pcu->alloc_algorithm = alloc_algorithm_b; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 87 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 88 | trx = bts->trx; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 89 | trx->pdch[4].enable(); |
| 90 | trx->pdch[5].enable(); |
| 91 | trx->pdch[6].enable(); |
| 92 | trx->pdch[7].enable(); |
| 93 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 94 | ms1 = bts_alloc_ms(bts, 10, 11); |
| 95 | tbf1 = tbf_alloc_dl_tbf(bts, ms1, 0, false); |
| 96 | ms2 = bts_alloc_ms(bts, 12, 13); |
| 97 | tbf2 = tbf_alloc_dl_tbf(bts, ms2, 0, false); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 98 | |
| 99 | fprintf(stderr, "\n"); |
| 100 | } |
| 101 | |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 102 | void test_sched_app_info_ok(const struct gsm_pcu_if_app_info_req *req) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 103 | { |
| 104 | struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, }; |
| 105 | struct msgb *msg; |
| 106 | |
| 107 | fprintf(stderr, "--- %s ---\n", __func__); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 108 | pcu_prim.u.app_info_req = *req; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 109 | pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim); |
| 110 | |
| 111 | msg = sched_app_info(tbf1); |
| 112 | assert(msg); |
| 113 | msgb_free(msg); |
| 114 | |
| 115 | msg = sched_app_info(tbf2); |
| 116 | assert(msg); |
| 117 | msgb_free(msg); |
| 118 | |
| 119 | fprintf(stderr, "\n"); |
| 120 | } |
| 121 | |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 122 | void test_sched_app_info_missing_app_info_in_bts(const struct gsm_pcu_if_app_info_req *req) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 123 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 124 | struct gprs_rlcmac_bts *bts = the_pcu->bts; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 125 | struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, }; |
| 126 | |
| 127 | fprintf(stderr, "--- %s ---\n", __func__); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 128 | pcu_prim.u.app_info_req = *req; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 129 | pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim); |
| 130 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 131 | msgb_free(bts->app_info); |
| 132 | bts->app_info = NULL; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 133 | |
| 134 | assert(sched_app_info(tbf1) == NULL); |
| 135 | |
| 136 | fprintf(stderr, "\n"); |
| 137 | } |
| 138 | |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 139 | void test_pcu_rx_overwrite_app_info(const struct gsm_pcu_if_app_info_req *req) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 140 | { |
| 141 | struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, }; |
| 142 | |
| 143 | fprintf(stderr, "--- %s ---\n", __func__); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 144 | pcu_prim.u.app_info_req = *req; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 145 | pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim); |
| 146 | pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim); |
| 147 | fprintf(stderr, "\n"); |
| 148 | } |
| 149 | |
| 150 | void cleanup() |
| 151 | { |
| 152 | fprintf(stderr, "--- %s ---\n", __func__); |
| 153 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 154 | tbf_free(tbf1); |
| 155 | tbf_free(tbf2); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 156 | TALLOC_FREE(the_pcu->bts); |
| 157 | /* FIXME: talloc report disabled, because bts_alloc_ms(bts, ) in prepare_bts_with_two_dl_tbf_subscr() causes leak */ |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 158 | /* talloc_report_full(tall_pcu_ctx, stderr); */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 159 | talloc_free(the_pcu); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 160 | talloc_free(tall_pcu_ctx); |
| 161 | } |
| 162 | |
| 163 | int main(int argc, char *argv[]) |
| 164 | { |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 165 | struct gsm_pcu_if_app_info_req req = {0, 15, {0}}; |
| 166 | const uint8_t req_data[] = {0xff, 0x00, 0xff}; |
| 167 | memcpy(req.data, req_data, 3); |
| 168 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 169 | tall_pcu_ctx = talloc_named_const(NULL, 1, "AppInfoTest"); |
| 170 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
| 171 | log_set_use_color(osmo_stderr_target, 0); |
| 172 | log_set_print_filename(osmo_stderr_target, 0); |
| 173 | log_parse_category_mask(osmo_stderr_target, "DL1IF,1:DRLCMAC,3:DRLCMACSCHED,1"); |
| 174 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 175 | the_pcu = gprs_pcu_alloc(tall_pcu_ctx); |
| 176 | the_pcu->bts = bts_alloc(the_pcu); |
| 177 | |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 178 | test_enc_zero_len(); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 179 | test_enc(&req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 180 | test_pcu_rx_no_subscr_with_active_tbf(); |
| 181 | |
| 182 | prepare_bts_with_two_dl_tbf_subscr(); |
Oliver Smith | 2beb1b8 | 2019-09-18 13:47:25 +0200 | [diff] [blame] | 183 | test_sched_app_info_ok(&req); |
| 184 | test_sched_app_info_missing_app_info_in_bts(&req); |
| 185 | test_pcu_rx_overwrite_app_info(&req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 186 | |
| 187 | cleanup(); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * stubs that should not be reached |
| 192 | */ |
| 193 | extern "C" { |
| 194 | void l1if_pdch_req() { abort(); } |
| 195 | void l1if_connect_pdch() { abort(); } |
| 196 | void l1if_close_pdch() { abort(); } |
| 197 | void l1if_open_pdch() { abort(); } |
| 198 | } |