blob: bcc4fb3299e8c0a511dafa8560a2edd2ec359863 [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);
Aravind Sirsikare8ccafc2016-07-13 11:37:47 +053089 void set_current_cs_dl(GprsCodingScheme::Scheme scheme);
Jacob Erlbeck9200ce62015-05-22 17:48:04 +020090
Jacob Erlbeckcb728902016-01-05 15:33:03 +010091 GprsCodingScheme current_cs_ul() const;
92 GprsCodingScheme current_cs_dl() const;
93 GprsCodingScheme max_cs_ul() const;
94 GprsCodingScheme max_cs_dl() const;
Jacob Erlbecka700dd92015-06-02 16:00:41 +020095
Jacob Erlbeck699b8dc2015-06-29 14:05:55 +020096 int first_common_ts() const;
Jacob Erlbeck617c7122015-06-30 09:18:30 +020097 uint8_t dl_slots() const;
98 uint8_t ul_slots() const;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +020099 uint8_t reserved_dl_slots() const;
100 uint8_t reserved_ul_slots() const;
Jacob Erlbeck7c72aca2016-01-22 17:06:14 +0100101 uint8_t current_pacch_slots() const;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +0200102 gprs_rlcmac_trx *current_trx() const;
103 void set_reserved_slots(gprs_rlcmac_trx *trx,
104 uint8_t ul_slots, uint8_t dl_slots);
Jacob Erlbeck699b8dc2015-06-29 14:05:55 +0200105
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200106 gprs_llc_queue *llc_queue();
107 const gprs_llc_queue *llc_queue() const;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200108 gprs_codel *codel_state() const;
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200109
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200110 void set_timeout(unsigned secs);
111
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200112 void attach_tbf(gprs_rlcmac_tbf *tbf);
113 void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf);
114 void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf);
115
116 void detach_tbf(gprs_rlcmac_tbf *tbf);
117
Jacob Erlbeck1751c622015-06-04 12:12:32 +0200118 void update_error_rate(gprs_rlcmac_tbf *tbf, int percent);
119
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200120 bool is_idle() const;
Jacob Erlbeckc8cbfc22015-09-01 11:38:40 +0200121 bool need_dl_tbf() const;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200122
123 void* operator new(size_t num);
124 void operator delete(void* p);
125
Jacob Erlbeck53670862015-05-12 17:54:33 +0200126 LListHead<GprsMs>& list() {return this->m_list;}
127 const LListHead<GprsMs>& list() const {return this->m_list;}
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200128 const LListHead<gprs_rlcmac_tbf>& old_tbfs() const {return m_old_tbfs;}
Jacob Erlbeck53670862015-05-12 17:54:33 +0200129
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200130 void update_l1_meas(const pcu_l1_meas *meas);
131 const pcu_l1_meas* l1_meas() const {return &m_l1_meas;};
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200132 unsigned nack_rate_dl() const;
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200133
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200134 /* internal use */
135 static void timeout(void *priv_);
136
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200137protected:
138 void update_status();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200139 GprsMs *ref();
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200140 void unref();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200141 void start_timer();
142 void stop_timer();
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100143 void update_cs_ul(const pcu_l1_meas*);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200144
145private:
Jacob Erlbeck17214bb2015-06-02 14:06:12 +0200146 BTS *m_bts;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200147 Callback * m_cb;
148 gprs_rlcmac_ul_tbf *m_ul_tbf;
149 gprs_rlcmac_dl_tbf *m_dl_tbf;
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200150 LListHead<gprs_rlcmac_tbf> m_old_tbfs;
151
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200152 uint32_t m_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200153 uint32_t m_new_ul_tlli;
154 uint32_t m_new_dl_tlli;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200155
156 /* store IMSI for look-up and PCH retransmission */
157 char m_imsi[16];
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200158 uint8_t m_ta;
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200159 uint8_t m_ms_class;
Jacob Erlbeckc3c58042015-09-28 17:55:32 +0200160 uint8_t m_egprs_ms_class;
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200161 /* current coding scheme */
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100162 GprsCodingScheme m_current_cs_ul;
163 GprsCodingScheme m_current_cs_dl;
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200164
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200165 gprs_llc_queue m_llc_queue;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200166
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200167 bool m_is_idle;
168 int m_ref;
Jacob Erlbeck53670862015-05-12 17:54:33 +0200169 LListHead<GprsMs> m_list;
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200170 struct osmo_timer_list m_timer;
171 unsigned m_delay;
Jacob Erlbeck8158ea72015-06-04 17:46:33 +0200172
173 int64_t m_last_cs_not_low;
Jacob Erlbecke4bcb622015-06-08 11:26:38 +0200174
175 pcu_l1_meas m_l1_meas;
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200176 unsigned m_nack_rate_dl;
Jacob Erlbeck23f93a12015-06-30 08:52:54 +0200177 uint8_t m_reserved_dl_slots;
178 uint8_t m_reserved_ul_slots;
179 gprs_rlcmac_trx *m_current_trx;
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200180
181 struct gprs_codel *m_codel_state;
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100182 GprsCodingScheme::Mode m_mode;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200183};
Jacob Erlbeck93990462015-05-15 15:50:43 +0200184
Jacob Erlbeck6835cea2015-08-21 15:24:02 +0200185inline bool GprsMs::is_idle() const
186{
187 return !m_ul_tbf && !m_dl_tbf && !m_ref && llist_empty(&m_old_tbfs);
188}
189
Jacob Erlbeckc8cbfc22015-09-01 11:38:40 +0200190inline bool GprsMs::need_dl_tbf() const
191{
192 if (dl_tbf() != NULL && dl_tbf()->state_is_not(GPRS_RLCMAC_WAIT_RELEASE))
193 return false;
194
195 return llc_queue()->size() > 0;
196}
197
Jacob Erlbeck93990462015-05-15 15:50:43 +0200198inline uint32_t GprsMs::tlli() const
199{
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200200 return m_new_ul_tlli ? m_new_ul_tlli :
201 m_tlli ? m_tlli :
202 m_new_dl_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200203}
204
205inline bool GprsMs::check_tlli(uint32_t tlli)
206{
207 return tlli != 0 &&
208 (tlli == m_tlli || tlli == m_new_ul_tlli || tlli == m_new_dl_tlli);
209}
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200210
211inline const char *GprsMs::imsi() const
212{
213 return m_imsi;
214}
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200215
216inline uint8_t GprsMs::ta() const
217{
218 return m_ta;
219}
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200220
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200221inline uint8_t GprsMs::ms_class() const
222{
223 return m_ms_class;
224}
225
Jacob Erlbeckc3c58042015-09-28 17:55:32 +0200226inline uint8_t GprsMs::egprs_ms_class() const
227{
228 return m_egprs_ms_class;
229}
230
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100231inline GprsCodingScheme GprsMs::current_cs_ul() const
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200232{
233 return m_current_cs_ul;
234}
235
Jacob Erlbeckcb728902016-01-05 15:33:03 +0100236inline GprsCodingScheme::Mode GprsMs::mode() const
237{
238 return m_mode;
239}
240
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200241inline void GprsMs::set_timeout(unsigned secs)
242{
243 m_delay = secs;
244}
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200245
246inline gprs_llc_queue *GprsMs::llc_queue()
247{
248 return &m_llc_queue;
249}
250
251inline const gprs_llc_queue *GprsMs::llc_queue() const
252{
253 return &m_llc_queue;
254}
255
Jacob Erlbeckd4ad7312015-07-17 16:39:09 +0200256inline gprs_codel *GprsMs::codel_state() const
257{
258 return m_codel_state;
259}
260
Jacob Erlbeck04a10862015-06-12 16:01:56 +0200261inline unsigned GprsMs::nack_rate_dl() const
262{
263 return m_nack_rate_dl;
264}
265
Jacob Erlbeck23f93a12015-06-30 08:52:54 +0200266inline uint8_t GprsMs::reserved_dl_slots() const
267{
268 return m_reserved_dl_slots;
269}
270
271inline uint8_t GprsMs::reserved_ul_slots() const
272{
273 return m_reserved_ul_slots;
274}
275
276inline gprs_rlcmac_trx *GprsMs::current_trx() const
277{
278 return m_current_trx;
279}