Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 1 | /* 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 | |
| 23 | struct gprs_rlcmac_tbf; |
| 24 | struct gprs_rlcmac_dl_tbf; |
| 25 | struct gprs_rlcmac_ul_tbf; |
| 26 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 27 | #include "cxx_linuxlist.h" |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 28 | #include "llc.h" |
Jacob Erlbeck | e4bcb62 | 2015-06-08 11:26:38 +0200 | [diff] [blame] | 29 | #include "pcu_l1_if.h" |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 30 | |
| 31 | extern "C" { |
| 32 | #include <osmocom/core/timer.h> |
| 33 | } |
| 34 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 35 | #include <stdint.h> |
| 36 | #include <stddef.h> |
| 37 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 38 | struct BTS; |
| 39 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 40 | class GprsMs { |
| 41 | public: |
| 42 | struct Callback { |
| 43 | virtual void ms_idle(class GprsMs *) = 0; |
| 44 | virtual void ms_active(class GprsMs *) = 0; |
| 45 | }; |
| 46 | |
| 47 | class Guard { |
| 48 | public: |
| 49 | Guard(GprsMs *ms); |
| 50 | ~Guard(); |
| 51 | |
| 52 | private: |
| 53 | GprsMs * const m_ms; |
| 54 | }; |
| 55 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 56 | GprsMs(BTS *bts, uint32_t tlli); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 57 | ~GprsMs(); |
| 58 | |
| 59 | void set_callback(Callback *cb) {m_cb = cb;} |
| 60 | |
| 61 | gprs_rlcmac_ul_tbf *ul_tbf() const {return m_ul_tbf;} |
| 62 | gprs_rlcmac_dl_tbf *dl_tbf() const {return m_dl_tbf;} |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 63 | uint32_t tlli() const; |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 64 | void set_tlli(uint32_t tlli); |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 65 | bool confirm_tlli(uint32_t tlli); |
| 66 | bool check_tlli(uint32_t tlli); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 67 | |
Jacob Erlbeck | b0e5eaf | 2015-05-21 11:07:16 +0200 | [diff] [blame] | 68 | const char *imsi() const; |
| 69 | void set_imsi(const char *imsi); |
| 70 | |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 71 | uint8_t ta() const; |
| 72 | void set_ta(uint8_t ta); |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 73 | uint8_t ms_class() const; |
| 74 | void set_ms_class(uint8_t ms_class); |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 75 | |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 76 | uint8_t current_cs_ul() const; |
| 77 | uint8_t current_cs_dl() const; |
| 78 | |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 79 | gprs_llc_queue *llc_queue(); |
| 80 | const gprs_llc_queue *llc_queue() const; |
| 81 | |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 82 | void set_timeout(unsigned secs); |
| 83 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 84 | void attach_tbf(gprs_rlcmac_tbf *tbf); |
| 85 | void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf); |
| 86 | void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf); |
| 87 | |
| 88 | void detach_tbf(gprs_rlcmac_tbf *tbf); |
| 89 | |
Jacob Erlbeck | 1751c62 | 2015-06-04 12:12:32 +0200 | [diff] [blame] | 90 | void update_error_rate(gprs_rlcmac_tbf *tbf, int percent); |
| 91 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 92 | bool is_idle() const {return !m_ul_tbf && !m_dl_tbf && !m_ref;} |
| 93 | |
| 94 | void* operator new(size_t num); |
| 95 | void operator delete(void* p); |
| 96 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 97 | LListHead<GprsMs>& list() {return this->m_list;} |
| 98 | const LListHead<GprsMs>& list() const {return this->m_list;} |
| 99 | |
Jacob Erlbeck | e4bcb62 | 2015-06-08 11:26:38 +0200 | [diff] [blame] | 100 | void update_l1_meas(const pcu_l1_meas *meas); |
| 101 | const pcu_l1_meas* l1_meas() const {return &m_l1_meas;}; |
Jacob Erlbeck | 04a1086 | 2015-06-12 16:01:56 +0200 | [diff] [blame] | 102 | unsigned nack_rate_dl() const; |
Jacob Erlbeck | e4bcb62 | 2015-06-08 11:26:38 +0200 | [diff] [blame] | 103 | |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 104 | /* internal use */ |
| 105 | static void timeout(void *priv_); |
| 106 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 107 | protected: |
| 108 | void update_status(); |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 109 | GprsMs *ref(); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 110 | void unref(); |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 111 | void start_timer(); |
| 112 | void stop_timer(); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 113 | |
| 114 | private: |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 115 | BTS *m_bts; |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 116 | Callback * m_cb; |
| 117 | gprs_rlcmac_ul_tbf *m_ul_tbf; |
| 118 | gprs_rlcmac_dl_tbf *m_dl_tbf; |
| 119 | uint32_t m_tlli; |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 120 | uint32_t m_new_ul_tlli; |
| 121 | uint32_t m_new_dl_tlli; |
Jacob Erlbeck | b0e5eaf | 2015-05-21 11:07:16 +0200 | [diff] [blame] | 122 | |
| 123 | /* store IMSI for look-up and PCH retransmission */ |
| 124 | char m_imsi[16]; |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 125 | uint8_t m_ta; |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 126 | uint8_t m_ms_class; |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 127 | /* current coding scheme */ |
| 128 | uint8_t m_current_cs_ul; |
| 129 | uint8_t m_current_cs_dl; |
| 130 | |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 131 | gprs_llc_queue m_llc_queue; |
Jacob Erlbeck | b0e5eaf | 2015-05-21 11:07:16 +0200 | [diff] [blame] | 132 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 133 | bool m_is_idle; |
| 134 | int m_ref; |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 135 | LListHead<GprsMs> m_list; |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 136 | struct osmo_timer_list m_timer; |
| 137 | unsigned m_delay; |
Jacob Erlbeck | 8158ea7 | 2015-06-04 17:46:33 +0200 | [diff] [blame] | 138 | |
| 139 | int64_t m_last_cs_not_low; |
Jacob Erlbeck | e4bcb62 | 2015-06-08 11:26:38 +0200 | [diff] [blame] | 140 | |
| 141 | pcu_l1_meas m_l1_meas; |
Jacob Erlbeck | 04a1086 | 2015-06-12 16:01:56 +0200 | [diff] [blame] | 142 | unsigned m_nack_rate_dl; |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 143 | }; |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 144 | |
| 145 | inline uint32_t GprsMs::tlli() const |
| 146 | { |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 147 | return m_new_ul_tlli ? m_new_ul_tlli : |
| 148 | m_tlli ? m_tlli : |
| 149 | m_new_dl_tlli; |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | inline bool GprsMs::check_tlli(uint32_t tlli) |
| 153 | { |
| 154 | return tlli != 0 && |
| 155 | (tlli == m_tlli || tlli == m_new_ul_tlli || tlli == m_new_dl_tlli); |
| 156 | } |
Jacob Erlbeck | b0e5eaf | 2015-05-21 11:07:16 +0200 | [diff] [blame] | 157 | |
| 158 | inline const char *GprsMs::imsi() const |
| 159 | { |
| 160 | return m_imsi; |
| 161 | } |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 162 | |
| 163 | inline uint8_t GprsMs::ta() const |
| 164 | { |
| 165 | return m_ta; |
| 166 | } |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 167 | |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 168 | inline uint8_t GprsMs::ms_class() const |
| 169 | { |
| 170 | return m_ms_class; |
| 171 | } |
| 172 | |
Jacob Erlbeck | a700dd9 | 2015-06-02 16:00:41 +0200 | [diff] [blame] | 173 | inline uint8_t GprsMs::current_cs_ul() const |
| 174 | { |
| 175 | return m_current_cs_ul; |
| 176 | } |
| 177 | |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 178 | inline void GprsMs::set_timeout(unsigned secs) |
| 179 | { |
| 180 | m_delay = secs; |
| 181 | } |
Jacob Erlbeck | 489a2b3 | 2015-05-28 19:07:01 +0200 | [diff] [blame] | 182 | |
| 183 | inline gprs_llc_queue *GprsMs::llc_queue() |
| 184 | { |
| 185 | return &m_llc_queue; |
| 186 | } |
| 187 | |
| 188 | inline const gprs_llc_queue *GprsMs::llc_queue() const |
| 189 | { |
| 190 | return &m_llc_queue; |
| 191 | } |
| 192 | |
Jacob Erlbeck | 04a1086 | 2015-06-12 16:01:56 +0200 | [diff] [blame] | 193 | inline unsigned GprsMs::nack_rate_dl() const |
| 194 | { |
| 195 | return m_nack_rate_dl; |
| 196 | } |
| 197 | |