blob: e52875ebeb21db7e3505b67234e10de9d3aa7a01 [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>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020028#include <osmocom/core/timer.h>
29}
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020030
31#include "poll_controller.h"
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +020032#include "sba.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020033#include "tbf.h"
Jacob Erlbecke43460b2015-05-13 13:33:12 +020034#include "gprs_ms_storage.h"
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020035#endif
36
37#include <stdint.h>
38
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020039struct BTS;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020040
41/*
42 * PDCH instance
43 */
44struct gprs_rlcmac_pdch {
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020045#ifdef __cplusplus
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020046 struct gprs_rlcmac_paging *dequeue_paging();
47 struct msgb *packet_paging_request();
48
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +020049 void add_paging(struct gprs_rlcmac_paging *pag);
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020050
Holger Hans Peter Freyther09ef27a2013-10-20 16:37:05 +020051 void free_resources();
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020052
53 bool is_enabled() const;
54
55 void enable();
56 void disable();
Holger Hans Peter Freyther9ae367f2013-10-26 16:42:38 +020057
58 /* dispatching of messages */
59 int rcv_block(uint8_t *data, uint8_t len, uint32_t fn, int8_t rssi);
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +020060
61 gprs_rlcmac_bts *bts_data() const;
62 BTS *bts() const;
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +020063 uint8_t trx_no() const;
Daniel Willmann1e0c6102014-06-04 14:56:09 +020064
Daniel Willmannfe6e2e42014-07-10 17:44:06 +020065 struct gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi);
66 struct gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020067#endif
68
69 uint8_t m_is_enabled; /* TS is enabled */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020070 uint8_t tsc; /* TSC of this slot */
71 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
72 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
Holger Hans Peter Freyther705653b2013-11-26 16:39:28 +010073 uint8_t next_ctrl_prio; /* next kind of ctrl message to schedule */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020074 struct llist_head paging_list; /* list of paging messages */
75 uint32_t last_rts_fn; /* store last frame number of RTS */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020076
77 /* back pointers */
78 struct gprs_rlcmac_trx *trx;
79 uint8_t ts_no;
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020080
81#ifdef __cplusplus
82private:
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +020083 int rcv_data_block_acknowledged(uint8_t *data, uint8_t len, int8_t rssi);
84 int rcv_control_block(bitvec *rlc_block, uint32_t fn);
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020085
Holger Hans Peter Freythere1a075a2013-10-27 13:35:30 +010086 void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn);
Holger Hans Peter Freyther5da20142013-10-27 11:41:01 +010087 void rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *, uint32_t fn);
Holger Hans Peter Freyther7a344712013-10-27 11:37:53 +010088 void rcv_resource_request(Packet_Resource_Request_t *t, uint32_t fn);
Holger Hans Peter Freythercb5c49b2013-10-27 11:19:13 +010089 void rcv_measurement_report(Packet_Measurement_Report_t *t, uint32_t fn);
Daniel Willmann2207c5e2014-07-10 17:44:06 +020090 gprs_rlcmac_tbf *tbf_from_list_by_tfi(struct llist_head *tbf_list, uint8_t tfi,
91 enum gprs_rlcmac_tbf_direction dir);
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020092#endif
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020093};
94
95struct gprs_rlcmac_trx {
96 void *fl1h;
97 uint16_t arfcn;
98 struct gprs_rlcmac_pdch pdch[8];
99 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
100 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +0200101
102 /* back pointers */
103 struct BTS *bts;
104 uint8_t trx_no;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200105};
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 {
112 uint8_t bsic;
113 uint8_t fc_interval;
Jacob Erlbeck0288cdb2015-05-06 10:47:30 +0200114 uint16_t fc_bucket_time;
Jacob Erlbeck87d73412015-04-21 12:56:48 +0200115 uint32_t fc_bvc_bucket_size;
116 uint32_t fc_bvc_leak_rate;
117 uint32_t fc_ms_bucket_size;
118 uint32_t fc_ms_leak_rate;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200119 uint8_t cs1;
120 uint8_t cs2;
121 uint8_t cs3;
122 uint8_t cs4;
123 uint8_t initial_cs_dl, initial_cs_ul;
Jacob Erlbeckb33e6752015-06-04 19:04:30 +0200124 uint8_t max_cs_dl, max_cs_ul;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200125 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
126 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
Jacob Erlbeck0c1c8772015-03-20 12:02:42 +0100127 uint32_t llc_discard_csec;
Jacob Erlbeckd0261b72015-04-02 13:58:09 +0200128 uint32_t llc_idle_ack_csec;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200129 uint8_t t3142;
130 uint8_t t3169;
131 uint8_t t3191;
132 uint16_t t3193_msec;
133 uint8_t t3195;
134 uint8_t n3101;
135 uint8_t n3103;
136 uint8_t n3105;
137 struct gprs_rlcmac_trx trx[8];
138 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
139 struct gprs_rlcmac_tbf *old_tbf,
140 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
141 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
142 uint8_t force_two_phase;
143 uint8_t alpha, gamma;
Jacob Erlbeck3bed5d12015-03-19 11:22:38 +0100144 uint32_t dl_tbf_idle_msec; /* hold time for idle DL TBFs */
Jacob Erlbecka098c192015-05-28 16:11:19 +0200145 uint32_t ms_idle_sec;
Jacob Erlbeck1751c622015-06-04 12:12:32 +0200146 uint8_t cs_adj_enabled;
147 uint8_t cs_adj_upper_limit;
148 uint8_t cs_adj_lower_limit;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200149
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200150 /* TBF handling, make private or move into TBFController */
151 /* list of uplink TBFs */
152 struct llist_head ul_tbfs;
153 /* list of downlink TBFs */
154 struct llist_head dl_tbfs;
155
156
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200157 /**
158 * Point back to the C++ object. This is used during the transition
159 * period.
160 */
161 struct BTS *bts;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200162};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200163
164#ifdef __cplusplus
165/**
166 * I represent a GSM BTS. I have one or more TRX, I know the current
167 * GSM time and I have controllers that help with allocating resources
168 * on my TRXs.
169 */
170struct BTS {
171public:
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100172 enum {
173 CTR_TBF_DL_ALLOCATED,
174 CTR_TBF_DL_FREED,
175 CTR_TBF_UL_ALLOCATED,
176 CTR_TBF_UL_FREED,
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100177 CTR_TBF_REUSED,
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100178 CTR_RLC_SENT,
179 CTR_RLC_RESENT,
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100180 CTR_RLC_RESTARTED,
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100181 CTR_RLC_STALLED,
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100182 CTR_RLC_NACKED,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100183 CTR_DECODE_ERRORS,
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100184 CTR_SBA_ALLOCATED,
185 CTR_SBA_FREED,
186 CTR_SBA_TIMEDOUT,
Holger Hans Peter Freyther19977872013-10-27 10:34:31 +0100187 CTR_LLC_FRAME_TIMEDOUT,
188 CTR_LLC_FRAME_DROPPED,
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100189 CTR_LLC_FRAME_SCHED,
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100190 CTR_RACH_REQUESTS,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100191 };
192
Jacob Erlbeck502bd1f2015-03-20 14:26:05 +0100193 enum {
194 TIMER_T3190_MSEC = 5000,
195 };
196
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200197 BTS();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100198 ~BTS();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200199
200 static BTS* main_bts();
201
202 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200203 SBAController *sba();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200204
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200205 /** TODO: change the number to unsigned */
206 void set_current_frame_number(int frame_number);
207 int current_frame_number() const;
208
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200209 /** add paging to paging queue(s) */
210 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
211
Daniel Willmannfe6e2e42014-07-10 17:44:06 +0200212 gprs_rlcmac_dl_tbf *dl_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
213 gprs_rlcmac_ul_tbf *ul_tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
214 gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi, uint8_t trx);
215 gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi, uint8_t trx);
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200216
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200217 int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx);
218
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200219 int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200220 int rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta);
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200221
Jacob Erlbeck71e55112015-05-21 11:10:15 +0200222 void trigger_dl_ass(gprs_rlcmac_dl_tbf *tbf, gprs_rlcmac_tbf *old_tbf);
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200223 void snd_dl_ass(gprs_rlcmac_tbf *tbf, uint8_t poll, const char *imsi);
224
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200225 GprsMsStorage &ms_store();
226 GprsMs *ms_by_tlli(uint32_t tlli, uint32_t old_tlli = 0);
227
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100228 /*
229 * Statistics
230 */
231 void tbf_dl_created();
232 void tbf_dl_freed();
233 void tbf_ul_created();
234 void tbf_ul_freed();
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100235 void tbf_reused();
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100236 void rlc_sent();
237 void rlc_resent();
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100238 void rlc_restarted();
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100239 void rlc_stalled();
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100240 void rlc_nacked();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100241 void decode_error();
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100242 void sba_allocated();
243 void sba_freed();
244 void sba_timedout();
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100245 void llc_timedout_frame();
246 void llc_dropped_frame();
247 void llc_frame_sched();
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100248 void rach_frame();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100249
250 /*
251 * Below for C interface for the VTY
252 */
253 struct rate_ctr_group *rate_counters() const;
254
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200255private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200256 int m_cur_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200257 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200258 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200259 SBAController m_sba;
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100260 struct rate_ctr_group *m_ratectrs;
Daniel Willmann54044b02014-07-02 17:58:15 +0200261 gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, uint8_t trx, enum gprs_rlcmac_tbf_direction dir);
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200262
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200263 GprsMsStorage m_ms_store;
264
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200265private:
266 /* disable copying to avoid slicing */
267 BTS(const BTS&);
268 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200269};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200270
271inline int BTS::current_frame_number() const
272{
273 return m_cur_fn;
274}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200275
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200276inline SBAController *BTS::sba()
277{
278 return &m_sba;
279}
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200280
Jacob Erlbecke43460b2015-05-13 13:33:12 +0200281inline GprsMsStorage &BTS::ms_store()
282{
283 return m_ms_store;
284}
285
286inline GprsMs *BTS::ms_by_tlli(uint32_t tlli, uint32_t old_tlli)
287{
288 return ms_store().get_ms(tlli, old_tlli);
289}
290
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200291inline BTS *gprs_rlcmac_pdch::bts() const
292{
293 return trx->bts;
294}
295
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100296inline struct rate_ctr_group *BTS::rate_counters() const
297{
298 return m_ratectrs;
299}
300
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100301#define CREATE_COUNT_INLINE(func_name, ctr_name) \
302 inline void BTS::func_name() {\
303 rate_ctr_inc(&m_ratectrs->ctr[ctr_name]); \
304 }
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100305
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100306CREATE_COUNT_INLINE(tbf_dl_created, CTR_TBF_DL_ALLOCATED)
307CREATE_COUNT_INLINE(tbf_dl_freed, CTR_TBF_DL_FREED)
308CREATE_COUNT_INLINE(tbf_ul_created, CTR_TBF_UL_ALLOCATED)
309CREATE_COUNT_INLINE(tbf_ul_freed, CTR_TBF_UL_FREED)
Holger Hans Peter Freytheraa35ba72013-11-13 15:02:50 +0100310CREATE_COUNT_INLINE(tbf_reused, CTR_TBF_REUSED)
Holger Hans Peter Freythere9429b52013-11-13 19:36:57 +0100311CREATE_COUNT_INLINE(rlc_sent, CTR_RLC_SENT)
312CREATE_COUNT_INLINE(rlc_resent, CTR_RLC_RESENT)
Holger Hans Peter Freytheref93bdb2013-11-24 00:01:50 +0100313CREATE_COUNT_INLINE(rlc_restarted, CTR_RLC_RESTARTED)
Holger Hans Peter Freytherc70aae42013-11-19 17:09:37 +0100314CREATE_COUNT_INLINE(rlc_stalled, CTR_RLC_STALLED)
Holger Hans Peter Freyther092478f2013-11-23 01:01:19 +0100315CREATE_COUNT_INLINE(rlc_nacked, CTR_RLC_NACKED)
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100316CREATE_COUNT_INLINE(decode_error, CTR_DECODE_ERRORS)
317CREATE_COUNT_INLINE(sba_allocated, CTR_SBA_ALLOCATED)
318CREATE_COUNT_INLINE(sba_freed, CTR_SBA_FREED)
319CREATE_COUNT_INLINE(sba_timedout, CTR_SBA_TIMEDOUT)
Holger Hans Peter Freytherb3d5ee22013-11-13 16:43:26 +0100320CREATE_COUNT_INLINE(llc_timedout_frame, CTR_LLC_FRAME_TIMEDOUT);
321CREATE_COUNT_INLINE(llc_dropped_frame, CTR_LLC_FRAME_DROPPED);
322CREATE_COUNT_INLINE(llc_frame_sched, CTR_LLC_FRAME_SCHED);
Holger Hans Peter Freytherc1ae2262013-10-27 10:50:35 +0100323CREATE_COUNT_INLINE(rach_frame, CTR_RACH_REQUESTS);
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100324
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100325#undef CREATE_COUNT_INLINE
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100326
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100327
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200328inline gprs_rlcmac_bts *gprs_rlcmac_pdch::bts_data() const
329{
330 return trx->bts->bts_data();
331}
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +0200332
333inline uint8_t gprs_rlcmac_pdch::trx_no() const
334{
335 return trx->trx_no;
336}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200337#endif
338
339#ifdef __cplusplus
340extern "C" {
341#endif
342 struct gprs_rlcmac_bts *bts_main_data();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100343 struct rate_ctr_group *bts_main_data_stats();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200344#ifdef __cplusplus
345}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200346
347inline bool gprs_rlcmac_pdch::is_enabled() const
348{
349 return m_is_enabled;
350}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200351#endif