Commit graph

63 commits

Author SHA1 Message Date
Tomi Fontanilles a986905df5 modem: chat: implement helper defines/structs
Those helpers allow to define some typical kinds of chat matches and
scripts with more ease/less boilerplate.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-04-24 15:00:10 -04:00
Tomi Fontanilles 18170ebce1 modem: cmux: make work buffer size configurable
A Kconfig item is added and the buffer
is embedded into the modem_cmux struct.
The default value is increased from 16 to 64 bytes in
an effort to reduce the number of modem_pipe_receive() calls.

CONFIG_MODEM_CHAT_LOG_BUFFER is renamed
to CONFIG_MODEM_CHAT_LOG_BUFFER_SIZE for consistency.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Tomi Fontanilles 419a398c01 modem: backends: uart_isr: improve the reception of bytes
Add a configurable delay between when a byte is received and
MODEM_PIPE_EVENT_RECEIVE_READY is sent.

This fixes data reception at baud rates above 460800, and
most likely also reduces the workload at any baud rate
when receiving bytes by not going through the work item
and callbacks for every single byte.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Tomi Fontanilles 9cea822cc4 modem: backends: uart_async: small improvements
- Set all the state bits before calling uart_rx_enable() because
  interrupts may happen already before it returns.
- Fix the byte count in the "Receive buffer overrun" log.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Tomi Fontanilles e7805f8d72 modem: cmux: improve frame debug logging
- Add the frame data length to the frame header log.
- Log the dropped frames as well.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Tomi Fontanilles 15cc3ff0d6 modem: backends: uart: register their own log modules
Instead of both using the same modem_backend_uart, for better visibility.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Tomi Fontanilles cf7d166fc1 modem: backends: uart_async: increase default TX timeout
The previous default value made UART TXs of size > 1145
time out at a baud rate of 115200.

It should not be so small that it can cause undesirable timeouts.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-26 09:29:55 +00:00
Mayank Mahajan 3d81167eaf ADD: GNSS Driver for U-BLOX M10 & Support for UBX Messages
MODEM_UBX: Adds Support for UBX Messages in Modem Subsystem.

GNSS API Supported: get_supported_systems, set_fix_rate, get_fix_rate,
	set_enabled_systems, get_enabled_systems, set_navigation_mode,
	get_navigation_mode.

Boards Tested: MIMXRT1062_FMURT6, VMU_RT1170.

Note: Partial support for U-BLOX Messages is provided as of now.

Signed-off-by: Sumit Batra <sumit.batra@nxp.com>
Signed-off-by: Mayank Mahajan <mayankmahajan.x@nxp.com>
2024-03-26 09:28:36 +00:00
Tomi Fontanilles 7f9ed8695c samples: net: cellular_modem: add nRF9160 DK's nRF52840
The added configuration files allow the sample to be run
on the nRF52840 present on the nRF9160 DK with the nRF9160
(running SLM) being the modem and communication happening
through pins that are routed internally between the two.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-04 22:13:14 +01:00
Tomi Fontanilles 3813faa302 modem: backends: uart_async: log the number of bytes dropped
When a receive buffer overrun happens.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-03-04 22:13:14 +01:00
Tomi Fontanilles a6b710fce3 modem: chat: fix init assert
Use the proper variable.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles 90f1ed6a81 modem: cmux: improve handling of receive buffer overrun
This allows to properly drop single CMUX frames that are
too big to fit in the receive buffer, keeping track of
where they end so that following frames are received
correctly regardless of the data contents.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles bc64c91d62 modem: backend: uart_async: improve logging on UART_TX_ABORTED
Only log if the abort is not self-triggered,
and also print the number of bytes sent.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles 11f22bf702 modem: ppp: fix receiving of successive frames when one 0x7E is omitted
The SOF delimiter byte may be omitted when a frame follows another
that just ended with that byte.
The parsing used to expect that second delimiter anyway,
which resulted in PPP frames going missing.

As an additional improvement, dropped bytes as well as the length
of received frames are now (debug) logged.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles 6aef9d4d9a modem: ppp: fix crash when attaching to a pipe
modem_pipe_attach() can send events before returning, which could
provoke a crash as ppp->pipe, still NULL at that time, could be
used either in receiving (if the pipe had some data pending) or
in sending (if the PPP module had already been attached and had
some data to send in its transmit buffer).

ppp->pipe is now set before modem_pipe_attach().
Also, the ATTACHED_BIT is now set only after having actually attached.
And finally, the send_work is now scheduled on PIPE_EVENT_OPENED
so that data is flushed when the (closed) attached pipe is opened.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles 5fc02e3501 modem: backends: use CONFIG_MODEM_MODULES_LOG_LEVEL
This makes the modem backends use the log level
set for the modem modules instead of the default one.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-28 18:02:17 +00:00
Tomi Fontanilles 825b676568 modem: small improvements
Changes include:
- Improving handling of frames for unconfigured DLCIs.
- Adding logs and outputting error codes in failure cases.
- Adding warnings to not reuse buffers.
- Fixing comments.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-26 11:34:32 +00:00
Bjarki Arge Andreasen 793c507209 modem: cmux: Prevent NULL deref in dlci_close_handler
Prevent unlikely item == NULL scenario identifed by CID
323104

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-02-15 10:22:09 +01:00
Bjarki Arge Andreasen cc3076be1d modem: cmux: Prevent NULL deref in dlci_open_handler
Prevent unlikely item == NULL scenario (CID 323102) and remove
superflous cmux == NULL check (CID 334903)

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-02-15 10:22:09 +01:00
Bjarki Arge Andreasen 9633fb70a0 modem: cmux: Prevent NULL deref in connect_handler
Prevent unlikely item == NULL scenario (CID 323091) and remove
superflous cmux == NULL check (CID 334904)

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-02-15 10:22:09 +01:00
Bjarki Arge Andreasen 96e48c91b4 modem: cmux: Prevent NULL deref in connect_response_transmit
Prevent potential NULL dereference identified by CID 338026

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-02-15 10:22:09 +01:00
Bjarki Arge Andreasen d801e697dd modem: chat: Implement TRANSMIT_IDLE event
Refactors modem chat module to use TRANSMIT_IDLE event instead
of polling when transmitting, cleaning up the transmit handler
by combining duplicate code and using an internal state instead
of multiple iterators to track send state.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-25 11:22:42 +01:00
Bjarki Arge Andreasen 27b0d4e3fe modem: chat: remove receive and transmit timeouts
Remove receive and transmit timeouts which are no
longer useful as the RECEIVE_READY and
TRANSMIT_IDLE events will be used to efficiently
manage timeouts between transmit/receive calls.

Then update the the in-tree drivers using the
modem_chat module to omit the process timeout
parameter.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-25 11:22:42 +01:00
Bjarki Arge Andreasen a9779eca40 modem: ppp: Implement TRANSMIT_IDLE event
Implement TRANSMIT_IDLE event for modem_ppp module. This addition
optimizes the sys workque CPU time when performing a throughput
test from 36% to 5%, while only reducing the throughput by 12%.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-22 10:35:37 +00:00
Bjarki Arge Andreasen 358f1ff934 tests: modem: cmux: Implement TRANSMIT_IDLE into test suite
Use transmit idle event to synchronize with data transmitted
through DLCI pipes to test TRANSMIT_IDLE implementation.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-17 09:20:50 -06:00
Bjarki Arge Andreasen c114627853 modem: cmux: Implement TRANSMIT_IDLE event
Implement transmit idle event both for transmitting data to the
bus, and for the individual DLCI channels.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-17 09:20:50 -06:00
Bjarki Arge Andreasen 7c9f2872e1 modem: chat: Start waiting for response after request is sent
This PR makes the modem_chat wait until a chat script chat
request has been sent before accepting responses to said
request.

This helps ensure that an unsolicitet response is not mistaken
for a response to a request, which is especially problematic
if the chat script chat is using an any match.

For example, start chat script sending AT+CGMI, expecting the
modem name as a response followed by OK

> start script, waiting for response immediately
> start sending "AT+CGMI"
> receive "+CEREG 1,0" while sending
> script accepts "+CEREG 1,0" as the response to "AT+CGMI"
> "AT+CGMI" sent
> receive "QUECTEL BG95"
> receive "OK"

script handler got "+CEREG 1,0" instead of "QUECTEL BG95"

After this PR:

> start script
> start sending AT+CGMI
> receive "+CEREG 1,0" while sending
> "AT+CGMI" sent
> start waiting for response
> receive "QUECTEL BG95"
> script accepts "QUECTEL BG95" as response to "AT+CGMI"
> receive "OK"

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-15 15:11:42 +01:00
Pisit Sawangvonganan 1270bce4d8 modem: modem_cmux: optimize modem_cmux_transmit_frame to save ROM
This optimization aggregates frame headers before adding to the ring buffer
and computes the FCS of the frame header in one operation.
This approach improves execution efficiency and reduces memory footprint.
This code adjustment aligns with the changes proposed in https://github.com/zephyrproject-rtos/zephyr/pull/67062.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-11 16:10:37 +00:00
Bjarki Arge Andreasen 4d99c69e4a modem: backend: tty: Implement transmit idle event
Implement transmit idle notification for TTY backend. Since TTY
has an "infinite" transmit buffer, we invoke transmit idle
immediately after writing the data to the TTY file.

The test suite for the TTY backend has been updated to match the
new behavior.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-11 16:09:44 +00:00
Bjarki Arge Andreasen 8c6a9ee594 modem: backend: uart: Implement transmit idle event
Make async and interrupt driven UART backends notify transmit
idle when transmit is idle.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-11 16:09:44 +00:00
Bjarki Arge Andreasen 516af3cb84 modem: pipe: Add TRANSMIT_IDLE event
Add transmit idle event to modem_pipe_event enum. This will
allow modules to await transmit idle before trying to transmit
more data, instead of blindly calling modem_pipe_transmit in
a loop until all data has been accepted.

This will reduce the time spent trying to transmit data while
the backend is blocked.

Similarly to the RECEIVE_READY event, backends will call
modem_pipe_notify_transmit_idle() to indicate that transmit
is idle, and the TRANSMIT_IDLE event will be reinvoked when
the modem pipe is attached to synchronize the state of the
pipe with the user of it.

Additionally, the TRANSMIT_IDLE event is also invoked when the
modem is opened to further help synchronization with the user
of the pipe.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-11 16:09:44 +00:00
Bjarki Arge Andreasen 3debfc8c8d modem: cmux: Simplify resync mechanism
Some modems don't start sending resync flags as described in
3G TS 27.010 V2.0.0 5.2.5, which results in the CMUX being
stuck in resync mode for said modems.

This patch simplifies the resync mechanism to simply drop
invalid frames, and wait for atleast two consequtive frame
flags (stop+start).

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-11 13:53:25 +01:00
Bjarki Arge Andreasen b3971d0112 modem: cmux: Add DLCI receive buffer overrun LOG WRN
DLCI receive buffer may overrun if data is not processed fast
enough. This error was not reported before this patch, resulting
in unexplained missing bytes.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-05 14:30:56 +01:00
Bjarki Arge Andreasen 48fa603da3 modem: cmux: Patch resync mechanism
The CMUX resync mechanism can get stuck between states
MODEM_CMUX_RECEIVE_STATE_RESYNC_0 and
MODEM_CMUX_RECEIVE_STATE_RESYNC_1 if the resync flags, which are
sent only once in state MODEM_CMUX_RECEIVE_STATE_SOF, are not
responded to, or the response is lost.

This patch ensures resync flags are sent from states
MODEM_CMUX_RECEIVE_STATE_SOF, MODEM_CMUX_RECEIVE_STATE_RESYNC_1
and MODEM_CMUX_RECEIVE_STATE_RESYNC_2 if its determined that the
resync flags are not being responded to.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-03 18:58:39 +00:00
Bjarki Arge Andreasen 3ebe814294 modem: chat: Patch invalid dereference
The chat module contains an array of three lists of matches,
one of which are static, two of which are contained within the
currently running script. The current match, which is an
object stored in one of the three lists, is stored in its own
pointer in the chat module context.

A memory error occurs when the script is stopped, while the
chat module is using one of the matches stored withing the
script. This commit clears the match pointer when the script
is stopped if the match is stored within the script.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-03 18:57:55 +00:00
Tomi Fontanilles 6564e8b756 modem: cmux: fix frame data length encoding
In cases where the data is bigger than 127 bytes,
the first bit of the second byte of the data length field
used to always be set.

This is wrong as according to the 3GPP 27.010 spec
only the first bit of the first byte is the EA bit;
all the others denote the data length.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-01-02 10:10:55 +01:00
Juha Heiskanen 093efc444d modem: modem_cmux: Support modem CMUX DCE role
Added missing command and message handling for use existing
modem cmux for DCE role.
DCE CMUX connection can be now initialized from DTE side.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
2023-12-08 20:17:58 +00:00
Bjarki Arge Andreasen 8128a726a4 modem: backend: uart_async: Remove UART flush
The UART flush is not relevant for the async UART implementation.
UART drivers should handle this internally.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2023-11-20 13:03:08 +01:00
Bjarki Arge Andreasen 6f1d49e7b3 modem: backend: uart_async: Use single ring buffer
Use single ring buffer and protect it with a spinlock as it is
shared between backend and UART thread (ISR). This is simpler
than the double ring buffer setup.

The receive idle timeout has also been made configurable
instead of being a hardcoded value.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2023-11-20 13:03:08 +01:00
Bjarki Arge Andreasen 7cf2b0fc9d modem: backend: uart_async: Extend "closed" requisites
The current implementation only waits for the RX disabled event
to determine if the UART is closed. It should wait for all RX
buffers to be released, and the TX to be done as well.

We now also call uart_tx_abort() when closing the pipe.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2023-11-20 13:03:08 +01:00
Bjarki Arge Andreasen 0aa6f3f3ff modem: cmux: Fix coverity issues
Possible NULL pointer dereferences where discovered by static
code analysis, they are addressed in this commit.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2023-11-20 09:24:58 +01:00
Bjarki Arge Andreasen 011adfa4ca modem: Add experimental tag
The modem subsystem is novel and should therefore be marked
experimental.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-11-03 09:56:30 +01:00
romain pelletant efebb1841f modem_chat: fix hard fault on script stop
Fix fault on modem_cellular disconnection/reconnection
Issue #64291

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2023-10-25 10:05:45 +02:00
Bjarki Arge Andreasen b4f3150592 modem: cmux: Optimize log message to save ROM
This commit reuses the string "Unknown %s frame type" for two
log messages, as suggested by ycsin.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen ee44357cfb modem: modem_cellular: Reset receive state on attach
This commit resets the state of the CMUX receive state
machine when the CMUX instance is attached to a pipe.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen b495fda6a1 modem: modem_cmux: Improve logging
This commit adds logging for CMUX frames and commands and
their data, for both transmit and receive. It also removes
the superseded LOG_DBG() lines like "Received frame".

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen 0f38136431 modem: modem_cmux: Clear DLCI pipes on open
This commit resets the receive ring buffer for each DLCI
pipe when they are opened. They may have old data stored
from last time they where opened.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen 92ad351e2a modem: modem_cmux: Use k_event_test instead of K_NO_WAIT
This commit replaces the k_event_wait calls using K_NO_WAIT
with k_event_test.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen 79e6c8411f modem: modem_cmux: Reset CMUX events on release
This commit resets the CMUX events to match the
initial value of disconnected.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00
Bjarki Arge Andreasen 7fe491c050 modem: modem_cmux: Make async connect/disconnect stateful
This commit adds a check to the async connect and disconnect
functions to validate the CMUX is not already connected
or disconnected respectively. This was already part of the
sync connect and disconnect functions, so the sync functions
now simply wrap the async functions to avoid duplicate code.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-24 14:31:38 +01:00