2013-10-17 17:41:11 +00:00
/*
* Copyright ( C ) 2013 by Holger Hans Peter Freyther
*
* All Rights Reserved
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*
*/
# include <bts.h>
2013-10-19 15:37:48 +00:00
# include <tbf.h>
2019-09-25 15:47:02 +00:00
# include <tbf_ul.h>
2013-10-19 17:04:03 +00:00
# include <encoding.h>
2013-10-26 15:32:04 +00:00
# include <decoding.h>
# include <rlc.h>
2013-10-26 18:12:59 +00:00
# include <pcu_l1_if.h>
2018-01-26 12:31:42 +00:00
# include <gprs_ms.h>
2013-10-19 15:37:48 +00:00
# include <gprs_rlcmac.h>
2013-10-19 16:15:44 +00:00
# include <gprs_debug.h>
2018-01-26 12:31:42 +00:00
# include <cxx_linuxlist.h>
2018-02-19 16:17:28 +00:00
# include <pdch.h>
2021-01-14 15:48:38 +00:00
# include <sba.h>
2021-08-23 12:19:21 +00:00
# include <bts_pch_timer.h>
2013-10-19 15:37:48 +00:00
extern " C " {
# include <osmocom/core/talloc.h>
2013-10-19 16:15:44 +00:00
# include <osmocom/core/msgb.h>
2015-11-07 20:04:40 +00:00
# include <osmocom/core/stats.h>
2016-07-18 10:50:18 +00:00
# include <osmocom/gsm/protocol/gsm_04_08.h>
2017-02-21 18:35:23 +00:00
# include <osmocom/gsm/gsm_utils.h>
2022-10-26 13:37:53 +00:00
# include <osmocom/gsm/gsm0502.h>
2019-12-23 12:19:25 +00:00
# include <osmocom/gsm/gsm48.h>
2017-07-21 19:56:23 +00:00
# include <osmocom/core/gsmtap_util.h>
2017-10-29 09:57:27 +00:00
# include <osmocom/core/application.h>
2018-01-26 12:31:42 +00:00
# include <osmocom/core/bitvec.h>
# include <osmocom/core/gsmtap.h>
# include <osmocom/core/logging.h>
# include <osmocom/core/utils.h>
2013-10-19 15:37:48 +00:00
}
2013-10-17 18:12:37 +00:00
2013-10-19 16:28:59 +00:00
# include <errno.h>
2013-10-17 17:41:11 +00:00
# include <string.h>
2017-02-21 18:35:23 +00:00
# define RFN_THRESHOLD RFN_MODULUS / 2
2013-10-19 16:15:44 +00:00
extern void * tall_pcu_ctx ;
2017-10-29 09:57:27 +00:00
extern " C " {
/* e must make sure to initialize logging before the BTS static
* constructors are executed below , as those call libosmocore APIs that
* require logging already to be initialized . */
2020-09-30 17:57:02 +00:00
__attribute__ ( ( constructor ( 101 ) ) ) static void early_init ( void )
2017-10-29 09:57:27 +00:00
{
2018-04-01 14:54:40 +00:00
if ( ! tall_pcu_ctx ) {
tall_pcu_ctx = talloc_named_const ( NULL , 1 , " Osmo-PCU context " ) ;
osmo_init_logging2 ( tall_pcu_ctx , & gprs_log_info ) ;
}
2017-10-29 09:57:27 +00:00
}
}
2021-01-18 16:53:29 +00:00
void bts_trx_free_all_tbf ( struct gprs_rlcmac_trx * trx )
{
for ( uint8_t ts = 0 ; ts < 8 ; ts + + )
pdch_free_all_tbf ( & trx - > pdch [ ts ] ) ;
}
2019-09-05 12:48:35 +00:00
static struct osmo_tdef T_defs_bts [ ] = {
2021-08-12 12:53:56 +00:00
{ . T = 3142 , . default_val = 20 , . unit = OSMO_TDEF_S , . desc = " Wait Indication used in Imm Ass Reject during TBF Establishment (CCCH) " , . val = 0 , . min_val = 0 , . max_val = 255 } , /* TS 44.018 10.5.2.43, TS 44.060 7.1.3.2.1 (T3172) */
{ . T = 3169 , . default_val = 5 , . unit = OSMO_TDEF_S , . desc = " Reuse of USF and TFI(s) after the MS uplink TBF assignment is invalid " , . val = 0 } ,
{ . T = 3191 , . default_val = 5 , . unit = OSMO_TDEF_S , . desc = " Reuse of TFI(s) after sending (1) last RLC Data Block on TBF(s), or (2) PACKET TBF RELEASE for an MBMS radio bearer " , . val = 0 } ,
{ . T = 3193 , . default_val = 100 , . unit = OSMO_TDEF_MS , . desc = " Reuse of TFI(s) after reception of final PACKET DOWNLINK ACK/NACK from MS for TBF " , . val = 0 } ,
{ . T = 3195 , . default_val = 5 , . unit = OSMO_TDEF_S , . desc = " Reuse of TFI(s) upon no response from the MS (radio failure or cell change) for TBF/MBMS radio bearer " , . val = 0 } ,
2021-11-10 18:09:10 +00:00
{ . T = - 16 , . default_val = 1000 , . unit = OSMO_TDEF_MS ,
. desc = " Granularity for *:all_allocated rate counters: amount of milliseconds that one counter increment "
" represents. See also X17, X18 " } ,
{ . T = - 17 , . default_val = 0 , . unit = OSMO_TDEF_MS ,
. desc = " Rounding threshold for *:all_allocated rate counters: round up to the next counter increment "
" after this many milliseconds. If set to half of X16 (or 0), employ the usual round() behavior: "
" round up after half of a granularity period. If set to 1, behave like ceil(): already "
" increment the counter immediately when all channels are allocated. If set >= X16, behave like "
" floor(): only increment after a full X16 period of all channels being occupied. "
" See also X16, X18 " } ,
{ . T = - 18 , . default_val = 60000 , . unit = OSMO_TDEF_MS ,
. desc = " Forget-sum period for *:all_allocated rate counters: "
" after this amount of idle time, forget internally cumulated time remainders. Zero to always "
" keep remainders. See also X16, X17. " } ,
2019-09-13 10:41:54 +00:00
{ . T = 0 , . default_val = 0 , . unit = OSMO_TDEF_S , . desc = NULL , . val = 0 } /* empty item at the end */
2019-09-05 12:48:35 +00:00
} ;
2013-10-27 08:02:31 +00:00
/**
* For gcc - 4.4 compat do not use extended initializer list but keep the
* order from the enum here . Once we support GCC4 .7 and up we can change
* the code below .
*/
static const struct rate_ctr_desc bts_ctr_description [ ] = {
2021-11-10 18:09:10 +00:00
{ " pdch:all_allocated " , " Cumulative counter of seconds where all enabled PDCH resources were allocated " } ,
2017-11-21 19:24:54 +00:00
{ " tbf:dl:alloc " , " TBF DL Allocated " } ,
{ " tbf:dl:freed " , " TBF DL Freed " } ,
{ " tbf:dl:aborted " , " TBF DL Aborted " } ,
{ " tbf:ul:alloc " , " TBF UL Allocated " } ,
{ " tbf:ul:freed " , " TBF UL Freed " } ,
{ " tbf:ul:aborted " , " TBF UL Aborted " } ,
{ " tbf:reused " , " TBF Reused " } ,
{ " tbf:alloc:algo-a " , " TBF Alloc Algo A " } ,
{ " tbf:alloc:algo-b " , " TBF Alloc Algo B " } ,
2021-02-25 17:30:33 +00:00
{ " tbf:alloc:failed " , " TBF Alloc Failure (any reason) " } ,
{ " tbf:alloc:failed:no_tfi " , " TBF Alloc Failure (TFIs exhausted) " } ,
{ " tbf:alloc:failed:no_usf " , " TBF Alloc Failure (USFs exhausted) " } ,
{ " tbf:alloc:failed:no_slot_combi " , " TBF Alloc Failure (No valid UL/DL slot combination found) " } ,
{ " tbf:alloc:failed:no_slot_avail " , " TBF Alloc Failure (No slot available) " } ,
2017-11-21 19:24:54 +00:00
{ " rlc:sent " , " RLC Sent " } ,
{ " rlc:resent " , " RLC Resent " } ,
{ " rlc:restarted " , " RLC Restarted " } ,
{ " rlc:stalled " , " RLC Stalled " } ,
{ " rlc:nacked " , " RLC Nacked " } ,
{ " rlc:final_block_resent " , " RLC Final Blk resent " } ,
{ " rlc:ass:timedout " , " RLC Assign Timeout " } ,
{ " rlc:ass:failed " , " RLC Assign Failed " } ,
{ " rlc:ack:timedout " , " RLC Ack Timeout " } ,
{ " rlc:ack:failed " , " RLC Ack Failed " } ,
{ " rlc:rel:timedout " , " RLC Release Timeout " } ,
{ " rlc:late-block " , " RLC Late Block " } ,
{ " rlc:sent-dummy " , " RLC Sent Dummy " } ,
{ " rlc:sent-control " , " RLC Sent Control " } ,
{ " rlc:dl_bytes " , " RLC DL Bytes " } ,
{ " rlc:dl_payload_bytes " , " RLC DL Payload Bytes " } ,
{ " rlc:ul_bytes " , " RLC UL Bytes " } ,
{ " rlc:ul_payload_bytes " , " RLC UL Payload Bytes " } ,
{ " decode:errors " , " Decode Errors " } ,
{ " sba:allocated " , " SBA Allocated " } ,
{ " sba:freed " , " SBA Freed " } ,
{ " sba:timedout " , " SBA Timeout " } ,
{ " llc:timeout " , " Timedout Frames " } ,
{ " llc:dropped " , " Dropped Frames " } ,
{ " llc:scheduled " , " Scheduled Frames " } ,
{ " llc:dl_bytes " , " RLC encapsulated PDUs " } ,
{ " llc:ul_bytes " , " full PDUs received " } ,
2021-06-24 15:01:41 +00:00
{ " pch:requests " , " PCH requests sent " } ,
2021-11-08 18:19:25 +00:00
{ " pch:requests:already " , " PCH requests on subscriber already being paged " } ,
2021-07-09 14:37:16 +00:00
{ " pch:requests:timeout " , " PCH requests timeout " } ,
2021-06-24 15:01:41 +00:00
{ " rach:requests " , " RACH requests received " } ,
2021-11-02 15:47:06 +00:00
{ " rach:requests:11bit " , " 11BIT_RACH requests received " } ,
2021-11-02 15:59:13 +00:00
{ " rach:requests:one_phase " , " One phase packet access with request for single TS UL " } , /* TS 52.402 B.2.1.49 */
{ " rach:requests:two_phase " , " Single block packet request for two phase packet access " } , /* TS 52.402 B.2.1.49 */
2021-11-02 16:20:59 +00:00
{ " rach:requests:unexpected " , " RACH Request with unexpected content received " } ,
2017-11-21 19:24:54 +00:00
{ " spb:uplink_first_segment " , " First seg of UL SPB " } ,
{ " spb:uplink_second_segment " , " Second seg of UL SPB " } ,
{ " spb:downlink_first_segment " , " First seg of DL SPB " } ,
{ " spb:downlink_second_segment " , " Second seg of DL SPB " } ,
{ " immediate:assignment_UL " , " Immediate Assign UL " } ,
2021-11-02 16:46:43 +00:00
{ " immediate:assignment_ul:one_phase " , " Immediate Assign UL (one phase packet access) " } , /* TS 52.402 B.2.1.50 */
{ " immediate:assignment_ul:two_phase " , " Immediate Assign UL (two phase packet access) " } , /* TS 52.402 B.2.1.50 */
2021-11-02 17:47:44 +00:00
{ " immediate:assignment_ul:contention_resolution_success " , " First RLC Block (PDU) on the PDTCH from the MS received " } , /* TS 52.402 B.2.1.51 */
2017-11-21 19:24:54 +00:00
{ " immediate:assignment_rej " , " Immediate Assign Rej " } ,
{ " immediate:assignment_DL " , " Immediate Assign DL " } ,
{ " channel:request_description " , " Channel Request Desc " } ,
{ " pkt:ul_assignment " , " Packet UL Assignment " } ,
{ " pkt:access_reject " , " Packet Access Reject " } ,
{ " pkt:dl_assignment " , " Packet DL Assignment " } ,
Introduce NACC support
A new nacc_fsm is introduced per MS object, with its partner priv
structure struct nacc_fsm_ctx, which exists and is available in the MS
object only during the duration of the NACC procedure.
The NACC context is created on an MS whenever a Pkt Cell Change
Notification is received on Uplink RLCMAC, which asks for neighbor
information of a given ARFCN+BSIC.
First, the target ARFCN+BSIC needs to be translated into a CGI-PS
(RAC+CI) address. That's done by asking the BSC through the Neighbour
Resolution Service available in osmo-bsc using the CTRL interface.
Once the CGI-PS of the target cell is known, PCU starts a RIM RAN-INFO
request against the SGSN (which will route the request as needed), and
wait for a response containing the SI bits from the target cell.
After the SI are received, the scheduler is instructed to eventually
poll a TBF for the MS originating the CCN, so that we can send the SI
encapsulated into multiple Packet Neighbor Cell Data messages on the
downlink.
One all the SI bits are sent, the scheduler is instructed to send a
Packet Cell Change Continue message.
Once the message above has been sent, the FSM autodestroys itself.
Caches are also introduced in this patch which allows for re-using
recently known translations ARFCN+BSIC -> CGI-PS and CGI-PS -> SI_INFO
respectively.
Change-Id: Id35f40d05f3e081f32fddbf1fa34cb338db452ca
2021-01-21 17:46:13 +00:00
{ " pkt:cell_chg_notification " , " Packet Cell Change Notification " } ,
{ " pkt:cell_chg_continue " , " Packet Cell Change Continue " } ,
{ " pkt:neigh_cell_data " , " Packet Neighbour Cell Data " } ,
2017-11-21 19:24:54 +00:00
{ " ul:control " , " UL control Block " } ,
{ " ul:assignment_poll_timeout " , " UL Assign Timeout " } ,
{ " ul:assignment_failed " , " UL Assign Failed " } ,
{ " dl:assignment_timeout " , " DL Assign Timeout " } ,
{ " dl:assignment_failed " , " DL Assign Failed " } ,
{ " pkt:ul_ack_nack_timeout " , " PUAN Poll Timeout " } ,
{ " pkt:ul_ack_nack_failed " , " PUAN poll Failed " } ,
{ " pkt:dl_ack_nack_timeout " , " PDAN poll Timeout " } ,
{ " pkt:dl_ack_nack_failed " , " PDAN poll Failed " } ,
{ " gprs:downlink_cs1 " , " CS1 downlink " } ,
{ " gprs:downlink_cs2 " , " CS2 downlink " } ,
{ " gprs:downlink_cs3 " , " CS3 downlink " } ,
{ " gprs:downlink_cs4 " , " CS4 downlink " } ,
{ " egprs:downlink_mcs1 " , " MCS1 downlink " } ,
{ " egprs:downlink_mcs2 " , " MCS2 downlink " } ,
{ " egprs:downlink_mcs3 " , " MCS3 downlink " } ,
{ " egprs:downlink_mcs4 " , " MCS4 downlink " } ,
{ " egprs:downlink_mcs5 " , " MCS5 downlink " } ,
{ " egprs:downlink_mcs6 " , " MCS6 downlink " } ,
{ " egprs:downlink_mcs7 " , " MCS7 downlink " } ,
{ " egprs:downlink_mcs8 " , " MCS8 downlink " } ,
{ " egprs:downlink_mcs9 " , " MCS9 downlink " } ,
{ " gprs:uplink_cs1 " , " CS1 Uplink " } ,
{ " gprs:uplink_cs2 " , " CS2 Uplink " } ,
{ " gprs:uplink_cs3 " , " CS3 Uplink " } ,
{ " gprs:uplink_cs4 " , " CS4 Uplink " } ,
{ " egprs:uplink_mcs1 " , " MCS1 Uplink " } ,
{ " egprs:uplink_mcs2 " , " MCS2 Uplink " } ,
{ " egprs:uplink_mcs3 " , " MCS3 Uplink " } ,
{ " egprs:uplink_mcs4 " , " MCS4 Uplink " } ,
{ " egprs:uplink_mcs5 " , " MCS5 Uplink " } ,
{ " egprs:uplink_mcs6 " , " MCS6 Uplink " } ,
{ " egprs:uplink_mcs7 " , " MCS7 Uplink " } ,
{ " egprs:uplink_mcs8 " , " MCS8 Uplink " } ,
{ " egprs:uplink_mcs9 " , " MCS9 Uplink " } ,
2013-10-27 08:02:31 +00:00
} ;
static const struct rate_ctr_group_desc bts_ctrg_desc = {
" bts " ,
" BTS Statistics " ,
2015-11-07 20:00:00 +00:00
OSMO_STATS_CLASS_GLOBAL ,
2013-10-27 08:02:31 +00:00
ARRAY_SIZE ( bts_ctr_description ) ,
bts_ctr_description ,
} ;
2015-11-27 18:05:13 +00:00
static const struct osmo_stat_item_desc bts_stat_item_description [ ] = {
{ " ms.present " , " MS Present " ,
OSMO_STAT_ITEM_NO_UNIT , 4 , 0 } ,
2021-09-02 10:23:58 +00:00
{ " pdch.available " , " PDCH available " ,
OSMO_STAT_ITEM_NO_UNIT , 50 , 0 } ,
2021-09-08 07:33:24 +00:00
{ " pdch.occupied " , " PDCH occupied (all) " ,
OSMO_STAT_ITEM_NO_UNIT , 50 , 0 } ,
{ " pdch.occupied.gprs " , " PDCH occupied (GPRS) " ,
OSMO_STAT_ITEM_NO_UNIT , 50 , 0 } ,
{ " pdch.occupied.egprs " , " PDCH occupied (EGPRS) " ,
2021-09-02 10:23:58 +00:00
OSMO_STAT_ITEM_NO_UNIT , 50 , 0 } ,
2015-11-27 18:05:13 +00:00
} ;
static const struct osmo_stat_item_group_desc bts_statg_desc = {
" bts " ,
" BTS Statistics " ,
OSMO_STATS_CLASS_GLOBAL ,
ARRAY_SIZE ( bts_stat_item_description ) ,
bts_stat_item_description ,
} ;
2021-01-18 11:57:32 +00:00
static int bts_talloc_destructor ( struct gprs_rlcmac_bts * bts )
2020-11-02 13:36:22 +00:00
{
2023-04-17 14:33:35 +00:00
struct GprsMs * ms ;
2023-04-20 14:42:54 +00:00
while ( ( ms = llist_first_entry_or_null ( & bts - > ms_list , struct GprsMs , list ) ) )
2023-04-17 14:33:35 +00:00
talloc_free ( ms ) ;
2021-01-18 11:57:32 +00:00
2022-05-09 14:31:22 +00:00
gprs_bssgp_destroy ( bts ) ;
2021-11-10 18:09:10 +00:00
osmo_time_cc_cleanup ( & bts - > all_allocated_pdch ) ;
2021-01-18 11:57:32 +00:00
if ( bts - > ratectrs ) {
rate_ctr_group_free ( bts - > ratectrs ) ;
bts - > ratectrs = NULL ;
}
if ( bts - > statg ) {
osmo_stat_item_group_free ( bts - > statg ) ;
bts - > statg = NULL ;
}
if ( bts - > app_info ) {
msgb_free ( bts - > app_info ) ;
bts - > app_info = NULL ;
}
2021-01-18 16:14:14 +00:00
2021-08-23 12:19:21 +00:00
bts_pch_timer_stop_all ( bts ) ;
2021-01-18 16:14:14 +00:00
llist_del ( & bts - > list ) ;
2021-01-18 11:57:32 +00:00
return 0 ;
}
2021-01-18 16:14:14 +00:00
struct gprs_rlcmac_bts * bts_alloc ( struct gprs_pcu * pcu , uint8_t bts_nr )
2021-01-18 11:57:32 +00:00
{
struct gprs_rlcmac_bts * bts ;
bts = talloc_zero ( pcu , struct gprs_rlcmac_bts ) ;
if ( ! bts )
return bts ;
talloc_set_destructor ( bts , bts_talloc_destructor ) ;
2021-01-14 15:48:38 +00:00
bts - > pcu = pcu ;
2021-01-18 16:14:14 +00:00
bts - > nr = bts_nr ;
2021-01-14 15:48:38 +00:00
2021-03-10 11:19:04 +00:00
bts - > cur_fn = FN_UNSET ;
2021-01-14 15:48:38 +00:00
bts - > cur_blk_fn = - 1 ;
bts - > max_cs_dl = MAX_GPRS_CS ;
bts - > max_cs_ul = MAX_GPRS_CS ;
bts - > max_mcs_dl = MAX_EDGE_MCS ;
bts - > max_mcs_ul = MAX_EDGE_MCS ;
2020-11-02 13:36:22 +00:00
bts - > initial_cs_dl = bts - > initial_cs_ul = 1 ;
bts - > initial_mcs_dl = bts - > initial_mcs_ul = 1 ;
2020-10-30 16:14:26 +00:00
bts - > cs_mask = 1 < < 0 ; /* CS-1 always enabled by default */
2020-11-02 13:36:22 +00:00
bts - > n3101 = 10 ;
bts - > n3103 = 4 ;
bts - > n3105 = 8 ;
bts - > si13_is_set = false ;
bts - > app_info = NULL ;
bts - > T_defs_bts = T_defs_bts ;
osmo_tdefs_reset ( bts - > T_defs_bts ) ;
/* initialize back pointers */
2021-03-08 13:15:54 +00:00
for ( size_t trx_no = 0 ; trx_no < ARRAY_SIZE ( bts - > trx ) ; + + trx_no )
bts_trx_init ( & bts - > trx [ trx_no ] , bts , trx_no ) ;
2020-11-02 13:36:22 +00:00
2021-01-14 15:48:38 +00:00
/* The static allocator might have already registered the counter group.
If this happens and we still called explicitly ( in tests / for example )
than just allocate the group with different index .
This shall be removed once weget rid of BTS singleton */
if ( rate_ctr_get_group_by_name_idx ( bts_ctrg_desc . group_name_prefix , 0 ) )
bts - > ratectrs = rate_ctr_group_alloc ( tall_pcu_ctx , & bts_ctrg_desc , 1 ) ;
else
bts - > ratectrs = rate_ctr_group_alloc ( tall_pcu_ctx , & bts_ctrg_desc , 0 ) ;
OSMO_ASSERT ( bts - > ratectrs ) ;
2013-10-17 17:41:11 +00:00
2021-01-14 15:48:38 +00:00
bts - > statg = osmo_stat_item_group_alloc ( tall_pcu_ctx , & bts_statg_desc , 0 ) ;
OSMO_ASSERT ( bts - > statg ) ;
2013-10-17 17:41:11 +00:00
2021-11-10 18:09:10 +00:00
osmo_time_cc_init ( & bts - > all_allocated_pdch ) ;
struct osmo_time_cc_cfg * cc_cfg = & bts - > all_allocated_pdch . cfg ;
cc_cfg - > gran_usec = 1 * 1000000 ,
cc_cfg - > forget_sum_usec = 60 * 1000000 ,
cc_cfg - > rate_ctr = rate_ctr_group_get_ctr ( bts - > ratectrs , CTR_PDCH_ALL_ALLOCATED ) ,
cc_cfg - > T_gran = - 16 ,
cc_cfg - > T_round_threshold = - 17 ,
cc_cfg - > T_forget_sum = - 18 ,
cc_cfg - > T_defs = T_defs_bts ,
2021-01-18 16:14:14 +00:00
llist_add_tail ( & bts - > list , & pcu - > bts_list ) ;
2021-07-09 14:37:16 +00:00
INIT_LLIST_HEAD ( & bts - > pch_timer ) ;
2023-04-17 14:33:35 +00:00
INIT_LLIST_HEAD ( & bts - > ms_list ) ;
2021-07-09 14:37:16 +00:00
2021-01-18 11:57:32 +00:00
return bts ;
2013-10-27 08:02:31 +00:00
}
2021-03-10 11:19:04 +00:00
void bts_set_current_frame_number ( struct gprs_rlcmac_bts * bts , uint32_t fn )
2013-10-17 17:59:56 +00:00
{
2023-01-05 10:55:17 +00:00
/* See also 3GPP TS 45.002, section 4.3.3 */
OSMO_ASSERT ( fn < GSM_TDMA_HYPERFRAME ) ;
2015-08-27 11:18:24 +00:00
/* The UL frame numbers lag 3 behind the DL frames and the data
* indication is only sent after all 4 frames of the block have been
* received . Sometimes there is an idle frame between the end of one
2021-03-09 16:18:12 +00:00
* and start of another frame ( every 3 blocks ) . */
2021-03-10 11:19:04 +00:00
if ( fn ! = bts - > cur_fn & & bts - > cur_fn ! = FN_UNSET & & fn ! = fn_next_block ( bts - > cur_fn ) ) {
LOGP ( DRLCMAC , LOGL_NOTICE ,
2023-01-05 11:09:51 +00:00
" Detected FN jump! %u -> %u (expected %u, delta %u) \n " ,
bts - > cur_fn , fn , fn_next_block ( bts - > cur_fn ) , GSM_TDMA_FN_DIFF ( bts - > cur_fn , fn ) ) ;
2021-03-10 11:19:04 +00:00
}
2021-01-14 15:48:38 +00:00
bts - > cur_fn = fn ;
2013-10-17 17:59:56 +00:00
}
2013-10-19 15:37:48 +00:00
2017-05-16 14:10:45 +00:00
static inline int delta_fn ( int fn , int to )
{
return ( fn + GSM_MAX_FN * 3 / 2 - to ) % GSM_MAX_FN - GSM_MAX_FN / 2 ;
}
2021-03-17 14:26:37 +00:00
void bts_set_current_block_frame_number ( struct gprs_rlcmac_bts * bts , int fn )
2015-08-24 12:35:14 +00:00
{
int delay = 0 ;
const int late_block_delay_thresh = 13 ;
const int fn_update_ok_min_delay = - 500 ;
const int fn_update_ok_max_delay = 0 ;
/* frame numbers in the received blocks are assumed to be strongly
* monotonic . */
2021-01-14 15:48:38 +00:00
if ( bts - > cur_blk_fn > = 0 ) {
int delta = delta_fn ( fn , bts - > cur_blk_fn ) ;
2015-08-24 12:35:14 +00:00
if ( delta < = 0 )
return ;
}
/* Check block delay vs. the current frame number */
2021-01-14 15:48:38 +00:00
if ( bts_current_frame_number ( bts ) ! = 0 )
delay = delta_fn ( fn , bts_current_frame_number ( bts ) ) ;
2015-08-25 13:19:31 +00:00
if ( delay < = - late_block_delay_thresh ) {
2015-08-24 12:35:14 +00:00
LOGP ( DRLCMAC , LOGL_NOTICE ,
" Late RLC block, FN delta: %d FN: %d curFN: %d \n " ,
2021-01-14 15:48:38 +00:00
delay , fn , bts_current_frame_number ( bts ) ) ;
bts_do_rate_ctr_inc ( bts , CTR_RLC_LATE_BLOCK ) ;
2015-08-25 13:19:31 +00:00
}
2015-08-24 12:35:14 +00:00
2021-01-14 15:48:38 +00:00
bts - > cur_blk_fn = fn ;
2015-08-24 12:35:14 +00:00
if ( delay < fn_update_ok_min_delay | | delay > fn_update_ok_max_delay | |
2021-03-10 11:19:04 +00:00
bts_current_frame_number ( bts ) = = FN_UNSET )
bts_set_current_frame_number ( bts , fn ) ;
2015-08-24 12:35:14 +00:00
}
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
/* Helper used by bts_add_paging() whenever the target MS is known */
static void bts_add_paging_known_ms ( struct GprsMs * ms , const struct osmo_mobile_identity * mi , uint8_t chan_needed )
{
uint8_t ts ;
if ( ms - > ul_tbf ) {
for ( ts = 0 ; ts < ARRAY_SIZE ( ms - > ul_tbf - > pdch ) ; ts + + ) {
if ( ms - > ul_tbf - > pdch [ ts ] ) {
LOGPDCH ( ms - > ul_tbf - > pdch [ ts ] , DRLCMAC , LOGL_INFO ,
" Paging on PACCH for %s \n " , tbf_name ( ms - > ul_tbf ) ) ;
if ( ! ms - > ul_tbf - > pdch [ ts ] - > add_paging ( chan_needed , mi ) )
continue ;
return ;
}
}
}
if ( ms - > dl_tbf ) {
for ( ts = 0 ; ts < ARRAY_SIZE ( ms - > dl_tbf - > pdch ) ; ts + + ) {
if ( ms - > dl_tbf - > pdch [ ts ] ) {
LOGPDCH ( ms - > dl_tbf - > pdch [ ts ] , DRLCMAC , LOGL_INFO ,
" Paging on PACCH for %s \n " , tbf_name ( ms - > ul_tbf ) ) ;
if ( ! ms - > dl_tbf - > pdch [ ts ] - > add_paging ( chan_needed , mi ) )
continue ;
return ;
}
}
}
LOGPMS ( ms , DRLCMAC , LOGL_INFO , " Unable to page on PACCH, no available TBFs \n " ) ;
return ;
}
/* ms is NULL if no specific taget was found */
int bts_add_paging ( struct gprs_rlcmac_bts * bts , const struct paging_req_cs * req , struct GprsMs * ms )
2013-10-19 16:28:59 +00:00
{
uint8_t l , trx , ts , any_tbf = 0 ;
struct gprs_rlcmac_tbf * tbf ;
2021-05-13 16:34:08 +00:00
struct llist_head * tmp ;
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
const struct osmo_mobile_identity * mi ;
2022-12-13 16:47:11 +00:00
uint8_t slot_mask [ ARRAY_SIZE ( bts - > trx ) ] ;
2013-10-19 16:28:59 +00:00
int8_t first_ts ; /* must be signed */
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
/* First, build the MI used to page on PDCH from available subscriber info: */
if ( req - > mi_tmsi_present ) {
mi = & req - > mi_tmsi ;
} else if ( req - > mi_imsi_present ) {
mi = & req - > mi_imsi ;
} else {
LOGPMS ( ms , DRLCMAC , LOGL_ERROR , " Unable to page on PACCH, no TMSI nor IMSI in request \n " ) ;
return - EINVAL ;
}
2020-08-21 13:44:58 +00:00
if ( log_check_level ( DRLCMAC , LOGL_INFO ) ) {
char str [ 64 ] ;
paging: pass struct osmo_mobile_identity, not encoded IE bytes
In get_paging_mi(), before this, an encoded buffer of Mobile Identity bytes is
returned. Code paths following this repeatedly decode the Mobile Identity
bytes, e.g. for logging. Also, in get_paging_mi(), since the TMSI is read in
from a different encoding than a typical Mobile Identity IE, the TMSI was
manually encoded into a typical Mobile Identity IE. This is essentially a code
dup of osmo_mobile_identity_encode(). Stop this madness.
Instead, in get_paging_mi(), return a decoded struct osmo_mobile_identity. Code
paths after this use the struct osmo_mobile_identity directly without repeated
decoding.
At the point of finally needing an encoded Mobile Identity IE (in
Encoding::write_paging_request()), do a proper osmo_mobile_identity_encode().
Since this may return errors, add an rc check for the caller of
write_paging_request(), gprs_rlcmac_paging_request().
A side effect is stricter validation of the Mobile Identity passing through the
Paging code path. Before, invalid MI might have passed through unnoticed.
Change-Id: Iad845acb0096b75dc453105c9c16b2252879b4ca
2020-08-21 14:21:23 +00:00
osmo_mobile_identity_to_str_buf ( str , sizeof ( str ) , mi ) ;
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
LOGP ( DRLCMAC , LOGL_INFO , " Add RR paging: chan-needed=%d MI=%s \n " , req - > chan_needed , str ) ;
}
/* We known the target MS for the paging req, send the req only on PDCH
* were that target MS is listening ( first slot is enough ) , and we are done . */
if ( ms ) {
bts_add_paging_known_ms ( ms , mi , req - > chan_needed ) ;
return 0 ;
2020-08-21 13:44:58 +00:00
}
2013-10-19 16:28:59 +00:00
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
/* We don't know the target MS.
* collect slots to page
2021-05-13 16:34:08 +00:00
* Mark up to one slot attached to each of the TBF of the MS .
2013-10-19 16:28:59 +00:00
* Mark only the first slot found .
* Don ' t mark , if TBF uses a different slot that is already marked . */
memset ( slot_mask , 0 , sizeof ( slot_mask ) ) ;
2021-05-13 16:34:08 +00:00
2023-04-17 14:33:35 +00:00
llist_for_each ( tmp , & bts - > ms_list ) {
2021-05-13 16:34:08 +00:00
ms = llist_entry ( tmp , typeof ( * ms ) , list ) ;
struct gprs_rlcmac_tbf * tbfs [ ] = { ms - > ul_tbf , ms - > dl_tbf } ;
for ( l = 0 ; l < ARRAY_SIZE ( tbfs ) ; l + + ) {
2022-10-27 13:40:20 +00:00
tbf = tbfs [ l ] ;
2021-05-13 16:34:08 +00:00
if ( ! tbf )
continue ;
2013-10-19 16:28:59 +00:00
first_ts = - 1 ;
for ( ts = 0 ; ts < 8 ; ts + + ) {
if ( tbf - > pdch [ ts ] ) {
/* remember the first slot found */
if ( first_ts < 0 )
first_ts = ts ;
/* break, if we already marked a slot */
2013-10-27 12:44:37 +00:00
if ( ( slot_mask [ tbf - > trx - > trx_no ] & ( 1 < < ts ) ) )
2013-10-19 16:28:59 +00:00
break ;
}
}
/* mark first slot found, if none is marked already */
if ( ts = = 8 & & first_ts > = 0 ) {
2017-12-15 16:36:45 +00:00
LOGPTBF ( tbf , LOGL_DEBUG , " uses "
2013-10-19 16:28:59 +00:00
" TRX=%d TS=%d, so we mark \n " ,
2013-10-27 15:39:36 +00:00
tbf - > trx - > trx_no , first_ts ) ;
2013-10-27 12:44:37 +00:00
slot_mask [ tbf - > trx - > trx_no ] | = ( 1 < < first_ts ) ;
2013-10-19 16:28:59 +00:00
} else
2017-12-15 16:36:45 +00:00
LOGPTBF ( tbf , LOGL_DEBUG , " uses "
2013-10-19 16:28:59 +00:00
" already marked TRX=%d TS=%d \n " ,
2013-10-27 15:39:36 +00:00
tbf - > trx - > trx_no , ts ) ;
2013-10-19 16:28:59 +00:00
}
}
/* Now we have a list of marked slots. Every TBF uses at least one
* of these slots . */
/* schedule paging to all marked slots */
for ( trx = 0 ; trx < 8 ; trx + + ) {
if ( slot_mask [ trx ] = = 0 )
continue ;
for ( ts = 0 ; ts < 8 ; ts + + ) {
if ( ( slot_mask [ trx ] & ( 1 < < ts ) ) ) {
/* schedule */
Optimize PAGING-CS PDCH set selection when target MS is known
Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).
The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.
This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).
In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.
Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
2021-05-13 15:44:51 +00:00
if ( ! bts - > trx [ trx ] . pdch [ ts ] . add_paging ( req - > chan_needed , mi ) )
2013-10-19 16:28:59 +00:00
return - ENOMEM ;
2018-01-30 11:00:08 +00:00
2021-05-19 10:02:34 +00:00
LOGPDCH ( & bts - > trx [ trx ] . pdch [ ts ] , DRLCMAC , LOGL_INFO , " Paging on PACCH \n " ) ;
2013-10-19 16:33:52 +00:00
any_tbf = 1 ;
2013-10-19 16:28:59 +00:00
}
}
}
if ( ! any_tbf )
LOGP ( DRLCMAC , LOGL_INFO , " No paging, because no TBF \n " ) ;
return 0 ;
}
2021-01-14 15:48:38 +00:00
void bts_send_gsmtap_rach ( struct gprs_rlcmac_bts * bts ,
enum pcu_gsmtap_category categ , uint8_t channel ,
const struct rach_ind_params * rip )
2020-06-10 17:26:15 +00:00
{
2021-01-06 21:44:06 +00:00
struct pcu_l1_meas meas = { 0 } ;
2020-06-10 18:04:44 +00:00
uint8_t ra_buf [ 2 ] ;
/* 3GPP TS 44.004 defines 11 bit RA as follows: xxxx xxxx .... .yyy
* On the PCUIF , we get 16 bit machne dependent number ( LE / BE )
* Over GSMTAP we send the following : xxxx xxxx yyy . . . . .
* This simplifies parsing in Wireshark using its CSN .1 codec . */
if ( rip - > is_11bit ) {
ra_buf [ 0 ] = ( uint8_t ) ( ( rip - > ra > > 3 ) & 0xff ) ;
ra_buf [ 1 ] = ( uint8_t ) ( ( rip - > ra < < 5 ) & 0xff ) ;
} else {
ra_buf [ 0 ] = ( uint8_t ) ( rip - > ra & 0xff ) ;
}
2021-01-14 15:48:38 +00:00
bts_send_gsmtap_meas ( bts , categ , true , rip - > trx_nr , rip - > ts_nr , channel ,
bts_rfn_to_fn ( bts , rip - > rfn ) , ra_buf ,
2020-06-10 17:26:15 +00:00
rip - > is_11bit ? 2 : 1 , & meas ) ;
}
2021-01-14 15:48:38 +00:00
void bts_send_gsmtap ( struct gprs_rlcmac_bts * bts ,
enum pcu_gsmtap_category categ , bool uplink , uint8_t trx_no ,
uint8_t ts_no , uint8_t channel , uint32_t fn ,
const uint8_t * data , unsigned int len )
2020-05-19 15:23:23 +00:00
{
2021-01-13 12:58:14 +00:00
struct pcu_l1_meas meas = { 0 } ;
2021-01-14 15:48:38 +00:00
bts_send_gsmtap_meas ( bts , categ , uplink , trx_no , ts_no , channel , fn , data , len , & meas ) ;
2020-05-19 15:23:23 +00:00
}
2021-01-14 15:48:38 +00:00
void bts_send_gsmtap_meas ( struct gprs_rlcmac_bts * bts ,
enum pcu_gsmtap_category categ , bool uplink , uint8_t trx_no ,
uint8_t ts_no , uint8_t channel , uint32_t fn ,
const uint8_t * data , unsigned int len , struct pcu_l1_meas * meas )
2017-07-21 19:56:23 +00:00
{
uint16_t arfcn ;
/* check if category is activated at all */
2021-01-14 15:48:38 +00:00
if ( ! ( bts - > pcu - > gsmtap_categ_mask & ( 1 < < categ ) ) )
2017-07-21 19:56:23 +00:00
return ;
2021-01-14 15:48:38 +00:00
arfcn = bts - > trx [ trx_no ] . arfcn ;
2017-07-21 19:56:23 +00:00
if ( uplink )
arfcn | = GSMTAP_ARFCN_F_UPLINK ;
2020-05-19 15:23:23 +00:00
/* GSMTAP needs the SNR here, but we only have C/I (meas->link_qual).
Those are not the same , but there is no known way to convert them ,
let ' s pass C / I instead of nothing */
2021-01-14 15:48:38 +00:00
gsmtap_send ( bts - > pcu - > gsmtap , arfcn , ts_no , channel , 0 , fn ,
2020-05-19 15:23:23 +00:00
meas - > rssi , meas - > link_qual , data , len ) ;
2017-07-21 19:56:23 +00:00
}
2014-07-02 15:58:15 +00:00
/* lookup downlink TBF Entity (by TFI) */
2021-01-14 15:48:38 +00:00
struct gprs_rlcmac_dl_tbf * bts_dl_tbf_by_tfi ( struct gprs_rlcmac_bts * bts , uint8_t tfi , uint8_t trx , uint8_t ts )
2014-07-02 15:58:15 +00:00
{
2015-07-10 17:52:37 +00:00
if ( trx > = 8 | | ts > = 8 )
return NULL ;
2014-07-02 15:58:15 +00:00
2021-01-14 15:48:38 +00:00
return bts - > trx [ trx ] . pdch [ ts ] . dl_tbf_by_tfi ( tfi ) ;
2014-07-02 15:58:15 +00:00
}
2015-07-10 17:52:37 +00:00
/* lookup uplink TBF Entity (by TFI) */
2021-01-14 15:48:38 +00:00
struct gprs_rlcmac_ul_tbf * bts_ul_tbf_by_tfi ( struct gprs_rlcmac_bts * bts , uint8_t tfi , uint8_t trx , uint8_t ts )
2013-10-26 17:10:43 +00:00
{
2015-07-10 17:52:37 +00:00
if ( trx > = 8 | | ts > = 8 )
2013-10-26 17:10:43 +00:00
return NULL ;
2021-01-14 15:48:38 +00:00
return bts - > trx [ trx ] . pdch [ ts ] . ul_tbf_by_tfi ( tfi ) ;
2013-10-26 17:10:43 +00:00
}
2020-10-26 13:52:06 +00:00
static unsigned int trx_count_free_tfi ( const struct gprs_rlcmac_trx * trx , enum gprs_rlcmac_tbf_direction dir , uint8_t * first_free_tfi )
{
const struct gprs_rlcmac_pdch * pdch ;
uint8_t ts ;
unsigned int i ;
unsigned int free_tfi_cnt = 0 ;
bool has_pdch = false ;
uint32_t mask = NO_FREE_TFI ;
for ( ts = 0 ; ts < ARRAY_SIZE ( trx - > pdch ) ; ts + + ) {
pdch = & trx - > pdch [ ts ] ;
if ( ! pdch - > is_enabled ( ) )
continue ;
has_pdch = true ;
mask & = ~ pdch - > assigned_tfi ( dir ) ;
}
if ( ! has_pdch | | ! mask ) {
* first_free_tfi = ( uint8_t ) - 1 ;
return 0 ;
}
/* Count free tfis and return */
for ( i = 0 ; i < sizeof ( mask ) * 8 ; i + + ) {
if ( mask & 1 ) {
if ( free_tfi_cnt = = 0 )
* first_free_tfi = i ;
free_tfi_cnt + + ;
}
mask > > = 1 ;
}
return free_tfi_cnt ;
}
2015-07-10 17:52:37 +00:00
/*
2020-10-26 13:52:06 +00:00
* Search for free TFI and return TFI , TRX . This method returns the first TFI
* that is currently not used in any PDCH of a the TRX with least TFIs currently
* assigned . Negative values indicate errors .
2015-07-10 17:52:37 +00:00
*/
2021-01-14 15:48:38 +00:00
int bts_tfi_find_free ( const struct gprs_rlcmac_bts * bts , enum gprs_rlcmac_tbf_direction dir ,
uint8_t * _trx , int8_t use_trx )
2013-10-26 17:17:58 +00:00
{
2020-10-26 13:52:06 +00:00
uint8_t trx_from , trx_to , trx ;
uint8_t best_trx_nr = 0xff ;
unsigned int best_cnt = 0 ;
uint8_t best_first_tfi = 0 ;
2013-10-26 17:17:58 +00:00
2022-12-16 11:54:12 +00:00
if ( use_trx > = 0 & & use_trx < ( int8_t ) ARRAY_SIZE ( bts - > trx ) )
2013-10-26 17:17:58 +00:00
trx_from = trx_to = use_trx ;
else {
trx_from = 0 ;
trx_to = 7 ;
}
2015-07-10 17:52:37 +00:00
/* find a TFI that is unused on all PDCH */
2013-10-26 17:17:58 +00:00
for ( trx = trx_from ; trx < = trx_to ; trx + + ) {
2020-10-26 13:52:06 +00:00
uint8_t tmp_first_tfi ;
unsigned int tmp_cnt ;
2021-01-14 15:48:38 +00:00
tmp_cnt = trx_count_free_tfi ( & bts - > trx [ trx ] , dir , & tmp_first_tfi ) ;
2020-10-26 13:52:06 +00:00
if ( tmp_cnt > best_cnt ) {
best_cnt = tmp_cnt ;
best_first_tfi = tmp_first_tfi ;
best_trx_nr = trx ;
2013-10-26 17:17:58 +00:00
}
}
2020-10-26 13:52:06 +00:00
if ( best_trx_nr = = 0xff | | best_cnt = = 0 ) {
2018-01-26 11:36:43 +00:00
LOGP ( DRLCMAC , LOGL_NOTICE , " No TFI available (suggested TRX: %d). \n " , use_trx ) ;
2021-02-25 17:30:33 +00:00
bts_do_rate_ctr_inc ( bts , CTR_TBF_ALLOC_FAIL_NO_TFI ) ;
2015-07-10 17:52:37 +00:00
return - EBUSY ;
}
2013-10-26 17:17:58 +00:00
2020-10-26 13:52:06 +00:00
OSMO_ASSERT ( best_first_tfi < 32 ) ;
2015-07-10 17:52:37 +00:00
2020-10-26 13:52:06 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " Found first unallocated TRX=%d TFI=%d \n " ,
best_trx_nr , best_first_tfi ) ;
* _trx = best_trx_nr ;
return best_first_tfi ;
2013-10-26 17:17:58 +00:00
}
2023-02-01 15:10:52 +00:00
static int tlli_from_imm_ass ( uint32_t * tlli , const uint8_t * data , uint32_t fn )
2013-10-26 17:49:16 +00:00
{
2022-10-14 15:01:22 +00:00
const struct gsm48_imm_ass * imm_ass = ( struct gsm48_imm_ass * ) data ;
2013-10-26 17:49:16 +00:00
uint8_t plen ;
2022-10-14 15:01:22 +00:00
/* Move to IA Rest Octets: TS 44.018 9.1.18 "The L2 pseudo length of
* this message is the sum of lengths of all information elements
* present in the message except the IA Rest Octets and L2 Pseudo Length
* information elements . " */
/* TS 44.018 10.5.2.19 l2_plen byte lowest 2 bits are '01'B */
plen = imm_ass - > l2_plen > > 2 ;
2013-10-26 17:49:16 +00:00
data + = 1 + plen ;
if ( ( * data & 0xf0 ) ! = 0xd0 ) {
2022-10-12 14:36:46 +00:00
LOGP ( DTBFDL , LOGL_ERROR , " FN=%u Got IMM.ASS confirm, but rest "
2013-10-26 17:49:16 +00:00
" octets do not start with bit sequence 'HH01' "
2022-10-12 14:36:46 +00:00
" (Packet Downlink Assignment) \n " , fn ) ;
2013-10-26 17:49:16 +00:00
return - EINVAL ;
}
/* get TLLI from downlink assignment */
2023-02-01 15:10:52 +00:00
* tlli = ( uint32_t ) ( ( * data + + ) & 0xf ) < < 28 ;
* tlli | = ( * data + + ) < < 20 ;
* tlli | = ( * data + + ) < < 12 ;
* tlli | = ( * data + + ) < < 4 ;
* tlli | = ( * data + + ) > > 4 ;
return 0 ;
}
int bts_rcv_imm_ass_cnf ( struct gprs_rlcmac_bts * bts , const uint8_t * data , uint32_t tlli , uint32_t fn )
{
struct gprs_rlcmac_dl_tbf * dl_tbf ;
GprsMs * ms ;
int rc ;
/* NOTE: A confirmation for a downlink IMMEDIATE ASSIGNMENT can be received using two different methods.
* One way is to send the whole IMMEDIATE ASSIGNMENT back to the PCU and the TLLI , which we use as
* reference is extracted from the rest octets of this message . Alternatively the TLLI may be sent as
* confirmation directly . */
/* Extract TLLI from the presented IMMEDIATE ASSIGNMENT
* ( if present and only when TLLI that is supplied as function parameter is valid . ) */
if ( data & & tlli = = GSM_RESERVED_TMSI ) {
rc = tlli_from_imm_ass ( & tlli , data , fn ) ;
if ( rc ! = 0 )
return - EINVAL ;
}
/* Make sure TLLI is valid */
if ( tlli = = GSM_RESERVED_TMSI ) {
LOGP ( DTBFDL , LOGL_ERROR , " FN=%u Got IMM.ASS confirm, but TLLI is invalid! \n " , fn ) ;
return - EINVAL ;
}
2013-10-26 17:49:16 +00:00
2023-02-01 15:10:52 +00:00
/* Find related TBF and send confirmation signal to FSM */
2023-04-17 16:16:48 +00:00
ms = bts_get_ms_by_tlli ( bts , tlli , GSM_RESERVED_TMSI ) ;
2022-10-12 14:36:46 +00:00
if ( ! ms ) {
LOGP ( DTBFDL , LOGL_ERROR , " FN=%u Got IMM.ASS confirm for unknown MS with TLLI=%08x \n " , fn , tlli ) ;
return - EINVAL ;
}
dl_tbf = ms_dl_tbf ( ms ) ;
2014-08-07 10:37:34 +00:00
if ( ! dl_tbf ) {
2022-10-12 14:36:46 +00:00
LOGPMS ( ms , DTBFDL , LOGL_ERROR , " FN=%u Got IMM.ASS confirm, but MS has no DL TBF! \n " , fn ) ;
2013-10-26 17:49:16 +00:00
return - EINVAL ;
}
2022-10-12 14:36:46 +00:00
LOGPTBFDL ( dl_tbf , LOGL_DEBUG , " FN=%u Got IMM.ASS confirm \n " , fn ) ;
2022-11-17 19:18:46 +00:00
osmo_fsm_inst_dispatch ( dl_tbf - > state_fi , TBF_EV_ASSIGN_PCUIF_CNF , NULL ) ;
2013-10-26 17:49:16 +00:00
return 0 ;
}
2017-02-21 18:35:23 +00:00
/* Determine the full frame number from a relative frame number */
2023-01-05 11:04:55 +00:00
uint32_t bts_rfn_to_fn ( const struct gprs_rlcmac_bts * bts , uint32_t rfn )
2017-02-21 18:35:23 +00:00
{
2023-01-05 11:04:55 +00:00
uint32_t m_cur_rfn ;
uint32_t fn_rounded ;
bts.cpp: Fix overloading ambiguity
Fix error introduced in 1275a3f91a744e011b0dba82b09124d249c7abb5 by
using signed 32 bit integer which is enough for Frame Number in
GSM. Also, mark parameter constraints more explicitly:
- add assert for expected FN values
- don't perform computation for non-relative FN
The error was:
bts.cpp: In member function ‘uint32_t BTS::rfn_to_fn(uint32_t)’:
bts.cpp:554:25: error: call of overloaded ‘abs(uint32_t)’ is ambiguous
if (abs(rfn - m_cur_rfn) > RFN_THRESHOLD) {
^
In file included from /usr/include/c++/6/cstdlib:75:0,
from /usr/include/c++/6/stdlib.h:36,
from /usr/include/osmocom/core/linuxrbtree.h:97,
from /usr/include/osmocom/core/timer.h:35,
from ./bts.h:29,
from bts.cpp:21:
/usr/include/stdlib.h:735:12: note: candidate: int abs(int)
extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
^~~
In file included from /usr/include/c++/6/stdlib.h:36:0,
from /usr/include/osmocom/core/linuxrbtree.h:97,
from /usr/include/osmocom/core/timer.h:35,
from ./bts.h:29,
from bts.cpp:21:
/usr/include/c++/6/cstdlib:185:3: note: candidate: __int128 std::abs(__int128)
abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
^~~
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
abs(long long __x) { return __builtin_llabs (__x); }
^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
abs(long __i) { return __builtin_labs(__i); }
Change-Id: Ib6d895a97aa35414f245ea4406c6e78f1b4fb5b8
2017-03-08 11:06:42 +00:00
2017-02-21 18:35:23 +00:00
/* Ensure that all following calculations are performed with the
* relative frame number */
2023-05-31 17:10:51 +00:00
OSMO_ASSERT ( rfn < RFN_MODULUS ) ;
2017-02-21 18:35:23 +00:00
/* Compute an internal relative frame number from the full internal
frame number */
2023-05-31 17:10:51 +00:00
m_cur_rfn = fn2rfn ( bts - > cur_fn ) ;
2017-02-21 18:35:23 +00:00
/* Compute a "rounded" version of the internal frame number, which
* exactly fits in the RFN_MODULUS raster */
2023-01-05 11:04:55 +00:00
fn_rounded = GSM_TDMA_FN_SUB ( bts - > cur_fn , m_cur_rfn ) ;
2017-02-21 18:35:23 +00:00
/* If the delta between the internal and the external relative frame
* number exceeds a certain limit , we need to assume that the incoming
* rach request belongs to a the previous rfn period . To correct this ,
* we roll back the rounded frame number by one RFN_MODULUS */
2023-01-05 11:04:55 +00:00
if ( GSM_TDMA_FN_DIFF ( rfn , m_cur_rfn ) > RFN_THRESHOLD ) {
2017-02-21 18:35:23 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG ,
2018-10-06 08:42:58 +00:00
" Race condition between rfn (%u) and m_cur_fn (%u) detected: rfn belongs to the previous modulus %u cycle, wrapping... \n " ,
2021-01-14 15:48:38 +00:00
rfn , bts - > cur_fn , RFN_MODULUS ) ;
2017-02-21 18:35:23 +00:00
if ( fn_rounded < RFN_MODULUS ) {
LOGP ( DRLCMAC , LOGL_DEBUG ,
" Cornercase detected: wrapping crosses %u border \n " ,
GSM_MAX_FN ) ;
2023-01-05 11:04:55 +00:00
fn_rounded = GSM_TDMA_FN_SUB ( GSM_MAX_FN , ( GSM_TDMA_FN_SUB ( RFN_MODULUS , fn_rounded ) ) ) ;
2017-02-21 18:35:23 +00:00
}
else
2023-01-05 11:04:55 +00:00
fn_rounded = GSM_TDMA_FN_SUB ( fn_rounded , RFN_MODULUS ) ;
2017-02-21 18:35:23 +00:00
}
/* The real frame number is the sum of the rounded frame number and the
* relative framenumber computed via RACH */
2023-01-05 11:04:55 +00:00
return GSM_TDMA_FN_SUM ( fn_rounded , rfn ) ;
2017-02-21 18:35:23 +00:00
}
2020-05-08 12:20:32 +00:00
/* 3GPP TS 44.060:
2020-05-21 12:55:46 +00:00
* Table 11.2 .5 .2 : PACKET CHANNEL REQUEST
* Table 11.2 .5 a .2 : EGPRS PACKET CHANNEL REQUEST
* Both GPRS and EGPRS use same MultislotClass coding , but since PRACH is
2020-05-08 12:20:32 +00:00
* deprecated , no PACKET CHANNEL REQUEST exists , which means for GPRS we will
* receive CCCH RACH which doesn ' t contain any mslot class . Hence in the end we
2020-05-21 12:55:46 +00:00
* can only receive EGPRS mslot class through 11 - bit EGPRS PACKET CHANNEL REQUEST . */
static int parse_egprs_pkt_ch_req ( uint16_t ra11 , struct chan_req_params * chan_req )
2018-01-05 14:04:50 +00:00
{
2020-05-21 13:20:34 +00:00
EGPRS_PacketChannelRequest_t req ;
int rc ;
rc = decode_egprs_pkt_ch_req ( ra11 , & req ) ;
if ( rc ) {
LOGP ( DRLCMAC , LOGL_NOTICE , " Failed to decode "
" EGPRS Packet Channel Request: rc=%d \n " , rc ) ;
return rc ;
}
LOGP ( DRLCMAC , LOGL_INFO , " Rx EGPRS Packet Channel Request: %s \n " ,
get_value_string ( egprs_pkt_ch_req_type_names , req . Type ) ) ;
switch ( req . Type ) {
case EGPRS_PKT_CHAN_REQ_ONE_PHASE :
chan_req - > egprs_mslot_class = req . Content . MultislotClass + 1 ;
chan_req - > priority = req . Content . Priority + 1 ;
break ;
case EGPRS_PKT_CHAN_REQ_SHORT :
chan_req - > priority = req . Content . Priority + 1 ;
if ( req . Content . NumberOfBlocks = = 0 )
chan_req - > single_block = true ;
break ;
case EGPRS_PKT_CHAN_REQ_ONE_PHASE_RED_LATENCY :
chan_req - > priority = req . Content . Priority + 1 ;
break ;
/* Two phase access => single block is needed */
case EGPRS_PKT_CHAN_REQ_TWO_PHASE :
case EGPRS_PKT_CHAN_REQ_TWO_PHASE_IPA :
chan_req - > priority = req . Content . Priority + 1 ;
chan_req - > single_block = true ;
break ;
/* Signalling => single block is needed */
case EGPRS_PKT_CHAN_REQ_SIGNALLING :
case EGPRS_PKT_CHAN_REQ_SIGNALLING_IPA :
chan_req - > single_block = true ;
break ;
/* Neither unacknowledged RLC mode, nor emergency calls are supported */
case EGPRS_PKT_CHAN_REQ_ONE_PHASE_UNACK :
case EGPRS_PKT_CHAN_REQ_EMERGENCY_CALL :
case EGPRS_PKT_CHAN_REQ_DEDICATED_CHANNEL :
LOGP ( DRLCMAC , LOGL_NOTICE , " %s is not supported, rejecting \n " ,
get_value_string ( egprs_pkt_ch_req_type_names , req . Type ) ) ;
return - ENOTSUP ;
default :
LOGP ( DRLCMAC , LOGL_ERROR , " Unknown EGPRS Packet Channel Request "
" type=0x%02x, probably a bug in CSN.1 codec \n " , req . Type ) ;
return - EINVAL ;
}
2018-01-05 14:04:50 +00:00
return 0 ;
}
2020-05-21 12:55:46 +00:00
/* NOTE: chan_req needs to be zero-initialized by the caller */
static int parse_rach_ind ( const struct rach_ind_params * rip ,
struct chan_req_params * chan_req )
2018-01-05 14:04:50 +00:00
{
2020-05-21 12:55:46 +00:00
int rc ;
2018-01-05 14:04:50 +00:00
2020-05-21 12:55:46 +00:00
switch ( rip - > burst_type ) {
case GSM_L1_BURST_TYPE_NONE :
LOGP ( DRLCMAC , LOGL_ERROR , " RACH.ind contains no burst type, assuming TS0 \n " ) ;
/* fall-through */
2018-01-05 14:53:08 +00:00
case GSM_L1_BURST_TYPE_ACCESS_0 :
2020-05-21 12:55:46 +00:00
if ( rip - > is_11bit ) { /* 11 bit Access Burst with TS0 => Packet Channel Request */
LOGP ( DRLCMAC , LOGL_ERROR , " 11 bit Packet Channel Request "
" is not supported (PBCCH is deprecated) \n " ) ;
return - ENOTSUP ;
2018-01-05 14:04:50 +00:00
}
2020-05-21 12:55:46 +00:00
/* 3GPP TS 44.018, table 9.1.8.1: 8 bit CHANNEL REQUEST.
* Mask 01110 xxx indicates single block packet access . */
chan_req - > single_block = ( ( rip - > ra & 0xf8 ) = = 0x70 ) ;
2018-01-05 14:53:08 +00:00
break ;
2020-05-21 12:55:46 +00:00
case GSM_L1_BURST_TYPE_ACCESS_1 :
2018-01-05 14:53:08 +00:00
case GSM_L1_BURST_TYPE_ACCESS_2 :
2020-05-21 12:55:46 +00:00
if ( ! rip - > is_11bit ) { /* TS1/TS2 => EGPRS Packet Channel Request (always 11 bit) */
LOGP ( DRLCMAC , LOGL_ERROR , " 11 bit Packet Channel Request "
" is not supported (PBCCH is deprecated) \n " ) ;
return - ENOTSUP ;
2018-01-05 14:04:50 +00:00
}
2020-05-21 12:55:46 +00:00
rc = parse_egprs_pkt_ch_req ( rip - > ra , chan_req ) ;
if ( rc )
return rc ;
2018-01-05 14:53:08 +00:00
break ;
default :
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_ERROR , " RACH.ind contains unknown burst type 0x%02x "
" (%u bit) \n " , rip - > burst_type , rip - > is_11bit ? 11 : 8 ) ;
return - EINVAL ;
2018-01-05 14:04:50 +00:00
}
2020-05-21 12:55:46 +00:00
return 0 ;
2018-01-05 14:04:50 +00:00
}
Add new PDCH UL Controller, drop SBAllocator class
Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.
This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.
As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.
Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
2021-03-08 13:57:58 +00:00
struct gprs_rlcmac_sba * bts_alloc_sba ( struct gprs_rlcmac_bts * bts , uint8_t ta )
{
struct gprs_rlcmac_pdch * pdch ;
struct gprs_rlcmac_sba * sba = NULL ;
int8_t trx , ts ;
if ( ! gsm48_ta_is_valid ( ta ) )
return NULL ;
for ( trx = 0 ; trx < 8 ; trx + + ) {
for ( ts = 7 ; ts > = 0 ; ts - - ) {
pdch = & bts - > trx [ trx ] . pdch [ ts ] ;
if ( ! pdch - > is_enabled ( ) )
continue ;
break ;
}
if ( ts > = 0 )
break ;
}
if ( trx = = 8 ) {
LOGP ( DRLCMAC , LOGL_NOTICE , " No PDCH available. \n " ) ;
return NULL ;
}
sba = sba_alloc ( bts , pdch , ta ) ;
if ( ! sba )
return NULL ;
bts_do_rate_ctr_inc ( bts , CTR_SBA_ALLOCATED ) ;
return sba ;
}
2021-01-14 15:48:38 +00:00
int bts_rcv_rach ( struct gprs_rlcmac_bts * bts , const struct rach_ind_params * rip )
2013-10-26 18:56:20 +00:00
{
2020-05-21 12:55:46 +00:00
struct chan_req_params chan_req = { 0 } ;
2015-05-04 06:21:17 +00:00
struct gprs_rlcmac_ul_tbf * tbf = NULL ;
Add new PDCH UL Controller, drop SBAllocator class
Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.
This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.
As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.
Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
2021-03-08 13:57:58 +00:00
struct gprs_rlcmac_sba * sba ;
2021-10-18 11:29:56 +00:00
struct gprs_rlcmac_pdch * pdch ;
struct gprs_rlcmac_trx * trx ;
2013-10-26 18:56:20 +00:00
uint32_t sb_fn = 0 ;
2016-01-20 17:26:13 +00:00
uint8_t usf = 7 ;
2020-05-21 12:55:46 +00:00
int plen , rc ;
2013-10-26 18:56:20 +00:00
2021-10-18 11:29:56 +00:00
/* Allocate a bit-vector for RR Immediate Assignment [Reject] */
struct bitvec * bv = bitvec_alloc ( 22 , tall_pcu_ctx ) ; /* without plen */
bitvec_unhex ( bv , DUMMY_VEC ) ; /* standard '2B'O padding */
2021-01-14 15:48:38 +00:00
bts_do_rate_ctr_inc ( bts , CTR_RACH_REQUESTS ) ;
2013-10-27 09:50:35 +00:00
2020-05-21 12:55:46 +00:00
if ( rip - > is_11bit )
2021-11-02 15:47:06 +00:00
bts_do_rate_ctr_inc ( bts , CTR_RACH_REQUESTS_11BIT ) ;
2016-11-10 12:46:30 +00:00
2017-02-21 18:35:23 +00:00
/* Determine full frame number */
2021-01-14 15:48:38 +00:00
uint32_t Fn = bts_rfn_to_fn ( bts , rip - > rfn ) ;
2020-05-21 12:55:46 +00:00
uint8_t ta = qta2ta ( rip - > qta ) ;
2021-01-14 15:48:38 +00:00
bts_send_gsmtap_rach ( bts , PCU_GSMTAP_C_UL_RACH , GSMTAP_CHANNEL_RACH , rip ) ;
2016-11-07 12:07:36 +00:00
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " MS requests Uplink resource on CCCH/RACH: "
" ra=0x%02x (%d bit) Fn=%u qta=%d \n " , rip - > ra ,
rip - > is_11bit ? 11 : 8 , Fn , rip - > qta ) ;
2019-09-30 16:33:14 +00:00
2020-05-21 12:55:46 +00:00
/* Parse [EGPRS Packet] Channel Request from RACH.ind */
rc = parse_rach_ind ( rip , & chan_req ) ;
2021-11-02 16:20:59 +00:00
if ( rc ) {
bts_do_rate_ctr_inc ( bts , CTR_RACH_REQUESTS_UNEXPECTED ) ;
/* Send RR Immediate Assignment Reject */
2020-05-21 12:55:46 +00:00
goto send_imm_ass_rej ;
2021-11-02 16:20:59 +00:00
}
2016-09-14 15:00:31 +00:00
2021-11-02 15:59:13 +00:00
if ( chan_req . single_block ) {
bts_do_rate_ctr_inc ( bts , CTR_RACH_REQUESTS_TWO_PHASE ) ;
2021-11-02 16:14:46 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " MS requests single block allocation "
" (two phase packet access) \n " ) ;
2021-11-02 15:59:13 +00:00
} else {
bts_do_rate_ctr_inc ( bts , CTR_RACH_REQUESTS_ONE_PHASE ) ;
2021-11-02 13:08:04 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " MS requests single TS uplink transmission "
2021-11-02 15:59:13 +00:00
" (one phase packet access) \n " ) ;
if ( bts - > pcu - > vty . force_two_phase ) {
LOGP ( DRLCMAC , LOGL_DEBUG , " Forcing two phase access \n " ) ;
chan_req . single_block = true ;
}
2020-05-21 12:55:46 +00:00
}
2016-09-14 15:00:31 +00:00
2020-05-21 13:20:34 +00:00
/* TODO: handle Radio Priority (see 3GPP TS 44.060, table 11.2.5a.5) */
if ( chan_req . priority > 0 )
LOGP ( DRLCMAC , LOGL_NOTICE , " EGPRS Packet Channel Request indicates "
" Radio Priority %u, however we ignore it \n " , chan_req . priority ) ;
2020-05-21 12:55:46 +00:00
/* Should we allocate a single block or an Uplink TBF? */
if ( chan_req . single_block ) {
Add new PDCH UL Controller, drop SBAllocator class
Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.
This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.
As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.
Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
2021-03-08 13:57:58 +00:00
sba = bts_alloc_sba ( bts , ta ) ;
if ( ! sba ) {
2016-11-09 10:57:00 +00:00
LOGP ( DRLCMAC , LOGL_NOTICE , " No PDCH resource for "
Add new PDCH UL Controller, drop SBAllocator class
Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.
This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.
As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.
Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
2021-03-08 13:57:58 +00:00
" single block allocation \n " ) ;
rc = - EBUSY ;
2020-05-21 12:55:46 +00:00
/* Send RR Immediate Assignment Reject */
goto send_imm_ass_rej ;
2016-11-09 10:57:00 +00:00
}
2020-05-21 12:55:46 +00:00
2021-10-18 11:20:32 +00:00
pdch = sba - > pdch ;
Add new PDCH UL Controller, drop SBAllocator class
Right now we handle different types of UL allocations in different
classes like PollAllocator and SBAllocator, and they usually don't take
into account the other one in most cases. Furthermore, those objects are
usually per-BTS object, instead of per PDCH object.
This is a first step towards having a unified per-PDCH controller which
takes care of controlling what is scheduled and hence expected on the
uplink. Each PDCH has a UL Controller which keeps track of all reserved
uplink frame, be it SB, RRBP poll or USF assigned, all under the same
API.
As a first step, only the SBA part is fully implemented and used (being
it the easiest part to replace); TBF poll+usf will come in follow-up
patches later on. As a result, the SBAllocator per-BTS class dissappears
but some of its code is refactored/reused to provide more features to the
gprs_rlcmac_sba object, which is also further integrated into the new UL
Controller.
Related: OS#5020
Change-Id: I84b24beea4a1aa2c1528f41435f77bd16df2b947
2021-03-08 13:57:58 +00:00
sb_fn = sba - > fn ;
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " Allocated a single block at "
2021-10-18 11:20:32 +00:00
" SBFn=%u TRX=%u TS=%u \n " , sb_fn , pdch - > trx - > trx_no , pdch - > ts_no ) ;
2021-11-02 16:46:43 +00:00
bts_do_rate_ctr_inc ( bts , CTR_IMMEDIATE_ASSIGN_UL_TBF_TWO_PHASE ) ;
2013-10-26 18:56:20 +00:00
} else {
2023-04-19 17:42:05 +00:00
GprsMs * ms = ms_alloc ( bts , __func__ ) ;
2023-04-17 12:49:29 +00:00
ms_set_egprs_ms_class ( ms , chan_req . egprs_mslot_class ) ;
2022-10-28 17:50:09 +00:00
tbf = ms_new_ul_tbf_assigned_agch ( ms ) ;
2023-04-19 17:42:05 +00:00
/* Here either tbf was created and it holds a ref to MS, or tbf
* creation failed and MS will end up without references and being
* freed : */
ms_unref ( ms , __func__ ) ;
2013-10-26 18:56:20 +00:00
if ( ! tbf ) {
2020-05-21 12:55:46 +00:00
/* Send RR Immediate Assignment Reject */
2016-11-09 10:57:00 +00:00
rc = - EBUSY ;
2020-05-21 12:55:46 +00:00
goto send_imm_ass_rej ;
2013-10-26 18:56:20 +00:00
}
2020-05-21 12:55:46 +00:00
tbf - > set_ta ( ta ) ;
2022-12-13 13:14:32 +00:00
/* Only single TS can be allocated through AGCH, hence first TS is the only one: */
pdch = tbf_get_first_ts ( tbf ) ;
2021-10-18 11:20:32 +00:00
usf = tbf - > m_usf [ pdch - > ts_no ] ;
2021-11-02 16:46:43 +00:00
bts_do_rate_ctr_inc ( bts , CTR_IMMEDIATE_ASSIGN_UL_TBF_ONE_PHASE ) ;
2013-10-26 18:56:20 +00:00
}
2021-10-18 11:20:32 +00:00
trx = pdch - > trx ;
2016-01-20 17:26:13 +00:00
2021-10-18 11:29:56 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " Tx Immediate Assignment on AGCH: "
" TRX=%u (ARFCN %u) TS=%u TA=%u TSC=%u TFI=%d USF=%d \n " ,
trx - > trx_no , trx - > arfcn & ~ ARFCN_FLAG_MASK ,
2021-10-18 11:35:05 +00:00
pdch - > ts_no , ta , pdch - > tsc , tbf ? tbf - > tfi ( ) : - 1 , usf ) ;
2021-10-18 11:29:56 +00:00
plen = Encoding : : write_immediate_assignment ( pdch , tbf , bv ,
false , rip - > ra , Fn , ta , usf , false , sb_fn ,
bts_get_ms_pwr_alpha ( bts ) , bts - > pcu - > vty . gamma , - 1 ,
rip - > burst_type ) ;
bts_do_rate_ctr_inc ( bts , CTR_IMMEDIATE_ASSIGN_UL_TBF ) ;
if ( plen > = 0 ) {
pcu_l1if_tx_agch ( bts , bv , plen ) ;
rc = 0 ;
2020-05-21 12:55:46 +00:00
} else {
2021-10-18 11:29:56 +00:00
rc = plen ;
2016-11-10 12:46:30 +00:00
}
2021-10-18 11:29:56 +00:00
bitvec_free ( bv ) ;
return rc ;
2016-02-01 15:13:38 +00:00
2021-10-18 11:29:56 +00:00
send_imm_ass_rej :
LOGP ( DRLCMAC , LOGL_DEBUG , " Tx Immediate Assignment Reject on AGCH \n " ) ;
plen = Encoding : : write_immediate_assignment_reject (
bv , rip - > ra , Fn , rip - > burst_type ,
( uint8_t ) osmo_tdef_get ( bts - > T_defs_bts , 3142 , OSMO_TDEF_S , - 1 ) ) ;
bts_do_rate_ctr_inc ( bts , CTR_IMMEDIATE_ASSIGN_REJ ) ;
2020-05-21 12:55:46 +00:00
if ( plen > = 0 )
2021-01-18 16:14:14 +00:00
pcu_l1if_tx_agch ( bts , bv , plen ) ;
2020-05-21 12:55:46 +00:00
bitvec_free ( bv ) ;
2021-10-18 11:29:56 +00:00
/* rc was already properly set before goto */
2016-11-09 10:57:00 +00:00
return rc ;
2013-10-26 18:56:20 +00:00
}
2019-10-05 16:45:31 +00:00
/* PTCCH/U sub-slot / frame-number mapping (see 3GPP TS 45.002, table 6) */
static uint32_t ptcch_slot_map [ PTCCH_TAI_NUM ] = {
12 , 38 , 64 , 90 ,
116 , 142 , 168 , 194 ,
220 , 246 , 272 , 298 ,
324 , 350 , 376 , 402 ,
} ;
2021-01-14 15:48:38 +00:00
int bts_rcv_ptcch_rach ( struct gprs_rlcmac_bts * bts , const struct rach_ind_params * rip )
2019-10-05 16:45:31 +00:00
{
2021-01-14 15:48:38 +00:00
uint32_t fn416 = bts_rfn_to_fn ( bts , rip - > rfn ) % 416 ;
2019-10-05 16:45:31 +00:00
struct gprs_rlcmac_pdch * pdch ;
uint8_t ss ;
2021-01-14 15:48:38 +00:00
bts_send_gsmtap_rach ( bts , PCU_GSMTAP_C_UL_PTCCH , GSMTAP_CHANNEL_PTCCH , rip ) ;
2020-06-10 17:26:15 +00:00
2019-10-05 16:45:31 +00:00
/* Prevent buffer overflow */
2020-05-21 12:55:46 +00:00
if ( rip - > trx_nr > = ARRAY_SIZE ( bts - > trx ) | | rip - > ts_nr > = 8 ) {
LOGP ( DRLCMAC , LOGL_ERROR , " (TRX=%u TS=%u RFN=%u) Rx malformed "
" RACH.ind (PTCCH/U) \n " , rip - > trx_nr , rip - > ts_nr , rip - > rfn ) ;
2019-10-05 16:45:31 +00:00
return - EINVAL ;
}
/* Make sure PDCH time-slot is enabled */
2020-05-21 12:55:46 +00:00
pdch = & bts - > trx [ rip - > trx_nr ] . pdch [ rip - > ts_nr ] ;
2021-08-31 12:56:17 +00:00
if ( ! pdch - > is_enabled ( ) ) {
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_NOTICE , " (TRX=%u TS=%u RFN=%u) Rx RACH.ind (PTCCH/U) "
" for inactive PDCH \n " , rip - > trx_nr , rip - > ts_nr , rip - > rfn ) ;
2019-10-05 16:45:31 +00:00
return - EAGAIN ;
}
/* Convert TDMA frame-number to PTCCH/U sub-slot number */
for ( ss = 0 ; ss < PTCCH_TAI_NUM ; ss + + )
if ( ptcch_slot_map [ ss ] = = fn416 )
break ;
if ( ss = = PTCCH_TAI_NUM ) {
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_ERROR , " (TRX=%u TS=%u RFN=%u) Failed to map "
" PTCCH/U sub-slot \n " , rip - > trx_nr , rip - > ts_nr , rip - > rfn ) ;
2019-10-05 16:45:31 +00:00
return - ENODEV ;
}
/* Apply the new Timing Advance value */
LOGP ( DRLCMAC , LOGL_INFO , " Continuous Timing Advance update "
2020-05-21 12:55:46 +00:00
" for TAI %u, new TA is %u \n " , ss , qta2ta ( rip - > qta ) ) ;
pdch - > update_ta ( ss , qta2ta ( rip - > qta ) ) ;
2019-10-05 16:45:31 +00:00
return 0 ;
}
2022-12-12 18:46:01 +00:00
void bts_snd_dl_ass ( struct gprs_rlcmac_bts * bts , const struct gprs_rlcmac_dl_tbf * tbf )
2013-10-26 18:12:59 +00:00
{
int plen ;
2022-12-13 13:14:32 +00:00
const struct gprs_rlcmac_pdch * pdch ;
2013-10-26 18:12:59 +00:00
2017-12-15 16:36:45 +00:00
LOGPTBF ( tbf , LOGL_INFO , " TX: START Immediate Assignment Downlink (PCH) \n " ) ;
2022-12-13 13:14:32 +00:00
/* Only one TS can be assigned through PCH, hence the first one is the only one: */
pdch = tbf_get_first_ts_const ( tbf ) ;
2017-02-04 02:10:08 +00:00
bitvec * immediate_assignment = bitvec_alloc ( 22 , tall_pcu_ctx ) ; /* without plen */
2020-07-18 13:33:08 +00:00
bitvec_unhex ( immediate_assignment , DUMMY_VEC ) ; /* standard '2B'O padding */
2022-10-26 13:34:44 +00:00
/* 3GPP TS 44.018, section 9.1.18.0d states that the network shall code the
* Request Reference IE , e . g . by using a suitably offset frame number , such
* that the resource reference cannot be confused with any CHANNEL REQUEST
* message sent by a mobile station . Use last_rts_fn + 21216 ( 16 TDMA
* super - frame periods , or ~ 21.3 seconds ) to achieve a decent distance . */
2021-03-29 16:40:18 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " - TRX=%d (%d) TS=%d TA=%d \n " ,
2022-12-13 13:14:32 +00:00
tbf - > trx - > trx_no , tbf - > trx - > arfcn , pdch - > ts_no , tbf - > ta ( ) ) ;
plen = Encoding : : write_immediate_assignment ( pdch ,
2020-07-18 16:34:17 +00:00
tbf , immediate_assignment , true , 125 ,
2022-12-13 13:14:32 +00:00
GSM_TDMA_FN_SUM ( pdch - > last_rts_fn , 21216 ) ,
2021-03-29 16:40:18 +00:00
tbf - > ta ( ) , 7 , false , 0 ,
2021-02-09 17:47:34 +00:00
bts_get_ms_pwr_alpha ( bts ) , bts - > pcu - > vty . gamma , - 1 ,
2019-02-18 17:52:38 +00:00
GSM_L1_BURST_TYPE_ACCESS_0 ) ;
2016-11-10 12:46:30 +00:00
if ( plen > = 0 ) {
2021-01-14 15:48:38 +00:00
bts_do_rate_ctr_inc ( bts , CTR_IMMEDIATE_ASSIGN_DL_TBF ) ;
2023-02-01 12:51:56 +00:00
if ( the_pcu - > pcu_if_version > = 0x0b )
pcu_l1if_tx_pch_dt ( bts , immediate_assignment , plen , tbf - > imsi ( ) , tbf - > tlli ( ) ) ;
else
2023-03-03 15:04:26 +00:00
pcu_l1if_tx_pch ( bts , immediate_assignment , plen , tbf - > imsi ( ) ) ;
2016-11-10 12:46:30 +00:00
}
2013-10-26 18:12:59 +00:00
bitvec_free ( immediate_assignment ) ;
}
2020-10-30 17:35:54 +00:00
/* return maximum DL CS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
uint8_t bts_max_cs_dl ( const struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
return bts - > max_cs_dl ;
2020-10-30 17:35:54 +00:00
}
/* return maximum UL CS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
uint8_t bts_max_cs_ul ( const struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
return bts - > max_cs_ul ;
2020-10-30 17:35:54 +00:00
}
/* return maximum DL MCS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
uint8_t bts_max_mcs_dl ( const struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
return bts - > max_mcs_dl ;
2020-10-30 17:35:54 +00:00
}
/* return maximum UL MCS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
uint8_t bts_max_mcs_ul ( const struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
return bts - > max_mcs_ul ;
2020-10-30 17:35:54 +00:00
}
/* Set maximum DL CS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
void bts_set_max_cs_dl ( struct gprs_rlcmac_bts * bts , uint8_t cs_dl )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
bts - > max_cs_dl = cs_dl ;
2020-10-30 17:35:54 +00:00
}
/* Set maximum UL CS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
void bts_set_max_cs_ul ( struct gprs_rlcmac_bts * bts , uint8_t cs_ul )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
bts - > max_cs_ul = cs_ul ;
2020-10-30 17:35:54 +00:00
}
/* Set maximum DL MCS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
void bts_set_max_mcs_dl ( struct gprs_rlcmac_bts * bts , uint8_t mcs_dl )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
bts - > max_mcs_dl = mcs_dl ;
2020-10-30 17:35:54 +00:00
}
/* Set maximum UL MCS supported by BTS and allowed by VTY */
2021-01-14 15:48:38 +00:00
void bts_set_max_mcs_ul ( struct gprs_rlcmac_bts * bts , uint8_t mcs_ul )
2020-10-30 17:35:54 +00:00
{
2021-01-14 15:48:38 +00:00
bts - > max_mcs_ul = mcs_ul ;
2020-10-30 17:35:54 +00:00
}
2013-10-26 15:32:04 +00:00
2021-01-14 15:48:38 +00:00
bool bts_cs_dl_is_supported ( const struct gprs_rlcmac_bts * bts , CodingScheme cs )
Implement downgrade to DL MCS1-4 when USF for GPRS_only MS
In previous status, if USF for GPRS-only MS was selected, then EGPRS
TBFs were skipped and either a GPRS TBF was selected or a Dummy Block
was sent. That means the behavior was unfair towards EGPRS TBFs, because
sometimes they were skipped in favor of GPRS ones.
This patch imporves the situation in the above mentioned USF scenario, by
first, under specific conditions, allowing selection of an EGPRS TBF and
then forcing it to transmit in EGPRS-GMSK (MCS1-4) so that the
USF-targeted MS can still decode the USF, while at the same time
providing more fairness by allowing the EGPRS TBF to transmit data.
The specific conditions mentioned above are, mainly, related to the fact
that once a DL data block has been sent, and hence a BSN was assigned to
it, it cannot be retransmitted later using another MCS, since lower
MCS1-4 wouldn't be able to contain higher MCS RLC payload.
The set of conditions could be expanded in the future by also selecting
the EGPRS TBF if retransmition is required and the block to be
retransmitted was originally transmitted as MCS1-4.
Related: OS#4544
Change-Id: I9af23e175435fe9ae7b0e4119ad52fcd4707b9ca
2020-11-16 17:49:39 +00:00
{
OSMO_ASSERT ( mcs_is_valid ( cs ) ) ;
uint8_t num = mcs_chan_code ( cs ) ;
if ( mcs_is_gprs ( cs ) ) {
2021-01-14 15:48:38 +00:00
return ( bts_max_cs_dl ( bts ) > = num ) & & ( bts - > cs_mask & ( 1U < < num ) ) ;
Implement downgrade to DL MCS1-4 when USF for GPRS_only MS
In previous status, if USF for GPRS-only MS was selected, then EGPRS
TBFs were skipped and either a GPRS TBF was selected or a Dummy Block
was sent. That means the behavior was unfair towards EGPRS TBFs, because
sometimes they were skipped in favor of GPRS ones.
This patch imporves the situation in the above mentioned USF scenario, by
first, under specific conditions, allowing selection of an EGPRS TBF and
then forcing it to transmit in EGPRS-GMSK (MCS1-4) so that the
USF-targeted MS can still decode the USF, while at the same time
providing more fairness by allowing the EGPRS TBF to transmit data.
The specific conditions mentioned above are, mainly, related to the fact
that once a DL data block has been sent, and hence a BSN was assigned to
it, it cannot be retransmitted later using another MCS, since lower
MCS1-4 wouldn't be able to contain higher MCS RLC payload.
The set of conditions could be expanded in the future by also selecting
the EGPRS TBF if retransmition is required and the block to be
retransmitted was originally transmitted as MCS1-4.
Related: OS#4544
Change-Id: I9af23e175435fe9ae7b0e4119ad52fcd4707b9ca
2020-11-16 17:49:39 +00:00
} else {
2021-01-14 15:48:38 +00:00
return ( bts_max_mcs_dl ( bts ) > = num ) & & ( bts - > mcs_mask & ( 1U < < num ) ) ;
Implement downgrade to DL MCS1-4 when USF for GPRS_only MS
In previous status, if USF for GPRS-only MS was selected, then EGPRS
TBFs were skipped and either a GPRS TBF was selected or a Dummy Block
was sent. That means the behavior was unfair towards EGPRS TBFs, because
sometimes they were skipped in favor of GPRS ones.
This patch imporves the situation in the above mentioned USF scenario, by
first, under specific conditions, allowing selection of an EGPRS TBF and
then forcing it to transmit in EGPRS-GMSK (MCS1-4) so that the
USF-targeted MS can still decode the USF, while at the same time
providing more fairness by allowing the EGPRS TBF to transmit data.
The specific conditions mentioned above are, mainly, related to the fact
that once a DL data block has been sent, and hence a BSN was assigned to
it, it cannot be retransmitted later using another MCS, since lower
MCS1-4 wouldn't be able to contain higher MCS RLC payload.
The set of conditions could be expanded in the future by also selecting
the EGPRS TBF if retransmition is required and the block to be
retransmitted was originally transmitted as MCS1-4.
Related: OS#4544
Change-Id: I9af23e175435fe9ae7b0e4119ad52fcd4707b9ca
2020-11-16 17:49:39 +00:00
}
}
2023-04-17 14:33:35 +00:00
struct GprsMs * bts_get_ms ( const struct gprs_rlcmac_bts * bts , uint32_t tlli , uint32_t old_tlli ,
const char * imsi )
2021-01-14 15:48:38 +00:00
{
2023-04-17 14:33:35 +00:00
struct llist_head * tmp ;
if ( tlli ! = GSM_RESERVED_TMSI | | old_tlli ! = GSM_RESERVED_TMSI ) {
llist_for_each ( tmp , & bts - > ms_list ) {
struct GprsMs * ms = llist_entry ( tmp , typeof ( * ms ) , list ) ;
if ( ms_check_tlli ( ms , tlli ) )
return ms ;
if ( ms_check_tlli ( ms , old_tlli ) )
return ms ;
}
}
/* not found by TLLI */
if ( imsi & & imsi [ 0 ] ! = ' \0 ' ) {
llist_for_each ( tmp , & bts - > ms_list ) {
struct GprsMs * ms = llist_entry ( tmp , typeof ( * ms ) , list ) ;
if ( ms_imsi_is_valid ( ms ) & & strcmp ( imsi , ms_imsi ( ms ) ) = = 0 )
return ms ;
}
}
return NULL ;
2021-01-14 15:48:38 +00:00
}
2023-04-17 16:16:48 +00:00
struct GprsMs * bts_get_ms_by_tlli ( const struct gprs_rlcmac_bts * bts , uint32_t tlli , uint32_t old_tlli )
2021-01-14 15:48:38 +00:00
{
2023-04-17 14:33:35 +00:00
return bts_get_ms ( bts , tlli , old_tlli , NULL ) ;
2021-01-14 15:48:38 +00:00
}
2023-04-17 16:16:48 +00:00
struct GprsMs * bts_get_ms_by_imsi ( const struct gprs_rlcmac_bts * bts , const char * imsi )
{
2023-04-17 14:33:35 +00:00
return bts_get_ms ( bts , GSM_RESERVED_TMSI , GSM_RESERVED_TMSI , imsi ) ;
2023-04-17 16:16:48 +00:00
}
2017-11-01 18:41:37 +00:00
/* update TA based on TA provided by PH-DATA-IND */
void update_tbf_ta ( struct gprs_rlcmac_ul_tbf * tbf , int8_t ta_delta )
{
int16_t ta_adj ;
uint8_t ta_target ;
if ( ta_delta ) {
/* adjust TA based on TA provided by PH-DATA-IND */
ta_adj = tbf - > ta ( ) + ta_delta ;
/* limit target TA in range 0..63 bits */
ta_target = ta_limit ( ta_adj ) ;
2021-03-29 17:01:13 +00:00
LOGP ( DL1IF , LOGL_INFO , " PH-DATA-IND is updating %s: TA %u -> %u on "
" TRX = %d \n " , tbf_name ( tbf ) , tbf - > ta ( ) , ta_target , tbf - > trx - > trx_no ) ;
2017-11-01 18:41:37 +00:00
tbf - > set_ta ( ta_target ) ;
}
}
/* set TA based on TA provided by PH-RA-IND */
void set_tbf_ta ( struct gprs_rlcmac_ul_tbf * tbf , uint8_t ta )
{
uint8_t ta_target ;
if ( tbf - > ta ( ) ! = ta ) {
/* limit target TA in range 0..63 bits */
ta_target = ta_limit ( ta ) ;
2021-03-29 17:01:13 +00:00
LOGP ( DL1IF , LOGL_INFO , " PH-RA-IND is updating %s: TA %u -> %u on "
" TRX = %d \n " , tbf_name ( tbf ) , tbf - > ta ( ) , ta_target , tbf - > trx - > trx_no ) ;
2017-11-01 18:41:37 +00:00
tbf - > set_ta ( ta_target ) ;
}
}
2021-01-18 16:14:14 +00:00
void bts_update_tbf_ta ( struct gprs_rlcmac_bts * bts , const char * p , uint32_t fn ,
uint8_t trx_no , uint8_t ts , int8_t ta , bool is_rach )
2016-09-19 14:17:06 +00:00
{
2021-03-09 16:18:12 +00:00
struct gprs_rlcmac_pdch * pdch = & bts - > trx [ trx_no ] . pdch [ ts ] ;
2021-08-31 12:09:42 +00:00
struct pdch_ulc_node * poll ;
2021-08-23 14:58:04 +00:00
struct gprs_rlcmac_ul_tbf * tbf ;
2021-08-31 12:09:42 +00:00
if ( ! pdch - > is_enabled ( ) )
goto no_tbf ;
poll = pdch_ulc_get_node ( pdch - > ulc , fn ) ;
2021-09-28 14:33:49 +00:00
if ( ! poll | | poll - > type ! = PDCH_ULC_NODE_TBF_POLL | |
2021-08-23 15:03:09 +00:00
poll - > tbf_poll . poll_tbf - > direction ! = GPRS_RLCMAC_UL_TBF )
2021-08-31 12:09:42 +00:00
goto no_tbf ;
2022-10-27 13:25:55 +00:00
tbf = tbf_as_ul_tbf ( poll - > tbf_poll . poll_tbf ) ;
2021-08-31 12:09:42 +00:00
/* we need to distinguish TA information provided by L1
* from PH - DATA - IND and PHY - RA - IND so that we can properly
* update TA for given TBF
*/
if ( is_rach )
set_tbf_ta ( tbf , ( uint8_t ) ta ) ;
else
update_tbf_ta ( tbf , ta ) ;
return ;
2017-11-01 18:41:37 +00:00
2021-08-31 12:09:42 +00:00
no_tbf :
LOGP ( DL1IF , LOGL_DEBUG , " [%s] update TA = %u ignored due to "
" unknown UL TBF on TRX = %d, TS = %d, FN = %d \n " ,
p , ta , trx_no , ts , fn ) ;
2016-09-19 14:17:06 +00:00
}
2021-03-08 13:15:54 +00:00
void bts_trx_init ( struct gprs_rlcmac_trx * trx , struct gprs_rlcmac_bts * bts , uint8_t trx_no )
{
trx - > trx_no = trx_no ;
trx - > bts = bts ;
2021-05-13 16:39:36 +00:00
INIT_LLIST_HEAD ( & trx - > ul_tbfs ) ;
INIT_LLIST_HEAD ( & trx - > dl_tbfs ) ;
2021-03-08 13:15:54 +00:00
for ( size_t ts_no = 0 ; ts_no < ARRAY_SIZE ( trx - > pdch ) ; ts_no + + )
pdch_init ( & trx - > pdch [ ts_no ] , trx , ts_no ) ;
}
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
void bts_trx_reserve_slots ( struct gprs_rlcmac_trx * trx , enum gprs_rlcmac_tbf_direction dir ,
2015-06-30 06:52:54 +00:00
uint8_t slots )
{
unsigned i ;
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
for ( i = 0 ; i < ARRAY_SIZE ( trx - > pdch ) ; i + = 1 )
2015-06-30 06:52:54 +00:00
if ( slots & ( 1 < < i ) )
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
trx - > pdch [ i ] . reserve ( dir ) ;
2015-06-30 06:52:54 +00:00
}
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
void bts_trx_unreserve_slots ( struct gprs_rlcmac_trx * trx , enum gprs_rlcmac_tbf_direction dir ,
2015-06-30 06:52:54 +00:00
uint8_t slots )
{
unsigned i ;
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
for ( i = 0 ; i < ARRAY_SIZE ( trx - > pdch ) ; i + = 1 )
2015-06-30 06:52:54 +00:00
if ( slots & ( 1 < < i ) )
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
trx - > pdch [ i ] . unreserve ( dir ) ;
2015-06-30 06:52:54 +00:00
}
2020-10-30 17:35:54 +00:00
2021-01-14 15:20:57 +00:00
void bts_recalc_initial_cs ( struct gprs_rlcmac_bts * bts )
{
uint8_t max_cs_dl , max_cs_ul ;
if ( the_pcu - > vty . force_initial_cs ) {
bts - > initial_cs_dl = the_pcu - > vty . initial_cs_dl ;
bts - > initial_cs_ul = the_pcu - > vty . initial_cs_ul ;
return ;
}
2021-01-14 15:48:38 +00:00
max_cs_dl = bts_max_cs_dl ( bts ) ;
2021-01-14 15:20:57 +00:00
if ( bts - > pcuif_info_ind . initial_cs > max_cs_dl ) {
LOGP ( DL1IF , LOGL_DEBUG , " downgrading initial_cs_dl to %d \n " , max_cs_dl ) ;
bts - > initial_cs_dl = max_cs_dl ;
} else {
bts - > initial_cs_dl = bts - > pcuif_info_ind . initial_cs ;
}
if ( bts - > initial_cs_dl = = 0 )
bts - > initial_cs_dl = 1 ; /* CS1 Must always be supported */
2021-01-14 15:48:38 +00:00
max_cs_ul = bts_max_cs_ul ( bts ) ;
2021-01-14 15:20:57 +00:00
if ( bts - > pcuif_info_ind . initial_cs > max_cs_ul ) {
LOGP ( DL1IF , LOGL_DEBUG , " downgrading initial_cs_ul to %d \n " , max_cs_ul ) ;
bts - > initial_cs_ul = max_cs_ul ;
} else {
bts - > initial_cs_ul = bts - > pcuif_info_ind . initial_cs ;
}
if ( bts - > initial_cs_ul = = 0 )
bts - > initial_cs_ul = 1 ; /* CS1 Must always be supported */
}
void bts_recalc_initial_mcs ( struct gprs_rlcmac_bts * bts )
{
uint8_t max_mcs_dl , max_mcs_ul ;
if ( the_pcu - > vty . force_initial_mcs ) {
bts - > initial_mcs_dl = the_pcu - > vty . initial_mcs_dl ;
bts - > initial_mcs_ul = the_pcu - > vty . initial_mcs_ul ;
return ;
}
2021-01-14 15:48:38 +00:00
max_mcs_dl = bts_max_mcs_dl ( bts ) ;
2021-01-14 15:20:57 +00:00
if ( bts - > pcuif_info_ind . initial_mcs > max_mcs_dl ) {
LOGP ( DL1IF , LOGL_DEBUG , " downgrading initial_mcs_dl to %d \n " , max_mcs_dl ) ;
bts - > initial_mcs_dl = max_mcs_dl ;
} else {
bts - > initial_mcs_dl = bts - > pcuif_info_ind . initial_mcs ;
}
2021-01-14 15:48:38 +00:00
max_mcs_ul = bts_max_mcs_ul ( bts ) ;
2021-01-14 15:20:57 +00:00
if ( bts - > pcuif_info_ind . initial_mcs > max_mcs_ul ) {
LOGP ( DL1IF , LOGL_DEBUG , " downgrading initial_mcs_ul to %d \n " , max_mcs_ul ) ;
bts - > initial_mcs_ul = max_mcs_ul ;
} else {
bts - > initial_mcs_ul = bts - > pcuif_info_ind . initial_mcs ;
}
}
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
void bts_recalc_max_cs ( struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
int i ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
uint8_t cs_dl , cs_ul ;
2021-01-14 15:48:38 +00:00
struct gprs_pcu * pcu = bts - > pcu ;
2020-10-30 17:35:54 +00:00
cs_dl = 0 ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
for ( i = pcu - > vty . max_cs_dl - 1 ; i > = 0 ; i - - ) {
2020-10-30 17:35:54 +00:00
if ( bts - > cs_mask & ( 1 < < i ) ) {
cs_dl = i + 1 ;
break ;
}
}
cs_ul = 0 ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
for ( i = pcu - > vty . max_cs_ul - 1 ; i > = 0 ; i - - ) {
2020-10-30 17:35:54 +00:00
if ( bts - > cs_mask & ( 1 < < i ) ) {
cs_ul = i + 1 ;
break ;
}
}
LOGP ( DRLCMAC , LOGL_DEBUG , " New max CS: DL=%u UL=%u \n " , cs_dl , cs_ul ) ;
2021-01-14 15:48:38 +00:00
bts_set_max_cs_dl ( bts , cs_dl ) ;
bts_set_max_cs_ul ( bts , cs_ul ) ;
2020-10-30 17:35:54 +00:00
}
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
void bts_recalc_max_mcs ( struct gprs_rlcmac_bts * bts )
2020-10-30 17:35:54 +00:00
{
int i ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
uint8_t mcs_dl , mcs_ul ;
2021-01-14 15:48:38 +00:00
struct gprs_pcu * pcu = bts - > pcu ;
2020-10-30 17:35:54 +00:00
mcs_dl = 0 ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
for ( i = pcu - > vty . max_mcs_dl - 1 ; i > = 0 ; i - - ) {
2020-10-30 17:35:54 +00:00
if ( bts - > mcs_mask & ( 1 < < i ) ) {
mcs_dl = i + 1 ;
break ;
}
}
mcs_ul = 0 ;
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
for ( i = pcu - > vty . max_mcs_ul - 1 ; i > = 0 ; i - - ) {
2020-10-30 17:35:54 +00:00
if ( bts - > mcs_mask & ( 1 < < i ) ) {
mcs_ul = i + 1 ;
break ;
}
}
LOGP ( DRLCMAC , LOGL_DEBUG , " New max MCS: DL=%u UL=%u \n " , mcs_dl , mcs_ul ) ;
2021-01-14 15:48:38 +00:00
bts_set_max_mcs_dl ( bts , mcs_dl ) ;
bts_set_max_mcs_ul ( bts , mcs_ul ) ;
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
}
2021-02-09 17:47:34 +00:00
uint8_t bts_get_ms_pwr_alpha ( const struct gprs_rlcmac_bts * bts )
{
if ( bts - > pcu - > vty . force_alpha ! = ( uint8_t ) - 1 )
return bts - > pcu - > vty . force_alpha ;
if ( bts - > si13_is_set )
2021-06-01 14:43:41 +00:00
return bts - > si13_ro_decoded . pwr_ctrl_pars . alpha ;
2021-02-09 17:47:34 +00:00
/* default if no SI13 is received yet: closed loop control, TS 44.060
* B .2 Closed loop control */
return 0 ;
}
2021-11-10 18:09:10 +00:00
/* Used by counter availablePDCHAllocatedTime, TS 52.402 B.2.1.45 "All available PDCH allocated time" */
bool bts_all_pdch_allocated ( const struct gprs_rlcmac_bts * bts )
{
unsigned trx_no , ts_no ;
for ( trx_no = 0 ; trx_no < ARRAY_SIZE ( bts - > trx ) ; trx_no + + ) {
const struct gprs_rlcmac_trx * trx = & bts - > trx [ trx_no ] ;
for ( ts_no = 0 ; ts_no < ARRAY_SIZE ( trx - > pdch ) ; ts_no + + ) {
const struct gprs_rlcmac_pdch * pdch = & trx - > pdch [ ts_no ] ;
if ( ! pdch_is_enabled ( pdch ) )
continue ;
if ( ! pdch_is_full ( pdch ) )
return false ;
}
}
return true ;
}