Commit graph

388 commits

Author SHA1 Message Date
Marcin Niestroj 0b59257d93 drivers: wifi: esp32: create event handling thread in runtime
Commit 95b916d104 ("drivers: wifi: esp32: fix reconnect issue")
switched from thread created at runtime to statically defined thread.
The difference is mainly visible for simple applications that use
CONFIG_NET_CONFIG_AUTO_INIT=y, where networking setup code is executed
before main() and any statically defined threads. All ESP32 events are
just queued and never handled, so conditions enforced by
CONFIG_NET_CONFIG_NEED_IPV4=y are never met (e.g. Zephyr networking
layer is never informed about being connected).

Switch back to thread created at runtime, which starts at the moment
when k_thread_create() is invoked. This allows ESP32 event processing to
happen just after ESP32 WiFi driver gets initialized and before Zephyr
network auto initialization code (CONFIG_NET_CONFIG_AUTO_INIT=y).

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-06-08 11:15:38 -05:00
Sylvio Alves 95b916d104 drivers: wifi: esp32: fix reconnect issue
Device won't reconnect automatically even if
AP station is available. This fix adds the carrier event, indicating
that network is present again enabling DHCP bound event.
Also, internal wifi event callback was added into wifi
driver to enable proper event handling.

Update west.yml to bring exposed wifi event callback.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>

Fixes #33843
2021-05-27 08:23:06 -05:00
Kamil Panek 8a23205a22 drivers: wifi: eswifi: fix swapped protocols in eswifi_off_getaddrinfo
As a result, when values returned by getaddrinfo were used, the wrong
socket was created.

Signed-off-by: Kamil Panek <kamil.panek@wbudowane.pl>
2021-05-25 16:59:17 -05:00
Marcin Niestroj eb78d70805 drivers: wifi: esp: stop using pkt->work in TX path
Usage of k_work object from within net_pkt results in undefined behavior
in case when net_pkt is deallocated (by net_pkt_unref()) before work has
been finished.

Use per socket k_work object (sock->send_work) to submit send work and
put net_pkt objects onto k_fifo (sock->tx_fifo). Add a helper function
esp_socket_queue_tx() for that, which will make sure that packets are
enqueued only when send work handler will be successfully submitted (so
that all packets are consumed/dereferenced).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-05-07 13:10:01 +02:00
Marcin Niestroj b4854debd1 drivers: wifi: esp_at: rename driver from esp
Recently WiFi ESP32 driver (utilizing WiFi radio in ESP32 SoC) was
introduced into drivers/wifi/esp32/ and it already caused confusion as
there was existing drivers/wifi/esp/ directory for ESP-AT
driver (utilizing external WiFi chip, by communicating using AT commands
from any serial capable platform). So question has arisen whether it is
good to merge both, while they are totally different drivers.

Rename ESP-AT driver to be placed in drivers/wifi/esp_at/, so that it is
easier to figure out difference between "esp32" and "esp_at" just by
looking at driver name. Rename also DT compatible and all Kconfig
options for the same reason.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-05-06 13:21:39 -04:00
Marcin Niestroj a8e6fc0b83 drivers: wifi: esp: do not wait at the end of ESP chip reset
esp_reset() is called from net_if init function, which holds net_if lock
after commit 24b49f4399 ("net: if: Add locking"). At the end of
esp_reset() there is a blocking wait on `sem_if_up` semaphore. This
semaphore can be release only by esp_init_work(). esp_init_work()
however blocks on net_if operations, because net_if init function (which
invokes esp_reset() underneath) is still holding net_if lock. As a
result there is a deadlock, because esp_reset() and esp_init_work() are
both waiting on each other.

Remove waiting for `sem_if_up`, so that net_if init can exit and release
net_if lock.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-05-06 07:42:55 -05:00
Marcin Niestroj bb8b8b8b5f drivers: wifi: esp: use dns_resolve_reconfigure() API
Use recently introduced API, which takes care of gracefully closing any
pending DNS requests and replacing existing DNS server list with new
one.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-29 08:00:09 -04:00
Gerard Marull-Paretas 0efc185018 drivers: wifi: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:25:39 -04:00
Sylvio Alves fe621f7071 wifi: esp32: allow wifi symbols into flash
When BT and WiFi coexists, IRAM usage increases a lot.
Add configuration that allow wifi symbols
to be placed in flash, freeing space in IRAM.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-04-26 13:39:21 +02:00
Peter Bigot 9fcd75160e drivers: wifi: rote conversion of k_work API
Replace all existing deprecated API with the recommended alternative.

Be aware that this does not address architectural errors in the use
of the work API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-04-14 07:07:40 -04:00
Kumar Gala 2235c71ced drivers: wifi: Remove unncessary zephyr_include_directories
Several wifi drivers add some form of zephyr_include_directories(.)
which isn't needed since the headers in the specific driver dir get
included via #include "foo.h".  So we can remove any uses of
zephyr_include_directories(.)

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-23 13:14:38 -05:00
Anas Nashif 5d6c219210 drivers: device: do not reuse tag name 'device'
Do not reuse tag name (misra rule 5.7).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 19:48:14 -04:00
Sylvio Alves 856ff7db3d wifi: esp32: remove posix api dependency
HAL was updated so that POSIX API is not a dependency anymore.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-03-19 17:27:40 +02:00
Raja D. Singh 554101ed70 drivers: wifi: winc1500: Add new config flag
There is a hardcoded macro in Winc1500 HAL SPI driver
that would prevent the driver from working.
This macro is now defined only based on KConfig entry.
This KConfig entry is by default not set.
To enable, set "CONFIG_WINC1500_DRV_USE_OLD_SW=y"
in proj.conf or board.conf

Signed-off-by: Raja D. Singh <rdsingh@iotwizards.com>
2021-03-04 09:34:00 +02:00
Shubham Kulkarni e16e606923 esp32: add esp32 wifi driver
add support for esp32 wifi

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
2021-02-25 17:00:20 -05:00
Marcin Niestroj 283f25f596 drivers: wifi: eswifi: Convert driver to new DT device macros
Convert eswifi driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Marcin Niestroj 5701ebb036 drivers: wifi: esp: Convert driver to new DT device macros
Convert esp driver:

    NET_DEVICE_OFFLOAD_INIT -> NET_DEVICE_DT_INST_OFFLOAD_DEFINE

DT label is already required, so use it and drop CONFIG_WIFI_ESP_NAME
option.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-15 08:31:52 -05:00
Marcin Niestroj fe6266ea7d drivers: wifi: esp: fix hostname configuration
By the time hostname configuration was implemented, driver was switching
only between STA and STA+AP modes. After dynamic selection between NONE,
STA, AP and STA+AP was implemented (commit referenced below), hostname
configuration no longer takes effect when ESP chip obtains address over
DHCP (and sends hostname in the DHCP request).

Set hostname each time after enabling STA mode, so that it takes effect
in DHCP requests.

Fixes: 03ce61004b ("drivers: wifi: esp: control CWMODE depending on
  current needs")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-14 22:12:47 -05:00
Marcin Niestroj 70efb83fd2 drivers: wifi: esp: process received packets in esp_rx thread
So far received packets were parsed (at AT command level) and allocated
in [esp_rx] thread. Then they were submitted to [esp_workq] thread for
processing (calling application callback).

This flow results in following deadlock when esp_workq thread waits on
response to some AT command:

  - [esp_rx] waits on allocation of new RX packet
  - [esp_workq] waits for [esp_rx] to process response to AT command
    that was just sent
  - blocked [esp_workq] prevents processing and deallocating RX packets
  - [esp_rx] times out on allocation and closes socket

Process RX packets directly from [esp_rx] thread to prevent above
deadlock.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-05 11:42:03 -05:00
Marcin Niestroj 4431ae5119 drivers: wifi: esp: support using DNS servers from ESP
ESP fetches DNS servers from local network by using DHCP. There is an AT
command to get those DNS addresses. Use that to provide DNS addresses
for Zephyr's DNS resolver.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-02-02 14:02:45 -05:00
Marcin Niestroj 3f1d1f5773 drivers: wifi: esp: suppress warning logs when socket was closed
Socket can be closed either by Zephyr or by peer. In the former case ESP
WiFi chip still notfies about closed socket, which currently results in
printing warning log:

  <wrn> wifi_esp: Link X already closed

Change level of this log from warning to debug, so that driver users are
not concerned about situation that is a normal behaviour.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-31 10:21:52 -05:00
Marcin Niestroj 2a6ddd2d3b drivers: wifi: esp: fix AT+CWMODE_CUR compatibility with ESP AT 1.7
There was a regression when implementing automatic AT+CWMODE{,_CUR}
handling based on driver needs. ESP AT 1.7 firmware does not support
AT+CWMODE_CUR=0, which means that radio needs to be either in STA, AP or
STA+AP mode (no NONE state available).

Fix ESP AT 1.7 compatibility by keeping radio in STA mode whenever it is
not used.

Move also first AT+CWMODE_CUR invocation before AT+CWDHCP_CUR, so that
the latter executes successfully with ESP AT 1.7.

Fixes: 03ce61004b ("drivers: wifi: esp: control CWMODE depending on
  current needs")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-28 17:23:06 -05:00
Nicolai Glud fc03bd2b86 drivers: wifi: winc1500: Updated driver capabilities.
Added ap_enable and ap_disable api. The driver will open create an
access point with DHCP Server ip 192.168.1.1 and no security.

Added a small fix for the AF_INET issue.

Added parent and remote to accept routine context.

Added put implementation.

Signed-off-by: Nicolai Glud <nicolai.glud@prevas.dk>
2021-01-26 17:43:45 -05:00
Marcin Niestroj 705eb1d2b0 drivers: wifi: esp: access socket type and ip_proto from net_context
net_context contains both net_sock_type and net_ip_protocol, which are
static during the lifetime of net_context. net_context has basically the
ownership of esp_socket, so we can be sure 'type' and 'ip_proto' are
always accessible through net_context API.

Remove 'type' and 'ip_proto' members from 'esp_socket' structure, as
those are already accessible by net_context API.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-26 14:47:46 -05:00
Marcin Niestroj cad292e17f drivers: wifi: esp: add thread-safety on esp_socket operations
Change type of esp_socket->flags from uint8_t to atomic_t, so that read
and write access to those flags is done in atomic (thread-safe) manner.

Introduce esp_socket_ref() and esp_socket_unref() functions, which
operate on atomic refcount variable. esp_socket_ref() role is to
increase refcount if it was already non-zero. If it was zero then NULL
is returned, which means that socket is not used by net_context at the
moment.

Role of refcount:
 * socket instance is assured to be between net_offload->get() and
   net_offload->put() when refcount > 0,
 * makes sure that socket instance can be used (its members can be
   dereferenced) when refcount > 0,
 * 'context' member is always valid and its members can be dereferenced
   when refcount > 0.

esp_socket_get() gets unused socket, as previously. Additionally it sets
refcount to 1 at the end of call, which basically means that from that
point such socket can be referenced by other parts of the driver. Each
esp_socket_get() call should be followed by esp_socket_unref() and
esp_socket_put() to properly invalidate socket and prevent other parts
of driver from using it.

Add ESP_SOCK_WORKQ_STOPPED flag, which is now used to prevent scheduling
more work into driver workqueue. This flag is set in net_offload->put()
callback, so that no more socket work (such as processing RX/TX packets
or closing socket because of errors) is submitted after that.

Introduce mutex lock, which has following role:
 * protects dst, connect_cb + conn_user_data, recv_cb + recv_user_data,
 * assures that checking ESP_SOCK_WORKQ_STOPPED flag and actually
   submitting (or not if net_offload->put was already called) new socket
   work to workqueue is done in atomic way.

As there is a mechanism to prevent submitting new work items to
workqueue when net_offload->put() has been executed, then there is no
need to explicitly call esp_socket_ref() in esp_workq thread. This is
because one reference is being held by net_context (after calling
net_context->get()). This is why all the esp_socket_in_use() were simply
dropped. Code running from esp_rx thread on the other hand always uses
esp_socket_ref_from_link_id() helper function (which is backed by
esp_socket_ref()), so that it replaces previous esp_socket_in_use()
calls and additionally makes sure that socket stays valid ("in use")
until esp_socket_unref() is called.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-26 14:47:46 -05:00
Marcin Niestroj 956923f8e5 drivers: wifi: esp: schedule each RX packet on separate work
So far a dedicated FIFO was used for all RX packets, which was consumed
in single submitted work. This work was also responsible for closing
socket and notifying uppper network layers if some errors occurred
previously or socket was simply closed by peer. There is however a
potential race condition in scenario described below:

  esp_rx thread             | esp_workq thread
  --------------------------|-----------------------------
                            | ---- esp_recv_work ----
                            | handle RX packets from FIFO
                            |
  ---- on_cmd_ipd ----      |
  put new RX packet to FIFO |
  ---- on_cmd_ipd ----      |
                            |
  ---- on_cmd_closed ----   |
  mark socket as closed     |
  ---- on_cmd_closed ----   |
                            |
                            | handle close
                            | ---- esp_recv_work ----

In this case we assume that esp_workq was preempted just after
processing all RX packets from FIFO and before checking if socket was
closed. In such scenario RX packet put to FIFO just before doing close
is going to be unhandled, so application layer will miss part of the
data.

Change the way RX packets are scheduled to workqueue, by using the
already available net_pkt->work objects (used for example in native TCP
stack). Create a separate work for closing connection. As a result all
RX packets and close handlers are on the same queue and there is no risk
of handling close events before handling all previously received data.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-22 12:02:10 +01:00
Marcin Niestroj dca2fd8042 drivers: wifi: esp: flush socket work items in socket put
There might be some scheduled work related to socket currently requested
to be destroyed/closed. Schedule a dummy work to make sure all
previously running work items in workqueue are finished.

When talking about TX packets, this makes sure that all previously
scheduled data is actually sent (flushed) before closing socket.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-22 12:02:10 +01:00
Marcin Niestroj 74e4f77fb4 drivers: wifi: esp: initialize per socket work structures only once
It is enough to initialize work structures once during driver init,
because work handlers do not change during driver lifetime.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-22 12:02:10 +01:00
Marcin Niestroj 7067373797 drivers: wifi: esp: always use net_pkt->work for sending
Currently there are two code paths when sending packets:
asynchronous (using workqueue) when zero timeout was specified and
synchronous in other cases. This doesn't seem to be justified, so
convert code to always schedule packet sending using workqueue.

Each net_pkt has an embedded work item, so use it instead of esp socket
specific work that was shared across all sent packets. This gives a
possibility to schedule multiple packets for sending.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-22 12:02:10 +01:00
Marcin Niestroj 90bb0847e4 drivers: wifi: esp: use context->send_cb and context->user_data
Callback and user data are saved in net_context structure. Those members
are used by native networking stack (net_if), so simply follow the same
pattern.

First of all this allows to reduce runtime information for driver socket
instance. Second and most important benefit is that it allows to move
send handling entirely to workqueue thread.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-22 12:02:10 +01:00
Marcin Niestroj a471e55da0 drivers: wifi: esp: always request MRU bytes with AT+CIPRECVDATA
ESP chip send number of available RX data using
+IPD=<sock>,<avail_bytes> command. This exact number (truncated to MRU)
was used to read data with AT+CIPRECVDATA=<sock>,<num_of_bytes>.

Use always MRU when sending AT+CIPRECVDATA=<sock>,<mru> request. When
there are less bytes available, then +CIPRECVDATA will just return less
bytes, which is fine for the driver.

There are two advantages to this new behavior:
 * there is no need to follow how many bytes were notified by +IPD
   message, thus reducing implementation size,
 * when data is constantly received by ESP chip, then the last number of
   bytes notified by +IPD is no longer up-to-date when sending a
   AT+CIPRECVDATA; always requesting MRU number of bytes allows to
   always receive maximum currently available number of bytes buffered
   by ESP chip.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-21 15:43:47 +02:00
Marcin Niestroj 831a5f0e55 drivers: wifi: esp: rely on +IPD after each +CIPRECVDATA
Dump of communication between ESP chip and Zephyr shows that
+IPD:<sock>,<bytes_avail> is always received after +CIPRECVDATA. This
means that we don't need to update sock->bytes_avail in esp_workq
thread. Additionally there is no need to schedule next AT+CIPRECVDATA
request, as that will be done by +IPD handler anyway.

Relying on +IPD to be received after each +CIPRECVDATA (as long as there
is some more data to be received) allows to simplify operations on
sock->bytes_avail. From now on only esp_rx thread will update its value
and schedule AT+CIPRECVDATA in esp_workq thread. Then in
sock->bytes_avail will be treated as "readonly" in esp_workq
thread. This allows to prevent race condition when both esp_rx and
esp_workq threads could potentially update value of sock->bytes_avail
value at the same time.

<sock>,CLOSED message is received always after retrieving all data from
ESP chip (using AT+CIPRECVDATA), so there is no need to check whether
there are more bytes to be received before marking socket as closed in
Zephyr driver.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-01-21 15:43:47 +02:00
Marcin Niestroj b2b8554da8 drivers: wifi: esp: deduplicate RX data processing
Deduplicate final part of RX data processing for two supported cases:
passive (+CIPRECVDATA) and non-passive (+IPD). Move implementation to
esp_socket module, as this is strictly related to socket.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 14:38:02 +02:00
Marcin Niestroj 1886d8c835 drivers: wifi: esp: rework +IPD handling
Split +IPD message handling into smaller logical functions, so it is
much easier to follow code and further improve it. Make sure to do as
much parsing work as possible, before accessing esp_socket object. This
will allow to introduce thread-safety locking just in the critical parts
in subsequent commits.

Prefer early return from function over goto to return instruction,
whenever cleanup code is not needed.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 14:38:02 +02:00
Marcin Niestroj d60bd57cb3 drivers: wifi: esp: rework +CIPRECVDATA handling
Current on_cmd_ciprecvdata handler is a bit overwhelming to follow.

Add a cmd_ciprecvdata_parse() helper, which is responsible only for
parsing received metadata (message offset and length), leaving socket
instance untouched.

Consume received payload later on, just after verifying that socket is
in valid state.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 14:38:02 +02:00
Marcin Niestroj caa35d1a3a drivers: wifi: esp: don't queue send after socket connect
After a synchronous (timeout > 0) connection attempt was made, it was
being checked if there is some packet to be sent. If positive, then a
send work was queued.

This behavior makes little sense, as TCP connection is not even
considered established at this point (from net_context perspective) if
function has not returned yet. Additionally it differs from
asynchronous (timeout == 0) connection attempt. In case of UDP (and
calling esp_connect() from esp_sendto()) sock->tx_pkt is assured to be
NULL. Drop this piece of code as it doesn't seem to be justified.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 11:42:51 +02:00
Marcin Niestroj 1814e2c8f1 drivers: wifi: esp: unify log level
2 (out of 3) components used CONFIG_WIFI_LOG_LEVEL, while the last one
didn't specify explicit log level. Always use CONFIG_WIFI_LOG_LEVEL in
all components.

While at it switch to LOG_MODULE_REGISTER(<module>, <log_level>), which
is a more compact way to define log level.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 11:42:32 +02:00
Marcin Niestroj add649adcd drivers: wifi: esp: calculate size of each command buffer
Calculate size based on the real message, instead of assuming some
arbitrary size. This consumes slightly less stack space, but more
importantly gives an idea what has been taken into account when
calculating the size.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 11:42:16 +02:00
Marcin Niestroj dd8aade16d drivers: wifi: esp: drop unused esp_socket members
No reason to occupy RAM if there is no use of stored information.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 11:41:56 +02:00
Marcin Niestroj bef25cd97d drivers: wifi: esp: support 32-bit length in +IPD
+IPD,<sock>,<bytes_avail> command in passive mode notifies about ESP
internal buffer usage level. Hence value of <bytes_avail> can exceed
4 digit value, which currently results in failure.

+IPD message is used in driver only for scheduling AT+CIPRECVDATA
command and actual value of <bytes_avail> doesn't really
matter. Increase maximum supported value that can be received from
9999 (maximum 4 digits) to 4294967295, which is maximum value of 32-bit
unsigned integer.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-17 11:41:26 +02:00
Marcin Niestroj 27b268f350 drivers: wifi: eswifi: set NET_CONTEXT_CONNECTED state
Set NET_CONTEXT_CONNECTED when stream socket got connected. This fixes
TCP connection when using eswifi WiFi 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>
2020-12-14 18:15:49 +02:00
Marcin Niestroj 65dd0f47ed drivers: wifi: winc1500: set NET_CONTEXT_CONNECTED state
Set NET_CONTEXT_CONNECTED when stream socket got connected. This fixes
TCP connection when using winc1500 WiFi 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>
2020-12-14 18:15:49 +02:00
Marcin Niestroj 9af6b9ed62 drivers: wifi: esp: set NET_CONTEXT_CONNECTED state
Set NET_CONTEXT_CONNECTED when stream socket got connected. This fixes
TCP connection when using ESP WiFi 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>
2020-12-14 18:15:49 +02:00
Marcin Niestroj 03ce61004b drivers: wifi: esp: control CWMODE depending on current needs
So far ESP chip was configured directly into STA mode. This works fine,
but consumes lots of power because of enabled WiFi radio, even when it
is not actively used.

Enter NONE mode during initialization, so WiFi radio will be
disabled. Switch between NONE, STA, AP and STA+AP modes depending on
what driver is currently doing (e.g. enable STA only when scanning,
connecting and being connected to AP).

AT+CWAUTOCONN=0 command fails when in NONE mode, so workaround that by
entering temporarily into STA and then switching back to NONE.

Add also a warning log when switching mode was not successful, to ease
debugging possible issues.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:16:36 -05:00
Marcin Niestroj 575fe89303 drivers: wifi: esp: improve readability of CWMODE changes
AT+CWMODE command controls in which mode (NONE, STA, AP, STA+AP) ESP
chip is operating. Add helper macros to replace usage of magic
numbers (0-3), hence improve readability. Add also a esp_mode_switch()
helper function, which allows to conveniently switch to chosen mode.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:16:36 -05:00
Marcin Niestroj 964775fafc drivers: wifi: esp: change internal API to work with multiple flags
Change internal API operating on ESP driver flags to support multiple
bitwise ORed flags at once. This allows to improve resulting code when
multiple flags are read or modified at once.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:16:36 -05:00
Marcin Niestroj 347c2501d7 drivers: wifi: esp: add esp_cmd_send() helper function
All except one invocations of modem_cmd_send() pass the same interface,
command handler and semaphore. Create a helper function in order to make
invocations slightly more readable.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:16:36 -05:00
Marcin Niestroj 135bbd5ae4 drivers: wifi: esp: stop locking scheduler when sending data
Locking scheduler was a workaround for issue that was just solved.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 11:15:19 -05:00
Marcin Niestroj aa07f8a442 drivers: wifi: winc1500: remove unused send_cb and send_user_data
Both 'cb' and 'user_data' parameters for send/sendto were saved as
'send_cb' and 'send_user_data' members in socket information. None of
them are actually used, so drop them.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-12-01 10:06:43 +02:00
Marcin Niestroj e0a418c1e3 drivers: wifi: esp: constify modem_cmd and setup_cmd structures
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 640 bytes of RAM and 64 bytes of ROM
when compiled on ARM.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-24 12:59:50 +02:00
Marcin Niestroj 980636dad3 drivers: wifi: esp: support hostname configuration
Configure hostname by issuing AT+CWHOSTNAME="<hostname>" command. Do it
just after setting link address, which is used to generate hostname
postfix when CONFIG_NET_HOSTNAME_UNIQUE=y.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-17 19:21:43 -05:00
Mohamed ElShahawi 9d1c47521f drivers: wifi: esp DHCP/Static IP Support
- Add ESP DHCP Support
- Add ESP Static IP Support including
 KConfig entries for configuring IP,Gateway and netMask

Signed-off-by: Mohamed ElShahawi <ExtremeGTX@hotmail.com>
2020-11-12 07:59:10 +02:00
Marcin Niestroj 2bab204ba3 drivers: wifi: esp: increase default RX net_pkt allocation timeout
So far there was 100ms timeout on allocation of RX net_pkt. This is too
little for cases when lots of data are incoming on pretty
fast (e.g. 1Mbps) UART interface and application layer does not consume
received network packets fast enough. Up to now in such cases all
incoming data was processed from UART and there was no data loss when
utilizing hardware flow control. However there was high chance that data
processed from UART could not be passed further to network stack,
because of the 100ms net_pkt allocation timeout. This happens for
example when low priority application does not have enough time to run.

Increase default RX net_pkt allocation timeout from 100ms to 5s, so
there is much more time to process network packets. Such timeout should
not harm, because only a dedicated RX thread will be suspended for that
time, resulting in suspending UART traffic if hardware flow control is
supported.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-04 09:02:04 +02:00
Marcin Niestroj 469053cc22 drivers: wifi: esp: allow to configure RX net_pkt allocation timeout
There is now a hardcoded 100ms timeout on allocating new net_pkt for
received data. Move that configuration to Kconfig, so that value can be
tuned according to application needs.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-04 09:02:04 +02:00
Mohamed ElShahawi d90da6fc9b drivers: wifi: rename WiFi kconfig prompt
use same naming convention for kconfig drivers entries

Signed-off-by: Mohamed ElShahawi <ExtremeGTX@hotmail.com>
2020-11-03 19:18:37 +02:00
Marcin Niestroj 8027612529 drivers: wifi: esp: close stream socket on allocation failure
There is no reason to keep active stream socket when there was some data
loss. Mark such socket for closing and close it when all (so far)
received packets have been processed.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-11-03 09:28:45 -06:00
Gerson Fernando Budke d8c9cb8d89 drivers: wifi: eswifi: Add uart bus interface
Add uart bus interface to extended esWIFI driver.  This enables all
Inventek modules with IWIN AT Commands firmware.

Signed-off-by: Gerson Fernando Budke <gerson.budke@atl-electronics.com>
2020-11-03 11:05:43 +01:00
Gerson Fernando Budke f479f60f84 drivers: wifi: eswifi: Drop WIFI_ESWIFI_NAME config
The WIFI_ESWIFI_NAME config would be uselful when there is no device
tree alternative.  The esWIFI driver already is on device tree and the
label property exists.  This remove WIFI_ESWIFI_NAME Kconfig variable
and switch to device tree equivalent.

Signed-off-by: Gerson Fernando Budke <gerson.budke@atl-electronics.com>
2020-11-03 11:05:43 +01:00
Gerson Fernando Budke 6bb879e72a drivers: wifi: eswifi: Drop global data visibility
Remove global access to structure eswifi_spi_data variable.  Instead,
add a method to pass access to that structure.  This allows better
control to the data bus variable.

Signed-off-by: Gerson Fernando Budke <gerson.budke@atl-electronics.com>
2020-11-03 11:05:43 +01:00
Marcin Niestroj b3272f3fe8 drivers: wifi: esp: allocate in modem_cmd_handler with K_NO_WAIT
All net_bufs allocated to modem_cmd_handler's data->rx_buf are consumed
synchronously in esp.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>
2020-10-27 09:32:51 -05:00
Marcin Niestroj 318cbe649a drivers: modem: cmd_handler: rework reading from interface
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>
2020-10-27 09:24:38 -05:00
Nicolai Glud 9ed7b6bd3c drivers: wifi: winc1500: removed semaphore on accept.
Listen func goes through a chain of calls to call winc1500_accept.
This is done to install the accept callback and should not block.
This fixes #28953 where winc1500 driver blocks on listen.

Signed-off-by: Nicolai Glud <nicolai.glud@prevas.dk>
2020-10-21 12:54:38 -05:00
Marcin Niestroj 668cbe19a3 drivers: wifi: esp: support power-gpios to enable ESP module
Add power-gpios device-tree binding property to power on module before
communicating with it. This pin is called CHIP_PU in case of ESP32{,-S2}
and CHIP_EN in case of ESP8266. Dedicated reset pin is available only on
the latter, however Espressif recommends (in ESP8266 Hardware Design
Guidelines) to use CHIP_EN instead. Follow those recommendations and use
power-gpios to reset chip if that is provided over device-tree.

Configure power-gpios and reset-gpios as inactive by default, so that
chip becomes ready after executing esp_reset() function, either if one
or both are provided over device-tree.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-20 07:32:01 -05:00
Marcin Niestroj 2e648d4872 drivers: wifi: esp: rename wifi-reset-gpios to reset-gpios
Most DT bindings use reset-gpios name when there is a pin to reset whole
chip. Rename wifi-reset-gpios to reset-gpios to be more consistent
between various drivers. Additionally this prevents confusion, as
somebody might think that this pin resets only WiFi, which is not true.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-10-20 07:32:01 -05:00
Marcin Niestroj f27de1f1bb drivers: wifi: esp: inform modem_context about HW flow control
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>
2020-10-05 17:04:52 +03:00
Marcin Niestroj 763bd27c75 modem: iface_uart: use ring_buf_{claim,finish} API
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>
2020-10-05 17:04:52 +03:00
Jan Pohanka 74dbcfebab drivers: wifi: fix simplelink driver to use zsock_ functions
This fix removes dependency on CONFIG_POSIX_API
or NET_SOCKETS_POSIX_NAMES.

Signed-off-by: Jan Pohanka <xhpohanka@gmail.com>
2020-10-01 17:35:45 +03:00
Marcin Niestroj c083548f80 drivers: wifi: esp: support reconfiguration of UART baudrate
Allow to reconfigure UART baudrate on ESP and on host MCU, so a
non-default baudrate can be used for communication. This option helps
for example to increase network bandwidth without touching ESP chip
firmware.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-09-30 17:05:22 +03:00
Marcin Niestroj f05fe8c082 drivers: wifi: esp: support configurable modem buffers size and count
Add Kconfig options to configure modem command handler buffer size and
count. This will allow to fine tune those based on UART baudrate, system
load and available memory.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-09-30 17:04:43 +03:00
Marcin Niestroj cfedf80009 drivers: wifi: esp: support configurable modem ring buffer size
Add new Kconfig option to configure modem UART interface handler ring
buffer size. This will allow to lower ring buffer to save some resources
or increase it in case high network bandwidth is utilized (with high
UART baudrate).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-09-30 17:04:43 +03:00
Vincent Wan 23b54832f8 drivers: wifi: simplelink: reimplement getaddrinfo
Reimplement getaddrinfo to call SlNetUtil_getAddrInfo from the TI HAL
for a more robust implementation that supports both client and server
modes, and performs better error-checking.

Fixes #11890

Signed-off-by: Vincent Wan <vwan@ti.com>
2020-09-11 15:29:03 +03:00
Abram Early c7cec489de drivers: winc1500: Fix signed/unsigned comparison
The value from socket() was directly assigned to offload_context, which
was treated as a unsigned integer when compared. This prevented the
following if statement from catching any errors, leading to random RAM
access. This is fixed by using an intermediate with the same type as the
return value, which is then assigned to offload_context after error
checking.

Signed-off-by: Abram Early <abram.early@gmail.com>
2020-09-08 18:06:30 -05:00
Carles Cufi c37e167b8c drivers: eswifi: Fix macro names for offloading
When offloading only ZSOCK_POLLIN and DNS_EAI_MEMORY are available, so
use those instead of the standard ones.

Fixes #28069.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-09-04 14:47:57 -04:00
Loic Poulain 4eba946e2b drivers: wifi: eswifi: Implement dns offload callbacks
Implement getaddrinfo and freeaddrinfo callbacks.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-09-04 09:51:09 +03:00
Loic Poulain 733af9a709 drivers: wifi: eswifi: Improve read work
Schedule read work every 100ms for better latency.
Reschedule read work directly in case of a packet is received
(fast dequeue).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-09-04 09:51:09 +03:00
Loic Poulain 6ea54db334 drivers: wifi: eswifi: fix socket poll
- Fix return value, must be number structures with events
- set revents flag

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-09-04 09:51:09 +03:00
Tomasz Bursztyka 7d8be66eba drivers: wifi: Fix device instance const qualifier loss in ESP
Passing the device's data was sufficient as only the data is being used
by the thread.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
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>
2020-09-02 13:48:13 +02:00
Loic Poulain 377f6c2a31 drivers: wifi: eswifi: rework read work
Remove non necessary eswifi lock/unlock in read procedure (eswifi
lock support nesting).

Return NULL packet in case socket is closed by remote (tested with
net shell and net recv).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-08-28 13:18:31 +03:00
Paul Sokolovsky 9ef03bb54c drivers: eswifi: Remove unused variable in ioctl routine
Variable "sd" is no longer referenced after refactoring in 2ed6b6a8ed.
It caused warning-as-error when building using sanitycheck, e.g. in CI.
This is 2nd fixed of the above refactor, after eb9a18432.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2020-08-19 14:35:10 +03:00
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
Parthiban Nallathambi 352e2a7ad4 drivers: wifi: eswifi: Coverity fix
Fix https://github.com/zephyrproject-rtos/zephyr/issues/27325
unchecked return value

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-08-14 18:50:17 -04: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
Loic Poulain ac45ad8830 drivers: wifi: eswifi: Fix unused variable in scan parsing
ret variable is not used.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-08-07 06:58:18 -05:00
Loic Poulain 5283a2be98 drivers: wifi: eswifi: fix dead code in ipv4 parsing
unsigned byte value is initialized to -1 and so never satisifies
the while condition, leading to broken ipv4 parsing (dead code).
Fix this by making byte value signed.

Reported by coverity #27326.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-08-07 06:58:18 -05: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
Loic Poulain 40e2d94bc8 drivers: wifi: eswifi: Fix parsing buffer-overflows
There are possible buffer overflows when parsing the ip address and
SSID. Ensure that we never overwrite the ip and SSID buffers.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-07-30 16:35:58 +03:00
Loic Poulain e7c4d29c86 drivers: wifi: eswifi: Add debug shell
Add a esWiFi shell for device specific controls.
For now used to send at commands.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-07-30 16:35:58 +03:00
Loic Poulain f851462f27 drivers: wifi: eswifi: Use log_strdup for strings
Use log_strdup() helper for logger string parameters.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-07-30 16:35:58 +03:00
Loic Poulain 0a1de7e96a drivers: wifi: eswifi: Stop client before starting
Stop any TCP/UDP client session before starting a new one.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2020-07-30 16:35:58 +03:00
David Leach f4caf7b890 drivers: wifi: eswifi: fix coverity Out-of-bounds access errors
There are multiple CID errors all based on the test of
'socket > ESWIFI_OFFLOAD_MAX_SOCKETS'. The test needs to
be '>=' in all cases.

Fixes: #27138
Fixes: #27139
Fixes: #27140
Fixes: #27141
Fixes: #27142
Fixes: #27143

Signed-off-by: David Leach <david.leach@nxp.com>
2020-07-28 07:03:55 -04:00
Vincent Wan 5014e7da44 drivers: wifi: resolve undefined macros when CONFIG_POSIX_API is set
When CONFIG_POSIX_API is set in lieu of CONFIG_NET_SOCKETS_POSIX_NAMES,
some macros such as POLLIN, POLLOUT and MSG_PEEK are undefined, and
the appropriate posix headers need to be included to access those.

Signed-off-by: Vincent Wan <vwan@ti.com>
2020-07-27 13:28:06 +02:00
Tobias Svehagen 7ea0c19c55 drivers: wifi: esp: Retry command for getting IP settings
If AT_CIPSTA? command fails it is retried again after 5 seconds.

Fixes #25741

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-07-24 12:01:30 +02:00
Parthiban Nallathambi d8e63e7161 drivers: wifi: eswifi: enable NET_SOCKETS_OFFLOAD by default
Enable NET_SOCKETS_OFFLOAD is default option for eswifi.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-07-24 11:13:31 +03:00
Parthiban Nallathambi 13808b7d83 drivers: wifi: eswifi: fix compilation warnings
Fix compilation warnings when CONFIG_NET_SOCKETS_OFFLOAD enabled

warning: passing argument 5 of '__eswifi_socket_new' makes pointer
 from integer without a cast [-Wint-conversion]
  395 |  idx = __eswifi_socket_new(eswifi, family, type, proto, 0x50CE);
      |                                                         ^~~~~~
      |                                                         |
      |                                                         int
eswifi.h:137:21: note: expected 'void *' but argument is of type 'int'
  137 |    int proto, void *context);
      |               ~~~~~~^~~~~~~
In function 'eswifi_socket_bind':
warning: comparison between pointer and integer
  461 |  if ((addrlen == NULL) || (addr == NULL) ||
      |

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-07-24 11:13:31 +03:00
Parthiban Nallathambi 0725719ada drivers: wifi: eswifi: Convert raw timeout values to use K_MSEC()
Use K_MSEC instead of raw timeout value.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-07-24 11:13:31 +03:00
Parthiban Nallathambi 1cb20aee34 driver: wifi: eswifi: use common log module
use common log module across all eswifi sources, which allows
to compile with CONFIG_NET_SOCKETS_OFFLOAD.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-07-24 11:13:31 +03:00
Tobias Svehagen 71e7cd3f99 drivers: wifi: esp: Fix issue with incorrect tx timeout
It can happen that the command '>' is received between
modem_cmd_send_nolock and modem_cmd_handler_update_cmds. Since the
command handler for '>' is not set, sem_tx_ready will not be given
and _sock_send will timeout. Make sure the command handlers are set
before the send by also passing them to modem_cmd_send_nolock.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-07-22 15:06:41 +03:00
Vincent Wan 53f408afe8 drivers: wifi: simplelink: enable IPv6 support
IPv6 support was not fully implemented in the driver and was disabled.
This commit completes the implementation and enables it when
configured.

Signed-off-by: Vincent Wan <vwan@ti.com>
2020-07-21 15:08:56 +02:00
Marcin Niestroj 967f485f38 drivers: wifi: simplelink: fix typo in logged option name
Fix typo in logged Kconfig option name that is missing in used
configuration. This one was mostly problematic for developers wanting to
find such option in source tree using grep - NET_SOCKET_OFFLOAD was not
found in Kconfig files.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-16 07:19:56 -05:00
Raja D.Singh bbabefb764 drivers: wifi: winc1500: Update to work with new timeouts
Change the driver to work without CONFIG_LEGACY_TIMEOUT_API option.

Signed-off-by: Raja D.Singh <rdsingh@iotwizards.com>
2020-07-08 15:38:43 -05:00
Marcin Niestroj 8ab0d153a2 drivers: wifi: esp: fix reset control logic and respect reset dts flags
wifi-reset-gpios flags were not respected so far. This means that
setting reset as active low (which is required in most cases for ESP
modules/chips) was done inside esp driver with inverted logic. Use dts
flags instead, so "active low" property is configured the same way as
for other drivers (i.e. in device-tree instead of driver).

This change also allows to configure reset as active high, in case where
ESP's nRST signal is somehow inverted on the board (behaving as RST
signal instead).

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-08 15:17:26 -05:00
Parthiban Nallathambi 3e62d73368 drivers: wifi: eswifi: Add chip select flags
Adds the chip select devicetree flags to the spi_cs_control instance.
ISM43362 chip select is ACTIVE_LOW.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-07-06 08:24:18 -05:00
Tobias Svehagen 822df6eef6 drivers: wifi: esp: Improvements to ESP driver
- Fix passive mode protocol selection depending on AT versions
- Use Kconfig value for reset timeout
- Fix bug with parsing security from scan result
- Re-order some AT commands during init due to some commands having
  dependency on other commands

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-07-02 08:52:28 -04:00
Tobias Svehagen edcee97346 drivers: wifi: esp: Fix bug with net_pkt_unref in tx path
The driver should only call net_pkt_unref on packets that get
successfully handled, ie where send/sendto return 0. If the packet
cannot be handled, net_context layer still owns the packet and should
take care or the unref.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-07-02 08:44:55 -04:00
Jordan Yates ab3e778f47 wifi: winc1500: Add chip select flags
Adds the chip select devicetree flags to the spi_cs_control instance.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-07-01 16:40:03 -05:00
Adam Porter 722a85aea2 drivers: wifi: remove dependency on NET_SOCKETS_POSIX_NAMES
This change removes references to raw POSIX types and functions,
allowing the drivers to build without NET_SOCKETS_POSIX_NAMES.

After this, the dependency between NET_SOCKETS_OFFLOAD and
NET_SOCKETS_POSIX_NAMES can be removed.

See issue #26033 for additional context

Signed-off-by: Adam Porter <porter.adam@gmail.com>
2020-06-15 16:59:36 +02: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
Bilal Wasim 64d5192f60 drivers: wifi: eswifi: Fully populate sockaddr_in on async msg
Updating the eswifi driver to provide port information (along with
IP / net context) whenever an async message is received. This is
needed to fully populate the "remote" info in "net_context"
required whenever net_context_send is called.

Also adding code to populate "remote" info in "net_context"..

Tested with STM32 disco IOT kit. Fixes #25621

Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
2020-05-26 21:40:23 +02:00
Gerson Fernando Budke 9a37154151 drivers: wifi: esp: Update to new timeout api
Update to new timeout api.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-05-12 17:18:34 +02:00
Xavier Chapron 2a8ff02ef2 drivers: Replace printf by printk when applicable
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-05-09 21:25:33 +02:00
Kumar Gala db725c0ec9 drivers: Replace GPIO_CS Kconfig with devicetree detection
Use DT_INST_SPI_DEV_HAS_CS_GPIOS() in drivers to determine if we should
utilize CS_GPIO base SPI chipselect handling.  This allows us to remove
Kconfig option for this feature.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-09 13:07:05 +02:00
Bilal Wasim 1966d48498 drivers: wifi: eswifi: WiFi Scan completion indication
Updating the eswifi driver to indicate "scan completion"
to WiFi Management once scanning is done.

Tested with STM32 disco IOT kit.

Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
2020-05-09 13:06:26 +02: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 c61faf6c55 drivers: wifi: Port the simplelink wifi to the new timeouts API
Port the code so it uses the new timeouts API.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-07 11:01:55 +02:00
Jukka Rissanen affe21c826 driver: wifi: eswifi: 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
Gerson Fernando Budke 351719ae0f drivers: wifi: esp: Add esp at version choice name
Add WIFI_ESP_AT_VERSION choice name to allows select version on
*.defconfig files.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-04-30 16:08:35 +03:00
Marcin Niestroj 91fe6534da drivers: wifi: esp: Fix wifi-reset-gpios handling
wifi-reset-gpios is currently ignored after conversion to DT_INST
macros. Use wifi_reset_gpios instead of reset_gpios to fix the problem.

Fixes: a464ae7163 ("drivers: wifi: esp: Convert to new DT_INST
  macros")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-04-06 10:29:58 -05:00
Tobias Svehagen ac53a8788e drivers: wifi: esp: Use UART settings from bus node
With the introduction of the new device-tree macros it is now possible
to use the settings for speed and flow-control from the bus node instead
of having the same properties on the esp node itself.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-04-06 09:12:58 -05: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
Tobias Svehagen 3b246fea6e drivers: wifi: esp: Fix DT_DRV_COMPAT to match binding
Change DT_DRV_COMPAT to espressif_esp to match the dts binding
"espressif,esp".

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-04-02 06:41:39 -05:00
Kumar Gala 7ea5f79ae2 drivers: wifi: winc1500: 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:15:43 -05:00
Kumar Gala 7264946c4a drivers: wifi: eswifi: 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-27 11:05:19 -05:00
Torsten Rasmussen d7862cf776 cmake: using ${ZEPHYR_BASE} instead of $ENV{ZEPHYR_BASE}
With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.

This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01: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 a464ae7163 drivers: wifi: esp: 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-27 04:51:58 -05:00
Tobias Svehagen 7b5f6bc660 drivers: wifi: Add ESP8266 and ESP32 wifi modem driver
This adds support for the Espressif ESP8266 and ESP32 devices to be used
as peripherals on a UART.

There are two main AT command versions that can be selected, 1.7 and
2.0. Since they behave a bit different it is important to select the
one that matches the used in the firmware on your device.

When downloading large amounts of data it is highly recommended to
enable CONFIG_ESP_PASSIVE_TCP and flow control on the UART so that
data is not lost due to UART speed or receive buffer size.

Currently unsupported:
- Changing UDP endpoint with a sendto()
- Bind to a specific local port
- Server socket operations, ie listen() and accept()

Official AT firmware for ESP8266 and ESP32 can be found at:
https://github.com/espressif/esp-at

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-03-21 19:08:02 +02:00
Carles Cufi 6574efa232 drivers: Add missing debug/stack.h include
In order to use log_stack_usage(), inclusion of <debug/stack.h> is
required.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Andrew Boie 2b38b3b33b drivers: winc1500: do not use net_analyze_stack
This API is unsafe. Use log_stack_usage() instead and
set the thread name.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Kumar Gala 46fe3046fe drivers: wifi: eswifi: Convert to use DT_INST defines
Use DT_INST define as this is the preferred set of defines to utilize
for drivers.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-11 07:59:38 -06:00
Peter Bigot ddc3f0699f gpio: replace gpio pin write/read with set/get
This API will be deprecated in favor of the new API that clearly
specifies whether it works on logical or physical levels.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Tomasz Bursztyka a40e9d3762 drivers/wifi: Switch WINC1500 to new GPIO API
Use new API to configure and interact with GPIOs.  Move GPIO
initialization from sample into driver.  The existing physical/line
level control has been kept rather than converting to logical level
signals.

Also improve error messages.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Erwan Gouriou e2721fee6f drivers/wifi: eswifi: Update to new GPIO API
Update to new GPIO API.
Tested on disco_l475_iot1


Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-05 12:00:36 +01:00
Robert Lubos aa17850455 drivers: wifi: eswifi: 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
Robert Lubos ece552c644 drivers: wifi: simplelink: Rework offloading mechanism
Switch to `NET_SOCKET_REGISTER` mechanism over the offloaded API
registration.

Including the following fixes from the review:

* The fd returned by the socket accept call needs to be finalized,
  similar to how it is done for socket creation.

* sl_RecvFrom() in TI SimpleLink Host driver does not support NULL
  pointers for 'from' address and address length, and sl_SendTo() does
  not ignore the destination address when in connection mode, so passing
  NULL would cause a failure. These issues have been reported to TI
  (CC3X20SDK-1970, CC3X20SDK-1971).

  Let's use sl_Recv and sl_Send to implement recvfrom/sendto in the case
  of NULL addresses.

* simplelink_poll() should not process negative file descriptors in the
  fds array after sl_Selecti() returns. A negative fd value indicates
  that the entry is invalid and should be ignored.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Peter Bigot 344c109f02 treewide: use full path to wifi/winc1500.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
NavinSankar Velliangiri e5328b8931 drivers: wifi: Fix the use of net_pkt_write() in eswifi driver
net_pkt_write() function returns 0 on success. But in this driver a
warning is thrown when zero is returned. Hence fix the driver to throw
the warning only when the negative value is returned.

Signed-off-by: NavinSankar Velliangiri <navin@linumiz.com>
2019-12-18 21:58:21 +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
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
Peter Bigot 6e5db350b2 coccinelle: standardize k_sleep calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Peter Bigot ab91eef23b coccinelle: standardize kernel API timeout arguments
Use the int_literal_to_timeout Coccinelle script to convert literal
integer arguments for kernel API timeout parameters to the standard
timeout value representations.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-03 11:55:44 -07:00
Saravanan Sekar 1aa696bc2b wifi: eswifi: Implement TCP/UDP socket offload with TLS
Newly implement socket based communication on eswifi mainly to
achive TLS. Tested with Inventek ISM43362-M3G-L44.

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2019-09-13 16:54:57 +03:00
Vincent Wan 7bcaf3696d drivers: wifi: simplelink: fixes to support CONFIG_NET_NATIVE=n
Remove unnecessary calls to net_if_ipv4_addr_add() and
net_if_ipv4_set_gw(), to prevent link errors when CONFIG_NET_NATIVE
is set to n.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-09-10 12:45:38 +03:00
Vincent Wan 0134a7de73 drivers: wifi: simplelink: fix 'log_strdup missing' error messages
Due to commit a211afb041, an error on
missing log_strdup() call is seen when running samples for CC32xx
devices that use the Wi-Fi driver. Adding log_strdup() calls to fix
this.

Fixes #18563

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-08-22 01:44:55 -05:00
Anas Nashif f156e95bbd ext: hal: make TI HAL a zephyr module
Move TI HAL to a module repository:
https://github.com/zephyrproject-rtos/hal_ti

managed by west.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-08-21 12:46:39 -05:00
Jukka Rissanen 5c05ef5101 net: Move include files outside of extern "C" block
This is related to findings in #17997 and changes network related
header files to have include files outside of extern "C" { } block.

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 14:46:36 +03:00
Saravanan Sekar 0fd92b463b wifi: eswifi: Select socket before configuration
Socket selection needs to be first in the order of operation

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2019-08-05 13:21:15 +02:00
Loic Poulain 8462f331f5 wifi: eswifi: Implement TCP listen/accept
Start es-wifi TCP server on accept.
An asynchronous (spi) message is received on client connection.
Only one connection is supported at a time.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-07-02 09:08:59 +03:00
Loic Poulain 033b267085 wifi: eswifi: Allow nested locking
In order to prevent potential deadlock in various callbacks such as
accept, recv, etc... Add support for nested eswifi locking, allowing
callee to safely access back to the eswifi methods.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-07-02 09:08:59 +03:00
Loic Poulain 50fa6bdd5e wifi: eswifi: Parse async messages
The eswifi controller can generate events via asynchronous messages
which can be polled via the 'MR\r' command. The messages will have a
Start Of Message Asynchronous [SOMA] and End Of Message Asynchronous
[EOMA] delimiters.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-07-02 09:08:59 +03: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 bd70f6f1ed cleanup: include/: move spi.h to drivers/spi.h
move spi.h to drivers/spi.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
Kumar Gala a614a026b7 dts: Rename DT_.*_GPIO_* to DT_.*_GPIOS_*
Convert DT_.*_GPIO_{CONTROLLER,PIN,FLAGS} ->
	DT_.*_GPIOS_{CONTROLLER,PIN,FLAGS)

Used the following commands to make these conversions:

git grep -l DT_.*_GPIO_CONTROLLER | xargs sed -i 's/DT_\(.*\)_GPIO_CONTROLLER/DT_\1_GPIOS_CONTROLLER/g'
git grep -l DT_.*_GPIO_PIN | xargs sed -i 's/DT_\(.*\)_GPIO_PIN/DT_\1_GPIOS_PIN/g'
git grep -l DT_.*_GPIO_FLAGS | xargs sed -i 's/DT_\(.*\)_GPIO_FLAGS/DT_\1_GPIOS_FLAGS/g'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-27 13:02:34 -05:00
Parthiban Nallathambi b7b9458ec6 wifi: eswifi: add UDP support
Add UDP support for eswifi driver. eswifi now can co-exist
with TCP and UDP functionality with 4 as max socket connection.

Tested UDP with custom DNS sample (wifi connect + DNS)

Signed-off-by: Parthiban Nallathambi <parthitce@gmail.com>
2019-06-26 23:20:22 +03: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
Parthiban Nallathambi d0d963a85d wifi: eswifi: init net_pkt cursor after net_pkt_write
Initialize the net_pkt cursor to begining after net_pkt_write.
Without which recv_cb can't peek/get net_pkt

Signed-off-by: Parthiban Nallathambi <parthitce@gmail.com>
2019-06-14 09:59:52 +03:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Vincent Wan 252ab55923 drivers: wifi: simplelink: Add static IP address support
Change the SimpleLink wifi driver to use static IP address instead of
DHCP when it is set by NET_CONFIG_MY_IPV4_ADDR. We also support setting
gateway and netmask via NET_CONFIG_MY_IPV4_GW and
NET_CONFIG_MY_IPV4_NETMASK.

This feature is tested out-of-tree against the echo sample after
modifying its prj.conf file to set the static IP address:

CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.191"

and after commenting out these lines in its board-specific config
file for cc3220sf_launchxl:

so that the NET_CONFIG_SETTINGS are not overridden.

The wifi sample is also verified to run correctly after running the
echo sample.

Fixes #14588

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-05-10 22:42:16 +03:00
David B. Kinder c5112327a7 doc: fix mentions of Wi-Fi trademark name
The approved trademark name is Wi-Fi so update references to WiFi and
other spellings to Wi-Fi in documentation and Kconfig help strings.
(Note that use of spelling variatios of "wifi" in module names, CONFIG
names, link names and such are untouched.)

https://www.wi-fi.org/

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-05-06 20:10:59 -04: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
Andrew Boie 4e5c093e66 kernel: demote K_THREAD_STACK_BUFFER() to private
This macro is slated for complete removal, as it's not possible
on arches with an MPU stack guard to know the true buffer bounds
without also knowing the runtime state of its associated thread.

As removing this completely would be invasive to where we are
in the 1.14 release, demote to a private kernel Z_ API instead.
The current way that the macro is being used internally will
not cause any undue harm, we just don't want any external code
depending on it.

The final work to remove this (and overhaul stack specification in
general) will take place in 1.15 in the context of #14269

Fixes: #14766

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-05 16:10:02 -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
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Kumar Gala c6662826b7 net/pkt: Fix a few left over cases of net_pkt_read_new
In the conversion of net_pkt_read_new to net_pkt_read, we missed
changing the function in the eth_smsc911x and eswifi_offload.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-20 15:26:30 -05:00
Vincent Wan a69955701d drivers: wifi: simplelink: Implement fcntl to set/get non-blocking mode
This commit implements fcntl() in the SimpleLink Wifi driver to set and
get the non-blocking mode on a socket.

Fixes #11891.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05: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 a25f054cbd net/pkt: Remove _new suffix to net_pkt_read 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
Vincent Wan 017446ba20 drivers: wifi: simplelink: Return success when TLS_PEER_VERIFY is set
mqtt_client_tls_connect() calls setsockopt() to set the TLS_PEER_VERIFY
option to require verfication. To enable mqtt, we need to return
success at a minimum when this option is set to 2.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-13 12:06:38 -05:00
Vincent Wan 7816827468 drivers: wifi: simplelink: Fix error handling
The driver is not returning correct error codes when error occurs.
The error handling function is expecting negative input values, but
that is not true for BSD error codes. So I am taking an approach
where I use a function to convert SimpleLink error codes to BSD
error codes, and call slcb_setErrno() to set the errno independently.

Fixes #12745

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-13 12:06:38 -05:00
Ulf Magnusson 3de2de89e0 kconfig: drivers: wifi: Remove redundant WIFI deps.
These symbols appear within an 'if WIFI' (in drivers/wifi/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:49:26 -05:00
Vincent Wan 2e15b0f611 drivers: wifi: simplelink: Use TI SimpleLink SDK 2.40
This commit updates the wifi driver to use the new TI SimpleLink SDK.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-05 11:37:10 -05:00
Vincent Wan 5c4a2193cd drivers: wifi: simplelink: Remove SO_REUSEADDR and TCP_NODELAY
The SimpleLink driver has been defining these macros for its local use.
Given these have been defined in a recent commit in Zephyr
(9c86dbfd8e), we should now avoid
redefining them to prevent build errors.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-02 12:21:21 -05:00
Tomasz Bursztyka 6fabbb7d14 drivers/wifi: Switch eswifi driver to new net_pkt API
Brings tiny simplifications.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-21 09:30:57 -05:00
Tomasz Bursztyka e8b0e1f35b drivers/wifi: Switch winc1500 driver to new net_pkt API
Use tx and rx pools relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-21 09:30:57 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Vincent Wan 581cfdb754 drivers: wifi: simplelink: Translate socket family/type/protocol values
In the SimpleLink wifi driver, the socket family value needs to be
converted to the SL_* equivalent to be understood by the SimpleLink
API, instead of being passed straight in.

While not strictly necessary, we are doing the same for socket type
and protocol values to future-proof ourselves in case similar changes
happen to the values defined for these in Zephyr header files.

Fixes #13203

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-02-13 06:48:40 -06: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
Vincent Wan 11b4b6f660 drivers: wifi: simplelink: Add handling for unknown root CA
Error code SL_ERROR_BSD_ESECUNKNOWNROOTCA is returned from sl_Connect()
when the root CA used is not part of the certificate catalog on the
network processor. We should warn the users about this and continue on,
given the connection is successful.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-01-31 06:36:08 -05:00
Vincent Wan f1619beab9 drivers: wifi: simplelink: socket() should return non-zero fds
simplelink_socket() is not returning non-zero socket file descriptors
when it succeeds. This leads to socket() to always return socket fd 0,
even when the network processor returns a non-zero fd.

This commit fixes simplelink_socket() to return the correct socket fd
when it succeeds in getting one from the network processor.

Fixes #12650

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-01-31 06:36:08 -05:00
Kumar Gala e0cd0c2b67 wifi: winc1500: Convert to new DT_<COMPAT>_<INSTANCE> defines
Convert winc1500 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-28 10:39:59 -06:00
Kumar Gala eaafdc85fc wifi: eswifi: Use generated SPI CS define
Move to using the generated DT_INVENTEK_ESWIFI_ESWIFI0_CS_GPIO_pin and
DT_INVENTEK_ESWIFI_ESWIFI0_CS_GPIO_CONTROLLER defines and drop the
DT_ESWIFI0_CS_GPIOS_PIN & DT_INVENTEK_ESWIFI_ESWIFI0_CS_GPIO_PIN from
dts_fixup.hl

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-23 18:12:24 -06:00
Loic Poulain 8a7b6ffaab wifi: eswifi: Add access point offload support
The eswifi controller is capable of acting as an Access Point.
Implement ap_enable/ap_disable methods.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Loic Poulain c893024184 drivers: wifi: eswifi: Fix mac address assignment
Use always valid mac pointer instead of a stacked local variable.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Loic Poulain 654d93999e wifi: eswifi: Add controller at command helpers
Create eswifi_at_cmd and eswifi_at_cmd_rsp helpers, allowing to send an
at command and parse the at response. These methods return success if
the response contains the OK* string. The eswifi_at_cmd_rsp method
extracts response content/size (DATA) on success.

*Response format is:
\r\n[DATA]\r\nOK\r\n>
Where DATA can be arbitrary (ASCII or not).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Robert Lubos 0b93c68f79 net: sockets: Add fcntl to socket offloading API
Offload fcntl calls through socket offloading API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Gil Pitney 7f956a9353 drivers: wifi: simplelink: add timeout for fast connect feature
The SimpleLink wifi driver enables the Fast Connect method of
WiFi provisioning, which allows the network coprocessor to
reconnect to a previously connected Access Point (AP) on
startup.

Previously, if Fast Connect failed to connect, any network
socket applications would inevitably fail, as there would have
been no wifi connection.

This patch adds a configurable timeout for the Fast Connect
feature, after which timeout, an error is logged informing
the user to manually reconnect to an AP.

Reconnection is typically accomplished by separately running the
wifi sample shell program.

Fixes: #11889

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2019-01-18 12:32:59 +02:00
Loic Poulain c9a9e0a4ee drivers: wifi: eswifi: Fix coverity issues
This patch fixes the following issues:
CID 190622 (#1 of 1): Out-of-bounds access (OVERRUN)
CID 190632 (#1 of 1): Out-of-bounds access (OVERRUN)
CID 190623 (#1 of 1): Unchecked return value (CHECKED_RETURN)
CID 190628 (#1 of 1): Out-of-bounds write (OVERRUN)
CID 190620 (#1 of 1): Dereference after null check (FORWARD_NULL)

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-08 08:01:20 -05:00
Vincent Wan 0f64ec5c31 drivers: wifi: simplelink: Fix strings used in assertions
Samples for cc3220sf_launchxl where assertions are enabled
(e.g. http_get) fail to build because some of the strings used in the
simplelink wifi driver have parentheses around them. This breaks the
current implementation of the __ASSERT macro. This commit removes
the parentheses, which are unnecessary.

http_get has been verified to build after this change.

Fixes #12192

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2018-12-26 09:42:29 -05:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 0f9312cde9 drivers/wifi: Remove usage of ll_reserve
It's not used anymore by the core IP.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Kumar Gala 0fbcf03ba9 drivers: wifi: eswifi: Remove unused code
uarthost isn't used anywhere, so lets remove it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-12-11 09:57:13 -06:00
Kumar Gala 0c12a7b050 drivers: wifi: eswifi: Fix build issue due to -fno-common
The introduction of -fno-common caused a link error in eswifi driver due
to lack of missing extern on eswifi_bus_ops_spi.  Adding the extern
resolves the link error.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-12-11 09:57:13 -06:00
Loic Poulain c67bb6d440 wifi: eswifi: Fix/clean TCP receive
This patch adds support for blocking tcp receive (with timeout).
This patch removes dedicated socket polling thread to use common
eswifi workqueue instead.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-12-05 08:56:24 -05:00
Loic Poulain 791343bb18 wifi: eswifi: Add support for non-blocking TCP connect/send
Current implementation unconditionnaly performs blocking connect
and send. Add support for non-blocking version using eswifi workqueue.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-12-05 08:56:24 -05: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
Gil Pitney c51cf1e463 drivers: wifi: simplelink: Implement setsockopt() for TLS offload
Implements setsockopt() for the socket offload driver
to process the TLS tags sent in via the Zephyr setsockopt() API,
when CONFIG_NET_SOCKETS_SOCKOPT_TLS is chosen.
For each tag, the credential filenames are retrieved and
set via SimpleLink's sl_SetSockOpt() API.

Also, creates a new KConfig option for TLS_CREDENTIAL_FILENAMES.
This new option is used by apps/protocols to add TLS credentials
via filenames referring to the actual content stored on a secure
file system or flash.

Handles the IPPROTO_TLS_* socket protocol families in the
socket() offloaded API.

This was validated on the cc3220sf_launchxl with the http_get sockets
sample, with the globalsign_r2.der file loaded to secure flash via
the TI Uniflash tool, and using the TI Catalog of known good
root CA's.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-11-23 09:16:21 -05:00