Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 1 | /* 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 | |
| 36 | /* starting time for assigning single slot |
| 37 | * This offset must be a multiple of 13. */ |
| 38 | #define AGCH_START_OFFSET 52 |
| 39 | |
| 40 | |
| 41 | struct gprs_rlcmac_sba *sba_alloc(void *ctx, struct gprs_rlcmac_pdch *pdch, uint8_t ta) |
| 42 | { |
| 43 | struct gprs_rlcmac_sba *sba; |
| 44 | sba = talloc_zero(ctx, struct gprs_rlcmac_sba); |
| 45 | if (!sba) |
| 46 | return NULL; |
| 47 | |
| 48 | sba->pdch = pdch; |
| 49 | sba->ta = ta; |
| 50 | |
| 51 | /* TODO: request ULC for next available FN instead of hardcoded AGCH_START_OFFSET */ |
| 52 | sba->fn = next_fn(pdch->last_rts_fn, AGCH_START_OFFSET); |
| 53 | |
| 54 | pdch_ulc_reserve_sba(pdch->ulc, sba); |
| 55 | return sba; |
| 56 | } |
| 57 | |
| 58 | /* Internal use */ |
| 59 | static void sba_free_norelease(struct gprs_rlcmac_sba *sba) |
| 60 | { |
| 61 | bts_do_rate_ctr_inc(sba->pdch->trx->bts, CTR_SBA_FREED); |
| 62 | talloc_free(sba); |
| 63 | } |
| 64 | |
| 65 | void sba_free(struct gprs_rlcmac_sba *sba) |
| 66 | { |
| 67 | if (pdch_ulc_release_fn(sba->pdch->ulc, sba->fn) < 0) |
| 68 | LOGPDCH(sba->pdch, DRLCMAC, LOGL_NOTICE, |
| 69 | "Trying to release unregistered SBA (FN=%u, TA=%u)\n", |
| 70 | sba->fn, sba->ta); |
| 71 | sba_free_norelease(sba); |
| 72 | } |
| 73 | |
| 74 | void sba_timeout(struct gprs_rlcmac_sba *sba) |
| 75 | { |
| 76 | /* Upon timeout, the UL Controller node is already released */ |
| 77 | sba_free_norelease(sba); |
| 78 | } |
| 79 | |
| 80 | uint32_t find_sba_rts(struct gprs_rlcmac_pdch *pdch, uint32_t fn, uint8_t block_nr) |
| 81 | { |
| 82 | uint32_t sba_fn = rts_next_fn(fn, block_nr); |
| 83 | struct gprs_rlcmac_sba *sba; |
| 84 | |
| 85 | sba = pdch_ulc_get_sba(pdch->ulc, sba_fn); |
| 86 | if (sba) |
| 87 | return sba_fn; |
| 88 | |
| 89 | return 0xffffffff; |
| 90 | } |