Commit graph

155 commits

Author SHA1 Message Date
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
Michael Scott 82dc1665af drivers: modem: cmd_handler: fix findcrlf() indentation
Missed during previous rework.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 74bb1a9be9 drivers: modem: cmd_handler: remove extra comment
Remove extra comment left over from prototype driver.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 44e977c467 drivers: modem: cmd_handler: save 1 char for NUL in match_buf
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>
2020-02-10 12:29:41 +02:00
Michael Scott f4b49fbb90 drivers: modem: cmd_handler: cleanup parse_params()
- 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>
2020-02-10 12:29:41 +02:00
Michael Scott 889fc85f67 drivers: modem: socket: add is_connected field to modem_socket
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>
2020-02-10 12:29:41 +02:00
Michael Scott 25ce3bf3eb drivers: modem: socket: add modem_socket_next_packet_size
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>
2020-02-10 12:29:41 +02:00
Michael Scott e23ada9d4a drivers: modem: socket: reset is_polled in modem_socket_put()
Let's make sure is_polled gets reset when we reset the socket.

Signed-off-by: Michael Scott <mike@foundries.io>
2020-02-10 12:29:41 +02:00
Michael Scott 8908c61bcc drivers: modem: socket: add wait_data and data_ready functions
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>
2020-02-10 12:29:41 +02:00
Michael Scott 987837ecd8 drivers: modem: socket: introduce locking
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>
2020-02-10 12:29:41 +02:00
Michael Scott d4b8b5fcf2 drivers: modem: socket: allow partial packet reads
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>
2020-02-10 12:29:41 +02:00
Jukka Rissanen 6009045902 drivers: modem: Fix gpio compile errors with modem shell
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>
2020-02-06 12:33:20 +02:00
Jukka Rissanen cb4bf32f2c drivers: modem: gsm: Add support for getting modem info
Add callbacks to get the modem information which can then be
shown by modem shell.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-02-06 10:19:25 +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 8399224271 drivers: modem: wncm14a2a: Convert to the new GPIO API
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>
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
Jukka Rissanen 1474b4ea14 drivers: modem: gsm: Use modem log level instead of ppp
Use the same log level as the other modems.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-02-05 10:19:15 +02: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
Jukka Rissanen 66cc8e9c3a drivers: modem: gsm: Fix uart_pipe.h location
The uart_pipe.h was moved to drivers/console/uart_pipe.h and that
was missed by sanity.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-28 19:11:13 +02:00
Patrik Flykt 3fe8707bc0 drivers: modem: Implement uart_pipe interface for GSM modem
Implement uart_pipe functionality for the modem so that it
integrates with the PPP implementation.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2020-01-28 12:44:17 +02:00
Patrik Flykt 2308293d89 drivers: modem: Support GSM modems and PPP
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>
2020-01-28 12:44:17 +02:00
Patrik Flykt 12f381888f drivers: modem: Document UART device name
Document that the third argument is the UART device name.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-12-02 15:34:45 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
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>
2019-11-04 17:31:27 -05:00
Christoph Schramm ce4cc465fc driver: modem: add simple power management to modem receiver
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>
2019-09-08 12:41:29 +02:00
Michael Scott a7379234ba drivers: modem: socket: sock_fd isn't an index in modem_socket_put()
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>
2019-08-14 11:01:47 +02: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
Michael Scott f5c45c2946 drivers: modem: introduce socket helper layer
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>
2019-08-10 00:03:39 +02:00
Michael Scott 02abddccd6 drivers: modem: cmd handler: introduce cmd handler driver layer
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>
2019-08-10 00:03:39 +02:00
Michael Scott d56a05f7a7 drivers: modem: interface: introduce UART interface driver layer
The UART-based modem interface layer implements the modem context
interface for Zephyr's UART APIs.  This driver closely resembles
the existing modem receiver, but conforming to the modem interface
agreements.

Example modem driver setup code looks like this:

/* create modem context object */
static struct modem_context mctx;

/* create uart interface data object and buffers */
static struct modem_iface_uart_data iface_data;
static u8_t iface_isr_buf[MDM_RECV_BUF_SIZE];
static u8_t iface_rb_buf[MDM_MAX_DATA_LENGTH];

iface_data.isr_buf = &iface_isr_buf[0];
iface_data.isr_buf_len = sizeof(iface_isr_buf);
iface_data.rx_rb_buf = &iface_rb_buf[0];
iface_data.rx_rb_buf_len = sizeof(iface_rb_buf);
ret = modem_iface_uart_init(&mctx.iface, &iface_data,
			    UART_DEV_NAME);

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-10 00:03:39 +02:00
Michael Scott 90e778d983 drivers: modem: context helper: introduce modem context helper driver
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>
2019-08-10 00:03:39 +02:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
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>
2019-06-27 22:55:49 -04:00
Anas Nashif 7435e5e089 cleanup: include/: move ring_buffer.h to sys/ring_buffer.h
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>
2019-06-27 22:55:49 -04:00
Anas Nashif d1b2718687 cleanup: include/: move uart.h to drivers/uart.h
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>
2019-06-27 22:55:49 -04: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
Michael Scott fd69094656 drivers: modem: wncm14a2a: remove HW specific Kconfig settings
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>
2019-05-21 08:17:20 -04:00
Michael Scott bd2d03923e drivers: modem: wncm14a2a: correct pinconfig assert check
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>
2019-05-21 08:17:20 -04:00
Michael Scott d8f8f0f253 drivers: modem: wncm14a2a: dont free packet on error
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>
2019-05-21 08:17:20 -04:00
Jukka Rissanen 712103d594 net: if: Add access functions for network interface flags
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>
2019-04-23 13:11:03 +03:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
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>
2019-04-07 08:45:22 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
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>
2019-04-03 17:31:00 -04:00
Tomasz Bursztyka a57e218965 net/offload: Remove useless token parameter
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>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka d6d52ce9e5 net/pkt: Remove _new suffix to net_pkt_write functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka f8a091104e net/pkt: Remove _new suffix to net_pkt_get_data_new function
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>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 820f3ad006 net/ipv6: Replace legacy net_ipv6_create by the new one
Thus removing the legacy one, and renaming the new one to legacy name.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka ca58b4c761 net/ipv4: Replace legacy net_ipv4_create by the new one
Thus removing the legacy one, and renaming the new one to legacy name.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Michael Scott 29cc3b5aed drivers: modem: wnc14a2a: dont stop RSSI processing on error
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>
2019-03-19 09:47:17 -05:00
Michael Scott 197757f4dd drivers: modem: wnc14a2a: correct IPv6 SRC and DST
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>
2019-03-19 09:47:17 -05:00
Michael Scott 19de7ecc5b drivers: modem: wncm14a2a: remove left-over includes
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>
2019-03-14 08:41:34 +01:00
Michael Scott 104effed85 drivers: modem: wncm14a2a: Fix timeout handling for AT@SOCKCONN
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>
2019-03-14 08:41:34 +01:00
Michael Scott a4cedf5a0b drivers: modem: remove leftover artifact from wncm14a2a split
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>
2019-03-14 08:41:34 +01:00
Michael Scott e99af7db3d drivers: modem: wnc-m14a2a: imply GPIO usage
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>
2019-03-14 08:41:34 +01:00
Ulf Magnusson 28063dc9ab kconfig: drivers: modem: Remove redundant MODEM_WNCM14A2A deps
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>
2019-03-09 09:58:08 -05:00
Michael Scott d5d35d06d1 drivers: modem: wncm14a2a: cleanup wncm14a2a_rx() handler block
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>
2019-03-07 04:58:45 -06:00
Michael Scott 693827d09b drivers: modem: wncm14a2a: Fix illegal mem access in on_cmd_sockread()
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>
2019-03-07 04:58:45 -06:00
Michael Scott bc5a3f25ad drivers: modem: fix extra bytes sent by mdm_receiver_send()
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>
2019-03-04 09:40:45 -05:00
Georgij Cernysiov c1f24abb13 drivers: modem: wistron kconfig separation
Separates Kconfig to a separate file.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:48:12 +01:00
Georgij Cernysiov 3fe917ef64 drivers: modem: receiver: guards against 0 size
Protects against 0 size in send, receive, and
registration.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov 27618404f6 drivers: modem: receiver: replace fifo_fill with poll_out
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>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov 886ab98fd0 drivers: modem: receiver: use asserts internally
Switch to asserts where applicable for internal
functions.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov 2234621d9e drivers: modem: receiver: fix sending
Send implementation shall return 0 for ok,
or < 0 for an error.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov de8b39f6eb drivers: modem: receiver: rearrange and comment
Rearranges functions to public and private groups,
and adds missing function comments.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov 94ee0ddbde drivers: modem: receiver: switch to ring buffer from pipe api
Replaces used k_pipe with ring_buffer API which is safe for ISR.

Signed-off-by: Georgij Cernysiov <g.cernysiov@elco-automation.de>
2019-03-01 09:46:48 +01:00
Georgij Cernysiov 23b64b0d35 drivers: modem: receiver: correct device bind error type
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>
2019-03-01 09:46:48 +01:00
Tomasz Bursztyka 854045c14d drivers/modem: Switch wncm14a2a driver to new net_pkt API
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>
2019-02-21 09:30:57 -05:00
Michael Scott aa226eb528 drivers: modem: wncm14a2a: stop reading when bytes read is 0
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>
2019-02-20 10:46:54 -06:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
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>
2019-02-20 07:31:35 -05:00
Kumar Gala b0e7d312db modem: Fix LOG Kconfig typo
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>
2019-02-12 07:50:06 -05:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
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>
2019-02-01 14:34:38 +02:00
Michael Scott 1e0a7116bd drivers: modem: wncm14a2a: allow more time for getting IMEI data
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>
2019-01-30 10:25:52 -06:00
Michael Scott 4fcab1ef1a drivers: modem: wncm14a2a: wait for modem init
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>
2019-01-30 10:25:52 -06:00
Kumar Gala 3e8fc3c0c1 modem: wncm14a2a: Convert to new DT_<COMPAT>_<INSTANCE> defines
Convert wncm14a2a driver to use new defines so we can remove the
dts_fixup.h code for it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-29 14:21:56 -06:00
Georgij Cernysiov bed7fb3df0 drivers: modem: modem receiver dependencies adaptation
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>
2019-01-25 17:36:59 -05:00
Paul Sokolovsky c885cb533e net: buf: linearize: Get rid of useless memset()
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>
2019-01-12 15:24:29 -06:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Tomasz Bursztyka ee9dedd5a7 net/iface: Finally remove the send function from net_if_api
And apply that to modem driver setting that pointer to NULL.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Michael Scott 0abd92266a drivers: modem: wncm14a2a: correct comment in on_cmd_sockdataind()
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>
2018-11-28 15:34:19 -08:00
Michael Scott e8a690ff70 drivers: modem: wncm14a2a: remove socket_reading logic
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>
2018-11-28 15:34:19 -08:00
Michael Scott 39843617cb drivers: modem: WNCM14A2A select UART_INTERRUPT_DRIVEN
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>
2018-11-21 04:09:23 -06:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
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>
2018-11-13 10:44:42 -06:00
Michael Scott 25d5736e69 drivers: modem: wncm14a2a: fix void ptr math warning
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>
2018-10-29 09:14:26 -04:00
Michael Scott 38bdc9f532 drivers: modem: migrate modem shell to new shell API
Convert modem-shell to use the new shell API.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-29 08:40:40 -04:00
Anas Nashif 5c76143bcd drivers: modem: register logging module
Add missing registration for modem driver.

Fixes #10518

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-15 10:48:11 -04:00
Anas Nashif ecc050e69e drivers: modem: move to new logger
Move driver to new logger.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-10 10:22:01 -04:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
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>
2018-09-19 09:30:29 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
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>
2018-09-14 16:55:37 -04:00
Mieszko Mierunski 4f6aac1a67 dts: nrf5: Changed GPIO and GPIOTE define names
Changed names using nrf5 to nrf for consistency with other drivers.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2018-08-17 07:29:14 -07:00