blob: 246f71e4bd8f16f9b93e1c4f80bc9c19af3426d4 [file] [log] [blame]
Jacob Erlbecke04e0b02015-05-06 18:30:48 +02001/* gprs_ms.h
2 *
3 * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
4 * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
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
23struct gprs_rlcmac_tbf;
24struct gprs_rlcmac_dl_tbf;
25struct gprs_rlcmac_ul_tbf;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +020026struct gprs_codel;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020027
Jacob Erlbeck53670862015-05-12 17:54:33 +020028#include "cxx_linuxlist.h"
Jacob Erlbeck489a2b32015-05-28 19:07:01 +020029#include "llc.h"
Jacob Erlbeckac89a552015-06-29 14:18:46 +020030#include "tbf.h"
Jacob Erlbecke4bcb622015-06-08 11:26:38 +020031#include "pcu_l1_if.h"
Jacob Erlbeckd9e10242015-05-28 15:43:53 +020032
33extern "C" {
34 #include <osmocom/core/timer.h>
35}
36
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020037#include <stdint.h>
38#include <stddef.h>
39
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020040struct BTS;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +020041struct gprs_rlcmac_trx;
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020042
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020043class GprsMs {
44public:
45 struct Callback {
46 virtual void ms_idle(class GprsMs *) = 0;
47 virtual void ms_active(class GprsMs *) = 0;
48 };
49
50 class Guard {
51 public:
52 Guard(GprsMs *ms);
53 ~Guard();
54
Jacob Erlbeckb2439bb2015-07-13 14:23:32 +020055 bool is_idle() const;
56
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020057 private:
58 GprsMs * const m_ms;
59 };
60
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020061 GprsMs(BTS *bts, uint32_t tlli);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020062 ~GprsMs();
63
64 void set_callback(Callback *cb) {m_cb = cb;}
65
Jacob Erlbeck2b349b52015-08-18 11:55:03 +020066 void merge_old_ms(GprsMs *old_ms);
67
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020068 gprs_rlcmac_ul_tbf *ul_tbf() const {return m_ul_tbf;}
69 gprs_rlcmac_dl_tbf *dl_tbf() const {return m_dl_tbf;}
Jacob Erlbeckac89a552015-06-29 14:18:46 +020070 gprs_rlcmac_tbf *tbf(enum gprs_rlcmac_tbf_direction dir) const;
Jacob Erlbeck93990462015-05-15 15:50:43 +020071 uint32_t tlli() const;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020072 void set_tlli(uint32_t tlli);
Jacob Erlbeck93990462015-05-15 15:50:43 +020073 bool confirm_tlli(uint32_t tlli);
74 bool check_tlli(uint32_t tlli);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020075
Jacob Erlbeckac289052015-08-14 12:50:54 +020076 void reset();
Jacob Erlbeckcb728902016-01-05 15:33:03 +010077 GprsCodingScheme::Mode mode() const;
78 void set_mode(GprsCodingScheme::Mode mode);
Jacob Erlbeckac289052015-08-14 12:50:54 +020079
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +020080 const char *imsi() const;
81 void set_imsi(const char *imsi);
82
Jacob Erlbeck9200ce62015-05-22 17:48:04 +020083 uint8_t ta() const;
84 void set_ta(uint8_t ta);
Jacob Erlbeckbefc7602015-06-02 12:33:30 +020085 uint8_t ms_class() const;
Jacob Erlbeckc3c58042015-09-28 17:55:32 +020086 uint8_t egprs_ms_class() const;
Jacob Erlbeckbefc7602015-06-02 12:33:30 +020087 void set_ms_class(uint8_t ms_class);
Jacob Erlbeckc3c58042015-09-28 17:55:32 +020088 void set_egprs_ms_class(uint8_t ms_class);
Jacob Erlbeck9200ce62015-05-22 17:48:04 +020089
Jacob Erlbeckcb728902016-01-05 15:33:03 +010090 GprsCodingScheme current_cs_ul() const;
91 GprsCodingScheme current_cs_dl() const;
92 GprsCodingScheme max_cs_ul() const;
93 GprsCodingScheme max_cs_dl() const;
Jacob Erlbecka700dd92015-06-02 16:00:41 +020094
Jacob Erlbeck699b8dc2015-06-29 14:05:55 +020095 int first_common_ts() const;
Jacob Erlbeck617c7122015-06-30 09:18:30 +020096 uint8_t dl_slots() const;
97 uint8_t ul_slots() const;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +020098 uint8_t reserved_dl_slots() const;
99 uint8_t reserved_ul_slots() const;
100 gprs_rlcmac_trx *current_trx() const;
101 void set_reserved_slots(gprs_rlcmac_trx *trx,
102 uint8_t ul_slots, uint8_t dl_slots);
Jacob Erlbeck699b8dc2015-06-29 14:05:55 +0200103
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200104 gprs_llc_queue *llc_queue();
105 const gprs_llc_queue *llc_queue() const;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200106 gprs_codel *codel_state() const;
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200107
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200108 void set_timeout(unsigned secs);
109
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200110 void attach_tbf(gprs_rlcmac_tbf *tbf);
111 void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf);
112 void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf);
113
114 void detach_tbf(gprs_rlcmac_tbf *tbf);
115
Jacob Erlbeck1751c622015-06-04 12:12:32 +0200116 void update_error_rate(gprs_rlcmac_tbf *tbf, int percent);
117
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200118 bool is_idle() const;
Jacob Erlbeckc8cbfc22015-09-01 11:38:40 +0200119 bool need_dl_tbf() const;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200120
121 void* operator new(size_t num);
122 void operator delete(void* p);
123
Jacob Erlbeck53670862015-05-12 17:54:33 +0200124 LListHead<GprsMs>& list() {return this->m_list;}
125 const LListHead<GprsMs>& list() const {return this->m_list;}
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200126 const LListHead<gprs_rlcmac_tbf>& old_tbfs() const {return m_old_tbfs;}
Jacob Erlbeck53670862015-05-12 17:54:33 +0200127
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200128 void update_l1_meas(const pcu_l1_meas *meas);
129 const pcu_l1_meas* l1_meas() const {return &m_l1_meas;};
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200130 unsigned nack_rate_dl() const;
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200131
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200132 /* internal use */
133 static void timeout(void *priv_);
134
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200135protected:
136 void update_status();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200137 GprsMs *ref();
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200138 void unref();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200139 void start_timer();
140 void stop_timer();
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100141 void update_cs_ul(const pcu_l1_meas*);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200142
143private:
Jacob Erlbeck17214bb2015-06-02 14:06:12 +0200144 BTS *m_bts;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200145 Callback * m_cb;
146 gprs_rlcmac_ul_tbf *m_ul_tbf;
147 gprs_rlcmac_dl_tbf *m_dl_tbf;
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200148 LListHead<gprs_rlcmac_tbf> m_old_tbfs;
149
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200150 uint32_t m_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200151 uint32_t m_new_ul_tlli;
152 uint32_t m_new_dl_tlli;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200153
154 /* store IMSI for look-up and PCH retransmission */
155 char m_imsi[16];
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200156 uint8_t m_ta;
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200157 uint8_t m_ms_class;
Jacob Erlbeckc3c58042015-09-28 17:55:32 +0200158 uint8_t m_egprs_ms_class;
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200159 /* current coding scheme */
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100160 GprsCodingScheme m_current_cs_ul;
161 GprsCodingScheme m_current_cs_dl;
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200162
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200163 gprs_llc_queue m_llc_queue;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200164
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200165 bool m_is_idle;
166 int m_ref;
Jacob Erlbeck53670862015-05-12 17:54:33 +0200167 LListHead<GprsMs> m_list;
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200168 struct osmo_timer_list m_timer;
169 unsigned m_delay;
Jacob Erlbeck8158ea72015-06-04 17:46:33 +0200170
171 int64_t m_last_cs_not_low;
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200172
173 pcu_l1_meas m_l1_meas;
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200174 unsigned m_nack_rate_dl;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +0200175 uint8_t m_reserved_dl_slots;
176 uint8_t m_reserved_ul_slots;
177 gprs_rlcmac_trx *m_current_trx;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200178
179 struct gprs_codel *m_codel_state;
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100180 GprsCodingScheme::Mode m_mode;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200181};
Jacob Erlbeck93990462015-05-15 15:50:43 +0200182
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200183inline bool GprsMs::is_idle() const
184{
185 return !m_ul_tbf && !m_dl_tbf && !m_ref && llist_empty(&m_old_tbfs);
186}
187
Jacob Erlbeckc8cbfc22015-09-01 11:38:40 +0200188inline bool GprsMs::need_dl_tbf() const
189{
190 if (dl_tbf() != NULL && dl_tbf()->state_is_not(GPRS_RLCMAC_WAIT_RELEASE))
191 return false;
192
193 return llc_queue()->size() > 0;
194}
195
Jacob Erlbeck93990462015-05-15 15:50:43 +0200196inline uint32_t GprsMs::tlli() const
197{
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200198 return m_new_ul_tlli ? m_new_ul_tlli :
199 m_tlli ? m_tlli :
200 m_new_dl_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200201}
202
203inline bool GprsMs::check_tlli(uint32_t tlli)
204{
205 return tlli != 0 &&
206 (tlli == m_tlli || tlli == m_new_ul_tlli || tlli == m_new_dl_tlli);
207}
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200208
209inline const char *GprsMs::imsi() const
210{
211 return m_imsi;
212}
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200213
214inline uint8_t GprsMs::ta() const
215{
216 return m_ta;
217}
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200218
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200219inline uint8_t GprsMs::ms_class() const
220{
221 return m_ms_class;
222}
223
Jacob Erlbeckc3c58042015-09-28 17:55:32 +0200224inline uint8_t GprsMs::egprs_ms_class() const
225{
226 return m_egprs_ms_class;
227}
228
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100229inline GprsCodingScheme GprsMs::current_cs_ul() const
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200230{
231 return m_current_cs_ul;
232}
233
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100234inline GprsCodingScheme::Mode GprsMs::mode() const
235{
236 return m_mode;
237}
238
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200239inline void GprsMs::set_timeout(unsigned secs)
240{
241 m_delay = secs;
242}
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200243
244inline gprs_llc_queue *GprsMs::llc_queue()
245{
246 return &m_llc_queue;
247}
248
249inline const gprs_llc_queue *GprsMs::llc_queue() const
250{
251 return &m_llc_queue;
252}
253
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200254inline gprs_codel *GprsMs::codel_state() const
255{
256 return m_codel_state;
257}
258
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200259inline unsigned GprsMs::nack_rate_dl() const
260{
261 return m_nack_rate_dl;
262}
263
Jacob Erlbeck23f93a12015-06-30 08:52:54 +0200264inline uint8_t GprsMs::reserved_dl_slots() const
265{
266 return m_reserved_dl_slots;
267}
268
269inline uint8_t GprsMs::reserved_ul_slots() const
270{
271 return m_reserved_ul_slots;
272}
273
274inline gprs_rlcmac_trx *GprsMs::current_trx() const
275{
276 return m_current_trx;
277}