Skip to content

Conversation

SeppoTakalo
Copy link
Contributor

The C/R bit in the address field should be handled as explained in 5.2.1.2 in the spec (3GPP TS 127.010).

To detect if the frame is a command or a response, we need to know who was the initiator of the CMUX channel.

Initiator is the station that take the initiative to initialize
the multiplexer (i.e. sends the SABM command at DLCI 0 )

See the table from given section of the specification.

Also, on UIH frames 5.4.3.1 says

The frames sent by the initiating station have the C/R bit set to 1
and those sent by the responding station have the C/R bit set to 0.

NOTE: This is different than a C/R bit in the Type field.

modem_cmux_log_received_frame(&cmux->frame);

if (cmux->state == MODEM_CMUX_STATE_CONNECTED && cmux->frame.cr == cmux->initiator) {
LOG_DBG("Received a response frame, dropping");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Received a response frame? Shouldn't this rather say that the received C/R bit is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not wrong. See 3GPP TS 27.010: 5.2.1.2 Address Field
image

The value of the C/R bit changes its meaning depending on which side send the packet.
Most implementations don't care, but for certain commands where the response is exact copy of the command, we should be able to distinct if we just received a response to our command or was this a new command.

In this PR, I'm not doing other than dropping unexpected frames, but on my follow up PR that I'm working, I use this information to know that our Power Saving Command is actually replied and we can shut down the UART.
Same with Close Down command.

static void modem_cmux_on_dlci_frame_ua(struct modem_cmux_dlci *dlci)
{
/* Drop invalid UA frames */
if (dlci->cmux->frame.cr != dlci->cmux->initiator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this rather be

Suggested change
if (dlci->cmux->frame.cr != dlci->cmux->initiator) {
if (dlci->cmux->frame.cr == dlci->cmux->initiator) {

as we are receiving the frame?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the image on my previous comment.
The value depends on which side of the CMUX pipe we are. So are we initiator or not.

The C/R bit in the address field should be handled as explained
in 5.2.1.2 in the spec (3GPP TS 127.010).

To detect if the frame is a command or a response,
we need to know who was the initiator of the CMUX channel.

>    Initiator is the station that take the initiative to initialize
>    the multiplexer (i.e. sends the SABM command at DLCI 0 )

See the table from given section of the specification.

Also, on UIH frames 5.4.3.1 says
>    The frames sent by the initiating station have the C/R bit set to 1
>    and those sent by the responding station have the C/R bit set to 0.

NOTE: This is different than a C/R bit in the Type field.

Signed-off-by: Seppo Takalo <[email protected]>
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 9, 2025
@zephyrbot zephyrbot requested a review from nashif October 9, 2025 14:38
Copy link

sonarqubecloud bot commented Oct 9, 2025

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test case for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Modem area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants