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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
So far all received bytes over UART where blindly drained and pushed to
ring_buf. This approach is okay for UART devices without configured HW
flow control, as it basically decouples data processing from ISR handler
and gives more time before data overrun. However when HW flow control
is enabled, such behavior somehow suppresses UART flow control
advantage, because data can overrun when pushing to ring_buf.
Allow drivers utilizing modem_context framework to pass information
about whether HW flow control is enabled or not. If it is enabled, then
read data from UART FIFO to the point when RX ring_buf is totally filled
and follow such situation by disabling RX interrupt. Incoming data will
be paused on HW level, so there is lots of time for RX thread to process
ring_buf content. Reenable RX interrupts after all data in ring_buf is
processed, so that number of context switches is kept at minimum level.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This API allows to drop use of preallocated isr_buf. Most importantly as
a result RAM usage is reduced for each driver utilizing modem_context
framework. Additionally there is less copying done in ISR context, as
data is direcly read from UART FIFO to ring_buf.
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The driver utilizes the CONFIG_NET_OFFLOAD setting to avoid the
normal handling of IP packets, and instead uses a socket-like
UART interface to handle incoming and outgoing data via AT commands.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
PR #27485 introduced new implementations for close() that do not build
correctly. This commit fixes the problem by re-implementing them.
Fixes#27587
Signed-off-by: Vincent Wan <vwan@ti.com>
This adds an option to query the modem for the SIM's IMSI and ICCID
numbers, just like the modem's IMEI is queried today. This requires
the SIM to be present, which might not be the case for all
applications, so it can be disabled.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
Do not route close() calls via ioctl() as that is error prone
and quite pointless. Instead create a callback for close() in
fdtable and use it directly.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
It was already using uart_irq_callback_user_data_set below, now it also
uses uart_irq_callback_user_data_t as callback type, so let's normalize
the callbacks.
Fixes#26923
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
By using the Zephyr-native zsock_ family of types and functions, these
drivers will be decoupled from NET_SOCKETS_POSIX_NAMES.
Signed-off-by: Adam Porter <porter.adam@gmail.com>
Used for permission validation when accessing the associated file
descriptors from user mode.
There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
The implementation of offload_getaddrinfo in this driver failed
when the node it was called with was an IP address. This condition
was never detected, and as a consequence a DNS query was done on
the IP address instead of returning it directly.
Also, the port was set first after running the DNS query.
As a consequence, if the IP address would have been returned directly,
this would have been done without a port been set.
Both errors are fixed in this patch.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
During communication initialisation, the IMSI of the inserted SIM
card is evaluated to determine the APN. This is done by comparing
the first 5 characters of the IMSI to a list of known providers.
The list can be given in Kconfig.
To enable this functionality, set following bool in Kconfig:
MODEM_UBLOX_SARA_AUTODETECT_APN
To set a list of providers, set following string:
MODEM_UBLOX_SARA_AUTODETECT_APN_PROFILES
If the provider can not be found in the list, the APN given in
following entry is used as a fallback:
MODEM_UBLOX_SARA_R4_APN
Signed-off-by: Hans Wilmers <hans@wilmers.no>
The modem type (Sara R410 or Sara U201) is detected automatically after
hardware initialisation of the modem. Further initialisation and
functionality is then chosen depending on the detected modem type.
To enable this functionality, set following bool in Kconfig:
MODEM_UBLOX_SARA_AUTODETECT_VARIANT
Signed-off-by: Hans Wilmers <hans@wilmers.no>
This fixes some cases where an integer timeout received as a parameter
was not converted to a timeout before being used in standard API.
Changes to the POSIX library were not included as that's being
reworked in a separate PR.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
TCP contexts are referenced twice,
once for the app and once for the stack.
Since TCP stack is not used for offload,
unref a second time to release the context.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Following issue is addressed in this bugfix:
When using offloaded sockets with modem ublox_sara_r4,
the socket is only closed if it is in connected state
at the time of the function call. When using UDP sockets,
this leads to a socket never being closed.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
Calculation of RSSI was done incorrectly for Sara U201.
When evaluating +CSQ command responses, the RSSI can be calculated
from the first value, which is <signal_strength>. Instead, the
RSSI was calculated from the second value, which is <qual>.
With the subsequent mapping to RSSI, this results in a wrong
value for RSSI.
This is now corrected by using value <signal_strength> to calculate
the RSSI.
Tested using Sara U201.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
This commit references modem_pin() and modem_shell()
modem_pin(): use new gpio api
The existing pin driver does not respect gpio
configuration in device tree for active high / low
This commit allows for the device tree to determine the
active logic level.
modem_shell(): use correct string length
The ms_send macro uses iface.write() to send a string.
iface.write() requires the length of the string not the
size of the string.
This commit corrects the string length.
drivers: ublox-sara-r4: fix vint polling
This eliminates the implication that the enable and disable values can
be something other than 1 and 0, and fixes the code so it won't enter
an infinite loop if the GPIO read returns an error.
Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
This is needed if muxing is enabled in which case we must
change the UART to muxing UART after the AT+CMUX command
has succeed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of using physical UART to connection to the modem, use
the GSM 07.10 muxing protocol and UART mux driver to create
virtual channels to the modem. This will allow simultaneous
PPP, AT and other type connections to the modem.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The net_buf subsystem is now fully compatible with the new timeout
API, so move the selection of the legacy API to those specific
subsystems that use net_buf and still need converting.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Run the int_literal_to_timeout Coccinelle script to fix places where
it is clear that an integer duration is being passed where a timeout
value is required.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
By changing the various *NET_DEVICE* macros. It is up to the device
drivers to either set a proper PM function or, if not supported or PM
disabled, to use device_pm_control_nop relevantly.
All existing macro calls are updated. Since no PM support was added so
far, device_pm_control_nop is used as the default everywhere.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Source and destination ports should be set properly
when assembling the receive socket data.
Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
Some commands need to be processed before a "\r\n" is available and
there might also be commands that have "\r\n" as data but doesn't mean
the end of the command.
To solve this a MODEM_CMD_DIRECT has been added. cmd_handler_process()
will look for matching direct commands before checking if a whole line
is available for matching the normal commands.
A direct command can return either -EAGAIN, meaning that more data is
needed or it will return the number of bytes to skip forward, ie the
length of the command that was handled.
Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
User is currently able to enable verbose packet debugging for
received packets. This commit enables the same for sent packets.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
pin is an unsigned variable so there is no meaning check if it is less
than zero.
CID :208407
CID :208408
CID :208410
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
usage of AT+UPSD command per UBX-17003787(R15) command reference is:
AT+UPSD=<profile_id>, <param_tag>, <param_val>
For AT+UPSD=0, 1, "<value>": we are setting value to MCCMNO, which
is technically incorrect. <param_tag> of 1 means:
1: APN - <param_val> defines the APN text string, e.g.
"apn.provider.com"; the maximum length is 99. The factory-programmed
value is an empty string.
Let's use APN here instead. This fixes a +CME ERROR: 113 when
connecting with U2 modem.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/22689
Signed-off-by: Michael Scott <mike@foundries.io>
Add Kconfig option that allows user to set MCC (Mobile Country
Code). If user does not set it, then automatic operator
registration is used.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Misc fixes / enhancements to the GSM driver:
* set the \r as a line ending character
* make gsm_init() static as there is no need to expose it
* print the gsm context pointer at init
* set buffer allocation timeout to modem context so that it is
not infinite
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Instead of using global static variable "gsm" everywhere,
store the context when calling DEVICE_INIT(). Then in the device
init function get the context from the device struct. This way
it is possible to use the same functions for implementing two
gsm modem instances. Currently this is not fully possible because
the context is not passed via uart_pipe API and modem_cmd
callbacks. So some future work would still be needed.
In practice this commit does not change anything, it just makes
it a little bit easier to have two instance of this modem which
might be quite unlikely case. Anyway, the driver now follows the
same style how some other drivers are done like Ethernet etc.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Now that the u-blox driver can let cmd_handler know that it hasn't
received enough data, let's disable the hex mode for readying
binary data.
On the SARA-R4 this mode limits the receiving MTU to 512 which is
unacceptable.
Signed-off-by: Michael Scott <mike@foundries.io>
Some modem commands can determine if they have enough data pulled from
the modem to continue or not. Let's allow those functions to return
EAGAIN which means there's more data needed from the modem.
Signed-off-by: Michael Scott <mike@foundries.io>
Modem commands are setup with arg_count to denote the number of params
to parse before returning. Let's honor that setting and return once
we've parse them.
This fixes a run-on bug where the parser would find as many of the
parameters via the supplied delimiter as it could.
Signed-off-by: Michael Scott <mike@foundries.io>
The original Ublox SARA-R4 driver was written for the net_context
APIs. As a result many of the return values are not POSIX standard.
Let's go through all of the socket offload functions and make sure
we return standard values (0 or -1) and set errno where appropriate.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 has a max read limit of 512 when using binary hex formatting.
Otherwise the max read limit is 1024.
Signed-off-by: Michael Scott <mike@foundries.io>
New socket functions were introduced to hide some of the modem_socket
internals:
- modem_socket_next_packet_size()
- modem_socket_wait_data()
- modem_socket_data_ready()
Let's use them.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's use sock->is_connected to check whether we need to clean up
the modem's socket. It may have already been closed via URC.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 AT command manual states +USOCO has a max timeout of 120s.
Let's use that instead of the default 10s command timeout.
Signed-off-by: Michael Scott <mike@foundries.io>
The SARA R412M requires manual activation of the PDP context. It also
reports RSSI instead of RSRP when on 2G. An off-by-one in the RSRP
calculation was also fixed in this commit.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
The u-blox SARA modems have the ability to output the network status
on a GPIO pin. This can be used to light up a LED when the modem is
connected to the network.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
The U2 modem will sometimes not power off even if we have given it the
signal to do so. We now signal it continually until the modem
indicates that power is off with VINT=0.
Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
This fixes two problems in modem_reset():
- mdata.net_iface is used without checking that it is valid.
Now, we validate mdata_net_iface before usage, and give a warning
if it was not set.
- if the modem does not perform network registration within the
given time of 20s, in the previous implementation the driver
gave up.
Now, the driver disables RF for a second, enables it again and
gives the modem another 20s to register. This has been seen
to help in roaming situations.
Tested on Sara R4.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
- limit max. number of bytes when sending to socket
The number of bytes sent to a socket in one transaction
is limited to 512 in HEX mode (Sara-R4), and to 1024
otherwise. This corresponds to numbers given in the
manual for ublox cellular modems.
- report number of bytes actually sent, as reported by modem
After writing data to a socket, we now return the number of
bytes actually written, as reported by the modem.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
In order to still process 128 bytes at a time, let's add 1 to the
length of match_buf which will be used to store a NUL char when
the match_buf is at max size (size - 1).
Otherwise we're processing 127 bytes at a time which is inefficient
compared to the data buffer sizes in net_buf.
Signed-off-by: Michael Scott <mike@foundries.io>
SARA-R4 modem supports offloaded DNS via AT+UDNSRN command.
Let's implement it.
NOTE! On SARA-R4 a new firmware *IS* required to support this feature:
L0.0.00.00.05.08 [Apr 17 2019 19:34:02]
Signed-off-by: Michael Scott <mike@foundries.io>
Managing the interface up / down events from driver code (as opposed
to L2 layers) has been an issue for quite some time. There are
race conditions which result in data aborts (referencing NULL
iface or NULL iface->if_dev) or ends up breaking ASSERT checks for
non-NULL iface.
Let's remove the handling for now and come up with something better
when a user actually needs it.
Signed-off-by: Michael Scott <mike@foundries.io>
In offload_recvfrom(), if we end up calling modem_cmd_send(),
then we should always wait for the results. We've already
checked for MSG_DONTWAIT and made sure that there is data ready.
We just need to get it from the modem buffer at this point.
Signed-off-by: Michael Scott <mike@foundries.io>
Users may be waiting for data via socket recv() function. We
notify them that data is ready when URC is received from modem.
Once unblocked, we read the data from the modem buffer which
is handled via on_cmd_sockread_common(). At this point, we
don't need to unblock waiting users again.
Signed-off-by: Michael Scott <mike@foundries.io>
The hex_to_binary() function is incorrectly assuming all buffers
passed to recv() will have an additinal byte for storing a NUL
terminating char. This should be optional as MQTT library uses
exact sized buffers for parsing socket data.
Signed-off-by: Michael Scott <mike@foundries.io>
The send_socket_data() is incorrectly sending 0 as successful result.
The socket APIs require the number of bytes sent to be returned.
Signed-off-by: Michael Scott <mike@foundries.io>
For parsing purposes we need to add a NUL to the end of match_buf.
When there is no CR/LF in the incoming rx bufs then we fill match_buf
to its max size. This ended up with an off by one error which was
overflowing match_buf into the following data.
To account for this, let's fill the buffer to size - 1 so that we
leave room for the NUL at the end and stop corrupting data.
Signed-off-by: Michael Scott <mike@foundries.io>
- rename buf_len to match_len for clarity
- pass in modem_cmd_handler_data instead of buffer pointer directly
- buffer adjustments for the command length are kept inside
parse_params()
Signed-off-by: Michael Scott <mike@foundries.io>
Let's add a field which the drivers can use to keep track of whether
they are connected or not. This will normally be enabled / disabled
in the socket connect and URC for socket close notify.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's hide the internals of sock->packet_sizes[] by adding a function
which returns the size of the next waiting packet.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's hide the internals of the modem_socket's sem_data_ready and
poll handling with 2 new functions:
- modem_socket_wait_data: take a semaphore and wait for data
- modem_socket_data_ready: give back the data ready semaphore and
unblock poll() users
Signed-off-by: Michael Scott <mike@foundries.io>
Add lock behavior for functions in modem_socket, to prevent race
conditions when performing socket data maintenance.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's allow protocols to request portions of the current packet.
This is seen in the MQTT library when parsing headers for the type
and variable length of the packet.
This fixes basic parsing done in the MQTT library and probably others.
Signed-off-by: Michael Scott <mike@foundries.io>
Compile errors because of missing include file and typos
when accessing variables in the modem_pin struct.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
After startup ublox-sara-r4 code sets the MDM_POWER signal to input
using a deprecated configuration macro. This was the only use of the
modem context API to configure a pin.
Refactor the API to not take the flags as an input but instead select
between the flags to be used when the pin is active and a disconnected
state. Use this API instead of a separate direct configure call when
initializing the modem pins.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Conver to the new GPIO API using raw access, since the driver
has its own macros to define signal levels.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Convert to the new API using raw access, since it's a common access
layer shared by multiple (right now only ublox-sara-r4) modems.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Implement uart_pipe functionality for the modem so that it
integrates with the PPP implementation.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Create a driver for GSM modems that use a standard AT command set
and enable Zephyr's own PPP stack for IP traffic.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Use this short header style in all Kconfig files:
# <description>
# <copyright>
# <license>
...
Also change all <description>s from
# Kconfig[.extension] - Foo-related options
to just
# Foo-related options
It's clear enough that it's about Kconfig.
The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)
git ls-files '*Kconfig*' | \
xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
As modem receiver is using UART, it requires disabling
of the UART and its callbacks to save power.
This adds simple sleep/wake functions which should be
called from defined device_pm functions in modem drivers later.
Signed-off-by: Christoph Schramm <schramm@makaio.com>
modem_socket_put() originally took an index as a parameter and was
later swapped to sock_fd as the reference.
The internal code was never updated to reflect that sock_fd isn't an
index -- it's a separate reference generated via z_reserve_fd().
Let's correct the modem_socket_put() logic.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18238
Reported-by: Tobias Svehagen <tobias.svehagen@gmail.com>
Signed-off-by: Michael Scott <mike@foundries.io>
This adds support for SARA-U2 modems. They have different timings on
the PWR_ON pin, don't support AT+CESQ and require a manual GPRS
connection setup.
The VINT pin is used as a more reliable and faster way to power on the
modem.
Based on work by Göran Weinholt <goran.weinholt@endian.se>
Signed-off-by: Michael Scott <mike@foundries.io>
Let's convert the SARA modem to use the more generic modem context
layers so that we don't maintain a lot of what should be shared code.
This conversion includes:
- modem context as the helper umbrella
- uart modem interface layer
- generic command handler layer
- modem socket helper
- move from net_context offload API to socket offload API
Signed-off-by: Michael Scott <mike@foundries.io>
Many modems implement socket-based APIs to manage data connections.
This layer provides much of the groundwork for keeping track of
these "sockets" throughout their lifecycle (from the initial offload
API calls through the command handler call back layers):
- structure for holding socket data like IP protocol, destination,
source and incoming packet sizes
- configuration to note modem starting socket id and number of
sockets
- methods to get/put socket structs from/to the pool
- function to update the # and size of packets in the modem receive
queue
- prebuilt modem_socket_poll() method for socket offload poll() API
Example modem driver setup code looks like this:
/* socket data */
static struct modem_socket_config socket_config;
static struct modem_socket sockets[MDM_MAX_SOCKETS];
static int modem_init(struct device *dev)
{
...
/* setup socket config */
socket_config.sockets = &sockets[0];
socket_config.sockets_len = ARRAY_SIZE(sockets);
socket_config.base_socket_num = 0;
ret = modem_socket_init(&socket_config);
...
}
Signed-off-by: Michael Scott <mike@foundries.io>
This is a generic command handler implementation which uses the
supplied modem interface to process incoming data and hand it
back to the modem driver via callbacks defined for:
- modem responses
- unsolicited messages
- specified handlers for current operation
The individual modem drivers define functions as command handlers
via the MODEM_CMD_DEFINE() macro.
To use these handlers, a modem operation defines a series of
modem_cmd structures and passes them to the modem_cmd_send()
function. The modem_cmd includes data for:
- a matching string for when to execute the handler
- # of parameters to parse after the matching string
- delimeters for the parameters
Example modem driver setup code looks like this:
/* create modem context object */
static struct modem_context mctx;
/* net_buf receive pool */
NET_BUF_POOL_DEFINE(mdm_recv_pool, MDM_RECV_MAX_BUF,
MDM_RECV_BUF_SIZE, 0, NULL);
/* modem cmds */
static struct modem_cmd_handler_data cmd_handler_data;
static u8_t cmd_read_buf[MDM_RECV_BUF_SIZE];
static u8_t cmd_match_buf[MDM_RECV_BUF_SIZE];
/* modem response handlers */
static struct modem_cmd response_cmds[] = {
MODEM_CMD("OK", on_cmd_ok, 0U, ""),
MODEM_CMD("ERROR", on_cmd_error, 0U, ""),
MODEM_CMD("+CME ERROR: ", on_cmd_exterror, 1U, ""),
};
/* unsolicited handlers */
static struct modem_cmd unsol_cmds[] = {
MODEM_CMD("+UUSOCL: ", on_cmd_socknotifyclose, 1U, ""),
MODEM_CMD("+UUSORD: ", on_cmd_socknotifydata, 2U, ","),
MODEM_CMD("+UUSORF: ", on_cmd_socknotifydata, 2U, ","),
MODEM_CMD("+CREG: ", on_cmd_socknotifycreg, 1U, ""),
};
/* setup cmd handler data */
cmd_handler_data.cmds[CMD_RESP] = response_cmds;
cmd_handler_data.cmds_len[CMD_RESP] = ARRAY_SIZE(response_cmds);
cmd_handler_data.cmds[CMD_UNSOL] = unsol_cmds;
cmd_handler_data.cmds_len[CMD_UNSOL] = ARRAY_SIZE(unsol_cmds);
cmd_handler_data.read_buf = &cmd_read_buf[0];
cmd_handler_data.read_buf_len = sizeof(cmd_read_buf);
cmd_handler_data.match_buf = &cmd_match_buf[0];
cmd_handler_data.match_buf_len = sizeof(cmd_match_buf);
cmd_handler_data.buf_pool = &mdm_recv_pool;
cmd_handler_data.alloc_timeout = BUF_ALLOC_TIMEOUT;
ret = modem_cmd_handler_init(&mctx.cmd_handler, &cmd_handler_data);
Signed-off-by: Michael Scott <mike@foundries.io>
Initial support for modems in Zephyr use the following driver model:
- Main portions of code live in the modem specific driver.
This includes internal socket management, command parsing, etc.
- They leverage a UART-based modem receiver helper to gather data.
- Interface with Zephyr networking via net_context offload APIs.
This implementation was good enough to kick start interest in
supporting modem usage in Zephyr, but lacks future scalability:
- The net_context offload APIs don't allow for operations such
as offloaded DNS, SSL/TLS and other HW specific features.
- Since most of the code lives within the modem drivers, it's
very hard for the Zephyr community to improve the driver layer
over time. Bugs found in 1 driver probably affect others due
to copy/paste method of development.
- Lack of abstraction for different modem interfaces and command
handlers makes it impossible to write a "dummy" layer which
could be used for testing.
- Lack of centralized processing makes implementing low power modes
and other advanced topics more difficult.
Introducing the modem context helper driver and sub-layers:
- modem context helper acts as an umbrella for several configurable
layers and exposes this data to externals such as the modem shell.
Included in the helper is GPIO pin config functions which are
currently duplicated in most drivers.
- modem interface layer: this layer sits on the HW APIs for the
peripheral which communicates with the modem. Users of the modem
interface can handle data via read/write functions. Individual
modem drivers can select from (potentially) several modem
interfaces.
- modem command parser layer: this layer communicates with the
modem interface and processes the data for use by modem drivers.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17922
Signed-off-by: Michael Scott <mike@foundries.io>
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move ring_buffer.h to sys/ring_buffer.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move uart.h to drivers/uart.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move gpio.h to drivers/gpio.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Move modem_receiver.h to the driver directory. No other users in the
tree and it is a private header.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
The u-blox SARA-R4 modem modules are Ultra-compact LTE Cat
M1 / NB1 ready:
- Configurable with a single hardware version
- Flexible mode selection as LTE Cat M1, LTE Cat NB1, EGPRS -
only/preferred
- Low power consumption and longer battery life
- Extended range in buildings, basements, and with NB1,
underground
This driver introduces support for basic AT commands to
query modem information as well as socket connection
for TCP/UDP communication.
Signed-off-by: Michael Scott <mike@foundries.io>
The WNC-M14A2A shield configuration has HW specific settings in place.
We can remove those settings here.
Signed-off-by: Michael Scott <mike@foundries.io>
Assert is checking the array size of pinconfig. Not the actual
size of the structure.
Fixes issue reported by Github User @weinholtendian
Signed-off-by: Michael Scott <mike@foundries.io>
Caller will handle freeing packet if error is encountered.
Fixes issue reported by Github User @weinholtendian:
<err> net_pkt: *** ERROR *** pkt 0x20027e78 is freed already
by offload_sendto():1717 (context_sendto():1473).
Signed-off-by: Michael Scott <mike@foundries.io>
Provide access functions for manipulating network interface flags.
There is no need for the caller of this API to know about the inner
details of the flags.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier. Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.
By default all files without license information are under the default
license of Zephyr, which is Apache version 2.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.
Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
This parameter was removed from net_context already thus applying the
change also on net_offload API.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Instead of aborting on RSSI poll error, let's continue on and
reschedule the next RSSI poll.
This fixes an issue where RSSI polling would stop if for any reason
the modem doesn't fulfill an RSSI poll on time.
Signed-off-by: Michael Scott <mike@foundries.io>
Changes in commit 854045c14d ("drivers/modem: Switch wncm14a2a
driver to new net_pkt API") moved WNC-M14A2A modem driver to new
net_pkt APIs. As part of these changes, the values for source and
destination passed into net_ipv6_create() were reversed.
Let's correct them.
Signed-off-by: Michael Scott <mike@foundries.io>
Commit fd1401495b ("net/tcp: Move net_tcp_set_hdr() away from net
core") removed <net/tcp.h>. This results in a not found error being
generated when CONFIG_NET_TCP is enabled.
We also, don't need to include <net/udp.h> anymore due to new
net_pkt API changes.
Let's clean up the includes by removing both of them.
Signed-off-by: Michael Scott <mike@foundries.io>
Socket-based API sends timeout K_FOREVER(-1) to net_context_connect()
function where previously net_app APIs used an actual timeout value.
Now that we've switched to socket-based APIs, we reveal poor handling
for the timeout value which causes an error in the WNC-M14A2A driver
due to math performed on the -1 value.
Let's be sure to check for valid timeout values prior to performing
math and then make sure it falls within the allowable range of values
for the AT@SOCKCONN command (30 seconds to 360 seconds).
Signed-off-by: Michael Scott <mike@foundries.io>
In commit c1f24abb13 ("drivers: modem: wistron kconfig separation"),
A single line of the WNC-M14A2A congigs was left in the main modem
Kconfig.
Let's clean up the Kconfig file by removing the left over.
Signed-off-by: Michael Scott <mike@foundries.io>
CONFIG_GPIO may not be enabled on some HW, so let's make sure to
enable it if the dependencies are met, as the WNC-M14A2A driver
needs to set power, reset and other GPIOs.
Signed-off-by: Michael Scott <mike@foundries.io>
These symbols are already within an 'if MODEM_WNCM14A2A', so no need to
put 'depends on MODEM_WNCM14A2A' on them.
Also remove a redundant 'depends on MODEM' from MODEM_WNCM14A2A.
drivers/modem/Kconfig.wncm14a2a is already sourced within an 'if MODEM',
in drivers/modem/Kconfig.
'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.
Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Coverity doesn't like that we're storing the return value of
net_buf_findcrlf() near the end of the handler block as "len".
Only to overwrite "len" again once we exit and look for the next
match.
Let's ignore the return value there and also remove the redundant
check for !frag. Either way, we've found a handler, and need to
break the search loop.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12315
Signed-off-by: Michael Scott <mike@foundries.io>
We can't let i == value_size during the loop which gathers characters
for the length. If we do, the next check of "value[i] != ','" would
access memory beyond the value boundary.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12290
Signed-off-by: Michael Scott <mike@foundries.io>
mdm_receiver_send() was sending 1 too many bytes of buf. This ended
up being the NULL terminator. Size should be reduced prior to the
while check so that this doesn't happen.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/14001
Signed-off-by: Michael Scott <mike@foundries.io>
Repalces send fifo_fill implementation with poll_out,
this makes the receiver usefull on most SoC.
Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
Rearranges functions to public and private groups,
and adds missing function comments.
Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
Log possible uart device binding error and change
the error type to a more correct one.
Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
It is a bit awkward that ip/proto headers have to be rebuilt (with fake
data in it though). Let's see in future if that's really needed,
offload device handles already ip/proto headers by themselves so we
should not care.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Let's also check for bytes_read == 0 after calling mdm_receiver_recv()
and if so, break the loop so we don't endlessly loop.
Signed-off-by: Michael Scott <mike@foundries.io>
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.
Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
LOG_LEVEL should be set to CONFIG_MODEM_LOG_LEVEL not
CONFIG_LOG_MODEM_LEVEL. In cleaning this up use
LOG_MODULE_REGISTER(x,y) form to reduce 3 lines to 1.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).
Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Every now and then the 100ms delay for collecting IMEI data from the
modem, wasn't long enough and this presents a bad user experience.
Let's set it to 500ms which seems to be working all the time.
Signed-off-by: Michael Scott <mike@foundries.io>
During development of the WNC-M14A2A modem driver, I felt like the
initialization took too long to make the user wait. However, due
to the addition of other drivers such as OpenThread where delays
during startup are noticable, the modem startup time isn't so bad.
Let's remove the delay work which allows Zephyr to startup before
the modem is fully initialized.
NOTE: This also fixes a long standing bug where samples using the
modem would never know when it was ready (without waiting for the
interface up event). This change makes it always ready once the
sample starts.
Signed-off-by: Michael Scott <mike@foundries.io>
Moved UART interrupt dependencies from concrete driver to
the modem receiver as it uses UART interrupt functions within.
This allows developing other UART interrupt based modems without
the need to depend on the aforementioned features explicitly.
Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
net_buf_linearize() used to clear the contents of output buffer,
just to fill it with data as the next step. The only effect that
would have is if less data was written to the output buffer. But
it's not reliable for a caller to rely on net_buf_linearize() for
that, instead callers should take care to handle any conditions
like that themselves. For example, a caller which wants to process
the data as zero-terminated string, must reserve a byte for it
in the output buffer explicitly (and set it to zero).
The only in-tree user which relied on clearing output buffer was
wncm14a2a.c. But either had buffer sizes calculated very precisely
to always accommodate extra trailing zero byte (without providing
code comments about this), or arguably could suffer from buffer
overruns (at least if data received from a modem was invalid and
filled up all destination buffer, leaving no space for trailing
zero).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
The comment was incorrect explaining why we were sending an
AT-command without waiting for a response (via a K_NO_WAIT timeout).
Let's correct the comment and avoid confusion.
Signed-off-by: Michael Scott <mike@foundries.io>
Remove overly complicated logic to skip incoming data if we were
still waiting on a previous set of data to be read.
This fixes a bug where an error during data receive could end up
with the modem ignoring all incoming data.
Signed-off-by: Michael Scott <mike@foundries.io>
Modem driver for WNCM14A2A was erroneously leaving the
selection of UART_INTERRUPT_DRIVEN up to CONSOLE_HANDLER.
Now, with the move to the new SHELL backend, this is no
longer happening.
Let's select it from the modem driver, instead of depending
on it.
Let's also add a dependency on SERIAL_SUPPORT_INTERRUPT
which the serial drivers enable to let us know
UART_INTERRUPT_DRIVEN is available.
Signed-off-by: Michael Scott <mike@foundries.io>
These changes were obtained by running a script created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:
1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
#define X Y)
3. Check if that name is also the name of a Kconfig option
3.a If it is, then do nothing
3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
(.c, .h, .ld)
Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.
Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
I have no idea what I was thinking when I wrote this.
But, it's an easy fix to remove the void * entirely.
Signed-off-by: Michael Scott <mike@foundries.io>
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.
The only directory excluded directory was ext/* since it contains
only imported code.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
These settings enable use of the WNC-M14A2A LTE-M modem as the default
network interface for the nRF52840-DK board (nrf52840_pca10056).
They include the following settings when MODEM_WNCM14A2A is selected:
- UARTE1 pin setup
- DTS / DTS fixup additions for WNC-M14A2A
- Kconfig settings for modem driver
Signed-off-by: Michael Scott <mike@foundries.io>
These settings enable use of the WNC-M14A2A LTE-M modem as the default
network interface instead of ethernet.
They include the following settings when MODEM_WNCM14A2A is selected:
- UART 2 setup
- Avoid ETH_0 setup due to pin conflicts
- DTS addition for WNC-M14A2A
- Kconfig settings for modem driver
Signed-off-by: Michael Scott <mike@foundries.io>
Add a set of modem shell commands to support modem development.
Start with:
modem list: Lists all registered modems and related information
modem send <modem receiver index> <command>: Send command to modem
Signed-off-by: Michael Scott <mike@foundries.io>
The WNC-M14A2A (LTE / LTE-M) modem is presented as an Arduino-
compatible shield via AT&T's IoT Starter Kit v1.0. It was
originally intended to work with the FRDM-K64F board, but
in theory as long as the right pins are configured it can
work with any board that supports Arduino-compatible headers.
The driver utilizes the CONFIG_NET_OFFLOAD setting to avoid the
normal handling of IP packets, and instead uses a socket-like
UART interface to handle incoming and outgoing data.
Signed-off-by: Michael Scott <mike@foundries.io>
Modem drivers need a fast buffer-based receiver for passing data
back and forth from the UART to the driver. This provides an
efficient configuarable driver which merely sends and receives
but doesn't process the data, that's left up to the modem driver.
Signed-off-by: Michael Scott <mike@foundries.io>