Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 1 | /* Copied from gprs_bssgp_pcu.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 4 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 5 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 22 | #include <bts.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 23 | #include <tbf.h> |
Holger Hans Peter Freyther | d11290b | 2013-10-26 17:32:04 +0200 | [diff] [blame] | 24 | #include <rlc.h> |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 25 | #include <encoding.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 26 | #include <gprs_rlcmac.h> |
| 27 | #include <gprs_debug.h> |
Holger Hans Peter Freyther | 3dc56a3 | 2013-10-26 21:38:30 +0200 | [diff] [blame] | 28 | #include <gprs_bssgp_pcu.h> |
Holger Hans Peter Freyther | 77e0597 | 2013-11-06 19:16:43 +0100 | [diff] [blame] | 29 | #include <decoding.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 30 | |
| 31 | extern "C" { |
| 32 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 33 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | #include <errno.h> |
| 37 | #include <string.h> |
| 38 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 39 | extern void *tall_pcu_ctx; |
| 40 | |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 41 | static void tbf_timer_cb(void *_tbf); |
| 42 | |
Daniel Willmann | ca102af | 2014-08-08 12:14:12 +0200 | [diff] [blame] | 43 | gprs_rlcmac_bts *gprs_rlcmac_tbf::bts_data() const |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 44 | { |
| 45 | return bts->bts_data(); |
| 46 | } |
| 47 | |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 48 | void gprs_rlcmac_tbf::assign_imsi(const char *imsi) |
Holger Hans Peter Freyther | d868928 | 2013-08-24 20:51:06 +0200 | [diff] [blame] | 49 | { |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 50 | strncpy(m_imsi, imsi, sizeof(m_imsi)); |
| 51 | m_imsi[sizeof(m_imsi) - 1] = '\0'; |
Holger Hans Peter Freyther | d868928 | 2013-08-24 20:51:06 +0200 | [diff] [blame] | 52 | } |
| 53 | |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 54 | void gprs_rlcmac_tbf::set_new_tbf(gprs_rlcmac_tbf *tbf) |
| 55 | { |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 56 | if (m_new_tbf) { |
| 57 | if (m_new_tbf == tbf) { |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 58 | LOGP(DRLCMAC, LOGL_INFO, |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 59 | "%s reassigning %s to m_new_tbf\n", |
| 60 | tbf_name(this), tbf_name(tbf)); |
| 61 | return; |
| 62 | } |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 63 | if (m_new_tbf != this) |
| 64 | LOGP(DRLCMAC, LOGL_NOTICE, |
| 65 | "%s m_new_tbf is already assigned to %s, " |
| 66 | "overwriting the old value with %s\n", |
| 67 | tbf_name(this), tbf_name(m_new_tbf), tbf_name(tbf)); |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 68 | /* Detach from other TBF */ |
| 69 | m_new_tbf->m_old_tbf = NULL; |
| 70 | } |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 71 | m_new_tbf = tbf; |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 72 | tbf->m_old_tbf = this; |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Daniel Willmann | 0d12a2f | 2014-07-10 17:44:07 +0200 | [diff] [blame] | 75 | gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts, |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 76 | int8_t use_trx, uint8_t ms_class, |
| 77 | uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf) |
| 78 | { |
| 79 | uint8_t trx; |
Daniel Willmann | 0d12a2f | 2014-07-10 17:44:07 +0200 | [diff] [blame] | 80 | struct gprs_rlcmac_ul_tbf *tbf; |
Holger Hans Peter Freyther | 5697b4c | 2013-11-11 16:22:39 +0100 | [diff] [blame] | 81 | int8_t tfi; /* must be signed */ |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 82 | |
| 83 | #warning "Copy and paste with tbf_new_dl_assignment" |
Holger Hans Peter Freyther | ba26368 | 2013-12-25 19:15:57 +0100 | [diff] [blame] | 84 | /* create new TBF, use same TRX as DL TBF */ |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 85 | tfi = bts->bts->tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx, use_trx); |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 86 | if (tfi < 0) { |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 87 | LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n"); |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 88 | /* FIXME: send reject */ |
| 89 | return NULL; |
| 90 | } |
| 91 | /* use multislot class of downlink TBF */ |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 92 | tbf = tbf_alloc_ul_tbf(bts, dl_tbf, tfi, trx, ms_class, 0); |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 93 | if (!tbf) { |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 94 | LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n"); |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 95 | /* FIXME: send reject */ |
| 96 | return NULL; |
| 97 | } |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 98 | tbf->m_tlli = tlli; |
| 99 | tbf->m_tlli_valid = 1; /* no contention resolution */ |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 100 | tbf->m_contention_resolution_done = 1; |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 101 | tbf->ta = ta; /* use current TA */ |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 102 | tbf->set_state(GPRS_RLCMAC_ASSIGN); |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 103 | tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_PACCH); |
| 104 | tbf_timer_start(tbf, 3169, bts->t3169, 0); |
| 105 | |
| 106 | return tbf; |
| 107 | } |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 108 | |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 109 | static void tbf_unlink_pdch(struct gprs_rlcmac_tbf *tbf) |
| 110 | { |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 111 | int ts; |
| 112 | |
| 113 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) { |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 114 | tbf->trx->ul_tbf[tbf->tfi()] = NULL; |
Daniel Willmann | 17a1d5e | 2014-05-30 20:21:30 +0200 | [diff] [blame] | 115 | for (ts = 0; ts < 8; ts++) |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 116 | tbf->pdch[ts] = NULL; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 117 | } else { |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 118 | tbf->trx->dl_tbf[tbf->tfi()] = NULL; |
Daniel Willmann | 17a1d5e | 2014-05-30 20:21:30 +0200 | [diff] [blame] | 119 | for (ts = 0; ts < 8; ts++) |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 120 | tbf->pdch[ts] = NULL; |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | void tbf_free(struct gprs_rlcmac_tbf *tbf) |
| 125 | { |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 126 | /* Give final measurement report */ |
| 127 | gprs_rlcmac_rssi_rep(tbf); |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 128 | if (tbf->direction == GPRS_RLCMAC_DL_TBF) { |
| 129 | gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(tbf); |
| 130 | gprs_rlcmac_lost_rep(dl_tbf); |
Jacob Erlbeck | d0261b7 | 2015-04-02 13:58:09 +0200 | [diff] [blame] | 131 | dl_tbf->cleanup(); |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 132 | } |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 133 | |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 134 | LOGP(DRLCMAC, LOGL_INFO, "%s free\n", tbf_name(tbf)); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 135 | if (tbf->ul_ass_state != GPRS_RLCMAC_UL_ASS_NONE) |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 136 | LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending uplink " |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 137 | "assignment. This may not happen, because the " |
| 138 | "assignment message never gets transmitted. Please " |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 139 | "be sure not to free in this state. PLEASE FIX!\n", |
| 140 | tbf_name(tbf)); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 141 | if (tbf->dl_ass_state != GPRS_RLCMAC_DL_ASS_NONE) |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 142 | LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: Pending downlink " |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 143 | "assignment. This may not happen, because the " |
| 144 | "assignment message never gets transmitted. Please " |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 145 | "be sure not to free in this state. PLEASE FIX!\n", |
| 146 | tbf_name(tbf)); |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 147 | tbf->stop_timer(); |
Holger Hans Peter Freyther | 782f6dd | 2013-10-26 18:31:51 +0200 | [diff] [blame] | 148 | #warning "TODO: Could/Should generate bssgp_tx_llc_discarded" |
Holger Hans Peter Freyther | 758dc12 | 2013-11-06 20:39:45 +0100 | [diff] [blame] | 149 | tbf->m_llc.clear(tbf->bts); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 150 | tbf_unlink_pdch(tbf); |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 151 | llist_del(&tbf->list.list); |
Holger Hans Peter Freyther | 1587764 | 2013-10-27 09:50:15 +0100 | [diff] [blame] | 152 | |
| 153 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) |
| 154 | tbf->bts->tbf_ul_freed(); |
| 155 | else |
| 156 | tbf->bts->tbf_dl_freed(); |
| 157 | |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 158 | if (tbf->m_old_tbf) { |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 159 | if (tbf->m_old_tbf == tbf) { |
| 160 | /* points to itself, ignore */ |
| 161 | } else if (tbf->m_old_tbf->m_new_tbf == tbf) { |
| 162 | LOGP(DRLCMAC, LOGL_INFO, |
| 163 | "%s Old TBF %s still exists, detaching\n", |
| 164 | tbf_name(tbf), tbf_name(tbf->m_old_tbf)); |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 165 | tbf->m_old_tbf->m_new_tbf = NULL; |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 166 | } else { |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 167 | LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: " |
| 168 | "tbf->m_old_tbf->m_new_tbf != tbf\n", |
| 169 | tbf_name(tbf)); |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 170 | } |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (tbf->m_new_tbf) { |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 174 | if (tbf->m_new_tbf == tbf) { |
| 175 | /* points to itself, ignore */ |
| 176 | } else if (tbf->m_new_tbf->m_old_tbf == tbf) { |
| 177 | LOGP(DRLCMAC, LOGL_INFO, |
| 178 | "%s New TBF %s still exists, detaching\n", |
| 179 | tbf_name(tbf), tbf_name(tbf->m_new_tbf)); |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 180 | tbf->m_new_tbf->m_old_tbf = NULL; |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 181 | } else { |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 182 | LOGP(DRLCMAC, LOGL_ERROR, "%s Software error: " |
| 183 | "tbf->m_new_tbf->m_old_tbf != tbf\n", |
| 184 | tbf_name(tbf)); |
Jacob Erlbeck | 1842c92 | 2015-03-02 13:01:35 +0100 | [diff] [blame] | 185 | } |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 188 | LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF ends here **********\n"); |
| 189 | talloc_free(tbf); |
| 190 | } |
| 191 | |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 192 | int gprs_rlcmac_tbf::update() |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 193 | { |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 194 | struct gprs_rlcmac_tbf *ul_tbf = NULL; |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 195 | struct gprs_rlcmac_bts *bts_data = bts->bts_data(); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 196 | int rc; |
| 197 | |
| 198 | LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF update **********\n"); |
| 199 | |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 200 | if (direction != GPRS_RLCMAC_DL_TBF) |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 201 | return -EINVAL; |
| 202 | |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 203 | ul_tbf = bts->ul_tbf_by_tlli(m_tlli); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 204 | |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 205 | tbf_unlink_pdch(this); |
| 206 | rc = bts_data->alloc_algorithm(bts_data, ul_tbf, this, bts_data->alloc_algorithm_curst, 0); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 207 | /* if no resource */ |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 208 | if (rc < 0) { |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 209 | LOGP(DRLCMAC, LOGL_ERROR, "No resource after update???\n"); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 210 | return -rc; |
| 211 | } |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf) |
| 217 | { |
| 218 | if (tbf->control_ts == 0xff) |
| 219 | LOGP(DRLCMAC, LOGL_INFO, "- Setting Control TS %d\n", |
| 220 | tbf->first_common_ts); |
| 221 | else if (tbf->control_ts != tbf->first_common_ts) |
| 222 | LOGP(DRLCMAC, LOGL_INFO, "- Changing Control TS %d\n", |
| 223 | tbf->first_common_ts); |
| 224 | tbf->control_ts = tbf->first_common_ts; |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 229 | const char *gprs_rlcmac_tbf::tbf_state_name[] = { |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 230 | "NULL", |
| 231 | "ASSIGN", |
| 232 | "FLOW", |
| 233 | "FINISHED", |
| 234 | "WAIT RELEASE", |
| 235 | "RELEASING", |
| 236 | }; |
| 237 | |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 238 | void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T, |
| 239 | unsigned int seconds, unsigned int microseconds) |
| 240 | { |
| 241 | if (!osmo_timer_pending(&tbf->timer)) |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 242 | LOGP(DRLCMAC, LOGL_DEBUG, "%s starting timer %u.\n", |
| 243 | tbf_name(tbf), T); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 244 | else |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 245 | LOGP(DRLCMAC, LOGL_DEBUG, "%s restarting timer %u " |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 246 | "while old timer %u pending \n", |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 247 | tbf_name(tbf), T, tbf->T); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 248 | |
| 249 | tbf->T = T; |
| 250 | tbf->num_T_exp = 0; |
| 251 | |
| 252 | /* Tunning timers can be safely re-scheduled. */ |
| 253 | tbf->timer.data = tbf; |
| 254 | tbf->timer.cb = &tbf_timer_cb; |
| 255 | |
| 256 | osmo_timer_schedule(&tbf->timer, seconds, microseconds); |
| 257 | } |
| 258 | |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 259 | void gprs_rlcmac_tbf::stop_t3191() |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 260 | { |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 261 | return stop_timer(); |
| 262 | } |
| 263 | |
| 264 | void gprs_rlcmac_tbf::stop_timer() |
| 265 | { |
| 266 | if (osmo_timer_pending(&timer)) { |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 267 | LOGP(DRLCMAC, LOGL_DEBUG, "%s stopping timer %u.\n", |
| 268 | tbf_name(this), T); |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 269 | osmo_timer_del(&timer); |
Holger Hans Peter Freyther | 4556130 | 2013-10-16 17:55:57 +0200 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 273 | void gprs_rlcmac_tbf::poll_timeout() |
| 274 | { |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 275 | LOGP(DRLCMAC, LOGL_NOTICE, "%s poll timeout\n", |
| 276 | tbf_name(this)); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 277 | |
| 278 | poll_state = GPRS_RLCMAC_POLL_NONE; |
| 279 | |
| 280 | if (ul_ack_state == GPRS_RLCMAC_UL_ACK_WAIT_ACK) { |
| 281 | if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK))) { |
| 282 | LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling " |
| 283 | "PACKET CONTROL ACK for PACKET UPLINK ACK\n"); |
| 284 | rlcmac_diag(); |
| 285 | state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ACK); |
| 286 | } |
| 287 | ul_ack_state = GPRS_RLCMAC_UL_ACK_NONE; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 288 | if (state_is(GPRS_RLCMAC_FINISHED)) { |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 289 | gprs_rlcmac_ul_tbf *ul_tbf = static_cast<gprs_rlcmac_ul_tbf *>(this); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 290 | ul_tbf->m_n3103++; |
| 291 | if (ul_tbf->m_n3103 == ul_tbf->bts->bts_data()->n3103) { |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 292 | LOGP(DRLCMAC, LOGL_NOTICE, |
| 293 | "- N3103 exceeded\n"); |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 294 | ul_tbf->set_state(GPRS_RLCMAC_RELEASING); |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 295 | tbf_timer_start(ul_tbf, 3169, ul_tbf->bts->bts_data()->t3169, 0); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | /* reschedule UL ack */ |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 299 | ul_tbf->ul_ack_state = GPRS_RLCMAC_UL_ACK_SEND_ACK; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 300 | } |
| 301 | } else if (ul_ass_state == GPRS_RLCMAC_UL_ASS_WAIT_ACK) { |
| 302 | if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS))) { |
| 303 | LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling " |
| 304 | "PACKET CONTROL ACK for PACKET UPLINK " |
| 305 | "ASSIGNMENT.\n"); |
| 306 | rlcmac_diag(); |
| 307 | state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_UL_ASS); |
| 308 | } |
| 309 | ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 310 | n3105++; |
| 311 | if (n3105 == bts_data()->n3105) { |
| 312 | LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n"); |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 313 | set_state(GPRS_RLCMAC_RELEASING); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 314 | tbf_timer_start(this, 3195, bts_data()->t3195, 0); |
| 315 | return; |
| 316 | } |
| 317 | /* reschedule UL assignment */ |
| 318 | ul_ass_state = GPRS_RLCMAC_UL_ASS_SEND_ASS; |
| 319 | } else if (dl_ass_state == GPRS_RLCMAC_DL_ASS_WAIT_ACK) { |
| 320 | if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS))) { |
| 321 | LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling " |
| 322 | "PACKET CONTROL ACK for PACKET DOWNLINK " |
| 323 | "ASSIGNMENT.\n"); |
| 324 | rlcmac_diag(); |
| 325 | state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ASS); |
| 326 | } |
| 327 | dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 328 | n3105++; |
| 329 | if (n3105 == bts->bts_data()->n3105) { |
| 330 | LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n"); |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 331 | set_state(GPRS_RLCMAC_RELEASING); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 332 | tbf_timer_start(this, 3195, bts_data()->t3195, 0); |
| 333 | return; |
| 334 | } |
| 335 | /* reschedule DL assignment */ |
| 336 | dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS; |
| 337 | } else if (direction == GPRS_RLCMAC_DL_TBF) { |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 338 | gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(this); |
| 339 | |
| 340 | if (!(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK))) { |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 341 | LOGP(DRLCMAC, LOGL_NOTICE, "- Timeout for polling " |
| 342 | "PACKET DOWNLINK ACK.\n"); |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 343 | dl_tbf->rlcmac_diag(); |
| 344 | dl_tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_TO_DL_ACK); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 345 | } |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 346 | dl_tbf->n3105++; |
| 347 | if (dl_tbf->n3105 == dl_tbf->bts->bts_data()->n3105) { |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 348 | LOGP(DRLCMAC, LOGL_NOTICE, "- N3105 exceeded\n"); |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 349 | dl_tbf->set_state(GPRS_RLCMAC_RELEASING); |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 350 | tbf_timer_start(dl_tbf, 3195, dl_tbf->bts_data()->t3195, 0); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | /* resend IMM.ASS on CCCH on timeout */ |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 354 | if ((dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)) |
| 355 | && !(dl_tbf->state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) { |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 356 | LOGP(DRLCMAC, LOGL_DEBUG, "Re-send dowlink assignment " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 357 | "for %s on PCH (IMSI=%s)\n", |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 358 | tbf_name(dl_tbf), |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 359 | m_imsi); |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 360 | /* send immediate assignment */ |
Daniel Willmann | 6a16e0c | 2014-08-07 13:03:35 +0200 | [diff] [blame] | 361 | dl_tbf->bts->snd_dl_ass(dl_tbf, 0, m_imsi); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 362 | dl_tbf->m_wait_confirm = 1; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 363 | } |
| 364 | } else |
| 365 | LOGP(DRLCMAC, LOGL_ERROR, "- Poll Timeout, but no event!\n"); |
| 366 | } |
| 367 | |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 368 | static int setup_tbf(struct gprs_rlcmac_tbf *tbf, struct gprs_rlcmac_bts *bts, |
| 369 | struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx, |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 370 | uint8_t ms_class, uint8_t single_slot) |
| 371 | { |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 372 | int rc; |
| 373 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 374 | if (trx >= 8 || tfi >= 32) |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 375 | return -1; |
Daniel Willmann | 078bb71 | 2014-07-10 17:44:06 +0200 | [diff] [blame] | 376 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 377 | if (!tbf) |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 378 | return -1; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 379 | |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 380 | /* Back pointer for PODS llist compatibility */ |
| 381 | tbf->list.back = tbf; |
| 382 | |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 383 | tbf->m_created_ts = time(NULL); |
Holger Hans Peter Freyther | 9f0c1d2 | 2013-10-19 21:24:34 +0200 | [diff] [blame] | 384 | tbf->bts = bts->bts; |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 385 | tbf->m_tfi = tfi; |
Holger Hans Peter Freyther | 743bafa | 2013-09-29 07:50:50 +0200 | [diff] [blame] | 386 | tbf->trx = &bts->trx[trx]; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 387 | tbf->ms_class = ms_class; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 388 | /* select algorithm */ |
| 389 | rc = bts->alloc_algorithm(bts, old_tbf, tbf, bts->alloc_algorithm_curst, |
| 390 | single_slot); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 391 | /* if no resource */ |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 392 | if (rc < 0) { |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 393 | return -1; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 394 | } |
| 395 | /* assign control ts */ |
| 396 | tbf->control_ts = 0xff; |
| 397 | rc = tbf_assign_control_ts(tbf); |
Holger Hans Peter Freyther | 90b87ea | 2013-10-27 10:38:31 +0100 | [diff] [blame] | 398 | /* if no resource */ |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 399 | if (rc < 0) { |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 400 | return -1; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* set timestamp */ |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 404 | gettimeofday(&tbf->meas.rssi_tv, NULL); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 405 | |
Holger Hans Peter Freyther | 758dc12 | 2013-11-06 20:39:45 +0100 | [diff] [blame] | 406 | tbf->m_llc.init(); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, |
| 412 | struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx, |
| 413 | uint8_t ms_class, uint8_t single_slot) |
| 414 | { |
| 415 | struct gprs_rlcmac_ul_tbf *tbf; |
| 416 | int rc; |
| 417 | |
| 418 | LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n"); |
| 419 | LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: TFI=%d TRX=%d " |
| 420 | "MS_CLASS=%d\n", "UL", tfi, trx, ms_class); |
| 421 | |
| 422 | if (trx >= 8 || tfi >= 32) |
| 423 | return NULL; |
| 424 | |
| 425 | tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 426 | |
| 427 | if (!tbf) |
| 428 | return NULL; |
| 429 | |
| 430 | tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 431 | rc = setup_tbf(tbf, bts, old_tbf, tfi, trx, ms_class, single_slot); |
| 432 | /* if no resource */ |
| 433 | if (rc < 0) { |
| 434 | talloc_free(tbf); |
| 435 | return NULL; |
Holger Hans Peter Freyther | 1587764 | 2013-10-27 09:50:15 +0100 | [diff] [blame] | 436 | } |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 437 | |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 438 | llist_add(&tbf->list.list, &bts->ul_tbfs); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 439 | tbf->bts->tbf_ul_created(); |
| 440 | |
| 441 | return tbf; |
| 442 | } |
| 443 | |
| 444 | struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts, |
| 445 | struct gprs_rlcmac_tbf *old_tbf, uint8_t tfi, uint8_t trx, |
| 446 | uint8_t ms_class, uint8_t single_slot) |
| 447 | { |
| 448 | struct gprs_rlcmac_dl_tbf *tbf; |
| 449 | int rc; |
| 450 | |
| 451 | LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n"); |
| 452 | LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: TFI=%d TRX=%d " |
| 453 | "MS_CLASS=%d\n", "DL", tfi, trx, ms_class); |
| 454 | |
| 455 | if (trx >= 8 || tfi >= 32) |
| 456 | return NULL; |
| 457 | |
| 458 | tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 459 | |
| 460 | if (!tbf) |
| 461 | return NULL; |
| 462 | |
| 463 | tbf->direction = GPRS_RLCMAC_DL_TBF; |
| 464 | rc = setup_tbf(tbf, bts, old_tbf, tfi, trx, ms_class, single_slot); |
| 465 | /* if no resource */ |
| 466 | if (rc < 0) { |
| 467 | talloc_free(tbf); |
| 468 | return NULL; |
| 469 | } |
| 470 | |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 471 | llist_add(&tbf->list.list, &bts->dl_tbfs); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 472 | tbf->bts->tbf_dl_created(); |
| 473 | |
Jacob Erlbeck | 005ee7f | 2015-03-20 14:53:54 +0100 | [diff] [blame] | 474 | tbf->m_last_dl_poll_fn = -1; |
Jacob Erlbeck | 3bed5d1 | 2015-03-19 11:22:38 +0100 | [diff] [blame] | 475 | tbf->m_last_dl_drained_fn = -1; |
Jacob Erlbeck | 005ee7f | 2015-03-20 14:53:54 +0100 | [diff] [blame] | 476 | |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 477 | gettimeofday(&tbf->m_bw.dl_bw_tv, NULL); |
| 478 | gettimeofday(&tbf->m_bw.dl_loss_tv, NULL); |
| 479 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 480 | return tbf; |
| 481 | } |
| 482 | |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 483 | static void tbf_timer_cb(void *_tbf) |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 484 | { |
| 485 | struct gprs_rlcmac_tbf *tbf = (struct gprs_rlcmac_tbf *)_tbf; |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 486 | tbf->handle_timeout(); |
| 487 | } |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 488 | |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 489 | void gprs_rlcmac_tbf::handle_timeout() |
| 490 | { |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 491 | LOGP(DRLCMAC, LOGL_DEBUG, "%s timer %u expired.\n", |
| 492 | tbf_name(this), T); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 493 | |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 494 | num_T_exp++; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 495 | |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 496 | switch (T) { |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 497 | case 0: /* assignment */ |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 498 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))) { |
| 499 | if (state_is(GPRS_RLCMAC_ASSIGN)) { |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 500 | LOGP(DRLCMAC, LOGL_NOTICE, "%s releasing due to " |
| 501 | "PACCH assignment timeout.\n", tbf_name(this)); |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 502 | tbf_free(this); |
Holger Hans Peter Freyther | 3d0cc2f | 2014-01-16 10:09:42 +0100 | [diff] [blame] | 503 | return; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 504 | } else |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 505 | LOGP(DRLCMAC, LOGL_ERROR, "Error: %s is not " |
| 506 | "in assign state\n", tbf_name(this)); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 507 | } |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 508 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))) { |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 509 | gprs_rlcmac_dl_tbf *dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(this); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 510 | dl_tbf->m_wait_confirm = 0; |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 511 | if (dl_tbf->state_is(GPRS_RLCMAC_ASSIGN)) { |
| 512 | tbf_assign_control_ts(dl_tbf); |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 513 | |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 514 | if (!dl_tbf->upgrade_to_multislot) { |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 515 | /* change state to FLOW, so scheduler |
| 516 | * will start transmission */ |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 517 | dl_tbf->set_state(GPRS_RLCMAC_FLOW); |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 518 | break; |
| 519 | } |
| 520 | |
| 521 | /* This tbf can be upgraded to use multiple DL |
| 522 | * timeslots and now that there is already one |
| 523 | * slot assigned send another DL assignment via |
| 524 | * PDCH. */ |
| 525 | |
| 526 | /* keep to flags */ |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 527 | dl_tbf->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; |
| 528 | dl_tbf->state_flags &= ~(1 << GPRS_RLCMAC_FLAG_CCCH); |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 529 | |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 530 | dl_tbf->update(); |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 531 | |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 532 | dl_tbf->bts->trigger_dl_ass(dl_tbf, dl_tbf, NULL); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 533 | } else |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 534 | LOGP(DRLCMAC, LOGL_NOTICE, "%s Continue flow after " |
Daniel Willmann | 532a4b5 | 2014-08-07 12:39:26 +0200 | [diff] [blame] | 535 | "IMM.ASS confirm\n", tbf_name(dl_tbf)); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 536 | } |
| 537 | break; |
| 538 | case 3169: |
| 539 | case 3191: |
| 540 | case 3195: |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 541 | LOGP(DRLCMAC, LOGL_NOTICE, "%s T%d timeout during " |
| 542 | "transsmission\n", tbf_name(this), T); |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 543 | rlcmac_diag(); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 544 | /* fall through */ |
| 545 | case 3193: |
Holger Hans Peter Freyther | 8d0e489 | 2013-10-27 12:42:58 +0100 | [diff] [blame] | 546 | LOGP(DRLCMAC, LOGL_DEBUG, |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 547 | "%s will be freed due to timeout\n", tbf_name(this)); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 548 | /* free TBF */ |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 549 | tbf_free(this); |
Holger Hans Peter Freyther | 3d0cc2f | 2014-01-16 10:09:42 +0100 | [diff] [blame] | 550 | return; |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 551 | break; |
| 552 | default: |
Holger Hans Peter Freyther | 8d0e489 | 2013-10-27 12:42:58 +0100 | [diff] [blame] | 553 | LOGP(DRLCMAC, LOGL_ERROR, |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 554 | "%s timer expired in unknown mode: %u\n", tbf_name(this), T); |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | int gprs_rlcmac_tbf::rlcmac_diag() |
| 559 | { |
| 560 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH))) |
| 561 | LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on CCCH\n"); |
| 562 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_PACCH))) |
| 563 | LOGP(DRLCMAC, LOGL_NOTICE, "- Assignment was on PACCH\n"); |
| 564 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_UL_DATA))) |
| 565 | LOGP(DRLCMAC, LOGL_NOTICE, "- Uplink data was received\n"); |
| 566 | else if (direction == GPRS_RLCMAC_UL_TBF) |
| 567 | LOGP(DRLCMAC, LOGL_NOTICE, "- No uplink data received yet\n"); |
| 568 | if ((state_flags & (1 << GPRS_RLCMAC_FLAG_DL_ACK))) |
| 569 | LOGP(DRLCMAC, LOGL_NOTICE, "- Downlink ACK was received\n"); |
| 570 | else if (direction == GPRS_RLCMAC_DL_TBF) |
| 571 | LOGP(DRLCMAC, LOGL_NOTICE, "- No downlink ACK received yet\n"); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 576 | struct msgb *gprs_rlcmac_tbf::create_dl_ass(uint32_t fn) |
| 577 | { |
| 578 | struct msgb *msg; |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 579 | struct gprs_rlcmac_dl_tbf *new_dl_tbf; |
Holger Hans Peter Freyther | 9977e15 | 2013-11-24 22:52:10 +0100 | [diff] [blame] | 580 | int poll_ass_dl = 1; |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 581 | |
Holger Hans Peter Freyther | 9977e15 | 2013-11-24 22:52:10 +0100 | [diff] [blame] | 582 | if (direction == GPRS_RLCMAC_DL_TBF && control_ts != first_common_ts) { |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 583 | LOGP(DRLCMAC, LOGL_NOTICE, "Cannot poll for downlink " |
| 584 | "assigment, because MS cannot reply. (control TS=%d, " |
| 585 | "first common TS=%d)\n", control_ts, |
| 586 | first_common_ts); |
| 587 | poll_ass_dl = 0; |
| 588 | } |
| 589 | if (poll_ass_dl) { |
| 590 | if (poll_state != GPRS_RLCMAC_POLL_NONE) { |
| 591 | LOGP(DRLCMAC, LOGL_DEBUG, "Polling is already sheduled " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 592 | "for %s, so we must wait for downlink " |
| 593 | "assignment...\n", tbf_name(this)); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 594 | return NULL; |
| 595 | } |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 596 | if (bts->sba()->find(trx->trx_no, control_ts, (fn + 13) % 2715648)) { |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 597 | LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already " |
| 598 | "scheduled for single block allocation...\n"); |
| 599 | return NULL; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /* on uplink TBF we get the downlink TBF to be assigned. */ |
| 604 | if (direction == GPRS_RLCMAC_UL_TBF) { |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 605 | gprs_rlcmac_ul_tbf *ul_tbf = static_cast<gprs_rlcmac_ul_tbf *>(this); |
| 606 | |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 607 | /* be sure to check first, if contention resolution is done, |
| 608 | * otherwise we cannot send the assignment yet */ |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 609 | if (!ul_tbf->m_contention_resolution_done) { |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 610 | LOGP(DRLCMAC, LOGL_DEBUG, "Cannot assign DL TBF now, " |
| 611 | "because contention resolution is not " |
| 612 | "finished.\n"); |
| 613 | return NULL; |
| 614 | } |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | new_dl_tbf = static_cast<gprs_rlcmac_dl_tbf *>(m_new_tbf); |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 618 | if (!new_dl_tbf) { |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 619 | LOGP(DRLCMACDL, LOGL_ERROR, "We have a schedule for downlink " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 620 | "assignment at uplink %s, but there is no downlink " |
| 621 | "TBF\n", tbf_name(this)); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 622 | dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE; |
| 623 | return NULL; |
| 624 | } |
| 625 | |
Holger Hans Peter Freyther | f5c9747 | 2014-12-26 18:32:00 +0100 | [diff] [blame] | 626 | new_dl_tbf->was_releasing = was_releasing; |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 627 | msg = msgb_alloc(23, "rlcmac_dl_ass"); |
| 628 | if (!msg) |
| 629 | return NULL; |
| 630 | bitvec *ass_vec = bitvec_alloc(23); |
| 631 | if (!ass_vec) { |
| 632 | msgb_free(msg); |
| 633 | return NULL; |
| 634 | } |
| 635 | bitvec_unhex(ass_vec, |
| 636 | "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 637 | LOGP(DRLCMAC, LOGL_INFO, "%s start Packet Downlink Assignment (PACCH)\n", tbf_name(new_dl_tbf)); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 638 | RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t); |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 639 | Encoding::write_packet_downlink_assignment(mac_control_block, m_tfi, |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 640 | (direction == GPRS_RLCMAC_DL_TBF), new_dl_tbf, |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 641 | poll_ass_dl, bts_data()->alpha, bts_data()->gamma, -1, 0); |
| 642 | LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Downlink Assignment +++++++++++++++++++++++++\n"); |
| 643 | encode_gsm_rlcmac_downlink(ass_vec, mac_control_block); |
| 644 | LOGPC(DCSN1, LOGL_NOTICE, "\n"); |
| 645 | LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Downlink Assignment -------------------------\n"); |
| 646 | bitvec_pack(ass_vec, msgb_put(msg, 23)); |
| 647 | bitvec_free(ass_vec); |
| 648 | talloc_free(mac_control_block); |
| 649 | |
| 650 | if (poll_ass_dl) { |
| 651 | poll_state = GPRS_RLCMAC_POLL_SCHED; |
| 652 | poll_fn = (fn + 13) % 2715648; |
| 653 | dl_ass_state = GPRS_RLCMAC_DL_ASS_WAIT_ACK; |
| 654 | } else { |
| 655 | dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE; |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 656 | new_dl_tbf->set_state(GPRS_RLCMAC_FLOW); |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 657 | tbf_assign_control_ts(new_dl_tbf); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 658 | /* stop pending assignment timer */ |
Daniel Willmann | b2886f1 | 2014-08-07 14:48:20 +0200 | [diff] [blame] | 659 | new_dl_tbf->stop_timer(); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 660 | |
| 661 | } |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 662 | |
| 663 | return msg; |
| 664 | } |
| 665 | |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 666 | struct msgb *gprs_rlcmac_tbf::create_ul_ass(uint32_t fn) |
| 667 | { |
| 668 | struct msgb *msg; |
Daniel Willmann | 350f64d | 2014-08-07 14:54:11 +0200 | [diff] [blame] | 669 | struct gprs_rlcmac_ul_tbf *new_tbf; |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 670 | |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 671 | if (poll_state != GPRS_RLCMAC_POLL_NONE) { |
| 672 | LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 673 | "sheduled for %s, so we must wait for uplink " |
| 674 | "assignment...\n", tbf_name(this)); |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 675 | return NULL; |
| 676 | } |
Holger Hans Peter Freyther | ec80f82 | 2013-10-27 13:44:37 +0100 | [diff] [blame] | 677 | if (bts->sba()->find(trx->trx_no, control_ts, (fn + 13) % 2715648)) { |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 678 | LOGP(DRLCMACUL, LOGL_DEBUG, "Polling is already scheduled for " |
| 679 | "single block allocation...\n"); |
| 680 | return NULL; |
| 681 | } |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 682 | |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 683 | new_tbf = static_cast<gprs_rlcmac_ul_tbf *>(m_new_tbf); |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 684 | if (!new_tbf) { |
| 685 | LOGP(DRLCMACUL, LOGL_ERROR, "We have a schedule for uplink " |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 686 | "assignment at downlink %s, but there is no uplink " |
| 687 | "TBF\n", tbf_name(this)); |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 688 | ul_ass_state = GPRS_RLCMAC_UL_ASS_NONE; |
| 689 | return NULL; |
| 690 | } |
| 691 | |
| 692 | msg = msgb_alloc(23, "rlcmac_ul_ass"); |
| 693 | if (!msg) |
| 694 | return NULL; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 695 | LOGP(DRLCMAC, LOGL_INFO, "%ss start Packet Uplink Assignment (PACCH)\n", tbf_name(new_tbf)); |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 696 | bitvec *ass_vec = bitvec_alloc(23); |
| 697 | if (!ass_vec) { |
| 698 | msgb_free(msg); |
| 699 | return NULL; |
| 700 | } |
| 701 | bitvec_unhex(ass_vec, |
| 702 | "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 703 | Encoding::write_packet_uplink_assignment(bts_data(), ass_vec, m_tfi, |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 704 | (direction == GPRS_RLCMAC_DL_TBF), m_tlli, |
Holger Hans Peter Freyther | 9977e15 | 2013-11-24 22:52:10 +0100 | [diff] [blame] | 705 | m_tlli_valid, new_tbf, 1, bts_data()->alpha, |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 706 | bts_data()->gamma, -1); |
| 707 | bitvec_pack(ass_vec, msgb_put(msg, 23)); |
| 708 | RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t); |
| 709 | LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Uplink Assignment +++++++++++++++++++++++++\n"); |
| 710 | decode_gsm_rlcmac_downlink(ass_vec, mac_control_block); |
| 711 | LOGPC(DCSN1, LOGL_NOTICE, "\n"); |
| 712 | LOGP(DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Uplink Assignment -------------------------\n"); |
| 713 | bitvec_free(ass_vec); |
| 714 | talloc_free(mac_control_block); |
| 715 | |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 716 | poll_state = GPRS_RLCMAC_POLL_SCHED; |
| 717 | poll_fn = (fn + 13) % 2715648; |
| 718 | ul_ass_state = GPRS_RLCMAC_UL_ASS_WAIT_ACK; |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 719 | |
| 720 | return msg; |
| 721 | } |
| 722 | |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 723 | void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_trx *trx) |
| 724 | { |
| 725 | for (uint8_t tfi = 0; tfi < 32; tfi++) { |
| 726 | struct gprs_rlcmac_tbf *tbf; |
| 727 | |
| 728 | tbf = trx->ul_tbf[tfi]; |
| 729 | if (tbf) |
| 730 | tbf_free(tbf); |
| 731 | tbf = trx->dl_tbf[tfi]; |
| 732 | if (tbf) |
| 733 | tbf_free(tbf); |
| 734 | } |
| 735 | } |
Holger Hans Peter Freyther | 4f6a4e5d | 2013-10-16 17:58:46 +0200 | [diff] [blame] | 736 | |
| 737 | void gprs_rlcmac_tbf::free_all(struct gprs_rlcmac_pdch *pdch) |
| 738 | { |
| 739 | for (uint8_t tfi = 0; tfi < 32; tfi++) { |
| 740 | struct gprs_rlcmac_tbf *tbf; |
| 741 | |
Daniel Willmann | 17a1d5e | 2014-05-30 20:21:30 +0200 | [diff] [blame] | 742 | tbf = pdch->ul_tbf_by_tfi(tfi); |
Holger Hans Peter Freyther | 4f6a4e5d | 2013-10-16 17:58:46 +0200 | [diff] [blame] | 743 | if (tbf) |
| 744 | tbf_free(tbf); |
Daniel Willmann | 17a1d5e | 2014-05-30 20:21:30 +0200 | [diff] [blame] | 745 | tbf = pdch->dl_tbf_by_tfi(tfi); |
Holger Hans Peter Freyther | 4f6a4e5d | 2013-10-16 17:58:46 +0200 | [diff] [blame] | 746 | if (tbf) |
| 747 | tbf_free(tbf); |
| 748 | } |
| 749 | } |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 750 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 751 | void gprs_rlcmac_tbf::tlli_mark_valid() |
| 752 | { |
| 753 | m_tlli_valid = true; |
| 754 | } |
| 755 | |
| 756 | void gprs_rlcmac_tbf::update_tlli(uint32_t tlli) |
| 757 | { |
| 758 | if (tlli == m_tlli) |
| 759 | return; |
| 760 | |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 761 | bool changedUl = false; |
| 762 | |
| 763 | /* |
| 764 | * During a Routing Area Update (due the assignment of a new |
| 765 | * P-TMSI) the tlli can change. We notice this when receiving |
| 766 | * a PACKET CONTROL ACK. |
| 767 | * When we get a TLLI change on the DL we will look if there |
| 768 | * is a UL TBF and change the tlli there as well. |
| 769 | * |
| 770 | * TODO: There could be multiple DL and UL TBFs and we should |
| 771 | * have a proper way to link all the related TBFs so we can do |
| 772 | * a group update. |
| 773 | */ |
| 774 | if (m_tlli_valid && direction == GPRS_RLCMAC_DL_TBF) { |
| 775 | gprs_rlcmac_tbf *ul_tbf; |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 776 | ul_tbf = bts->ul_tbf_by_tlli(m_tlli); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 777 | |
| 778 | if (ul_tbf) { |
| 779 | ul_tbf->m_tlli = tlli; |
| 780 | changedUl = true; |
| 781 | } |
| 782 | } |
| 783 | |
Holger Hans Peter Freyther | bc1626e | 2013-10-30 19:50:49 +0100 | [diff] [blame] | 784 | /* update the timing advance for the new tlli */ |
| 785 | bts->timing_advance()->update(m_tlli, tlli, ta); |
| 786 | |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 787 | LOGP(DRLCMAC, LOGL_NOTICE, |
| 788 | "%s changing tlli from TLLI=0x%08x TLLI=0x%08x ul_changed=%d\n", |
| 789 | tbf_name(this), m_tlli, tlli, changedUl); |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 790 | m_tlli = tlli; |
| 791 | } |
| 792 | |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 793 | int gprs_rlcmac_tbf::extract_tlli(const uint8_t *data, const size_t len) |
| 794 | { |
| 795 | struct gprs_rlcmac_tbf *dl_tbf, *ul_tbf; |
| 796 | struct rlc_ul_header *rh = (struct rlc_ul_header *)data; |
| 797 | uint32_t new_tlli; |
| 798 | int rc; |
| 799 | |
| 800 | /* no TLLI yet */ |
| 801 | if (!rh->ti) { |
| 802 | LOGP(DRLCMACUL, LOGL_NOTICE, "UL DATA TFI=%d without " |
| 803 | "TLLI, but no TLLI received yet\n", rh->tfi); |
| 804 | return 0; |
| 805 | } |
| 806 | rc = Decoding::tlli_from_ul_data(data, len, &new_tlli); |
| 807 | if (rc) { |
| 808 | bts->decode_error(); |
| 809 | LOGP(DRLCMACUL, LOGL_NOTICE, "Failed to decode TLLI " |
| 810 | "of UL DATA TFI=%d.\n", rh->tfi); |
| 811 | return 0; |
| 812 | } |
| 813 | update_tlli(new_tlli); |
| 814 | LOGP(DRLCMACUL, LOGL_INFO, "Decoded premier TLLI=0x%08x of " |
| 815 | "UL DATA TFI=%d.\n", tlli(), rh->tfi); |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 816 | if ((dl_tbf = bts->dl_tbf_by_tlli(tlli()))) { |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 817 | LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from " |
| 818 | "TLLI=0x%08x while %s still exists. " |
| 819 | "Killing pending DL TBF\n", tlli(), |
| 820 | tbf_name(dl_tbf)); |
| 821 | tbf_free(dl_tbf); |
Holger Hans Peter Freyther | 3d0cc2f | 2014-01-16 10:09:42 +0100 | [diff] [blame] | 822 | dl_tbf = NULL; |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 823 | } |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 824 | /* ul_tbf_by_tlli will not find your TLLI, because it is not |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 825 | * yet marked valid */ |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 826 | if ((ul_tbf = bts->ul_tbf_by_tlli(tlli()))) { |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 827 | LOGP(DRLCMACUL, LOGL_NOTICE, "Got RACH from " |
| 828 | "TLLI=0x%08x while %s still exists. " |
| 829 | "Killing pending UL TBF\n", tlli(), |
| 830 | tbf_name(ul_tbf)); |
| 831 | tbf_free(ul_tbf); |
Holger Hans Peter Freyther | 3d0cc2f | 2014-01-16 10:09:42 +0100 | [diff] [blame] | 832 | ul_tbf = NULL; |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 833 | } |
| 834 | /* mark TLLI valid now */ |
| 835 | tlli_mark_valid(); |
| 836 | /* store current timing advance */ |
| 837 | bts->timing_advance()->remember(tlli(), ta); |
| 838 | return 1; |
| 839 | } |
| 840 | |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 841 | const char *tbf_name(gprs_rlcmac_tbf *tbf) |
| 842 | { |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 843 | return tbf->name(); |
| 844 | } |
| 845 | |
| 846 | const char *gprs_rlcmac_tbf::name() const |
| 847 | { |
| 848 | snprintf(m_name_buf, sizeof(m_name_buf) - 1, |
| 849 | "TBF(TFI=%d TLLI=0x%08x DIR=%s STATE=%s)", |
| 850 | m_tfi, m_tlli, |
| 851 | direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL", |
| 852 | state_name() |
| 853 | ); |
| 854 | m_name_buf[sizeof(m_name_buf) - 1] = '\0'; |
| 855 | return m_name_buf; |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 856 | } |
Holger Hans Peter Freyther | 758dc12 | 2013-11-06 20:39:45 +0100 | [diff] [blame] | 857 | |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 858 | void gprs_rlcmac_tbf::rotate_in_list() |
| 859 | { |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 860 | llist_del(&list.list); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 861 | if (direction == GPRS_RLCMAC_UL_TBF) |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 862 | llist_add(&list.list, &bts->bts_data()->ul_tbfs); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 863 | else |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 864 | llist_add(&list.list, &bts->bts_data()->dl_tbfs); |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 865 | } |
Holger Hans Peter Freyther | 8f399de | 2013-12-25 20:22:35 +0100 | [diff] [blame] | 866 | |
| 867 | uint8_t gprs_rlcmac_tbf::tsc() const |
| 868 | { |
| 869 | return trx->pdch[first_ts].tsc; |
| 870 | } |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 871 | |
| 872 | void tbf_print_vty_info(struct vty *vty, llist_head *ltbf) |
| 873 | { |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 874 | gprs_rlcmac_tbf *tbf = llist_pods_entry(ltbf, gprs_rlcmac_tbf); |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 875 | |
Daniel Willmann | 772415f | 2014-01-15 17:06:51 +0100 | [diff] [blame] | 876 | vty_out(vty, "TBF: TFI=%d TLLI=0x%08x (%s) DIR=%s IMSI=%s%s", tbf->tfi(), |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 877 | tbf->tlli(), tbf->is_tlli_valid() ? "valid" : "invalid", |
| 878 | tbf->direction == GPRS_RLCMAC_UL_TBF ? "UL" : "DL", |
| 879 | tbf->imsi(), VTY_NEWLINE); |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 880 | vty_out(vty, " created=%lu state=%08x 1st_TS=%d 1st_cTS=%d ctrl_TS=%d " |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 881 | "MS_CLASS=%d%s", |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 882 | tbf->created_ts(), tbf->state_flags, tbf->first_ts, |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 883 | tbf->first_common_ts, tbf->control_ts, tbf->ms_class, |
| 884 | VTY_NEWLINE); |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 885 | vty_out(vty, " TS_alloc="); |
| 886 | for (int i = 0; i < 8; i++) { |
| 887 | if (tbf->pdch[i]) |
| 888 | vty_out(vty, "%d ", i); |
| 889 | } |
Daniel Willmann | 772415f | 2014-01-15 17:06:51 +0100 | [diff] [blame] | 890 | vty_out(vty, " CS=%d%s%s", tbf->cs, VTY_NEWLINE, VTY_NEWLINE); |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 891 | } |