Commit graph

523 commits

Author SHA1 Message Date
Yong Cong Sin c7267dc26a drivers: modem: gsm: remove mux_enabled flag and checks
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>
2022-06-05 14:13:45 +02:00
Yong Cong Sin b7eb2202e3 drivers: modem: gsm: introduce lock
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
2022-06-05 14:13:45 +02:00
Yong Cong Sin 975bc85b14 drivers: modem: gsm: move the rssi query an individual function
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>
2022-06-05 14:13:45 +02:00
Jordan Yates 95d8deb572 modem: modem_iface_uart_async: added
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>
2022-05-10 10:44:04 +02:00
Jordan Yates 5228de3af5 modem: choice symbol for UART backend
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>
2022-05-10 10:44:04 +02:00
Ryan Erickson ab9715031c modem: hl7800: fix UART shutdown
Allow CTS line to determine UART shutdown for any sleep mode.
This allows lower average current consumption for LITE
HIBERNATE mode.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-05-06 20:17:23 +02:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Ryan Erickson b8aa44ec46 modem: hl7800: do not query SIM if not present
Do not query SIM card parameters if the SIM
card is not present.
This shortens the driver initialization time
significantly if a SIM card is not present.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-05-04 09:49:17 -05:00
Robert Lubos 7946988b16 net: sockets: Add separate macro for registering offloaded sockets
Add a separate macro for registering offloaded sockets implementation,
along with information in the structure whether the implementation is
offloaded or not. This allows to differentiate between native and
offloaded socket implementations, which is critical for binding socket
API with an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-20 11:27:05 +02:00
Robert Lubos fa8ba73833 net: if: Connect interface with offloaded socket implementation
Instead of keeping a boolean informing whether a network interface is
offloaded at socket layer or not, keep a pointer to a function which
allows to create an offloaded socket. Native interfaces keep this as
NULL, while for offloaded interfaces it allows to connect an offloaded
socket implementation with an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-20 11:27:05 +02:00
Marcin Niestroj f9e2fad7e3 modem: quectel-bg9x: implement 'is_supported' socket offload cb
Check if requested socket family, type and protocol are all supported by
the driver, instead of blindly acknowledging every possible variant.

There is explicit support for TCP on top of IPv4 and IPv6.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:51:24 -07:00
Marcin Niestroj 61dfdf1d60 modem: sim7080: implement 'is_supported' socket offload cb
Check if requested socket family, type and protocol are all supported by
the driver, instead of blindly acknowledging every possible variant.

There is explicit support for UDP and TCP on top of IPv4 and IPv6.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:51:24 -07:00
Marcin Niestroj a0c5c176a0 modem: ublox-sara-r4: implement 'is_supported' socket offload cb
Check if requested socket family, type and protocol are all supported by
the driver, instead of blindly acknowledging every possible variant.

There is explicit support for UDP, TCP and TLS on top of IPv4 and IPv6.
TLS seems to be supported only in 1.2 version, so allow just that
version.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:51:24 -07:00
Marcin Niestroj 19b75f47c0 modem: quectel-bg9x: use NET_SOCKETS_OFFLOAD_PRIORITY
Use NET_SOCKETS_OFFLOAD_PRIORITY instead of
NET_SOCKETS_OFFLOAD_PRIORITY, so that by default offloaded sockets will
be used instead of native sockets.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:50:11 -07:00
Marcin Niestroj aae48b5c32 modem: sim7080: use NET_SOCKETS_OFFLOAD_PRIORITY
Use configurable NET_SOCKETS_OFFLOAD_PRIORITY instead of hardcoded value
in the driver itself. This allows to select relative priority of
offloaded TLS versus native TLS when used together with
NET_SOCKETS_TLS_PRIORITY.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:50:11 -07:00
Marcin Niestroj 6e81f891c6 modem: ublox-sara-r4: use NET_SOCKETS_OFFLOAD_PRIORITY
Use configurable NET_SOCKETS_OFFLOAD_PRIORITY instead of hardcoded value
in the driver itself. This allows to select relative priority of
offloaded TLS versus native TLS when used together with
NET_SOCKETS_TLS_PRIORITY.

Drop the build assert, as always prioritizing offloaded TLS over native
TLS should be application developer choice.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-04-08 15:50:11 -07:00
Ryan Erickson 69ffc1f228 modem: hl7800: add API to set bands
Add API to set LTE bands at runtime.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-03-30 11:39:06 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Xavier Chapron 5cc583bf3a drivers: modem: modem_cmd_handler.c: Drop cmd from buf if args are missing
In 90c6dc5e7f, a change was introduced to
allow modem commands determine if they have enough data or not.
In a situation where some data is missing, the command should return
-EAGAIN and this should lead to another call of the command with more
data.
In this commit, the argument parser was also allowed to return -EAGAIN
to request more data due to missing arguments.

However, this can't work because in cmd_handler_process_rx_buf() before
calling process_cmd():
- we make sure that a CR/LF has been found.
- we compute match_len which can't be greater than the distance to the
  next CR/LF.
Therefore, even if the command argument parser ask for more data by
returning -EAGAIN, next call will have the same value for match_len,
meaning that the parsing of argument will result in the same missing
argument situation.
This leads to an infinite loop of parsing the same data over and over in
an infinite loop.

This commit change this behavior to always drop the data in such a
situation. The command will not be answered and will therefore timeout,
but at least, next commands will correctly parse their returned data.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2022-03-17 11:33:17 +01:00
Yong Cong Sin 2befd6ef87 drivers: modem: gsm: Use Kconfig macros directly
Use the Kconfig macros of MODEM_GSM_RX_STACK_SIZE and
MODEM_GSM_WORKQ_STACK_SIZE directly without another macros.

They are well within the column limit and this make them
more obvious that they are actually configurable by Kconfig.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-16 10:23:32 +01:00
Yong Cong Sin 9ee8c12a24 drivers: modem: gsm: wait for cellular registration
The driver should check for cellular registration before
attempting to attach to packet service, otherwise it will just
fails.

This patch waits for registration for 300 seconds, configurable
by CONFIG_MODEM_GSM_REGISTER_TIMEOUT, if it isn't registered by
then, it would toggle the airplane mode using AT+CFUN & wait
again, until it is registered, or `gsm_ppp_stop` is invoked.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-03-16 10:23:32 +01:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Gerard Marull-Paretas dffaf5375c kconfig: tweak Kconfig prompts
Tweak some Kconfig prompts after the removal of "Enable...".

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Rene Bredlau 876ea8d215 modem: hl7800: use correct timeouts on KTCPSND to avoid internal deadlock
The response of a KTCPSND has two phases. According to documentation by
wireless the timeout is 60 seconds. The fix respects the timeout on the
second phase, too (waiting for OK or errors from modem). Previously only
the first phase used 60 seconds and the second phase used 5 seconds.

Without this fix the hl7800 will lock the tcp stack for the current
socket indefinitely if another socket operation is performed before the
response from the modem is received.

Additionally all timeouts are adjusted to be at least one second longer
as the documented timeout from wireless. This avoids races between the
hl7800 and the driver.

Signed-off-by: Rene Bredlau <git@unrelated.de>
2022-03-07 09:24:25 -06:00
Yong Cong Sin 6e6009ea55 drivers: modem: gsm: define retry delay in macro
Define the delay used to reschedule work when AT command failed
in a macro.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin a5394e865a drivers: modem: gsm: Define tx_lock timeout at the top
The tx_lock timeout is closely related to GSM_CMD_AT_TIMEOUT
& GSM_CMD_SETUP_TIMEOUT, and should be longer than both of
them, otherwise the gsm_ppp_stop might fail to lock the tx.

Define the timeout at the top of the driver and added a comment
to make it clear for the user.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 7a6764987e drivers: modem: gsm: remove use of preprocessor directives for rssi
The rssi_work_handle always exists in the gsm struct, so use

```
if (IS_ENABLED(CONFIG_GSM_MUX))
```
instead of

```
#if defined(CONFIG_GSM_MUX)
```

for better code readability.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin f505028280 drivers: modem: gsm: cancel rssi work only if GSM_MUX is enabled
There's no need to cancel rssi work when CONFIG_GSM_MUX isn't
enabled, since it is not scheduled.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 62c383d062 drivers: modem: gsm: rssi_work should be submitted to gsm workq
The rssi_work_handle should be submitted to the gsm workqueue
using the gsm_work_reschedule, fix that.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin cd216b17e0 drivers: modem: gsm: Reset attached flag on stop
The 'attached' flag should be reset on gsm_ppp_stop, or else
some part of the gsm_finalize_connection won't be executed
during the next gsm_ppp_start.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin db31558c7d drivers: modem: gsm: Convert gsm_finalize_connection to work
Convert gsm_finalize_connection into a work so that the caller
work won't have to run again when gsm_finalize_connection
reschedule gsm_configure_work on error.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin c063c44028 drivers: modem: gsm: Go to next state if mux_attach successfully
Currently the mux_setup set the state to the next one after
uart_mux_alloc is successful even if the mux_setup fails which
can be a problem.

Set the state after both mux_setup & uart_mux_alloc are
successful.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin ef2d51c076 drivers: modem: gsm: Remove unnecessary mux_enabled check
Remove redundant mux_enabled checks, the code execution will
not reach here if mux_enabled is false in the first place.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 2984a9c322 drivers: modem: gsm: Customize error logs to ease debugging
Customize the error logs in each connection finalization steps
so that it is easier to trace the error.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 499412a60d drivers: modem: gsm: Reorder gsm mux logs so that it will be printed
The gsm_configure will return if it fails to perform mux_enable,
therefore the disable part of the log will not be printed.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 00513c90c5 drivers: modem: gsm: Remove unused flags
The `setup_done` and `mux_setup_done` aren't being used
anywhere in the driver, therefore should be removed.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin 7dc1e790a8 drivers: modem: gsm: Init rssi_work_handle on gsm_init only
Initializing rssi_work_handle on gsm_start would (re)init it
unnecessarily everytime the gsm_start is invoked, we only need
to initialize it once in the gsm_init.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Yong Cong Sin b2dd782879 drivers: modem: modem_cmd_handler: Fix missing documentations
Fix missing documentations.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-28 11:05:06 +01:00
Ryan Erickson 34acbceef5 modem: hl7800: CTS to monitor sleep
Use CTS input to monitor HL7800 sleep state
when in SLEEP mode.
When CTS is high, shutdown the UART to
save power.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-25 10:10:22 -08:00
Ryan Erickson 48cca618fb modem: hl7800: fix +CFUN handler
Fix the +CFUN command handler to find
the end of the message properly.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-25 09:56:43 -08:00
Yong Cong Sin 176bd02a56 drivers: modem: gsm: +CSQ shouldn't give sem_response
The +CSQ: is followed by 'OK' or 'ERROR', so its handler
should not give sem_response.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-24 13:57:48 -08:00
Yong Cong Sin 6bf44c5af5 drivers: modem: gsm: +CGATT shouldn't give sem_response & set error
The +CGATT: is followed by 'OK' or 'ERROR', so its handler
should not set error code and give sem_response.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-24 13:57:48 -08:00
Ryan Erickson 8c1387ef1a modem: hl7800: Make RSSI rate configurable
Improve ability to sleep.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-24 13:46:33 -08:00
Ryan Erickson 05e818c51c modem: hl7800: Add callbacks for sleep IO
Allows mapping of sleep signals to user
accessible test points on the development
board.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-24 13:46:18 -08:00
Yong Cong Sin 71707745b2 drivers: modem: gsm: Kconfig: Add MODEM_GSM_TYPE to choice
Add a name for the choice of gsm modem so that it can be
default to a certain type in board's Kconfig.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-24 08:45:16 -06:00
Ryan Erickson a9804002e2 modem: hl7800: Use built in socket restore on boot
When sleep modes are used, configure sockets
to restore on boot. Letting the HL7800 manage
this means the driver does not have to do it.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-21 22:01:23 -05:00
Ryan Erickson cdff607d74 modem: hl7800: Make sleep mode configurable
Allow application to choose between 3 different low power levels of modem.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-21 21:57:52 -05:00
Yong Cong Sin e15f6f121f drivers: modem: gsm: add handler for +CME ERROR
The driver enabled extended error code (AT+CMEE=1) during
setup but is missing a handler for the +CME ERROR, fix that.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-02-21 20:40:22 -05:00
Sjors Hettinga 60beb291df drivers: gsm: Wait for NET_EVENT_IF_DOWN in in gsm_ppp_stop
Waits until the network interface goes down before switching the
GSM_MUX. It uses the NET_MGMT_EVENT to signal a semaphore to
contiue when closed. This allows for the LCP state machine to
properly terminate. When skipping this wait, the second time
connecting, the connection might fail.
Tested on a real modem.

Fixes GSM PPP behavior in combination with: #41802

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2022-02-21 20:39:44 -05:00
Guillaume Lager 4d777b43fd drivers: modem: Fix loop variables type
int was used regardless of the type used in the
end-loop condition

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
2022-02-04 11:19:28 +01:00
Ryan Erickson a9eead1824 modem: hl7800: only send null packet for TCP
Only TCP sockets should send a NULL packet
if the server closes the connection or there
is a socket error.
UDP sockets do not need to do this because
they are connectionless.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-02-04 10:57:15 +01:00
Yong Cong Sin 41bff12625 drivers: modem: gsm: Use K_KERNEL_* macros
GSM workq is a system only thread, use K_KERNEL_* macros
instead of K_THREAD_*

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-21 14:39:30 -05:00
Yong Cong Sin e77d87da65 drivers: modem: gsm: Fix NULL being passed to rssi_handler
Fix hard fault due to NULL being passed as argument into
rssi_handler, which now derives the gsm_modem struct pointer from
the argument.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-05 14:57:16 -05:00
Yong Cong Sin 19910666e0 drivers: modem: gsm: Cancel the work when stopped
gsm_ppp_stop should cancel possible running work items.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
2022-01-04 15:03:06 -06:00
Yong Cong Sin d9ea07b7bd drivers: modem: gsm: convert work to delayable work
The 'work' argument of a delayable work's handler should be
converted to delayable work before passing into the CONTAINER_OF
macro.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-04 15:03:06 -06:00
Yong Cong Sin b2b9343c95 drivers: modem: gsm: declare structs in gsm_modem
Move the declarations of a few structs into the struct
gsm_modem

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-04 15:03:06 -06:00
Yong Cong Sin 522eff91e5 drivers: modem: gsm: Use dedicated workq
The driver performs AT commands configurations using the
system workqueue, this can delay the workqueue by up to 6
seconds to wait for the modem replies, which isn't ideal.

This PR creates a dedicated workqueue for the gsm, and
provides a helper function to reschedule work items to the
gsm workqueue.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-01-01 07:40:13 -05:00
Lukas Gehreke 53dea67733 drivers: modem: Added simcom sim7080 modem driver.
Implemented driver for the simcom sim7080 modem.
This driver features Socket offloading, TCP, UDP, DNS,
SMS, GPS and FTP.

Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
2021-12-20 17:48:47 +01:00
Gerard Marull-Paretas 89a4f36fc8 device: remove inclusion of pm/device.h
The device PM subsystem _depends_ on device, not vice-versa. Devices
only hold a reference to struct pm_device now, and initialize this
reference with the value provided in Z_DEVICE_DEFINE. This requirement
can be solved with a forward struct declaration, meaning there is no
need to include device PM headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-29 11:08:38 +01:00
Flavio Ceolin 6451626ce7 pm: Use pm_device_action_run instead of state_set
Since drivers implement a callback based on action and not the state,
we should be using the API based on the action instead of the one based
on the state.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-24 14:21:50 -05:00
Wouter Cappelle ebed957005 modem: Update modem sockets poll to allow eventfd
The modem sockets poll implementation does not allow
a combination of poll on modem sockets and on other sockets
like eventfd. This blocks trivial application signalling. Current
users are using a poll timeout, which needs to check if other
work needs to be done in the thread (eg: lwm2m engine).
To allow proper signalling with eventfd, the non offload poll
methods needs to work for the modem sockets.
This commit is implementing this for POLLIN.

Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
2021-11-11 19:12:46 -05:00
Emil Lindqvist 38eed4a49e sara-r4: increase socket processing prio
Higher socket processing prio is required for offloaded sockets.

Resolves #40074

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-11-09 14:40:54 -05:00
Ryan Erickson 270608139f modem: hl7800: remove NEWLIB_LIBC dependency
Zephyr LIBC minimal has definitions for struct tm.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-11-09 11:19:02 +01:00
Bartosz Bilas ee7cd10563 drivers: modem: improve modem context RSSI member
The previous bf68b67 commit incorrectly passes minfo.mdm_rssi
value to the modem context data_rssi member during the driver
initialization which causes the `modem info` shell command
to return 0 as RSSI value. Fix that by changing data_rssi
modem ctx member to a pointer that is assigned to the RSSI
variable stored within the modem driver context structure.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2021-11-07 15:02:43 +02:00
Guillaume Lager ec0d5b6e8d driver: modem: Fix mux device name comparison
CONFIG_UART_MUX_DEVICE_NAME is used as a prefix for the uart muxes
name. Pointer comparison will always return false

Fix #39774

Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
2021-11-06 10:20:42 -04:00
Jair Jack 8e95b95bb4 drivers: modem: gsm: Fix to COPS cmd parse info
drivers: modem: gsm: Quectel EC21 and BG9x act as a gsm modem without
problem, but COPS commands can returns just one value with 'mode'.

Format and oper are not mandatory. This modification reads 'mode'.
Also a modification on modem_cmd_read_cops_cmd is needed.

Signed-off-by: Jair Jack <jack@icatorze.com.br>
2021-11-06 10:20:11 -04:00
Bartosz Bilas bf68b670f1 drivers: modem: gsm: extend modem info struct about RSSI value
Add RSSI member into gsm_ppp_modem_info structure in order to
get that information using the gsm_ppp_modem_info function.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2021-10-26 14:47:38 +03:00
Bartosz Bilas 5107691441 drivers: modem: gsm: allow the user to get modem information
Make modem_info structure public in order to allow the user
to get modem information using gsm_ppp_modem_info function.
Move modem info query commands into separate function
that's called only once during gsm configuring because
there is no necessity to re-querying modem since
they should not change.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2021-10-26 14:47:38 +03:00
Bartosz Bilas cb30cc5f8c drivers: modem: gsm: move header file into modem directory
There is a specified location for modem drivers so move this
header right there.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2021-10-26 14:47:38 +03:00
Torsten Rasmussen bd61122aa2 kconfig: drivers: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all drivers settings having `[EXPERIMENTAL]` in their
prompt has has been updated to include `select EXPERIMENTAL` so that
developers can enable warnings when experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-25 10:46:48 +02:00
Wouter Cappelle 96f9f6e6d2 modem: clang-format the modem_socket files
Running clang-format on the modem socket files

Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
2021-10-20 07:30:46 -04:00
Wouter Cappelle 287481ef0a modem: Rework the modem_sockets poll behavior
The current modem sockets poll implementation has 2 limitations
as of today:
- not following posix spec wrt timeout of -1 (should be forever,
  but as today it's was returning immediately)
- not able to poll from multiple threads on different sockets
  on the same modem.
This pull request should implement these limitations.

Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
2021-10-20 07:30:46 -04:00
Ryan Erickson d6adbf9d0e modem: hl7800: fix IPv6 socket creation
When creating a socket, be sure to check the address
family and set the correct address family option in
the AT command.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-10-18 17:58:15 -04:00
Bartosz Bilas d6792dd7be drivers: gsm_ppp: introduce modem on/off callbacks
Allow the user to register function callbacks that
are executed during gsm modem configuring and stopping.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2021-10-04 20:46:04 -04:00
Sjors Hettinga 7f9b4d807c drivers: modem: Fix reference to stack in modem_context_sprint_ip_addr
Changes the modem_context_sprint_ip addr to write into a provided
buffer. This approach fixes a referencing to a non existing stack
variable, without using a lot of stack space.
Tested using the by building all used modems and tested on HW using
IPv4.

Fixes: #38459

Signed-off-by: Sjors Hettinga <s.a.hettinga@gmail.com>
2021-10-01 11:06:32 -04:00
Robert Lubos 0dbdcc770d net: sockets: Add socket processing priority
When creating a socket, all of the registered socket implementation are
processed in a sequence, allowing to find appropriate socket
implementation for specified family/type/protocol. So far however,
the order of processing was not clearly defined, leaving ambiguity if
multiple implmentations supported the same set of parameters.

Fix this, by registering socket priority along with implementation. This
makes the processing order of particular socket implementations
explicit, giving more flexibility to the user, for example when it's
neeed to prioritze one implementation over another if they support the
same set of parameters.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-09-28 20:11:26 -04:00
Torsten Rasmussen d800b4a4d7 drivers: gpio: remove unused GPIO selection
Fixes: #38403

Removing unneeded `imply GPIO` and `CONFIG_GPIO=y` occurrences where no
files are added to the gpio zephyr library.

Also removed `CONFIG_GPIO=y` occurences where this is handled by
defconfigs for the soc or board.

Selection of GPIO without selecting any drivers results in the warning:

> No SOURCES given to Zephyr library: drivers__gpio
>
> Excluding target from build.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-09-28 12:13:23 +02:00
Ryan Erickson 1715e39414 modem: hl7800: separate IO interrupt config
The interrupt config flags for an IO should be separate
from the standard IO configs because the interrupt config
is a separate API.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-24 11:30:37 -04:00
Yong Cong Sin 6083b89553 drivers: modem: gsm_ppp: Add support for Quectel modems
Add support for Quectel modem in gsm_ppp modem driver.

The CMUX cmd is based on MUX application notes v1.0(2020-09-22)
for BG95, BG77 and BG600L. Tested and working on EC21e.

As the gsm_ppp doesn't do power control, it is required to power
on the modem manually in the application.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-09-23 08:40:10 -04:00
Ryan Erickson e1eb55d7f7 modem: hl7800: sync APN for PDN and GPRS connection
Ensure the GPRS connection APN settings match the PDP
context. This it best to ensure proper IP connectivity.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-23 04:15:55 -04:00
Ryan Erickson bd24fba6c4 modem: hl7800: ensure IP family set correctly
Ensure that the IP family is synchronized between the PDP
context and the GPRS connection.
There were cases where they could get out of sync.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-23 04:15:55 -04:00
Ryan Erickson e8e9d83ab7 modem: hl7800: Add address family config
Add ability to set the IP address family with Kconfig.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-23 04:15:55 -04:00
Ryan Erickson 3fb82291d2 modem: hl7800: Fix IPv6 operation
Assign the IPv6 address from the LTE network to the
network iface.
Configure DNS resolver with IPv6 DNS address from the
LTE network.
Fix socket AT commands to account for IPv6 addresses.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-23 04:15:55 -04:00
Ryan Erickson a28a20b50f modem: hl7800: Only reconfig DNS if iface up
In the DNS work callback ensure the iface is up
(on the LTE network) before trying to reconfigure the
DNS resolver with the DNS address.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-23 04:15:55 -04:00
Ryan Erickson 7cf0a5c4a1 modem: hl7800: fix gpio with interrupts init
Need to use gpio_pin_interrupt_configure for any IO
that uses interrupts.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-22 06:36:11 -04:00
Ryan Erickson 42075342a8 modem: hl7800: fix PSM
Fix power-save-mode (PSM) operation.
When in PSM, do not bring the networking interface down
when an out-of-coverage event occurs.
When PSM goes into hibernate, this will cause an
out-of-coverage event to occur, even though the device
still has access to service.
Keeping the networking interface in the up state
allows an app to send data whenever it needs to.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-20 12:24:40 -04:00
Ryan Erickson 38c8d4729f modem: hl7800: remove DTR control
Using DTR to control sleep modes is a legacy mode
of operation. Remove control of DTR IO.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-20 12:24:40 -04:00
Ryan Erickson 982c072221 modem: hl7800: change sleep mode
Sleep mode 0 (driven by DTR) is only recommended for use
as a legacy option.
Sleep mode 1 is recommend by Sierra Wireless.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-20 12:24:40 -04:00
Xavier Chapron f83bb02cbf drivers: modem: sara-r4: Replace snprintf calls by snprintk
Snprintf calls should be avoid when not necessary, instead snprintk
should be used as it offers the same functionnalities at a lower cost
in flash.

Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2021-09-16 09:33:28 -04:00
Yong Cong Sin 495f6b7ccc drivers: modem: bg9x: Fix unused configs
Fix Kconfig so that unused configs won't be compiled.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-09-15 11:30:03 -04:00
Yong Cong Sin 293af9e823 drivers: modem: gsm_ppp: Fix ppp_dev
ppp_dev should be pointing to the net/ppp driver.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-09-08 10:49:45 -04:00
Ryan Erickson ef322d9e16 drivers: modem: hl7800 Add Site Survey
Add API to determine nearby cell towers and their signal
strength.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 12:33:29 -04:00
Ryan Erickson aba8a21001 drivers: modem: hl7800: Add Position over LTE (PoLTE)
Position over LTE (PoLTE) can be used to locate a device as
an alternative to GNSS.
Increase RX thread stack size for PoLTE processing.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 09:33:46 -04:00
Ryan Erickson f094346e18 drivers: modem: hl7800: Add GNSS support
Add API to use GNSS on the HL7800 modem.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 09:33:46 -04:00
Ryan Erickson e29dbf5d04 drivers: modem: hl7800: Add airplane mode
Add API to set HL7800 to airplane mode.
Also add option to boot into airplane mode.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 09:33:46 -04:00
Ryan Erickson 11e992099b drivers: modem: hl7800: Add delayed start
Allow application control for starting modem driver.
This allows network attach to be randomized.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 09:33:46 -04:00
Ryan Erickson 7cfedb915b drivers: modem: hl7800: fix COPS handler
Add support for handling the +COPS=? response
to the +COPS command handler.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-09-01 08:37:49 -04:00
Ryan Erickson 1c14a4b1ba modem: hl7800: reconfig IP connection on startup
For low power operation, set the IP connection reconfig
flag when receiving a startup report.
This will ensure the GPRS connection is reconfigured
before any socket operations take place.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-31 19:27:23 -04:00
Ryan Erickson ac751b7bcc drivers: modem: hl7800: Query IMSI
Add API to query SIM card IMSI.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-31 19:25:13 -04:00
Ryan Erickson d83aaef031 drivers: modem: hl7800: Add retries to get IP address info
Allow command retries when querying IP address info.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-31 17:34:53 -04:00
Yong Cong Sin 9d2f8a1124 drivers: modem: gsm_ppp: Use DTS
Convert the gsm_ppp driver to use DTS.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-08-31 17:33:34 -04:00
Ryan Erickson 61ef41fc24 drivers: modem: hl7800: Add query carrier config
Add API to query the carrier config of the HL7800.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-31 17:30:46 -04:00
Andrew Hedin 6fb6533a48 drivers: modem: hl7800: Fix generation of FOTA complete event
FOTA complete event is now generated and can be used by application.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-08-31 17:30:15 -04:00
Andrew Hedin fd864c61bb drivers: modem: hl7800: Allow operation without a SIM card
Allow the driver to run if a SIM card is not present.
This allows public HL7800 APIs like firmware updates
to be used even if no network is available.
Remove duplicate query ICCID command.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-08-31 16:29:31 -04:00
Ryan Erickson 2e045a0ed6 drivers: modem: hl7800: null terminate DNS server list
bugfix: NULL termination is required by
dns_resolve_reconfigure API so null terminate the DNS
server list.
Fix checkpatch warning.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-20 14:10:22 -05:00
Ryan Erickson 8d6832b256 drivers: modem: hl7800: socket RX could drop data
net_buf_skipcrlf() will remove all \r\n characters from the buffer.
If the data after CONNECT\r\n contained \r or \n it would
be removed, resulting in dropped data.
Fix this to only remove two bytes to ensure data is not dropped.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-20 06:33:31 -04:00
Ryan Erickson 6ef958c2e1 drivers: modem: hl7800: keep socket data if EOF not found
Change socket RX trailer (EOF) missing to warning and
keep socket RX data instead of discarding.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-20 06:33:31 -04:00
Martí Bolívar 3910c35193 dts: fix u-blox sara r4 compatible
It should be "u-blox,sara-r4", because the vendor prefix for this
company is "u-blox", not "ublox".

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-08-17 17:51:57 -04:00
Daniel Leung 0f0c17880e drivers: modem: build as static library
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Gerard Marull-Paretas 6d273f49bd pm: fix incorrect usages of PM_DEVICE_STATE_OFF
According to the documentation the OFF state has to be used when the
devices is fully turned off, ie, power removed. Most drivers were using
a sort of fall-through for all non-active states, leading to behaviors
not following the specifications.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas d41dadc569 pm: rename PM_DEVICE_STATE_SUSPEND to PM_DEVICE_STATE_SUSPENDED
The verb tense for the suspended state was not consistent with other
states. The likely reason: state was being used as a command/action.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 56a35e5682 pm: converge to suspend state for low power modes
The difference between low power and suspend states is a thin blur line
that is is not clear and most drivers have used indistinctly. This patch
converges to the usage of the suspend state for low power, since
contrary to the low power state, it is used by both system and runtime
device PM. The low power state is still kept, but its future is unclear
and needs some discussion.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Kumar Gala a1a895e331 drivers: modem: Fix compiler warning
When building tests/drivers/build_all/modem on native_posix_64 we get:

	modem_cmd_handler.c:545:9: error: ret may be used
	uninitialized in this function
	[-Werror=maybe-uninitialized]

Fix by adding simple initialization of ret = 0 at start of function.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-08-02 11:32:02 -05:00
Marcin Niestroj 1a4cb7e0e3 drivers: modem: add modem_cmd_send_ext()
There are currently modem_cmd_send() and modem_cmd_send_nolock()
functions, each with slightly different behavior regarding acquiring (or
not) sem_tx_lock. Introduce a generic function that will allow caller to
select behavior using flags.

While at it, add possibility to disable setting and unsetting command
handlers. This will be useful in situations when there are multiple
replies expected one after the other coming as a response to single
command. This is the case for example with ESP-AT driver, which expects
following data as response to AT+CIPSEND command:

  OK
  >

where 'OK' is handled by static CMD_RESP (so releasing response
semaphore right away), while '>' is handled by dynamic
CMD_HANDLER (which is releasing another semaphore). Keeping command
handlers in place allows to receive '>' without race condition because
of small period of time where command handlers are not set.

Convert modem_cmd_send_nolock() and modem_cmd_send() to static inline
functions, as they are just a specific invocation of
modem_cmd_send_ext() function.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-07-28 21:08:51 -04:00
Marcin Niestroj 26bd4fb45e drivers: modem: operate on device pointers instead of names
So far modem API used UART device names / labels. Change API to operate
on device pointers instead, so that we stop using device_get_binding()
in modem core and in some DT compatible modem drivers.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-07-15 11:48:00 -04:00
Tahir Akram 608ad430f3 drivers: modem: RSSI measurement for PPP link
This PR addresses radio signal stength measurement during
and before PPP session. The PR provides provides facility
of readout for both +CSQ and +CESQ versions depending
upon the modems. This PR follows the idea of rssi readout
of PR#35496. Additionally, reliable Cell info update
is also ensured.

Signed-off-by: Tahir Akram <mtahirbutt@hotmail.com>
2021-07-14 21:06:30 -04:00
Gerard Marull-Paretas 26ad8376bd pm: remove callback from control function
The callback is not used anymore, so just delete it from the pm_control
callback signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Jukka Rissanen 2758aeedbc drivers: modem: gsm: Ignore semaphore take return value
We do not need the return value of k_sem_take() so ignore it.

Coverity-CID: 236602
Fixes #36313

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-06-16 22:12:40 -04:00
Hans Wilmers 0a345df211 drivers: modem: ublox-sara-r4: query for operator and cell info
Query the numerical network operator id, location area code (LAC)
and cell id. Following AT commands are used:

  AT+COPS?
  AT+CEREG?

Functionality is enabled by CONFIG_MODEM_CELL_INFO=y.

Tested with uBlox SARA-R410M-02B.

Signed-off-by: Hans Wilmers <hans@wilmers.no>
2021-06-14 15:19:13 +02:00
Hans Wilmers 09fd688d23 drivers: modem: gsm_ppp: query for operator and cell info
Query the numerical network operator id, location area code (LAC)
and cell id. Following AT commands are used:

  AT+COPS?
  AT+CEREG?

Functionality is enabled by CONFIG_MODEM_CELL_INFO=y.

Tested with uBlox SARA-R410M-02B.

Signed-off-by: Hans Wilmers <hans@wilmers.no>
2021-06-14 15:19:13 +02:00
Hans Wilmers 120b2165ec drivers: modem: implement operator id and cell info
Implement numerical network operator id, location area code (LAC)
and cell id in modem context and modem shell.

Please note that the functionality to query these values must be
implemented in the modem driver.

Signed-off-by: Hans Wilmers <hans@wilmers.no>
2021-06-14 15:19:13 +02:00
Emil Lindqvist 9b7d9d43b8 drivers: modem: ublox-sara-r4: implement F_GETFL in ioctl
Zephyr sees fnctl as an alias of ioctl, and so the F_GETFL
request should be handled here as well.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-05-27 15:44:03 +02:00
Ryan Erickson a1498f3e40 drivers: modem: hl7800: +KSRAT dependent on firmware version
The reboot option of the +KSRAT command is only
supported by newer firmware.
Add a check to determine what version of the command
to use when setting the RAT.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-05-19 08:09:37 -05:00
Ryan Erickson 62ccddb035 drivers: modem: hl7800: fix update RAT
The default behavior of the +KSRAT= command has
changed to not reboot the HL7800.
Adjust the command so the reboot takes place properly.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-05-14 08:25:49 -05:00
Flavio Ceolin 0c607adb63 pm: device: Align state names with system states
Change device pm states to the same pattern used by system power
management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 18:35:12 -04:00
Kumar Gala 27e33e25c9 drivers: modem: Fix build errors on 64-bit platforms
If the modem drivers are built on a 64-bit platform we get errors with
the logging code due to use of size_t.  Update to use %zX to handle this
correctly between 32-bit and 64-bit platforms.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-05-07 16:08:09 -05:00
Emil Lindqvist f3f8af4cc2 drivers: modem: ublox-sara-r4: make reset pin optional
Remove reset pin requirement from devicetree as this
is not required for modem functionality, and is not
used in the driver anyways.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-05-06 09:44:19 -05:00
Gerard Marull-Paretas 7988ab4a26 pm: rename device_set/get_power_state to pm_device_set/get
Make name consistent with other device PM APIs.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 2c7b763e47 pm: replace DEVICE_PM_* states with PM_DEVICE_*
Prefix device PM states with PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 3863be02a5 drivers: replace power/power.h with pm/device.h
Drivers need access to the device PM API, so just include pm/device.h.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Ryan Erickson 5af20cd258 drivers: modem: hl7800: fix fault with IPv6 address
If modem receives an IPv6 address, buffer overrun
would occur. Fix this by checking string length to
ensure what type of IP address needs to be parsed.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-05-05 13:39:50 -05:00
Ryan Erickson c9b8f89b80 drivers: modem: hl7800: fix potential buffer overrrun
Correct destination buffer size when processing
RX messages from modem.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-05-05 13:39:50 -05:00
Marcin Niestroj ba391b80b0 drivers: modem: hl7800: use dns_resolve_reconfigure() API
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Gerard Marull-Paretas 126e1eead8 drivers: modem: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:25:24 -04:00
Yong Cong Sin 084a8b6bf4 drivers: modem: BG9X wait for RDY instead of polling AT.
BG9X wait for RDY instead of polling AT.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-04-21 17:04:40 +03:00
Johann Tael 5425700e74 drivers: modem: ublox-sara-r4: add TLS offload support
Currently it's able to connect to google iot. All other use cases are
untested.

Signed-off-by: Johann Tael <jntael@gmail.com>
2021-04-21 11:13:34 +03:00
Peter Bigot cc090726e6 drivers: modem: rote conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Be aware that this does not address architectural errors in the use
of the work API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-14 07:07:40 -04:00
Benjamin Lindqvist 28ac1f70bf drivers: modem: gsm_ppp: proper attach retry
In a previous commit, a check was added to ensure modem was properly
attached to packet service before initializing PPP. Failure to perform
this check can lead to the dreaded 'NO CARRIER' issue.

While this is a nice idea, the implementation was lacking because when
the check failed, the entire modem initialization procedure was
restarted from square one. For modems/bearers that were slow to attach,
this is potentially disastrous. The proper solution is to loop only the
'AT+CGATT?' part until it succeeds, or fails N times.

This commit implements this looping behavior (using the work queue).

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2021-04-06 15:37:11 +03:00
Ryan Erickson 78200f1812 drivers: modem: hl7800: use new work queue API
Implement new work queue API changes.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-04-02 07:24:46 -04:00
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
Jukka Rissanen cc230815cb drivers: gsm: Add GSM modem device name
Application might need to know the GSM modem device name so
provide it in the header file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-10-19 18:29:02 +02:00
Benjamin Lindqvist 449fc7bb1c net: ppp: Avoid wrapping each byte in muxing headers
When PPP is muxed, using uart_poll_out resulted in each byte getting
wrapped in a muxing header. This led to UART bombardment which
can quickly cause some modems to hang and panic. This was observed
regularly using a SIMCOM7600E modem.

A perfect fix would involve rewriting ppp.c, uart_mux.c and
modem_iface_uart.c to all use another UART API, but that would be more
invasive by several orders of magnitude than this one, which utilizes
the fact that the uart_mux implementation of uart_fifo_fill does NOT
require ISR context. Since the Zephyr UART API states that the behavior
of uart_fifo_fill outside of ISR context is implementation defined, this
should be kosher.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-19 18:29:02 +02:00
Benjamin Lindqvist 54cb2bcd41 drivers: modem: gsm_ppp: Enable start/stop
These changes enable applications to restart the networking stack which
was previously not possible without rebooting the device. This was a
major show-stopper because it made power management impossible, and
furthermore made it impossible to recover from a bad modem state without
rebooting.

This has been verified to work on a SIMCOM7600E modem, both with and
without CONFIG_GSM_MUX enabled.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-19 18:29:02 +02:00
Benjamin Lindqvist 966932a033 drivers: modem: add forgotten log_strdup call
The char pointer that is logged could get scoped out and so should be
strduped before logging.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-19 18:29:02 +02:00
Ryan Erickson 0e86699223 drivers: modem: hl7800: only set DNS addr if not set
Only set the DNS resolver server address if one has not been specified.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-10-19 15:22:33 +03:00
Benjamin Lindqvist 598adb8830 drivers: modem: gsm_ppp: hold off ppp until we're attached to nw
Attempting to initialize PPP without first ensuring we're attached to
the network packet service will sometimes lead to "NO CARRIER" errors
when we initialize PPP with the modem. This has been observed
reproducibly on some SIMCOM7600E modems.

This commit holds off on PPP initialization until modem has reported
that it is indeed attached by using the "AT+CGATT?" command (see 3GPP TS
27.007)

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2020-10-17 16:36:07 +03:00
Ryan Erickson e36fc53fa6 drivers: modem: hl7800: fix file open in fw update
File open function for firmware update
requires a flags parameter to be passed in.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-10-15 08:46:41 -05:00
Ryan Erickson 72d54055a3 drivers: modem: hl7800: UDP socket not closed
Ensure UDP socket is always closed when offload_put is called.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-10-14 12:30:45 +03:00
Ryan Erickson 2d7ccb59a9 drivers: modem: hl7800: Fix cases where socket would not close
There are cases where the socket would not be closed.
offload_put function will now always close the socket
properly.

Remove error log messages as they are redundant.
on_cmd_sock_error_code handles printing errors.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-10-05 15:41:03 -05:00
Marcin Niestroj ad0dc48067 drivers: modem: ublox-sara-r4: inform modem_context about HW flow control
If HW flow control is enabled, then modem_context framework won't drain
UART FIFO blindly, but will stop when there is no more space in RX
ring_buf. This prevents data loss by "pausing" incoming data on hardware
level.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-05 17:04:52 +03:00