blob: 31268930f40fa482a7adb5e4fc122d9ef5a8a33e [file] [log] [blame]
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +01001/* sba.c
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <sba.h>
22#include <gprs_debug.h>
23#include <bts.h>
24#include <pcu_utils.h>
25#include <pdch.h>
26#include <errno.h>
27
28#include <osmocom/core/logging.h>
29#include <osmocom/core/talloc.h>
30#include <osmocom/gsm/protocol/gsm_04_08.h>
31#include <osmocom/gsm/gsm_utils.h>
32
33#include "pdch.h"
34#include "pdch_ul_controller.h"
35
Pau Espin Pedrol54e64502021-03-26 20:44:48 +010036/* TBF Starting Time for assigning SBA.
37 * See TS 44.060 12.21 "Starting Frame Number Description".
38 * According to spec, k=0 (offset=4) "should not be used, so as to leave time
39 * for the MS to analyze the message and get ready to receive or transmit".
40 * Hence, k=1 (offset=8-9) is theoretically the minimum offset which could be
41 * used.
42 *
43 * However, it was found, empirically, that it takes around 30-40 FNs time for
44 * the Immediate Assignment message created with this "TBF Starting Time" to
45 * travel from PCU->BTS and be transmitted over CCCH on the Um interface. Hence,
46 * we must account for this delay here, otherwise the MS would be receiving eg.
47 * a TBF Starting Time of FN=40 while the Imm Assigned containing it is sent in
48 * eg. FN=50, which would be too late for the MS to answer to it.
49 *
50 * The situation described above, can even get worse on high BTS load for AGCH,
51 * since the Immediate Assignment will queue in the BTS waiting to be
52 * transmitted one after the other, hence increasing the required delay.
53 */
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010054#define AGCH_START_OFFSET 52
55
56
57struct gprs_rlcmac_sba *sba_alloc(void *ctx, struct gprs_rlcmac_pdch *pdch, uint8_t ta)
58{
59 struct gprs_rlcmac_sba *sba;
60 sba = talloc_zero(ctx, struct gprs_rlcmac_sba);
61 if (!sba)
62 return NULL;
63
64 sba->pdch = pdch;
65 sba->ta = ta;
66
67 /* TODO: request ULC for next available FN instead of hardcoded AGCH_START_OFFSET */
68 sba->fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET);
69
70 pdch_ulc_reserve_sba(pdch->ulc, sba);
71 return sba;
72}
73
74/* Internal use */
75static void sba_free_norelease(struct gprs_rlcmac_sba *sba)
76{
77 bts_do_rate_ctr_inc(sba->pdch->trx->bts, CTR_SBA_FREED);
78 talloc_free(sba);
79}
80
81void sba_free(struct gprs_rlcmac_sba *sba)
82{
83 if (pdch_ulc_release_fn(sba->pdch->ulc, sba->fn) < 0)
84 LOGPDCH(sba->pdch, DRLCMAC, LOGL_NOTICE,
85 "Trying to release unregistered SBA (FN=%u, TA=%u)\n",
86 sba->fn, sba->ta);
87 sba_free_norelease(sba);
88}
89
90void sba_timeout(struct gprs_rlcmac_sba *sba)
91{
92 /* Upon timeout, the UL Controller node is already released */
93 sba_free_norelease(sba);
94}
95
96uint32_t find_sba_rts(struct gprs_rlcmac_pdch *pdch, uint32_t fn, uint8_t block_nr)
97{
98 uint32_t sba_fn = rts_next_fn(fn, block_nr);
99 struct gprs_rlcmac_sba *sba;
100
101 sba = pdch_ulc_get_sba(pdch->ulc, sba_fn);
102 if (sba)
103 return sba_fn;
104
105 return 0xffffffff;
106}