Commit graph

7023 commits

Author SHA1 Message Date
Robert Lubos ee8a85e38f net: openthread: Forward IEEE802154_HW_TX_RX_ACK capability
Translate and forward to OpenThread stack IEEE802154_HW_TX_RX_ACK
capability.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-09 16:56:11 +02:00
Kyle Sun a9b926414c net: lwm2m: Publicize firmware block context
This change is to allow access to the firmware block context in order to
give the firmware update callback implementation an indication of when
to reset the flash context. Additionally, it allows for a validity check
between the total expected size downloaded and the actual size
downloaded. A simple implementation can check if the block context's
current downloaded blocks is equal to the expected block size in order
to determine if the flash context needs to be reset. This approach
seemed the simplest, and knowing the firmware block context can have
other purposes. This has been tested by accessing the block context
during the update in the block received callback and confirming that the
callback had information regarding the current downloaded bytes.

Fixes #16122

Signed-off-by: Kyle Sun <yaomon18@yahoo.com>
2020-04-09 16:48:45 +02:00
Marek Porwisz ccd74755d5 net: openthread: Pass received frame to the proper thread.
Received frames shall be handled in the OpenThread thread, not in
the receiver thread.
Passed received frame to the function that will handle it in a proper
thread instead of calling otPlatRadioReceiveDone directly.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-04-09 16:19:20 +03:00
Marek Porwisz 8f2bcee35b net: lib: openthread: Create API for RX frame handling
OpenThread received frame handling shall be done in the OpenThread
thread.
Created API to pass net packets to the proper thread and handle them
there.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-04-09 16:19:20 +03:00
Jukka Rissanen 1ecac129c8 net: mqtt: websocket: Only accept data packets in RX
Check the message type and only accept MQTT binary data.

Fixes #24156

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:16:57 +03:00
Jukka Rissanen 3146b59204 shell: telnet: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 8cd1dcc69c net: buf: Remove timeout variable from debug print
The timeout value cannot be printed anymore after k_timeout_t
changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 66d394d97a net: getaddrinfo: Fix timeout data type
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 00a8406d7f net: ieee802154: Fix the scan duration data type
Converting to k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 053dcaa494 net: shell: Convert k_sleep() to k_msleep()
Needed because of k_timeout_t changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 3f9d734d15 net: conn_mgr: Fix time delay in K_THREAD_DEFINE()
The time parameter cannot be K_NO_DELAY because the time delay
parameter is ms so using value 0 instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 7d2c2691bb net: config: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen fb33da6f81 net: arp: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen b9cbf8a5ed net: pkt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 76d07ccd00 net: dhcpv4: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 406bdb1fc6 net: promisc: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 9e3778f89d net: ipv4: autoconf: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 38dd9bc299 net: mgmt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 08d532489c net: trickle: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen edb39cb40c net: tcp2: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 35dbe1c7d5 net: tcp: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 005ee2f768 net: ipv6: nbr: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 63a7b92fd8 net: if: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen e56fa75ade net: context: Refactor because of timeout overhaul
The net_context API will change, the s32_t timeout parameter
will be changed to k_timeout_t. All the Zephyr users of this API will
be changed in subsequent commits. This is internal Zephyr API only,
so the API is not deprecated etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen ab5aba4f8f net: ppp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 40f269f033 net: lldp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen f1d886ad29 net: gptp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 9f17c33b60 net: sockets: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 5cf75fe091 net: websocket: Refactor because of timeout overhaul
Mention in websocket API documentation that the timeout value
is in milliseconds. Check timeout values properly using K_TIMEOUT_EQ()
macro.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 1b04d44247 net: http: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.
Clarify the documentation of the timeout parameter that it is
in milliseconds.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 8a9153678a net: sntp: Refactor because of timeout overhaul
Use 64-bit time in order to avoid overlaps, and do not use K_MSEC()
as that will convert to k_timeout_t which we do not want in this
case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen a49741ff66 net: dns: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Andries Kruithof aafd563195 Bluetooth: controller: legacy: Correct DLE time calculations
This PR fixes #23482. The preamble size for a 2M phy was incorrect.

There is a bug in calculation of time for the DLE procedure:
the preamble size is incorrect for the 2M phy

Fixes #23482

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-04-09 14:55:20 +02:00
Lingao Meng ada840a308 Bluetooth: Mesh: Fix duplicated close callback
When PB-GATT Procedure timeout, func `bt_mesh_pb_gatt_close`
will also dumplicated with `link_closed()`

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-09 14:19:18 +03:00
Joakim Andersson b1611d0ace Bluetooth: host: Check return value of le_ext_adv_param_set
Check the return value of LE Set Extended Advertising Parameters
command when starting an advertiser from bt_le_adv_start with
CONFIG_BT_EXT_ADV enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:59:13 +03:00
Joakim Andersson 19434a1056 Bluetooth: host: Do not set adv random address before adv parameters
The LE Set Extended Advertising Set Random Address command may be
issued at any time after an advertising set identified by
the Advertising Handle parameter has been created using the
LE Set Extended Advertising Parameters command.

This commit fixes the advertising set issueing the set random address
command before the advertising set is created in the controller.
Since the le_adv_set_random_addr function has is used to get the the
own address parameter for the it could not simply be moved, and
moving the own address parameter handling out of this function
would create a potentioal maintaince problem.
Also this function is used for both with and without advertising
extension feature so changing it is not trivial without breaking all
the previous random address handling already put in place.
The simplest solution was therefore to postpone the command until the
parameters has been set using 2 flags.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:59:13 +03:00
Joakim Andersson d10d0f0b39 Bluetooth: host: Use bluetooth assert on HCI command send error
Use bluetooth assert on HCI command send error since this assertion is
always enabled and we should not continue after this has failed.
Log command status failure with information in order to make it more
visible as the HCI status code is more interesting than the -EIO error
code returned by the function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:58:32 +03:00
Joakim Andersson 9e8a30203f Bluetooth: log: Add BT_ASSERT_MSG that matches __ASSERT
Add BT_ASSERT_MSG assert mechanism that can print assertion messages
when verbose bluetooth asserts are enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-08 17:58:32 +03:00
Julien D'Ascenzio c413cca280 net: sntp: close socket when connect failed
The socket must be closed when the connection failed

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2020-04-08 12:49:53 +03:00
Lingao Meng 5b991aa09a Bluetooth: Mesh: Fix transport tx and rx
Fix seg_tx occupy when no segment not send
and allocate rx_seg when receive such message.

Fixes: #24101

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-08 11:36:11 +03:00
Kumar Gala 60541af791 Bluetooth: controller: specify entropy device explicitly
For the ll code we know the exact entropy device as its the one for the
SoC that we are on.  So use the new DT macro's to get the entropy device
via DT_INST rather than using CONFIG_ENTROPY_NAME.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-07 13:07:45 -05:00
Joakim Andersson fe8334c130 Bluetooth: host: Fix wrong latency and timeout values in conn update
Fix the pending slave set connection latency and timeout values not used
in the connection update procedure when
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS has not been enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-07 18:12:15 +03:00
Marcin Niestroj 29cb9271ed net: wifi: fix log message printing ssid and psk
The following logs show up when trying to connect:

  uart:~$ wifi connect xxxxxx xxxxxxxxxx
  Connection requested
  <dbg> net_wifi_mgmt.wifi_connect: (0x20000500): xxxxxx 6 255 1 \
                xxxxxxxxxx 10
  <err> log: argument 6 in source net_wifi_mgmt log message \
                "%s: (%p): %s %u %u %u %s %u" missinglog_strdup().
  <err> log: argument 2 in source net_wifi_mgmt log message \
                "%s: (%p): %s %u %u %u %s %u" missinglog_strdup().
  Connected
  uart:~$

Fix that by using LOG_HEXDUMP_DBG() to print SSID and PSK.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-04-07 15:00:55 +03:00
Marek Porwisz 19c8ff9f0a net: openthread: Tx started notification
OpenThread uses "tx started" notification to start ACK
timeout if the driver does not support it.
In order for this to be achieved tx task needs to run in parallel
to the OpenThread task, otherwise it may delay the gap between
cca and tx or run after transmission has already finished.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-04-07 14:24:10 +03:00
Peter A. Bigot 093fec62e7 usb: dfu: correct image names to match alt numbers
One would expect alt=0 to be named image-0 and alt=1 to be named
image-1.  Make it so.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-04-06 22:13:07 -04:00
Peter Bigot e2e74c0f53 shell: fix return after taking lock
Check for error conditions before locking a mutex.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 16.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot 55daa79ba3 net: context: fix return with held lock
An internal early return left a mutex locked.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 15.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot 7bdc235775 nvs: fix return with held lock
An internal early return left a mutex locked.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragments 13
and 14.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot abbd53ce1f net: lwm2m: correct return value in tlv put
The function calculates the number of octets put, but does not return
it.  Call sites check for non-zero values suggesting this is a bug.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 12.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot 4fb4d280d3 net: l2: ppp: validate pointer before dereferencing it
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 9.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot cbce6dde4c net: tcp: validate pointer before dereferencing it
See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 8.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot adb13b7d65 fs: shell: fix broken duplication of mount point path
Existing code wrote NUL to the end of the source string, rather than
the copy.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 5.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Peter Bigot 687826e83e net: lwm2m: json: fix potential buffer overflow
Use the size of the target buffer as the maximum length when
formatting with snprintf.

See https://habr.com/en/company/pvs-studio/blog/495284/ fragment 3.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-06 22:09:12 -04:00
Ruslan Mstoi bffd6576f9 net: tcp2: Fix handling single octet option at the EOL
This patch enables handling of a single octet of option-kind at the end
of the option list (EOL). Also, add functionality to drop a segment with
an invalid single octet option-kind at the EOL.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-06 15:13:21 +03:00
Carles Cufi 205cf1595e boards: nrf52810_pca10040: Rename to nrf52dk_nrf52810
The board target for emulation of nRF52810 on nRF5DK, so far
known as nrf52810_pca10040, is renamed to nrf52dk_nrf52810.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Carles Cufi 6656214af2 boards: nrf52_pca10040: Rename to nrf52dk_nrf52832
The board name for the nRF52 DK, so far known as nrf52_pca10040, is
renamed to nrf52dk_nrf52832.  Its documentation and all references
to its name in the tree are updated accordingly. Overlay and
configuration files specific to this board are also renamed, to
match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Jordan Yates a038dc76f1 bluetooth: host: Dynamic bt_conn_le_create timeout
Extends the bt_conn_le_create_param struct to provide the option
to set a custom timeout for the initiation of the connection.

The logic for the default values of window_coded and interval_coded
were moved to conn.c in order to resolve all defaults for the
create_param struct at a single location.

Timeout is not added as a parameter to the BT_CONN_LE_CREATE_PARAM
macro due to the expectation that CONFIG_BT_CREATE_CONN_TIMEOUT
will be the typical value that users will expect.

Fixes #23468

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-04-06 13:29:49 +03:00
Lingao Meng 3b4d58aa4b Bluetooth: Mesh: optimize performance for lpn node
Fixed overflow risk when `poll_timeout` is 1s,
although it is not recommended to use it like this,
when it is used like this, `POLL_TIMEOUT_MAX`
will overflow.

When the poll timeout set like above, the default `6`
req_attemps for first pull request lost,
may cause this procedure bigger than poll_timeout,

Well, stop scanning when lpn terminated friendship,
this will save lots of energy, when lpn mode enable,
the scanning will be start after `FRIEND_REQ_RETRY_TIMEOUT`

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-04-06 11:33:51 +03:00
Joakim Andersson 7ab754d997 Bluetooth: SMP: Fix bond lost on pairing failure.
Fix an an issue where established bonding information in the peripheral
are deleted when the central does not have the bond information.
This could be because the central has removed the bond information, or
this is in fact not the central but someone spoofing it's identity, or
an accidental RPA match.

This is a regression from: a3e89e84a8

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-05 14:32:56 +03:00
Joakim Andersson cd3a1f8ba3 logging: fix signed and unsigend comparison warnings
Fix instances of:
warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 18:06:59 -04:00
Joakim Andersson 7b2f9d929f bluetooth: fix signed and unsigend comparison warnings
Fix instances of:
warning: comparison between signed and unsigned integer expressions
[-Wsign-compare]

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 18:06:59 -04:00
Johan Hedberg 71eb56a34c net: buf: Move LEGACY_TIMEOUT_API selection to specific subsystems
The net_buf subsystem is now fully compatible with the new timeout
API, so move the selection of the legacy API to those specific
subsystems that use net_buf and still need converting.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-03 23:17:53 +03:00
Johan Hedberg 54ca1c118b net: buf: Convert net_buf to use k_timeout_t where appropriate
This patch updates the net_buf API to use k_timeout_t in essentially
all places where "s32_t timeout" was previously used. For the most
part the conversion is trivial, except for the places where
intermediate decrements of remaining timeout is needed. For this the
z_timeout_end_calc() API is used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-03 23:17:53 +03:00
Vinayak Kariappa Chettimada 4547bfb452 Bluetooth: controller: split: handle latency for cancelled conn events
Update implementation of master and slave LLL's to correctly
handle event counter values when latencies introduced due to
connection events cancelled by active events operating in
unreserved time space.

When an active radio event extends into unreserved time
space, and a connection event prepare is scheduled but at
the time of pre-emption timeout if the connection event is
cancelled then the event count and latencies needs to be
continiued to get acummulated.

In the current controller usecases the above scenarios does
not get exercised, the changes in this commit is needed for
future roles that can extend into unreserved time space and
would cancel a scheduled connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-03 22:10:40 +02:00
Joakim Andersson 93f644e1c0 Bluetooth: Use zd print conversion modifier for ssize_t
Use the zd print conversion modifier for ssizet_t variables.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Joakim Andersson 3baccee472 Bluetooth: tests: Add additional build configurations
Add additional build configurations to the shell to catch build errors
when enabling extended advertising.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Joakim Andersson a167e08910 Bluetooth: host: Fix compilation issue when privacy is disabled
Fix compilation issue when extended advertising is enabled but privacy
is disabled. In this case the rpa_update work is compiled out.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-03 21:13:14 +03:00
Ravi kumar Veeramally b9d8884c25 net: tcp2: tp: Simplify pkt creation in test protocol
Use existing network stack calls to create net pkt,
ip header and udp header creation. Also simplify
finalize api calls.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Ravi kumar Veeramally 69551b4681 net: tcp2: Simplify TCP pkt creation
Use existing network stack calls to create net pkt,
ip header and tcp header creation. Also simplify
finalize api calls.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Ravi kumar Veeramally a4d4485c0e net: context: Move asserts to proper place
net_context local sin/sin6 addresses are used only
when input src is not available. So ASSERT should
be inside if block.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-04-03 17:12:21 +03:00
Robert Lubos 108820aafb net: openthread: Add support for HW CSMA CA
Forward CSMA CA capability to OpenThread and use CSMA CA enabled
transfer if supported.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Robert Lubos 369109b4b2 net: ieee802154: Avoid ACK processing when not needed
In case hardware CSMA CA is used, ieee802154 L2 does not initialize ACK
processing structures, as it does not need to process ACK messages. As
it is not possible to conditionally disable ACK reporting to the upper
layer, ieee802154 could end up using uninitialized kernel primitive
(semaphore) in the ACK handler, which lead to a crash.

Avoid this, by explicitly checking in the ACK handler, if HW CSMA CA is
used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Robert Lubos 1fb418df4c net: ieee802154_radio: Allow to specify TX mode
Even though radio driver can report in its capabilities that it does
support CSMA CA, there's no way in the driver to select how the frame
should be transmitted (with CSMA or without). As layers above radio
driver (Thread, Zigbee) can expect that both TX modes are available, we
need to extend the API to allow either of these modes.

This commits extends the API `tx` function with an extra parameter,
`ieee802154_tx_mode`, which informs the driver how the packet should be
transmitted. Currently, the following modes are specified:
* direct (regular tx, no cca, just how it worked so far),
* CCA before transmission,
* CSMA CA before transmission,
* delayed TX,
* delayed TX with CCA

Assume that radios that reported CSMA CA capability transmit in CSMA CA
mode by default, all others will support direct mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Jukka Rissanen e1f06e26b2 net: tcp2: Check pointer before use in accept
The conn pointer NULL value was checked too late.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-02 23:03:37 -04:00
Jukka Rissanen ea1bed4744 logging: net: Avoid copying too much data
Use strncpy() in order to avoid copying extra data to hostname buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-02 15:54:36 -04: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
Joakim Andersson d751e09652 Bluetooth: host: Add parentesis around bitmask expression
Add parentesis around bitmask expression.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Joakim Andersson ecf3bcf747 canopen: Use ssize_t for the return value of read_cb
Use ssize_t for the return value of read_cb.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Joakim Andersson f8017adf5c Bluetooth: Use ssize_t for the return value of read_cb
Most places used an int so that should have handled most cases but
keys_set was using an unsigned int, which meant that checking len > 0
is an expression that is always false, and the error handling is not
working.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Joakim Andersson 21c37a6c6a Bluetooth: mesh: Remove redundant expression
Remove checking of the same argument twice.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-02 19:39:28 +03:00
Tomasz Konieczny 8214f26720 net: opentread: Implemented otPlatRadioGetRssi
Implemented blocking OpenThread otPlatRadioGetRssi api function using
no-blocking energy scan function from radio driver api interface.

Signed-off-by: Tomasz Konieczny <tomasz.konieczny@nordicsemi.no>
2020-04-02 18:20:57 +03:00
Johan Hedberg 329d5908a2 Bluetooth: Mesh: Fix dereferencing pointer before checking for NULL
The publication context is checked for NULL in bt_mesh_model_publish()
however it was dereferenced before that. Move the assignment to
ctx.send_rel to the same place where other ctx members are set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-02 17:44:50 +03:00
Tomasz Bursztyka e9bcf5e32b net/shell: Add PM suspend statistics print-out
Along with other statistics.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-04-02 11:07:45 +03:00
Tomasz Bursztyka 00926e3899 net/iface: Add PM suspend state statistics
Counting how many times it went suspended, for how long on the last one
and on overage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-04-02 11:07:45 +03:00
Ruslan Mstoi e5f714575e net: tcp2: Fix handling of the END TCP option
End option indicates the end of the option list. Hence, correct way to
handle it is to break out of the option parsing routine.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-01 20:58:40 +03:00
Johan Hedberg 0c4b87dc9f net: openthread: Fix timeout passed to k_sleep()
k_sleep() now takes a k_timeout_t so an integer value needs to be
wrapped through the appropriate macro, in this case K_SECONDS().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-01 20:03:15 +03:00
Robert Lubos 94490d3f19 net: openthread: Check if ed_scan API is implemented before use
Verify that `ed_scan` is implemented by the radio driver before use. In
case it's not, return appropriate error code to OpenThread.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-01 15:41:31 +03:00
Vinayak Kariappa Chettimada b7e35ae4a3 Bluetooth: controller: legacy: Fix slave latency during conn update
Fix regression in cancelling slave latency during Connection
Update Procedure.

Slave latency should not be applied between the ack of a
Connection Update Indication PDU and until the instant.
When caching was introduced, implementation missed this
consideration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:41:00 +02:00
Vinayak Kariappa Chettimada fd343ee3c8 Bluetooth: controller: nRF: Revert use of ticker compat mode as default
Ticker is now fixed to avoid catch up of periodic timeout under
large ISR latencies.

Revert commit a749e28d98 ("Bluetooth: controller: split:
nRF: Use ticker compat mode as default").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 7b89438f4b Bluetooth: controller: Consider must_expire while avoiding catchup
If must_expire is set for a ticker instance, then ticker
expiry shall still perform catchup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 6cb43749a4 Bluetooth: controller: Fix ticks_slot_previous calculation
Fix ticks_slot_previous calculation in the ticker_job when
tickers are skipped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada b263c2860e Bluetooth: controller: Fix ticker state on skipped
Reset ticker state in ticker_job for ticker instances that
have been skipped in the ticker_worker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 32352a1041 Bluetooth: controller: Remove lazy handling in ticker_worker
Removed lazy handling from ticker_worker as it is now taken
care in ticker_job.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada 7182c7062e Bluetooth: controller: Fix ticker catch up on ISR latency
Fix ticker to avoid catch up of periodic timeouts in case of
large ISR latencies like in case of flash erase scenarios.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:52 +02:00
Vinayak Kariappa Chettimada bc357718a7 Bluetooth: controller: split: Fix slave latency during conn update
Fix regression in cancelling slave latency during Connection
Update Procedure.

Slave latency should not be applied between the ack of a
Connection Update Indication PDU and until the instant.
When caching was introduced, implementation missed this
consideration.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:16 +02:00
Vinayak Kariappa Chettimada 79942b47cc Bluetooth: controller: legacy: Fix DLE duplicate requests
Fix implementation to handle back-to-back and duplicate
LENGTH_REQ PDU reception.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:00 +02:00
Vinayak Kariappa Chettimada 9bd4a786cd Bluetooth: controller: legacy: Simplify DLE state checks
Simplify the Data Length Update Procedure state check when
processing incoming LENGTH_REQ/RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:40:00 +02:00
Vinayak Kariappa Chettimada 45500f3dc9 Bluetooth: controller: split: Fix DLE duplicate requests
Fix implementation to handle back-to-back and duplicate
LENGTH_REQ PDU reception.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:31 +02:00
Vinayak Kariappa Chettimada d13c6b2b29 Bluetooth: controller: split: Simplify DLE state checks
Simplify the Data Length Update Procedure state check when
processing incoming LENGTH_REQ/RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:31 +02:00
Vinayak Kariappa Chettimada e217ade79e Bluetooth: controller: legacy: Validate chan map and hop value
Add validation of channel map and hop increment value
received in CONNECT_IND PDU.

Zero bit count leads to controller assert or divide-by-zero
fault.

Hop increment shall be between 5 and 16 by BT Specification.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:39:17 +02:00
Vinayak Kariappa Chettimada 4a5f263e5a Bluetooth: controller: split: Validate chan map and hop value
Add validation of channel map and hop increment value
received in CONNECT_IND PDU.

Zero bit count leads to controller assert or divide-by-zero
fault.

Hop increment shall be between 5 and 16 by BT Specification.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-04-01 14:38:27 +02:00
Emil Obalski 444c56d843 usb: cdc_acm: Omit notification about set interface.
This commit makes cdc class to omit notifications about
interfaces swap that may happen if cdc is configured together
with audio.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-04-01 11:37:14 +02:00
Ruslan Mstoi 4171220405 net: tcp2: Fix option name PAD to END
According to RFC 793 and IANA "TCP Option Kind Numbers" an option with
kind 0 is an End of Option List option and not a PAD.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2020-04-01 11:29:39 +03:00
Andy Ross 7832738ae9 kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument.  Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created.  This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.

The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.

The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.

Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.

For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided.  When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.

Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions.  These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig.  These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.

k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.

Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate.  Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure.  But k_poll() does not fail
spuriously, so the loop was removed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross 32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Kumar Gala 646f12383a disk: convert DT_NODE_HAS_PROP(..,label) to DT_HAS_NODE()
The check for label property is really checking to see if a device
exists and the better way to do that is to use DT_HAS_NODE().  Replace
refernces of DT_NODE_HAS_PROP(DT_INST(...), label) with
DT_HAS_NODE(DT_INST(...)).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-31 11:34:50 -05:00
Vincent Wan 4a8cfe02a3 power: policy: cc13x2_cc26x2: remove unnecessary sleep state conditions
Minor clean up to remove unnecessary references in the code to
CONFIG_HAS_SYS_POWER_STATE_SLEEP_1 and
CONFIG_HAS_SYS_POWER_STATE_SLEEP_2, as they are always defined for this
SoC.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-31 07:38:31 -05:00
Vincent Wan 8cf74c8e02 power: policy: cc13x2_cc26x2: guard references to sleep states
Use of macros such as SYS_POWER_STATE_SLEEP_2 needs to be guarded by
making sure CONFIG_SYS_POWER_SLEEP_STATES is defined.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-31 07:38:31 -05:00
Kumar Gala b2f13ccddf disk: 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-31 07:06:40 -05:00
Joakim Andersson 29749af88a Bluetooth: host: Fix high-duty cycle directed extended advertising
Fix high-duty cycle directed advertising when extended advertising
feature has been enabled. The duration parameter when starting extended
high duty cycle directed advertising has to be set to a non-zero value
less than or equal to 1.28 seconds.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:48:19 +03:00
Joakim Andersson 17276d558e Bluetooth: host: Replace alignment with tabs with spaces
Replace alignment with tabs with spaces.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Joakim Andersson 6d9e45a2ee Bluetooth: host: Avoid removing keys from controller that are not added
Avoid removing identity keys from the controller during the pairing
procedure. During the pairing procedure the keys will be cleared before
they are updated. This causes an unnecessary warning from HCI core where
it tries to remove an IRK key-set from the controller that has has not
been added yet.

While this is not an issue, the warning from HCI core is misleading and
might lead to unnecessary questions and investigations.
Warning appeared after: 6c6bd8c49e

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Joakim Andersson c8b3d2772a Bluetooth: host: Move pending keys pending flags out of key storage
Move the pending ID keys add and delete flag out of keys storage area.
These flags are runtime flags and should not be stored in persistent
storage.
Due to struct alignment storage start has to be aligned so that
variables added before storage start does not affect the storage bytes
by introducing padding in the storage area

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-31 12:26:15 +03:00
Lingao Meng 96c733c4d7 Bluetooth: Mesh: Fix restore when revoke keys
Store keys again after revokes keys

Signed-off-by: Lingao Meng <mengabc1086@gmail.com>
2020-03-31 12:25:12 +03:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Joakim Andersson a20066ed4f Bluetooth: shell: Add shell advertise set info get command
Add shell advertise set info get command to print advertiser set local
identity and TX power selected by the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 506bb7f005 Bluetooth: host: Add get advertising set info
Implement function to get advertising set information.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 0e3586c375 Bluetooth: host: Skip feature testing when legacy adv is disabled
Skip feature testing of controller features when legacy advertising
commands are not supported. For combined builds or builds where the
capability of the controller is known it is not required to have runtime
check of controller extended advertising support.

This gives the following size reduction for hci_core.c:

Without legacy support
hci_core.c  19980     7.75%
total      257679

With legacy support
hci_core.c  21816     8.41%
total      259519

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 06ce4de658 Bluetooth: host: Handle identity keys update for limited adv or scan
Handle updating the identity keys in the controller while a scanner
limited by timeout or advertiser limited by number of events or timeout
is active in the controller. For this case we mark they keys as pending
and handle the update of the resolving list ones the roles are stopped.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson fc04cb0553 Bluetooth: shell: Add shell option to set scan timeout parameter
Add shell option to set scan timeout parameter.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 8f8b163a93 Bluetooth: host: Refactor HCI remove from resolving list command
Move HCI remove device from resolving list command out to it's own
function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 84fefc776e Bluetooth: host: Add RPA handling for scan limited by timeout
Add RPA handling for scan limited by timeout. The scan limited by
timeout has no information about elapsed time when stopped. So pausing
the scan at RPA timeout has no new scan timeout value to set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d4c17e5648 Bluetooth: host: Handle anonymous advertiser
Add handling of anonymous advertise address type.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson b9acef930b Bluetooth: shell: Add shell command for advertising OOB information
Add shell command to retrieve advertising set OOB information for the
selected advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson ed11ca1744 Bluetooth: host: Add error code to directed advertiser
Add error code to API for starting directed advertiser. Also rename the
API in order to follow the established naming pattern.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson fe597c07bf Bluetooth: shell: Use the new advertising callbacks
Add advertising sent connected and scanned callback and print the
information available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 7c92ffdcb3 Bluetooth: shell: Add shell commands for advertising sets
Add shell commands to create advertising sets, add advertising data,
start advertising, stop advertising, and delete advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 9ee31a4106 Bluetooth: shell: Add shell arguments to control scanning phys
Add shell arguments to control scanning phys for scanner and initiator.
This allows to scan on coded or create connections on coded.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 8859ddab92 Bluetooth: shell: Use the new scan callbacks to print extended info
Add scan recv callback and print extended scan information available.
Add scan timeout callback to print when scanner has stopped.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 11970b89f9 Bluetooth: shell: Print error code in hex
Print the error codes in hex so that it is easier to lookup, error
codes are usually given as hex.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson bcad8cf1c6 Bluetooth: host: Add support for single advertising set
Add support for creating and advertising with an advertising set.
This has support to advertise with extended data and with long range
feature on Coded PHY.
Limited to only supported one advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 06ee3d8e62 Bluetooth: host: Add support for extended conn create options
Add support to use the extended conn create options to establish
connections on LE Coded PHY or 2M. This uses the connection options
set by bt_conn_set_scan_params.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson f24cc91a6b Bluetooth: host: Add API to set initiator scan parameters
Add API to set the scan parameters used in the LE Create Connection
HCI command used by bt_conn_create_le and bt_conn_create_aute_le.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 38b1d58b62 Bluetooth: host: Add scanner options for extendend scanning
Add support for the new scan options and use the LE Extended Scan
HCI commands if they are available in the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d29ab4a7df Bluetooth: host: Refactor scan and initiator random address handling
Refactor scan and initiator random address handling to a helper function
so that it can be re-used.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 869bea659a Bluetooth: host: Add reference count old and new value in debug print
Add reference count old to new value transition in the debug print, this
makes it easier to interpret the printed line when debuggin reference
count bugs.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 3c603b225b Bluetooth: host: Refactor get advertiser filter policy
Extract setting advertising filter policy parameter from the adv params
options field to a helper function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 88a6234ff2 Bluetooth: host: Use bluetooth defines instead of hci defines
Use the scan types defined in bluetooth.h instead of the hci defined
ones. Although they have the same value it is best to avoid using the
hci.h header in applications.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson d9d0964fcc Bluetooth: Kconfig: Update buffer sizes for advertising extension
Update buffer sizes needed when advertising extensions is enabled. Since
BT_RX_BUF_LEN is used for the HCI command as well we need to fit the
full 255 bytes of the Set Extended Advertising Data or Scan Response
Data plus the 3 byte header of an HCI command.

For the discardable buffer size we need to fit the LE Extended
Advertising Report event, which can be a maximum of 255 bytes plus the
2 byte header of an HCI event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 886badc69e Bluetooth: Kconfig: Add kconfig options for extended advertising
Add Kconfig options to enable extendend advertising and scanning
support.
Include option to support both types of advertising
commands in case the controller capabilities is not know or the
controller is pluggable.
Include option to only support legacy advertising API, this is to
support the use-case of advertising using different identity than the
scanner or initiator.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson f2d7b77e96 Bluetooth: host: Deprecate BT_LE_ADV defines in hci.h in favour of gap.h
Deprecate BT_LE_ADV defines in hci.h that are expected to be used by the
application in the scan received callback to identify the advertising
PDU type. These defines are mixing HCI input parameters and advertising
PDU types. Internally it is acceptable to mix these, but at the API we
should to mix in them.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson be57dfbe2a Bluetooth: host: Rename and deprecate scan filter for more scan options
Rename filter_dup parameters used for scanning filter options to the
more generic name options, and make scan filter options follow same
naming patters as advertising and initiator scan options.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Joakim Andersson 405ce842ab Bluetooth: host: Add new argument and return code to bt_create_conn_le
Deprecate bt_create_conn_le and rename it to in order to add return
code, new arguments and to follow the established naming convention.

Add API for the application to control the scan parameters of the
initiator role. This allows the application more scheduling control
of the initiator in multi-role scenarios. Also provides options to
configure the initiator for LE Coded PHY for long range support.
We deprecate the old way of creating connection to make the name more
consistent with the rest of the API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-30 00:38:23 +03:00
Robert Lubos b173c177db net: mqtt: Improve PUBLISH message length validation
Identify when received PUBLISH message is malformed and overall packet
length received is smaller than parsed variable header lenght.
Add unit test to cover this case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-28 09:36:12 +02:00
Robert Lubos 6110a7cb63 net: mqtt: Improve buffer bounds validation in mqtt_read_message_chunk
Verify more strictly that data read from the transport fits into RX
buffer. Switch to unsigned integers, where possible, to prevent
unnecessary signed/unsigned operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-28 09:36:12 +02:00
Robert Lubos 1ad165a62d net: mqtt: Fix packet length decryption
The standard allows up to 4 bytes of packet length data, while current
implementation parsed up to 5 bytes.

Add additional unit test, which verifies that error is reported in case
of invalid packet length.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-28 09:36:12 +02:00
Kumar Gala 3a59f87ba9 bluetooth: 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 16:53:21 -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 839bacc0f0 power management: Add k6x SOC core list
Just inserting mcux's ethernet device there.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka cb0da79e7f net/shell: Add a quick way to suspend/resume a network interface
Meaningful for testing purpose only.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 4322c66e4b net: Expose a way to know if the network interface is suspended or not
And use it in the shell to display such information then.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 80917ec16f net: Add preliminaly support for suspending/resuming a net interface
Such state needs to be set _from_ the PM API functions and not the other
way round. So if a network device driver does not support such API, it
will not be able to set the core net_if on PM state, obviously.

Currently, these functions only set/unset NET_IF_SUSPENDED flag.

More logic will be added later, to decide whether the net_if can be
actually set to suspend mode or not and also to take care of all timers
related to the interface.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Jukka Rissanen dee07c9e0a net: if: Add function to check any pending TX packets
This function can be used for example by network power management
to check if the network interface can be suspended or not.
If there are network packets in transmit queue, then the network
interface cannot be suspended yet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-27 14:48:30 +02:00
Jukka Rissanen 15dfa28c2e net: tc: Return information whether TX pkt was queued
We need to know whether the net_pkt was successfully placed
to transmit queue. It is possible in TX side, that the net_pkt
is already in TX queue when for example TCP packet is
re-transmitted, in which case the queue submit will fail.
This cannot happen in RX side as there are no timers involved.

It is required to check about such pending flag before trying to submit
it into the queue. Indeed, the work queue could be scheduled right after
such queuing, thus checking for the pending flag afterwards would
provide a false information.

It is unfortunate k_work_submit_to_queue() does not return anything as
it would simplify the code then.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02: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
Vinayak Kariappa Chettimada d7cc4bd2c5 Bluetooth: controller: ticker minor code optimization
Minor optimization to use a local variable instead of a
deferencing of a struct member.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-27 11:37:36 +01:00
Andrzej Głąbek 4253eae005 boards: nrf52840_pca10056: Rename board to nrf52840dk_nrf52840
The nRF52840 DK board target, so far known as nrf52840_pca10056,
is renamed to nrf52840dk_nrf52840.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-03-27 09:14:08 +01:00
Tomasz Bursztyka f090e2563a shell: Fix device service module
There is a new init level SMP that was just added, and this module needs
to take it into account.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-26 14:52:47 -04:00
Robert Lubos 832d752794 net: openthread: Add promiscuous mode support
Implement OT radio API to enable/disable promiscuous mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-26 17:42:40 +02:00
Johan Carlsson 552508506f usb: filter out synchronization type for isochronous endpoints
Fix so that different isochronous synchronization modes can be used.
It filters out the synchronization mode before sending the endpoint
type to drivers.

Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
2020-03-26 14:09:55 +01:00
Vinayak Kariappa Chettimada b77b099bf9 Bluetooth: controller: Fix ticker ticks_current value
Update the ticks_current value on last stopped ticker
instance, so that when a new ticker instance is started
the anchor ticks calculation uses the correct current tick
with respect to supplied anchor ticks.

Fixes #23805.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-26 12:46:04 +01:00
Stephanos Ioannidis a033683783 arch: arm: aarch32: Rename cortex_r to cortex_a_r
This commit renames the `cortex_r` directory under the AArch32 to
`cortex_a_r`, in preparation for the AArch32 Cortex-A support.

The rationale for this renaming is that the Cortex-A and Cortex-R share
the same base design and the difference between them, other than the
MPU vs. MMU, is minimal.

Since most of the architecture port code and configurations will be
shared between the Cortex-A and Cortex-R architectures, it is
advantageous to have them together in the same directory.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-26 11:20:36 +01:00
Vincent Wan 61625366c9 power: policy: only bring devices to low-power when in sleep mode 2
Sleep mode 1 is supposed to be a low-latency sleep mode where devices
are left in active mode. Thus we should only bring devices to low-power
when in sleep mode 2 in sys_pm_policy_low_power_devices().

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-25 16:21:33 -04:00
Vincent Wan 41cc9b2c2a power: device: add core device list for cc13xx/cc26xx
Update the core device list to support device power management.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-25 16:21:33 -04:00
Robert Lubos bd8410cf3c net: openthread: Fix builds with NCP option disabled
In case OPENTHREAD_NCP option is disabled, uart.c platform driver should
not be compiled as it misses dependencies.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-25 12:16:32 +02:00
Markus Becker 0651141d84 net: openthread: Add NCP start-up and required platform changes
When NCP starts-up some of the initialisation functions of a regular
OpenThread device do not need to be called, because they get triggered
by wpantund via UART. Instead NCP initialisation needs to be called.

A small typo has been fixed as well.

Also initialisation for raw link packet interface has been added. Can be
used for picking up 802.15.4 frames and interpreting them in the
application.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-25 08:37:16 +02:00
Markus Becker 71ce94e0ed net: openthread: Add UART platform backend for NCP
Currently based on CDC-ACM. Can possibly be used with plain UART as
well.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-25 08:37:16 +02:00
Markus Becker 653a15d138 net: openthread: Remove log_strdup warnings for OpenThread
Log messages from the OpenThread logging system were not log_strdup()

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-25 08:37:16 +02:00
Christian Taedcke a401aefa0a net: ppp: Implement missing ppp mgmt functions
The functions ppp_mgmt_raise_carrier_on/off_event() were not
implemented, but already documeted in the header net/ppp.h

Fixes #23420

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2020-03-24 14:29:49 -05:00
Dominik Ermel 1f3c9a22a0 subsys/mgmt: Fix mcumgr file download
The commit reduces default MCUMGR buffer size and introduces changes to
mcumgr that fix problem with mcumgr not being able to download file off
the Zephyr running device.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-03-24 15:17:00 +01:00
Vinayak Kariappa Chettimada 915c510a0a Bluetooth: controller: split: Remove use of k_cpu_idle
Remove use of k_cpu_idle in controller, and refactor the
implementation used to start, wait and stop clocks needed
by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-24 13:38:59 +01:00
Ioannis Glaropoulos f3807f19dc boards: arm: nrf51_pca10028: rename board to nrf51dk_nrf51422
We rename the nRF51 Dev Kit board target (nrf51_pca10028)
to nrf51dk_nrf51422. We update all associated references
in the supportive documentation and all nRF51-related
cofigurations and overlay files in the samples and tests
in the tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-24 11:45:27 +01:00
Joakim Andersson 6c6bd8c49e Bluetooth: host: Fix directed advertising from privacy-disabled peer
Fix directed advertising from privacy disabled peer. In this case we
need to have the local IRK in the controllers resolving list in order to
have the controller resolve the initiator address of the directed
advertising pdu (ADV_DIR_IND).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-23 12:44:44 +02:00
Joakim Andersson 9ec6fb87c9 Bluetooth: host: Fix directed advertiser for multiple local identities
Fix directed advertiser using the wrong local IRK when doing directed
advertising when the identity of the advertiser is not the default
identity.
This is only an issue for the directed advertiser because it is only
for the directed advertiser that we use the controllers local IRK
to generate the Advertisers RPA.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-23 12:44:44 +02:00
Joakim Andersson e4538c6807 Bluetooth: HCI: Re-organize vendor read static address handling
Add header definition for bt_read_static_addr function. Declaring it
without a header definition will not give any compilation error when
function definition changes.
Refactor nRF SoC specific code into nRF specific source files and
provide weak definitions when these are not implemented. This will make
it easier to add handlers per vendor.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-22 11:58:17 +02:00
Carles Cufi 1c79096559 ext: debug: Move ctf_map.h to subsys/tracing/ctf
To complete the removal of the ext/ folder, move the ctf_map.h file to
where it really belongs, which is subsys/tracing/ctf.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-20 22:56:19 -04:00
Joakim Andersson ffa10eba83 Bluetooth: host: Include scan response with name when non-connectable
When using BT_LE_ADV_NCONN_NAME then the advertising name will not be
included in the advertising data. This is because the host always puts
the device name in the scan response. But since the scan data was
otherwise empty the advertising type was set to ADV_NONCONN_IND.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-20 14:06:42 +02:00
Trond Einar Snekvik 09333caf52 Bluetooth: Mesh: Split out provisioning bearers
Splits PB-ADV and PB-GATT into separate modules with a common interface
to modularize prov.c.

Additional trivial fixes from testing:

- Reduces warnings for normal occurances like repeated packets.
- Makes link ack a non-reliable packet to prevent it from being repeated
  until prov invite.
- Provisioner does not send link fail, but closes the link (as per spec
  section 5.4.4). This prevents lingering zombie links on both sides.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-20 12:45:53 +02:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Trond Einar Snekvik 824c2ebc58 Bluetooth: Mesh: Slab based segmentation handling
Allocates segmented message buffers as slabs in a common pool for RX and
TX. This reduces memory requirements for both TX and RX, as TX messages
can be stored without the network and advertising buffer overhead, and
RX can use only the slabs it needs, instead of allocating a full size
segmented message. This approach also removes the need for decrypting
the segments for each retransmission, reducing overall processing load.

Slab based segmentation for tx also introduces queuing of segmented
messages, which allows the application layer to send multiple messages
to the same destination without violating Bluetooth Mesh specification
v1.0.1, section 3.6.4.1. This mechanism is provided through a flag that
blocks segmented messages to a destination which a message is already
being sent to until the previous message finishes.

This changes the SDU size configuration to a symmetrical
RX_SEG_MAX/TX_SEG_MAX pair of configurations, plus a new segment pool
side configuration. It also removes the binding between the TX_SEG_MAX
config and the advertising buffers, reducing the minimum advertising
buffer count from 6 to 3.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-19 15:54:26 +02:00
Trond Einar Snekvik ca2f5c3f91 Bluetooth: Mesh: Friend SeqAuth cleanup
The Friend queue uses the message SeqAuth to determine whether the
message is already in the queue. To facilitate this, the SeqAuth is
passed around as a pointer throughout the transport modules. In the
bt_mesh_ctl_send functions, this parameter is also exposed in the API,
but the internal usage is inconsistent and buggy. Also, no one actually
uses this parameter.

- Removes seq_auth param from bt_mesh_ctl_send, instead passing NULL
  directly to the friend module, to enforce its addition to the queue.
- Makes the seq_auth pointer const throughout the friend module.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-19 15:54:26 +02:00
Andries Kruithof 30e3205e32 Bluetooth: controller: split: correct timing calculation in PKT_US
A bug in the PKT_US resulted in wrong calculations for the 2M phy.
Fixes the bug, verified on EBQ.
Also adds some defines for improved readability.

Fixes #23482

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-03-18 16:09:33 +01:00
Vinayak Kariappa Chettimada b7220cef86 Bluetooth: controller: split: Fix densely scheduled event preemption
Fix LLL implementation handling preemption of currently
active radio event with densely scheduled events in the
pipeline.

Preempt timeout was stopped without consideration to there
being more queued events in the pipeline. Also, added
chaining of preemption timeouts one after the other expiry
so as to preempt currently active events by the densely
scheduled events in the pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:45:43 +01:00
Vinayak Kariappa Chettimada 5474dbb544 Bluetooth: controller: split: Fix regression in handling invalid pkt seq
Fix regression in handling invalid packet sequence in the
first packet in a connection.

This relates to commit 62c1e1a52b ("Bluetooth: controller:
split: Fix assert on invalid packet sequence")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:44:47 +01:00
Vinayak Kariappa Chettimada 6a37dc5a68 Bluetooth: controller: legacy: Fix regression handling tx pool corruption
Fix regression in handling tx pool corruption in relation to
commit 7a3e29af06 ("Bluetooth: controller: legacy: Fix Tx
pool corruption").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-18 10:44:21 +01:00
Flavio Ceolin 6fec8ea84e net: ieee802154: Fix possible null pointer de-reference
ieee802154_scan() checks if ctx->scan_ctx (scan) is NULL what implies
that this can be true, but de-reference this variable before this
check what may cause a problem.

Fixes #23299 [3]

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-03-17 17:03:19 -05:00
Flavio Ceolin 841b6ab990 fb: Fix possible NULL pointer de-reference
ftpr assignment is being done before checking fb->fonts pointer.
Just changing assignment position.

Fixes 23299 [1]

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-03-17 17:03:19 -05:00
Jukka Rissanen 077b52c6f8 net: lib: config: Timeout when network interface is down
If the network interface is down, we should timeout properly
and let the application to handle the situation.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 17:17:20 +02:00
Johann Fischer 08222c2e64 usb: mass_storage: fix API usage by using memmove
Fix API usage error introduced by the commit c88155fd2d
("usb: mass_storage: fix possible page buffer overflow")'

Fixes: #23295
CID: 208676

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-17 10:18:42 -04:00
Wolfgang Puffitsch f3de1f5b38 Bluetooth: controller: split: Fix response to unexpected LL_FEATURE_RSP
Fix response to unexpected LL_FEATURE_RSP for the case that
BT_CTLR_SLAVE_FEAT_REQ is disabled. Fixes LL/PAC/SLA/BV-01 for such a
configuration.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2020-03-17 12:37:03 +01:00
Jukka Rissanen 907dede475 net: iface: Make sure we access valid ll address
It is possible that net_pkt will disappear while we are sending
it, so save link address if we need that information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 9325109cbc net: pkt: Print size of the failed net_buf allocation
This information is useful when debugging things.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 0a47dc5918 net: sockets: Release net_pkt if error during UDP recv()
If we are receiving UDP packet and if there is some error happening
inside zsock_recv_dgram(), then make sure that the net_pkt received
from recv_q is freed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 65d8429d29 net: pkt: Print caller and line when allocation fails
It is useful to know who called the net_pkt allocator when
we run out of buffers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen aee31bb7c1 net: tcp: Print information when proper ACK is received
It is useful to know that we received ACK when debugging the
TCP code.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Jukka Rissanen 8fd677e9e1 net: tcp: Fix memory leak when lot of incoming packets
The code was leaking memory in TX side when there was lot of
incoming packets. The reason was that the net_pkt_sent() flag
was manipulated in two threads which caused races. The solution
is to move the sent flag check only to tcp.c.

Fixes #23246

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Dominik Ermel 08c8dc7e27 subsys/mgmt: Enabling mynewt-core version of tinycbor
This PR provides changes that are required after replacing Tinycbor
with copy of source code from mynewt-core.
The Tinycbor has been replaced with mynewt-core version to reduce
maintenance effort; by replacing it the Zephy specific changes have been
reduced to small patch over mynewt codebase.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-03-17 11:58:18 +01:00
Andrew Boie 80a0d9d16b kernel: interrupt/idle stacks/threads as array
The set of interrupt stacks is now expressed as an array. We
also define the idle threads and their associated stacks this
way. This allows for iteration in cases where we have multiple
CPUs.

There is now a centralized declaration in kernel_internal.h.

On uniprocessor systems, z_interrupt_stacks has one element
and can be used in the same way as _interrupt_stack.

The IRQ stack for CPU 0 is now set in init.c instead of in
arch code.

The extern definition of the main thread stack is now removed,
this doesn't need to be in a header.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-16 23:17:36 +02:00
Dan Erichsen 6a12a2dbe1 bluetooth: host: Do not send unwanted SC indicate
Fixes #23485

When we create a GATT table dynamically, we also create a hash
identifying this table. This hash can be stored in persistent memory and
we can thus determine after recreating the GATT table whether the
services have changed or not from before the reboot.

When these hashes are identical, it implies that the table has not
changed, wherefore a service changed indication should not be sent to
any bonded clients. The method for achieving this was to remove the
gatt_sc.work entry from the work queue. This work queue entry was to
send an indication to the clients when the table had been allocated.
If the final entry then caused the hashes to match, the indication
would be cancelled.

On unit testing this behaviour in simulation and in practice, we found
that the indication was sent nonetheless, and the issue was located to
be tied to the SERVICE_RANGE_CHANGED flag which is set when the services
are changed and is cleared when the indications are being sent out.

It was the job of the work queue entry to clear this flag, and as the
entry was never serviced, the flag was never cleared, and when
sc_commit() is called at the end of the process, it believes that there
is a new service change pending and therefore starts the job over, thus
creating a redundant indication to the clients.

This commit fixes the issue by clearing the flag when the work entry
is removed due to a hash match. This has been unittested in a live
environment, in a simulation environment, and sanitycheck has been run
on it.

Signed-off-by: Dan Erichsen <daee@demant.com>
2020-03-16 21:09:24 +02:00
Peter Bigot e70de6ee82 power: device: fix name for Nordic clock driver
The device power management infrastructure maintains a hard-coded list
of critical devices to ensure suspend and resume are performed in the
proper order.  PR #21298 combined the 32 KiHz and 16 MHz clock devices
into a single driver, changing the name so the clock driver is not
handled at the correct time, but rather at whatever point it appears
in the general device list.

Update the list to the current clock driver name.  Also store the
device names as standard strings rather than padding them to a fixed
length.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-03-16 15:54:36 +01:00
Johan Hedberg 80cb358fe2 Bluetooth: Kconfig: Fix BT_ECC defaults
The commit e85dd8af5d changed the way the BT_ECC Kconfig option
is enabled, however it got the dependency wrong. The dependency should
only look at BT_SMP_OOB_LEGACY_PAIR_ONLY if BT_SMP was also enable.

This broke e.g. the build of the mesh_demo app for the BBC
micro:bit since the memory consumption jumped up by roughly 2k.

This patch fixes the issue, and in the same go makes the Mesh handling
consistent by also using a conditional default rather than select.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-03-16 14:26:08 +02:00
Andrew Boie 22b9167acb shell: show IRQ stack information
This is placeholder code; better kernel support for dumping
exception/interrupt related stacks is forthcoming.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Andrew Boie 760644041c net: purge NET_STACK and other stack APIs
The current design of the network-specific stack dumping APIs
is fundamentally unsafe. You cannot properly dump stack data
without information which is only available in the thread object.

In addition, this infrastructure is unnecessary. There is already
a core shell command which dumps stack information for all
active threads.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Joakim Andersson 628b3bc416 Bluetooth: host: Allow get local OOB data while advertiser is enabled
Allow to get local OOB data while advertiser, scanner or whitelist
initiator is active. If direct initiator is active or the advertiser
is using the random address as a random static identity address then
the function will return error.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 17:16:51 +02:00
Joakim Andersson 7ff4a632b7 Bluetooth: host: Allow to initiate pairing without OOB present
When OOB callbacks are present it is possible to achieve authenticated
pairing without having the remote OOB data present. Using OOB with
LE Secure Connection only one side of the pairing procedure is required
to have the OOB data present. If we have given the remote our OOB data
then pairing can proceed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 14:18:48 +02:00
Joakim Andersson 8514794ed3 Bluetooth: controller: Do not use LL procedures not supported by remote
Update LLCP handling during PHY update and Data Length update to not
start the LL control procedure if the remote has already indicated that
the procedure is not supported.

This fulfills the following requirement from the BT Core Specification
(Core_v5.2, Vol 6, Part B, Section 4.6):

Except where explicitly stated elsewhere in this specification, if the
peer Link Layer has indicated either during a feature exchange procedure
or by responding with an LL_UNKNOWN_RSP PDU that it does not support a
procedure, then the Link Layer shall not use that procedure.

Re-use the connection parameter request handling for PHY and
data length update procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-13 13:02:13 +01:00
Vinayak Kariappa Chettimada 8a294a62d4 Bluetooth: controller: legacy: Fix missing first conn event
Fix missing first connection event due to first connection
event ticks_slot overlapping with the initiator window
ticks_slot.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-13 10:39:39 +01:00
Vinayak Kariappa Chettimada 489bebfb04 Bluetooth: controller: Add ticker_stop_abs interface
Add ticker_stop_abs interface, similar functionality as to
ticker_stop interface to stop a running ticker but with a
supplied absolute tick reference value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-13 10:39:39 +01:00
Marcin Niestroj c0b50c72be net: mqtt: use MQTT_UTF8_LITERAL() to simplify code and fix debug log
Contents of mqtt_3_1_0_proto_desc and mqtt_3_1_1_proto_desc were logged
with following code:

  MQTT_TRC("Encoding Protocol Description. Str:%s Size:%08x.",
           mqtt_proto_desc->utf8, mqtt_proto_desc->size);

This resulted in invalid log, since they were not NULL-terminated
strings. Use MQTT_UTF8_LITERAL() to initialize both utf8 strings to make
sure they are NULL-terminated now and valid to print and
log. Additionally this makes the code a bit shorter.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-13 10:06:18 +02:00
Vincent Wan 5637def2b3 power: policy: add PM policy function for TI CC13X2/CC26X2
Create a residency-based system power policy function for TI
CC13X2/CC26X2 that uses TI's Power module.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-03-12 19:22:53 -06:00
George Stefan 76b1f03345 bluetooth: controller: openisa/RV32M1: use DSM from LLL
Added the functions to turn on/off the radio from LLL.
Added WAKE_IRQ to start radio after it's out of DSM.

Signed-off-by: George Stefan <george.stefan@nxp.com>
2020-03-12 17:05:02 +02:00
Ionut Ursescu 27878377b2 bluetooth: controller: openisa/RV32M1: introducing radio Deep Sleep Mode
Added the functions to turn on/off the radio.
Deep Sleep Mode (DSM)

Signed-off-by: Ionut Ursescu <ionut.ursescu@nxp.com>
Signed-off-by: George Stefan <george.stefan@nxp.com>
2020-03-12 17:05:02 +02:00
Andrei Emeltchenko 767d1bb6f9 logging: log_backend_rb: Use int for memory area size
Change "hex" to "int" for LOG_BACKEND_RB_MEM_SIZE.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-03-12 13:31:24 +02:00
Andrei Emeltchenko dbf1d5d87d logging: log_backend_rb: Make message buffer size configurable
Make slot size configurable making it easy to use with other
platforms.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-03-12 13:31:24 +02:00
Andrei Emeltchenko f4357837af logging: Make ring buffer backend more general
Ring buffer in memory backend does not depends on xtensa adsp board,
so make it general: remove to log_backend_rb and remove dependency on
up_squared_adsp.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-03-12 13:31:24 +02:00
Alex Porosanu cf96a0bdaa bluetooth: controller: enable 2Mbps PHY for RV32M1
This patch adds the selection of  the necessary CONFIG_*
options for allowing the use of the 2Mbps BLE PHY on
VEGA platform.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-03-12 13:10:04 +02:00
Alex Porosanu cb0a6c2eff bluetooth: controller: openisa/RV32M1: add 2 Mbps PHY support
The radio on the VEGA platform supports both 1Mbps, as well
as 2Mbps BLE PHYs. It does not support coded BLE PHY. This patch
adds the necessary callback, as well as timings to enable the 2 Mbps
PHY support in the SW LL HAL for VEGA.

Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
2020-03-12 13:10:04 +02:00
Joakim Andersson a421fc882b Bluetooth: shell: Add support for Legacy OOB pairing in the shell
Add command to input the legacy pairing OOB TK during the pairing
procedure.
Fixed shell build with CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY defined.
Print error code when passkey input failed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-12 12:30:15 +02:00
Iván Morales e85dd8af5d Bluetooth: smp: Adding Legacy OOB only mode and no JW/Passkey mode
Added CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY option that completely disables
all legacy and SC pairing modes(except for Out of Band) and frees the
memory previously used by these.

Added CONFIG_BT_SMP_DISABLE_LEGACY_JW_PASSKEY option that force rejects
pair requests that lead to legacy Just Works or Passkey pairing.

Signed-off-by: Iván Morales <ivan98ams@gmail.com>
2020-03-12 12:30:15 +02:00
Iván Morales cc0d2447f1 Bluetooth: smp: Adding Legacy OOB pairing support
Added support for Legacy pairing using OOB Temporary Key

Signed-off-by: Iván Morales <ivan98ams@gmail.com>
2020-03-12 12:30:15 +02:00
PK Chan 9f9e00a62d net: mqtt: Added event for MQTT ping response.
There are scenarios where there is a NAT firewall in between MQTT
client and server. In such case, the NAT TCP timeout may be shorter
than MQTT keepalive timeout and TCP timeout. The the MQTT ping
request message is dropped by the NAT firewall, so that it cannot be
received by the server, resulting in void MQTT ping response message.
There is no TCP FIN or RST at all. The application looks hang-up
until TCP timeout happens on the client side, which may take too
long.

Therefore, the event MQTT_EVT_PINGRESP is added to inform the
application that the route between client and server is still valid.

Signed-off-by: PK Chan <pak.kee.chan@nordicsemi.no>
2020-03-12 11:07:14 +02:00
Stephanos Ioannidis 5aa62369d4 net: shell: Handle ENETUNREACH for IPv4 ping
This commit updates the the IPv4 ping command to handle the ENETUNREACH
error number returned by `net_icmpv4_send_echo_request` function when
IPv4 is unavailable.

The `net_icmpv4_send_echo_request` function previously returned EINVAL
when IPv4 is unavailable and this caused the shell command to report
"Invalid IP address" even when the provided IP address is correct; this
problem was corrected by returning ENETUNREACH instead of EINVAL in the
aforementioned function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-11 13:25:55 -05:00
Stephanos Ioannidis 2c733d5195 net: icmpv4: Return ENETUNREACH when IPv4 is unavailable
net_icmpv4_send_echo_request currently returns EINVAL (invalid
argument) when IPv4 is unavailable.

Since the availability of IPv4 has nothing to do with the arguments
provided to this function and the meaning of EINVAL in this case is
ambiguous, return the ENETUNREACH (network is unreachable) error
number instead.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-11 13:25:55 -05:00
Oleg Zhurakivskyy bedd4e01fd net: tcp2: Add a mutex to TCP connection
The TCP connection might be concurrently modified from the
TR/TX threads, so add a mutex to protect from the concurrent
modification.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy fad38b12a3 net: tcp2: Update test protocol functions
After removing the test windows, update test protocol
functions for the TTCN-3 sanity check.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 615d73b2c9 net: tcp2: Set TCP connection endpoints in net_tcp_connect()
Initialize and set IPv4/IPv6 connection endpoints in net_tcp_connect().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy a156d76f8e net: tcp2: Do not base the incoming data evaluation on PSH
Do not base the incoming data evaluation on PSH.

Also, reduce the condition branches.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy f149eb7b14 net: tcp2: Remove obsolete test window functions
These test receive windows were used by TTCN-3 sanity check,
but it's possible to do without them.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 16b8244cf8 net: tcp2: Eliminate the need for a test send window
In order to drop dependency on a heap, drop the
test send window.

Use net_tcp_queue_data() to receive the outgoing data
from the socket layer.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy b25faa6159 net: tcp2: Eliminate the need for a test receive window
In order to drop dependency on a heap, drop the test
receive window.

The receive window was needed for TTCN-3 sanity check,
but it's possible to do without it.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 4c81935c2e net: tcp2: Don't instantiate an extra connection on SYN+ACK
On incoming SYN+ACK, use the existing TCP connection.

This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy b0381bc80e net: tcp2: Check the ack number in SYN_SENT
In SYN_SENT check the ack number of the incoming TCP message
against our sequence number.

This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 038618dbc8 net: tcp2: Guard against th_get() on NULL pkt
This problem was overlooked earlier and was found while
testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 1eccf22526 net: tcp2: Add log_strdup() where necessary
In case the log output involves the content of the static
buffer, add log_strdup().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy ebbb7f3d56 net: tcp2: Don't instantiate an extra connection on connect
Don't erroneously instantiate an extra TCP connection
on TCP connect.

This problem was overlooked earlier and found while testing
TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy d6f1937fbb net: tcp2: Switch from k_timer to k_delayed_work
k_timer callback is executed from ISR context, which isn't
currenty compatible with Zephyr's shell implementation.

This problem was found while testing TCP2 client side.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy bab5e7bd96 net: tp: Add IPv6 support for test protocol
In order to suport using test protocol over IPv6,
add IPv6 support.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 27a12b78cb net: tcp2: Drop obsolete ip_get(), ip6_get() macros
After adding IPv6 support, there's no need for them.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy e301397af1 net: tcp2: Use net_tcp_finalize() for checksum calculation
In order to support IPv6, use net_tcp_finalize() for checksum
calculation.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 9292ce9efc net: tcp2: Add IPv6 support for outgoing packets
Add IPv6 support for outgoing packets.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 75820c9bdf net: tcp2: Register test inputs for TTCN-3 based TCP2 sanity check
In order to support TTCN-3 based TCP2 sanity check,
register test inputs with net_conn_register() and adjust
test functions to account for this.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy f5c1ee03b8 net: tcp2: Add support for a IPv6
In order to support IPv4/IPv6, work with packet through
net_pkt_ip_hdr_len(), net_pkt_ip_opts_len() which account
for IPv4/IPv6, IPv4 options and IPv6 extension headers.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Oleg Zhurakivskyy 6be5935f17 net: ipv4: Remove temporary interception of TCP, UDP for TCP2
Remove temporary interception of TCP, UDP for TTCN-3 based
TCP2 sanity check.

As a part of adding IPv6 support, TCP2 will register test
callbacks/inputs with net_conn_register().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-11 16:24:52 +02:00
Patrik Flykt 794b32a4fc net: tcp2: Allocate endpoints before using
Allocate tcp2.c endpoints before storing port numbers or addresses.
Select the IPv4 source address since net_context_create_ipv4_new()
is not currently called on packet output.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2020-03-11 16:24:52 +02:00
Markus Becker 6a66ae53f2 usb: cdc_acm: set initialization level to POST_KERNEL
Set initialization level of CDC ACM class to POST_KERNEL.

The proposed OpenThread Network-Coprocessor uses ACM. OpenThread is
started at POST_KERNEL level by the 802.15.4 radio drivers.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2020-03-11 11:09:21 +01:00
Miguel Azevedo 61d56b4c53 mgmt: Added Kconfig values and west.yml changes for mcumgr new version
The new version of mcumgr adds a few new Kconfig values, so
this commit adds them on Zephyr side.
This commit also updates west.yml so it points to the latest
changes on mcumgr's repo.

Signed-off-by: Miguel Azevedo <miguellazev@gmail.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-11 10:11:31 +01:00
Trond Einar Snekvik 56a918f8ca Bluetooth: Mesh: Rework msg_cache
Changes the behavior of the message cache to optimize for cache
capacity. Previously, the message cache's primary function was to avoid
decrypting messages multiple times, although the cache's main function
in the spec is to avoid message rebroadcasting. Optimizing for minimal
decryption causes us to fill the network cache faster, which in turn
causes more cache misses, potentially outweighing the advantage.

Now stores src + seq in message cache instead of field hash value. This
cuts cache size in two, while including more of the sequence number than
before.

Adds messages to the cache only after the packet is successfully
decrypted. This reduces noise in the cache, and ensures that no
invalid deobfuscations are added.

Additionally, this fixes a bug where multiple calls to net_decrypt with
the same packet failed, as the message cache found its own entry from
the previous call.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 17:13:32 +02:00
Marcin Niestroj f15ac65254 net: icmpv4: drop requests on NET_OFFLOAD interfaces
NET_OFFLOAD interfaces do not handle ICMP request. Request to send ICMP
packet resulted in NULL pointer dereference in net_if_tx() later
on. Prevent that by detecting NET_OFFLOAD interfaces early in icmpv4
module.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-10 16:44:13 +02:00
Andrew Boie 81cfb08f52 random: remove rand32_timestamp.c
This is a copy of rand32_timer.c that uses
z_do_read_cpu_timestamp32() instead of k_cycle_get_32(),
with some logic to ensure different values when called in
rapid succession missing.

Like the other driver, its reported values are not random,
it's a testing generator only.

This appears to have no advantages over rand32_timer.c,
just remove it. In QEMU emulation, the reported TSC values
tend to have the lowest five bits zeroed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:40:13 -04:00
Andrew Boie 831f6d5051 shell: use correct data type for atomic variables
The variable needs to be an atomic_t, and in one case it was
being incremented outside of an atomic_inc/atomic_add.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Joakim Andersson 564ba1a07b Bluetooth: host: Use switch statement in bt_conn_set_state
Refactor old state handling in bt_conn_set_state to use switch statement
instead of if statements.
This will give us warning about enum values not covered.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:09:43 +02:00
Joakim Andersson f19b7a6e69 Bluetooth: host: Fix local RPA not valid in connection complete
Fix connection complete event handling when the local RPA is not valid.
This can happen when the controller was not instructed to use an RPA
address, or the local IRK was set to an all zero IRK.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:09:31 +02:00
Håkon Øye Amundsen 64d8e65f33 DFU: add init function with area id as parameter
This allows flash_img.c to be used outside of mcuboot scope.
Add new call to not break existing code.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-03-10 15:07:27 +02:00
Rubin Gerritsen 9c28569901 bluetooth: controller: Fix incorrect dependency of Coded PHY
In Core v5.2, Vol 6, Part B, Section 4.6.9 it is stated that it is
mandatory to support the PHY procedure if any PHY other than 1M is
supported.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-03-10 15:05:51 +02:00
Rubin Gerritsen 213c8e9d53 bluetooth: controller: Allow any controller to config PHY support
For the time being this 2M is only selectable for !nRF51 platforms.
Coded PHY is only selectable for nRF platforms supporting Coded PHY.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-03-10 15:05:51 +02:00
Nick Ward c411ed9322 shell: modules: Add date commands to display or set date
Currently only supports Unix time.

‘get’ subcommand returns date in format “Y-m-d H:M:S”
‘set’ subcommand format is ‘[Y-m-d] <H:M:S>’

The ‘set’ subcommand is implemented with basic date validation.

For user convenience of small adjustments to time the time argument
will accept H:M:S, :M:S or ::S where the missing field(s) will be
filled in by the previous time state.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2020-03-10 15:04:12 +02:00
Joakim Andersson 681dfdc12b Bluetooth: HCI_VS: Check for supported command
According to the Zephyr VS HCI specification:
Only Read_Version_Information and Read_Supported_Commands commands are
mandatory.

Check for supported Read Supported Features command before issuing this
command to the controller.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 15:02:48 +02:00
Vinayak Kariappa Chettimada 66d1be6728 Bluetooth: controller: nRF51x: Force optimize for speed
Make BT_CTLR_OPTIMIZE_FOR_SPEED option so that it is not
user selectable for nRF51x series SoC with encrypted
connections support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 15:01:43 +02:00
Marek Porwisz 914a00230f net: openthread: Implement energy scan in openthread using radio driver api
OpenThread has api to make use of radios energy scan feature.
Implemented this api in zephyr. This allows thread to perform energy
scan when needed.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-03-10 14:59:10 +02:00
Jukka Rissanen 505e306b72 net: context: Allow binding AF_PACKET multiple times
If the system has more than one network interface, then it should
be possible to bind a AF_PACKET socket to each interface if the
network interface index is set when bind() is called. This was
not possible earlier as the code was always using default network
interface with AF_PACKET socket bind().

Fixes #23153

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-10 14:58:30 +02:00
Robert Lubos d2e7a7d0c7 net: lwm2m: Notify when it's safe to turn RX off
According to LWM2M specification, when Queue Mode is used, the LWM2M
client should keep the reciever on for specified time after sending A
CoAP message. This commit adds a new LWM2M event,
`LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF`, to facilitate the process by
notifying the application when it's safe to turn the receiver off.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:57:29 +02:00
Robert Lubos 842d4b220f net: lwm2m: Add option to register in UDP queue mode
Add Kconfig option to enable Queue Mode binding. With this option
enabled, the LWM2M client will register with `UQ` binding, instead of
`U`.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:57:29 +02:00
Vinayak Kariappa Chettimada b466d5399c Bluetooth: controller: legacy: Fix mandatory min PDU len Code PHY
Fix to return the max tx/rx time back to set default time
after using mandatory minimum PDU length and time while
switching back from Coded PHY to 1M PHY.

Also fixes #23109.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Vinayak Kariappa Chettimada baeed73684 Bluetooth: controller: legacy: Fix DLE tx rx time on PHY update
Fix Data Length Update transmit and receive time calculation
on PHY update procedure completion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Vinayak Kariappa Chettimada 5386095ba4 Bluetooth: controller: legacy: Fix Data Length Tx Rx time
Fix Data Length Update procedure calculation of transmit
and receive time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-03-10 14:55:31 +02:00
Johann Fischer 5b5cfaf1a6 usb: mass_storage: check dCBWDataTransferLength for read commands
Check dCBWDataTransferLength for every read command.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 14:54:29 +02:00
Johann Fischer 098a16ed3c usb: mass_storage: use sys_get_be32, sys_put_be32
Use sys_get_be32, sys_put_be32 where possible.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 14:54:29 +02:00
Audun Korneliussen 8fac501c0f usb: msc: Stall data stage before sending error status
When an unsupported SCSI command is received, an error status reply
is sent even if the Host expects data prior to the status.

This fix stalls the data reply before sending the error status.

Signed-off-by: Audun Korneliussen <audun.korneliussen@nordicsemi.no>
2020-03-10 14:54:29 +02:00
Marcin Niestroj f5edc6db8f net: wifi: shell: drop explicit length parameter
Calculate length based on provided SSID string, so user does not have to
provide length explicitly over shell.

This patch also removes requirement of minimum 3 characters SSID, as
the shortest SSID can be even 1 character.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-10 14:37:57 +02:00
Robert Lubos 24b6afaec2 net: openthread: Unify IS_ENABLED macro usage
Older OT code used preprocessor #if conditionals, while newer code
used IS_ENABLED macro. Unify the approach by switching to the latter
option.

Additinally, fix inclusion issue that came out after switching to
IS_ENABLED.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:36:24 +02:00
Robert Lubos 0c8d81c46f net: mqtt: Add write message handler
Add new transport handler for MQTT, with sendmsg-like functionality.
This allows TCP transport to send PUBLISH packets w/o fragmentation at
the TCP layer. Implement this new functionality for all existing
transports.

Fixes #22679

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:10:18 +02:00
Robert Lubos 5b58273a34 net: mqtt: Fix incorrect error code use in log
`mqtt_transport_write` failue was logged with `errno` value which is not
correct as the return value from the function is valid in this case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:10:18 +02:00
Luuk Bosma 9587a271f6 net/ip/dhcpv4: Set Host Name in DHCP Request
This option specifies the name of the client.
See https://tools.ietf.org/html/rfc2132#section-3.14

This is useful for identification when looking in DHCP lease table.

Signed-off-by: Luuk Bosma <l.bosma@interay.com>
2020-03-10 14:10:01 +02:00
Göran Weinholt 091f630014 net: ppp: ipcp: negotiate DNS servers and optionally use them
We now negotiate DNS servers in the IPCP configuration. This has been
observed to speed up the connection setup. The received DNS servers
are used by the DNS resolver library, but we leave it optional since
the static server list might be preferable.

Increase MAX_IPCP_OPTIONS to 4 so that we can nack all RFC 1877
options.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-03-10 14:09:10 +02:00
Göran Weinholt eef8e67ea7 net: ppp: ipcp: do not require a peer address
It is not unusual that the peer does not provide an IP address in the
ipcp negotiation. But because ppp is a peer-to-peer protocol, we do
not actually need to know the peer's address to use the network.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-03-10 14:09:10 +02:00
Robert Lubos 56566ad497 net: sockets: tls: Fix net_context referencing
TLS sockets did not increase refcount of a net_context running TCP,
which could lead to a crash upon TCP disconnection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:08:20 +02:00
Jukka Rissanen 2d992baa42 net: ipv6: Add network interface to various debug prints
Useful when figuring out where the device is sending the
network packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-10 12:39:13 +02:00
Joakim Andersson 94e1620c03 Bluetooth: host: Fix host resolving peer identity in connection complete
Fix host resolving the peer identity address in enhanced connection
complete event when the resolving list in the controller is full and
resolution is done in the host.
Move the handling from legacy connection complete into enhanced
connection complete event so that it is done for both connection
complete events.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-10 12:18:09 +02:00
Trond Einar Snekvik db330cb06a Bluetooth: Mesh: Segmented TX to groups
Implements several changes to the transport layer segmented tx to
improve group message performance:
- Moves retransmit counter to tx context instead of per packet. As every
  unacked packet is sent every retransmit, the retransmit counters would
  be the same in each segment. This makes it easier to control progress.
- Delays the scheduling of the retransmit until the completion of the
  last segment by adding a seg_pending counter. This is essentially the
  same as the old behavior, except that the old behavior might retrigger
  the sending before all segments are finished if the advertising is
  slow.
- Allows the group transmits to stop as soon as all retransmits have
  been exhausted, instead of timing out waiting for acks that won't
  come. This allows group tx to finish without error.
- Fixes a bug where a failed TX would block IV update.
- Cancels any pending transmissions of acked segments.
- Reduces log level for several common group tx scenarios that aren't
  erronous.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 12:17:13 +02:00
Trond Einar Snekvik 2f27e0ce84 Bluetooth: Mesh: CDB for config client in shell
When available, the shell will use the CDB when configuring. This
replaces the default key for configuration and self-provisioning,
ensuring that there aren't multiple key values for the same indexes.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-10 12:16:31 +02:00
Joakim Andersson bb42abdd7c Bluetooth: host: Fix LE SC OOB authentication and id for central role
If the application has used bt_le_oob_get_local to retrieve the OOB
RPA address and OOB authentication information the central role should
use this RPA address for the next RPA timeout period.

The central role always refreshes the RPA address for the initiator,
this will make the OOB information not usable as the peer cannot
recognize the central role since the RPA address is changed.
Check if the initiator can use the address for the duration of the of
remaining RPA period.

Fix central role using the advertiser identity when setting the private
address. The central role should only use the default identity.

Regressions from:
fbe3285bfa
and
4876a8f39a

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-06 18:25:48 +02:00
Flavio Ceolin a2872c3a00 shell: utils: Fix buffer overrun in shell_spaces_trim
The third argument in memmove can possible be greater than remaining
buffer size. Just ensuring that memmove will changes bytes only inside
the string buffer and nothing else.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-03-06 10:08:46 +02:00
Joakim Andersson c97e1aafb1 Bluetooth: Mesh: Fix possible NULL dereference in BT_DBG statement.
Fix possible NULL dereference in BT_DBG statement when
bt_mesh_friend_get is called before a successful cfg_srv init

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-03-06 10:04:46 +02:00
Trond Einar Snekvik 2835da8194 Bluetooth: Mesh: Fix cdb key update iteration
Fixes copy/paste error taking the size of the the wrong array.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-03-05 20:33:07 +02:00
Johann Fischer 23ace0e556 usb: mass_storage: check LBA range
Check if LBA is in range of the memory size.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-04 17:14:52 +02:00
Johann Fischer c88155fd2d usb: mass_storage: fix possible page buffer overflow
The page buffer can overflow if dCBWDataTransferLength
is multiple of the BLOCK_SIZE but the host uses
OUT packets smaller than MPS durng transfer.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-04 17:14:52 +02:00
Ravi kumar Veeramally 491367115d net: ipv4: Fix compilation errors
opts_len renamed to total_opts_len in previous changes.
But it's not replaced at one place.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-03-03 16:50:32 +02:00
Johann Fischer 105849cf38 usb: dfu: check requested length (wLength) during DFU_UPLOAD
During DFU_UPLOAD, the host could requests more data
as stated in wTransferSize. Limit upload length to the
size of the request buffer (USB_REQUEST_BUFFER_SIZE).

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-02 17:37:24 +02:00
Vinayak Kariappa Chettimada 4bacb0e098 Bluetooth: controller: legacy: Fix cond. compile error
Fix conditional compilation error when enabling
BT_CTLR_FAST_ENC for central only application builds.

Also added additional compilation to code exclusive to
central or peripheral role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-29 19:39:41 +02:00
Vinayak Kariappa Chettimada ca66f5b2e5 tests: Bluetooth: shell: Fix conditional compile error
When building the tests/bluetooth/shell application without
the BT_CENTRAL feature, compilation fails:

subsys/bluetooth/shell/bt.c:1642: undefined reference to
`bt_conn_create_auto_le'

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa@gmail.com>
2020-02-29 10:47:18 +02:00
Ravi kumar Veeramally 22f93b35ab net: ipv4: Fix parsing of IPv4 header options
If IPv4 header options has wrong options length
(e.g. options length is more that actual data),
then parser decrements opts_len without checking
actual data length. Which crashes the network stack.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2020-02-28 22:34:11 +02:00
Tobias Svehagen 60563977df Bluetooth: Mesh: Fix handling of app index and local device key
Fix problem of not checking if the remote device key is actually our
own. This bug was intruduced in
46a95f12ad and causes failure of models
that use app_idx BT_MESH_KEY_DEV_REMOTE. Since this is used by cfg_cli,
it was not possible to do self-configuration.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-28 20:18:54 +02:00
Vinayak Kariappa Chettimada f972fb057d Bluetooth: controller: Add Kconfig for Optimize for Speed
Add Kconfig option to support building the controller
optimized for speed.

Fixes #21601.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-28 10:55:33 +02:00
Vinayak Kariappa Chettimada e1d9620187 Bluetooth: controller: legacy: Fix assert on DLE procedure stall
Fix local initiated Data Length Update procedure from being
stalled when a remote initiates a procedure with instant.

Fixes #23069.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-28 10:02:15 +02:00
Andries Kruithof 2c70df32b7 Bluetooth: controller: split: Fix regression errors
This commit fixes problems with LL tests CON/SLA/129, CON/SLA/130,
CON/SLA/132, CON/MAS/126, CON/MAS/127, CON/MAS/129, CON/MAS/55,
CON/SLA/57

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-02-27 19:14:32 +02:00
Vinayak Kariappa Chettimada 7a3e29af06 Bluetooth: controller: legacy: Fix Tx pool corruption
Fix Tx pool from being corrupted when rough central device
uses invalid packet sequence numbers, causing NULL pointer
to be released into free data Tx pool.

Fixes #22968.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-02-27 12:54:35 +02:00
Tobias Svehagen 7a737a0084 Bluetooth: Mesh: Fix bug with storing node in CDB
The free_slot->clear must be set to false since it could still be true
from previous use.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2020-02-27 12:40:19 +02:00
Rubin Gerritsen 3a30eed083 bluetooth: Fix wrong warning text for unsupported Zephyr HCI commands
They were interchanged.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-02-27 12:31:01 +02:00
Dag Bjarvin 1a43a798e7 Bluetooth: controller: Merge 2 lines
Merge 2 lines that fit on one line

Signed-off-by: Dag Bjarvin <Dag.Bjarvin@nordicsemi.no>
2020-02-27 12:30:44 +02:00