diff --git a/src/encoding.cpp b/src/encoding.cpp index 6742efda..87c6f086 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -60,6 +60,21 @@ static inline void write_ta(bitvec *dest, unsigned& wp, int8_t ta) } } +/* 3GPP TS 44.060 Table 12.5.2.1 */ +static inline uint16_t enc_ws(uint16_t ws) +{ + return (ws - 64) / 32; +} + +static inline void write_ws(bitvec *dest, unsigned int *write_index, uint16_t ws) +{ + dest->cur_bit = *write_index; + + bitvec_set_u64(dest, enc_ws(ws), 5, false); + + *write_index += 5; +} + /* 3GPP TS 44.060 ยง 12.12: { 0 | 1 < TIMING_ADVANCE_VALUE : bit (6) > } { 0 | 1 < TIMING_ADVANCE_INDEX : bit (4) > @@ -114,9 +129,8 @@ static int write_ia_rest_downlink( // bitvec_write_field(dest, &wp,,0xb,4); if (tbf->is_egprs_enabled()) { /* see GMS 44.018, 10.5.2.16 */ - unsigned int ws_enc = (tbf->m_window.ws() - 64) / 32; bitvec_write_field(dest, &wp, 1, 1); // "H" - bitvec_write_field(dest, &wp, ws_enc, 5); // EGPRS Window Size + write_ws(dest, &wp, tbf->window_size()); // EGPRS Window Size bitvec_write_field(dest, &wp, 0x0, 2); // LINK_QUALITY_MEASUREMENT_MODE bitvec_write_field(dest, &wp, 0, 1); // BEP_PERIOD2 not present } @@ -178,7 +192,6 @@ static int write_ia_rest_egprs_uplink( uint8_t alpha, uint8_t gamma, int8_t ta_idx, enum ph_burst_type burst_type, uint16_t ra) { - unsigned int ws_enc = 0; uint8_t extended_ra = 0; extended_ra = (ra & 0x1F); @@ -208,9 +221,6 @@ static int write_ia_rest_egprs_uplink( bitvec_write_field(dest, &wp, 0, 1); } else { - - ws_enc = (tbf->m_window.ws() - 64) / 32; - bitvec_write_field(dest, &wp, 1, 1); /* single block alloc */ bitvec_write_field(dest, &wp, tbf->tfi(), 5);/* TFI assignment */ bitvec_write_field(dest, &wp, 0, 1); /* polling bit */ @@ -224,7 +234,7 @@ static int write_ia_rest_egprs_uplink( bitvec_write_field(dest, &wp, tbf->tlli(), 1); bitvec_write_field(dest, &wp, 0, 1); /* BEP period present */ bitvec_write_field(dest, &wp, 0, 1); /* resegmentation */ - bitvec_write_field(dest, &wp, ws_enc, 5);/* egprs window_size */ + write_ws(dest, &wp, tbf->window_size()); /* EGPRS window size */ if (alpha) { bitvec_write_field(dest, &wp, 0x1, 1); /* ALPHA =yes */ @@ -450,7 +460,6 @@ void Encoding::write_packet_uplink_assignment( bitvec_write_field(dest, &wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING write_ta_ie(dest, wp,tbf->ta(), ta_idx, ta_ts); } else { /* EPGRS */ - unsigned int ws_enc = (tbf->m_window.ws() - 64) / 32; bitvec_write_field(dest, &wp,0x1,1); // Message escape bitvec_write_field(dest, &wp,0x0,2); // EGPRS message contents bitvec_write_field(dest, &wp,0x0,1); // No CONTENTION_RESOLUTION_TLLI @@ -458,7 +467,7 @@ void Encoding::write_packet_uplink_assignment( bitvec_write_field(dest, &wp,tbf->current_cs().to_num()-1, 4); // EGPRS Modulation and Coding IE /* 0: no RESEGMENT, 1: Segmentation*/ bitvec_write_field(dest, &wp, 0x1, 1); - bitvec_write_field(dest, &wp,ws_enc,5); // EGPRS Window Size + write_ws(dest, &wp, tbf->window_size()); // EGPRS Window Size bitvec_write_field(dest, &wp,0x0,1); // No Access Technologies Request bitvec_write_field(dest, &wp,0x0,1); // No ARAC RETRANSMISSION REQUEST bitvec_write_field(dest, &wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING @@ -509,7 +518,7 @@ void Encoding::write_packet_uplink_assignment( /* generate downlink assignment */ void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block, bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink, - struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp, + struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll, uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts, bool use_egprs) { @@ -518,7 +527,6 @@ void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block, PDA_AdditionsR99_t *pda_r99; uint8_t tn; - unsigned int ws_enc; block->PAYLOAD_TYPE = 0x1; // RLC/MAC control block that does not include the optional octets of the RLC/MAC control header block->RRBP = rrbp; // 0: N+13 @@ -591,12 +599,10 @@ void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block, return; } - ws_enc = (tbf->window()->ws() - 64) / 32; - block->u.Packet_Downlink_Assignment.Exist_AdditionsR99 = 0x1; // AdditionsR99 = on pda_r99 = &block->u.Packet_Downlink_Assignment.AdditionsR99; pda_r99->Exist_EGPRS_Params = 1; - pda_r99->EGPRS_WindowSize = ws_enc; /* see TS 44.060, table 12.5.2.1 */ + pda_r99->EGPRS_WindowSize = enc_ws(tbf->window_size()); /* see TS 44.060, table 12.5.2.1 */ pda_r99->LINK_QUALITY_MEASUREMENT_MODE = 0x0; /* no meas, see TS 44.060, table 11.2.7.2 */ pda_r99->Exist_BEP_PERIOD2 = 0; /* No extra EGPRS BEP PERIOD */ pda_r99->Exist_Packet_Extended_Timing_Advance = 0; diff --git a/src/encoding.h b/src/encoding.h index 6164b891..54cb0573 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -68,7 +68,7 @@ public: static void write_packet_downlink_assignment(RlcMacDownlink_t * block, bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink, - struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp, + struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll, uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts, bool use_egprs); diff --git a/src/pcu_vty_functions.cpp b/src/pcu_vty_functions.cpp index f1dd25c4..0a80a235 100644 --- a/src/pcu_vty_functions.cpp +++ b/src/pcu_vty_functions.cpp @@ -64,13 +64,12 @@ static void tbf_print_vty_info(struct vty *vty, gprs_rlcmac_tbf *tbf) } if (tbf->trx != NULL) vty_out(vty, " TRX_ID=%d", tbf->trx->trx_no); - vty_out(vty, " CS=%s WS=%d", - tbf->current_cs().name(), tbf->window()->ws()); + vty_out(vty, " CS=%s", tbf->current_cs().name()); if (ul_tbf) { gprs_rlc_ul_window *win = &ul_tbf->m_window; - vty_out(vty, " V(Q)=%d V(R)=%d", - win->v_q(), win->v_r()); + vty_out(vty, " WS=%u V(Q)=%d V(R)=%d", + ul_tbf->window_size(), win->v_q(), win->v_r()); vty_out(vty, "%s", VTY_NEWLINE); vty_out(vty, " TBF Statistics:%s", VTY_NEWLINE); if(GprsCodingScheme::GPRS == tbf->ms()->mode()) { @@ -81,8 +80,8 @@ static void tbf_print_vty_info(struct vty *vty, gprs_rlcmac_tbf *tbf) } if (dl_tbf) { gprs_rlc_dl_window *win = &dl_tbf->m_window; - vty_out(vty, " V(A)=%d V(S)=%d nBSN=%d%s", - win->v_a(), win->v_s(), win->resend_needed(), + vty_out(vty, " WS=%u V(A)=%d V(S)=%d nBSN=%d%s", + dl_tbf->window_size(), win->v_a(), win->v_s(), win->resend_needed(), win->window_stalled() ? " STALLED" : ""); vty_out(vty, "%s", VTY_NEWLINE); vty_out_rate_ctr_group(vty, " ", tbf->m_ctrs); diff --git a/src/tbf.h b/src/tbf.h index f57dbe3c..9491f2a4 100644 --- a/src/tbf.h +++ b/src/tbf.h @@ -464,7 +464,7 @@ struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf { bool keep_open(unsigned fn) const; int release(); int abort(); - + uint16_t window_size() const; void egprs_calc_window_size(); void update_coding_scheme_counter_dl(const GprsCodingScheme cs); @@ -562,7 +562,7 @@ struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf { uint8_t *data, const uint8_t block_idx); void egprs_calc_ulwindow_size(); - + uint16_t window_size() const; void update_coding_scheme_counter_ul(const GprsCodingScheme cs); /* Please note that all variables here will be reset when changing @@ -599,6 +599,16 @@ inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir ((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF); } +inline uint16_t gprs_rlcmac_ul_tbf::window_size() const +{ + return m_window.ws(); +} + +inline uint16_t gprs_rlcmac_dl_tbf::window_size() const +{ + return m_window.ws(); +} + inline void gprs_rlcmac_ul_tbf::enable_egprs() { m_window.set_sns(RLC_EGPRS_SNS); diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp index 28631516..40cb3136 100644 --- a/tests/tbf/TbfTest.cpp +++ b/tests/tbf/TbfTest.cpp @@ -2214,9 +2214,9 @@ static void test_tbf_ws() fprintf(stderr, "DL TBF slots: 0x%02x, N: %d, WS: %d\n", dl_tbf->dl_slots(), pcu_bitcount(dl_tbf->dl_slots()), - dl_tbf->window()->ws()); + dl_tbf->window_size()); OSMO_ASSERT(pcu_bitcount(dl_tbf->dl_slots()) == 4); - OSMO_ASSERT(dl_tbf->window()->ws() == 64); + OSMO_ASSERT(dl_tbf->window_size() == 64); tbf_free(dl_tbf); /* EGPRS-only */ @@ -2229,9 +2229,9 @@ static void test_tbf_ws() fprintf(stderr, "DL TBF slots: 0x%02x, N: %d, WS: %d\n", dl_tbf->dl_slots(), pcu_bitcount(dl_tbf->dl_slots()), - dl_tbf->window()->ws()); + dl_tbf->window_size()); OSMO_ASSERT(pcu_bitcount(dl_tbf->dl_slots()) == 4); - OSMO_ASSERT(dl_tbf->window()->ws() == 128 + 4 * 64); + OSMO_ASSERT(dl_tbf->window_size() == 128 + 4 * 64); tbf_free(dl_tbf); printf("=== end %s ===\n", __func__); @@ -2273,9 +2273,9 @@ static void test_tbf_update_ws(void) fprintf(stderr, "DL TBF slots: 0x%02x, N: %d, WS: %d\n", dl_tbf->dl_slots(), pcu_bitcount(dl_tbf->dl_slots()), - dl_tbf->window()->ws()); + dl_tbf->window_size()); OSMO_ASSERT(pcu_bitcount(dl_tbf->dl_slots()) == 1); - OSMO_ASSERT(dl_tbf->window()->ws() == 128 + 1 * 64); + OSMO_ASSERT(dl_tbf->window_size() == 128 + 1 * 64); dl_tbf->update(); @@ -2284,9 +2284,9 @@ static void test_tbf_update_ws(void) fprintf(stderr, "DL TBF slots: 0x%02x, N: %d, WS: %d\n", dl_tbf->dl_slots(), pcu_bitcount(dl_tbf->dl_slots()), - dl_tbf->window()->ws()); + dl_tbf->window_size()); OSMO_ASSERT(pcu_bitcount(dl_tbf->dl_slots()) == 4); - OSMO_ASSERT(dl_tbf->window()->ws() == 128 + 4 * 64); + OSMO_ASSERT(dl_tbf->window_size() == 128 + 4 * 64); tbf_free(dl_tbf);