Commit graph

155 commits

Author SHA1 Message Date
Flavio Ceolin c4f7faea10 random: Include header where it is used
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>
2020-07-08 21:05:36 -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
Jukka Rissanen d81be8fd9c drivers: modem: gsm: Do not reference possible null pointer
The ppp_dev was used even if its value could be NULL.

Fixes #25781
Coverity-CID: 210031

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-06-08 16:50:35 +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
Andrew Boie fed960b94a net: tag net socket objects
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>
2020-06-03 22:33:32 +02: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
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +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
Carles Cufi 94861a438b drivers: modem: Port to new timeout API
Port the internal modem API to the new timeout API, using the native
k_timeout_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 11:01:55 +02:00
Jukka Rissanen 0576ce813f driver: modem: wncm14a2a: Convert to use k_timeout_t
Convert the code to use k_timeout_t when applicable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-01 10:50:03 +03:00
Ryan Erickson a757832110 drivers: modem: wncm14a2a: fully release TCP context
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>
2020-04-29 23:14:29 +03: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
Peter Bigot df106a1708 modem: gsm: correct timeout parameter to k_delayed_work_submit
The parameter is a k_timeout_t, not an integer in milliseconds.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-20 18:09:18 +03:00
Jukka Rissanen 31ec75fca3 modem: shell: Add info command
Add an information command that currently will only prints
GSM muxing status.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-17 10:15:54 +03:00
Jukka Rissanen 775dcb222e modem: gsm: Initialize the modem UART separately
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>
2020-04-17 10:15:54 +03:00
Jukka Rissanen 492088b3fa net: ppp: Convert PPP driver to use normal UART APIs
This is needed so that we can support GSM 07.10 muxing protocol.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-17 10:15:54 +03:00
Jukka Rissanen eb1ad99cff drivers: modem: gsm: Add support for GSM 07.10 muxing protocol
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>
2020-04-17 10:15:54 +03:00
Johan Hedberg 71eb56a34c net: buf: Move LEGACY_TIMEOUT_API selection to specific subsystems
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>
2020-04-03 23:17:53 +03:00
Peter Bigot ecf3bdb5b3 coccinelle: re-run timeout conversion semantic patch
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>
2020-04-02 19:47:51 +03:00
Kumar Gala b00697a9b1 drivers: modem: wncm14a2a: 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 14:38:58 -05: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
Ryan Erickson 6a625c371f drivers: modem: wncm14a2a: fix RX socket src/dst port assignment
Source and destination ports should be set properly
when assembling the receive socket data.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2020-03-20 10:54:51 +01:00
Tobias Svehagen 990ab00e30 drivers: modem: Add support for commands that don't have a line ending
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>
2020-03-11 23:48:06 +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
Jukka Rissanen ded0ea62a1 driver: modem: Print sent data if verbose debugging is enabled
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>
2020-03-10 15:20:02 +02:00
Flavio Ceolin 6e25ebf269 drivers: modem: Remove invalid comparison
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>
2020-03-10 13:03:03 +02: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
Jukka Rissanen 45eccbc5d7 drivers: modem: gsm: Command handlers should return value
GSM modem command handlers were missing a return value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-02-10 19:52:33 +02:00
Jukka Rissanen b05e72f3bb drivers: modem: gsm: Add setting of MCC number
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>
2020-02-10 12:32:24 +02:00
Jukka Rissanen 49724e25a0 drivers: modem: gsm: Add misc fixes like line ending char set
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>
2020-02-10 12:32:24 +02:00
Jukka Rissanen 4c1b0ab2a9 drivers: modem: gsm: Add context to DEVICE_INIT()
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>
2020-02-10 12:32:24 +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 5185b8cf40 drivers: modem: cmd_handler: honor num of params in parse_params
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>
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