lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

February 2023

  • 1 participants
  • 2601 discussions
Change in libosmo-abis[master]: e1_input: add timeslot type NONE
by dexter 13 Feb '23

13 Feb '23
dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/31307 ) Change subject: e1_input: add timeslot type NONE ...................................................................... Patch Set 1: (2 comments) Patchset: PS1: Please see my comment in e1_input.c File src/e1_input.c: https://gerrit.osmocom.org/c/libosmo-abis/+/31307/comment/899321fe_8a02d574 PS1, Line 451: There is an open question here: At the moment we implicitly expect the API user to take care that this timeslot no longer has any resources attached to it. It seems that the API was created with the expectation that we never change the mode of a timeslot (which is indeed the case so far). I think we should check here (and also in all other e1inp_ts_config_ functions) if there are still resources pending and take care that all of them are freed. Especially the sign and trau mode hold allocated resources, which could leak. -- To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/31307 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-abis Gerrit-Branch: master Gerrit-Change-Id: I073cfaba0d5073447842f22665e213135ea3f635 Gerrit-Change-Number: 31307 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Comment-Date: Mon, 13 Feb 2023 11:20:53 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
1 0
0 0
Change in libosmo-abis[master]: e1_input: add timeslot type NONE
by dexter 13 Feb '23

13 Feb '23
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/31307 ) Change subject: e1_input: add timeslot type NONE ...................................................................... e1_input: add timeslot type NONE Allow to configure a timeslot as type E1INP_TS_TYPE_NONE. The timeslot is then put back in its unconfigured state Change-Id: I073cfaba0d5073447842f22665e213135ea3f635 Related: OS#5198 --- M include/osmocom/abis/e1_input.h M src/e1_input.c 2 files changed, 14 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/07/31307/1 diff --git a/include/osmocom/abis/e1_input.h b/include/osmocom/abis/e1_input.h index 91bf181..eb29e8a 100644 --- a/include/osmocom/abis/e1_input.h +++ b/include/osmocom/abis/e1_input.h @@ -305,6 +305,9 @@ void (*hdlc_recv_cb)(struct e1inp_ts *ts, struct msgb *msg)); +/* configure and initialize one timeslot dedicated to nothing */ +int e1inp_ts_config_none(struct e1inp_ts *ts, struct e1inp_line *line); + /* obtain a string identifier/name for the given timeslot */ void e1inp_ts_name(char *out, size_t out_len, const struct e1inp_ts *ts); diff --git a/src/e1_input.c b/src/e1_input.c index 6c82d08..78615e6 100644 --- a/src/e1_input.c +++ b/src/e1_input.c @@ -444,6 +444,17 @@ return 0; } +int e1inp_ts_config_none(struct e1inp_ts *ts, struct e1inp_line *line) +{ + if (ts->type == E1INP_TS_TYPE_NONE && ts->line && line) + return 0; + + ts->type = E1INP_TS_TYPE_NONE; + ts->line = line; + + return 0; +} + static int e1inp_line_use_cb(struct osmo_use_count_entry *use_count_entry, int32_t old_use_count, const char *file, int file_line) { -- To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/31307 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-abis Gerrit-Branch: master Gerrit-Change-Id: I073cfaba0d5073447842f22665e213135ea3f635 Gerrit-Change-Number: 31307 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-ttcn3-hacks[master]: MGCP_Test: use constants to predefine RTP payloads
by pespin 13 Feb '23

13 Feb '23
Attention is currently required from: dexter. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31306 ) Change subject: MGCP_Test: use constants to predefine RTP payloads ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31306 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I7efc22e2f8a941e36200dda7841089e6c97185c6 Gerrit-Change-Number: 31306 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Mon, 13 Feb 2023 10:39:40 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in osmo-ttcn3-hacks[master]: MGCP_Test: Test ts101318 rfc5993 conversation with fmtp
by dexter 13 Feb '23

13 Feb '23
Attention is currently required from: laforge, pespin. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31205 ) Change subject: MGCP_Test: Test ts101318 rfc5993 conversation with fmtp ...................................................................... Patch Set 2: (1 comment) File mgw/MGCP_Test.ttcn: https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31205/comment/fb810774_abb5… PS1, Line 2312: testcase TC_ts101318_rfc5993_rtp_conversion() runs on dummy_CT { > agreeing with pespin. Done -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31205 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I14421f780c4ef9e4c7e91182154070617852e957 Gerrit-Change-Number: 31205 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Mon, 13 Feb 2023 10:17:17 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge <laforge(a)osmocom.org> Comment-In-Reply-To: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: comment
1 0
0 0
Change in osmo-ttcn3-hacks[master]: MGCP_Test: use constants to predefine RTP payloads
by dexter 13 Feb '23

13 Feb '23
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31306 ) Change subject: MGCP_Test: use constants to predefine RTP payloads ...................................................................... MGCP_Test: use constants to predefine RTP payloads The function f_TC_amr_x_x_rtp_conversion() is called with RTP payload octetstrings in the parameter list. Lets define constants for those octetstrings so that it is better visible which RTP payload is which. Change-Id: I7efc22e2f8a941e36200dda7841089e6c97185c6 --- M mgw/MGCP_Test.ttcn 1 file changed, 8 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/06/31306/1 diff --git a/mgw/MGCP_Test.ttcn b/mgw/MGCP_Test.ttcn index 7252882..dfbe263 100644 --- a/mgw/MGCP_Test.ttcn +++ b/mgw/MGCP_Test.ttcn @@ -2388,16 +2388,21 @@ * functions are real world AMR RTP payloads including AMR header. The * payloads were extracted from a trace with known good payloads. */ + const octetstring rtp_amr_5_90k_oa := '2014e959f35fdfe5e9667ffbc088818088'O; + const octetstring rtp_amr_5_90k_bwe := '217a567cd7f7f97a599ffef022206022'O; + const octetstring rtp_amr_5_15k_oa := '100c4e9ba850e30d5d53d04de41e7c'O; + const octetstring rtp_amr_5_15k_bwe := '10d3a6ea1438c35754f41379079f'O; + testcase TC_amr_oa_bwe_rtp_conversion() runs on dummy_CT { - f_TC_amr_x_x_rtp_conversion('2014e959f35fdfe5e9667ffbc088818088'O, '217a567cd7f7f97a599ffef022206022'O, "octet-align=1", "octet-align=0"); + f_TC_amr_x_x_rtp_conversion(rtp_amr_5_90k_oa, rtp_amr_5_90k_bwe, "octet-align=1", "octet-align=0"); } testcase TC_amr_oa_oa_rtp_conversion() runs on dummy_CT { - f_TC_amr_x_x_rtp_conversion('100c4e9ba850e30d5d53d04de41e7c'O, '100c4e9ba850e30d5d53d04de41e7c'O, "octet-align=1", "octet-align=1"); + f_TC_amr_x_x_rtp_conversion(rtp_amr_5_15k_oa, rtp_amr_5_15k_oa, "octet-align=1", "octet-align=1"); } testcase TC_amr_bwe_bwe_rtp_conversion() runs on dummy_CT { - f_TC_amr_x_x_rtp_conversion('10d3a6ea1438c35754f41379079f'O, '10d3a6ea1438c35754f41379079f'O, "octet-align=0", "octet-align=0"); + f_TC_amr_x_x_rtp_conversion(rtp_amr_5_15k_bwe, rtp_amr_5_15k_bwe, "octet-align=0", "octet-align=0"); } /* TODO: Double-DLCX (no retransmission) */ -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/31306 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I7efc22e2f8a941e36200dda7841089e6c97185c6 Gerrit-Change-Number: 31306 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: Implement GMMRR-ASSIGN.req
by pespin 13 Feb '23

13 Feb '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/31285 ) Change subject: rlcmac: Implement GMMRR-ASSIGN.req ...................................................................... rlcmac: Implement GMMRR-ASSIGN.req Change-Id: I3178aa1af4a6c05c84253c6befcd4c786b8dd8e9 --- M include/osmocom/gprs/rlcmac/rlcmac_prim.h M src/rlcmac/rlcmac_prim.c 2 files changed, 16 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved laforge: Looks good to me, but someone else must approve diff --git a/include/osmocom/gprs/rlcmac/rlcmac_prim.h b/include/osmocom/gprs/rlcmac/rlcmac_prim.h index 92e644e..40d2d9a 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_prim.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_prim.h @@ -186,7 +186,7 @@ uint32_t tlli, uint8_t *ll_pdu, size_t ll_pdu_len); /* Alloc primitive for GMMRR SAP: */ -struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_gmmrr_asign_req( +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_gmmrr_assign_req( uint32_t new_tlli); /* Alloc primitive for L1CTL SAP: */ diff --git a/src/rlcmac/rlcmac_prim.c b/src/rlcmac/rlcmac_prim.c index ef0dd22..954f954 100644 --- a/src/rlcmac/rlcmac_prim.c +++ b/src/rlcmac/rlcmac_prim.c @@ -383,8 +383,21 @@ static int rlcmac_prim_handle_gmmrr_assign_req(struct osmo_gprs_rlcmac_prim *rlcmac_prim) { - int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); - return rc; + struct gprs_rlcmac_entity *gre; + + gre = gprs_rlcmac_find_entity_by_tlli(rlcmac_prim->gmmrr.assign_req.new_tlli); + if (!gre) { + LOGRLCMAC(LOGL_INFO, "GMMRR-ASSIGN.req: creating new entity TLLI=0x%08x\n", + rlcmac_prim->gmmrr.assign_req.new_tlli); + gre = gprs_rlcmac_entity_alloc(rlcmac_prim->gmmrr.assign_req.new_tlli); + OSMO_ASSERT(gre); + } else { + LOGRLCMAC(LOGL_INFO, "GMMRR-ASSIGN.req: TLLI=0x%08x already exists\n", + rlcmac_prim->gmmrr.assign_req.new_tlli); + } + + msgb_free(rlcmac_prim->oph.msg); + return 0; } static int gprs_rlcmac_prim_gmmrr_upper_down(struct osmo_gprs_rlcmac_prim *rlcmac_prim) -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/31285 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I3178aa1af4a6c05c84253c6befcd4c786b8dd8e9 Gerrit-Change-Number: 31285 Gerrit-PatchSet: 4 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: msuraev <msuraev(a)sysmocom.de> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: Initial ul_tbf data support
by pespin 13 Feb '23

13 Feb '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/31170 ) Change subject: rlcmac: Initial ul_tbf data support ...................................................................... rlcmac: Initial ul_tbf data support This is basically an import of relevant code from osmo-pcu.git 08523c2286dfe27402f8e2eb4b98da5a529c7915 which allows encoding LLC frames into RLC/MAC uplink data blocks. A 1-to-1 import was not possible for several reasons: * osmo-pcu uses C++ in some places * osmo-pcu implements encoding of DL data blocks, not UL data blocks * Some osmo-pcu code is still not really polished and stuff is still mixed (for instance rlc_window(_ul).c/h were split into their own files here). Hence this was not a "copy all files and leave as they are" import, but rather looking at the encode path starting on osmo-pcu.git scheduler and see which code had to be pulled in to encode the RLC/MAC blocks. Due to the slightly different requerirements for UL and DL blocks, it is well possible that further work in needed in order to have the code produce correct blocks. This is only a first step to pull in all code so that stuff can be fixed in smallish incremental steps. Related: OS#5500 Change-Id: I0a01d79d16bbfc63aa88e6bb0f432f3772645730 --- M include/osmocom/gprs/rlcmac/Makefile.am A include/osmocom/gprs/rlcmac/coding_scheme.h A include/osmocom/gprs/rlcmac/rlc.h A include/osmocom/gprs/rlcmac/rlc_window.h A include/osmocom/gprs/rlcmac/rlc_window_ul.h M include/osmocom/gprs/rlcmac/rlcmac_enc.h M include/osmocom/gprs/rlcmac/rlcmac_private.h M include/osmocom/gprs/rlcmac/tbf.h M include/osmocom/gprs/rlcmac/tbf_ul.h M include/osmocom/gprs/rlcmac/tbf_ul_fsm.h M src/rlcmac/Makefile.am A src/rlcmac/coding_scheme.c A src/rlcmac/rlc.c A src/rlcmac/rlc_window.c A src/rlcmac/rlc_window_ul.c M src/rlcmac/rlcmac.c M src/rlcmac/rlcmac_enc.c M src/rlcmac/sched.c M src/rlcmac/tbf_ul.c M src/rlcmac/tbf_ul_ass_fsm.c M src/rlcmac/tbf_ul_fsm.c M tests/rlcmac/rlcmac_prim_test.c M tests/rlcmac/rlcmac_prim_test.err M tests/rlcmac/rlcmac_prim_test.ok 24 files changed, 2,596 insertions(+), 15 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/include/osmocom/gprs/rlcmac/Makefile.am b/include/osmocom/gprs/rlcmac/Makefile.am index c529a4e..3f04ee3 100644 --- a/include/osmocom/gprs/rlcmac/Makefile.am +++ b/include/osmocom/gprs/rlcmac/Makefile.am @@ -1,7 +1,11 @@ noinst_HEADERS = \ codel.h \ + coding_scheme.h \ gre.h \ llc_queue.h \ + rlc.h \ + rlc_window.h \ + rlc_window_ul.h \ rlcmac_enc.h \ rlcmac_private.h \ sched.h \ diff --git a/include/osmocom/gprs/rlcmac/coding_scheme.h b/include/osmocom/gprs/rlcmac/coding_scheme.h new file mode 100644 index 0000000..31692a5 --- /dev/null +++ b/include/osmocom/gprs/rlcmac/coding_scheme.h @@ -0,0 +1,106 @@ +/* coding_scheme.h + * + * Copyright (C) 2015-2023 by sysmocom s.f.m.c. GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#pragma once + +#include <osmocom/core/utils.h> + +#include <stdbool.h> + +enum gprs_rlcmac_coding_scheme { + GPRS_RLCMAC_CS_UNKNOWN, + /* GPRS Coding Schemes: */ + GPRS_RLCMAC_CS_1, + GPRS_RLCMAC_CS_2, + GPRS_RLCMAC_CS_3, + GPRS_RLCMAC_CS_4, + /* EDGE/EGPRS Modulation and Coding Schemes: */ + GPRS_RLCMAC_MCS_1, + GPRS_RLCMAC_MCS_2, + GPRS_RLCMAC_MCS_3, + GPRS_RLCMAC_MCS_4, + GPRS_RLCMAC_MCS_5, + GPRS_RLCMAC_MCS_6, + GPRS_RLCMAC_MCS_7, + GPRS_RLCMAC_MCS_8, + GPRS_RLCMAC_MCS_9, + GPRS_RLCMAC_NUM_SCHEMES +}; + +enum gprs_rlcmac_coding_scheme_kind { + GPRS_RLCMAC_SCHEME_GPRS, + GPRS_RLCMAC_SCHEME_EGPRS_GMSK, + GPRS_RLCMAC_SCHEME_EGPRS, +}; + +enum gprs_rlcmac_egprs_arq_type { + GPRS_RLCMAC_EGPRS_ARQ1 = 0, + GPRS_RLCMAC_EGPRS_ARQ2 = 1, +}; + +extern const struct value_string gprs_rlcmac_coding_scheme_names[]; +const char *gprs_rlcmac_mcs_name(enum gprs_rlcmac_coding_scheme val); +enum gprs_rlcmac_coding_scheme gprs_rlcmac_get_retx_mcs(enum gprs_rlcmac_coding_scheme initial_mcs, enum gprs_rlcmac_coding_scheme commanded_mcs, bool resegment_bit); + +bool gprs_rlcmac_mcs_is_gprs(enum gprs_rlcmac_coding_scheme cs); +bool gprs_rlcmac_mcs_is_edge(enum gprs_rlcmac_coding_scheme cs); +bool gprs_rlcmac_mcs_is_edge_gmsk(enum gprs_rlcmac_coding_scheme cs); + +uint8_t gprs_rlcmac_mcs_chan_code(enum gprs_rlcmac_coding_scheme cs); + +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_by_size_ul(unsigned size); +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_gprs_by_num(unsigned num); +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_egprs_by_num(unsigned num); +bool gprs_rlcmac_mcs_is_valid(enum gprs_rlcmac_coding_scheme cs); +bool gprs_rlcmac_mcs_is_compat(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme o); +bool gprs_rlcmac_mcs_is_compat_kind(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme_kind mode); + +uint8_t gprs_rlcmac_mcs_size_ul(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_size_dl(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_used_size_ul(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_used_size_dl(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_max_bytes_ul(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_max_bytes_dl(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_spare_bits_ul(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_spare_bits_dl(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_max_data_block_bytes(enum gprs_rlcmac_coding_scheme cs); +uint8_t gprs_rlcmac_mcs_opt_padding_bits(enum gprs_rlcmac_coding_scheme cs); + +void gprs_rlcmac_mcs_inc_kind(enum gprs_rlcmac_coding_scheme *cs, enum gprs_rlcmac_coding_scheme_kind mode); +void gprs_rlcmac_mcs_dec_kind(enum gprs_rlcmac_coding_scheme *cs, enum gprs_rlcmac_coding_scheme_kind mode); +void gprs_rlcmac_mcs_inc(enum gprs_rlcmac_coding_scheme *cs); +void gprs_rlcmac_mcs_dec(enum gprs_rlcmac_coding_scheme *cs); + +bool gprs_rlcmac_mcs_is_family_compat(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme o); +void gprs_rlcmac_mcs_dec_to_single_block(enum gprs_rlcmac_coding_scheme *cs, bool *need_stuffing); + +enum gprs_rlcmac_header_type { + GPRS_RLCMAC_HEADER_INVALID, + GPRS_RLCMAC_HEADER_GPRS_CONTROL, + GPRS_RLCMAC_HEADER_GPRS_DATA, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3, + GPRS_RLCMAC_NUM_HEADER_TYPES +}; + +enum gprs_rlcmac_header_type gprs_rlcmac_mcs_header_type(enum gprs_rlcmac_coding_scheme mcs); + +uint8_t gprs_rlcmac_num_data_blocks(enum gprs_rlcmac_header_type ht); +uint8_t gprs_rlcmac_num_data_header_bits_UL(enum gprs_rlcmac_header_type ht); +uint8_t gprs_rlcmac_num_data_header_bits_DL(enum gprs_rlcmac_header_type ht); +uint8_t gprs_rlcmac_num_data_block_header_bits(enum gprs_rlcmac_header_type ht); + +const char *gprs_rlcmac_msc_kind_name(enum gprs_rlcmac_coding_scheme_kind val); diff --git a/include/osmocom/gprs/rlcmac/rlc.h b/include/osmocom/gprs/rlcmac/rlc.h new file mode 100644 index 0000000..8ca5370 --- /dev/null +++ b/include/osmocom/gprs/rlcmac/rlc.h @@ -0,0 +1,275 @@ +/* RLC block manipulation, 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +#include <osmocom/core/endian.h> +#include <osmocom/gprs/rlcmac/coding_scheme.h> + +#define RLC_GPRS_SNS 128 /* GPRS, must be power of 2 */ +#define RLC_EGPRS_SNS 2048 /* EGPRS, must be power of 2 */ +#define RLC_EGPRS_MAX_BSN_DELTA 512 +#define RLC_MAX_SNS RLC_EGPRS_SNS +#define RLC_MAX_LEN 74 /* MCS-9 data unit */ + +struct gprs_rlcmac_rlc_li_field { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t e:1, + m:1, + li:6; + uint8_t ll_pdu[0]; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + uint8_t li:6, m:1, e:1; + uint8_t ll_pdu[0]; +#endif +} __attribute__ ((packed)); + +/* TS 44.060 10.2.2 Uplink RLC data block */ +struct gprs_rlcmac_rlc_ul_data_header { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t r:1, + si:1, + cv:4, + pt:2; + uint8_t ti:1, + tfi:5, + pi:1, + spare:1; + uint8_t e:1, + bsn:7; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + uint8_t pt:2, cv:4, si:1, r:1; + uint8_t spare:1, pi:1, tfi:5, ti:1; + uint8_t bsn:7, e:1; +#endif +} __attribute__ ((packed)); + +/* TS 44.060 10.2.1 Downlink RLC data block */ +struct gprs_rlcmac_rlc_dl_data_header { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t usf:3, + s_p:1, + rrbp:2, + pt:2; + uint8_t fbi:1, + tfi:5, + pr:2; + uint8_t e:1, + bsn:7; + struct gprs_rlcmac_rlc_li_field lime[0]; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + uint8_t pt:2, rrbp:2, s_p:1, usf:3; + uint8_t pr:2, tfi:5, fbi:1; + uint8_t bsn:7, e:1; + struct gprs_rlcmac_rlc_li_field lime[0]; +#endif +} __attribute__ ((packed)); + +struct gprs_rlcmacrlc_li_field_egprs { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t e:1, + li:7; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + uint8_t li:7, e:1; +#endif +} __attribute__ ((packed)); + +static inline uint16_t mod_sns_half(void) +{ + return (RLC_MAX_SNS / 2) - 1; +} + +struct gprs_rlcmac_rlc_block_info { + unsigned int data_len; /* EGPRS: N2, GPRS: N2-2, N-2 */ + unsigned int bsn; + unsigned int ti; + unsigned int e; + unsigned int cv; /* FBI == 1 <=> CV == 0 */ + unsigned int pi; + unsigned int spb; +}; +void gprs_rlcmac_rlc_block_info_init(struct gprs_rlcmac_rlc_block_info *rdbi, enum gprs_rlcmac_coding_scheme cs, bool with_padding, const unsigned int spb); + +struct gprs_rlcmac_rlc_data_info { + enum gprs_rlcmac_coding_scheme cs; + unsigned int r; + unsigned int si; + unsigned int tfi; + unsigned int cps; + unsigned int rsb; + unsigned int usf; + unsigned int es_p; + unsigned int rrbp; + unsigned int pr; + uint8_t num_data_blocks; /* this can actually be only 0, 1, 2: enforced in gprs_rlcmac_rlc_data_header_init() */ + unsigned int with_padding; + unsigned int data_offs_bits[2]; + struct gprs_rlcmac_rlc_block_info block_info[2]; +}; +void gprs_rlcmac_rlc_data_info_init_ul(struct gprs_rlcmac_rlc_data_info *rlc, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding, unsigned int spb); +void gprs_rlcmac_rlc_data_info_init_dl(struct gprs_rlcmac_rlc_data_info *rlc, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding); + +/* + * EGPRS resegment status information for UL + * When only first split block is received bsn state + * will be set to EGPRS_RESEG_FIRST_SEG_RXD and when + * only second segment is received the state will be + * set to EGPRS_RESEG_SECOND_SEG_RXD. When both Split + * blocks are received the state will be set to + * EGPRS_RESEG_DEFAULT + * The EGPRS resegmentation feature allows MS to retransmit + * RLC blocks of HeaderType1, HeaderType2 by segmenting + * them to 2 HeaderType3 blocks(Example MCS5 will be + * retransmitted as 2 MCS2 blocks). Table 10.4.8b.1 of 44.060 + * explains the possible values of SPB in HeadrType3 for UL + * direction. When the MCS is changed at the PCU, PCU directs the + * changed MCS to MS by PUAN or UPLINK ASSIGNMENT message along + * with RESEGMENT flag, Then MS may decide to retransmit the + * blocks by resegmenting it based on Table 8.1.1.1 of 44.060. + * The retransmission MCS is calculated based on current MCS of + * the Block and demanded MCS by PCU. Section 10.3a.4.3 of 44.060 + * shows the HeadrType3 with SPB field present in it +*/ +enum gprs_rlcmac_rlc_egprs_dl_reseg_bsn_state { + GPRS_RLCMAC_EGPRS_RESEG_DEFAULT = 0, + GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_RXD = 0x01, + GPRS_RLCMAC_EGPRS_RESEG_SECOND_SEG_RXD = 0x02, + GPRS_RLCMAC_EGPRS_RESEG_INVALID = 0x04 +}; + +/* + * EGPRS resegment status information for DL + * When only first segment is sent, bsn state + * will be set to EGPRS_RESEG_FIRST_SEG_SENT and when + * second segment is sent the state will be + * set to EGPRS_RESEG_SECOND_SEG_SENT. + * EGPRS_RESEG_DL_INVALID is set to 8 considering there is a scope for + * 3rd segment according to Table 10.4.8b.2 of 44.060 + * The EGPRS resegmentation feature allows PCU to retransmit + * RLC blocks of HeaderType1, HeaderType2 by segmenting + * them to 2 HeaderType3 blocks(Example MCS5 will be + * retransmitted as 2 MCS2 blocks). Table 10.4.8b.2 of 44.060 + * explains the possible values of SPB in HeadrType3 for DL + * direction.The PCU decides to retransmit the + * blocks by resegmenting it based on Table 8.1.1.1 of 44.060. + * The retransmission MCS is calculated based on current MCS of + * the Block and demanded MCS by PCU. Section 10.3a.3.3 of 44.060 + * shows the HeadrType3 with SPB field present in it + */ +enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state { + GPRS_RLCMAC_EGPRS_RESEG_UL_DEFAULT = 0, + GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_SENT = 0x01, + GPRS_RLCMAC_EGPRS_RESEG_SECOND_SEG_SENT = 0x02, + GPRS_RLCMAC_EGPRS_RESEG_UL_INVALID = 0x08 +}; + +/* holds the current status of the block w.r.t UL/DL split blocks */ +union split_block_status { + enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state block_status_ul; + enum gprs_rlcmac_rlc_egprs_dl_reseg_bsn_state block_status_dl; +}; + +/* Table 10.4.8b.2 of 44.060 */ +enum gprs_rlcmac_rlc_egprs_ul_spb { + GPRS_RLCMAC_EGPRS_UL_SPB_NO_RETX = 0, + GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_10PAD = 1, + GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_6NOPAD = 2, + GPRS_RLCMAC_EGPRS_UL_SPB_SEC_SEG = 3, +}; + +#if 0 +/* Table 10.4.8b.2 of 44.060 */ +enum gprs_rlcmac_rlc_egprs_dl_spb { + GPRS_RLCMAC_EGPRS_DL_SPB_NO_RETX = 0, + GPRS_RLCMAC_EGPRS_DL_SPB_FIRST_SEG = 2, + GPRS_RLCMAC_EGPRS_DL_SPB_SEC_SEG = 3, +}; +#endif + +/* + * Valid puncturing scheme values + * TS 44.060 10.4.8a.3.1, 10.4.8a.2.1, 10.4.8a.1.1 + */ +enum gprs_rlcmac_egprs_puncturing_values { + GPRS_RLCMAC_EGPRS_PS_1, + GPRS_RLCMAC_EGPRS_PS_2, + GPRS_RLCMAC_EGPRS_PS_3, + GPRS_RLCMAC_EGPRS_PS_INVALID, +}; + +/* + * EGPRS_MAX_PS_NUM_2 is valid for MCS 1,2,5,6. + * And EGPRS_MAX_PS_NUM_3 is valid for MCS 3,4,7,8,9 + * TS 44.060 10.4.8a.3.1, 10.4.8a.2.1, 10.4.8a.1.1 + */ +enum gprs_rlcmac_egprs_puncturing_types { + GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2 = 2, + GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3, + GPRS_RLCMAC_EGPRS_MAX_PS_NUM_INVALID, +}; + +struct gprs_rlcmac_rlc_block { + /* block data including LI headers */ + uint8_t buf[RLC_MAX_LEN]; + /* block data len including LI headers*/ + uint8_t len; + + struct gprs_rlcmac_rlc_block_info block_info; + /* + * cs_current_trans is variable to hold the cs_last value for + * current transmission. cs_current_trans is same as cs_last during + * transmission case. during retransmission cs_current_trans is + * fetched from egprs_mcs_retx_tbl table based on + * cs and demanded cs.reference is 44.060 Table + * 8.1.1.1 and Table 8.1.1.2 + * For UL. cs_last shall be used everywhere. + */ + enum gprs_rlcmac_coding_scheme cs_current_trans; + enum gprs_rlcmac_coding_scheme cs_last; + + /* + * The MCS of initial transmission of a BSN + * This variable is used for split block + * processing in DL + */ + enum gprs_rlcmac_coding_scheme cs_init; + + /* puncturing scheme value to be used for next transmission*/ + enum gprs_rlcmac_egprs_puncturing_values next_ps; + + /* holds the status of the block w.r.t UL/DL split blocks*/ + union split_block_status spb_status; +}; +uint8_t *gprs_rlcmac_rlc_block_prepare(struct gprs_rlcmac_rlc_block *blk, size_t block_data_len); + +/* + * I hold the currently transferred blocks and will provide + * the routines to manipulate these arrays. + */ +struct gprs_rlcmac_rlc_block_store { + struct gprs_rlcmac_rlc_block blocks[RLC_MAX_SNS/2]; +}; + +struct gprs_rlcmac_rlc_block_store *gprs_rlcmac_rlc_block_store_alloc(void *ctx); +void gprs_rlcmac_rlc_block_store_free(struct gprs_rlcmac_rlc_block_store *blkst); + +struct gprs_rlcmac_rlc_block *gprs_rlcmac_rlc_block_store_get_block(struct gprs_rlcmac_rlc_block_store *blkst, int bsn); + +unsigned int gprs_rlcmac_rlc_mcs_cps(enum gprs_rlcmac_coding_scheme cs, + enum gprs_rlcmac_egprs_puncturing_values punct, + enum gprs_rlcmac_egprs_puncturing_values punct2, + bool with_padding); +enum gprs_rlcmac_egprs_puncturing_values gprs_rlcmac_get_punct_scheme(enum gprs_rlcmac_egprs_puncturing_values punct, + enum gprs_rlcmac_coding_scheme cs, + enum gprs_rlcmac_coding_scheme cs_current_trans, + enum gprs_rlcmac_rlc_egprs_ul_spb spb); +void gprs_rlcmac_update_punct_scheme(enum gprs_rlcmac_egprs_puncturing_values *punct, + enum gprs_rlcmac_coding_scheme cs); diff --git a/include/osmocom/gprs/rlcmac/rlc_window.h b/include/osmocom/gprs/rlcmac/rlc_window.h new file mode 100644 index 0000000..a5d89ab --- /dev/null +++ b/include/osmocom/gprs/rlcmac/rlc_window.h @@ -0,0 +1,22 @@ +/* RLC Window (common for both UL/DL TBF), 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +struct gprs_rlcmac_rlc_window { + uint16_t sns; + uint16_t ws; +}; + +struct gprs_rlcmac_rlc_window; + +void gprs_rlcmac_rlc_window_constructor(struct gprs_rlcmac_rlc_window *w); +void gprs_rlcmac_rlc_window_destructor(struct gprs_rlcmac_rlc_window *w); + +uint16_t gprs_rlcmac_rlc_window_mod_sns(const struct gprs_rlcmac_rlc_window *w); +uint16_t gprs_rlcmac_rlc_window_mod_sns_bsn(const struct gprs_rlcmac_rlc_window *w, uint16_t bsn); +uint16_t gprs_rlcmac_rlc_window_sns(const struct gprs_rlcmac_rlc_window *w); +uint16_t gprs_rlcmac_rlc_window_ws(const struct gprs_rlcmac_rlc_window *w); + +void gprs_rlcmac_rlc_window_set_sns(struct gprs_rlcmac_rlc_window *w, uint16_t sns); +void gprs_rlcmac_rlc_window_set_ws(struct gprs_rlcmac_rlc_window *w, uint16_t ws); diff --git a/include/osmocom/gprs/rlcmac/rlc_window_ul.h b/include/osmocom/gprs/rlcmac/rlc_window_ul.h new file mode 100644 index 0000000..ea51cd1 --- /dev/null +++ b/include/osmocom/gprs/rlcmac/rlc_window_ul.h @@ -0,0 +1,98 @@ +/* RLC Window (common for both UL/DL TBF), 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +#include <osmocom/core/bitvec.h> + +#include <osmocom/gprs/rlcmac/rlc.h> +#include <osmocom/gprs/rlcmac/rlc_window.h> + +struct gprs_rlcmac_ul_tbf; + +enum gprs_rlcmac_rlc_ul_bsn_state { + GPRS_RLCMAC_RLC_UL_BSN_INVALID, + GPRS_RLCMAC_RLC_UL_BSN_NACKED, + GPRS_RLCMAC_RLC_UL_BSN_ACKED, + GPRS_RLCMAC_RLC_UL_BSN_UNACKED, + GPRS_RLCMAC_RLC_UL_BSN_RESEND, + GPRS_RLCMAC_RLC_UL_BSN_MAX, +}; + +struct gprs_rlcmac_rlc_v_b { + enum gprs_rlcmac_rlc_ul_bsn_state v_b[RLC_MAX_SNS/2]; /* acknowledge state array */ +}; + +void gprs_rlcmac_rlc_v_b_reset(struct gprs_rlcmac_rlc_v_b *v_b); +/* Check for an individual frame */ +bool gprs_rlcmac_rlc_v_b_is_unacked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +bool gprs_rlcmac_rlc_v_b_is_nacked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +bool gprs_rlcmac_rlc_v_b_is_acked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +bool gprs_rlcmac_rlc_v_b_is_resend(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +bool gprs_rlcmac_rlc_v_b_is_invalid(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +enum gprs_rlcmac_rlc_ul_bsn_state gprs_rlcmac_rlc_v_b_get_state(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn); + +/* Mark a RLC frame for something */ +void gprs_rlcmac_rlc_v_b_mark_unacked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +void gprs_rlcmac_rlc_v_b_mark_nacked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +void gprs_rlcmac_rlc_v_b_mark_acked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +void gprs_rlcmac_rlc_v_b_mark_resend(struct gprs_rlcmac_rlc_v_b *v_b, int bsn); +void gprs_rlcmac_rlc_v_b_mark_invalid(struct gprs_rlcmac_rlc_v_b *v_b, int bsn); + + +struct gprs_rlcmac_rlc_ul_window { + struct gprs_rlcmac_rlc_window window; /* parent */ + struct gprs_rlcmac_ul_tbf *ul_tbf; /* backpointer */ + + uint16_t v_s; /* send state */ + uint16_t v_a; /* ack state */ + struct gprs_rlcmac_rlc_v_b v_b; +}; + +struct gprs_rlcmac_rlc_ul_window *gprs_rlcmac_rlc_ul_window_alloc(struct gprs_rlcmac_ul_tbf *ul_tbf); +void gprs_rlcmac_rlc_ul_window_free(struct gprs_rlcmac_rlc_ul_window *ulw); + +void gprs_rlcmac_rlc_ul_window_reset(struct gprs_rlcmac_rlc_ul_window *ulw); + +bool gprs_rlcmac_rlc_ul_window_window_stalled(const struct gprs_rlcmac_rlc_ul_window *ulw); +bool gprs_rlcmac_rlc_ul_window_window_empty(const struct gprs_rlcmac_rlc_ul_window *ulw); + +void gprs_rlcmac_rlc_ul_window_increment_send(struct gprs_rlcmac_rlc_ul_window *ulw); +void gprs_rlcmac_rlc_ul_window_raise(struct gprs_rlcmac_rlc_ul_window *ulw, int moves); + +uint16_t gprs_rlcmac_rlc_ul_window_v_s(const struct gprs_rlcmac_rlc_ul_window *ulw); +uint16_t gprs_rlcmac_rlc_ul_window_v_s_mod(const struct gprs_rlcmac_rlc_ul_window *ulw, int offset); +uint16_t gprs_rlcmac_rlc_ul_window_v_a(const struct gprs_rlcmac_rlc_ul_window *ulw); +uint16_t gprs_rlcmac_rlc_ul_window_distance(const struct gprs_rlcmac_rlc_ul_window *ulw); + +/* Methods to manage reception */ +int gprs_rlcmac_rlc_ul_window_resend_needed(const struct gprs_rlcmac_rlc_ul_window *ulw); +unsigned int gprs_rlcmac_rlc_ul_window_mark_for_resend(struct gprs_rlcmac_rlc_ul_window *ulw); +void gprs_rlcmac_rlc_ul_window_update_ssn(struct gprs_rlcmac_rlc_ul_window *ulw, char *show_rbb, + uint16_t ssn, uint16_t *lost, uint16_t *received); +void gprs_rlcmac_rlc_ul_window_update(struct gprs_rlcmac_rlc_ul_window *ulw, const struct bitvec *rbb, + uint16_t first_bsn, uint16_t *lost, uint16_t *received); +unsigned int gprs_rlcmac_rlc_ul_window_move_window(struct gprs_rlcmac_rlc_ul_window *ulw); +void gprs_rlcmac_rlc_ul_window_show_state(const struct gprs_rlcmac_rlc_ul_window *ulw, char *show_v_b); +unsigned int gprs_rlcmac_rlc_ul_window_count_unacked(const struct gprs_rlcmac_rlc_ul_window *ulw); + + +static inline struct gprs_rlcmac_rlc_window *rlc_ulw_as_w(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + return &ulw->window; +} + +static inline const struct gprs_rlcmac_rlc_window *rlc_ulw_as_w_const(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + return &ulw->window; +} + +static inline struct gprs_rlcmac_rlc_ul_window *rlc_w_as_ulw(struct gprs_rlcmac_rlc_window *w) +{ + return (struct gprs_rlcmac_rlc_ul_window *)w; +} + +static inline const struct gprs_rlcmac_rlc_ul_window *rcl_w_as_ulw_const(struct gprs_rlcmac_rlc_window *w) +{ + return (const struct gprs_rlcmac_rlc_ul_window *)w; +} diff --git a/include/osmocom/gprs/rlcmac/rlcmac_enc.h b/include/osmocom/gprs/rlcmac/rlcmac_enc.h index 67448c1..d091d53 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_enc.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_enc.h @@ -3,13 +3,46 @@ /* RLCMAC encoding support functions */ #include <stdint.h> +#include <osmocom/core/msgb.h> #include <osmocom/gprs/rlcmac/csn1_defs.h> #include <osmocom/gprs/rlcmac/types_private.h> #include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/rlc.h> #define GPRS_RLCMAC_DUMMY_VEC "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b" + +/**************** + * DATA BLOCKS: + ****************/ + +enum gpr_rlcmac_append_result { + GPRS_RLCMAC_AR_NEED_MORE_BLOCKS, + GPRS_RLCMAC_AR_COMPLETED_SPACE_LEFT, + GPRS_RLCMAC_AR_COMPLETED_BLOCK_FILLED, +}; + +int gprs_rlcmac_rlc_write_ul_data_header(const struct gprs_rlcmac_rlc_data_info *rlc, uint8_t *data); + +enum gpr_rlcmac_append_result gprs_rlcmac_enc_append_ul_data( + struct gprs_rlcmac_rlc_block_info *rdbi, + enum gprs_rlcmac_coding_scheme cs, + struct msgb *llc_msg, int *offset, int *num_chunks, + uint8_t *data_block, bool is_final, int *count_payload); + +void gprs_rlcmac_rlc_data_to_ul_append_egprs_li_padding(const struct gprs_rlcmac_rlc_block_info *rdbi, + int *offset, int *num_chunks, uint8_t *data_block); + +unsigned int gprs_rlcmac_rlc_copy_from_aligned_buffer(const struct gprs_rlcmac_rlc_data_info *rlc, + unsigned int data_block_idx, + uint8_t *dst, const uint8_t *buffer); + + +/**************** + * CONTROL BLOCKS: + ****************/ + void gprs_rlcmac_enc_prepare_pkt_ul_dummy_block(RlcMacUplink_t *block, uint32_t tlli); void gprs_rlcmac_enc_prepare_pkt_resource_req(RlcMacUplink_t *block, struct gprs_rlcmac_ul_tbf *ul_tbf, enum gprs_rlcmac_access_type acc_type); diff --git a/include/osmocom/gprs/rlcmac/rlcmac_private.h b/include/osmocom/gprs/rlcmac/rlcmac_private.h index e838c32..f35b69a 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_private.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_private.h @@ -10,6 +10,7 @@ #include <osmocom/gprs/rlcmac/rlcmac_prim.h> #include <osmocom/gprs/rlcmac/rlcmac.h> +#include <osmocom/gprs/rlcmac/coding_scheme.h> /* 3GPP TS 44.064 § 8.3 TLLI assignment procedures */ #define GPRS_RLCMAC_TLLI_UNASSIGNED (0xffffffff) @@ -41,6 +42,8 @@ bool use; uint32_t interval_msec; } codel; + enum gprs_rlcmac_egprs_arq_type egprs_arq_type; + bool ul_tbf_preemptive_retransmission; } cfg; osmo_gprs_rlcmac_prim_up_cb rlcmac_up_cb; void *rlcmac_up_cb_user_data; diff --git a/include/osmocom/gprs/rlcmac/tbf.h b/include/osmocom/gprs/rlcmac/tbf.h index df5698f..2886c83 100644 --- a/include/osmocom/gprs/rlcmac/tbf.h +++ b/include/osmocom/gprs/rlcmac/tbf.h @@ -2,6 +2,7 @@ #pragma once #include <stdint.h> +#include <stdbool.h> struct gprs_rlcmac_entity; @@ -15,6 +16,9 @@ enum gprs_rlcmac_tbf_direction direction; const char *name; uint8_t nr; /* TBF number, separate address space for DL and UL, used to identify TBF. */ + + /* Whether the TBF is EGPRS or not */ + bool is_egprs; }; void gprs_rlcmac_tbf_constructor(struct gprs_rlcmac_tbf *tbf, diff --git a/include/osmocom/gprs/rlcmac/tbf_ul.h b/include/osmocom/gprs/rlcmac/tbf_ul.h index 8d122ae..efe03b4 100644 --- a/include/osmocom/gprs/rlcmac/tbf_ul.h +++ b/include/osmocom/gprs/rlcmac/tbf_ul.h @@ -8,15 +8,36 @@ #include <osmocom/gprs/rlcmac/tbf.h> #include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> #include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> +#include <osmocom/gprs/rlcmac/coding_scheme.h> #include <osmocom/gprs/rlcmac/sched.h> #include <osmocom/gprs/rlcmac/rlcmac_private.h> +struct gprs_rlcmac_rlc_window; +struct gprs_rlcmac_rlc_ul_window; + struct gprs_rlcmac_ul_tbf { struct gprs_rlcmac_tbf tbf; struct gprs_rlcmac_tbf_ul_fsm_ctx state_fsm; struct gprs_rlcmac_tbf_ul_ass_fsm_ctx ul_ass_fsm; + /* Current TS/TFI/USF allocated by the PCU: */ struct gprs_rlcmac_ul_tbf_allocation cur_alloc; + + /* Currently selected LLC frame to be scheduled/transmitted */ + struct msgb *llc_tx_msg; + int32_t last_ul_drained_fn; + + /* Holds state of all generated in-transit RLC blocks */ + struct gprs_rlcmac_rlc_block_store *blkst; + + /* Uplink RLC Window, holds ACK state */ + union { /* easy access to parent and child */ + struct gprs_rlcmac_rlc_window *w; + struct gprs_rlcmac_rlc_ul_window *ulw; + }; + + /* (M)CS used to transmit uplink blocks, assigned by PCU: */ + enum gprs_rlcmac_coding_scheme tx_cs; }; struct gprs_rlcmac_ul_tbf *gprs_rlcmac_ul_tbf_alloc(struct gprs_rlcmac_entity *gre); @@ -25,7 +46,7 @@ bool gprs_rlcmac_ul_tbf_data_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); bool gprs_rlcmac_ul_tbf_dummy_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); -struct msgb *gprs_rlcmac_ul_tbf_data_create(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); +struct msgb *gprs_rlcmac_ul_tbf_data_create(struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); struct msgb *gprs_rlcmac_ul_tbf_dummy_create(const struct gprs_rlcmac_ul_tbf *ul_tbf); diff --git a/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h b/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h index 7aa4b1e..dc50a66 100644 --- a/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h +++ b/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h @@ -11,6 +11,7 @@ GPRS_RLCMAC_TBF_UL_ST_NEW = 0, /* new created TBF */ GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN, /* wait for Immediate Assignment */ GPRS_RLCMAC_TBF_UL_ST_FLOW, /* RLC/MAC flow, resource needed */ + GPRS_RLCMAC_TBF_UL_ST_FINISHED, /* flow finished, wait for release */ }; struct gprs_rlcmac_tbf_ul_fsm_ctx { @@ -24,6 +25,7 @@ enum tbf_ul_fsm_event { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, + GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT, GPRS_RLCMAC_TBF_UL_EV_FOOBAR, }; diff --git a/src/rlcmac/Makefile.am b/src/rlcmac/Makefile.am index fe221a2..6fca2b0 100644 --- a/src/rlcmac/Makefile.am +++ b/src/rlcmac/Makefile.am @@ -24,12 +24,16 @@ $(NULL) libosmo_gprs_rlcmac_la_SOURCES = \ + codel.c \ + coding_scheme.c \ csn1_ts_24_008.c \ csn1_ts_44_018.c \ csn1_ts_44_060.c \ - codel.c \ gre.c \ llc_queue.c \ + rlc_window.c \ + rlc_window_ul.c \ + rlc.c \ rlcmac.c \ rlcmac_enc.c \ rlcmac_prim.c \ diff --git a/src/rlcmac/coding_scheme.c b/src/rlcmac/coding_scheme.c new file mode 100644 index 0000000..889e0ff --- /dev/null +++ b/src/rlcmac/coding_scheme.c @@ -0,0 +1,418 @@ +/* coding_scheme.c + * + * Copyright (C) 2019-2023 by sysmocom s.f.m.c. GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#include <stdint.h> +#include <stdbool.h> + +#include <osmocom/core/utils.h> + +#include <osmocom/gprs/rlcmac/coding_scheme.h> + +const struct value_string gprs_rlcmac_coding_scheme_names[] = { + { GPRS_RLCMAC_CS_UNKNOWN, "UNKNOWN" }, + { GPRS_RLCMAC_CS_1, "CS-1" }, + { GPRS_RLCMAC_CS_2, "CS-2" }, + { GPRS_RLCMAC_CS_3, "CS-3" }, + { GPRS_RLCMAC_CS_4, "CS-4" }, + { GPRS_RLCMAC_MCS_1, "MCS-1" }, + { GPRS_RLCMAC_MCS_2, "MCS-2" }, + { GPRS_RLCMAC_MCS_3, "MCS-3" }, + { GPRS_RLCMAC_MCS_4, "MCS-4" }, + { GPRS_RLCMAC_MCS_5, "MCS-5" }, + { GPRS_RLCMAC_MCS_6, "MCS-6" }, + { GPRS_RLCMAC_MCS_7, "MCS-7" }, + { GPRS_RLCMAC_MCS_8, "MCS-8" }, + { GPRS_RLCMAC_MCS_9, "MCS-9" }, + { 0, NULL } +}; + +enum gprs_rlcmac_family { + FAMILY_INVALID, + FAMILY_A, + FAMILY_B, + FAMILY_C, +}; + +const static struct { + struct { + uint8_t bytes; + uint8_t ext_bits; + uint8_t data_header_bits; + } uplink, downlink; + uint8_t data_bytes; + uint8_t optional_padding_bits; + enum gprs_rlcmac_header_type data_hdr; + enum gprs_rlcmac_family family; +} mcs_info[GPRS_RLCMAC_NUM_SCHEMES] = { + {{0, 0}, {0, 0}, 0, 0, + GPRS_RLCMAC_HEADER_INVALID, FAMILY_INVALID}, + {{23, 0}, {23, 0}, 20, 0, + GPRS_RLCMAC_HEADER_GPRS_DATA, FAMILY_INVALID}, + {{33, 7}, {33, 7}, 30, 0, + GPRS_RLCMAC_HEADER_GPRS_DATA, FAMILY_INVALID}, + {{39, 3}, {39, 3}, 36, 0, + GPRS_RLCMAC_HEADER_GPRS_DATA, FAMILY_INVALID}, + {{53, 7}, {53, 7}, 50, 0, + GPRS_RLCMAC_HEADER_GPRS_DATA, FAMILY_INVALID}, + + {{26, 1}, {26, 1}, 22, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3, FAMILY_C}, + {{32, 1}, {32, 1}, 28, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3, FAMILY_B}, + {{41, 1}, {41, 1}, 37, 48, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3, FAMILY_A}, + {{48, 1}, {48, 1}, 44, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3, FAMILY_C}, + + {{60, 7}, {59, 6}, 56, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2, FAMILY_B}, + {{78, 7}, {77, 6}, 74, 48, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2, FAMILY_A}, + {{118, 2}, {117, 4}, 56, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1, FAMILY_B}, + {{142, 2}, {141, 4}, 68, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1, FAMILY_A}, + {{154, 2}, {153, 4}, 74, 0, + GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1, FAMILY_A}, +}; + +const char *gprs_rlcmac_mcs_name(enum gprs_rlcmac_coding_scheme val) +{ + return get_value_string(gprs_rlcmac_coding_scheme_names, val); +} + +bool gprs_rlcmac_mcs_is_gprs(enum gprs_rlcmac_coding_scheme cs) +{ + return GPRS_RLCMAC_CS_1 <= cs && cs <= GPRS_RLCMAC_CS_4; +} + +bool gprs_rlcmac_mcs_is_edge(enum gprs_rlcmac_coding_scheme cs) +{ + return GPRS_RLCMAC_MCS_1 <= cs && cs <= GPRS_RLCMAC_MCS_9; +} + +bool gprs_rlcmac_mcs_is_edge_gmsk(enum gprs_rlcmac_coding_scheme cs) +{ + if (gprs_rlcmac_mcs_is_edge(cs)) + return cs <= GPRS_RLCMAC_MCS_4; + + return false; +} + +/* Return 3GPP TS 44.060 §12.10d (EDGE) or Table 11.2.28.2 (GPRS) Channel Coding Command value */ +uint8_t gprs_rlcmac_mcs_chan_code(enum gprs_rlcmac_coding_scheme cs) +{ + if (gprs_rlcmac_mcs_is_gprs(cs)) + return cs - GPRS_RLCMAC_CS_1; + + if (gprs_rlcmac_mcs_is_edge(cs)) + return cs - GPRS_RLCMAC_MCS_1; + + /* Defaults to (M)GPRS_RLCMAC_CS_1 */ + return 0; +} + +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_by_size_ul(unsigned size) +{ + switch (size) { + case 23: return GPRS_RLCMAC_CS_1; + case 27: return GPRS_RLCMAC_MCS_1; + case 33: return GPRS_RLCMAC_MCS_2; + case 34: return GPRS_RLCMAC_CS_2; + case 40: return GPRS_RLCMAC_CS_3; + case 42: return GPRS_RLCMAC_MCS_3; + case 49: return GPRS_RLCMAC_MCS_4; + case 54: return GPRS_RLCMAC_CS_4; + case 61: return GPRS_RLCMAC_MCS_5; + case 79: return GPRS_RLCMAC_MCS_6; + case 119: return GPRS_RLCMAC_MCS_7; + case 143: return GPRS_RLCMAC_MCS_8; + case 155: return GPRS_RLCMAC_MCS_9; + default: return GPRS_RLCMAC_CS_UNKNOWN; + } +} + +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_gprs_by_num(unsigned num) +{ + if (num < 1 || num > 4) + return GPRS_RLCMAC_CS_UNKNOWN; + return GPRS_RLCMAC_CS_1 + (num - 1); +} + +enum gprs_rlcmac_coding_scheme gprs_rlcmac_mcs_get_egprs_by_num(unsigned num) +{ + if (num < 1 || num > 9) + return GPRS_RLCMAC_CS_UNKNOWN; + return GPRS_RLCMAC_MCS_1 + (num - 1); +} + +bool gprs_rlcmac_mcs_is_valid(enum gprs_rlcmac_coding_scheme cs) +{ + return GPRS_RLCMAC_CS_UNKNOWN < cs && cs <= GPRS_RLCMAC_MCS_9; +} + +bool gprs_rlcmac_mcs_is_compat_kind(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme_kind mode) +{ + switch (mode) { + case GPRS_RLCMAC_SCHEME_GPRS: return gprs_rlcmac_mcs_is_gprs(cs); + case GPRS_RLCMAC_SCHEME_EGPRS_GMSK: return gprs_rlcmac_mcs_is_edge_gmsk(cs); + case GPRS_RLCMAC_SCHEME_EGPRS: return gprs_rlcmac_mcs_is_edge(cs); + } + + return false; +} + +bool gprs_rlcmac_mcs_is_compat(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme o) +{ + return (gprs_rlcmac_mcs_is_gprs(cs) && gprs_rlcmac_mcs_is_gprs(o)) || + (gprs_rlcmac_mcs_is_edge(cs) && gprs_rlcmac_mcs_is_edge(o)); +} + +uint8_t gprs_rlcmac_mcs_size_ul(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].uplink.bytes + (gprs_rlcmac_mcs_spare_bits_ul(cs) ? 1 : 0); +} + +uint8_t gprs_rlcmac_mcs_size_dl(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].downlink.bytes + (gprs_rlcmac_mcs_spare_bits_dl(cs) ? 1 : 0); +} + +uint8_t gprs_rlcmac_mcs_used_size_ul(enum gprs_rlcmac_coding_scheme cs) +{ + if (mcs_info[cs].data_hdr == GPRS_RLCMAC_HEADER_GPRS_DATA) + return mcs_info[cs].uplink.bytes; + else + return gprs_rlcmac_mcs_size_ul(cs); +} + +uint8_t gprs_rlcmac_mcs_used_size_dl(enum gprs_rlcmac_coding_scheme cs) +{ + if (mcs_info[cs].data_hdr == GPRS_RLCMAC_HEADER_GPRS_DATA) + return mcs_info[cs].downlink.bytes; + else + return gprs_rlcmac_mcs_size_dl(cs); +} + +uint8_t gprs_rlcmac_mcs_max_bytes_ul(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].uplink.bytes; +} + +uint8_t gprs_rlcmac_mcs_max_bytes_dl(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].downlink.bytes; +} + +uint8_t gprs_rlcmac_mcs_spare_bits_ul(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].uplink.ext_bits; +} + +uint8_t gprs_rlcmac_mcs_spare_bits_dl(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].downlink.ext_bits; +} + +uint8_t gprs_rlcmac_mcs_max_data_block_bytes(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].data_bytes; +} + +uint8_t gprs_rlcmac_mcs_opt_padding_bits(enum gprs_rlcmac_coding_scheme cs) +{ + return mcs_info[cs].optional_padding_bits; +} + +void gprs_rlcmac_mcs_inc_kind(enum gprs_rlcmac_coding_scheme *cs, enum gprs_rlcmac_coding_scheme_kind mode) +{ + if (!gprs_rlcmac_mcs_is_compat_kind(*cs, mode)) + /* This should not happen. TODO: Use assert? */ + return; + + enum gprs_rlcmac_coding_scheme new_cs = *cs + 1; + if (!gprs_rlcmac_mcs_is_compat_kind(new_cs, mode)) + /* Clipping, do not change the value */ + return; + + *cs = new_cs; +} + +void gprs_rlcmac_mcs_dec_kind(enum gprs_rlcmac_coding_scheme *cs, enum gprs_rlcmac_coding_scheme_kind mode) +{ + if (!gprs_rlcmac_mcs_is_compat_kind(*cs, mode)) + /* This should not happen. TODO: Use assert? */ + return; + + enum gprs_rlcmac_coding_scheme new_cs = *cs - 1; + if (!gprs_rlcmac_mcs_is_compat_kind(new_cs, mode)) + /* Clipping, do not change the value */ + return; + + *cs = new_cs; +} + +void gprs_rlcmac_mcs_inc(enum gprs_rlcmac_coding_scheme *cs) +{ + if (gprs_rlcmac_mcs_is_gprs(*cs) && *cs == GPRS_RLCMAC_CS_4) + return; + + if (gprs_rlcmac_mcs_is_edge(*cs) && *cs == GPRS_RLCMAC_MCS_9) + return; + + if (!gprs_rlcmac_mcs_is_valid(*cs)) + return; + + *cs = *cs + 1; +} + +void gprs_rlcmac_mcs_dec(enum gprs_rlcmac_coding_scheme *cs) +{ + if (gprs_rlcmac_mcs_is_gprs(*cs) && *cs == GPRS_RLCMAC_CS_1) + return; + + if (gprs_rlcmac_mcs_is_edge(*cs) && *cs == GPRS_RLCMAC_MCS_1) + return; + + if (!gprs_rlcmac_mcs_is_valid(*cs)) + return; + + *cs = *cs - 1; +} + +bool gprs_rlcmac_mcs_is_family_compat(enum gprs_rlcmac_coding_scheme cs, enum gprs_rlcmac_coding_scheme o) +{ + if (cs == o) + return true; + + if (mcs_info[cs].family == FAMILY_INVALID) + return false; + + return mcs_info[cs].family == mcs_info[o].family; +} + +void gprs_rlcmac_mcs_dec_to_single_block(enum gprs_rlcmac_coding_scheme *cs, bool *need_stuffing) +{ + switch (*cs) { + case GPRS_RLCMAC_MCS_7: + *need_stuffing = false; + *cs = GPRS_RLCMAC_MCS_5; + break; + case GPRS_RLCMAC_MCS_8: + *need_stuffing = true; + *cs = GPRS_RLCMAC_MCS_6; + break; + case GPRS_RLCMAC_MCS_9: + *need_stuffing = false; + *cs = GPRS_RLCMAC_MCS_6; + break; + default: + *need_stuffing = false; + break; + } +} + +static struct { + struct { + uint8_t data_header_bits; + } uplink, downlink; + uint8_t data_block_header_bits; + uint8_t num_blocks; + const char *name; +} hdr_type_info[GPRS_RLCMAC_NUM_HEADER_TYPES] = { + { { 0 }, { 0 }, 0, 0, "INVALID" }, + { { 1 * 8 + 0 }, { 1 * 8 + 0 }, 0, 0, "CONTROL" }, + { { 3 * 8 + 0 }, { 3 * 8 + 0 }, 0, 1, "GPRS_DATA" }, + { { 5 * 8 + 6 }, { 5 * 8 + 0 }, 2, 2, "EGPRS_DATA_TYPE1" }, + { { 4 * 8 + 5 }, { 3 * 8 + 4 }, 2, 1, "EGPRS_DATA_TYPE2" }, + { { 3 * 8 + 7 }, { 3 * 8 + 7 }, 2, 1, "EGPRS_DATA_TYPE3" }, +}; + +enum gprs_rlcmac_header_type gprs_rlcmac_mcs_header_type(enum gprs_rlcmac_coding_scheme mcs) +{ + return mcs_info[mcs].data_hdr; +} + +uint8_t gprs_rlcmac_num_data_blocks(enum gprs_rlcmac_header_type ht) +{ + OSMO_ASSERT(ht < GPRS_RLCMAC_NUM_HEADER_TYPES); + return hdr_type_info[ht].num_blocks; +} + +uint8_t gprs_rlcmac_num_data_header_bits_UL(enum gprs_rlcmac_header_type ht) +{ + OSMO_ASSERT(ht < GPRS_RLCMAC_NUM_HEADER_TYPES); + return hdr_type_info[ht].uplink.data_header_bits; +} + +uint8_t gprs_rlcmac_num_data_header_bits_DL(enum gprs_rlcmac_header_type ht) +{ + OSMO_ASSERT(ht < GPRS_RLCMAC_NUM_HEADER_TYPES); + return hdr_type_info[ht].downlink.data_header_bits; +} + +uint8_t gprs_rlcmac_num_data_block_header_bits(enum gprs_rlcmac_header_type ht) +{ + OSMO_ASSERT(ht < GPRS_RLCMAC_NUM_HEADER_TYPES); + return hdr_type_info[ht].data_block_header_bits; +} + +static const struct value_string gprs_rlcmac_mcs_kind_names[] = { + { GPRS_RLCMAC_SCHEME_GPRS, "GPRS" }, + { GPRS_RLCMAC_SCHEME_EGPRS_GMSK, "EGPRS_GMSK-only"}, + { GPRS_RLCMAC_SCHEME_EGPRS, "EGPRS"}, + { 0, NULL } +}; + +const char *gprs_rlcmac_msc_kind_name(enum gprs_rlcmac_coding_scheme_kind val) +{ + return get_value_string(gprs_rlcmac_mcs_kind_names, val); +} + +/* FIXME: take into account padding and special cases of commanded MCS (MCS-6-9 and MCS-5-7) */ +enum gprs_rlcmac_coding_scheme gprs_rlcmac_get_retx_mcs(enum gprs_rlcmac_coding_scheme initial_mcs, enum gprs_rlcmac_coding_scheme commanded_mcs, bool resegment_bit) +{ + OSMO_ASSERT(gprs_rlcmac_mcs_is_edge(initial_mcs)); + OSMO_ASSERT(gprs_rlcmac_mcs_is_edge(commanded_mcs)); + OSMO_ASSERT(GPRS_RLCMAC_NUM_SCHEMES - GPRS_RLCMAC_MCS_1 == 9); + + if (resegment_bit) { /* 3GPP TS 44.060 Table 8.1.1.1, reflected over antidiagonal */ + enum gprs_rlcmac_coding_scheme egprs_reseg[GPRS_RLCMAC_NUM_SCHEMES - GPRS_RLCMAC_MCS_1][GPRS_RLCMAC_NUM_SCHEMES - GPRS_RLCMAC_MCS_1] = { + { GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1 }, + { GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2 }, + { GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3 }, + { GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4 }, + { GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7 }, + { GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_9 }, + { GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7 }, + { GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_8, GPRS_RLCMAC_MCS_8 }, + { GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_9 }, + }; + return egprs_reseg[gprs_rlcmac_mcs_chan_code(initial_mcs)][gprs_rlcmac_mcs_chan_code(commanded_mcs)]; + } + /* else: 3GPP TS 44.060 Table 8.1.1.2, reflected over antidiagonal */ + enum gprs_rlcmac_coding_scheme egprs_no_reseg[GPRS_RLCMAC_NUM_SCHEMES - GPRS_RLCMAC_MCS_1][GPRS_RLCMAC_NUM_SCHEMES - GPRS_RLCMAC_MCS_1] = { + { GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1, GPRS_RLCMAC_MCS_1 }, + { GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2, GPRS_RLCMAC_MCS_2 }, + { GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3, GPRS_RLCMAC_MCS_3 }, + { GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4, GPRS_RLCMAC_MCS_4 }, + { GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7 }, + { GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_9 }, + { GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_5, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7, GPRS_RLCMAC_MCS_7 }, + { GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_8, GPRS_RLCMAC_MCS_8 }, + { GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_6, GPRS_RLCMAC_MCS_9 }, + }; + return egprs_no_reseg[gprs_rlcmac_mcs_chan_code(initial_mcs)][gprs_rlcmac_mcs_chan_code(commanded_mcs)]; +} diff --git a/src/rlcmac/rlc.c b/src/rlcmac/rlc.c new file mode 100644 index 0000000..305c295 --- /dev/null +++ b/src/rlcmac/rlc.c @@ -0,0 +1,271 @@ +/* RLC block management as per 3GPP TS 44.060 */ +/* + * (C) 2012 Ivan Klyuchnikov + * (C) 2012 Andreas Eversberg <jolly(a)eversberg.eu> + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#include <osmocom/core/utils.h> +#include <osmocom/core/logging.h> + +#include <osmocom/gprs/rlcmac/rlc.h> +#include <osmocom/gprs/rlcmac/rlcmac_private.h> + +void gprs_rlcmac_rlc_block_info_init(struct gprs_rlcmac_rlc_block_info *rdbi, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding, unsigned int spb) +{ + unsigned int data_len = gprs_rlcmac_mcs_max_data_block_bytes(cs); + if (with_padding) + data_len -= gprs_rlcmac_mcs_opt_padding_bits(cs) / 8; + + rdbi->data_len = data_len; + rdbi->bsn = 0; + rdbi->ti = 0; + rdbi->e = 1; + rdbi->cv = 15; + rdbi->pi = 0; + rdbi->spb = spb; +} + +static void gprs_rlcmac_rlc_data_header_init(struct gprs_rlcmac_rlc_data_info *rlc, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding, unsigned int header_bits, + unsigned int spb) +{ + unsigned int i; + unsigned int padding_bits = with_padding ? gprs_rlcmac_mcs_opt_padding_bits(cs) : 0; + + rlc->cs = cs; + rlc->r = 0; + rlc->si = 0; + rlc->tfi = 0; + rlc->cps = 0; + rlc->rsb = 0; + rlc->usf = 0; + rlc->es_p = 0; + rlc->rrbp = 0; + rlc->pr = 0; + rlc->num_data_blocks = gprs_rlcmac_num_data_blocks(gprs_rlcmac_mcs_header_type(cs)); + rlc->with_padding = with_padding; + + OSMO_ASSERT(rlc->num_data_blocks <= ARRAY_SIZE(rlc->block_info)); + + for (i = 0; i < rlc->num_data_blocks; i++) { + gprs_rlcmac_rlc_block_info_init(&rlc->block_info[i], cs, with_padding, spb); + + rlc->data_offs_bits[i] = + header_bits + padding_bits + + (i+1) * gprs_rlcmac_num_data_block_header_bits(gprs_rlcmac_mcs_header_type(cs)) + + i * 8 * rlc->block_info[0].data_len; + } +} + +void gprs_rlcmac_rlc_data_info_init_ul(struct gprs_rlcmac_rlc_data_info *rlc, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding, unsigned int spb) +{ + OSMO_ASSERT(gprs_rlcmac_mcs_is_valid(cs)); + return gprs_rlcmac_rlc_data_header_init( + rlc, cs, with_padding, + gprs_rlcmac_num_data_header_bits_UL(gprs_rlcmac_mcs_header_type(cs)), spb); +} + +void gprs_rlcmac_rlc_data_info_init_dl(struct gprs_rlcmac_rlc_data_info *rlc, + enum gprs_rlcmac_coding_scheme cs, + bool with_padding) +{ + OSMO_ASSERT(gprs_rlcmac_mcs_is_valid(cs)); + /* + * last parameter is sent as 0 since common function used + * for both DL and UL + */ + return gprs_rlcmac_rlc_data_header_init( + rlc, cs, with_padding, + gprs_rlcmac_num_data_header_bits_DL(gprs_rlcmac_mcs_header_type(cs)), 0); +} + +uint8_t *gprs_rlcmac_rlc_block_prepare(struct gprs_rlcmac_rlc_block *blk, size_t block_data_len) +{ + /* todo.. only set it once if it turns out to be a bottleneck */ + memset(blk->buf, 0x0, sizeof(blk->buf)); + memset(blk->buf, 0x2b, block_data_len); + + /* Initial value of puncturing scheme */ + blk->next_ps = GPRS_RLCMAC_EGPRS_PS_1; + + return blk->buf; +} + +struct gprs_rlcmac_rlc_block_store *gprs_rlcmac_rlc_block_store_alloc(void *ctx) +{ + struct gprs_rlcmac_rlc_block_store *blkst; + + blkst = talloc_zero(ctx, struct gprs_rlcmac_rlc_block_store); + if (!blkst) + return NULL; + + return blkst; +} + +void gprs_rlcmac_rlc_block_store_free(struct gprs_rlcmac_rlc_block_store *blkst) +{ + talloc_free(blkst); +} + +struct gprs_rlcmac_rlc_block *gprs_rlcmac_rlc_block_store_get_block(struct gprs_rlcmac_rlc_block_store *blkst, int bsn) +{ + return &blkst->blocks[bsn & mod_sns_half()]; +} + +unsigned int gprs_rlcmac_rlc_mcs_cps(enum gprs_rlcmac_coding_scheme cs, + enum gprs_rlcmac_egprs_puncturing_values punct, + enum gprs_rlcmac_egprs_puncturing_values punct2, + bool with_padding) +{ + /* validate that punct and punct2 are as expected */ + switch (cs) { + case GPRS_RLCMAC_MCS_9: + case GPRS_RLCMAC_MCS_8: + case GPRS_RLCMAC_MCS_7: + if (punct2 == GPRS_RLCMAC_EGPRS_PS_INVALID) { + LOGRLCMAC(LOGL_ERROR, "Invalid punct2 value for coding scheme %d: %d\n", + cs, punct2); + return -1; + } + /* fall through */ + case GPRS_RLCMAC_MCS_6: + case GPRS_RLCMAC_MCS_5: + case GPRS_RLCMAC_MCS_4: + case GPRS_RLCMAC_MCS_3: + case GPRS_RLCMAC_MCS_2: + case GPRS_RLCMAC_MCS_1: + if (punct == GPRS_RLCMAC_EGPRS_PS_INVALID) { + LOGRLCMAC(LOGL_ERROR, "Invalid punct value for coding scheme %d: %d\n", + cs, punct); + return -1; + } + break; + default: + return -1; + } + + /* See 3GPP TS 44.060 10.4.8a.3.1, 10.4.8a.2.1, 10.4.8a.1.1 */ + switch (cs) { + case GPRS_RLCMAC_MCS_1: + return 0b1011 + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2; + case GPRS_RLCMAC_MCS_2: + return 0b1001 + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2; + case GPRS_RLCMAC_MCS_3: + return (with_padding ? 0b0110 : 0b0011) + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3; + case GPRS_RLCMAC_MCS_4: + return 0b0000 + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3; + case GPRS_RLCMAC_MCS_5: + return 0b100 + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2; + case GPRS_RLCMAC_MCS_6: + return (with_padding ? 0b010 : 0b000) + + punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2; + case GPRS_RLCMAC_MCS_7: + return 0b10100 + + 3 * (punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3) + + punct2 % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3; + case GPRS_RLCMAC_MCS_8: + return 0b01011 + + 3 * (punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3) + + punct2 % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3; + case GPRS_RLCMAC_MCS_9: + return 0b00000 + + 4 * (punct % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3) + + punct2 % GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3; + default: + break; + } + + return -1; +} + +enum gprs_rlcmac_egprs_puncturing_values +gprs_rlcmac_get_punct_scheme(enum gprs_rlcmac_egprs_puncturing_values punct, + enum gprs_rlcmac_coding_scheme cs, + enum gprs_rlcmac_coding_scheme cs_current, + enum gprs_rlcmac_rlc_egprs_ul_spb spb) +{ + + /* + * 10.4.8b of TS 44.060 + * If it is second segment of the block + * dont change the puncturing scheme + */ + if (spb == GPRS_RLCMAC_EGPRS_UL_SPB_SEC_SEG) + return punct; + + /* TS 44.060 9.3.2.1.1 */ + if ((cs == GPRS_RLCMAC_MCS_9) && + (cs_current == GPRS_RLCMAC_MCS_6)) { + if ((punct == GPRS_RLCMAC_EGPRS_PS_1) || (punct == GPRS_RLCMAC_EGPRS_PS_3)) + return GPRS_RLCMAC_EGPRS_PS_1; + else if (punct == GPRS_RLCMAC_EGPRS_PS_2) + return GPRS_RLCMAC_EGPRS_PS_2; + } else if ((cs == GPRS_RLCMAC_MCS_6) && + (cs_current == GPRS_RLCMAC_MCS_9)) { + if (punct == GPRS_RLCMAC_EGPRS_PS_1) + return GPRS_RLCMAC_EGPRS_PS_3; + else if (punct == GPRS_RLCMAC_EGPRS_PS_2) + return GPRS_RLCMAC_EGPRS_PS_2; + } else if ((cs == GPRS_RLCMAC_MCS_7) && + (cs_current == GPRS_RLCMAC_MCS_5)) + return GPRS_RLCMAC_EGPRS_PS_1; + else if ((cs == GPRS_RLCMAC_MCS_5) && + (cs_current == GPRS_RLCMAC_MCS_7)) + return GPRS_RLCMAC_EGPRS_PS_2; + else if (cs != cs_current) + return GPRS_RLCMAC_EGPRS_PS_1; + /* TS 44.060 9.3.2.1.1 ends here */ + /* + * Below else will handle fresh transmission, retransmission with no + * MCS change case + */ + else + return punct; + return GPRS_RLCMAC_EGPRS_PS_INVALID; +} + +void gprs_rlcmac_update_punct_scheme(enum gprs_rlcmac_egprs_puncturing_values *punct, enum gprs_rlcmac_coding_scheme cs) +{ + switch (cs) { + case GPRS_RLCMAC_MCS_1: + case GPRS_RLCMAC_MCS_2: + case GPRS_RLCMAC_MCS_5: + case GPRS_RLCMAC_MCS_6: + *punct = ((enum gprs_rlcmac_egprs_puncturing_values)((*punct + 1) % + GPRS_RLCMAC_EGPRS_MAX_PS_NUM_2)); + break; + case GPRS_RLCMAC_MCS_3: + case GPRS_RLCMAC_MCS_4: + case GPRS_RLCMAC_MCS_7: + case GPRS_RLCMAC_MCS_8: + case GPRS_RLCMAC_MCS_9: + *punct = ((enum gprs_rlcmac_egprs_puncturing_values)((*punct + 1) % + GPRS_RLCMAC_EGPRS_MAX_PS_NUM_3)); + break; + default: + break; + } +} diff --git a/src/rlcmac/rlc_window.c b/src/rlcmac/rlc_window.c new file mode 100644 index 0000000..d17307b --- /dev/null +++ b/src/rlcmac/rlc_window.c @@ -0,0 +1,76 @@ +/* RLC Window as per 3GPP TS 44.060 */ +/* + * (C) 2012 Ivan Klyuchnikov + * (C) 2012 Andreas Eversberg <jolly(a)eversberg.eu> + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#include <osmocom/core/utils.h> + +#include <osmocom/gprs/rlcmac/rlc.h> +#include <osmocom/gprs/rlcmac/rlc_window.h> + +#define RLC_GPRS_WS 64 /* max window size */ +#define RLC_EGPRS_MIN_WS 64 /* min window size */ +#define RLC_EGPRS_MAX_WS 1024 /* min window size */ +#define RLC_EGPRS_MAX_BSN_DELTA 512 +#define RLC_MAX_WS RLC_EGPRS_MAX_WS + +void gprs_rlcmac_rlc_window_constructor(struct gprs_rlcmac_rlc_window *w) +{ + w->sns = RLC_GPRS_SNS; + w->ws = RLC_GPRS_WS; +} + +void gprs_rlcmac_rlc_window_destructor(struct gprs_rlcmac_rlc_window *w) +{ + /* Nothing to be done here yet */ +} + +uint16_t gprs_rlcmac_rlc_window_mod_sns(const struct gprs_rlcmac_rlc_window *w) +{ + return gprs_rlcmac_rlc_window_sns(w) - 1; +} + +uint16_t gprs_rlcmac_rlc_window_mod_sns_bsn(const struct gprs_rlcmac_rlc_window *w, uint16_t bsn) +{ + return bsn & gprs_rlcmac_rlc_window_mod_sns(w); +} + +uint16_t gprs_rlcmac_rlc_window_sns(const struct gprs_rlcmac_rlc_window *w) +{ + return w->sns; +} + +uint16_t gprs_rlcmac_rlc_window_ws(const struct gprs_rlcmac_rlc_window *w) +{ + return w->ws; +} + +void gprs_rlcmac_rlc_window_set_sns(struct gprs_rlcmac_rlc_window *w, uint16_t sns) +{ + OSMO_ASSERT(sns >= RLC_GPRS_SNS); + OSMO_ASSERT(sns <= RLC_MAX_SNS); + /* check for 2^n */ + OSMO_ASSERT((sns & (-sns)) == sns); + w->sns = sns; +} + +void gprs_rlcmac_rlc_window_set_ws(struct gprs_rlcmac_rlc_window *w, uint16_t ws) +{ + OSMO_ASSERT(ws >= RLC_GPRS_SNS/2); + OSMO_ASSERT(ws <= RLC_MAX_SNS/2); + w->ws = ws; +} diff --git a/src/rlcmac/rlc_window_ul.c b/src/rlcmac/rlc_window_ul.c new file mode 100644 index 0000000..af1c32b --- /dev/null +++ b/src/rlcmac/rlc_window_ul.c @@ -0,0 +1,355 @@ +/* Uplink RLC Window as per 3GPP TS 44.060 */ +/* + * (C) 2012 Ivan Klyuchnikov + * (C) 2012 Andreas Eversberg <jolly(a)eversberg.eu> + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#include <stdint.h> +#include <stdbool.h> +#include <osmocom/core/bitvec.h> + +#include <osmocom/gprs/rlcmac/rlc.h> +#include <osmocom/gprs/rlcmac/rlc_window_ul.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> + +static inline bool gprs_rlcmac_rlc_v_b_is_state(const struct gprs_rlcmac_rlc_v_b *v_b, + int bsn, enum gprs_rlcmac_rlc_ul_bsn_state type) +{ + return v_b->v_b[bsn & mod_sns_half()] == type; +} + +static inline void gprs_rlcmac_rlc_v_b_mark(struct gprs_rlcmac_rlc_v_b *v_b, + int bsn, enum gprs_rlcmac_rlc_ul_bsn_state type) +{ + v_b->v_b[bsn & mod_sns_half()] = type; +} + +void gprs_rlcmac_rlc_v_b_reset(struct gprs_rlcmac_rlc_v_b *v_b) +{ + unsigned int i; + for (i = 0; i < ARRAY_SIZE(v_b->v_b); i++) + gprs_rlcmac_rlc_v_b_mark_invalid(v_b, i); +} + +/* Check for an individual frame */ +bool gprs_rlcmac_rlc_v_b_is_unacked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_is_state(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_UNACKED); +} + +bool gprs_rlcmac_rlc_v_b_is_nacked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_is_state(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_NACKED); +} + +bool gprs_rlcmac_rlc_v_b_is_acked(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_is_state(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_ACKED); +} + +bool gprs_rlcmac_rlc_v_b_is_resend(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_is_state(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_RESEND); +} + +bool gprs_rlcmac_rlc_v_b_is_invalid(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_is_state(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_INVALID); +} + +enum gprs_rlcmac_rlc_ul_bsn_state gprs_rlcmac_rlc_v_b_get_state(const struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return v_b->v_b[bsn & mod_sns_half()]; +} + +/* Mark a RLC frame for something */ +void gprs_rlcmac_rlc_v_b_mark_unacked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_mark(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_UNACKED); +} + +void gprs_rlcmac_rlc_v_b_mark_nacked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_mark(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_NACKED); +} + +void gprs_rlcmac_rlc_v_b_mark_acked(struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_mark(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_ACKED); +} + +void gprs_rlcmac_rlc_v_b_mark_resend(struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_mark(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_RESEND); +} + +void gprs_rlcmac_rlc_v_b_mark_invalid(struct gprs_rlcmac_rlc_v_b *v_b, int bsn) +{ + return gprs_rlcmac_rlc_v_b_mark(v_b, bsn, GPRS_RLCMAC_RLC_UL_BSN_INVALID); +} + + +/************* + * UL WINDOW +*************/ +struct gprs_rlcmac_rlc_ul_window *gprs_rlcmac_rlc_ul_window_alloc(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct gprs_rlcmac_rlc_ul_window *ulw; + + ulw = talloc_zero(ul_tbf, struct gprs_rlcmac_rlc_ul_window); + if (!ulw) + return NULL; + + gprs_rlcmac_rlc_window_constructor(rlc_ulw_as_w(ulw)); + + ulw->ul_tbf = ul_tbf; + gprs_rlcmac_rlc_ul_window_reset(ulw); + + return ulw; +} + +void gprs_rlcmac_rlc_ul_window_free(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + if (!ulw) + return; + + gprs_rlcmac_rlc_window_destructor(rlc_ulw_as_w(ulw)); + talloc_free(ulw); +} + +void gprs_rlcmac_rlc_ul_window_reset(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + ulw->v_s = 0; + ulw->v_a = 0; + gprs_rlcmac_rlc_v_b_reset(&ulw->v_b); +} + +bool gprs_rlcmac_rlc_ul_window_window_stalled(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + + return (gprs_rlcmac_rlc_window_mod_sns_bsn(w, ulw->v_s - ulw->v_a) == + gprs_rlcmac_rlc_window_ws(w)); +} + +bool gprs_rlcmac_rlc_ul_window_window_empty(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + return ulw->v_s == ulw->v_a; +} + +void gprs_rlcmac_rlc_ul_window_increment_send(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + + ulw->v_s = (ulw->v_s + 1) & gprs_rlcmac_rlc_window_mod_sns(w); +} + +void gprs_rlcmac_rlc_ul_window_raise(struct gprs_rlcmac_rlc_ul_window *ulw, int moves) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + + ulw->v_a = (ulw->v_a + moves) & gprs_rlcmac_rlc_window_mod_sns(w); +} + +uint16_t gprs_rlcmac_rlc_ul_window_v_s(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + return ulw->v_s; +} + +uint16_t gprs_rlcmac_rlc_ul_window_v_s_mod(const struct gprs_rlcmac_rlc_ul_window *ulw, int offset) +{ + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + + return gprs_rlcmac_rlc_window_mod_sns_bsn(w, ulw->v_s + offset); +} + +uint16_t gprs_rlcmac_rlc_ul_window_v_a(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + return ulw->v_a; +} + +uint16_t gprs_rlcmac_rlc_ul_window_distance(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + + return (ulw->v_s - ulw->v_a) & gprs_rlcmac_rlc_window_mod_sns(w); +} + +/* Methods to manage reception */ +int gprs_rlcmac_rlc_ul_window_resend_needed(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + uint16_t bsn; + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + + for (bsn = gprs_rlcmac_rlc_ul_window_v_a(ulw); + bsn != gprs_rlcmac_rlc_ul_window_v_s(ulw); + bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bsn + 1)) { + if (gprs_rlcmac_rlc_v_b_is_nacked(&ulw->v_b, bsn) || + gprs_rlcmac_rlc_v_b_is_resend(&ulw->v_b, bsn)) + return bsn; + } + + return -1; +} + +unsigned int gprs_rlcmac_rlc_ul_window_mark_for_resend(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + unsigned int resend = 0; + uint16_t bsn; + + for (bsn = gprs_rlcmac_rlc_ul_window_v_a(ulw); + bsn != gprs_rlcmac_rlc_ul_window_v_s(ulw); + bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bsn + 1)) { + if (gprs_rlcmac_rlc_v_b_is_unacked(&ulw->v_b, bsn)) { + /* mark to be re-send */ + gprs_rlcmac_rlc_v_b_mark_resend(&ulw->v_b, bsn); + resend += 1; + } + } + + return resend; +} + +static inline uint16_t bitnum_to_bsn(int bitnum, uint16_t ssn) +{ + return (ssn - 1 - bitnum); +} + +void gprs_rlcmac_rlc_ul_window_update_ssn(struct gprs_rlcmac_rlc_ul_window *ulw, char *show_rbb, + uint16_t ssn, uint16_t *lost, uint16_t *received) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + unsigned int bitpos; + + /* SSN - 1 is in range V(A)..V(S)-1 */ + for (bitpos = 0; bitpos < gprs_rlcmac_rlc_window_ws(w); bitpos++) { + uint16_t bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bitnum_to_bsn(bitpos, ssn)); + + if (bsn == gprs_rlcmac_rlc_window_mod_sns_bsn(w, gprs_rlcmac_rlc_ul_window_v_a(ulw) - 1)) + break; + + if (show_rbb[gprs_rlcmac_rlc_window_ws(w) - 1 - bitpos] == 'R') { + LOGRLCMAC(LOGL_DEBUG, "- got ack for BSN=%u\n", bsn); + if (!gprs_rlcmac_rlc_v_b_is_acked(&ulw->v_b, bsn)) + *received += 1; + gprs_rlcmac_rlc_v_b_mark_acked(&ulw->v_b, bsn); + } else { + LOGRLCMAC(LOGL_DEBUG, "- got NACK for BSN=%u\n", bsn); + gprs_rlcmac_rlc_v_b_mark_nacked(&ulw->v_b, bsn); + *lost += 1; + } + } +} + +void gprs_rlcmac_rlc_ul_window_update(struct gprs_rlcmac_rlc_ul_window *ulw, const struct bitvec *rbb, + uint16_t first_bsn, uint16_t *lost, uint16_t *received) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + unsigned int dist = gprs_rlcmac_rlc_ul_window_distance(ulw); + unsigned int num_blocks = rbb->cur_bit > dist + ? dist : rbb->cur_bit; + unsigned int bsn; + unsigned int bitpos; + + /* first_bsn is in range V(A)..V(S) */ + + for (bitpos = 0; bitpos < num_blocks; bitpos++) { + bool is_ack; + bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, first_bsn + bitpos); + if (bsn == gprs_rlcmac_rlc_window_mod_sns_bsn(w, gprs_rlcmac_rlc_ul_window_v_a(ulw) - 1)) + break; + + is_ack = bitvec_get_bit_pos(rbb, bitpos) == 1; + + if (is_ack) { + LOGRLCMAC(LOGL_DEBUG, "- got ack for BSN=%u\n", bsn); + if (!gprs_rlcmac_rlc_v_b_is_acked(&ulw->v_b, bsn)) + *received += 1; + gprs_rlcmac_rlc_v_b_mark_acked(&ulw->v_b, bsn); + } else { + LOGRLCMAC(LOGL_DEBUG, "- got NACK for BSN=%u\n", bsn); + gprs_rlcmac_rlc_v_b_mark_nacked(&ulw->v_b, bsn); + *lost += 1; + } + } +} + +unsigned int gprs_rlcmac_rlc_ul_window_move_window(struct gprs_rlcmac_rlc_ul_window *ulw) +{ + struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w(ulw); + unsigned int i; + uint16_t bsn; + unsigned int moved = 0; + + for (i = 0, bsn = gprs_rlcmac_rlc_ul_window_v_a(ulw); + bsn != gprs_rlcmac_rlc_ul_window_v_s(ulw); + i++, bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bsn + 1)) { + if (gprs_rlcmac_rlc_v_b_is_acked(&ulw->v_b, bsn)) { + gprs_rlcmac_rlc_v_b_mark_invalid(&ulw->v_b, bsn); + moved += 1; + } else + break; + } + + return moved; +} + +void gprs_rlcmac_rlc_ul_window_show_state(const struct gprs_rlcmac_rlc_ul_window *ulw, char *show_v_b) +{ + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + unsigned int i; + uint16_t bsn; + + for (i = 0, bsn = gprs_rlcmac_rlc_ul_window_v_a(ulw); + bsn != gprs_rlcmac_rlc_ul_window_v_s(ulw); + i++, bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bsn + 1)) { + uint16_t index = bsn & mod_sns_half(); + switch (gprs_rlcmac_rlc_v_b_get_state(&ulw->v_b, index)) { + case GPRS_RLCMAC_RLC_UL_BSN_INVALID: + show_v_b[i] = 'I'; + break; + case GPRS_RLCMAC_RLC_UL_BSN_ACKED: + show_v_b[i] = 'A'; + break; + case GPRS_RLCMAC_RLC_UL_BSN_RESEND: + show_v_b[i] = 'X'; + break; + case GPRS_RLCMAC_RLC_UL_BSN_NACKED: + show_v_b[i] = 'N'; + break; + default: + show_v_b[i] = '?'; + } + } + show_v_b[i] = '\0'; +} + +unsigned int gprs_rlcmac_rlc_ul_window_count_unacked(const struct gprs_rlcmac_rlc_ul_window *ulw) +{ + const struct gprs_rlcmac_rlc_window *w = rlc_ulw_as_w_const(ulw); + unsigned int unacked = 0; + uint16_t bsn; + + for (bsn = gprs_rlcmac_rlc_ul_window_v_a(ulw); + bsn != gprs_rlcmac_rlc_ul_window_v_s(ulw); + bsn = gprs_rlcmac_rlc_window_mod_sns_bsn(w, bsn + 1)) { + if (!gprs_rlcmac_rlc_v_b_is_acked(&ulw->v_b, bsn)) + unacked += 1; + } + + return unacked; +} diff --git a/src/rlcmac/rlcmac.c b/src/rlcmac/rlcmac.c index f8e3939..3310950 100644 --- a/src/rlcmac/rlcmac.c +++ b/src/rlcmac/rlcmac.c @@ -65,6 +65,8 @@ g_ctx->cfg.location = location; g_ctx->cfg.codel.use = true; g_ctx->cfg.codel.interval_msec = GPRS_CODEL_SLOW_INTERVAL_MS; + g_ctx->cfg.egprs_arq_type = GPRS_RLCMAC_EGPRS_ARQ1; + g_ctx->cfg.ul_tbf_preemptive_retransmission = true; g_ctx->T_defs = T_defs_rlcmac; INIT_LLIST_HEAD(&g_ctx->gre_list); diff --git a/src/rlcmac/rlcmac_enc.c b/src/rlcmac/rlcmac_enc.c index ef22f05..723fdc9 100644 --- a/src/rlcmac/rlcmac_enc.c +++ b/src/rlcmac/rlcmac_enc.c @@ -18,11 +18,270 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + +#include <osmocom/core/endian.h> + #include <osmocom/gprs/rlcmac/csn1_defs.h> #include <osmocom/gprs/rlcmac/rlcmac_enc.h> #include <osmocom/gprs/rlcmac/gre.h> #include <osmocom/gprs/rlcmac/tbf_ul.h> +int gprs_rlcmac_rlc_write_ul_data_header(const struct gprs_rlcmac_rlc_data_info *rlc, uint8_t *data) +{ + struct gprs_rlcmac_rlc_ul_data_header *gprs; + + switch (gprs_rlcmac_mcs_header_type(rlc->cs)) { + case GPRS_RLCMAC_HEADER_GPRS_DATA: + gprs = (struct gprs_rlcmac_rlc_ul_data_header *)data; + + gprs->r = rlc->r; + gprs->si = rlc->si; + gprs->cv = rlc->block_info[0].cv; + gprs->pt = 0; + + gprs->ti = 0; /* TODO */ + gprs->tfi = rlc->tfi; + gprs->pi = 0; /* TODO */ + gprs->spare = 0; + + gprs->e = rlc->block_info[0].e; + gprs->bsn = rlc->block_info[0].bsn; + break; + + case GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1: + case GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2: + case GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3: + /* TODO: EGPRS. See osmo-pcu.git Encoding::rlc_write_dl_data_header() */ + default: + LOGRLCMAC(LOGL_ERROR, "Encoding of uplink %s data blocks not yet supported.\n", + gprs_rlcmac_mcs_name(rlc->cs)); + return -ENOTSUP; + }; + + return 0; +} + +enum gpr_rlcmac_append_result gprs_rlcmac_enc_append_ul_data( + struct gprs_rlcmac_rlc_block_info *rdbi, + enum gprs_rlcmac_coding_scheme cs, + struct msgb *llc_msg, int *offset, int *num_chunks, + uint8_t *data_block, bool is_final, int *count_payload) +{ + int chunk; + int space; + struct gprs_rlcmac_rlc_li_field *li; + uint8_t *delimiter, *data, *e_pointer; + + data = data_block + *offset; + delimiter = data_block + *num_chunks; + e_pointer = (*num_chunks ? delimiter - 1 : NULL); + + chunk = msgb_length(llc_msg); + space = rdbi->data_len - *offset; + + /* if chunk will exceed block limit */ + if (chunk > space) { + LOGRLCMAC(LOGL_DEBUG, "-- Chunk with length %d " + "larger than space (%d) left in block: copy " + "only remaining space, and we are done\n", + chunk, space); + if (e_pointer) { + /* LLC frame not finished, so there is no extension octet */ + *e_pointer |= 0x02; /* set previous M bit = 1 */ + } + /* fill only space */ + memcpy(data, msgb_data(llc_msg), space); + msgb_pull(llc_msg, space); + if (count_payload) + *count_payload = space; + /* return data block as message */ + *offset = rdbi->data_len; + (*num_chunks)++; + return GPRS_RLCMAC_AR_NEED_MORE_BLOCKS; + } + /* if FINAL chunk would fit precisely in space left */ + if (chunk == space && is_final) { + LOGRLCMAC(LOGL_DEBUG, "-- Chunk with length %d " + "would exactly fit into space (%d): because " + "this is a final block, we don't add length " + "header, and we are done\n", chunk, space); + /* block is filled, so there is no extension */ + if (e_pointer) + *e_pointer |= 0x01; + /* fill space */ + memcpy(data, msgb_data(llc_msg), space); + msgb_pull(llc_msg, space); + if (count_payload) + *count_payload = space; + *offset = rdbi->data_len; + (*num_chunks)++; + rdbi->cv = 0; + return GPRS_RLCMAC_AR_COMPLETED_BLOCK_FILLED; + } + /* if chunk would fit exactly in space left */ + if (chunk == space) { + LOGRLCMAC(LOGL_DEBUG, "-- Chunk with length %d " + "would exactly fit into space (%d): add length " + "header with LI=0, to make frame extend to " + "next block, and we are done\n", chunk, space); + /* make space for delimiter */ + if (delimiter != data) + memmove(delimiter + 1, delimiter, + data - delimiter); + if (e_pointer) { + *e_pointer &= 0xfe; /* set previous E bit = 0 */ + *e_pointer |= 0x02; /* set previous M bit = 1 */ + } + data++; + (*offset)++; + space--; + /* add LI with 0 length */ + li = (struct gprs_rlcmac_rlc_li_field *)delimiter; + li->e = 1; /* not more extension */ + li->m = 0; /* shall be set to 0, in case of li = 0 */ + li->li = 0; /* chunk fills the complete space */ + rdbi->e = 0; /* 0: extensions present */ + // no need to set e_pointer nor increase delimiter + /* fill only space, which is 1 octet less than chunk */ + memcpy(data, msgb_data(llc_msg), space); + msgb_pull(llc_msg, space); + if (count_payload) + *count_payload = space; + /* return data block as message */ + *offset = rdbi->data_len; + (*num_chunks)++; + return GPRS_RLCMAC_AR_NEED_MORE_BLOCKS; + } + + LOGRLCMAC(LOGL_DEBUG, "-- Chunk with length %d is less " + "than remaining space (%d): add length header to " + "delimit LLC frame\n", chunk, space); + /* the LLC frame chunk ends in this block */ + /* make space for delimiter */ + if (delimiter != data) + memmove(delimiter + 1, delimiter, data - delimiter); + if (e_pointer) { + *e_pointer &= 0xfe; /* set previous E bit = 0 */ + *e_pointer |= 0x02; /* set previous M bit = 1 */ + } + data++; + (*offset)++; + space--; + /* add LI to delimit frame */ + li = (struct gprs_rlcmac_rlc_li_field *)delimiter; + li->e = 1; /* not more extension, maybe set later */ + li->m = 0; /* will be set later, if there is more LLC data */ + li->li = chunk; /* length of chunk */ + rdbi->e = 0; /* 0: extensions present */ + (*num_chunks)++; + /* copy (rest of) LLC frame to space and reset later */ + memcpy(data, msgb_data(llc_msg), chunk); + msgb_pull(llc_msg, chunk); + if (count_payload) + *count_payload = chunk; + data += chunk; + space -= chunk; + (*offset) += chunk; + /* if we have more data and we have space left */ + if (space > 0 && !is_final) + return GPRS_RLCMAC_AR_COMPLETED_SPACE_LEFT; + + /* if we don't have more LLC frames */ + if (is_final) { + LOGRLCMAC(LOGL_DEBUG, "-- Final block, so we done.\n"); + rdbi->cv = 0; + return GPRS_RLCMAC_AR_COMPLETED_BLOCK_FILLED; + } + /* we have no space left */ + LOGRLCMAC(LOGL_DEBUG, "-- No space left, so we are done.\n"); + return GPRS_RLCMAC_AR_COMPLETED_BLOCK_FILLED; +} + +void gprs_rlcmac_rlc_data_to_ul_append_egprs_li_padding(const struct gprs_rlcmac_rlc_block_info *rdbi, + int *offset, int *num_chunks, uint8_t *data_block) +{ + struct gprs_rlcmacrlc_li_field_egprs *li; + struct gprs_rlcmacrlc_li_field_egprs *prev_li; + uint8_t *delimiter, *data; + + LOGRLCMAC(LOGL_DEBUG, "Adding LI=127 to signal padding\n"); + + data = data_block + *offset; + delimiter = data_block + *num_chunks; + prev_li = (struct gprs_rlcmacrlc_li_field_egprs *)(*num_chunks ? delimiter - 1 : NULL); + + /* we don't have more LLC frames */ + /* We will have to add another chunk with filling octets */ + + if (delimiter != data) + memmove(delimiter + 1, delimiter, data - delimiter); + + /* set filling bytes extension */ + li = (struct gprs_rlcmacrlc_li_field_egprs *)delimiter; + li->e = 1; + li->li = 127; + + /* tell previous extension header about the new one */ + if (prev_li) + prev_li->e = 0; + + (*num_chunks)++; + *offset = rdbi->data_len; +} + +/** + * Copy LSB bitstream RLC data block from byte aligned buffer. + * + * Note that the bitstream is encoded in LSB first order, so the two octets + * 654321xx xxxxxx87 contain the octet 87654321 starting at bit position 3 + * (LSB has bit position 1). This is a different order than the one used by + * CSN.1. + * + * \param data_block_idx The block index, 0..1 for header type 1, 0 otherwise + * \param src A pointer to the start of the RLC block (incl. the header) + * \param buffer A data area of a least the size of the RLC block + * \returns the number of bytes copied + */ +unsigned int gprs_rlcmac_rlc_copy_from_aligned_buffer(const struct gprs_rlcmac_rlc_data_info *rlc, + unsigned int data_block_idx, + uint8_t *dst, const uint8_t *buffer) +{ + unsigned int hdr_bytes; + unsigned int extra_bits; + unsigned int i; + + uint8_t c, last_c; + const uint8_t *src; + const struct gprs_rlcmac_rlc_block_info *rdbi; + + OSMO_ASSERT(data_block_idx < rlc->num_data_blocks); + rdbi = &rlc->block_info[data_block_idx]; + + hdr_bytes = rlc->data_offs_bits[data_block_idx] / 8; + extra_bits = (rlc->data_offs_bits[data_block_idx] % 8); + + if (extra_bits == 0) { + /* It is aligned already */ + memmove(dst + hdr_bytes, buffer, rdbi->data_len); + return rdbi->data_len; + } + + src = buffer; + dst = dst + hdr_bytes; + last_c = *dst << (8 - extra_bits); + + for (i = 0; i < rdbi->data_len; i++) { + c = src[i]; + *(dst++) = (last_c >> (8 - extra_bits)) | (c << extra_bits); + last_c = c; + } + + /* overwrite the lower extra_bits */ + *dst = (*dst & (0xff << extra_bits)) | (last_c >> (8 - extra_bits)); + + return rdbi->data_len; +} + void gprs_rlcmac_enc_prepare_pkt_ul_dummy_block(RlcMacUplink_t *block, uint32_t tlli) { Packet_Uplink_Dummy_Control_Block_t *dummy; diff --git a/src/rlcmac/sched.c b/src/rlcmac/sched.c index 93dc50f..ea133c5 100644 --- a/src/rlcmac/sched.c +++ b/src/rlcmac/sched.c @@ -115,6 +115,8 @@ { struct msgb *msg = NULL; struct tbf_sched_ctrl_candidates tbf_cand = {0}; + struct osmo_gprs_rlcmac_prim *rlcmac_prim_tx; + int rc; get_ctrl_msg_tbf_candidates(bi, &tbf_cand); @@ -130,7 +132,11 @@ /* Nothing to transmit */ return 0; + tx_msg: - /* TODO: transmit msg to lower layer (L1CTL?) */ - return 0; + rlcmac_prim_tx = gprs_rlcmac_prim_alloc_l1ctl_pdch_data_req(bi->ts, bi->fn, msgb_data(msg), 0); + rlcmac_prim_tx->l1ctl.pdch_data_req.data_len = msgb_length(msg); + rc = gprs_rlcmac_prim_call_down_cb(rlcmac_prim_tx); + msgb_free(msg); + return rc; } diff --git a/src/rlcmac/tbf_ul.c b/src/rlcmac/tbf_ul.c index 54ecd34..906efbe 100644 --- a/src/rlcmac/tbf_ul.c +++ b/src/rlcmac/tbf_ul.c @@ -24,6 +24,9 @@ #include <osmocom/gprs/rlcmac/tbf_ul.h> #include <osmocom/gprs/rlcmac/rlcmac_enc.h> #include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/coding_scheme.h> +#include <osmocom/gprs/rlcmac/rlc_window_ul.h> +#include <osmocom/gprs/rlcmac/rlc.h> struct gprs_rlcmac_ul_tbf *gprs_rlcmac_ul_tbf_alloc(struct gprs_rlcmac_entity *gre) { @@ -45,6 +48,13 @@ goto err_state_fsm_destruct; ul_tbf->tbf.nr = g_ctx->next_ul_tbf_nr++; + ul_tbf->tx_cs = GPRS_RLCMAC_CS_1; + + ul_tbf->ulw = gprs_rlcmac_rlc_ul_window_alloc(ul_tbf); + OSMO_ASSERT(ul_tbf->ulw); + + ul_tbf->blkst = gprs_rlcmac_rlc_block_store_alloc(ul_tbf); + OSMO_ASSERT(ul_tbf->blkst); return ul_tbf; @@ -61,6 +71,14 @@ if (!ul_tbf) return; + talloc_free(ul_tbf->llc_tx_msg); + + gprs_rlcmac_rlc_block_store_free(ul_tbf->blkst); + ul_tbf->blkst = NULL; + + gprs_rlcmac_rlc_ul_window_free(ul_tbf->ulw); + ul_tbf->ulw = NULL; + gprs_rlcmac_tbf_ul_ass_fsm_destructor(ul_tbf); gprs_rlcmac_tbf_ul_fsm_destructor(ul_tbf); @@ -126,9 +144,566 @@ return NULL; } -struct msgb *gprs_rlcmac_ul_tbf_data_create(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +bool gprs_rlcmac_ul_tbf_have_data(const struct gprs_rlcmac_ul_tbf *ul_tbf) { - LOGPTBFUL(ul_tbf, LOGL_ERROR, "(ts=%u,fn=%u,usf=%u) TODO: implement dequeue from LLC\n", - bi->ts, bi->fn, bi->usf); - return NULL; + return (ul_tbf->llc_tx_msg && msgb_length(ul_tbf->llc_tx_msg) > 0) || + (gprs_rlcmac_llc_queue_size(ul_tbf->tbf.gre->llc_queue) > 0); +} + +bool gprs_rlcmac_ul_tbf_shall_keep_open(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + /* TODO: In here a VTY timer can be defined which specifies an amount of + * time during which the MS stays in CV=15 while waiting for more data from + * upper layers. This way we avoid entering last CV modes and keep the TBF + * open (sending Uplink Dummy Ctrl Block if necessary). + * Amount of time elapsed in this condition can be valculated based on + * bi->fn - ul_tbf->last_ul_drained_fn; + */ + return false; +} + +void gprs_rlcmac_ul_tbf_schedule_next_llc_frame(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + if (ul_tbf->llc_tx_msg && msgb_length(ul_tbf->llc_tx_msg)) + return; + + msgb_free(ul_tbf->llc_tx_msg); + /* dequeue next LLC frame, if any */ + ul_tbf->llc_tx_msg = gprs_rlcmac_llc_queue_dequeue(ul_tbf->tbf.gre->llc_queue); + if (!ul_tbf->llc_tx_msg) + return; + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Dequeue next LLC (len=%d)\n", msgb_length(ul_tbf->llc_tx_msg)); + + ul_tbf->last_ul_drained_fn = -1; +} + +static int create_new_bsn(struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi, enum gprs_rlcmac_coding_scheme cs) +{ + struct gprs_rlcmac_llc_queue *llc_queue = ul_tbf->tbf.gre->llc_queue; + const uint16_t bsn = gprs_rlcmac_rlc_ul_window_v_s(ul_tbf->ulw); + struct gprs_rlcmac_rlc_block *blk; + struct gprs_rlcmac_rlc_block_info *rdbi; + uint8_t *data; + int num_chunks = 0; + int write_offset = 0; + enum gpr_rlcmac_append_result ar; + + if (!ul_tbf->llc_tx_msg || msgb_length(ul_tbf->llc_tx_msg) == 0) + gprs_rlcmac_ul_tbf_schedule_next_llc_frame(ul_tbf); + OSMO_ASSERT(ul_tbf->llc_tx_msg); + + OSMO_ASSERT(gprs_rlcmac_mcs_is_valid(cs)); + + /* length of usable data block (single data unit w/o header) */ + const uint8_t block_data_len = gprs_rlcmac_mcs_max_data_block_bytes(cs); + + /* now we still have untransmitted LLC data, so we fill mac block */ + blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + data = gprs_rlcmac_rlc_block_prepare(blk, block_data_len); + blk->cs_last = cs; + blk->cs_current_trans = cs; + + /* Initialise the variable related to UL SPB */ + blk->spb_status.block_status_ul = GPRS_RLCMAC_EGPRS_RESEG_UL_DEFAULT; + blk->cs_init = cs; + + blk->len = block_data_len; + + rdbi = &(blk->block_info); + memset(rdbi, 0, sizeof(*rdbi)); + rdbi->data_len = block_data_len; + + rdbi->cv = 15; /* Final Block Indicator, set late, if true */ + rdbi->bsn = bsn; /* Block Sequence Number */ + rdbi->e = 1; /* Extension bit, maybe set later (1: no extension) */ + + do { + bool is_final; + int payload_written = 0; + + if (msgb_length(ul_tbf->llc_tx_msg) == 0) { + /* The data just drained, store the current fn */ + if (ul_tbf->last_ul_drained_fn < 0) + ul_tbf->last_ul_drained_fn = bi->fn; + + int space = block_data_len - write_offset; + + if (num_chunks != 0) { + /* Nothing to send, and we already put some data in + * rlcmac data block, we are done */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, + "LLC queue completely drained and there's " + "still %d free bytes in rlcmac data block\n", space); + + /* We may need to update fbi in header here + * since ul_tbf->last_ul_drained_fn was updated above + * Specially important when X2031 is 0. */ + is_final = gprs_rlcmac_llc_queue_size(llc_queue) == 0 && + !gprs_rlcmac_ul_tbf_shall_keep_open(ul_tbf, bi); + if (is_final) { + rdbi->cv = 0; + osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT, NULL); + } + + if (gprs_rlcmac_mcs_is_edge(cs)) { + /* in EGPRS there's no M bit, so we need + * to flag padding with LI=127 */ + gprs_rlcmac_rlc_data_to_ul_append_egprs_li_padding( + rdbi, &write_offset, &num_chunks, data); + } + break; + } + } + + is_final = gprs_rlcmac_llc_queue_size(llc_queue) == 0 && + !gprs_rlcmac_ul_tbf_shall_keep_open(ul_tbf, bi); + + ar = gprs_rlcmac_enc_append_ul_data(rdbi, cs, ul_tbf->llc_tx_msg, + &write_offset, &num_chunks, data, + is_final, &payload_written); + + if (ar == GPRS_RLCMAC_AR_NEED_MORE_BLOCKS) + break; + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Complete UL frame, len=%d\n", msgb_length(ul_tbf->llc_tx_msg)); + msgb_free(ul_tbf->llc_tx_msg); + ul_tbf->llc_tx_msg = NULL; + + if (is_final) + osmo_fsm_inst_dispatch(ul_tbf->state_fsm.fi, GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT, NULL); + + /* dequeue next LLC frame, if any */ + gprs_rlcmac_ul_tbf_schedule_next_llc_frame(ul_tbf); + } while (ar == GPRS_RLCMAC_AR_COMPLETED_SPACE_LEFT); + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "data block (BSN %d, %s): %s\n", + bsn, gprs_rlcmac_mcs_name(blk->cs_last), + osmo_hexdump(blk->buf, block_data_len)); + /* raise send state and set ack state array */ + gprs_rlcmac_rlc_v_b_mark_unacked(&ul_tbf->ulw->v_b, bsn); + gprs_rlcmac_rlc_ul_window_increment_send(ul_tbf->ulw); + + return bsn; +} + +static bool restart_bsn_cycle(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + /* If V(S) == V(A) and finished state, we would have received + * acknowledgement of all transmitted block. In this case we would + * have transmitted the final block, and received ack from MS. But in + * this case we did not receive the final ack indication from MS. This + * should never happen if MS works correctly. + */ + if (gprs_rlcmac_rlc_ul_window_window_empty(ul_tbf->ulw)) { + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "MS acked all blocks\n"); + return false; + } + + /* cycle through all unacked blocks */ + int resend = gprs_rlcmac_rlc_ul_window_mark_for_resend(ul_tbf->ulw); + + /* At this point there should be at least one unacked block + * to be resent. If not, this is an software error. */ + if (resend == 0) { + LOGPTBFUL(ul_tbf, LOGL_ERROR, + "FIXME: Software error: There are no unacknowledged blocks, but V(A) != V(S). PLEASE FIX!\n"); + return false; + } + + return true; +} + +static int take_next_bsn(struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi, + int previous_bsn, bool *may_combine) +{ + int bsn; + int data_len2; + int force_data_len = -1; + enum gprs_rlcmac_coding_scheme tx_cs; + struct gprs_rlcmac_rlc_block *blk; + + /* search for a nacked or resend marked bsn */ + bsn = gprs_rlcmac_rlc_ul_window_resend_needed(ul_tbf->ulw); + + if (previous_bsn >= 0) { + struct gprs_rlcmac_rlc_block *pevious_blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, previous_bsn); + tx_cs = pevious_blk->cs_current_trans; + if (!gprs_rlcmac_mcs_is_edge(tx_cs)) + return -1; + force_data_len = pevious_blk->len; + } else { + tx_cs = ul_tbf->tx_cs; + } + + if (bsn >= 0) { + /* resend an unacked bsn or resend bsn. */ + if (previous_bsn == bsn) + return -1; + + if (previous_bsn >= 0 && + gprs_rlcmac_rlc_window_mod_sns_bsn(ul_tbf->w, bsn - previous_bsn) > RLC_EGPRS_MAX_BSN_DELTA) + return -1; + + blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + if (ul_tbf->tbf.is_egprs) { + /* Table 8.1.1.2 and Table 8.1.1.1 of 44.060 */ + blk->cs_current_trans = gprs_rlcmac_get_retx_mcs(blk->cs_init, tx_cs, + g_ctx->cfg.egprs_arq_type == GPRS_RLCMAC_EGPRS_ARQ1); + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, + "initial_cs_dl(%s) last_mcs(%s) demanded_mcs(%s) cs_trans(%s) arq_type(%d) bsn(%d)\n", + gprs_rlcmac_mcs_name(blk->cs_init), + gprs_rlcmac_mcs_name(blk->cs_last), + gprs_rlcmac_mcs_name(tx_cs), + gprs_rlcmac_mcs_name(blk->cs_current_trans), + g_ctx->cfg.egprs_arq_type, bsn); + + /* TODO: Need to remove this check when MCS-8 -> MCS-6 + * transistion is handled. + * Refer commit be881c028fc4da00c4046ecd9296727975c206a3 + */ + if (blk->cs_init == GPRS_RLCMAC_MCS_8) + blk->cs_current_trans = GPRS_RLCMAC_MCS_8; + } else { + /* gprs */ + blk->cs_current_trans = blk->cs_last; + } + + data_len2 = blk->len; + if (force_data_len > 0 && force_data_len != data_len2) + return -1; + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Resending BSN %d\n", bsn); + /* re-send block with negative acknowlegement */ + gprs_rlcmac_rlc_v_b_mark_unacked(&ul_tbf->ulw->v_b, bsn); + } else if (gprs_rlcmac_tbf_ul_state(ul_tbf) == GPRS_RLCMAC_TBF_UL_ST_FINISHED) { + /* If the TBF is in finished, we already sent all packages at least once. + * If any packages could have been sent (because of unacked) it should have + * been catched up by the upper if(bsn >= 0) */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Restarting at BSN %d, because all blocks have been transmitted.\n", + gprs_rlcmac_rlc_ul_window_v_a(ul_tbf->ulw)); + if (restart_bsn_cycle(ul_tbf)) + return take_next_bsn(ul_tbf, bi, previous_bsn, may_combine); + } else if (gprs_rlcmac_rlc_ul_window_window_stalled(ul_tbf->ulw)) { + /* There are no more packages to send, but the window is stalled. + * Restart the bsn_cycle to resend all unacked messages */ + LOGPTBFUL(ul_tbf, LOGL_NOTICE, "Restarting at BSN %d, because the window is stalled.\n", + gprs_rlcmac_rlc_ul_window_v_a(ul_tbf->ulw)); + if (restart_bsn_cycle(ul_tbf)) + return take_next_bsn(ul_tbf, bi, previous_bsn, may_combine); + } else if (gprs_rlcmac_ul_tbf_have_data(ul_tbf)) { + /* The window has space left, generate new bsn */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Sending new block at BSN %d, CS=%s%s\n", + gprs_rlcmac_rlc_ul_window_v_s(ul_tbf->ulw), gprs_rlcmac_mcs_name(tx_cs), + force_data_len != -1 ? " (forced)" : ""); + + bsn = create_new_bsn(ul_tbf, bi, tx_cs); + } else if (g_ctx->cfg.ul_tbf_preemptive_retransmission && + !gprs_rlcmac_rlc_ul_window_window_empty(ul_tbf->ulw)) { + /* The window contains unacked packages, but not acked. + * Mark unacked bsns as RESEND */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Restarting at BSN %d, because all blocks have been transmitted (FLOW).\n", + gprs_rlcmac_rlc_ul_window_v_a(ul_tbf->ulw)); + if (restart_bsn_cycle(ul_tbf)) + return take_next_bsn(ul_tbf, bi, previous_bsn, may_combine); + } else { + /* Nothing left to send, create dummy LLC commands */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Sending new dummy block at BSN %d, CS=%s\n", + gprs_rlcmac_rlc_ul_window_v_s(ul_tbf->ulw), + gprs_rlcmac_mcs_name(tx_cs)); + bsn = create_new_bsn(ul_tbf, bi, tx_cs); + /* Don't send a second block, so don't set cs_current_trans */ + } + + if (bsn < 0) { + /* we just send final block again */ + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Nothing else to send, Re-transmit final block!\n"); + bsn = gprs_rlcmac_rlc_ul_window_v_s_mod(ul_tbf->ulw, -1); + } + + blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + *may_combine = gprs_rlcmac_num_data_blocks(gprs_rlcmac_mcs_header_type(blk->cs_current_trans)) > 1; + + return bsn; +} + +/* + * This function returns the pointer to data which needs + * to be copied. Also updates the status of the block related to + * Split block handling in the RLC/MAC block. + */ +static enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state egprs_ul_get_data(const struct gprs_rlcmac_ul_tbf *ul_tbf, int bsn, uint8_t **block_data) +{ + struct gprs_rlcmac_rlc_block *blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state *block_status_ul = &blk->spb_status.block_status_ul; + + enum gprs_rlcmac_coding_scheme cs_init = blk->cs_init; + enum gprs_rlcmac_coding_scheme cs_current_trans = blk->cs_current_trans; + + enum gprs_rlcmac_header_type ht_cs_init = gprs_rlcmac_mcs_header_type(blk->cs_init); + enum gprs_rlcmac_header_type ht_cs_current_trans = gprs_rlcmac_mcs_header_type(blk->cs_current_trans); + + *block_data = &blk->buf[0]; + + /* + * Table 10.3a.0.1 of 44.060 + * MCS6,9: second segment starts at 74/2 = 37 + * MCS5,7: second segment starts at 56/2 = 28 + * MCS8: second segment starts at 31 + * MCS4: second segment starts at 44/2 = 22 + */ + if (ht_cs_current_trans == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3) { + if (*block_status_ul == GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_SENT) { + switch (cs_init) { + case GPRS_RLCMAC_MCS_6: + case GPRS_RLCMAC_MCS_9: + *block_data = &blk->buf[37]; + break; + case GPRS_RLCMAC_MCS_7: + case GPRS_RLCMAC_MCS_5: + *block_data = &blk->buf[28]; + break; + case GPRS_RLCMAC_MCS_8: + *block_data = &blk->buf[31]; + break; + case GPRS_RLCMAC_MCS_4: + *block_data = &blk->buf[22]; + break; + default: + LOGPTBFUL(ul_tbf, LOGL_ERROR, + "FIXME: Software error: hit invalid condition. " + "headerType(%d) blockstatus(%d) cs(%s) PLEASE FIX!\n", + ht_cs_current_trans, + *block_status_ul, gprs_rlcmac_mcs_name(cs_init)); + break; + + } + return GPRS_RLCMAC_EGPRS_RESEG_SECOND_SEG_SENT; + } else if ((ht_cs_init == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1) || + (ht_cs_init == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2)) { + return GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_SENT; + } else if ((cs_init == GPRS_RLCMAC_MCS_4) && + (cs_current_trans == GPRS_RLCMAC_MCS_1)) { + return GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_SENT; + } + } + return GPRS_RLCMAC_EGPRS_RESEG_UL_DEFAULT; +} + +/* + * This function returns the spb value to be sent OTA + * for RLC/MAC block. + */ +static enum gprs_rlcmac_rlc_egprs_ul_spb get_egprs_ul_spb(const struct gprs_rlcmac_ul_tbf *ul_tbf, int bsn) +{ + struct gprs_rlcmac_rlc_block *blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state block_status_ul = blk->spb_status.block_status_ul; + + enum gprs_rlcmac_coding_scheme cs_init = blk->cs_init; + enum gprs_rlcmac_coding_scheme cs_current_trans = blk->cs_current_trans; + + enum gprs_rlcmac_header_type ht_cs_init = gprs_rlcmac_mcs_header_type(blk->cs_init); + enum gprs_rlcmac_header_type ht_cs_current_trans = gprs_rlcmac_mcs_header_type(blk->cs_current_trans); + + /* Table 10.4.8b.1 of 44.060 */ + if (ht_cs_current_trans == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_3) { + /* + * if we are sending the second segment the spb should be 3 + * otherwise it should be 2 + */ + if (block_status_ul == GPRS_RLCMAC_EGPRS_RESEG_FIRST_SEG_SENT) { + return GPRS_RLCMAC_EGPRS_UL_SPB_SEC_SEG; + } else if ((ht_cs_init == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_1) || + (ht_cs_init == GPRS_RLCMAC_HEADER_EGPRS_DATA_TYPE_2)) { + return GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_6NOPAD; + } else if ((cs_init == GPRS_RLCMAC_MCS_4) && + (cs_current_trans == GPRS_RLCMAC_MCS_1)) { + return GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_10PAD; + } + } + /* Non SPB cases 0 is reurned */ + return GPRS_RLCMAC_EGPRS_UL_SPB_NO_RETX; +} + +static struct msgb *create_ul_acked_block(struct gprs_rlcmac_ul_tbf *ul_tbf, + const struct gprs_rlcmac_rts_block_ind *bi, + int index, int index2) +{ + uint8_t *msg_data; + struct msgb *msg; + unsigned msg_len; + /* TODO: support MCS-7 - MCS-9, where data_block_idx can be 1 */ + uint8_t data_block_idx = 0; + bool is_final = false; + enum gprs_rlcmac_coding_scheme cs_init, cs; + struct gprs_rlcmac_rlc_data_info rlc; + int bsns[ARRAY_SIZE(rlc.block_info)]; + unsigned num_bsns; + bool need_padding = false; + enum gprs_rlcmac_rlc_egprs_ul_spb spb = GPRS_RLCMAC_EGPRS_UL_SPB_NO_RETX; + unsigned int spb_status; + struct gprs_rlcmac_rlc_block *blk; + + blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, index); + spb_status = blk->spb_status.block_status_ul; + + enum gprs_rlcmac_egprs_puncturing_values punct[2] = { + GPRS_RLCMAC_EGPRS_PS_INVALID, GPRS_RLCMAC_EGPRS_PS_INVALID + }; + osmo_static_assert(ARRAY_SIZE(rlc.block_info) == 2, rlc_block_info_size_is_two); + + /* + * TODO: This is an experimental work-around to put 2 BSN into + * MCS-7 to MCS-9 encoded messages. It just sends the same BSN + * twice in the block. The cs should be derived from the TBF's + * current CS such that both BSNs (that must be compatible) can + * be put into the data area, even if the resulting CS is higher than + * the current limit. + */ + cs = blk->cs_current_trans; + cs_init = blk->cs_init; + bsns[0] = index; + num_bsns = 1; + + if (index2 >= 0) { + bsns[num_bsns] = index2; + num_bsns += 1; + } + + /* + * if the initial mcs is 8 and retransmission mcs is either 6 or 3 + * we have to include the padding of 6 octets in first segment + */ + if ((cs_init == GPRS_RLCMAC_MCS_8) && + (cs == GPRS_RLCMAC_MCS_6 || cs == GPRS_RLCMAC_MCS_3)) { + if (spb_status == GPRS_RLCMAC_EGPRS_RESEG_UL_DEFAULT || + spb_status == GPRS_RLCMAC_EGPRS_RESEG_SECOND_SEG_SENT) + need_padding = true; + } else if (num_bsns == 1) { + /* TODO: remove the conditional when MCS-6 padding isn't + * failing to be decoded by MEs anymore */ + /* TODO: support of MCS-8 -> MCS-6 transition should be + * handled + * Refer commit be881c028fc4da00c4046ecd9296727975c206a3 + * dated 2016-02-07 23:45:40 (UTC) + */ + if (cs != GPRS_RLCMAC_MCS_8) + gprs_rlcmac_mcs_dec_to_single_block(&cs, &need_padding); + } + + spb = get_egprs_ul_spb(ul_tbf, index); + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "need_padding %d spb_status %d spb %d (BSN1 %d BSN2 %d)\n", + need_padding, spb_status, spb, index, index2); + + gprs_rlcmac_rlc_data_info_init_ul(&rlc, cs, need_padding, spb); + + rlc.usf = 7; /* will be set at scheduler */ + rlc.pr = 0; /* FIXME: power reduction */ + rlc.tfi = ul_tbf->cur_alloc.ul_tfi; /* TFI */ + + /* return data block(s) as message */ + msg_len = gprs_rlcmac_mcs_size_dl(cs); + msg = msgb_alloc(msg_len, "rlcmac_ul_data"); + if (!msg) + return NULL; + + msg_data = msgb_put(msg, msg_len); + + OSMO_ASSERT(rlc.num_data_blocks <= ARRAY_SIZE(rlc.block_info)); + OSMO_ASSERT(rlc.num_data_blocks > 0); + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Copying %u RLC blocks, %u BSNs\n", rlc.num_data_blocks, num_bsns); + + /* Copy block(s) to RLC message: the num_data_blocks cannot be more than 2 - see assert above */ + for (data_block_idx = 0; data_block_idx < OSMO_MIN(rlc.num_data_blocks, 2); data_block_idx++) { + int bsn; + uint8_t *block_data; + struct gprs_rlcmac_rlc_block_info *rdbi, *block_info; + enum gprs_rlcmac_rlc_egprs_ul_reseg_bsn_state reseg_status; + + /* Check if there are more blocks than BSNs */ + if (data_block_idx < num_bsns) + bsn = bsns[data_block_idx]; + else + bsn = bsns[0]; + + /* Get current puncturing scheme from block */ + blk = gprs_rlcmac_rlc_block_store_get_block(ul_tbf->blkst, bsn); + + blk->next_ps = gprs_rlcmac_get_punct_scheme(blk->next_ps, blk->cs_last, cs, spb); + + if (gprs_rlcmac_mcs_is_edge(cs)) { + OSMO_ASSERT(blk->next_ps >= GPRS_RLCMAC_EGPRS_PS_1); + OSMO_ASSERT(blk->next_ps <= GPRS_RLCMAC_EGPRS_PS_3); + } + + punct[data_block_idx] = blk->next_ps; + + rdbi = &rlc.block_info[data_block_idx]; + block_info = &blk->block_info; + + /* + * get data and header from current block + * function returns the reseg status + */ + reseg_status = egprs_ul_get_data(ul_tbf, bsn, &block_data); + blk->spb_status.block_status_dl = reseg_status; + + /* + * If it is first segment of the split block set the state of + * bsn to nacked. If it is the first segment dont update the + * next ps value of bsn. since next segment also needs same cps + */ + if (spb == GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_10PAD || + spb == GPRS_RLCMAC_EGPRS_UL_SPB_FIRST_SEG_6NOPAD) + gprs_rlcmac_rlc_v_b_mark_nacked(&ul_tbf->ulw->v_b, bsn); + else { + /* + * TODO: Need to handle 2 same bsns + * in header type 1 + */ + gprs_rlcmac_update_punct_scheme(&blk->next_ps, cs); + } + + blk->cs_last = cs; + rdbi->e = block_info->e; + rdbi->cv = block_info->cv; + rdbi->bsn = bsn; + is_final = is_final || rdbi->cv == 0; + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "Copying data unit %d (BSN %d)\n", + data_block_idx, bsn); + + gprs_rlcmac_rlc_copy_from_aligned_buffer(&rlc, data_block_idx, msg_data, block_data); + } + + /* Calculate CPS only for EGPRS case */ + if (gprs_rlcmac_mcs_is_edge(cs)) + rlc.cps = gprs_rlcmac_rlc_mcs_cps(cs, punct[0], punct[1], need_padding); + + gprs_rlcmac_rlc_write_ul_data_header(&rlc, msg_data); + + LOGPTBFUL(ul_tbf, LOGL_DEBUG, "msg block (BSN %d, %s%s): %s\n", + index, gprs_rlcmac_mcs_name(cs), + need_padding ? ", padded" : "", + msgb_hexdump(msg)); + + return msg; +} + +struct msgb *gprs_rlcmac_ul_tbf_data_create(struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + int bsn; + int bsn2 = -1; + bool may_combine; + + bsn = take_next_bsn(ul_tbf, bi, -1, &may_combine); + if (bsn < 0) + return NULL; + + if (may_combine) + bsn2 = take_next_bsn(ul_tbf, bi, bsn, &may_combine); + + return create_ul_acked_block(ul_tbf, bi, bsn, bsn2); } diff --git a/src/rlcmac/tbf_ul_ass_fsm.c b/src/rlcmac/tbf_ul_ass_fsm.c index 1130187..1eb38ae 100644 --- a/src/rlcmac/tbf_ul_ass_fsm.c +++ b/src/rlcmac/tbf_ul_ass_fsm.c @@ -138,8 +138,8 @@ LOGPFSML(ctx->fi, LOGL_ERROR, "ImmAss SingleBlock (2phase access) not yet supported!\n"); return -ENOTSUP; case 1: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.* (GPRS_DynamicOrFixedAllocation_t) */ - //ctx->ul_tbf->tx_cs = d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.CHANNEL_CODING_COMMAND + 1; - //LOGPFSML(ctx->fi, LOGL_INFO, "ImmAss initial CS=%s\n", gprs_rlcmac_mcs_name(ctx->ul_tbf->tx_cs)); + ctx->ul_tbf->tx_cs = d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.CHANNEL_CODING_COMMAND + 1; + LOGPFSML(ctx->fi, LOGL_INFO, "ImmAss initial CS=%s\n", gprs_rlcmac_mcs_name(ctx->ul_tbf->tx_cs)); switch (d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.UnionType) { case 0: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.DynamicAllocation (DynamicAllocation_t) */ /* TODO: 2phase access support: Schedule transmit of PKT_RES_REQ on FN=(GPRS_SingleBlockAllocation_t).TBF_STARTING_TIME */ diff --git a/src/rlcmac/tbf_ul_fsm.c b/src/rlcmac/tbf_ul_fsm.c index 0078846..5095605 100644 --- a/src/rlcmac/tbf_ul_fsm.c +++ b/src/rlcmac/tbf_ul_fsm.c @@ -30,9 +30,10 @@ #define X(s) (1 << (s)) static const struct value_string tbf_ul_fsm_event_names[] = { - { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, "UL_ASS_START" }, - { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, "UL_ASS_COMPL" }, - { GPRS_RLCMAC_TBF_UL_EV_FOOBAR, "FOOBAR" }, + { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, "UL_ASS_START" }, + { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, "UL_ASS_COMPL" }, + { GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT, "LAST_UL_DATA_SENT" }, + { GPRS_RLCMAC_TBF_UL_EV_FOOBAR, "FOOBAR" }, { 0, NULL } }; @@ -40,6 +41,7 @@ [GPRS_RLCMAC_TBF_UL_ST_NEW] = { }, [GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN] = { }, [GPRS_RLCMAC_TBF_UL_ST_FLOW] = { }, + [GPRS_RLCMAC_TBF_UL_ST_FINISHED] = { }, }; /* Transition to a state, using the T timer defined in tbf_fsm_timeouts. @@ -104,6 +106,18 @@ { //struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; switch (event) { + case GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT: + tbf_ul_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ST_FINISHED); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_finished(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + //struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; + switch (event) { default: OSMO_ASSERT(0); } @@ -129,11 +143,19 @@ }, [GPRS_RLCMAC_TBF_UL_ST_FLOW] = { .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_EV_LAST_UL_DATA_SENT), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ST_FINISHED), + .name = "FLOW", + .action = st_flow, + }, + [GPRS_RLCMAC_TBF_UL_ST_FINISHED] = { + .in_event_mask = X(GPRS_RLCMAC_TBF_UL_EV_FOOBAR), .out_state_mask = X(GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN), - .name = "FLOW", - .action = st_flow, + .name = "FINISHED", + .action = st_finished, }, }; diff --git a/tests/rlcmac/rlcmac_prim_test.c b/tests/rlcmac/rlcmac_prim_test.c index fb12f05..fa864f9 100644 --- a/tests/rlcmac/rlcmac_prim_test.c +++ b/tests/rlcmac/rlcmac_prim_test.c @@ -146,6 +146,13 @@ switch (rlcmac_prim->oph.sap) { case OSMO_GPRS_RLCMAC_SAP_L1CTL: switch (OSMO_PRIM_HDR(&rlcmac_prim->oph)) { + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, PRIM_OP_REQUEST): + printf("%s(): Rx %s fn=%u ts=%u data_len=%u data=[%s]\n", __func__, pdu_name, + rlcmac_prim->l1ctl.pdch_data_req.fn, + rlcmac_prim->l1ctl.pdch_data_req.ts_nr, + rlcmac_prim->l1ctl.pdch_data_req.data_len, + osmo_hexdump(rlcmac_prim->l1ctl.pdch_data_req.data, rlcmac_prim->l1ctl.pdch_data_req.data_len)); + break; case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_RACH, PRIM_OP_REQUEST): last_rach_req_ra = rlcmac_prim->l1ctl.rach_req.ra; printf("%s(): Rx %s ra=0x%02x\n", __func__, pdu_name, last_rach_req_ra); @@ -184,6 +191,9 @@ printf("=== %s start ===\n", __func__); prepare_test(); uint32_t tlli = 0x2342; + uint8_t ts_nr = 7; + uint8_t usf = 0; + uint32_t rts_fn = 4; rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_grr_unitdata_req(tlli, pdu_llc_gmm_att_req, sizeof(pdu_llc_gmm_att_req)); @@ -195,6 +205,10 @@ rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_l1ctl_ccch_data_ind(0, ccch_imm_ass_pkt_ul_tbf_normal); rc = osmo_gprs_rlcmac_prim_lower_up(rlcmac_prim); + /* Trigger transmission of LLC data (GMM Attach) */ + rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_l1ctl_pdch_rts_ind(ts_nr, rts_fn, usf); + rc = osmo_gprs_rlcmac_prim_lower_up(rlcmac_prim); + OSMO_ASSERT(rc == 0); printf("=== %s end ===\n", __func__); } diff --git a/tests/rlcmac/rlcmac_prim_test.err b/tests/rlcmac/rlcmac_prim_test.err index 7e75164..e6d6b30 100644 --- a/tests/rlcmac/rlcmac_prim_test.err +++ b/tests/rlcmac/rlcmac_prim_test.err @@ -9,9 +9,19 @@ DLGLOBAL INFO UL_TBF_ASS{IDLE}: state_chg to WAIT_CCCH_IMM_ASS DLGLOBAL INFO Rx from lower layers: L1CTL-CCCH_DATA.indication DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: Received Event RX_CCCH_IMM_ASS +DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: ImmAss initial CS=CS-2 DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: ImmAss DynamicAlloc (1phase access) ts_nr=7 usf=0 DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: state_chg to COMPLETED DLGLOBAL INFO UL_TBF{ASSIGN}: Received Event UL_ASS_COMPL DLGLOBAL INFO UL_TBF{ASSIGN}: Send L1CTL-CF_UL_TBF.req ul_slotmask=0x80 DLGLOBAL INFO UL_TBF{ASSIGN}: state_chg to FLOW DLGLOBAL INFO UL_TBF_ASS{COMPLETED}: state_chg to IDLE +DLGLOBAL INFO Rx from lower layers: L1CTL-PDCH_RTS.indication +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) Sending new block at BSN 0, CS=CS-2 +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) Dequeue next LLC (len=33) +DLGLOBAL DEBUG -- Chunk with length 33 larger than space (30) left in block: copy only remaining space, and we are done +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) data block (BSN 0, CS-2): 01 c0 00 08 01 01 d5 71 00 00 08 29 26 24 00 00 00 00 71 62 f2 24 6c 84 44 04 11 e5 10 00 +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) need_padding 0 spb_status 0 spb 0 (BSN1 0 BSN2 -1) +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) Copying 1 RLC blocks, 1 BSNs +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) Copying data unit 0 (BSN 0) +DLGLOBAL DEBUG TBF(UL:NR-0:TLLI-00002342) msg block (BSN 0, CS-2): 3c 00 01 01 c0 00 08 01 01 d5 71 00 00 08 29 26 24 00 00 00 00 71 62 f2 24 6c 84 44 04 11 e5 10 00 00 diff --git a/tests/rlcmac/rlcmac_prim_test.ok b/tests/rlcmac/rlcmac_prim_test.ok index 030743e..6e0db40 100644 --- a/tests/rlcmac/rlcmac_prim_test.ok +++ b/tests/rlcmac/rlcmac_prim_test.ok @@ -1,4 +1,5 @@ === test_ul_tbf_attach start === test_rlcmac_prim_down_cb(): Rx L1CTL-RACH.request ra=0x7e test_rlcmac_prim_down_cb(): Rx L1CTL-CFG_UL_TBF.request ul_tbf_nr=0 ul_slotmask=0x80 +test_rlcmac_prim_down_cb(): Rx L1CTL-PDCH_DATA.request fn=4 ts=7 data_len=34 data=[3c 00 01 01 c0 00 08 01 01 d5 71 00 00 08 29 26 24 00 00 00 00 71 62 f2 24 6c 84 44 04 11 e5 10 00 00 ] === test_ul_tbf_attach end === -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/31170 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I0a01d79d16bbfc63aa88e6bb0f432f3772645730 Gerrit-Change-Number: 31170 Gerrit-PatchSet: 11 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: Make sure entities are freed if lib is re-initialized
by pespin 13 Feb '23

13 Feb '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/31284 ) Change subject: rlcmac: Make sure entities are freed if lib is re-initialized ...................................................................... rlcmac: Make sure entities are freed if lib is re-initialized This allows proper memory cleanup of the whole library everytime we want to run a new unit test in the same proces. Change-Id: I568e2f783a575ae457f0845eca34951ae9822eeb --- M src/rlcmac/rlcmac.c 1 file changed, 11 insertions(+), 1 deletion(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/rlcmac/rlcmac.c b/src/rlcmac/rlcmac.c index 97516d5..f8e3939 100644 --- a/src/rlcmac/rlcmac.c +++ b/src/rlcmac/rlcmac.c @@ -40,6 +40,16 @@ { 0 } /* empty item at the end */ }; +static void gprs_rlcmac_ctx_free(void) +{ + struct gprs_rlcmac_entity *gre; + + while ((gre = llist_first_entry_or_null(&g_ctx->gre_list, struct gprs_rlcmac_entity, entry))) + gprs_rlcmac_entity_free(gre); + + talloc_free(g_ctx); +} + int osmo_gprs_rlcmac_init(enum osmo_gprs_rlcmac_location location) { bool first_init = true; @@ -47,7 +57,7 @@ OSMO_ASSERT(location == OSMO_GPRS_RLCMAC_LOCATION_MS || location == OSMO_GPRS_RLCMAC_LOCATION_PCU) if (g_ctx) { - talloc_free(g_ctx); + gprs_rlcmac_ctx_free(); first_init = false; } 1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/31284 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I568e2f783a575ae457f0845eca34951ae9822eeb Gerrit-Change-Number: 31284 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: Introduce lower primitive layer API
by pespin 13 Feb '23

13 Feb '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/31177 ) Change subject: rlcmac: Introduce lower primitive layer API ...................................................................... rlcmac: Introduce lower primitive layer API This primitive API allows the application to drive the RLCMAC layer based on a lower L1CTL interface. * RACH req are requested to the lower layers by the RLCMAC through the RACH.req primitive. * Received ImmAss, SI are fed to the RLC/MAC layer through CCCH_DATA.ind * The RLCMAC registers DL and UL TBFs in the lower part (firwmare, L1CTL): ** The lower part will trigger PDCH_RTS.ind in every TS in the "(dl_slotmask|ul_slotmask)" superset, with the received USF. This allows UL uplink to transmit blocks when requested by USF, or UL/DL TBF to answer polls from PCU at a specific N+X FN (RRBP). This also allows the RLCMAC layer to update its GSM clock and trigger internall timeouts. ** The lower part will trigger PDCH_DATA.ind in every TS in the dl_slotmask if either a CTRL block is received or a data block matching the configured dl_tfi is received. ** Upon receival of PDCH_DATA.ind, the RLCMAC layer updates its FN clock and submits PDCH_DATA.req based on USF. This commit only adds the primitive set and API to submit/receive them, but doesn't really implement them yet internally. Related: OS#5500 Change-Id: I3d97425ec75059ceae983de869419230e8c4df01 --- M include/osmocom/gprs/rlcmac/rlcmac_prim.h M include/osmocom/gprs/rlcmac/rlcmac_private.h M src/rlcmac/rlcmac_prim.c M tests/rlcmac/Makefile.am A tests/rlcmac/rlcmac_prim_test.c A tests/rlcmac/rlcmac_prim_test.err A tests/rlcmac/rlcmac_prim_test.ok M tests/testsuite.at 8 files changed, 477 insertions(+), 4 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/include/osmocom/gprs/rlcmac/rlcmac_prim.h b/include/osmocom/gprs/rlcmac/rlcmac_prim.h index 443dede..92e644e 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_prim.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_prim.h @@ -15,6 +15,7 @@ enum osmo_gprs_rlcmac_prim_sap { OSMO_GPRS_RLCMAC_SAP_GRR, OSMO_GPRS_RLCMAC_SAP_GMMRR, + OSMO_GPRS_RLCMAC_SAP_L1CTL, }; extern const struct value_string osmo_gprs_rlcmac_prim_sap_names[]; @@ -87,11 +88,85 @@ }; }; +/* From/Towards lower layers */ +enum osmo_gprs_rlcmac_l1ctl_prim_type { + OSMO_GPRS_RLCMAC_L1CTL_RACH, + OSMO_GPRS_RLCMAC_L1CTL_CCCH_DATA, + OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, + OSMO_GPRS_RLCMAC_L1CTL_PDCH_RTS, + OSMO_GPRS_RLCMAC_L1CTL_CFG_UL_TBF, + OSMO_GPRS_RLCMAC_L1CTL_CFG_DL_TBF, +}; + +extern const struct value_string osmo_gprs_rlcmac_l1ctl_prim_type_names[]; +static inline const char *osmo_gprs_rlcmac_l1ctl_prim_type_name(enum osmo_gprs_rlcmac_l1ctl_prim_type val) +{ + return get_value_string(osmo_gprs_rlcmac_l1ctl_prim_type_names, val); +} + +/* Parameters for OSMO_GPRS_RLCMAC_L1CTL_* prims */ +struct osmo_gprs_rlcmac_l1ctl_prim { + /* Common fields (none) */ + union { + /* OSMO_GPRS_RLCMAC_L1CTL_RACH | Req */ + struct { + bool is_11bit; + union { + uint8_t ra; + struct { + uint16_t ra11; + uint8_t synch_seq; + }; + }; + } rach_req; + /* OSMO_GPRS_RLCMAC_L1CTL_CCCH_DATA | Ind */ + struct { + uint32_t fn; + uint8_t *data; /* data_len = GSM_MACBLOCK_LEN */ + } ccch_data_ind; + /* OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA | Req */ + struct { + uint32_t fn; + uint8_t ts_nr; + uint8_t data_len; + uint8_t *data; + } pdch_data_req; + /* OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA | Ind */ + struct { + uint32_t fn; + uint8_t ts_nr; + uint8_t rx_lev; + uint16_t ber10k; + int16_t ci_cb; + uint8_t data_len; /* data_len = 0 if decoding fails or filtered by lower layer based on DL TFI */ + uint8_t *data; + } pdch_data_ind; + /* OSMO_GPRS_RLCMAC_L1CTL_PDCH_RTS | Ind */ + struct { + uint32_t fn; + uint8_t ts_nr; + uint8_t usf; + } pdch_rts_ind; + /* OSMO_GPRS_RLCMAC_L1CTL_CFG_UL_TBF | Req */ + struct { + uint8_t ul_tbf_nr; + uint8_t ul_slotmask; + } cfg_ul_tbf_req; + /* OSMO_GPRS_RLCMAC_L1CTL_CFG_DL_TBF | Req */ + struct { + uint8_t dl_tbf_nr; + uint8_t dl_slotmask; + uint8_t dl_tfi; + } cfg_dl_tbf_req; + }; +}; + struct osmo_gprs_rlcmac_prim { struct osmo_prim_hdr oph; union { struct osmo_gprs_rlcmac_grr_prim grr; struct osmo_gprs_rlcmac_gmmrr_prim gmmrr; + struct osmo_gprs_rlcmac_l1ctl_prim l1ctl; }; }; @@ -113,3 +188,10 @@ /* Alloc primitive for GMMRR SAP: */ struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_gmmrr_asign_req( uint32_t new_tlli); + +/* Alloc primitive for L1CTL SAP: */ +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_ccch_data_ind(uint32_t fn, uint8_t *data); +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_pdch_data_ind(uint8_t ts_nr, uint32_t fn, + uint8_t rx_lev, uint16_t ber10k, int16_t ci_cb, + uint8_t *data, uint8_t data_len); +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_pdch_rts_ind(uint8_t ts_nr, uint32_t fn, uint8_t usf); diff --git a/include/osmocom/gprs/rlcmac/rlcmac_private.h b/include/osmocom/gprs/rlcmac/rlcmac_private.h index 26284c1..c10b159 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_private.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_private.h @@ -46,3 +46,10 @@ struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_grr_unitdata_ind( uint32_t tlli, uint8_t *ll_pdu, size_t ll_pdu_len); struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_gmmrr_page_ind(uint32_t tlli); + +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_rach8_req(uint8_t ra); +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_rach11_req(uint16_t ra11, uint8_t synch_seq); +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_pdch_data_req(uint8_t ts_nr, uint32_t fn, + uint8_t *data, uint8_t data_len); +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_cfg_dl_tbf_req(uint8_t dl_tbf_nr, uint8_t dl_slotmask, uint8_t dl_tfi); +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_cfg_ul_tbf_req(uint8_t ul_tbf_nr, uint8_t ul_slotmask); diff --git a/src/rlcmac/rlcmac_prim.c b/src/rlcmac/rlcmac_prim.c index 8d57580..a2f2576 100644 --- a/src/rlcmac/rlcmac_prim.c +++ b/src/rlcmac/rlcmac_prim.c @@ -42,6 +42,7 @@ const struct value_string osmo_gprs_rlcmac_prim_sap_names[] = { { OSMO_GPRS_RLCMAC_SAP_GRR, "GRR" }, { OSMO_GPRS_RLCMAC_SAP_GMMRR, "GMMRR" }, + { OSMO_GPRS_RLCMAC_SAP_L1CTL, "L1CTL" }, { 0, NULL } }; @@ -57,6 +58,16 @@ { 0, NULL } }; +const struct value_string osmo_gprs_rlcmac_l1ctl_prim_type_names[] = { + { OSMO_GPRS_RLCMAC_L1CTL_RACH, "RACH" }, + { OSMO_GPRS_RLCMAC_L1CTL_CCCH_DATA, "CCCH_DATA" }, + { OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, "PDCH_DATA" }, + { OSMO_GPRS_RLCMAC_L1CTL_PDCH_RTS, "PDCH_RTS" }, + { OSMO_GPRS_RLCMAC_L1CTL_CFG_UL_TBF, "CFG_UL_TBF" }, + { OSMO_GPRS_RLCMAC_L1CTL_CFG_DL_TBF, "CFG_DL_TBF" }, + { 0, NULL } +}; + const char *osmo_gprs_rlcmac_prim_name(const struct osmo_gprs_rlcmac_prim *rlcmac_prim) { static char name_buf[256]; @@ -71,6 +82,9 @@ case OSMO_GPRS_RLCMAC_SAP_GMMRR: type = osmo_gprs_rlcmac_gmmrr_prim_type_name(rlcmac_prim->oph.primitive); break; + case OSMO_GPRS_RLCMAC_SAP_L1CTL: + type = osmo_gprs_rlcmac_l1ctl_prim_type_name(rlcmac_prim->oph.primitive); + break; default: type = "unsupported-rlcmac-sap"; } @@ -152,6 +166,14 @@ return gprs_rlcmac_prim_alloc(OSMO_GPRS_RLCMAC_SAP_GMMRR, type, operation, l3_len); } +static inline +struct osmo_gprs_rlcmac_prim *rlcmac_prim_l1ctl_alloc(enum osmo_gprs_rlcmac_l1ctl_prim_type type, + enum osmo_prim_operation operation, + unsigned int l3_len) +{ + return gprs_rlcmac_prim_alloc(OSMO_GPRS_RLCMAC_SAP_L1CTL, type, operation, l3_len); +} + /* 3GPP TS 44.064 7.2.3.2 GRR-UNITDATA.ind (MS):*/ struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_grr_unitdata_ind( uint32_t tlli, uint8_t *ll_pdu, @@ -195,6 +217,98 @@ return rlcmac_prim; } +/* L1CTL-RACH.req (8bit) */ +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_rach8_req(uint8_t ra) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_RACH, PRIM_OP_REQUEST, 0); + rlcmac_prim->l1ctl.rach_req.is_11bit = false; + rlcmac_prim->l1ctl.rach_req.ra = ra; + return rlcmac_prim; +} + +/* L1CTL-RACH.req (11bit) */ +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_rach11_req(uint16_t ra11, uint8_t synch_seq) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_RACH, PRIM_OP_REQUEST, 0); + rlcmac_prim->l1ctl.rach_req.is_11bit = true; + rlcmac_prim->l1ctl.rach_req.ra11 = ra11; + rlcmac_prim->l1ctl.rach_req.synch_seq = synch_seq; + return rlcmac_prim; +} + +/* L1CTL-CCCH_DATA.ind */ +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_ccch_data_ind(uint32_t fn, uint8_t *data) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_CCCH_DATA, PRIM_OP_INDICATION, 0); + rlcmac_prim->l1ctl.ccch_data_ind.fn = fn; + rlcmac_prim->l1ctl.ccch_data_ind.data = data; + return rlcmac_prim; +} + +/* L1CTL-PDCH_DATA.req */ +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_pdch_data_req(uint8_t ts_nr, uint32_t fn, + uint8_t *data, uint8_t data_len) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, PRIM_OP_REQUEST, data_len); + rlcmac_prim->l1ctl.pdch_data_req.fn = fn; + rlcmac_prim->l1ctl.pdch_data_req.ts_nr = ts_nr; + rlcmac_prim->l1ctl.pdch_data_req.data_len = data_len; + rlcmac_prim->l1ctl.pdch_data_req.data = data; + return rlcmac_prim; +} + +/* L1CTL-PDCH_DATA.ind */ +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_pdch_data_ind(uint8_t ts_nr, uint32_t fn, + uint8_t rx_lev, uint16_t ber10k, int16_t ci_cb, uint8_t *data, uint8_t data_len) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, PRIM_OP_INDICATION, data_len); + rlcmac_prim->l1ctl.pdch_data_ind.fn = fn; + rlcmac_prim->l1ctl.pdch_data_ind.ts_nr = ts_nr; + rlcmac_prim->l1ctl.pdch_data_ind.rx_lev = rx_lev; + rlcmac_prim->l1ctl.pdch_data_ind.ber10k = ber10k; + rlcmac_prim->l1ctl.pdch_data_ind.ci_cb = ci_cb; + rlcmac_prim->l1ctl.pdch_data_ind.data_len = data_len; + rlcmac_prim->l1ctl.pdch_data_ind.data = data; + return rlcmac_prim; +} + +/* L1CTL-PDCH_RTS.ind */ +struct osmo_gprs_rlcmac_prim *osmo_gprs_rlcmac_prim_alloc_l1ctl_pdch_rts_ind(uint8_t ts_nr, uint32_t fn, uint8_t usf) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_PDCH_RTS, PRIM_OP_INDICATION, 0); + rlcmac_prim->l1ctl.pdch_rts_ind.fn = fn; + rlcmac_prim->l1ctl.pdch_rts_ind.ts_nr = ts_nr; + rlcmac_prim->l1ctl.pdch_rts_ind.usf = usf; + return rlcmac_prim; +} + +/* L1CTL-CFG_DL_TBF.req */ +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_cfg_dl_tbf_req(uint8_t tbf_nr, uint8_t slotmask, uint8_t dl_tfi) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_CFG_DL_TBF, PRIM_OP_REQUEST, 0); + rlcmac_prim->l1ctl.cfg_dl_tbf_req.dl_tbf_nr = tbf_nr; + rlcmac_prim->l1ctl.cfg_dl_tbf_req.dl_slotmask = slotmask; + rlcmac_prim->l1ctl.cfg_dl_tbf_req.dl_tfi = dl_tfi; + return rlcmac_prim; +} + +/* L1CTL-CFG_UL_TBF.req */ +struct osmo_gprs_rlcmac_prim *gprs_rlcmac_prim_alloc_l1ctl_cfg_ul_tbf_req(uint8_t ul_tbf_nr, uint8_t ul_slotmask) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + rlcmac_prim = rlcmac_prim_l1ctl_alloc(OSMO_GPRS_RLCMAC_L1CTL_CFG_UL_TBF, PRIM_OP_REQUEST, 0); + rlcmac_prim->l1ctl.cfg_ul_tbf_req.ul_tbf_nr = ul_tbf_nr; + rlcmac_prim->l1ctl.cfg_ul_tbf_req.ul_slotmask = ul_slotmask; + return rlcmac_prim; +} + int gprs_rlcmac_prim_handle_unsupported(struct osmo_gprs_rlcmac_prim *rlcmac_prim) { LOGRLCMAC(LOGL_ERROR, "Unsupported rlcmac_prim! %s\n", osmo_gprs_rlcmac_prim_name(rlcmac_prim)); @@ -321,6 +435,47 @@ return rc; } +static int rlcmac_prim_handle_l1ctl_pdch_rts_ind(struct osmo_gprs_rlcmac_prim *rlcmac_prim) +{ + int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); + rc = 1; /* msg owned (freed) */ + return rc; +} + +static int rlcmac_prim_handle_l1ctl_pdch_data_ind(struct osmo_gprs_rlcmac_prim *rlcmac_prim) +{ + int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); + rc = 1; /* msg owned (freed) */ + return rc; +} + +static int rlcmac_prim_handle_l1ctl_ccch_data_ind(struct osmo_gprs_rlcmac_prim *rlcmac_prim) +{ + int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); + rc = 1; /* msg owned (freed) */ + return rc; +} + +static int gprs_rlcmac_prim_l1ctl_lower_up(struct osmo_gprs_rlcmac_prim *rlcmac_prim) +{ + int rc; + + switch (OSMO_PRIM_HDR(&rlcmac_prim->oph)) { + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_PDCH_RTS, PRIM_OP_INDICATION): + rc = rlcmac_prim_handle_l1ctl_pdch_rts_ind(rlcmac_prim); + break; + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_PDCH_DATA, PRIM_OP_INDICATION): + rc = rlcmac_prim_handle_l1ctl_pdch_data_ind(rlcmac_prim); + break; + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_CCCH_DATA, PRIM_OP_INDICATION): + rc = rlcmac_prim_handle_l1ctl_ccch_data_ind(rlcmac_prim); + break; + default: + rc = -ENOTSUP; + } + return rc; +} + int osmo_gprs_rlcmac_prim_lower_up(struct osmo_gprs_rlcmac_prim *rlcmac_prim) { OSMO_ASSERT(g_ctx); @@ -331,10 +486,9 @@ LOGRLCMAC(LOGL_INFO, "Rx from lower layers: %s\n", osmo_gprs_rlcmac_prim_name(rlcmac_prim)); switch (rlcmac_prim->oph.sap) { - // TODO - //case OSMO_GPRS_LLC_SAP_GRR: - // OSMO_ASSERT(g_ctx->location == OSMO_GPRS_LLC_LOCATION_MS); - // rc = gprs_rlcmac_prim_lower_up_grr(rlcmac_prim); + case OSMO_GPRS_RLCMAC_SAP_L1CTL: + rc = gprs_rlcmac_prim_l1ctl_lower_up(rlcmac_prim); + break; default: rc = -EINVAL; } diff --git a/tests/rlcmac/Makefile.am b/tests/rlcmac/Makefile.am index 9ea8f16..949aed6 100644 --- a/tests/rlcmac/Makefile.am +++ b/tests/rlcmac/Makefile.am @@ -11,6 +11,7 @@ check_PROGRAMS = \ csn1_ts_44_018_test \ csn1_ts_44_060_test \ + rlcmac_prim_test \ $(NULL) EXTRA_DIST = \ @@ -18,6 +19,8 @@ csn1_ts_44_018_test.err \ csn1_ts_44_060_test.ok \ csn1_ts_44_060_test.err \ + rlcmac_prim_test.ok \ + rlcmac_prim_test.err \ $(NULL) # Common LDADD entries @@ -32,3 +35,6 @@ csn1_ts_44_060_test_SOURCES = csn1_ts_44_060_test.c csn1_ts_44_060_test_LDADD = $(LDADD) + +rlcmac_prim_test_SOURCES = rlcmac_prim_test.c +rlcmac_prim_test_LDADD = $(LDADD) diff --git a/tests/rlcmac/rlcmac_prim_test.c b/tests/rlcmac/rlcmac_prim_test.c new file mode 100644 index 0000000..9347b01 --- /dev/null +++ b/tests/rlcmac/rlcmac_prim_test.c @@ -0,0 +1,211 @@ +/* rlcmac_prim_test.c + * + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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. + */ + +#include <stdint.h> +#include <stdio.h> + +#include <osmocom/core/application.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/fsm.h> + +#include <osmocom/gprs/rlcmac/rlcmac.h> +#include <osmocom/gprs/rlcmac/gre.h> + +static void *tall_ctx = NULL; + +/** +MS-SGSN LLC (Mobile Station - Serving GPRS Support Node Logical Link Control) SAPI: GPRS Mobility Management + Address field SAPI: LLGMM + 0... .... = Protocol Discriminator_bit: OK + .0.. .... = Command/Response bit: DownLink/UpLink = Response/Command + .... 0001 = SAPI: GPRS Mobility Management (1) + Unconfirmed Information format - UI: UI format: 0x6, Spare bits: 0x0, N(U): 0, E bit: non encrypted frame, PM bit: FCS covers only the frame header and first N202 octets of the information field + 110. .... .... .... = UI format: 0x6 + ...0 0... .... .... = Spare bits: 0x0 + .... .000 0000 00.. = N(U): 0 + .... .... .... ..0. = E bit: non encrypted frame + .... .... .... ...0 = PM bit: FCS covers only the frame header and first N202 octets of the information field + FCS: 0xf218e2 (correct) +GSM A-I/F DTAP - Attach Request + Protocol Discriminator: GPRS mobility management messages (8) + DTAP GPRS Mobility Management Message Type: Attach Request (0x01) + MS Network Capability + Attach Type + Ciphering Key Sequence Number + DRX Parameter + Mobile Identity - IMSI (262420000000017) + Routing Area Identification - Old routing area identification - RAI: 262-42-27780-68 + MS Radio Access Capability +*/ +static uint8_t pdu_llc_gmm_att_req[] = { + 0x01, 0xc0, 0x00, 0x08, 0x01, 0x01, 0xd5, 0x71, 0x00, 0x00, 0x08, 0x29, 0x26, + 0x24, 0x00, 0x00, 0x00, 0x00, 0x71, 0x62, 0xf2, 0x24, 0x6c, 0x84, 0x44, 0x04, + 0x11, 0xe5, 0x10, 0x00, 0xe2, 0x18, 0xf2 +}; + +/** +GSM CCCH - Immediate Assignment + L2 Pseudo Length + 0010 11.. = L2 Pseudo Length value: 11 + .... 0110 = Protocol discriminator: Radio Resources Management messages (0x6) + .... 0110 = Protocol discriminator: Radio Resources Management messages (0x6) + 0000 .... = Skip Indicator: No indication of selected PLMN (0) + Message Type: Immediate Assignment + Page Mode + .... 0000 = Page Mode: Normal paging (0) + Dedicated mode or TBF + 0001 .... = Dedicated mode or TBF: This message assigns an uplink TBF or is the second message of two in a two-message assignment of an uplink or downlink TBF (1) + Packet Channel Description + 0000 1... = Channel Type: 1 + .... .111 = Timeslot: 7 + 111. .... = Training Sequence: 7 + .... .0.. = Spare: 0x00 + .... ..11 0110 0111 = Single channel ARFCN: 871 + Request Reference + Random Access Information (RA): 120 + 0000 1... = T1': 1 + .... .001 011. .... = T3: 11 + ...0 1011 = T2: 11 + [RFN: 1337] + Timing Advance + Timing advance value: 0 + Mobile Allocation + Length: 0 + IA Rest Octets + H... .... = First Discriminator Bit: High + .H.. .... = Second Discriminator Bit: High + ..0. .... = Discriminator Bit: Packet Assignment + ...0 .... = Discriminator Bit: Packet Uplink Assignment + Packet Uplink Assignment + .... 1... = Packet Uplink Assignment: Normal + .... .000 00.. .... = TFI_Assignment: 0 + ..0. .... = Polling: no action is required from MS + ...0 .... = Allocation Type: Dynamic Allocation (mandatory after Rel-4) + .... 000. = USF: 0 + .... ...0 = USF_granularity: the mobile station shall transmit one RLC/MAC block + 0... .... = P0: Not Present + .01. .... = Channel_Coding_Command: CS-2 (1) + ...1 .... = TLLI_Block_Channel_Coding: mobile station shall use coding scheme as specified by the corresponding CHANNEL CODING COMMAND or EGPRS CHANNEL CODING COMMAND field + .... 0... = Alpha: Not Present + .... .000 00.. .... = Gamma: 0 dB (0) + ..0. .... = Timing Advance Index: Not Present + ...0 .... = TBF Starting Time: Not Present + .... L... = Additions in R99: Not Present + .... .L.. = Additions in Rel-6: Not Present + .... ..L. = Additions in Rel-10: Not Present + .... ...L = Additions in Rel-13: Not Present + Padding Bits: default padding +*/ +static uint8_t ccch_imm_ass_pkt_ul_tbf_normal[] = { + 0x2d, 0x06, 0x3f, 0x10, 0x0f, 0xe3, 0x67, 0x78, 0x09, 0x6b, + 0x00, 0x00, 0xc8, 0x00, 0x30, 0x0b, + 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b +}; + +static int test_rlcmac_prim_up_cb(struct osmo_gprs_rlcmac_prim *rlcmac_prim, void *user_data) +{ + const char *pdu_name = osmo_gprs_rlcmac_prim_name(rlcmac_prim); + + switch (rlcmac_prim->oph.sap) { + case OSMO_GPRS_RLCMAC_SAP_GMMRR: + printf("%s(): Rx %s TLLI=0x%08x\n", __func__, pdu_name, rlcmac_prim->gmmrr.page_ind.tlli); + break; + case OSMO_GPRS_RLCMAC_SAP_GRR: + printf("%s(): Rx %s TLLI=0x%08x SAPI=%s ll=[%s]\n", __func__, pdu_name, + rlcmac_prim->grr.tlli, + get_value_string(osmo_gprs_rlcmac_llc_sapi_names, rlcmac_prim->grr.unitdata_req.sapi), + osmo_hexdump(rlcmac_prim->grr.ll_pdu, rlcmac_prim->grr.ll_pdu_len)); + break; + default: + printf("%s(): Unexpected Rx %s\n", __func__, pdu_name); + OSMO_ASSERT(0); + } + return 0; +} + +static int test_rlcmac_prim_down_cb(struct osmo_gprs_rlcmac_prim *rlcmac_prim, void *user_data) +{ + const char *pdu_name = osmo_gprs_rlcmac_prim_name(rlcmac_prim); + + switch (rlcmac_prim->oph.sap) { + case OSMO_GPRS_RLCMAC_SAP_L1CTL: + printf("%s(): Rx %s\n", __func__, pdu_name); + break; + default: + printf("%s(): Unexpected Rx %s\n", __func__, pdu_name); + OSMO_ASSERT(0); + } + return 0; +} + +void prepare_test(void) +{ + int rc; + rc = osmo_gprs_rlcmac_init(OSMO_GPRS_RLCMAC_LOCATION_MS); + OSMO_ASSERT(rc == 0); + + osmo_gprs_rlcmac_prim_set_up_cb(test_rlcmac_prim_up_cb, NULL); + osmo_gprs_rlcmac_prim_set_down_cb(test_rlcmac_prim_down_cb, NULL); +} + +static void test_ul_tbf_attach(void) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + int rc; + + printf("=== %s start ===\n", __func__); + prepare_test(); + uint32_t tlli = 0x2342; + + rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_grr_unitdata_req(tlli, pdu_llc_gmm_att_req, + sizeof(pdu_llc_gmm_att_req)); + rlcmac_prim->grr.unitdata_req.sapi = OSMO_GPRS_RLCMAC_LLC_SAPI_GMM; + rc = osmo_gprs_rlcmac_prim_upper_down(rlcmac_prim); + + OSMO_ASSERT(sizeof(ccch_imm_ass_pkt_ul_tbf_normal) == GSM_MACBLOCK_LEN); + rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_l1ctl_ccch_data_ind(0, ccch_imm_ass_pkt_ul_tbf_normal); + rc = osmo_gprs_rlcmac_prim_lower_up(rlcmac_prim); + + /* This now fails because it's not yet implemented: */ + OSMO_ASSERT(rc != 0); + printf("=== %s end ===\n", __func__); +} + +static const struct log_info_cat test_log_categories[] = { }; +static const struct log_info test_log_info = { + .cat = test_log_categories, + .num_cat = ARRAY_SIZE(test_log_categories), +}; + +int main(int argc, char *argv[]) +{ + tall_ctx = talloc_named_const(NULL, 1, __FILE__); + + osmo_init_logging2(tall_ctx, &test_log_info); + log_parse_category_mask(osmo_stderr_target, "DLGLOBAL,1:"); + osmo_fsm_log_addr(false); + + log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); + log_set_print_category_hex(osmo_stderr_target, 0); + log_set_print_category(osmo_stderr_target, 1); + log_set_print_level(osmo_stderr_target, 1); + log_set_use_color(osmo_stderr_target, 0); + + test_ul_tbf_attach(); + + talloc_free(tall_ctx); +} diff --git a/tests/rlcmac/rlcmac_prim_test.err b/tests/rlcmac/rlcmac_prim_test.err new file mode 100644 index 0000000..f9268b1 --- /dev/null +++ b/tests/rlcmac/rlcmac_prim_test.err @@ -0,0 +1,4 @@ +DLGLOBAL INFO Rx from upper layers: GRR-UNITDATA.request +DLGLOBAL INFO TLLI=0x00002342 not found, creating entity on the fly +DLGLOBAL INFO Rx from lower layers: L1CTL-CCCH_DATA.indication +DLGLOBAL ERROR Unsupported rlcmac_prim! L1CTL-CCCH_DATA.indication diff --git a/tests/rlcmac/rlcmac_prim_test.ok b/tests/rlcmac/rlcmac_prim_test.ok new file mode 100644 index 0000000..3deb5e9 --- /dev/null +++ b/tests/rlcmac/rlcmac_prim_test.ok @@ -0,0 +1,2 @@ +=== test_ul_tbf_attach start === +=== test_ul_tbf_attach end === diff --git a/tests/testsuite.at b/tests/testsuite.at index 87e95b6..e27a320 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -43,6 +43,13 @@ AT_CHECK([$abs_top_builddir/tests/rlcmac/csn1_ts_44_060_test], [0], [expout], [experr]) AT_CLEANUP +AT_SETUP([rlcmac/rlcmac_prim]) +AT_KEYWORDS([rlcmac rlcmac_prim]) +cat $abs_srcdir/rlcmac/rlcmac_prim_test.ok > expout +cat $abs_srcdir/rlcmac/rlcmac_prim_test.err > experr +AT_CHECK([$abs_top_builddir/tests/rlcmac/rlcmac_prim_test], [0], [expout], [experr]) +AT_CLEANUP + AT_SETUP([sndcp/sndcp_prim]) AT_KEYWORDS([sndcp sndcp_prim]) cat $abs_srcdir/sndcp/sndcp_prim_test.ok > expout -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/31177 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I3d97425ec75059ceae983de869419230e8c4df01 Gerrit-Change-Number: 31177 Gerrit-PatchSet: 10 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: Initial implementation of UL TBF assignment and scheduler
by pespin 13 Feb '23

13 Feb '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/31099 ) Change subject: rlcmac: Initial implementation of UL TBF assignment and scheduler ...................................................................... rlcmac: Initial implementation of UL TBF assignment and scheduler This patch is another step towards a working RLC/MAC implementation. It adds: * An initial data model with MS (gprs_rlcmac_entity) and ul_tbf. * A UL_TBF state FSM from initial to FLOW status * A UL_TBF assignemnt FSM, covering both 1phase and 2phase assignments. * Triggering of UL_TBF allocation and assignment FSM when new LLC data is pushed from upper layers. * A scheduler generating some ctrl messages (PktResReq and UlDummyCtrlBlk) when indicated by the network. This patch is pushed as a WIP state since it already contains a considerable amount of code and lots of new files, which can be used/extended at a later point, making parallel contribution easier. Related: OS#5500 Change-Id: I420c57a9d0b63f9c2805a7c2ae8ce85532a48eef --- M include/osmocom/gprs/rlcmac/Makefile.am M include/osmocom/gprs/rlcmac/rlcmac.h A include/osmocom/gprs/rlcmac/rlcmac_enc.h M include/osmocom/gprs/rlcmac/rlcmac_private.h A include/osmocom/gprs/rlcmac/sched.h A include/osmocom/gprs/rlcmac/tbf.h A include/osmocom/gprs/rlcmac/tbf_ul.h A include/osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h A include/osmocom/gprs/rlcmac/tbf_ul_fsm.h A include/osmocom/gprs/rlcmac/types_private.h M src/rlcmac/Makefile.am M src/rlcmac/gre.c M src/rlcmac/misc.c M src/rlcmac/rlcmac.c A src/rlcmac/rlcmac_enc.c M src/rlcmac/rlcmac_prim.c A src/rlcmac/sched.c A src/rlcmac/tbf.c A src/rlcmac/tbf_ul.c A src/rlcmac/tbf_ul_ass_fsm.c A src/rlcmac/tbf_ul_fsm.c M tests/rlcmac/rlcmac_prim_test.c M tests/rlcmac/rlcmac_prim_test.err M tests/rlcmac/rlcmac_prim_test.ok 24 files changed, 1,549 insertions(+), 10 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/include/osmocom/gprs/rlcmac/Makefile.am b/include/osmocom/gprs/rlcmac/Makefile.am index e797480..c529a4e 100644 --- a/include/osmocom/gprs/rlcmac/Makefile.am +++ b/include/osmocom/gprs/rlcmac/Makefile.am @@ -2,7 +2,14 @@ codel.h \ gre.h \ llc_queue.h \ + rlcmac_enc.h \ rlcmac_private.h \ + sched.h \ + tbf.h \ + tbf_ul.h \ + tbf_ul_fsm.h \ + tbf_ul_ass_fsm.h \ + types_private.h \ $(NULL) rlcmac_HEADERS = \ diff --git a/include/osmocom/gprs/rlcmac/rlcmac.h b/include/osmocom/gprs/rlcmac/rlcmac.h index d7bfb0a..2de5687 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac.h +++ b/include/osmocom/gprs/rlcmac/rlcmac.h @@ -17,6 +17,7 @@ enum osmo_gprs_rlcmac_log_cat { OSMO_GPRS_RLCMAC_LOGC_RLCMAC, + OSMO_GPRS_RLCMAC_LOGC_TBFUL, _OSMO_GPRS_RLCMAC_LOGC_MAX, }; diff --git a/include/osmocom/gprs/rlcmac/rlcmac_enc.h b/include/osmocom/gprs/rlcmac/rlcmac_enc.h new file mode 100644 index 0000000..67448c1 --- /dev/null +++ b/include/osmocom/gprs/rlcmac/rlcmac_enc.h @@ -0,0 +1,15 @@ +#pragma once + +/* RLCMAC encoding support functions */ + +#include <stdint.h> + +#include <osmocom/gprs/rlcmac/csn1_defs.h> +#include <osmocom/gprs/rlcmac/types_private.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> + +#define GPRS_RLCMAC_DUMMY_VEC "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b" + +void gprs_rlcmac_enc_prepare_pkt_ul_dummy_block(RlcMacUplink_t *block, uint32_t tlli); + +void gprs_rlcmac_enc_prepare_pkt_resource_req(RlcMacUplink_t *block, struct gprs_rlcmac_ul_tbf *ul_tbf, enum gprs_rlcmac_access_type acc_type); diff --git a/include/osmocom/gprs/rlcmac/rlcmac_private.h b/include/osmocom/gprs/rlcmac/rlcmac_private.h index c10b159..e838c32 100644 --- a/include/osmocom/gprs/rlcmac/rlcmac_private.h +++ b/include/osmocom/gprs/rlcmac/rlcmac_private.h @@ -6,10 +6,27 @@ #include <stddef.h> #include <osmocom/core/msgb.h> +#include <osmocom/core/tdef.h> #include <osmocom/gprs/rlcmac/rlcmac_prim.h> #include <osmocom/gprs/rlcmac/rlcmac.h> +/* 3GPP TS 44.064 § 8.3 TLLI assignment procedures */ +#define GPRS_RLCMAC_TLLI_UNASSIGNED (0xffffffff) + +#define GPRS_RLCMAC_USF_UNUSED 0x07 + +struct gprs_rlcmac_ul_tbf_allocation_ts { + bool allocated; + uint8_t usf; +}; + +struct gprs_rlcmac_ul_tbf_allocation { + uint8_t ul_tfi; + uint8_t num_ts; /* number of allocated TS */ + struct gprs_rlcmac_ul_tbf_allocation_ts ts[8]; +}; + extern int g_rlcmac_log_cat[_OSMO_GPRS_RLCMAC_LOGC_MAX]; #define LOGRLCMAC(lvl, fmt, args...) LOGP(g_rlcmac_log_cat[OSMO_GPRS_RLCMAC_LOGC_RLCMAC], lvl, fmt, ## args) @@ -31,13 +48,18 @@ osmo_gprs_rlcmac_prim_down_cb rlcmac_down_cb; void *rlcmac_down_cb_user_data; + struct osmo_tdef *T_defs; /* timers controlled by RLC/MAC layer */ + struct llist_head gre_list; /* contains (struct gprs_rlcmac_entity)->entry */ + + uint8_t next_ul_tbf_nr; }; extern struct gprs_rlcmac_ctx *g_ctx; /* rlcmac.c */ struct gprs_rlcmac_entity *gprs_rlcmac_find_entity_by_tlli(uint32_t tlli); +int gprs_rlcmac_handle_ccch_imm_ass(const struct gsm48_imm_ass *ia); /* rlcmac_prim.c */ int gprs_rlcmac_prim_call_up_cb(struct osmo_gprs_rlcmac_prim *rlcmac_prim); diff --git a/include/osmocom/gprs/rlcmac/sched.h b/include/osmocom/gprs/rlcmac/sched.h new file mode 100644 index 0000000..d344aea --- /dev/null +++ b/include/osmocom/gprs/rlcmac/sched.h @@ -0,0 +1,12 @@ +/* RLC/MAC scheduler, 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +struct gprs_rlcmac_rts_block_ind { + uint8_t ts; + uint32_t fn; + uint8_t usf; +}; + +int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_rts_block_ind *bi); diff --git a/include/osmocom/gprs/rlcmac/tbf.h b/include/osmocom/gprs/rlcmac/tbf.h new file mode 100644 index 0000000..df5698f --- /dev/null +++ b/include/osmocom/gprs/rlcmac/tbf.h @@ -0,0 +1,25 @@ +/* TBF, 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +struct gprs_rlcmac_entity; + +enum gprs_rlcmac_tbf_direction { + GPRS_RLCMAC_TBF_DIR_DL, + GPRS_RLCMAC_TBF_DIR_UL +}; + +struct gprs_rlcmac_tbf { + struct gprs_rlcmac_entity *gre; /* backpointer */ + enum gprs_rlcmac_tbf_direction direction; + const char *name; + uint8_t nr; /* TBF number, separate address space for DL and UL, used to identify TBF. */ +}; + +void gprs_rlcmac_tbf_constructor(struct gprs_rlcmac_tbf *tbf, + enum gprs_rlcmac_tbf_direction direction, + struct gprs_rlcmac_entity *gre); +void gprs_rlcmac_tbf_destructor(struct gprs_rlcmac_tbf *tbf); + +void gprs_rlcmac_tbf_free(struct gprs_rlcmac_tbf *tbf); diff --git a/include/osmocom/gprs/rlcmac/tbf_ul.h b/include/osmocom/gprs/rlcmac/tbf_ul.h new file mode 100644 index 0000000..8d122ae --- /dev/null +++ b/include/osmocom/gprs/rlcmac/tbf_ul.h @@ -0,0 +1,57 @@ +/* Uplink TBF, 3GPP TS 44.060 */ +#pragma once + +#include <inttypes.h> + +#include <osmocom/core/msgb.h> + +#include <osmocom/gprs/rlcmac/tbf.h> +#include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> +#include <osmocom/gprs/rlcmac/sched.h> +#include <osmocom/gprs/rlcmac/rlcmac_private.h> + +struct gprs_rlcmac_ul_tbf { + struct gprs_rlcmac_tbf tbf; + struct gprs_rlcmac_tbf_ul_fsm_ctx state_fsm; + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx ul_ass_fsm; + + struct gprs_rlcmac_ul_tbf_allocation cur_alloc; +}; + +struct gprs_rlcmac_ul_tbf *gprs_rlcmac_ul_tbf_alloc(struct gprs_rlcmac_entity *gre); +void gprs_rlcmac_ul_tbf_free(struct gprs_rlcmac_ul_tbf *ul_tbf); + +bool gprs_rlcmac_ul_tbf_data_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); +bool gprs_rlcmac_ul_tbf_dummy_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); + +struct msgb *gprs_rlcmac_ul_tbf_data_create(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); +struct msgb *gprs_rlcmac_ul_tbf_dummy_create(const struct gprs_rlcmac_ul_tbf *ul_tbf); + + +static inline struct gprs_rlcmac_tbf *ul_tbf_as_tbf(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + return &ul_tbf->tbf; +} + +static inline const struct gprs_rlcmac_tbf *ul_tbf_as_tbf_const(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + return &ul_tbf->tbf; +} + +static inline struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf(struct gprs_rlcmac_tbf *tbf) +{ + OSMO_ASSERT(tbf->direction == GPRS_RLCMAC_TBF_DIR_UL); + return (struct gprs_rlcmac_ul_tbf *)tbf; +} + +static inline const struct gprs_rlcmac_ul_tbf *tbf_as_ul_tbf_const(struct gprs_rlcmac_tbf *tbf) +{ + OSMO_ASSERT(tbf->direction == GPRS_RLCMAC_TBF_DIR_UL); + return (const struct gprs_rlcmac_ul_tbf *)tbf; +} + +#define LOGPTBFUL(ul_tbf, lvl, fmt, args...) \ + LOGP(g_rlcmac_log_cat[OSMO_GPRS_RLCMAC_LOGC_TBFUL], lvl, "TBF(UL:NR-%" PRIu8 ":TLLI-%08x) " fmt, \ + (ul_tbf)->tbf.nr, (ul_tbf)->tbf.gre->tlli, \ + ## args) diff --git a/include/osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h b/include/osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h new file mode 100644 index 0000000..28a51af --- /dev/null +++ b/include/osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h @@ -0,0 +1,78 @@ +/* UL TBF Assignment FSM, 3GPP TS 44.060 */ +#pragma once + +#include <stdint.h> + +#include <osmocom/core/fsm.h> +#include <osmocom/core/msgb.h> + +#include <osmocom/gprs/rlcmac/csn1_defs.h> +#include <osmocom/gprs/rlcmac/rlcmac_private.h> + +struct gprs_rlcmac_ul_tbf; +struct gprs_rlcmac_rts_block_ind; + +enum gprs_rlcmac_tbf_ul_ass_type { + GPRS_RLCMAC_TBF_UL_ASS_TYPE_1PHASE, + GPRS_RLCMAC_TBF_UL_ASS_TYPE_2PHASE, +}; + +enum gprs_rlcmac_tbf_ul_ass_fsm_states { + GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE = 0, /* new created TBF */ + GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS, /* wait for Immediate Assignment */ + GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ, /* wait PDCH sched (USF) */ + GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_PKT_UL_ASS, /* Wait for PCU to send the new assignment */ + GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK, /* Wait for scheduler to send PKT CTRL ACK */ + GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL, /* Completed, will update TBF and return to IDLE state */ +}; + +struct gprs_rlcmac_tbf_ul_ass_fsm_ctx { + struct osmo_fsm_inst *fi; + union { /* back pointer. union used to easily access superclass from ctx */ + struct gprs_rlcmac_tbf *tbf; + struct gprs_rlcmac_ul_tbf *ul_tbf; + }; + enum gprs_rlcmac_tbf_ul_ass_type ass_type; + uint8_t rach_req_ra; + struct gprs_rlcmac_ul_tbf_allocation phase1_alloc; + struct gprs_rlcmac_ul_tbf_allocation phase2_alloc; + struct { /* Filled when we receive the poll; exact time here the response PKT CTL ACK is to be transmitted: */ + uint8_t ts; + uint32_t fn; + } sched_pkt_ctrl_ack; +}; + +enum tbf_ul_ass_fsm_event { + GPRS_RLCMAC_TBF_UL_ASS_EV_START, /* Start Uplink assignment (data: enum gprs_rlcmac_tbf_ul_ass_type) */ + GPRS_RLCMAC_TBF_UL_ASS_EV_RX_CCCH_IMM_ASS, /* (data: struct tbf_ul_ass_ev_rx_ccch_imm_ass_ctx *) */ + GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG, /* Generate RLC/MAC block (data: struct tbf_ul_ass_ev_create_rlcmac_msg_ctx) */ + GPRS_RLCMAC_TBF_UL_ASS_EV_RX_PKT_UL_ASS, /* (data: decoded PktUlAss) */ + GPRS_RLCMAC_TBF_UL_ASS_EV_FOOBAR, +}; + +struct tbf_ul_ass_ev_rx_ccch_imm_ass_ctx { + uint8_t ts_nr; + const struct gsm48_imm_ass *ia; + const IA_RestOctets_t *iaro; +}; + +struct tbf_ul_ass_ev_create_rlcmac_msg_ctx { + uint8_t ts; /* TS where the created UL ctrl block is to be sent */ + uint32_t fn; /* FN where the created UL ctrl block is to be sent */ + struct msgb *msg; /* to be filled by FSM during event processing */ +}; + +int gprs_rlcmac_tbf_ul_ass_fsm_init(void); +void gprs_rlcmac_tbf_ul_ass_fsm_set_log_cat(int logcat); + +int gprs_rlcmac_tbf_ul_ass_fsm_constructor(struct gprs_rlcmac_ul_tbf *ul_tbf); +void gprs_rlcmac_tbf_ul_ass_fsm_destructor(struct gprs_rlcmac_ul_tbf *ul_tbf); + +int gprs_rlcmac_tbf_ul_ass_start(struct gprs_rlcmac_ul_tbf *ul_tbf, enum gprs_rlcmac_tbf_ul_ass_type type); +bool gprs_rlcmac_tbf_ul_ass_pending(struct gprs_rlcmac_ul_tbf *ul_tbf); +bool gprs_rlcmac_tbf_ul_ass_match_rach_req(struct gprs_rlcmac_ul_tbf *ul_tbf, uint8_t ra); +bool gprs_rlcmac_tbf_ul_ass_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi); +struct msgb *gprs_rlcmac_tbf_ul_ass_create_rlcmac_msg(const struct gprs_rlcmac_ul_tbf *ul_tbf, + const struct gprs_rlcmac_rts_block_ind *bi); + +enum gprs_rlcmac_tbf_ul_ass_fsm_states gprs_rlcmac_tbf_ul_ass_state(const struct gprs_rlcmac_ul_tbf *ul_tbf); diff --git a/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h b/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h new file mode 100644 index 0000000..7aa4b1e --- /dev/null +++ b/include/osmocom/gprs/rlcmac/tbf_ul_fsm.h @@ -0,0 +1,36 @@ +/* Uplink TBF, 3GPP TS 44.060 */ +#pragma once + +#include <osmocom/core/fsm.h> + +#include <osmocom/gprs/rlcmac/rlcmac_private.h> + +struct gprs_rlcmac_ul_tbf; + +enum gprs_rlcmac_tbf_ul_fsm_states { + GPRS_RLCMAC_TBF_UL_ST_NEW = 0, /* new created TBF */ + GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN, /* wait for Immediate Assignment */ + GPRS_RLCMAC_TBF_UL_ST_FLOW, /* RLC/MAC flow, resource needed */ +}; + +struct gprs_rlcmac_tbf_ul_fsm_ctx { + struct osmo_fsm_inst *fi; + union { /* back pointer. union used to easily access superclass from ctx */ + struct gprs_rlcmac_tbf *tbf; + struct gprs_rlcmac_ul_tbf *ul_tbf; + }; +}; + +enum tbf_ul_fsm_event { + GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, + GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, + GPRS_RLCMAC_TBF_UL_EV_FOOBAR, +}; + +int gprs_rlcmac_tbf_ul_fsm_init(void); +void gprs_rlcmac_tbf_ul_fsm_set_log_cat(int logcat); + +int gprs_rlcmac_tbf_ul_fsm_constructor(struct gprs_rlcmac_ul_tbf *ul_tbf); +void gprs_rlcmac_tbf_ul_fsm_destructor(struct gprs_rlcmac_ul_tbf *ul_tbf); + +enum gprs_rlcmac_tbf_ul_fsm_states gprs_rlcmac_tbf_ul_state(const struct gprs_rlcmac_ul_tbf *ul_tbf); diff --git a/include/osmocom/gprs/rlcmac/types_private.h b/include/osmocom/gprs/rlcmac/types_private.h new file mode 100644 index 0000000..10852cf --- /dev/null +++ b/include/osmocom/gprs/rlcmac/types_private.h @@ -0,0 +1,32 @@ +/* Types & defines from TS 44.060, TS 44.064, private extensions */ +#pragma once + +#include <osmocom/gprs/rlcmac/types.h> + +/* TS 44.060 Table 11.2.16.2 "ACCESS_TYPE" */ +enum gprs_rlcmac_access_type { + GPRS_RLCMAC_ACCESS_TYPE_2PHASE_ACC_REQ = 0, /* Two Phase Access Request */ + GPRS_RLCMAC_ACCESS_TYPE_PAGE_RESP = 1, /* Page Response */ + GPRS_RLCMAC_ACCESS_TYPE_CELL_UPD = 2, /* Cell Update */ + GPRS_RLCMAC_ACCESS_TYPE_MM = 3, /* Mobility Management procedure */ +}; + +/* TS 44.060 Table Table 11.2.5. "Radio Priority" */ +enum gprs_rlcmac_radio_priority { + GPRS_RLCMAC_RADIO_PRIORITY_1 = 0, /* Radio Priority 1 (Highest priority) */ + GPRS_RLCMAC_RADIO_PRIORITY_2 = 1, /* Radio Priority 2 */ + GPRS_RLCMAC_RADIO_PRIORITY_3 = 2, /* Radio Priority 3 */ + GPRS_RLCMAC_RADIO_PRIORITY_4 = 3, /* Radio Priority 4 (Lower priority) */ +}; + +/* TS 44.060 Table Table 12.7.2 "RLC_MODE" */ +enum gprs_rlcmac_rlc_mode { + GPRS_RLCMAC_RLC_MODE_ACKNOWLEDGED = 0, + GPRS_RLCMAC_RLC_MODE_UNACKNOWLEDGED = 1, +}; + +/* TS 44.060 Table Table Table 12.7.2 "LLC_PDU_TYPE" */ +enum gprs_rlcmac_llc_pdu_type { + GPRS_RLCMAC_LLC_PDU_TYPE_ACKNOWLEDGED = 0, + GPRS_RLCMAC_LLC_PDU_TYPE_UNACKNOWLEDGED = 1, +}; diff --git a/src/rlcmac/Makefile.am b/src/rlcmac/Makefile.am index 676abe0..fe221a2 100644 --- a/src/rlcmac/Makefile.am +++ b/src/rlcmac/Makefile.am @@ -10,10 +10,12 @@ AM_CFLAGS = \ -Wall \ + $(LIBOSMOGSM_CFLAGS) \ $(LIBOSMOCORE_CFLAGS) \ $(NULL) AM_LDFLAGS = \ + $(LIBOSMOGSM_LIBS) \ $(LIBOSMOCORE_LIBS) \ $(NULL) @@ -29,7 +31,13 @@ gre.c \ llc_queue.c \ rlcmac.c \ + rlcmac_enc.c \ rlcmac_prim.c \ + sched.c \ + tbf.c \ + tbf_ul.c \ + tbf_ul_fsm.c \ + tbf_ul_ass_fsm.c \ ts_44_060.c \ ts_44_064.c \ misc.c \ @@ -43,5 +51,6 @@ libosmo_gprs_rlcmac_la_LIBADD = \ $(top_builddir)/src/csn1/libosmo-csn1.la \ + $(LIBOSMOGSM_LIBS) \ $(LIBOSMOCORE_LIBS) \ $(NULL) diff --git a/src/rlcmac/gre.c b/src/rlcmac/gre.c index 7acd4f6..3d8ba08 100644 --- a/src/rlcmac/gre.c +++ b/src/rlcmac/gre.c @@ -24,6 +24,8 @@ #include <osmocom/gprs/rlcmac/rlcmac.h> #include <osmocom/gprs/rlcmac/rlcmac_prim.h> #include <osmocom/gprs/rlcmac/rlcmac_private.h> +#include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> #include <osmocom/gprs/rlcmac/gre.h> struct gprs_rlcmac_entity *gprs_rlcmac_entity_alloc(uint32_t tlli) @@ -55,6 +57,8 @@ { if (!gre) return; + + gprs_rlcmac_ul_tbf_free(gre->ul_tbf); gprs_rlcmac_llc_queue_free(gre->llc_queue); llist_del(&gre->entry); talloc_free(gre); @@ -69,7 +73,14 @@ if (rc < 0) return rc; - /* TODO: here a new UL TBF will be created if not available yet */ + if (!gre->ul_tbf) { + /* We have new data in the queue but we have no ul_tbf. Allocate one and start UL Assignment. */ + gre->ul_tbf = gprs_rlcmac_ul_tbf_alloc(gre); + if (!gre->ul_tbf) + return -ENOMEM; + /* We always use 1phase for now... */ + rc = gprs_rlcmac_tbf_ul_ass_start(gre->ul_tbf, GPRS_RLCMAC_TBF_UL_ASS_TYPE_1PHASE); + } return rc; } diff --git a/src/rlcmac/misc.c b/src/rlcmac/misc.c index 4885bbf..4edc2b9 100644 --- a/src/rlcmac/misc.c +++ b/src/rlcmac/misc.c @@ -18,6 +18,8 @@ #include <osmocom/core/utils.h> #include <osmocom/core/logging.h> #include <osmocom/gprs/rlcmac/rlcmac.h> +#include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> int g_rlcmac_log_cat[_OSMO_GPRS_RLCMAC_LOGC_MAX] = { [0 ... _OSMO_GPRS_RLCMAC_LOGC_MAX - 1] = DLGLOBAL @@ -27,4 +29,9 @@ { OSMO_ASSERT(logc < _OSMO_GPRS_RLCMAC_LOGC_MAX); g_rlcmac_log_cat[logc] = logc_num; + + if (logc == OSMO_GPRS_RLCMAC_LOGC_TBFUL) { + gprs_rlcmac_tbf_ul_fsm_set_log_cat(logc_num); + gprs_rlcmac_tbf_ul_ass_fsm_set_log_cat(logc_num); + } } diff --git a/src/rlcmac/rlcmac.c b/src/rlcmac/rlcmac.c index 13a3e84..97516d5 100644 --- a/src/rlcmac/rlcmac.c +++ b/src/rlcmac/rlcmac.c @@ -21,28 +21,58 @@ #include <stdbool.h> +#include <osmocom/gsm/rsl.h> + #include <osmocom/gprs/rlcmac/rlcmac.h> #include <osmocom/gprs/rlcmac/rlcmac_prim.h> #include <osmocom/gprs/rlcmac/rlcmac_private.h> +#include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> #include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/csn1_defs.h> #define GPRS_CODEL_SLOW_INTERVAL_MS 4000 struct gprs_rlcmac_ctx *g_ctx; +static struct osmo_tdef T_defs_rlcmac[] = { + { 0 } /* empty item at the end */ +}; + int osmo_gprs_rlcmac_init(enum osmo_gprs_rlcmac_location location) { + bool first_init = true; + int rc; OSMO_ASSERT(location == OSMO_GPRS_RLCMAC_LOCATION_MS || location == OSMO_GPRS_RLCMAC_LOCATION_PCU) - if (g_ctx) + if (g_ctx) { talloc_free(g_ctx); + first_init = false; + } g_ctx = talloc_zero(NULL, struct gprs_rlcmac_ctx); g_ctx->cfg.location = location; g_ctx->cfg.codel.use = true; g_ctx->cfg.codel.interval_msec = GPRS_CODEL_SLOW_INTERVAL_MS; + g_ctx->T_defs = T_defs_rlcmac; INIT_LLIST_HEAD(&g_ctx->gre_list); + osmo_tdefs_reset(g_ctx->T_defs); + + if (first_init) { + rc = gprs_rlcmac_tbf_ul_fsm_init(); + if (rc != 0) { + TALLOC_FREE(g_ctx); + return rc; + } + rc = gprs_rlcmac_tbf_ul_ass_fsm_init(); + if (rc != 0) { + TALLOC_FREE(g_ctx); + return rc; + } + } + return 0; } @@ -71,3 +101,106 @@ } return NULL; } + +static int gprs_rlcmac_handle_ccch_imm_ass_ul_tbf(uint8_t ts_nr, const struct gsm48_imm_ass *ia, const IA_RestOctets_t *iaro) +{ + int rc = -ENOENT; + struct gprs_rlcmac_entity *gre; + struct gprs_rlcmac_ul_tbf *ul_tbf; + struct tbf_ul_ass_ev_rx_ccch_imm_ass_ctx d = { + .ts_nr = ts_nr, + .ia = ia, + .iaro = iaro + }; + + llist_for_each_entry(gre, &g_ctx->gre_list, entry) { + ul_tbf = gre->ul_tbf; + if (!ul_tbf) + continue; + if (!gprs_rlcmac_tbf_ul_ass_match_rach_req(ul_tbf, ia->req_ref.ra)) + continue; + rc = osmo_fsm_inst_dispatch(ul_tbf->ul_ass_fsm.fi, + GPRS_RLCMAC_TBF_UL_ASS_EV_RX_CCCH_IMM_ASS, + &d); + break; + } + return rc; +} + +int gprs_rlcmac_handle_ccch_imm_ass(const struct gsm48_imm_ass *ia) +{ + int rc; + uint8_t ch_type, ch_subch, ch_ts; + IA_RestOctets_t iaro; + const uint8_t *iaro_raw = ((uint8_t *)ia) + sizeof(*ia) + ia->mob_alloc_len; + size_t iaro_raw_len = GSM_MACBLOCK_LEN - (sizeof(*ia) + ia->mob_alloc_len); + + rc = rsl_dec_chan_nr(ia->chan_desc.chan_nr, &ch_type, &ch_subch, &ch_ts); + if (rc != 0) { + LOGRLCMAC(LOGL_ERROR, "rsl_dec_chan_nr(chan_nr=0x%02x) failed\n", + ia->chan_desc.chan_nr); + return rc; + } + + rc = osmo_gprs_rlcmac_decode_imm_ass_ro(&iaro, iaro_raw, iaro_raw_len); + if (rc != 0) { + LOGRLCMAC(LOGL_ERROR, "Failed to decode IA Rest Octets IE\n"); + return rc; + } + + switch (iaro.UnionType) { + case 0: /* iaro.u.ll.* (IA_RestOctetsLL_t) */ + /* TODO: iaro.u.ll.Compressed_Inter_RAT_HO_INFO_IND */ + /* TODO: iaro.u.ll.AdditionsR13.* (IA_AdditionsR13_t) */ + break; + case 1: /* iaro.u.lh.* (IA_RestOctetsLH_t) */ + switch (iaro.u.lh.lh0x.UnionType) { + case 0: /* iaro.u.ll.lh0x.EGPRS_PktUlAss.* (IA_EGPRS_PktUlAss_t) */ + rc = gprs_rlcmac_handle_ccch_imm_ass_ul_tbf(ch_ts, ia, &iaro); + break; + case 1: /* iaro.u.ll.lh0x.MultiBlock_PktDlAss.* (IA_MultiBlock_PktDlAss_t) */ + /* TODO: Alloc DL TBF */ + break; + } + /* TODO: iaro.u.lh.AdditionsR13.* (IA_AdditionsR13_t) */ + break; + case 2: /* iaro.u.hl.* (IA_RestOctetsHL_t) */ + /* TODO: iaro.u.hl.IA_FrequencyParams (IA_FreqParamsBeforeTime_t) */ + /* TODO: iaro.u.hl.Compressed_Inter_RAT_HO_INFO_IND */ + /* TODO: iaro.u.hl.AdditionsR13.* (IA_AdditionsR13_t) */ + break; + case 3: /* iaro.u.hh.* (IA_RestOctetsHH_t) */ + switch (iaro.u.hh.UnionType) { + case 0: /* iaro.u.hh.u.UplinkDownlinkAssignment.* (IA_PacketAssignment_UL_DL_t) */ + switch (iaro.u.hh.u.UplinkDownlinkAssignment.UnionType) { + case 0: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.* (Packet_Uplink_ImmAssignment_t) */ + switch (iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.UnionType) { + case 0: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.SingleBlockAllocation.* (GPRS_SingleBlockAllocation_t) */ + /* TODO: 2phase access support: Schedule transmit of PKT_RES_REQ on FN=(GPRS_SingleBlockAllocation_t).TBF_STARTING_TIME */ + LOGRLCMAC(LOGL_ERROR, "ImmAss SingleBlock (2phase access) not yet supported!\n"); + break; + case 1: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.* (GPRS_DynamicOrFixedAllocation_t) */ + switch (iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.UnionType) { + case 0: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.DynamicAllocation (DynamicAllocation_t) */ + rc = gprs_rlcmac_handle_ccch_imm_ass_ul_tbf(ch_ts, ia, &iaro); + break; + case 1: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.FixedAllocationDummy (guint8) */ + rc = gprs_rlcmac_handle_ccch_imm_ass_ul_tbf(ch_ts, ia, &iaro); + break; + } + break; + } + break; + case 1: /* iaro.u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Downlink_ImmAssignment* (Packet_Downlink_ImmAssignment_t) */ + /* TODO: Alloc DL TBF */ + break; + } + break; + case 1: /* iaro.u.hh.u.SecondPartPacketAssignment.* (Second_Part_Packet_Assignment_t) */ + break; + } + break; + } + + return rc; +} diff --git a/src/rlcmac/rlcmac_enc.c b/src/rlcmac/rlcmac_enc.c new file mode 100644 index 0000000..ef22f05 --- /dev/null +++ b/src/rlcmac/rlcmac_enc.c @@ -0,0 +1,95 @@ +/* RLC/MAC encoding helpers, 3GPP TS 44.060 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <osmocom/gprs/rlcmac/csn1_defs.h> +#include <osmocom/gprs/rlcmac/rlcmac_enc.h> +#include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> + +void gprs_rlcmac_enc_prepare_pkt_ul_dummy_block(RlcMacUplink_t *block, uint32_t tlli) +{ + Packet_Uplink_Dummy_Control_Block_t *dummy; + + memset(block, 0, sizeof(*block)); + + dummy = &block->u.Packet_Uplink_Dummy_Control_Block; + dummy->MESSAGE_TYPE = OSMO_GPRS_RLCMAC_UL_MSGT_PACKET_UPLINK_DUMMY_CONTROL_BLOCK; + /* 10.4.7: RLC/MAC control block that does not include the optional octets of the RLC/MAC control header: */ + dummy->PayloadType = 0x1; + dummy->R = 0; /* MS sent channel request message once */ + dummy->TLLI = tlli; +} + +/* 11.2.16 Packet Resource Request */ +void gprs_rlcmac_enc_prepare_pkt_resource_req(RlcMacUplink_t *block, + struct gprs_rlcmac_ul_tbf *ul_tbf, + enum gprs_rlcmac_access_type acc_type) +{ + Packet_Resource_Request_t *req; + struct gprs_rlcmac_entity *gre = ul_tbf->tbf.gre; + + memset(block, 0, sizeof(*block)); + + req = &block->u.Packet_Resource_Request; + req->MESSAGE_TYPE = OSMO_GPRS_RLCMAC_UL_MSGT_PACKET_RESOURCE_REQUEST; + /* 10.4.7: RLC/MAC control block that does not include the optional octets of the RLC/MAC control header: */ + req->PayloadType = 0x1; + req->R = 0; /* MS sent channel request message once */ + + req->Exist_ACCESS_TYPE = 1; + req->ACCESS_TYPE = acc_type; + + req->ID.UnionType = 1; /* Use TLLI */ + req->ID.u.TLLI = gre->tlli; /* Use TLLI */ + req->Exist_MS_Radio_Access_capability2 = 1; + + req->MS_Radio_Access_capability2.Count_MS_RA_capability_value = 1; + /* TODO: fill Content_t: */ + /* req->MS_Radio_Access_capability2.MS_RA_capability_value[0].Content.* */ + + /* 3GPP TS 24.008 Peak Throughput Class, range 1..9 */ + req->Channel_Request_Description.PEAK_THROUGHPUT_CLASS = 1; + req->Channel_Request_Description.RADIO_PRIORITY = GPRS_RLCMAC_RADIO_PRIORITY_4; + req->Channel_Request_Description.RLC_MODE = GPRS_RLCMAC_RLC_MODE_ACKNOWLEDGED; + req->Channel_Request_Description.LLC_PDU_TYPE = GPRS_RLCMAC_LLC_PDU_TYPE_ACKNOWLEDGED; + req->Channel_Request_Description.RLC_OCTET_COUNT = gprs_rlcmac_llc_queue_octets(gre->llc_queue); + + /* "this field contains the SI13_CHANGE_MARK value stored by the mobile station. + * If the mobile station does not have a valid PSI2 or SI13 change mark for the current cell, + * the mobile station shall omit this field." */ + req->Exist_CHANGE_MARK = 0; + /* req->CHANGE_MARK; */ + + /* TODO: binary representation of the C value as specified in 3GPP TS 45.008. */ + req->C_VALUE = 0; + + /* SIGN_VAR: "This field is not present for TBF establishment using two phase access or for + * a TBF in EGPRS mode" (see 3GPP TS 45.008) */ + if (acc_type != GPRS_RLCMAC_ACCESS_TYPE_2PHASE_ACC_REQ) { + req->Exist_SIGN_VAR = 1; + req->SIGN_VAR = 0; /* TODO: calculate */ + } + + /* For element definition see sub-clause 11.2.6 - Packet Downlink Ack/Nack. */ + /* TODO: req->I_LEVEL_TN[8]; */ + + req->Exist_AdditionsR99 = 0; + /* TODO: no req->AdditionsR99 yet */ +} diff --git a/src/rlcmac/rlcmac_prim.c b/src/rlcmac/rlcmac_prim.c index a2f2576..ef0dd22 100644 --- a/src/rlcmac/rlcmac_prim.c +++ b/src/rlcmac/rlcmac_prim.c @@ -31,11 +31,14 @@ #include <osmocom/core/logging.h> #include <osmocom/crypt/gprs_cipher.h> #include <osmocom/gsm/gsm_utils.h> +#include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/gprs/rlcmac/rlcmac.h> #include <osmocom/gprs/rlcmac/rlcmac_prim.h> #include <osmocom/gprs/rlcmac/rlcmac_private.h> #include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> #define RLCMAC_MSGB_HEADROOM 0 @@ -437,8 +440,14 @@ static int rlcmac_prim_handle_l1ctl_pdch_rts_ind(struct osmo_gprs_rlcmac_prim *rlcmac_prim) { - int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); - rc = 1; /* msg owned (freed) */ + int rc; + struct gprs_rlcmac_rts_block_ind bi = { + .ts = rlcmac_prim->l1ctl.pdch_rts_ind.ts_nr, + .fn = rlcmac_prim->l1ctl.pdch_rts_ind.fn, + .usf = rlcmac_prim->l1ctl.pdch_rts_ind.usf, + }; + + rc = gprs_rlcmac_rcv_rts_block(&bi); return rc; } @@ -451,8 +460,13 @@ static int rlcmac_prim_handle_l1ctl_ccch_data_ind(struct osmo_gprs_rlcmac_prim *rlcmac_prim) { - int rc = gprs_rlcmac_prim_handle_unsupported(rlcmac_prim); - rc = 1; /* msg owned (freed) */ + /* TODO: check if it's IMM_ASS: */ + int rc; + + if (rlcmac_prim->l1ctl.ccch_data_ind.data[2] == GSM48_MT_RR_IMM_ASS) + rc = gprs_rlcmac_handle_ccch_imm_ass((struct gsm48_imm_ass *)rlcmac_prim->l1ctl.ccch_data_ind.data); + else + rc = -ENOTSUP; return rc; } diff --git a/src/rlcmac/sched.c b/src/rlcmac/sched.c new file mode 100644 index 0000000..93dc50f --- /dev/null +++ b/src/rlcmac/sched.c @@ -0,0 +1,136 @@ +/* RLC/MAC scheduler, 3GPP TS 44.060 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <osmocom/core/linuxlist.h> +#include <osmocom/core/msgb.h> + +#include <osmocom/gprs/rlcmac/rlcmac_private.h> +#include <osmocom/gprs/rlcmac/sched.h> +#include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> + +struct tbf_sched_ctrl_candidates { + struct gprs_rlcmac_ul_tbf *ul_ass; +}; + +static void get_ctrl_msg_tbf_candidates(const struct gprs_rlcmac_rts_block_ind *bi, + struct tbf_sched_ctrl_candidates *tbfs) +{ + + struct gprs_rlcmac_entity *gre; + struct gprs_rlcmac_ul_tbf *ul_tbf; + + /* Iterate over UL TBFs: */ + llist_for_each_entry(gre, &g_ctx->gre_list, entry) { + if (!gre->ul_tbf) + continue; + ul_tbf = gre->ul_tbf; + if (gprs_rlcmac_tbf_ul_ass_rts(ul_tbf, bi)) + tbfs->ul_ass = ul_tbf; + } + + /* TODO: Iterate over DL TBFs: */ +} + +static struct gprs_rlcmac_ul_tbf *find_requested_ul_tbf_for_data(const struct gprs_rlcmac_rts_block_ind *bi) +{ + struct gprs_rlcmac_entity *gre; + llist_for_each_entry(gre, &g_ctx->gre_list, entry) { + if (!gre->ul_tbf) + continue; + if (gprs_rlcmac_ul_tbf_data_rts(gre->ul_tbf, bi)) + return gre->ul_tbf; + } + return NULL; +} + +static struct gprs_rlcmac_ul_tbf *find_requested_ul_tbf_for_dummy(const struct gprs_rlcmac_rts_block_ind *bi) +{ + struct gprs_rlcmac_entity *gre; + llist_for_each_entry(gre, &g_ctx->gre_list, entry) { + if (!gre->ul_tbf) + continue; + if (gprs_rlcmac_ul_tbf_dummy_rts(gre->ul_tbf, bi)) + return gre->ul_tbf; + } + return NULL; +} + +static struct msgb *sched_select_ctrl_msg(const struct gprs_rlcmac_rts_block_ind *bi, + struct tbf_sched_ctrl_candidates *tbfs) +{ + struct msgb *msg = NULL; + if (tbfs->ul_ass) + msg = gprs_rlcmac_tbf_ul_ass_create_rlcmac_msg(tbfs->ul_ass, bi); + return msg; +} + +static struct msgb *sched_select_ul_data_msg(const struct gprs_rlcmac_rts_block_ind *bi) +{ + struct gprs_rlcmac_ul_tbf *ul_tbf; + + ul_tbf = find_requested_ul_tbf_for_data(bi); + if (!ul_tbf) { + LOGRLCMAC(LOGL_DEBUG, "(ts=%u,fn=%u,usf=%u) No Uplink TBF available to transmit RLC/MAC Ul Data Block\n", + bi->ts, bi->fn, bi->usf); + return NULL; + } + return gprs_rlcmac_ul_tbf_data_create(ul_tbf, bi); +} + +static struct msgb *sched_select_ul_dummy_ctrl_blk(const struct gprs_rlcmac_rts_block_ind *bi) +{ + struct gprs_rlcmac_ul_tbf *ul_tbf; + + ul_tbf = find_requested_ul_tbf_for_dummy(bi); + if (!ul_tbf) { + LOGRLCMAC(LOGL_DEBUG, "(ts=%u,fn=%u,usf=%u) No Uplink TBF available to transmit RLC/MAC Ul Dummy Ctrl Block\n", + bi->ts, bi->fn, bi->usf); + return NULL; + } + + return gprs_rlcmac_ul_tbf_dummy_create(ul_tbf); +} + +int gprs_rlcmac_rcv_rts_block(struct gprs_rlcmac_rts_block_ind *bi) +{ + struct msgb *msg = NULL; + struct tbf_sched_ctrl_candidates tbf_cand = {0}; + + get_ctrl_msg_tbf_candidates(bi, &tbf_cand); + + if ((msg = sched_select_ctrl_msg(bi, &tbf_cand))) + goto tx_msg; + + if ((msg = sched_select_ul_data_msg(bi))) + goto tx_msg; + + /* Prio 3: send dummy control message (or nothing depending on EXT_UTBF_NODATA) */ + if ((msg = sched_select_ul_dummy_ctrl_blk(bi))) + goto tx_msg; + + /* Nothing to transmit */ + return 0; +tx_msg: + /* TODO: transmit msg to lower layer (L1CTL?) */ + return 0; +} diff --git a/src/rlcmac/tbf.c b/src/rlcmac/tbf.c new file mode 100644 index 0000000..ea15d69 --- /dev/null +++ b/src/rlcmac/tbf.c @@ -0,0 +1,43 @@ +/* TBF as per 3GPP TS 44.064 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <osmocom/gprs/rlcmac/tbf.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> + +void gprs_rlcmac_tbf_constructor(struct gprs_rlcmac_tbf *tbf, + enum gprs_rlcmac_tbf_direction direction, + struct gprs_rlcmac_entity *gre) +{ + tbf->gre = gre; + tbf->direction = direction; +} + +void gprs_rlcmac_tbf_destructor(struct gprs_rlcmac_tbf *tbf) +{ + +} + +void gprs_rlcmac_tbf_free(struct gprs_rlcmac_tbf *tbf) +{ + if (tbf->direction == GPRS_RLCMAC_TBF_DIR_UL) + gprs_rlcmac_ul_tbf_free(tbf_as_ul_tbf(tbf)); + /* else: TODO dl_tbf not yet implemented */ +} diff --git a/src/rlcmac/tbf_ul.c b/src/rlcmac/tbf_ul.c new file mode 100644 index 0000000..54ecd34 --- /dev/null +++ b/src/rlcmac/tbf_ul.c @@ -0,0 +1,134 @@ +/* Uplink TBF as per 3GPP TS 44.064 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <osmocom/core/bitvec.h> + +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/rlcmac_enc.h> +#include <osmocom/gprs/rlcmac/gre.h> + +struct gprs_rlcmac_ul_tbf *gprs_rlcmac_ul_tbf_alloc(struct gprs_rlcmac_entity *gre) +{ + struct gprs_rlcmac_ul_tbf *ul_tbf; + int rc; + + ul_tbf = talloc_zero(gre, struct gprs_rlcmac_ul_tbf); + if (!ul_tbf) + return NULL; + + gprs_rlcmac_tbf_constructor(ul_tbf_as_tbf(ul_tbf), GPRS_RLCMAC_TBF_DIR_UL, gre); + + rc = gprs_rlcmac_tbf_ul_fsm_constructor(ul_tbf); + if (rc < 0) + goto err_tbf_destruct; + + rc = gprs_rlcmac_tbf_ul_ass_fsm_constructor(ul_tbf); + if (rc < 0) + goto err_state_fsm_destruct; + + ul_tbf->tbf.nr = g_ctx->next_ul_tbf_nr++; + + return ul_tbf; + +err_state_fsm_destruct: + gprs_rlcmac_tbf_destructor(ul_tbf_as_tbf(ul_tbf)); +err_tbf_destruct: + gprs_rlcmac_tbf_destructor(ul_tbf_as_tbf(ul_tbf)); + talloc_free(ul_tbf); + return NULL; +} + +void gprs_rlcmac_ul_tbf_free(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + if (!ul_tbf) + return; + + gprs_rlcmac_tbf_ul_ass_fsm_destructor(ul_tbf); + gprs_rlcmac_tbf_ul_fsm_destructor(ul_tbf); + + gprs_rlcmac_tbf_destructor(ul_tbf_as_tbf(ul_tbf)); + talloc_free(ul_tbf); +} + +/* Used by the scheduler to find out whether an Uplink Dummy Control Block can be transmitted. If + * true, it will potentially call gprs_rlcmac_ul_tbf_dummy_create() to generate a new dummy message to transmit. */ +bool gprs_rlcmac_ul_tbf_dummy_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + if (!ul_tbf->cur_alloc.ts[bi->ts].allocated) + return false; + if (ul_tbf->cur_alloc.ts[bi->ts].usf != bi->usf) + return false; + return true; +} + +/* Used by the scheduler to find out whether there's data to be transmitted at the requested time. If + * true, it will potentially call gprs_rlcmac_ul_tbf_data_create() to generate a new data message to transmit. */ +bool gprs_rlcmac_ul_tbf_data_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + enum gprs_rlcmac_tbf_ul_fsm_states st; + + if (!gprs_rlcmac_ul_tbf_dummy_rts(ul_tbf, bi)) + return false; + + st = gprs_rlcmac_tbf_ul_state(ul_tbf); + return (st == GPRS_RLCMAC_TBF_UL_ST_FLOW); +} + +struct msgb *gprs_rlcmac_ul_tbf_dummy_create(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct msgb *msg; + struct bitvec bv; + RlcMacUplink_t ul_block; + int rc; + + OSMO_ASSERT(ul_tbf); + + msg = msgb_alloc(GSM_MACBLOCK_LEN, "pkt_ul_dummy_ctrl_blk"); + if (!msg) + return NULL; + + /* Initialize a bit vector that uses allocated msgb as the data buffer. */ + bv = (struct bitvec){ + .data = msgb_put(msg, GSM_MACBLOCK_LEN), + .data_len = GSM_MACBLOCK_LEN, + }; + bitvec_unhex(&bv, GPRS_RLCMAC_DUMMY_VEC); + + gprs_rlcmac_enc_prepare_pkt_ul_dummy_block(&ul_block, ul_tbf->tbf.gre->tlli); + rc = osmo_gprs_rlcmac_encode_uplink(&bv, &ul_block); + if (rc < 0) { + LOGPTBFUL(ul_tbf, LOGL_ERROR, "Encoding of Packet Uplink Dummy Control Block failed (%d)\n", rc); + goto free_ret; + } + + return msg; + +free_ret: + msgb_free(msg); + return NULL; +} + +struct msgb *gprs_rlcmac_ul_tbf_data_create(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + LOGPTBFUL(ul_tbf, LOGL_ERROR, "(ts=%u,fn=%u,usf=%u) TODO: implement dequeue from LLC\n", + bi->ts, bi->fn, bi->usf); + return NULL; +} diff --git a/src/rlcmac/tbf_ul_ass_fsm.c b/src/rlcmac/tbf_ul_ass_fsm.c new file mode 100644 index 0000000..1130187 --- /dev/null +++ b/src/rlcmac/tbf_ul_ass_fsm.c @@ -0,0 +1,445 @@ +/* TBF as per 3GPP TS 44.064 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <errno.h> +#include <talloc.h> +#include <osmocom/core/tdef.h> +#include <osmocom/core/fsm.h> +#include <osmocom/core/bitvec.h> + +#include <osmocom/gprs/rlcmac/types.h> +#include <osmocom/gprs/rlcmac/tbf_ul_ass_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/gre.h> +#include <osmocom/gprs/rlcmac/sched.h> +#include <osmocom/gprs/rlcmac/csn1_defs.h> +#include <osmocom/gprs/rlcmac/rlcmac_enc.h> + +#define X(s) (1 << (s)) + +static const struct value_string tbf_ul_ass_fsm_event_names[] = { + { GPRS_RLCMAC_TBF_UL_ASS_EV_START, "START" }, + { GPRS_RLCMAC_TBF_UL_ASS_EV_RX_CCCH_IMM_ASS, "RX_CCCH_IMM_ASS" }, + { GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG, "CREATE_RLCMAC_MSG" }, + { GPRS_RLCMAC_TBF_UL_ASS_EV_RX_PKT_UL_ASS, "RX_PKT_UL_ASS" }, + { GPRS_RLCMAC_TBF_UL_ASS_EV_FOOBAR, "FOOBAR" }, + { 0, NULL } +}; + +static const struct osmo_tdef_state_timeout tbf_ul_ass_fsm_timeouts[32] = { + [GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE] = { }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS] = { }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ] = { }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_PKT_UL_ASS] = { }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK] = { }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL] = { }, +}; + +/* Transition to a state, using the T timer defined in tbf_fsm_timeouts. + * The actual timeout value is in turn obtained from conn->T_defs. + * Assumes local variable fi exists. */ + #define tbf_ul_ass_fsm_state_chg(fi, NEXT_STATE) \ + osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, \ + tbf_ul_ass_fsm_timeouts, \ + g_ctx->T_defs, \ + -1) + +static struct msgb *create_pkt_resource_req(const struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx, + struct tbf_ul_ass_ev_create_rlcmac_msg_ctx *d) +{ + struct msgb *msg; + struct bitvec bv; + RlcMacUplink_t ul_block; + int rc; + + msg = msgb_alloc(GSM_MACBLOCK_LEN, "pkt_res_req"); + if (!msg) + return NULL; + + /* Initialize a bit vector that uses allocated msgb as the data buffer. */ + bv = (struct bitvec){ + .data = msgb_put(msg, GSM_MACBLOCK_LEN), + .data_len = GSM_MACBLOCK_LEN, + }; + bitvec_unhex(&bv, GPRS_RLCMAC_DUMMY_VEC); + + gprs_rlcmac_enc_prepare_pkt_resource_req(&ul_block, ctx->ul_tbf, GPRS_RLCMAC_ACCESS_TYPE_2PHASE_ACC_REQ); + rc = osmo_gprs_rlcmac_encode_uplink(&bv, &ul_block); + if (rc < 0) { + LOGPTBFUL(ctx->ul_tbf, LOGL_ERROR, "Encoding of Packet Resource Req failed (%d)\n", rc); + goto free_ret; + } + + return msg; + +free_ret: + msgb_free(msg); + return NULL; +} + +/* Generate a 8-bit CHANNEL REQUEST message as per 3GPP TS 44.018, 9.1.8 */ +static uint8_t gen_chan_req(bool single_block) +{ + uint8_t rnd = (uint8_t)rand(); + + if (single_block) /* 01110xxx */ + return 0x70 | (rnd & 0x07); + + /* 011110xx or 01111x0x or 01111xx0 */ + if ((rnd & 0x07) == 0x07) + return 0x78; + return 0x78 | (rnd & 0x07); +} + +static int submit_rach_req(struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + ctx->rach_req_ra = gen_chan_req(ctx->ass_type == GPRS_RLCMAC_TBF_UL_ASS_TYPE_2PHASE); + + LOGPFSML(ctx->fi, LOGL_INFO, "Send RACH.req ra=0x%02x\n", ctx->rach_req_ra); + rlcmac_prim = gprs_rlcmac_prim_alloc_l1ctl_rach8_req(ctx->rach_req_ra); + return gprs_rlcmac_prim_call_down_cb(rlcmac_prim); +} + +static int handle_imm_ass(struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx, const struct tbf_ul_ass_ev_rx_ccch_imm_ass_ctx *d) +{ + switch (d->iaro->UnionType) { + case 1: /* d->iaro->u.lh.* (IA_RestOctetsLH_t) */ + switch (d->iaro->u.lh.lh0x.UnionType) { + case 0: /* d->iaro->u.ll.lh0x.EGPRS_PktUlAss.* (IA_EGPRS_PktUlAss_t) */ + return -ENOTSUP; /* TODO */ + } + case 3: /* d->iaro->u.hh.* (IA_RestOctetsHH_t) */ + switch (d->iaro->u.hh.UnionType) { + case 0: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.* (IA_PacketAssignment_UL_DL_t) */ + switch (d->iaro->u.hh.u.UplinkDownlinkAssignment.UnionType) { + case 0: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.* (Packet_Uplink_ImmAssignment_t) */ + switch (d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.UnionType) { + case 0: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.SingleBlockAllocation.* (GPRS_SingleBlockAllocation_t) */ + /* TODO: 2phase access support: Schedule transmit of PKT_RES_REQ on FN=(GPRS_SingleBlockAllocation_t).TBF_STARTING_TIME */ + LOGPFSML(ctx->fi, LOGL_ERROR, "ImmAss SingleBlock (2phase access) not yet supported!\n"); + return -ENOTSUP; + case 1: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.* (GPRS_DynamicOrFixedAllocation_t) */ + //ctx->ul_tbf->tx_cs = d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.CHANNEL_CODING_COMMAND + 1; + //LOGPFSML(ctx->fi, LOGL_INFO, "ImmAss initial CS=%s\n", gprs_rlcmac_mcs_name(ctx->ul_tbf->tx_cs)); + switch (d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.UnionType) { + case 0: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.DynamicAllocation (DynamicAllocation_t) */ + /* TODO: 2phase access support: Schedule transmit of PKT_RES_REQ on FN=(GPRS_SingleBlockAllocation_t).TBF_STARTING_TIME */ + ctx->phase1_alloc.ts[d->ts_nr].allocated = true; + ctx->phase1_alloc.ts[d->ts_nr].usf = d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.DynamicAllocation.USF; + ctx->phase1_alloc.num_ts = 1; + LOGPFSML(ctx->fi, LOGL_INFO, "ImmAss DynamicAlloc (1phase access) ts_nr=%u usf=%u\n", d->ts_nr, ctx->phase1_alloc.ts[d->ts_nr].usf); + return 0; + case 1: /* d->iaro->u.hh.u.UplinkDownlinkAssignment.ul_dl.Packet_Uplink_ImmAssignment.Access.DynamicOrFixedAllocation.Allocation.FixedAllocationDummy (guint8) */ + return -ENOTSUP; + } + break; + } + break; + } + break; + } + break; + } + + OSMO_ASSERT(0); + return -EFAULT; +} + +static void st_idle_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + + /* Reset state: */ + memset(&ctx->phase1_alloc, 0, sizeof(ctx->phase1_alloc)); + memset(&ctx->phase2_alloc, 0, sizeof(ctx->phase2_alloc)); + memset(&ctx->sched_pkt_ctrl_ack, 0, sizeof(ctx->sched_pkt_ctrl_ack)); +} + +static void st_idle(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + switch (event) { + case GPRS_RLCMAC_TBF_UL_ASS_EV_START: + /* Inform the main TBF state about the assignment starting: */ + osmo_fsm_inst_dispatch(ctx->ul_tbf->state_fsm.fi, GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, NULL); + ctx->ass_type = *(enum gprs_rlcmac_tbf_ul_ass_type *)data; + submit_rach_req(ctx); + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_wait_ccch_imm_ass(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + const struct tbf_ul_ass_ev_rx_ccch_imm_ass_ctx *ev_rx_ccch_imm_ass_ctx; + + switch (event) { + case GPRS_RLCMAC_TBF_UL_ASS_EV_RX_CCCH_IMM_ASS: + ev_rx_ccch_imm_ass_ctx = data; + if (handle_imm_ass(ctx, ev_rx_ccch_imm_ass_ctx) < 0) + return; + if (ctx->ass_type == GPRS_RLCMAC_TBF_UL_ASS_TYPE_1PHASE) + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL); + else + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_sched_pkt_res_req(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + struct tbf_ul_ass_ev_create_rlcmac_msg_ctx *data_ctx; + switch (event) { + case GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG: + data_ctx = (struct tbf_ul_ass_ev_create_rlcmac_msg_ctx *)data; + LOGPFSML(fi, LOGL_ERROR, "TODO: create PKT RES REQ...\n"); + data_ctx->msg = create_pkt_resource_req(ctx, data_ctx); + if (!data_ctx->msg) + return; + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_PKT_UL_ASS); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_wait_pkt_ul_ass(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + //struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + switch (event) { + case GPRS_RLCMAC_TBF_UL_ASS_EV_RX_PKT_UL_ASS: + // TODO: fill ctx->phase2_alloc with contents from pkt_ul_ass + // TODO: what to do if Pkt_ul_ass is "reject"? need to check spec, depending on cause. + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_sched_pkt_ctrl_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + //struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + struct tbf_ul_ass_ev_create_rlcmac_msg_ctx *data_ctx; + + switch (event) { + case GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG: + data_ctx = (struct tbf_ul_ass_ev_create_rlcmac_msg_ctx *)data; + LOGPFSML(fi, LOGL_ERROR, "TODO: create PKT CTRL ACK...\n"); + //data_ctx->msg = create_packet_ctrl_ack(ctx, data_ctx); + data_ctx->msg = NULL; + if (!data_ctx->msg) + return; + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_compl_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + + /* Update TBF with allocated content: */ + if (ctx->ass_type == GPRS_RLCMAC_TBF_UL_ASS_TYPE_1PHASE) + memcpy(&ctx->ul_tbf->cur_alloc, &ctx->phase1_alloc, sizeof(ctx->phase1_alloc)); + else + memcpy(&ctx->ul_tbf->cur_alloc, &ctx->phase2_alloc, sizeof(ctx->phase1_alloc)); + /* Inform the main TBF state about the assignment completed: */ + osmo_fsm_inst_dispatch(ctx->ul_tbf->state_fsm.fi, GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, NULL); + /* Go back to IDLE state. */ + tbf_ul_ass_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE); +} + +static struct osmo_fsm_state tbf_ul_ass_fsm_states[] = { + [GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_EV_START), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS), + .name = "IDLE", + .onenter = st_idle_on_enter, + .action = st_idle, + }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_EV_RX_CCCH_IMM_ASS), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ) | + X(GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL), + .name = "WAIT_CCCH_IMM_ASS", + .action = st_wait_ccch_imm_ass, + }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_PKT_UL_ASS), + .name = "SCHED_PKT_RES_REQ", + .action = st_sched_pkt_res_req, + }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_PKT_UL_ASS] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_EV_RX_PKT_UL_ASS), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK), + .name = "WAIT_PKT_UL_ASS", + .action = st_wait_pkt_ul_ass, + }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL), + .name = "SCHED_PKT_CTRL_ACK", + .action = st_sched_pkt_ctrl_ack, + }, + [GPRS_RLCMAC_TBF_UL_ASS_ST_COMPL] = { + .in_event_mask = 0, + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE), + .name = "COMPLETED", + .onenter = st_compl_on_enter, + }, +}; + + +static int tbf_ul_ass_fsm_timer_cb(struct osmo_fsm_inst *fi) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *)fi->priv; + switch (fi->T) { + case -2001: + LOGPTBFUL(ctx->ul_tbf, LOGL_NOTICE, "releasing due to PACCH assignment timeout.\n"); + /* fall-through */ + case 3169: + case 3195: + gprs_rlcmac_ul_tbf_free(ctx->ul_tbf); + break; + default: + OSMO_ASSERT(0); + } + return 0; +} + +static struct osmo_fsm tbf_ul_ass_fsm = { + .name = "UL_TBF_ASS", + .states = tbf_ul_ass_fsm_states, + .num_states = ARRAY_SIZE(tbf_ul_ass_fsm_states), + .timer_cb = tbf_ul_ass_fsm_timer_cb, + .log_subsys = DLGLOBAL, /* updated dynamically through gprs_rlcmac_tbf_ul_ass_fsm_set_log_cat() */ + .event_names = tbf_ul_ass_fsm_event_names, +}; + +int gprs_rlcmac_tbf_ul_ass_fsm_init(void) +{ + return osmo_fsm_register(&tbf_ul_ass_fsm); +} + +void gprs_rlcmac_tbf_ul_ass_fsm_set_log_cat(int logcat) +{ + tbf_ul_ass_fsm.log_subsys = logcat; +} + +int gprs_rlcmac_tbf_ul_ass_fsm_constructor(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = &ul_tbf->ul_ass_fsm; + ctx->ul_tbf = ul_tbf; + ctx->fi = osmo_fsm_inst_alloc(&tbf_ul_ass_fsm, ul_tbf, ctx, LOGL_INFO, NULL); + if (!ctx->fi) + return -ENODATA; + + return 0; +} + +void gprs_rlcmac_tbf_ul_ass_fsm_destructor(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = &ul_tbf->ul_ass_fsm; + osmo_fsm_inst_free(ctx->fi); + ctx->fi = NULL; +} + +int gprs_rlcmac_tbf_ul_ass_start(struct gprs_rlcmac_ul_tbf *ul_tbf, enum gprs_rlcmac_tbf_ul_ass_type type) +{ + int rc; + rc = osmo_fsm_inst_dispatch(ul_tbf->ul_ass_fsm.fi, + GPRS_RLCMAC_TBF_UL_ASS_EV_START, + &type); + return rc; +} + +bool gprs_rlcmac_tbf_ul_ass_pending(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + return ul_tbf->ul_ass_fsm.fi->state != GPRS_RLCMAC_TBF_UL_ASS_ST_IDLE; +} + +bool gprs_rlcmac_tbf_ul_ass_match_rach_req(struct gprs_rlcmac_ul_tbf *ul_tbf, uint8_t ra) +{ + return ul_tbf->ul_ass_fsm.fi->state == GPRS_RLCMAC_TBF_UL_ASS_ST_WAIT_CCCH_IMM_ASS && + ul_tbf->ul_ass_fsm.rach_req_ra == ra; +} + +enum gprs_rlcmac_tbf_ul_ass_fsm_states gprs_rlcmac_tbf_ul_ass_state(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + const struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = &ul_tbf->ul_ass_fsm; + return ctx->fi->state; +} + +bool gprs_rlcmac_tbf_ul_ass_rts(const struct gprs_rlcmac_ul_tbf *ul_tbf, const struct gprs_rlcmac_rts_block_ind *bi) +{ + const struct gprs_rlcmac_tbf_ul_ass_fsm_ctx *ctx = &ul_tbf->ul_ass_fsm; + + switch (ctx->fi->state) { + case GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_RES_REQ: + return (ctx->phase1_alloc.ts[bi->ts].allocated && + ctx->phase1_alloc.ts[bi->ts].usf == bi->usf); + case GPRS_RLCMAC_TBF_UL_ASS_ST_SCHED_PKT_CTRL_ACK: + return (ctx->sched_pkt_ctrl_ack.ts == bi->ts && + ctx->sched_pkt_ctrl_ack.fn == bi->fn); + default: + return false; + }; +} + +struct msgb *gprs_rlcmac_tbf_ul_ass_create_rlcmac_msg(const struct gprs_rlcmac_ul_tbf *ul_tbf, + const struct gprs_rlcmac_rts_block_ind *bi) +{ + int rc; + struct tbf_ul_ass_ev_create_rlcmac_msg_ctx data_ctx = { + .ts = bi->ts, + .fn = bi->fn, + .msg = NULL, + }; + + rc = osmo_fsm_inst_dispatch(ul_tbf->ul_ass_fsm.fi, + GPRS_RLCMAC_TBF_UL_ASS_EV_CREATE_RLCMAC_MSG, + &data_ctx); + if (rc != 0 || !data_ctx.msg) + return NULL; + return data_ctx.msg; +} diff --git a/src/rlcmac/tbf_ul_fsm.c b/src/rlcmac/tbf_ul_fsm.c new file mode 100644 index 0000000..0078846 --- /dev/null +++ b/src/rlcmac/tbf_ul_fsm.c @@ -0,0 +1,198 @@ +/* TBF as per 3GPP TS 44.064 */ +/* + * (C) 2023 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * + * 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 Affero 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 <talloc.h> +#include <osmocom/core/tdef.h> +#include <osmocom/core/fsm.h> + +#include <osmocom/gprs/rlcmac/tbf_ul_fsm.h> +#include <osmocom/gprs/rlcmac/tbf_ul.h> +#include <osmocom/gprs/rlcmac/gre.h> + +#define X(s) (1 << (s)) + +static const struct value_string tbf_ul_fsm_event_names[] = { + { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START, "UL_ASS_START" }, + { GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL, "UL_ASS_COMPL" }, + { GPRS_RLCMAC_TBF_UL_EV_FOOBAR, "FOOBAR" }, + { 0, NULL } +}; + +static const struct osmo_tdef_state_timeout tbf_ul_fsm_timeouts[32] = { + [GPRS_RLCMAC_TBF_UL_ST_NEW] = { }, + [GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN] = { }, + [GPRS_RLCMAC_TBF_UL_ST_FLOW] = { }, +}; + +/* Transition to a state, using the T timer defined in tbf_fsm_timeouts. + * The actual timeout value is in turn obtained from conn->T_defs. + * Assumes local variable fi exists. */ + #define tbf_ul_fsm_state_chg(fi, NEXT_STATE) \ + osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, \ + tbf_ul_fsm_timeouts, \ + g_ctx->T_defs, \ + -1) + +static uint8_t ul_tbf_ul_slotmask(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + uint8_t i; + uint8_t ul_slotmask = 0; + + for (i = 0; i < 8; i++) { + if (ul_tbf->cur_alloc.ts[i].allocated) + ul_slotmask |= (1 << i); + } + + return ul_slotmask; +} + +static int configure_ul_tbf(struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx) +{ + struct osmo_gprs_rlcmac_prim *rlcmac_prim; + uint8_t ul_slotmask = ul_tbf_ul_slotmask(ctx->ul_tbf); + + LOGPFSML(ctx->fi, LOGL_INFO, "Send L1CTL-CF_UL_TBF.req ul_slotmask=0x%02x\n", ul_slotmask); + rlcmac_prim = gprs_rlcmac_prim_alloc_l1ctl_cfg_ul_tbf_req(ctx->tbf->nr, ul_slotmask); + return gprs_rlcmac_prim_call_down_cb(rlcmac_prim); +} + +static void st_new(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + //struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; + switch (event) { + case GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START: + tbf_ul_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_wait_assign(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; + switch (event) { + case GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL: + /* Configure UL TBF on the lower MAC side: */ + configure_ul_tbf(ctx); + tbf_ul_fsm_state_chg(fi, GPRS_RLCMAC_TBF_UL_ST_FLOW); + break; + default: + OSMO_ASSERT(0); + } +} + +static void st_flow(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + //struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; + switch (event) { + default: + OSMO_ASSERT(0); + } +} + +static struct osmo_fsm_state tbf_ul_fsm_states[] = { + [GPRS_RLCMAC_TBF_UL_ST_NEW] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_EV_UL_ASS_START), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN) | + X(GPRS_RLCMAC_TBF_UL_ST_FLOW), + .name = "NEW", + .action = st_new, + }, + [GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_EV_UL_ASS_COMPL), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ST_FLOW), + .name = "ASSIGN", + .action = st_wait_assign, + }, + [GPRS_RLCMAC_TBF_UL_ST_FLOW] = { + .in_event_mask = + X(GPRS_RLCMAC_TBF_UL_EV_FOOBAR), + .out_state_mask = + X(GPRS_RLCMAC_TBF_UL_ST_WAIT_ASSIGN), + .name = "FLOW", + .action = st_flow, + }, +}; + +static int tbf_ul_fsm_timer_cb(struct osmo_fsm_inst *fi) +{ + struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = (struct gprs_rlcmac_tbf_ul_fsm_ctx *)fi->priv; + switch (fi->T) { + case -2001: + LOGPTBFUL(ctx->ul_tbf, LOGL_NOTICE, "releasing due to PACCH assignment timeout.\n"); + /* fall-through */ + case 3169: + case 3195: + gprs_rlcmac_ul_tbf_free(ctx->ul_tbf); + break; + default: + OSMO_ASSERT(0); + } + return 0; +} + +static struct osmo_fsm tbf_ul_fsm = { + .name = "UL_TBF", + .states = tbf_ul_fsm_states, + .num_states = ARRAY_SIZE(tbf_ul_fsm_states), + .timer_cb = tbf_ul_fsm_timer_cb, + .log_subsys = DLGLOBAL, /* updated dynamically through gprs_rlcmac_tbf_ul_fsm_set_log_cat() */ + .event_names = tbf_ul_fsm_event_names, +}; + +int gprs_rlcmac_tbf_ul_fsm_init(void) +{ + return osmo_fsm_register(&tbf_ul_fsm); +} + +void gprs_rlcmac_tbf_ul_fsm_set_log_cat(int logcat) +{ + tbf_ul_fsm.log_subsys = logcat; +} + +int gprs_rlcmac_tbf_ul_fsm_constructor(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = &ul_tbf->state_fsm; + ctx->ul_tbf = ul_tbf; + ctx->fi = osmo_fsm_inst_alloc(&tbf_ul_fsm, ul_tbf, ctx, LOGL_INFO, NULL); + if (!ctx->fi) + return -ENODATA; + + return 0; +} + +void gprs_rlcmac_tbf_ul_fsm_destructor(struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = &ul_tbf->state_fsm; + osmo_fsm_inst_free(ctx->fi); + ctx->fi = NULL; +} + +enum gprs_rlcmac_tbf_ul_fsm_states gprs_rlcmac_tbf_ul_state(const struct gprs_rlcmac_ul_tbf *ul_tbf) +{ + const struct gprs_rlcmac_tbf_ul_fsm_ctx *ctx = &ul_tbf->state_fsm; + return ctx->fi->state; +} diff --git a/tests/rlcmac/rlcmac_prim_test.c b/tests/rlcmac/rlcmac_prim_test.c index 9347b01..fb12f05 100644 --- a/tests/rlcmac/rlcmac_prim_test.c +++ b/tests/rlcmac/rlcmac_prim_test.c @@ -27,6 +27,8 @@ static void *tall_ctx = NULL; +uint8_t last_rach_req_ra = 0; + /** MS-SGSN LLC (Mobile Station - Serving GPRS Support Node Logical Link Control) SAPI: GPRS Mobility Management Address field SAPI: LLGMM @@ -143,7 +145,19 @@ switch (rlcmac_prim->oph.sap) { case OSMO_GPRS_RLCMAC_SAP_L1CTL: - printf("%s(): Rx %s\n", __func__, pdu_name); + switch (OSMO_PRIM_HDR(&rlcmac_prim->oph)) { + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_RACH, PRIM_OP_REQUEST): + last_rach_req_ra = rlcmac_prim->l1ctl.rach_req.ra; + printf("%s(): Rx %s ra=0x%02x\n", __func__, pdu_name, last_rach_req_ra); + break; + case OSMO_PRIM(OSMO_GPRS_RLCMAC_L1CTL_CFG_UL_TBF, PRIM_OP_REQUEST): + printf("%s(): Rx %s ul_tbf_nr=%u ul_slotmask=0x%02x\n", __func__, pdu_name, + rlcmac_prim->l1ctl.cfg_ul_tbf_req.ul_tbf_nr, + rlcmac_prim->l1ctl.cfg_ul_tbf_req.ul_slotmask); + break; + default: + printf("%s(): Rx %s\n", __func__, pdu_name); + } break; default: printf("%s(): Unexpected Rx %s\n", __func__, pdu_name); @@ -177,11 +191,11 @@ rc = osmo_gprs_rlcmac_prim_upper_down(rlcmac_prim); OSMO_ASSERT(sizeof(ccch_imm_ass_pkt_ul_tbf_normal) == GSM_MACBLOCK_LEN); + ccch_imm_ass_pkt_ul_tbf_normal[7] = last_rach_req_ra; /* Update RA to match */ rlcmac_prim = osmo_gprs_rlcmac_prim_alloc_l1ctl_ccch_data_ind(0, ccch_imm_ass_pkt_ul_tbf_normal); rc = osmo_gprs_rlcmac_prim_lower_up(rlcmac_prim); - /* This now fails because it's not yet implemented: */ - OSMO_ASSERT(rc != 0); + OSMO_ASSERT(rc == 0); printf("=== %s end ===\n", __func__); } diff --git a/tests/rlcmac/rlcmac_prim_test.err b/tests/rlcmac/rlcmac_prim_test.err index f9268b1..7e75164 100644 --- a/tests/rlcmac/rlcmac_prim_test.err +++ b/tests/rlcmac/rlcmac_prim_test.err @@ -1,4 +1,17 @@ DLGLOBAL INFO Rx from upper layers: GRR-UNITDATA.request DLGLOBAL INFO TLLI=0x00002342 not found, creating entity on the fly +DLGLOBAL INFO UL_TBF{NEW}: Allocated +DLGLOBAL INFO UL_TBF_ASS{IDLE}: Allocated +DLGLOBAL INFO UL_TBF_ASS{IDLE}: Received Event START +DLGLOBAL INFO UL_TBF{NEW}: Received Event UL_ASS_START +DLGLOBAL INFO UL_TBF{NEW}: state_chg to ASSIGN +DLGLOBAL INFO UL_TBF_ASS{IDLE}: Send RACH.req ra=0x7e +DLGLOBAL INFO UL_TBF_ASS{IDLE}: state_chg to WAIT_CCCH_IMM_ASS DLGLOBAL INFO Rx from lower layers: L1CTL-CCCH_DATA.indication -DLGLOBAL ERROR Unsupported rlcmac_prim! L1CTL-CCCH_DATA.indication +DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: Received Event RX_CCCH_IMM_ASS +DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: ImmAss DynamicAlloc (1phase access) ts_nr=7 usf=0 +DLGLOBAL INFO UL_TBF_ASS{WAIT_CCCH_IMM_ASS}: state_chg to COMPLETED +DLGLOBAL INFO UL_TBF{ASSIGN}: Received Event UL_ASS_COMPL +DLGLOBAL INFO UL_TBF{ASSIGN}: Send L1CTL-CF_UL_TBF.req ul_slotmask=0x80 +DLGLOBAL INFO UL_TBF{ASSIGN}: state_chg to FLOW +DLGLOBAL INFO UL_TBF_ASS{COMPLETED}: state_chg to IDLE diff --git a/tests/rlcmac/rlcmac_prim_test.ok b/tests/rlcmac/rlcmac_prim_test.ok index 3deb5e9..030743e 100644 --- a/tests/rlcmac/rlcmac_prim_test.ok +++ b/tests/rlcmac/rlcmac_prim_test.ok @@ -1,2 +1,4 @@ === test_ul_tbf_attach start === +test_rlcmac_prim_down_cb(): Rx L1CTL-RACH.request ra=0x7e +test_rlcmac_prim_down_cb(): Rx L1CTL-CFG_UL_TBF.request ul_tbf_nr=0 ul_slotmask=0x80 === test_ul_tbf_attach end === -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/31099 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I420c57a9d0b63f9c2805a7c2ae8ce85532a48eef Gerrit-Change-Number: 31099 Gerrit-PatchSet: 17 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • ...
  • 261
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.