blob: 055b131d48be42b7abb303f98602c4d67693b6db [file] [log] [blame]
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +02001/* bts.h
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2013 by Holger Hans Peter Freyther
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#pragma once
22
23
24#ifdef __cplusplus
25extern "C" {
Alexander Couzens5012e072020-12-06 01:23:51 +010026#endif
27
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020028#include <osmocom/core/linuxlist.h>
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +010029#include <osmocom/core/rate_ctr.h>
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010030#include <osmocom/core/stat_item.h>
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +020031#include <osmocom/core/tdef.h>
Alexander Couzens5012e072020-12-06 01:23:51 +010032#include <osmocom/gprs/gprs_ns2.h>
bhargava959d1de2016-08-17 15:17:21 +053033#include <osmocom/gsm/l1sap.h>
Max84bf0fa2017-09-01 11:02:40 +020034#include <osmocom/gsm/protocol/gsm_04_08.h>
Vadim Yanitskiycb988942020-11-08 13:27:35 +070035#include <osmocom/gsm/gsm48.h>
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010036#include "mslot_class.h"
37#include "gsm_rlcmac.h"
Alexander Couzens5012e072020-12-06 01:23:51 +010038#ifdef __cplusplus
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020039}
Alexander Couzens5012e072020-12-06 01:23:51 +010040#endif
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020041
Alexander Couzens5012e072020-12-06 01:23:51 +010042#ifdef __cplusplus
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020043#include "poll_controller.h"
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +020044#include "sba.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020045#include "tbf.h"
Jacob Erlbecke43460b2015-05-13 13:33:12 +020046#include "gprs_ms_storage.h"
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020047#include "coding_scheme.h"
Max1187a772018-01-26 13:31:42 +010048#include <cxx_linuxlist.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020049#endif
50
Daniel Willmannfb3fd092019-03-06 17:09:43 +010051#include <pdch.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020052#include <stdint.h>
Pau Espin Pedrol4d166352020-10-26 18:39:51 +010053#include <stdbool.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020054
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +020055#define LLC_CODEL_DISABLE 0
56#define LLC_CODEL_USE_DEFAULT (-1)
Max8119ecd2019-03-06 19:03:01 +010057
58#define MAX_EDGE_MCS 9
59#define MAX_GPRS_CS 4
Aravind Sirsikar99ab0a82016-06-15 17:46:41 +053060
Harald Welte717cdf52017-07-21 21:56:23 +020061/* see bts->gsmtap_categ_mask */
62enum pcu_gsmtap_category {
63 PCU_GSMTAP_C_DL_UNKNOWN = 0, /* unknown or undecodable downlink blocks */
64 PCU_GSMTAP_C_DL_DUMMY = 1, /* downlink dummy blocks */
65 PCU_GSMTAP_C_DL_CTRL = 2, /* downlink control blocks */
66 PCU_GSMTAP_C_DL_DATA_GPRS = 3, /* downlink GPRS data blocks */
67 PCU_GSMTAP_C_DL_DATA_EGPRS = 4, /* downlink EGPRS data blocks */
Harald Weltebc219d52017-07-29 13:42:27 +020068 PCU_GSMTAP_C_DL_PTCCH = 5, /* downlink PTCCH blocks */
Pau Espin Pedrol58543702019-09-30 19:07:16 +020069 PCU_GSMTAP_C_DL_AGCH = 6, /* downlink AGCH blocks */
70 PCU_GSMTAP_C_DL_PCH = 7, /* downlink PCH blocks */
Harald Welte717cdf52017-07-21 21:56:23 +020071
72 PCU_GSMTAP_C_UL_UNKNOWN = 15, /* unknown or undecodable uplink blocks */
73 PCU_GSMTAP_C_UL_DUMMY = 16, /* uplink dummy blocks */
74 PCU_GSMTAP_C_UL_CTRL = 17, /* uplink control blocks */
75 PCU_GSMTAP_C_UL_DATA_GPRS = 18, /* uplink GPRS data blocks */
76 PCU_GSMTAP_C_UL_DATA_EGPRS = 19, /* uplink EGPRS data blocks */
Pau Espin Pedrol1ec211f2019-09-30 18:33:14 +020077 PCU_GSMTAP_C_UL_RACH = 20, /* uplink RACH bursts */
Vadim Yanitskiy07b64872020-06-11 00:26:15 +070078 PCU_GSMTAP_C_UL_PTCCH = 21, /* uplink PTCCH bursts */
Harald Welte717cdf52017-07-21 21:56:23 +020079};
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +020080
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020081struct BTS;
Jacob Erlbecke2e004e2015-06-18 17:16:26 +020082struct GprsMs;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020083
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020084struct gprs_rlcmac_trx {
85 void *fl1h;
86 uint16_t arfcn;
87 struct gprs_rlcmac_pdch pdch[8];
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020088
89 /* back pointers */
90 struct BTS *bts;
91 uint8_t trx_no;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +020092
93#ifdef __cplusplus
94 void reserve_slots(enum gprs_rlcmac_tbf_direction dir, uint8_t slots);
95 void unreserve_slots(enum gprs_rlcmac_tbf_direction dir, uint8_t slots);
96#endif
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020097};
98
Maxd71e8b32016-09-19 16:17:06 +020099#ifdef __cplusplus
100extern "C" {
101#endif
Minh-Quang Nguyen1bcfa9a2017-11-01 14:41:37 -0400102void bts_update_tbf_ta(const char *p, uint32_t fn, uint8_t trx_no, uint8_t ts, int8_t ta, bool is_rach);
Maxd71e8b32016-09-19 16:17:06 +0200103#ifdef __cplusplus
104}
105#endif
106
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200107/**
108 * This is the data from C. As soon as our minimal compiler is gcc 4.7
109 * we can start to compile pcu_vty.c with c++ and remove the split.
110 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200111struct gprs_rlcmac_bts {
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100112 bool active;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200113 uint8_t bsic;
114 uint8_t fc_interval;
Jacob Erlbeck0288cdb2015-05-06 10:47:30 +0200115 uint16_t fc_bucket_time;
Jacob Erlbeck87d73412015-04-21 12:56:48 +0200116 uint32_t fc_bvc_bucket_size;
117 uint32_t fc_bvc_leak_rate;
118 uint32_t fc_ms_bucket_size;
119 uint32_t fc_ms_leak_rate;
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100120 uint8_t cs_mask; /* Allowed CS mask from BTS */
121 uint16_t mcs_mask; /* Allowed MCS mask from BTS */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200122 uint8_t initial_cs_dl, initial_cs_ul;
Jacob Erlbeck96ccea82016-01-07 15:00:43 +0100123 uint8_t initial_mcs_dl, initial_mcs_ul;
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100124 struct { /* Config Values set by VTY */
Pau Espin Pedrolb47b1372020-11-03 15:59:39 +0100125 bool force_initial_cs; /* false=use from BTS true=use from VTY */
126 bool force_initial_mcs; /* false=use from BTS true=use from VTY */
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100127 uint8_t max_cs_dl, max_cs_ul;
128 uint8_t max_mcs_dl, max_mcs_ul;
129 } vty;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200130 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +0100131 uint32_t llc_discard_csec;
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200132 uint32_t llc_idle_ack_csec;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200133 uint32_t llc_codel_interval_msec; /* 0=disabled, -1=use default interval */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200134 /* Timer defintions */
135 struct osmo_tdef *T_defs_bts; /* timers controlled by BTS, received through PCUIF */
136 struct osmo_tdef *T_defs_pcu; /* timers controlled by PCU */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200137 uint8_t n3101;
138 uint8_t n3103;
139 uint8_t n3105;
Max2efdf692016-02-22 11:39:30 +0100140 struct gsmtap_inst *gsmtap;
Harald Welte717cdf52017-07-21 21:56:23 +0200141 uint32_t gsmtap_categ_mask;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200142 struct gprs_rlcmac_trx trx[8];
Maxe9fe0e32017-09-28 15:56:05 +0200143 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf,
144 bool single, int8_t use_tbf);
145
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200146 uint8_t force_two_phase;
147 uint8_t alpha, gamma;
Oliver Smith45fdc442019-09-05 15:12:20 +0200148 bool dl_tbf_preemptive_retransmission;
Max84bf0fa2017-09-01 11:02:40 +0200149 uint8_t si13[GSM_MACBLOCK_LEN];
150 bool si13_is_set;
Aravind Sirsikare6cadb42016-08-16 16:32:59 +0530151 /* 0 to support resegmentation in DL, 1 for no reseg */
152 uint8_t dl_arq_type;
153
Pau Espin Pedrol1e6eb302019-11-28 17:00:44 +0100154 uint8_t cs_adj_enabled; /* whether cs_adj_{upper,lower}_limit are used to adjust DL CS */
155 uint8_t cs_adj_upper_limit; /* downgrade DL CS if error rate above its value */
156 uint8_t cs_adj_lower_limit; /* upgrade DL CS if error rate below its value */
157 /* downgrade DL CS when less than specified octets are left in tx queue. Optimization, see paper:
158 "Theoretical Analysis of GPRS Throughput and Delay" */
159 uint16_t cs_downgrade_threshold;
160 /* Link quality range for each UL (M)CS. Below or above, next/prev (M)CS is selected. */
Aravind Sirsikar99ab0a82016-06-15 17:46:41 +0530161 struct {int16_t low; int16_t high; } cs_lqual_ranges[MAX_GPRS_CS];
Max8119ecd2019-03-06 19:03:01 +0100162 struct {int16_t low; int16_t high; } mcs_lqual_ranges[MAX_EDGE_MCS];
Jacob Erlbeck36df7742016-01-19 15:53:30 +0100163 uint16_t ws_base;
164 uint16_t ws_pdch; /* increase WS by this value per PDCH */
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200165
Jacob Erlbeck77da3552015-07-16 18:33:46 +0200166 /* State for dynamic algorithm selection */
167 int multislot_disabled;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200168
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200169 /**
170 * Point back to the C++ object. This is used during the transition
171 * period.
172 */
173 struct BTS *bts;
Pau Espin Pedrolc4178e52017-08-08 15:03:50 +0200174
175 /* Path to be used for the pcu-bts socket */
176 char *pcu_sock_path;
Harald Welte57d35152018-07-05 03:11:17 +0200177
178 /* Are we talking Gb with IP-SNS (true) or classic Gb? */
Alexander Couzens5012e072020-12-06 01:23:51 +0100179 enum gprs_ns2_dialect ns_dialect;
Oliver Smithcfb63212019-09-05 17:13:33 +0200180
181 /* Packet Application Information (3GPP TS 44.060 11.2.47, usually ETWS primary message). We don't need to store
182 * more than one message, because they get sent so rarely. */
183 struct msgb *app_info;
184 uint32_t app_info_pending; /* Count of MS with active TBF, to which we did not send app_info yet */
Alexander Couzens290d9032020-09-16 21:52:02 +0200185
186 struct gprs_ns2_inst *nsi;
187 /* main nsei */
188 struct gprs_ns2_nse *nse;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200189};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200190
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200191enum {
192 CTR_TBF_DL_ALLOCATED,
193 CTR_TBF_DL_FREED,
194 CTR_TBF_DL_ABORTED,
195 CTR_TBF_UL_ALLOCATED,
196 CTR_TBF_UL_FREED,
197 CTR_TBF_UL_ABORTED,
198 CTR_TBF_REUSED,
199 CTR_TBF_ALLOC_ALGO_A,
200 CTR_TBF_ALLOC_ALGO_B,
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200201 CTR_RLC_SENT,
202 CTR_RLC_RESENT,
203 CTR_RLC_RESTARTED,
204 CTR_RLC_STALLED,
205 CTR_RLC_NACKED,
206 CTR_RLC_FINAL_BLOCK_RESENT,
207 CTR_RLC_ASS_TIMEDOUT,
208 CTR_RLC_ASS_FAILED,
209 CTR_RLC_ACK_TIMEDOUT,
210 CTR_RLC_ACK_FAILED,
211 CTR_RLC_REL_TIMEDOUT,
212 CTR_RLC_LATE_BLOCK,
213 CTR_RLC_SENT_DUMMY,
214 CTR_RLC_SENT_CONTROL,
215 CTR_RLC_DL_BYTES,
216 CTR_RLC_DL_PAYLOAD_BYTES,
217 CTR_RLC_UL_BYTES,
218 CTR_RLC_UL_PAYLOAD_BYTES,
219 CTR_DECODE_ERRORS,
220 CTR_SBA_ALLOCATED,
221 CTR_SBA_FREED,
222 CTR_SBA_TIMEDOUT,
223 CTR_LLC_FRAME_TIMEDOUT,
224 CTR_LLC_FRAME_DROPPED,
225 CTR_LLC_FRAME_SCHED,
226 CTR_LLC_DL_BYTES,
227 CTR_LLC_UL_BYTES,
228 CTR_RACH_REQUESTS,
229 CTR_11BIT_RACH_REQUESTS,
230 CTR_SPB_UL_FIRST_SEGMENT,
231 CTR_SPB_UL_SECOND_SEGMENT,
232 CTR_SPB_DL_FIRST_SEGMENT,
233 CTR_SPB_DL_SECOND_SEGMENT,
234 CTR_IMMEDIATE_ASSIGN_UL_TBF,
235 CTR_IMMEDIATE_ASSIGN_REJ,
236 CTR_IMMEDIATE_ASSIGN_DL_TBF,
237 CTR_CHANNEL_REQUEST_DESCRIPTION,
238 CTR_PKT_UL_ASSIGNMENT,
239 CTR_PKT_ACCESS_REJ,
240 CTR_PKT_DL_ASSIGNMENT,
241 CTR_RLC_RECV_CONTROL,
242 CTR_PUA_POLL_TIMEDOUT,
243 CTR_PUA_POLL_FAILED,
244 CTR_PDA_POLL_TIMEDOUT,
245 CTR_PDA_POLL_FAILED,
246 CTR_PUAN_POLL_TIMEDOUT,
247 CTR_PUAN_POLL_FAILED,
248 CTR_PDAN_POLL_TIMEDOUT,
249 CTR_PDAN_POLL_FAILED,
250 CTR_GPRS_DL_CS1,
251 CTR_GPRS_DL_CS2,
252 CTR_GPRS_DL_CS3,
253 CTR_GPRS_DL_CS4,
254 CTR_EGPRS_DL_MCS1,
255 CTR_EGPRS_DL_MCS2,
256 CTR_EGPRS_DL_MCS3,
257 CTR_EGPRS_DL_MCS4,
258 CTR_EGPRS_DL_MCS5,
259 CTR_EGPRS_DL_MCS6,
260 CTR_EGPRS_DL_MCS7,
261 CTR_EGPRS_DL_MCS8,
262 CTR_EGPRS_DL_MCS9,
263 CTR_GPRS_UL_CS1,
264 CTR_GPRS_UL_CS2,
265 CTR_GPRS_UL_CS3,
266 CTR_GPRS_UL_CS4,
267 CTR_EGPRS_UL_MCS1,
268 CTR_EGPRS_UL_MCS2,
269 CTR_EGPRS_UL_MCS3,
270 CTR_EGPRS_UL_MCS4,
271 CTR_EGPRS_UL_MCS5,
272 CTR_EGPRS_UL_MCS6,
273 CTR_EGPRS_UL_MCS7,
274 CTR_EGPRS_UL_MCS8,
275 CTR_EGPRS_UL_MCS9,
276};
277
Pau Espin Pedrol97e88fd2020-05-12 22:45:04 +0200278enum {
279 STAT_MS_PRESENT,
280};
281
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700282/* RACH.ind parameters (to be parsed) */
283struct rach_ind_params {
284 enum ph_burst_type burst_type;
285 bool is_11bit;
286 uint16_t ra;
287 uint8_t trx_nr;
288 uint8_t ts_nr;
289 uint32_t rfn;
290 int16_t qta;
291};
292
293/* [EGPRS Packet] Channel Request parameters (parsed) */
294struct chan_req_params {
295 unsigned int egprs_mslot_class;
296 unsigned int priority;
297 bool single_block;
298};
299
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200300#ifdef __cplusplus
301/**
302 * I represent a GSM BTS. I have one or more TRX, I know the current
303 * GSM time and I have controllers that help with allocating resources
304 * on my TRXs.
305 */
306struct BTS {
307public:
308 BTS();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100309 ~BTS();
Maxd5ffeb52019-03-18 15:48:38 +0100310 void cleanup();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200311
312 static BTS* main_bts();
313
314 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200315 SBAController *sba();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200316
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200317 /** TODO: change the number to unsigned */
318 void set_current_frame_number(int frame_number);
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200319 void set_current_block_frame_number(int frame_number, unsigned max_delay);
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200320 int current_frame_number() const;
321
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200322 /** add paging to paging queue(s) */
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +0200323 int add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi);
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200324
Daniel Willmannfe6e2e42014-07-10 17:44:06 +0200325 gprs_rlcmac_dl_tbf *dl_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
326 gprs_rlcmac_ul_tbf *ul_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +0200327 gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts);
328 gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts);
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200329
Maxa76a7d02018-01-26 11:09:16 +0100330 int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx) const;
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200331
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200332 int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
Philipp Maier1275a3f2017-02-21 19:35:23 +0100333
Max5dd8d1b2017-03-08 12:06:42 +0100334 uint32_t rfn_to_fn(int32_t rfn);
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700335 int rcv_rach(const struct rach_ind_params *rip);
336 int rcv_ptcch_rach(const struct rach_ind_params *rip);
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200337
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100338 void snd_dl_ass(gprs_rlcmac_tbf *tbf, bool poll, uint16_t pgroup);
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200339
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100340 uint8_t max_cs_dl(void) const;
341 uint8_t max_cs_ul(void) const;
342 uint8_t max_mcs_dl(void) const;
343 uint8_t max_mcs_ul(void) const;
344 void set_max_cs_dl(uint8_t cs_dl);
345 void set_max_cs_ul(uint8_t cs_ul);
346 void set_max_mcs_dl(uint8_t mcs_dl);
347 void set_max_mcs_ul(uint8_t mcs_ul);
Pau Espin Pedrol022f9e52020-11-16 18:49:39 +0100348 bool cs_dl_is_supported(CodingScheme cs);
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100349
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200350 GprsMsStorage &ms_store();
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700351 GprsMs *ms_by_tlli(uint32_t tlli, uint32_t old_tlli = GSM_RESERVED_TMSI);
Jacob Erlbeck076f5c72015-08-21 18:00:54 +0200352 GprsMs *ms_by_imsi(const char *imsi);
Jacob Erlbeck86b6f052015-11-27 15:17:34 +0100353 GprsMs *ms_alloc(uint8_t ms_class, uint8_t egprs_ms_class = 0);
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200354
Harald Welte717cdf52017-07-21 21:56:23 +0200355 void send_gsmtap(enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no,
356 uint8_t ts_no, uint8_t channel, uint32_t fn,
357 const uint8_t *data, unsigned int len);
Pau Espin Pedrol0b0391f2020-05-19 17:23:23 +0200358 void send_gsmtap_meas(enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no,
359 uint8_t ts_no, uint8_t channel, uint32_t fn,
360 const uint8_t *data, unsigned int len, struct pcu_l1_meas *meas);
Vadim Yanitskiy07b64872020-06-11 00:26:15 +0700361 void send_gsmtap_rach(enum pcu_gsmtap_category categ, uint8_t channel,
362 const struct rach_ind_params *rip);
Harald Welte717cdf52017-07-21 21:56:23 +0200363
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100364 /*
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100365 * Below for C interface for the VTY
366 */
367 struct rate_ctr_group *rate_counters() const;
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100368 struct osmo_stat_item_group *stat_items() const;
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200369 void do_rate_ctr_inc(unsigned int ctr_id);
Pau Espin Pedrola107f8f2020-05-12 22:32:24 +0200370 void do_rate_ctr_add(unsigned int ctr_id, int inc);
Pau Espin Pedrol97e88fd2020-05-12 22:45:04 +0200371 void stat_item_add(unsigned int stat_id, int inc);
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100372
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100373 LListHead<gprs_rlcmac_tbf>& ul_tbfs();
374 LListHead<gprs_rlcmac_tbf>& dl_tbfs();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200375private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200376 int m_cur_fn;
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200377 int m_cur_blk_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200378 struct gprs_rlcmac_bts m_bts;
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100379 uint8_t m_max_cs_dl, m_max_cs_ul;
380 uint8_t m_max_mcs_dl, m_max_mcs_ul;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200381 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200382 SBAController m_sba;
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100383 struct rate_ctr_group *m_ratectrs;
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100384 struct osmo_stat_item_group *m_statg;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200385
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200386 GprsMsStorage m_ms_store;
387
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100388 /* list of uplink TBFs */
389 LListHead<gprs_rlcmac_tbf> m_ul_tbfs;
390 /* list of downlink TBFs */
391 LListHead<gprs_rlcmac_tbf> m_dl_tbfs;
392
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200393 /* disable copying to avoid slicing */
394 BTS(const BTS&);
395 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200396};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200397
398inline int BTS::current_frame_number() const
399{
400 return m_cur_fn;
401}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200402
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200403inline SBAController *BTS::sba()
404{
405 return &m_sba;
406}
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200407
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200408inline GprsMsStorage &BTS::ms_store()
409{
410 return m_ms_store;
411}
412
413inline GprsMs *BTS::ms_by_tlli(uint32_t tlli, uint32_t old_tlli)
414{
415 return ms_store().get_ms(tlli, old_tlli);
416}
417
Jacob Erlbeck076f5c72015-08-21 18:00:54 +0200418inline GprsMs *BTS::ms_by_imsi(const char *imsi)
419{
420 return ms_store().get_ms(0, 0, imsi);
421}
422
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100423inline LListHead<gprs_rlcmac_tbf>& BTS::ul_tbfs()
424{
425 return m_ul_tbfs;
426}
427
428inline LListHead<gprs_rlcmac_tbf>& BTS::dl_tbfs()
429{
430 return m_dl_tbfs;
431}
432
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100433inline struct rate_ctr_group *BTS::rate_counters() const
434{
435 return m_ratectrs;
436}
437
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100438inline struct osmo_stat_item_group *BTS::stat_items() const
439{
440 return m_statg;
441}
442
Pau Espin Pedrol2338e532020-05-12 20:54:35 +0200443inline void BTS::do_rate_ctr_inc(unsigned int ctr_id) {
444 rate_ctr_inc(&m_ratectrs->ctr[ctr_id]);
445}
446
Pau Espin Pedrola107f8f2020-05-12 22:32:24 +0200447inline void BTS::do_rate_ctr_add(unsigned int ctr_id, int inc) {
448 rate_ctr_add(&m_ratectrs->ctr[ctr_id], inc);
449}
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200450
Pau Espin Pedrol97e88fd2020-05-12 22:45:04 +0200451inline void BTS::stat_item_add(unsigned int stat_id, int inc) {
452 int32_t val = osmo_stat_item_get_last(m_statg->items[stat_id]);
453 osmo_stat_item_set(m_statg->items[stat_id], val + inc);
454}
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100455
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200456#endif
457
458#ifdef __cplusplus
459extern "C" {
460#endif
Maxd5ffeb52019-03-18 15:48:38 +0100461 void bts_cleanup();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200462 struct gprs_rlcmac_bts *bts_main_data();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100463 struct rate_ctr_group *bts_main_data_stats();
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100464 struct osmo_stat_item_group *bts_main_data_stat_items();
Pau Espin Pedrol343ec9b2020-10-30 18:35:54 +0100465 void bts_set_max_cs(struct gprs_rlcmac_bts *bts, uint8_t cs_dl, uint8_t cs_ul);
466 void bts_set_max_mcs(struct gprs_rlcmac_bts *bts, uint8_t mcs_dl, uint8_t mcs_ul);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200467#ifdef __cplusplus
468}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200469
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200470#endif