Commit graph

98 commits

Author SHA1 Message Date
Bjarki Arge Andreasen aa6ecc59d1 drivers/modem/modem_cmd_handler: Update API
There is currently not a clear separation between
user configuration and internal context when using the
modem_cmd_handler library. This update adds a clear
separation, placing user configuration in a seperate
struct passed to modem_cmd_handler_init alongside the
internal context modem_cmd_handler_data.

There is also a lack of documentation of the user
configurations, these have been added to the new config
struct.

The new API function modem_cmd_handler_process has been
added to remove the need for the user to directly access
the process member of the internal context. This ensures
that the user is not encouraged to access any internal
context members.

Some whitespace errors exist in the modem_cmd_handler.c
file, these are outside of the scope of this PR. These
can be addressed in a later PR as they are not functional
changes.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-04-11 11:42:00 +02:00
Bjarki Arge Andreasen a4afcf8c93 drivers/modem/modem_iface_uart: Update API
The UART IFACE API currently exposes the context struct
modem_iface_uart_data, expecting the user to fill in some
of the fields, with no documentation specifying which fields
and what they mean.

This API update moves all user configurable values in the context
out into a config struct, modem_iface_uart_config, within which
members are documented.

This prevents the user from interacting directly with the context
making use of the library safer and more readable.

The config structure helps make code readable by using "named args"
in a const struct instead of a long, nameless, parameter list passed
to the modem_iface_uart_init function.

The new API function modem_iface_uart_rx_wait is added to prevent the
user from having to interact with the rx sem in the context directly.

The context can now be safely interated with without direct access to
any of its members.

Pointers to the ring buffer params in the context have been moved to
config struct, as these are only useful during initialization of the
context.

Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
2023-04-11 11:42:00 +02:00
Marin Jurjević b99b66fba2 drivers: modem: gsm: fix RSSI check condition
Fixes invalid condition introduced in #48533 when FSM implementation
was added.

Signed-off-by: Marin Jurjević <marin.jurjevic@hotmail.com>
2022-12-27 15:32:07 +01:00
Maciej Zagrabski ec7237c38a drivers: gsm_ppp: replace DT_INST with DT_DRV_INST
Replace error prone DT_INST with proper DT_DRV_INST.

Signed-off-by: Maciej Zagrabski <mzi@trackunit.com>
2022-12-07 10:29:34 +00:00
Jeppe Odgaard afd6eb35f9 modem: ppp: gsm: extract access technology
Some modems supports multiple access technologies.
The access technology of the serving cell can be extracted from the
+CEREG command, which is already sent to the modem.

The parse function is extended to also parse the access technology value.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/51153.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2022-11-11 08:41:13 +00:00
Jeppe Odgaard 625efd8447 drivers: modem: gsm: Fix set gsm->state in gsm_ppp_stop
The driver should set the `gsm->state` to GSM_PPP_STOP when
`gsm_ppp_stop()` is run. This commit fixes that.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/51505

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2022-11-01 08:59:59 +00:00
GUITTER Pierrick 2ef94ec479 drivers: gsm_ppp: fix modem_cmd_handler_tx_lock
Remove modem_cmd_handler_tx_lock lock when CONFIG_GSM_MUX
is disabled, as modem_cmd_handler_tx_unlock is under the same
conditions.

Signed-off-by: GUITTER Pierrick <pguitter@silicom.fr>
2022-09-27 14:12:57 +00:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Bartosz Bilas e7eee79e7e drivers: modem: gsm: adjust logs level
Let's switch to the LOG_DBG for +CREG, +CESQ and +CSQ
AT commands responses because they flood the console so much.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2022-08-05 11:43:11 +01:00
Yong Cong Sin b707785411 drivers: modem: gsm: Goto fail state if iface errors after setup
Patches the driver such that if the iface errors after init, the
driver will enter FSM error state.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Yong Cong Sin a0a80c350c drivers: modem: gsm: Make the precedence explicit
Add brackets to make the precedence of if conditions
explicit.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Yong Cong Sin 7685301df6 drivers: modem: gsm: If condition should be bool
Compare these variables properly so that the condition in an if
statement will be boolean.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>

Update gsm_ppp.c
2022-08-04 13:43:45 +02:00
Yong Cong Sin e5fb94e4a0 drivers: modem: gsm: Cast unhandled functions to void
The return value of these functions are not handled,
cast them to void to make that explicit.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Yong Cong Sin 4b59ba8fe3 drivers: modem: gsm: Test against NULL
Test these pointer against NULL explicitly

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Yong Cong Sin 21bf04c29b drivers: modem: gsm: Rename r to ret
Rename the variable `r` to `ret` for better consistency
with the rest of the driver.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Yong Cong Sin f5d646e204 drivers: modem: gsm: FSM implementation
Introduce FSM implemention for the gsm_ppp driver.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-08-04 13:43:45 +02:00
Jeppe Odgaard 41ff2373e1 drivers: modem: gsm: set AT+IFC if hw-flow-control is enabled
If hw-flow-control is set in the uart section of the device tree source,
it is read by gsm_ppp.c and AT+IFC=2,2 is sent to the modem.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/46928.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2022-07-01 16:32:17 +00:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Marek Metelski d046ea281c drivers: gsm_ppp: Fix null pointer dereference in log message
Log message references gsm->context.data_rssi which is NULL
when CONFIG_MODEM_SHELL=n. Use gsm->minfo.mdm_rssi which is
internally used when accessing RSSI value.

Signed-off-by: Marek Metelski <marek@metelski.dev>
2022-06-07 19:04:48 +02:00
Marek Metelski 7ade471a47 drivers: gsm_ppp: Wait for NET_IF_DOWN in gsm_ppp_stop only if iface was up
Check if ppp iface was actually up before taking it down and waiting
for NET_EVENT_IF_DOWN. This allows to call gsm_ppp_stop() even if
the PPP was never started, which previously caused the call to lock
forever. This case is useful, for example, if the modem didn't attach
to network in desirable time and user wants to abort PPP setup.

Signed-off-by: Marek Metelski <marek@metelski.dev>
2022-06-07 18:57:18 +02:00
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
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
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
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 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
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
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
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