blob: 90b81fee283efce90bb5d83b5f2592d685cfd047 [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;
26
Jacob Erlbeck53670862015-05-12 17:54:33 +020027#include "cxx_linuxlist.h"
Jacob Erlbeck489a2b32015-05-28 19:07:01 +020028#include "llc.h"
Jacob Erlbeckd9e10242015-05-28 15:43:53 +020029
30extern "C" {
31 #include <osmocom/core/timer.h>
32}
33
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020034#include <stdint.h>
35#include <stddef.h>
36
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020037struct BTS;
38
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020039class GprsMs {
40public:
41 struct Callback {
42 virtual void ms_idle(class GprsMs *) = 0;
43 virtual void ms_active(class GprsMs *) = 0;
44 };
45
46 class Guard {
47 public:
48 Guard(GprsMs *ms);
49 ~Guard();
50
51 private:
52 GprsMs * const m_ms;
53 };
54
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020055 GprsMs(BTS *bts, uint32_t tlli);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020056 ~GprsMs();
57
58 void set_callback(Callback *cb) {m_cb = cb;}
59
60 gprs_rlcmac_ul_tbf *ul_tbf() const {return m_ul_tbf;}
61 gprs_rlcmac_dl_tbf *dl_tbf() const {return m_dl_tbf;}
Jacob Erlbeck93990462015-05-15 15:50:43 +020062 uint32_t tlli() const;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020063 void set_tlli(uint32_t tlli);
Jacob Erlbeck93990462015-05-15 15:50:43 +020064 bool confirm_tlli(uint32_t tlli);
65 bool check_tlli(uint32_t tlli);
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020066
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +020067 const char *imsi() const;
68 void set_imsi(const char *imsi);
69
Jacob Erlbeck9200ce62015-05-22 17:48:04 +020070 uint8_t ta() const;
71 void set_ta(uint8_t ta);
Jacob Erlbeckbefc7602015-06-02 12:33:30 +020072 uint8_t ms_class() const;
73 void set_ms_class(uint8_t ms_class);
Jacob Erlbeck9200ce62015-05-22 17:48:04 +020074
Jacob Erlbecka700dd92015-06-02 16:00:41 +020075 uint8_t current_cs_ul() const;
76 uint8_t current_cs_dl() const;
77
Jacob Erlbeck489a2b32015-05-28 19:07:01 +020078 gprs_llc_queue *llc_queue();
79 const gprs_llc_queue *llc_queue() const;
80
Jacob Erlbeckd9e10242015-05-28 15:43:53 +020081 void set_timeout(unsigned secs);
82
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020083 void attach_tbf(gprs_rlcmac_tbf *tbf);
84 void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf);
85 void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf);
86
87 void detach_tbf(gprs_rlcmac_tbf *tbf);
88
Jacob Erlbeck1751c622015-06-04 12:12:32 +020089 void update_error_rate(gprs_rlcmac_tbf *tbf, int percent);
90
Jacob Erlbecke04e0b02015-05-06 18:30:48 +020091 bool is_idle() const {return !m_ul_tbf && !m_dl_tbf && !m_ref;}
92
93 void* operator new(size_t num);
94 void operator delete(void* p);
95
Jacob Erlbeck53670862015-05-12 17:54:33 +020096 LListHead<GprsMs>& list() {return this->m_list;}
97 const LListHead<GprsMs>& list() const {return this->m_list;}
98
Jacob Erlbeckd9e10242015-05-28 15:43:53 +020099 /* internal use */
100 static void timeout(void *priv_);
101
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200102protected:
103 void update_status();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200104 GprsMs *ref();
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200105 void unref();
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200106 void start_timer();
107 void stop_timer();
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200108
109private:
Jacob Erlbeck17214bb2015-06-02 14:06:12 +0200110 BTS *m_bts;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200111 Callback * m_cb;
112 gprs_rlcmac_ul_tbf *m_ul_tbf;
113 gprs_rlcmac_dl_tbf *m_dl_tbf;
114 uint32_t m_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200115 uint32_t m_new_ul_tlli;
116 uint32_t m_new_dl_tlli;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200117
118 /* store IMSI for look-up and PCH retransmission */
119 char m_imsi[16];
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200120 uint8_t m_ta;
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200121 uint8_t m_ms_class;
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200122 /* current coding scheme */
123 uint8_t m_current_cs_ul;
124 uint8_t m_current_cs_dl;
125
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200126 gprs_llc_queue m_llc_queue;
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200127
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200128 bool m_is_idle;
129 int m_ref;
Jacob Erlbeck53670862015-05-12 17:54:33 +0200130 LListHead<GprsMs> m_list;
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200131 struct osmo_timer_list m_timer;
132 unsigned m_delay;
Jacob Erlbeck8158ea72015-06-04 17:46:33 +0200133
134 int64_t m_last_cs_not_low;
Jacob Erlbecke04e0b02015-05-06 18:30:48 +0200135};
Jacob Erlbeck93990462015-05-15 15:50:43 +0200136
137inline uint32_t GprsMs::tlli() const
138{
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200139 return m_new_ul_tlli ? m_new_ul_tlli :
140 m_tlli ? m_tlli :
141 m_new_dl_tlli;
Jacob Erlbeck93990462015-05-15 15:50:43 +0200142}
143
144inline bool GprsMs::check_tlli(uint32_t tlli)
145{
146 return tlli != 0 &&
147 (tlli == m_tlli || tlli == m_new_ul_tlli || tlli == m_new_dl_tlli);
148}
Jacob Erlbeckb0e5eaf2015-05-21 11:07:16 +0200149
150inline const char *GprsMs::imsi() const
151{
152 return m_imsi;
153}
Jacob Erlbeck9200ce62015-05-22 17:48:04 +0200154
155inline uint8_t GprsMs::ta() const
156{
157 return m_ta;
158}
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200159
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200160inline uint8_t GprsMs::ms_class() const
161{
162 return m_ms_class;
163}
164
Jacob Erlbecka700dd92015-06-02 16:00:41 +0200165inline uint8_t GprsMs::current_cs_dl() const
166{
167 return m_current_cs_dl;
168}
169
170inline uint8_t GprsMs::current_cs_ul() const
171{
172 return m_current_cs_ul;
173}
174
Jacob Erlbeckd9e10242015-05-28 15:43:53 +0200175inline void GprsMs::set_timeout(unsigned secs)
176{
177 m_delay = secs;
178}
Jacob Erlbeck489a2b32015-05-28 19:07:01 +0200179
180inline gprs_llc_queue *GprsMs::llc_queue()
181{
182 return &m_llc_queue;
183}
184
185inline const gprs_llc_queue *GprsMs::llc_queue() const
186{
187 return &m_llc_queue;
188}
189