blob: 05f220005fc132c87c148ca993642bc41c5a01c0 [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 Freyther17b0d832013-10-19 17:37:48 +020050 /* TODO: the PDCH should know the trx/ts it belongs to */
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +020051 void free_resources(BTS *bts, uint8_t trx, uint8_t ts);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +020052
53 bool is_enabled() const;
54
55 void enable();
56 void disable();
57#endif
58
59 uint8_t m_is_enabled; /* TS is enabled */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020060 uint8_t tsc; /* TSC of this slot */
61 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
62 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
63 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
64 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
65 struct llist_head paging_list; /* list of paging messages */
66 uint32_t last_rts_fn; /* store last frame number of RTS */
67};
68
69struct gprs_rlcmac_trx {
70 void *fl1h;
71 uint16_t arfcn;
72 struct gprs_rlcmac_pdch pdch[8];
73 struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */
74 struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */
75};
76
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020077/**
78 * This is the data from C. As soon as our minimal compiler is gcc 4.7
79 * we can start to compile pcu_vty.c with c++ and remove the split.
80 */
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020081struct gprs_rlcmac_bts {
82 uint8_t bsic;
83 uint8_t fc_interval;
84 uint8_t cs1;
85 uint8_t cs2;
86 uint8_t cs3;
87 uint8_t cs4;
88 uint8_t initial_cs_dl, initial_cs_ul;
89 uint8_t force_cs; /* 0=use from BTS 1=use from VTY */
90 uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */
91 uint8_t t3142;
92 uint8_t t3169;
93 uint8_t t3191;
94 uint16_t t3193_msec;
95 uint8_t t3195;
96 uint8_t n3101;
97 uint8_t n3103;
98 uint8_t n3105;
99 struct gprs_rlcmac_trx trx[8];
100 int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts,
101 struct gprs_rlcmac_tbf *old_tbf,
102 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single);
103 uint32_t alloc_algorithm_curst; /* options to customize algorithm */
104 uint8_t force_two_phase;
105 uint8_t alpha, gamma;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200106
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200107 /* TBF handling, make private or move into TBFController */
108 /* list of uplink TBFs */
109 struct llist_head ul_tbfs;
110 /* list of downlink TBFs */
111 struct llist_head dl_tbfs;
112
113
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200114 /**
115 * Point back to the C++ object. This is used during the transition
116 * period.
117 */
118 struct BTS *bts;
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +0200119};
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200120
121#ifdef __cplusplus
122/**
123 * I represent a GSM BTS. I have one or more TRX, I know the current
124 * GSM time and I have controllers that help with allocating resources
125 * on my TRXs.
126 */
127struct BTS {
128public:
129 BTS();
130
131 static BTS* main_bts();
132
133 struct gprs_rlcmac_bts *bts_data();
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200134 SBAController *sba();
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200135 TimingAdvance *timing_advance();
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200136
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200137 /** TODO: change the number to unsigned */
138 void set_current_frame_number(int frame_number);
139 int current_frame_number() const;
140
Holger Hans Peter Freytherf0984892013-10-19 18:28:59 +0200141 /** add paging to paging queue(s) */
142 int add_paging(uint8_t chan_needed, uint8_t *identity_lv);
143
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200144 gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir);
145 gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts);
146
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200147private:
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200148 int m_cur_fn;
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200149 struct gprs_rlcmac_bts m_bts;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200150 PollController m_pollController;
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200151 SBAController m_sba;
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200152 TimingAdvance m_ta;
Holger Hans Peter Freytherb78adcd2013-10-17 20:12:37 +0200153
154private:
155 /* disable copying to avoid slicing */
156 BTS(const BTS&);
157 BTS& operator=(const BTS&);
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200158};
Holger Hans Peter Freyther9b30c7f2013-10-17 19:59:56 +0200159
160inline int BTS::current_frame_number() const
161{
162 return m_cur_fn;
163}
Holger Hans Peter Freyther111614a2013-10-19 20:04:57 +0200164
165inline TimingAdvance *BTS::timing_advance()
166{
167 return &m_ta;
168}
Holger Hans Peter Freythercedf8902013-10-19 20:47:12 +0200169
170inline SBAController *BTS::sba()
171{
172 return &m_sba;
173}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200174#endif
175
176#ifdef __cplusplus
177extern "C" {
178#endif
179 struct gprs_rlcmac_bts *bts_main_data();
180#ifdef __cplusplus
181}
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200182
183inline bool gprs_rlcmac_pdch::is_enabled() const
184{
185 return m_is_enabled;
186}
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200187#endif