blob: 608f215e18c2401ac1197a31f3b43ce5dfcc5fc9 [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>
27#include <osmocom/core/timer.h>
28}
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +020029
30#include "poll_controller.h"
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +020031#include "sba.h"
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +020032#include "ta.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020033#include "tbf.h"
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020034#endif
35
36#include <stdint.h>
37
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020038struct BTS;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020039
40/*
41 * PDCH instance
42 */
43struct gprs_rlcmac_pdch {
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020044#ifdef __cplusplus
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020045 struct gprs_rlcmac_paging *dequeue_paging();
46 struct msgb *packet_paging_request();
47
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +020048 void add_paging(struct gprs_rlcmac_paging *pag);
Holger Hans Peter Freyther24e98d02013-10-19 18:15:44 +020049
Holger Hans Peter Freyther09ef27a2013-10-20 16:37:05 +020050 void free_resources();
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020051
52 bool is_enabled() const;
53
54 void enable();
55 void disable();
Holger Hans Peter Freyther9ae367f2013-10-26 16:42:38 +020056
57 /* dispatching of messages */
58 int rcv_block(uint8_t *data, uint8_t len, uint32_t fn, int8_t rssi);
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +020059
60 gprs_rlcmac_bts *bts_data() const;
61 BTS *bts() const;
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +020062 uint8_t trx_no() const;
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020063#endif
64
65 uint8_t m_is_enabled; /* TS is enabled */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020066 uint8_t tsc; /* TSC of this slot */
67 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
68 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
69 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
70 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
71 struct llist_head paging_list; /* list of paging messages */
72 uint32_t last_rts_fn; /* store last frame number of RTS */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020073
74 /* back pointers */
75 struct gprs_rlcmac_trx *trx;
76 uint8_t ts_no;
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020077
78#ifdef __cplusplus
79private:
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +020080 int rcv_data_block_acknowledged(uint8_t *data, uint8_t len, int8_t rssi);
81 int rcv_control_block(bitvec *rlc_block, uint32_t fn);
Holger Hans Peter Freytherd11290b2013-10-26 17:32:04 +020082
83#endif
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020084};
85
86struct gprs_rlcmac_trx {
87 void *fl1h;
88 uint16_t arfcn;
89 struct gprs_rlcmac_pdch pdch[8];
90 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
91 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020092
93 /* back pointers */
94 struct BTS *bts;
95 uint8_t trx_no;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020096};
97
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020098/**
99 * This is the data from C. As soon as our minimal compiler is gcc 4.7
100 * we can start to compile pcu_vty.c with c++ and remove the split.
101 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200102struct gprs_rlcmac_bts {
103 uint8_t bsic;
104 uint8_t fc_interval;
105 uint8_t cs1;
106 uint8_t cs2;
107 uint8_t cs3;
108 uint8_t cs4;
109 uint8_t initial_cs_dl, initial_cs_ul;
110 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
111 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
112 uint8_t t3142;
113 uint8_t t3169;
114 uint8_t t3191;
115 uint16_t t3193_msec;
116 uint8_t t3195;
117 uint8_t n3101;
118 uint8_t n3103;
119 uint8_t n3105;
120 struct gprs_rlcmac_trx trx[8];
121 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
122 struct gprs_rlcmac_tbf *old_tbf,
123 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
124 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
125 uint8_t force_two_phase;
126 uint8_t alpha, gamma;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200127
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200128 /* TBF handling, make private or move into TBFController */
129 /* list of uplink TBFs */
130 struct llist_head ul_tbfs;
131 /* list of downlink TBFs */
132 struct llist_head dl_tbfs;
133
134
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200135 /**
136 * Point back to the C++ object. This is used during the transition
137 * period.
138 */
139 struct BTS *bts;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200140};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200141
142#ifdef __cplusplus
143/**
144 * I represent a GSM BTS. I have one or more TRX, I know the current
145 * GSM time and I have controllers that help with allocating resources
146 * on my TRXs.
147 */
148struct BTS {
149public:
150 BTS();
151
152 static BTS* main_bts();
153
154 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200155 SBAController *sba();
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200156 TimingAdvance *timing_advance();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200157
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200158 /** TODO: change the number to unsigned */
159 void set_current_frame_number(int frame_number);
160 int current_frame_number() const;
161
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200162 /** add paging to paging queue(s) */
163 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
164
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200165 gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
166 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 +0200167 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 +0200168
Holger Hans Peter Freyther70ddde62013-10-26 19:17:58 +0200169 int tfi_find_free(enum gprs_rlcmac_tbf_direction dir, uint8_t *_trx, int8_t use_trx);
170
Holger Hans Peter Freyther40cfaa62013-10-26 19:49:16 +0200171 int rcv_imm_ass_cnf(const uint8_t *data, uint32_t fn);
172
Holger Hans Peter Freytherd9262b32013-10-26 20:12:59 +0200173 void snd_dl_ass(gprs_rlcmac_tbf *tbf, uint8_t poll, const char *imsi);
174
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200175private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200176 int m_cur_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200177 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200178 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200179 SBAController m_sba;
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200180 TimingAdvance m_ta;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200181
182private:
183 /* disable copying to avoid slicing */
184 BTS(const BTS&);
185 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200186};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200187
188inline int BTS::current_frame_number() const
189{
190 return m_cur_fn;
191}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200192
193inline TimingAdvance *BTS::timing_advance()
194{
195 return &m_ta;
196}
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200197
198inline SBAController *BTS::sba()
199{
200 return &m_sba;
201}
Holger Hans Peter Freyther65be4802013-10-26 18:39:36 +0200202
203inline BTS *gprs_rlcmac_pdch::bts() const
204{
205 return trx->bts;
206}
207
208inline gprs_rlcmac_bts *gprs_rlcmac_pdch::bts_data() const
209{
210 return trx->bts->bts_data();
211}
Holger Hans Peter Freyther05f8efc2013-10-26 18:53:16 +0200212
213inline uint8_t gprs_rlcmac_pdch::trx_no() const
214{
215 return trx->trx_no;
216}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200217#endif
218
219#ifdef __cplusplus
220extern "C" {
221#endif
222 struct gprs_rlcmac_bts *bts_main_data();
223#ifdef __cplusplus
224}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200225
226inline bool gprs_rlcmac_pdch::is_enabled() const
227{
228 return m_is_enabled;
229}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200230#endif