blob: 259be205bd16c3fc69fb7a9ed344e76966793c2f [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 Freyther111614a2013-10-19 20:04:57 +020033#include "ta.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020034#include "tbf.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;
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020064#endif
65
66 uint8_t m_is_enabled; /* TS is enabled */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020067 uint8_t tsc; /* TSC of this slot */
68 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
69 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
70 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
71 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
72 struct llist_head paging_list; /* list of paging messages */
73 uint32_t last_rts_fn; /* store last frame number of RTS */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020074
75 /* back pointers */
76 struct gprs_rlcmac_trx *trx;
77 uint8_t ts_no;
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020078
79#ifdef __cplusplus
80private:
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +020081 int rcv_data_block_acknowledged(uint8_t *data, uint8_t len, int8_t rssi);
82 int rcv_control_block(bitvec *rlc_block, uint32_t fn);
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020083
84#endif
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020085};
86
87struct gprs_rlcmac_trx {
88 void *fl1h;
89 uint16_t arfcn;
90 struct gprs_rlcmac_pdch pdch[8];
91 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
92 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020093
94 /* back pointers */
95 struct BTS *bts;
96 uint8_t trx_no;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020097};
98
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020099/**
100 * This is the data from C. As soon as our minimal compiler is gcc 4.7
101 * we can start to compile pcu_vty.c with c++ and remove the split.
102 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200103struct gprs_rlcmac_bts {
104 uint8_t bsic;
105 uint8_t fc_interval;
106 uint8_t cs1;
107 uint8_t cs2;
108 uint8_t cs3;
109 uint8_t cs4;
110 uint8_t initial_cs_dl, initial_cs_ul;
111 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
112 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
113 uint8_t t3142;
114 uint8_t t3169;
115 uint8_t t3191;
116 uint16_t t3193_msec;
117 uint8_t t3195;
118 uint8_t n3101;
119 uint8_t n3103;
120 uint8_t n3105;
121 struct gprs_rlcmac_trx trx[8];
122 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
123 struct gprs_rlcmac_tbf *old_tbf,
124 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
125 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
126 uint8_t force_two_phase;
127 uint8_t alpha, gamma;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200128
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200129 /* TBF handling, make private or move into TBFController */
130 /* list of uplink TBFs */
131 struct llist_head ul_tbfs;
132 /* list of downlink TBFs */
133 struct llist_head dl_tbfs;
134
135
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200136 /**
137 * Point back to the C++ object. This is used during the transition
138 * period.
139 */
140 struct BTS *bts;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200141};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200142
143#ifdef __cplusplus
144/**
145 * I represent a GSM BTS. I have one or more TRX, I know the current
146 * GSM time and I have controllers that help with allocating resources
147 * on my TRXs.
148 */
149struct BTS {
150public:
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100151 enum {
152 CTR_TBF_DL_ALLOCATED,
153 CTR_TBF_DL_FREED,
154 CTR_TBF_UL_ALLOCATED,
155 CTR_TBF_UL_FREED,
156 CTR_DECODE_ERRORS,
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100157 CTR_SBA_ALLOCATED,
158 CTR_SBA_FREED,
159 CTR_SBA_TIMEDOUT,
Holger Hans Peter Freyther19977872013-10-27 10:34:31 +0100160 CTR_LLC_FRAME_TIMEDOUT,
161 CTR_LLC_FRAME_DROPPED,
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100162 };
163
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200164 BTS();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100165 ~BTS();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200166
167 static BTS* main_bts();
168
169 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200170 SBAController *sba();
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200171 TimingAdvance *timing_advance();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200172
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200173 /** TODO: change the number to unsigned */
174 void set_current_frame_number(int frame_number);
175 int current_frame_number() const;
176
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200177 /** add paging to paging queue(s) */
178 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
179
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200180 gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
181 gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
Holger Hans Peter Freytherf63cabd2013-10-26 19:10:43 +0200182 gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, uint8_t trx, enum gprs_rlcmac_tbf_direction dir);
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200183
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200184 int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx);
185
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200186 int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
Holger Hans Peter Freyther02beed52013-10-26 20:56:20 +0200187 int rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta);
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200188
Holger Hans Peter Freyther24c1a5b2013-10-26 20:27:44 +0200189 void trigger_dl_ass(gprs_rlcmac_tbf *tbf, gprs_rlcmac_tbf *old_tbf, const char *imsi);
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200190 void snd_dl_ass(gprs_rlcmac_tbf *tbf, uint8_t poll, const char *imsi);
191
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100192 /*
193 * Statistics
194 */
195 void tbf_dl_created();
196 void tbf_dl_freed();
197 void tbf_ul_created();
198 void tbf_ul_freed();
199 void decode_error();
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100200 void sba_allocated();
201 void sba_freed();
202 void sba_timedout();
Holger Hans Peter Freyther19977872013-10-27 10:34:31 +0100203 void timedout_frame();
204 void dropped_frame();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100205
206 /*
207 * Below for C interface for the VTY
208 */
209 struct rate_ctr_group *rate_counters() const;
210
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200211private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200212 int m_cur_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200213 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200214 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200215 SBAController m_sba;
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200216 TimingAdvance m_ta;
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100217 struct rate_ctr_group *m_ratectrs;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200218
219private:
220 /* disable copying to avoid slicing */
221 BTS(const BTS&);
222 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200223};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200224
225inline int BTS::current_frame_number() const
226{
227 return m_cur_fn;
228}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200229
230inline TimingAdvance *BTS::timing_advance()
231{
232 return &m_ta;
233}
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200234
235inline SBAController *BTS::sba()
236{
237 return &m_sba;
238}
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200239
240inline BTS *gprs_rlcmac_pdch::bts() const
241{
242 return trx->bts;
243}
244
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100245inline struct rate_ctr_group *BTS::rate_counters() const
246{
247 return m_ratectrs;
248}
249
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100250#define CREATE_COUNT_INLINE(func_name, ctr_name) \
251 inline void BTS::func_name() {\
252 rate_ctr_inc(&m_ratectrs->ctr[ctr_name]); \
253 }
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100254
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100255CREATE_COUNT_INLINE(tbf_dl_created, CTR_TBF_DL_ALLOCATED)
256CREATE_COUNT_INLINE(tbf_dl_freed, CTR_TBF_DL_FREED)
257CREATE_COUNT_INLINE(tbf_ul_created, CTR_TBF_UL_ALLOCATED)
258CREATE_COUNT_INLINE(tbf_ul_freed, CTR_TBF_UL_FREED)
259CREATE_COUNT_INLINE(decode_error, CTR_DECODE_ERRORS)
260CREATE_COUNT_INLINE(sba_allocated, CTR_SBA_ALLOCATED)
261CREATE_COUNT_INLINE(sba_freed, CTR_SBA_FREED)
262CREATE_COUNT_INLINE(sba_timedout, CTR_SBA_TIMEDOUT)
Holger Hans Peter Freyther19977872013-10-27 10:34:31 +0100263CREATE_COUNT_INLINE(timedout_frame, CTR_LLC_FRAME_TIMEDOUT);
264CREATE_COUNT_INLINE(dropped_frame, CTR_LLC_FRAME_DROPPED);
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100265
Holger Hans Peter Freyther93e048f2013-10-27 10:00:47 +0100266#undef CREATE_COUNT_INLINE
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100267
Holger Hans Peter Freyther15877642013-10-27 09:50:15 +0100268
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200269inline gprs_rlcmac_bts *gprs_rlcmac_pdch::bts_data() const
270{
271 return trx->bts->bts_data();
272}
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +0200273
274inline uint8_t gprs_rlcmac_pdch::trx_no() const
275{
276 return trx->trx_no;
277}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200278#endif
279
280#ifdef __cplusplus
281extern "C" {
282#endif
283 struct gprs_rlcmac_bts *bts_main_data();
Holger Hans Peter Freytherf5372982013-10-27 09:02:31 +0100284 struct rate_ctr_group *bts_main_data_stats();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200285#ifdef __cplusplus
286}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200287
288inline bool gprs_rlcmac_pdch::is_enabled() const
289{
290 return m_is_enabled;
291}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200292#endif