Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 3 | * Copyright (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (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 Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <bts.h> |
| 23 | #include <pdch.h> |
| 24 | #include <decoding.h> |
| 25 | #include <encoding.h> |
| 26 | #include <gprs_rlcmac.h> |
| 27 | #include <gprs_debug.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 28 | #include <coding_scheme.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 29 | #include <gprs_ms.h> |
| 30 | #include <gprs_ms_storage.h> |
| 31 | #include <pcu_l1_if.h> |
| 32 | #include <rlc.h> |
| 33 | #include <sba.h> |
| 34 | #include <tbf.h> |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 35 | #include <tbf_ul.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 36 | #include <cxx_linuxlist.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 37 | |
| 38 | extern "C" { |
Pau Espin Pedrol | 980ef1e | 2020-03-26 15:06:11 +0100 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
| 40 | #include <osmocom/core/msgb.h> |
Vadim Yanitskiy | d71c566 | 2020-03-26 15:45:21 +0700 | [diff] [blame] | 41 | #include <osmocom/gsm/gsm48.h> |
Pau Espin Pedrol | 980ef1e | 2020-03-26 15:06:11 +0100 | [diff] [blame] | 42 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 43 | #include <osmocom/core/bitvec.h> |
| 44 | #include <osmocom/core/gsmtap.h> |
| 45 | #include <osmocom/core/logging.h> |
| 46 | #include <osmocom/core/utils.h> |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 47 | |
Pau Espin Pedrol | 980ef1e | 2020-03-26 15:06:11 +0100 | [diff] [blame] | 48 | #include "coding_scheme.h" |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 49 | #include "gsm_rlcmac.h" |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 50 | #include "nacc_fsm.h" |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #include <errno.h> |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 54 | #include <stdlib.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 55 | #include <arpa/inet.h> |
| 56 | |
| 57 | extern void *tall_pcu_ctx; |
| 58 | |
| 59 | static void get_rx_qual_meas(struct pcu_l1_meas *meas, uint8_t rx_qual_enc) |
| 60 | { |
| 61 | static const int16_t rx_qual_map[] = { |
| 62 | 0, /* 0,14 % */ |
| 63 | 0, /* 0,28 % */ |
| 64 | 1, /* 0,57 % */ |
| 65 | 1, /* 1,13 % */ |
| 66 | 2, /* 2,26 % */ |
| 67 | 5, /* 4,53 % */ |
| 68 | 9, /* 9,05 % */ |
| 69 | 18, /* 18,10 % */ |
| 70 | }; |
| 71 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 72 | pcu_l1_meas_set_ms_rx_qual(meas, rx_qual_map[ |
| 73 | OSMO_MIN(rx_qual_enc, ARRAY_SIZE(rx_qual_map)-1) |
| 74 | ]); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void get_meas(struct pcu_l1_meas *meas, |
| 78 | const Packet_Resource_Request_t *qr) |
| 79 | { |
| 80 | unsigned i; |
| 81 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 82 | pcu_l1_meas_set_ms_c_value(meas, qr->C_VALUE); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 83 | if (qr->Exist_SIGN_VAR) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 84 | pcu_l1_meas_set_ms_sign_var(meas, (qr->SIGN_VAR + 2) / 4); /* SIGN_VAR * 0.25 dB */ |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 85 | |
Pau Espin Pedrol | 0daf913 | 2020-02-23 16:11:28 +0700 | [diff] [blame] | 86 | for (i = 0; i < OSMO_MIN(ARRAY_SIZE(qr->I_LEVEL_TN), ARRAY_SIZE(meas->ts)); i++) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 87 | { |
Pau Espin Pedrol | 0daf913 | 2020-02-23 16:11:28 +0700 | [diff] [blame] | 88 | if (qr->I_LEVEL_TN[i].Exist) { |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 89 | LOGP(DRLCMAC, LOGL_INFO, |
| 90 | "Packet resource request: i_level[%d] = %d\n", |
Pau Espin Pedrol | 0daf913 | 2020-02-23 16:11:28 +0700 | [diff] [blame] | 91 | i, qr->I_LEVEL_TN[i].I_LEVEL); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 92 | pcu_l1_meas_set_ms_i_level(meas, i, -2 * qr->I_LEVEL_TN[i].I_LEVEL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void get_meas(struct pcu_l1_meas *meas, |
| 98 | const Channel_Quality_Report_t *qr) |
| 99 | { |
| 100 | unsigned i; |
| 101 | |
| 102 | get_rx_qual_meas(meas, qr->RXQUAL); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 103 | pcu_l1_meas_set_ms_c_value(meas, qr->C_VALUE); |
| 104 | pcu_l1_meas_set_ms_sign_var(meas, (qr->SIGN_VAR + 2) / 4); /* SIGN_VAR * 0.25 dB */ |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 105 | |
| 106 | for (i = 0; i < OSMO_MIN(ARRAY_SIZE(qr->Slot), ARRAY_SIZE(meas->ts)); i++) |
| 107 | { |
| 108 | if (qr->Slot[i].Exist) { |
| 109 | LOGP(DRLCMAC, LOGL_DEBUG, |
| 110 | "Channel quality report: i_level[%d] = %d\n", |
| 111 | i, qr->Slot[i].I_LEVEL_TN); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 112 | pcu_l1_meas_set_ms_i_level(meas, i, -2 * qr->Slot[i].I_LEVEL_TN); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 117 | static inline void sched_ul_ass_or_rej(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_dl_tbf *tbf) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 118 | { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 119 | bts_do_rate_ctr_inc(bts, CTR_CHANNEL_REQUEST_DESCRIPTION); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 120 | |
| 121 | /* This call will register the new TBF with the MS on success */ |
Pau Espin Pedrol | 9438613 | 2022-10-28 19:50:09 +0200 | [diff] [blame] | 122 | gprs_rlcmac_ul_tbf *ul_tbf = ms_new_ul_tbf_assigned_pacch(tbf->ms(), tbf->trx->trx_no); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 123 | |
| 124 | /* schedule uplink assignment or reject */ |
| 125 | if (ul_tbf) { |
Pau Espin Pedrol | fb904fb | 2021-11-09 14:01:40 +0100 | [diff] [blame] | 126 | LOGPTBFDL(tbf, LOGL_DEBUG, "MS requests UL TBF in ack message, so we provide one:\n"); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 127 | osmo_fsm_inst_dispatch(tbf->ul_ass_fsm.fi, TBF_UL_ASS_EV_SCHED_ASS, NULL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 128 | } else { |
Pau Espin Pedrol | fb904fb | 2021-11-09 14:01:40 +0100 | [diff] [blame] | 129 | LOGPTBFDL(tbf, LOGL_NOTICE, "MS requests UL TBF in ack message, but alloc failed: send PktAssRej\n"); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 130 | osmo_fsm_inst_dispatch(tbf->ul_ass_fsm.fi, TBF_UL_ASS_EV_SCHED_ASS_REJ, NULL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Pau Espin Pedrol | 54a126f | 2021-11-09 18:41:05 +0100 | [diff] [blame] | 134 | /* Make sure the PDCH vanished from the mask of reserved PDCHs for all MS, to |
| 135 | * avoid alloc_algorithm using it. */ |
| 136 | static void pdch_unreserve_all_ms_reserved_slots(struct gprs_rlcmac_pdch *pdch) |
| 137 | { |
| 138 | struct llist_head *tmp; |
| 139 | uint8_t ts_rm_mask = (~(1 << pdch->ts_no)); |
| 140 | struct gprs_rlcmac_trx *trx = pdch->trx; |
| 141 | |
| 142 | llist_for_each(tmp, bts_ms_list(trx->bts)) { |
| 143 | struct GprsMs *ms = llist_entry(tmp, typeof(*ms), list); |
| 144 | if (ms->current_trx != trx) |
| 145 | continue; |
| 146 | uint8_t old_dl_slots = ms_reserved_dl_slots(ms); |
| 147 | uint8_t old_ul_slots = ms_reserved_ul_slots(ms); |
| 148 | uint8_t new_dl_slots = old_dl_slots & ts_rm_mask; |
| 149 | uint8_t new_ul_slots = old_ul_slots & ts_rm_mask; |
| 150 | if (old_dl_slots == new_dl_slots && old_ul_slots == new_ul_slots) |
| 151 | continue; |
| 152 | ms_set_reserved_slots(ms, trx, new_ul_slots, new_dl_slots); |
| 153 | } |
| 154 | if (pdch->num_reserved(GPRS_RLCMAC_UL_TBF) > 0 || pdch->num_reserved(GPRS_RLCMAC_DL_TBF) > 0) |
| 155 | LOGPDCH(pdch, DRLCMAC, LOGL_ERROR, |
| 156 | "Reserved TS count not zero after unreserving from all current MS in list! UL=%u DL=%u\n", |
| 157 | pdch->num_reserved(GPRS_RLCMAC_UL_TBF), pdch->num_reserved(GPRS_RLCMAC_DL_TBF)); |
| 158 | } |
| 159 | |
Pau Espin Pedrol | 702ebee | 2021-03-08 14:15:54 +0100 | [diff] [blame] | 160 | void pdch_init(struct gprs_rlcmac_pdch *pdch, struct gprs_rlcmac_trx *trx, uint8_t ts_nr) |
| 161 | { |
| 162 | pdch->ts_no = ts_nr; |
| 163 | pdch->trx = trx; |
| 164 | |
| 165 | /* Initialize the PTCCH/D message (Packet Timing Advance Control Channel) */ |
| 166 | memset(pdch->ptcch_msg, PTCCH_TAI_FREE, PTCCH_TAI_NUM); |
| 167 | memset(pdch->ptcch_msg + PTCCH_TAI_NUM, PTCCH_PADDING, 7); |
| 168 | } |
| 169 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 170 | void gprs_rlcmac_pdch::enable() |
| 171 | { |
Pau Espin Pedrol | 304b10a | 2021-11-09 12:22:48 +0100 | [diff] [blame] | 172 | LOGPDCH(this, DRLCMAC, LOGL_INFO, "PDCH state: %s => enabled\n", m_is_enabled ? "enabled" : "disabled"); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 173 | OSMO_ASSERT(m_is_enabled == 0); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 174 | INIT_LLIST_HEAD(&paging_list); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 175 | |
| 176 | OSMO_ASSERT(!this->ulc); |
| 177 | this->ulc = pdch_ulc_alloc(this, trx->bts); |
| 178 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 179 | m_is_enabled = 1; |
Oliver Smith | 35d51ca | 2021-09-02 12:23:58 +0200 | [diff] [blame] | 180 | bts_stat_item_inc(trx->bts, STAT_PDCH_AVAILABLE); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void gprs_rlcmac_pdch::disable() |
| 184 | { |
Pau Espin Pedrol | 304b10a | 2021-11-09 12:22:48 +0100 | [diff] [blame] | 185 | LOGPDCH(this, DRLCMAC, LOGL_INFO, "PDCH state: %s => disabled\n", m_is_enabled ? "enabled" : "disabled"); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 186 | OSMO_ASSERT(m_is_enabled == 1); |
| 187 | this->free_resources(); |
| 188 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 189 | m_is_enabled = 0; |
Oliver Smith | 35d51ca | 2021-09-02 12:23:58 +0200 | [diff] [blame] | 190 | bts_stat_item_dec(trx->bts, STAT_PDCH_AVAILABLE); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void gprs_rlcmac_pdch::free_resources() |
| 194 | { |
| 195 | struct gprs_rlcmac_paging *pag; |
| 196 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 197 | /* kick all TBF on slot */ |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 198 | pdch_free_all_tbf(this); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 199 | |
Pau Espin Pedrol | 54a126f | 2021-11-09 18:41:05 +0100 | [diff] [blame] | 200 | pdch_unreserve_all_ms_reserved_slots(this); |
| 201 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 202 | /* flush all pending paging messages */ |
| 203 | while ((pag = dequeue_paging())) |
| 204 | talloc_free(pag); |
| 205 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 206 | talloc_free(this->ulc); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 207 | this->ulc = NULL; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | struct gprs_rlcmac_paging *gprs_rlcmac_pdch::dequeue_paging() |
| 211 | { |
| 212 | struct gprs_rlcmac_paging *pag; |
| 213 | |
| 214 | if (llist_empty(&paging_list)) |
| 215 | return NULL; |
Pau Espin Pedrol | c48d27b | 2021-05-13 15:58:55 +0200 | [diff] [blame] | 216 | pag = llist_first_entry(&paging_list, struct gprs_rlcmac_paging, list); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 217 | llist_del(&pag->list); |
| 218 | |
| 219 | return pag; |
| 220 | } |
| 221 | |
| 222 | struct msgb *gprs_rlcmac_pdch::packet_paging_request() |
| 223 | { |
| 224 | struct gprs_rlcmac_paging *pag; |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 225 | RlcMacDownlink_t *mac_control_block; |
| 226 | bitvec *pag_vec; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 227 | struct msgb *msg; |
| 228 | unsigned wp = 0, len; |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 229 | int rc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 230 | |
| 231 | /* no paging, no message */ |
| 232 | pag = dequeue_paging(); |
| 233 | if (!pag) |
| 234 | return NULL; |
| 235 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 236 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "Scheduling paging\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 237 | |
| 238 | /* alloc message */ |
| 239 | msg = msgb_alloc(23, "pag ctrl block"); |
| 240 | if (!msg) { |
| 241 | talloc_free(pag); |
| 242 | return NULL; |
| 243 | } |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 244 | pag_vec = bitvec_alloc(23, tall_pcu_ctx); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 245 | if (!pag_vec) { |
| 246 | msgb_free(msg); |
| 247 | talloc_free(pag); |
| 248 | return NULL; |
| 249 | } |
| 250 | wp = Encoding::write_packet_paging_request(pag_vec); |
| 251 | |
| 252 | /* loop until message is full */ |
| 253 | while (pag) { |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 254 | if (log_check_level(DRLCMAC, LOGL_DEBUG)) { |
| 255 | struct osmo_mobile_identity omi = {}; |
| 256 | char str[64]; |
| 257 | osmo_mobile_identity_decode(&omi, pag->identity_lv + 1, pag->identity_lv[0], true); |
| 258 | osmo_mobile_identity_to_str_buf(str, sizeof(str), &omi); |
| 259 | LOGP(DRLCMAC, LOGL_DEBUG, "Paging MI - %s\n", str); |
| 260 | } |
Vadim Yanitskiy | d71c566 | 2020-03-26 15:45:21 +0700 | [diff] [blame] | 261 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 262 | /* try to add paging */ |
Vadim Yanitskiy | ce16014 | 2020-03-26 16:18:17 +0700 | [diff] [blame] | 263 | if ((pag->identity_lv[1] & GSM_MI_TYPE_MASK) == GSM_MI_TYPE_TMSI) { |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 264 | /* TMSI */ |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 265 | len = 1 + 1 + 1 + 32 + 2 + 1; |
| 266 | if (pag->identity_lv[0] != 5) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 267 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, |
| 268 | "TMSI paging with MI != 5 octets!\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 269 | goto continue_next; |
| 270 | } |
| 271 | } else { |
| 272 | /* MI */ |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 273 | len = 1 + 1 + 1 + 4 + (pag->identity_lv[0]<<3) + 2 + 1; |
| 274 | if (pag->identity_lv[0] > 8) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 275 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, |
| 276 | "Paging with MI > 8 octets!\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 277 | goto continue_next; |
| 278 | } |
| 279 | } |
| 280 | if (wp + len > 184) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 281 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, |
| 282 | "- Does not fit, so schedule next time\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 283 | /* put back paging record, because does not fit */ |
Pau Espin Pedrol | 7d3ee9e | 2020-11-23 16:04:02 +0100 | [diff] [blame] | 284 | llist_add(&pag->list, &paging_list); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | Encoding::write_repeated_page_info(pag_vec, wp, pag->identity_lv[0], |
| 288 | pag->identity_lv + 1, pag->chan_needed); |
| 289 | |
| 290 | continue_next: |
| 291 | talloc_free(pag); |
| 292 | pag = dequeue_paging(); |
| 293 | } |
| 294 | |
| 295 | bitvec_pack(pag_vec, msgb_put(msg, 23)); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 296 | mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t); |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 297 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Paging Request +++++++++++++++++++++++++\n"); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 298 | rc = decode_gsm_rlcmac_downlink(pag_vec, mac_control_block); |
| 299 | if (rc < 0) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 300 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, "Decoding of Downlink Packet Paging Request failed (%d): %s\n", |
Pau Espin Pedrol | 9c4f9ff | 2020-11-23 16:36:42 +0100 | [diff] [blame] | 301 | rc, osmo_hexdump(msgb_data(msg), msgb_length(msg))); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 302 | goto free_ret; |
| 303 | } |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 304 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "------------------------- TX : Packet Paging Request -------------------------\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 305 | bitvec_free(pag_vec); |
| 306 | talloc_free(mac_control_block); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 307 | return msg; |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 308 | |
| 309 | free_ret: |
| 310 | bitvec_free(pag_vec); |
| 311 | talloc_free(mac_control_block); |
| 312 | msgb_free(msg); |
| 313 | return NULL; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 314 | } |
| 315 | |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 316 | bool gprs_rlcmac_pdch::add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 317 | { |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 318 | int rc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 319 | struct gprs_rlcmac_paging *pag = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_paging); |
| 320 | if (!pag) |
| 321 | return false; |
| 322 | |
| 323 | pag->chan_needed = chan_needed; |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 324 | rc = osmo_mobile_identity_encode_buf(pag->identity_lv + 1, sizeof(pag->identity_lv) - 1, mi, true); |
| 325 | if (rc <= 0) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 326 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, "Cannot encode Mobile Identity (rc=%d)\n", rc); |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 327 | talloc_free(pag); |
| 328 | return false; |
| 329 | } |
| 330 | pag->identity_lv[0] = rc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 331 | |
| 332 | llist_add(&pag->list, &paging_list); |
| 333 | |
| 334 | return true; |
| 335 | } |
| 336 | |
| 337 | void gprs_rlcmac_pdch::rcv_control_ack(Packet_Control_Acknowledgement_t *packet, uint32_t fn) |
| 338 | { |
| 339 | struct gprs_rlcmac_tbf *tbf, *new_tbf; |
| 340 | uint32_t tlli = packet->TLLI; |
Pau Espin Pedrol | ab17890 | 2021-06-22 22:15:20 +0200 | [diff] [blame] | 341 | GprsMs *ms; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 342 | gprs_rlcmac_ul_tbf *ul_tbf; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 343 | enum pdch_ulc_tbf_poll_reason reason; |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 344 | struct pdch_ulc_node *poll; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 345 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 346 | poll = pdch_ulc_get_node(ulc, fn); |
Pau Espin Pedrol | e9db5c7 | 2021-09-28 16:38:05 +0200 | [diff] [blame] | 347 | if (!poll || poll->type != PDCH_ULC_NODE_TBF_POLL) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 348 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "PACKET CONTROL ACK with " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 349 | "unknown FN=%u TLLI=0x%08x (TRX %d TS %d)\n", |
| 350 | fn, tlli, trx_no(), ts_no); |
Pau Espin Pedrol | ab17890 | 2021-06-22 22:15:20 +0200 | [diff] [blame] | 351 | ms = bts_ms_by_tlli(bts(), tlli, GSM_RESERVED_TMSI); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 352 | if (ms) |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 353 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "PACKET CONTROL ACK with " |
| 354 | "unknown TBF corresponds to MS with IMSI %s, TA %d, " |
| 355 | "uTBF (TFI=%d, state=%s), dTBF (TFI=%d, state=%s)\n", |
| 356 | ms_imsi(ms), ms_ta(ms), |
| 357 | ms_ul_tbf(ms) ? ms_ul_tbf(ms)->tfi() : 0, |
| 358 | ms_ul_tbf(ms) ? ms_ul_tbf(ms)->state_name() : "None", |
| 359 | ms_dl_tbf(ms) ? ms_dl_tbf(ms)->tfi() : 0, |
| 360 | ms_dl_tbf(ms) ? ms_dl_tbf(ms)->state_name() : "None"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 361 | return; |
| 362 | } |
Pau Espin Pedrol | e9db5c7 | 2021-09-28 16:38:05 +0200 | [diff] [blame] | 363 | OSMO_ASSERT(poll->tbf_poll.poll_tbf); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 364 | tbf = poll->tbf_poll.poll_tbf; |
Pau Espin Pedrol | 86580e1 | 2021-03-29 18:15:30 +0200 | [diff] [blame] | 365 | reason = poll->tbf_poll.reason; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 366 | |
| 367 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 368 | tbf->n_reset(N3101); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 369 | |
Pau Espin Pedrol | 8abe13c | 2022-10-21 18:49:48 +0200 | [diff] [blame] | 370 | ms_update_announced_tlli(tbf->ms(), tlli); |
| 371 | /* Gather MS from TBF again, since it may be NULL or may have been merged during ms_update_announced_tlli */ |
Pau Espin Pedrol | ab17890 | 2021-06-22 22:15:20 +0200 | [diff] [blame] | 372 | ms = tbf->ms(); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 373 | |
Pau Espin Pedrol | c6e911c | 2021-06-07 18:13:23 +0200 | [diff] [blame] | 374 | LOGPTBF(tbf, LOGL_DEBUG, "FN=%" PRIu32 " Rx Packet Control Ack (reason=%s)\n", |
| 375 | fn, get_value_string(pdch_ulc_tbf_poll_reason_names, reason)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 376 | |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 377 | switch (reason) { |
| 378 | case PDCH_ULC_POLL_UL_ACK: |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 379 | ul_tbf = tbf_as_ul_tbf(tbf); |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 380 | OSMO_ASSERT(ul_tbf); |
| 381 | if (!tbf_ul_ack_exp_ctrl_ack(ul_tbf, fn, ts_no)) { |
| 382 | LOGPTBF(tbf, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_UL_ACK not expected!\n", |
| 383 | fn, ts_no, bts_current_frame_number(tbf->bts)); |
| 384 | return; |
| 385 | } |
Pau Espin Pedrol | 0dbf6f2 | 2021-10-11 18:08:25 +0200 | [diff] [blame] | 386 | pdch_ulc_release_fn(ulc, fn); |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 387 | osmo_fsm_inst_dispatch(ul_tbf->ul_ack_fsm.fi, TBF_UL_ACK_EV_RX_CTRL_ACK, NULL); |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 388 | /* We only set polling on final UL ACK/NACK, something is wrong... */ |
| 389 | if (tbf_state(tbf) == TBF_ST_FINISHED) |
| 390 | osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, TBF_EV_FINAL_UL_ACK_CONFIRMED, (void*)false); |
| 391 | /* ul_tbf is freed here! */ |
| 392 | else |
| 393 | LOGPTBFUL(ul_tbf, LOGL_ERROR, "Received POLL_UL_ACK for UL TBF in unexpected state!\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 394 | return; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 395 | |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 396 | case PDCH_ULC_POLL_UL_ASS: |
| 397 | if (!tbf->ul_ass_state_is(TBF_UL_ASS_WAIT_ACK)) { |
| 398 | LOGPTBF(tbf, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_UL_ASS not expected! state is %s\n", |
| 399 | fn, ts_no, bts_current_frame_number(tbf->bts), |
| 400 | osmo_fsm_inst_state_name(tbf_ul_ass_fi(tbf))); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 401 | return; |
| 402 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 403 | LOGPTBF(tbf, LOGL_DEBUG, "[DOWNLINK] UPLINK ASSIGNED\n"); |
Pau Espin Pedrol | 0dbf6f2 | 2021-10-11 18:08:25 +0200 | [diff] [blame] | 404 | pdch_ulc_release_fn(ulc, fn); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 405 | /* reset N3105 */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 406 | tbf->n_reset(N3105); |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 407 | osmo_fsm_inst_dispatch(tbf->ul_ass_fsm.fi, TBF_UL_ASS_EV_RX_ASS_CTRL_ACK, NULL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 408 | |
Pau Espin Pedrol | ab17890 | 2021-06-22 22:15:20 +0200 | [diff] [blame] | 409 | new_tbf = ms_ul_tbf(ms); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 410 | if (!new_tbf) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 411 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, "Got ACK, but UL " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 412 | "TBF is gone TLLI=0x%08x\n", tlli); |
| 413 | return; |
| 414 | } |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 415 | if (tbf->state_is(TBF_ST_WAIT_RELEASE) && |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 416 | tbf->direction == new_tbf->direction) |
| 417 | tbf_free(tbf); |
| 418 | |
Pau Espin Pedrol | 720e19e | 2021-07-22 19:56:37 +0200 | [diff] [blame] | 419 | osmo_fsm_inst_dispatch(new_tbf->state_fsm.fi, TBF_EV_ASSIGN_ACK_PACCH, NULL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 420 | /* there might be LLC packets waiting in the queue, but the DL |
| 421 | * TBF might have been released while the UL TBF has been |
| 422 | * established */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 423 | if (ms_need_dl_tbf(new_tbf->ms())) |
Pau Espin Pedrol | 091642a | 2022-10-28 18:01:31 +0200 | [diff] [blame] | 424 | ms_new_dl_tbf_assigned_on_pacch(new_tbf->ms(), new_tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 425 | return; |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 426 | |
| 427 | case PDCH_ULC_POLL_DL_ASS: |
| 428 | if (!tbf->dl_ass_state_is(TBF_DL_ASS_WAIT_ACK)) { |
| 429 | LOGPTBF(tbf, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_DL_ASS not expected! state is %s\n", |
| 430 | fn, ts_no, bts_current_frame_number(tbf->bts), |
| 431 | osmo_fsm_inst_state_name(tbf_dl_ass_fi(tbf))); |
| 432 | return; |
| 433 | } |
| 434 | LOGPTBF(tbf, LOGL_DEBUG, "[UPLINK] DOWNLINK ASSIGNED\n"); |
Pau Espin Pedrol | 0dbf6f2 | 2021-10-11 18:08:25 +0200 | [diff] [blame] | 435 | pdch_ulc_release_fn(ulc, fn); |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 436 | /* reset N3105 */ |
| 437 | tbf->n_reset(N3105); |
| 438 | osmo_fsm_inst_dispatch(tbf->dl_ass_fsm.fi, TBF_DL_ASS_EV_RX_ASS_CTRL_ACK, NULL); |
| 439 | |
| 440 | new_tbf = ms_dl_tbf(ms); |
| 441 | if (!new_tbf) { |
| 442 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, "Got ACK, but DL " |
| 443 | "TBF is gone TLLI=0x%08x\n", tlli); |
| 444 | return; |
| 445 | } |
| 446 | if (tbf->state_is(TBF_ST_WAIT_RELEASE) && |
| 447 | tbf->direction == new_tbf->direction) |
| 448 | tbf_free(tbf); |
| 449 | |
| 450 | osmo_fsm_inst_dispatch(new_tbf->state_fsm.fi, TBF_EV_ASSIGN_ACK_PACCH, NULL); |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 451 | return; |
| 452 | |
| 453 | case PDCH_ULC_POLL_CELL_CHG_CONTINUE: |
| 454 | if (!ms->nacc || !nacc_fsm_exp_ctrl_ack(ms->nacc, fn, ts_no)) { |
| 455 | LOGPTBF(tbf, LOGL_NOTICE, "FN=%d, TS=%d (curr FN %d): POLL_CELL_CHG_CONTINUE not expected!\n", |
| 456 | fn, ts_no, bts_current_frame_number(tbf->bts)); |
| 457 | return; |
| 458 | } |
Pau Espin Pedrol | 0dbf6f2 | 2021-10-11 18:08:25 +0200 | [diff] [blame] | 459 | pdch_ulc_release_fn(ulc, fn); |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 460 | osmo_fsm_inst_dispatch(ms->nacc->fi, NACC_EV_RX_CELL_CHG_CONTINUE_ACK, NULL); |
| 461 | /* Don't assume MS is no longer reachable (hence don't free) after this: TS 44.060 |
| 462 | * "When the mobile station receives the PACKET CELL CHANGE ORDER |
| 463 | * or the PACKET CELL CHANGE CONTINUE message the mobile station |
| 464 | * shall transmit a PACKET CONTROL ACKNOWLEDGMENT message in the |
| 465 | * specified uplink radio block if a valid RRBP field is |
| 466 | * received as part of the message; the mobile station _MAY_ then |
| 467 | * switch to a new cell." |
| 468 | */ |
| 469 | return; |
Pau Espin Pedrol | c8d2166 | 2021-09-28 13:27:51 +0200 | [diff] [blame] | 470 | |
| 471 | case PDCH_ULC_POLL_DL_ACK: |
| 472 | /* Handled in rcv_control_dl_ack_nack() upon receival of DL ACK/NACK as a response to our POLL. */ |
| 473 | return; |
| 474 | default: |
| 475 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, "FN=%" PRIu32 " " |
| 476 | "Error: received PACKET CONTROL ACK at no request (reason=%s)\n", fn, |
| 477 | get_value_string(pdch_ulc_tbf_poll_reason_names, reason)); |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 478 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 481 | void gprs_rlcmac_pdch::rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *ack_nack, uint32_t fn, struct pcu_l1_meas *meas) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 482 | { |
| 483 | int8_t tfi = 0; /* must be signed */ |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 484 | struct pdch_ulc_node *poll; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 485 | struct gprs_rlcmac_dl_tbf *tbf; |
| 486 | int rc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 487 | int num_blocks; |
| 488 | uint8_t bits_data[RLC_GPRS_WS/8]; |
| 489 | bitvec bits; |
| 490 | int bsn_begin, bsn_end; |
| 491 | char show_bits[RLC_GPRS_WS + 1]; |
| 492 | |
| 493 | tfi = ack_nack->DOWNLINK_TFI; |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 494 | poll = pdch_ulc_get_node(ulc, fn); |
Pau Espin Pedrol | 8318d9c | 2021-10-11 18:17:35 +0200 | [diff] [blame] | 495 | if (!poll || poll->type != PDCH_ULC_NODE_TBF_POLL || |
| 496 | poll->tbf_poll.reason != PDCH_ULC_POLL_DL_ACK) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 497 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "PACKET DOWNLINK ACK with " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 498 | "unknown FN=%u TFI=%d (TRX %d TS %d)\n", |
| 499 | fn, tfi, trx_no(), ts_no); |
| 500 | return; |
| 501 | } |
Pau Espin Pedrol | e9db5c7 | 2021-09-28 16:38:05 +0200 | [diff] [blame] | 502 | OSMO_ASSERT(poll->tbf_poll.poll_tbf); |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 503 | tbf = tbf_as_dl_tbf(poll->tbf_poll.poll_tbf); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 504 | if (tbf->tfi() != tfi) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 505 | LOGPTBFDL(tbf, LOGL_NOTICE, |
| 506 | "PACKET DOWNLINK ACK with wrong TFI=%d, ignoring!\n", tfi); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | |
| 510 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 511 | tbf->n_reset(N3101); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 512 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 513 | pdch_ulc_release_fn(ulc, fn); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 514 | |
| 515 | LOGPTBF(tbf, LOGL_DEBUG, "RX: [PCU <- BTS] Packet Downlink Ack/Nack\n"); |
| 516 | |
| 517 | bits.data = bits_data; |
| 518 | bits.data_len = sizeof(bits_data); |
| 519 | bits.cur_bit = 0; |
| 520 | |
| 521 | num_blocks = Decoding::decode_gprs_acknack_bits( |
| 522 | &ack_nack->Ack_Nack_Description, &bits, |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 523 | &bsn_begin, &bsn_end, static_cast<gprs_rlc_dl_window *>(tbf->window())); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 524 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 525 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 526 | "Got GPRS DL ACK bitmap: SSN: %d, BSN %d to %d - 1 (%d blocks), " |
| 527 | "\"%s\"\n", |
| 528 | ack_nack->Ack_Nack_Description.STARTING_SEQUENCE_NUMBER, |
| 529 | bsn_begin, bsn_end, num_blocks, |
| 530 | (Decoding::extract_rbb(&bits, show_bits), show_bits)); |
| 531 | |
| 532 | rc = tbf->rcvd_dl_ack( |
| 533 | ack_nack->Ack_Nack_Description.FINAL_ACK_INDICATION, |
| 534 | bsn_begin, &bits); |
| 535 | if (rc == 1) { |
| 536 | tbf_free(tbf); |
| 537 | return; |
| 538 | } |
| 539 | /* check for channel request */ |
| 540 | if (ack_nack->Exist_Channel_Request_Description) |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 541 | sched_ul_ass_or_rej(bts(), tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 542 | |
| 543 | /* get measurements */ |
| 544 | if (tbf->ms()) { |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 545 | get_meas(meas, &ack_nack->Channel_Quality_Report); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 546 | ms_update_l1_meas(tbf->ms(), meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 550 | void gprs_rlcmac_pdch::rcv_control_egprs_dl_ack_nack(EGPRS_PD_AckNack_t *ack_nack, uint32_t fn, struct pcu_l1_meas *meas) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 551 | { |
| 552 | int8_t tfi = 0; /* must be signed */ |
| 553 | struct gprs_rlcmac_dl_tbf *tbf; |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 554 | struct pdch_ulc_node *poll; |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 555 | gprs_rlc_dl_window *window; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 556 | int rc; |
| 557 | int num_blocks; |
| 558 | uint8_t bits_data[RLC_EGPRS_MAX_WS/8]; |
| 559 | char show_bits[RLC_EGPRS_MAX_WS + 1]; |
| 560 | bitvec bits; |
| 561 | int bsn_begin, bsn_end; |
| 562 | |
| 563 | tfi = ack_nack->DOWNLINK_TFI; |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 564 | poll = pdch_ulc_get_node(ulc, fn); |
Pau Espin Pedrol | 8318d9c | 2021-10-11 18:17:35 +0200 | [diff] [blame] | 565 | if (!poll || poll->type != PDCH_ULC_NODE_TBF_POLL || |
| 566 | poll->tbf_poll.reason != PDCH_ULC_POLL_DL_ACK) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 567 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "EGPRS PACKET DOWNLINK ACK with " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 568 | "unknown FN=%u TFI=%d (TRX %d TS %d)\n", |
| 569 | fn, tfi, trx_no(), ts_no); |
| 570 | return; |
| 571 | } |
Pau Espin Pedrol | e9db5c7 | 2021-09-28 16:38:05 +0200 | [diff] [blame] | 572 | OSMO_ASSERT(poll->tbf_poll.poll_tbf); |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 573 | tbf = tbf_as_dl_tbf(poll->tbf_poll.poll_tbf); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 574 | if (tbf->tfi() != tfi) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 575 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "EGPRS PACKET DOWNLINK ACK with " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 576 | "wrong TFI=%d, ignoring!\n", tfi); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 581 | tbf->n_reset(N3101); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 582 | pdch_ulc_release_fn(ulc, fn); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 583 | |
| 584 | LOGPTBF(tbf, LOGL_DEBUG, |
| 585 | "RX: [PCU <- BTS] EGPRS Packet Downlink Ack/Nack\n"); |
| 586 | |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 587 | window = static_cast<gprs_rlc_dl_window *>(tbf->window()); |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 588 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "EGPRS ACK/NACK: " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 589 | "ut: %d, final: %d, bow: %d, eow: %d, ssn: %d, have_crbb: %d, " |
| 590 | "urbb_len:%d, %p, %p, %d, %d, win: %d-%d, urbb: %s\n", |
| 591 | (int)ack_nack->EGPRS_AckNack.UnionType, |
| 592 | (int)ack_nack->EGPRS_AckNack.Desc.FINAL_ACK_INDICATION, |
| 593 | (int)ack_nack->EGPRS_AckNack.Desc.BEGINNING_OF_WINDOW, |
| 594 | (int)ack_nack->EGPRS_AckNack.Desc.END_OF_WINDOW, |
| 595 | (int)ack_nack->EGPRS_AckNack.Desc.STARTING_SEQUENCE_NUMBER, |
| 596 | (int)ack_nack->EGPRS_AckNack.Desc.Exist_CRBB, |
| 597 | (int)ack_nack->EGPRS_AckNack.Desc.URBB_LENGTH, |
| 598 | (void *)&ack_nack->EGPRS_AckNack.UnionType, |
| 599 | (void *)&ack_nack->EGPRS_AckNack.Desc, |
| 600 | (int)offsetof(EGPRS_AckNack_t, Desc), |
| 601 | (int)offsetof(EGPRS_AckNack_w_len_t, Desc), |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 602 | window->v_a(), |
| 603 | window->v_s(), |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 604 | osmo_hexdump((const uint8_t *)&ack_nack->EGPRS_AckNack.Desc.URBB, |
| 605 | sizeof(ack_nack->EGPRS_AckNack.Desc.URBB))); |
| 606 | |
| 607 | bits.data = bits_data; |
| 608 | bits.data_len = sizeof(bits_data); |
| 609 | bits.cur_bit = 0; |
| 610 | |
| 611 | num_blocks = Decoding::decode_egprs_acknack_bits( |
| 612 | &ack_nack->EGPRS_AckNack.Desc, &bits, |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 613 | &bsn_begin, &bsn_end, window); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 614 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 615 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 616 | "Got EGPRS DL ACK bitmap: SSN: %d, BSN %d to %d - 1 (%d blocks), " |
| 617 | "\"%s\"\n", |
| 618 | ack_nack->EGPRS_AckNack.Desc.STARTING_SEQUENCE_NUMBER, |
| 619 | bsn_begin, bsn_end, num_blocks, |
| 620 | (Decoding::extract_rbb(&bits, show_bits), show_bits) |
| 621 | ); |
| 622 | |
| 623 | rc = tbf->rcvd_dl_ack( |
| 624 | ack_nack->EGPRS_AckNack.Desc.FINAL_ACK_INDICATION, |
| 625 | bsn_begin, &bits); |
| 626 | if (rc == 1) { |
| 627 | tbf_free(tbf); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | /* check for channel request */ |
| 632 | if (ack_nack->Exist_ChannelRequestDescription) |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 633 | sched_ul_ass_or_rej(bts(), tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 634 | |
| 635 | /* get measurements */ |
| 636 | if (tbf->ms()) { |
| 637 | /* TODO: Implement Measurements parsing for EGPRS */ |
| 638 | /* |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 639 | get_meas(meas, &ack_nack->Channel_Quality_Report); |
| 640 | tbf->ms()->update_l1_meas(meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 641 | */ |
| 642 | } |
| 643 | } |
| 644 | |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 645 | void gprs_rlcmac_pdch::rcv_resource_request(Packet_Resource_Request_t *request, uint32_t fn, struct pcu_l1_meas *meas) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 646 | { |
| 647 | struct gprs_rlcmac_sba *sba; |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 648 | int rc; |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 649 | struct gprs_rlcmac_bts *bts = trx->bts; |
Pau Espin Pedrol | 1e81b2e | 2022-10-28 15:30:39 +0200 | [diff] [blame] | 650 | struct pdch_ulc_node *item; |
| 651 | |
| 652 | if (!(item = pdch_ulc_get_node(ulc, fn))) { |
| 653 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "FN=%u PKT RESOURCE REQ: " |
| 654 | "UL block not reserved\n", fn); |
| 655 | return; |
| 656 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 657 | |
| 658 | if (request->ID.UnionType) { |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 659 | struct gprs_rlcmac_ul_tbf *ul_tbf = NULL; |
Pau Espin Pedrol | 677bebb | 2022-10-31 13:56:33 +0100 | [diff] [blame^] | 660 | struct gprs_rlcmac_dl_tbf *dl_tbf = NULL; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 661 | uint32_t tlli = request->ID.u.TLLI; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 662 | |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 663 | GprsMs *ms = bts_ms_by_tlli(bts, tlli, GSM_RESERVED_TMSI); |
Pau Espin Pedrol | ce60011 | 2020-05-12 19:20:10 +0200 | [diff] [blame] | 664 | if (!ms) { |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 665 | ms = bts_alloc_ms(bts, 0, 0); /* ms class updated later */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 666 | ms_set_tlli(ms, tlli); |
Pau Espin Pedrol | ce60011 | 2020-05-12 19:20:10 +0200 | [diff] [blame] | 667 | } |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 668 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 669 | /* Keep the ms, even if it gets idle temporarily */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 670 | ms_ref(ms); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 671 | |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 672 | switch (item->type) { |
Pau Espin Pedrol | 201dbe0 | 2021-10-11 19:04:24 +0200 | [diff] [blame] | 673 | case PDCH_ULC_NODE_TBF_USF: |
| 674 | /* Is it actually valid for an MS to send a PKT Res Req during USF? */ |
| 675 | ul_tbf = item->tbf_usf.ul_tbf; |
| 676 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "FN=%u PKT RESOURCE REQ: " |
| 677 | "Unexpectedly received, waiting USF of %s\n", |
| 678 | fn, tbf_name(item->tbf_usf.ul_tbf)); |
| 679 | /* Ignore it, let common path expire related ULC entry */ |
| 680 | goto return_unref; |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 681 | case PDCH_ULC_NODE_SBA: |
| 682 | sba = item->sba.sba; |
| 683 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "FN=%u PKT RESOURCE REQ: " |
| 684 | "MS requests UL TBF throguh SBA\n", fn); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 685 | ms_set_ta(ms, sba->ta); |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 686 | sba_free(sba); |
Pau Espin Pedrol | ace3b1b | 2021-11-10 16:11:17 +0100 | [diff] [blame] | 687 | /* If MS identified by TLLI sent us a PktResReq through SBA, it means it came |
| 688 | * from CCCH, so it's for sure not using previous UL |
| 689 | * TBF; drop it if it still exits on our end: */ |
| 690 | if ((ul_tbf = ms_ul_tbf(ms))) { |
| 691 | /* Get rid of previous finished UL TBF before providing a new one */ |
| 692 | LOGPTBFUL(ul_tbf, LOGL_NOTICE, |
| 693 | "Got PACKET RESOURCE REQ while TBF not finished, killing pending UL TBF\n"); |
| 694 | tbf_free(ul_tbf); |
| 695 | ul_tbf = NULL; |
| 696 | } |
Pau Espin Pedrol | 677bebb | 2022-10-31 13:56:33 +0100 | [diff] [blame^] | 697 | /* Similarly, it is for sure not using any DL-TBF. We |
| 698 | * still may have some because we were trying to assign a |
| 699 | * DL-TBF over CCCH when the MS proactively requested for a |
| 700 | * UL-TBF. In that case we'll need to re-assigna new DL-TBF through PACCH when contention resolution is done: */ |
| 701 | if ((dl_tbf = ms_dl_tbf(ms))) { |
| 702 | /* Get rid of previous finished UL TBF before providing a new one */ |
| 703 | LOGPTBFDL(dl_tbf, LOGL_NOTICE, |
| 704 | "Got PACKET RESOURCE REQ while DL-TBF pending, killing it\n"); |
| 705 | tbf_free(dl_tbf); |
| 706 | dl_tbf = NULL; |
| 707 | } |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 708 | break; |
| 709 | case PDCH_ULC_NODE_TBF_POLL: |
| 710 | if (item->tbf_poll.poll_tbf->direction != GPRS_RLCMAC_UL_TBF) { |
| 711 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "FN=%u PKT RESOURCE REQ: " |
| 712 | "Unexpectedly received for DL TBF %s\n", fn, |
| 713 | tbf_name(item->tbf_poll.poll_tbf)); |
| 714 | /* let common path expire the poll */ |
| 715 | goto return_unref; |
| 716 | } |
Pau Espin Pedrol | 36ada89 | 2022-10-27 16:08:46 +0200 | [diff] [blame] | 717 | ul_tbf = tbf_as_ul_tbf(item->tbf_poll.poll_tbf); |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 718 | if (item->tbf_poll.reason != PDCH_ULC_POLL_UL_ACK) { |
| 719 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "FN=%u PKT RESOURCE REQ: " |
| 720 | "Unexpectedly received, waiting for poll reason %d\n", |
| 721 | fn, item->tbf_poll.reason); |
| 722 | /* let common path expire the poll */ |
| 723 | goto return_unref; |
| 724 | } |
| 725 | if (ul_tbf != ms_ul_tbf(ms)) { |
| 726 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "FN=%u PKT RESOURCE REQ: " |
| 727 | "Unexpected TLLI 0x%08x received vs exp 0x%08x\n", |
| 728 | fn, tlli, ul_tbf->tlli()); |
| 729 | /* let common path expire the poll */ |
| 730 | goto return_unref; |
| 731 | } |
| 732 | /* 3GPP TS 44.060 $ 9.3.3.3 */ |
| 733 | LOGPTBFUL(ul_tbf, LOGL_DEBUG, "FN=%u PKT RESOURCE REQ: " |
| 734 | "MS requests reuse of finished UL TBF in RRBP " |
| 735 | "block of final UL ACK/NACK\n", fn); |
| 736 | ul_tbf->n_reset(N3103); |
| 737 | pdch_ulc_release_node(ulc, item); |
Pau Espin Pedrol | 22b26d8 | 2022-10-26 15:44:14 +0200 | [diff] [blame] | 738 | rc = osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, TBF_EV_FINAL_UL_ACK_CONFIRMED, (void*)true); |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 739 | if (rc) { |
| 740 | /* FSM failed handling, get rid of previous finished UL TBF before providing a new one */ |
| 741 | LOGPTBFUL(ul_tbf, LOGL_NOTICE, |
| 742 | "Got PACKET RESOURCE REQ while TBF not finished, killing pending UL TBF\n"); |
| 743 | tbf_free(ul_tbf); |
| 744 | } /* else: ul_tbf has been freed by state_fsm */ |
| 745 | ul_tbf = NULL; |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 746 | break; |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 747 | default: |
| 748 | OSMO_ASSERT(0); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 749 | } |
Pau Espin Pedrol | 4347997 | 2021-04-22 19:18:13 +0200 | [diff] [blame] | 750 | |
Pau Espin Pedrol | 7a2b65e | 2021-10-11 19:18:13 +0200 | [diff] [blame] | 751 | /* Here ul_tbf is NULL: |
| 752 | * - SBA case: no previous TBF) and in |
| 753 | * - POLL case: PktResReq is a final ACk confirmation and ul_tbf was freed |
| 754 | */ |
Pau Espin Pedrol | 9e7361a | 2020-07-08 17:35:12 +0200 | [diff] [blame] | 755 | |
Pau Espin Pedrol | e50ce6e | 2020-03-23 18:49:16 +0100 | [diff] [blame] | 756 | if (request->Exist_MS_Radio_Access_capability2) { |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 757 | uint8_t ms_class, egprs_ms_class; |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 758 | ms_class = get_ms_class_by_capability(&request->MS_Radio_Access_capability2); |
| 759 | egprs_ms_class = get_egprs_ms_class_by_capability(&request->MS_Radio_Access_capability2); |
Pau Espin Pedrol | bcb226d | 2020-07-08 17:18:22 +0200 | [diff] [blame] | 760 | if (ms_class) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 761 | ms_set_ms_class(ms, ms_class); |
Pau Espin Pedrol | bcb226d | 2020-07-08 17:18:22 +0200 | [diff] [blame] | 762 | if (egprs_ms_class) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 763 | ms_set_egprs_ms_class(ms, egprs_ms_class); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 764 | } |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 765 | |
Pau Espin Pedrol | 3a7af57 | 2022-10-28 16:05:32 +0200 | [diff] [blame] | 766 | /* get measurements */ |
| 767 | get_meas(meas, request); |
| 768 | ms_update_l1_meas(ms, meas); |
| 769 | |
Pau Espin Pedrol | 9438613 | 2022-10-28 19:50:09 +0200 | [diff] [blame] | 770 | ul_tbf = ms_new_ul_tbf_assigned_pacch(ms, trx_no()); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 771 | if (!ul_tbf) { |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 772 | handle_tbf_reject(bts, ms, trx_no(), ts_no); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 773 | goto return_unref; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 774 | } |
| 775 | |
Pau Espin Pedrol | ffe998c | 2021-10-12 19:32:28 +0200 | [diff] [blame] | 776 | /* Set control TS to the TS where this PktResReq was received, |
| 777 | * which in practice happens to be the control_ts from the |
| 778 | * previous UL-TBF or SBA. When CTRL ACK is received as RRBP of the Pkt |
| 779 | * UL Ass scheduled below, then TBF_EV_ASSIGN_ACK_PACCH will be |
| 780 | * sent to tbf_fsm which will call tbf_assign_control_ts(), |
| 781 | * effectively setting back control_ts to |
| 782 | * tbf->initial_common_ts. */ |
Pau Espin Pedrol | 715aeb4 | 2021-11-10 17:21:41 +0100 | [diff] [blame] | 783 | LOGPTBF(ul_tbf, LOGL_INFO, "change control TS %d -> %d until assignment is complete.\n", |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 784 | ul_tbf->control_ts, ts_no); |
| 785 | |
| 786 | ul_tbf->control_ts = ts_no; |
| 787 | /* schedule uplink assignment */ |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 788 | osmo_fsm_inst_dispatch(ul_tbf->ul_ass_fsm.fi, TBF_UL_ASS_EV_SCHED_ASS, NULL); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 789 | return_unref: |
| 790 | ms_unref(ms); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 791 | return; |
| 792 | } |
| 793 | |
| 794 | if (request->ID.u.Global_TFI.UnionType) { |
| 795 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 796 | int8_t tfi = request->ID.u.Global_TFI.u.DOWNLINK_TFI; |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 797 | dl_tbf = bts_dl_tbf_by_tfi(bts, tfi, trx_no(), ts_no); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 798 | if (!dl_tbf) { |
Thorsten Alteholz | 8bb7904 | 2018-10-06 10:42:58 +0200 | [diff] [blame] | 799 | LOGP(DRLCMAC, LOGL_NOTICE, "PACKET RESOURCE REQ unknown downlink TFI=%d\n", tfi); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | LOGPTBFDL(dl_tbf, LOGL_ERROR, |
| 803 | "RX: [PCU <- BTS] FIXME: Packet resource request\n"); |
| 804 | |
| 805 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 806 | dl_tbf->n_reset(N3101); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 807 | } else { |
| 808 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
| 809 | int8_t tfi = request->ID.u.Global_TFI.u.UPLINK_TFI; |
Pau Espin Pedrol | 10b2915 | 2021-11-02 18:45:04 +0100 | [diff] [blame] | 810 | ul_tbf = bts_ul_tbf_by_tfi(bts, tfi, trx_no(), ts_no); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 811 | if (!ul_tbf) { |
Thorsten Alteholz | 8bb7904 | 2018-10-06 10:42:58 +0200 | [diff] [blame] | 812 | LOGP(DRLCMAC, LOGL_NOTICE, "PACKET RESOURCE REQ unknown uplink TFI=%d\n", tfi); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 813 | return; |
| 814 | } |
| 815 | LOGPTBFUL(ul_tbf, LOGL_ERROR, |
| 816 | "RX: [PCU <- BTS] FIXME: Packet resource request\n"); |
| 817 | |
| 818 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 819 | ul_tbf->n_reset(N3101); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
| 823 | void gprs_rlcmac_pdch::rcv_measurement_report(Packet_Measurement_Report_t *report, uint32_t fn) |
| 824 | { |
Pau Espin Pedrol | b69928c | 2020-08-18 20:29:40 +0200 | [diff] [blame] | 825 | struct gprs_rlcmac_sba *sba; |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 826 | struct pdch_ulc_node *poll; |
Pau Espin Pedrol | b69928c | 2020-08-18 20:29:40 +0200 | [diff] [blame] | 827 | GprsMs *ms; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 828 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 829 | ms = bts_ms_by_tlli(bts(), report->TLLI, GSM_RESERVED_TMSI); |
Pau Espin Pedrol | b69928c | 2020-08-18 20:29:40 +0200 | [diff] [blame] | 830 | if (!ms) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 831 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "MS send measurement " |
| 832 | "but TLLI 0x%08x is unknown\n", report->TLLI); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 833 | ms = bts_alloc_ms(bts(), 0, 0); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 834 | ms_set_tlli(ms, report->TLLI); |
Pau Espin Pedrol | b69928c | 2020-08-18 20:29:40 +0200 | [diff] [blame] | 835 | } |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 836 | if ((poll = pdch_ulc_get_node(ulc, fn))) { |
| 837 | switch (poll->type) { |
| 838 | case PDCH_ULC_NODE_TBF_USF: |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 839 | pdch_ulc_release_fn(ulc, fn); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 840 | break; |
| 841 | case PDCH_ULC_NODE_TBF_POLL: |
| 842 | LOGPDCH(this, DRLCMAC, LOGL_INFO, "FN=%" PRIu32 " Rx Meas Report " |
| 843 | "on RRBP POLL, this probably means a DL/CTRL ACK/NACk will " |
| 844 | "need to be polled again later\n", fn); |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 845 | pdch_ulc_release_fn(ulc, fn); |
| 846 | break; |
| 847 | case PDCH_ULC_NODE_SBA: |
| 848 | sba = poll->sba.sba; |
| 849 | ms_set_ta(ms, sba->ta); |
| 850 | sba_free(sba); |
| 851 | break; |
| 852 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 853 | } |
Pau Espin Pedrol | b69928c | 2020-08-18 20:29:40 +0200 | [diff] [blame] | 854 | gprs_rlcmac_meas_rep(ms, report); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 857 | void gprs_rlcmac_pdch::rcv_cell_change_notification(Packet_Cell_Change_Notification_t *notif, |
| 858 | uint32_t fn, struct pcu_l1_meas *meas) |
| 859 | { |
| 860 | GprsMs *ms; |
| 861 | |
| 862 | bts_do_rate_ctr_inc(bts(), CTR_PKT_CELL_CHG_NOTIFICATION); |
| 863 | |
| 864 | if (notif->Global_TFI.UnionType == 0) { |
| 865 | struct gprs_rlcmac_ul_tbf *ul_tbf = ul_tbf_by_tfi(notif->Global_TFI.u.UPLINK_TFI); |
| 866 | if (!ul_tbf) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 867 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "UL TBF TFI=0x%2x not found\n", notif->Global_TFI.u.UPLINK_TFI); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 868 | return; |
| 869 | } |
| 870 | ms = ul_tbf->ms(); |
| 871 | } else if (notif->Global_TFI.UnionType == 1) { |
| 872 | struct gprs_rlcmac_dl_tbf *dl_tbf = dl_tbf_by_tfi(notif->Global_TFI.u.DOWNLINK_TFI); |
| 873 | if (!dl_tbf) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 874 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "DL TBF TFI=0x%2x not found\n", notif->Global_TFI.u.DOWNLINK_TFI); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 875 | return; |
| 876 | } |
| 877 | ms = dl_tbf->ms(); |
| 878 | } else { OSMO_ASSERT(0); } |
| 879 | |
Pau Espin Pedrol | 9a6f0b1 | 2021-03-24 14:05:04 +0100 | [diff] [blame] | 880 | pdch_ulc_release_fn(ulc, fn); |
| 881 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 882 | ms_update_l1_meas(ms, meas); |
| 883 | ms_nacc_start(ms, notif); |
| 884 | } |
| 885 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 886 | /* Received Uplink RLC control block. */ |
Pau Espin Pedrol | 812d466 | 2019-09-25 13:35:11 +0200 | [diff] [blame] | 887 | int gprs_rlcmac_pdch::rcv_control_block(const uint8_t *data, uint8_t data_len, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 888 | uint32_t fn, struct pcu_l1_meas *meas, enum CodingScheme cs) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 889 | { |
Pau Espin Pedrol | 812d466 | 2019-09-25 13:35:11 +0200 | [diff] [blame] | 890 | bitvec *rlc_block; |
| 891 | RlcMacUplink_t *ul_control_block; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 892 | unsigned len = mcs_max_bytes_ul(cs); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 893 | int rc; |
Pau Espin Pedrol | 812d466 | 2019-09-25 13:35:11 +0200 | [diff] [blame] | 894 | |
| 895 | if (!(rlc_block = bitvec_alloc(len, tall_pcu_ctx))) |
| 896 | return -ENOMEM; |
| 897 | bitvec_unpack(rlc_block, data); |
| 898 | ul_control_block = (RlcMacUplink_t *)talloc_zero(tall_pcu_ctx, RlcMacUplink_t); |
| 899 | |
Pau Espin Pedrol | 68bfdff | 2021-03-09 20:19:51 +0100 | [diff] [blame] | 900 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "FN=%u +++++++++++++++++++++++++ RX : Uplink Control Block +++++++++++++++++++++++++\n", fn); |
Keith | 6fd8ffb | 2020-03-05 19:48:24 -0600 | [diff] [blame] | 901 | |
Keith | 2b6acd8 | 2020-03-26 16:33:59 -0500 | [diff] [blame] | 902 | rc = decode_gsm_rlcmac_uplink(rlc_block, ul_control_block); |
Keith | 6fd8ffb | 2020-03-05 19:48:24 -0600 | [diff] [blame] | 903 | if (ul_control_block->u.MESSAGE_TYPE == MT_PACKET_UPLINK_DUMMY_CONTROL_BLOCK) |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 904 | bts_send_gsmtap_meas(bts(), PCU_GSMTAP_C_UL_DUMMY, true, trx_no(), ts_no, GSMTAP_CHANNEL_PACCH, fn, data, data_len, meas); |
Keith | 6fd8ffb | 2020-03-05 19:48:24 -0600 | [diff] [blame] | 905 | else |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 906 | bts_send_gsmtap_meas(bts(), PCU_GSMTAP_C_UL_CTRL, true, trx_no(), ts_no, GSMTAP_CHANNEL_PACCH, fn, data, data_len, meas); |
Keith | 6fd8ffb | 2020-03-05 19:48:24 -0600 | [diff] [blame] | 907 | |
Pau Espin Pedrol | 16705a4 | 2020-10-27 10:24:57 +0100 | [diff] [blame] | 908 | if (rc < 0) { |
Pau Espin Pedrol | 68bfdff | 2021-03-09 20:19:51 +0100 | [diff] [blame] | 909 | LOGPDCH(this, DRLCMACUL, LOGL_ERROR, "FN=%u Dropping Uplink Control Block " |
| 910 | "with invalid content, decode failed: %d)\n", fn, rc); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 911 | goto free_ret; |
| 912 | } |
Pau Espin Pedrol | 68bfdff | 2021-03-09 20:19:51 +0100 | [diff] [blame] | 913 | LOGPDCH(this, DRLCMAC, LOGL_DEBUG, "FN=%u ------------------------- RX : Uplink Control Block -------------------------\n", fn); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 914 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 915 | bts_do_rate_ctr_inc(bts(), CTR_RLC_RECV_CONTROL); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 916 | switch (ul_control_block->u.MESSAGE_TYPE) { |
| 917 | case MT_PACKET_CONTROL_ACK: |
| 918 | rcv_control_ack(&ul_control_block->u.Packet_Control_Acknowledgement, fn); |
| 919 | break; |
| 920 | case MT_PACKET_DOWNLINK_ACK_NACK: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 921 | rcv_control_dl_ack_nack(&ul_control_block->u.Packet_Downlink_Ack_Nack, fn, meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 922 | break; |
| 923 | case MT_EGPRS_PACKET_DOWNLINK_ACK_NACK: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 924 | rcv_control_egprs_dl_ack_nack(&ul_control_block->u.Egprs_Packet_Downlink_Ack_Nack, fn, meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 925 | break; |
| 926 | case MT_PACKET_RESOURCE_REQUEST: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 927 | rcv_resource_request(&ul_control_block->u.Packet_Resource_Request, fn, meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 928 | break; |
| 929 | case MT_PACKET_MEASUREMENT_REPORT: |
| 930 | rcv_measurement_report(&ul_control_block->u.Packet_Measurement_Report, fn); |
| 931 | break; |
| 932 | case MT_PACKET_UPLINK_DUMMY_CONTROL_BLOCK: |
| 933 | /* ignoring it. change the SI to not force sending these? */ |
| 934 | break; |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 935 | case MT_PACKET_CELL_CHANGE_NOTIFICATION: |
| 936 | rcv_cell_change_notification(&ul_control_block->u.Packet_Cell_Change_Notification, fn, meas); |
| 937 | break; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 938 | default: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 939 | bts_do_rate_ctr_inc(bts(), CTR_DECODE_ERRORS); |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 940 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, |
Pau Espin Pedrol | 68bfdff | 2021-03-09 20:19:51 +0100 | [diff] [blame] | 941 | "FN=%u RX: [PCU <- BTS] unknown control block(%d) received\n", |
| 942 | fn, ul_control_block->u.MESSAGE_TYPE); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 943 | } |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 944 | |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 945 | free_ret: |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 946 | talloc_free(ul_control_block); |
Pau Espin Pedrol | 812d466 | 2019-09-25 13:35:11 +0200 | [diff] [blame] | 947 | bitvec_free(rlc_block); |
Pau Espin Pedrol | 5e300ce | 2020-02-03 17:18:03 +0100 | [diff] [blame] | 948 | return rc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /* received RLC/MAC block from L1 */ |
| 952 | int gprs_rlcmac_pdch::rcv_block(uint8_t *data, uint8_t len, uint32_t fn, |
| 953 | struct pcu_l1_meas *meas) |
| 954 | { |
Pau Espin Pedrol | 3061711 | 2021-03-05 18:59:05 +0100 | [diff] [blame] | 955 | /* First of all, update TDMA clock: */ |
| 956 | bts_set_current_frame_number(trx->bts, fn); |
| 957 | |
Pau Espin Pedrol | 3cba94d | 2021-03-05 18:54:01 +0100 | [diff] [blame] | 958 | /* No successfully decoded UL block was received during this FN: */ |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 959 | if (len == 0) |
Pau Espin Pedrol | 3cba94d | 2021-03-05 18:54:01 +0100 | [diff] [blame] | 960 | return 0; |
Pau Espin Pedrol | 3cba94d | 2021-03-05 18:54:01 +0100 | [diff] [blame] | 961 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 962 | enum CodingScheme cs = mcs_get_by_size_ul(len); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 963 | if (!cs) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 964 | bts_do_rate_ctr_inc(bts(), CTR_DECODE_ERRORS); |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 965 | LOGPDCH(this, DRLCMACUL, LOGL_ERROR, "Dropping data block with invalid " |
| 966 | "length %d: %s\n", len, osmo_hexdump(data, len)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 967 | return -EINVAL; |
| 968 | } |
| 969 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 970 | bts_do_rate_ctr_add(bts(), CTR_RLC_UL_BYTES, len); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 971 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 972 | LOGPDCH(this, DRLCMACUL, LOGL_DEBUG, "Got RLC block, coding scheme: %s, " |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 973 | "length: %d (%d))\n", mcs_name(cs), len, mcs_used_size_ul(cs)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 974 | |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 975 | if (mcs_is_gprs(cs)) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 976 | return rcv_block_gprs(data, len, fn, meas, cs); |
| 977 | |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 978 | if (mcs_is_edge(cs)) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 979 | return rcv_data_block(data, len, fn, meas, cs); |
| 980 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 981 | bts_do_rate_ctr_inc(bts(), CTR_DECODE_ERRORS); |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 982 | LOGPDCH(this, DRLCMACUL, LOGL_ERROR, "Unsupported coding scheme %s\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 983 | mcs_name(cs)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 984 | return -EINVAL; |
| 985 | } |
| 986 | |
| 987 | /*! \brief process egprs and gprs data blocks */ |
| 988 | int gprs_rlcmac_pdch::rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t fn, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 989 | struct pcu_l1_meas *meas, enum CodingScheme cs) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 990 | { |
| 991 | int rc; |
| 992 | struct gprs_rlc_data_info rlc_dec; |
| 993 | struct gprs_rlcmac_ul_tbf *tbf; |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 994 | struct pdch_ulc_node *node; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 995 | unsigned len = mcs_size_ul(cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 996 | |
| 997 | /* These are always data blocks, since EGPRS still uses CS-1 for |
| 998 | * control blocks (see 44.060, section 10.3, 1st par.) |
| 999 | */ |
Max | 8a8e0fb | 2019-03-25 16:32:50 +0100 | [diff] [blame] | 1000 | if (mcs_is_edge(cs)) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1001 | bts_send_gsmtap_meas(bts(), PCU_GSMTAP_C_UL_DATA_EGPRS, true, |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 1002 | trx_no(), ts_no, GSMTAP_CHANNEL_PDTCH, fn, |
| 1003 | data, data_len, meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1004 | } else { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1005 | bts_send_gsmtap_meas(bts(), PCU_GSMTAP_C_UL_DATA_GPRS, true, |
Pau Espin Pedrol | 0b0391f | 2020-05-19 17:23:23 +0200 | [diff] [blame] | 1006 | trx_no(), ts_no, GSMTAP_CHANNEL_PDTCH, fn, |
| 1007 | data, data_len, meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1010 | LOGPDCH(this, DRLCMACUL, LOGL_DEBUG, " UL data: %s\n", osmo_hexdump(data, len)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1011 | |
| 1012 | rc = Decoding::rlc_parse_ul_data_header(&rlc_dec, data, cs); |
| 1013 | if (rc < 0) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1014 | LOGPDCH(this, DRLCMACUL, LOGL_ERROR, |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1015 | "Got %s RLC block but header parsing has failed\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 1016 | mcs_name(cs)); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1017 | bts_do_rate_ctr_inc(bts(), CTR_DECODE_ERRORS); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1018 | return rc; |
| 1019 | } |
| 1020 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1021 | LOGPDCH(this, DRLCMACUL, LOGL_INFO, |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1022 | "Got %s RLC block: " |
| 1023 | "R=%d, SI=%d, TFI=%d, CPS=%d, RSB=%d, " |
| 1024 | "rc=%d\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 1025 | mcs_name(cs), |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1026 | rlc_dec.r, rlc_dec.si, rlc_dec.tfi, rlc_dec.cps, rlc_dec.rsb, |
| 1027 | rc); |
| 1028 | |
| 1029 | /* find TBF inst from given TFI */ |
| 1030 | tbf = ul_tbf_by_tfi(rlc_dec.tfi); |
| 1031 | if (!tbf) { |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1032 | LOGPDCH(this, DRLCMACUL, LOGL_NOTICE, "UL DATA unknown TFI=%d\n", |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1033 | rlc_dec.tfi); |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 1037 | node = pdch_ulc_get_node(ulc, fn); |
| 1038 | if (node) { |
| 1039 | switch (node->type) { |
| 1040 | case PDCH_ULC_NODE_TBF_USF: |
Pau Espin Pedrol | ffa2918 | 2021-10-12 20:05:37 +0200 | [diff] [blame] | 1041 | if (tbf == node->tbf_usf.ul_tbf) |
| 1042 | pdch_ulc_release_node(ulc, node); |
| 1043 | else |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 1044 | LOGPDCH(this, DRLCMACUL, LOGL_NOTICE, "FN=%" PRIu32 " " |
| 1045 | "Rx UL DATA from unexpected %s vs expected %s\n", |
| 1046 | fn, tbf_name(tbf), tbf_name(node->tbf_usf.ul_tbf)); |
| 1047 | break; |
| 1048 | case PDCH_ULC_NODE_TBF_POLL: |
| 1049 | LOGPDCH(this, DRLCMACUL, LOGL_NOTICE, "FN=%" PRIu32 " " |
Pau Espin Pedrol | 196f36b | 2021-10-18 12:37:51 +0200 | [diff] [blame] | 1050 | "Rx UL DATA from unexpected %s vs expected POLL %s reason=%s\n", |
| 1051 | fn, tbf_name(tbf), tbf_name(node->tbf_poll.poll_tbf), |
| 1052 | get_value_string(pdch_ulc_tbf_poll_reason_names, node->tbf_poll.reason)); |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 1053 | break; |
| 1054 | case PDCH_ULC_NODE_SBA: |
| 1055 | LOGPDCH(this, DRLCMACUL, LOGL_NOTICE, "FN=%" PRIu32 " " |
| 1056 | "Rx UL DATA from unexpected %s vs expected SBA\n", |
| 1057 | fn, tbf_name(tbf)); |
| 1058 | break; |
| 1059 | } |
Pau Espin Pedrol | c1f38c7 | 2021-03-24 14:06:15 +0100 | [diff] [blame] | 1060 | } else { |
| 1061 | LOGPDCH(this, DRLCMACUL, LOGL_NOTICE, "FN=%" PRIu32 " " |
| 1062 | "Rx UL DATA from unexpected %s\n", fn, tbf_name(tbf)); |
| 1063 | } |
| 1064 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1065 | /* Reset N3101 counter: */ |
Max | 847ed9f | 2018-02-20 18:16:11 +0100 | [diff] [blame] | 1066 | tbf->n_reset(N3101); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1067 | |
| 1068 | return tbf->rcv_data_block_acknowledged(&rlc_dec, data, meas); |
| 1069 | } |
| 1070 | |
| 1071 | int gprs_rlcmac_pdch::rcv_block_gprs(uint8_t *data, uint8_t data_len, uint32_t fn, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 1072 | struct pcu_l1_meas *meas, enum CodingScheme cs) |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1073 | { |
| 1074 | unsigned payload = data[0] >> 6; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1075 | int rc = 0; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1076 | |
| 1077 | switch (payload) { |
| 1078 | case GPRS_RLCMAC_DATA_BLOCK: |
| 1079 | rc = rcv_data_block(data, data_len, fn, meas, cs); |
| 1080 | break; |
| 1081 | case GPRS_RLCMAC_CONTROL_BLOCK: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 1082 | rc = rcv_control_block(data, data_len, fn, meas, cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1083 | break; |
| 1084 | case GPRS_RLCMAC_CONTROL_BLOCK_OPT: |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1085 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "GPRS_RLCMAC_CONTROL_BLOCK_OPT block payload is not supported.\n"); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1086 | break; |
| 1087 | default: |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1088 | LOGPDCH(this, DRLCMAC, LOGL_NOTICE, "Unknown RLCMAC block payload(%u).\n", payload); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1089 | rc = -EINVAL; |
| 1090 | } |
| 1091 | |
| 1092 | return rc; |
| 1093 | } |
| 1094 | |
| 1095 | gprs_rlcmac_tbf *gprs_rlcmac_pdch::tbf_from_list_by_tfi( |
| 1096 | LListHead<gprs_rlcmac_tbf> *tbf_list, uint8_t tfi, |
| 1097 | enum gprs_rlcmac_tbf_direction dir) |
| 1098 | { |
| 1099 | gprs_rlcmac_tbf *tbf; |
| 1100 | LListHead<gprs_rlcmac_tbf> *pos; |
| 1101 | |
| 1102 | llist_for_each(pos, tbf_list) { |
| 1103 | tbf = pos->entry(); |
| 1104 | if (tbf->tfi() != tfi) |
| 1105 | continue; |
| 1106 | if (!tbf->pdch[ts_no]) |
| 1107 | continue; |
| 1108 | return tbf; |
| 1109 | } |
| 1110 | return NULL; |
| 1111 | } |
| 1112 | |
| 1113 | gprs_rlcmac_ul_tbf *gprs_rlcmac_pdch::ul_tbf_by_tfi(uint8_t tfi) |
| 1114 | { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 1115 | return tbf_as_ul_tbf(tbf_by_tfi(tfi, GPRS_RLCMAC_UL_TBF)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | gprs_rlcmac_dl_tbf *gprs_rlcmac_pdch::dl_tbf_by_tfi(uint8_t tfi) |
| 1119 | { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 1120 | return tbf_as_dl_tbf(tbf_by_tfi(tfi, GPRS_RLCMAC_DL_TBF)); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /* lookup TBF Entity (by TFI) */ |
| 1124 | gprs_rlcmac_tbf *gprs_rlcmac_pdch::tbf_by_tfi(uint8_t tfi, |
| 1125 | enum gprs_rlcmac_tbf_direction dir) |
| 1126 | { |
| 1127 | struct gprs_rlcmac_tbf *tbf; |
| 1128 | |
| 1129 | if (tfi >= 32) |
| 1130 | return NULL; |
| 1131 | |
| 1132 | tbf = m_tbfs[dir][tfi]; |
| 1133 | |
Pau Espin Pedrol | 710e0e9 | 2021-04-22 21:03:33 +0200 | [diff] [blame] | 1134 | return tbf; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1135 | } |
| 1136 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 1137 | void gprs_rlcmac_pdch::num_tbfs_update(gprs_rlcmac_tbf *tbf, bool is_attach) |
| 1138 | { |
| 1139 | int threshold = is_attach ? 0 : 1; |
| 1140 | int inc = is_attach ? 1 : -1; |
| 1141 | uint8_t ul_dl_gprs = m_num_tbfs_gprs[GPRS_RLCMAC_UL_TBF] + |
| 1142 | m_num_tbfs_gprs[GPRS_RLCMAC_DL_TBF]; |
| 1143 | uint8_t ul_dl_egprs = m_num_tbfs_egprs[GPRS_RLCMAC_UL_TBF] + |
| 1144 | m_num_tbfs_egprs[GPRS_RLCMAC_DL_TBF]; |
| 1145 | |
| 1146 | /* Count PDCHs with at least one TBF as "occupied", as in |
| 1147 | * 3GPP TS 52.402 § B.2.1.42-44. So if transitioning from 0 (threshold) |
| 1148 | * TBFs in this PDCH to 1, increase the counter by 1 (inc). */ |
| 1149 | if (ul_dl_gprs + ul_dl_egprs == threshold) |
| 1150 | bts_stat_item_add(trx->bts, STAT_PDCH_OCCUPIED, inc); |
| 1151 | |
| 1152 | /* Update occupied GPRS/EGPRS stats (§ B.2.1.54-55) too */ |
| 1153 | if (tbf->is_egprs_enabled() && ul_dl_egprs == threshold) |
| 1154 | bts_stat_item_add(trx->bts, STAT_PDCH_OCCUPIED_EGPRS, inc); |
| 1155 | else if (!tbf->is_egprs_enabled() && ul_dl_gprs == threshold) |
| 1156 | bts_stat_item_add(trx->bts, STAT_PDCH_OCCUPIED_GPRS, inc); |
| 1157 | |
| 1158 | if (tbf->is_egprs_enabled()) |
| 1159 | m_num_tbfs_egprs[tbf->direction] += inc; |
| 1160 | else |
| 1161 | m_num_tbfs_gprs[tbf->direction] += inc; |
| 1162 | } |
| 1163 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1164 | void gprs_rlcmac_pdch::attach_tbf(gprs_rlcmac_tbf *tbf) |
| 1165 | { |
| 1166 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 1167 | |
| 1168 | if (m_tbfs[tbf->direction][tbf->tfi()]) |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1169 | LOGPDCH(this, DRLCMAC, LOGL_ERROR, |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1170 | "%s has not been detached, overwriting it\n", |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1171 | m_tbfs[tbf->direction][tbf->tfi()]->name()); |
| 1172 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 1173 | num_tbfs_update(tbf, true); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 1174 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 1175 | ul_tbf = tbf_as_ul_tbf(tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1176 | m_assigned_usf |= 1 << ul_tbf->m_usf[ts_no]; |
| 1177 | } |
| 1178 | m_assigned_tfi[tbf->direction] |= 1UL << tbf->tfi(); |
| 1179 | m_tbfs[tbf->direction][tbf->tfi()] = tbf; |
| 1180 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 1181 | LOGPDCH(this, DRLCMAC, LOGL_INFO, "Attaching %s, %d TBFs, " |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1182 | "USFs = %02x, TFIs = %08x.\n", |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 1183 | tbf->name(), num_tbfs(tbf->direction), |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1184 | m_assigned_usf, m_assigned_tfi[tbf->direction]); |
| 1185 | } |
| 1186 | |
| 1187 | void gprs_rlcmac_pdch::detach_tbf(gprs_rlcmac_tbf *tbf) |
| 1188 | { |
| 1189 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 1190 | |
Pau Espin Pedrol | 20dfa54 | 2021-11-09 12:15:16 +0100 | [diff] [blame] | 1191 | LOGPDCH(this, DRLCMAC, LOGL_INFO, "Detaching %s, %d TBFs, " |
| 1192 | "USFs = %02x, TFIs = %08x.\n", |
| 1193 | tbf->name(), num_tbfs(tbf->direction), |
| 1194 | m_assigned_usf, m_assigned_tfi[tbf->direction]); |
| 1195 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 1196 | if (tbf->is_egprs_enabled()) { |
| 1197 | OSMO_ASSERT(m_num_tbfs_egprs[tbf->direction] > 0); |
| 1198 | } else { |
| 1199 | OSMO_ASSERT(m_num_tbfs_gprs[tbf->direction] > 0); |
| 1200 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1201 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 1202 | num_tbfs_update(tbf, false); |
Pau Espin Pedrol | b5fece9 | 2021-08-23 16:58:04 +0200 | [diff] [blame] | 1203 | if (tbf->direction == GPRS_RLCMAC_UL_TBF) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 1204 | ul_tbf = tbf_as_ul_tbf(tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1205 | m_assigned_usf &= ~(1 << ul_tbf->m_usf[ts_no]); |
| 1206 | } |
| 1207 | m_assigned_tfi[tbf->direction] &= ~(1UL << tbf->tfi()); |
| 1208 | m_tbfs[tbf->direction][tbf->tfi()] = NULL; |
| 1209 | |
Pau Espin Pedrol | 99360a3 | 2021-03-09 17:18:12 +0100 | [diff] [blame] | 1210 | pdch_ulc_release_tbf(ulc, tbf); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 1213 | bool gprs_rlcmac_pdch::has_gprs_only_tbf_attached() const |
| 1214 | { |
Oliver Smith | fce67bc | 2021-09-08 11:36:03 +0200 | [diff] [blame] | 1215 | return (m_num_tbfs_gprs[GPRS_RLCMAC_UL_TBF] + |
| 1216 | m_num_tbfs_gprs[GPRS_RLCMAC_DL_TBF]) > 0; |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1219 | void gprs_rlcmac_pdch::reserve(enum gprs_rlcmac_tbf_direction dir) |
| 1220 | { |
| 1221 | m_num_reserved[dir] += 1; |
| 1222 | } |
| 1223 | |
| 1224 | void gprs_rlcmac_pdch::unreserve(enum gprs_rlcmac_tbf_direction dir) |
| 1225 | { |
| 1226 | OSMO_ASSERT(m_num_reserved[dir] > 0); |
| 1227 | m_num_reserved[dir] -= 1; |
| 1228 | } |
| 1229 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1230 | inline struct gprs_rlcmac_bts *gprs_rlcmac_pdch::bts() const |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1231 | { |
| 1232 | return trx->bts; |
| 1233 | } |
| 1234 | |
| 1235 | uint8_t gprs_rlcmac_pdch::trx_no() const |
| 1236 | { |
| 1237 | return trx->trx_no; |
| 1238 | } |
| 1239 | |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 1240 | uint8_t gprs_rlcmac_pdch::reserve_tai(uint8_t ta) |
| 1241 | { |
| 1242 | uint8_t tai; |
| 1243 | |
| 1244 | for (tai = 0; tai < PTCCH_TAI_NUM; tai++) { |
| 1245 | if (ptcch_msg[tai] == PTCCH_TAI_FREE) { |
| 1246 | ptcch_msg[tai] = ta; |
| 1247 | return tai; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | /* Special case: no free TAI available */ |
| 1252 | return PTCCH_TAI_FREE; |
| 1253 | } |
| 1254 | |
| 1255 | void gprs_rlcmac_pdch::release_tai(uint8_t tai) |
| 1256 | { |
| 1257 | OSMO_ASSERT(tai < PTCCH_TAI_NUM); |
| 1258 | ptcch_msg[tai] = PTCCH_TAI_FREE; |
| 1259 | } |
| 1260 | |
| 1261 | void gprs_rlcmac_pdch::update_ta(uint8_t tai, uint8_t ta) |
| 1262 | { |
| 1263 | OSMO_ASSERT(tai < PTCCH_TAI_NUM); |
| 1264 | ptcch_msg[tai] = ta; |
| 1265 | } |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 1266 | |
| 1267 | void pdch_free_all_tbf(struct gprs_rlcmac_pdch *pdch) |
| 1268 | { |
Pau Espin Pedrol | 1d663d9 | 2021-09-03 12:39:26 +0200 | [diff] [blame] | 1269 | struct llist_item *pos; |
| 1270 | struct llist_item *pos2; |
| 1271 | |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 1272 | for (uint8_t tfi = 0; tfi < 32; tfi++) { |
| 1273 | struct gprs_rlcmac_tbf *tbf; |
| 1274 | |
| 1275 | tbf = pdch->ul_tbf_by_tfi(tfi); |
| 1276 | if (tbf) |
| 1277 | tbf_free(tbf); |
| 1278 | tbf = pdch->dl_tbf_by_tfi(tfi); |
| 1279 | if (tbf) |
| 1280 | tbf_free(tbf); |
| 1281 | } |
Pau Espin Pedrol | 1d663d9 | 2021-09-03 12:39:26 +0200 | [diff] [blame] | 1282 | |
| 1283 | /* Some temporary dummy TBFs to tx ImmAssRej may be left linked to the |
| 1284 | * PDCH, since they have no TFI assigned (see handle_tbf_reject()). |
| 1285 | * Get rid of them too: */ |
| 1286 | llist_for_each_entry_safe(pos, pos2, &pdch->trx->ul_tbfs, list) { |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 1287 | struct gprs_rlcmac_ul_tbf *ul_tbf = tbf_as_ul_tbf((struct gprs_rlcmac_tbf *)pos->entry); |
Pau Espin Pedrol | 1d663d9 | 2021-09-03 12:39:26 +0200 | [diff] [blame] | 1288 | if (ul_tbf->control_ts == pdch->ts_no) |
| 1289 | tbf_free(ul_tbf); |
| 1290 | } |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 1291 | } |
Pau Espin Pedrol | e91c4c7 | 2021-01-18 17:54:30 +0100 | [diff] [blame] | 1292 | |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 1293 | void pdch_disable(struct gprs_rlcmac_pdch *pdch) |
| 1294 | { |
Pau Espin Pedrol | e91c4c7 | 2021-01-18 17:54:30 +0100 | [diff] [blame] | 1295 | pdch->disable(); |
| 1296 | } |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 1297 | |
| 1298 | bool pdch_is_enabled(const struct gprs_rlcmac_pdch *pdch) |
| 1299 | { |
| 1300 | return pdch->is_enabled(); |
| 1301 | } |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 1302 | |
| 1303 | /* To be called only on enabled PDCHs. Used to gather information on whether the |
| 1304 | * PDCH is currently unable to allocate more TBFs due to any resource being |
| 1305 | * full. Used by bts_all_pdch_allocated() for counting purposes. */ |
| 1306 | bool pdch_is_full(const struct gprs_rlcmac_pdch *pdch) |
| 1307 | { |
| 1308 | return pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) == NO_FREE_TFI || |
| 1309 | pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) == NO_FREE_TFI || |
| 1310 | find_free_usf(pdch->assigned_usf()) < 0; |
| 1311 | } |