blob: 767605cdc4c5f08d60b60f84ddf82cbe8cd3df1d [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" {
26#include <osmocom/core/linuxlist.h>
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +010027#include <osmocom/core/rate_ctr.h>
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010028#include <osmocom/core/stat_item.h>
bhargava959d1de2016-08-17 15:17:21 +053029#include <osmocom/gsm/l1sap.h>
Max84bf0fa2017-09-01 11:02:40 +020030#include <osmocom/gsm/protocol/gsm_04_08.h>
Maxc5407c72018-02-05 16:11:36 +010031 #include <mslot_class.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020032}
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020033
Max1187a772018-01-26 13:31:42 +010034#include <gsm_rlcmac.h>
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020035#include "poll_controller.h"
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +020036#include "sba.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020037#include "tbf.h"
Jacob Erlbecke43460b2015-05-13 13:33:12 +020038#include "gprs_ms_storage.h"
Jacob Erlbeck9e862e12015-12-14 15:19:12 +010039#include "gprs_coding_scheme.h"
Max1187a772018-01-26 13:31:42 +010040#include <cxx_linuxlist.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020041#endif
42
Daniel Willmannfb3fd092019-03-06 17:09:43 +010043#include <pdch.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020044#include <stdint.h>
45
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +020046#define LLC_CODEL_DISABLE 0
47#define LLC_CODEL_USE_DEFAULT (-1)
Max8119ecd2019-03-06 19:03:01 +010048
49#define MAX_EDGE_MCS 9
50#define MAX_GPRS_CS 4
Aravind Sirsikar99ab0a82016-06-15 17:46:41 +053051
Harald Welte717cdf52017-07-21 21:56:23 +020052/* see bts->gsmtap_categ_mask */
53enum pcu_gsmtap_category {
54 PCU_GSMTAP_C_DL_UNKNOWN = 0, /* unknown or undecodable downlink blocks */
55 PCU_GSMTAP_C_DL_DUMMY = 1, /* downlink dummy blocks */
56 PCU_GSMTAP_C_DL_CTRL = 2, /* downlink control blocks */
57 PCU_GSMTAP_C_DL_DATA_GPRS = 3, /* downlink GPRS data blocks */
58 PCU_GSMTAP_C_DL_DATA_EGPRS = 4, /* downlink EGPRS data blocks */
Harald Weltebc219d52017-07-29 13:42:27 +020059 PCU_GSMTAP_C_DL_PTCCH = 5, /* downlink PTCCH blocks */
Harald Welte717cdf52017-07-21 21:56:23 +020060
61 PCU_GSMTAP_C_UL_UNKNOWN = 15, /* unknown or undecodable uplink blocks */
62 PCU_GSMTAP_C_UL_DUMMY = 16, /* uplink dummy blocks */
63 PCU_GSMTAP_C_UL_CTRL = 17, /* uplink control blocks */
64 PCU_GSMTAP_C_UL_DATA_GPRS = 18, /* uplink GPRS data blocks */
65 PCU_GSMTAP_C_UL_DATA_EGPRS = 19, /* uplink EGPRS data blocks */
66};
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +020067
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020068struct BTS;
Jacob Erlbecke2e004e2015-06-18 17:16:26 +020069struct GprsMs;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020070
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020071struct gprs_rlcmac_trx {
72 void *fl1h;
73 uint16_t arfcn;
74 struct gprs_rlcmac_pdch pdch[8];
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020075
76 /* back pointers */
77 struct BTS *bts;
78 uint8_t trx_no;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +020079
80#ifdef __cplusplus
81 void reserve_slots(enum gprs_rlcmac_tbf_direction dir, uint8_t slots);
82 void unreserve_slots(enum gprs_rlcmac_tbf_direction dir, uint8_t slots);
83#endif
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020084};
85
Maxd71e8b32016-09-19 16:17:06 +020086#ifdef __cplusplus
87extern "C" {
88#endif
Minh-Quang Nguyen1bcfa9a2017-11-01 14:41:37 -040089void 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 +020090#ifdef __cplusplus
91}
92#endif
93
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020094/**
95 * This is the data from C. As soon as our minimal compiler is gcc 4.7
96 * we can start to compile pcu_vty.c with c++ and remove the split.
97 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020098struct gprs_rlcmac_bts {
Stefan Sperling5b22fb72018-02-14 19:46:33 +010099 bool active;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200100 uint8_t bsic;
101 uint8_t fc_interval;
Jacob Erlbeck0288cdb2015-05-06 10:47:30 +0200102 uint16_t fc_bucket_time;
Jacob Erlbeck87d73412015-04-21 12:56:48 +0200103 uint32_t fc_bvc_bucket_size;
104 uint32_t fc_bvc_leak_rate;
105 uint32_t fc_ms_bucket_size;
106 uint32_t fc_ms_leak_rate;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200107 uint8_t cs1;
108 uint8_t cs2;
109 uint8_t cs3;
110 uint8_t cs4;
111 uint8_t initial_cs_dl, initial_cs_ul;
Jacob Erlbeck96ccea82016-01-07 15:00:43 +0100112 uint8_t initial_mcs_dl, initial_mcs_ul;
Jacob Erlbeckb33e6752015-06-04 19:04:30 +0200113 uint8_t max_cs_dl, max_cs_ul;
Jacob Erlbeck0d058052016-01-07 11:48:28 +0100114 uint8_t max_mcs_dl, max_mcs_ul;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200115 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
116 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +0100117 uint32_t llc_discard_csec;
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200118 uint32_t llc_idle_ack_csec;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200119 uint32_t llc_codel_interval_msec; /* 0=disabled, -1=use default interval */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200120 uint8_t t3142;
121 uint8_t t3169;
122 uint8_t t3191;
123 uint16_t t3193_msec;
124 uint8_t t3195;
125 uint8_t n3101;
126 uint8_t n3103;
127 uint8_t n3105;
Max2efdf692016-02-22 11:39:30 +0100128 struct gsmtap_inst *gsmtap;
Harald Welte717cdf52017-07-21 21:56:23 +0200129 uint32_t gsmtap_categ_mask;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200130 struct gprs_rlcmac_trx trx[8];
Maxe9fe0e32017-09-28 15:56:05 +0200131 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf,
132 bool single, int8_t use_tbf);
133
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200134 uint8_t force_two_phase;
135 uint8_t alpha, gamma;
Jacob Erlbeck953c7892015-09-28 18:12:57 +0200136 uint8_t egprs_enabled;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100137 uint32_t dl_tbf_idle_msec; /* hold time for idle DL TBFs */
Max84bf0fa2017-09-01 11:02:40 +0200138 uint8_t si13[GSM_MACBLOCK_LEN];
139 bool si13_is_set;
Aravind Sirsikare6cadb42016-08-16 16:32:59 +0530140 /* 0 to support resegmentation in DL, 1 for no reseg */
141 uint8_t dl_arq_type;
142
Jacob Erlbecka098c192015-05-28 16:11:19 +0200143 uint32_t ms_idle_sec;
Jacob Erlbeck1751c622015-06-04 12:12:32 +0200144 uint8_t cs_adj_enabled;
145 uint8_t cs_adj_upper_limit;
146 uint8_t cs_adj_lower_limit;
Aravind Sirsikar99ab0a82016-06-15 17:46:41 +0530147 struct {int16_t low; int16_t high; } cs_lqual_ranges[MAX_GPRS_CS];
Max8119ecd2019-03-06 19:03:01 +0100148 struct {int16_t low; int16_t high; } mcs_lqual_ranges[MAX_EDGE_MCS];
Jacob Erlbeck70b96aa2015-06-12 10:52:34 +0200149 uint16_t cs_downgrade_threshold; /* downgrade if less packets left (DL) */
Jacob Erlbeck36df7742016-01-19 15:53:30 +0100150 uint16_t ws_base;
151 uint16_t ws_pdch; /* increase WS by this value per PDCH */
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200152
Jacob Erlbeck77da3552015-07-16 18:33:46 +0200153 /* State for dynamic algorithm selection */
154 int multislot_disabled;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200155
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200156 /**
157 * Point back to the C++ object. This is used during the transition
158 * period.
159 */
160 struct BTS *bts;
Pau Espin Pedrolc4178e52017-08-08 15:03:50 +0200161
162 /* Path to be used for the pcu-bts socket */
163 char *pcu_sock_path;
Harald Welte57d35152018-07-05 03:11:17 +0200164
165 /* Are we talking Gb with IP-SNS (true) or classic Gb? */
166 bool gb_dialect_sns;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200167};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200168
169#ifdef __cplusplus
170/**
171 * I represent a GSM BTS. I have one or more TRX, I know the current
172 * GSM time and I have controllers that help with allocating resources
173 * on my TRXs.
174 */
175struct BTS {
176public:
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100177 enum {
178 CTR_TBF_DL_ALLOCATED,
179 CTR_TBF_DL_FREED,
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100180 CTR_TBF_DL_ABORTED,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100181 CTR_TBF_UL_ALLOCATED,
182 CTR_TBF_UL_FREED,
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100183 CTR_TBF_UL_ABORTED,
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100184 CTR_TBF_REUSED,
Jacob Erlbeck5979fe92015-07-14 14:02:41 +0200185 CTR_TBF_ALLOC_ALGO_A,
186 CTR_TBF_ALLOC_ALGO_B,
Jacob Erlbeck9b3d7e02016-01-19 10:44:42 +0100187 CTR_TBF_FAILED_EGPRS_ONLY,
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100188 CTR_RLC_SENT,
189 CTR_RLC_RESENT,
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100190 CTR_RLC_RESTARTED,
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100191 CTR_RLC_STALLED,
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100192 CTR_RLC_NACKED,
sivasankari168911b2016-11-25 19:53:36 +0530193 CTR_RLC_FINAL_BLOCK_RESENT,
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200194 CTR_RLC_ASS_TIMEDOUT,
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200195 CTR_RLC_ASS_FAILED,
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200196 CTR_RLC_ACK_TIMEDOUT,
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200197 CTR_RLC_ACK_FAILED,
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200198 CTR_RLC_REL_TIMEDOUT,
Jacob Erlbeckbe4a08b2015-08-25 15:19:31 +0200199 CTR_RLC_LATE_BLOCK,
Alexander Couzens2cb15472016-05-18 16:43:10 +0200200 CTR_RLC_SENT_DUMMY,
Alexander Couzensf929e622016-05-22 00:02:56 +0200201 CTR_RLC_SENT_CONTROL,
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200202 CTR_RLC_DL_BYTES,
203 CTR_RLC_DL_PAYLOAD_BYTES,
204 CTR_RLC_UL_BYTES,
205 CTR_RLC_UL_PAYLOAD_BYTES,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100206 CTR_DECODE_ERRORS,
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100207 CTR_SBA_ALLOCATED,
208 CTR_SBA_FREED,
209 CTR_SBA_TIMEDOUT,
Holger Hans Peter Freyther19977872013-10-27 10:34:31 +0100210 CTR_LLC_FRAME_TIMEDOUT,
211 CTR_LLC_FRAME_DROPPED,
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100212 CTR_LLC_FRAME_SCHED,
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200213 CTR_LLC_DL_BYTES,
214 CTR_LLC_UL_BYTES,
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100215 CTR_RACH_REQUESTS,
sivasankari67b89ca2016-12-29 16:25:30 +0530216 CTR_11BIT_RACH_REQUESTS,
sivasankarida7250a2016-12-16 12:57:18 +0530217 CTR_SPB_UL_FIRST_SEGMENT,
218 CTR_SPB_UL_SECOND_SEGMENT,
219 CTR_SPB_DL_FIRST_SEGMENT,
220 CTR_SPB_DL_SECOND_SEGMENT,
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530221 CTR_IMMEDIATE_ASSIGN_UL_TBF,
sivasankari168911b2016-11-25 19:53:36 +0530222 CTR_IMMEDIATE_ASSIGN_REJ,
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530223 CTR_IMMEDIATE_ASSIGN_DL_TBF,
sivasankari168911b2016-11-25 19:53:36 +0530224 CTR_CHANNEL_REQUEST_DESCRIPTION,
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530225 CTR_PKT_UL_ASSIGNMENT,
sivasankari168911b2016-11-25 19:53:36 +0530226 CTR_PKT_ACCESS_REJ,
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530227 CTR_PKT_DL_ASSIGNMENT,
228 CTR_RLC_RECV_CONTROL,
229 CTR_PUA_POLL_TIMEDOUT,
230 CTR_PUA_POLL_FAILED,
231 CTR_PDA_POLL_TIMEDOUT,
232 CTR_PDA_POLL_FAILED,
233 CTR_PUAN_POLL_TIMEDOUT,
234 CTR_PUAN_POLL_FAILED,
235 CTR_PDAN_POLL_TIMEDOUT,
236 CTR_PDAN_POLL_FAILED,
237 CTR_GPRS_DL_CS1,
238 CTR_GPRS_DL_CS2,
239 CTR_GPRS_DL_CS3,
240 CTR_GPRS_DL_CS4,
241 CTR_EGPRS_DL_MCS1,
242 CTR_EGPRS_DL_MCS2,
243 CTR_EGPRS_DL_MCS3,
244 CTR_EGPRS_DL_MCS4,
245 CTR_EGPRS_DL_MCS5,
246 CTR_EGPRS_DL_MCS6,
247 CTR_EGPRS_DL_MCS7,
248 CTR_EGPRS_DL_MCS8,
249 CTR_EGPRS_DL_MCS9,
250 CTR_GPRS_UL_CS1,
251 CTR_GPRS_UL_CS2,
252 CTR_GPRS_UL_CS3,
253 CTR_GPRS_UL_CS4,
254 CTR_EGPRS_UL_MCS1,
255 CTR_EGPRS_UL_MCS2,
256 CTR_EGPRS_UL_MCS3,
257 CTR_EGPRS_UL_MCS4,
258 CTR_EGPRS_UL_MCS5,
259 CTR_EGPRS_UL_MCS6,
260 CTR_EGPRS_UL_MCS7,
261 CTR_EGPRS_UL_MCS8,
262 CTR_EGPRS_UL_MCS9,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100263 };
264
Jacob Erlbeck502bd1f2015-03-20 14:26:05 +0100265 enum {
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100266 STAT_MS_PRESENT,
267 };
268
269 enum {
Jacob Erlbeck502bd1f2015-03-20 14:26:05 +0100270 TIMER_T3190_MSEC = 5000,
271 };
272
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200273 BTS();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100274 ~BTS();
Maxd5ffeb52019-03-18 15:48:38 +0100275 void cleanup();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200276
277 static BTS* main_bts();
278
279 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200280 SBAController *sba();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200281
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200282 /** TODO: change the number to unsigned */
283 void set_current_frame_number(int frame_number);
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200284 void set_current_block_frame_number(int frame_number, unsigned max_delay);
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200285 int current_frame_number() const;
286
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200287 /** add paging to paging queue(s) */
288 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
289
Daniel Willmannfe6e2e42014-07-10 17:44:06 +0200290 gprs_rlcmac_dl_tbf *dl_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
291 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 +0200292 gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi, uint8_t trx, uint8_t ts);
293 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 +0200294
Maxa76a7d02018-01-26 11:09:16 +0100295 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 +0200296
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200297 int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
Philipp Maier1275a3f2017-02-21 19:35:23 +0100298
Max5dd8d1b2017-03-08 12:06:42 +0100299 uint32_t rfn_to_fn(int32_t rfn);
Max58818582018-01-05 15:04:50 +0100300 int rcv_rach(uint16_t ra, uint32_t Fn, int16_t qta, bool is_11bit,
bhargava959d1de2016-08-17 15:17:21 +0530301 enum ph_burst_type burst_type);
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200302
Maxfc8afc22019-02-18 18:52:38 +0100303 void snd_dl_ass(gprs_rlcmac_tbf *tbf, bool poll, const char *imsi);
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200304
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200305 GprsMsStorage &ms_store();
306 GprsMs *ms_by_tlli(uint32_t tlli, uint32_t old_tlli = 0);
Jacob Erlbeck076f5c72015-08-21 18:00:54 +0200307 GprsMs *ms_by_imsi(const char *imsi);
Jacob Erlbeck86b6f052015-11-27 15:17:34 +0100308 GprsMs *ms_alloc(uint8_t ms_class, uint8_t egprs_ms_class = 0);
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200309
Harald Welte717cdf52017-07-21 21:56:23 +0200310 void send_gsmtap(enum pcu_gsmtap_category categ, bool uplink, uint8_t trx_no,
311 uint8_t ts_no, uint8_t channel, uint32_t fn,
312 const uint8_t *data, unsigned int len);
313
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100314 /*
315 * Statistics
316 */
317 void tbf_dl_created();
318 void tbf_dl_freed();
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100319 void tbf_dl_aborted();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100320 void tbf_ul_created();
321 void tbf_ul_freed();
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100322 void tbf_ul_aborted();
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100323 void tbf_reused();
Jacob Erlbeck5979fe92015-07-14 14:02:41 +0200324 void tbf_alloc_algo_a();
325 void tbf_alloc_algo_b();
Jacob Erlbeck9b3d7e02016-01-19 10:44:42 +0100326 void tbf_failed_egprs_only();
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100327 void rlc_sent();
328 void rlc_resent();
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100329 void rlc_restarted();
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100330 void rlc_stalled();
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100331 void rlc_nacked();
sivasankari168911b2016-11-25 19:53:36 +0530332 void rlc_final_block_resent();
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200333 void rlc_ass_timedout();
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200334 void rlc_ass_failed();
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200335 void rlc_ack_timedout();
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200336 void rlc_ack_failed();
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200337 void rlc_rel_timedout();
Jacob Erlbeckbe4a08b2015-08-25 15:19:31 +0200338 void rlc_late_block();
Alexander Couzens2cb15472016-05-18 16:43:10 +0200339 void rlc_sent_dummy();
Alexander Couzensf929e622016-05-22 00:02:56 +0200340 void rlc_sent_control();
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200341 void rlc_dl_bytes(int bytes);
342 void rlc_dl_payload_bytes(int bytes);
343 void rlc_ul_bytes(int bytes);
344 void rlc_ul_payload_bytes(int bytes);
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100345 void decode_error();
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100346 void sba_allocated();
347 void sba_freed();
348 void sba_timedout();
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100349 void llc_timedout_frame();
350 void llc_dropped_frame();
351 void llc_frame_sched();
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200352 void llc_dl_bytes(int bytes);
353 void llc_ul_bytes(int bytes);
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100354 void rach_frame();
sivasankari67b89ca2016-12-29 16:25:30 +0530355 void rach_frame_11bit();
sivasankarida7250a2016-12-16 12:57:18 +0530356 void spb_uplink_first_segment();
357 void spb_uplink_second_segment();
358 void spb_downlink_first_segment();
359 void spb_downlink_second_segment();
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530360 void immediate_assignment_ul_tbf();
sivasankari168911b2016-11-25 19:53:36 +0530361 void immediate_assignment_reject();
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530362 void immediate_assignment_dl_tbf();
sivasankari168911b2016-11-25 19:53:36 +0530363 void channel_request_description();
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530364 void pkt_ul_assignment();
sivasankari168911b2016-11-25 19:53:36 +0530365 void pkt_access_reject();
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530366 void pkt_dl_assignemnt();
367 void rlc_rcvd_control();
368 void pua_poll_timedout();
369 void pua_poll_failed();
370 void pda_poll_timedout();
371 void pda_poll_failed();
372 void pkt_ul_ack_nack_poll_timedout();
373 void pkt_ul_ack_nack_poll_failed();
374 void pkt_dl_ack_nack_poll_timedout();
375 void pkt_dl_ack_nack_poll_failed();
376 void gprs_dl_cs1();
377 void gprs_dl_cs2();
378 void gprs_dl_cs3();
379 void gprs_dl_cs4();
380 void egprs_dl_mcs1();
381 void egprs_dl_mcs2();
382 void egprs_dl_mcs3();
383 void egprs_dl_mcs4();
384 void egprs_dl_mcs5();
385 void egprs_dl_mcs6();
386 void egprs_dl_mcs7();
387 void egprs_dl_mcs8();
388 void egprs_dl_mcs9();
389 void gprs_ul_cs1();
390 void gprs_ul_cs2();
391 void gprs_ul_cs3();
392 void gprs_ul_cs4();
393 void egprs_ul_mcs1();
394 void egprs_ul_mcs2();
395 void egprs_ul_mcs3();
396 void egprs_ul_mcs4();
397 void egprs_ul_mcs5();
398 void egprs_ul_mcs6();
399 void egprs_ul_mcs7();
400 void egprs_ul_mcs8();
401 void egprs_ul_mcs9();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100402
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100403 void ms_present(int32_t n);
404 int32_t ms_present_get();
405
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100406 /*
407 * Below for C interface for the VTY
408 */
409 struct rate_ctr_group *rate_counters() const;
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100410 struct osmo_stat_item_group *stat_items() const;
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100411
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100412 LListHead<gprs_rlcmac_tbf>& ul_tbfs();
413 LListHead<gprs_rlcmac_tbf>& dl_tbfs();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200414private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200415 int m_cur_fn;
Jacob Erlbeck60f77032015-08-24 14:35:14 +0200416 int m_cur_blk_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200417 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200418 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200419 SBAController m_sba;
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100420 struct rate_ctr_group *m_ratectrs;
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100421 struct osmo_stat_item_group *m_statg;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200422
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200423 GprsMsStorage m_ms_store;
424
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100425 /* list of uplink TBFs */
426 LListHead<gprs_rlcmac_tbf> m_ul_tbfs;
427 /* list of downlink TBFs */
428 LListHead<gprs_rlcmac_tbf> m_dl_tbfs;
429
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200430 /* disable copying to avoid slicing */
431 BTS(const BTS&);
432 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200433};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200434
435inline int BTS::current_frame_number() const
436{
437 return m_cur_fn;
438}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200439
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200440inline SBAController *BTS::sba()
441{
442 return &m_sba;
443}
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200444
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200445inline GprsMsStorage &BTS::ms_store()
446{
447 return m_ms_store;
448}
449
450inline GprsMs *BTS::ms_by_tlli(uint32_t tlli, uint32_t old_tlli)
451{
452 return ms_store().get_ms(tlli, old_tlli);
453}
454
Jacob Erlbeck076f5c72015-08-21 18:00:54 +0200455inline GprsMs *BTS::ms_by_imsi(const char *imsi)
456{
457 return ms_store().get_ms(0, 0, imsi);
458}
459
Jacob Erlbecked2dbf62015-12-28 19:15:40 +0100460inline LListHead<gprs_rlcmac_tbf>& BTS::ul_tbfs()
461{
462 return m_ul_tbfs;
463}
464
465inline LListHead<gprs_rlcmac_tbf>& BTS::dl_tbfs()
466{
467 return m_dl_tbfs;
468}
469
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100470inline struct rate_ctr_group *BTS::rate_counters() const
471{
472 return m_ratectrs;
473}
474
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100475inline struct osmo_stat_item_group *BTS::stat_items() const
476{
477 return m_statg;
478}
479
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200480#define CREATE_COUNT_ADD_INLINE(func_name, ctr_name) \
481 inline void BTS::func_name(int inc) {\
482 rate_ctr_add(&m_ratectrs->ctr[ctr_name], inc); \
483 }
484
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100485#define CREATE_COUNT_INLINE(func_name, ctr_name) \
486 inline void BTS::func_name() {\
487 rate_ctr_inc(&m_ratectrs->ctr[ctr_name]); \
488 }
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100489
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100490CREATE_COUNT_INLINE(tbf_dl_created, CTR_TBF_DL_ALLOCATED)
491CREATE_COUNT_INLINE(tbf_dl_freed, CTR_TBF_DL_FREED)
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100492CREATE_COUNT_INLINE(tbf_dl_aborted, CTR_TBF_DL_ABORTED)
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100493CREATE_COUNT_INLINE(tbf_ul_created, CTR_TBF_UL_ALLOCATED)
494CREATE_COUNT_INLINE(tbf_ul_freed, CTR_TBF_UL_FREED)
Jacob Erlbeck0316dc62016-01-21 20:12:04 +0100495CREATE_COUNT_INLINE(tbf_ul_aborted, CTR_TBF_UL_ABORTED)
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100496CREATE_COUNT_INLINE(tbf_reused, CTR_TBF_REUSED)
Jacob Erlbeck5979fe92015-07-14 14:02:41 +0200497CREATE_COUNT_INLINE(tbf_alloc_algo_a, CTR_TBF_ALLOC_ALGO_A)
498CREATE_COUNT_INLINE(tbf_alloc_algo_b, CTR_TBF_ALLOC_ALGO_B)
Jacob Erlbeck9b3d7e02016-01-19 10:44:42 +0100499CREATE_COUNT_INLINE(tbf_failed_egprs_only, CTR_TBF_FAILED_EGPRS_ONLY)
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100500CREATE_COUNT_INLINE(rlc_sent, CTR_RLC_SENT)
501CREATE_COUNT_INLINE(rlc_resent, CTR_RLC_RESENT)
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100502CREATE_COUNT_INLINE(rlc_restarted, CTR_RLC_RESTARTED)
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100503CREATE_COUNT_INLINE(rlc_stalled, CTR_RLC_STALLED)
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100504CREATE_COUNT_INLINE(rlc_nacked, CTR_RLC_NACKED)
sivasankari168911b2016-11-25 19:53:36 +0530505CREATE_COUNT_INLINE(rlc_final_block_resent, CTR_RLC_FINAL_BLOCK_RESENT);
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200506CREATE_COUNT_INLINE(rlc_ass_timedout, CTR_RLC_ASS_TIMEDOUT);
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200507CREATE_COUNT_INLINE(rlc_ass_failed, CTR_RLC_ASS_FAILED);
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200508CREATE_COUNT_INLINE(rlc_ack_timedout, CTR_RLC_ACK_TIMEDOUT);
Jacob Erlbeck7c8d39a2015-09-07 14:04:56 +0200509CREATE_COUNT_INLINE(rlc_ack_failed, CTR_RLC_ACK_FAILED);
Jacob Erlbeckc91c18e2015-07-07 09:33:29 +0200510CREATE_COUNT_INLINE(rlc_rel_timedout, CTR_RLC_REL_TIMEDOUT);
Jacob Erlbeckbe4a08b2015-08-25 15:19:31 +0200511CREATE_COUNT_INLINE(rlc_late_block, CTR_RLC_LATE_BLOCK);
Alexander Couzens2cb15472016-05-18 16:43:10 +0200512CREATE_COUNT_INLINE(rlc_sent_dummy, CTR_RLC_SENT_DUMMY);
Alexander Couzensf929e622016-05-22 00:02:56 +0200513CREATE_COUNT_INLINE(rlc_sent_control, CTR_RLC_SENT_CONTROL);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200514CREATE_COUNT_ADD_INLINE(rlc_dl_bytes, CTR_RLC_DL_BYTES);
515CREATE_COUNT_ADD_INLINE(rlc_dl_payload_bytes, CTR_RLC_DL_PAYLOAD_BYTES);
516CREATE_COUNT_ADD_INLINE(rlc_ul_bytes, CTR_RLC_UL_BYTES);
517CREATE_COUNT_ADD_INLINE(rlc_ul_payload_bytes, CTR_RLC_UL_PAYLOAD_BYTES);
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100518CREATE_COUNT_INLINE(decode_error, CTR_DECODE_ERRORS)
519CREATE_COUNT_INLINE(sba_allocated, CTR_SBA_ALLOCATED)
520CREATE_COUNT_INLINE(sba_freed, CTR_SBA_FREED)
521CREATE_COUNT_INLINE(sba_timedout, CTR_SBA_TIMEDOUT)
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100522CREATE_COUNT_INLINE(llc_timedout_frame, CTR_LLC_FRAME_TIMEDOUT);
523CREATE_COUNT_INLINE(llc_dropped_frame, CTR_LLC_FRAME_DROPPED);
524CREATE_COUNT_INLINE(llc_frame_sched, CTR_LLC_FRAME_SCHED);
Alexander Couzens7fdbf892016-05-21 19:45:23 +0200525CREATE_COUNT_ADD_INLINE(llc_dl_bytes, CTR_LLC_DL_BYTES);
526CREATE_COUNT_ADD_INLINE(llc_ul_bytes, CTR_LLC_UL_BYTES);
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100527CREATE_COUNT_INLINE(rach_frame, CTR_RACH_REQUESTS);
sivasankari67b89ca2016-12-29 16:25:30 +0530528CREATE_COUNT_INLINE(rach_frame_11bit, CTR_11BIT_RACH_REQUESTS);
sivasankarida7250a2016-12-16 12:57:18 +0530529CREATE_COUNT_INLINE(spb_uplink_first_segment, CTR_SPB_UL_FIRST_SEGMENT);
530CREATE_COUNT_INLINE(spb_uplink_second_segment, CTR_SPB_UL_SECOND_SEGMENT);
531CREATE_COUNT_INLINE(spb_downlink_first_segment, CTR_SPB_DL_FIRST_SEGMENT);
532CREATE_COUNT_INLINE(spb_downlink_second_segment, CTR_SPB_DL_SECOND_SEGMENT);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530533CREATE_COUNT_INLINE(immediate_assignment_ul_tbf, CTR_IMMEDIATE_ASSIGN_UL_TBF);
sivasankari168911b2016-11-25 19:53:36 +0530534CREATE_COUNT_INLINE(immediate_assignment_reject, CTR_IMMEDIATE_ASSIGN_REJ);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530535CREATE_COUNT_INLINE(immediate_assignment_dl_tbf, CTR_IMMEDIATE_ASSIGN_DL_TBF);
sivasankari168911b2016-11-25 19:53:36 +0530536CREATE_COUNT_INLINE(channel_request_description, CTR_CHANNEL_REQUEST_DESCRIPTION);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530537CREATE_COUNT_INLINE(pkt_ul_assignment, CTR_PKT_UL_ASSIGNMENT);
sivasankari168911b2016-11-25 19:53:36 +0530538CREATE_COUNT_INLINE(pkt_access_reject, CTR_PKT_ACCESS_REJ);
Mrinal Mishraf86307e2016-11-10 18:16:30 +0530539CREATE_COUNT_INLINE(pkt_dl_assignemnt, CTR_PKT_DL_ASSIGNMENT);
540CREATE_COUNT_INLINE(rlc_rcvd_control, CTR_RLC_RECV_CONTROL);
541CREATE_COUNT_INLINE(pua_poll_timedout, CTR_PUA_POLL_TIMEDOUT);
542CREATE_COUNT_INLINE(pua_poll_failed, CTR_PUA_POLL_FAILED);
543CREATE_COUNT_INLINE(pda_poll_timedout, CTR_PDA_POLL_TIMEDOUT);
544CREATE_COUNT_INLINE(pda_poll_failed, CTR_PDA_POLL_FAILED);
545CREATE_COUNT_INLINE(pkt_ul_ack_nack_poll_timedout, CTR_PUAN_POLL_TIMEDOUT);
546CREATE_COUNT_INLINE(pkt_ul_ack_nack_poll_failed, CTR_PUAN_POLL_FAILED);
547CREATE_COUNT_INLINE(pkt_dl_ack_nack_poll_timedout, CTR_PDAN_POLL_TIMEDOUT);
548CREATE_COUNT_INLINE(pkt_dl_ack_nack_poll_failed, CTR_PDAN_POLL_FAILED);
549CREATE_COUNT_INLINE(gprs_dl_cs1, CTR_GPRS_DL_CS1);
550CREATE_COUNT_INLINE(gprs_dl_cs2, CTR_GPRS_DL_CS2);
551CREATE_COUNT_INLINE(gprs_dl_cs3, CTR_GPRS_DL_CS3);
552CREATE_COUNT_INLINE(gprs_dl_cs4, CTR_GPRS_DL_CS4);
553CREATE_COUNT_INLINE(egprs_dl_mcs1, CTR_EGPRS_DL_MCS1);
554CREATE_COUNT_INLINE(egprs_dl_mcs2, CTR_EGPRS_DL_MCS2);
555CREATE_COUNT_INLINE(egprs_dl_mcs3, CTR_EGPRS_DL_MCS3);
556CREATE_COUNT_INLINE(egprs_dl_mcs4, CTR_EGPRS_DL_MCS4);
557CREATE_COUNT_INLINE(egprs_dl_mcs5, CTR_EGPRS_DL_MCS5);
558CREATE_COUNT_INLINE(egprs_dl_mcs6, CTR_EGPRS_DL_MCS6);
559CREATE_COUNT_INLINE(egprs_dl_mcs7, CTR_EGPRS_DL_MCS7);
560CREATE_COUNT_INLINE(egprs_dl_mcs8, CTR_EGPRS_DL_MCS8);
561CREATE_COUNT_INLINE(egprs_dl_mcs9, CTR_EGPRS_DL_MCS9);
562CREATE_COUNT_INLINE(gprs_ul_cs1, CTR_GPRS_UL_CS1);
563CREATE_COUNT_INLINE(gprs_ul_cs2, CTR_GPRS_UL_CS2);
564CREATE_COUNT_INLINE(gprs_ul_cs3, CTR_GPRS_UL_CS3);
565CREATE_COUNT_INLINE(gprs_ul_cs4, CTR_GPRS_UL_CS4);
566CREATE_COUNT_INLINE(egprs_ul_mcs1, CTR_EGPRS_UL_MCS1);
567CREATE_COUNT_INLINE(egprs_ul_mcs2, CTR_EGPRS_UL_MCS2);
568CREATE_COUNT_INLINE(egprs_ul_mcs3, CTR_EGPRS_UL_MCS3);
569CREATE_COUNT_INLINE(egprs_ul_mcs4, CTR_EGPRS_UL_MCS4);
570CREATE_COUNT_INLINE(egprs_ul_mcs5, CTR_EGPRS_UL_MCS5);
571CREATE_COUNT_INLINE(egprs_ul_mcs6, CTR_EGPRS_UL_MCS6);
572CREATE_COUNT_INLINE(egprs_ul_mcs7, CTR_EGPRS_UL_MCS7);
573CREATE_COUNT_INLINE(egprs_ul_mcs8, CTR_EGPRS_UL_MCS8);
574CREATE_COUNT_INLINE(egprs_ul_mcs9, CTR_EGPRS_UL_MCS9);
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100575
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100576#undef CREATE_COUNT_INLINE
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100577
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100578#define CREATE_STAT_INLINE(func_name, func_name_get, stat_name) \
579 inline void BTS::func_name(int32_t val) {\
580 osmo_stat_item_set(m_statg->items[stat_name], val); \
581 } \
582 inline int32_t BTS::func_name_get() {\
583 return osmo_stat_item_get_last(m_statg->items[stat_name]); \
584 }
585
586CREATE_STAT_INLINE(ms_present, ms_present_get, STAT_MS_PRESENT);
587
588#undef CREATE_STAT_INLINE
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100589
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200590#endif
591
592#ifdef __cplusplus
593extern "C" {
594#endif
Maxd5ffeb52019-03-18 15:48:38 +0100595 void bts_cleanup();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200596 struct gprs_rlcmac_bts *bts_main_data();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100597 struct rate_ctr_group *bts_main_data_stats();
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100598 struct osmo_stat_item_group *bts_main_data_stat_items();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200599#ifdef __cplusplus
600}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200601
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200602#endif