Commit graph

233 commits

Author SHA1 Message Date
Anas Nashif 5fa12073cb drivers: remove what appears to be code from comments
Some tools consider this as commented code because of the ifdef, so
remove that and fix a coding guideline violation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-01 05:34:17 -04:00
Robert Lubos e45de8d703 drivers: modem: wncm14a2a: Explicitly ignore unused return value
Coverity complains about unchecked return value for `k_sem_take` which
is called with `K_FOREVER` and thus cannot expire/timeout. Explicity
ingore the return value to silence Coverity.

CID: 219676
Fixes #33019

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-03-24 12:23:55 +01:00
Anas Nashif 5d6c219210 drivers: device: do not reuse tag name 'device'
Do not reuse tag name (misra rule 5.7).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 19:48:14 -04:00
Xavier Chapron 30c9588aaa drivers: modem: ublox-sara-r4: Fix dereference before null check
Fixes #32916

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2021-03-17 07:25:59 -05:00
Benjamin Lindqvist 4626a577c4 drivers: modem: gsm_ppp: Kconfig for autostarting ppp
Autostarting PPP is far from controversial. There are many, many reasons
someone could have for wanting to control exactly when PPP starts. Power
management, NET_EVENT race condition avoidance and any application not
requiring constant and instant use of networking just to name a few.

This commit introduces a Kconfig setting, GSM_PPP_AUTOSTART, which
controls whether gsm_ppp should connect and initialize PPP at boot. It
is set to "y" as default to minimize surprises for legacy code.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-03-12 13:27:22 +02:00
Guðni Már Gilbert 6145ab537f drivers: modem: fix coverity issue
Added (void) cast to supress coverity report. The usage of K_FOREVER
tells me we're not interested in the returned value.

Coverity-CID: 219653
Fixes #33034

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2021-03-11 10:08:19 -05:00
Benjamin Lindqvist 254c126236 drivers: modem: optional factory reset at modem boot
Some modems, under some conditions, have a tendency to get stuck without
a connection due to cached state. We have observed this on some Simcom
LTE modems after large cellular outages. The modems are unable to escape
their cached state for some reason unless they're factory reset (or a
cache clearence is forced in some other way).

This commit allows for the modem to be factory reset at each boot. This
minimizes dependencies on external state by ensuring each power-up is as
similar as possible.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-03-06 09:09:35 -06:00
Thomas LE ROUX f360718d0b drivers: modem: Fix PDP context management for BG9X
The PDP context might be active.
If that's the case, the AT+QIACT command returns an error.
It's then not possible to succeed at setting up the module.

Furthermore, we apply the logic described in the Quectel Documentation :
- If there is an issue 3 consecutive times on activating/deactivating
the context, we restart the module.
- If the AT+QIDEAT command returns an error, we restart the module.

This PR is bug-fix aimed.
We leave parameterization of context ID for future enhancement.

Signed-off-by: Thomas LE ROUX <thomas.leroux@smile.fr>
2021-02-23 12:01:27 +02:00
Jacob Siverskog 4b5a2b989e drivers: modem: quectel-bg9x: fix potential null pointer dereference
reorganize code so that null pointer check is done prior to accessing
element.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-02-16 19:31:11 +02:00
Marcin Niestroj 1e15ca94ff drivers: modem: wncm14a2a: Convert driver to new DT device macros
Convert wncm14a2a driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Marcin Niestroj 2ae9c262c9 drivers: modem: quectel-bg9x: Convert driver to new DT device macros
Convert quectel-bg9x driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Marcin Niestroj a2d940ab80 drivers: modem: hl7800: Convert driver to new DT device macros
Convert hl7800 driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Marcin Niestroj dd55786ffc drivers: modem: ublox-sara-r4: Convert driver to new DT device macros
Convert ublox-sara-r4 driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

DT label is already required, so use it and drop
CONFIG_MODEM_UBLOX_SARA_R4_NAME option.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Guillaume Paquet 143a776657 boards: arm: nordic: Add BG96 to RAK5010 board
Add BG96 in board description
Add W Disable Pin in BG96 descriptor

Signed-off-by: Guillaume Paquet <guillaume.paquet@smile.fr>
2021-02-15 08:25:46 -05:00
Ryan Erickson f1f309d56b drivers: modem: hl7800: fix buffer null termination
Fix possibility of no_id_resp_cmd buffer missing a
null terminator.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-01-27 08:03:45 -05:00
Ryan Erickson a7b61fa2a8 drivers: modem: hl7800: fix possible null reference
Ensure sock is not referenced if it is null.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-01-27 08:03:24 -05:00
Xavier Chapron 47da2bed27 drivers: modem: sara-r4: Add sanity timeout for @ prompt
This wait on @ prompt was added in
fa3d586483.
The situation were the @ prompt is never received should not occurs,
however it's definitively safer to catch it instead of having a
deadlock.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2021-01-22 10:04:11 -05:00
Emil Lindqvist 09e9736b4b drivers: modem: ublox-sara-r4: remove redundant wait after sendto
According to AT commands manual, no wait after prompt '@'
is required if using AT+USOST commmand (aka. sendto,
only used with UDP).

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-01-15 12:41:25 +02:00
Guillaume Paquet 6e7a2ecf1e drivers: modem: Fix UDP management in BG96 modem
Fix UDP test in connect and send to be able to send in TCP

Signed-off-by: Guillaume Paquet <guillaume.paquet@smile.fr>
2021-01-15 08:45:51 +02:00
Akseli Peltola 3bcb1efc33 modem: fix socket descriptor leak
z_free_fd() is called twice then you close(). For example in ublox sara
r4 driver offload_close() calls modem_socket_put() where z_free_fd() is
called first time. Then this same function is called another time in
socket.c in z_impl_zsock_close() after this function has called
offload_close() in ublox sara r4 driver. This causes socket
descriptor leak.

Fixes #26819

Signed-off-by: Akseli Peltola <peltsu1324@gmail.com>
2021-01-07 10:36:19 +02:00
Marcin Niestroj 1b680c8234 drivers: modem: wncm14a2a: set NET_CONTEXT_CONNECTED state
Set NET_CONTEXT_CONNECTED when stream socket got connected. This fixes
TCP connection when using wncm14a2a modem driver, which got broken after
sockets layer started to validate net_context connection state before
allowing to receive any data.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-14 18:15:49 +02:00
Anas Nashif dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Marcin Niestroj 5cbf2ec1f7 drivers: modem: fix sending with zero timeout and no semaphore
There was a regression introduced when reordering function parameters
check. It is valid to pass NULL semaphore with zero timeout, so fix
parameter check to respect that.

Fixes: 67976f8686 ("drivers: modem: verify send semaphore before
  taking any action")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-07 10:25:56 +02:00
Xavier Chapron d66d748b71 drivers: modem: sara-r4: Improve offload_sendmsg() support
Previously, msghdr was handled by forwarding each msg_iov to
offload_sendto() one by one.
This is not optimal, as msg_iov payload might have been sent
simultaneously which would be faster.
With this commit, send_socket_data() expect payload to be formated as
struct msghdr which can be used directly by both offload_sendto() and
offload_sendmsg().

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron 6020d4ce53 drivers: modem: sara-r4: Add Kconfig to configure RSSI work
This comit introduce two new Kconfig which allow to configure RSSI
polling work.
One Kconfig allow to completely disable the polling.
The other one allow to sonfigure the polling period.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron fa3d586483 drivers: modem: sara-r4: Add direct CMD to catch @ when sending data
Replace hard coded wait by real detection of '@'.
This make sure that datasheet timings are correctly followed.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron 7129aff701 drivers: modem: sara-r4: Sanitize send_socket_data() semaphore handling
Reset of the sem_response semaphore should be done before sending data.
This prevent any potential race conditions between the rx thread and the
thread running send_socket_data().

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron 900d48c88b drivers: modem: modem_socket: Reset all socket data upon socket_put
Some data where not properly reset on socket_put() and not correctly
initialized at socket creation. Which means we were potentially re-using
data from previous use of this socket.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron 3d61989bc7 drivers: modem: modem_cmd_handler: Allow dynamic number of commands args
This is necessary to allow parsing of commands with dynamic number of
arguments.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Xavier Chapron 7d67991a91 drivers: modem: modem_socket: Fix blocking modem_socket_poll
Before this commit, if a socket had received data before calling the
poll function, then the poll was waiting for either new data or a
timeout.
With this fix, polled socket are check for pending data before the
semaphore wait.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-12-03 17:37:48 -05:00
Bilal Wasim 503a70a40a drivers: modem: Add support for quectel bg95
Adding support for Quectel BG95 Modem offloaded driver
to zephyr.

The driver currently implements only the
client side functions of the "socket_op_vtable", and
so cannot be used for cases where Zephyr acts as a
server. Moreover the driver only supports TCP for now.

Looking through the guides, the same driver should be
usable for BG96 (and other modems) except for the modem
boot-up sequence. Hence its named as "bg9x" instead of
"bg95".

Tested extensively with Zephyr acting as MQTT endpoint
and publishing / subscribing data to / from an MQTT
broker.

Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
2020-12-01 17:43:59 -05:00
Marcin Niestroj 9fe279f744 drivers: modem: don't clear out cmd handlers if they were not setup
There is no point in clearing out command handlers if they were not
setup properly. Just skip to next instruction.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:15:19 -05:00
Marcin Niestroj eae32b7e7a drivers: modem: fix race condition when waiting on cmd reply
Command was sent first, then a semaphore was reset. This semaphore could
be released by received reply even before semaphore was reset. This is
quite unlikely, but possible result of race condition.

Move k_sem_reset() call before attempt to send command over modem
interface. This makes sure that receiving reply momentarily after
sending request will always be handled properly.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:15:19 -05:00
Marcin Niestroj 67976f8686 drivers: modem: verify send semaphore before taking any action
Semaphore argument is checked only after requested command is already
sent over modem interface. It makes little sense to return -EINVAL when
half of the requested operation (send) has already been done.

Check timeout and semaphore arguments just on the beginning of
function. Return -EINVAL early, before sending any data or taking any
locks.

Clear out 'sem' variable when there is no need to wait. Use this
variable later on as an indication to actually wait on semaphore or not.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:15:19 -05:00
Marcin Niestroj 5e3d542862 drivers: modem: hl7800: don't cleaup net_context members
There is no reason to clenaup members of net_context structure, as those
should be (and are) managed by net_context_put() implementation.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:13:48 -05:00
Marcin Niestroj 33a90f20e9 drivers: modem: wncm14a2a: don't cleaup net_context members
There is no reason to clenaup members of net_context structure, as those
should be (and are) managed by net_context_put() implementation.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:13:48 -05:00
Marcin Niestroj c934e74bf9 drivers: modem: gsm_ppp: constify modem_cmd and setup_cmd structures
Constifying global data allows to save lots of RAM. This improvement
allows to save 224 bytes of RAM when compiled on ARM, with default
configuration.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-24 12:59:50 +02:00
Marcin Niestroj ddf2278c3f drivers: modem: ublox-sara-r4: constify modem_cmd and setup_cmd structures
Constifying global data allows to save lots of RAM. Defining data inside
function as 'static const' allows on the other hand to save stack usage
and reduced code size (because data doesn't have to be copied on stack
in runtime).

This improvement allows to save 448 bytes of RAM and 88 bytes of ROM
when compiled on ARM, with default configuration.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-24 12:59:50 +02:00
Marcin Niestroj 1d25e9c6ae drivers: modem: constify modem_cmd and setup_cmd structures
modem_cmd and setup_cmd structures are used only to store static
information about commands to be sent and replies to be
received. Reference it as const, so that it is possible to define const
instances and save some RAM space by placing those definitions entirely
in ROM.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-24 12:59:50 +02:00
Jukka Rissanen b16602afb5 drivers: modem: gsm: Fix DEVICE_DEFINE() data ptr
The commit 5e97d779bb ("device: convert DEVICE_INIT to DEVICE_DEFINE
or SYS_DEVICE_DEFINE") did not convert the gsm_ppp.c properly. The
power management parameter was not set to NULL but was pointing to
the data pointer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-11-16 14:26:37 -05:00
Kumar Gala 5e97d779bb device: convert DEVICE_INIT to DEVICE_DEFINE or SYS_DEVICE_DEFINE
Convert handful of users of DEVICE_INIT to DEVICE_DEFINE or
SYS_DEVICE_DEFINE to allow deprecation of DEVICE_INIT.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-11-10 08:38:09 -06:00
Trond Einar Snekvik 86c793af3f sys: util: Replace MIN(MAX(a, b), c) with CLAMP
Replaces all existing variants of value clamping with the MIN and MAX
macros with the CLAMP macro.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-05 12:12:17 +01:00
Ryan Erickson d3dcf49735 drivers: modem: hl7800: Make RX net_bufs configurable
Make receive network buffer count and size
configurable via kconfig.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-10-30 10:09:48 +02:00
Marcin Niestroj 5fa69327f2 drivers: modem: ublox-sara-r4: allocate in modem_cmd_handler with K_NO_WAIT
All net_bufs allocated to modem_cmd_handler's data->rx_buf are consumed
synchronously in ublox-sara-r4.c in the same thread. This means that
allocating them with timeout makes no sense, because timeout
will *always* be hit when there are no more buffers in net_buf_pool.

Get rid of the unnecessary timeout, as it doesn't help and just slows
down processing of incoming data, increasing possibility of data
overrun.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-27 09:32:51 -05:00
Marcin Niestroj 94caa8f2fd drivers: modem: gsm: allocate in modem_cmd_handler with K_NO_WAIT
All net_bufs allocated to modem_cmd_handler's data->rx_buf are consumed
synchronously in gsm_ppp.c in the same thread. This means that
allocating them with timeout makes no sense, because timeout
will *always* be hit when there are no more buffers in net_buf_pool.

Get rid of the unnecessary timeout, as it doesn't help and just slows
down processing of incoming data, increasing possibility of data
overrun.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-27 09:32:51 -05:00
Marcin Niestroj 318cbe649a drivers: modem: cmd_handler: rework reading from interface
So far a dedicated buffer was used for data read from modem
interface. New net_bufs were allocated and filled later, which means
that data was lost when no more net_bufs were available in the pool.

Prevent data loss by allocating net_buf before attempting any read on
modem interface. Process incoming data in a loop as long as reading from
interface results in new data. Also remove dedicated buffer
(data->read_buf) and directly fill net_buf content instead. As a side
effect there are less memory copy operations and RAM usage is reduced.

Pre-allocated net_buf is now always appended to data->rx_buf. When there
was no (more) data read from interface to such net_buf, then this empty
net_buf will be on the end of data->rx_buf fragment list. Update
skipcrlf() and findcrlf() implementations to explicitly check for each
net_buf length, instead of blindly assuming them to have at least single
byte.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-27 09:24:38 -05:00
Marcin Niestroj 3d659a35bb drivers: modem: cmd_handler: split cmd_handler_process() implementation
cmd_handler_process() does two major things:

 - reads data from modem interface and fills data->rx_buf,
 - processes data in data->rx_buf.

Split implementation accordingly to two separate functions, which
improves readability (less automatic variables to follow at once) and
simplifies refactoring of each action.

No functional change was intended in this commit.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-27 09:24:38 -05:00
Kumar Gala 9f97a1c8ab drivers: modem: wncm14a2a: fix build if CONFIG_MODEM_SIM_NUMBERS=n
If CONFIG_MODEM_SIM_NUMBERS is 'n' than the data_imei field of struct
modem_context doesn't exist, so add ifdef protection for that case.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-10-23 08:53:38 -05:00
Benjamin Lindqvist e7df25c848 drivers: modem: gsm_ppp: lock modem when required
If other threads are accessing the modem concurrently during gsm_ppp
initialization, they can easily corrupt UART comms. Normally this is not
noticable since those services are usually started only after modem
setup has been completed. But with the new gsm_ppp stop/start
functionality, the need of synchronizing concurrent access in a
structured way has arisen.

This commit ensures modem_cmd_handler is locked when concurrent access
to the modem UART would interfere with the driver, or otherwise cause
problems. Since the semaphore is not available during this period, all
essential calls to modem_cmd_send has been replaced with the non-locking
equivalents.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-21 10:15:45 +03:00
Benjamin Lindqvist 820bb07c81 drivers: modem: cmd_handler: Allow locking TX
A semaphore is used by modem_cmd_handler to protect against concurrent
UART access. This is only used for the duration of sending a command,
but there are cases when one wants to prevent UART access for other
reasons, such as when powering off the modem.

This commit exposes functionality for hogging this semaphore without
having to send a command. Furthermore, a non-locking equivalent for
modem_cmd_handler_setup_cmds is added which was previously missing.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-21 10:15:45 +03:00