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-17 18:12:37 +00:00
# include <poll_controller.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>
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>
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_MODULUS 42432
# 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
}
}
2019-09-05 12:48:35 +00:00
static struct osmo_tdef T_defs_bts [ ] = {
{ . T = 3142 , . default_val = 20 , . unit = OSMO_TDEF_S , . desc = " timer (s) " , . val = 0 } ,
{ . T = 3169 , . default_val = 5 , . unit = OSMO_TDEF_S , . desc = " Reuse of USF and TFI(s) after the MS uplink TBF assignment is invalid (s) " , . 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 (s) " , . 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 (ms) " , . 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 (s) " , . val = 0 } ,
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 [ ] = {
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 " } ,
{ " 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 " } ,
{ " rach:requests " , " RACH requests " } ,
{ " 11bit_rach:requests " , " 11BIT_RACH requests " } ,
{ " 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 " } ,
{ " 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 " } ,
{ " 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 } ,
} ;
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 ,
} ;
2020-11-02 13:36:22 +00:00
static void bts_init ( struct gprs_rlcmac_bts * bts , BTS * bts_obj )
{
memset ( bts , 0 , sizeof ( * bts ) ) ;
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 - > bts = bts_obj ;
bts - > T_defs_bts = T_defs_bts ;
osmo_tdefs_reset ( bts - > T_defs_bts ) ;
/* initialize back pointers */
for ( size_t trx_no = 0 ; trx_no < ARRAY_SIZE ( bts - > trx ) ; + + trx_no ) {
struct gprs_rlcmac_trx * trx = & bts - > trx [ trx_no ] ;
trx - > trx_no = trx_no ;
trx - > bts = bts_obj ;
for ( size_t ts_no = 0 ; ts_no < ARRAY_SIZE ( trx - > pdch ) ; + + ts_no ) {
struct gprs_rlcmac_pdch * pdch = & trx - > pdch [ ts_no ] ;
pdch - > init_ptcch_msg ( ) ;
pdch - > ts_no = ts_no ;
pdch - > trx = trx ;
}
}
}
2013-10-17 17:41:11 +00:00
BTS * BTS : : main_bts ( )
{
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
return the_pcu - > bts ;
2013-10-17 17:41:11 +00:00
}
struct gprs_rlcmac_bts * BTS : : bts_data ( )
{
return & m_bts ;
}
struct gprs_rlcmac_bts * bts_main_data ( )
{
return BTS : : main_bts ( ) - > bts_data ( ) ;
}
2019-03-18 14:48:38 +00:00
void bts_cleanup ( )
{
return BTS : : main_bts ( ) - > cleanup ( ) ;
}
2013-10-27 08:02:31 +00:00
struct rate_ctr_group * bts_main_data_stats ( )
{
return BTS : : main_bts ( ) - > rate_counters ( ) ;
}
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
BTS : : BTS ( struct gprs_pcu * pcu )
: pcu ( pcu )
, m_cur_fn ( 0 )
2015-08-24 12:35:14 +00:00
, m_cur_blk_fn ( - 1 )
2020-10-30 17:35:54 +00:00
, m_max_cs_dl ( MAX_GPRS_CS )
, m_max_cs_ul ( MAX_GPRS_CS )
, m_max_mcs_dl ( MAX_EDGE_MCS )
, m_max_mcs_ul ( MAX_EDGE_MCS )
2013-10-17 18:12:37 +00:00
, m_pollController ( * this )
2013-10-19 18:47:12 +00:00
, m_sba ( * this )
2015-06-02 12:06:12 +00:00
, m_ms_store ( this )
2013-10-17 17:41:11 +00:00
{
2020-11-02 13:36:22 +00:00
bts_init ( & m_bts , this ) ;
2013-10-27 08:02:31 +00:00
2017-12-18 21:52:52 +00:00
/* The static allocator might have already registered the counter group.
2017-12-21 10:19:39 +00:00
If this happens and we still called explicitly ( in tests / for example )
2017-12-18 21:52:52 +00:00
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 ) )
m_ratectrs = rate_ctr_group_alloc ( tall_pcu_ctx , & bts_ctrg_desc , 1 ) ;
else
m_ratectrs = rate_ctr_group_alloc ( tall_pcu_ctx , & bts_ctrg_desc , 0 ) ;
2017-07-11 22:46:36 +00:00
OSMO_ASSERT ( m_ratectrs ) ;
2017-12-18 21:52:52 +00:00
2015-11-27 18:05:13 +00:00
m_statg = osmo_stat_item_group_alloc ( tall_pcu_ctx , & bts_statg_desc , 0 ) ;
2017-07-11 22:46:36 +00:00
OSMO_ASSERT ( m_statg ) ;
2013-10-17 17:41:11 +00:00
}
2013-10-17 17:59:56 +00:00
2019-03-18 14:48:38 +00:00
void BTS : : cleanup ( )
2013-10-27 08:02:31 +00:00
{
2016-01-20 21:02:19 +00:00
/* this can cause counter updates and must not be left to the
* m_ms_store ' s destructor */
m_ms_store . cleanup ( ) ;
2019-03-18 14:48:38 +00:00
if ( m_ratectrs ) {
rate_ctr_group_free ( m_ratectrs ) ;
m_ratectrs = NULL ;
}
if ( m_statg ) {
osmo_stat_item_group_free ( m_statg ) ;
m_statg = NULL ;
}
2019-09-05 15:13:33 +00:00
if ( m_bts . app_info ) {
msgb_free ( m_bts . app_info ) ;
m_bts . app_info = NULL ;
}
2013-10-27 08:02:31 +00:00
}
2019-03-18 14:48:38 +00:00
BTS : : ~ BTS ( )
{
cleanup ( ) ;
}
2013-10-27 08:02:31 +00:00
2013-10-17 17:59:56 +00:00
void BTS : : set_current_frame_number ( int fn )
{
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
* and start of another frame ( every 3 blocks ) . So the timeout should
* definitely be there if we ' re more than 8 frames past poll_fn . Let ' s
2015-08-27 11:28:05 +00:00
* stay on the safe side and say 13 or more . An additional delay can
* happen due to the block processing time in the DSP , so the delay of
* decoded blocks relative to the timing clock can be much larger .
* Values up to 50 frames have been observed under load . */
const static int max_delay = 60 ;
2015-08-27 11:18:24 +00:00
2013-10-17 17:59:56 +00:00
m_cur_fn = fn ;
2015-08-27 11:18:24 +00:00
m_pollController . expireTimedout ( m_cur_fn , max_delay ) ;
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 ;
}
2015-08-26 11:22:28 +00:00
void BTS : : set_current_block_frame_number ( int fn , unsigned max_delay )
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 . */
if ( m_cur_blk_fn > = 0 ) {
2017-05-16 14:10:45 +00:00
int delta = delta_fn ( fn , m_cur_blk_fn ) ;
2015-08-24 12:35:14 +00:00
if ( delta < = 0 )
return ;
}
/* Check block delay vs. the current frame number */
if ( current_frame_number ( ) ! = 0 )
2017-05-16 14:10:45 +00:00
delay = delta_fn ( fn , current_frame_number ( ) ) ;
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 " ,
delay , fn , current_frame_number ( ) ) ;
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_RLC_LATE_BLOCK ) ;
2015-08-25 13:19:31 +00:00
}
2015-08-24 12:35:14 +00:00
m_cur_blk_fn = fn ;
if ( delay < fn_update_ok_min_delay | | delay > fn_update_ok_max_delay | |
current_frame_number ( ) = = 0 )
m_cur_fn = fn ;
2015-08-26 11:22:28 +00:00
m_pollController . expireTimedout ( fn , max_delay ) ;
2015-08-24 12:35:14 +00:00
}
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
int BTS : : add_paging ( uint8_t chan_needed , const struct osmo_mobile_identity * mi )
2013-10-19 16:28:59 +00:00
{
uint8_t l , trx , ts , any_tbf = 0 ;
struct gprs_rlcmac_tbf * tbf ;
2015-12-28 18:15:40 +00:00
LListHead < gprs_rlcmac_tbf > * pos ;
2013-10-19 16:28:59 +00:00
uint8_t slot_mask [ 8 ] ;
int8_t first_ts ; /* must be signed */
2015-12-28 18:15:40 +00:00
LListHead < gprs_rlcmac_tbf > * tbfs_lists [ ] = {
& m_ul_tbfs ,
& m_dl_tbfs ,
2013-10-19 19:10:38 +00:00
NULL
} ;
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 ) ;
2020-08-21 13:44:58 +00:00
LOGP ( DRLCMAC , LOGL_INFO , " Add RR paging: chan-needed=%d MI=%s \n " , chan_needed , str ) ;
}
2013-10-19 16:28:59 +00:00
/* collect slots to page
* Mark slots for every TBF , but only mark one of it .
* 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 ) ) ;
2013-10-19 19:10:38 +00:00
for ( l = 0 ; tbfs_lists [ l ] ; l + + ) {
2015-12-28 18:15:40 +00:00
llist_for_each ( pos , tbfs_lists [ l ] ) {
tbf = pos - > entry ( ) ;
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 */
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
if ( ! m_bts . trx [ trx ] . pdch [ ts ] . add_paging ( chan_needed , mi ) )
2013-10-19 16:28:59 +00:00
return - ENOMEM ;
2018-01-30 11:00:08 +00:00
LOGP ( DRLCMAC , LOGL_INFO , " Paging on PACCH of TRX=%d TS=%d \n " , trx , ts ) ;
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 ;
}
2020-06-10 17:26:15 +00:00
void BTS : : send_gsmtap_rach ( enum pcu_gsmtap_category categ , uint8_t channel ,
const struct rach_ind_params * rip )
{
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 ) ;
}
2020-06-10 17:26:15 +00:00
send_gsmtap_meas ( categ , true , rip - > trx_nr , rip - > ts_nr , channel ,
2020-06-10 18:04:44 +00:00
rfn_to_fn ( rip - > rfn ) , ra_buf ,
2020-06-10 17:26:15 +00:00
rip - > is_11bit ? 2 : 1 , & meas ) ;
}
2017-07-21 19:56:23 +00:00
void BTS : : send_gsmtap ( 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 } ;
2020-05-19 15:23:23 +00:00
send_gsmtap_meas ( categ , uplink , trx_no , ts_no , channel , fn , data , len , & meas ) ;
}
void BTS : : send_gsmtap_meas ( 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 */
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
if ( ! ( pcu - > gsmtap_categ_mask & ( 1 < < categ ) ) )
2017-07-21 19:56:23 +00:00
return ;
arfcn = m_bts . trx [ trx_no ] . arfcn ;
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 */
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
gsmtap_send ( 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
}
2017-08-14 13:49:59 +00:00
static inline bool tbf_check ( gprs_rlcmac_tbf * tbf , uint32_t fn , uint8_t trx_no , uint8_t ts )
{
2018-01-24 10:00:17 +00:00
if ( tbf - > state_is_not ( GPRS_RLCMAC_RELEASING ) & & tbf - > poll_scheduled ( )
2017-08-14 13:49:59 +00:00
& & tbf - > poll_fn = = fn & & tbf - > trx - > trx_no = = trx_no & & tbf - > poll_ts = = ts )
return true ;
return false ;
}
2014-07-10 15:44:06 +00:00
gprs_rlcmac_dl_tbf * BTS : : dl_tbf_by_poll_fn ( uint32_t fn , uint8_t trx , uint8_t ts )
2013-10-19 19:10:38 +00:00
{
2015-12-28 18:15:40 +00:00
LListHead < gprs_rlcmac_tbf > * pos ;
2013-10-19 19:10:38 +00:00
/* only one TBF can poll on specific TS/FN, because scheduler can only
* schedule one downlink control block ( with polling ) at a FN per TS */
2015-12-28 18:15:40 +00:00
llist_for_each ( pos , & m_dl_tbfs ) {
2017-08-14 13:49:59 +00:00
if ( tbf_check ( pos - > entry ( ) , fn , trx , ts ) )
return as_dl_tbf ( pos - > entry ( ) ) ;
2013-10-19 19:10:38 +00:00
}
2014-07-02 15:58:16 +00:00
return NULL ;
}
2017-08-14 13:49:59 +00:00
2014-07-10 15:44:06 +00:00
gprs_rlcmac_ul_tbf * BTS : : ul_tbf_by_poll_fn ( uint32_t fn , uint8_t trx , uint8_t ts )
2014-07-02 15:58:16 +00:00
{
2015-12-28 18:15:40 +00:00
LListHead < gprs_rlcmac_tbf > * pos ;
2014-07-02 15:58:16 +00:00
/* only one TBF can poll on specific TS/FN, because scheduler can only
* schedule one downlink control block ( with polling ) at a FN per TS */
2015-12-28 18:15:40 +00:00
llist_for_each ( pos , & m_ul_tbfs ) {
2017-08-14 13:49:59 +00:00
if ( tbf_check ( pos - > entry ( ) , fn , trx , ts ) )
return as_ul_tbf ( pos - > entry ( ) ) ;
2013-10-19 19:10:38 +00:00
}
return NULL ;
}
2014-07-02 15:58:15 +00:00
/* lookup downlink TBF Entity (by TFI) */
2015-07-10 17:52:37 +00:00
gprs_rlcmac_dl_tbf * BTS : : dl_tbf_by_tfi ( 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
2015-07-10 17:52:37 +00:00
return m_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) */
gprs_rlcmac_ul_tbf * BTS : : ul_tbf_by_tfi ( 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 ;
2015-07-10 17:52:37 +00:00
return m_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
*/
2018-01-26 10:09:16 +00:00
int BTS : : tfi_find_free ( enum gprs_rlcmac_tbf_direction dir , uint8_t * _trx , int8_t use_trx ) const
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
if ( use_trx > = 0 & & use_trx < 8 )
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 ;
tmp_cnt = trx_count_free_tfi ( & m_bts . trx [ trx ] , dir , & tmp_first_tfi ) ;
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 ) ;
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
}
2013-10-26 17:49:16 +00:00
int BTS : : rcv_imm_ass_cnf ( const uint8_t * data , uint32_t fn )
{
2015-05-20 10:06:46 +00:00
struct gprs_rlcmac_dl_tbf * dl_tbf = NULL ;
2013-10-26 17:49:16 +00:00
uint8_t plen ;
uint32_t tlli ;
2015-05-20 10:06:46 +00:00
GprsMs * ms ;
2013-10-26 17:49:16 +00:00
/* move to IA Rest Octets */
plen = data [ 0 ] > > 2 ;
data + = 1 + plen ;
if ( ( * data & 0xf0 ) ! = 0xd0 ) {
LOGP ( DRLCMAC , LOGL_ERROR , " Got IMM.ASS confirm, but rest "
" octets do not start with bit sequence 'HH01' "
" (Packet Downlink Assignment) \n " ) ;
return - EINVAL ;
}
/* get TLLI from downlink assignment */
2019-07-23 15:16:06 +00:00
tlli = ( uint32_t ) ( ( * data + + ) & 0xf ) < < 28 ;
2013-10-26 17:49:16 +00:00
tlli | = ( * data + + ) < < 20 ;
tlli | = ( * data + + ) < < 12 ;
tlli | = ( * data + + ) < < 4 ;
tlli | = ( * data + + ) > > 4 ;
2015-05-20 10:06:46 +00:00
ms = ms_by_tlli ( tlli ) ;
if ( ms )
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
dl_tbf = ms_dl_tbf ( ms ) ;
2014-08-07 10:37:34 +00:00
if ( ! dl_tbf ) {
2013-10-26 17:49:16 +00:00
LOGP ( DRLCMAC , LOGL_ERROR , " Got IMM.ASS confirm, but TLLI=%08x "
" does not exit \n " , tlli ) ;
return - EINVAL ;
}
LOGP ( DRLCMAC , LOGL_DEBUG , " Got IMM.ASS confirm for TLLI=%08x \n " , tlli ) ;
2014-08-07 13:49:21 +00:00
if ( dl_tbf - > m_wait_confirm )
2019-09-05 12:48:35 +00:00
T_START ( dl_tbf , T0 , - 2002 , " assignment (AGCH) " , true ) ;
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 */
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
uint32_t BTS : : rfn_to_fn ( int32_t rfn )
2017-02-21 18:35:23 +00:00
{
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
int32_t m_cur_rfn ;
int32_t fn ;
int32_t fn_rounded ;
/* double-check that relative FN is not negative and fits into int32_t */
OSMO_ASSERT ( rfn < GSM_MAX_FN ) ;
OSMO_ASSERT ( rfn > = 0 ) ;
2017-02-21 18:35:23 +00:00
/* Note: If a BTS is sending in a rach request it will be fully aware
* of the frame number . If the PCU is used in a BSC - co - located setup .
* The BSC will forward the incoming RACH request . The RACH request
* only contains the relative frame number ( Fn % 42432 ) in its request
* reference . This PCU implementation has to fit both scenarios , so
* we need to assume that Fn is a relative frame number . */
/* Ensure that all following calculations are performed with the
* relative frame number */
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
if ( rfn > = RFN_MODULUS )
return rfn ;
2017-02-21 18:35:23 +00:00
/* Compute an internal relative frame number from the full internal
frame number */
m_cur_rfn = m_cur_fn % RFN_MODULUS ;
/* Compute a "rounded" version of the internal frame number, which
* exactly fits in the RFN_MODULUS raster */
fn_rounded = m_cur_fn - m_cur_rfn ;
/* 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 */
if ( abs ( rfn - m_cur_rfn ) > RFN_THRESHOLD ) {
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 " ,
2017-02-21 18:35:23 +00:00
rfn , m_cur_fn , RFN_MODULUS ) ;
if ( fn_rounded < RFN_MODULUS ) {
LOGP ( DRLCMAC , LOGL_DEBUG ,
" Cornercase detected: wrapping crosses %u border \n " ,
GSM_MAX_FN ) ;
fn_rounded = GSM_MAX_FN - ( RFN_MODULUS - fn_rounded ) ;
}
else
fn_rounded - = RFN_MODULUS ;
}
/* The real frame number is the sum of the rounded frame number and the
* relative framenumber computed via RACH */
fn = fn_rounded + rfn ;
return fn ;
}
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
}
2020-05-21 12:55:46 +00:00
int BTS : : rcv_rach ( 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 ;
2020-05-21 12:55:46 +00:00
uint8_t trx_no , ts_no ;
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
uint8_t tsc = 0 ;
int plen , rc ;
2013-10-26 18:56:20 +00:00
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_RACH_REQUESTS ) ;
2013-10-27 09:50:35 +00:00
2020-05-21 12:55:46 +00:00
if ( rip - > is_11bit )
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_11BIT_RACH_REQUESTS ) ;
2016-11-10 12:46:30 +00:00
2017-02-21 18:35:23 +00:00
/* Determine full frame number */
2020-05-21 12:55:46 +00:00
uint32_t Fn = rfn_to_fn ( rip - > rfn ) ;
uint8_t ta = qta2ta ( rip - > qta ) ;
2020-06-10 17:26:15 +00:00
send_gsmtap_rach ( 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 ) ;
if ( rc ) /* Send RR Immediate Assignment Reject */
goto send_imm_ass_rej ;
2016-09-14 15:00:31 +00:00
2020-05-21 12:55:46 +00:00
if ( chan_req . single_block )
LOGP ( DRLCMAC , LOGL_DEBUG , " MS requests single block allocation \n " ) ;
2021-01-14 11:48:50 +00:00
else if ( pcu - > vty . force_two_phase ) {
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " MS requests single block allocation, "
" but we force two phase access \n " ) ;
chan_req . single_block = true ;
}
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 ) {
2016-01-20 17:26:13 +00:00
rc = sba ( ) - > alloc ( & trx_no , & ts_no , & sb_fn , ta ) ;
2016-11-09 10:57:00 +00:00
if ( rc < 0 ) {
LOGP ( DRLCMAC , LOGL_NOTICE , " No PDCH resource for "
2020-05-21 12:55:46 +00:00
" single block allocation: rc=%d \n " , rc ) ;
/* 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
tsc = m_bts . trx [ trx_no ] . pdch [ ts_no ] . tsc ;
LOGP ( DRLCMAC , LOGL_DEBUG , " Allocated a single block at "
" SBFn=%u TRX=%u TS=%u \n " , sb_fn , trx_no , ts_no ) ;
2013-10-26 18:56:20 +00:00
} else {
2020-05-21 12:55:46 +00:00
GprsMs * ms = ms_alloc ( 0 , chan_req . egprs_mslot_class ) ;
2020-05-08 15:44:33 +00:00
tbf = tbf_alloc_ul_tbf ( & m_bts , ms , - 1 , true ) ;
2013-10-26 18:56:20 +00:00
if ( ! tbf ) {
2020-05-21 12:55:46 +00:00
LOGP ( DRLCMAC , LOGL_NOTICE , " No PDCH resource for Uplink TBF \n " ) ;
/* 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
/* FIXME: Copy and paste with other routines.. */
tbf - > set_ta ( ta ) ;
TBF_SET_STATE ( tbf , GPRS_RLCMAC_FLOW ) ;
TBF_ASS_TYPE_SET ( tbf , GPRS_RLCMAC_FLAG_CCCH ) ;
T_START ( tbf , T3169 , 3169 , " RACH (new UL-TBF) " , true ) ;
trx_no = tbf - > trx - > trx_no ;
ts_no = tbf - > first_ts ;
usf = tbf - > m_usf [ ts_no ] ;
tsc = tbf - > tsc ( ) ;
2013-10-26 18:56:20 +00:00
}
2016-01-20 17:26:13 +00:00
2020-05-21 12:55:46 +00:00
send_imm_ass_rej :
/* Allocate a bit-vector for RR Immediate Assignment [Reject] */
struct bitvec * bv = bitvec_alloc ( 22 , tall_pcu_ctx ) ; /* without plen */
2020-07-18 13:33:08 +00:00
bitvec_unhex ( bv , DUMMY_VEC ) ; /* standard '2B'O padding */
2016-01-20 17:26:13 +00:00
2020-05-21 12:55:46 +00:00
if ( rc ! = 0 ) {
LOGP ( DRLCMAC , LOGL_DEBUG , " Tx Immediate Assignment Reject on AGCH \n " ) ;
2016-11-09 10:57:00 +00:00
plen = Encoding : : write_immediate_assignment_reject (
2020-05-21 12:55:46 +00:00
bv , rip - > ra , Fn , rip - > burst_type ) ;
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_IMMEDIATE_ASSIGN_REJ ) ;
2020-05-21 12:55:46 +00:00
} else {
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_no , m_bts . trx [ trx_no ] . arfcn & ~ ARFCN_FLAG_MASK ,
ts_no , ta , tsc , tbf ? tbf - > tfi ( ) : - 1 , usf ) ;
plen = Encoding : : write_immediate_assignment (
2020-07-18 16:34:17 +00:00
& m_bts . trx [ trx_no ] . pdch [ ts_no ] , tbf , bv ,
false , rip - > ra , Fn , ta , usf , false , sb_fn ,
2021-01-14 11:53:53 +00:00
pcu - > vty . alpha , pcu - > vty . gamma , - 1 ,
2020-05-21 12:55:46 +00:00
rip - > burst_type ) ;
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_IMMEDIATE_ASSIGN_UL_TBF ) ;
2016-11-10 12:46:30 +00:00
}
2016-02-01 15:13:38 +00:00
2020-05-21 12:55:46 +00:00
if ( plen > = 0 )
pcu_l1if_tx_agch ( bv , plen ) ;
else
rc = plen ;
bitvec_free ( bv ) ;
2013-10-26 18:56:20 +00:00
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 ,
} ;
2020-05-21 12:55:46 +00:00
int BTS : : rcv_ptcch_rach ( const struct rach_ind_params * rip )
2019-10-05 16:45:31 +00:00
{
2020-05-21 12:55:46 +00:00
uint32_t fn416 = rfn_to_fn ( rip - > rfn ) % 416 ;
2019-10-05 16:45:31 +00:00
struct gprs_rlcmac_bts * bts = bts_data ( ) ;
struct gprs_rlcmac_pdch * pdch ;
uint8_t ss ;
2020-06-10 17:26:15 +00:00
send_gsmtap_rach ( PCU_GSMTAP_C_UL_PTCCH , GSMTAP_CHANNEL_PTCCH , rip ) ;
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 ] ;
2019-10-05 16:45:31 +00:00
if ( ! pdch - > m_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 ;
}
2019-12-23 11:41:34 +00:00
void BTS : : snd_dl_ass ( gprs_rlcmac_tbf * tbf , bool poll , uint16_t pgroup )
2013-10-26 18:12:59 +00:00
{
2020-07-18 16:34:17 +00:00
uint8_t trx_no = tbf - > trx - > trx_no ;
uint8_t ts_no = tbf - > first_ts ;
2013-10-26 18:12:59 +00:00
int plen ;
2017-12-15 16:36:45 +00:00
LOGPTBF ( tbf , LOGL_INFO , " TX: START Immediate Assignment Downlink (PCH) \n " ) ;
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 */
2013-10-26 18:12:59 +00:00
/* use request reference that has maximum distance to current time,
* so the assignment will not conflict with possible RACH requests . */
2016-01-20 17:26:13 +00:00
LOGP ( DRLCMAC , LOGL_DEBUG , " - TRX=%d (%d) TS=%d TA=%d pollFN=%d \n " ,
2020-07-18 16:34:17 +00:00
trx_no , tbf - > trx - > arfcn , ts_no , tbf - > ta ( ) , poll ? tbf - > poll_fn : - 1 ) ;
plen = Encoding : : write_immediate_assignment ( & m_bts . trx [ trx_no ] . pdch [ ts_no ] ,
tbf , immediate_assignment , true , 125 ,
( tbf - > pdch [ ts_no ] - > last_rts_fn + 21216 ) % GSM_MAX_FN ,
tbf - > ta ( ) , 7 , poll , tbf - > poll_fn ,
2021-01-14 11:53:53 +00:00
pcu - > vty . alpha , 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 ) {
2020-05-12 18:54:35 +00:00
do_rate_ctr_inc ( CTR_IMMEDIATE_ASSIGN_DL_TBF ) ;
2019-12-23 11:41:34 +00:00
pcu_l1if_tx_pch ( immediate_assignment , plen , pgroup ) ;
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 */
uint8_t BTS : : max_cs_dl ( void ) const
{
return m_max_cs_dl ;
}
/* return maximum UL CS supported by BTS and allowed by VTY */
uint8_t BTS : : max_cs_ul ( void ) const
{
return m_max_cs_ul ;
}
/* return maximum DL MCS supported by BTS and allowed by VTY */
uint8_t BTS : : max_mcs_dl ( void ) const
{
return m_max_mcs_dl ;
}
/* return maximum UL MCS supported by BTS and allowed by VTY */
uint8_t BTS : : max_mcs_ul ( void ) const
{
return m_max_mcs_ul ;
}
/* Set maximum DL CS supported by BTS and allowed by VTY */
void BTS : : set_max_cs_dl ( uint8_t cs_dl )
{
m_max_cs_dl = cs_dl ;
}
/* Set maximum UL CS supported by BTS and allowed by VTY */
void BTS : : set_max_cs_ul ( uint8_t cs_ul )
{
m_max_cs_ul = cs_ul ;
}
/* Set maximum DL MCS supported by BTS and allowed by VTY */
void BTS : : set_max_mcs_dl ( uint8_t mcs_dl )
{
m_max_mcs_dl = mcs_dl ;
}
/* Set maximum UL MCS supported by BTS and allowed by VTY */
void BTS : : set_max_mcs_ul ( uint8_t mcs_ul )
{
m_max_mcs_ul = mcs_ul ;
}
2013-10-26 15:32:04 +00:00
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
bool BTS : : cs_dl_is_supported ( CodingScheme cs )
{
OSMO_ASSERT ( mcs_is_valid ( cs ) ) ;
uint8_t num = mcs_chan_code ( cs ) ;
if ( mcs_is_gprs ( cs ) ) {
return ( max_cs_dl ( ) > = num ) & & ( m_bts . cs_mask & ( 1U < < num ) ) ;
} else {
return ( max_mcs_dl ( ) > = num ) & & ( m_bts . mcs_mask & ( 1U < < num ) ) ;
}
}
2015-11-27 14:17:34 +00:00
GprsMs * BTS : : ms_alloc ( uint8_t ms_class , uint8_t egprs_ms_class )
2015-06-19 08:59:58 +00:00
{
GprsMs * ms ;
ms = ms_store ( ) . create_ms ( ) ;
2021-01-14 11:01:42 +00:00
ms_set_timeout ( ms , osmo_tdef_get ( pcu - > T_defs , - 2030 , OSMO_TDEF_S , - 1 ) ) ;
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
ms_set_ms_class ( ms , ms_class ) ;
ms_set_egprs_ms_class ( ms , egprs_ms_class ) ;
2015-06-19 08:59:58 +00:00
return ms ;
}
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
static int bts_talloc_destructor ( struct BTS * bts )
{
bts - > ~ BTS ( ) ;
return 0 ;
}
struct BTS * bts_alloc ( struct gprs_pcu * pcu )
{
struct BTS * bts ;
bts = talloc ( pcu , struct BTS ) ;
if ( ! bts )
return bts ;
talloc_set_destructor ( bts , bts_talloc_destructor ) ;
new ( bts ) BTS ( pcu ) ;
return bts ;
}
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 ) ;
LOGP ( DL1IF , LOGL_INFO , " PH-DATA-IND is updating TLLI=0x%08x: TA %u -> %u on "
" TRX = %d, TS = %d, FN = %d \n " ,
tbf - > tlli ( ) , tbf - > ta ( ) , ta_target ,
tbf - > trx - > trx_no , tbf - > poll_ts , tbf - > poll_fn ) ;
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 ) ;
LOGP ( DL1IF , LOGL_INFO , " PH-RA-IND is updating TLLI=0x%08x: TA %u -> %u on "
" TRX = %d, TS = %d, FN = %d \n " ,
tbf - > tlli ( ) , tbf - > ta ( ) , ta_target ,
tbf - > trx - > trx_no , tbf - > poll_ts , tbf - > poll_fn ) ;
tbf - > set_ta ( ta_target ) ;
}
}
void bts_update_tbf_ta ( 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
{
struct gprs_rlcmac_ul_tbf * tbf =
bts_main_data ( ) - > bts - > ul_tbf_by_poll_fn ( fn , trx_no , ts ) ;
if ( ! 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 ) ;
2017-11-01 18:41:37 +00:00
else {
/* 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 ) ;
2016-09-19 14:17:06 +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_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
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 ;
struct gprs_pcu * pcu = bts - > 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 ) ;
bts - > bts - > set_max_cs_dl ( cs_dl ) ;
bts - > bts - > set_max_cs_ul ( cs_ul ) ;
}
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 ;
struct gprs_pcu * pcu = bts - > 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 ) ;
bts - > bts - > set_max_mcs_dl ( mcs_dl ) ;
bts - > bts - > set_max_mcs_ul ( 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
struct gprs_rlcmac_bts * bts_data ( struct BTS * bts )
{
return & bts - > m_bts ;
}
struct GprsMs * bts_ms_by_imsi ( struct BTS * bts , const char * imsi )
{
return bts - > ms_by_imsi ( imsi ) ;
}
uint8_t bts_max_cs_dl ( const struct BTS * bts )
{
return bts - > max_cs_dl ( ) ;
}
uint8_t bts_max_cs_ul ( const struct BTS * bts )
{
return bts - > max_cs_ul ( ) ;
}
uint8_t bts_max_mcs_dl ( const struct BTS * bts )
{
return bts - > max_mcs_dl ( ) ;
}
uint8_t bts_max_mcs_ul ( const struct BTS * bts )
{
return bts - > max_mcs_ul ( ) ;
}