GCC format-truncation kicks in on this printk whenever the logging
configuration transforms the LOG_WRN below into a noop, and the snprintk
return argument become unused.
Fix that by switching to strncpy, fixes:
zephyrproject/zephyr/drivers/modem/hl7800.c:1786:74: warning: '%s'
directive output may be truncated writing up to 53 bytes into a region
of size 21 [-Wformat-truncation=]
reproduced with:
west build -p -b mg100 -T samples/net/telnet/sample.net.telnet
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit updates the modem_cellular driver to use the
new naming scheme for the modem_chat functions.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit improves the usage of the bus pipe (connected
to UART) to only open it when the modem is actually
powered and ready, not when leaving the idle state. This
ensures the pipe is flushed before sending the init script,
and re-enables the UART driver if it is disabled due to
errors.
While building a test platform based on the nRF9160 and a
Quectel BG95, it was discovered that the nRF9160 correctly
throws UART errors if the RX is enabled while the UART RX
line is low (which was due to the modem being powered
down).
The improvements should also help help remove the
"<wrn> modem_chat: receive buffer overrun" warning which
would occur during startup as the pipe was opened, but
nothing was receiving the data, causing the buffer to
overflow.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
The added cellular modem driver is a naive driver, which
shall serve as a template for implementing tailored
drivers for modems like the UBLOX-R4. It uses only
generic at commands, described in 3gpp, and protocols,
like CMUX and PPP.
A binding for the BG95 has been added, which replaces
the quectel,bg9x. This is neccesary since the BG95 does
not have a usable reset pin, the reset and powerkey are
internally connected to each other.
Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
Use the symbol iface_ctx in place of ictx. This was
introduced seemingly by mistake in PR #61510
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Ensure the driver enables the LTE radio during init unless boot
in airplane mode is specified.
To ensure the settings applied during init are used, the LTE radio
is turned off during config.
Fix issue where PDP and GPRS connection config could have a mismatched APN.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
This commit removes the direct calls of the PPP API of the
network device used by gsm_ppp.c
These calls are now performed by the L2 PPP interface when it
is brought up or down using net_if_up() or net_if_down()
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Cache the delimiter string length in `parse_params`, instead of
calculating it on each character in the match buffer.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Given the following response: `+CIPSTA:ip6ll:"FE80::EDC:7EFF:FEDD:110C"`
The response delimiter is `:`, but there is also a quoted string that
contains the delimiter character. These delimiters should not be
considered when searching for the end of a parameter.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit replaces the workarounds spread around the
drivers and subsystems with the updated PPP L2
interface.
Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
In case of BG95 where there is no reset pin, reseting the board
which uses a BG95 modem could result in powering-off the modem
(as oposed to "reset" the modem). This commit is an attempt
to handle this case and re-power the modem.
Signed-off-by: Andrei Hutanu <andrei.hutanu.i@gmail.com>
Using bg9x driver with bg95 specifically has the issue that BG95
modem replies with "RDY" when it's not fully initialized and AT
commands sent to the modem after this point would result in modem
reply of "ERROR". This commit adds a new prj.conf field in the build
configuration for custom unsolicited app ready string, with
the default being BG96 one ("RDY").
Signed-off-by: Andrei Hutanu <andrei.hutanu.i@gmail.com>
The BG95 pin configuration does not internally ever use the reset pin.
Because of this, there is no need to make reset pin mandatory.
Commit removes reset pin dependency [e.g. in case of BG95].
Signed-off-by: Andrei Hutanu <andrei.hutanu.i@gmail.com>
Re-enable reception on the UART instance when `UART_RX_DISABLED`
triggers, which can happen when errors occur on the line.
This stops the driver permanently moving into an unresponsive state.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Fix link error when both modems' drivers are enabled
as they both define the same structure but did not
make it static.
This fixes the CI build failure of
tests/drivers/build_all/modem/drivers.modem.simcom_sim7080.build
on particle_boron
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Fix the following build warning:
include <fcntl.h> without CONFIG_POSIX_API
is deprecated. Please use CONFIG_POSIX_API
or #include <zephyr/posix/fcntl.h>
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
When building drivers.modem.build we get a link error since
log_source_id_get() is not defined when CONFIG_LOG_MODE_MINIMAL
is defined.
Change ifdef protection to be CONFIG_LOG_RUNTIME_FILTERING
instead of CONFIG_LOG in the code to handle this case.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
When building with arm-clang we get warnings of the type:
wncm14a2a.c:828:14: error: array subscript is of type
'char' [-Werror,-Wchar-subscripts]:
} else if (isalpha(c2) != 0) {
^~~~~~~~~~~
Fix this by adding explicit casts to (int) when callinng isalpha()
or isdigit().
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The internal socket context struct modem_socket_config
currently has members accessed directly by user. The
modem_socket_init() function has been updated to take all
user configurations as args. Thus removing the need for
the user to directly access the internal context for
initialization.
The user also currently needs to know of internal modem
socket libary behavior to determine if a socket has been
allocated and assigned an id, this is documented, and is
not safe. The functions:
modem_socket_is_allocated()
modem_socket_id_is_assigned()
modem_socket_id_assign()
have been added to the modem socket library API to perform
these checks, and to assign socket ids.
This commit makes use of the modem socket library safer and
adds documentation to the API.
Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
There is currently not a clear separation between
user configuration and internal context when using the
modem_cmd_handler library. This update adds a clear
separation, placing user configuration in a seperate
struct passed to modem_cmd_handler_init alongside the
internal context modem_cmd_handler_data.
There is also a lack of documentation of the user
configurations, these have been added to the new config
struct.
The new API function modem_cmd_handler_process has been
added to remove the need for the user to directly access
the process member of the internal context. This ensures
that the user is not encouraged to access any internal
context members.
Some whitespace errors exist in the modem_cmd_handler.c
file, these are outside of the scope of this PR. These
can be addressed in a later PR as they are not functional
changes.
Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
The UART IFACE API currently exposes the context struct
modem_iface_uart_data, expecting the user to fill in some
of the fields, with no documentation specifying which fields
and what they mean.
This API update moves all user configurable values in the context
out into a config struct, modem_iface_uart_config, within which
members are documented.
This prevents the user from interacting directly with the context
making use of the library safer and more readable.
The config structure helps make code readable by using "named args"
in a const struct instead of a long, nameless, parameter list passed
to the modem_iface_uart_init function.
The new API function modem_iface_uart_rx_wait is added to prevent the
user from having to interact with the rx sem in the context directly.
The context can now be safely interated with without direct access to
any of its members.
Pointers to the ring buffer params in the context have been moved to
config struct, as these are only useful during initialization of the
context.
Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
We get compile warnings of the form:
error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
[-Werror,-Wint-in-bool-context]
if (!isprint(byte)) {
^
Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".
Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Adds dummy link layer for offloaded ifaces, allowing
ifaces to directly receive l2_enable calls
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Fix DNS resolver config for IPv6 only setup.
Check validity of the DNS addresses before trying to
configure the resolver.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Ensure DNS resolver is stopped if modem is turned off.
All IO connected to the HL7800 need to be de-asserted
in order for the HL7800 to power off.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
PSM hibernate mode would draw excessive current
because the UART would be enabled if CTS went low.
In hibernate mode, do not use CTS to power on the UART.
Fix reading of input pin states for low power by reading
the raw value.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Change event callback lock to a semaphore to avoid
priority issues the mutexes can cause.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
After a firmware update, DNS needs to be reconfigured.
Fix debug log for AT command strings.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Some modems supports multiple access technologies.
The access technology of the serving cell can be extracted from the
+CEREG command, which is already sent to the modem.
The parse function is extended to also parse the access technology value.
Fixes https://github.com/zephyrproject-rtos/zephyr/issues/51153.
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Trigger network dropped based on socket error notifications.
This debounces the network state and only triggers
the network interface to go down if the network
really drops or causes socket problems.
This will ensure upper networking stack layers can
cleanup broken sockets properly.
Debounce DNS resolver refresh.
Only trigger DNS resolver refresh if the DNS address changes.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Adding multidomain support by introducing log_link module which
acts as a receiver of log messages created by another domain.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Remove modem_cmd_handler_tx_lock lock when CONFIG_GSM_MUX
is disabled, as modem_cmd_handler_tx_unlock is under the same
conditions.
Signed-off-by: GUITTER Pierrick <pguitter@silicom.fr>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).
Automated using:
```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
mdm_hl7800_log_filter_set uses LOG_MODULE_NAME which
is undefined.
log_source_id_get() will fail to get the correct source id.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Let's switch to the LOG_DBG for +CREG, +CESQ and +CSQ
AT commands responses because they flood the console so much.
Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
Patches the driver such that if the iface errors after init, the
driver will enter FSM error state.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Compare these variables properly so that the condition in an if
statement will be boolean.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Update gsm_ppp.c
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.
The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a
Signed-off-by: Simon Hein <SHein@baumer.com>
If TCP server closed notification is received it
could interrupt the TCP socket RX or TX data sequence.
Remove the SOCK_SERVER_CLOSED state and instead
use a unique error code to know if the socket
has been closed by the server.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
There is is an error in the way that the sock id is
determined. A unique fd is reserved and assigned appropriatly, but
the id, which should correspond to a socket number within the modem,
is set to an invalid, and identical for all sockets, value, and then
not used appropriatly in the drivers, instead, the sock_fd is used,
which can be any value really, it is not related to the socket number
in any way.
This results in the drivers only working if the reserved fd happens
to be between base_socket_num and (socket_len - 1)
This patch assignes the id to the index of the socket + the
base_socket_num, the socket at index 0 will get the id 1 if the
base_socket_num is 1, and the modem_socket_from_id should then
be used to get a pointer to the socket, since the id is not
neccesarily equal to the index.
The FIXME has been solved by adding a note both at the start
of the modem_socket_get function and inside the Kconfig file
for the MODEM_SOCKET option description. It is not an error,
but the user must be aware that it uses the POSIX file
descriptors, for which only 4 are allocated by default.
This patch fixes the bug, without breaking the brittle modem
drivers which currently are built around this bug.
The modem drivers should be updated to use the id as the
socket num instead of the sock_fd after this fix has been merged.
The "socket # needs assigning" has been removed, as that is what
this patch is doing
I also added comments to the id and sock_fd in the modem_socket
structure to help developers use the id and fd appropriately.
Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Simplify the implementation by using gpio_dt_spec.
As part of this use logical values of 0/1 for gpio_pin_set_dt
and handle any inversions as GPIO flags that might be required
at a board level (in dts config).
Signed-off-by: Kumar Gala <galak@kernel.org>
Use logical values of 0/1 for gpio_pin_set_dt and handle any
inversions as GPIO flags that might be required at a board level.
Signed-off-by: Kumar Gala <galak@kernel.org>
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Change logic in `modem_cmd_handler_setup_cmds` and
`modem_cmd_handler_setup_cmds_nolock` to always sleep
after each sent AT command.
The issue was found using a logic analyzer while debugging 'NO CARRIER'
from a BG95 modem while being in data mode.
The reason 'NO CARRIER' occured was due to crosstalk to DTR which
terminated data mode.
The logic analyzer also revealed that without the delay the next AT
command is sent before the whole 'OK\r\n' is received. This is not
addressed in this commit.
Fixes https://github.com/zephyrproject-rtos/zephyr/issues/47082
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
If hw-flow-control is set in the uart section of the device tree source,
it is read by gsm_ppp.c and AT+IFC=2,2 is sent to the modem.
Fixes https://github.com/zephyrproject-rtos/zephyr/issues/46928.
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Default mode must be debug or it can't ever be enabled.
Allow debug log messages to be printed when using
mdm_hl7800_send_at_cmd API.
Add logging to active bands and network coverage commands.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Using a global error flag could lead to an error on one
socket appearing as an error with a separate socket instance.
Socket errors moved into the socket context.
Continue to use global error flag for commands not
related to sockets.
For TCP sockets closed by the server, don't try and close
the socket again when offload_put is called.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Files including <zephyr/kernel.h> do not have to include
<zephyr/zephyr.h>, a shim to <zephyr/kernel.h>.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
These drivers use stack buffers to hold AT command strings which are
generated at runtime using sprintk. The buffers are only sized for the
expected range of values, not the full possible range given the datatypes
involved. Values outside this expected range could cause a buffer overflow.
To mitigate this, increase the size of each buffef to hold the full range
of each parameter type.
Signed-off-by: Keith Packard <keithp@keithp.com>
Log message references gsm->context.data_rssi which is NULL
when CONFIG_MODEM_SHELL=n. Use gsm->minfo.mdm_rssi which is
internally used when accessing RSSI value.
Signed-off-by: Marek Metelski <marek@metelski.dev>
Check if ppp iface was actually up before taking it down and waiting
for NET_EVENT_IF_DOWN. This allows to call gsm_ppp_stop() even if
the PPP was never started, which previously caused the call to lock
forever. This case is useful, for example, if the modem didn't attach
to network in desirable time and user wants to abort PPP setup.
Signed-off-by: Marek Metelski <marek@metelski.dev>
Do not truncate outgoing datagrams if they do not fit in maximum handled
packet size. Set EMSGSIZE errno and return -1 instead.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Coverity reported unused value for a variable "ret" in the function
send_socket_data(). Indeed there were two subsequent assignments
to "ret", meaning that the first one was unused.
The root cause of the problem is not checking the value of "ret"
after correctly invoking a function within send_socket_data(). Fix
this by adding appropriate checks.
Coverity-CID: 215249
Signed-off-by: Aleksandar Markovic <aleksandar.markovic.sa@gmail.com>
Check if there are multiple non-empty data fragments passed to sendmsg()
function. If positive, then set EMSGSIZE errno and return -1, as that case
is not handled properly with current implementation.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
If one data fragment was not sent successfully in sendmsg(), then
attempting to send the rest does not make any sense, as it would introduce
hole in data stream.
Currently if one fragment was not sent successfully, then there is a
'break' in inner loop, but that moves the execution to sending the
following data fragments.
Return early in case of fragment sending failure, so that there are no more
send attempts.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
added user_data field to modem_cmd_handler_data
this allows for multiple instances of modem drivers which use
the modem cmd handler. currently, the only identifiable
parameter passed to the modem command handlers is the
modem_cmd_handler_data struct.
The added user_data variable allows for the a modem driver to
pass its dev or data pointer to the modem_cmd_handler_data
struct to be retrieved from within the modem command callbacks.
Signed-off-by: Bjarki AA <baa@trackunit.com>
All drivers using 'modem_pin' abstraction were converted already, so remove
its implementation now.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Move away from 'modem_pin' abstraction as it has not obvious value compared
to generic 'gpio_dt_spec'.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Move away from 'modem_pin' abstraction as it has not obvious value compared
to generic 'gpio_dt_spec'.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Move away from 'modem_pin' abstraction as it has not obvious value compared
to generic 'gpio_dt_spec'.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
mux_enabled check in the gsm_configure is unnecessary since it
is init and scheduled by gsm_ppp_start which means that the
mux must be disabled. The IS_ENABLED(CONFIG_GSM_MUX) check
should be good enough to determine whether or not the
mux_enable function should be ran.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
After the introduction of start/stop & rssi query work, these
additional functions can be invoked from different threads.
Things can quickly become hard to analyze when an interrupt
fires during one of these functions and upon return the
scheduler schedules another thread and run another function.
This PR introduces a simple mutex lock that guarantees thread
safety. Similar implementation can be found in hl7800 driver,
which has lots of public APIs that can be invoked from different
threads.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Update gsm_ppp.c
Move the rssi query part out from the rssi_handler work item as
an individual function, so that it can be used directly without
referencing the work.
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Adds a communications backend based on the asynchronous UART API,
instead of the interrupt-driven UART API. The primary advantage of this
backend is an improved robustness to dropping bytes under high interrupt
or critical section loads.
Under all loads system efficiency is improved by:
* Reducing the time spent writing out individual bytes.
* Reducing the number of UART interrupts fired.
* Waking up the RX thread much less often.
When utilising this backend over `nordic,nrf-uarte` on a nRF52840, the
baudrate of an esp-at modem could be pushed to at least 921600 without
dropping bytes, compared to a maximum of 230400 with the interrupt API.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Add a choice symbol that is used to select which UART backend to use.
This allows backends that don't use the interrupt API to be implemented.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>