During testing and code inspection, there were various anti-patterns
on this (and U-Blox driver) codebase(s), including obfuscation, and
lack of data validation. This made it increasingly difficult to
introduce further variants of u-blox GNSS modems.
With this patch, both the UBX modem and the M8 driver have been
refactored to ease the reliability and maintainability of these
codebases. Here are some highlights:
WRT UBX modem:
- Helper macros to easily create UBX frames, (including checksum
calculation), at compile time; thus, making it easier to extend UBX
commands.
- Logic validation by the inclusion of the modem_ubx testsuite, used to
refactor the code through TDD.
- Ability to receive unsolicited messages, in order to enable U-Blox
drivers to rely on modem_ubx to transceive all commands, and avoid
hopping between modem_ubx and modem_chat.
WRT M8 driver:
- Remove GNSS specific protocol header files. Instead, unify them under
modem/ubx/protocol.h. Background: After a survey and looking at ubxlib
SDK I conclude the UBX protocol is by definition a GNSS protocol (there
are non-GNSS u-blox modems, but they're not interfaced through UBX
protocol).
- Establish pattern to create and send/receive commands using new
foundations on modem ubx.
- Remove dependency of Modem chat, and instead use UBX unsolicited
messages to get Navigation and Satellites data.
- Switch from the auto-baudrate detection pattern to a pattern of
transitioning between an initial known baudrate to a desired baudrate,
in order to improve initialization time.
- Add dts property to configure default fix-rate.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
Add support for the simcom a76xx modem which is similar to the simcom 7080
but has a few key differences. Tested with a simcom A7672SA module but as
there is a single simcom A76XX AT commands manual, the driver should work
with other modems of the series.
Signed-off-by: Olivier Lalonde <o@syskall.com>
Receive buffer must be aligned to word when
CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC=y is set.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
Add Asynchronous UART implementation, which does not drop data
when automatic hardware-flow-control is set in the device tree.
With automatic hardware flow control, the CTS pin will be
automatically deactivated when there are no more asynchronous
UART RX buffers available. After buffer space becomes available,
and UART RX is restarted, the CTS pin will be activated.
Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
If we end up writing zero bytes to cmux output, we can return
zero instead of -ENOMEM as it would break various modules when
using small buffers. For example modem_chat.c does not tolerate
-ENOMEM but handles zero OK.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Allow configuring MTU for CMUX.
Some AT manual and specification define this as a
frame size. Linux ldattach default to 127 bytes,
3GPP TS 27.010 defaults to 31.
We should limit our CMUX frames to a size that
remote end is capable of handling.
Linux silently drops oversized frames.
Also, remove MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE as
this was only limiting a buffer sizes, and resulted
CMUX frames to be capped to same value.
Use MODEM_CMUX_WORK_BUFFER_SIZE and MODEM_CMUX_MTU instead.
Also rename CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZES to
CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZE as it is now
only used as a Chat module. DLCI pipes use
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The variables 'first' and 'next' in function 'stats_buffer_list_first()'
and 'stats_buffer_list_next()' were potentially used uninitialized.
Depending on the compiler and target architecture, this can lead to
different behavior, including warnings or errors when using strict
warning flags.
By initializing these pointers to 'NULL', we ensure consistent and
expected behavior across all toolchains and configurations.
Signed-off-by: Fabian Kainka <kainka@cognid.de>
To improve performance in FCS calculation, this commit replaces
the usage of the generic `crc8` function with the specific `crc8_rohc`
function in `modem_cmux.c`.
The `crc8_rohc` function utilizes a small table approach, enhancing
the efficiency of CRC-8/ROHC variant calculations while optimizing
memory usage.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
`ret` holds the amount of bytes received from the modem. However during
processing of the bytes its value is overwritten by the return value of
`modem_ubx_process_received_byte`, in practice discarding all but the
first byte read.
To prevent this, store the length in a separate variable.
Signed-off-by: Anders T. Akre <anders@akre.io>
The modem pipe APIs include synchronous calls to open/close,
which internally use a fixed timeout of 10 seconds. The timeout
should be configurable through the APIs, anywhere from K_NO_WAIT
to K_FOREVER.
This commit adds timeout parameters to the open/close APIs, and
updates in-tree usage of the open/close APIs to explicitly
provide the previously implicit timeout of 10 seconds.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Added `static const` to various `struct modem_pipe_api` and
`frame` in `modem_cmux_connect_handler` to make these structures
immutable and reduce RAM usage.
Corrected a typo, changing "consequtive" to "consecutive".
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Changed the `api` field in the `modem_pipe` structure to be
a pointer to constant.
This ensures that the `api` field remains immutable after
initialization.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
The cmux module does not properly cancel all work when it is
released from its modem pipe. Releasing CMUX must cancel all
work as the pipe is no longer available, as it is set to NULL.
If work remains which tries to transmit something to the now
released pipe, a NULL dereference occurs.
This exact issue occurs if a DLCI channel is trying to open
after the modem pipe has been released, as the CMUX component
will send an open request at a fixed interval.
The expected behavior is for the open request to be cancelled,
and further open requests to be prevented until cmux is again
attached to a pipe.
Lastly, added a check to ensure that the pipe is indeed released
when calling attach, to ensure all work is indeed stopped before
modifying the pipe and buffers.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Explicitly ignore the return value of net_pkt_read_u8() as the
net_pkt is validated before being queued for transmit within
modem_ppp_ppp_api_send()
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The design of the pipe is overly complicated compared to the
in-tree and planned future use of the pipe module.
The pipe is currently designed to protect against multiple
threads calling any API simultaineously. This is not neccesary
as only one thread ever calls open/close/transmit/receive at
once, while the notification APIs are potentially called by a
different thread.
This commit removes the synchronization of calls to the open/
close/receive/transmit APIs. It also uses a k_event for thread
safe event and state handling instead of a k_mutex and k_condvar.
The callback is proteced by a k_sem as it modified using the
attach/release APIs, which can be called simultaneously to a
thread invoking the callback.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Trying to start a chat script using either modem_chat_run_script()
or modem_chat_run_script_async() should result in returning -EBUSY
without affecting the currently running script and thread waiting
on the current script to stop.
The current behavior causes the thread waiting for the current
script to stop to return with error -EAGAIN, and the thread trying
to start the new script to return with error -EBUSY.
This commit moves the reset of the sem the current thread is
waiting on, to after the check of whether a script is currently
running, leaving the current thread unaffected as is intended.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add modem pipelink module which exposes modem pipes globally.
The pipelink module implements a callback to inform when a
pipe becomes available to use by whichever modem is attached
to it. This could be a shell, or a network interface.
The module aims to allow modem drivers to be split into modules,
and allowing applications to implement their own custom logic
without altering the modem drivers.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add APIs for changing the contents of modem chat matches
safely at runtime.
This allows for reusing a single modem_chat_match at the cost
of placing the match and its buffers in RAM.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Add statistics module which tracks the usage of modem backend
transmit/receive buffers if implemented by a backend.
A modem backend may register itself to the modem backend
stat module, and advertise its transmit and receive buffer
sizes and momentary usage (length).
The modem backend module tracks the maximum usage, which can be
output to the shell using the "modem_stats buffer" shell command.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
Modem chat scripts should be able to add a script command which
is simply a delay. The validation of chat scripts currently
disallows chat script commands which only have a timeout set.
Update modem_chat to allow modem chat script commands which
only have a timeout. Additionally do a bit of cleanup to
remove duplicate code.
Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
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>
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>
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>
- 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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>