Commit graph

342 commits

Author SHA1 Message Date
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