blob: a8b62237d491ca4ccd821dcbf312c7ae481e0778 [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();
56#endif
57
58 uint8_t m_is_enabled; /* TS is enabled */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020059 uint8_t tsc; /* TSC of this slot */
60 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
61 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
62 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
63 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
64 struct llist_head paging_list; /* list of paging messages */
65 uint32_t last_rts_fn; /* store last frame number of RTS */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020066
67 /* back pointers */
68 struct gprs_rlcmac_trx *trx;
69 uint8_t ts_no;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020070};
71
72struct gprs_rlcmac_trx {
73 void *fl1h;
74 uint16_t arfcn;
75 struct gprs_rlcmac_pdch pdch[8];
76 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
77 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
Holger Hans Peter Freyther4ed1dae2013-10-20 10:14:03 +020078
79 /* back pointers */
80 struct BTS *bts;
81 uint8_t trx_no;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020082};
83
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020084/**
85 * This is the data from C. As soon as our minimal compiler is gcc 4.7
86 * we can start to compile pcu_vty.c with c++ and remove the split.
87 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020088struct gprs_rlcmac_bts {
89 uint8_t bsic;
90 uint8_t fc_interval;
91 uint8_t cs1;
92 uint8_t cs2;
93 uint8_t cs3;
94 uint8_t cs4;
95 uint8_t initial_cs_dl, initial_cs_ul;
96 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
97 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
98 uint8_t t3142;
99 uint8_t t3169;
100 uint8_t t3191;
101 uint16_t t3193_msec;
102 uint8_t t3195;
103 uint8_t n3101;
104 uint8_t n3103;
105 uint8_t n3105;
106 struct gprs_rlcmac_trx trx[8];
107 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
108 struct gprs_rlcmac_tbf *old_tbf,
109 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
110 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
111 uint8_t force_two_phase;
112 uint8_t alpha, gamma;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200113
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200114 /* TBF handling, make private or move into TBFController */
115 /* list of uplink TBFs */
116 struct llist_head ul_tbfs;
117 /* list of downlink TBFs */
118 struct llist_head dl_tbfs;
119
120
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200121 /**
122 * Point back to the C++ object. This is used during the transition
123 * period.
124 */
125 struct BTS *bts;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200126};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200127
128#ifdef __cplusplus
129/**
130 * I represent a GSM BTS. I have one or more TRX, I know the current
131 * GSM time and I have controllers that help with allocating resources
132 * on my TRXs.
133 */
134struct BTS {
135public:
136 BTS();
137
138 static BTS* main_bts();
139
140 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200141 SBAController *sba();
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200142 TimingAdvance *timing_advance();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200143
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200144 /** TODO: change the number to unsigned */
145 void set_current_frame_number(int frame_number);
146 int current_frame_number() const;
147
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200148 /** add paging to paging queue(s) */
149 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
150
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200151 gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
152 gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
153
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200154private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200155 int m_cur_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200156 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200157 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200158 SBAController m_sba;
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200159 TimingAdvance m_ta;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200160
161private:
162 /* disable copying to avoid slicing */
163 BTS(const BTS&);
164 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200165};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200166
167inline int BTS::current_frame_number() const
168{
169 return m_cur_fn;
170}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200171
172inline TimingAdvance *BTS::timing_advance()
173{
174 return &m_ta;
175}
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200176
177inline SBAController *BTS::sba()
178{
179 return &m_sba;
180}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200181#endif
182
183#ifdef __cplusplus
184extern "C" {
185#endif
186 struct gprs_rlcmac_bts *bts_main_data();
187#ifdef __cplusplus
188}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200189
190inline bool gprs_rlcmac_pdch::is_enabled() const
191{
192 return m_is_enabled;
193}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200194#endif