Commit graph

100 commits

Author SHA1 Message Date
Vincent Wan eb9a184324 drivers: fix socket close() implementations for socket offloading
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>
2020-08-18 10:41:01 +03:00
Jukka Rissanen 2ed6b6a8ed lib: fdtable: Add callback for close() calls
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>
2020-08-14 09:47:51 -07:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Andrew Boie 7d920ba39b drivers: use K_KERNEL_STACK macros
None of these threads run in user mode and we can save some
memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-04 12:16:43 -04:00
Adam Porter 9da0f2af31 drivers: modem: use zsock_ variants of socket API
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>
2020-06-10 09:27:51 +03:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Piotr Mienkowski bf1eceeebc drivers: ublox-sara-r4: update to the new timeout api
Update to the new timeout api. This fixes compilation errors.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2020-06-01 12:30:40 +02:00
Hans Wilmers 2972cdc763 drivers: modem: ublox-sara-r4: fix getaddrinfo
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>
2020-05-27 18:35:39 +02:00
Hans Wilmers fdd89efd3a drivers: modem: ublox-sara-r4: automatic setting of APN
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>
2020-05-07 23:36:10 -05:00
Hans Wilmers cef334b5fe drivers: modem: ublox-sara-r4: automatic detection of modem type
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>
2020-05-07 23:36:10 -05:00
Peter Bigot 93884a4fe1 coccinelle: run int_ms_to_timeout conversion semantic patch
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>
2020-05-07 19:46:03 +02:00
Hans Wilmers 5d6770aeea drivers: modem: ublox-sara-r4: implemented sendmsg
Implemented sendmsg

Tested using Sara U201 and the MQTT protocol library.

Signed-off-by: Hans Wilmers <hans@wilmers.no>
2020-04-21 17:37:08 +03:00
Hans Wilmers ed88088ba2 driver: modem: ublox_sara_r4: fixed closing UDP socket
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>
2020-04-21 17:37:08 +03:00
Hans Wilmers 71fa7ba5ad drivers: modem: ublox_sara_r4: fixed rssi for Sara U201
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>
2020-04-21 17:37:08 +03:00
Steven Slupsky b39423e0e2 drivers: modem: gpio api and string len
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>
2020-04-21 17:02:22 +03:00
Kumar Gala bf4246ad6b drivers: modem: ublox-sara-r4: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 13:08:30 -05:00
Tomasz Bursztyka 4ae72db135 net: Enable PM settings on network devices
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>
2020-03-27 14:48:30 +02:00
Kumar Gala 4a7c2921f8 drivers: modem: ublox-sara-r4: convert to DT_INST defines
Convert driver to use DT_INST_ defines.  The preferred defines for
drivers are DT_INST_.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-11 07:59:38 -06:00
Michael Scott e934825719 drivers: modem: sara-r4: fix APN setting for U2 modem
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>
2020-02-10 20:00:15 +02:00
Michael Scott b6b4396c48 drivers: modem: sara-r4: use +USO[RF|RD] based on proto
Regardless of whether from is set, let's use the correct socket read
commands for UDP and TCP.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott a6fc7f8669 drivers: modem: sara-r4: disable hex mode for binary data
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>
2020-02-10 12:29:41 +02:00
Michael Scott 90c6dc5e7f drivers: modem: cmd_handler: add return value to modem commands
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>
2020-02-10 12:29:41 +02:00
Michael Scott 698661b56e drivers: modem: sara-r4: update functions to return POSIX values
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>
2020-02-10 12:29:41 +02:00
Michael Scott 87481e8eef drivers: modem: sara-r4: handle read limits
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>
2020-02-10 12:29:41 +02:00
Michael Scott 52afcc21d6 drivers: modem: sara-r4: fix error text in net_offload_dummy_get
Correctly tell the user that CONFIG_NET_SOCKETS_OFFLOAD needs to be
enabled.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 2be4f997b3 drivers: modem: sara-r4: use new socket functions
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>
2020-02-10 12:29:41 +02:00
Michael Scott 36e4fc7743 drivers: modem: sara-r4: manage sock->is_connected
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>
2020-02-10 12:29:41 +02:00
Michael Scott 6c9bb48ce7 drivers: modem: sara-r4: use 120s connection timeout
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>
2020-02-10 12:29:41 +02:00
Göran Weinholt 8fb3f21e58 drivers: modem: sara-r4: support for 2G on the SARA R412M modem
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>
2020-02-10 12:29:41 +02:00
Göran Weinholt bf59ceda0b drivers: modem: sara-r4: support for network indication on SARA modems
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>
2020-02-10 12:29:41 +02:00
Göran Weinholt ea99d34e00 drivers: modem: sara-r4: continually signal the modem to power off
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>
2020-02-10 12:29:41 +02:00
Hans Wilmers 1db79054af drivers: modem: sara-r4: fix modem reset
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>
2020-02-10 12:29:41 +02:00
Hans Wilmers 97921368d3 drivers: modem: sara-r4: adjust send and receive lengths
- 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>
2020-02-10 12:29:41 +02:00
Michael Scott a18f78894f drivers: modem: sara-r4: make room for NUL in match_buf
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>
2020-02-10 12:29:41 +02:00
Michael Scott 8ef2ae8ce5 drivers: modem: sara-r4: add offloaded DNS handling
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>
2020-02-10 12:29:41 +02:00
Michael Scott 50d4e07d0c drivers: modem: sara-r4: remove interface up / down
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>
2020-02-10 12:29:41 +02:00
Michael Scott 1265843495 drivers: modem: sara-r4: cleanup offload_recvfrom timeout
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>
2020-02-10 12:29:41 +02:00
Michael Scott ba34136581 drivers: modem: sara-r4: dont unblock on sockread
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>
2020-02-10 12:29:41 +02:00
Michael Scott 1f68802899 drivers: modem: sara-r4: space for NUL in buffer is optional
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>
2020-02-10 12:29:41 +02:00
Michael Scott 179307c723 drivers: modem: sara-r4: return send bytes from send_socket_data
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>
2020-02-10 12:29:41 +02:00
Tobias Svehagen 8a9c9d43bf drivers: modem: Add support for different line endings
This makes it possible to handle devices that use different line
endings.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-05 23:31:56 +02:00
Peter Bigot 97106bf95e drivers: modem: clean up pin configuration
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>
2020-02-05 12:00:36 +01:00
Carles Cufi d7afd55a45 drivers: modem: ublox-sara-r4: Convert to the new GPIO API
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>
2020-02-05 12:00:36 +01:00
Robert Lubos e434725bdf drivers: modem: ublox-sara-r4: Rework offloading mechanism
Switch to `NET_SOCKET_REGISTER` mechanism over the offloaded API
registration.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Michael Scott ee92cf4d68 drivers: modem: ublox-sara-r4: Support SARA-U2 modems, sense VINT
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>
2019-08-10 00:03:39 +02:00
Michael Scott ebf6520d87 drivers: modem: ublox SARA convert to modem context
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>
2019-08-10 00:03:39 +02:00
Anas Nashif 6aa9c3a68f cleanup: include/: move gpio.h to drivers/gpio.h
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>
2019-06-27 22:55:49 -04:00
Anas Nashif 158d921cde drivers: modem: modem_receiver.h: move header from /include/
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>
2019-06-25 15:27:00 -04:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
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>
2019-06-14 08:02:15 -05:00
Michael Scott 759d1d6408 drivers: modem: introduce u-blox SARA-R4 modem driver
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>
2019-05-21 08:17:20 -04:00