Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 1 | /* 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 |
| 25 | extern "C" { |
| 26 | #include <osmocom/core/linuxlist.h> |
| 27 | #include <osmocom/core/timer.h> |
| 28 | } |
Holger Hans Peter Freyther | b78adcd | 2013-10-17 20:12:37 +0200 | [diff] [blame] | 29 | |
| 30 | #include "poll_controller.h" |
Holger Hans Peter Freyther | cedf890 | 2013-10-19 20:47:12 +0200 | [diff] [blame] | 31 | #include "sba.h" |
Holger Hans Peter Freyther | 111614a | 2013-10-19 20:04:57 +0200 | [diff] [blame] | 32 | #include "ta.h" |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 33 | #include "tbf.h" |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | #include <stdint.h> |
| 37 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 38 | struct BTS; |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * PDCH instance |
| 42 | */ |
| 43 | struct gprs_rlcmac_pdch { |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 44 | #ifdef __cplusplus |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 45 | struct gprs_rlcmac_paging *dequeue_paging(); |
| 46 | struct msgb *packet_paging_request(); |
| 47 | |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 48 | void add_paging(struct gprs_rlcmac_paging *pag); |
Holger Hans Peter Freyther | 24e98d0 | 2013-10-19 18:15:44 +0200 | [diff] [blame] | 49 | |
Holger Hans Peter Freyther | 09ef27a | 2013-10-20 16:37:05 +0200 | [diff] [blame] | 50 | void free_resources(); |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 51 | |
| 52 | bool is_enabled() const; |
| 53 | |
| 54 | void enable(); |
| 55 | void disable(); |
Holger Hans Peter Freyther | 9ae367f | 2013-10-26 16:42:38 +0200 | [diff] [blame] | 56 | |
| 57 | /* dispatching of messages */ |
| 58 | int rcv_block(uint8_t *data, uint8_t len, uint32_t fn, int8_t rssi); |
Holger Hans Peter Freyther | 65be480 | 2013-10-26 18:39:36 +0200 | [diff] [blame] | 59 | |
| 60 | gprs_rlcmac_bts *bts_data() const; |
| 61 | BTS *bts() const; |
Holger Hans Peter Freyther | 05f8efc | 2013-10-26 18:53:16 +0200 | [diff] [blame] | 62 | uint8_t trx_no() const; |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 63 | #endif |
| 64 | |
| 65 | uint8_t m_is_enabled; /* TS is enabled */ |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 66 | uint8_t tsc; /* TSC of this slot */ |
| 67 | uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */ |
| 68 | uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */ |
| 69 | struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */ |
| 70 | struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */ |
| 71 | struct llist_head paging_list; /* list of paging messages */ |
| 72 | uint32_t last_rts_fn; /* store last frame number of RTS */ |
Holger Hans Peter Freyther | 4ed1dae | 2013-10-20 10:14:03 +0200 | [diff] [blame] | 73 | |
| 74 | /* back pointers */ |
| 75 | struct gprs_rlcmac_trx *trx; |
| 76 | uint8_t ts_no; |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 77 | |
| 78 | #ifdef __cplusplus |
| 79 | private: |
Holger Hans Peter Freyther | 05f8efc | 2013-10-26 18:53:16 +0200 | [diff] [blame] | 80 | int rcv_data_block_acknowledged(uint8_t *data, uint8_t len, int8_t rssi); |
| 81 | int rcv_control_block(bitvec *rlc_block, uint32_t fn); |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 82 | |
| 83 | #endif |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct gprs_rlcmac_trx { |
| 87 | void *fl1h; |
| 88 | uint16_t arfcn; |
| 89 | struct gprs_rlcmac_pdch pdch[8]; |
| 90 | struct gprs_rlcmac_tbf *ul_tbf[32]; /* array of UL TBF, by UL TFI */ |
| 91 | struct gprs_rlcmac_tbf *dl_tbf[32]; /* array of DL TBF, by DL TFI */ |
Holger Hans Peter Freyther | 4ed1dae | 2013-10-20 10:14:03 +0200 | [diff] [blame] | 92 | |
| 93 | /* back pointers */ |
| 94 | struct BTS *bts; |
| 95 | uint8_t trx_no; |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 98 | /** |
| 99 | * This is the data from C. As soon as our minimal compiler is gcc 4.7 |
| 100 | * we can start to compile pcu_vty.c with c++ and remove the split. |
| 101 | */ |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 102 | struct gprs_rlcmac_bts { |
| 103 | uint8_t bsic; |
| 104 | uint8_t fc_interval; |
| 105 | uint8_t cs1; |
| 106 | uint8_t cs2; |
| 107 | uint8_t cs3; |
| 108 | uint8_t cs4; |
| 109 | uint8_t initial_cs_dl, initial_cs_ul; |
| 110 | uint8_t force_cs; /* 0=use from BTS 1=use from VTY */ |
| 111 | uint16_t force_llc_lifetime; /* overrides lifetime from SGSN */ |
| 112 | uint8_t t3142; |
| 113 | uint8_t t3169; |
| 114 | uint8_t t3191; |
| 115 | uint16_t t3193_msec; |
| 116 | uint8_t t3195; |
| 117 | uint8_t n3101; |
| 118 | uint8_t n3103; |
| 119 | uint8_t n3105; |
| 120 | struct gprs_rlcmac_trx trx[8]; |
| 121 | int (*alloc_algorithm)(struct gprs_rlcmac_bts *bts, |
| 122 | struct gprs_rlcmac_tbf *old_tbf, |
| 123 | struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single); |
| 124 | uint32_t alloc_algorithm_curst; /* options to customize algorithm */ |
| 125 | uint8_t force_two_phase; |
| 126 | uint8_t alpha, gamma; |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 127 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 128 | /* TBF handling, make private or move into TBFController */ |
| 129 | /* list of uplink TBFs */ |
| 130 | struct llist_head ul_tbfs; |
| 131 | /* list of downlink TBFs */ |
| 132 | struct llist_head dl_tbfs; |
| 133 | |
| 134 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 135 | /** |
| 136 | * Point back to the C++ object. This is used during the transition |
| 137 | * period. |
| 138 | */ |
| 139 | struct BTS *bts; |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 140 | }; |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 141 | |
| 142 | #ifdef __cplusplus |
| 143 | /** |
| 144 | * I represent a GSM BTS. I have one or more TRX, I know the current |
| 145 | * GSM time and I have controllers that help with allocating resources |
| 146 | * on my TRXs. |
| 147 | */ |
| 148 | struct BTS { |
| 149 | public: |
| 150 | BTS(); |
| 151 | |
| 152 | static BTS* main_bts(); |
| 153 | |
| 154 | struct gprs_rlcmac_bts *bts_data(); |
Holger Hans Peter Freyther | cedf890 | 2013-10-19 20:47:12 +0200 | [diff] [blame] | 155 | SBAController *sba(); |
Holger Hans Peter Freyther | 111614a | 2013-10-19 20:04:57 +0200 | [diff] [blame] | 156 | TimingAdvance *timing_advance(); |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 157 | |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 158 | /** TODO: change the number to unsigned */ |
| 159 | void set_current_frame_number(int frame_number); |
| 160 | int current_frame_number() const; |
| 161 | |
Holger Hans Peter Freyther | f098489 | 2013-10-19 18:28:59 +0200 | [diff] [blame] | 162 | /** add paging to paging queue(s) */ |
| 163 | int add_paging(uint8_t chan_needed, uint8_t *identity_lv); |
| 164 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 165 | gprs_rlcmac_tbf *tbf_by_tlli(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir); |
| 166 | gprs_rlcmac_tbf *tbf_by_poll_fn(uint32_t fn, uint8_t trx, uint8_t ts); |
Holger Hans Peter Freyther | f63cabd | 2013-10-26 19:10:43 +0200 | [diff] [blame^] | 167 | gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, uint8_t trx, enum gprs_rlcmac_tbf_direction dir); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 168 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 169 | private: |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 170 | int m_cur_fn; |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 171 | struct gprs_rlcmac_bts m_bts; |
Holger Hans Peter Freyther | b78adcd | 2013-10-17 20:12:37 +0200 | [diff] [blame] | 172 | PollController m_pollController; |
Holger Hans Peter Freyther | cedf890 | 2013-10-19 20:47:12 +0200 | [diff] [blame] | 173 | SBAController m_sba; |
Holger Hans Peter Freyther | 111614a | 2013-10-19 20:04:57 +0200 | [diff] [blame] | 174 | TimingAdvance m_ta; |
Holger Hans Peter Freyther | b78adcd | 2013-10-17 20:12:37 +0200 | [diff] [blame] | 175 | |
| 176 | private: |
| 177 | /* disable copying to avoid slicing */ |
| 178 | BTS(const BTS&); |
| 179 | BTS& operator=(const BTS&); |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 180 | }; |
Holger Hans Peter Freyther | 9b30c7f | 2013-10-17 19:59:56 +0200 | [diff] [blame] | 181 | |
| 182 | inline int BTS::current_frame_number() const |
| 183 | { |
| 184 | return m_cur_fn; |
| 185 | } |
Holger Hans Peter Freyther | 111614a | 2013-10-19 20:04:57 +0200 | [diff] [blame] | 186 | |
| 187 | inline TimingAdvance *BTS::timing_advance() |
| 188 | { |
| 189 | return &m_ta; |
| 190 | } |
Holger Hans Peter Freyther | cedf890 | 2013-10-19 20:47:12 +0200 | [diff] [blame] | 191 | |
| 192 | inline SBAController *BTS::sba() |
| 193 | { |
| 194 | return &m_sba; |
| 195 | } |
Holger Hans Peter Freyther | 65be480 | 2013-10-26 18:39:36 +0200 | [diff] [blame] | 196 | |
| 197 | inline BTS *gprs_rlcmac_pdch::bts() const |
| 198 | { |
| 199 | return trx->bts; |
| 200 | } |
| 201 | |
| 202 | inline gprs_rlcmac_bts *gprs_rlcmac_pdch::bts_data() const |
| 203 | { |
| 204 | return trx->bts->bts_data(); |
| 205 | } |
Holger Hans Peter Freyther | 05f8efc | 2013-10-26 18:53:16 +0200 | [diff] [blame] | 206 | |
| 207 | inline uint8_t gprs_rlcmac_pdch::trx_no() const |
| 208 | { |
| 209 | return trx->trx_no; |
| 210 | } |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 211 | #endif |
| 212 | |
| 213 | #ifdef __cplusplus |
| 214 | extern "C" { |
| 215 | #endif |
| 216 | struct gprs_rlcmac_bts *bts_main_data(); |
| 217 | #ifdef __cplusplus |
| 218 | } |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 219 | |
| 220 | inline bool gprs_rlcmac_pdch::is_enabled() const |
| 221 | { |
| 222 | return m_is_enabled; |
| 223 | } |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 224 | #endif |