Commit graph

18329 commits

Author SHA1 Message Date
Jukka Rissanen 93e5181fbd net: context: Add locking for concurrent access
If the net_context functions are accessed from preemptive priority,
then we need to protect various internal resources.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-31 11:20:26 +02:00
Kumar Gala 93d0f8c58d dfu: Fix build issue with gcc8
We get the following warning when buiding with gcc8:

	error: 'packed' attribute ignored for type 'u32_t *'
	{aka 'unsigned int *'} [-Werror=attributes]

Use UNALIGNED_GET() to access the data since we don't know the
alignment.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-31 03:13:52 -06:00
Aurelien Jarno 4394601524 net: sntp: get rid of the callback function
The original SNTP client library was designed for the net-app API, for
which it makes sense to have a callback function, which is called
asynchronously when an answer is received.

For the socket based interface, the callback is called just before
sntp_request() returns. It gets the status and the epoch_time in
parameter, however the status is already returned by sntp_request(). It
therefore make sense to replace the callback function by a pointer to
epoch_time.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-31 10:14:12 +02:00
Andrew Boie c253a686bf app_shmem: auto-initialize partitions
There are no longer per-partition initialization functions.
Instead, we iterate over all of them at boot to set up the
derived k_mem_partitions properly.

Some ARC-specific hacks that should never have been applied
have been removed from the userspace test.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-30 23:15:51 -05:00
Robert Lubos e0a44c388c net: openthread: Bump OpenThread commit to f9d757a1
This version has cli_console backend fixed, hence no longer crashes on
`ot ping` command.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-30 21:01:53 -05:00
Krzysztof Chruscinski a0904ff86a logging: Handle panic occuring before log initialization
Log backends (marked as autostart) are initialized late. By default
in logger thread which has the lowest priority. If log_panic() occurs
earlier no logs is printed because there is no backend enabled.

This patch fixes it by adding log_init() call to log_panic(). Log_init()
can be called multiple times.

This patch ensures that logs are printed if early panic occurs if
backend is configured to auto-start. This is not the case if shell
is acting as log backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 23:26:13 +01:00
Krzysztof Chruscinski eac2f7c763 logging: log_backend_rtt: Fix panic behavior when no host
RTT log backend was locking in panic if host absense was not yet
detected (early panic). It is fixed by adding detection of host
absense while pending on data being read by the host.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 08:21:04 -05:00
Jakub Rzeszutko 4c3bcbafef shell: documentation update
Updated documantation in regards to new shell printing strategy.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Jakub Rzeszutko ce6be8600b shell: safe print from different threads
Added display text management to shell_fprintf function.
Now it can be used from diffrent threads with not risk that
displayed lines will overlay.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Jakub Rzeszutko 75ad61f7ef shell: removed foreground command functionality
Removed foreground command functionality from shell source files.
Removed associated example.
Removed enter/exit command functions from the Bluetooth example
Updated project config files.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-30 13:05:56 +01:00
Léonard Bise c8eeb91222 net: tcp: Call cb in case last ACK is not received
After receiving FIN, the TCP stack will send a FIN and start
a timer to track the reception of the associated ACK. In case this
ACK is never received then the context will be released
without calling the associated received callback which leads to
upper layers not being informed that the connection was closed.

This issue was observed when using sockets, the effect is
that in this case the socket would never be closed and stay
in limbo forever.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2019-01-30 12:47:00 +02:00
Michael Scott 8a115ca556 net: lwm2m: remove some unnecessary includes
net/lwm2m.h is included by object.h

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 44e9b5ed44 net: lwm2m: refactor lwm2m_engine_context into lwm2m_message
The relationship between lwm2m_engine_context and lwm2m_message
has always been a tenuous one.  Let's merge the 2 structures
into lwm2m_message and remove all of the extra stack variables.

This change increases SRAM usage slightly due to the
addition of the context structures to the multiple lwm2m_messages.
However, the way lwm2m_engine_context was being used off the stack
was probably creating hard to debug issues in the longterm.

Also, having all of the structures in 1 place makes sharing them
much easier later.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 86728d849b net: lwm2m: fix unsigned check for <0 in LwM2M device obj
Reported by Github user himanshujha199640 using coccinelle:
subsys/net/lib/lwm2m/lwm2m_obj_device.c:172:5-16:
WARNING: Unsigned expression compared with zero.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/11135

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 0ee0773abd net: lwm2m: remove unused CONFIG_NET_CONTEXT_NET_PKT_POOL config
CONFIG_NET_CONTEXT_NET_PKT_POOL is used by Zephyr's TCP stack as
a way of keeping the original packet data when compression and
other l2 specific actions make the data unusable for retries.

LwM2M uses UDP and this option was never used.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Krzysztof Chruscinski be4b2cd62d shell: Add support for notifying about dropped logs
Extended shell log backend to print warning message on dropped
log messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 18:31:16 +01:00
Ravi kumar Veeramally f51cebeea2 net: sntp: Rework SNTP client library to use sockets
As networking libraries and protocols are moving to socket
based implementation, reworked SNTP client library to use sockets.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-01-29 12:25:01 -05:00
Aurelien Jarno ed0b0b7cbd nvs: fix alloc/data wra log format string
Commit 41f86c3db2 ("nvs: fix warnings in logger") wrongly changed the
"%d" into "%x" while it was only supposed to suppress the warning.

This patch switches back the format string to "%x".

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-29 17:49:44 +01:00
Jakub Rzeszutko 770261045e shell: added static to char_replace function
Function char_replace is only used in shell_ops.c file.
Added keyword static to function definition and removed
declaration from shell_ops.h

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-29 17:46:47 +01:00
Jakub Rzeszutko e7b55a6eb5 shell: meta-keys handle condition update
Meta keys are active when they are enabled and when shell echo is set
to on.
Updated meta keys description in shell's Kconfig file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-29 17:46:47 +01:00
Krzysztof Chruscinski 790fdb9ebd logging: Add support for new 'in place' mode to native posix backend
Extended native posix backend to support new backend API for
'in place' mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 8e9cc62e7a logging: Add support for new 'in place' mode to RTT backend
Extended RTT backend to support new backend API for 'in place' mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 71697969c7 logging: Add support for new 'in place' mode to UART backend
Extended UART backend to support new backend API for 'in place'
mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 08e5103105 logging: Extend log_output to support raw data
Added functions for processing log string and hexdump. Details
are passed as function parameters and not as log_msg. Those
functions can be used when logger works in  synchronous mode
and log messages are not created.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 1d9e5ee108 logging: Refactoring 'in place' mode to reduce memory footprint
Changed 'in place' mode to bypass logger system and directly
call active backends. With this approach memory footprint of
the logger can be significantly reduced in terms of RAM and ROM.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Jukka Rissanen 09365adced net: shell: Fix network interface type for OpenThread
The "net iface" net-shell command printed "<unknown type>" for
OpenThread based technology. After this commit, the network
interface type is set to "OpenThread".

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-29 16:03:47 +02:00
Johan Hedberg 1c171ec283 Bluetooth: Add identifiers for Bluetooth 5.1
The Bluetooth 5.1 specification was recently released, and has a new
version identifier (10) assigned to it in the Bluetooth Assigned
Numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-29 16:00:57 +02:00
Jukka Rissanen 581261334c net: mqtt: Remove legacy MQTT library
The old and deprecated net-app based MQTT library is removed.
See the BSD socket based MQTT library for a replacement.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-29 07:11:23 -05:00
Daniel Glöckner d678f309b8 net: pkt: convert remaining users of ref to atomic_ref
The previous commit replaced the net_pkt element ref with an element
atomic_ref. CI tests turned up more places where ref was used directly.
This commit converts them to use the new element.

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Daniel Glöckner 5ef825fdf6 net: pkt: fix race condition in packet reference counting
It has been observed that some network drivers, f.ex. the SAM E70 GMAC,
call net_pkt_unref from inside the interrupt that signals the successful
transmission of a packet. This conflicts with the net_pkt_unref call
made by ethernet_send after the packet has been given to the driver.

We fix this by using an atomic_t to hold the reference count as there
might be other, difficult to find cases of net_pkt_(un)ref being used
across threads and interrupts.

The name of the element has been changed from "ref" to "atomic_ref" to
cause a compile error when code still has not been converted to use the
atomic_* functions.

Fixes #12708

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Paul Sokolovsky 3e6d7d382a net: sockets_select: Fix build without CONFIG_NET_SOCKETS_POSIX_NAMES
The implementation code itself should not rely on plain POSIX names
and use zsock_ and ZSOCK_ prefixed versions of symbols.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-29 09:19:54 +02:00
Robert Lubos 43a431e149 net: openthread: Set mesh_local flag in mesh-local OT addresses
Mark automatically and statically configured mesh-local addresses
with mesh_local flag, so that they are not used as a source for
off-mesh destinations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-28 21:24:26 -05:00
Robert Lubos 83b8abaf8a net: ip: Introduce mesh_local address flag
This commit introduces a concept of mesh-local IPv6 addresses. Such
addresses should only be used for mesh-local communication, therefore
should not be used to communicate with different subnets (i. e.
destinations outside the mesh).

As `addr_type` field already holds different kind of information
(whether address was created automatically/manually) it was not used in
this case.

Instead a mesh_local flag was added, so that we do not lose information
on how address was created. Address with such flag set will only be
selected as a source address automatically if the destination address
is within the same subnet it belongs to.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-28 21:24:26 -05:00
Johan Hedberg fe7f1e17de Bluetooth: Take advantage of net_buf_pull_mem()
Convert the remaining places of the host stack where
net_buf_pull_mem() makes more sense than net_buf_pull().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg c10b9ac228 Bluetooth: Redesign HCI event handling
Take advantage of the new net_buf_pull_mem() API, and refactor the
events from long switch statements into (const) handler tables. This
helps reduce code size and makes it cheap to add proper checks/asserts
for having sufficient data in the buffers coming from the controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg e399399a99 Bluetooth: Mesh: Take advantage of net_buf_simple_pull_mem()
Use net_buf_simple_pull_mem() instead of net_buf_simple_pull() where
it makes sense.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg 006946b8f4 Bluetooth: controller: Use net_buf_pull_mem() for command parsing
It's more natural to use net_buf_pull_mem() for the HCI command
parsing. Note that this also fixes a bug in hci_cmd_handle() where it
would previously check for sufficient parameter length with the
command header still included in the buffer (which it shouldn't have
been).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg 80dd9be4ca net: buf: Add net_buf_pull_mem() API
This is the same as net_buf_pull(), except that instead of returning
the new buf->data it returns the old buf->data. This was recently
discussed in github issue #12562.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Johan Hedberg 9abce3ec58 Bluetooth: Mesh: Fix publish timer handling when sending fails
Sending a model publication message could fail e.g. if there are no
buffers available, however this doesn't mean that we should stop doing
periodic publishing indefinitely. When an error occurs, make sure to
call the publish_sent() function so that the periodic publishing timer
gets resubmitted if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg e5b8f60bb6 Bluetooth: Mesh: Add support for suspend/resume
In some cases the Friendship & Low Power Node features aren't
available or feasible, however power saving is nevertheless required.
This patch introduces two new APIs to suspend and resume the Mesh
network. Currently, what this impacts is the LE scanning, the
ability to allocate new outgoing buffers, as well as the model
publishing, beacon and heartbeat timers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg 3e11177a06 Bluetooth: Mesh: Clean up net validity & provisioning state handling
Tracking of the BT_MESH_VALID flag and the PB-GATT state was rather
fragile. Add proper error returns to the various GATT service enable &
disable handlers, and toggle the BT_MESH_VALID flag in a single file
(main.c). Use the newly added error returns to ensure that we don't
re-enable PB-GATT if it wasn't already enabled from before.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Johan Hedberg fbe661fd3b Bluetooth: Mesh: Convert bit-fields into flags
There's already a flags member in the bt_mesh context, so take
advantage of that for any boolean members that have so far been
bit-fields. This should produce more efficient code, also for the
sequence number that's now its own u32_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 14:10:58 +02:00
Marek Pieta a304528f51 debug: SystemView fix
Change fixes problem with mutexes and initialization for SystemView,
adds config options to:
- choose if SystemView should start logging events on system start
- select SystemView RTT buffer size

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2019-01-25 17:37:51 -05:00
Johan Hedberg f18e978837 Bluetooth: Take advantage of atomic_set_bit_to() API
Use the atomic_set_bit_to() API to simplify code where possible.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-25 17:35:44 -05:00
Aurelien Jarno 41f86c3db2 nvs: fix warnings in logger
When compiling NVS with NEWLIB_LIBC=y, GCC outputs the following
warning:

In file included from $ZEPHYR/include/logging/log.h:11:0,
                 from $ZEPHYR/subsys/fs/nvs/nvs.c:17:
$ZEPHYR/subsys/fs/nvs/nvs.c: In function 'nvs_init':
$ZEPHYR/subsys/fs/nvs/nvs.c:748:10: warning: format '%lx' expects
argument of type 'long unsigned int', but argument 3 has type 'u32_t
{aka unsigned int}' [-Wformat=]
  LOG_INF("alloc wra: %d, %" PRIx32 "",
          ^
fs->ate_wra and fs->data_wra are both defined as u32_t, so they need to
be printed with '%d'.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-25 22:26:58 +01:00
Jukka Rissanen 4043909d69 net: http: Remove HTTP client and server APIs
The old legacy APIs use net-app library and as that is being
removed, then the dependencies need to be removed also.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Jukka Rissanen 1cba0161ed net: websocket: Remove the websocket as HTTP APIs are removed
Remove the experimental websocket code as it uses HTTP APIs
which are being removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Johann Fischer 5c23843e65 bluetooth: smp: fix build if BT_SMP_SELFTEST is enabled
Build fails in smp.c:3942 if BT_SMP_SELFTEST is enabled,
sign_test uses smp_sign_buf which only available for BT_SIGNING.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-01-25 13:47:24 +02:00
Robert Lubos c349bafab3 net: openthread: Do not register RLOC and ALOC addresses
In OpenThread RLOC address and ALOC address are used for internal mesh
routing and should not be used by applications as they can change
dynamically during runtime. Therefore prevent registering them on Zephyr
interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-25 10:09:27 +02:00
Paul Sokolovsky 9c91094ff7 net: sockets: select: Get rid of timeval in favor of zsock_timeval
struct timeval is per POSIX defined in sys/time.h, but that also
allowed to pull sys/select.h (and indeed, it does with native_posix),
which then starts to conflict with out select implementation (if
NET_SOCKETS_POSIX_NAMES is defined, and many samples/tests have it).

So, for now follow the existing route of duplicating all definitions
needed by our code in namespaced manner. Things like struct timeval
usage will need to be revisited later, when we'll want socket
subsystem to work with POSIX subsystem, but that's a separate deep
matter.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Paul Sokolovsky 3a0a9944c0 net: sockets: Implement select() call.
It's implemented on top of poll() anyway, and the current
implementation of fd_set uses array of fd's underlyingly, which
leads to O(n) complexity for FD_SET() and friends.

The purpose of select() implementation is to allow to perform
proof-of-concept port of 3rd-party code to Zephyr quickly. For
efficiency, poll() should be used instead.

Fixes: #11333

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Krzysztof Chruscinski 880bfb37c0 logging: Fix reporting of dropped logs before backend init
Dropped logs were not counted if logger has no backend
attached (system startup phase).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-24 08:39:29 -05:00
Andrei Emeltchenko 372fb5da51 usb: cdc_acm: Fix composite build
Fixes bug below:
subsys/usb/class/cdc_acm.c:554:15: error: ‘dev_data’ undeclared (first
use in this function) k_work_init(&dev_data->cb_work,
cdc_acm_irq_callback_work_handler); ^~~~~~~~

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-01-24 08:37:16 -05:00
Andrzej Puzdrowski f0616a4394 subsys/settings: fcb compress areas only once
fcb instance might use less areas than CONFIG_SETTINGS_FCB_NUM_AREAS.
During compression of completely filled up fcb it was possible to try
compress areas more than once.

What this patch fixes is not a bug - rather fix for inefficient service
of the corner case.

fixes #12657

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-01-23 14:43:00 +01:00
Vinayak Kariappa Chettimada 5478e82993 Bluetooth: shell: Updates related to new ULL LLL architecture
Updates related to new ULL LLL controller architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 749652080c Bluetooth: controller: Fix control procedure context safety
Fix the control procedure context safety by adding checks in
thread mode control path to detect pre-emption by interrupt.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 1475402d41 Bluetooth: controller: Introduce ULL LLL architecture
This is a squash merge of commits introducing the new split
Upper Link Layer and Lower Link Layer architecture of the
Bluetooth Low Energy controller.

This introduces a new, improved Link Layer based on the
concept of split responsibilities; The Upper Link Layer
(ULL) is in charge of control procedures, inter-event
scheduling and overall role management. The code for the
ULL is shared among all hardware implementations. The
Lower Link Layer (LLL) is responsible for the intra-event
scheduling and vendor specific radio hardware access.

The communication between ULL and LLL is achieved through
a set of FIFOs that contain both control and data packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
Signed-off-by: Morten Priess <mtpr@oticon.com>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 254a97af93 Bluetooth: controller: Preliminary work in progress mesh ext.
Preliminary work done towards Mesh extensions on the old LL
architecture implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 44d046ff8d Bluetooth: controller: Updates to prep to introduce new arch
Missing updates to old architecture implementation towards
introduction of new ULL LLL architecture.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Vinayak Kariappa Chettimada 0989c0f8c2 Bluetooth: controller: Refactor the internal LL interfaces
Refactored the internal LL interfaces to have return value
to match the HCI error code u8_t data type.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-23 09:45:06 +01:00
Anas Nashif feadb532e3 power: move reboot.c to subsys/power
One of the few last files in misc/. It fits better under subsys/power.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif 5f371e038f debug: move segger configs to subsys/debug
We have dependency on this module in code which is part of Zephyr. When
this module is split out of the tree we need to be able to build. Move
this Kconfig part to be part of zephyr and keep the external code in
ext/ with plan to split it out on the future.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Loic Poulain 192733c096 net: wifi: Add Access Point mode interface
Add access point mode disable/enable to wifi mgmt/offload.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-19 07:20:36 -05:00
Loic Poulain d9365dff92 net: wifi: shell: Add access point commands
Expose access point disable/enable commands.

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Robert Lubos 73ec83a9a5 net: openthread: Increase default stack size when commissioner is on
OpenThread commissioner feature has extra stack requirements, hence
increase it in this configuration.

Fixes #12455

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 15:24:16 +02:00
Jakub Rzeszutko f2c03280f2 shell: documentation update
1. Update shell documentation according to proposals in
PR #12437 (Extend shell meta keys).
2. Fix lines exceeding 80 characters limit.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-17 15:45:28 -05:00
Robert Lubos 635191ac8c net: ieee802154: Fix ack check
15.4 MHR is no longer set in net_buf pointed by net_pkt, but in a
separate net_buf, hence we need to check that net_buf now to
determine if we need to wait for ACK or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-17 11:16:26 +02:00
Robert Lubos 8f8c6017f4 net: 6lo: Fix ieee802154 fragmentation
Two issues identified with 6lo fragmentation for ieee802154 that broke
the communication:

1) ieee802154_fragment_is_needed function did not take 15.4 FCS size
into account, hence taking wrong decision in some cases.
2) set_up_frag_hdr was writing with wrong offset, which resulted in 6lo
bytes being overwritten by 15.4 header.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-17 11:16:26 +02:00
Luiz Augusto von Dentz 478b6b5381 Bluetooth: Shell: Add write-without-response-cb command
This adds write-without-response-cb command which can be used to
confirm the transmission of the PDU using bt_gatt_write_without_rsp_cb.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Luiz Augusto von Dentz a779705f16 Bluetooth: GATT: Add bt_gatt_write_response_cb
This adds bt_gatt_write_response_cb works similarly to
bt_gatt_notify_cb which can take a callback to be called when the PDU
is considered transmitted over the air.

Note: This can also be used to disable the ATT flow control which would
blocks sending multiple commands without wainting their transmissions.

Fixes #11558

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Jakub Rzeszutko fd0b7f7767 shell: removing legacy shell
Legacy shell removed in order to avoid maintaining two shells
systems.

All examples and tests have been migrated to the new shell.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-16 21:35:36 -05:00
Rajavardhan Gundi 75f6f1b279 drivers: flash: spi_nor: Enable Flash Page Layout and Map
This patch enables the support for FLASH_PAGE_LAYOUT and
FLASH_MAP for the generic spin nor flash driver.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2019-01-16 21:22:56 -05:00
Jan Van Winkel ce1ed82d4d settings: Corrected __ASSERT include paths
Renamed <assert.h> to <misc/__assert.h> and removed <assert.h> where
not needed.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-01-16 08:36:38 -06:00
Adithya Baglody e908ea9aa5 logging: Increase the stack size when coverage is enabled.
This prevents the stack overflow which is caused by gcov.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05:00
Aurelien Jarno 40b8854705 net: tcp: do not drop successfully received packets
Each time a successfully TCP connection is done, the number of dropped
TCP packets increases by 2. This is happens because when receiving an
initial SYN packet, or an ACK packet following a SYN+ACK packet,
NET_DROP is returned even if there is no error.

Fix that by replacing the two corresponding "return NET_DROP" by
"net_pkt_unref(pkt)" followed by "return 0".

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-16 13:11:39 +02:00
Mieszko Mierunski 8587bb19a7 smp: shell: Add support for SMP in new shell.
Added smp support for new shell.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2019-01-15 17:19:20 -05:00
Ioannis Glaropoulos 2e687653fa drivers: clock control: rename nrf5_power_clock source and header
This commit renames the nrf5_clock_control.h and
nrf5_clock_control.c files to nrf_clock_control.h and
nrf_clock_control.c, respectively, as they are used
in nRF9160 builds, as well.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Ioannis Glaropoulos 302a746bd6 drivers: clock control: nrf: rename CLOCK_CONTROL_NRF5 Kconfig symbol
This commit renames the CLOCK_CONTROL_NRF5 Kconfig symbol to
CLOCK_CONTROL_NRF. The change is required to aleviates confusion
when selecting the symbol in nRF9160 SOC definition.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Johan Hedberg a7a0d27ae2 Bluetooth: Give proper names to Bluetooth threads
Provide names for all Bluetooth threads so that they don't show up as
"NA" when issuing the "kernel stacks" command in the shell.

To get this info the following Kconfig options need to be enabled:

CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_KERNEL_SHELL=y
CONFIG_INIT_STACKS=y
CONFIG_THREAD_NAME=y

After issuing the "kernel stacks" command the output should look
something like this:

uart:~$ kernel stacks
0x200011D0 BT RX      (real size 1024): unused 760      usage 264 / 1024 (25 %)
0x20001148 BT RX pri  (real size 448):  unused 280      usage 168 / 448 (37 %)
0x20000654 BT ECC     (real size 1100): unused 168      usage 932 / 1100 (84 %)
0x20000764 BT TX      (real size 640):  unused 280      usage 360 / 640 (56 %)
0x20001ED8 sysworkq   (real size 1024): unused 592      usage 432 / 1024 (42 %)
0x200004C4 shell_uart (real size 2048): unused 904      usage 1144 / 2048 (55 %)
0x20000058 logging    (real size 768):  unused 584      usage 184 / 768 (23 %)
0x20001D84 idle       (real size 256):  unused 184      usage 72 / 256 (28 %)
0x20001E08 main       (real size 1024): unused 768      usage 256 / 1024 (25 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 17:39:54 +01:00
Johan Hedberg eba16555ce Bluetooth: Increase default TX stack size
The current stack consumption with the H4 driver on qemu_x86 is as
follows with a change from 256 to 512:

	usage 396 / 512 (77 %)

Increase the default for this configuration, as well as other similar
configurations. Set the fallback default to a higher value as well.

Fixes #12429

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-15 10:31:55 +02:00
Jakub Rzeszutko 63696968eb shell: add meta-keys
Added following meta-keys:
Ctrl-B - moves the cursor backward one character
Ctrl-D - deletes the character under the cursor
Ctrl-F - moves the cursor forward one character
Ctrl-K - deletes from the cursor to the end of the line
Alt-F  - moves the cursor forward one word
Alt-B  - moves the cursor backward one word

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-01-14 16:01:48 -05:00
Johan Hedberg 61ff1bda2f Bluetooth: Mesh: Remove redundant stack variable
The msg->prev_addr is already stored in frnd->clear.frnd, so there's
no need to have an extra stack variable for this (in the form of
prev_addr).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-14 11:38:51 +02:00
Wolfgang Puffitsch 3159049c39 bluetooth: controller: Update ticker_user_op for predictable layout.
Use fixed-width type instead of enum for field op in struct
ticker_user_op to avoid struct layout differences between
compilers. Also make check whether struct sizes match size definitions
build-time asserts.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-01-14 10:12:15 +01:00
Jiahao Li 5b9d5a217c Bluetooth: Fixes length limit in bt_hex_real
Since `str` is the output buffer, `bt_hex_real` should limit its output
length according to the `str` size, not the `hex` size.

Signed-off-by: Jiahao Li <reg@ljh.me>
2019-01-13 23:19:30 +02:00
Jukka Rissanen a7afdc3512 net: rpl: Remove the deprecated code
The RPL was deprecated earlier so remove it by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-13 09:40:36 -05:00
Paul Sokolovsky c885cb533e net: buf: linearize: Get rid of useless memset()
net_buf_linearize() used to clear the contents of output buffer,
just to fill it with data as the next step. The only effect that
would have is if less data was written to the output buffer. But
it's not reliable for a caller to rely on net_buf_linearize() for
that, instead callers should take care to handle any conditions
like that themselves. For example, a caller which wants to process
the data as zero-terminated string, must reserve a byte for it
in the output buffer explicitly (and set it to zero).

The only in-tree user which relied on clearing output buffer was
wncm14a2a.c. But either had buffer sizes calculated very precisely
to always accommodate extra trailing zero byte (without providing
code comments about this), or arguably could suffer from buffer
overruns (at least if data received from a modem was invalid and
filled up all destination buffer, leaving no space for trailing
zero).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-12 15:24:29 -06:00
Jiahao Li 6a5623566e Bluetooth: Mesh: Fixes existing friend lookup in Friend Request handling
Currently, when handling a Friend Request message with `prev_addr` set,
we look up existing friend entry using `prev_addr` as the address.
However, `prev_addr` is the address of the requesting node's previous
friend, NOT the address of the requesting node itself. Therefore, we
should always look up existing friend entry using `rx->ctx.addr` as the
address.

Signed-off-by: Jiahao Li <reg@ljh.me>
2019-01-12 22:07:41 +02:00
Johan Hedberg a886229c2b Bluetooth: shell: Fix incorrect indentation
This line was indented using four spaces instead of a tab.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-11 15:27:38 +02:00
Björn Stenberg d4ef80ec57 net: tcp: Release connect() semaphore if connection is refused
Connecting to a non-open port causes connect() to hang forever.
This patch releases connect() to return error to the caller.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2019-01-10 12:32:17 -05:00
Mark Ruvald Pedersen 076fd6a32a bluetooth: controller: Document mem, memq, util
Adds documentation-commentary to some infrastructure used by the LL.
It is a long-term effort to better document the LL.

Notably ticker and mayfly require more documentation; this will be
done later.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-01-10 18:00:41 +01:00
Krzysztof Chruscinski 4e32721135 logging: Add buffer flushing on entering panic
It may happen that panic occured while logger backend
was formatting output data. In that case output buffer
could get corrupted as logger assumes that processing
happens in one context only (panic is the only exception).

Added log output buffer flushing on entering panic state.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-10 07:27:14 -05:00
Wenjie Xu ce43d428c0 Bluetooth: shell: Fix NULL shell context
On bt_ready, ctx_shell would be NULL if not initialized before
bt_enable.

Signed-off-by: Wenjie Xu <xuwenjie@huantengsmart.com>
2019-01-10 11:56:07 +01:00
Martin Schwan c5de716af4 net: mqtt: Fix typo "seg_tag_list"
Fix a typo in the mqtt_sec_config struct where it was "seg_tag_list"
instead of "sec_tag_list".

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
2019-01-10 11:30:33 +02:00
Piotr Mienkowski 03eaafddfd logger: add a SWO backend
This commit adds Serial Wire Output (SWO) logger backend. SWO is an
extension of Serial Wire Debug (SWD) port developed by ARM.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-01-09 15:30:59 +01:00
Aurelien Jarno 7f334c84d6 usb: cdc_acm: call the IRQ callback from the system work queue
The IRQ callback function of the USB CDC ACM driver can currently be
called from:
- the USB thread when a bulk in or a bulk out interrupt has been
  triggered
- the thread calling cdc_acm_irq_rx_enable or cdc_acm_irq_tx_enable when
  enabling the interrupt fires an irq (ie if there is data to read or if
  there is no pending data to send)

This causes some issues with at least the shell uart backend, as the
IRQ callback function ends up being called twice concurrently in case a
USB driver sends the requested data almost instantaneously. This is the
case for example of the USB nRF driver which uses DMA. In turn this
cause ring_buf_item_get to be called concurrently, leading to data
corruption:

  uart:~$ help
  Please press the <Tab> button to see all available commandands.
  You can also use the e <Tab> button to prompt or auto-coomplelete all
  commands or its subcommands.
  You can try toto call commands with <-h> or <--help> parameter for
  more informatation.
  uart:~$

Fix that by always calling the IRQ callback function through the system
work queue.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-09 07:47:43 -06:00
Andrzej Puzdrowski 493ae365a8 settings: fix value-len-get while base64 is enabled
While base64 encoding was enabled settings_val_get_len_cb() returned
encoded length instead of decoded value length.

This patches introduce procedure which calculates the value length
properly. For that additional read of the end of the encoded value is
required for checking how many form last 3 value bytes wear encoded.

fixes #12122

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-01-09 08:40:00 -05:00
Tomasz Bursztyka b04e71901f net/icmpv4: Disable broadcast echo request reply by default
Accepting broadcast echo request and replying to it could provide an
attack vector.

Fixes #12162

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-08 13:42:18 +02:00
Oleg Zhurakivskyy 20ee76ab22 net: ethernet: Clean an obscure ref/unref logic in ethernet_send()
Do not extra ref and then obscurely unref the packet inside
the statistics update function.

Actually, this extra ref/unref isn't needed here at all.

The packet is unreferenced only on a successful send, statistics
updating can be done before the unref in a clean and understandable way.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-01-08 13:39:40 +02:00
Tomasz Bursztyka dc9e408e22 net/ieee802154: Compute ll hdr size before 6lo compression
Or then the IP header access will be bogus afterwards.

Fixes #12154

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-08 13:36:14 +02:00
Jukka Rissanen 235ebd0ca0 net: gptp: Track memory allocations better
Try to catch the original caller of setup_gptp_frame() function
in order to see who is allocating buffers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-08 13:29:18 +02:00
Jukka Rissanen 69f849235f net: pkt: Only enable debug print when really needed
The NET_LOG_LEVEL is enabled also when allocation debugging is
enabled but when net_pkt debugging is not. Thus we need to use
the CONFIG_NET_PKT_LOG_LEVEL when printing normal debug log
prints.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-08 13:29:18 +02:00
Paul Sokolovsky 3329eb2c4e net: pkt: net_frag_linearize: Make consistent with net_buf_linearize
net_frag_linearize() is just a wrapper for net_buf_linearize(). As
the latter was refactored to never return error, and instead just
return actual copied length, update the former and its usages too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Paul Sokolovsky 71e2e31a76 net: buf: linearize: Never return -ENOMEM, just do what user asked to
Don't try to find "errors" in the values of dst_len and len params
passed to net_buf_linearize(). Instead, do what entails with the
common sense from the values passed in, specifically:

1. Never read more than dst_len (or it would lead to buffer
overflow).
2. It's absolutely ok to read than specified by "len" param, that's
why this function returns number of bytes read in the first place.

The motivation for this change is that it's not useful with its
current behavior. For example, a number of Ethernet drivers linearize
a packet to send, but each does it with its own duplicated adhoc
routine, because net_buf_linearize() would just return error for the
natural use of:

net_buf_linearize(buf, sizeof(buf), pkt->frags, 0, sizeof(buf));

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Frank Li 978bdf0d5d net: shell: Fix cmd_net_http_monitor build error
No declar 'count',Enable CONFIG_NET_DEBUG_HTTP_CONN will build error.

Using http_monitor_count replace count.

Fixed #12329

Signed-off-by: Frank Li <lgl88911@163.com>
2019-01-07 16:24:32 -05:00
Frank Li 6b5906b8e9 net: shell: Fix showing ping reply
shell_fprintf() doesn't work in callback handlers.
To fix that, set shell state to SHELL_STATE_COMMAND before using it.

Fixed: #12347

Signed-off-by: Frank Li <lgl88911@163.com>
2019-01-07 16:07:31 -05:00
Jan Van Winkel 8fb4384927 dfu: Cast offset to u32_t before calling LOG
Cast offset to u32_t before printing in hexadecimal form.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-01-07 16:07:03 -05:00
Flavio Ceolin f342019986 log: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-01-07 08:52:07 -05:00
Vinayak Kariappa Chettimada dfe415a912 Bluetooth: shell: Changes related to controller split preparation
Changes to Bluetooth shell application related to the
controller split architecture preparation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-07 13:42:01 +01:00
Vinayak Kariappa Chettimada 87fe440f01 Bluetooth: controller: Prepare to introduce LL split architecture
Preparation to introduce the Upper Link Layer (ULL) and
Lower Link Layer (LLL) split architecture.

- Move SoC dependent HAL to vendor specific folder.
- Preparation to split data structures into ULL and LLL
  types.
- Added more role and state conditional compilations.
- Added some work-in-progress implementation of advertising
  extensions, will be used as inspiration in the new split
  architecture work.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2019-01-07 13:42:01 +01:00
Johan Hedberg d57a9a648b Bluetooth: Mesh: Fix heartbeat publication storing
This fixes usage of an uninitialized variable (to_store) as introduced
by commit bfad2a0.

Fixes #12314

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Johan Hedberg 3d0950e59a Bluetooth: Mesh: Fix typo leading to incorrect settings storage
This was intended to be an equality comparison and not an assignment.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-07 12:49:36 +02:00
Jan Van Winkel 3034dc7dab settings: Corrected type for offset variables
Changed type of offset variables from off_t to size_t as expected
by called functions.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-01-07 11:48:35 +01:00
Aurelien Jarno e98e6a8a87 net: openthread: remove one subcommand level in shell
Currently OpenThread commands have to be prefixed in the shell by "ot
cmd", for example "ot cmd state". With the new shell, it is possible to
remove one subcommand level and change it to "ot state".

At the same time validate the number of arguments using
SHELL_CMD_ARG_REGISTER and improve the help message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Aurelien Jarno ac3ff65a91 net: openthread: improve shell output
Following the introduction of the new shell, the OpenThread shell
wrapper is not well integrated. It outputs the answer to a command using
printk(), which is not necessarily using the same device than the shell
if "zephyr,console" does not match "zephyr,shell-uart".

OpenThread calls the otConsoleOutputCallback() function to output the
answer to the shell. It can provide a callback argument, but defined
when OpenThread is initialized, not when the command is submitted.
Workaround that by taking a copy of the shell argument in a static
variable and use it for the call to shell_fprintf(). It is not perfect
if two or more shells issue concurrent commands, but is already an
improvement compared to printk().

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Tomasz Bursztyka e82e31e351 net/icmpv4: A checksum value of 0 is valid
Introduced by commit id de78a7af28.
If the sum is 0xffff, a ~sum will give 0.

Fixes #12164

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-04 10:46:52 -05:00
Andrei Emeltchenko eb6601e5f0 net: logs: Enable logging for NET_RAW
The patch allows to enable logs for NET_RAW configuration.
For example using wpanusb currently breaks build with logging enabled.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-01-03 12:33:54 -05:00
Luiz Augusto von Dentz 80bc21e03c Bluetooth: GATT: Fix warning when attempting to use read callback
When using bt_gatt_discover with BT_GATT_DISCOVER_CHARACTERISTIC the
read callback would be set to bt_gatt_attr_read_chrc which would attempt
to access the next attribute which in this case would not be set since
the value attribute is no fetched by the discovery, the spec actually
omit the value handle saying it should always be the first attribute to
appear after the characteristic thus we can assume it to be handle + 1.

Fixes #12159

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-03 12:12:10 +01:00
Aurelien Jarno d3b6c5a755 net: coap: return -EPERM for a resource without requested method
When walking through the coap resources in coap_handle_request, return
-EPERM if a resource exists but does not have the request method. This
allows the caller to catch the error and return a 4.05 message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:04:46 +01:00
Aurelien Jarno 9e8bb61009 nvs: workaround a GCC and Coverity warning
Following the recent NVS changes, the following warning now appear with
GCC 7.3 when building with -O2:

ZEPHYROOT/subsys/fs/nvs/nvs.c: In function 'nvs_reinit':
ZEPHYROOT/subsys/fs/nvs/nvs.c:92:36: warning: 'addr' may be used
uninitialized in this function [-Wmaybe-uninitialized]
  offset += fs->sector_size * (addr >> ADDR_SECT_SHIFT);
                              ~~~~~~^~~~~~~~~~~~~~~~~~~
ZEPHYROOT/subsys/fs/nvs/nvs.c:606:8: note: 'addr' was declared here
  u32_t addr;
        ^~~~

This was already reported by Coverity earlier as CID:187903.

In practice this can only happen if fs->sector_count equals 0, which is
not possible as checked in nvs_init(). At least in the GCC case, it
believes that k_mutex_lock(&fs->nvs_lock, K_FOREVER) could modify
fs->sector_count.

Workaround the issue by initializing addr to 0.

Fixes #9767

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:03:09 +01:00
Aurelien Jarno a169d90667 nvs: avoid reading multiple times the same area
The current NVS code checks for an empty ATE using th
_nvs_flash_cmp_const() function. This function loads the data and
compare them to a value. This means that when executed multiple on the
same area, the data get reloaded multiple time. This might have a
noticeable performance impact with an SPI flash.

Instead define a function _nvs_ate_cmp_const to compare an already read
struct nvs_ate with a constant value. Then replace the calls to
_nvs_flash_cmp_const() on struct nvs_ate by _nvs_flash_ate_rd() followed
by _nvs_ate_cmp_const(). This also has the advantage of explicitly
checking for errors instead of testing the error and the result of the
comparison at the same time.

Tested on a Nucleo L432KC board with the nvs sample. The maximum
initialization time (ie just before running the first garbage collector)
goes down to 6213 µs from 7350 µs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:03:09 +01:00
Sebastian Bøe 0438657193 kconfig: Have the 'framebuffer' menu depend on it being enabled
As this was written before, a 'Framebuffer' menu entry was present,
and to see what kind of features or configuration it had, one had to
navigate into the menu to determine if anything related to
'Framebuffer' was enabled at all.

Now there is an unchecked box on the 'framebuffer' menu when it is
disabled, which clearly expresses that it is disabled without the need
to enter the menu entry.

This change only changes the menu layout, and not the dependencies of
any options.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-30 16:24:50 -05:00
Savinay Dharmappa 0fb1a8a836 usb: class: dfu: Add a worker thread to flash data from usb to flash
The bulk of implementation in the current DFU arch is done in the ISR.
This works well when the Flash device is memory mapped as these writes
get done comparatively quickly. However, in case of platforms where
the flash device is sitting on the SPI Bus, this was observed to
cause an exception. This exception may be because there are multiple
function calls consuming larger processing time inside the ISR. The
ISR stack may also end up going deeper and risk stack corruption on
devices with low RAM. To resolve this, we deferred flash write to a
worker thread. Also, some handshaking was added to have synchronization
with the host in accordance with the Host-Device DFU protocol.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-12-30 16:24:33 -05:00
Savinay Dharmappa b9b8daa3bc samples: subsys: usb: dfu: Fix build error for intel_s1000
intel_s1000 uses DT_SPI_NOR_DRV_NAME instead of DT_FLASH_DEV_NAME
for device binding of flash device.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-12-30 16:24:33 -05:00
Yannis Damigos 33f1951c9d crc: Move crc7 into CRC single header
Move crc7 into CRC single header

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-12-30 16:24:10 -05:00
Yannis Damigos 6c1af0e090 disk: disck_access_sdhc: Switch to new SPI API
Replace legacy API calls by news ones.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-12-30 16:24:10 -05:00
Yannis Damigos 937592ead8 disk: disk_access_sdhc: Enable multiple disk interfaces
Enable multiple disk interfaces for SDHC.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-12-30 16:24:10 -05:00
Yannis Damigos b28cd8a141 disk: disk_access_sdhc: Move to new logger subsystem
Move to new logger subsystem.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-12-30 16:24:10 -05:00
Michael Hope 42accf2e64 disk: add a SDHC card over SPI driver.
Features:

- Uses the SPI bus to communicate with the card
- Detects and safely rejects SDSC (<= 2 GiB) cards
- Uses the optional CRC support for data integrity
- Retries resumable errors like CRC failure or temporary IO failure
- Works well with ELMFAT
- When used on a device with a FIFO or DMA, achieves >= 310 KiB/s on a
  4 MHz bus

Tested on a mix of SanDisk, Samsung, 4V, and ADATA cards from 4 GiB to
32 GiB.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-12-30 16:24:10 -05:00
Flavio Ceolin 6bed8fc241 shell: Changing shell_history_get signature
Change arg_len to be u16_t in shell_history_get since it is returning
a value that can be hold by u16_t.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Flavio Ceolin 80c03550ba shell: Make shell_strlen return u16_t
Everywhere the return of this function was being assigned to u16_t to
save space on stack. Instead of casting in all these places (and may
end up with overflow), just changing this function's return.

Note that the function itself is not checking for overflow yet since
I'm not sure this can happen and/or is a problem. Though now we have
only one single point to fix this problem.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Flavio Ceolin bc4cb76df5 shell: Fix return error in shell_execute_cmd
ENOEXEC should be used for executable file format error.
While is undertandable return it when the command is wrong, this
function is returning it two cases where other errors are more
descriptive. When parameter is NULL, is better return EINVAL.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-28 17:47:46 -05:00
Anas Nashif 74a74bb6b8 power: rename api sys_soc -> sys_
sys_soc is just redundant, just call APIs with sys_*.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-28 16:16:28 -05:00
Anas Nashif 9151fbebf2 power: rename APIs and removing leading _
Remove leading underscore from PM APIs. _ was used for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-28 16:16:28 -05:00
Krzysztof Chruscinski 16e7e82af8 shell: Fix code style errors in shell.c
Fixed errors and warnings reported by checkpatch.pl

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-28 10:42:06 -05:00
Krzysztof Chruscinski d653a5182c shell: Allow calling shell_fprintf from various contexts
Extended shell to allow command to indicate that shell should
halt not accepting any input until termination sequence is
received (CTRL+C) or shell_command_exit() is called. While shell
is in that state it is allowed to print to shell from any thread
context.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-28 10:42:06 -05:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Laczen JMS bebdf2a479 fs/nvs: Speed Improvement
NVS with modified flash layout. At the end of a sector a special ate is
placed that points to the last ate that was written. This special ate
is written when a sector is closed. This allows nvs to travel through
the fs much quicker as it doesn't have to search for the last ate in
a sector.

This modification also speeds up the nvs_init procedure that was very
slow on external (spi) flash.

Remark: As the layout of data in flash is changed old data in the flash
cannot be recovered. It is advised to erase the nvs flash area before
using the changed nvs.

Modification after review by @nvlsianpu applied

Modification after review by @aurel32:

_nvs_prev_ate(): provide a backup search of a valid ate when the sector
close_ate has a bad CRC8. Tested on nrf81522 by making flash writing
bad data to the sector closing ate. Also validated that if a valid ate
is overwritten the filesystem keeps working.

_nvs_gc(): return error if _nvs_flash_cmp_const() is < 0.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2018-12-23 12:23:25 +01:00
Flavio Ceolin 1036edcfbb log: Fix switch statement
MISRA-C has several rules about switch statements like each clause
end with an unconditional break. This commit fix these problems to
be in accordance with the standard.

MISRA-C rules 16.1, 16.3 and 16.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-21 21:06:18 +01:00
Tomasz Gorochowik 754ab1d1b0 net/pkt: Fix debug logs checking
The slab2str function which is used in the debug log call is not defined
unless NET_LOG_PKT_LOG_LEVEL >= LOG_LEVEL_DEBUG.

It looks like this change was accidentally introduced in #11374.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-12-21 21:00:54 +01:00
Martin Turon 6410a16adb openthread: Update openthread version to latest upstream/master.
Update zephyr integration of openthread to latest api as of 2018-12-17:

2a75d30684

Both echo_server and echo_client compile and are operational.

Signed-off-by: Martin Turon <mturon@google.com>
2018-12-20 12:24:51 +01:00
Paul Sokolovsky 2ffb951630 console: Kconfig: Update for recent changes
Buffer sizes aren't required to be power of 2 for a while. Describe
that by setting buffers sizes to 0, one can get non interrupt driven
operation.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-20 12:21:49 +01:00
Paul Sokolovsky 0925411356 tty: Remove buffer params from tty_init()
Let's have more orthogonal and cleaner API, where buffers are
configured by tty_set_rx_buf/tty_set_tx_buf, and only them. It
means that newly initialized tty starts in unbuffered mode, which
is somewhat a sidestep from a main usecase behind tty, which is
buffered operation, but again, having a cleaner API (and good
docs, explaining users how it should be and what they should do)
prevails.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-20 12:21:49 +01:00
Paul Sokolovsky a7df3a1e09 tty: Support unbuffered operation to extend usecase coverage
The whole "tty" concept is conceived around efficient
interrupt-driven operation. However, it's beneficial to add
non interupt-driven operation under the same API:

1. Wider usecase coverage in general.
2. Allows to use the same familiar API (based on POSIX concepts)
even for UART implementations without interrupt support.
3. Allows to switch operation dynamically based on the needs.
For example, if the system is in degraded mode and interrupt
handling cannot be trusted/disabled, allows to still output
diagnostic information to user. This was the original motivation
to provide such a mode, to support logging subsystem's "panic"
mode.

To implement this feature, tty_set_rx_buf() and tty_set_tx_buf()
functions are provided, allowing to reconfigure buffers used
dynamically. If configured buffer length is 0, the operation
switched to unbuffered.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-20 12:21:49 +01:00
Krzysztof Chruscinski 1cc9e98ae6 logging: Refactor RTT backend to handle host absence
Refactored blocking operation of RTT backend. Log_output buffer
is used directly in case of blocking operation. Detection of
host presence added. Prevent use of RTT lock when in panic mode.
Removed pending on data being read by the host on every message.

Refactor gives savings of 300 bytes in ROM and 120 bytes in RAM.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:53:48 +01:00
Vinayak Kariappa Chettimada 99ae80b632 Bluetooth: controller: Fix Conn Param Req procedure stall issue
Fix an issue wherein local or remote initiated Connection
Parameter Request procedure would stall without generation
of LE Connection Update Complete HCI event because a local
or remote initiated PHY Update procedure has overwritten the
currently active Link Layer Control Procedure type.

Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa@gmail.com>
2018-12-19 14:47:38 +01:00
Flavio Ceolin 27435e4cb3 log: Explicitly ignoring return of memcpy
According with MISRA-C the value returned by a non-void function has
to be used. As memcpy return is almost useless, we are explicitly
ignoring it.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-19 14:37:25 +01:00
Krzysztof Chruscinski b467de5849 shell: Add dropping of expired messages
Log message get timestamp when being added to shell log message queue.
When adding to log message queue timeouts then all messages added
before timeout are dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:37:00 +01:00
Krzysztof Chruscinski 08f0d93cbb shell: Improve handling of log messages
If burst of log messages was passed to the shell log
backend, it was likely that messages were lost because
shell had no means to control arrivals of log messages.

Added log message enqueueing timeout to the shell instance
to allow blocking logger thread if short-term arrival rate
exceeded shell capabilities.

Added kconfig option for setting log message queue size
and timeout in RTT and UART instances. Added section in
shell documentation which explains interaction between
the logger and shell instance acting as a logger backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:37:00 +01:00
Marcin Szymczyk 801b54edb9 usb: hid: boot protocol
Set_Protocol and Get_Protocol requests are handled now.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-19 07:36:18 -06:00
Jakub Rzeszutko f0b19181e0 bt_shell: fix command bt advertise valid argument count
Changed number of valid arguments from two required to
one required and one optional.

Command can be called with required <type: off, on, scan, nconn>
and optional <mode: discov, non_discov>".

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-18 18:52:00 +02:00
Krzysztof Chruscinski fcc7240fbe logging: Add handling of dropped messages to native POSIX backend
Extended native POSIX backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 31a90ca592 logging: Add handling of dropped messages to RTT backend
Extend RTT backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 1edf09e17a logging: Add handling of dropped messages to UART backend
Extend UART backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski a7568e4a6a logging: Handle dropped messages in log_output
Extended log_output interface to handle dropped
messages. Log_output is printing a message containing
number of dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Jakub Rzeszutko cab9fa35ad shell: fix tab key functionality.
Fixing commit:#7ad59c84c84e8b7ea3c0438ff01c8a6343e65812

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-18 12:42:29 +01:00
Aurelien Jarno a1c3b0aad3 usb: fix CDC ACM breakage with CONFIG_USB_DEVICE_SOF
Commit e4c447aac3 ("usb: add SoF event") added support for calling the
status callback with the USB_DC_SOF value for each SoF when
CONFIG_USB_DEVICE_SOF is enabled. The CDC ACM driver saves the latest
received status and compares it USB_DC_CONFIGURED to decide if it can
send data to the host. This therefore doesn't work any more when the
status callback is called regulary with USB_DC_SOF.

Fix that by ignoring USB_DC_SOF when saving the latest received status.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-17 08:16:49 -06:00
Jakub Rzeszutko 956b00388f shell: fix execute command when help not active
When help functionality is not compiled and command is called with
-h or --help option shell will now either pass this option as
an argument or it will print a message that command does not have
a handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko f7f4fe33a1 shell: static functions cleanup
Removed shell_ prefix from static functions in .c files.
Added static functions for setting and getting shell
internal flags.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko 4d491b283b shell: remove obsolete \r characters
shell parses output string and it adds \r for each found \n.
It is no longer needed to keep \r for each shell message.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Jakub Rzeszutko 7ad59c84c8 shell: minor shell source cleanup
Cleanup in shell.c file.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-17 11:31:22 +01:00
Robert Lubos e8620e2cca ext: mbedtls: Unify mbedTLS Kconfig prefixes
Currently there is a mixed approach in prefixes from mbedTLS
configuration (MBEDTLS_ and TLS_). The latter was used in generic config
file and could bring up confusion that it can only be used with TLS
subsystem. Hence unify the approach to MBEDTLS_ prefix to avoid such
confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-17 11:27:02 +01:00
Tomasz Bursztyka 7f8d92827f net/ethernet: Remove usage of net_pkt_ll() function
This function is planned to be removed, thus avoiding its usage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 91a9994aaf net/ieee802154: Remove usage of net_pkt_ll() function
This function is planned to be removed, thus avoiding its usage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka c8d26f845a net/l2: Finally get rid of reserve concept from L2
Now that net core does not use ll reserve, it can be nuked from L2.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 6ea225e34a net/ieee802154: Finally removing usage of ll_reserve in L2
Moving towards serialized fragmentation, adapting mac command creation
to avoid the need of ll_reserve etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka f923d2cb1e net/ieee802154: Serialize packet fragmentation
This will permit to avoid the need for ll_reserve.
It also removes net_buf allocation and deletion, as it works per-frame.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 57a0c55dac net/6lo: Remove fragmentation function parameter on compression
Fragmentation has nothing to do with 6lo. Up to the bearer to do so.

This change is required for futur serialization of 15.4 fragmentation.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 66cc034a34 net/ipv6: Remove any use of ll reserve
As this is now unnecessary, let's ignore that and use 0 instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 156213078d net/ipv4: Remove any use of ll reserve
As this is now unnecessary, let's ignore that and use 0 instead.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 0873f8fb20 net/pkt: Let's ignore ll reserve and use 0 instead
ll reserve is of no use as the l2 is allocating what it needs for
filling in its header.

This is another step forward to removing ll reserve concept.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 01a5238ee8 usb/netusb: Let's remove the use for ll reserve
It's useless now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka bff65b6330 net/ethernet: Let's remove the use for ll reserve
There is no need to reserve any space for each frag, as the l2 will
allocate a frag for the ethernet header, arp will do the same.

This is one step further to removing the concept of ll reserve.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Marcin Szymczyk c6d5d09d70 usb: hid: allow hid_ops to be null
Allows for hid_ops argument in usb_hid_register_device() to be NULL.
In that case, application does not implement any custom callbacks.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-14 13:19:04 +01:00
Varun Sharma 3d9213ac57 tests: subsys: fs: multifs: Enable fs shell using new shell
Fixes #11356, resolved compilation issue wrt to NFFS_FLASH_DEV_NAME

Enabled new shell implementation for testing fs shell

Signed-off-by: Varun Sharma <varun.sharma@intel.com>
2018-12-14 13:14:17 +01:00
Jukka Rissanen 139aab2975 net: pkt: Show buffer allocations only when needed
The net-shell "net allocs" command should print network buffer
allocations even if network packet debugging is not enabled.
This is how it used to work earlier but the behaviour got lost
at some point. So user needs to set CONFIG_NET_DEBUG_NET_PKT_ALLOC
in order to see the buffer allocations. The option will be enabled
by default if network packet log level is set to DBG.
The reason for a separate option is that the network packet debug
logging prints just too much data and it is very difficult to
track allocations when that happens.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:49:04 +02:00
Paul Sokolovsky 8a65f68a48 net: sockets_tls: Typo fix in comment
s/DLTS/DTLS.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 13b38ed686 lib: fdtable: Change ioctl vmethod signature to take va_list
As extend fdtable usage to more cases, there regularly arises a need
to forward ioctl/fcntl arguments to another ioctl vmethod, which is
complicated because it defined as taking variadic arguments. The only
portable solution is to convert variadic arguments to va_list at the
first point of entry from client code, and then pass va_list around.

To facilitate calling ioctl with variadic arguments from system code,
z_fdtable_call_ioctl() helper function is added.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 94007da116 net: sockets: Rework fcntl() dispatching to the underlying fd object
fcntl operations are implemented using ioctl vmethod.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Jukka Rissanen bafa802657 net: gptp: Calculate the link delay same way as Avnu/gptp
Make sure that the link delay (propagation time) is calculated
same way as how Avnu/gptp is doing it with checks for rate ratio.
This is done like this in order to behave same way as their gptp.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Jukka Rissanen 11bb406332 net: gptp: Add debug print if a gptp packet cannot be created
This is useful info as otherwise we get no indication to user
if the packet is not created and not sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Jukka Rissanen 5a56900b07 net: gptp: Make sure that neighbor_rate_ratio cannot be 0
Neighbor rate ratio cannot be 0 as that would mean 0 packet
delivery time which is not plausible.
Add also some debugging to print current neighbor propagation
delay value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-14 13:13:15 +02:00
Krzysztof Chruscinski dc2ab4d74f bluetooth: Simplifying log macros
Function name prefix is now configurable (by default only debug
messages are prefixed) and log macros can be simplified.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Krzysztof Chruscinski 0899a6c0b7 logging: severity-wise filtering of function name prefix presence
Extended logger configuration to allow function name prefix for
messages with certain severity levels. By default only debug
messages are prefixed with function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Krzysztof Chruscinski aa19fd9298 logging: Fix allocation of single chunk log messages
Generic log message allocator was wrongly allocating single
chunk messages as initially it was intended to allocate only
multichunk messages. It resulted in invalid pointer being freed
on log message free. Issue detected by valgrind.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 12:46:29 +01:00
Andrzej Puzdrowski 523acef71c settings: fix key-value duplication check
Whenever a new key-value is about to be stored, the settings
perform check whether the value really changes. This check
after #9521 patch should work differently as `\0` is not
the value terminator anymore. Because of above any value which
starts from \0 will be treated mistakenly as a NULL.

This patch uses check-length callback instead read-callback which
fix the issue and simplify the code a little.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-12 12:51:12 +01:00
Alberto Escolar Piedras fc0f80391c Bluetooth: nordic ECB hal: Bugfix for simulation
Fix in the do_ecb() function
In real HW this function busy waits for the ECB to be done.
In simulation with the POSIX arch a WFE was added to avoid that
infinite loop.
But this function is called with the ECB interrupts disabled.
In normal builds other interrupts will awake the CPU very soon
after entering into that WFE, and the problem was not discovered.

But, in controller only builds, during some conformance tests,
the loop will hang as no other interrupts are coming.

=> Replace the WFE() with a k_busy_wait (only for simulation)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-12-12 12:12:04 +01:00
Vinayak Kariappa Chettimada afbbb97ab1 Bluetooth: controller: Fix chan map update's diff trans collision
Fix channel map update procedure implementation's handling
of different transaction collision by not asserting but
disconnecting the connection due to invalid behavior by
peer implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-12 12:05:05 +01:00
Johan Hedberg fc29dd8c8f Bluetooth: Mesh: Fix confusing language in log messages
Both "store" and "clear" are verbs, so putting them after each other
is just confusing. Use "clean" consistently when clearing settings
entries.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Johan Hedberg ed3c2cd38a Bluetooth: Mesh: Fix missing log_strdup() for logging
Several non-persistent strings were being logged without log_strdup().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-12-11 16:58:36 +02:00
Jukka Rissanen e41fd1ddf9 net: gptp: Update pdelay req lost counter when needed
The pdelay_allowed_lost_resp_exceed_count was updated even if we
had received pdelay response.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-11 16:38:12 +02:00
Tomasz Bursztyka 2d38c915d0 net/icmpv4: No need of a local variable
Result can be tested right away.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka d943554df6 net/icmpv4: Avoid input function to access IPv4 header again
IPv4 can pass the broadcast information.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka cb5d1108d9 net/ipv4: Rework ipv4 processing to clarify drop issues
All IPv4 destination address related drop reasons in one place.
This helps also to have one unique call of net_conn_input().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka fc09921b82 net/ipv4: Use existing hdr pointer to get ttl value
Header is already accessible via a local varialbe so let's use it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka 8fae4fc620 net/ipv6: Have a unique call for net_conn_input()
As for IPv4, net_conn_input() can be called at one place for udp/tcp.
It will anyway check if given protocol is enabled so no need to check
such support here.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Tomasz Bursztyka bd23754387 net/icmpv6: Refactoring ICMPv6 input end-point
It was weird to pre-parse ICMPv6 headers in IPv6. Moreover parsing
failure of such header would not generate the right statistic.

Instead, centralizing all into net_icmpv6_input relevantly, and adapting
the test cases which were using that function. In RPL test, removing the
dummy dio test was simpler since dio is anyway tested later on.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-11 15:49:45 +02:00
Jukka Rissanen e21d7cc72d net: gptp: Refactor the gPTP header addition
Increase the net_buf length in proper places. So when gPTP
header is added, increase the buf->len properly, and then
when gPTP packet type is added, increase it again properly.
This way the net_buf length is updated in more logical way.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-11 13:50:54 +02:00
Andrzej Puzdrowski bfad2a0cbf bluetooth: host: mesh: align code to reworked settings
The code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski bfb60743d5 bluetooth: host: align code to reworked settings
The Code need to be align after introduction of stream codec to
setting serialization subsystem.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski c2e7847daa bluetooth: common: Add BT hexdump
Added BT alisa for dumping binary data to the logg.
The macro will be useful for BT as reworked settings supports r/w of
raw data - which will be widely leveraged in bluetooth storage alignment
to reworked settings.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski cb92c95aab settings: add delete key-value pair API
So far to deleting av existing key-value pair it was
required to storing NULL value using setting_save_one().
This patch introduce more intuitive API which takes only
the name key string.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski e5a09ccb3e settings: add API for check value size
Such API is convinient for check the persistent storage
value size or whether the value is NULL.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski 63961e36a1 settings: make base64 encoding optional
Thanks to previous commit base64 encoding of the settings
value is not required anymore for NFFS and FCB back-end.

This patch makes encoding an option in case it will be required
in the future.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski 76f8b97871 subsys/settings: stream-style encoding and decoding to/from storage
This patch reworks routines used to store and read the settings data.
Provide stream-style encoding and decoding to/from flash, so the the
API only requires a pointer to binary data, and the settings
implementation takes care of encoding/decoding to/from base64 and
writing/reading to/from flash on the fly. This would eliminate the
need of a separate base64 value buffer on the application-side, thereby
further contributing to the stack footprint reduction.

Above changes allows to remove:
  256-byte value length limitation.
  removing enum settings_type usage so all settings data are treated
  now as a byte array (i.e. what's previously SETTINGS_BYTES)

Introduced routine settings_val_read_cb for read and decode the
settings data from storage inside h_set handler implementations.
h_set settings handler now provide persistent value's context
used along with read routine instead of immediately value.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Jan Van Winkel 6f42904185 drivers: Clear SSD1673 display during display init
Clear SSD1673 display during display driver initialization instead of
triggering clear via setting contrast.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2018-12-10 17:21:37 -05:00
Jan Van Winkel 7bd108b0e9 cfb: Set dimensions in character framebuffer
Set width, height and pitch dimensions in character framebuffer before
calling display write API.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2018-12-10 17:21:37 -05:00
Ruslan Mstoi a2a7459f23 net: shell: Update info to enable allocs
If relevant configs are not enabled shell allocs command would print
wrong info:

"Enable CONFIG_NET_DEBUG_NET_PKT to see allocations"

CONFIG_NET_DEBUG_NET_PKT is obsolete and an undefined symbol, setting it
causes cmake to fail. This patch fixes this issue by printing up-to-date
information on how to enable allocs command

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-12-10 18:00:01 +02:00
Vinayak Kariappa Chettimada 5e7c916e77 Bluetooth: controller: Fix CPR procedure regression
This fixes regression introduced in commit a11868fea9.

Fixes the following conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request -
Preferred Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request -
Preferred Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-10 11:13:48 +01:00
Robert Lubos ee0b61fff8 net: sockets: Rework poll to support ioctl helper commands
This commit reworks socket poll implementation to support multiple
socket implementations.

To achieve that, two ioctl poll helper requests were added:
ZFD_IOCTL_POLL_PREPARE and ZFD_IOCTL_POLL_UPDATE. The poll
implementation calls ioctl with these requests for each socket
requested in the fds table.

The first request is responsible for preparing k_poll_event objects
for specific socket. It can request to skip waiting in k_poll by
returning EALREADY through errno.

The latter request is responsible for processing outcome of k_poll for
each socket. It can request to retry the k_poll by returning EAGAIN
through errno.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos 31ab8d061d net: sockets: tls: Implement vtable for TLS sockets
Implement extended socket vtable for TLS sockets, therefore allowing to
integrate the implementation with socket subsystem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos df8693af64 net: sockets: Extend socket vtable
This commit extends socket vtable, allowing to redirect socket calls to
alternate implementations (e.g. TLS sockets).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Diego Sueiro 20e4567bab shell: Add initial code for Character Framebuffer shell module
This adds the config option and files of the Character Framebuffer
shell module

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-07 10:21:02 -05:00
Diego Sueiro 72981ea31a subsys/fb/cfb: Introduce cfb_get_numof_fonts function
Adds the cfb_get_numof_fonts function to get the number of
available fonts

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-07 10:21:02 -05:00
Diego Sueiro 0ab9c46d86 subsys/fb/cfb: Introduce cfb_framebuffer_invert function
Adds the cfb_framebuffer_invert function to invert Pixels in the
Character Framebuffer

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-07 10:21:02 -05:00
Jukka Rissanen 2b268f8d3d net: gptp: state2str() func is only available if debugging
The state2str() function should only be used if debugging
is enabled thus add some pre-processor checks there.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen 3af324033e net: gptp: Add more debugging when changing state
Print function and line number when changing state and when
debugging is enabled. Otherwise it is a bit difficult to follow
the program logic and locate the state change operation.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen 83f38b5f2d net: gptp: Remove log_strdup() when printing packet info
As the msg parameter for PRINT_INFO() is always a const string
that is not coming from stack, there is no need to use
log_strdup() here. This helps to avoid the
"<log_strdup alloc failed>" messages.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen ff0483c5af net: gptp: Get the gPTP header properly
If the link layer header is in the separate net_buf,
then skip that one.

Fixes #11827

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:43:59 +02:00
Jukka Rissanen e812b6804a net: if: Make dst address const when selecting src addr
As the functions do not modify the destination address parameter,
it can be made const.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:18:24 +02:00
Tomasz Bursztyka 952e494bdd net/ethernet: Let L2 updating common rx/tx statistics
Common statistics should be updated in one centralized place and
ethernet_send is the right place for tx stats, as well as ethernet_recv
for rx stats.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-07 14:30:06 +02:00
Tomasz Bursztyka 76fa82f7ab net/icmpv6: Optimize how chksum is verified
Just recalculate the chksum without resetting its value to 0, and test
if return value is 0.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-07 13:50:46 +02:00
Jakub Rzeszutko f8178dcb05 shell: remove Console dependencies
Removed Console dependencies from shell uart backend.
Generated define: CONFIG_UART_SHELL_ON_DEV_NAME for each board.

Fixes #10191

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-07 12:11:11 +01:00
Vincent van der Locht 58463b7ea7 net: dhcpv4: dhcp start/stop made compatible for multiple interfaces
The net_dhcpv4_stop() function stops the event listener for any IF_UP
events previously. In case multiple interfaces are used and optionally
being switched over, it could result in disabling dhcp unintentionally.

The callback is initialized at the init function and added/removed in
the start/stop function based on the interface list being empty
or not. (first added, last removed)

The event handler checks if the interface is in the list before acting
on it.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:23:46 +02:00
Vincent van der Locht 994a4772ca net: dhcpv4: net_dhcpv4_stop() removing address during renew
In case "net_dhcpv4_stop(..) is called when the interface is
in NET_DHCPV4_RENEWING state, the address is not removed.
When deleting the address in the NET_DHCPV4_RENEWING state
means the status is always equal to the moment before _start
is called.

Signed-off-by: Vincent van der Locht <vincent@vlotech.nl>
2018-12-07 12:22:19 +02:00
Jukka Rissanen 301d342571 net: Move net_analyze_stack() function to net_core.c
No need to this function be inlined so move it to .c file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Anas Nashif 64aecd044f Revert "subsys/fb/cfb: Introduce cfb_framebuffer_invert function"
This reverts commit b6528469df.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-06 11:39:44 -05:00
Anas Nashif f8625ced84 Revert "subsys/fb/cfb: Introduce cfb_get_numof_fonts function"
This reverts commit c2c293a3e0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-06 11:39:44 -05:00
Anas Nashif 4e2c9d1491 Revert "shell: Add initial code for Character Framebuffer shell module"
This reverts commit 2e27113eec.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-06 11:39:44 -05:00
Diego Sueiro 2e27113eec shell: Add initial code for Character Framebuffer shell module
This adds the config option and files of the Character Framebuffer
shell module

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-06 09:55:15 -05:00
Diego Sueiro c2c293a3e0 subsys/fb/cfb: Introduce cfb_get_numof_fonts function
Adds the cfb_get_numof_fonts function to get the number of
available fonts

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-06 09:55:15 -05:00
Diego Sueiro b6528469df subsys/fb/cfb: Introduce cfb_framebuffer_invert function
Adds the cfb_framebuffer_invert function to invert Pixels in the
Character Framebuffer

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
2018-12-06 09:55:15 -05:00
Jakub Rzeszutko b928b71756 shell: rename shell_help_print function
Function printing help has been renamed to shell_help.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 3064ca4f2f shell: creating new module for help functionality
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Aurelien Jarno 46a1bb7cdd usb: cdc_acm: select SERIAL_HAS_DRIVER and SERIAL_SUPPORT_INTERRUPT
USB CDC ACM is a serial driver like another. Therefore select both
SERIAL_HAS_DRIVER and SERIAL_SUPPORT_INTERRUPT. This allows one to
enable the console driver without having to enable another serial
driver.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-05 08:53:15 -05:00
Aurelien Jarno 3eda3b61f8 usb: cdc_acm: fix interrupt mode
The CDC ACM driver has to emulate the TX and RX interrupts from the USB
ones. However it does not correctly emulate them as "TX buffer empty"
and "RX buffer not empty" interrupts.

For "TX buffer empty" interrupt:
- Reading the interrupt status should not clear the interrupt
- Enabling the interrupt should fire an interrupt if the TX buffer is
  empty
- An interrupt should be triggered when the USB device get configured

For "RX buffer not empty" interrupt:
- Reading the interrupt status should not clear the interrupt
- Enabling the interrupt should fire an interrupt if the RX buffer is
  not empty

This make the a console on the USB CDC ACM port usable for the shell
and the logs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-05 08:53:15 -05:00
Pawel Dunaj e344e5752c ext: debug: segger: Fix SEGGER header inclusion
Fix issue caused by 3fc497ac9a

This change removes `rtt` and `systemview` from header includes
as these are already placed in the path.

Also `SEGGER_SYSVIEW_ConfDefaults.h` header included from
`SEGGER_SYSVIEW_Int.h` is placed higher to make sure `INLINE`
definition is properly visible.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2018-12-05 14:35:42 +01:00
Krzysztof Chruscinski 7c68befb15 logging: Fix initial log level in shell
Shell log backends were initialized from shell context. After
lowering logger thread priority order has been flipped. That
revealed a bug where shell logger backend was enabled before
backend ID's has been assigned during logger initialization.

ID assignment is moved to log backend enabling function making
it independent of order of initialization.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-05 14:35:33 +01:00
Tomasz Bursztyka 93fc23bc7e net/icmpv6: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 6c291524bc net/icmpv4: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 3db4378d9e net/ipv4: Verify header's checksum relevantly
Missing verification.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka 0dd5113ca4 net/connection: Verify UDP and TCP checksum the easy way
No need to store/reset/recompute the chksums, only compute it again and
if it's not 0: drop the packet.

RFC 1071:

"To check a checksum, the 1's complement sum is computed over the
 same set of octets, including the checksum field.  If the result
 is all 1 bits (-0 in 1's complement arithmetic), the check succeeds."

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Tomasz Bursztyka b4f79ae418 net: Return fully calculated chksum
IPv4, ICMPv4/6, UDP, TCP: all checksums are meant to be one's complement
on a calculated sum. Thus return one's complement already from the right
place instead of applying it in each and every place where
net_calc_chksum is called.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-05 11:43:54 +02:00
Krzysztof Chruscinski 07e01cbb70 shell: Fix thread priority
Removed kconfig option for setting shell thread priority and fix
it to K_LOWEST_APPLICATION_THREAD_PRIO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-05 10:37:45 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Krzysztof Chruscinski f78067e1f9 shell: Refactor RTT backend
Improved reception in the backend and replaced thread
with periodic timer as thread was used only to
periodically poll RTT data availability and using timer
is more RAM-wise efficient.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-04 16:24:44 -05:00
Marcin Szymczyk d5b79ff42c usb: hid: implement idle rate
Idle rate functionality has been implemented for HID USB class.
Bassed on Device Class Definition for Human Interface Devices 1.11.
Tested with USB3CV and host with idle rate.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Marcin Szymczyk 6a4ddffaf9 usb: hid: default request handlers
HID class now defaults to universal request callbacks in case they
are not provided by the application. This applies to following,
class-specific requests: Get_Report, Set_Report, Get_Idle, Set_Idle,
Get_Protocol and Set_Protocol.
Tested with USB3CV.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-12-04 15:58:19 -05:00
Jukka Rissanen 88d3a0a88f net: config: Enable syslog to network in init
Start to send syslog messages to net after we have a proper
IP address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Jukka Rissanen 44a9bb6abe logging: Add network backend
Allow logging subsystem to send the logging messages to outside
system. This backend implements RFC 5424 (syslog protocol) and
RFC 5426 (syslog over UDP).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Jakub Rzeszutko 1a220b4e80 shell: decrease built-in commands flash usage
Rephrase some help messages to decrease flash usage.
Deactivate shell history feature for test test_netusb_rndis

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:53:02 -05:00
Jakub Rzeszutko 10aeb0e8ab shell: fix resize command
Resize command requires shell to be working on UART interrupt
driven API. This will be now enabled by default when shell serial
backend is selected. Recently this feature was accidentally turned
off in PR #11556.

k_sleep(1) has been replaced with k_busy_wait(1000) to avoid
hanging in command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:53:02 -05:00
Jakub Rzeszutko 8e1d79a641 shell: improve partial completion
Shell used to require adding commands and subcommands in alphabetical
order to ensure correct autocompletion and printing options with the
<Tab> key.

Commit: bd3a4e5fe5 implemented correct
options printing with the <Tab> key for not sorted commands.
This PR allows to partially autocomplete not sorted commands.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-04 15:52:36 -05:00
Vijay Kumar B 5ff42e038d net: ethernet: Add helper functions to update error stats.
Add missed out helper functions to update the errors.tx and error.rx
in the stats structure.

Signed-off-by: Fadhel Habeeb <fadhel@zilogic.com>
Signed-off-by: Nirav Parmar <niravparmar@zilogic.com>
Signed-off-by: Vijay Kumar B <vijaykumar@zilogic.com>
2018-12-04 09:36:51 -06:00
Anas Nashif b8424b4cae crc: deprecate old headers and issue warning when used
Change code to use crc.h instead crc{8,16,32}.h and issue warning when
old headers are used.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-04 08:52:46 -06:00
Krzysztof Chruscinski 0c24e62f2c logging: Fix log_core initialization
Timestamp function and pool for log_strdup were initialized
in log thread initialization while they should be initialized
in log_core_init() which is performed earliest possible. Log
API was using uninitialized data when called before log thread
was started.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-04 15:05:18 +01:00
Andrei Laperie 35a95a9b2f net: gptp: Replace calls to power function with pre-computed values
gPTP subsystem was calling pow(x,y) function with X and Y being
constants; these are replaced with the pre-computed values.

Signed-off-by: Andrei Laperie <andrei.laperie@intel.com>
2018-12-04 15:05:36 +02:00
Paul Sokolovsky 6a2853f9f4 net: ipv4: Clarify basic IPv4 packet drop logging
1. Clarify message telling that the actual packet length fed by the
driver differs from what specified in IPv4 header, and that leads to
drop.
2. Debug log any dropped packets in general.

These changes come from the experience of developing a networking
driver, where figuring out why packets get dropped may require
quite a head-scratching.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-04 12:29:03 +02:00
Krzysztof Chruscinski a211c42a29 logging: Add dropped messages notification to backends
Extended backend interface to allow notifying backend
that log messages has been dropped due to insufficient
internal buffer size. Notification contains number of
log messages dropped since last notification. It
is optional for a backend to implement handler.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-03 14:22:42 -08:00
Krzysztof Chruscinski 65b5e86c52 logging: Fix RTT backend being enabled with shell RTT
If USE_SEGGER_RTT option was enabled then LOG_BACKEND_RTT was
enabled by default. In case shell RTT was also used then both
write to RTT. Updated Kconfig to prevent such situation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-03 11:55:33 +01:00
Vinayak Kariappa Chettimada a2f2d23c9f Bluetooth: controller: Fix conn update assert in slave role
Explicitly track the connection update related ticker stop
and start to avoid asserting due to ticker update being done
at the same time for compensating the clock drift.

The compensation related ticker update failure in this case
can be safely ignored as new anchor point is used anyway
at the instant of the connection update.

Fixes #8796

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-12-03 10:38:57 +01:00
Jukka Rissanen e9364d52fe net: Discard received extra data at the end of the IP message
If we receive extra data at the end of the IP message, then
discard that data and accept the packet.

Fixes #11649

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-02 14:23:13 -05:00
Tomasz Bursztyka 10c4841835 net/net_if: Do not set TCP related flags on non-INET/6 family
Such sent flag is in a union in net_pkt, shared with a gptp flag.
Tweaking it when the family is not AF_INET or AF_INET6 will generate
corrupted gptp packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 5fb9a7bc4a net/gptp: Let Ethernet setting up the header
Instead of redoing what Ethernet L2 already does, let just create the
gptp message without any Ethenet header. Which one will be done as
sending phase by Ethernet L2 relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka ee9dedd5a7 net/iface: Finally remove the send function from net_if_api
And apply that to modem driver setting that pointer to NULL.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 2b3046df70 net/bluetooth: Switch to L2 sending path
This is a much more trivial move than in Ethernet or ieee802154 L2s.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka ebb40ba338 net/ieee802154: Switch to L2 sending path
As for Ethernet, up to ieee802154 L2's send to actually sent the packet.
It's currently unoptimized as 6lo compression, 15.4 fragmentation and so
on will reallocate net_buf etc... but it's the first step towards
removing ll reserve space and more.

Applying changes to Openthread L2 as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 7f2cb02720 net/dummy: Switch to L2 sending path
And adapt loopback and slip drivers relevantly

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 9464ec3343 net/iface: Switch fully to a one-pass sending logic in net_if
Now instead of such path:

net_if_send_data -> L2's send -> net_if tx_queue -> net_if_tx -> driver
net_if's send

It will be:

net_if_send_data -> net_if tx_queue -> net_if_tx -> L2's send -> driver
net_if's send

Only Ethernet is adapted, but 15.4 and bt will follow up.
All Ethernet drivers are made compatible with that new scheme also.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 114521c4bf net/arp: ARP packet can be queued right away
Now that sending is done at last time, in one pass, no need to go
through net_if_send_data here.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 500eca745d net/ethernet: Move sending to a one-pass logic
Currently, first part is done in L2's send, then the next one in
ethernet device driver net_if send function. That last one was already
moved to a L2 based implementation. Let's just move forward and place
the whole logic of the L2's send in that second function.

This is the first step, ethernet centric only, to move towards a
one-pass sending logic in net stack. In future, net_if's send will
disappear.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka dcc6eddfef net/ethernet: Centralize where and when header is filled in
Current code generating Ethernet header is scattered all over the place,
sometimes in functions that are supposed to check something (and not
filling the header). Not to say about innefficiency.

Src ll address does not need to be set in L2 as net_if.c handles that
already.

Broadcast dst ll address is the same in ipv4 or ipv6, thus factorizing.
In each case, multicast is filled in only at the relevant place.

This is the first step towards changing L2 sending logic, when L2 send
API function will be the only point of sending. The redirection from
driver to L2 again (which finally uses the right device API function to
send) it a temporary hack.

This simplifies the code but will also enable using statically
allocated net_buf and ethernet header payload buffer afterwards.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Tomasz Bursztyka 94e89a11b7 net/ethernet: Make ethernet allocating its own frag for the header
This is currently unoptimized, as all frags are allocated with relevant
ll reserve for such header space. However, this is the first step
towards getting rid of that ll reserve concept everywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Marek Pieta 788210816d debug: tracing: Add CPU stats module
Change adds CPU stats module for tracing hooks. Module provides
information about percent of CPU usage based on tracing hooks
for threads switching in and out, interrupts enters and exits.
cpu_stats only distinguishes between idle thread, non idle
thread and scheduler.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2018-11-30 11:01:32 -08:00
Krzysztof Chruscinski 4d94257162 logging: Make logging thread priority fixed
Removed kconfig option for setting logging thread priority
and fix it to K_LOWEST_APPLICATION_THREAD_PRIO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-30 10:59:02 -08:00
Flavio Ceolin 713ec4c71c shell: utils: Remove dead code
Coverity-CID: 188741

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-30 08:06:40 -08:00
Paul Sokolovsky 1165e852c1 subsys: console: tty: Use tty_putchar() instead of console_putchar()
To be properly layered.

This call is used to signal to user an input buffer overload. Take
a chance to output just a single character in this case, to avoid
amplification and possible output buffer overflow either.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:05:40 -08:00
Paul Sokolovsky ed852e8b4a subsys: console: Split tty definitions into tty.h, to form its own API
This patch proceeds with the separation of older serial console
subsystem into device-independent console subsytem and buffered
serial device ("tty") API.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:05:40 -08:00
Paul Sokolovsky 226ff48384 logging: Elaborate description of CONFIG_LOG_STRDUP_BUF_COUNT
Description is improved, guidelines for when increase is required are
provided, together with associated overheads information.

Fixes: #11007

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:04:33 -08:00
Paul Sokolovsky 600a2340f2 logging: log_core: Clarify message when log_strdup failed allocation
Don't say that pool is empty, say that allocation failed, because
that's what happened (because the pool is full apparently).

Partially addresses #11007.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:04:33 -08:00
Tavish Naruka 68a14eda15 log: Don't enable LOG_CMDS if SHELL is disabled
This was preventing compilation due to undefined
symbols like 'shell_fprintf' etc.

Signed-off-by: Tavish Naruka <tavishnaruka@gmail.com>
2018-11-30 08:01:39 -08:00
Andrei Emeltchenko e209ebe05a usb: device: Use sys_le16_to_cpu conversion
USB protocol is Little Endian so make conversions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-30 07:58:31 -08:00
Flavio Ceolin c16b1d08df misra: Ignoring the return atomic_set when not used
The function atomic_set return the previous value of the
target. Sometimes this value is irrelevant, e.g when initializing a
variable.

As MISRA-C rule 17.7 requires that the value returned by a non-void
function must be used, we have to explicitly ignore some cases.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 10:18:59 -08:00
Flavio Ceolin 98d03266f1 serial: Change poll_out signature
poll_out function was returning the character that was sent. It
happens that it is always constant and the return of this functions is
never tested. Changing it to be a void function.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 10:18:59 -08:00
Johan Hedberg bec74121f6 Bluetooth: Mesh: Fix matching for all elements of an LPN
When we're acting as a Friend for an LPN, we need to consider all
elements of the LPN. The information of how many elements the LPN has
is provided in the Friend Request message, however until now the code
did not do anything with this information.

Fix the issue by tracking the number of elements for each LPN and
update the unicast address matching code to take this into account.

Fixes #11731

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-29 17:55:23 +02:00
Jakub Rzeszutko 9643ed6d27 shell: fix double new line print for RTT backend
In case terminal sends `\r\n` on the Enter button
shell will go to the new line twice and it will print
prompt twice. This patch fixes it.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-29 11:54:56 +01:00
Aurelien Jarno a0b9e70e10 c++: kconfig: EXCEPTIONS needs to depend on NEWLIB_LIBC
C++ exception support needs to use the newlib C library in order to get
the abort function. C++ exceptions also do not work with the simple
malloc/free implementation provided by the Zephyr minimal C library.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-28 13:51:35 -08:00
Robert Lubos b5f9771252 net: mqtt: Fix NULL pointer dereference in logs
MQTT packet_length_encode function accepts NULL buf argument, therefore
it cannot be dereferenced without a check.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00
Robert Lubos a26db60b2f net: mqtt: Add missing mutex_unlock
mqtt_connect was not releasing mutex after successfull connection.
Reworked the code to have a single exit path with mutex unlock.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00
Himanshu Jha 36279b69a8 net: lwm2m: ipso_temp_sensor: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Himanshu Jha dbcc5392fe net: openthread: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Himanshu Jha a273cfaf32 net: lwm2m: ipso_light_control: remove unnecessary variable
Remove an unnecessary local variable to store the
return value, instead return directly thereby saving
few bits of memory.

Found using Coccinelle.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 11:54:01 -08:00
Olivier Martin 58245cd02f Bluetooth: Define log level at bluetooth subsystem level
This commit defines a default log level at bluetooth subsystem
level when module log level is not defined.

Prior to this change, the bluetooth subsystem would use
the firmware default log level.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-28 13:52:35 -06:00
Himanshu Jha 547e75723c net: llmnr_responder: Check return value of net_udp_get_hdr
net_udp_get_hdr() function returns NULL on failure. Therefore
handle its return value to avoid potential NULL dereference.

Fixes #11485
Coverity-CID: 189738

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
2018-11-28 19:20:04 +02:00
Kim Sekkelund bf11698ed9 bluetooth: host: Rename bt_conn_get_id and make it public.
There is not an easy way to relate an application's user_data to a
connection. One way is to save a pointer to bt_conn in the
application's user_data array upon connection establishment.
Each connection related callback function will have to loop for all
user_data and compare the saved pointer to the passed bt_conn
pointer. This is inefficient if there are many callback activations
during the connection.

This change makes the internal bt_conn mapping function accessible to
applications in conn.h. The function name is changed to
bt_conn_index() to clearly indicate that the function returns an
index of an array.
Add an ASSERT to catch illegal parameter.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2018-11-28 18:20:38 +02:00
Jukka Rissanen 4770528018 net: app: Remove extra log_strdup() calls
The _net_app_sprint_ipaddr() was calling log_strdup() when
creating the debug print string. This is not correct as
the log_strdup() can only be used when calling the logging macro
to print strings.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-28 14:25:25 +02:00
Ravi kumar Veeramally 7a5640f126 net: ipv4: Drop incoming packets with src addr is multicast
As per RFC1112 sec 6.2 "A host group address must never be
placed in the source address field or anywhere in a source
route or record route option of an outgoing IP datagram."

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally 3746652f85 net: arp: Drop ARP requests from localhost address
If ARP Request with sender IP address set to localhost then drop
the request.

Fixes #11489

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally 6227b12fb4 net: arp: Fix ptype for non arp messages
If network stack found ARP entry for peer address, then it
tries to send pending IP packet. But it always keeps ptype
as ARP only. In this particular scenario it has to be IP
packet.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally f2e0754718 net: ipv4: Drop the replies if src address in unspecified
Networking stack sometimes try to find source address based
on destination address. If interface could not find best match
then it returns unspecified address (0.0.0.0). Host should not
send these packets.

IPv4 reply related issues fixed.

Fixes #11329

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Ravi kumar Veeramally 0c547f9da9 net: arp: Discard ARP request on special scenario
Discard ARP request if Ethernet address is broadcast and
Source IP address is Multicast address.

REFERENCES:
RFC 826: page 4
RFC 1122: section 3.3.6 {Silently discard link-layer-only b'cast dg's}
RFC 1812: section 3.3.2, page 34

ARP related issues fixed.

Fixes #11329

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-28 10:13:41 +01:00
Jakub Rzeszutko 6de96b1802 shell: fix make_argv function
Shell will now detect not terminated " or ' character.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-27 15:00:19 -06:00
Olivier Martin ff66b4b09a Bluetooth: host: Remove peer from CCC cfg
When removing a peer from a CCC, it also needs to be removed from
the attribute `cfg`.

Not removing it would create a shortage of `cfg` that could
prevent new host to pair to the BLE device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-27 13:58:21 +02:00
Ramakrishna Pallala dbf405ab21 power: Move application level API's to public header
Move the API's used by applications to include/power.h file.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-11-26 18:38:40 -08:00
Andrei Emeltchenko 575bd0bbc9 usb: Fix unaligned access
Use sys_put_le16() for unaligned access, this is refactored work of
PR #8495
PR #11432

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-26 09:13:56 -08:00
Olivier Martin 6c3aefa0b6 Bluetooth: host: Clear CCC when clearing all keys
CCC settings was not removed when unpairing all keys.
It means CCC settings were still present in flash and were
loading at bluetooth initialization time.

Loading these orphan CCC settings would fill `bt_gatt_ccc_cfg`
configurations and would prevent to add new CCC when pairing
with a new device.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-26 18:34:41 +02:00
Ramakrishna Pallala 212b2180c9 power: Add API's to enable/disable System PM states
Add API's to enable/disable System PM states so that an
an application can enable/disable system from entering
certain Low Power states.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-11-26 06:55:57 -08:00
Aurelien Jarno 38efc2d426 shell: add a missing space in the help message
The help message is missing a space between "auto-complete" and "all".
Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-26 01:04:45 -05:00
Marcin Szymczyk e4c447aac3 usb: add SoF event
Start of Frame events can now be accessed from USB classes.
This will be useful when implementing idle rate functionality.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-11-23 09:18:41 -05:00
Gil Pitney c51cf1e463 drivers: wifi: simplelink: Implement setsockopt() for TLS offload
Implements setsockopt() for the socket offload driver
to process the TLS tags sent in via the Zephyr setsockopt() API,
when CONFIG_NET_SOCKETS_SOCKOPT_TLS is chosen.
For each tag, the credential filenames are retrieved and
set via SimpleLink's sl_SetSockOpt() API.

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

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

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

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-11-23 09:16:21 -05:00
Ravi kumar Veeramally b848f8f9c5 net: rpl: Remove __deprecated tag to one function
net_rpl_get_interface() function which returns always NULL is
defined if NET_RPL is not enabled. so remove deprecated tag to
this particular function. Otherwise it will cause unnecessary
compilation warnings.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-23 09:10:23 -05:00
Krzysztof Chruscinski 2d6a226b2e logging: Fix lost printk output when no newline
Log_output module was always postfixing printk strings
with '\r'. If printk message did not ended with '\n'
it lead to last printk message being overwritten.

Fixed by adding '\r' only when string was ended by '\n'.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-22 19:18:41 -05:00
Krzysztof Chruscinski 96a610b736 shell: Fix log messages queueing for multiple instances
Shell log backend was using k_fifo to enqueue log messages.
It was using field in log message that was used for same
purpose in log_core before passing message to backends.
However, this method supported only single shell as
other shell was corruption the fifo because field was
reused.

Modified shell log backend to use k_msgq for pending
messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-22 13:14:49 -05:00
Luiz Augusto von Dentz 6798a421e1 Bluetooth: GATT: Ensure GATT service is registered first
Accourding to Bluetooth specification the Service Changed
Characteristic shall not have its handle changed once it has been
bonded, so this moves the GATT service to be the very first service
registered that way it is guaranteed that it won't change even if
device is flashed with a different configuration which end up changing
the handles after it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-22 17:27:48 +02:00
Ravi kumar Veeramally 19c598f081 net: coap: Deprecate net_pkt based CoAP library
Deprecating net_pkt based CoAP library due to Socket based
CoAP library.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:08:46 -05:00
Anas Nashif 3d906dc4c1 net: coap: Move both CoAP implementations into one Kconfig
Two separate folders and Kconfig options causing confusion on
CoAP and CoAP_SOCK implementations. This patch simplifies it.
Current CoAP Kconfig option moved to COAP_NET_PKT.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-22 09:08:46 -05:00
Ravi kumar Veeramally 7d0aecfc2a net: rpl: Deprecate RPL
RPL support has been deprecated from Zephyr.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:01:04 -05:00
Mariusz Skamra 474b2b3e94 Bluetooth: Don't mask ECDH related events if CONFIG_BT_ECC disabled
It is related to b904ad387f.
This fixes checking ECDH related events in event mask.
If ECDH support is disabled in host, there is no need to check
if those are supported in the controller.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-22 12:54:57 +02:00
Krzysztof Chruscinski af973ca1e9 shell: enable UART backend without interrupts
Currently shell UART backend is interrupt driven if UART driver
is interrupt driven. That can be limitation if one instance
wants to use interrupts but shell UART should not.

Added option to shell uart to be able to control use of
interrupts. By default interrupts are enabled if driver
supports it.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-21 22:41:21 -05:00
Luiz Augusto von Dentz a618ea2a5a Bluetooth: GATT: Fix not handling duplicated CCC storage
Some backends may actually contain the same key multiple times so the
code needs to check if there is already a ccc_cfg for an address before
attempting to use one that is unallocated.

Fixes #11409

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:48:16 +02:00
Luiz Augusto von Dentz 046e1ab94a Bluetooth: GATT: Fix not resetting CCC storage
If there are no CCC to be stored the value should be set to NULL so it
is properly cleared otherwise calling settings_str_from_bytes will leave
str uninitialized which may cause a crash when attempting to load the
value.

Fixes #11564

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-21 19:32:16 +02:00
Michael Scott 70b9e7bab6 net: lwm2m: handle pending before send in retransmit
When resending data, we need to always check pending status first.
If the pending check returns an "expired" status, avoid sending the
data to L2 network driver entirely.

This change fixes a use after free issue, where the L2 network driver
was still handling a packet that was expired out from under it when
the pending status was checked.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 144cfce42a net: lwm2m: firmware_pull: don't use pending pkt for token
During firmware transmit timeout, we rely on the pending packet data to
reconstitute the token and token length.  At this point the pending
structure may be cleared out due to multiple retries.  To avoid getting
a zero token, let's use the token data from the original msg structure
instead.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 64c03819ec net: lwm2m: don't use pending pkt on retransmit error
We are using msg->cpkt.pkt as the net_pkt pointer in the call to
net_app_send_pkt().  Let's keep the code clean and not expose
ourselves to "out of order" issues, by also using msg->cpkt.pkt
in the error handling unref call.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Michael Scott 547e449f98 net: lwm2m: remove extra ref/unref in retransmit
During the retransmit cycle we take ref on the outgoing packet,
only to immediately unref it.  Originally, this was to make sure
the net_context handling didn't get rid of the packet when
sendto() is called.  But after checking, the ref counter is never
in danger of going to 0 at this point in the code, so the
added ref handling is useless.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-21 12:30:42 -05:00
Marti Bolivar 1cd137c393 net: lwm2m: increase IPSO light object color size
Add some extra space to the color resource buffer, to allow more
exotic and application-specific color spaces.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-21 12:30:42 -05:00
Mariusz Skamra b904ad387f Bluetooth: Add Kconfig option to disable HCI ECDH support
This adds Kconfig option to disable HCI ECDH support.
It will compile out ECDH related code, especially HCI event handlers.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra 8f5ba0be88 Bluetooth: Add common Kconfig option to disable LE Data Length Update
This adds common option to disable support for LE Data Length Update
procedure in controller and host.
This will reduce flash usage by compiling out le_data_len_change
event handler that will never be called if controller has been
compiled with BT_CTLR_DATA_LENGTH option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Mariusz Skamra be314d3af5 Bluetooth: Add common Kconfig option to disable PHY Update
This adds common option to disable support for PHY Update
procedure in controller and host.
This will reduce flash usage by compiling out le_phy_update_complete
event handler that will never be called if controller has been
compiled with BT_CTLR_PHY option disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-21 12:26:27 -05:00
Savinay Dharmappa 0576f93ff8 usb: class: hid: Fix fault due to unaligned access
patch fix fault due to unaligned access while setting hid
report size on xtensa platform.

Fixes #11266

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-11-21 12:25:22 -05:00
Olivier Martin 1d9fb2b2b3 Bluetooth: host: Increase ECC thread stack
Logging subsystem could take few extra bytes when enabled.
ECC thread stack has been unconditionally increased to
support it.

During my test, I noticed a usage of 1052 bytes when logging
subsystem is enabled.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-11-21 14:39:36 +02:00
Krzysztof Chruscinski f214f8b2b2 shell: fix RTT backend not returning TX amount
RTT backend was returning number of transfered data equal
to requested amount because it was not taking into
account value returned by SEGGER_RTT_Write. As the outcome
data could be lost.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-21 12:53:22 +01:00
Krzysztof Chruscinski e85986e153 logging: refactor log_filter_set to set existing log level
Modified log_filter_set function to limit level if requested
level is not compiled in. Additionally, extended function to
return actually set level. Removed redundant code from log_cmds.

Change fixes shell log backend initialization which was setting
log levels without taking into account compiled in limits.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-20 08:43:34 -05:00
Luiz Augusto von Dentz 57a6858278 Bluetooth: ATT: Rename op parameter of att_write_rsp
This makes it clear that only request need to set an opcode since they
require a error response in case it fails.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz 8f812f30a1 Bluetooth: GATT: Fix comment related to write attribute
The comment was suggesting that write callback was reading and storing
buffer when in fact it should write to the attribute value.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Luiz Augusto von Dentz ae05089946 Bluetooth: GATT: Add flag to indicate write command
Application may need to handle the write differently depending on the
write operation so this adds a flag called BT_GATT_WRITE_FLAG_CMD which
can then be checked by the callback, for instance one can respond with
BT_ATT_ERR_WRITE_REQ_REJECTED when that flag is not set which should
indicate to the client to use write command instead.

Fixes #11206

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 13:14:58 +02:00
Paul Sokolovsky 2e21a95fd4 net: sockets: zsock_close: Be sure to free file descriptor
File descriptor I freed automagically when using POSIX subsystem's
close() function, but any subsys-adhoc functions like zsock_close()
should do that explicitly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-20 11:25:17 +01:00
Vinayak Kariappa Chettimada aa5bbd5dfe Bluetooth: controller: Fix enable and disable of scan state
Updated controller implementation to disallow disabling
initiator state using scan disable. But allow disabling an
already disabled scan state. Also, disallow enabling scan
state while in initiator state.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:19:07 +01:00
Luiz Augusto von Dentz 3fdedde967 Bluetooth: ATT: Assert if request is invalid
Consider invalid if the request pointer is NULL or the callback is NULL
or there is a request ongoing. This conditions would likely lead to a
crash and most likely there is some other bug involved like for example
the application queueing the same request multiple times.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-20 11:15:33 +01:00
Rajavardhan Gundi 4e8e0748e8 storage: flash_map: Make flash_map as extern
flash_map should be made extern in flash_map.c since it is defined
in flash_map_default.c. Not having flash_map as extern will result
in build errors.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-11-20 11:15:16 +01:00
Vinayak Kariappa Chettimada c326ae729f Bluetooth: controller: Do not feature exchange more than once
Updated the controller implementation to not feature
exchange if already done once either by local or remote peer
device in an active connection session.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-20 11:14:58 +01:00
Flavio Ceolin c554ab7100 subsys: logging: Fix invalid memory access
Coverity-CID: 189512

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-20 11:14:31 +01:00
Jakub Rzeszutko 7d31796416 shell: fix shell thread name
Each shell thread will have unique name.
Previously thread name "shell" has been created for each shell
backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-19 11:40:05 -05:00
Robert Lubos d2a397bcf8 net: mqtt: Add TLS socket transport
Add TLS transport to socket MQTT implementation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Robert Lubos 37563a92d5 net: mqtt: Add BSD socket implementation
Add new, socket based MQTT implementation, based on MQTT from Nordic
nRF5 SDK, introducing the following features:

* transport independent MQTT logic, with support for multiple transports
* support for multiple MQTT versions (3.1.0 and 3.1.1 supported)
* single event handler - no need to keep callback array in RAM
* automatic send of Ping Requests, for connection keep-alive
* message/event parameters wrapped into strucutres - easier extension
  for future MQTT versions
* no separate thread needed to run MQTT - application only needs to call
  mqtt_input and mqtt_live periodically

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Robert Lubos f50aa6d3fb net: mqtt: Mark existing implementation as legacy
Rename existing headers and sybols to mqtt_legacy, to allow new
implementation to keep old config and header names.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Szymon Janc e693997c29 Bluetooth: host: Fix not starting slave conn param update timer
When issuing LE Set Data Length Command host should not assume that
LE Data Length Change Event will be generated. From Core Spec 5.0:
"If the command causes the maximum transmission packet size or maximum
packet transmission time to change, an LE Data Length Change Event
shall be generated."

Change-Id: I17723b58ed4f390aa465db3f69126ee229871123
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:40:13 +02:00
Szymon Janc bf71fa1aeb Bluetooth: host: Don't send slave conn param request if not needed
If master or application decided to switch connection parameters to
ones that meet pending parameters don't bother sending request
after 5 seconds timeout.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-19 13:22:43 +02:00
Krzysztof Chruscinski 8421543f1c shell: Add initial log level for rtt and uart backends
RTT and uart shell backends were started with fixed
log limit set to INF. Configuration has been moved
to Kconfig allowing certain level or default LOG_MAX_LEVEL.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-19 12:05:44 +01:00
Krzysztof Chruscinski 5af45bd392 shell: uart: Handle RX ring buffer full case
Scenario where RX ring buffer is full and cannot accept
more data was not handled. In that case byte should be
dropped. Such situation may occur when long command is
pasted (exceeding ring buffer size).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-16 08:31:01 -05:00
Johan Hedberg 296dab3fe2 Bluetooth: Mesh: Increase scan window from 10ms to 30ms
Experiments have shown that the probability of missing advertising
packets is significantly lower with 30ms scan window compared to 10ms
scan window. This is especially the case with advertisers using a 20ms
advertising interval, which in turn is perhaps the most common one
since it's the smallest allowed by the Bluetooth 5.0 specification.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-16 09:36:20 +02:00
Robert Lubos 824d0bd854 sockets: tls: Use FD table to reach net_context
With FD table introduction, net_context can no longer be reached by
typecasting socket descriptor. Instead, file descriptor API have to be
used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Robert Lubos 72958f2e1c sockets: tls: Fix getsockopt/setsockop return value
ztls_setsockopt and ztls_getsockopt returned error codes instead of
setting errno in particular cases. This commit fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-15 17:54:40 -05:00
Patrik Flykt 07697dd004 subsys/mgmt: Avoid C++ comments inside C comments
MISRA-C rule 3.1 wants to avoid mixing C/C++ comments. An ellipsis
works fine here.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-11-15 17:38:25 -05:00
Anas Nashif 065903f3c7 usb: netusb: fix log level macro
Using the wrong Kconfig for log level.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-15 15:24:32 -05:00
Andrei Emeltchenko 1cd95969e3 ieee802154: Remove dead code
Remove unused ieee802154_shell_init()

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-15 08:42:52 -05:00
Andrei Emeltchenko db42716cde usb: msc: Check input parameters for class handle
Fixes USB Certification tests for class requests.

Fixes #11359

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andrei Emeltchenko 5bf12356e2 usb: msc: Do not give warning after SET_INTERFACE
Add USB_DC_INTERFACE 'handling'.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andrei Emeltchenko 3f698494bb usb: msc: Set default Serial Number string
According to the "USB Mass Storage Class" Spec. the serial
number shall contain at least 12 valid digits, represented
as a UNICODE string.

Fixes: #11336

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-14 23:54:08 -05:00
Andy Ross 923e1b60e7 misc/printk: Make the default char_out routine weak
Architecture init code and/or HAL layers often have a working
"putchar" routine available long before the Zephyr driver layer is
initialized.

Make the default printk() output a weak symbol, so it can be
overridden on these platforms.

Also remove the kconfig depedency on CONSOLE_HAS_DRIVER, as this is a
non-driver mechanism.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-14 19:08:27 -05:00
Luiz Augusto von Dentz 67e4710598 Bluetooth: shell: Make use of SHELL_CMD_ARG
Use SHELL_CMD_ARG to register commands.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Luiz Augusto von Dentz b7c6ea4971 Bluetooth: shell: Remove macros to print messages
Make use of shell_print and shell_error now that they are available.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Luiz Augusto von Dentz 4add794570 Bluetooth: shell: Remove auto selecting of SERIAL
This is no longer needed and the shell itself will take care of
selecting SERIAL.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-13 20:42:01 +02:00
Jukka Rissanen 279da528bc net: pkt: Print debug prints in one line
In earlier commit 15e7e3ea4 ("net: ip: Split debug prints into
smaller pieces"), the net_pkt debug prints were split to two
lines because of the argument count limitation in logging system.
As the logging subsystem increased the limit count in
commit 62d011549a ("logging: Support for up to 15 arguments in log
message") we can restore the original version as it is easier
to read.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 12:54:27 -05:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Filip Kubicz 7c290b053d Bluetooth: settings: store CCC on write
By default, CCC value is only stored to persistent memory during
BT disconnection. This commit adds an optional storing of CCC right
after it has been updated. This results in better robustness of
peripheral but increases system workqueue stack usage.

Signed-off-by: Filip Kubicz <filip.kubicz@nordicsemi.no>
2018-11-13 16:36:49 +02:00
Pavel Kral 47f529829f logger: fix missing macro in RTT backend, when blocking mode is selected
This simple patch fix compiler error when RTT blocking mode is selected.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-11-13 09:27:37 -05:00
Krzysztof Chruscinski 6d1a31b3fc logging: Add uart backend dependency to shell uart backend
If shell UART backend was enabled and logger uart backend was
not explicitly disabled then both were used resulting in logs
being printed twice on terminal.

Patch modifies default state of log uart backend to depend on
state of shell uart backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-13 09:17:05 -05:00
Kumar Gala e8587f4493 usb: Make USB_VBUS_GPIO a Kconfig option
Previously we had a set of magic #define's in board.h that would both
enable and set the GPIO controller & pin if a given board used a GPIO
for USB VBUS.  Now we make it a proper Kconfig set of options that
specify if the feature is needed, the GPIO controller device name, and
pin number.  In the future this should move to devicetree.

Updated the related boards that used this feature to set the Kconfig
options in the Kconfig.defconfig

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-13 07:10:04 -06:00
Andrei Emeltchenko 40f7a49ffe usb: hid: Trivial syntax fix
Fix typo

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Andrei Emeltchenko 85cfe33262 usb: hid: Define helper definitions and cleanup code
Use newly defined definitions for cleaning the code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Andrei Emeltchenko f6a20b83d6 usb: hid: Implement Return HID Descriptor
Resolves certification USB tests.
Fixes #11321

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-13 12:41:39 +01:00
Jukka Rissanen 89355e14ac net: if: Properly turn off promiscuous mode
Pass the promiscuous mode OFF event properly to device driver
instead of just toggling the network interface flag.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 12:53:44 +02:00
Jukka Rissanen 64eb47e032 net: promisc: Flush the promisc queue properly
Flush the promiscuous queue after all the clients have turned
off promiscuous mode. This makes sure that we do not leave any
RX packets hanging on the queue and waste memory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-13 10:00:07 +02:00
Ravi kumar Veeramally 483378027a net: arp: Check invalid fields in ARP header
If ARP header contains invalid fields then drop the packet.

Fixes #11257
Fixes #11254
Fixes #11253
Fixes #11248

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-12 15:42:54 +02:00
Anas Nashif 86ad37a533 kconfig: distribute misc/Kconfig option where they belong
Move misc/Kconfig options to where they belong. misc/Kconfig was used as
a catch-all, but we are now able to put things in a better place.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-12 08:01:15 -05:00
Anas Nashif 24666e6946 stats: move from misc to subsys/stats
Create a new subsystem for statistics and move it from misc/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-12 08:01:15 -05:00
qianfan Zhao e3506832a4 subsys: shell: Print help message only if command doesn't available
Fixes: #11250

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-11-11 14:53:34 -05:00
Andrzej Głąbek 4750cf3b7b bluetooth: controller: nrf5: Reorder used PPI channels
The channels assigned to the controller are reordered so that the ones
previously used and now available for other purposes have continuous
numbers. When the controller can take advantage of the pre-programmed
PPI channels (when TIMER0 is used as the event timer), the now free
channels are 0-4, when it cannot, it is the channel 0.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Andrzej Głąbek 589b65e72d bluetooth: controller: nrf5: Use pre-programmed PPI channels
Several PPI channels in nRF5 family SoCs are pre-programmed with fixed
settings. A few of them can be used in the bluetooth controller instead
of the freely programmable ones that are used currently. This commit
makes such replacements where possible so that the universal channels
can be left available for other purposes.

This commit also removes macros used previously in calls to functions
enabling and disabling particular PPI channels (as it is sufficient
to use the BIT macro to set bits corresponding to the channel numbers)
to prevent such problems like the one introduces by commit
9d1ca9c390 (channel 18 changed to 17
but the related macro definition not updated).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-10 12:39:40 -05:00
Krzysztof Chruscinski 5e346812ac logging: Refactor LOG_MODULE_REGISTER and LOG_MODULE_DECLARE macros
Changed LOG_MODULE_REGISTER and LOG_MODULE_DECLARE macros to take log
level as optional parameter. LOG_MODULE_DECLARE can now also be used
in static inline functions in headers. Added LOG_LEVEL_SET macro
which is used when instance logging API is used to indicate maximal
log level compiled into the file.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Krzysztof Chruscinski fa95089b3d net: l2: Fix NET_L2_BT dependency in KConfig
Added NET_IPV6 dependency to NET_L2_BT.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Jukka Rissanen 421505c7e3 net: qemu: Allow SLIP or normal ethernet connectivity
Introduce new Kconfig option for selecting either slip or ethernet
connectivity to host.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-10 09:13:45 -05:00
Kumar Gala 896472a13d shell: Fix reference to nonexistent Kconfig symbol
The code referenced CONFIG_SHELL_VT100_COLORS_ENABLED which does not
exist.  Its mostly likely that CONFIG_SHELL_VT100_COLORS was meant
to be tested instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-09 11:01:06 -06:00
Kumar Gala 701a574c03 Bluetooth: host: Fix trivial comment mismatch
The endif comment block is for CONFIG_BT_FIXED_PASSKEY not
CONFIG_SMP_FIXED_PASSKEY.  Fix the comment to match.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-09 16:20:19 +02:00
Luiz Augusto von Dentz 75979397b2 Bluetooth: shell: Fix illegal access
BT_LE_ADV_CONN_DIR_LOW_DUTY declares a local variable so it cannot go
out of scope, so instead of assigning in the scope of the if statement
this rework the code to mantain the declaration in the same scope it is
used.

Fixes #10570

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 16:18:44 +02:00
Ravi kumar Veeramally 4b0aa92bba net: arp: Verify incoming packet HW and protocol type
Verify incoming ARP packet hardware and protocol type. Drop
unknown type of packets.

Fixes #11215
Fixes #11217

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-09 15:21:28 +02:00
Luiz Augusto von Dentz 7aa58ff91d mesh: Port shell module to the new shell
This makes mesh shell to register commands with the new shell subsystem
and stop using the legacy shell.

Fixes #11056

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 11:19:49 +01:00
Luiz Augusto von Dentz a89690d10f shell: Add APIs to set number of arguments
This allows the shell core to perform precheck before calling the
handler which then can assume the number of arguments is correct.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-11-09 11:19:49 +01:00
Paul Sokolovsky 8f690e291b lib: fdtable: FD method tables should be const.
FD method tables contain function pointers, and thus should be
const and reside in ROM. This patch fixes all cases of FD vtable
definitions: for POSIX FS API and for sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-08 09:47:46 -08:00
Andrei Emeltchenko 93bd26343e usb: logs: Rename USB_WRN to LOG_WRN
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko f22060cdbe usb: logs: Rename USB_INF to LOG_INF
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 17f7abd3dc usb: logs: Rename USB_ERR to LOG_ERR
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 92c7ab74c0 usb: logs: Rename USB_DBG to LOG_DBG
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Jukka Rissanen 42c180ed5b net: eth: Remove old IPv6 interface identifier address
If we change the ethernet MAC address, then we must also remove
the old IPv6 interface identifier (iid) address from the
interface. Otherwise there might not be enough space in the IPv6
address array for the new iid address and beside the old iid
address is not useful any more after the MAC address is changed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Jukka Rissanen aa5f219bd1 net: if: Allow calling IPv4 specific functions
Make sure that IPv4 specific functions are callable even if
IPv4 is not enabled. This allows use of IS_ENABLED() macro
in other parts of the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Jukka Rissanen 2808b23f44 net: if: Allow calling IPv6 specific functions
Make sure that IPv6 specific functions are callable even if
IPv6 is not enabled. This allows use of IS_ENABLED() macro
in other parts of the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Szymon Janc 602e08c69a Bluetooth: host: Don't restart scan if connection is pending
With multiple devices on auto-connect list it is possible that while
having pending connection to device A, device B disconnects. In that
case host should not try to start scan (currently controller doesn't
support concurrent scanning and initiating).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-08 14:21:21 +02:00
Emanuele Di Santo 7e8b44f774 subsys: bluetooth: services: dev. information service enhancements
This commit moves the BLE GATT Device Information service
from /samples/bluetooth/gatt to /subsys/bluetooth/services and adds
a Kconfig entry to enable and configure the service;
when enabled, it will register itself automatically.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-11-07 18:08:05 +01:00
Michael Scott 6575e84002 logging: start log processing thread in enable_logger()
Currently, if CONFIG_LOG_PROCESS_THREAD is enabled, log processing
does not start until just before the main() function is called in
the user sample.  This means that no real-time logging information
will be sent to the backends while drivers and/or other processes
which are triggered during kernel boot are processing their tasks.
Worse, if they take a longish time to finish, the user is
presented with a blank log backend regardless of the debug levels.

Let's start processing logs earlier to avoid this issue.

NOTE: Since this thread is now triggered specifically rather than
started during static thread init, let's also name it.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-07 14:39:55 +02:00
Mariusz Skamra 9a69cfbf19 mgmt: Add function to unregister GATT service
This adds a possibility to unregister GATT SMP service.
Using this function, device can disable Firmware Update
functionality, if not needed.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-07 14:35:22 +02:00
Szymon Janc 16fe6c5473 Bluetooth: host: Add comment clarifying L2CAP fallback for CPUP
Makes it easier to understand reason for else branch.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-07 13:01:01 +02:00
Vinayak Kariappa Chettimada f403bfa343 Bluetooth: controller: Add min & max interval support in CPR
Add support for exchanging both minimum and maximum
connection interval values in Connection Parameter Request
Procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-06 20:56:13 -05:00
Jakub Rzeszutko 59c23b11ff shell: wildcard active by default
Wildcard plugin is active by default.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-06 17:12:41 -05:00
Krzysztof Chruscinski 4962618e5f shell: shell_uart: add ring_buffers and interrupt support
Improved RX path to use ring buffer for incoming data instead of single
byte buffer. Improved TX path to use ring buffer. Added support for
asynchronous UART API (interrupts).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-06 17:11:26 -05:00
Aurelien Jarno 2eeff9aab0 subsys: nvs: increase NVS_BLOCK_SIZE
The Atmel SAM E70 flash has a 16-byte write block size. Increase the
NVS_BLOCK_SIZE a bit and take some margin. This might also improve the
performances by reducing the calls to the flash driver when moving data
during garbage collection.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-06 17:09:03 -05:00
Aurelien Jarno 523caef224 subsys: nvs: fix ATE read/write when write block size > 8 bytes
When the write block size is bigger than sizeof(nvs_ate), which is 8
bytes, we should not read or write more than the ATE. The
_nvs_flash_al_wrt() function will take care of padding the write with
0xff up to write_block_size. Of course the addresses should still be
incremented by write_block_size.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-06 17:09:03 -05:00
Aurelien Jarno 199309dbf5 subsys: nvs: kill a VLA
VLA are usually not recommended and are a MISRA C violation. Replace
fs->write_block_size by NVS_BLOCK_SIZE as we now have a check at
initialization that ensures that fs->write_block_size <= NVS_BLOCK_SIZE.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-06 17:09:03 -05:00
Aurelien Jarno da2495e914 subsys: nvs: error out if write block size is not supported
In case the write block size is bigger than NVS_BLOCK_SIZE, some
functions end up in an endless loop. Detect the unsupported cases
at initialization.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-06 17:09:03 -05:00
Szymon Janc b6979010c6 Bluetooth: host: Fallback to L2CAP for CPUP if rejected by master on LL
Fallback to L2CAP Connection Parameters Update Request if LL Connection
Update Request was rejected by remote device that has this marked as
supported in features. This can happen if procedure is supported only
by remote controller, but not enabled by host. This is connection
parameters update with iOS devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-11-06 16:30:15 -05:00
Flavio Ceolin 3ced176088 subsys: logging: Fix switch statement
According with MISRA-C and unconditional break statement must
terminate every switch-clause.

MISRA-C rule 16.1 and 16.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-06 16:20:15 -05:00
Marek Pieta c99fd5c807 subsys: debug: tracing: Fix interrupt hooks
Change fixes interrupt hooks.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2018-11-06 16:15:29 -05:00
Johan Hedberg 97141734f1 Bluetooth: shell/gatt: Fix unreachable code
The code had somehow gotten corrupt (yet in a way that it compiles) so
that an intended if-branch was missing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-11-06 22:29:51 +02:00
Tomasz Bursztyka 3200914ed9 net/ethernet: Remove as many ifdef for CONFIG_NET_VLAN as possible
Most of vlan functions have dummy aliases when it's not enabled, so
let's use this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-06 12:42:06 +02:00
Tomasz Bursztyka 7280757d7d net/ipv4: Use iface's ll reserve relevantly
No need to evaluate what's the ll reserve size here as net if has a
function to do so.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-06 12:42:06 +02:00
Jukka Rissanen 9fc9d1496e net: ipv6: Loopback interface local scope packets back to us
If the destination IPv6 address is interface local scope multicast
address FF01::, then loopback those packets back to us as that is
the purpose of those addresses. They are to work same way as
localhost unicast address. See RFC 3513 ch 2.7 for details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:11:08 +02:00
Jukka Rissanen a13cee27c3 net: shell: Add IPv6 and IPv4 checks for ping command
If IPv6 is disabled, then we can skip IPv6 checks and avoid
Coverity warnings. Same thing for IPv4.

Coverity-CID: 189506
Fixes #11100

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:09:12 +02:00
Jukka Rissanen ad27d0e39e net: ipv6: Check the size of the ICMPv6 echo-req packet
The minimum size is 8 bytes, drop packet if shorter.

Fixes #10970

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-06 11:08:15 +02:00
Mariusz Skamra 50768a6bba Bluetooth: Do not compile GATT response handlers if Client is disabled
This will exclude GATT Client response handlers from compilation
if GATT Client support is disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-11-06 09:33:19 +02:00
Sebastian Bøe 637c41a382 Bluetooth: controller: Refactor the k32src_wait() function
This is a pure refactoring of the k32src_wait function. It used the
following rules when refactoring:

Don't use the preprocessor when unprocessed C language suffices.

Don't undefine macro's.

Avoid global variables when possible.

Use consistent names for similiar things (hf_clock, lf_clock).

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-05 21:46:00 +01:00
Aurelien Jarno fdfa975b9d usb: device: fix wrong direction in usb_transfer_ep_callback
In case no transfer is ongoing, the usb_transfer_ep_callback consumes
the received data. This is however associated with the wrong test. USB
is host centric, so data reception on the device is signaled by
USB_DC_EP_DATA_OUT and not USB_DC_EP_DATA_IN.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-05 16:33:01 +01:00
Paul Sokolovsky 6203020bfd subsys: console: Switch to POSIX-like read/write interface
Tty device gets only read/write calls, but console retains
getchar/putchar for convenience.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 17:31:39 -05:00
Paul Sokolovsky 9d3b48fd48 subsys: console: tty: Allow to specify transmit timeout
Previously, transmit was effectively non-blocking - a character either
went into buffer, or -1 was returned. Now it's possible to block if
buffer is full. Timeout is K_FOREVER by default, can be adjusted
with tty_set_tx_timeout() (similar to receive timeout).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 17:31:39 -05:00
Paul Sokolovsky 680085b3e2 subsys: console: tty: Allow to specify receive timeout
This allows to specify receive timeout, instead of previously
hardcoded K_FOREVER value. K_FOREVER is still the default, and can
be changes after tty initialization using tty_set_rx_timeout() call,
and timeout is stored as a property of tty. (Instead of e.g. being
a param of each receive call. Handling like that is required for
POSIX-like behavior of tty).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 17:31:39 -05:00
Paul Sokolovsky f750ce56ce net: lib: sockets: Switch to use fdtable
Previously the "socket file descriptors" were just net_context
pointers cast to int. For full POSIX compatibility and support
of generic operations line read/write/close/fcntl/ioctl, the
real file descriptors should be supported, as implemented by
fdtable mini-subsys.

Socket implementation already has userspace vs flatspace dichotomy,
and adding to that ptr-fds vs real-fds dichotomy (4 possible cases)
is just too cumbersome. So, switch sockets to real fd's regardless
if full POSIX subsystem is enabled or not.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Flavio Ceolin aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Flavio Ceolin a406b88fca kernel: Remove duplicated identifier
There was an struct and a variable called _kernel. This is error prone
and a MISRA-C violation. It is changing the struct to have a unique
identifier.

MISRA-C rule 5.8

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
David B. Kinder ee47f7fb7a doc: fix kconfig misspellings
Fix misspellings in Kconfig files that show up in the configuration
documentation (and make menuconfig screens).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-11-02 17:58:16 -04:00
Anas Nashif 0ab6da1e03 logging: make LOG_LEVEL depend on LOG
We are getting all of those Kconfigs related to logging even without
having logging enabled, make the variables depend on LOG for all users
of the template.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Anas Nashif 282291cd6e subsys: mcumgr: make Kconfigs depend on MCUMGR
We had the if in the wrong place causing some Kconfigs to be set even if
mcumgr was not configured in.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Anas Nashif b4caa74684 subsys: filesystem: move conditional location
We had the if in the wrong place causing some Kconfigs to be set even if
filesystem was not configured in.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Anas Nashif 412a0b0682 subsys: disk: move conditional location
We had the if in the wrong place causing some Kconfigs to be set even if
DISK_ACCESS was not configured in.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Anas Nashif c01339554b dfu: image_mgr: make Kconfigs depend on IMG_MANAGER
Add an if statement around IMG_MANAGER options.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Kumar Gala f05888446d subsys: usb_device: Fix removal of board.h
Restore including board.h to get USB_VUSB_EN_GPIO and associate defines
if the board.h sets them.  This should move to device tree in the
future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-02 14:55:53 -04:00
Jukka Rissanen cf063fe85b net: Rename net_is_xxx...() functions to net_xxx_is...()
Unify the function naming for various network checking functions.

For example:
     net_is_ipv6_addr_loopback() -> net_ipv6_is_addr_loopback()
     net_is_my_ipv6_maddr() -> net_ipv6_is_my_maddr()
etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 14:52:33 -04:00
Vinayak Kariappa Chettimada 133d3870b3 Bluetooth: controller: Fix integer overflow in scheduling code
Fix an integer overflow in the scheduling implementation
that calculates whether resources required for next radio
event be retained.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-11-02 12:26:32 -04:00
Pavel Kral e781997450 logger: rtt backend don't let starve others in blocking mode
When a RTT logger backend is configured to blocks, allow other threads
to continue during waiting for data to be transferred to host.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-11-02 12:24:05 -04:00
Krzysztof Chruscinski 62d011549a logging: Support for up to 15 arguments in log message
Extended support in the log_core and log_output to 15 arguments
which is the hard limitation of log message format.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 12:22:01 -04:00
Pushpal Sidhu 4c0441b666 fs: fat_fs: Implement fs_rename API
This API call clobbers the destination path as per the fs.h API
definition.

Signed-off-by: Pushpal Sidhu <psidhu.devel@gmail.com>
2018-11-02 12:21:22 -04:00
Christoph Schramm f17a9c93b4 shell: Add a Segger RTT backend
Fixes: #8394

Signed-off-by: Christoph Schramm <schramm@makaio.com>
2018-11-02 12:19:58 -04:00
Jukka Rissanen 6c628737e0 net: ipv6: Verify ICMPv6 checksum before accepting packet
Make sure that ICMPv6 checksum is correct before continuing
processing the packet.

Fixes #10971

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 16:03:18 +02:00
Jukka Rissanen 4b7d8fb76d net: ipv6: Drop organisation scope multicast dst address pkt
If we receive an IPv6 packet with organisation scope multicast
address FF08:: then we must drop it as those addresses are
reserved for organisation network traffic only.

Fixes #10961

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 84e85db994 net: ipv6: Drop site scope multicast dst address pkt
If we receive an IPv6 packet with site scope multicast
address FF05:: then we must drop it as those addresses are
reserved for site network traffic only.

Fixes #10960

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen fbaf9d615c net: ipv6: Drop zero scope multicast packet
The zero scope is a reserved value so it should not be used
so drop it.

Fixes #10958

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 1e293b4089 net: ipv6: Drop interface scope multicast dst address pkt
If we receive an IPv6 packet with interface scope multicast
address FF01:: then we must drop it as those addresses are
reserved for local network traffic only.

Fixes #10959

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Jukka Rissanen 1e4f268ea9 net: if: Move link address assert check to net_if_up()
For Bluetooth, the link address is set only after the Bluetooth
connection is established. Because of this, place the link address
check to net_if_up() because at that point the link address should
be set properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:08:39 +02:00
Krzysztof Chruscinski 39e355eb5b shell: Fix TXDONE signal not being cleared
Fixed the case when TXDONE signal was not cleared. Bug was unnoticed
because UART backend was synchronous.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 08:54:49 -04:00
Krzysztof Chruscinski fe9f4900ff shell: Postpone enabling log backend
Shell log backend was enabled too early, before shell thread was
up and running. That could lead to failure if log thread passes
log message to shell log backend.

Additionally, modified algorithm for multiplexing log output with
shell prompt. In case of logs flood prompt was unreadable because
it was deleted immediately after being printed. Added k_sleep
after printing prompt if any character was typed. This ensures that
shell prompt is readable if user uses it.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 08:54:49 -04:00
Paul Sokolovsky 51c7b5f73a net: if: Assert that link layer addr was set by driver
There's a lot of code which assumes net_if_get_link_addr(iface)->addr
Forgetting to set it leads to deferred, spectacular crashes. It's
impractical to assert it on every usage. So, instead let's assert
it after call to driver->init(), as that is supposed to set it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-02 10:18:17 +02:00
Andrei Emeltchenko 62f3f8e92a net: llmnr_responder: Fix uninitialized use Warning
Fixes following warning:
...
subsys/net/lib/dns/llmnr_responder.c:24:0:
subsys/net/lib/dns/llmnr_responder.c: In function ‘recv_cb’:
include/net/net_pkt.h:1203:9: warning: ‘addr’ may be used uninitialized
in this function [-Wmaybe-uninitialized]
  return net_pkt_append(pkt, len, data, timeout) == len;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsys/net/lib/dns/llmnr_responder.c:306:14: note: ‘addr’ was declared
here
  const u8_t *addr;
              ^~~~
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-02 10:03:04 +02:00
Andrei Emeltchenko 006231bbdc net: llmnr_responder: Fix unused Warning
Fixes warning:
warning: ‘ipv6’ defined but not used [-Wunused-variable]
 static struct net_context *ipv6;

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-02 10:03:04 +02:00
Jakub Rzeszutko 2445ba7a26 shell: fix possible hanging reason when history feature is used
Fixed possible race condition.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-11-01 13:39:20 +01:00
Jukka Rissanen 87dd0e7e6b net: ipv6: Drop outside pkt with ::1 dst or src address
We must drop packet that is received from outside and which has
IPv6 loopback address (::1) either as a destination address or
source address.

Fixes #10933

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-01 14:32:21 +02:00
Kumar Gala cabdf5e9dd subsys: Remove board.h include
The subsys code doesn't need anything from board.h so lets remove the
include.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:15:18 +01:00
Ravi kumar Veeramally c8954d3544 net: coap: CoAP library support over sockets
CoAP library is migrated to support over socket based
applications or other higher layer protocols. Most of the
API's and functionality is kept as it is except few changes.

net_pkt/net_buf is removed from CoAP library. Now it expects
a pre-allocated flat buffer and length. If there is not enough
space to append any data, library simply returns an error.
It's user's responsibility to allocate and free memory.

One change in functionality is, earlier coap_pending_clear()
used to clear the memory, but now it's user's responsibility
to free the memory.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-10-31 19:44:25 -04:00
Maureen Helm a5b6215a06 debug: openocd: Add floating point context to openocd offsets
Adds preemptive and cooperative floating point contexts to the openocd
offsets array for arm and x86 architectures.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-31 12:05:11 -04:00
Maureen Helm 1b2ca67f78 debug: openocd: Add thread name to openocd offsets
Adds the thread name to the openocd offsets array so openocd and pyocd
can show thread names in the debugger.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-31 12:05:11 -04:00
Krzysztof Chruscinski 4213dbb2e6 logging: add arguments counting in log_generic
Log_generic() can be used by external logger systems to map to zephyr
logger subsystem. Function has variable number of arguments. So far
logger assumed maximal number of arguments to avoid scanning
string to count number of arguments. In outcome, uninitialized memory
was treated as valid argument in a message (but discarded when actual
string formatting took place). Valgrind complained about that so
log_generic() has been extended to scan the string and count number
of arguments and build message with valid number of arguments.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-31 14:32:21 +01:00
Pavel Kral a19726ee1e logger: console: init rtt only once
As RTT is used by more subsystem in Zephyr, initialization is moved
from RTT console and RTT logger backend to common kernel init phase.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 9eba380cf7 logger: replace hardcoded constant in rtt backend
Replace hardcoded report limit of dropped message by macro.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 02afc16dcb logger: fix line_pos setup in rtt backend drop mode
Fix initial write position in line_buf when drop mode is selected.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 0459ee4fa1 logger: better code maintainability in rtt backend
Better use of preprocessor to be aware of external library API
changes.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral ced1592e54 logger: fix PR codestyle issues
Fix some issues as complained by shippable.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
David Kinder a7e74b8fdc subsys: logging: Fix grammar in Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig

Signed-off-by: David Kinder <david.b.kinder@intel.com>
Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 1a583fa8be ext: debug: segger: Add USE_SEGGER_RTT that enables RTT libraries.
This option allows to explicitly include Segger RTT libraries and
enables use of it for various subsystems. It is disabled by
default as it consumes more RAM.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 2c84fd2631 ext: debug: segger: Terminal sharing using SEGGER_RTT_LOCK/UNLOCK macros
This commit allows to share default RTT (terminal) buffer with various
Zephyr subsystems.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral f19f217f08 logger: fix grammar/punctuation in rtt backend Kconfig
Fix some czenglish grammar issues.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 89b355c916 logger: Add a Segger RTT backend
Add logger backend that uses Segger RTT for message output. Several
options are provided allowing configuration of up-buffer and logger
behaviour.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Krzysztof Chruscinski 9f7e25ad22 logging: Fix possible out-of-bound access in log_output
Coverity issue #187067

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-30 15:29:28 +01:00
Ruslan Mstoi de78a7af28 net: icmpv4: Drop ICMPv4 packet with zero checksum
ICMPv4 checksum is not optional and thus cannot be zero. Hence, drop
packet with invalid zero ICMPv4 checksum.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-10-30 16:13:57 +02:00
Benoit Leforestier 16451850e7 C++: Fix vtable with libstdc++
__cxxabiv1 is an internal namespace used by GNU's libstdc++.
When linking with C++ standard library (libstdc++),
__cxxabiv1::__class_type_info is already defined inside.
If user code contains virtual classes,
__cxxabiv1::__class_type_info is defined twice.

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2018-10-30 08:11:28 -04:00
Piotr Zięcik 708468bdce Bluetooth: controller: Optimize RNG access
This commit optimizes access to RNG driver by taking advantage
of the data structures layout. As result, number of calls to RNG
driver is reduced.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Piotr Zięcik 615efcce69 drivers: entropy: nrf5: Remove entropy_nrf_get_entropy_isr() function
The entropy_nrf_get_entropy_isr(), which is specific to this driver,
is in fact equivalent of generic entropy_get_entropy_isr(..., 0).

This commit removes the entropy_nrf_get_entropy_isr() function
and replaces its usage by call to generic entropy API.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-10-30 11:16:34 +01:00
Marek Pieta e87193896a subsys: debug: tracing: Fix thread tracing
Change fixes issue with thread execution tracing.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2018-10-29 22:09:12 -04:00
Kumar Gala 42dc4e9b51 usb: device: Fix compile warning
/home/galak/git/zephyr/subsys/usb/usb_device.c: In function ‘usb_transfer_work’:
/home/galak/git/zephyr/subsys/usb/usb_device.c:1156:58: error: passing argument 4 of ‘usb_dc_ep_write’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   ret = usb_dc_ep_write(ep, trans->buffer, trans->bsize, &bytes);
                                                          ^
In file included from /home/galak/git/zephyr/include/usb/usb_device.h:39:0,
                 from /home/galak/git/zephyr/subsys/usb/usb_device.c:68:
/home/galak/git/zephyr/include/drivers/usb/usb_dc.h:270:5: note: expected ‘u32_t * const {aka long unsigned int * const}’ but argument is of type ‘int *’
 int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
     ^~~~~~~~~~~~~~~
/home/galak/git/zephyr/subsys/usb/usb_device.c:1168:8: error: passing argument 4 of ‘usb_dc_ep_read_wait’ from incompatible pointer type [-Werror=incompatible-pointer-types]
        &bytes);
        ^
In file included from /home/galak/git/zephyr/include/usb/usb_device.h:39:0,
                 from /home/galak/git/zephyr/subsys/usb/usb_device.c:68:
/home/galak/git/zephyr/include/drivers/usb/usb_dc.h:328:5: note: expected ‘u32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len,
     ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:52:00 -04:00
qianfan Zhao 02bd01e856 subsys: logging: Using struct to manger log_strdup buffer.
log_strdup requested for a piece of memory, with the first 4 bytes as
the number of references and the next used to copy strings. In the
implementation of this function, the memory is managed by user and
is a little hard to understand.

Rewriting this part of code, using structure to manage the memory
requested, make it easier to understand.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-10-29 09:46:01 -04:00
Benoit Leforestier 26e0f9a9e1 Build: Improve C++ support
Can choose the C++ standard (C++98/11/14/17/2a)
Can link with standard C++ library (libstdc++)
Add support of C++ exceptions
Add support of C++ RTTI
Add C++ options to subsys/cpp/Kconfig
Implements new and delete using k_malloc and k_free
if CONFIG_HEAP_MEM_POOL_SIZE is defined

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2018-10-29 09:15:04 -04:00
Joakim Andersson 2487d55403 Bluetooth: host: Fix identation of struct members
Fix identation of struct members so that all are aligned.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Joakim Andersson c2d62a29f0 Bluetooth: host: Require 128-bit encryption key for security level 4.
In Bluetooth 5 the definition of LE security mode 1, has changed.
LE Security Mode 1 level 4 requires authenticated LE Secure Connections
pairing with encryption using a 128-bit strength encryption key.
This also changes the behaviour when a security request and response
would end up with a security level that is lower than the one requested.
Before pairing would complete, and the link would disconnect with error
authentication failure. Instead a SMP will abort pairing with error code
authentication requirement, or encryption key size.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-29 14:10:26 +02:00
Mariusz Skamra 45411bc08d Bluetooth: Update advertising data without advertising restart
This adds new API fuction to update running advertising data.
It will remove the need of advertising restarting.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-29 12:30:34 +02:00
Jakub Rzeszutko 3aaf280108 shell: fix assert in wildcard plugin
Fixing a variable name in assert check in a function subcmd_get.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-29 09:58:08 +00:00
Jakub Rzeszutko 7e3a6e85d3 doc: shell: add information about dummy backend
Shell documentation has been updated with information about new
backend called DUMMY.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-28 11:45:41 -04:00
Jakub Rzeszutko c3bc7180b0 subsys: shell: add dummy backend to simplify commands testing
Added dummy backend which can be enabled with Kconfig. By default it is
disabled because it needs the same amount of memory as other phisical
backends. It shall be use only for commands testing purposes.

Improved shell_execute_cmd function, now it clears command context
before new command will be executed.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-28 11:45:41 -04:00
Ramakrishna Pallala 359341203f power: Add OS Power Management debug hooks
Add the necessary PM hooks like Low Power state entry
count and residencies for logging and debugging purposes.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-10-28 11:44:22 -04:00
Björn Stenberg 01ff384f10 net: ipv6: Remove incorrect length assignment in MLDv2
This assignment causes the later code to overwrite part of the
packet, making it malformed.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2018-10-26 22:28:43 +03:00
Mariusz Skamra 74318e61ca Bluetooth: Change l2cap accept callback return error
This changes EKEYREJECTED to EPERM due to newlib dependencies
errors.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-26 16:56:01 +01:00
Sebastian Bøe 5e23278bab Bluetooth: Controller: Use a different flag for speed optimization
The bluetooth controller has been using the flag '-Ofast' to keep
within a real-time limit. There are two problems with this; firstly,
when a project should be optimized for size it is standard to use -O2,
not -Ofast.

Secondly, optimization flags have been deemed to be non-portable, so
instead of directly using "-Ofast" we should use the intent-macro
OPTIMIZE_FOR_SPEED_FLAG to ensure toolchain portability.

Testing has shown that we are still within the real-time limit when
changing from -Ofast to -O2. -Ofast is about 1us and 1% faster, but
increases the code size by 13kB (5% of the available flash on a
nRF51).

Since the slowdown is comparatively small compared to the code size
increase we have decided to use -O2 in place of -Ofast.

Other optimization combinations were also measured and their results
can be seen below:

-Ofast in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 45, 132.

-O2 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      125840 B       256 KB     48.00%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 51, 133

-O3 in BLE Controller and in #pragma in entropy driver.

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138920 B       256 KB     52.99%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 75, 50, 132.

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SIZE_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      120124 B       256 KB     45.82%

        [bt] [ERR] isr_rx_conn: assert: '!radio_is_ready()' failed

No extra CFLAGS for BLE and entropy driver (pragmas removed), using
CONFIG_SPEED_OPTIMIZATIONS=y

        Memory region         Used Size  Region Size  %age Used
                   FLASH:      138004 B       256 KB     52.64%

        [bt] [INF] encode_control: l: 6, 6, 7; t: 61, 51, 130.

NB: RAM usage differences were insignificant.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-26 15:55:49 +01:00
Jukka Rissanen b34da1ad62 net: Drop IPv4 packet if source address is broadcast one
Source address cannot be broadcast one so check it properly.

Fixes #10782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 7d83543379 net: Properly handle pkt IPv4 broadcast destination address
If we receive an IPv4 that has broadcast destination address, then
properly handle it.
This means that for
  * ICMPv4, if CONFIG_NET_ICMPV4_ACCEPT_BROADCAST is set (this is the
    default value) and we receive echo-request then accept the packet.
    Drop other ICMPv4 packets.
  * TCP, drop the packet
  * UDP, accept the packet if the destination address is the broadcast
    address 255.255.255.255 or the subnet broadcast address.
    Drop the packet if the packets broadcast address is not in our
    configured subnet.

In sending side, make sure that we do not route broadcast address
IPv4 packets back to us. Also set Ethernet MAC destination address
properly if destination IPv4 address is broadcast one.

Fixes #10780

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen aa2240a444 net: ip: Add function to check if IPv4 address is broadcast one
Add utility function that returns true if given IPv4 address is
a broadcast address. This will be used in later commits to check
received packet IPv4 source and destination addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 5f66852f62 net: ipv4: Fix network byte ordering for netmask related computing
Remove extra ntohl() calls when checking IPv4 address against
a subnet address.

Convert also the IPv4 address to be const as the netmask related
functions do not change its value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 15:37:21 +03:00
Jukka Rissanen 601426866a net: Set used transport protocol to net_pkt
Cache the used transport protocol in net_pkt. This way we can
avoid traversing IP header to get the last protocol in network
packet. This is mostly an issue in IPv6 which can have a long
list of extension headers after IPv6 header and before the
transport protocol header.

Fixes #10853

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 14:08:43 +03:00
Gil Pitney 621ec506e2 net: wifi: Update connect cmd to deal with new shell quoted args
Previously, the wifi shell needed to remove the quotes from the
SSID parameter, passed in by the underlying shell.

The new shell is now able to parse quoted strings as arguments,
so this adjustment can be removed.

Otherwise, it results in a failure to connect to an AP, as the first
character of the SSID name is stripped off.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-25 20:46:38 +03:00
Szymon Janc 2abd05e9fc Bluetooth: controller: Compile conn complete due to cancel conditionally
BT_HCI_ERR_UNKNOWN_CONN_ID can only be sent when master role is enabled.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Szymon Janc b732a9a69b Bluetooth: host: Compile master role conn complete conditionally
Connection complete event with error code can be received only for
central role and can be compiled conditionally.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-25 17:03:59 +01:00
Ruslan Mstoi f1c67615cf net: ipv6: Add Destination Options Header support
This patch adds support for IPv6 Destination Options Header

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-10-25 16:50:15 +03:00
Jukka Rissanen 72a37e59e5 net: log: Max debug level was forced too high
Wrong Kconfig template was used for max debug level which caused
the max level to be the default level (ERROR). This prevented
all debug prints from showing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-25 15:05:19 +03:00
Pawel Dunaj 8d55b03414 subsys: usb: class: hid: Allow control of USB poll interval
This closes issue #10807

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2018-10-25 12:54:24 +01:00
Mariusz Skamra c04b70469b Bluetooth: shell: Add possibility to reject L2CAP CoC conn request
This adds a possibility to reject incomming LE Connection request
due to insufficient authorization or encryption key size.
This is needed for qualification purposes

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Mariusz Skamra e82ebb2c84 Bluetooth: L2CAP: Extend available return codes from accept cb
This adds support for returning various return codes from
the channel accept callback.
This is needed for implementation of incoming connection
authorization for certification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Mariusz Skamra 2c6065c2d1 Bluetooth: L2CAP: Rename LE Connection Response Results
Rename connection response results to map those that are defined
for BR.
BR: BT_L2CAP_BR_*
LE: BT_L2CAP_LE_*

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-10-25 08:02:54 +01:00
Johann Fischer ce4be3af86 logging: fix out of bounds write in log_strdup
log_strdup writes out of bounds of a strdup slab.
e.g: CONFIG_LOG_STRDUP_MAX_STRING=46 and
     LOG_STRBUF_STR_SIZE=47 then in the line L:529
sdupl[LOG_STRBUF_STR_SIZE - 1] = '\0';
writes out of bounds because the available buffer space
is only 44 bytes (rounded up to 48 bytes and minus 4 bytes
for the allocated flag).

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-10-24 16:41:21 +01:00
Jakub Rzeszutko 4c420ff3bf shell: fix history feature
When user was typing a new command and next pressed an up arrow
shell has displayed previously executed command. Next it was not
possible to display back currently edited command using a down arrow.

Fixes #10766.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-24 14:31:25 +01:00
Jukka Rissanen b82c9d85b4 net: buf: Use proper Kconfig log level template
The net_buf log level Kconfig setting was using template from
networking, which might not be available for Bluetooth code.
This caused the log level to be ignored.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-24 15:10:33 +03:00
Jukka Rissanen 7797c01eb5 net: Honor max log level in net
The maximum log level was using wrong template which caused
the max value to be ignored.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-24 15:10:33 +03:00
Andrei Emeltchenko a6340c588d usb: loopback: Add documentation markers
Add markers to the code to be included in the USB documentation.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-24 11:18:12 +01:00
Krzysztof Chruscinski 5d28fcd689 logging: Add optional function name prefix
Extended logger to support optional log message prepending with
function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Krzysztof Chruscinski c696e68bb9 logging: Added support for 10 arguments in log message
Extended supported number of arguments in log message. Support for
messages consisting of more than 2 chunks had to be added. So far
messages could consist of one chunk (up to 3 args) or two chunks
(2 args in first chunk and 7 in second chunk). Once 2+ chunks
support is added number of arguments is techinically limited to
15 (4 bit field). log_core and log_output extended to suppor 10
arguments.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Jukka Rissanen 9051068630 net: buf: Fix debug level setting
Some of the net_buf related tests failed if they enabled
CONFIG_NET_BUF_LOG setting.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-23 10:36:01 +03:00
Jukka Rissanen eb6f37d753 net: log: Add missing spaces around = in Kconfig.debug
The CONFIG_NET_DEFAULT_LOG_LEVEL template entry was only partially
fixed earlier and some spaces were not there around "=".

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Jukka Rissanen 469ff39b11 net: lib: init: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from init.c as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Jukka Rissanen fb73aee36f net: openthread: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from OpenThread code as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Jukka Rissanen be092a607a net: buf: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from buf.c as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Robert Lubos 683628ab73 net: tls: Do not assume PSK id is NULL terminated
Current TLS socket implementation assumed that PSK ID stored in
credential manager is NULL terminated. It's actually better to store
only the string content, as the string length is stored as well. This
approach is less confusing, when a user is not operating on C strings
but on a non-NULL terminated byte array.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-10-22 10:32:07 +03:00
Artur Pacholec 556dc7fdfc shell: Fix typo
Added a missing letter in the function name.

Signed-off-by: Artur Pacholec <arturo182@tlen.pl>
2018-10-21 17:25:14 -04:00
Satya Bhattacharya 6063707662 bluetooth: shell: Uninitialized scalar variables
Initialize variables chan_map in bt.c
Pass NULL and 0 directly to bt_le_adv_start()
Coverity-CID: 188735
Coverity-CID: 188729

Fixes #10588 #10594

Signed-off-by: Satya Bhattacharya <satyacube@gmail.com>
2018-10-21 15:09:54 +03:00
Michael Scott 263dab3eda net: lwm2m: fix compile warning related to Logger changes
When DBG level for CONFIG_LWM2M_LOG_LEVEL is disabled, a compiler
warning is generated:
In file included from include/logging/log.h:11:0,
                 from subsys/net/lib/lwm2m/lwm2m_engine.c:28:
subsys/net/lib/lwm2m/lwm2m_engine.c: In function ‘engine_add_observer’:
subsys/net/lib/lwm2m/lwm2m_engine.c:558:3: warning: implicit
declaration of function ‘sprint_token’
[-Wimplicit-function-declaration]
   sprint_token(token, tkl), lwm2m_sprint_ip_addr(addr));
   ^

Let's remove the #if guards around sprint_token() and let
the Linker remove it when not needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-19 17:32:36 -04:00
Jukka Rissanen 8f76169190 net: wifi: Make sure shell is valid before trying to print to it
It is possible that connect callback is called when shell is not
yet set. Make sure to check this and fallback to use printk() if
shell_printf() cannot be used.

Fixes #10617

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16:48 -04:00
Jukka Rissanen 1d72af0393 net: wifi: Fix connect command parameter checks in shell
The connect command parameters were not checked properly if
user decided to supply only mandatory parameters.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16:48 -04:00
Jukka Rissanen dab9030ab9 net: wifi: Check offloading pointers before accessing them
If the device does not support wifi offloading, then return -ENOTSUP
so that wifi support can be enabled for testing purposes even if
the actual device does not have wifi support. This is happens for
example in qemu which does not support wifi offloading.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:16:48 -04:00
Jukka Rissanen 7c34dcd315 net: app: Fix register and unregister functions
Make sure that we define and declare the _net_app_register() and
_net_app_unregister() functions properly if net_app logging level
is set to debug.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:13:48 -04:00
Jukka Rissanen c42b41ed21 net: Honor default log level
Make sure that if user has not set log level, the default one
is used properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 16:13:48 -04:00
Johan Hedberg 9f18ff9baf Bluetooth: Convert monitor protocol to a logger backend
Convert the monitor protocol to a proper logger backend. This also
means that our log.h headerfile gets greatly simplified.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg cd4cf4e580 Bluetooth: Convert string helpers to use log_strdup
This reduces the multiple buffer requirement to a single buffer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 343c53e841 Bluetooth: Switch from SYS_LOG to logger-based logging
Initial conversion to use syslog instead of logger.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 5bd6bc4bed Bluetooth: log: Make address helpers more robust
Use irq_lock (same way as bt_hex does it) and increase the number of
static buffers to reduce the risk of reuse before a buffer gets
processed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 6a68b29f41 Bluetooth: Only build bt_hex() if BT_DEBUG is enabled
bt_hex() should be included in the same block as the address helpers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Paul Sokolovsky cdeddee7c6 net: Set names for threads used by the network subsys/libs
Previously, these either used generic names like "workqueue" (so,
it wasn't possible to distiguish tx and rx workqueues) or didn't
set for net management thread. Here's an example of thread dump
in a typical system (using stack_analyze() call):

rx_workq (real size 4092):	unused 3696	usage 396 / 4092 (9 %)
tx_workq (real size 4092):	unused 3692	usage 400 / 4092 (9 %)
net_mgmt (real size 4092):	unused 3772	usage 320 / 4092 (7 %)
sysworkq (real size 4092):	unused 3512	usage 580 / 4092 (14 %)
idle (real size 252):	unused 64	usage 188 / 252 (74 %)
main (real size 4732):	unused 3672	usage 1060 / 4732 (22 %)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-19 07:58:45 -04:00
Jakub Rzeszutko 147122e77f shell: examples unification
Updating examples according to new return value of function
shell_cmd_precheck.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-19 13:35:56 +02:00
Jakub Rzeszutko a88d5d7e4f shell: commands help unification
1. Changed return value of function: shell_cmd_precheck from bool to
int. Now it returns:
  0       when argument count is correct and help print is not requested
  1       when help was requested and printed
  -EINVAL on wrong arguments count
This change simply shell_cmd_precheck usege in command handlers.

2. Unified all commands in shell_cmd.c file.

3. Fixed a bug where help was not printed on wrong argument count.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-19 13:35:56 +02:00
Anas Nashif 3aa2a1c6db flash: make flash shell generic
This shell command was tied to bluetooth and the bluetooth shell and
also had messages all related to nordic ICs.
Make it generic and put it under drivers/flash/ so it can be included by
anyone and independently of bluetooth.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-19 11:49:18 +02:00
Carles Cufi 322647129f subsys: logging: Add CR/LF handling flags
Add 2 new flags to control the output of newlines by the logger output
module. By default the logger adds both CR and LF, and with these 2 new
flags it is now possible to request LF only or no newlines at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-18 17:53:11 -04:00
Szymon Janc 30ce313482 Bluetooth: host: Avoid using out-of-scope pointer
Mkae sure that variable pointed by params is valid when passing it
as function argument.

Fixes #10587

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-18 21:22:33 +03:00
Jukka Rissanen 10c77dfbba net: gptp: Calculate GM rate ratio properly
Typo when calculating new value for local_time_n.low, the calculation
was just a constant expression and the value was not modified.

Coverity-CID: 188759
Fixes #10568

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-18 20:35:02 +03:00
Jukka Rissanen 89783f5282 net: connection: Fix debug print for connection index
The connection index was printed incorrectly in debug print.

Coverity-CID: 188742
Coverity-CID: 188753

Fixes #10583 #10574

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-18 20:35:02 +03:00
Anas Nashif 79f434273e shell: kernel: list configured devices
Very simple command to list configured devices and their priorities.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-18 10:15:50 -04:00
Andrei Emeltchenko 4bec02019b usb: logs: Remove newlines from the logs
Fixes double newline in the logger output.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-18 09:45:29 -04:00
Ramakrishna Pallala 8b20f9dbab subsys: power: Add an API for force suspending the devices
Add an API for force suspending the devices. This API can be
called during unexpected system shutdown/poweroff scenarios
to safely turnoff the devices.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-10-17 22:02:06 -04:00
Tedd Ho-Jeong An 548361c4e2 net: ip: Fix compile error due to config dependency
This patch fixes the compile error when CONFIG_NET_PKT_LOG_LEVEL
is LOG_LEVEL_DBG.

> subsys/net/ip/net_shell.c: In function ‘context_info’:
> subsys/net/ip/net_shell.c:2893:106: error: ‘struct net_buf_pool’
> has no member named ‘avail_count’
> subsys/net/ip/net_shell.c:2893:125: error: ‘struct net_buf_pool’
> has no member named ‘name’

In struct net_buf_pool, 'avail_count' and 'name' are depends on
CONFIG_NET_BUF_POOL_USAGE.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2018-10-17 21:35:24 +03:00
qianfan Zhao a52186ded2 net: shell: Return -ETIMEDOUT if ping target timeout
The previous code returned 0 even if ping failed(timeout).

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-10-17 18:04:18 +03:00
Satya Bhattacharya 4f4c7e2b1a net: rpl: Null pointer dereferences
Check for NULL IPv6 addr values from net_if_ipv6_get_ll() in rpl.c
If NULL, print out an error statement stating that no proper IPv6
address was found
Coverity-CID: 188169

Fixes #10094.

Signed-off-by: Satya Bhattacharya <satyacube@gmail.com>
2018-10-17 14:33:36 +03:00
Sebastian Bøe 2aea475846 Bluetooth: host: Improve error feedback on invalid input
Improve the error feedback when calling bt_le_adv_start and inputting
too much data in the advertisement.

Error feedback before:

Bluetooth initialized
Advertising failed to start (err -22)

Error feedback after:

Bluetooth initialized
[bt] [ERR] set_ad: Advertising data does not fit in buffer
Advertising failed to start (err -22)

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-17 13:37:24 +03:00
Anas Nashif 58134e0f78 subsys: disk access: move to new logger
Move to the new logger.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-16 17:30:09 -04:00
Andy Ross b8ffd9acd6 sys_clock: Make clock_always_on true by default
This flag is an indication to the timer driver that the OS doesn't
care about rollover conditions of the tick count while idling, so the
system doesn't need to wake up once per counter flip[1].  Obviously in
that circumstance values returned from k_uptime_get_32() are going to
be wrong, so the implementation had an assert to check for misuse.

But no one understood that from the docs, so the only place these APIs
were used in practice were as "guards" around code that needed to call
k_uptime_get_32(), even though that's 100% wrong per docs!

Clarify the docs.  Remove the incorrect guards.  Change the flag to
initialize to true so that uptime isn't broken-by-default in tickless
mode.  Also move the implemenations of the functions out of the
header, as there's no good reason for these to need to be inlined.

[1] Which can be significant.  A 100MHz ARM using the 24 bit SysTick
    counter rolls over at about 6 Hz, and if it had to come out of
    idle at that rate it would be a significant power issue that would
    swamp the gains from tickless.  Obviously systems with slow
    counters like nRF or 64 bit ones like RISC-V or x86's TSC aren't
    as affected.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross 393ec71ec3 clock: Remove CONFIG_TICKLESS_KERNEL_TIME_UNIT_IN_MICRO_SECS
This was only used in a few places just to indirect the already
perfectly valid SYS_CLOCK_TICKS_PER_SEC value.  There's no reason for
these to ever have been kconfig units, and in fact the distinction
appears to have introduced a hidden/untested bug in the power
subsystem (the two variables were used interchangably, but they were
defined in reciprocal units!).

Just use "ticks" as our time unit pervasively, and clarify the docs to
explain that.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Johann Fischer f531e0d62e subsys: add monochrome character framebuffer
Add monochrome character framebuffer for monochrome
graphic dot matrix displays and electrophoretic displays.

These displays are mostly monochrome and can only display
black and some other color, for example white. Typically,
a byte controls 8 pixels, arranged vertically or horizontally
depending on the controller or settings.
The API is not suitable to display graphics, the purpose is
to display text or symbols. It is possible to use several fonts.
A font can also consist of graphic symbols only and thus,
for example, enable the realization of a menu.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-10-16 14:54:47 -04:00
Joakim Andersson 912cdc0b8e Bluetooth: host: Allow to disable legacy pairing.
Add option to disable legacy pairing and only use secure connection.
If legacy pairing was requested pairing will be denied with status
insufficient authenticated

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-16 14:25:56 +03:00
Vinayak Kariappa Chettimada 51574c177f Bluetooth: controller: Avoid retransmission of NACK-ed Tx PDU
Added implementation to avoid retransmitting NACK-ed Tx PDU,
to save on current consumption in retrying to transmit in
case peer device has no free buffer to receive the PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-16 10:32:41 +02:00
Andrei Emeltchenko 557f0ed72e usb: Enable log level menu after enabling module
This makes menuconfig much more readable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-15 12:58:27 -04:00
Alberto Escolar Piedras 5f39dbb1b0 Bluetooth: Use new nrf COMPATIBLE options
To allow the BLE stack to be used both in the real nRF platforms
and simulated ones, change the used macros in the code to the
COMPATIBLE ones.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-15 09:36:37 -04:00
Varun Sharma 3de44b748c subsys: fs: Use template to define CONFIG_FS_LOG_LEVEL
Use "subsys/logging/Kconfig.template.log_config" as template

Signed-off-by: Varun Sharma <varun.sharma@intel.com>
2018-10-15 09:18:03 -04:00
Varun Sharma 7622fc37a0 subsys: fs: Migrate to new logging subsys
subsys:fs : Migrate from `SYS_LOG` to `LOG` logging mechanism.

tests: subsys: fs: Enabled CONFIG_LOG in prj.conf

Signed-off-by: Varun Sharma <varun.sharma@intel.com>
2018-10-15 09:18:03 -04:00
Krzysztof Chruscinski 0ac7f76017 fs: Port shell commands to new shell
Port existing commands to the new shell subsystem.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-15 13:49:26 +02:00
Vinayak Kariappa Chettimada d80fee1ecb Bluetooth: controller: Fix master role RSSI measurement
Fix broken master role RSSI measurement. Since the original
contribution clean up into Zephyr, the radio shorts that was
set for measuring the RSSI for master role has been broken,
as it was cleared by the radio switching code further in the
Tx ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-15 11:08:00 +02:00
Jukka Rissanen 9ae7c394ab net: openthread: Convert to use new shell
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Jukka Rissanen d8defbd08a net: bt: Convert network Bluetooth shell to use new shell
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Jukka Rissanen 1f4bae79e2 net: ieee802154: Convert IEEE 802.15.4 shell to use new shell
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Jukka Rissanen 681ff12379 net: wifi: Convert wifi shell to use new shell
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Jukka Rissanen 436e295dd9 net: shell: Migrate to new shell API
Convert net-shell to use the new shell API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-15 11:14:02 +03:00
Gil Pitney 00895795fa net: Fix assert on net_if_api send for NET_OFFLOAD drivers.
Recently, the wifi net offload driver has been asserting
as init_iface() was checking for api->send != NULL, even in
the case of NET_OFFLOAD

This patch suggests a fix to handle the NET_OFFLOAD case.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-12 09:58:16 +03:00
Vinayak Kariappa Chettimada ae8649c5ec Bluetooth: controller: Fix connection failed to be established
Fix connection failed to be established regression
introduced by the commit 350c569aba ("Bluetooth:
controller: Avoid offseting to lldata").

As the Rx-ed PDU buffer is re-used to construct the
connection complete message towards HCI, the fields in the
Rx-ed PDU need to be backup for future use in the control
path. Here the channel selection bit is backup now.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:50:44 +02:00
Andrei Emeltchenko cfa04c318e netusb: Remove ifdef registration for functions
netusb functions are now registered when interface is selected or
configured.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 216b1457ed netusb: Move init() to separate functions
Move init() invocation to function code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 91fc0bcd50 netusb: Register each function
Register each function found in the linker USB data cfg section.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 6b3c096a95 netusb: Refactor RNDIS code
Move RNDIS functionality from netusb to function_rndis.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko 0db9062cdb netusb: Refactor EEM code
Move EEM functionality from netusb to function_eem.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Andrei Emeltchenko fd1ac0f209 netusb: Refactor ECM code
Move ECM functionality from netusb to function_ecm making defines not
needed in many cases.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-11 14:45:26 -04:00
Vinayak Kariappa Chettimada a11868fea9 Bluetooth: controller: Fix conn param req procedure response
Fix Connection Parameter Request Procedure implementation
to respond with sent interval_min and interval_max so that
certain peer devices dont reject the response as Invalid LL
Parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-11 20:30:02 +02:00
Gil Pitney c2cdbbafd7 net: sockets: Get socket offload to build after net logging overhaul.
Also, defines one LOG_MODULE_NAME for the simplelink WiFi driver, and
uses the same name for all files in this driver (module).

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-11 15:51:57 +03:00
Krzysztof Chruscinski 05b854c168 logging: Postpone log processing when no backends enabled
In initial state of the system it is possible that no backends are
yet enabled and log processing is triggered. In that case logs were
discarded. A flag has been added to the log core to do processing
only if at least one backend is enabled. It is applicable only to
initial phase. If backends are disabled in application lifetime
logs will be discarded.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-11 13:29:50 +03:00
Krzysztof Chruscinski 5f6070e2f7 logging: Add autostart option to LOG_BACKEND_DEFINE
Extended macro to accept flag indicating if given backend must be
initialized and enabled when log subsystem starts. Typically, simple
backends will have autostart flag set. More complex may require
explicit enabling (e.g. shell over BLE can only be enabled when
BLE connection is established).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-11 13:29:50 +03:00
Michael Scott 518444487c logging: init strdup mem_slab with aligned buffer size
We are using a non-32-bit aligned value as the block size
when initializing the strdup mem_slab for Logger.

When the non-aligned pointer is being freed, it's converted
to a u32_t and this generates the following:
***** USAGE FAULT *****
  Unaligned memory access

Let's use the aligned buffer size as the block size instead.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-11 13:20:32 +03:00
Jakub Rzeszutko f6197c4f3c shell: create instances automatically basing on enabled backend
If user will enable shell than for each backend shell instance
will be created automatically.

Update all shell examples according to the new initialization
procedure.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-11 12:08:04 +02:00
Aurelien Jarno 124f5776a7 usb: device: fix the log level of a debug message
When using composite devices, an error is printed during the
initialization:

| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x81
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x1
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x82
|
| [00:00:00.000,000] <err> usb_device: set cb, ep: 0x2

This is actually not an error, but rather a debug message. In addition
it should not contain a new line as it is automatically added by the
logger subsystem.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-10-10 17:48:55 -04:00
Andrei Emeltchenko 1eb6a01723 usb: Use const for status_callback parameter
usb_dc_status_callback() parameters are interface or configuration
numbers and should be const.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko adf056dc92 usb: Use always single callback definition
Use one callback type, remove duplicates.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko 82a5ee0cad usb: hid: General code cleanup
Trivial style cleanup.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Andrei Emeltchenko 3288da9c0b usb: hid: Add status_cb to hid ops
Adding status callback allows to control report sending only when i.e.
device is connected or configured.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-10-10 09:21:55 -04:00
Jukka Rissanen fa8ff4f379 net: arp: Add support for receiving gratuitous ARP request
If we receive a valid gratuitous ARP request, then update ARP
cache accordingly. This feature is optional and by default
it is enabled, but can be turned off if needed.

This is similar to a feature available in Linux, and is enabled
by default in many distros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-10 16:12:35 +03:00
Jakub Rzeszutko b0571746e2 shell: parsing output LF character
Some terminals literally interprets shell output data. Hence to print
a message in new line shell needs to send `\r\n` each time. To minimize
flash usage user can now send `\n` as a line delimiter and shell will
automatically add missing CR character.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-10 10:45:28 +02:00
Dong Xiang 026f06efeb net: l2: update wifi mgmt to adapt non-offload wifi chip.
The wifi mgmt does only support TCP/IP offload wifi chip,
while non-offload wifi chip can not scan/connect to AP.

Signed-off-by: Dong Xiang <dong.xiang@unisoc.com>
2018-10-10 11:38:04 +03:00
Paul Sokolovsky 8e1d78c357 libc: minimal: Make fcntl.h be at top level, not sys/fcntl.h
Placing it at sys/fcntl.h was due to mimicking internal newlib's
layout, but what we need is this file at the standard location,
for reuse.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 15:44:59 -04:00
Paweł Zadrożniak a6134a374e subsys: usb: Change the buffer fragmentation for IN transfers.
USB controller was performing the fragmentation by itself and the driver
was not aware if current chunk is the last one if data size is equal to
maximum chunk size. Some hardware controllers (i.e. in nRF52840) handle
the status stage by hardware which must be triggered after the last data
chunk.
Currently, the whole remaining data is passed to the driver, and the
driver decides whether to fragment the data internally, or send only
the chunk and report back to the stack.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-10-09 21:37:51 +02:00
Léonard Bise 9975f7b854 net: sockets: Unblock threads waiting on recv on socket close
This commit fixes the issue that if a thread is waiting on recv for
data and the user closes the socket, the waiting thread is not
unblocked.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2018-10-09 18:35:22 +02:00
Radoslaw Koppel 4db9731451 bluetooth: host: conn: Add const to addr in bt_le_set_auto_conn
This commit adds missed const modifier for addr pointer for
bt_le_set_auto_conn function

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-10-08 20:31:39 -04:00
Anas Nashif 7dea257e92 dfu: log: rename level variable
Rename log level variable:
CONFIG_LOG_IMG_MANAGER_LEVEL to CONFIG_IMG_MANAGER_LOG_LEVEL

Use template for log levels.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Olivier Martin 1e630baa02 subsys: dfu: Migrate to new logging subsys
Migrate from `SYS_LOG` to `LOG` logging mechanism.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-10-08 17:49:12 -04:00
Anas Nashif 3c7e60ee74 nvs: fix style
Fix code style after moving to new logger.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Anas Nashif 12984c6d1f subsys: nvs: move to new logger
Move to new logger and update all related samples and configs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Yannis Damigos d1a655a624 subsys/usb: Move to new logger subsystem
Move to new logger subsystem.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Vinayak Kariappa Chettimada 71fff7648d Bluetooth: controller: Refactor adv random delay resolution fix
Refactored the fix in the commit 685da02354 ("Bluetooth:
controller: Fix advertising random delay resolution calc")
to apply modulo in tick units before adding a tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-08 12:53:50 -04:00
Joakim Andersson 773b21ac38 bluetooth: config: Fix bluetooth config dependencies
Fix bluetooth config dependencies where the definitions depend on other
definitions.
BT_RX_PRIO is not always defined in a controller only build.
BT_CTLR_TX_BUFFER_SIZE does not depend on BT_CTLR, but BT_LL_SW.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-10-05 11:15:27 -04:00
Marti Bolivar 7f3e07ee11 tracing: don't include kernel_structs.h from tracing_sysview.h
This header is private data and we shouldn't (and aren't) using it in
the tracing_sysview.h. SystemView tracing works fine without it, as
tested with the philosophers sample.

This commit fixes the build when bluetooth SMP and SystemView tracing
are used, because the kernel_structs.h inclusion ends up pulling in
kernel_internal.h, which declares smp_init(), whose declaration
conflicts with another internal routine by the same name in
subsys/bluetooth/host/smp.c.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-05 10:37:01 -04:00
Jukka Rissanen 7138e34d31 net: wifi: Removing SYS_LOG_DBG as that is no longer used
The wifi management interface was still using one SYS_LOG_DBG
macro call, replacing that with NET_DBG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 10:08:32 -04:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Vinayak Kariappa Chettimada 049267a5ca Bluetooth: controller: Fix connection cancel deadlock
Calling bt_recv in the Bluetooth host Tx thread by the
controller implementation caused deadlock in combined host
controller builds when HCI LE Create Connection Cancel
generated the HCI LE Connection Complete or HCI LE Enhanced
Connection Complete events.

Controller's HCI implementation has been updated to place
the generated event into Rx FIFO to avoid the deadlock.

Relates to commit a59f544fb4 ("bluetooth: controller:
Handle non-priority events correctly")

Relates to #10314.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Vinayak Kariappa Chettimada 350c569aba Bluetooth: controller: Avoid offseting to lldata
Avoid offseting to lldata when populating event structure
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-05 13:44:10 +02:00
Szymon Janc 861bae22b8 Bluetooth: Fix autoconnect if cancelled pending connection
bt_conn_disconnect removes device from autoconnect list and thus
should not be called from le_conn_update when timeouting pending
connection. Also auto connect flag needs to be check on connection
failure to make sure scan is restarted.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-10-05 13:43:49 +02:00
Michael Scott 685da02354 Bluetooth: controller: Fix advertising random delay resolution calc
In commit d5836195d7 ("Bluetooth: controller: Increase advertising
random delay resolution"), the resolution of random_delay was
increased from 8-bit to 16-bit.  Due to this switch the result
of HAL_TICKER_US_TO_TICKS() can now be a 0, which causes the following
crash:
***** Kernel OOPS! *****
Current thread ID = 0x200043f0
Faulting instruction address = 0x17914
Fatal fault in ISR! Spinning...

Let's make sure we don't pass a 0 to ticker_update() by increasing
the result of HAL_TICKER_US_TO_TICKS() by 1.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-05 10:18:27 +02:00
Jakub Rzeszutko bc6da1c34a shell: Enable backends via Kconfig file
Added functionality to enable active shell backends via Kconfig
file. When there will be more backends implemented user will
have an option to select only required ones.

It is no longer needed to select SERIAL in prj.conf.

Fixes #10190

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-05 10:04:44 +02:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen df13dcf911 net: app: No need to print anything if resolving is not possible
The code was trying to print peer IP address string but that
pointer could contain garbage. There is actually no need to print
anything in this case, the error code return is enough.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 5705573c46 net: lwm2m: Convert to new logging system
Use new logging system instead of SYS_LOG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen ac88baca02 usb: net: Convert to use new logging
Convert the USB networking to use the new logging system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 4851e2ea1b usb: Fix net_hexdump_frags() parameters
One parameter was missing when calling net_hexdump_frags() which
caused compile error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 9b460b1105 net: Use logger hexdump print macro
As the logger provides hexdump macro, use that instead of our own.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 15e7e3ea4b net: ip: Split debug prints into smaller pieces
Currently logging subsystem supports quite small number of function
parameters. So split some long functions into smaller pieces.
Hopefully this is just a temporary patch and we can support more
parameters to logging macros.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 2bc38a8f88 net: mgmt: Use correct printf modifier in debug print
Net event information debug print was using wrong printf modifiers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 502130d6ea net: lib: Convert mqtt library to use log level
Use network log level in mqtt library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 1165f0d400 net: lib: Convert websocket library to use log level
Use network log level in Websocket library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen dc29ed0bd9 net: lib: Convert socket library to use log level
Use network log level in BSD socket library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 51e9297c4d net: lib: Convert sntp library to use log level
Use network log level in SNTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 1fbf7862f2 net: lib: Convert openthread library to use log level
Use network log level in OpenThread library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 8ffb0fc968 net: lib: Convert http library to use log level
Use network log level in HTTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen d880d7c9c8 net: lib: Convert dns library to use log level
Use network log level in DNS library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen cb4fa371c5 net: lib: Convert config library to use log level
Use network log level in config library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen dc018376f2 net: lib: Convert coap API to use log level
Use network log level in CoAP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 3ab1f90822 net: lib: Convert net_app to use log level
Use network log level in net_app library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 46bc51d8c1 net: buf: Convert to new logging system
This commit replaces syslog with new logging subsystem in buf.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen a76814bfb6 net: Convert core IP stack to use log levels
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.

The commit also converts the code to use the new logger
instead of the old sys_log.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Vinayak Kariappa Chettimada 3d1a659019 Bluetooth: controller: Fix default Tx buffers
Fix the default Tx buffers to 3. While the first Tx-ed
buffer generates the HCI Number of Completed Packets Event,
the controller needs to have 2 additional Tx buffers queued
so that the second Tx PDU has the More Data (MD) bit set so
as to have the connection event to continue to transmit any
additional Tx buffers that the Host will enqueue in the same
connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-10-04 11:45:54 +02:00
Radoslaw Koppel 152b15ab3b subsys: bluetooth: shell: bt: Add command to show LL address
This commit implements command in the shell to show current
link layer address.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2018-10-04 10:35:06 +02:00
Paul Sokolovsky ca8aea1a62 subsys: console: Split serial tty handling to a separate module
Before going further for API refactoring in console subsys, makes
sense to split "tty" implementation from "console" implementation,
to make it clearer that "console" is just a "tty" instantiated on
a particular UART device.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-03 16:40:49 +02:00
Jukka Rissanen 65477b7391 logging: Make log_strdup() parameter const
The string parameter needs to be const as otherwise calling this
function using a const string pointer will lead to a warning.
Besides the function does not modify the parameter so should be
const anyway.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-03 13:05:49 +03:00
Luiz Augusto von Dentz bbaa374afa Shell: Remove reference to alphabetically sorted
It is no longer required to have the command table alphabetically
sorted.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 10:51:52 +02:00
Luiz Augusto von Dentz bd3a4e5fe5 shell: Make autocomplete works with non-sorted commands
This allows declaring the commands in any order which sometimes is
convenient when commands are conditional making it undesirable to
sort everything.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 10:51:52 +02:00
Luiz Augusto von Dentz 76714c1480 Bluetooth: Shell: Make error message for unknown parameter consistent
Also simplify it by having the 'unknown parameter:' as part of the
message format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 09:49:58 +02:00
Luiz Augusto von Dentz ba545e0d3c Bluetooth: shell: Fix using \n with print/error
Those macros already contain line termination.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-03 09:49:58 +02:00
Jakub Rzeszutko c471614cb6 subsys: shell: fix accept either CR or LF as as line delimiter
1. Shell will accept CR or LF as line delimiter.
2. Macro SHELL_DEFINE simplified - it no longer requires
   new line character.
3. Fixes: #10207.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 11:55:47 -07:00
Carles Cufi 990ab2de70 Bluetooth: shell: Transition flash.c to the new shell
Convert the flash.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Carles Cufi 63f4d9f509 Bluetooth: shell: Transition ticker.c to the new shell
Convert the ticker.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Carles Cufi 5372950336 Bluetooth: shell: Transition ll.c to the new shell
Convert the ll.c functions to the new shell format.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-02 18:41:11 +02:00
Jakub Rzeszutko 61ca8c17c8 subsys: shell: add handlers diagnostic function
Added function: shell_execute_cmd that can be called
for command diagnostic purposes.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Jakub Rzeszutko 0eea1ef212 subsys: shell: add int ret_val to command handlers
1. Command handler can return command exectution status as int.
2. Existing command handlers rework.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Jakub Rzeszutko 0ce966bc28 subsys: shell: manual * parsing
This PR fixes: #10195.
Function _vprintk when used cannot parse '*' what
a as result causes dereferencing bad pointer.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 11:23:37 +02:00
Krzysztof Chruscinski a15438e8f5 logging: add mechanism for handling transient strings
Extending logger to support logging transient strings (with %s).
With dedicated call (log_strdup), string is duplicated to a buffer
from internal logger pool. Logger implicitly manages the pool.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-01 15:26:14 -04:00
Tomasz Gorochowik 3a51c8d932 net: gptp: Fix sync interval timeout timer starting
The last parameter is 'period', we should not pass duration twice.
Doing so makes zephyr hang with current mainline when it is chosen to be
the Grand Master.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik a979841ec4 net: gptp: Fix sync receipt timeout timer starting
Completely remove the last_sync_receipt_timeout time. It is not part of
the standard (see 802.1AS-2011, 10.2.11 for the complete list of
variables for this state machine). Additionally this extra variable was
never really initialized so the calculated duration made no sense.

Just start the timer based on the regular sync receipt timeout time
interval from the port data set.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 0888da4dfe net: gptp: Add clock accuracy selection
This commits adds a possibility to select PTP clock accuracy through
KConfig.

The chosen accuracy should reflect the capabilities of the used
hardware.

See IEEE 1588-2008, chapter 7.6.2.5 for more details.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 68127a3100 net: gptp: Initial GrandMaster capability support
Implements GMCAP-1, GMCAP-2, and GMCAP-3 and their dependencies from
802.1AS-2011. See Annex A.10 for more details.

The Grand Master Capability can be turned on and off through KConfig.

Note: the correction field in FUP packets is not yet properly
calculated. There is a TODO left in the code, near which some parameters
are zeroed to make the correction field be set to 0. This mimics the
behavior of openAvnu (a Linux gPTP client). For full compliance the
field should be calculated and set properly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 117b9ac3e9 net: gptp: Use packed enums when applicable
Optimize memory usage of enums that are used within structs.
Reorganize the affected structs to avoid holes.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 5c5a4461a4 net: gptp: Fix port number in SYN and FUP packets
Make sure the packets contain the port number they are actually coming
from.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 792dfd4a04 net: gptp: Convert SyncReceiptTime to ExtendedTimestamp
SyncReceiptTime should use an ExtendedTimestamp (with fractional
nanoseconds precision). Add a struct with the definition of the needed
type and convert that variable.

The struct representing the ExtendedTimestamp is named
net_ptp_extended_time to keep consistency with the existing net_ptp_time
which is used for regular PTP timestamps.

See 802.1AS-2011 chapters 10.2.3.4 and 6.3.3.5 for more reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik a84e60b8de net: gptp: Rename the ClockMasterSyncReceive state struct
There are other ClockMasterSync state-machines (to be implemented).
Current name would either cause conflicts or be too ambiguous.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Luiz Augusto von Dentz 17558c9382 Bluetooth: shell: Use \r\n to terminate line
Shell expects each printed lined to be terminated with \r\n.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz fb4785d274 Bluetooth: shell: Split L2CAP commands
This splits L2CAP commands under 'bt' to 'l2cap' removing 'l2cap-'
prefix from the commands:

l2cap - Bluetooth L2CAP shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  connect     :<psm>
  disconnect  :[none]
  metrics     :<value on, off>
  recv        :[delay (in miliseconds)
  register    :<psm> [sec_level]
  send        :<number of packets>

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz 043a8b0202 Bluetooth: shell: Split GATT commands
This splits GATT command under 'bt' to 'gatt' removing 'gatt-' prefix
from commands:

gatt - Bluetooth GATT shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  discover-characteristic  :[UUID] [start handle] [end handle]
  discover-descriptor      :[UUID] [start handle] [end handle]
  discover-include         :[UUID] [start handle] [end handle]
  discover-primary         :[UUID] [start handle] [end handle]
  discover-secondary       :[UUID] [start handle] [end handle]
  exchange-mtu             :[none]
  read                     :<handle> [offset]
  read-multiple            :<handle 1> <handle 2> ...
  subscribe                :<CCC handle> <value handle> [ind]
  write                    :<handle> <offset> <data> [length]
  write-without-response   :<handle> <data> [length] [repeat]
  write-signed             :<handle> <data> [length] [repeat]
  unsubscribe              :[none]
  metrics                  :register vendr char and measure rx
			    [value on, off]
  register                 :register pre-predefined test service
  show-db                  :[none]
  unregister               :unregister pre-predefined test service

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz bcfc9939e4 Bluetooth: shell: Split RFCOMM commands
This splits RFCOMM command under 'br' to 'rfcomm' removing 'rfcomm-'
prefix from commands:

rfcomm - Bluetooth RFCOMM shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  register    :<channel>
  connect     :<channel>
  disconnect  :[none]
  send        :<number of packets>

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz 310ffc4c4c Bluetooth: shell: Split BR/EDR commands
This splits BR/EDR command under 'bt' to 'br' to reduce the command
list and at same time cleaning the mix between different bearers.

In addition to that also remove "br-" prefix for the commands:

br - Bluetooth BR/EDR shell commands
Options:
  -h, --help  :Show command help.
Subcommands:
  auth-pincode       :<pincode>
  connect            :<address>
  discovery          :<value: on, off> [length: 1-48] [mode: limited]
  iscan              :<value: on, off>
  l2cap-register     :<psm>
  oob                :
  pscan              :value: on, off
  sdp-find           :<HFPAG>
  rfcomm-register    :<channel>
  rfcomm-connect     :<channel>
  rfcomm-send        :<number of packets>
  rfcomm-disconnect  :[none]

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Luiz Augusto von Dentz 592dd2e964 Bluetooth: shell: Port commands to the news shell
Fixes #8873

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-10-01 11:10:46 +02:00
Vinayak Kariappa Chettimada d5836195d7 Bluetooth: controller: Increase advertising random delay resolution
Increase the resolution of advertising random delay from
1 ms unit to 1 us units. The controller scheduling will
floor it to nearest 32KHz clock unit on nRF5 series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-28 18:03:51 +02:00
Szymon Janc a7bf9de0ee Bluetooth: Use BT_CMD_TEST macro for testing supported commands
Make code easier to read and more consistent.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:39 +03:00
Szymon Janc 9c5c2f8baf Bluetooth: Fix incorrectly reporting connection as failure
Auto connect code reuses bt_conn object and connection code was assuming
object was cleared which resulted in invalid code being provided to
application. Fix that by explicitly setting error code to 0 on
successful connection.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:43:00 +03:00
Szymon Janc f0f4147a57 Bluetooth: Allow to configure LE Create Connection timeout
Depending on perhiperal advertising interval 3 seconds might not be
enough and would result in cancelling pending connection. Make this
Kconfig configurable and let application to decide.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-28 13:42:26 +03:00
Taehwa Kang 2bdc5923ad net: coap: Fix Coap coap_option_value_to_int and coap_append_option_int
In coap_option_value_to_int function, when coap option length is 4,
option->value[3] should be shifted by 0 rather than option->value[2].
This doesn't affect the behavior of function but needs to be fixed.

In coap_append_option_int function, when the value is between 0xffff
and 0xffffff(when option length is 3), bit shift operation is wrong.
For example, if the value is 0xABCDEF, by sys_put_be16(val, data)
data[0]=0xCD, data[1]=0xEF, by val >> 16, data[2]=0xAB. So the result
becomes 0xCDEFAB not 0xABCDEF. So, to sys_put_be16 function hand
&data[1] over instead of handing data over and val >> 16 needs to be
set to data[0], not data[2].

Signed-off-by: Taehwa Kang <hegrecomm@gmail.com>
2018-09-28 11:11:17 +03:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Alberto Escolar Piedras 3e41ac5f04 subsys: shell: Add missing dependency to SERIAL
The shell subsystem, as it is today, depends on having a UART,
therefore let's add the dependency explicitly in its Kconfig

Fixes #10190

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-27 17:24:34 +02:00
Alberto Escolar Piedras c09b76abd0 subsys: shell: support posix arch
The posix arch does not compile either of Zephyr's libc,
so _prf() is not avaliable

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-27 17:24:34 +02:00
Andrzej Puzdrowski 5df93af87a subsys: storage: flash_map: add API for check flash driver support
Some applications might want to check whether flash_areas binds to
any flash drive in the system. It might be better to do that while
sanity check at application start-up then while regular run process.
Example of such application is the mcuboot.

This patch introduce such API for checking whether device bindings
were resolved properly during system startup.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-09-27 16:24:21 +02:00
Krzysztof Chruscinski 87d177a6fb logging: allow mulitple log_panic calls
Ensure that only first log_panic() sends panic signal to backends

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-27 13:11:26 +05:30
Anas Nashif 6d3fb8b4cf shell: kernel: add more thread data to threads command
Show thread and stack data all under one command and reformat output.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Anas Nashif 1aed3858ac logging: rename log_process_thread to logging
Keep the name short to make usuable when thread names are enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Anas Nashif 46f7cd51dd shell: kernel: print thread name
Use new kernel API to display thread name when listing threads.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Anas Nashif 57554055d2 kernel: add a new API for setting thread names
Added k_thread_name_set() and enable thread name setting when declaring
static threads. This is enabled only when THREAD_MONITOR is used. System
threads get a name by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Szymon Janc 063123f35a Bluetooth: Allow to configure background scan window and interval
Applications may require different scan windows and interval depending
on expected re-connection time or peer devices advertising parameters.
Default to GAP recommended slow values.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-26 22:45:37 +02:00
Krzysztof Chruscinski 2cc6d0c9c2 logging: Add option to suppress timestamp printing in log_output
Added flag in log_output module to add timestamp when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Krzysztof Chruscinski 07da32aae5 logging: Add option to suppress level printing in log_output
Added flag in log_output module to add severity level when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Carles Cufi d813b13109 Bluetooth: controller: Remove timestamp from HCI
In order to avoid the build system complications that come from
including a timestamp, remove it by default from the version string in
HCI Vendor Extensions. Users can still include a unique identifier, be
it timestamp or not, using the CONFIG_BT_CTLR_HCI_VS_BUILD_INFO Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-26 14:50:26 +02:00
Vinayak Kariappa Chettimada 684f753fd4 Bluetooth: controller: Fix Data Length Update implementation
The Data Length Update implementation reused the flags used
by Encryption Procedure which caused invalid Encryption
Procedure sequence under conditions where Data Length Update
Procedure collide with Encryption Setup initiated by the
peer central device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-26 11:55:02 +02:00
Johann Fischer 7ba6736ac0 net: ipv6: set pkt properties prior to routing
pkt properties should be set prior to routing.
If packet routing is turned on and the packet is
forwarded to an interface, the pkt properties like
ipv6_ext_len or ip_hdr_len will not be initialized.
If a UDP packet is forwarded to an 6lo interface,
it leads to incorrect calculation of UDP header
during UDP header compression (net_udp_get_hdr).

Fixes #10204

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-09-26 10:09:05 +03:00
Kamil Piszczek 868a3bff0d Bluetooth: host: always set address via HCI before scanning
The address of the device is also set via HCI interface when passive
scanning is used. As a result, LL does not filter out directed
advertising packets that are targeted at this device.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-25 14:25:17 +03:00
Szymon Janc bb271a6d98 Bluetooth: Add option to configure peripheral connection parameters
This allows to configure desired parameters for peripheral. When set
PPCP characteristic is also added to GAP service. If disabled it is
up to application to controll connection parameters and stack will
only enforce 5 seconds delay before update.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Szymon Janc 75405f5613 Bluetooth: Fix connection parameters update
This fixes a few issues with the handling of Connection Parameter
update in the Host:
 - starting conn param update timer as master
 - ignoring 5 seconds slave timer when calling bt_conn_le_param_update
 - starting conn param update timer on every PHY update

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-25 13:31:10 +03:00
Jakub Rzeszutko 73c2178027 shell : assert standardization
1. All macros assert have been replaced with __ASSERT_NO_MSG.
2. Macro _Static_assert has been replaced with BUILD_ASSERT.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-25 10:31:13 +02:00
Jakub Rzeszutko f3db4d7034 subsys: shell: removing troubleshooting assert
Removing assert that was crashing shell in allowed scenario.
For example the Tab button is pressed when command buffer is empty.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-25 09:52:07 +02:00
Sebastian Bøe f8616291e4 Kconfig: BT: Give the LL selection option a name
There is an unnamed choice for the BT link layer selection.

Giving the choice a name would allow multiple declarations of the
option and the ability to select out-of-tree LL's.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-25 09:42:23 +02:00
Olivier Martin 7c19e90612 subsys: logging: Mark the local functions as 'static'
After the recent change in `struct log_backend_api` (ie: add
of `init` function), init function can be marked as `static`
as it is only used in the scope of the file.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-09-24 22:51:53 +05:30
Jakub Rzeszutko e59b8cbef9 subsys : shell : Added API changing prompt
1. Added API to change shell prompt in runtime.
2. Added prompt buffer length configuration in Kconfig.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-24 13:17:24 +02:00
Johan Hedberg 559578c09a Bluetooth: Add API to iterate through existing bonds
So far the stack hasn't provided any way for the application to access
the existing bonds. This patch adds such an API.

Fixes #10122

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-24 13:27:26 +03:00
Alberto Escolar Piedras 204acc8232 subsys: logger: fix merge error
Fix merge error introduced in:
ba01a3952f
(as part of #9362)
which deleted the native_posix backend for the logger.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-24 12:06:12 +02:00
Luiz Augusto von Dentz 8c02af73be Bluetooth: shell: Add l2cap-recv command
This adds l2cap-recv which can be used to set a delay when confirming
the receptions of packets:

> l2cap-recv 1000
Incoming conn 0x00401c20
Channel 0x004220c8 connected
Channel 0x004220c8 requires buffer
Incoming data channel 0x004220c8 len 230
00000000 00 00 00 00 e6 00 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000010 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000020 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000030 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000040 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000050 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000060 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000070 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000080 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
00000090 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000a0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000b0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000c0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000d0 7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f 7f 7f 7f 7f
000000e0 7f 7f 7f 7f 7f 7f
Delaying response...
Confirming reception

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 9f79862300 net: buf: Use net_buf_add_mem in net_buf_append_bytes
This ensures the memory copies are properly logged when debug is
enabled.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 16fdd74908 Bluetooth: L2CAP: Make use of net_buf_append_bytes
This uses net_buf_append_bytes to reassemble the SDU segments instead of
doing it manually.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 62f41df283 Bluetooth: L2CAP: Prevent the channel to stall
If the remote stack is not able to fully utilize each segment it is
possible it would run out of credits before completing the SDU, these
changes detects if that would happen and attempt to restore enough
credits for the SDU to be received.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 8af4786e9f Bluetooth: L2CAP: Restore credits after receiving an SDU
This simplify the logic of restoring the credits after each SDU instead
of using an arbitrary threshold which was not configurable per channel.

Because the credits are restored only when the full SDU has been
reassembled it means the channels needs to be set up with enough for
the configured MTU otherwise there is a risk of the channel to run out
of RX credits before the packet is fully reassembled, because of such
corner case the code will now warn if a channel is setup with not enough
init_credits.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Luiz Augusto von Dentz 3151d26572 Bluetooth: L2CAP: Add return to recv
This adds a int return to recv callback which can be used to notify the
stack about errors when receiving a packet. In addition to that the user
can return -EINPROGRESS to inform the stack the data will be processed
asynchronously which can be complete by calling
bt_l2cap_chan_recv_complete.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Joakim Andersson 0287a04340 Bluetooth: host: Fix name conflict with kernel smp_init in smp.c
When activating SystemView internal kernel header files will be
included. This causes a name conflict with smp_init in smp.c
and smp_init in kernel_internal.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-24 10:53:20 +03:00
Krzysztof Chruscinski 73c01f9e9f shell: modules: Adapt kernel commands to new shell
Kernel commands ported to new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-23 11:43:33 -04:00
Krzysztof Chruscinski 8feab483c9 shell: fix shell_log_backend dependency
Fixed case when shell_log_backend.c was included even though
shell was disabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-22 22:28:17 -04:00
Kamil Piszczek e48434bc71 Bluetooth: gatt: gatt_discover_next with inclusive handle range
This fix ensures that the handle range used for next GATT discovery is
always inclusive. Previously, the discovery procedure could not be
started with equal value of start and end handle.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-21 18:52:52 -04:00
Jukka Rissanen 02e9f9c8e6 net: route: Check that neighbor exists before deleting it
If the neighbour does not exists, then the route to it cannot
be deleted so we can return error to caller in that case.

Coverity-CID: 188173
Fixes #10090

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-21 17:32:18 +03:00
Jukka Rissanen 3b8c37de45 net: route: Check NULL value in debug print
In net_route_add(), do not try to print route information if
route to neighbor is not found.

Coverity-CID: 188172
Fixes #10091

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-21 17:32:18 +03:00
Szymon Janc 6c89c4b5f7 Bluetooth: Controller: Add support for setting public address
This allows to provide public address for controller without using
VS HCI command from host. Useful for controller only builds or
combined builds that are not using VS HCI commands.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-21 12:40:10 +02:00
Luiz Augusto von Dentz 0a23067540 Bluetooth: GATT: Remove BT_GATT_WRITE_FLAG_PREPARE check in GAP
This check is only required when BT_GATT_WRITE_FLAG_PREPARE is set.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-21 12:27:50 +03:00
Adithya Baglody ae92f2badf subsys: app_memory: Fixed the size calculation for power of 2 MPUs
The size calculation for power of 2 MPUs were incorrect.
The calculation was not taking into account the amount of padding
the linker does when doing the required alignment. Hence the size
being calculated was completely incorrect.

With this patch the code now is optimized and the size of
partitions is now provided by the linker.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:25:53 -04:00
Ramakrishna Pallala c511857f57 subsys: power: Add support for pluggable PM policies
Add support for adding and selecting pluggable PM policies
which can be enabled based on the application needs.

Also added a dummy policy for demonstration purpose which
simply loops over the supported PM states.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-09-20 10:20:23 -04:00
Jukka Rissanen fc27a81ed2 net: context: Select proper network interface when binding
Use the destination address to select the proper network interface
when binding. The default network interface cannot be used here
as then the packet might be sent to wrong network interface.

Fixes #9935

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-20 11:21:22 +03:00
Adithya Baglody 9fe378b7e7 Bluetooth: Mesh: Enforce proper compilation.
The current method relies heavily on the linker/compiler to
do the correct operation. Which is to eliminate the code that will
never get called. This posses a problem if the build even changes
by a smallest fraction.
The current patch will enforce proper inclusion of the code at the
pre-processing stage. Thereby not relying on the compiler/linker to
do the right thing.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:14:03 +03:00
Krzysztof Chruscinski 68249ce966 shell: Add wildcard support
Extended shell to support wildcard characters: * and ? and expand
commands accordingly.
Increased default stack size.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski ba01a3952f logging: Add shell commands
Added commands for getting current status and controlling which log
messages are forwared to available backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski c71a5595dc shell: Extend shell as a log backend
Initial logger backend support added to shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 989fef9c0e shell: Add built-in shell commands
Added optional shell commands:
- clear - for clearing terminal
- history - commands history
- resize - terminal resize
- shell - controling echo and colors

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 82ca811661 shell: Add shell history feature
Extending shell with terminal-like  history feature.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 6aed72e487 shell: Shell subsystem reimplementation
New shell support features like:
- multi-instance
- command tree
- static and dynamic commands
- multiline
- help print function
- smart tab (autocompletion)
- meta-keys
- history, wildcards etc.
- generic transport (initially, uart present)

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Krzysztof Chruscinski 527256501f shell: Rename shell to legacy_shell
New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Olivier Martin 2328ed7e21 subsys: logging: native_posix: Fixed output buffer size
`LOG_OUTPUT_DEFINE()` accepts buffer size as a last parameter.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-09-19 09:07:26 -04:00
Joakim Andersson 9c2214e2a3 Bluetooth: shell: Add shell command set channel map
Add a new command in the shell which can be used to set the channel
map by specifying a 37 bit bitmask written as a five byte hex array.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-19 15:51:57 +03:00
Joakim Andersson 139beac5cf Bluetooth: host: Add set channel map command
Add functionality for setting the host channel classification in
the controller using the HCI command.
This closes issue #9851

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-09-19 15:51:57 +03:00
Szymon Janc 732b45cff3 Bluetooth: Read static address from FICR on nRF5 if no VS enabled
When running combined build on nRF5 with disabled VS command it is
possible to simply read static random address from FICR in host.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc e76224d038 Bluetooth: Controller: Add CONFIG_BT_HCI_VS option
This allows to fully disable HCI VS commands support.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:03:56 +02:00
Szymon Janc f93eef17a5 Bluetooth: Fix security level checking with LE SC and no-bonding
This was affecting SM/MAS/SCPK/BV-01-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-19 13:34:29 +03:00
Mariusz Skamra 323243d376 Bluetooth: Add a shell command to disable bondable mode
This adds a shell command for qualification purposes to enable/disable
Bonding flag in Authentication Requirements.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra 4f74f69814 Bluetooth: Add run-time option to disable SMP bondable mode
This adds a function that will disable Bonding flag in
Authentication Requirements flag in SMP Pairing Request/Response.
This is needed for qualification purposes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra 7ff9eeea0e Bluetooth: Add Kconfig option to disable bondable mode
This adds Kconfig option to allow disable bondable mode in compile
time.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Mariusz Skamra 64e608be8b Bluetooth: testing: Exclude Mesh related code if BT_MESH not set
This will exclude testing Mesh related code from build if BT_MESH
option in Kconfig is not set.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-19 10:48:39 +03:00
Jukka Rissanen 0433e1a840 net: mdns: Wrong net_buf pool was used
Use mDNS specific net_buf pool for received mDNS data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-19 09:55:44 +03:00
Jukka Rissanen ab8ff324d3 net: mdns: Select source IPv4 address properly for sent msg
There is now a proper function to select the right source IPv4
address when sending a mDNS packet so use it instead of selecting
the address directly from network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-19 09:55:44 +03:00
Tomasz Gorochowik 24a91afa38 net: gptp: Remove unused macro
Minor cleanup.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik 3c68a06743 net: gptp: Fix the default value of sync receipt timeout
The default value shall be 3.

See 802.1AS-2011, 10.6.3.1 for reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik c3baa22778 net: gptp: Fix sync timeout calculation
Sync timeouts were calculated incorrectly - this led to a 'Multiple
Masters Issue' as denoted by PTP debugging software.

See 802.1AS-2011, chapter 10.2.4.2 for reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Tomasz Gorochowik 09b6f956d4 net: gptp: kconfig: Fix log-based intervals help
Fix the formula listed in help messages which is used to calculate
actual intervals given their log2 values.

It is all calculated properly in the code, because the unit of the
actual field uses the UScaledNs type of which the unit is 2^(-16)ns, so
it is just the help messages that got it wrong.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-09-19 09:54:29 +03:00
Luiz Augusto von Dentz f67d45609e Bluetooth: shell: Fix requiring UUID for gatt-discover
This enables using these commands to perform discover all procedure:

> gatt-discover-primary
 Discover pending
 Service 1800 found: start handle 1, end_handle 5
 Service 1801 found: start handle 6, end_handle 9

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:23:08 +03:00
Luiz Augusto von Dentz e2362e1d00 Bluetooth: GATT: Make bt_gatt_discover perform discover all procedure
This makes bt_gatt_discover perform discover all proceduce if no UUID
is given in the parameters.

Fixes #9713

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:23:08 +03:00
Luiz Augusto von Dentz 0d1724b069 Bluetooth: GATT: Fix long write procedure
Long write procedure currently requires BT_GATT_PERM_PREPARE_WRITE to
be set otherwise the prepares would fail. This changes the behavior so
that BT_GATT_PERM_PREPARE_WRITE enables checking each prepare chunk
skipping it otherwise.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-19 09:22:31 +03:00
Andrei Emeltchenko 8fc5fd55de logger: Simplify UART backend initialization
Move definition to sources of UART backend.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 94bae6a462 logger: Move native_posix_backend definition
Move definition to appropriate place removing ugly defines.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 6162caf787 logger: Add init() api and simplify init and activate
Simplify logger initialization process using already existing loops.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Alberto Escolar Piedras 2f6370c0dd subsys: logging: for native_posix use appropriate tracing
For the native_posix backend, use the appropiate tracing
functions and enable color if it should be

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-18 14:56:10 +02:00
Alberto Escolar Piedras f8b97ab70e subsys: logging: Fix for no CONFIG_LOG_PROCESS_THREAD
When CONFIG_LOG_PROCESS_THREAD was not set the logger
was not initialized.
Register a POST_KERNEL init for that case.

Also added an assert in the logger thread in case there
is no backends, instead of having that thread spinning
forever.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko e65ee6870e logger: Add native backend for native_posix
Add backend to be used in native_posix arch.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 70f046e396 logger: Rename SHOW_COLOR and FORMAT_TIMESTAMP options
Make options available for other backends

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Matias Karhumaa 22a27fa0e2 Bluetooth: hci_ecc: Fix byte order of dbg keys
Pass Bluetooth SMP debug keys to crypto API in correct byte order.

Fixes #9867

Signed-off-by: Matias Karhumaa <matias.karhumaa@gmail.com>
2018-09-18 14:23:15 +03:00
Szymon Janc 9d3237c89e shell: Add support for custom line2argv callback
This allows to define shells which are using different syntax for
commands parsing eg. foocmd=param1,param2.

This is usefull for providing compatibility with existing external
tools while allowing to use Zephyr's shell subsystem.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-09-18 12:54:44 +02:00
Johan Hedberg 366378f8ac Bluetooth: GATT: Fix const'ness of characteristic descriptor data
None of the data for the CEP, CUD and CPF descriptors needs to be
modified by the stack at runtime. Make it possible to pass constant
data to the descriptor macros, and make sure the descriptor handlers
cast the data back to be a constant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-18 10:19:08 +03:00
Johan Hedberg 3c1dab005f Bluetooth: SMP: Remove bogus ARG_UNUSED() macro
The req variable in smp_pairing_failed() does get used, so
ARG_UNUSED() is inappropriate for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 14:46:10 -04:00
Johan Hedberg b4d7c2906b Bluetooth: Remove bogus condition for setting IRK for an identity
Just like we set the address for an identity without depending on the
BT_DEV_READY flag, we should do the same for the IRK. Otherwise we
risk getting an all-zeroes IRK. Remove the condition and always set
the IRK value whenever CONFIG_BT_PRIVACY is enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg cb08963fac Bluetooth: Fix identity creation through vendor HCI
The code creating identities from the Read_Static_Addresses vendor
command was failing to create matching IRKs, resulting in an
all-zeroes IRK to be used. Fix this by using the existing id_create()
function which takes care of generaing an IRK when necessary.

Fixes #10003

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Johan Hedberg a8f4370966 Bluetooth: Move bt_setup_id_addr() to avoid forward declaration
A subsequent patch will make bt_setup_id_addr() depend on id_create()
which was so far lower down in the hci_core.c c-file. Move
bt_setup_id_addr() further down to avoid a forward declaration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-17 19:50:49 +03:00
Aurelien Jarno 9fa1af694e subsys: fs/nvs: do not leave the flash unprotected in case of error
In case a write to the flash failed, do not leave the flash unprotected.
Always call flash_write_protection_set in that case.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno ce7e1a1cc8 subsys: fs/nvs: do not change flash protection for zero-length case
Avoid unsetting and setting the flash protection if there is nothing to
write to the flash. This happens for example when deleting data from the
flash using nvs_delete.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno 7a76792c87 subsys: fs/nvs: break if no end of sector is found
In case a sector is not empty nor properly closed (ie it never contains
8 times 0xff nor 0x00), the _nvs_prev_ate will loop indefinitely and
will start adressing memory outside of the flash area.

Fix that by stopping the loop when the address matches the beginning of
the sector.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno 725d9f7e09 subsys: fs/nvs: simplify crc8 computation
Instead of forcing the crc8 entry to 0xff for the crc8 computation, just
ignore this field in the computation as it is the last one. This avoid
having to set it back to the original value for _nvs_ate_crc8_check.

Add a build assertion to ensure crc8 is kept last.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno f1c6f91def subsys: fs/nvs: declare the ate structure as packed
The allocation table entry should be as small as possible in the flash,
so declare it as packed to avoid that the compiler pads it.

Note that this doesn't change anything on ARM, but it might help for
other (future) architectures.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno afa9e1f9fc subsys: fs/nvs: improve syslog messages
- Add a missing plural.
- Use a comma to separate the sector number with the offset to not
  confuse that with a range.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Aurelien Jarno 9ec11d70eb subsys: fs/nvs: improve some comments
Use "within sector" instead of "sector", as it could be confused with
the unit otherwise.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-09-17 07:54:35 -04:00
Robert Lubos 349e14d63c net: tls: Fix mbedtls hostname erros when certificates are not used
When no certificate-based ciphersuites are used, mbedTLS compiles out
hostname field and associated functions from its SSL context. This
resulted in compilation error when only PSK-based ciphersuites were
configured.

This commit resolves the issue by compiling-out hostname-related code
from secure sockets implementation on the same basis as mbedTLS does.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-17 09:48:11 +03:00
Flavio Ceolin abffd83d26 kernel: atomic: Ignore atomic_and/or return when not used
There are some cases where atomic_and/or don't need to be
checked. Actively acknowledge these cases.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin a1135620ba misc: printk: Change function return
The result of both printk and vprintk are not used in any place.
MISRA-C says that the return of every non void function must be
checked.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Krzysztof Chruscinski a728a46a60 logging: add template for log configuration
Added Kconfig.log_template file with template for module log
configuration.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-14 12:32:56 -04:00
Krzysztof Chruscinski 1fbea945f4 logging: Refactor log_output module
Module refactored: splitted data into read-only part and control block,
adding macro for creating log_output instance

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-14 15:05:50 +02:00
Kamil Gawor 8853cb3d06 subsys: bluetooth: Add notification TX complete callback
This changed added notification complete callback which
gives information if a given notification has been sent.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2018-09-14 14:39:01 +02:00
Robert Lubos 5286524a5c net: tls: Add missing entropy header
sockets_tls subsystem uses entropy driver, yet it does not include
entropy header. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-14 15:01:57 +03:00
Varun Sharma 28f5da6c38 subsys: shell : fs new shell module for fs mount operation
Fixes # 7348, also includes test cases

Signed-off-by: Varun Sharma <varun.sharma@intel.com>
2018-09-13 09:27:45 -04:00
Kamil Piszczek 3e8f118d8f Bluetooth: shell: adding command for directed advertising
Added a new command, which can be used to test the directed advertising
API. This command allows user to turn on directed advertising in two
modes: low and high duty. High duty mode is the default one.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-13 14:21:21 +02:00
Kamil Piszczek 9af28ddc09 Bluetooth: host: directed advertising support
Added implementation to the directed advertising API in the Connection
Management module. Introduced a new connection state for this type of
advertising. The new state is symmetric to the connection state used for
scanning.

Added a new advertising option that can be used to trigger low and high
duty directed advertising. Added macros for default values of
Advertising Parameters, which are used to trigger directed advertising.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2018-09-13 14:21:21 +02:00
Tomasz Bursztyka e8dee89079 net/udp: Separating net_context from udp and other cleanup
- Up to net_context to give the source port.
- net_udp_append is unused anywhere: let's remove it.
- left over macros on _raw versions removed as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-13 14:34:25 +03:00
Tomasz Bursztyka a7ddb1fb82 net/udp: Removing useless init function
There is nothing to initialize, so it can be removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-12 14:49:23 +03:00
Tomasz Bursztyka f1e5e17d3b net/udp: Removing useless insert/append _raw functions
These are not used anywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-12 14:49:23 +03:00
Alberto Escolar Piedras 877c4d0ca7 Bluetooth: controller: Use nRFx functions for PPI reg access
In the BLE controller, NRF radio HAL, for the PPI registers used
for the SW TIFS.
To allow easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-12 13:13:48 +02:00
Kumar Gala 4fede8dd0b log: make name param explicit
Rather than having some implied name for the logging name, explicitly
pass it in the macros LOG_MODULE_REGISTER & LOG_MODULE_DECLARE.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-11 13:25:55 -05:00
Gil Pitney c21b0fb357 net: sockets: Add a socket offload module
This patch enables BSD socket offload to a dedicated
TCP/IP offload engine.

This provides a simpler, more direct mechanism than going
through NET_OFFLOAD (zsock -> net_context -> socket conversions)
for those devices which provide complete TCP/IP offload at the
BSD socket level, and whose use cases do not require
IP routing between multiple network interfaces.

To use, configure CONFIG_NET_SOCKETS_OFFLOAD=y, and register
socket_offload_ops with this module.

Fixes #3706

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-09-11 18:42:34 +03:00
Tomasz Bursztyka b6468999e4 net/pkt: Rename link layer address accessors relevantly
*_ll_src/*_ll_dst/*_ll_swap/*_ll_if were not self explanatory, ll
meaning "link layer" it's ambiguous what the names meant.
Changing to:
*_lladdr_src/*_lladdr_dst/*_lladdr_swap/*_lladdr_if to fix this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-11 16:06:13 +03:00
Johan Hedberg b088a09235 net: buf: Use size_t instead of u16_t for lengths in public API
Even though the net_buf implementation may (and does currently)
internally use u16_t for lengths, keep the public facing API
consistent by using size_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Johan Hedberg c90549c474 net: buf: Use void * instead of u8_t * for arbitrary data
This makes the net_buf_append_bytes() API consistent with all other
net_buf APIs that take a pointer to arbitrary data.

Fixes #9283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Andrei Emeltchenko e1757277ae net: lldp: Implement LLDP RX API
Add RX API to LLDP. Caller should register callback which is called
from ethernet_recv().

Fixes #9407

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-11 10:55:01 +03:00
Jukka Rissanen 1d33f2ba50 net: shell: Add information about IPv6 configuration
The new "net ipv6" command which will print general IPv6 configuration
and information about autoconfigured IPv6 addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen 3f4d468059 net: if: Add utility function to return IPv6 prefix info
The net_if_ipv6_prefix_get() function will return the proper prefix
for a given IPv6 address and network interface. This is used when
checking which source address should be returned to the caller.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen 09390e5b3f net: if: Support long lifetime IPv6 prefixes
Enable IPv6 prefix to have long lifetime (> 25 days)

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen f8c6c7f0f0 tests: net: ipv6: Test long address lifetime timeouts
Check that long (> 24 days) IPv6 address lifetime timer is
properly handled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen c4cc8a5f3e net: if: Refactor IPv6 address lifetime timer
Refactor IPv6 address lifetime timer setting in net_if_addr to support
longer lifetime than 24 days.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Paul Sokolovsky 4d375eef23 net: config: Use sizeof() to get size of buffer for net_addr_ntop()
Using sizeof() is a common best practice in C, because it allows to
adjust size in one place instead of many.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-11 10:42:51 +03:00
Mariusz Skamra 02d980add3 bluetooth: gatt: Add GAP Central Address Resolution characteristic
This adds Central Address Resolution characteristic that is required
to check by peer if it's about to send directed advertisements where
initiator address is set to RPA.
Zephyr supports the Address Resolution, so the characteristic value
is hard-coded.
Please check Core 5.0 Vol 3 Part C 12.4 CENTRAL ADDRESS RESOLUTION
Related PTS test case: GAP/CONN/ACEP/BV-03-C

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-09-10 17:47:15 -04:00
Luiz Augusto von Dentz 148c7dd8a3 Bluetooth: GATT: Auto init if bt_gatt_service_register is called
This ensures the core services are always registered first and the
gatt_sc work is initialized.

Fixes #9785

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 12:07:08 -04:00
David Leach c2d980798a Bluetooth: Mesh: Fix incorrect reference to BT_SETTINGS
The test for IS_ENABLED(BT_SETTINGS) in mod_reset()
should be IS_ENABLED(CONFIG_BT_SETTINGS).

Signed-off-by: David Leach <david.leach@nxp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-10 10:46:23 -04:00
Jukka Rissanen 42a23e2b83 net: gptp: Set stack size correctly for handler thread
The gptp stack size was not properly set, one must use
the K_THREAD_STACK_SIZEOF() macro to calculate stack size.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-06 09:56:51 -04:00
Anas Nashif a9f32d66cf tracing: remove stray event_logger code
Remove obsolete kernel event logger code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-05 16:05:08 -04:00
Adithya Baglody 984ce023cc subsys: random: xoroshiro128: Use entropy get isr during init
Current implementation of the xoroshiro depends on the ISR being
triggered when the interrupts is locked. This patch proposes
implementing the init with entropy_get_isr. This implementation
can be called at PRE_KERNEL_2 stage, even when the interrupts
are locked.

Fixes: GH-8199

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-05 13:04:20 -04:00
Carles Cufi 022f9157e8 Bluetooth: mesh: Fix missing semicolon
Fix a missing semicolon at the end of a statement.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-09-05 10:45:19 -04:00
Ravi kumar Veeramally 005f014ce4 net: ipv6: Initialize memory
Fix accessing uninitialized memory. Fixes coverity issue.

Coverity-CID: 187902
Fixes: #9768

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-09-04 08:10:18 -04:00
Johan Hedberg 697919c5ba Bluetooth: Mesh: Fix checking for subnet when recovering App Key
The ordering of items in flash is not guaranteed, so it's possible we
get an App Key before the corresponding Net Key. Remove the check for
a Net Key, since the storing code should never store an App Key if
there is no corresponding Net Key.

Fixes #9670

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-02 21:44:54 -04:00
Michael Scott d30f2abbe4 net: lwm2m: fix formatter reader/writer initialization syntax
For ease of maintenance, let's swap the reader/writer initialization
syntax to:
.put_begin = put_begin,
.put_end = put_end,
...

This way we only assign used fields and adding new ones later is
less error prone.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott e42611615c net: lwm2m: in oma_tlv_put don't re-add value when insert is true
We set "insert" to true when the value is already in the buffer, but
we need to insert a TLV to denote things like RESOURCE_INSTANCE or
OBJECT_INSTANCE.  In this case, let's not re-add the value.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 7345023dc8 net: lwm2m: TLV: mark object instance boundry when needed
Let's implement put_begin/end_oi functions in the TLV formatter
so to mark the boundry of an object instance when more than 1
object instance is returned.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/9470

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4ba194942a net: lwm2m: refactor put_begin_ri/put_end_ri into generic functions
In order to re-use the put_begin_ri / put_end_ri logic, let's create
generic functions for them: put_begin_tlv and put_end_tlv

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 24e63f1295 net: lwm2m: implement begin/end processing for obj inst and resources
Implement put_begin/end calls for object instance and resource
processing in lwm2m_perform_read_op()

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 90b0986be8 net: lwm2m: store a backup of the entire path in perform_read_op
Currently, we only save the resource id of the incoming path setting.
In the future, we will need to change other values in order to process
multi-instance READ operations.

Let's save and restore the entire path only at the beginning and end
of processing.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 3d2c1b7d72 net: lwm2m: introduce put_begin/end for object instance and resources
Data formatters may need to process data at the beginning and end of
each object instance and/or resource.  Currently, they can only add
processing at the beginning and end of resource instances.

Let's establish put_begin/end_oi (object instance) and put_begin/end_r
(resource) API functions that data formatters can use for this purpose.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 019b24f16a net: lwm2m: optimize lwm2m_perform_read_op()
Optimize the resource processing loop to avoid extra
assignments before checking if we need to process the
actual resource.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 0561887bcb net: lwm2m: fix JSON format for multi-instance reads
When reading multiple instances, the base name value should not
include an object instance id.  The object instance id is added
to the individual resource name values.

Accomplish this by saving the original path level and adjusting
the (base) name where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 658cb19339 net: lwm2m: correct placement of put_begin/put_end in READ op
The put_begin / put_end calls are to be used at the very beginning
and end of processing a READ op.  Let's correct that logic.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 1821c27462 net: lwm2m: optimize variable order in lwm2m_perform_read_op()
Let's sort by largest to smallest so that we don't leave odd gaps
in memory.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott f21b20550c net: lwm2m: remove unused members from lwm2m_output_context
Now that formatters use their own private data to hold state,
let's remove the old member variables from lwm2m_output_context
which are now unused.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4a344e7d0f net: lwm2m: tlv formatter use private data
Use newly introduced private data pointer in output context to
store TLV formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 4fb29949af net: lwm2m: json formatter use private data
Use newly introduced private data pointer in output context to
store JSON formatter information.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott fff8422f60 net: lwm2m: introduce output context user_data
Data formatters have various private state variables which are
currently located in the output context structure.  Let's add
a place where data formatters can store a pointer to their
private data so that as we add more formatters the output
context doesn't get cluttered up.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott a4001f02b0 net: lwm2m: plain-text: process only reads for a specific resource
The plain-text format only supports READ op for a specific resource.
In all other cases return NOT_ALLOWED.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 34a135b608 net: lwm2m: allow formatters to perform processing prior to read_op
Data formatters are becoming too complex for a simple do_read_op()
function to handle all in one place.  Also, more data formatters are
going to be added for LwM2M v1.1 support in the future.

In order for data formatters to perform internal setup or deny
invalid requests (specific to the formatter's logic), let's
establish do_read_op_* functions in each formatter.

Once the internal processing is done, they can call back into the
more generic lwm2m_perform_read_op function.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 485bf7a7eb net: lwm2m: fix reading multiple objects that don't start at 0
Let's correct the starting logic in do_read_op() to not assume
a default value of 0 will be present for the first object, when
reading multiple objects.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 280f159b67 net: lwm2m: fix logic for lwm2m_next_engine_obj_inst()
The object instance list isn't sorted by object instance id.  Let's
simplify this and fix the logic in lwm2m_next_engine_obj_inst() to make
sure that we always get the NEXT object instance by value of
obj_inst_id, not just the next object instance in the list.

NOTE: This change removes the "last" object instance pointer from the
parameters of lwm2m_next_engine_obj_inst().  Some of the logic to return
a NULL value for the end of the list has to be moved back into
do_read_op().

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Michael Scott 0f0455e0b6 net: lwm2m: simplify MATCH_ logic in do_read_op()
Remove over-complicated match_type logic in do_read_op().  Replace
MATCH_* checks with actual path->level values.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-30 14:06:18 -04:00
Jukka Rissanen feed6bfb3b net: dhcpv4: Do not debug print IP address using NULL pointer
The ciaddr can be null in requesting state so do not try to print
it in that case.

Fixes #9575

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-30 10:50:27 -04:00
Paul Sokolovsky a2d12527f6 net: sockets: poll: Handle EINTR return from k_poll
This is similar to change which was done in 21f31e90ec, unfortunately
this case was missed.

Fixes: #9032

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-30 09:28:29 -04:00
Jukka Rissanen cfe27b3984 net: app: Notify peers properly when DTLS connection is closed
The peers were not informed about DTLS connection close because
we removed DTLS context. The fix is to notify peers before we
remove the DTLS connection.

Fixes #8605

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-30 09:27:38 -04:00
Johan Hedberg 643c8abea3 Bluetooth: Fix using correct IRK when generating RPA
The code in le_set_private_addr() was hardcoding identity 0, even
though it is given a specific identity as an input parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-30 13:49:59 +03:00
Subramanian Meenakshi Sundaram 591985140b subsys: logging: Fix possible null dereference
Fixing a possible null dereferencing in log_msg_create_n

Signed-off-by: Subramanian Meenakshi Sundaram <subbu147@gmail.com>
2018-08-29 15:21:19 -04:00
Flavio Ceolin 9624593a0c subsys: logging: Fix possible out-of-bounds read
Coverity issue #187069

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-29 15:15:50 -04:00
Paul Sokolovsky b0c3b35735 net: tcp: Add comment of func prototype for NET_CONN_CB macro usages
NET_CONN_CB() functional macro hides the parameters a function takes
and its return type. In #8723, it's proposed to remove that macro
altogether. Until that proposal is reviewed, at least provide real
protype in code comments to help people who read/analyze the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-29 11:55:07 -04:00
Ruslan Mstoi 6dae106d79 net: ipv6: Drop packet with multiple HBHO
If a malformed packet with multiple HBHO is received by the Zephyr IP
stack it replies with ICMPv6 type 4 code 1: "Parameter problem
unrecognized Next Header type encountered". This ICMPv6 message has
wrong IPv6 payload length and ICMPv6 checksum.

RFC 8200 in chapter 4.1 states:

   Each extension header should occur at most once, except for the
   Destination Options header, which should occur at most twice (once
   before a Routing header and once before the upper-layer header).

There are two possible solutions to the problem at hand:

1) Respond with ICMPv6 Parameter problem, in this case IPv6 length and
   ICMPv6 checksum need to be fixed

2) Drop the malformed packet

This patch implements the easy solution - 2. Basically it changes the
code to drop the malformed packet instead of sending ICMPv6 type 4
code 1.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-08-29 09:26:19 -04:00
David B. Kinder 1c29bff055 doc: fix kconfig misspellings
Fix misspellings in kconfig files missed during regular reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-28 13:58:46 -04:00
Michael Scott a166ba77c4 net: lwm2m: return observe errors immediately
Instead of continuing to do_read_op(), let's handle errors during
observe processing immediately.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott 881fae33a9 net: lwm2m: fix typo in observe error message
obserer -> observe

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott be2b361b35 net: lwm2m: check for read permission on observe
When processing an observe request we fail to check whether a
resource has the read permission set.  Let's check and if it
doesn't return -EPERM.

NOTE: Also do diligence and return -ENOENT when an object field
cannot be found while looking for the permission.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/8286

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-28 08:30:48 -04:00
Michael Scott 3b80998ff2 net: lwm2m: correct Copyright to Foundries.io
Due to a change in the company name, the LwM2M copyrights need
to be changed from "Open Source Foundries Limited" ->
"Foundries.io".

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-27 19:29:16 -04:00
Savinay Dharmappa 6b44a00336 subsys: usb: class: hid: Add OUT interrupt endpoint
patch add a OUT interrupt endpoint descriptor and registers a
corresponding notification callback with usb driver, which is invoked
when data is sent to device from host.

Implement the read ready notification as suggesteed by
Aurelien Jarno <aurelien@aurel32.net>

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-08-27 18:59:58 -04:00
Olivier Martin c3118e66ee subsys: bluetooth: host: Ensure PDUs are not allocated in ISR
`bt_conn_create_pdu()` must not be called in ISR has the call
might be blocking.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-08-27 12:52:11 -04:00
Paul Sokolovsky 45a394e805 net: tcp: Remove NET_TCP_FINAL_* flags
These were at most set, but never used. They appear to be artifacts
of importing code from the FNET stack.

Addresses: #9570

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-27 12:51:37 -04:00
Vinayak Kariappa Chettimada f3be631625 Bluetooth: controller: Fix compile error when PHY update disabled
Fixed compile error when PHY update feature is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:48:12 -04:00
Vinayak Kariappa Chettimada 021b12328a Bluetooth: Kconfig the Auto PHY Update Procedure initiation
Added Kconfig option to select Auto-initiation of PHY update
procedure on connection establishment.

Relates to #9608.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-27 12:47:34 -04:00
Paul Sokolovsky 338dc8a952 net: tcp: Properly queue FIN packets for retransmission
In TCP protocol, any packet is subject to retransmission if not
ACKed in expected time. Thus, any packet, including FIN (and SYN
for that matter) should be added to the retransmission queue.

In our case, despite its name, queue_fin() function didn't add
FIN packet to rexmit queue, so do that. Then, in
net_tcp_ack_received() which handles ACKs, make sure that we can
handle FIN packets: calculate its sequence number properly, don't
make adhoc adjustments to retransmission logic (it's handled
centrally in restart_timer() already), etc.

Fixes: #8188

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-27 12:46:28 -04:00
Jukka Rissanen 4fedec2ee5 net: tcp: Handle out-of-buf properly when preparing segment
If we run out of buffers and cannot create the TCP segment,
then handle it properly and do not access NULL pointer.

Coverity-CID: 187822
Fixes #9639

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-27 12:26:26 -04:00
Jukka Rissanen ab9f39481f net: udp: Check return value when appending UDP data
If there is timeout when adding UDP data, then check this
condition and bail out by returning NULL as the packet is now
malformed.

Coverity-CID: 187825
Fixes #9636

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-27 12:26:26 -04:00
Paul Sokolovsky 2af8dc9630 net: sockets: close: Call net_context_accept only for listening socket
The previous code "optimized" and called both net_context_accept()
and net_context_recv() blindly to reset the corresponding callbacks.
But this leads to "wrong state" logging if debugging is enabled, so
clean that up.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:18:31 -07:00
Paul Sokolovsky 8ccac9f74c net: context: Move/rename net_context_set_appdata_values() to net_pkt.c
This function has absolutely nothing to do with net_context.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:16:15 -07:00
Paul Sokolovsky 8d3510c554 net: pkt: Cleanup validation of min fragment size based on max headers
1. Where we calculate max size, name variable (preprocessor define)
correspondingly.
2. Calling TCP/UDP an "app protocol" is original, use "next protocol"
terminology of IPv6.
3. As headers go as IP, then "next", order calculations that way too.
4. Add more comments.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-25 07:15:58 -07:00
Aurelien Jarno d47fada3a4 subsys: fs/nvs: fix writes when write_block_size != 1
The current code computes the block-aligned len by ANDing the len with
~write_block_size instead of ~(write_block_size - 1).

In addition the compute value can be 0 (for lengths that are less than
the block size), so the first flash write might have to be skipped.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-08-24 13:24:04 -05:00
Vinayak Kariappa Chettimada f232643f7c Bluetooth: controller: Use HCI Error Code definitions
Replase magic numbers with HCI Error Code definitions in the
LE controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Vinayak Kariappa Chettimada 94d7669cf3 Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of Connection Update Procedure to
not assert when peer master violates the Bluetooth
Specification v5.0 Vol.6 Part B Section 5.3 Procedure
Collisions. Instead disconnect the link with reason
Different Transaction Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Relates to commit 8b3fd6963c ("Bluetooth: controller: Fix
assert on different transaction collision")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-24 16:10:01 +03:00
Ramakrishna Pallala 2ad647857c subsys: power: Add OS managed Power Management framework
Add support for OS managed Power Management framework for Zephyr
under 'subsys/power'. This framework takes care of implementing
the _sys_soc_suspend/_sys_soc_resume API's, a PM policy based on
SoC Low Power residencies and also provides necessary API's to
do devices suspend and resume.

Also add necessary changes to support the existing Application
managed Power Management framework.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-08-22 08:07:14 -07:00
Paul Sokolovsky 49732b27d9 net: Move CONFIG_NET_OFFLOAD definition to net/ip/
CONFIG_NET_OFFLOAD was defined in Kconfig of net/ip/l2/, but actually
used by the code in net/ip/.

Fixes: #8646

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-22 12:56:34 +03:00
Luiz Augusto von Dentz 871859a07e Bluetooth: GATT: Make CCC cfg_changed optional
If cfg_changed has not been set consider that the application don't
care and just skip it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-21 21:57:00 +03:00
Anas Nashif 483910ab4b systemview: add support natively using tracing hooks
Add needed hooks as a subsystem that can be enabled in any application.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Anas Nashif a2248782a2 kernel: event_logger: remove kernel_event_logger
Move to more generic tracing hooks that can be implemented in different
ways and do not interfere with the kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Florian Vaussard 5212659820 net: tcp: fix spurious TCP retries
Spurious TCP retries were observed using Wireshark while continuously
sending TCP packets at an interval faster than the initial RTO.

If the send list is empty and CONFIG_NET_TCP_TIME_WAIT_DELAY is used,
the retry timer will not be correctly stopped when receiving a valid
ACK. As a consequence, the timer might be running when a new packet is
queued, but the logics in net_tcp_queue_data() will not restart the
timer as it is already running. This will make the retry timer to expire
prematurely, potentially while sending packets.

The nested condition is merged into a single condition, allowing the
final else clause to be reached when a valid ACK is received.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-08-20 13:53:49 +03:00
Vinayak Kariappa Chettimada 8b3fd6963c Bluetooth: controller: Fix assert on different transaction collision
Updated the implementation of PHY update procedure to not
assert when peer master violates the Bluetooth Specification
v5.0 Vol.6 Part B Section 5.3 Procedure Collisions. Instead
disconnect the link with reason Different Transaction
Collision (0x2A).

Certain phones in the market perform Connection Update
Procedure and do not correctly handle remote initiated
colliding PHY update procedures. They try to perform both
the transactions involving an instant simultaneously
violating the Bluetooth Specifications.

Implementation in Zephyr is updated to gracefully handle
the violating remote master device, and not fatally assert
in the local device.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-18 23:22:10 +02:00
Jukka Rissanen a5f7e3345b net: lldp: Fix timeout triggering if multiple workers
The code was not working properly if there was multiple timers
that were triggered in different times.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:49:53 +03:00
Jukka Rissanen 57a41a2330 net: if: Remove IPv6 auto addresses if the prefix is removed
The autoconfigured IPv6 addresses that are related to removed
prefix, need also removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:02:21 +03:00
Jukka Rissanen 3bfc1385f1 net: if: Mark IPv6 address as preferred if lifetime is renewed
If the IPv6 address expires, then it is marked as deprecated.
If a renewal is received in router advertisement, then the address
can be re-used again and is marked as preferred.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:02:21 +03:00
Ravi kumar Veeramally 7aff94dc5a net: ipv6: Separate IPv6 fragment functionality
No functionality changes. Just moved IPv6 fragment and related functions
to ipv6_fragment.c for better readability

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 8ddb3ba360 net: ipv6: Separate IPv6 MLD functionality
No functionality changes. Just moved IPv6 MLD and related functions
to ipv6_mld.c for better readability.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 58f3e18301 net: ipv6: Separate IPv6 Neighbor functionality
No functionality changes. Just moved IPv6 neighbor and related functions
to ipv6_nbr.c for better readability.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally 51aa291f2c net: ipv6: Centralize ND reachable timeout through one k_delayed_work
Each IPv6 neighbor entry had a k_delayed_work to be used as a timer to
send ND reachable message and waiting for the reply in order to get to
the neighbor details.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
IPv6 ND reachable request timer by having one central k_delayed_work
and a timestamp in every IPv6 neighbor data entry properly handled at
every timeout.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Ravi kumar Veeramally e300275185 net: ipv6: Centralize IPv6 send NS timeout through one k_delayed_work
Each IPv6 neighbor entry had a k_delayed_work to be used as a timer to
send NS message and waiting for the NS reply in order to get to the
neighbor details.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
IPv6 send NS request timer by having one central k_delayed_work and
a timestamp in every IPv6 neighbor data entry properly handled at every
timeout.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-17 17:01:54 +03:00
Robert Lubos d529aef9f2 net: tls: Apply DTLS review fixes
This commit contains several fixes for DTLS implementation, proposed in
a post-merge review of #9338.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-17 15:10:00 +03:00
Jukka Rissanen eeabc2ba3d net: if: Lower ram usage for IP address lifetime handling
Instead of having one delayed_work struct / IP address, use
only one delayed_work struct for lifetime timer. This saves
over 20 bytes / allocated address struct.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 13:36:59 +03:00
Oleg Zhurakivskyy 99dc5aef88 net: ip: Refactor usage of net_sprint_ip*()
Refactor usage of net_sprint_ip*() where multiple
invocations are needed per single log call.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 9d7711f029 net: ip: Redirect net_sprint_ipv*_addr() invocations
Redirect net_sprint_ipv*_addr() invocations into net_sprint_addr().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 37837f5be3 net: ip: Add net_sprint_addr()
The intention is to clean up the usage of net_sprint_ipv*_addr()
functions where 2 or 3 invocations are needed.

Thus, the default number of buffers is 3.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Oleg Zhurakivskyy 1a7e365f8b net: ip: Remove unused function
This is a preparation to refactor net_sprint_ip*().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-17 12:36:50 +03:00
Flavio Ceolin 0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Johan Hedberg bf023d6210 Bluetooth: Mesh: Fix heartbeat subscription state handling
PTS version 7.3.0 incorporates some errata which change the expected
behavior of the heartbeat subscription state. Update the code so that
the following tests pass successfully:

MESH/NODE/CFG/HBS/BV-01
MESH/NODE/CFG/HBS/BV-02
MESH/NODE/CFG/HBS/BV-03
MESH/NODE/CFG/HBS/BV-04

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:40:02 +03:00
Johan Hedberg c037127754 Bluetooth: Mesh: Initialize PB-GATT advertising data at the right time
Some things, such as UUID, URI or even the local name may be different
when bt_mesh_prov_enable() is called compared to when bt_mesh_init()
was called. Create the advertising data on-demand each time when
enabling PB-GATT.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg bb576f61b6 Bluetooth: Mesh: Move Device UUID log to bt_mesh_prov_enable()
In some cases the application might only initialize its UUID after
calling bt_mesh_init(), e.g. in the case of deriving the UUID from the
identity address. To avoid confusing logs, only print the UUID when
actually enabling one of the provisioing bearers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 22:39:36 +03:00
Johan Hedberg e4908119f1 Bluetooth: Mesh: Transport: Fix calculating SeqAuth
This patch fixes case where Mesh is receiving segmented data with
SEQ and SeqZero as in logs below:

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00031FFF friend_match 0
bt_mesh_trans_recv: Payload dd7ffc016e5c7f861272e5f7577a6644
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 0 SegN 1
trans_seg: ######## seq_auth=204799

bt_mesh_trans_recv: src 0x07FF dst 0x0001 seq 0x00032000 friend_match 0
bt_mesh_trans_recv: Payload dd7ffc21abb5a7
trans_seg: ASZMIC 0 AKF 1 AID 0x1D
trans_seg: SeqZero 0x1FFF SegO 1 SegN 1
trans_seg: ######## seq_auth=212991

Original-patch-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-16 17:36:27 +03:00
Paul Sokolovsky 95b64fb776 subsys: console: Refactor code to allow per-UART "tty" wrapper
Instead of having just one static "UART console" device, allow to
instantiate buffered, interrupt-driven POSIX-like "tty" wrapper for
any underlying device. Then, use this functionality to provide
compatible "console API".

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-16 06:18:50 -07:00
Daniel Egger d66e8077ce net/dhcpv4: Use new net_pkt_append_memset() function
Thise uses the new net_pkt_append_memset() function to generate the
required zero filling instead of calling net_pkt_append_u8() in loops.

Fixes #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Daniel Egger 5d3bc8b3d8 net: pkt: Added new function net_pkt_append_memset() to prefill packet
Some locations like DHCPv4 client create a prefilled packet by appending
new fragments in a loop with one byte each via net_pkt_append_u8() which
is wasteful and noisy. This patch adds the new functions
net_pkt_append_memset() which creates fragments as needed in the desired
size and initialises it to the specified value.

This change also adds a unittest for the new function.

Prerequisite for #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Ruslan Mstoi afa0e0026f net: ipv6: Fix crash from fragmented packets
Echo server crashes upon reception of fragmented packets. This
occurs when fragmentation is enabled with the default prj.conf
of echo server. The cause is that by default with logs disabled
net_sprint_ipv6_addr returns NULL.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-08-15 23:49:24 +03:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Jukka Rissanen 355d58b0d0 net: http: One extra byte was sent in last chunk
There was one extra byte sent in last chunk which caused
this error to be printed by curl

  * Illegal or missing hexadecimal sequence in chunked-encoding
  * stopped the pause stream!
  * Closing connection 0
  curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-15 12:59:13 +03:00
Ulf Magnusson 14b4084d88 net: rpl: Kconfig: Fix 'Network type' choice default
The 'Network type' choice always defaulted to NET_RPL_L2_ANY, because
choices prefer the first default with a satisfied condition (this was
true even when Zephyr still had the prefer-later-defaults patch).

Swap the defaults so that NET_RPL_L2_IEEE802154 becomes the default if
NET_L2_IEEE802154 is enabled, as intended.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-14 13:43:11 -07:00
Paul Sokolovsky 78d2476348 subsys: console: Mark as EXPERIMENTAL.
This subsys is in the process of collecting requirements/usecases,
the API is subject to change. (Should have been marked experimental
from the beginning.)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-14 11:56:42 -07:00
Krzysztof Chruscinski 3c63d05dfc logging: Add metadata to hexdump
Extended hexdump API with a raw string attached to the data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-08-14 07:14:34 -07:00
Jukka Rissanen 4078e46e7d net: l2/lib: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit adds checks to L2 and network support libraries.

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Jukka Rissanen 7c7cfdda50 net: core: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit only adds checks to core IP stack in subsys/net/ip

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Xuan Ze 96abe861a7 net/mqtt: Fix function mqtt_parser
There have a funtion mqtt_rx_unsuback defined but not used.
So add it into mqtt_parser and fix the missing case.

Fixes #8431

Signed-off-by: Xuan Ze <119524428@qq.com>
2018-08-13 19:37:36 -07:00
Paul Sokolovsky 028aae1ec9 net: config: Rename Kconfig options to correspond to library name
This finishes refactor of splitting off net_config library name from
net_app library, started in c60df1311, c89a06dbc. This commit makes
sure that Kconfig options are prefixed with CONFIG_NET_CONFIG_
instead of CONFIG_NET_APP_, and propagates these changes thru the
app configs in the tree.

Also, minor dependency, etc. tweaks are made.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-13 18:42:31 -07:00
Krzysztof Chruscinski c859e2a254 logging: Replace ifdefs with if
Replacing preprocessor with compiler in UART backend initialization.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-08-13 13:20:27 -07:00
Johan Hedberg 61ec51251e Bluetooth: shell: Add id-delete command
Add a command to test the new bt_id_delete() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 346f815d9e Bluetooth: Introduce bt_id_delete() API
This API makes it possible to delete an existing identity and to flag
its storage slot as unused.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 47291330b2 Bluetooth: Add safe-guards for creating duplicate identities
Make sure the application doesn't pass existing identity addresses to
bt_id_create() and bt_id_reset(). Also make sure we don't accidentally
create a duplicate when generating random identity addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 7ec40e81d0 Bluetooth: shell: Add multiple identity support
Add shell support for creating and showing identities.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 7dba2512e3 Bluetooth: Introduce bt_id_reset() API
Add a new API which can be used to reclaim an identity slot for a new
identity. When called, any previous pairings, connections, or other
data will be cleared, and then a new identity will be generated in the
place of the old one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 3d3888c094 Bluetooth: Remove return parameter from bt_id_add/del
None of the callers of these APIs do anything with the return value,
so just remove it to produce more efficient code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 9336049725 Bluetooth: Remove bogus bt_keys_func_t typedef
This wasn't used anywhere and was typed incorrectly (the foreach
callback takes two parameters). There was also one user of this which
was triggering compiler warnings of mismatched callback type.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg cbb1b84f91 Bluetooth: Pass identity to connection and pairing clearing functions
When doing bt_unpair() we need to pass the given identity when
disconnecting and clearing keys, in case all associated pairings were
requested to be cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg e70c556dcc Bluetooth: Add full storage support for multiple identities
Update the storage handling to take into account multiple identities.
We can save a bit of code by using the new bt_id_create() API from
within settings.c.

Also make the treatment of addr & irk parameters to bt_id_create()
consistent, in that NULL is acceptable for both of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 3ed01b48b9 Bluetooth: Remove redundant BT_DEV_ID_STATIC_RANDOM flag
This flag was both redundant and creates confusion with potentially
multiple identity addresses (it was only referring to the first
identity address). We can simply just look at the type of the identity
address wanting to be used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 1d8dab811e Bluetooth: Add initial APIs for identity manipulation
Add APIs for getting current identities as well as for creating new
ones.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 5708f1e8b1 Bluetooth: Add infrastructure to handle multiple identities
Make it possible to have multiple identity addresses as an LE
peripheral. For central role only the default identity is supported
for now. This also extends the flash storage in a backward compatible
way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Johan Hedberg 6b8af4f0b2 Bluetooth: Minor whitespace fixes
Remove redundant whitespace.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-13 19:53:22 +03:00
Andrew Boie 18cec245ba net: introduce system calls for zsock socket APIs
Add system calls for the zsock implementations of socket,
close, bind, connect, listen, accept, sendto, recvfrom,
fcntl, poll, inet_pton, and getaddrinfo.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-13 07:19:39 -07:00
Robert Lubos 7c487ba04a net: tls: Use EINVAL for NULL pointer error in option setters
Originally EFAULT was used to indicate NULL pointer error in TLS option
set/get functions. EINVAL was suggested to be more apropriate error code
for this case, hence replace it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 800392e128 net: tls: Enable non-blocking DTLS handshake
Introduce non-blocking DTLS handshake, used during recv function call.
This prevents from blocking while waiting for initial handshake packet
on non-blocking sockets during receive.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos ae41ec1f35 net: tls: Make TLS poll implementation check mbedTLS data
Make TLS poll function verify if decrypted data is available after
socket has notified activity with POLLIN flag. This prevents from giving
false notifications in case data was received on socket but was consumed
by mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8697cc946f net: tls: Add timeout for mbetTLS read
Specify timeout value for mbedtls_ssl_read function for DTLS servers.
Adding this can prevent TLS context lockup in case blocking recv is used
and peer has shut down DTLS connection without closing it gracefully.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b1d8271152 net: tls: Support DTLS recv and handshake
Add support for DTLS recv/recvfrom function.

For DTLS client, recv function requires to have an already established
DTLS connection.

For DTLS servers, this function will try to establish DTLS connection
before receiving data. In case that DTLS handshake fails, recv function
will silently retry.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos bdc56cfe89 net: tls: Support DTLS send and handshake
Add support for DTLS send/sendto function.

For DTLS clients, send function will try to establish DTLS connection
before sending data. If DTLS handshake fails, it will return an error.

For DTLS servers, send function requires to have DTLS connection already
established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos d021b8c60f net: tls: Adapt connect for DTLS
Extend connect function with DTLS functionality.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 6c5aaa070c net: tls: Handle HELLO_VERIFY_REQUIRED during DTLS handshake
DTLS handshake can return MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED, which
indicate that TLS session context should be reset.

Also, store information whether TLS connection has beed established.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4c235dea73 net: tls: Add DTLS bio functions
Add binary IO functions for DTLS connections.

dtls_rx function is more complex than it's TLS counterpart due to fact,
that DTLS does not allow blocking operation for this function. A simple
timeout mechanism was implmented basing on the zsock_poll function.

This function also verifies peer address. As currently only a single
DTLS connection is supported on a socket, if a DTLS connection is
established, and we receive datagram from different peer, it is silently
dropped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 8719f9a802 net: socket: Extract flag related functions to internal header file
Functions for checking flags set on sockets are needed by TLS sockets as
well, therefore extract them to a separate header file to avoid code
duplication.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 4aaffaff8a net: tls: Add DTLS peer address helpers
Add helper functions to handle stored DTLS peer address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 3ad2bbceda net: tls: Add cookie for DTLS
Add DTLS cookie to TLS context, required by DTLS servers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 011b4f4265 net: tls: Add timer handling for DTLS
Add timer functions required by DTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b03a388d73 net: tls: Add socket option to set DTLS role
Add write-only socket option to set role for DTLS connection. This
option is irrelevant for TLS connections.

This options accepts and integer with a TLS role, compatible with
mbedTLS values:
0 - client,
1 - server.

By default, DTLS will assume client role.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 85db974ec3 net: tls: Add DTLS protocol types
Define DTLS protocol types and and Kconfig option to enable DTLS
support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Tedd Ho-Jeong An 8b1f966b12 net: tcp: Handle RST packet when multiple flags are set
After it sends SYN_ACK, there is a case that the client sends the packet
with both ACK and RST bits are set, and this packet needs to be handled
if the packet is valid.

   CLIENT                 SERVER
   ------                 ------
     |--------- SYN -------->|
     |<------ SYN_ACK -------|
     |------- ACK_RST ------>|
     |--------- SYN -------->|
     |<-------- ??? ---------|

This patch checks the RST bits even if other flags are set and process
the packet.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2018-08-13 15:23:18 +03:00
Ravi kumar Veeramally 0aa437a16c net: ipv6: Fix regression in IPv6 cleanup
IPv6 cleanup patch introduced a regression. Misunderstood the logic.
Do not drop the packet if packet does not have ND options, just skip.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-13 14:41:34 +03:00
Oleg Zhurakivskyy ac92a01f5a net: ipv6: Refactor IPv6 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-13 13:53:14 +03:00
Ravi kumar Veeramally 7d55b7f11a net: icmpv4: Simplify the flow at net_icmpv4_get/set_xxx() calls
Instead of reading or writing different icmpv4 header's individual
variables, better to read or write whole struct at a time. This
minimizes the calls to net_frag_read() or net_frag_write().
changes also removed slow and fast paths. Changes should optimize
the total flow.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-13 13:52:57 +03:00
Laczen JMS 7d2e59813f subsys: fs/nvs: Rewrite for improved robustness
On flash NVS was stored one entry after another including the metadata
of each entry. This has the disadvantage that when an incomplete write
is performed (e.g. due to power failure) the complete sector had to be
rewritten to get a completely functional system.

The present rewrite changed the storage in flash of the data. For each
sector the data is now written as follows: the data itself at the
beginning of the sector (one after the other), the metadata (id, length,
data offset in the sector, and a crc of the metadata) is written from
the end of the sector. The metadata is of fixed size (8 byte) and for
a sector that is completely occupied a metadata entry of all zeros is
used.

Writing data to flash always is done by:
1. Writing the data,
2. Writing the metadata.

If an incomplete write is done NVS will ignore this incomplete write.

At the same time the following improvements were done:
1. NVS now support 65536 sectors of each 65536 byte.
2. The sector size no longer requires to be a power of 2 (but it
still needs to be a multiple of the flash erase page size).
3. NVS now also keeps track of the free space available.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2018-08-10 14:16:06 -07:00
Laczen JMS b9dead0a42 subsys: fs/nvs: Improved nvs for larger blocksizes
The nvs module has some disadvantages for larger block size. The data
header and slot are taking up to much space. A rewrite is proposed that
reduces the used storage space for systems with write block size > 4.

The data storage in flash is now one unit consisting of: data_length,
data_id, data and data_length again in a multiple of the write block
size. The data_length at the end is used to validate the correctness of
the flash write and also allows to travel backwards in the filesystem.

As a comparison, on a system with block size 8 byte, a 32 bit values
now fits 1 block including the metadata (length and id). This used to
be 3 blocks.

The data_length will occupy 1 byte if the data length is less than 128
byte, it will occupy 2 byte if the data length is 128 byte or more. The
data length is limited to 16383 byte.

Each write to flash is verified by a read back of the data.

The read performance is improved because reading is done backwards so
the latest items are found first.

When the filesystem is locked it can be unlocked by calling
reinit(), this will clear flash and setup everything for storage.

add sample documentation - README.rst

Update dtsi to include erase_block_size, use erase_block_size in sample

Update prj.conf to include CONFIG_MPU_ALLOW_FLASH_WRITE

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2018-08-10 14:16:06 -07:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Marcin Niestroj 6521b9e4fa net: tcp: Fix net_buf leak in case of low available net_buf count
This net_buf leak happends when we are low on available net_buf
count. During TCP segment preparation we do allocate IP header
successfully, but we fail to allocate TCP header. In such case
pkt->frags is not NULL anymore (it contains IP header), but we
override it during TCP header allocation error path. This results
in net_buf containing IP header to never be deallocated, because
it does not belong to any net_pkt anymore.

Use net_pkt_frag_add() function to add tail for future net_pkt
deallocation, instead of assigning tail to pkt->frags pointer.

Fixes: c6407659f3 ("net: tcp: Add the frag back to caller allocated
  net_pkt")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2018-08-10 13:38:08 +03:00
Ravi kumar Veeramally 06c4a9504f net: icmpv6: Simplify the flow at net_icmpv6_get/set_xxx() calls
Instead of reading or writing different icmpv6 header's individual
variables, better to read or write whole struct at a time. This
minimizes the calls to net_frag_read() or net_frag_write().
changes also removed slow and fast paths. Changes should optimize
the total flow.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-10 12:53:59 +03:00
Jukka Rissanen 31f89b0303 net: eth: Add start and stop L2 functions
If the driver has created start() and stop() functions, then those
are called when ethernet L2 is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-10 12:36:19 +03:00
Ravi kumar Veeramally c8b589045d net: ipv6: Fix memory leak
IPv6 fragmentation splits the packet into two parts, one is header
and another is payload. Every time header is cloned and part of
payload is appended. At the end original header packet is not freed.
Causes memory leak.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-09 16:25:52 +03:00
Ravi kumar Veeramally bfa7516851 net: Do not set appdata on a cloned packet
Current implementation only considers IP header length while setting
appdata value on a cloned packet. It will give bogus value if original
packet contains extension headers and if extension headers are large
(i.e. more than one fragment). Only consider appdata length from the
original packet.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-08-09 16:25:52 +03:00
Oleg Zhurakivskyy fbac80bb94 net: ipv4: Refactor IPv4 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Oleg Zhurakivskyy 33e06441ba net: ipv4: Minor refactoring
Trivial refactoring, no functionality changes.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Alberto Escolar Piedras 3712fd3415 Bluetooth: controller: remove unnecessary guards in hal headers
After a dedicated header is allocated to the simulated SOC versions
there is no need anymore to have guards in these other files

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
Alberto Escolar Piedras e0864a9338 Bluetooth: controller: HAL: Separate simulated SOC in own header
To avoid issues with differences between the simulated and the real
SOC let's separate the simulated one into its own header

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-09 12:15:45 +02:00
Jukka Rissanen d003d0e6a6 net: ipv4: Corrupted ARP pkt was sent instead of real IPv4 pkt
The ethernet sending routine sent a corrupted ARP packet instead
of the actual IPv4 packet.

Fixes #9348

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-09 11:56:44 +03:00
Jukka Rissanen f39ff76ced net: if: Do not inline net_if_ipv6_addr_lookup_by_iface()
No need to inline the net_if_ipv6_addr_lookup_by_iface() function
as it is used multiple times in ipv6.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen d0205693ae net: if: Add net_if_select_src_iface() function
Add a function which returns proper network interface to send either
IPv4 or IPv6 network packet to corresponding destination address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen b8fdf3c67a net: if: Add net_if_ipv6_select_src_iface() function
Add a function that will return the network interface that would
be used when sending a IPv6 network packet to specific IPv6 destination
address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Tomasz Gorochowik e75b607131 net: Fix credit-based shaper typos
The same typo copied to two places, do a: s/sharper/shaper/

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-08 13:01:37 +03:00
Jukka Rissanen 1f855095b4 net: l2: Add promiscuous mode to L2 flags when applicable
This allows more bearers than just ethernet to have promiscuous
mode support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen 66244a0e67 net: if: No need to always join solicit node mcast group
For example for Bluetooth IPSP, it is not needed to join solicited
node multicast group address.

From https://tools.ietf.org/html/rfc7668#section-3.2.2 :

"""
There is no need for 6LN to join the solicited-node multicast address,
since 6LBR will know device addresses and hence link-local addresses
of all connected 6LNs.
"""

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen ccfcdabaf6 net: l2: Add flags to tell if L2 supports multicast
If multicast is not supported, then we do not need to join
multicast group.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jesus Sanchez-Palencia 598276262c net: l2: Add support for Link Layer Discovery Protocol (LLDP)
The LLDP protocol defines 2 separate agents, the Transmitters and
the Receivers. For the context of Zephyr, we are only interested in
the Tx agent, thus we drop any LLDP frames received by Zephyr.

LLDP frames are basically composed by an ethernet header followed by
the LLDP Protocol Data Unit (LLDPDU). The LLDPDU is composed by several
TLVs, some of them being mandatory and some optional.

Our approach here is having TLVs fully configured from Kconfig, thus
having the entire LLDPDU constructed on build time.

The commit adds NET_ETH_PTYPE_LLDP definition and related handling.

If CONFIG_NET_LLDP is enabled then ethernet_context has a pointer to
the struct net_lldpdu that belongs to that ethernet interface. Also
when CONFIG_NET_LLDP is enabled, the LLDP state machine will start to
send packets when network interface is coming up.

Currently the LLDP state machine is just a k_delayed_work() sending the
LLDPDU at a given period (defined by CONFIG_NET_LLDP_TX_INTERVAL).

Fixes #3233

Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 09:53:24 +03:00
David B. Kinder 7c89b63b7c doc: fix kconfig misspellings
Fix misspellings in Kconfig files missed during normal reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-08 01:48:24 -05:00
Michael Scott 9c26c3fa3b net: lwm2m: no need to cleanup net_app_ctx in RD client
The LwM2M engine will cleanup the net_app_ctx if there are
errors during initialization.  The clean up calls here in
RD client are duplicated.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-07 19:55:49 +03:00
Jukka Rissanen 2ff503b7c8 net: shell: Check strtol() conversion errors
Make sure that string to integer conversions are checked properly
so that we are not trying to use the return value from strtol()
if the string is not a number.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-06 14:21:26 +03:00
Robert Lubos b7e686648b net: sockets: Fix setsockopt coverity issues
Minor refactoring to satisfy Coverity.

Fixes #9291 (CID 187324)
Fixes #9296 (CID 187319)

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-06 12:40:40 +03:00
Michael Scott db577f00b1 net: buf: add linearize, append_bytes and skip APIs to net_buf
This change moves the logic for linearize and append_bytes from
the net_pkt sources into the net_buf sources where it can be
made available to layers which to not depend on net_pkt.  It also,
adds a new net_buf_skip() function which can be used to iterated
through a list of net_buf (freeing the buffers as it goes).

For the append_bytes function to be generic in nature, a net_buf
allocator callback was created.  Callers of append_bytes pass in
the callback which determines where the resulting net_buf is
allocated from.

Also, the dst buffer in linearize is now cleared prior to copy
(this was an addition from the code moved from net_pkt).

In order to preserve existing callers, the original functions are
left in the net_pkt layer, but now merely act as wrappers.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-06 10:43:46 +03:00
Tomasz Gorochowik b6852e5a3a net: eth: mgmt: Add remaining 802.1Qav parameter types
This are all the parameters defined by the standard (12.21.1).

Additionally the parameters that are read-only are validated in the
ethernet_set_config callback.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:37:09 +03:00
Tomasz Gorochowik 126602ac43 net: tc: Add other priority to traffic class mappings
This commits adds new priority to traffic class mappings and allows
users to choose which mapping to use through menuconfig.

The new mappings are recommended in 802.1 (chapter 34.5) for
time-sensitive applications supporting the credit-based sharper
algorithm.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:23:57 +03:00
Tomasz Gorochowik c0487a0608 net: tc: Fix priority to traffic class mappings
Priority 0 is the default, but 1 is the lowest. See 802.1Q tables I-1
and I-2.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:23:57 +03:00
Szymon Janc 504584a998 Bluetooth: att: Add option to disable GATT writable name
This allow to set name at runtime while leaving GAP name characteristic
read only.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-08-03 10:41:01 +02:00
Paul Sokolovsky 57286afdd6 drivers: uart: Allow to pass arbitrary user data to irq callback
Zephyr UART drivers offer very low-level functionality. Oftentimes,
it would be useful to provide higher-level wrappers around UART
device which would offer additional functionality. However, UART
driver irq callback routine receives just a pointer to (low-level)
UART device, and it's not possible to get to a wrapper structure
(without introducing expensive external mapping structures). This
is an indirect reason why the current UARt wrappers - uart_pipe,
console - are instantiated statically just for one underlying UART
device and cannot be reused for multiple devices.

Solve this by allowing to pass an arbitrary user data to irq
callback, set by new uart_irq_callback_user_data_set() function.
Existing uart_irq_callback_set() keeps setting a callback which
will receive pointer to the device.

While public API maintains compatibility, drivers themselves need
to be updated to support arbitrary user data storage/passing (as
legacy uart_irq_callback_set() functionality is now implemented in
terms of it).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-02 19:20:12 +02:00
Marti Bolivar 55327a183d logging: fix runtime filtering initialization
The runtime filters (both aggregated and per-backend) are all getting
initialized to the default level CONFIG_LOG_DEFAULT_LEVEL. This is not
correct behavior: the initial runtime setting for each source ID
should match its compile-time level setting.

Otherwise, setting CONFIG_LOG_RUNTIME_FILTERING=y changes the logging
behavior for messages that pass the compile time filter check, but not
the runtime check (this currently happens when LOG_LEVEL=4, since
CONFIG_LOG_DEFAULT_LEVEL=3).

Fix this by initializing all filters to their module's compile time
settings. Also make sure that filters are set up before backends are
activated, to avoid race conditions.

Fix a stray documentation typo while we are here.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-02 19:18:05 +02:00
Luiz Augusto von Dentz 1329763a14 Bluetooth: Fix storing name in plain text
Settings consider the character space the end of the value, so instead
encode the name using settings_str_from_bytes and restore it with
settings_bytes_from_str.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-08-02 19:16:58 +02:00
Alberto Escolar Piedras 4486478f53 shell: Add missing header
When compiling with the native_posix console, the prototype
for posix_flush_stdout() was missing => added.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-02 19:14:19 +02:00
Florian Vaussard 1f23d2681f ip: route: disable LL address check when using dummy L2
The dummy L2 does not setup the link layer address. Do not check the
source and destination link layer addresses when routing packets
otherwise packet routing will not work when using a dummy L2.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-02 16:42:47 +03:00
Jukka Rissanen bab35512f8 net: ipv4_autoconf: Fix requested IPv4 address in ARP packet
Unspecified address 0.0.0.0 was used as a requested IPv4 address
because the ARP message was generated second time. So for IPv4
autoconf ARP message, generate the message only once.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-02 12:42:52 +03:00
Jonathan Yong dd88711a69 net: eth: Vendor specific statistics
Allows ethernet drivers to provide vendor specific statistics
and details in the form of key-value pairs with the name of
the staticstic and its value.

The new string tables will be behind a new config:
	NET_STATISTICS_ETHERNET_VENDOR

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-08-02 12:42:27 +03:00
Philémon Jaermann c3eea5f6ee net: net_app: Correctly notify server on TCP disconnection
If a disconnection callback was registered, it is not called
as the check done in net_app is reversed. The disconnection callback
is not called if there are any inactive contexts.
The check should be on any active context.

Signed-off-by: Philémon Jaermann <p.jaermann@gmail.com>
2018-08-02 10:28:20 +03:00
Johan Hedberg 6ee8e41915 Bluetooth: Mesh: Clarify confusing log message
Normally App Keys are identified using the AppKey Index value (a 12
bit value in practice), whereas the stack-internal array index has
very little relevance.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:06:29 +02:00
Johan Hedberg 28d5a65a94 Bluetooth: SMP: Don't try to encrypt with a non-existing LTK
When we receive a security request we need to make sure that any
existing keys contain an LTK to encrypt with. Otherwise there's a risk
of trying to encrypt with an all-zeroes LTK.

Fixes #3221

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-02 01:05:49 +02:00
Vinayak Kariappa Chettimada 3ebb81ba73 Bluetooth: controller: Wait for stable k32src for connected roles
Added implementation to check and wait for stable 32KHz
clock source before starting connectable/directed
advertising state and initiating state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:04:46 +02:00
Vinayak Kariappa Chettimada 76320d2142 Bluetooth: controller: Fix HCI LE Set PHY command status response
Fixed the implementation to generate command status as per
Bluetooth v5.0 specification instead of the incorrect
command complete that was generated before.

Also, the unsupported features status will be generated
before the invalid parameters status.

Relates to commit 258c7ccff1 ("Bluetooth: controller: Fix
HCI LE Set PHY invalid behavior check")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:03:17 +02:00
Vinayak Kariappa Chettimada 97da52bb95 Bluetooth: controller: Update AA generation for Coded PHY support
Update the access address generation function with Coded PHY
support requirements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-08-02 01:02:29 +02:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Johan Hedberg 0ab27e6803 Bluetooth: shell: Add support for pairing confirm-only callbacks
Add a callback struct with only the pairing_confirm authentication
method. This is useful both for just-works testing as well as the
recently added fixed passkey support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg e504aad28f Bluetooth: shell: Add pairing failed/complete callbacks
Add support for the recently added pairing failed/complete callbacks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg b049ac1216 Bluetooth: shell: Add command for setting fixed passkey
Add a shell command to utilize the newly added bt_passkey_set() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg c446c8267b Bluetooth: Add support for fixed passkeys
Add a new bt_passkey_set() API that can be used to set a fixed passkey
to be used for pairing. The new API also requires a new Kconfig option
to be enabled first (CONFIG_BT_FIXED_PASSKEY).

Fixes #8350

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg ef70fc85a9 Bluetooth: SMP: Fix SMP context init when sending security request
The code was not doing the right thing when we as peripheral would
send a security request to the central. First of all, the SEQ_REQ flag
was getting cleared by the pairing request handler, resulting in
pairing_confirm() callbacks for no reason. Secondly, the behavior in
encrypt_change() was not utilizing the smp_reset() helper as it should
have done.

Fix the situation by calling smp_init() when sending a security
request, and detect that this has been done when receiving a pairing
request. Also do the appropriate cleanup if the result is an encrypt
change instead of a pairing request (in case we were already paired
with the peer).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg da8f62de3a Bluetooth: SMP: Remove redundant check for smp pointer
The smp pointer is the return value of CONTAINER_OF() which is
guaranteed to always be non-NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Johan Hedberg 4752788c81 Bluetooth: Fix documentation and other issues with auth callbacks
Provide proper documentation for all of the authentication callbacks,
and clarify the usage of the cancel callback. Previously the cancel
callback was always required, even though that doesn't necessarily
make sense now that the pairing_complete/failed callbacks exist.

Fixes #8385

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-08-01 16:13:21 +03:00
Tomasz Gorochowik 805e2f2c79 net: eth: mgmt: Merge 802.1Qav related mgmt requests
There are too many individual requests for Qav related parameters. There
are more Qav parameters that need to be supported (and will be supported
soon - both on the GET and SET side). Handling it the way it was handled
so far would render the eth mgmt API dominated by Qav parameters. That
would make the file hard to read and understand.

Instead of that - use a single GET and SET requests for all Qav
parameters. This works by adding a separate enum with Qav request type
to the ethernet_qav_param struct.

Additionally this approach makes it much easier to document it all since
we now have just a single request and documentation comments in the
ethernet_qav_param struct.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-01 15:58:05 +03:00
Jukka Rissanen 528f7f8f2b net: shell: Print supported features for ethernet interfaces
Print information about supported hardware capabilities for
ethernet interfaces when executing "net iface" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-01 11:26:35 +03:00
Tomasz Gorochowik cb3f30a0c9 net: shell: print info about priority queues
If ethernet mgmt is enabled and the driver supports priority queues,
show info about them including the Qav status
(enabled/disabled/unsupported).

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-31 17:54:24 +03:00
Tomasz Gorochowik f568be48d0 net: eth: mgmt: Add Qav status hooks
Add calls responsible for getting and setting on/off status of Qav on
capable priority queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-31 17:54:24 +03:00
Jukka Rissanen 00e37cbb5b net: IPv4 link local support
Add basic IPv4 Link Local support as described in RFC 3927.

Signed-off-by: Matthias Boesl <matthias.boesl@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-31 16:34:28 +03:00
Ulf Magnusson 642db77591 bluetooth: kconfig: Fix swapped 'range's on BT_RFCOMM_L2CAP_MTU
Whoever added Zephyr's prefer-later-defaults Kconfig patch originally
didn't do the same for 'range's. Earlier ranges are still preferred.
Swap the ranges on BT_RFCOMM_L2CAP_MTU to give the intended behavior.

Fixes the following warning for tests/bluetooth/shell/prj_br.conf:

  warning: default value 200 on BT_RFCOMM_L2CAP_MTU (defined at
  subsys/bluetooth/host/Kconfig:508) clamped to 264 due to being outside
  the active range ([264, 32767])

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-31 08:26:28 -04:00
Johan Hedberg db0e4d5267 Bluetooth: Kconfig: Enable TINYCRYPT_ECC for combined builds
Essentially all products that support pairing or Mesh need to be able
to support ECC. This is particularly important for traditional
peripheral/central use cases where legacy pairing is considered
insecure. With split builds we don't know if the controller supports
ECC HCI commands or not, however with a combined build we know that
the current controller lacks any special ECC support, so enable
TINYCRYPT_ECC by default for such a configuration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-31 13:55:40 +03:00
Robert Lubos 80e828b983 net: openthread: Don't regsiter mcast addresses in Zephyr multiple times
OpenThread L2 could've called multicast address registration multiple
times for specific address, which resulted in having multiple entries
containing the same multicast IPv6 address in Zephyr.
Checking if address was already registered prevents that.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-31 11:13:04 +03:00
Robert Lubos 96e794e6b7 net: openthread: Register OT unicast adresses in Zephyr
Register all OpenThread unicast adresses in Zephyr, not only multicast
adresses.

Fixes #9160

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-31 11:13:04 +03:00
Jukka Rissanen 21a27e8807 net: l2: Move individual L2 to dedicated directories
No need to keep technologies in main L2 directory so for consistency
create a directory for each of them and place each L2 component to
relevant L2 directory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-30 09:02:02 -04:00
Johan Hedberg 4fe8eddd27 Bluetooth: SMP: Don't return STK if it hasn't been generated yet
The SMP_FLAG_ENC_PENDING flag indicates that we've generated an STK
and are waiting for encryption to happen. In case the remote enables
encryption prematurely we should not try to encrypt with whatever is
stored in smp->tk, rather reject the pairing attempt.

Fixes #3222

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 13:02:34 +03:00
Jukka Rissanen 9ffab9e63a net: arp: Fix ARP message sending if VLAN is enabled
VLAN tags were not set properly for ARP messages.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-30 12:47:02 +03:00
Johan Hedberg 4d10b04aa1 Bluetooth: SMP: Fix missing NULL-checks for bt_auth
The recently added pairing_complete & pairing_failed callbacks
were missing a NULL-check for bt_auth, since it is possible that
there's no authentication callback structure registered at all.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-30 12:42:45 +03:00
Tomasz Gorochowik 3cd1425b58 net: eth: mgmt: Extend the management interface with a getter
This makes use of the get_config callback added to the Ethernet API.

For now the only parameter to get is the number of available priority
queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-27 20:27:59 +03:00
Luiz Augusto von Dentz 8780636ff8 Bluetooth: shell: Add hci-cmd command
hci-cmd can be used to inject an arbritrary HCI command which can be
useful when testing vendor/new commands.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-27 19:36:11 +03:00
Johan Hedberg e2e0202995 Bluetooth: SMP: Fix minor coding style issues
commit 9b6ad4067b introduced some minor
coding style issues related to line splitting. Fix these.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-27 19:34:34 +03:00
Jun Li 9b6ad4067b bluetooth: add callback to notify pairing is complete
Added two new callbacks for Bluetooth stack to notify
the application that pairing has been completed or failed.

fixes: #8390

Signed-off-by: Jun Li <jun.r.li@intel.com>
2018-07-27 16:16:52 +03:00
Tomasz Bursztyka 2ba28dd78c net/dhcpv4: Unify timeout management in a unique k_delayed_work
This reduces memory overhead on net_if_dhcpv4: 16 bytes vs 120 bytes
before. This might proove to be beneficial when there are many network
interface.

dhcpv4 ROM consumption is now 2132 bytes vs 4224 (many switches removed)

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 11ccf36aa1 net/dhcpv4: Cleanup debug messages
No need to use PRIxxx primitives.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka bb6b2769ab net/dhcpv4: Tiny style fixes
Empty line before if (unless test uses previous line assignment) and
after } (unless it's another } ...)

Indentation fixed as well.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 502912acf5 net/dhcpv4: Reuse generic IPv4 function relevantly
No need to recreate the IPv4 header code here, nor the checksum etc...

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 6d74e26245 net/dhcpv4: Reorder variable declaration
- Pre-assigned are always coming first.
- Always declare at the beginning of a code block

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 3d5876d4a8 net/dhcpv4: Rename functions to follow domain related naming rules
dhcpv4_ for static ones, net_dhcpv4_ for exported ones.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Tomasz Bursztyka 09233e6929 net/dhcpv4: Move definitions to header
As done everywhere else.

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Robert Lubos 7826228def net: tls: Add socket option to set peer verification level
Add write only TLS secure option to set peer verification level for
TLS connection.

This option accepts an integer with a peer verification
level, compatible with mbedtls values (0 - none, 1 - optional, 2 -
required.

By default, socket mimics mebdTLS behavior - (none for server, required
for client).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 3d560e14ac net: tls: Add socket option to read chosen ciphersuite
Add TLS secure socket option to read a ciphersuite chosen during TLS
handshake. Might be useful during development.

This is a read-only option that returns an integer containing an
IANA assigned ciphersuite identifier of chosen ciphersuite.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11c24c855d net: tls: Add socket option to select ciphersuites
Add TLS secure socket option that enables to narrow list of ciphersuites
available for TLS connection.

This option accepts an array of integers with IANA assigned ciphersuite
identifiers and returns such.

By default, every statically configured ciphersuite is available for a
socket and getsockopt returns an array of these.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 915317724c net: tls: Add socket option to set TLS hostname
Add write-only TLS secure socket option to set hostname.

This option accepts a string containing the hostname. May be NULL, to
disable hostname verification.

By default, an empty string is set as a hostname for TLS clients,
to enforce hostname verification in mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos a3edfc2563 net: tls: Set TLS credentials in mbedTLS
Configure selected credentials in mbedTLS before the handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 48e055577b net: tls: Add socket option to select TLS credentials
Add TLS secure socket option to select TLS credentials to use.

This option accepts and returns an array of sec_tag_t that indicate
which TLS credentials should be used with specific socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos f959b5c164 net: tls: Add TLS socket options placeholder
Add TLS secure sockets wrapper for getsockopt/setsockopt functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11f7abcefd net: socket: Define getsockopt() and setsockopt()
Define socket option functions and make them return ENOPROTOOPT.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos d09cbcaf6f net: tls: Add credential management subsystem
Add TLS credential management subsystem that enables to register TLS
credentials in the system. Once specific credentials are registered in
the system, they will be available for TLS secure sockets to use.

To use a TLS credential with a socket, the following steps have to be
taken:
1. TLS credential has to be registered in a system-wide pool, using the
API provided in "net/tls_credentials.h" header file.
2. TLS credential (and other TLS parameters) should be set on a socket
using setsockopt().

Note, that there is no need to repeat step 1 for different sockets using
the same credentials. Once TLS credential is registered in the system,
it can be used with mulitple sockets, as long as it's not deleted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Léonard Bise a691cc8159 net: ipv6: Fix memory leak caused by NS request failure
When an echo request is sent to an unknown neighbor, a Neighbor
Solicitation request is sent, however if the source address
cannot be determined the NS request is dropped but the pending
packet is not freed.

Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
2018-07-26 13:56:32 +03:00
Tomasz Bursztyka 9c5725a69d net/ethernet: Pre-assigned declaration always comes first
And no need of extra parenthesis for casting.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-26 13:55:38 +03:00
Tomasz Bursztyka 5ebc86bdc6 net/ethernet: A device driver api uses struct device *dev
Always use struct device *dev as first parameter for a device driver
API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-26 13:55:38 +03:00
Shawn Mosley 573f32b6d2 userspace: compartmentalized app memory organization
Summary: revised attempt at addressing issue 6290.  The
following provides an alternative to using
CONFIG_APPLICATION_MEMORY by compartmentalizing data into
Memory Domains.  Dependent on MPU limitations, supports
compartmentalized Memory Domains for 1...N logical
applications.  This is considered an initial attempt at
designing flexible compartmentalized Memory Domains for
multiple logical applications and, with the provided python
script and edited CMakeLists.txt, provides support for power
of 2 aligned MPU architectures.

Overview: The current patch uses qualifiers to group data into
subsections.  The qualifier usage allows for dynamic subsection
creation and affords the developer a large amount of flexibility
in the grouping, naming, and size of the resulting partitions and
domains that are built on these subsections. By additional macro
calls, functions are created that help calculate the size,
address, and permissions for the subsections and enable the
developer to control application data in specified partitions and
memory domains.

Background: Initial attempts focused on creating a single
section in the linker script that then contained internally
grouped variables/data to allow MPU/MMU alignment and protection.
This did not provide additional functionality beyond
CONFIG_APPLICATION_MEMORY as we were unable to reliably group
data or determine their grouping via exported linker symbols.
Thus, the resulting decision was made to dynamically create
subsections using the current qualifier method. An attempt to
group the data by object file was tested, but found that this
broke applications such as ztest where two object files are
created: ztest and main.  This also creates an issue of grouping
the two object files together in the same memory domain while
also allowing for compartmenting other data among threads.

Because it is not possible to know a) the name of the partition
and thus the symbol in the linker, b) the size of all the data
in the subsection, nor c) the overall number of partitions
created by the developer, it was not feasible to align the
subsections at compile time without using dynamically generated
linker script for MPU architectures requiring power of 2
alignment.

In order to provide support for MPU architectures that require a
power of 2 alignment, a python script is run at build prior to
when linker_priv_stacks.cmd is generated.  This script scans the
built object files for all possible partitions and the names given
to them. It then generates a linker file (app_smem.ld) that is
included in the main linker.ld file.  This app_smem.ld allows the
compiler and linker to then create each subsection and align to
the next power of 2.

Usage:
 - Requires: app_memory/app_memdomain.h .
 - _app_dmem(id) marks a variable to be placed into a data
section for memory partition id.
 - _app_bmem(id) marks a variable to be placed into a bss
section for memory partition id.
 - These are seen in the linker.map as "data_smem_id" and
"data_smem_idb".
 - To create a k_mem_partition, call the macro
app_mem_partition(part0) where "part0" is the name then used to
refer to that partition. This macro only creates a function and
necessary data structures for the later "initialization".
 - To create a memory domain for the partition, the macro
app_mem_domain(dom0) is called where "dom0" is the name then
used for the memory domain.
 - To initialize the partition (effectively adding the partition
to a linked list), init_part_part0() is called. This is followed
by init_app_memory(), which walks all partitions in the linked
list and calculates the sizes for each partition.
 - Once the partition is initialized, the domain can be
initialized with init_domain_dom0(part0) which initializes the
domain with partition part0.
 - After the domain has been initialized, the current thread
can be added using add_thread_dom0(k_current_get()).
 - The code used in ztests ans kernel/init has been added under
a conditional #ifdef to isolate the code from other tests.
The userspace test CMakeLists.txt file has commands to insert
the CONFIG_APP_SHARED_MEM definition into the required build
targets.
  Example:
        /* create partition at top of file outside functions */
        app_mem_partition(part0);
        /* create domain */
        app_mem_domain(dom0);
        _app_dmem(dom0) int var1;
        _app_bmem(dom0) static volatile int var2;

        int main()
        {
                init_part_part0();
                init_app_memory();
                init_domain_dom0(part0);
                add_thread_dom0(k_current_get());
                ...
        }

 - If multiple partitions are being created, a variadic
preprocessor macro can be used as provided in
app_macro_support.h:

        FOR_EACH(app_mem_partition, part0, part1, part2);

or, for multiple domains, similarly:

        FOR_EACH(app_mem_domain, dom0, dom1);

Similarly, the init_part_* can also be used in the macro:

        FOR_EACH(init_part, part0, part1, part2);

Testing:
 - This has been successfully tested on qemu_x86 and the
ARM frdm_k64f board.  It compiles and builds power of 2
aligned subsections for the linker script on the 96b_carbon
boards.  These power of 2 alignments have been checked by
hand and are viewable in the zephyr.map file that is
produced during build. However, due to a shortage of
available MPU regions on the 96b_carbon board, we are unable
to test this.
 - When run on the 96b_carbon board, the test suite will
enter execution, but each individaul test will fail due to
an MPU FAULT.  This is expected as the required number of
MPU regions exceeds the number allowed due to the static
allocation. As the MPU driver does not detect this issue,
the fault occurs because the data being accessed has been
placed outside the active MPU region.
 - This now compiles successfully for the ARC boards
em_starterkit_em7d and em_starterkit_em7d_v22. However,
as we lack ARC hardware to run this build on, we are unable
to test this build.

Current known issues:
1) While the script and edited CMakeLists.txt creates the
ability to align to the next power of 2, this does not
address the shortage of available MPU regions on certain
devices (e.g. 96b_carbon).  In testing the APB and PPB
regions were commented out.
2) checkpatch.pl lists several issues regarding the
following:
a) Complex macros. The FOR_EACH macros as defined in
app_macro_support.h are listed as complex macros needing
parentheses.  Adding parentheses breaks their
functionality, and we have otherwise been unable to
resolve the reported error.
b) __aligned() preferred. The _app_dmem_pad() and
_app_bmem_pad() macros give warnings that __aligned()
is preferred. Prior iterations had this implementation,
which resulted in errors due to "complex macros".
c) Trailing semicolon. The macro init_part(name) has
a trailing semicolon as the semicolon is needed for the
inlined macro call that is generated when this macro
expands.

Update: updated to alternative CONFIG_APPLCATION_MEMORY.
Added config option CONFIG_APP_SHARED_MEM to enable a new section
app_smem to contain the shared memory component.  This commit
seperates the Kconfig definition from the definition used for the
conditional code.  The change is in response to changes in the
way the build system treats definitions.  The python script used
to generate a linker script for app_smem was also midified to
simplify the alignment directives.  A default linker script
app_smem.ld was added to remove the conditional includes dependency
on CONFIG_APP_SHARED_MEM.  By addining the default linker script
the prebuild stages link properly prior to the python script running

Signed-off-by: Joshua Domagalski <jedomag@tycho.nsa.gov>
Signed-off-by: Shawn Mosley <smmosle@tycho.nsa.gov>
2018-07-25 12:02:01 -07:00
Johan Hedberg c384631dac Bluetooth: Mesh: Kconfig: Tweak RX SDU value
Update the RX SDU Kconfig value to something that reflects better
current use cases and doesn't waste memory needlessly. Also lower the
minimum to two segments, since while many samples need three for their
composition data (typically the biggest transferred payload), it's
possible to have a very simple node whose composition fits in two
segments.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Johan Hedberg 8c1c1641fe Bluetooth: Mesh: Improve outgoing segment count configuration
The Mesh specification doesn't support more than 32 transport layer
segments, the way the number was so far derived from the advertising
buffer count could result in a highre numbe than 32, thereby wasting
memory. Make the number of supported segments build-time configurable
through a new BT_MESH_TX_SEG_MAX configuration option.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 18:16:45 +03:00
Johan Hedberg 1292609458 logging: Use vsnprintk instead of vsnprintf
The printk family of functions is used elsewhere, so make this
consistent. Also, printk has a smaller stack footprint.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 17:41:05 +03:00
Sebastian Bøe c68ab81f89 cmake: settings: Don't add ext nffs include dir to global includes
The settings subsystem has been adding nffs's include dir to the
global set of paths. Presumably because app's will need acces. But
this is no longer necessary as we default to linking 'app' with FS,
which again has the NFFS include paths.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-07-25 08:27:45 -04:00
Sebastian Bøe 4c60c510c3 cmake: default to linking 'app' with the interface library 'FS'
This patch removes the need for application build script code to
explicitly link 'app' with a filesystem implementation.

It does this by introducing a zephyr interface library called 'FS'
that contains the usage requirements for linking with the filesystem
library subsys__fs and using Kconfig to default to linking the 'app'
library with this interface library.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-07-25 08:27:45 -04:00
Jukka Rissanen 9b8c83f44a net: Avoid holes in structs
Move struct members around in networking code so that we avoid
unnecessary holes inside structs. No functionality changes by
this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-25 15:20:34 +03:00
Marti Bolivar 1bfcea244b subsys: logging: fix trigger threshold corner case
The CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD option can be used to wake up
the background log processing thread when a given number of messages
have been queued.

Currently, the msg_finalize() routine which is responsible for
queueing a log message for later handling appends messages to the
global list after performing the threshold check and waking up the
thread.

This leads to a race condition with undesirable behavior if the
threshold == 1:

- the msg_finalize() thread is scheduled out by calling k_wakeup()
- the log processing thread wakes up, notice that no messages are
  queued, and goes back to sleep
- the msg_finalize() thread is scheduled back in and the message is
  queued for processing

This defers the handling of the message until the processing thread
wakes up again after the CONFIG_LOG_PROCESS_THREAD_SLEEP_MS timeout,
which is not what the user wants.

Fix this by queueing the message before waking up the handler thread.
(This also may improve responsiveness for larger threshold values.)

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-07-25 07:14:16 -04:00
Szymon Janc e3bf53566e Bluetooth: controller: Fix disabling LE Encryption support
Symbols without prompt cannot be configured from application
configuration file.

warning: BT_CTLR_LE_ENC (defined at subsys/bluetooth/controller/
Kconfig:198) was assigned the value 'n' but got the value 'y'.
This symbol has no prompt, meaning assignments in configuration files
have no effect on it. It can only be set indirectly, via Kconfig
defaults (e.g. in a Kconfig.defconfig file) or through being 'select'ed
or 'imply'd (note: try to avoid Kconfig 'select's except for trivial
promptless "helper" symbols without dependencies, as it ignores
dependencies and forces symbols on).

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2018-07-25 13:52:03 +03:00
Tomasz Bursztyka 9bb56cc6b9 net/icmpv4: Rename static function with icmpv4_ prefix
Static ones with that prefix, exported ones with net_icmpv4_ prefix.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka ea5610af0a net/icmpv4: src ll address does not need to be set
net if core code will do it.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka be6f59d322 net/icmpv4: Checksum is always set to 0 prior to being calculated
Through net_icmpv4_set_chksum()

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka b89f127f01 net/icmpv4: Use generic IPv4 relevantly
Avoiding to re-create the IPv4 header into ICMPv4 code directly.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka abf68bc5ea net/ipv4: Remove useless return value
net_ipv4_finalize is always successful.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka a38dc0914f net/ipv4: Remove ifdefs and use IS_ENABLED instead
Reduces the logic as well as the ipv4 header checksum needs to be
computed either way.

Fixes #8720

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Tomasz Bursztyka df4325a9b8 net/ipv4: Remove useless proto field setting in ipv4 header
No need to initialize it to 0 as it will be set through given parameter.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-24 17:22:58 +03:00
Jukka Rissanen fbbef6f436 net: stats: Simplify periodic statistics printing
Use modular arithmetic in statistics prints so that wraparounds are
automatically handled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 09:20:46 -04:00
Jukka Rissanen 36ab41df79 net: shell: Print information about promiscuous mode
If the network interface is in promiscuous mode, print information
about it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen 3f9c7bd159 net: Add promiscuous mode support
Allow user to set the network interface into promiscuous mode
and then receive all the network packets that are received by
that interface.

Fixes #7595

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen bf9bae58d1 net: eth: Add generic promiscuous mode support
Allow ethernet L2 driver to set / unset the device driver
promiscuous mode flag.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen b19cb207cb net: if: Add promiscuous mode set / unset functionality
User is able to set the network interface to promiscuous mode
and query the promisc mode status.

Note that currently this is only supported for ethernet bearer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Johan Hedberg 99a91c9459 Bluetooth: Kconfig: Lower minimum required ACL buffer count
The controller already has a minimum of 1, and the host should mirror
that (in particular to avoid Kconfig warnings). A single buffer is
unsafe in some scenarios (such as with LE SC enabled) however there
are valid scenarios where a single buffer makes sense, so leave it up
to the developer to choose this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-24 14:14:49 +03:00
Paul Sokolovsky 58cc75327b net: getaddrinfo: Make availability depend on CONFIG_DNS_RESOLVER
CONFIG_DNS_RESOLVER is the master switch for DNS resolution support,
for both native and socket APIs. Avoid confusing link errors by
compiling out both dns_resolve_name() and getaddrinfo() if that
option is not enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-23 10:04:39 -07:00
Ravi kumar Veeramally 3fafe4f9ad net: ipv6: Handle large IPv6 packets properly
Current implementation does not handle large extension headers
(e.g HBHO). Which resulted network stack crashes or due to
misinterpretation of lengths network packets are dropped. Also
caused issues while preparing IPv6 packet (e.g. large HBHO header
with IPv6 fragmentation support).

Issues fixed and provided more unit tests.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-07-23 15:01:09 +03:00
Luiz Augusto von Dentz e9e5115116 Bluetooth: shell: Add name command
name command can be used to read or write the GAP Device Name which is
used by the advertise command.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz d1c4ce8741 Bluetooth: shell: Make use of BT_LE_ADV_OPT_USE_NAME
Use BT_LE_ADV_OPT_USE_NAME whenver possible since it does properly
track updates.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz 4052ca6d17 Bluetooth: Use shortened name if complete doesn't fit
If the complete name doesn't fit try shortening the name.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz 18df11646f Bluetooth: Allow use of ScanData with BT_LE_ADV_OPT_USE_NAME
This enables the user to provide a ScanData, as long as it contain
names, and set BT_LE_ADV_OPT_USE_NAME.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz acc3e5129e Bluetooth: Add BT_LE_ADV_OPT_USE_NAME
This introduces a new advertising flag BT_LE_ADV_OPT_USE_NAME which can
be used by applications to make the stack automatically include the
Bluetooth Device Name in the Scan Response.

The name is also updated in case there is already an advertising
instance using it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz aa339ed0f2 Bluetooth: GATT: Make GAP name writable
This makes GAP name writable if CONFIG_BT_DEVICE_NAME_STORAGE is > 0
which means the name can be persisted.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Luiz Augusto von Dentz 2637c978fe Bluetooth: Store device name
This uses bt_dev to store the name and allow changing it at runtime, in
addtion to that if CONFIG_BT_SETTINGS is defined make the name
persistent.

Fixes #8357

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-07-23 14:45:58 +03:00
Johan Hedberg be9966f3ae Bluetooth: Mesh: Fix missing semicolon for debug log
Without this it's not possible to build cfg_srv.c with debug logs
enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-20 14:15:49 +03:00
Jukka Rissanen 408a580644 net: ethernet: mgmt: Fix Qav deltaBandwith check
As the value type is unsigned int, it cannot be <0.

Coverity-CID: 187063
Fixes #9002

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 7f0432a114 net: utils: Check null pointer when parsing IPv6 address
We might access NULL pointer if strchr() return value is not
checked properly.

Coverity-CID: 187073
Fixes #8993

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen dfa3f10b26 net: gptp: Add comment for falling through case
Make sure that it is clear that we are suppose to fall through
a case statement.

Coverity-CID: 187078
Fixes #8989

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 27fef49d17 net: gptp: Check overflow of log msg interval
Make sure that we do not overflow when creating UScaledNS
value for interval.

Coverity-CID: 187079
Fixes #8988

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Jukka Rissanen 4670214c26 net: gptp: Fix unsigned value comparison
The nanosecond check was using <0 for unsigned value.

Coverity-CID: 187080
Fixes #8987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-20 00:02:01 -04:00
Johan Hedberg 83db9ad753 logging: Make prefixes the same length
Make the severity level prefixes the same length. This helps both
readability of mixed level logs, and it's also consistent with how the
levels are named in the public API macros.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-19 16:23:19 -04:00
Andrew Boie a74137f665 net: getaddrinfo: use memory allocation for res
We no longer use a global array for what is supposed to be
a memory allocation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Andrew Boie 1b37602859 net: getaddrinfo: ai_state no longer global
Move this onto the call stack of the getaddrinfo() function,
there's no need for it to be global.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Krzysztof Chruscinski 86b5edc4d0 logging: Internal processing thread enabled by default
Enabling internal processing thread allows implicit initialization
and processing log messages in case mutlithreading is enabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-19 09:50:18 -04:00
Jonathan Yong 40f743669b net: eth: Convert to use callbacks to query stats
The advantage to this approach allows drivers for
devices that already keep statistics data on hardware
registers to use those instead, rather than try to
replicate it the same counters again within the driver
itself.

The eth_native_posix.c driver though do not benefit
from this, is modified to use the new callback system.

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-07-19 13:46:13 +03:00
Jukka Rissanen 0251a9f140 net: ipv6: Fix NA debug print
If Neighbor Advertisement cannot be sent, then print info about it.
Earlier we printed info when NA succeeded.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-18 13:01:04 -04:00
Anas Nashif e29acf0015 Bluetooth: shell: fix type usage
We have been mixing u32_t and uint32_t. Using u32_t when the API expects
something else.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-18 12:32:23 -04:00
Mariusz Skamra 051c1f5fd6 subsys: mgmt: Fix broken OTA firmware update
This fixes freeing net_buf without bt_conn_unref call.
As the result, the OTA was broken.

Fixes 8636
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-07-18 14:32:06 +02:00
Ramon Ribeiro 0e626f5ef5 net: openthread: Add NETWORKNAME and XPANID config
This patch add the option to the user sets the network name and
the extended PAN ID

Signed-off-by: Ramon Ribeiro <rhpr@cesar.org.br>
2018-07-17 16:40:53 +03:00
Ramon Ribeiro a9c684c6e6 net: openThread: Fix MTD build
This patch fix the problem when the user select to use the MTD
in OpenThread configuration

Signed-off-by: Ramon Ribeiro <rhpr@cesar.org.br>
2018-07-17 16:40:53 +03:00
Michael Scott 3f53e6d1d8 net: lwm2m: read past not supported TLV resources
During transfer of object data via OMA TLV format, we can
encounter resources which are optional or not handled in base
LwM2M engine.  When these resources cannot be handled let's
read past them and continue on.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott ce48f18d10 net: lwm2m: use ARRAY_SIZE to calculate # of options
Don't use hard-coded value of 4 for passing the # of options to
coap_find_options() in handle_request().  This can easily get
out of sync.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott 538d3418fd net: lwm2m: introduce user-code callbacks for obj create/delete
LwM2M engine now supports optional resources that may need to be
setup or torn down in user-based code during object instance
creation / deletion.

Let's provide callbacks that can be used for this purpose.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott 56e240e528 net: lwm2m: make lwm2m_engine_exec_cb_t more generic
Let's rename lwm2m_engine_exec_cb_t to lwm2m_engine_user_cb_t so that
future user-code callbacks can make use of the same definition.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Paul Sokolovsky eedb8a7bd8 net: sockets: Make poll() call threadsafe by avoiding global array
Initial implementation of poll() was more of a proof of concept, so
was coded with a single-thread application in mind. As we move to
sockets as the main networking API, make it possible to use poll()
from different threads.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-17 13:02:16 +03:00
Ulf Magnusson 53c5058d6e net: ip: kconfig: Simplify NET_RX_STACK_RPL definition
A condition can be but on a prompt to make a symbol conditionally
user-assignable (visible).

Kconfig note:

'default's don't care whether the symbol is visible (has a prompt with a
satisfied condition) or not. 'if'/'depends on' just puts the same
condition on all the properties, disabling both the defaults and the
prompt at the same time. That might make it look like they're connected.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-16 21:03:27 -04:00
qianfan Zhao 32e6d0ca87 usb: set SN string descriptor at runtime
implement a method that can set SN string descriptor at runtime.
but runtime SN and default SN configured in Kconfig must has the
same length.

Fixes: #6593

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-07-16 17:20:58 +02:00
Krzysztof Chruscinski 46db70ac4c doc: subsys: logging: internal thread and thread wake up
Documenting new logger features: waking up processing thread
and internal logger processing thread.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Krzysztof Chruscinski 000aaf96fb logging: Add internal thread for log processing
When enabled, logger is creating own thread which processes buffered
logs. When no logs to process, thread sleeps for configurable period.
Thread can be waken up if number of buffered log messages exceeds
configured threshold. Logging sample aligned to use new feature.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Krzysztof Chruscinski 1ba542c352 logging: Logger to wake up logs processing thread
Added configurable threshold of number of buffered log messages
on which log wakes up thread which processes buffered logs. Thread
ID is provided during logger initialization. Feature is optional
and can be disabled by setting CONFIG_LOG_PROCESS_TRIGGER_THR to 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Kumar Gala f035395ed0 bluetooth: at: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Kumar Gala c2862eda4d bluetooth: mesh: shell: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:06:20 -04:00
Krzysztof Chruscinski 6b01c89935 logging: Add log initialization to system startup
Log API can be used before user can explicitly initialize the logger.
In order to ensure that logger core is ready to buffer log messages
it must be initialize as early as possible. Initialization does not
include initialization of default backend since driver may not be
ready and backend is needed only when log messages are processed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-14 08:32:44 -04:00
Robert Lubos 47f908872d net: tls: Implement poll with support for mbedTLS pending data
Implement socket poll function for TLS socket. In addition to regular
poll checks, we have to check if there is some decrypted data pending on
mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 07f1a1fe2c net: tls: Handle TLS socket send and recv
Implement socket recv/recvfrom and send/sendto functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos d08fd07f60 net: tls: Handle TLS handshake
Implement TLS handshake handling in socket connect/accept functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 2d4815dd15 net: tls: Add mbedTLS logging
Add mbedTLS logging function to enable logs from mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos ccdc6a6bdf net: tls: Add mbedTLS entropy source
Add entropy source for mbedTLS. If no entropy driver is available, use
non-secure, software entropy source.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos a7c698d936 net: tls: Add TLS context allocation/deallocation
Add tls_context structure that stored data required by TLS socket
implementation. This structure is allocated from global pool during
socket creation and freed during socket closure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 00a69bf9bb net: socket: Add switch to enable TLS socket option support
Add switch to a socket layer that will enable switching socket API to
TLS secure sockets. At this point there is no secure sockets
implementation, so secure socket calls redirect to regular socket calls.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Andrei Emeltchenko c8af08e5d4 usb: osdesc: Use definition for string descriptor index
Use definition and add description block.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 25afcc574f usb: device: Refactor vendor_handler
Since vendor commands cannot assume that wIndex keeps interface number
we change logic trying to call every vendor handler which should check
input parameters.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko c2fdfbb835 usb: rndis: Use RFC 7042 Doc value for Host MAC
Use similar RFC 7042 Documentation value like it is in CDC ECM.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 7b0e9d7c53 usb: composite: Add handling osdesc feature
Add handling osdesc feature also for composite configuration.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko d8da50a30d usb: rndis: Set subCompatibleID parameter for exact MS driver
Set subCompatibleID value according to "C:\Windows\INF\rndiscmp.inf"
file. The exact matching part is:
"USB\MS_COMP_RNDIS&MS_SUBCOMP_5162001"

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 93dd1b99c2 usb: rndis: Add MS OS v1 descriptors to RNDIS
This should allow automatic driver loading in MS Windows.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 59e9cd0f13 usb: osdesc: Add MS OS Descriptors version 1 support
Add support for MS OS Descriptors. The patch structures already
existing code for webusb to the single place to be easy added to other
places.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko a19b469ae3 usb: Cleanup code style for usb_device
Make usb_device code consistent with the rest of the code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Andrei Emeltchenko 44b7076c22 usb: Correct include path
This makes possible to include headers from subsys/usb

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-12 23:10:22 -04:00
Kumar Gala 21d6e302f6 net: lwm2m: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:47:15 -05:00
Krzysztof Chruscinski d731e539ce logging: Handle 0 Hz frequency in log_output
It is possible that user provides 0 hz frquency to the log_output
(if CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=0). In that case timestamp
must not be formatted to avoid division by 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-11 10:56:07 -04:00
Jukka Rissanen cb00061cbe net: dhcpv4: Use less parameters in debug print
Having 24 parameters in a debug print is a bit extreme especially
as it is causing warning from new logger. Split the debug print
to three pieces each having 8 parameters which is more reasonable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-10 12:37:31 +03:00
Vinayak Kariappa Chettimada 505a83414e drivers: gpio: nrf5: Fix GPIOTE channel use overlap
Fixes issues caused in GPIO driver due to overlapping GPIOTE
channel use in nRF5 software PWM driver and in Bluetooth
controller for implementing PA/LNA feature.

The issue is solved by assigning the base and available
channel count for GPIOTE considering whether PWM and/or
PA/LNA feature is selected in the Kconfig.

Fixes #8815.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-07-10 11:25:32 +02:00
Krzysztof Chruscinski e854dd0069 logging: log_output: Data lost because of uninitialized variable
Uninitialized variable error could lead to a situation where
printk calls processed by the logger were dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-09 12:09:43 -04:00
Jukka Rissanen f10cbe5ee9 logging: Print 7, 8 or 9 parameter macros properly
The log prints for 7, 8 and 9 parameters were not properly printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-09 11:16:49 -04:00
Johan Hedberg 5c3d5660ef shell: Fix command completion logic
Similar fix as in commit b26ca13672. Just later in the same
function. This is how the logic used to be before quite heavy redesign
that happened a while ago.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-08 08:04:10 -04:00
Johann Fischer 25b0212fc3 subsys: usb: class: add loopback function
Add loopback function. This function can be used to test
USB device drivers and device stack connected to linux host
and has the similar interface as "Gadget Zero" [1] of the Linux
kernel.

Use modprobe usbtest to load the module, see also [2] for the
description of the tests and for Vendor and Product ID of the
"Gadget Zero". The userspace tool testusb [3] is needed to start
the tests.

[1] linux/drivers/usb/gadget/function/f_loopback.c
[2] linux/drivers/usb/misc/usbtest.c
[3] linux/tools/usb/testusb.c

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Johann Fischer 3a471e3240 subsys: usb: stall if there is no data buffer
Return a STALL in the setup or data stage if there is no data buffer.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Johann Fischer 1b5775249d usb: add callback codes for Set/Clear Feature ENDPOINT_HALT
Add callback codes for Set/Clear Feature ENDPOINT_HALT.
These can be used to inform a function that the device stack has
received Set/Clear Feature request ENDPOINT_HALT. The function can
then abort or restart the transfer accordingly.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-06 11:56:16 -05:00
Andrei Emeltchenko 7cb8689397 usb: netusb: Add ethernet_init()
After PR #8608 every driver should call ethernet_init(), fixes missing
chunks of that PR.

Fixes: #8752

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-05 09:56:53 -04:00
Jukka Rissanen 48802024f2 net: icmpv4: Set the ICMPv4 header correctly
The code did not check if the icmpv4 header struct is already
pointing to net_buf or not. This meant that the code did not
set the ICMPv4 options and types correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-05 15:44:49 +03:00
Walter Xie 354c50e8ed net: add bound checking in net_addr_pton()
The net_addr_pton() did not check the number of ":" characters properly.
For example with following net-shell input
net ping fe80::210:2030:9b:d48efe80::210:2030:9b:d48e
the kernel panics.

Signed-off-by: Walter Xie <41377148@qq.com>
2018-07-05 14:17:23 +03:00
Jukka Rissanen 37125781aa net: gptp: Fix debug prints and use correct modifier
Use %zd instead of %lu when printing size_t variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-05 13:08:04 +03:00
Tomasz Gorochowik 226fa97304 net: ethernet: Add 802.1Qav settings to eth mgmt api
This commit adds a possibility to use Qav (credit-based shaping) in the
ethernet drivers.

There are two parameters exposed through the mgmt api: deltaBandwidth
and idleSlope.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:27:34 -04:00
Tomasz Gorochowik 22ba08faa3 net: gptp: Send Announce messages with correct GM info
There is no point in sending Announces with GM chosen in BMCA if it is
expired and InfoIS is changed to MINE.

Check where does the GM info come from and fill the Announce packet
accordingly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 1a0968bd74 net: gptp: Normalize seconds and nanoseconds differences
Do not allow seconds and nanoseconds drifts to have the opposite signs.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik fd62617ce2 net: gptp: Fix memcpy calls on arrays
Copy array content, not pointers.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 2ca3b1e3c4 net: if: Fix TX timestamp callbacks invocation
The problem is that net_if_call_timestamp_cb only checked if the
callback was registered for the PORT which invoked the whole action.

There is a possibility, that the callback will be registered, and packet
A will be passed to eth driver. Before the driver is finished with
packet A, network layer will start handling another packet (B) - so it
will unregister the callback for packet A and register it for B. After
that the network driver will finish processing packet A and invoke the
timestamp callback. The mechanism would then only check if a callback is
registered for the port of the driver and invoke the callback for the
packet that was registered earlier (so A instead of B).

This commit fixes that by storing info not only about the port but about
the packet too.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Jukka Rissanen 65e9177a27 net: gptp: Print port state change information
If debugging is enabled, then print port state change information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik fb6223b893 net: gptp: Drop the older pdelay req after receiving a new one
Previously the newer one got dropped.

The older ones will be dropped in a way that the follow up messages for
them will not be sent.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik 214aebc6e1 net: gptp: Fix gptp port number validation
The gptp port number starts from 1, so the check was incorrect.
Use the proper define values before printing stats.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Tomasz Gorochowik b51f1ccce8 net: gptp: Fix validation of non-numeric inputs from net shell
The shell did not check if the gptp port (command argument) is numeric.
Add that check before executing the port info functions.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Jukka Rissanen 5356ee5d20 net: gptp: Init only the ports we have configured
The MI state machine was init with too many ports, even if
we only had one of them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-04 11:22:23 -04:00
Joakim Andersson dbc00ba374 Bluetooth: controller: Fix empty_pkt_us_get for 2M phy.
An empty packet on 2M phy is one more byte compared to 1M phy because
of the preamble.
The empty packet is then 11 bytes, which takes 44 us to transmit.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-03 22:47:45 -04:00
Leandro Pereira 91220ba640 boards: native_posix: Add option to build with Address Sanitizer
Address Sanitizer helps finding issues related to memory: buffer
overflows, usage of uninitialized memory, etc.  This is available in
both Clang and GCC for a while, and, since the POSIX port is only
meant for testing, this will help find issues.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-03 17:06:25 -04:00
Johann Fischer 06ac62ed32 usb: usb_descriptor: fix null pointer dereference
Fix possible null pointer dereference if the device
descriptor is not complete.

Fixes: #8700
Coverity-ID: 186841

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-03 14:28:46 -04:00
Jukka Rissanen e9228a3964 net: gptp: Allow gPTP to run over VLAN
Allow this setup as Linux supports this too.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen 65b15c3226 net: eth: Add helper to return VLAN info for an interface
A small helper function will return information whether
a given network interface has VLAN enabled or not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen 3fd2d53e56 net: mgmt: Add VLAN enabled / disabled event support
Send network management event if VLAN tag is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Oleg Zhurakivskyy dadc5293aa net: icmpv4: Simplify the flow at net_icmpv4_get_hdr()
Using net_frag_linearize() should be optimal for fast and slow paths.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-07-03 15:38:43 +03:00
Ioannis Glaropoulos 0677812910 arch: arm: nrf: remove kernel_includes.h from nRF5x soc.h inclusions
This commit removes the inclusion of kernel_includes.h from
the nRF51 and nRF52 soc.h headers. This prevents from an
inclusion cycle formation on soc.h. In the wake of
kernel_includes.h removal, necessary header files have been
added in several source files to be able to compile Zephyr for
nRF5x SOCs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-02 16:50:10 +02:00
Oleg Zhurakivskyy 2b6e70d10d net: icmpv4: Merge process_icmpv4_pkt() into net_icmpv4_input()
Both are small, merging makes the flow clearer.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-07-02 17:33:44 +03:00
Jukka Rissanen 58e40cb029 net: gptp: Fix shell statistics output
Some printout fixes are needed for "net gptp 1" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 17:01:00 +03:00
Jukka Rissanen f3146c09ab net: gptp: Fix buf leak in PDELAY_REQ send
Do not clear pending PDELAY_REQ pointer when sending a new one.
Unref the state->tx_pdelay_req_ptr first and only then set the
new pointer value. This will prevent buffer leak if we miss the
response from the peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 5e3ea84e64 net: gptp: Use calculated neighbor ratios only once
Make sure that the calculated ratio values are used just once.
Without this, if the ratio is even insignificantly larger than 1, the
actual clock quickly drifts to really large numbers. This causes the
sync procedure to restart too often.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 93fe54d148 net: gptp: Fix sync timestamp callback registration
The logic was inverted which prevented the callback from ever being
registered.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik 7e545c998c net: gptp: Do not handle multiple pdelay requests at once
The problem with the previous approach was that the response timestamp
callback which calls net_pkt_unref could be skipped if the callback was
already registered for another packet. The net_pkt_ref function was
always called which led to memory leaks.

This commit simply disallows handling multiple pdelay requests at once.
If the timestamp callback is already registered, the received request
will not be handled.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Tomasz Gorochowik b422d38650 net: gptp: Fix sync follow up packets content
The issue was that the length field of the tlv extension in the sync
follow up packets was wrong. It is supposed to skip the length of the
header of that extension. The easiest fix was separating the header and
the actual contents into separate structs and that's what this commit
does.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-02 16:52:49 +03:00
Jukka Rissanen cf272e6667 net: gptp: Use the ptp clock instead of zephyr uptime
As the PTP clock should return the correct time, use that
instead of zephyr uptime for time as that has only ms accuracy.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Jukka Rissanen 70b60cca1d net: gptp: Set priority of the sent gPTP packets
Use priority 3 (critial app) for outgoing event messages (Sync,
Pdelay_Req and Pdelay_Resp). Use priority 6 (Internetwork Control)
for all other outgoing packets.
See IEEE 802.1Q chapter 8.4.4 for more details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Dong Xiang 7ba7119f82 net: l2: Fixed wifi can not connect to open AP.
When connect to open AP, the security is always set to
WIFI_SECURITY_TYPE_PSK.

Signed-off-by: Dong Xiang <dong.xiang@unisoc.com>
2018-07-02 15:19:37 +03:00
Joakim Andersson c6dea9e068 Bluetooth: Reorganize Kconfig options for BLE controller
Split meaning of BT_CTLR and BT_LL_SW, since they always are the same.
This way BT_CTLR means that there an controller implemented,
and BT_LL_SW refers to the specific implementation.
This allows alternative controller implementations.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-07-02 11:59:43 +02:00
Paul Sokolovsky c89a06dbc1 net: config: Introduce a dedicated header for the library
Split out definition of net_app_init() and its parameter flags from
net_app.h header to new net_config.h header. As we do this, rename
the function to net_config_init() and flags to NET_CONFIG_NEED_*.
This is a second step in splitting out network configuration API
out of net_app API, started in the c60df1311 commit.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-02 12:36:35 +03:00
Tomasz Bursztyka d309c870c7 net/ipv6: Properly separate what belongs to ipv6 from the rest
Context part should be in context. Then, rename ipv6 function for
clarity.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-02 12:34:12 +03:00
Tomasz Bursztyka 68f7e96916 net/ipv4: Properly separate what belongs to ipv4 from the rest
Context part should be in context. Then, rename ipv4 function for
clarity.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-02 12:34:12 +03:00
Jukka Rissanen 0738ab3e09 net: shell: Check link address when printing iface info
There is no link address for Dummy network technology, so check
that before trying to print link address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 12:21:16 +03:00
Anas Nashif 964979f539 usb: mark unused arguments correctly
use ARG_UNUSED instead of making variable equal itself.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:23 +02:00
Jukka Rissanen b833d010eb net: llmnr: Add LLMNR responder support
This allows zephyr to listen LLMNR DNS queries sent by Windows
and respond to them. See RFC 4795 for details.

The feature requires that hostname is set properly to the
zephyr device and LLMNR is configured properly.

Typically following config options are enough for this support:

CONFIG_NET_HOSTNAME_ENABLE=y
CONFIG_NET_HOSTNAME="zephyr-device"
CONFIG_DNS_RESOLVER=y
CONFIG_LLMNR_RESPONDER=y

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-29 13:11:18 +03:00
Jukka Rissanen 837ed14a0d net: llmnr: Add link-local mcast name resolution client support
This implements LLMNR client from RFC 4795. This means that caller
is able to resolve DNS resource records using multicast DNS.
The LLMNR is used in Windows networks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-29 13:11:18 +03:00
Tomasz Bursztyka 922d63cee5 net/arp: Normalize all function names
Let's follow the same prefix for all function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 2df23f567b net/arp: Let's reduce the size of each ARP entry
An ARP entry, if not free, will be either in pending list or in the ARP
table. What differentiate both is the type of data they hold: either a
pending packet or an actual ethernet address.

It is then possible to unite these 2 attributes to save 4 bytes
per-entry.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 35a7804cdf net/arp: Centralize ARP request timeout through one k_delayed_work
Until now, each ARP entry had a k_delayed_work to be used as a timer
when the ARP entry is a pending one, waiting for the ARP request to
succeed in order to get to the ARP table.

But k_delayed_work is not a small object (40 bytes). Thus reworking the
ARP request timer by having one central k_delayed_work and a timestamp
in every ARP entry properly handled at every timeout (1+ entry might
have reached the timeout then).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 0025a3fce2 net/arp: Optimize ARP table by switching to various single list
Instead of looping over the entries array, which will keep the same
order, let's use slist: one for free entries, one for pending ones and
finally one as the actual ARP table.

This permits some optimizations in how to look up and making small
heuristics by changing entries order when it seems relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Tomasz Bursztyka 89eeba4250 net/arp: No need to expose publicly arp header
ARP is something internal to ethernet L2, let's just hide its header
file.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Krzysztof Chruściński bbeef4155c logging: subsystem major redesign
Adding new implementation of logging subsystem. New features
includes: support for multiple backends, improving performance
by deferring log processing to the known context, adding
timestamps and logs filtering options (compile time, runtime,
module level, instance level). Console backend added as the
example backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2018-06-29 10:16:45 +02:00
Mariusz Skamra 8f6ebc5322 Bluetooth: controller: Fix LE Extended Scanner Filter Policy dependency
This adds dependency upon Observer role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-28 22:16:31 +02:00
Jukka Rissanen 066edbb233 net: shell: Add gptp command
This "net gptp [port id]" command will give some extra info about
gPTP status if gPTP is enabled in config file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-28 16:50:50 +03:00
Jukka Rissanen 67b4c5d5d4 samples: net: gptp: Sample application for gPTP support
The application does not do much, it just registers to a callback
in order to get information about gPTP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-28 16:50:50 +03:00
Jukka Rissanen 45b06a252f net: gptp: Initial core IEEE 802.1AS support
Core IEEE 802.1AS-2011 (gPTP) support and application interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-28 16:50:50 +03:00
Ismael Fillonneau 4535b9443d subsys: dfu: img_util: Fix warning with ERR log
GCC complains because of wrong format. commit based on #7412

Signed-off-by: Ismael Fillonneau <ismael.fillonneau@stimio.fr>
2018-06-28 13:02:42 +02:00
Johan Hedberg cd1111e16f mgmt: Reduce net_buf user data requirement
Instead of storing a bt_addr_le_t, just store a pointer to the bt_conn
object (which is what the code is interested in anyway). This way the
user data size requirement drops from 7 to 4, which is the default
that all current users are happy with.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:49:52 +03:00
Johan Hedberg 387e91a76b Bluetooth: Mesh: cfg_srv: Ignore Prohibited element addresses
The Configuration Model specification states that all non-unicast
addresses given as the address of an element are Prohibited. The
correct action for Prohibited parameter values is to ignore the
message. As of writing this patch the PTS does not enforce this, but
it might in the future (as it does for many other Prohibited values).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Johan Hedberg e69b735a5a Bluetooth: Mesh: Fix checking for model subscription address
Previously the code only checked if any of the models within an
element had the destination address in their subscription list. After
that check the specific model that the message was addressed to was
not verified to have that address in it's subscription list. This
patch fixes the problem.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:48:18 +03:00
Vinayak Kariappa Chettimada cea4b31866 Bluetooth: controller: Add support for the nRF52810
The nRF52810 is a low-cost variant of the nRF52832, with a reduced set
of peripherals and memory. This commit adds Bluetooth controller support
for it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-27 16:09:58 +02:00
Jukka Rissanen 8ae6bad21d net: l2: Move the layer 2 code into subsys/net/
The subsys/net/ directory is more logical place for L2 code instead
of ip/ directory. No functionality changes by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-27 17:02:59 +03:00
Johan Hedberg 59bbab99a8 Bluetooth: Mesh: Fix cyclic rewriting to flash when restoring state
When we're reading the initial state from flash, calling the various
internal functions was leading to scheduling a rewrite to flash. Add
an extra parameter to the appropriate functions so they know when
they're called due to active configuration by a configuration client,
and when they're called due to restoring the state from flash.

This was not only wasting flash space, but also causing erroneous
behavior with the FCB settings backend if there was an intermediate
node reset operation stored, followed by a reprovisioning. The node
reset entries would cause them to be re-appened after the second valid
provisioning, leading to an incomplete node state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg f23e808ed0 Bluetooth: Mesh: Fix redundant model publication clearing
If the model publication is not enabled, we should return success,
however no other steps need to be done. This also helps avoid writing
redundant entries to flash when resetting a node that never had model
publication enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Johan Hedberg 310320c4d1 Bluetooth: Mesh: Fix initialization order during node reset
There were several things broken with the initialization order during
node reset:

 - The model->flags should not be touched since the writing to
   persistent storage happends through delayed work, and the flags
   need to be kept until that.

 - The unprovision() function should only be called at the very end of
   the reset procedure, since it calls model-specific init functions
   which may clear things which the earlier reset routines depend on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-27 15:54:40 +03:00
Paweł Zadrożniak f3d1b22487 subsys: usb: Fixes USB DFU class by updating the bcdUSB value.
bcdUSB has been previously updated from 1.1 to 2.0 in default
device descriptor, but not in DFU class. After USB bus reset
performed by dfu-util, alternative descriptor is registered
with bcdUSB set to 1.1. This mismatch causes communication failure.
DFU descriptor's bcdUSB has been updated to match default one.

Relates to #7570

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-06-27 13:38:12 +02:00
Joakim Andersson 5e3c48f43c bluetooth: Make controller crypto functions optional
Provide flexibility in choosing to use the host defined crypto
functions or the ones provided by the controller

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-06-27 12:12:45 +02:00
Mariusz Skamra 698311d220 Bluetooth: att: Add Kconfig option to disable Multiple Read operation
This adds an Kconfig option to disable GATT Multiple Read support.
This GATT sub-procedure is optional and does not have to be supported.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra becbfa2243 Bluetooth: att: Do not build Signed Write cmd handler if SMP disabled
This function does nothing actually if SMP is disabled.
This excludes att_signed_write_cmd handler from build if BT_SMP
is disabled or BT_SIGNING is disabled.

Note:
BT_SIGNING depends on BT_SMP

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra 76d0dd41f9 Bluetooth: hci_core: Exclude scan related code if non-observer
This chunks should be excluded from build if the target application
does not support neither observer not central role.
This helps to reduce the application image size that implement
Peripheral or Broadcaster role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra 8a50160198 Bluetooth: Mesh: Depend Mesh upon Observer and Broadcaster roles
This adds dependency upon BT_BROADCASTER and BT_OBSERVER roles.
Those are necessary to implement Mesh device.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Mariusz Skamra f3ba6e3806 Bluetooth: hci_core: Exclude conn creation related code for non-central
Don't build the code that is related to central role if the target
does not support connection creation.
This helps to reduce the application image size that implement
either Observer, Peripheral or Broadcaster role.

Note:
BT_CENTRAL implies BT_CONN and BT_OBSERVER

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-27 12:50:24 +03:00
Johan Hedberg d41d9bd112 Bluetooth: Convert sample code to use the new bt_data_parse() API
Convert the shell and central_hr sample apps to use the newly
introduced bt_data_parse() API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-26 19:34:57 +03:00
Johan Hedberg 8818244959 Bluetooth: Add helper for parsing advertising data
It is quite easy to implement a buggy or security vulnerable
advertising data parser. Provide a helper for this purpose, which uses
the existing bt_data struct which is used for programming the local
advertising data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-26 19:34:57 +03:00
Jukka Rissanen ed25a16a3b driver: ptp_clock: PTP clock driver definition
Defines a PTP clock driver that can be implemented in those network
interface drivers that provide gPTP support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-26 12:37:28 +03:00
Tomasz Gorochowik 23526e4f93 net: if: vlan: Implement packet priority to PCP conversion
This is actually the same as #7229 in which we missed this side of
conversion (only PCP to packet priority was implemented).

The conversion is actually the same both ways, thus it uses the map
added earlier.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-06-26 09:56:57 +03:00
Johan Hedberg b26ca13672 shell: Fix command completion logic
The original code (introduced by commit d5db35204a) looked like this
before the last rewrite/cleanup:

       if (default_module != -1) {
               return (str == NULL) ? dest : -1;
       }

However with the cleanup the logic seems to have gotten reversed.

Fixes #8501

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-22 15:09:18 -04:00
Jukka Rissanen 580596c30a net: if: Add TX timestamp callback support
Allow creation of TX timestamp thread which will collect TX timestamp
information from device drivers. If the callback is registered, then
it will pass that timestamp information to the relevant party for
further processing. This support will be used by gPTP code in
subsequent commits.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-22 12:31:32 -04:00
Johann Fischer c36e800e8e usb: remove all CONFIG_*_EP_ADDR options
Remove all CONFIG_*_EP_ADDR options but keep the default
values for it, as they are necessary to find ep_addr in
usb_ep_cfg_data associated with bEndpointAddress in
interface descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-22 12:30:55 -04:00
Vinayak Kariappa Chettimada b35ed7e79c Bluetooth: Fix central from failing to start encryption
This fixes a regression introduced in commit 6af5d1cd1f
("Bluetooth: Compress bt_keys struct").

Instead of passing a value zero as the random number, the
value at the RAM address zero was being used by the start
encryption function call. It is now fixed by consistently
using byte-array to store EDiv and Rand values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-22 18:03:43 +02:00
Paul Sokolovsky 5acb7fc9a9 subsys: console: Make CONSOLE_GETCHAR and *_GETLINE optional
It should be possible to make both these options off, and that
should be default, otherwise targets not supporting them yet, e.g.
native_posix, have build issues.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-20 15:59:12 -04:00
Paul Sokolovsky f6d8ab8289 subsys: console: Factor out fifo-based console input abstraction
Console subsystem is intended to be a layer between console drivers
and console clients, like e.g. shell. This change factors out code
from shell which dealed with individial console drivers and moves it
to console subsystem, under the name console_register_line_input().

To accommodate for this change, older console subsys Kconfig symbol
is changed from CONFIG_CONSOLE_PULL to CONFIG_CONSOLE_SUBSYS
(CONFIG_CONSOLE is already used by console drivers). This signifies
that console subsystem is intended to deal with all of console
aspects in Zephyr (existing and new), not just provide some "new"
functionality on top of raw console drivers, like it initially
started.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-20 15:59:12 -04:00
Andrei Emeltchenko c1724f65bf usb: bos: Add USB BOS descriptors API
Add API for USB BOS Descriptors.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Andrei Emeltchenko f07275e6e6 usb: trivial: Remove unneeded braces
Clean up the code

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Andrei Emeltchenko b25567eab8 usb: Allow to enable stack on native_posix arch
At the moment USB Device stack is not possible to enable for
native_posix architecture since there is not USB controller.
The patch allows to enable stack making possible to use it in unit
tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-06-20 15:47:00 -04:00
Paul Sokolovsky 83b3f84d6f net: lib: app: Convert CMakeLists.txt to avoid library
Due to the fact that cmake doesn't allow to build empty "library"
(which would be the case when neither CONFIG_NET_APP_SERVER nor
CONFIG_NET_APP_CLIENT is defined).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-20 17:10:39 +03:00
Paul Sokolovsky c60df13110 net: app: Split code for configuring network to a separate lib, "config"
net_app library consisted of 2 disjoint parts: a) library to
setup/configure networking on the application startup; b) library
to setup client and server connections.

As the configuration library is universally useful and is a generic
Zephyr networking component, split it out to a seperate top-level
networking library under net/lib/config/.

Fixes: #7658

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-20 17:10:39 +03:00
Franco Saworski e6a746ea6f net: ieee802154: fix csma-ca backoff
This patch changes the backoff factor to be random between zero and
2^be-1, as defined by the standard.

The previous implementation generated either a power-of-two number or
zero for bo_n, because it only overlaps a single bit with the random
number. The overlap is very rare, as in random, and results in the
backoff time being zero most of the time.

Signed-off-by: Franco Saworski <franco.saworski@blik.io>
2018-06-19 20:26:15 -04:00
Sathish Kuttan a3095087aa subsys: usb: Make HID payload size configurable
The payload size was hardcoded to 64.
This commit adds a configuration option to choose > 64 bytes
when the device allows larger packets.
A configuration option USB_HID_MAX_PAYLOAD_SIZE is added in
subsys/usb/class/hid/Kconfig
The default value is set to 64

Signed-off-by: Sathish Kuttan <sathish.k.kuttan@intel.com>
2018-06-19 20:16:18 -04:00
Ruslan Mstoi 1da4ddba86 net: pkt: Fix comment typo in word tailroom
Fix comment typo in word tailroom

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-06-18 09:17:47 -04:00
Alberto Escolar Piedras 15ae4fa314 Bluetooth: controller: Use nRFx functions for PPI reg with sideef
In the BLE controller, radio HAL, for the PPI registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras c97645c884 Bluetooth: controller: Use nRFx functions for TIMER reg w sideeffects
In the BLE controller, radio HAL (TIMER registers):
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 1c5bb49415 Bluetooth: controller: Use nRFx functions for CCM reg w sideeffects
In the BLE controller radio HAL, for the CCM registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.
(CCM part)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 88f0fbdc00 Bluetooth: controller: Use nRFx functions for RTC reg w sideeffects
In the Radio HAL, for the RADIO and RTC registers:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 5f146e491e Bluetooth: controller: Use SOC series macro instead of the board macro
In the BLE controller radio HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 1742972585 Bluetooth: controller: Use SOC series macro instead of board macro
In the BLE controller ECB HAL:
To avoid confusion, use SOC series macro instead of board macro.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras 347f32621a Bluetooth: controller: Use nRFx functions for ECB reg with sideeffect
In the BLE HAL for the ECB:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Alberto Escolar Piedras bc606d2220 Bluetooth: controller: Use nRFx functions for RTC reg with sideeffects
In the ble hal for the RTC:
To enable for easier testing, replace direct use of registers
from Nordic's nrfx MDK with accesses via its HAL inlined functions
Cleaned up old test hooks.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-06-18 11:09:19 +02:00
Michael Scott 7934e24983 net: lwm2m: retry registration update 6 seconds before expiration
When the priority of the LwM2M engine was lowered, it causes an
occasional registration update to fall outside of the registration
lifetime.  This shows up as the following error:
Failed with code 4.4. Retrying registration

Let's try and retry a bit earlier to account for the priority
change.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-06-18 10:51:15 +03:00
Johann Fischer 085a8b75c5 usb: hid: fix write to interrupt IN endpoint
A HID application can no longer write to the default
interrupt IN endpoint because the addresses are assigned
dynamically. Add hid_int_ep_write() function  and leave
it to the hid-core to call the usb_write() with the correct
endpoint address.

fixes: #8424

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-16 11:46:56 +02:00
Mariusz Skamra 48b7f236fa Bluetooth: Fix assertion condition in bt_gatt_discover
This fixes invalid assert condition.

As stated in Bluetooth Core v5.0 Vol 3 Part F
3.4.4.1 Read By Type Request &&
3.4.4.9 Read by Group Type Request
"The starting handle shall be less than or equal to the
ending handle."

3.4.3.1 Find Information Request &&
3.4.3.3 Find By Type Value Request
"Only attributes with attribute handles between and
including the Starting Handle parameter and the Ending
Handle parameter that match the requested attribute type
and the attribute value that have sufficient permissions
to allow reading will be returned."

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-06-15 15:47:04 +02:00
Johann Fischer 32cac08e55 usb: class: adapt functions for new composite interface
Adapt functions for new composite interface.

Assign bInterfaceNumber and similar variables of a Interface
default values, these should be valid values for non-composite
configuration. For the case of the composite configuration,
these variables must be set by the interface configuration
function (interface_config) accordingly.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 1383dad8a7 subsys: usb: rework composite device support
This patch reworks composite device support. It allows the
functions to be modular and the user to combine its own
functions with the USB functions of the Zephyr OS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 1237549082 subsys: usb: configure Interface descriptor at runtime
Introduce function to configure interface descriptor at runtime.
It is simple to leave the corresponding function to configure the
interface descriptor and fix bInterfaceNumber and iInterface values,
for example.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer bf332d0004 subsys: usb: validate and update endpoint address
Add the routine to validate endpoint address and update the endpoint
descriptors and usb_ep_cfg_data at runtime.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 18b27b7f9d subsys: usb: fetch endpoint address from usb_ep_cfg_data
This patch changes all class functions so that the endpoint
address will be retrieved from the usb_ep_cfg_data at runtime.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 6807f3a826 subsys: usb: move descriptor parts to the class drivers
This patch moves the descriptor parts to related class
and function drivers and extends the usb_fix_descriptor
function so that the wTotalLength and bNumInterfaces
are corrected before enumeration.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 589dbc4cd8 subsys: usb: add function to find and fix USB descriptors
This patch introduces a function to find and correct all string
descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 0fca16443a subsys: usb: rework usb string descriptor fixup
This patch simplifies the handling of the string descriptors.
It introduces common macro for all string descriptors to
calculate the length of the bString.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Leandro Pereira c16bce7a6a samples, subsys, tests: Use ARRAY_SIZE() whenever possible
The ARRAY_SIZE() utility macro will actually test the parameter types,
and ensure that it is only called with arrays, and not arrays decayed
to pointers.

Changes were performed with a simple Coccinelle script.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-06-14 19:12:51 -04:00
Sebastian Bøe d62117e5b8 kconfig: Change how BT affects SYSTEM_WORKQUEUE_PRIORITY
Invalid configurations should be detected during configuration instead
of during compilation whenever possible.

This patch replaces a BUILD_ASSERT on CONFIG_SYSTEM_WORKQUEUE_PRIORITY
with what is intended to be an equivalent Kconfig restriction.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-14 16:49:50 -04:00
Vinayak Kariappa Chettimada 660c5c92c0 Bluetooth: controller: Remove include guards in internal files
Remove include guards in internal files; it is an agreed
convention to not have include guards in internal header
files in Bluetooth subsystem.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-14 17:11:42 +02:00
Aurelien Jarno a55c72d35f subsys: usb/class/hid: make interrupt endpoint size configurable
The Kconfig option HID_INTERRUPT_EP_MPS does not have a prompt entry,
so it is not configurable in practice. Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-13 21:07:09 -04:00
Johan Hedberg b20aff2f80 Bluetooth: Introduce HCI driver quirks
Introduce a quirks field to the HCI driver struct, which can be used
to create exceptions in host behavior for non-standard or unusual
controller behavior. An initial quirk is added to prevent the host
from sending the HCI_Reset command (in which case the controller is
responsible for performing the reset).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Johan Hedberg b1b1017178 Bluetooth: Export HCI command APIs through public hci.h header file
This is the simplest & cleanest way to make these APIs available for
drivers. We already have a public hci.h header file, so using it seems
most natural.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-13 21:04:27 +02:00
Ulf Magnusson c0e0d6131d net: rpl: Fix malformed Kconfig default
'default false' should have been 'default n', though they happen to have
the same effect here, due to undefined Kconfig symbols ('false')
evaluating to 'n' in a boolean sense.

Kconfig bool symbols implicitly default to 'n', so remove the default
rather than fixing it.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-06-13 13:35:56 -04:00
Sebastian Bøe f8dc4b6b50 net: bluetooth: Enforce the minimum user_data size at Kconfig
Invalid configurations should be detected during configuration instead
of during compilation whenever possible.

This patch replaces a BUILD_ASSERT on CONFIG_NET_BUF_USER_DATA_SIZE
with what is intended to be an equivalent Kconfig restriction.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-13 15:13:18 +02:00
Paul Sokolovsky 268c0e3310 net: tcp: Add MSS option on sending SYN request
Currently, we add TCP options only to SYN+ACK reply to peer's SYN
(i.e. passive open). For consistency, add them also when we send
SYN ourselves (active open). In both cases, we add just MSS option
currently.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-13 08:45:54 -04:00
Paul Sokolovsky e62972bb8e net: ethernet: net_eth_fill_header: Remove superfluous "frag" param
Ethernet header is always filled in the first fragment of a packet,
so passing it as a separate function paramter is supefluous.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-13 08:44:51 -04:00
Paul Sokolovsky 699023a987 net: ethernet: Fix asserts in net_eth_fill_header()
There's an apparent typo in testing net_buf headroom. Also, after
adding VLAN header support, its size should be used too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-13 08:44:51 -04:00
Jukka Rissanen 4ae875f9c1 net: arp: Timeout too long ARP request
There was no proper support to timeout an ARP requests which meant
that trying to resolve non-existent IP address left network packet
pending on ARP cache.

Fixes #8019

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-12 20:26:36 -04:00
Johan Hedberg e1b772479b Bluetooth: GATT: Fix notifications
Recent commits which made the choice of attribute to pass to
bt_gatt_notify() more flexible contained some unfortunate bugs in
handling the attributes and their values. In particular, both calls to
gatt_notify() would in certain circumstances pass the wrong handle
value. This should now be fixed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-12 17:54:59 +02:00
Jukka Rissanen 1a96f2b48f net: ethernet: Show interface for dropped RX packet
For debugging purposes it is useful to know which interface
the dropped packet was received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-12 08:16:55 -04:00
Ulf Magnusson ce6f9819e0 net: Remove redundant NETWORKING dependency
The 'source' of subsys/net/ip/Kconfig in subsys/net/Kconfig is already
within an 'if NETWORKING' block, so the NETWORKING dependency in
subsys/net/ip/Kconfig is redundant.

Remove the redundant dependency.

This gets rid of a bunch of 'NETWORKING && NETWORKING' dependencies in
the auto-generated Kconfig docs.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-06-12 08:13:11 -04:00
Vinayak Kariappa Chettimada 362a6b34c7 Bluetooth: controller: Fix to use max. tx power in DTM test mode
According to the Bluetooth Specification v5.0, Direct Test
Mode shall use maximum Tx power.

Fixed by adding nRF5x Radio HAL interfaces to get supported
maximum Tx power for SoC selected, and DTM testing sets the
Radio peripheral to use maximum Tx power.

Fixes #7243

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-12 13:22:10 +02:00
Paul Sokolovsky c524ff6b8c subsys: console: getchar: Use consistent var names for RX path
Initially, there was support only for buffered input, and adhoc var
names used. Later, buffered output support was added, with variables
consistently using "tx_" prefix. Now, rename the original RX path
to use symmetric "rx_" prefix.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-11 17:41:44 -04:00
Vinayak Kariappa Chettimada dc95e1ba05 Bluetooth: controller: Add Tx Power Kconfig option
Add support for changing the default Tx Power value using
Kconfig option.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:40:00 -04:00
Robert Lubos d494398940 net: stats: handle_na_input: unref packet after stats are updated
Because per-interface statistics rely on interface pointer stored in a
net_pkt, it should not be unreferenced before stats are updated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-06-11 17:33:17 -04:00
Robert Lubos 3cf1b07d5a net: stats: do not use deallocated packet pointer
Functions for per-interface statistics collection used a pointer to a
packet that could've been deallocated in the net_conn callback function.
In result, application could crash when interface related to the packet
was referenced. To fix that, packet interface is stored earlier, so it
can be used instead for statistics collection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-06-11 17:33:17 -04:00
Johann Fischer 1ce6a6eaa8 subsys: usb: update bcdUSB to 2.00
Update bcdUSB to 2.00

resolves #7570

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-11 17:31:15 -04:00
Vinayak Kariappa Chettimada edb2ad11f0 Bluetooth: controller: Remove redundant include of cmsis.h
Remove the redundant include of cmsis.h as soc.h already
includes it as necessary.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-06-11 17:30:29 -04:00
Paul Sokolovsky 4dd61f8897 net: tcp: Process zero window probes when our recv_wnd == 0
The IP stack drops any TCP segment which doesn't fit into our
receive window. However, we still must accept Zero Window Probe
segments, which are segments, usually with data length of 1, which
a peer sends to us after we stayed with zero window for some time.
In this case, we need to repeat an ACK with the old ack number.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-11 17:30:04 -04:00
Loic Poulain 452cb61844 usb: bluetooth: Use transfer API for ACL packets
Use transfer API for ACL out transfers. No extra buffer is requested,
directly use the net buf and update its len on transfer completion.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Loic Poulain 00a6b4c5ae usb: bluetooth: Fix assert due to unreserved headroom
Bluetooth net buffers have 1-byte reserve, which can be used by HCI bus
driver (uart, spi...) to set packet type (H4).
This fixes assert when building hci_usb with CONFIG_NET_BUF_SIMPLE_LOG.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Loic Poulain 51fecf80d9 usb: bluetooth: Add TX thread
Calling bt_send from IRQ context is not safe, at least in HCI SPI case.
In the same way as hci_core, create a thread for TX.
This fixes hci_usb sample for 96b_carbon board.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Jukka Rissanen 5cda31c8f1 net: dhcpv4: Detect network interface on/off events
Catch interface up/down events so that we can renew the
address if interface goes down and is then restored.

Fixes #7553

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Jukka Rissanen fa8824184d net: dhcpv4: Fix IPv4 and UDP checksum calculation
Make sure we calculate the IPv4 and UDP checksum only when
needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Jukka Rissanen b93d29df56 net: ethernet: Add carrier detection to L2
Add net_eth_carrier_on() and net_eth_carrier_off() functions that
can be called by ethernet device driver when it detects that carrier
is lost or found.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Paul Sokolovsky eb3ecf6e66 net: shell: conn: Always show TCP state
It's rather confusing to not see current TCP state in any way (it
makes distinguishing different TCP contexts very hard). And nobody
can know/remember that it's printed with CONFIG_NET_DEBUG_TCP
defined. So, just make it be printed always (initially I thought
about printing just numeric value if CONFIG_NET_DEBUG_TCP isn't
defined, but why, if we can print symbolic name easily).

Also, add a hint that defining CONFIG_NET_DEBUG_TCP will still
print even more info (like unacked pkt list) - similarly to
similar helpful hints we have in other parts of net shell.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-11 17:21:58 -04:00
Tomasz Bursztyka e1c1149957 net/pkt: Use IS_ENABLED instead of ifdef
It's a bit nicer that way.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 17:21:12 -04:00
Tomasz Bursztyka d4e0a6872e net/pkt: Simplify a tiny bit how TC priority is set
Let's set it by default when allocating net_pkt. A macro will avoid
ifdefs as well

CONFIG_NET_TX_DEFAULT_PRIORITY is always defined.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 17:21:12 -04:00
Tomasz Bursztyka a999d53a33 net/icmpv6: Removing duplicate checksum calculation
net_ipv6_finalize_raw() is already going to do that calculation.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 17:21:12 -04:00
Johan Hedberg 7d9896575b Bluetooth: Add HCI User Channel driver for native POSIX port
Introduce a custom HCI driver for the native POSIX port, which opens a
HCI User Channel socket to the Linux kernel to gain access to a local
Bluetooth controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-11 17:14:43 -04:00
Luiz Augusto von Dentz 68de9d5d66 Bluetooth: Use Characteristic attribute whenever possible
With updates to bt_gatt_notify and bt_gatt_indicate it is now possible
to pass the Characteristic attribute instead of its value which makes
the code able to verify if attribute properties are set correctly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz 679a0b395f Bluetooth: GATT: Allow Characterist to be used with bt_gatt_indicate
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_indicate as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Luiz Augusto von Dentz c3edc82fe7 Bluetooth: GATT: Allow Characterist to be used with bt_gatt_notify
Since BT_GATT_CHARACTERISTIC now expands to 2 attributes it may be
confusing to use bt_gatt_notify as that expects the Value attribute to
be given which is no longer visible, so this enables the user to use
the Characteristic attribute in addition to its value.

Fixes #8231

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-11 14:41:19 -04:00
Tomasz Bursztyka 97699537f3 net/arp: Clear cache per-iface when relevant
When disabling an ethernet interface, only its cache entries need to be
cleared up and not the whole cache. This is meaninful in case there is
2+ ethernet interface instances.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 14:35:29 -04:00
Tomasz Bursztyka 06fbcb1cd0 net/arp: Removing header filling duplicate
Header is filled in either in prepare_arp() or at the end of the
function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 14:35:29 -04:00
Tomasz Bursztyka 9e0cfaf0a7 net/arp: There is no need to fill in the header in all frags
Only the first one requires it. Same issue as already fixed in ethernet
side.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 14:35:29 -04:00
Tomasz Bursztyka c0109fd690 net/ethernet: There is no need to fill in the header in all frags
Only the first one requires it. Actually drivers know that already and
handle the frags list correctly.

In case ethernet has to run along with 15.4 on the same SoC, this will
optimize things quite a bit knowing that biggest ethernet frame will be
forcefully split in as many 128 bytes frags as necessary.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 14:35:29 -04:00
Michael Scott ed3ea06f88 net: lwm2m: fix observer attribute update logic
A typo in update_attrs() was setting every observer to a PMIN of 0.
This meant we could send observer data as often as the process was
called.  This is out of spec as the default minimum is 10 seconds.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-06-07 12:27:46 -05:00
Jukka Rissanen e72dcf0290 net: ipv4: Set TTL in net_pkt according to IPv4 header
The time-to-live value in net_pkt was not updated according to
received IPv4 header.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-07 12:00:17 -05:00
Jukka Rissanen d9a14f5a27 net: ipv6: Set hop limit in net_pkt according to IPv6 header
The hop limit value in net_pkt was not updated according to
received IPv6 header.

Fixes #8182

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-07 11:59:17 -05:00
Michael Scott a957107d50 net: lwm2m: lower priority of engine thread
The LwM2M engine thread is used for various periodic triggers.
None of these are in a critical path that requires super sensitive
timing and the current K_PRIO_COOP(7) setting was causing the
Bluetooth RX thread to have to wait too long for certain actions
to complete.

Let's lower the priority to -1 (effectively) to eliminate these
conflicts.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-06-07 11:51:51 -05:00
Daniele Biagetti bfdb6acaf6 subsys: settings: Fix file exist error.
Fix file exist error within settings_subsys_init in order to correctly
reload existing settings when CONFIG_SETTINGS_FS is enabled.

Signed-off-by: Daniele Biagetti <daniele.biagetti@cblelectronics.com>
2018-06-06 09:43:19 -04:00
Luiz Augusto von Dentz 1218648ed1 Bluetooth: ATT: Fix clearing context at disconnect
When att_disconnected is called a thread may be waiting for the tx_sem
but that is memset to 0, furthermore there exists a flag
ATT_DISCONNECTED to indicate the context is no longer valid so instead
move memset to bt_att_accept so it is cleared when it is about to be
reused.

Fixes #8083

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-06-06 09:38:37 -04:00
Johan Hedberg ed5fb3ff37 Bluetooth: Mesh: Fix (re)transmit interval handling
The adv_send() function was incorrectly decoding the 5-bit value (it
was using it directly as milliseconds), which effectively lead to the
code always picking the controller's minimum supported interval.

Fix this issue, but do it by simplifying the (re)transmission state
tracking so that the state is always stored in the original "packed"
8-bit value, where 5 bits are reserved for the interval, and 3 for the
count.

Fixes #7972

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-05 19:15:14 +02:00
Andrzej Puzdrowski 2cba701703 subsys: mgmt: Remove unnecessary comparison
In the function zephyr_smp_write_at the offset was checked
for negative values while it type is unsigned -
which cause static analyses issue.

Fixes #7737

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-06-05 08:06:09 -04:00
Paul Sokolovsky 955552210e net: shell: Correct help text for "mem" command
Before, it was copy-paste from "iface" command help.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-04 23:08:04 -04:00
Johan Hedberg ae829b269d Bluetooth: Fix unchecked settings value lengths
We should check for valid lengths, not just because flash may have
become corrupted, but also because this fixes coverity errors, such as
CID 186030.

Fixes #7739

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-04 17:05:07 -04:00
Andrzej Puzdrowski 6a138977cf susbys: disk: Fix misleading menuconfig prompts
DISK_ERASE_BLOCK_SIZE, DISK_VOLUME_SIZE was described in misleading
manner. This patch changes descriptions for both prompts to
appropriate.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-06-04 21:45:09 +02:00
qianfan Zhao c84b37b086 net: icmpv4: fix incorrect IP header checksum
IPv4 header's checksum was set when 'setup_ipv4_header', but in that
times IPv4 header's source ip and dest ip address haven't setted. So
it may be set an incorrect checksum.

Fixes: #7989

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-31 14:06:38 -04:00
Michael Scott dcb0ac1256 net: tc: dont yield during net_rc tx/rx workq init
We init the net_tc tx/rx work queues during net_init() with a
call to init_rx_queues().  The L2/L3 and networking drivers have been
setup at this point.  If we yield the current thread, we risk
a call to net_recv_data() which calls net_queue_rx() which calls
net_tc_submit_to_rx_queue() on an RX work queue which hasn't been
setup yet.

This manifests as a boot hang under seemingly random circumstances.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-30 20:26:25 -04:00
Andrei Emeltchenko 73009d05ce usb: cdc_acm: Set bInterfaceProtocol to No Protocol (0)
Do not set protocol in interface descriptor. Although this field has
been ignored by major OSs during the last decades, this creates a big
deal of problems with ModemManager sending unexpected AT commands when
plugging in a dev board.

Fixes: #6646

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-30 09:05:40 -04:00
Tomasz Bursztyka 201a1b402a net/ieee802154: Security session must be initialized with a valid key
Security layer was tested only against CC2520, which does not mandate to
begin the session with a valid key. However, the crypto API tells it
must do so. And indeed, starting a session on mtls shim crypto device
will fail due to missing key. Thus moving the relevant code where it
should.

Reported-by: Johann Fischer <j.fischer@phytec.de>

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-05-29 16:23:18 -04:00
Jukka Rissanen 48ac4a372c net: Convert raw timeout values to use K_MSEC() macro
This one converts "raw" timeout value to use K_MSEC() macro
in order to make clear how long the timeout is.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-28 17:20:11 -04:00
Jukka Rissanen 8670e8a1f7 net: Convert MSEC_PER_SEC to K_SECONDS()
Use of K_SECONDS() macro is more intuitive so use that instead of
plain MSEC_PER_SEC define.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-28 17:20:11 -04:00
Jukka Rissanen 8f5929ddf0 net: Too long timeout for k_sleep
Convert couple of MSEC() calls to K_MSEC() as the timeouts
when using MSEC() are just too long.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-28 17:20:11 -04:00
Johann Fischer cb0dd0cc93 usb: function_eem: fix eem_read_cb
This patch prevents eem_read_cb from trying to allocate a lot of memory.

It may happen that EEM payload size is zero, the eem_read_cb then tries
to allocate a buffer which is 0xfffc bytes large and luckily blocks.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-28 12:47:32 -04:00
Ramakrishna Pallala ae2f419b56 subsys: disk: Fix log level issues
Fix SYS_LOG_DISK_LEVEL Kconfig message.

Fix SYS_LOG_DBG compilation issues.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-28 08:47:05 -04:00
Andrei Emeltchenko fc8bcb9a1b usb: netusb: Refactor function's status callbacks
Refactor functions status callbacks for netusb ECM, EEM and RNDIS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 7a6f1c9884 usb: netusb: Implement status callback for RNDIS
Implement status callback

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 1d5692a7b6 usb: netusb: Implement status callback for EEM
Implement status callback.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 851195bfe3 usb: netusb: Implement status callback for ECM
Implement status callback.

Fixes: #7364

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 3497791372 usb: netusb: Use function - defined status callbacks
Allow functions to define status callbacks

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Andrei Emeltchenko 5135a73391 usb: netusb: Add subsys/usb to include list
This helps to source files without ../../ etc paths.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-26 08:27:16 -04:00
Aurelien Jarno 4089602f3a subsys: fs/nvs: fix _nvs_sector_is_used
_nvs_sector_is_used() never uses the offset argument. As a consequence,
it only check the first sector of the flash. Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 131c4a4f74 subsys: fs/nvs: do not assume the flash is mapped at address 0
The two functions that compute the crc16 when writing (nvs_append_close)
and when reading (nvs_check_crc) currently assume that the flash is
also mapped in read mode at address 0. This is not true on all SoCs, and
even less on an SPI flash.

Fix this by adding a new nvs_compute_crc() function which compute the
CRC16 of an entry using the flash using nvs_flash_read, in blocks of
write_block_size. This might not be the optimal size, but it keeps the
stack usage small.

Use this function in both nvs_append_close() and nvs_check_crc() instead
of accessing the flash from address 0.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 4795b79e9d subsys: fs/nvs: kill a warning
GCC complains that last_entry.len and last_entry.data_addr might be
uninitialized in _nvs_gc. Fix that.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 14aae1a189 subsys: fs/nvs: remove explicit padding from structures
Now that the flash writes are padded up to the write block size, there
is no need to have explicit padding fields in the _nvs_sector_hdr and
_nvs_data_slt structure. This allow to save space when the write block
size equals to 1 or 2

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 154e6ea72f subsys: fs/nvs: never write more than the source buffer
Writing more than the source buffer means that some random data,
possibly coming from the stack, ends-up in the flash. This could be
a security issue.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 7acd339974 subsys: fs/nvs: never read more than the destination buffer
Reading more than the destination buffer means that data is overwritten
possibly on the stack. This causes unpredictable behaviours like
crashes.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Aurelien Jarno 83ac3f8bd5 subsys: fs/nvs: explicitly pad flash writes up to the write block size
Some SoCs do not allow shorter writes than the write block size, usually
when they have ECC memory. This patch first write all data in multiple
of the write block size and then do a last write with the data padded.
It uses 0xff as the padding byte to avoid wearing-out the flash.

nvs_append_close() is slightly modified to compute the crc16 that will
be put in the slot over the size defined in the header, to match the way
it is checked on read.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-26 08:26:40 -04:00
Michael Scott 4c58ffb5ab net: lwm2m: dont release reply for duplicate block transfer
During normal use, a CoAP packet can be resent due to network congestion
and other causes.  During block transfer the LwM2M client checks to make
sure the block received is the one we expect and if not generates a
"duplicate" warning.  When this happened, we were releasing the reply
handler and when the correct block was received the client would
generate a "No handler" error.

To avoid releasing the reply handler too early, let's set the coap_reply
"user_data" field to an error condition (1).  Then, once the reply
processing is complete we can check the user_data field to be sure that
it's ok to release the reply handler.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-25 17:19:34 -04:00
Carles Cufi a59f544fb4 bluetooth: controller: Handle non-priority events correctly
In certain cases the response to a command can come in the form of a
non-priority event. This is the case of LE Create Connection Cancel,
which generates a Command Complete and then an LE (Enh) Connection
Complete. Take this case (and other future ones) into account by calling
the correct Host recv function.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-25 17:25:41 +02:00
Kumar Gala b0e697cc43 subsys: usb: Remove undefined CONFIG_USB_DEVICE_HID_BOOTP
The Kconfig symbol CONFIG_USB_DEVICE_HID_BOOTP isn't defined anywhere,
so remove dead code associated with it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-25 08:04:36 -05:00
Johann Fischer c5cfb462f9 net: rpl: fix null pointer dereference
This patch fixes possible null pointer dereference in
net_stats_update_rpl_resets(...).

net_rpl_set_root_with_version(...) does not initialize instance->iface
and calls net_rpl_reset_dio_timer(...), which then calls
net_stats_update_rpl_resets(instance->iface).

fixes: #7862

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-25 09:03:34 -04:00
Johan Hedberg c4b0f1c5b4 Bluetooth: Mesh: Fix build error when LPN is not enabled
Some versions of gcc do not seem to compile out the inaccessible code
in this case and instead give the following error:

subsys/bluetooth/host/mesh/transport.c:419: undefined reference to
`bt_mesh_lpn_poll'

This happens at least when building samples/bluetooth/mesh for
native_posix on Fedora 28.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-25 10:53:46 +03:00
Carles Cufi 6f534e4551 drivers: entropy: nrf5: Implement standard ISR-specific call
Implement the new entropy_get_entropy_isr() function to allow the kernel
to collect entropy before the scheduler and kernel data structures are
ready. Switch to an nrf-specific version for high-performance
requirements in the BLE Link Layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-05-24 15:13:13 -07:00
Andrew Boie bc40f9340d debug: enable assertions for all tests
This keeps biting us; sanitycheck turns on assertions by
default for tests, but standalone builds, or builds done
for other test infrastructure do not. Put all builds in
the same state.

Specific tests (such as benchmarks) can override this with
CONFIG_FORCE_NO_ASSERT.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-05-24 15:12:56 -07:00
Jukka Rissanen 5ec569dfd2 net: Fix dependency to offload driver in Kconfig
The CONFIG_NET_DEFAULT_IF_OFFLOAD should depend on CONFIG_NET_OFFLOAD

Fixes #7797

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-24 08:03:32 -04:00
Kumar Gala 5013cca676 usb: rndis: Rename CONFIG_RNDIS_TX_BUF_* and CONFIG_RNDIS_CMD_BUF_*
Rename CONFIG_RNDIS_TX_BUF_* to CFG_RNDIS_TX_BUF_* and rename
CONFIG_RNDIS_CMD_BUF_* to CFG_RNDIS_CMD_BUF_*.  The CONFIG options where
not exposed in Kconfig so limit use of CONFIG_ to Kconfig only symbols.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 17:57:06 -04:00
Johan Hedberg 8d1f67c605 Bluetooth: Remove references to non-existing Kconfig symbols
Remove non-existent Kconfig symbol references. An additional (but
related) change is the removal of all persistent storage symbols from
the Arduino 101 Bluetooth shell app, since BT_STORAGE no longer
exists.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
Johan Hedberg 20a2b7a79d Bluetooth: Mesh: Fix reference to CONFIG_BT_MESH_FRIEND
The Kconfig symbols use BT_* and not BLUETOOTH_*.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-23 16:57:59 -04:00
David B. Kinder 44383a394b doc: fix misspellings in Kconfig files
Found some misspellings missed during normal reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-05-23 16:57:20 -04:00
Ramakrishna Pallala 2f074783c4 subsys: disk: Fix NULL pointer checks for disk operations
Fix NULL pointerer checks for disk supported operatins.

CID: 186027
CID: 186029
CID: 186045
CID: 186056
CID: 186063

Fixes Issues #7742 #7740 #7726 #7718 #7712

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-23 13:14:17 -04:00
Leandro Pereira fcc56e315f subsys: random: xoroshiro128: Use SYS_INIT hook to initialize properly
Not only removes a branch during normal operation, but also ensures
that, by initializing at the PRE_KERNEL_2 stage, and granting
privileges to all threads to the semaphore, this code will work in
early boot situations and in user mode.

This assumes that entropy drivers will all initialize during
PRE_KERNEL_1 stage.  All in-tree drivers do that.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-22 15:59:25 -07:00
Joakim Andersson 81b964b619 doc: Update description of BT_RECV_IS_RX_THREAD.
Clarify why this option is needed and which restrictions it has if
disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-05-22 13:30:45 -04:00
Jukka Rissanen 6180b904af net: Too long timeout was passed to k_sleep
The code was using MSEC() macro in few places instead of more
proper K_MSEC(). The MSEC() takes seconds as a parameter and
K_MSEC() takes milliseconds.

Fixes #7657

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-22 08:55:27 -04:00
Ravi kumar Veeramally 6586dba334 net: coap: Fix CoAP observer helper function
sin6_scope_id is not set anywhere and not used. Probably left over
from old ZOAP library. Just address, port and family type are enough
to find registered CoAP observer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-05-22 08:54:54 -04:00
Daniel Egger b1e06f2b3b net: lwm2m: remove silent fail for bad endpoint data in rd_client
The next error check is much more suitable to handle the error due to
the error message which lets the user know that something went wrong.

Fixes #7661.

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-05-21 22:50:12 -04:00
Ruslan Mstoi 4dd5867a79 net: conn: Fix is_invalid_packet
In switch statement break statement was missing causing IPv4 part to
execute even if the packet is IPv6. Also logical negation is wrong in
this context.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-05-21 22:49:19 -04:00
Ulf Magnusson aa26289458 kconfig: Get rid of leading/trailing whitespace in prompts
Leading/trailing whitespace in prompts requires ugly workarounds in
genrest.py, as e.g. *prompt * is invalid RST. strip() all prompts in
Kconfiglib and get rid of the genrest.py workarounds. Add a warning too.

The Kconfiglib update has some unrelated cleanups and fixes (that won't
affect Zephyr).

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-05-19 09:26:39 +03:00
Andy Ross ca9a98e6e2 samples/subsys/console: Remove unused tx_sem semaphore
This was declared but unused.  And recent toolchains have apparently
started warning on it leading to sanitycheck failures.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-05-19 07:00:55 +03:00
Florian Vaussard 3a6944d81f net: icmpv6: replace NET_ASSERT with NET_ERR
NET_ASSERT is useless here, as we already know that an error happened.
Use NET_ERR in order to print a more informative message.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-05-18 21:18:10 +03:00
Florian Vaussard 38866179a5 net: icmpv6: Fix error condition
When calling net_frag_read(), frag == NULL is an error only if pos is
not zero. It is thus incorrect to throw an error only if !frag, as
pos must also be checked to be not zero.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-05-18 21:18:10 +03:00
Robert Lubos 5f534dc6de net: openthread: Add function for getting current radio channel
Current implementation hardcoded channel in received frame structure.
With this change channel can be retrieved from a OpenThread platform,
and put in the frame. In result procedures like Discovery can be
executed correctly. Change was tested with OpenThread Border Router.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-05-18 15:09:53 +03:00
Robert Lubos c0af4de7b3 net: openthread: Bump OpenThread commit to db4759cc
This commit contains bugfix for Joiner eui-64 handling and setting radio
in correct mode after calling thread stop.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-05-18 15:09:53 +03:00
Jukka Rissanen 3c09bee921 net: app: server: Fix compile error if TCP is disabled
There was a compile error if TCP was disabled in net-app server.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-18 14:06:33 +03:00
Johan Hedberg df4220b213 Bluetooth: L2CAP: Add support for dynamically allocated PSM values
The Bluetooth core specification splits the valid LE L2CAP PSM range
into two subranges:

 - Standard, SIG-assigned fixed PSM values in the range 0x0001-0x007f
 - Dynamic, allocated at runtime in the range 0x0080-0x00ff

Previously the bt_l2cap_server_register() API was assuming that the
app would always decide the PSM, which effectively made it impossible
to have collision-free dynamic PSMs. This patch extends the
implementation so that if server->psm is 0, then the stack will look
for a free PSM from the dynamic range and take it into use.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:58 +03:00
Johan Hedberg 20ea1b86b9 Bluetooth: Mesh: Remove redundant ivu_unknown variable
Instead of having an ivu_unknown variable to track when we can ignore
the 96-hour minimum duration requirement, simply set the duration to
the minimum (96 hours) in the places where ivu_unknown would have been
1.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-18 12:39:41 +03:00
Ruslan Mstoi 68ef8f06a5 net: conn: Drop invalid packet
If a packet with source IP address and port same as the address of echo
server is received, it causes echo server to recursively send the packet
to itself, resulting in a crash and memory depletion. This commit fixes
the crash by dropping the packet.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-05-18 11:24:14 +03:00
Michael Scott 198b358638 net: lwm2m: simplify registration client
When designing the registration client for LwM2M, I understood
that the LwM2M Technical Specification allows for a multi-server
connection setup where the client makes several connections
to various LwM2M servers and allows each of them to manage
various aspects of the LwM2M client based on Access Controls.

However, the way I implemented it was not well thought out and
as we look forward to adding Bootstrap support, it needs a
do over.

Let's remove all of the code dedicated to handling multiple LwM2M
client connections.  This will simplify and reduce the code size
of the registration client considerably.

Later, once Bootstrap support has been added, we can implement
multi-server connections in a cleaner manner.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Michael Scott a58781f504 net: lwm2m: add LWM2M_FIRMWARE_UPDATE_PULL_LOCAL_PORT setting
This allows a user to customize the port used for downloading
firmware via the pull method of the LwM2M client.  It's default
value of 0 will select a random port during initialization.

NOTE: If set, this value should not be the same port as the
LWM2M_LOCAL_PORT setting.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Michael Scott 21fdf536ba net: lwm2m: default LWM2M_LOCAL_PORT to 0 (random)
Due to a bug where LWM2M_LOCAL_PORT was not being honored, all
outgoing traffic from the LwM2M client was coming from a random
port determined during initialization.

Now that this bug bas been fixed, let's default the client to the
behavior that most users are expecting, and let new users customize
the outgoing port if needed (which should be rarely).

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Michael Scott a021034327 net: lwm2m: honor CONFIG_LWM2M_LOCAL_PORT when starting client
Currently, CONFIG_LWM2M_LOCAL_PORT is never used when setting up
the LwM2M client.  Let's set the port of the local address using
CONFIG_LWM2M_LOCAL_PORT, so that the client can bind to it.

NOTE: A setting of 0 will use a random port.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Michael Scott 9cbe86f832 net: app: client: handle client_addr port in net_app_init_client()
Currently, the client_addr parameter is only used to check the
sa_family at various points during the init process.  Both the
IP address and the port are ignored.  Let's set the local client's
port based on the port value of the passed in client_addr if one
is supplied.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Michael Scott cc8fab8ddb net: app: client: fix local port byte-order in bind_local()
The port parameter passed to _net_app_set_local_addr() is converted
from host byte-order to network byte-order.  Here we are passing
a port value which has already been translated to network byte-order.

Let's translate the local port to host byte-order when passing it
to _net_app_set_local_addr() to fix this issue.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-18 09:28:28 +03:00
Andy Ross ccf3bf7ed3 kernel: Fix sloppy wait queue API
There were multiple spots where code was using the _wait_q_t
abstraction as a synonym for a dlist and doing direct list management
on them with the dlist APIs.  Refactor _wait_q_t into a proper opaque
struct (not a typedef for sys_dlist_t) and write a simple wrapper API
for the existing usages.  Now replacement of wait_q with a different
data structure is much cleaner.

Note that there were some SYS_DLIST_FOR_EACH_SAFE loops in mailbox.c
that got replaced by the normal/non-safe macro.  While these loops do
mutate the list in the code body, they always do an early return in
those circumstances instead of returning into the macro'd for() loop,
so the _SAFE usage was needless.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-05-18 01:48:48 +03:00
Johan Hedberg 2b73c97d68 Bluetooth: Mesh: Fix IV Update duration tracking
When the IV Update state enters Normal operation or IV Update in
Progress, we need to keep track of how many hours has passed in the
state, since the specification requires us to remain in the state at
least for 96 hours (Update in Progress has an additional upper limit
of 144 hours).

In order to fulfil the above requirement, even if the node might be
powered off once in a while, we need to store persistently how many
hours the node has been in the state. This doesn't necessarily need to
happen every hour (thanks to the flexible duration range). The exact
cadence will depend a lot on the ways that the node will be used and
what kind of power source it has.

Since there is no single optimal answer, this patch adds a new
configuration option, which allows specifying a divider, i.e. how many
intervals the 96 hour minimum gets split into. After each interval the
duration that the node has been in the current state gets stored to
flash. E.g. the default value of 4 means that the state is saved every
24 hours (96 / 4).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-17 17:30:03 +03:00
Tomasz Bursztyka 49bd1e9c6f ieee802154: Add support for filtering source short/ieee addresses
L2 could take advantage of such hardware capability, when supported by
the device. This is also required for OpenThread.

Fixes #5714

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-05-17 16:18:53 +03:00
Johan Hedberg 72050f46bc settings: Make it safe to call settings_subsys_init() multiple times
The settings_init() API was protected against multiple calls, but the
only function that calls it, settings_subsys_init(), was not. Add the
protection to the higher-level function as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-17 12:17:30 +02:00
Johan Hedberg cfb34d2b80 Bluetooth: Mesh: shell: Add persistent storage support
Add persistent storage support to the mesh shell module and app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:41:23 +03:00
Johan Hedberg a3c1b3dbcc Bluetooth: Mesh: Expose bt_mesh_is_provisioned() publicly
After introducing persistent storage, it's useful for an app to check
if the node has been provisioned or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-16 18:00:19 +03:00
Tomasz Gorochowik d6dfde36c4 net/ethernet: Fix mac address setting through ethernet mgmt
Attributes passed to memcpy were inverted so the mac was always getting
set to all zeroes.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-05-16 16:22:38 +03:00
Luiz Augusto von Dentz 05148610a4 mgmt: Fix smp_bt.c build
BT_GATT_CHARACTERISTIC has been changed to include the attribute value.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-16 15:42:38 +03:00
Paul Sokolovsky 89f57c225a net: tcp: Define single config option for TIME_WAIT delay
Previously, there was a boolean CONFIG_NET_TCP_TIME_WAIT setting
("master switch") and numeric CONFIG_NET_TCP_2MSL_TIME setting,
both named not ideally (there were both NET_TCP_TIME_WAIT and
CONFIG_NET_TCP_TIME_WAIT symbols in the source, with very different
meaning; "2MSL_TIME" was also a roundabout way to refer to
TIME_WAIT state time). In addition to that, some code was defining
adhoc, hardcoded duplicates for these settings.

CONFIG_NET_TCP_2MSL_TIME was also measured in seconds, giving
poor precision control for this resource-tying setting.

Instead, replace them all with the single
CONFIG_NET_TCP_TIME_WAIT_DELAY setting, measured in milliseconds.
The value of 0 means that TIME_WAIT state is skipped.

Fixes: #7459

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-05-16 11:03:49 +03:00
Michael Scott d07391d386 net: coap: clear more fields in coap_reply_clear()
We only clear 3 of the 6 member variables of the coap_reply structure
in coap_reply_clear().

Let's make sure to reset all of them.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:57:55 +03:00
Michael Scott bb98d8766a net: coap: add COAP_INIT_ACK_TIMEOUT_MS setting
The base CoAP retry setting is quite fast for network technologies
such as LTE-M and LoRa.  Let's add an option to delay retries
a bit longer depending on the need.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:57:55 +03:00
Michael Scott 07ec5567fc net: lwm2m: remove unused OBJ_FIELD_MULTI_DATA macro
The use-case for this macro was removed during optional resource
changes.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott b6774f0eea net: lwm2m: mark OPTIONAL resources for IPSO Temperature
Using IPSO Smart Object Guideline: "Smart Objects Starter Pack 1.0"
dated May 27, 2017, let's mark the OPTIONAL resources for an
IPSO Temperature object (Section 10. "IPSO Object: Temperature").

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott a5bdbc1751 net: lwm2m: mark OPTIONAL resources for IPSO Light Control
Using IPSO Smart Object Guideline: "Smart Objects Starter Pack 1.0"
dated May 27, 2017, let's mark the OPTIONAL resources for an
IPSO Light Control object (Section 16. "IPSO Object: Light Control")

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 7a1024e5c8 net: lwm2m: mark OPTIONAL resources for LwM2M Firmware Update
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Firmware Update object (Section E.6 "LwM2M Object: Firmware
Update")

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 1290139626 net: lwm2m: mark OPTIONAL resources for LwM2M Device
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Device object (Section E.4 "LwM2M Object: Device")

As a result, the Device object no longer configures the default
buffers for data storage of several optional resources.
The LwM2M client sample is also changed to to setup these read-only
buffers instead.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 9506b427b7 net: lwm2m: mark OPTIONAL resources for LwM2M Server
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Server object (Section E.1 "LwM2M Object: Server")

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 4fb16db26d net: lwm2m: mark OPTIONAL resources for LwM2M Security
Using OMA Technical Specification LwM2M Enabler 1.0.2 dated
Feb. 9, 2018, let's mark the OPTIONAL resources for an LwM2M
Security object (Section E.1 "LwM2M Object: Security")

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 0d67f6a78d net: lwm2m: introduce FLAG_OPTIONAL to denote optional resources
This patch introduces several changes to support OPTIONAL resources.

The primary indicator for this behavior is to assign FLAG_OPTIONAL
to the object field's permission flags.

These resources are not setup by the LwM2M object code.  They are
left up to the user-based code for initialization via the following
functions:
lwm2m_engine_set_res_data()
lwm2m_engine_get_res_data()

When assigning const-based data as a data buffer, user-based code can
also specify the following data flag: LWM2M_RES_DATA_FLAG_RO

The FLAG_OPTIONAL flag also affects the LwM2M engine in the following
ways:
- CREATE operations won't generate an error if optional resources are
  not included.
- Object instance READ operations won't complain about missing
  optional resources.
- In the future, BOOTSTRAP operations can have different handling
  based on optional resources.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 0db9af5a28 net: lwm2m: return error from lwm2m_engine_get_* functions
In the future, we will have optional resources that may or may
not be assigned a buffer for data storage.  When these resources
are queried we need to be able to return an error code if the
buffer isn't set.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Jukka Rissanen e50cacb356 net: app: Select proper source IPv4 address in client
Instead of selecting the first IPv4 address from the network
interface, use destination address to select the proper local IPv4
address.

Fixes #7500

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-16 10:47:01 +03:00
Michael Scott 8a21d3862b net: app: fix build warning in _net_app_ssl_mainloop()
Fix a build warning when compiling a net_app sample with
CONFIG_NET_APP_DTLS enabled by changing the print formatter from %zu
to %d.  It references the var hdr_len which is defined as an int:

In file included from include/net/net_core.h:78:0,
                 from subsys/net/lib/app/net_app.c:27:
subsys/net/lib/app/net_app.c: In function ‘_net_app_ssl_mainloop’:
include/logging/sys_log.h:96:20: warning: format ‘%zu’ expects
...
subsys/net/lib/app/net_app.c:2132:6: note: in expansion of macro
‘NET_ERR’
      NET_ERR("could not skip %zu bytes",
      ^~~~~~~

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 09:16:35 +03:00
Michael Scott 2c987298f2 net: tcp: expose some TCP helper functions
Similar to UDP, some drivers can make use of the following functions:
net_tcp_get_hdr()
net_tcp_set_hdr()

Let's expose them as <net/tcp.h> and change all internal references
to "tcp_internal.h".

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-15 18:07:47 +03:00
Ramakrishna Pallala 0fb9ea0304 subsys: bluetooth: Remove deprcated k_call_stacks_analyze API
Replace deprecated k_call_stacks_analyze() API with
k_thread_foreach() API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-15 13:43:00 +03:00
Ramakrishna Pallala 62bff616c2 subsys: shell: Remove deprcated k_call_stacks_analyze API
Replace deprecated k_call_stacks_analyze() API with
k_thread_foreach() API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-15 13:43:00 +03:00
Laczen JMS b1e45b413e subsys: fs: Add Non Volatile Storage (NVS) for zephyr
Zephyr supports fatfs, nffs and fcb as storage layer. fatfs and nffs
are less suited for application in memory restricted IC's. fcb has a
smaller footprint but has a complex api.

The proposed module is a module with a even smaller footprint compared
to fcb and a simple interface for reading and writing entries. The
module provides wear levelling of flash. This allows the module to be
used not only to store configuration settings but to store device state
(e.g. state of a light switch over reboots) of a zephyr device.

Fixes buffer overflow by introducing maximum read length in nvs_read()
and nvs_read_hist().

Fixes nvs_write() not to reflash the same data. Allows the user to do
call nvs_write() for all defined entries without worries about flash
wear.

Fixes garbage collection error where wrong data could be copied.

Add nvs_delete() to allow deleting a stored entry. A deleted entry will
not be copied to a new flash sector

Include flash wear information in the README.md documentation

0/25 Update module after reviewers remarks, added documentation to
nvs.h, removed README.md by nvs.rst in doc/subsystems folder

04/26 Update module after reviewers remarks, updated nvs.rst, added more
documentation to samples/subsys/nvs/src/main.c, updated doxygen info
in nvs.h (hope this time it works).

04/26 Update subsystems.rst to include nvs.restart

04/27 Updated nvs.c and nvs.h to avoid a possible flash deletion loop
when the file system is full.

04/29 Updated nvs_write to detect and ignore deletes of non-existing
items

05/06 Update NVS module to return standard error codes, removed low
level API, added configuration options. NVS now uses the board dts to
determine the flash storage location (FLASH_AREA_STORAGE_OFFSET).

05/06 Update nvs.rst. Updated intendation and added intermediate
variables in nvs.c to make the code easier to read.

05/06 Update nvs.rst.

05/07 Update nvs.rst

05/08 Changed the API to a more standard file system API.

05/08 Removed cnt_max from nvs_read() as it is not used.

05/08 Removed #ifdef(CONFIG_NVS_LOG) from nvs_priv.h, now the module can
be build with debugging off.

05/09 Removed configuration options for SECTOR_SIZE, SECTOR_COUNT and
MAX_ELEM_SIZE. It is now easy to support multiple NVS filesystems on
one or multiple devices. Changed logging to support newlib systems.
Thanks to Olivier Martin for reporting and proposed changes.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2018-05-15 10:29:16 +02:00
Johann Fischer 4b0b65c1b8 subsys: usb: check for invalid descriptor type request
Implementation of Get Descriptor Request should not return interface
or endpoint descriptors in a single request without configuration
descriptor, see USB Spec. Revision 2.0, 9.4.3 Get Descriptor

This patch fixes linux kernel usbtest subtest 7 and subtest 11 errors.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-14 17:24:52 -04:00
David Leach 9e09e2a1b7 OpenThread: Change SETTINGS_CONFIG_PAGE_SIZE to target specific value
- Changed define for SETTINGS_CONFIG_PAGE_SIZE from a hard coded value
  to reference build system generated FLASH_ERASE_BLOCK_SIZE. This value
  comes from 'erase-block-size' found in the dtsi file of devices.
- Modified nrf52840.dtsi to include definition for 'erase-block-size'

Fixes #7107

Signed-off-by: David Leach <david.leach@nxp.com>
2018-05-14 17:23:38 -04:00
qianfan Zhao 63ffbe9dcb usb: usb_device.c: rewrite if condition judgment
The 'if condition' in usb_handle_control_transfer is diffcult
to understand. So I rewrite another version.

Fixes #7340

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-14 17:23:21 -04:00
Luiz Augusto von Dentz 1b038f2941 Bluetooth: GATT: Make BT_GATT_CHARACTERISTIC declare its value
This ensures the every characteristic has a value attribute declared
with the same UUID since the old macro did not declare the value the
application would normally have to declare one itself using a different
UUID which is not allowed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-14 18:51:22 +03:00
Leandro Pereira 03f9f66496 net: websocket: Revise generation of Sec-WebSocket-Accept header
This removes some tricky math to calculate lengths and offsets,
ensuring that, when appending the WebSocket UUID to the handshake
key, the key_accept buffer won't overflow.

Coverity-ID: 183057
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-14 08:16:46 +03:00
Leandro Pereira e81b9043c5 net: websocket: Simplify building of responses
Rewrite prepare_reply() to reduce unnecessary string copies and calls
to net_pkt_append_all().  Also reduces some of the tricky string length
calculations.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-14 08:16:46 +03:00
Johan Hedberg 4f4afce5b0 Bluetooth: Remove unused rx_prio_queue
The rx_prio_queue k_fifo object has not been used for anything for a
really long time. The use for it was originally removed by the following
commit:

commit ad475d863a
Author: Szymon Janc <ext.szymon.janc@tieto.com>
Date:   Fri Apr 22 11:36:04 2016 +0200

    Bluetooth: Remove RX priority fiber

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-12 21:28:09 +03:00
Johan Hedberg 88dfd399f4 Bluetooth: Mesh: Remove sequence number from bt_mesh_provision()
The sequence number was acting as a stop-gap for missing persistent
storage. Now that we have the settings support in place it's no longer
needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg e240421496 Bluetooth: Mesh: Fix sequence number restoring
The logic for restoring the sequence number was flawed in that it
would not always cause an incremented sequence write upon the
transmission of the first packet. The reason the code didn't work is
that it assumed the stored value was a multiple of SEQ_STORE_RATE,
however since the sequence number is stored in a deferred fashion
that's not always true.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 53c85cf8bf Bluetooth: Mesh: Fix updating RPL for locally originated messages
We can implicitly trust locally originated messages, so there's no
need to burden the RPL with them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 59239032f6 Bluetooth: Mesh: Support for storing common configuration states
Add support for storing the remaining configuration server model
states (all of which are one byte values). The states are stored under
a single settings key bt/mesh/Cfg.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 44bd56877b Bluetooth: Mesh: Support for storing heartbeat publication persistently
Add support for storing the heartbeat publication persistently. The
information is only stored as "publish indefinitely" or as "periodic
publishing disabled" since we can't know for how long the node is
powered off. The information is stored under the settings key
bt/mesh/HBPub.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg efb68ca2da Bluetooth: Mesh: Support for storing model publication persistently
Add support for storing the model publication information
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/pub for SIG models and bt/mesh/v/<mod id>/pub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg dde2db5626 Bluetooth: Mesh: Support for storing model subscriptions persistently
Add support for storing the subscribed group addresses for each model
persistently. The addresses are stored under the settings key
bt/mesh/s/<mod id>/sub for SIG models and bt/mesh/v/<mod id>/sub for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg c3d5a0da62 Bluetooth: Mesh: Support for storing model bindings persistently
Add support for storing the bound App Keys for each model
persistently. The bindings are stored under the settings key
bt/mesh/s/<mod id>/bind for SIG models and bt/mesh/v/<mod id>/bind for
vendor models.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 8703ffad23 Bluetooth: Mesh: Redesign element and storage info for models
Keeping the model struct same sized, change the element pointer to two
indexes, and add a flags member that will be used to track pending
storage actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg b7078e1487 Bluetooth: Mesh: Perform storage clearing also through delayed work
In order not to have a Node Reset consume more stack than other
operations, also perform the related storage writes through the same
delayed work as all other storage updates.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg 9e2189c4c1 Bluetooth: Mesh: Introduce generic storage timer
Instead of having an RPL-specific storage timer, introduce a generic
one that'll eventually be used for all persistent storage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Johan Hedberg ace198142e Bluetooth: Mesh: Convert RPL storage timer into a generic one
To reduce stack consumption, and to avoid blocking the CPU during
network activity, prepare for a generic timer that can be used for
most (possibly all) mesh storage values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 16:44:43 +03:00
Michael Scott fc8d093592 net: lwm2m: lower default maximum observes from 20 to 10
In an effort to reduce the footprint of the LwM2M client, let's
lower the default # of observes handled by the client from 20 to
10.

This saves ~640 bytes of SRAM.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott ad13866ffd net: lwm2m: remove "used" from observe_node
Remove "used" member from observe_node structure and replace by
checking the ctx for non-NULL value.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott 6ef46e3f31 net: lwm2m: remove attr_list from obj, obj_inst and res_inst structs
The slist attr_list doesn't scale well when added to the LwM2M object,
object instance and resource instance structures.  The goal of a
robust LwM2M client is to let the user create MANY object instances
and these will have many resource instances each.  The amount of SRAM
taken up by the attr_lists will only increase over time, regardless
of the actual # of write attribute structures reserved via the
LWM2M_NUM_ATTR config setting.

Instead, let's remove the slist from these structures and add a
reference pointer to the lwm2m_attr structure.  We can use this
reference to create the one to many relationship between the objects,
object instances and resource instances for a much smaller amount of
code and SRAM resources.

The sacrifice for these savings will be a larger # of iterations when
looking up assigned write attributes and matching them to their
references.  However, due to the # of write attributes current being
handled, the # of iterations during this process is very manageable.

Example flash and SRAM savings when building for nrf52_blenano2:
Before patch:
Memory region         Used Size  Region Size  %age Used
           FLASH:      139532 B       512 KB     26.61%
            SRAM:       36576 B        64 KB     55.81%
        IDT_LIST:         148 B         2 KB      7.23%

After patch:
Memory region         Used Size  Region Size  %age Used
           FLASH:      139284 B       512 KB     26.57%
            SRAM:       36000 B        64 KB     54.93%
        IDT_LIST:         148 B         2 KB      7.23%

Summary: This patch saves ~248 bytes of flash and ~576 bytes of SRAM
for the typical configuration of LwM2M client in Zephyr.

NOTE: these values will vary by architecture.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott 573c1f777e net: lwm2m: improve return errors from update_attrs()
When any error is returned from update_attrs() in engine_add_observer()
an EINVAL is returned back to the caller.  Let's return whatever error
code was generated in update_attrs() instead.

Also, add handling where previously errors were ignored.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott bc7a5d3a6c net: lwm2m: relocate/memory align notification_attrs struct
For code clarity, let's move notification_attrs structure to the top
of lwm2m_engine.c.  While we're at it, we can re-order it's members
for memory alignment.

NOTE: This patch does not change the current flash or SRAM usage but
further additions to the notification_attrs structure could.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott 2027c10a9f net: lwm2m: remove "path" from object and resource instances
The path member of the object instance and resource instance structures
can easily be removed to save several bytes per instance over the entire
LwM2M subsystem.  So let's remove it.

Example savings when building for nrf52_blenano:
SRAM usage before patch: 37952 B
SRAM usage after patch: 36576 B

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Michael Scott bba1fe8ca9 net: lwm2m: Re-order lwm2m object structs for memory alignment
Let's optimize the order of the following structures to account for
memory alignment:
lwm2m_engine_obj
lwm2m_engine_res_inst
lwm2m_output_context
lwm2m_output_context

Tested building for nrf52_blenano hardware:
SRAM usage before patch: 38240 B
SRAM usage after patch: 37952 B

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-11 16:38:49 +03:00
Luiz Augusto von Dentz f6a687c0ce Bluetooth: GATT: Add support to persistent CCC config
This makes use of bt_settings to store CCC configs for bonded devices.

Fixes #7073

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-05-11 14:55:42 +03:00
Johan Hedberg c1c5f3d9a3 Bluetooth: Mesh: Expose destination address in bt_mesh_msg_ctx
There are valid use cases where the model layer must know the true
destination address. So far only the fact that it was one of the
addresses that the model subscribes to (its element's unicast
included) has been knowable.

Solve the issue by moving the destination address from the internal
net_rx context to the public bt_mesh_msg_ctx struct.

Fixes #7453

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-11 13:57:43 +03:00
Andrzej Puzdrowski cf06bc58a7 susbsys: settings: optimized fcb compression for deleted entry
During the compression an empty settings entry was
copied to the scratch sector form the oldest sector in case
lack of newer entry version in fcb storage.

This doesn't make sense as empty entry and lack of entry has
similar meaning.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-11 09:56:52 +02:00
qianfan Zhao 4e324e2171 usb: dfu: fix 'this area can not be overwritten'
fix issue #7336

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-10 16:26:38 -07:00
Paul Sokolovsky 8c2362a62d net: ip: context: Merge send_data() into the only caller
sendto() is one and only caller of send_data(), a function of handful
of lines, and yet send_data() is located a hundred lines away from
it. Such "spaghetti functions" complicate review, debugging, and
refactoring of the IP stack.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-05-10 16:23:53 -07:00
Leandro Pereira 7359c5b10b net: lwm2m: Do not use snprintk() to get debugging token
It's highly unlikely that snprintk() will return a negative value, but
that's a possibility that will make the `pos` variable be set to a
value outside the boundaries of the statically allocated `buf` array.

Also clamp writes to ensure that the statically allocated buffer won't
be overwritten with a large token length.

Fixes #7070.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-10 14:17:35 -07:00
Andy Gross abf77ef753 subsys: debug: Fix stack sentinel dependencies
This patch restricts the stack sentinel to only be allowed if the
USERSPACE configuration option is not set.  The stack sentinel feature
is redundant if used in conjunction with the USERSPACE, due to the
protection mechanisms in place for stacks.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-05-10 14:16:46 -07:00
Johan Hedberg 5b01cb1a46 Bluetooth: Introduce new bt_set_id_addr() API
There are certain use cases where the application needs to be able to
explicitly set a specific identity address. This was previously
possible using the bt_storage API, however now that it's gone another
solution is needed.

This patch adds a ne bt_set_id_addr() API which the application can
use to set a specific identity address before calling bt_enable().

Fixes #7434

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-10 22:39:04 +02:00
Johan Hedberg 31afd18977 Bluetooth: Mesh: Add support for clearing persistent network storage
Add support for clearing all data that's currently supported to be
persistently stored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg cc3830f8ed Bluetooth: Mesh: Fix resetting configuration model state
Instead of manually iterating all app keys and net keys, use the
bt_mesh_subnet_del() helper on all subnets. This will also clear any
app keys, and ensures that persistent storage is cleared as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg be7fe55b82 Bluetooth: Mesh: Introduce measures to avoid too frequent flash writes
Both the local sequence number as well as the Replay Protection List
(RPL) are states that may potentially change very often. In order not
to wear out the flash with these updates it makes sense to try to
avoid too frequent writes.

For the local sequence number a simple solution is not to write the
number on every increment. This patch introduces a new Kconfig option
to define after how many increments the sequence number gets written.
When the stack gets initialized it automatically adds the configured
number to the last stored one, thereby guaranteeing that the node
starts off with a number that's larger than the last used one.

The RPL is more problematic, since in principle it needs to be updated
every single time that we receive and process a message. Especially
security sentitive nodes will want this stored immediately to flash.
To give some use-case dependent flexibility, this patch introduces a
new Kconfig option to specify a timeout after which the RPL gets
written to flash.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 43c7ef3959 Bluetooth: Mesh: Move network startup operations to common function
These are needed both for bt_mesh_provision() as well as persistent
storage-based network creation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 3f30d12ce5 Bluetooth: Mesh: Remove redundant 'provisioned' variable
This variable is both redundant as well as problematic when it comes
to adding persistent-storage-based provisioning information, which
will not come through main.c or the bt_mesh_provision() API. Just
remove it and use bt_mesh.valid which serves the same purpose in
practice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 1c846651db Bluetooth: Mesh: Add storage APIs for core network values
Add APIs for storing core network values, such as Net and App Keys, IV
Index, Sequence number, RPL, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 9540f7d52d Bluetooth: Mesh: Add skeleton for persistent storage
Add initial skeleton for doing settings-based persistent storage for
the mesh network state. This patch only includes restoring some core
network state such as IV Index, Sequence number, Net Keys, App Keys
and the Replay Protection list. The remaining state, and actually
storing the state, is left for follow-up patches.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 2be496a03b Bluetooth: Mesh: Create dedicated helper for incrementing seq
The sequence number is incremented from several different places in
the stack. The way it was done was potentially race condition prone,
and was also problematic from the perspective of updating the
sequence number in persistent storage. Create a dedicated helper for
incrementing the sequence number (solves the race) which can in later
patches be used to add the persistent storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg ca10b6bc94 Bluetooth: Mesh: Remove redundant initialization
This for loop runs inside an "if (!sub)" branch, so explicitly setting
sub to NULL in the loop is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg f7e780a719 Bluetooth: Mesh: Increase visibility of net & app key helpers
These app key and net key (subnet) helpers will soon be needed to be
called from the persistent storage code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Johan Hedberg 10fabcd04f Bluetooth: Mesh: Move IV Update defines to net.h
These will soon be needed from other places, e.g. the persistent
storage support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-09 12:36:32 +03:00
Ramakrishna Pallala dd5449a77b subsys: fs: Add the support for multiple instances of fs
Add support for multiple instances of a file system by
making use of mount point as the disk volume name which
is used by the file system library while formatting or
mounting a disk.

Also moved out file system specific data structures from
public fs.h header and handled them in corresponding
file system interface files by introducing open files and
open directories concept which is already being used in
NFFS interface module. Now it is extended to FatFs as well.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-08 08:53:01 -04:00
Ramakrishna Pallala 2b5b7da9f3 subsys: disk: Add support for multiple disk interfaces
Add support for enabling multiple disk interfaces (Flash, RAM)
simultaneously in Zephyr by introducing a simple disk interface
framework where we can register multiple disks which would
interface with different storage devices. This would enable us
to have multiple instances of FATFS in Zephyr.

Add support for mass storage drive disk name which will be
used as an argument when calling the disk interface API's.

Enable multiple volumes support configuration in
ELM FAT library.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-08 08:53:01 -04:00
Ramakrishna Pallala b99ff6f9e1 subsys: fs: Extend storage_dev type beyond 'struct device'
Extend storage_dev type beyond 'struct device' by changing
the variable type to void pointer. This will be needed if we
have additional transactional layers b/w filesystem and the
actual backend device.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-08 08:53:01 -04:00
Johan Hedberg a29554360a Bluetooth: shell: Add settings support
Enable settings and increase the system workqueue size to deal with
the stack usage. This also makes it possible to test unpairing support
with the shell's 'clear' command.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg 6af5d1cd1f Bluetooth: Compress bt_keys struct
There's a bit of unnecessary space in the bt_keys struct. Re-design
some fields for a more compact format, which is particularly helpful
now that the struct gets stored as-is to flash through the settings
API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg f36ea83628 Bluetooth: Add support for persistent pairing keys storage
Integrate the bt_keys submodule with bt_settings. Add a new
bt_keys_store() API to write keys to flash, and extend the existing
bt_keys_clear() to remove the keys from flash.

Along with this, add some helpers for genrating settings key values
containing a bluetooth address, as well as for decoding them to get
the binary bt_addr_le_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg 470349c25a Bluetooth: settings: Add support for per-submodule handlers
Add a new linker section for a list of submodule settings handlers,
and iterate the list from the various settings callbacks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg d22b7c9f2d Bluetooth: Remove bt_storage API
The same functionality is now supported by the settings-based
solution, so remove bt_storage out of the way. There were stubs in
bt_storage to handle per-peer information (e.g. pairing keys) but this
was never actually implemented in full. The next step is to add this
support to the settings-based solution.

Leave the code for generating temporary IRK and identity address in
case BT_SETTINGS is not enabled. Also leave the code for using vendor
HCI to read the identity address, in which case the settings
implementation will not touch it.

Introduce a new bt_unpair() API to replace the removed
bt_storage_clear(), since the latter was actually doing more than just
storage management: it was also handling runtime storage of pairing
information. Later, the bt_unpair() implementation will be extended to
clear settings-based pairing storage.

There is one feature that the bt shell module looses: the ability to
give a specific identity address to the "init" command as a parameter.
We might look later in the future if this is really needed, and add a
separate API for this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Johan Hedberg b997a283f7 Bluetooth: Introduce skeleton for settings-based storage
Introduce a basic skeleton for peristent storage based on the settings
subsystem. Also enable support for this to the peripheral sample
application, so the new code gets exersized by CI. For now, the
implementation provides the same level support as the bt_storage API
ever did, i.e. for the identity address and the IRK.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-04 17:26:05 -04:00
Andrzej Puzdrowski f4dcb4593d subsys: fs: fcb: fix - crc write size not aligned
This is bug-fix for issue #7311
FCB: CRC write size in append_finish doesn't honor
flash min write size

This patch changes write size to the minimum supported
write size.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-04 17:25:29 -04:00
Andrzej Puzdrowski 4954fe06f2 subsys: fs: fix generic storage partition selection
FS_FLASH_MAP_STORAGE keyword enables the storage partition,
but it was depend on flash_map module which is unused by
NFFS. This patch makes it independent thanks
to it is possible to enable the storage partition
without flash_map module.

FS_FLASH_MAP_STORAGE was renamed to
CONFIG_FS_FLASH_STORAGE_PARTITION
as it is independent for flash_map.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-04 10:14:01 -04:00
Jukka Rissanen af8a0b1a5d net: tc: Proper packet priority to traffic class mapping
The IEEE 802.1Q chapter I.3 contains a proper network packet
priority to traffic class mapping. The original mapping was
clearly incorrect.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-04 11:06:43 +03:00
Michael Scott f038d35a98 net: lwm2m: remove unused LWM2M_PEER_PORT define
Code references CONFIG_LWM2M_PEER_PORT directly.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott b6ca731bdc net: lwm2m: remove unused CONFIG_LWM2M_BOOTSTRAP_PORT config
In the future, when bootstrap support is added, this config won't
be used.  Let's remove it.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott 42717a97f7 net: lwm2m: use BIT macro instead of LWM2M_OP_BIT
Now that the LWM2M_OP_* bits have been renumbered, we no longer need
a custom BIT() macro for the LwM2M code.  Let's remove it and use
BIT() instead.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott aa9a24aa25 net: lwm2m: remove LWM2M_OP_NONE flag and renumber the rest
Remove unused OP flag LWM2M_OP_NONE and renumber the existing flags
so that the operations used in object permissions land in the lowest
bits, and extended operations come later.

We may eventually add more permission / data flags, so let's try and
keep them inside a 1 byte boundary (flags with bits 0 to 7).

NOTE: LWM2M_OP_DELETE is currently not checked as a permission but
it may be in the future so it is in the lower bits.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott f80c52d668 net: lwm2m: introduce LWM2M_HAS_PERM macro
Standardize permission checks via the LWM2M_HAS_PERM macro.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott cf55b70b4c net: lwm2m: fix error code in read and write handlers
When a data pointer or data length is not set, the read and write
handlers should return ENOENT to generate the correct LwM2M error
code (COAP_RESPONSE_CODE_NOT_FOUND).

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott 44c9b79a49 net: lwm2m: clear lwm2m_obj_path obj in string_to_path
Before ever call of string_to_path(), the lwm2m_obj_path object
was being cleared via memset.  Let's move the memset into
string_to_path() to remove the duplicate code.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Michael Scott 3e16be3c3c net: lwm2m: refactor engine_get_obj to be more useful
Eliminate several similar code-blocks by replacing
engine_get_resource() with a more useful function called:
path_to_objs()

By supplying an lwm2m_obj_path object, it will find and set
the related values for:
struct lwm2m_engine_obj_inst
struct lwm2m_engine_obj_field
struct lwm2m_engine_res_inst

NOTE: NULLs can be supplied where the returned value is not
important.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-04 09:45:35 +03:00
Jukka Rissanen 128557896c net: if: Add functions to get correct IPv4 address
Add functions that will return correct source IPv4 address
according to given destination address. This is done similar
way as for IPv6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-03 12:47:52 +03:00
Johan Hedberg 8dd37fa79a Bluetooth: Mesh: Fix sequence number in Friend queue
The code was updating net_rx->seq to make sure sdu_recv() gets the
right sequence number (seq_auth for segmented messages), however later
net_rx->seq was also used for enqueuing to the Friend Queue, causing
the queued messages to have the wrong value.

To fix this, don't update net_rx->seq, rather pass an explicit
sequence number value to sdu_recv(), which is just net_rx->seq for
unsegmented messages, and seq_auth for segmented messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 10:01:00 +01:00
Johan Hedberg 6a71a69f8d Bluetooth: GATT: Fix CCC handling
The 'valid' member of struct bt_gatt_ccc_cfg was redundant, since
setting 'peer' to BT_ADDR_LE_ANY does the same job. What's worse, the
handling of 'valid' was also buggy in that some places looking for
valid CCC structs only matched the address, meaning it might yield a
positive match for invalid entries.

Fix these issues by removing the 'valid' struct member, and solely
using the 'peer' member to identify valid entries. Also simplify the
code by acknowledging that no CCC entry is essentially the same as the
value '0' written to CCC.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-03 09:53:16 +01:00
Ruslan Mstoi d171568582 net: icmpv6: Fix payload length and checksum
With fragmentation disabled echo server responds to packet fragment with
ICMPv6 message Type: "Parameter Problem (4)", Code: "unrecognized Next
Header type encountered (1)". If a fragment with payload length 15 is
received in response sent by echo server IPv6 payload length and ICMPv6
checksum are wrong. This patch solves the issue by correcting payload
length.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-05-02 18:12:58 +03:00
Johan Hedberg 6b11106440 Bluetooth: Mesh: Fix enabling Node Identity advertising
The bt_mesh_provision() call results in the provisioning link state
being cleared, so link.conn will become NULL. Add code to store the
information of whether PB-GATT was used and use this information after
the call instead of relying on link.conn anymore at this point.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-05-02 15:45:16 +01:00
Johann Fischer b2ca5ee5bc subsys: usb: rework USB DFU class driver
This patch moves USB DFU class driver to subsys/usb/class.

For the first the USB DFU class driver depends on DFU image
manager and partition layout and is limited to use as an
application for the bootloader. The driver fetches the
information about the flash, erase block size, write block
size and partitions offset from the DT now. The driver has
two interfaces associated with the two partitions "SLOT-0"
and "SLOT-1". The "SLOT-0" can only be read.

In the following work the class driver can be extended so
that it can be used from the bootloader and update a flash
region directly from the bootloader.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-04-30 17:42:40 -04:00
Sebastian Bøe f9b2da37b0 kconfig: Move CPLUSPLUS from root to "Compiler Options"
Enabling C++ support for the application has been inappropriately
located at the root of the Kconfig menu. The root should be kept as
clean possible to allow easy navigation.

This commit moves CONFIG_CPLUSPLUS into

~/"Build and Linker Features"/"Compiler Options".

This is a purely cosmetic change and does not change the
'visibility' (depends) of the Kconfig option.

Arguably, it would fit better into

~/"Build and Linker Features"/"Language Options"

but this entry does not exist.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-30 13:12:01 -04:00
Jukka Rissanen 2002a4e245 net: arp: Do not access NULL network packet
The code was accessing network pkt before the value of the pkt
was checked.

Coverity-CID: 185394

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-30 10:45:12 +03:00
Johan Hedberg d67009da08 subsys: settings: Fix Kconfig dependencies
If CONFIG_FLASH_PAGE_LAYOUT is not enabled, building the settings code
fails at the linking stage with the following error when FCB is the
backend.

libzephyr.a(settings_init.c.obj): In function `settings_init_fcb':
subsys/settings/src/settings_init.c:62: undefined reference to `flash_area_get_sectors'
collect2: error: ld returned 1 exit status

Also, the File System backend will currently only work with NFFS due
to fs_rename() missing from other File Systems (FAT in particular).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 16:24:31 +02:00
Jukka Rissanen a12138d45c net: hostname: Fix hostname buffer length
The buffer allocated for hostname was one byte too short.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-26 16:31:16 +03:00
Andrei Emeltchenko 222aa6009c netusb: rndis: Fix RNDIS always disabled state
Fix regression with RNDIS due to different USB configuration method.
RNDIS drivers in Windows never call Set Interface and netusb is always
disabled. Change to enable netusb upon USB Set Configuration.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-26 16:30:29 +03:00
Andrei Emeltchenko 185f2be681 netusb: rndis: Add more debugs
Add debug for enable / disable callbacks

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-26 16:30:29 +03:00
Johan Hedberg 9968cda453 fs: Convert NFFS partition to a generic one
The NFFS partition at the end of flash is also useful for any other
file system or even the Flash Circular Buffer (FCB). Rename the
partition from 'nffs_partition' to 'storage_partition' and make it
depend on a new hidden Kconfig entry which the relevant users will
select (such as NFFS and FCB).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 16:06:55 +05:30
Johan Hedberg aa67a4c55a Bluetooth: Mesh: Remove redundant branch for IV Update
The condition 'iv_index != bt_mesh.iv_index + 1' is already caught by
the earlier conditions in this branch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg c7c5829ba6 Bluetooth: Mesh: Fix missing IVU normal mode timer when provisioning
If the network is in IV Update In Progress state when we get
provisioned we should set a timer so we eventually transition back to
Normal mode (otherwise we may end up in IVU In Progress indefinitely).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Johan Hedberg 2a896cc6c4 Bluetooth: Mesh: Fix IV Update tests when duration is unknown
When we get provisioned we can't know how long the network has been in
the current IV Update state. Introduce a special value for
bt_mesh.last_update to indicate that we don't know the duration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 12:18:31 +03:00
Ruslan Mstoi bf185f58eb net: ipv6: Fix crash from double free of fragment
This commit fixes crash caused by double free from message sequence
fragmentation. When double free happens the call stack is:

0  reassembly_cancel
1  handle_fragment_hdr
2  net_ipv6_process_pkt
3  process_data
4  processing_data
5  net_rx
6  process_rx_packet
7  work_q_main
8  _thread_entry

So at first packet is unrefed in reassembly_cancel and then also in
processing_data.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-04-26 07:58:11 +03:00
Paul Sokolovsky 460a6c77c5 net: tcp: send_syn_segment: Log packet before it's sent
After successful send, the packet is automatically cleared, so
trying to call print_send_info() on it leads to errors:

[net/pkt] [ERR] net_pkt_tcp_data: NULL fragment data!
[net/tcp] [ERR] net_tcp_get_hdr: NULL TCP header!

(if error logging enabled).

This change is similar to how print_send_info() is called in
existing send_reset() function of this source file.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-04-26 07:55:21 +03:00
Andrzej Puzdrowski 341b427366 subsys: settings: fix fcb back-end initialization
In f. settings_init_fcb the storage area was implemented badly:
- storage was always erased
- the only source of settings fcb instance was pointed twice.
This patch fix both issues.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-25 22:25:32 +05:30
Andrzej Puzdrowski 9fe30535d7 susbsys: settings: fix coverity issues
API settings_subsys_init call was changed so that it returns
error (so returns int instead of void).
Prototype of storage helper function export_func for
settings_handler::h_export was changed so that it returns error
(so returns int instead of void).
Fixed few other error handling issues by ignoring return
values.

Tests were aligned to above patches.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-25 22:25:32 +05:30
Henrik Brix Andersen 83ac3e24d8 shell: kernel: Add reboot command
Add a reboot command for requesting a warm or cold system reboot
through the kernel shell.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2018-04-25 07:18:35 +05:30
Andrei Emeltchenko 7e067414cd usb: Remove unneeded header include
The should be included from sources

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-25 07:17:42 +05:30
qianfan Zhao b7862eb832 hid: core: truncated wLength if it doesn't match report descriptor size
Some buggy system may be pass a larger wLength when it try read
HID report descriptor, although we had already tell it the right
descriptor size.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-04-21 07:01:36 -07:00
Andrei Emeltchenko 53410af994 usb: Add Bluetooth device class core functionality
Implement Bluetooth over USB functionality through Bluetooth raw
access to the Bluetooth controller. Most devices with Bluetooth and
USB controllers supported by Zephyr can export themselves as USB
Bluetooth dongles.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 0322af5896 usb: Add Bluetooth device decriptors
Add USB Bluetooth device descriptors to usb_descriptor table.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 4d703b1e14 usb: Add Bluetooth USB Device configuration options
Add USB_DEVICE_BLUETOOTH option

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 1653254924 usb: mass_storage: Use simpler header include
Use searched dirs for descriptor headers

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 6239341add usb: Add subsys/usb for device descriptor header
Support device descriptor header easy access

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Andrei Emeltchenko 773f3e18bb usb: Add sys_cpu_to_le16() conversion for USB field
Add missing conversion.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:04:42 -07:00
Ruslan Mstoi c0d0a61bcc net: ipv6: Remove irrelevant error log
"NULL pending fragment" error log is not really an error, hence it is
removed.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-04-20 13:13:43 +03:00
Ruslan Mstoi 4c400e8762 net: ipv6: Fix crash from malformed fragment payload
This commit fixes crash from dereferencing NULL frag pointer in
handle_fragment_hdr.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-04-17 12:38:04 +03:00
Leandro Pereira 50893349fe subsys: nffs: Unlock mutex before returning
The implementation for the tell() primitive was attempting to unlock
the NFFS mutex after returning an error code.

Coverity-Id: 185283

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-14 23:35:52 -04:00
Ruslan Mstoi 2563c373c3 net: ipv6: Fix crash from NULL fragment pointer access
This commit fixes crash from dereferencing NULL pointer to pending
fragment in net_pkt_get_len.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-04-13 15:40:20 +03:00
Jukka Rissanen be6bf29363 syslog: net: Fix multiple network interface selection for IPv4
In IPv4 we need to select the network interface, where the packet
is to be sent, using the IPv4 address instead of default network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
Jukka Rissanen a91c46ffde net: app: Select local IP address properly if multiple interfaces
If we have multiple network interface (like in VLAN), then we need
to select the proper local interface based on destination address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
Jukka Rissanen 2bb179b7e1 net: shell: Use correct network interface for IPv4 ping
Instead of always using default interface, use the IPv4 target
address to select the correct network interface when sending
IPv4 ping request.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
Jukka Rissanen da8af39302 net: if: Add helper to select src interface for a IPv4 dst addr
If we have multiple network interfaces and we want to send
a IPv4 network packet to certain destination, then this new
helper can be used to figure out what network interface to use.

Note that this commit only adds support to select the correct network
interface according to destination IPv4 address. This does not enable
any automatic routing to happen.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
David B. Kinder 5e9f7cb27a doc: fix misspellings in Kconfig files
occasional spelling-check scan found some misspellings

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-04-13 08:28:57 -04:00
Tomasz Bursztyka c995bfe7e6 net/wifi: Add a shell module for controlling WiFi devices
This module exposes for now the net mgmt for WiFi: connect, disconnect
and scan commands.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Tomasz Bursztyka eab3f168fd net/mgmt/wifi: Add dedicated net mgmt hooks for WiFi offload devices
Exposing connect, disconnect and scan for now.

In case the iface is an instance of a WiFi offload device, the way it
manages scanning, connecting and disconnecting will be specific to that
device (not the mgmt interface obviously). In such case the device will
have to export relevantly a dedicated bunch of function to serve the
mgmt interface in a generic way.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Tomasz Bursztyka dc81659bc5 net/wifi: Select dependencies to get wifi mgmt working
Wifi mgmt interface will be required by offloaded wifi device drivers
therefore when selecting this interface, make sure dependencies are
selected too.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Patrik Flykt 7bde51d86a net/mgmt: Add initial WiFi management API definitions
Add empty WiFi network management functions that only return -ENETDOWN.
Define management handlers for scan, connect and disconnect requests,
again without any implementation nor parameters defined.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Tomasz Bursztyka 93ac7ce655 net/mgmt: Move NET_EVENT_INFO_MAX_SIZE into net core's private header
First because nobody needs to know that besides net_mgmt core and
secondary to avoid possible circular dependancy on
net_mgmt.h/net_event.h.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Gil Pitney c7d5e872dc net: Don't call l2->enable for offload devices
Previously, with CONFIG_OFFLOAD enabled, net_if_up() and
net_if_down() were calling l2->enable, which didn't exist,
so was crashing.
Instead, if CONFIG_OFFLOAD is enabled, it will test for if the net_if is
of an offload type and react accordingly.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Dario Pennisi 6d387ec98f net: Remove the need for an l2 on offloaded drivers
Drivers will be directly contacted via net_if's offload attribute. No
need for a an extra layer as an L2.

Signed-off-by: Dario Pennisi <dario@iptronix.com>
Signed-off-by: Massimiliano Agneni <massimiliano.agneni@iptronix.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Marcin Niestroj ac661a0779 net: tcp: Cancel fin_timer in FIN_WAIT_2 instead FIN_WAIT_1
According to RFC 793 we should wait for FIN in FIN_WAIT_1 and
FIN_WAIT_2 states. Receiving ACK in FIN_WAIT_1 just moves us to
FIN_WAIT_2 state.

Right now TCP connection is never closed if FIN is not received
in FIN_WAIT_2 state. Fix that by keeping fin_timer active in
FIN_WAIT_2 state, but canceling it just after FIN is received.

Fixes: 124c067027 ("net: tcp: Cancel the fin_timer on FIN message
  in FIN_WAIT1 state")
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2018-04-11 17:27:20 +03:00
Tomasz Bursztyka 6f57c03aee net: app: Always set relevant sa_family when starting a TCP server
Without that, if ipv4 is configured via DHCPv4, server will not be
accessible. It looks like it won't properly bind addresses.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-11 17:25:36 +03:00
David Leach 00885bbf28 OpenThread: Normalize IEEE802.15.4 driver name for use by L2 layers
- Removed OT_PLAT_RADIO_DEVICE_NAME
- Changed OpenThread binding to use NET_AP_IEEE802154_DEV_NAME
- Modified Kconfig chain to ensure NET_AP_IEEE802154_DEV_NAME
  is enabled for both native 802.15.4 and OpenThread configurations
- Changed default setting of NET_L2_IEEE802154 in defconfig for mkw41z4.
- Fixed OpenThread api support code to use the state of mIsCcaEnabled
  in the transmit frame to conditionally invoke radio_api->cc() on
  transmits.

Signed-off-by: David Leach <david.leach@nxp.com>
2018-04-11 16:57:12 +03:00
David Leach 03b24082ee subsys: net: ip: l2: openthread: Fixed compiler errors and warnings
- Debug code did not compile when level set to DEBUG.
- OpenThread has a define for BASE which conflicts with the BASE
  field in MTB_Type defined in MKW41Z4.h. The change is consistent
  with how it was handled in the KW41 port in OpenThread.

Signed-off-by: David Leach <david.leach@nxp.com>
2018-04-11 16:57:12 +03:00
David Leach 51a2090780 newlib: Fix compiler warning when using Newlib
- There is a mismatch when interfacing with external code where a
  uint32_t is defined as a parameter and internal Zephyr code attempts
  to use u32_t. If NewLib is used, the typedef for u32_t is
  'unsigned int' which is not a portable match to uint32_t as
  'unsigned int' is not a common size across architectures so gcc will
  output a warning.
- The mcux flash code calls NXP supplied functions that expect a
  uint32_t.
- openthread.c ot_state_changed_handler has a uint32_t flag as a
  parameter.

Signed-off-by: David Leach <david.leach@nxp.com>
2018-04-11 16:57:12 +03:00
Jukka Rissanen c90b9f53cd net: shell: Print ethernet statistics
Print ethernet interface statistics with "net stats all" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-11 16:49:48 +03:00
Jukka Rissanen c1e7fd76ef net: stats: Add infrastructure for collecting ethernet stats
Make sure we are able to collect ethernet statistics and query
it via net management API.

Fixes #6899

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-11 16:49:48 +03:00
Jukka Rissanen 1146ba1f91 net: app: server: Create IPv4 listener also if IPv6 is enabled
We returned too early when creating listeners which meant that
IPv4 listener was not created if IPv6 one was created successfully.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-11 16:35:23 +03:00
Andrzej Puzdrowski 61cd96ee45 net: l2: ethernet: fix kconfig
Missing newline on end of the file - this cause failure
while try to use menuconfig.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-11 13:01:33 +03:00
Tomasz Bursztyka 757c5d1857 net/ethernet: Fix uninitialized attributes in ethernet mgmt parameters
Without that, behavior is unknown and bogus.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 16:43:32 +03:00
Tomasz Bursztyka 8d558fb5ea net/ethernet: Add a management interface
This will permit to tweak ethernet L2 and devices settings at runtime.
Currently, only devices settings are tweaked through this interface.

Fixes #6640

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka af0c586988 net/ethernet: Moving ethernet code to dedicated directory
There will be additional source files coming in, so let's not clutter l2
root directory.

Reordering a bit l2 Kconfig: offload part come first, then the l2
drivers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka 4bf1a9bd60 net/ethernet: All types are prefixed with ethernet_
Aligning eth_hw_caps to the right prefix, so ethernet_hw_caps.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka e9d77b60de net/ethernet: No need to expose vlan_setup if vlan is not enabled
Function should be exposed if only vlan is enabled.

Also, changing vlan_setup's signature to stay consistent with device
driver API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Jukka Rissanen 1443ff0f5e net: stats: Make statistics collection per network interface
Instead of one global statistics, collect statistics information
separately for each network interface. This per interface statistics
collection is optional but turned on by default. It can be turned
off if needed, in which case only global statistics are collected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-10 13:29:39 +03:00
Jukka Rissanen 85d65b20c9 net: stats: Fix the net_mgmt statistics collection
Make sure that we return proper network statistics data if
someone asks it via network management interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-10 13:29:39 +03:00
Michael Hope 7383814d8b cpp: mark __dso_handle as weak.
The POSIX target uses the native crt0 which already provides
__dso_handle.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-04-09 23:21:52 -04:00
Jukka Rissanen e56a9f0ec4 net: ethernet: Return correct non VLAN interface
If we have several network interfaces and not all of them are
VLAN enabled, then we might return wrong network interface to
the ethernet device driver when it asks one. To fix this, return
the first interface that has not enabled VLAN if the tag of the
network packet is unspecified.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-09 17:17:00 +03:00
Vinayak Kariappa Chettimada 6c6d98bc4e Bluetooth: controller: Use hal/ticker.h to abstract SoC specifics
Introduce hal/ticker.h to abstract out SoC specific
implementations and move any conditional compilations to
include header files here.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-04-09 10:34:04 +02:00
Johan Hedberg d6a549ceba Bluetooth: Mesh: Fix Node Identity advertising with PB-ADV
The Node Identity advertising should only be automatically enabled
when provisioning happened over PB-GATT, but not when it happened over
PB-ADV. Move the enabling of Node Identity to the provisioning code,
where we know the bearer that was used (this information does not get
passed to the bt_mesh_provision function).

Fixes #6338

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-09 11:13:10 +03:00
Michael Hope dbb2264454 usb: hid: implement set_report()
set_report() is used by the host to set a feature on the device such
as turning a LED on or off.

This is also used by protocols such as FIDO U2F to transfer data to
the device.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-04-06 23:06:07 -04:00
Michael Hope 0d04aef6fe usb: hid: add a INT IN transfer complete callback.
int_in_ready is an optional callback that is called when the current
interrupt IN transfer has completed.  This can be used to wait for the
endpoint to go idle or to trigger the next transfer.

This is needed for protocols like FIDO U2F that use the interrupt
endpoint for transfers.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-04-06 23:06:07 -04:00
Loic Poulain d80ae8aeeb usb: netusb: Add CDC EEM network usb function
Add CDC Ethernet Emulation Model function driver. This usb network
function can be used for ethernet over USB. Ethernet packet are
encapsulated within EEM packets. An EEM pkt contains 2-byte header
and 4-byte sentinel (or crc).

Note that EEM packets can be split across USB packets but shall not
be split across USB transfers.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-04-06 06:50:34 -04:00
Loic Poulain 992e32842b usb: netusb: Rework netusb media connect/disconnect
Consider media connected when interface is selected by the host and
disconnected on device diconnection.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-04-06 06:50:34 -04:00
Jukka Rissanen ffd0a1f5d0 net: core: Check interface when receiving a packet
Although very unlikely, make sure that if the net_recv_data() is
called with NULL network interface or packet, we recover that and
return error to the caller.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 10:46:55 -04:00
Jukka Rissanen b70b4bcad6 net: shell: Add network interface up/down command
User is able to take a network interface down or bring it up.
The command syntax is "net iface [up|down] [index]"

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 17:21:31 +03:00
Jukka Rissanen 6643bb0898 net: l2: ethernet: Add priority to sent ethernet VLAN header
When sending packet add the VLAN priority to the ethernet header.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen 2c343d2b25 drivers: net: slip: Add VLAN support
This enables VLAN support in slip tap ethernet driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen 487e8104ba net: shell: Add VLAN support
Add commands to add, remove or get information about VLANs
attached to network interfaces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen de13e979fc net: if: vlan: Add virtual lan support
This allows creation of virtual lan (VLAN) networks. VLAN support is
only available for ethernet network technology.

Fixes #3234

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen a0df4f6698 samples: net: Fix sanitycheck for sam_e70_xplained board
Some of the sanitycheck tests were having too small limit for
network buffers when compiling for sam_e70_xplained board.
Increase the buffer limits when testing this for this board.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:25:49 -04:00
Johan Hedberg b8042ea9ce Bluetooth: Mesh: Fix possible NULL dereferences in client models
There's a small but real chance of a race-condition when sending
messages to the local node (through the local network interface) that
expected parameters will be NULL in the message handles. Add
appropriate NULL checks for them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-05 10:08:18 +03:00
Andrei Emeltchenko 4291fb67a3 usb: Remove duplicated CDC_ECM_SUBCLASS definition
Use ECM_SUBCLASS instead.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-04 08:21:06 -04:00
Jukka Rissanen 9d38f46c38 net: tc: Using u8_t for queue and thread priority
As the priority currently fits u8_t then use it instead of int
for priority value for queue and thread.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-03 23:18:57 +03:00
Jukka Rissanen 79bb5896b4 net: tc: Fix array checks
The array size checks were incorrect.

Coverity-CID: 183482
Coverity-CID: 183485

Fixes #6883
Fixes #6885

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-03 23:18:57 +03:00
Andrei Emeltchenko 75397485ba usb: hid: Fix setting report size for composite configuration
Fixes usb_set_hid_report_size() not called for composite configuration

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-03 15:58:33 -04:00
Mariusz Skamra 276d17df04 Bluetooth: L2CAP: Update LE specific connection result values
This updates result values for LE Credit Based Connection
Response according to Table 4.20 from Core 5.0 Vol 3 Part A.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-04-03 14:30:10 +03:00
Mariusz Skamra d458f1e7a2 Bluetooth: L2CAP: Use BR definition on connection success
This fixes BR L2CAP to use BT_L2CAP_BR_SUCCESS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-04-03 14:30:10 +03:00
Ruslan Mstoi 9705f4af46 net: tcp: Fix crash from SYN flood
SYN flood causes crash in RX thread due to NULL pointer access. After
the crash available RX memory is zero, hence echo server does not
respond to echo request.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-04-03 14:17:24 +03:00
Stig Bjørlykke 97b83ffc2c net: sockets: Check for errors from dns_get_addr_info
When dns_get_addr_info() returns an error it does not call the
resolve callback, and thus the semaphore will not be given.

This fix will avoid a deadlock situation for various errors.

Added some small tests for getaddrinfo().

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-04-03 14:15:43 +03:00
Stig Bjørlykke 5da0d2928f net: dns: Fix end-of-results callback on error
Callers of dns_get_addr_info() depends on receiving an end-of-results
callback (where 'info' is NULL) when finished. Do this on failure in
cb_recv() instead of pointing to an empty object.

This fix will avoid a deadlock situation in getaddrinfo().

A reply code other than "no error" in the DNS response is a typical
case when the lookup failed and this occurs.

Moved "struct dns_addrinfo info" variable from cb_recv() to dns_read()
because it was now unused in cb_recv().

Adding tests for this requires network access and a DNS server,
or a mechanism for generating a DNS response with a reply code.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-04-03 14:14:00 +03:00
Stig Bjørlykke e652b74860 net: sockets: Do not lookup DNS AAAA entries if IPv6 is disabled
Do not lookup DNS AAAA entries if IPv6 is disabled. The result can not
be used anyway because "struct sockaddr" does not have enough space for
IPv6 address in that case.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-04-03 10:23:06 +03:00
Ulf Magnusson 93689bdc80 kconfig: Remove no-op selects of choice symbols
Selecting a choice symbol is always a no-op, and the latest version of
Kconfiglib prints a warning. This commit removes all selects of choice
symbols, which might make the Kconfig files a bit clearer and gets rid
of the warnings.

This is just a dumb removal. I did not try to guess the intent of each
select.

Fixes #6849

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-03-29 08:57:39 -04:00
Patrik Flykt e9b00eae75 net: tcp: Move TCP stack to tcp.c
Move core TCP functionality from net_context.c to tcp.c. Create empty
functions that the compiler can remove if TCP is not configured. As a
result remove TCP ifdefs from net_context.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 2c748ae6b5 net: context: Fix connect for UDP contexts
Similar to the socket connect() call, calling connect for a UDP
context needs to set both local and remote addresses and port
number. Fix this not to be exclusive for TCP.

Similarly, the remote destination can be a multicast address when
UDP is used.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt cfc6b56203 net: context: Factor out TCP receive window handling
Receive window is needed only for TCP.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 08110d8295 net: context: Factor out TCP context listen state
Factor out TCP context listening state change.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt b5c74b9706 net: context: Refactor queueing of a TCP FIN when closing socket
Queue a TCP FIN packet when needed if the socket was connected or
listening and where FIN wasn't already received.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt aed6a227a6 net: context: Remove unnecessary callback clearing
A new context cannot have callbacks set, as it was freshly created
in the beginning of the function. Thus the extra callback clearing
can be removed. This is a left-over from commit ce41d5f432.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 081e0eb8af net: context: Refactor net_tcp_send_data()
Refactor net_tcp_send_data() by adding callback information in the
function.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 34d82eb949 net: context: Factor out code for TCP receive
Create a function for TCP receive.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt d8522657bd net: context: Remove unnecessary ifdefs
Ifdefs around TCP code can be removed since the TCP code will compile
to empty functions when not enabled.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 8236e1e5cd net: context: Factor out TCP header length checking
TCP header length checking is needed by net_context.c.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 3b579ffb90 net: context: Refactor sendto()
Refactor sendto() code so that destination address and its validity
is checked first, followed by offloading verification. Move context
and shutdown checks into TCP queueing function.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 09b67a4825 net: context: Update net_context_sendto()
Only #ifdefs are removed in net_context_sendto().

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Patrik Flykt 7f8b2fc5ce net: tcp: Define empty static functions when TCP is disabled
With CONFIG_NET_TCP is not set, provide empty static inline
prototypes for all TCP functions available to other parts of
the IP stack.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-03-29 12:39:43 +03:00
Andrzej Puzdrowski 94ff339cbf subsys: Add a new settings subsystem
Adapt the MyNewt non-volatile configuration system to become a settings
system in Zephyr.
The original code was modifed in the following ways:

* Renamed from config to settings
* Use the zephyr FCB, FS API, and base64 subsystems
* lltoa like function was added to sources as it was required but not
  included in Zephyr itself.
* The original code was modified to use Zephyr's slist.h as single
  linked list implementation.
* Reworked code which was using strtok_r, added function
  for decoding a string to a s64_t value.
* Thank to the above the settings subsys doesn't require newlibc anymore.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-28 10:44:20 -04:00
Andrzej Puzdrowski e33aa5509a subsys: fs: add NFFS rename API implementation
Added file/directory rename implementation basing on NFFS
native support.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-03-28 10:44:20 -04:00
Michael Hope 29f4e18af4 cdc_acm: fix interrupt handling, API registration, and propgate errors.
As per uart_pipe.c, irq_is_pending should only return true if any
*unmasked* interrupts are pending.

The device_get_binding() code only checks devices that have an API.
Set the API at compile time so that other devices can refer to the CDC
ACM driver.

usb_write() may return EBUSY if the endpoint is full.  Propagate this
for future use.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-28 11:17:14 +02:00
Michael Hope 4e7deb49b9 usb: netusb: implement the ethernet interface.
net_eth_get_hw_capabilities() calls .get_capabilities() which is part
of the ethernet API but not the net_if_api that netusb implements.
This causes a fault as .get_capabilities() was past the end of the
struct and resolved to a random address.

Also, make the API const and give it a unique name.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-28 09:36:55 +03:00
Jukka Rissanen d114deadcf net: shell: Print TX and RX threads stacks with more info
The "net stacks" command was printing TX or RX thread values so
that it was not possible to use the values in debugging easily.
Add traffic class value when printing the info so that it is
easy to see what TX or RX queue is doing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 99e93db6b2 net: stats: Add traffic class statistics
Add statistics for number of packets and bytes to each traffic
class. Print this information in net-shell.

Also make sure that we do not calculate total packet length many
times. So calculate network packet total length once and then use
that value instead of calculating it many times in a row.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 6049207a29 net: Add initial TX and RX traffic class support
With this commit it is possible to add priority to sent or received
network packets. So user is able to send or receive higher priority
packets faster than lower level packets.
The traffic class support is activated by CONFIG_NET_TC_COUNT option.
The TC support uses work queues to separate the traffic. The
priority of the work queue thread specifies the ordering of the
network traffic. Each work queue thread handles traffic to one specific
work queue. Note that you should not enable traffic classes unless
you really need them by your application. Each TC thread needs
stack so this feature requires more memory.

It is possible to disable transmit traffic class support and keep the
receive traffic class support, or vice versa. If both RX and TX traffic
classes are enabled, then both will use the same number of queues
defined by CONFIG_NET_TC_COUNT option.

Fixes #6588

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 81d8d5219c net: context: Add PRIORITY option support
Add context option support and implement PRIORITY option that
can be used to classify the network traffic to different trafic
classes according to said priority value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen ca8b00a3cc net: if: Make interface IP configuration more flexible
Instead of always allocating both IPv6 and IPv4 address information
to every network interface, allow more fine grained address
configuration. So it is possible to have IPv6 or IPv4 only network
interfaces.

This commit introduces two new config options:
CONFIG_NET_IF_MAX_IPV4_COUNT and CONFIG_NET_IF_MAX_IPV6_COUNT
which tell how many IP address information structs are allocated
statically. At runtime when network interface is setup, it is then
possible to attach this IP address info struct to a specific
network interface. This can save considerable amount of memory
as the IP address information struct can be quite large (depends
on how many IP addresses user configures in the system).

Note that the value of CONFIG_NET_IF_MAX_IPV4_COUNT and
CONFIG_NET_IF_MAX_IPV6_COUNT should reflect the estimated number of
network interfaces in the system. So if if CONFIG_NET_IF_MAX_IPV6_COUNT
is set to 1 and there are two network interfaces that need IPv6
addresses, then the system will not be able to setup IPv6 addresses to
the second network interface in this case. This scenario might be
just fine if the second network interface is IPv4 only. The net_if.c
will print a warning during startup if mismatch about the counts and
the actual number of network interface is detected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 47dafffb67 net: if: Separate IP address configuration from net_if
Move IP address settings from net_if to separate structs.
This is needed for VLAN support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Anas Nashif 993c350b92 cleanup: replace old jira numbers with GH issues
Replace all references to old JIRA issues (ZEP) with the corrosponding
Github issue ID.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-26 13:13:04 -04:00
Vinayak Kariappa Chettimada 4c49df98e5 Bluetooth: controller: Fix missing device filter clear
Fix missing device filter clearing for cases where whitelist
was used and then in subsequent adv/scan enable it was
unused.

This fixes an assert in ll_filter.c at line 248.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-26 16:44:35 +02:00
Tomasz Bursztyka 185ff16675 net/mgmt: Remove spurious k_sem_give()
Caller of that function is the one giving the semaphore.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-26 15:07:00 +03:00
Tomasz Bursztyka 807f3e335b net/mgmt: Reenforce pushing events into notification list
Previous way was too lazy. Now let's match exactly for the layer and the
layer code.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-26 15:07:00 +03:00
Tomasz Bursztyka 059fc95099 net/mgmt: Ensure that event order is kept as FIFO
Make sure also to increase in_event if only inserting event info was
properly done.
Raising also range limit in Kconfig to a much higher value.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-26 15:07:00 +03:00
David Maitland f77469a3bb Bluetooth: controller: Refactor to use max macro
Cleaned up the use of conditional statements to use the max macro.

Fixes #6230.

Signed-off-by: David Maitland <hello@davidmaitland.me>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-25 11:33:51 +02:00
Jukka Rissanen 6170ae5e2e net: websocket: Use system provided base64 function
Instead of using mbedtls_base64, use system provided base64 encoding
function.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-23 08:30:26 -04:00
Carles Cufi 4295306232 mgmt: Switch to new base64 library
Now that mbedTLS is no longer required, use the new base64 library
instead.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-23 05:18:11 -04:00
Jukka Rissanen 85a2459edb net: Support network packet checksum calc offloading
Create infrastructure that allows ethernet device driver to tell
if it supports network packet checksum offloading. This applies only
to IPv4, UDP or TCP checksums. The driver can enable/disable checksum
offloading separately for Tx and Rx network packets.

If the device (ethernet in this case) can calculate the network
packet checksum for IPv4, UDP or TCP, then do not calculate the
corresponding checksum by the stack itself.

Fixes #2987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-23 08:37:01 +02:00
Michael Hope 4d6d04d3ea hid: change the API table to const.
A minor change to put the API function table into flash.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-21 19:45:11 -04:00
Johann Fischer c0c4dfc6ea subsys: usb: usb_descriptor: fix style and function declaration
Fix style and function declaration

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-03-21 15:39:56 -04:00
Johan Hedberg bf8050b016 Bluetooth: Mesh: Introduce debug option to use identity address
Add a Kconfig debug option to enable using the local identity address
for advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Johan Hedberg ac133268a5 Bluetooth: Remove 'own_addr' from advertising parameters
This was originally added as a work-around to avoid the heavy stack
consumption of the TinyCrypt PRNG when generating NRPAs. This is
no-longer an issue, and there are in fact no (in-tree) users of this.
Remove it before it gains any wider users, since it was in many ways a
hack/work-around to begin with.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Johan Hedberg 7d4514a8b0 Bluetooth: Add option to force using identity address for advertising
In some cases the app may want to force using the identity address
regardless of privacy support or what type of advertising is done.
Provide such an option in bt_le_adv_param.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-21 18:11:49 +02:00
Stig Bjørlykke 5f42a26488 net: sockets: Allow empty service in getaddrinfo()
Make the service parameter optional in getaddrinfo().

The application should be able to use NULL as service when only
interested in the host lookup.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-21 10:00:17 +02:00
Stig Bjørlykke 57e7ea8793 net: sockets: Support MSG_DONTWAIT flag in zsock_sendto
Add support for MSG_DONTWAIT flag in send() and sendto(). This
aligns with the same flag used in recv() and recvfrom().

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-21 09:59:49 +02:00
Carles Cufi 8aa9a37902 drivers: flash: nrf: Rename nrf5 to nrf
With upcoming ICs that are not in the nRF5x family, rename the flash
driver and all its dependencies from nrf5 to nrf.

Should also fix the issue introduced by f49150cab6 which broke the
assignment of the flash device due to a partial rename.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 20:07:09 +01:00
Jukka Rissanen feec8bfadb net: websocket: Leave space for null in strncpy
There was not enough space for \0 at the end of the string.

Coverity-CID: 183057
Coverity-CID: 183050
Fixes #6675
Fixes #6682

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-20 12:19:13 -04:00
Stig Bjørlykke 7c9c825138 net: sockets: Support MSG_PEEK flag in zsock_recvfrom
Add support for MSG_PEEK flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-20 15:55:04 +02:00
Ruslan Mstoi b3a5797dba net: ipv6: fix memory leak caused by echo request
Memory leak occurs if neighbor table is full and echo request from an
unknown neighbor is received. Hence, on an attempt to send NS unref of
pending is not done, causing the memory leak.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-03-20 15:51:37 +02:00
Jukka Rissanen 317eae06f6 net: ethernet: Avoid overlapping memcpy for tx packets
This was reported by valgrind

Source and destination overlap in memcpy(0x80c18c0, 0x80c18c0, 6)
   at 0x4035C3E: memcpy (vg_replace_strmem.c:1023)
   by 0x80978CA: ethernet_send (ethernet.c:319)
   by 0x8061B9B: net_if_send_data (net_if.c:281)
   by 0x805F215: net_send_data (net_core.c:399)
   by 0x8080998: send_mldv2_raw (ipv6.c:2858)
   by 0x8080BA6: send_mldv2 (ipv6.c:2889)
   by 0x8080D6C: net_ipv6_mld_join (ipv6.c:2915)
   by 0x8061EF0: join_mcast_allnodes (net_if.c:438)
   by 0x8062CA4: net_if_ipv6_addr_add (net_if.c:826)
   by 0x8062296: net_if_start_dad (net_if.c:557)
   by 0x8066667: net_if_up (net_if.c:2107)
   by 0x8066AF0: net_if_post_init (net_if.c:2341)

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-20 14:36:07 +02:00
Carles Cufi f49150cab6 arch: arm: nrf: Rename nrf5 SoC Family to nrf
Upcoming Nordic ICs that share many of the peripherals and architecture
with the currently supported nRF5x ones are no longer part of the nRF5
family. In order to accomodate that, rename the SoC family from nrf5 to
nrf, so that it can contain all of the members of the wider Nordic
family.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-20 11:57:14 +01:00
Johan Hedberg 0cee4ed747 Bluetooth: Mesh: cfg_cli: Fix possible race condition
If the thread that sends the configuration messages has low priority
and is sending to the local node (a common use case currently) it's
possible that the response arrives before the cli->op_* state
variables are set, resulting in the message never getting properly
processed and the client API call timing out.

Split the initialization into a separete cli_prepare() call and add a
cli_reset() to clean up the variables in case of premature completion
of the client operation (e.g. due to message sending failure).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-20 09:22:42 +02:00
Johan Hedberg 7fd4184d2e Bluetooth: Mesh: cfg_cli: Fix trying to write a NULL pointer
It's not always guaranteed that param->status will be non-NULL,
especially not after a subsequent patch to fix a race condition with
the response waiting.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-20 09:22:42 +02:00
Jukka Rissanen b047f816f4 net: Create helper to convert MAC strings to array of bytes
As following commits need this functionality, create a function
which converts "01:02:ab:fe:34:dd" type hex strings to array of
bytes. Change the SLIP driver to use this new function.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-18 20:47:36 -04:00
Stig Bjørlykke 158adc684f net: sockets: Support MSG_DONTWAIT flag in zsock_recvfrom
Add support for MSG_DONTWAIT flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-18 17:06:38 -04:00
Andy Ross c7ceef6751 kernel_event_logger: Ignore events before subsystem init
Thread and interrupt events may well arrive before the subsystem
initialization call has been made.  Just swallow such events.

In particular, an incoming change to the way _ready_thread works
causes the main and idle thread initialization to throw thread ready
events (which isn't wrong!), which the current setup can't handle.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-03-18 16:58:12 -04:00
Paul Sokolovsky e82578919a mbedtls: Replace COAP-specific max len setting with generic
Instead of CONFIG_COAP_MBEDTLS_SSL_MAX_CONTENT_LEN, use recently
introduced CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-18 09:38:22 -07:00
Loic Poulain ccf0b46a31 usb: usbnet: ecm: Use transfer API
Replace low-level usb_read/usb_write with transfer functions.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain c97d9c6c27 usb: netusb: consider media connected on interface selection event
The interface and its enpoints are only enabled once interface is
selected by the host.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain b4d305d752 usb: call status_callback on interface set
Add new status event indicating an interface has been selected.
Interface and its endpoint(s) are enabled.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain ddb1b8f6c7 usb: usbnet: Add USBNET_MTU definition
This value can be used in sub-functions for buffer mgmt.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 16921b0698 usb: Add transfer management API
The transfer API provides 'high' level functions to manage sending and
reception of USB data. A USB (class) driver has to register the generic
usb_transfer_ep_callback as endpoint status callback in order to use
the API.

With this API, the class driver does not need to take care of low-level
usb transfer management (packet splitting, ZLP, synchronization...).
The usb_transfer methods will split transfer into multiple transactions
depending endpoint max size and controller capabilities.

Once the transfer is completed, class driver is notified by a callback.
The usb_transfer method can be executed in IRQ/atomic context.
A usb_transfer synchronous helper exists which block-waits until
transfer completion.

In write case, a transfer is complete when all data has been sent.
In read case, a transfer is complete when the exact amount of data
requested has been received or if a short-pkt (including ZLP) is
received.

transfer methods are thread-safe.

A transfer can be cancelled at any time.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Leandro Pereira 2f5659d4d2 arch: x86: Unwind the stack on fatal errors
Prints up to 8 stack frames, with the following format:
  RETURN_ADDR(ARGUMENTS)

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-16 14:12:15 -07:00
Tomasz Bursztyka c49d176c35 ieee802154: Make AR flag check generic and not tight to L2
Since this function is used on some drivers, and knowing these drivers
can be built for OpenThread, let's make it generic and out of the
802.15.4 L2 stack.

Fixes #5942

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-16 13:57:55 -07:00
Jukka Rissanen 4cfca3ea62 net: ipv6: Fix compile error if neighbor cache is disabled
If net-shell is enabled then it could try to access neighbor state
names. This would cause compile error as net_ipv6_nbr_state2str()
function is then missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-16 14:05:50 +02:00
Ruslan Mstoi c288bf7aeb net: icmpv6: Drop malformed ICMPv6 echo request
This commit fixes the crash of echo_server from malformed echo request.

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-03-16 14:03:49 +02:00
Andrei Emeltchenko 65db8e1e0f usb: cdc_acm: Fix typo
Fix typo in callback debug message

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-15 15:58:02 -07:00
Jukka Rissanen 7f8315a928 net: app: Fix debug level check
We need to check the debug level to be INFO or higher, otherwise
the some of the variables in net app init.c will give unused
warning. Also the sys_log.h needs to be included _after_ we have
set the logging level, this is done by net_core.h so we should
not include the syslog header file here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:19:46 +02:00
Jukka Rissanen c8879293cc net: app: Enable syslog to network in init
Start to send syslog messages to net after we have a proper
IP address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:19:46 +02:00
Jukka Rissanen 9f73d5e2fd syslog: Add networking backend
If network based syslog backend is enabled in Kconfig file,
then syslog messages are sent to external system using UDP.
See RFC 5424 and RFC 5426 for details about the syslog protocol.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:19:46 +02:00
Jukka Rissanen ead9cd409c net: websocket: Add console support
Add console driver that allows console session to be transferred
over a websocket connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Jukka Rissanen d70c7383de net: websocket: Initial support for server websocket
This commit creates a websocket library that can be used by
applications. The websocket library implements currently only
server role and it uses services provided by net-app API.
The library supports TLS if enabled in configuration file.

This also adds websocket calls to HTTP app server if websocket
connection is established.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Stig Bjørlykke b0c8cd8048 net: sockets: Refactoring zsock_recvfrom
Refactor recvfrom code for handling SOCK_DGRAM into zsock_recv_dgram
to align with SOCK_STREAM. Add flags parameter, will be used later.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-15 15:10:04 +02:00
Carles Cufi fb3387a490 Bluetooth: Remove rand driver and use entropy instead
After porting the rand driver to drivers/entropy, replace the usage of
the old, Buetooth-specific driver with the generic entropy one.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-14 16:47:50 +01:00
Iván Sánchez Ortega fa57ebd5b7 usb: Rename unicode into UTF16LE
In order to avoid confusion between "Unicode", UTF8, UTF16, UTF32,
and endianess of these encodings, rename all instances of "Unicode"
in the USB subsystem and samples into "UTF16LE".

Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
2018-03-14 13:40:59 +01:00
Iván Sánchez Ortega 0186b0731a usb: provide different USB product strings in the USB samples
Make it possible to change USB manufacturer, product and
serial number strings by forcing prompt in the kconfig files.

Signed-off-by: Iván Sánchez Ortega <ivan@sanchezortega.es>
2018-03-14 11:25:56 +01:00
Kumar Gala d68b6a901a subsys: fs: Fix fs_file_t and fs_dir_t usage
With the introduce of VFS the typedef for fs_file_t & fs_dir_t don't
exist anymore so we need to use 'struct fs_dir_t' or 'struct fs_file_t'.
Fix up some places that got missed in the VFS conversion.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-03-13 09:47:58 -05:00
Ruslan Mstoi 8109bdf8c1 net: ipv6: Drop RA with MTU out of valid range
This commit fixes incorrect Ethernet frame check sequence and ICMPv6
checksum caused by MTU set to zero in RA

Fixes #6342

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-03-12 17:26:41 +02:00
Ramakrishna Pallala 3e83a52781 subsys: fs: Kconfig changes to enable multiple file systems
Kconfig changes to enable or select multiple file systems.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-03-10 21:38:04 -05:00
Ramakrishna Pallala 25302b1980 subsys: fs: Add Virtual File system Switch (VFS) support
Add support for Virtual File system Switch (VFS) by
introducing mount point concept to Zephyr. This allows
the applications to mount multiple file systems at
different mount points (ex: "/fatfs" and "/nffs"). The
mount point structure contains all the necessary info
required to instantiate, mount and operate on file system.

Decouple applications from directly accessing individual
file systems API's or internal functions by introducing
file system registration mechanism in VFS.

Move the file system defination and mount responsibility
to application so that application can decide which file system
to use and where to mount.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-03-10 21:38:04 -05:00
Ramakrishna Pallala 9792951570 subsys: fs: Kconfig: Add log level support for fs subsystem
Add SYS_LOG_FS_LEVEL Kconfig option for file system subsystem.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-03-10 21:38:04 -05:00
Andrzej Puzdrowski 80a99fa450 subsys: storage: flash_map: enable only if any flash driver is enable
It was possible to have enable flash module while no flash driver
implementation was enabled. This cause coverity issues and unnecessary
initialization call.

This pat introduce FLASH_HAS_DRIVER_ENABLED Kconfig keyword which is
selected once any flash driver is enabled. flash_map switch its
dependency to this keyword.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-03-08 10:18:57 +01:00
Andrzej Puzdrowski 51527e07ef subsys: storage: flash_map: Fix Coverity issues
Loop counter was type of signed int while it was compared
to unsigned lvalue in loop condition.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-03-08 10:18:57 +01:00
Carles Cufi 50693c0fcd Bluetooth: controller: Generate LE Conn Complete on cancellation
When using the LE Create Connection Cancel command, the controller is
supposed to return a Command Complete first and then an LE Connection
Complete Event after. Since the Link Layer does not generate an event in
this case emulate the behavior in the HCI layer instead.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-07 12:49:47 +01:00
Mariusz Skamra cfc79d1669 Bluetooth: Fix available LPN groups count
This fixes the LPN_GROUPS define.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-06 18:41:17 +01:00
Luiz Augusto von Dentz 9c92609a66 Bluetooth: GATT: Fix possible crash while resubscribing
When reconnecting the code will attempt to recover the subscriptions
but it was not setting any callback causing the bt_att_req.func to be
NULL.

Fixes #5982

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-03-06 17:06:22 +01:00
Mariusz Skamra b7ac9770c9 Bluetooth: Add missing check prior sending LE Set Privacy Mode cmd
This check is needed to not send command that is not supported
by controller. LE Set Privacy Mode command was introduced in
Bluetooth 5.0 so that it will fail on older controllers.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-06 08:54:58 +01:00
Johan Hedberg b9588d8eb6 Bluetooth: Mesh: Switch to using Linux Foundation Company ID
The Linux Foundation now has an assigned Company Identifier, so switch
to using that.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-03-05 19:54:21 -05:00
Paul Sokolovsky 5925112ee6 net: sockets: Preserve user_data for any net_context send() or recv()
We use ctx->user_data to hold socket flags. As each call to
net_context_recv() and net_context_send() overwrites its previous
value, we explicitly must pass the current ctx value there.

Without this, non-blocking socket was turned into blocking after
e.g. switching from receiving to sending.

Fixes: #6309

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Paul Sokolovsky 934195cc43 net: sockets: zsock_accepted_cb: Init child socket on success only
If accept callback is called with error, don't treat the context
passed to the callback as a new accepted context.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Paul Sokolovsky 9e02f7b644 net: sockets: Fix mask application in sock_set_flag()
We pass normal 1-based mask, and mask invert it before logically
AND'ing with the value. This apparently a mix-up between how the
mask was intended to be passed initially and how it was in the end.
This issue actually didn't have an effect, because currently defined
flags have mutually exclusive lifetime (when "eof" flag is set,
"non-blocking" flag value is no longer import). Anyway, that's a
bug and needs fixing.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-03-05 12:54:42 +01:00
Ravi kumar Veeramally ebc81bdf8d net: http: Provide destination address in http replies
net_app_ctx maintains multiple net contexts(net_ctx). But when http
api's wants to reply or send some data, its always choose the first
net_context in the array, which is not correct always.

net_app_get_net_pkt_with_dst() api will select proper context
based on destination address. So with the help of new api in
net_app, http can select proper context and send packets. To
achieve this, desination address is provided in http_recv_cb_t
and http_connect_cb_t callbacks. Also chaged relevant API's to
provide destination address in http message preparation methods.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-03-05 10:23:17 +01:00
Michael Scott ddbcef4623 net: context: fix semaphore for offload in in net_context_put()
We're missing a k_sem_give for contexts_lock in the
CONFIG_NET_OFFLOAD path of net_context_put().

This fixes a network hang which occurs after any http_close()
call when CONFIG_NET_OFFLOAD is enabled.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-03 20:40:25 +01:00
Andrei Emeltchenko 42e94c73c7 usb: msc: Cleanup USB write
This makes code more readable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-03 10:27:21 +01:00
Andrei Emeltchenko c857c20f88 usb: msc: Fix USB write check
Fix checking error code when write to USB endpoint.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-03 10:27:21 +01:00
Mariusz Skamra 777f9c8cd0 Bluetooth: Workaround privacy feature issue
This fixes intercompatibility issues with controllers supporting
privacy feature.
Core Spec requires to use network privacy mode as a default when
peer device provides its IRK during bonding when LL Privacy is used,
which is the case for Zephyr. We've seen devices including PTS
which exchanges it's IRK but is not aware about network privacy
mode. This results in Zephyr not able do be reconnect to such bonded
devices.
This workaround sets device privacy mode to be able to reconnect
to such devices.

Fixes #4989
Fixes #5486

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-03-02 17:56:37 +01:00
Carles Cufi d4d2581b76 Bluetooth: controller: Default to the LF Company ID
The Linux Foundation has been assigned a Company Identifier, and with it
a means of identifying Zephyr over the air. Default to the LF Company
Identifier, which can be overridden by silicon vendors.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-02 17:27:35 +01:00
Michael Scott e9c0d001fa net: http: client: remove payload send_chunk logic
Logic for sending chunks of data is incompatible with adding
Content-Length: header.

Per https://tools.ietf.org/html/rfc7230#section-3.3.1:
"A sender MUST NOT send a Content-Length header field in any
message that contains a Transfer-Encoding header field."

Going a bit further in my mind: also don't send Transfer-Encoded
chunked data either when the Content-Length header is present.

In general, there will be problems if the http client library
makes payload changes without the user code knowing about it.

This patch removes the use of http_send_chunk() from the new
HTTP client code and instead sends the payload directly to
http_prepare_and_send()

This fixes an issue where every available buffer would be allocated
with repeating payload data because the for loop in http_request()
wasn't ending until we ran out of memory.

NOTE: This patch was previously applied but was lost when
commit d1675bf3e6 ("net: http: Remove the old legacy API")
moved code around.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott 4fe2bcf13f net: http: fix flush in http_prepare_and_send()
In commit 9489fa54cc ("net: http: Fix http_prepare_and_send"),
the logic for when to call http_send_flush() was incorrect.  This
is causing a call to http_send_flush() every time
http_prepare_and_send() is called.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott fcb5e2b1ee net: http: honor CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT setting
We should not use the user suppied timeout setting in
http_client_send_req() for the connection timeout.  In the
previous API the call to tcp_connect() used
CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT as the timeout setting.

Let's do that here too.

This fixes -ETIMEDOUT error generation when using K_NO_WAIT
for http_client_send_req().

NOTE: This patch was previously applied but was lost when
commit d1675bf3e6 ("net: http: Remove the old legacy API")
moved code around.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott a2dfaebafc net: http: client: handle empty body for PUT/POST request response
In previous version of the HTTP API, commit 8ebaf29927 ("net: http:
dont timeout on HTTP requests w/o body") fixed handling of HTTP
responses without body content.

For the new API, let's add a specific fix for when PUT/POST requests
are responded to with just the status code.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Tomasz Bursztyka f835f7f6a0 net/mgmt: Protect the event_callback list when manipulating it.
Adding a lock where relevant.

Fixes #6413

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-02 16:50:21 +01:00
Tomasz Bursztyka 7255d7bbfb net/mgmt: Fix how event_mask is handled on layer and layer code part
Exact match is the rule here.

Fixes #6413

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-02 16:50:21 +01:00
Vinayak Kariappa Chettimada ac34131f42 Bluetooth: controller: Fix missing advDelay in Low Duty Cycle Directed
Fixed the controller implementation for the missing advDelay
for connectable directed advertising events used in a low
duty cycle mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-03-02 16:34:39 +01:00
Alberto Escolar Piedras 4484e9efbd bluetooth: controller: nrf5: fix to IC-specific reset function
Fix of 80210198ad so it does
not cause a segfault in simulated boards

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-03-02 16:33:52 +01:00
Michael Hope 2262ed7b18 netusb: drop the extra byte added for multiple-of-64-byte packets.
This fixes a bug in the cdc_ecm Ethernet over USB driver.  The ECM
spec (section 3.3.1) says that the end of an Ethernet frame is marked
using the USB short packet mechanisim, where the last packet is less
than the maximum packet size.  If the Ethernet frame is a multiple of
the USB maximum packet size then a final zero length packet must be
sent.

Linux however sends a one byte packet (usbnet.c:1393) to work
around hardware issues with zero length packets.

The current Zephyr driver works most of the time except when you send
an Ethernet frame of the right length where the last byte is zero,
such as:

$ ping 192.0.2.1 -s 23 -p 0

Zephyr then drops the last byte, creating a short frame which gets
dropped higher up in the stack.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-02 07:34:53 +01:00
Ruslan Mstoi 3012157a94 net: ipv6: Ignore reachable time greater than maximum
This commit fixes the crash of echo server from unsolicited RA with
reachable time set to 2147483648. The crash was in
net_if_ipv6_calc_reachable_time because such large value resulted in
modulus by zero due to integer overflow.

Fixes #6382

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-03-02 07:34:12 +01:00
Andrei Emeltchenko d91e9e5436 net: Exit early on zero length packet append
Shorten exit path on zero length data append to a packet.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-03-02 07:33:26 +01:00
Sebastian Bøe fc5f0b2400 openthread: Use ccache when enabled
Use ccache when building OpenThread. When the cache is warm, I was
able to observe that this patch sped up a clean build from 45 seconds
to 33 seconds.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-03-02 07:13:21 +01:00
Leandro Pereira 816c709ef2 net: sockets: Do not reference NULL pointer with empty frags on start
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 6b3192a572 net: net_app: Close packet if couldn't skip TLS header
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira a53f525830 net: route: Do not dereference NULL pointer while getting next hop
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 5bdb1c2fe7 net: net_pkt: A net_context might have no interface
The code will attempt to dereference the pointer if built on release
mode.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 3cb979a42a net: ieee802154: net_udp_get_hdr() might return NULL
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 561ad8e7c7 net: ipv6: net_icmpv6_get_ra_hdr() may return NULL
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 7fdb0eedc5 net: ipv6: net_icmpv6_get_ns_hdr() may return NULL
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 54c0742fd0 net: ipv6: Remove unused net_ipv6_get_nbr_by_index()
This doesn't appear to be used by anything in Zephyr.  Remove it,
as it doesn't perform correct bounds checking.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira a6a101811b net: ipv6: net_icmpv6_get_na_hdr() may return NULL
If net_icmpv6_get_na_hdr() returns NULL (which is possible with a
specially crafted packet), utility functions net_is_solicited(),
net_is_router(), and net_is_override() will attempt to read invalid
memory.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 6504b2850e net: ip: dhcpv4: Do not try to write to NULL pointer on failure
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Leandro Pereira 7768796a4e net: 6lo: Do not try compressing IPHC header if not set
Assertions should only be used to check invariants.  Things that may
change value in runtime are better left to proper checks.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-03-02 07:11:46 +01:00
Ruslan Mstoi f710fc9443 net: ipv6: Drop ICMPv6 NS if neighbor table is full
This commit fixes the crash of echo_server from NS flood.

Fixes #6393

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-03-02 07:09:50 +01:00
Alberto Escolar Piedras cf07caa3c9 bluetooth: controller: last radio hal changes for simulation
All sideeffects for simulation are there now, including CCM part

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-28 19:56:16 +01:00
Carles Cufi 80210198ad bluetooth: controller: nrf5: Add IC-specific reset function
In order to address anomalies 102, 106 and 107 in nRF52, add a generic
hal_radio_reset() that does additional processing when required by a
particular IC or IC family. Implement the fix for the nRF52.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-02-24 12:33:51 +01:00
Ruslan Mstoi b7ef393bfe net: ipv6: Drop ICMPv6 packet if NA header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 NA packet.

Fixes #6315

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-23 09:13:10 +02:00
Paul Sokolovsky ec207f4250 net: app: Move mbedTLS debug log level config to mbedTLS Kconfig
mbedTLS log level is obviously a mbedTLS config setting. It makes
sense to have it defined in mbedTLS Kconfig, and different parts
of Zephyr to reuse as needed (e.g. net-app vs upcoming TLS wrapper
for sockets).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-22 18:44:55 -05:00
Christopher Collins f31245d365 subsys: dfu: boot: Remove unused ver query code.
Duplicate code to query was mistakenly added in commit
2ad7ccdb2d.  This code is redundant; the
existing `boot_read_bank_header()` function can read the version from
both image banks.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-21 18:53:42 -05:00
Jukka Rissanen 7fc5ffa92b net: shell: Fix net mem command output
Pool size is no longer available so it is no use trying to print
its value. This change was introduced in commit dd09cbc1c4
("net: buf: Redesigned API with split data and meta-data")

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-21 11:05:19 +02:00
Christopher Collins 3986ef2770 subsys: mgmt: CMake and Kconfig support.
Add the necessary CMakeLists.txt and Kconfig files for the mgmt
subsystem.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins d14b1aca62 mgmt: Bluetooth transport for SMP (mcumgr).
Add a Bluetooth service dedicated to transporting mcumgr SMP requests
and responses.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins 14735116d1 subsys: mgmt: UART transport for SMP (mcumgr).
Add a UART driver dedicated to transporting mcumgr SMP requests and
responses.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins 76bf5646d5 subsys: mgmt: Shell transport for SMP (mcumgr).
Enable the shell to transport mcumgr SMP requests and responses.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins 6721d64735 subsys: mgmt: SMP protocol for mcumgr.
The Simple Management Protocol (SMP) is a basic protocol that sits on
top of mcumgr's mgmt layer.  This commit adds the functionality needed
to hook into mcumgr's SMP layer.

More information about SMP can be found at:
`ext/lib/mgmt/mcumgr/smp/include/smp/smp.h`.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins 2ad7ccdb2d subsys: dfu: boot: mcuboot: Query current img ver
Allow a running image to query its own version number.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Christopher Collins 7b27fa6d5a subsys: dfu: boot: Allow inspection of boot state.
Exposes the operation that MCUboot will perform on the next reboot
(e.g., stay on current image, swap to alternate image, etc.).

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-20 22:07:52 +01:00
Johan Hedberg 1e159de848 Bluetooth: Mesh: Use a single transmission from Friend to LPN
As per TSE 10009 the TS will enforce that a Friend ever only uses a
single transmission when sending packets to an LPN. Make sure that our
implementation follows this.

https://www.bluetooth.org/tse/errata_view.cfm?errata_id=10009

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-20 17:22:23 +02:00
Ruslan Mstoi 76b262cae2 net: pkt: Fix comment typo in word fragment
Fix comment typo in word fragment

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-20 09:58:23 -05:00
Ruslan Mstoi 9f376407c0 net: ipv6: Drop NS packet if LL address is too long
This commit fixes the crash of echo_server from overflow in ICMPv6 NS
source link-layer address option.

Fixes #6235

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-20 16:54:47 +02:00
Vinayak Kariappa Chettimada b55e7b784c Bluetooth: controller: Use RADIO_TIES_US to define inter event space
Use RADIO_TIES_US to define minimum inter event space
between concurrent master and slave roles below which it
will be detected as a probable drift towards each other
leading to them overlapping on each other.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-20 15:34:55 +01:00
Ravi kumar Veeramally 5490d28d8c net: app: Fix issue while configuring local context
When IPv6 and IPv4 both are enabled and net_app acting as a client,
configuring local context has one glitch.

After selection of IPv6 context as a default context  function
should return immediately, otherwise it continue to select IPv4
context as default context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-20 14:50:39 +02:00
Ravi kumar Veeramally 88e8119078 net: app: Fix connection closure issues with net_app_ctx
In case of TCP and node acting as a APP_SERVER it can have multiple
concurrent connections. Calling close callback when there are still
active connections exists, causing an issue.

e.g. When a node acting as a HTTP server and can support multiple
TCP connections. Let's say one of the connection is in closing
state and the rest are still in active state. net_app_ctx is
calling close (http_closed) callback of registered upper layers.
HTTP assumes all the connections are closed and unref all the
connection related stuff.

Call the close callback only when there are no active connections.
Patch has also moved TCP stuff under one #ifdef.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-20 14:50:39 +02:00
Jukka Rissanen 023628f3d7 net: Set net_buf alloc timeout for IPv4 ARP and IPv6 ND
Instead of having K_FOREVER when allocating a packet in IPv4 ARP
and IPv6 ND, set a timeout so that we do not have a case where we
would wait net_buf forever.

Fixes #5484

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-20 14:31:39 +02:00
Luiz Augusto von Dentz ec6188bc06 net: bt: Call net_if_carrier_down when disconnected
If IPSP channel is disconnected call net_if_carrier_down instead of
net_if_down since the later may still attempt to send packets while the
former just discard them immediatelly.

Fixes #5317

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-19 14:46:33 +02:00
Luiz Augusto von Dentz 656bab0361 net: Introduce net_if_carrier_down
This introduces net_if_carrier_down so the L2 driver can inform when it
has lost connectivity so all packets shall be flushed and the interface
should be put down.

Fixes #5317

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-19 14:46:33 +02:00
Leandro Pereira 517df4d73c subsys: net: http: Send "Internal Server Error" on unknown error code
Avoid using an uninitialized pointer when adding headers to the HTTP
context.

Coverity-CID: 178792
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-02-19 10:37:57 +02:00
Leandro Pereira 02dc6eb960 subsys: fcb: Check for mutex lock failure when walking FCB
Coverity-CID: 182195
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-02-17 09:14:16 -05:00
Andy Ross 6eef2f1485 misc: Add a FORCE_NO_ASSERT kconfig directive
The mbedtls test is hitting a compiler bug where two subtests will
soft fail on qemu_xtensa when assertions are enabled.  This is despite
the fact that:

+ The failure is entirely internal to the mbedtls suite.
+ The mbedtls code does not use zephyr asserts
+ The mbedtls code does not call into zephyr code that might assert.
+ The behavior persists even when an irq_lock() is held across the
  entire test, ruling out any asserts in interrupt/exception context.
+ And EVEN WHEN the mbedtls library blobs are bytewise identical
  between assert and non-assert cases.

The bug seems to be a layout thing where the mbedtls code behavior
differently based on code address and/or link-time optimizations
(xtensa has a few).

Unfortunately sanitycheck enables assertions by setting CFLAGS
directly and not via kconfig, so we can't fix this by turning the
feature off in an app right now.  This patch adds a simple "override"
flag that can be set by apps like this that hit bugs.

Again, note that zephyr assertions are not used nor needed by this one
test.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Vinayak Kariappa Chettimada 7fa2c4dfac Bluetooth: controller: Add missing HCI supp. cmd bits for PHY Update
Added missing HCI Supported Commands bit fields for PHY
Update feature. Also, refactored with missing conditional
compilation for other bit fields.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 11:46:21 +01:00
Ruslan Mstoi d35cc75d2d net: icmpv6: Drop ICMPv6 packet if NS header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 NS packet.

Fixes #6217

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-16 09:22:38 +02:00
Vinayak Kariappa Chettimada ae03e35d6c Bluetooth: controller: Fix incorrect master role scheduling
Revert incorrect calculation introduced in
commit ec5a787da2 ("Bluetooth: controller: Fix multiple
master role event scheduling") and revert a related
incorrect fix in commit a02606cbf9 ("Bluetooth:
controller: Fix missing ticks to us conversion").

Fixes the controller assert in ctrl.c line number 1477. A
64-bit arithmetic took ~35 us in Radio ISR for nRF51 causing
the ISR to take too much time before packet buffer could be
set.

Also, fixed master scheduling by correctly accounting for
the jitter between each master event.

Relates to: #5486

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 067ac68f0b Bluetooth: controller: Fix XTAL_ADVANCED threshold detection
Fix incorrect calculation of unreserved timespace which
should take into account the ticks_slot of current event,
and compensation for any reduced prepare in the current
event as well as in the next event.

This regression relates to the commit ad7c9d3d76
("Bluetooth: controller: Improved continuous scanning")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 1433475b29 Bluetooth: controller: Define HAL_TIMER_SIGN_BIT
Define a macro HAL_TIMER_SIGN_BIT to correspond to the most
significant bit support by counter hardware used by ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Vinayak Kariappa Chettimada 8f5e96a1b7 Bluetooth: controller: Use XON_BITMASK instead of BIT(31)
Use XON_BITMASK define instead of raw BIT(31) or bit shift
operations in code to represent use of reduced prepared by
an event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-16 07:29:12 +02:00
Anas Nashif 8949233390 kconfig: fix more help spacing issues
Fix Kconfig help sections and add spacing to be consistent across all
Kconfig file. In a previous run we missed a few.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-15 23:20:55 -05:00
Vinayak Kariappa Chettimada 1bda83af1c Bluetooth: controller: Fix to use random CRC init value
Fixed controller implementation to use random CRC init value.

Fixes #6204.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Vinayak Kariappa Chettimada 499baff333 Bluetooth: controller: Reuse safer bt_rand in thread call path
Reuse the thread safe bt_rand() interface in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-15 21:15:21 +01:00
Johan Hedberg 294c68d087 Bluetooth: SMP: Send Pairing failed if there's no key space
If there's no more room to store new pairings, send a proper error
instead of letting the SMP timeout expire.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 20:54:50 +02:00
Johan Hedberg c9097a9346 Bluetooth: Mesh: Declare seg_rx_buf_data as __noinit
This is a fairly large buffer, and there's no need to initialize it to
zeroes at boottime.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 10:58:24 +02:00
Johan Hedberg 05884c7f18 Bluetooth: Mesh: Split proxy client buffer payload into separate array
This makes things slightly cleaner, and we don't need to rely on the
deprecated net_buf_simple_init() API (which was a bit hackish for
these custom-constructed net_buf_simple objects anyway).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-15 10:58:24 +02:00
Christopher Collins 821dc37f3f subsys: storage: flash_map: Fix warning
Prior to this commit, `flash_area_layout()` was being passed a pointer
to the incorrect type (`uint32_t *` where `int *` was expected).  This
caused the following warning to be reported:

```
[...]/subsys/storage/flash_map/flash_map.c: In
function 'flash_area_get_sectors':
[...]/subsys/storage/flash_map/flash_map.c:191:32:
warning: passing argument 2 of 'flash_area_layout' from incompatible
pointer type [-Wincompatible-pointer-types]
  return flash_area_layout(idx, cnt, ret, get_sectors_cb, &data);
                                ^~~
[...]/subsys/storage/flash_map/flash_map.c:136:12:
note: expected 'int *' but argument is of type 'uint32_t * {aka long
unsigned int *}'
 static int flash_area_layout(int idx, int *cnt, void *ret,
            ^~~~~~~~~~~~~~~~~
```

This commit changes the argument type to `u32_t` for both functions.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-14 14:36:52 -05:00
Mariusz Skamra daa8040e2f Bluetooth: Mesh: Ignore segments of cancelled message
This fixes the issue when after incomplete timer expiration
host sent ACK.
The host failed in two cases:
1. Sending ACK right after the incomplete timer expiration;
2. Sending ACK from new RX context. Now, seq_auth of cancelled
message is not cleaned on RX reset, so segments of cancelled message
will be discarded when resend.

According to the Mesh Profile v1.0
"When the incomplete timer expires, the lower transport layer
shall consider that the message being received has failed and
cancel the acknowledgment timer. Any segment of a canceled
message shall be ignored."

Fixes #6023

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-02-14 17:53:37 +02:00
Ruslan Mstoi c78a1227ff net: icmpv6: Drop ICMPv6 packet if ICMP header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv6 packet.

Fixes #6197

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-14 17:44:29 +02:00
Johan Hedberg 6b3d2935f4 Bluetooth: Mesh: Fix sending Provisioning Failed for PB-GATT
In the case of an unexpected PDU we need to send the right response.
This was already taken care of for PB-ADV, but not for PB-GATT.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg 4f47bc3611 Bluetooth: Mesh: Resend Link Acknowledgment when necessary
The Provisioner might have missed our earlier Link Acknowledgement, so
if we receive another one with matching Link ID and link.expect state,
simply send another acknowledgement.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg 27e1c4fbb2 Bluetooth: Mesh: Fix handling of failed transmissions
When sending a segmented message, the state could get stuck if the
advertising bearer fails in transmitting and we don't detect that it
happened. Add a send_start callback for all packets so we can always
know if sending fails.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Johan Hedberg 6379da2a09 Bluetooth: Mesh: Fix NULL pointer access with PB-ADV
When both PB-ADV and PB-GATT are enabled, the PB-ADV code (prov.c)
uses the bt_mesh_proxy_get_buf() API to get a net_buf_simple buffer.
Unfortunately this function also suffers from the same issue that was
fixed by commit 2b273444c1.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 11:43:34 +02:00
Michael Scott 086893fc55 net: app: client: set remote port after DNS lookup
In net_app_init_client(), the remote port is set after an initial
set of checks based on the remote_addr's assigned family.

However, if the peer_addr_str is a host name which needs to be
resolved via DNS, the family won't be set yet, and the port is
left as 0.

To fix this behavior let's move the port assignment after the
DNS lookup section to be sure that the remote sa_family is set.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-14 09:40:01 +02:00
Tomasz Bursztyka 47e45c52a1 net: buf: Support allocation of a net_buf pointing to external buffer
Difference being that the data is not, then, allocated from the pool.
Only the net_buf is.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-02-13 16:46:32 +02:00
Ruslan Mstoi b743f98896 net: icmpv4: Drop ICMPv4 packet if ICMP header is NULL
This commit fixes the crash of echo_server from malformed
ICMPv4 packet.

Fixes #6081

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2018-02-13 16:05:25 +02:00
Johan Hedberg 2b273444c1 Bluetooth: Mesh: Fix NULL pointer access with GATT Proxy
The conversion to the new net_buf_simple API was done incorrectly
here. The buffer initialization should use net_buf_simple_init()
instead of net_buf_simple_reset(), so that buf->__buf gets properly
initialized (and not left pointing at NULL).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 15:03:34 +02:00
Johan Hedberg abc20e7eae Bluetooth: Introduce dedicated TX fragment pool
There's a risk of a deadlock if we use the same pool for ACL fragments
as we use for general ACL TX buffers: all TX buffers are queued up,
and we try to segment one of them, a segment buffer will never become
available. To work around this risk, introduce a dedicated fragment
pool.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 14:49:52 +02:00
Vinayak Kariappa Chettimada 4c123a5162 Bluetooth: controller: Refactor ticker integration into hal
Refactor ticker execution context dependency out into HAL
folder. This decouples ticker from mayfly, enabling porting
towards a more tasklet (if and when kernel gets the support)
style execution contexts type implementation support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-13 13:26:37 +01:00
Johan Hedberg ac1360f0a7 Bluetooth: Mesh: Convert to new net_buf_simple APIs
Convert the mesh code to use the new net_buf_siple APIs. This has the
benefit of saving 4 bytes off the stack due to the not needed pointer.
Also update the publication context helpers to map to the new
net_buf_simple API in an intuitive way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-13 14:00:08 +02:00
Ravi kumar Veeramally 18422de8da net: tcp: Provide local address in TCP reset message preparation
If context is bound to IPv6 unspecified addresss and some port
number, then unspecified address is passed in TCP reset packet
message preparation. Eventually packet dropped at the peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally 1f20111ef3 net: tcp: Do not handle packet re-transmission in TCP ACK
Zephyr doesn't have luxury to create re-transmit timer per packet. So
it has different methods to handle packets in queue. But re-sending
packets on valid ack messages causing issues.

E.g. A TCP node sent two packets (packet-1, packet-2). Peer replied
two ACKs (ACK-1 and ACK-2), and these two ACK's are at rx_thread
queue. Now ACK-1 is handled and reference of packet-1 is freed
from sent list. Then if condiftion (valid ACK and connection
state is ESTABLISHED) notices that, sent list is not empty.
Restart the timer, modify sent flag and resend packets in a
list. Here packet-2 is sent again, even though ACK-2 is already
received. Situation is worse if there are more packets in the
list.

So only start the re-transmit timer in-case queue is not empty. It
allows rx_thread to handle all incoming packets (in this e.g ACKs).
When the re-trasmit timer expires, it sends the packets which
are left in queue.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally e059e8b379 net: context: Handle failure case of tcp backlog entry
In case of failed to get source address from the net packet,
release the assgined tcp backlog entry. Otherwise it will
never be freed.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Ravi kumar Veeramally 7dc72c3ca6 net: context: Remove duplicate call
k_delayed_work_cancel(&context->tcp->fin_timer) called twice
immediately one after other.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-13 13:37:20 +02:00
Luiz Augusto von Dentz 800bfaf9a7 Bluetooth: UUID: Remove macros defining 16 bit values
Application should normally declare a bt_uuid with proper type and then
use bt_uuid_cmp.

Fixes #5162

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-02-13 13:33:48 +02:00
Robert Chou 6f466cd7e5 net: coap: retransmission for four times
RFC 7252, sec 4.8 [https://tools.ietf.org/html/rfc7252#section-4.8]
The default MAX_RETRANSMIT is 4, current implementation only
retry 3 times. Update next_timeout() to return one more retry.

Also, add a TODO for random generated initial ACK timeout

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-13 13:06:15 +02:00
Paul Sokolovsky ede25c12a3 net: sockets: getaddrinfo() buffer overflow, etc. fixes
The existing implementation assumed DNS resolv callback will be
called just once, but that's not always the case (apparently,
for multi-homes hosts or something). So, apply array bounds
checking (and do pointer arithmetic only after it, as the C
standard otherwise warns of "undefined behavior"). In such a case,
the port number wasn't set in each entry too, so rework how it's
done.

The issues discovered while resolving archive.ubuntu.com.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-12 20:17:26 -05:00
Anas Nashif ff42bdd0a0 debug: remove option GDB_INFO
This feature is X86 only and is not used or being tested. It is legacy
feature and no one can prove it actually works. Remove it until we have
proper documentation and samples and multi architecture support.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-12 13:58:28 -08:00
Vinayak Kariappa Chettimada 4eedb5067f Bluetooth: mesh: Account for scan window delaying adv events
New advertising started while scanning is already enabled
would delay the first advertisement event until the end of
the current overlapping scan window in the Zephyr native BLE
controller implementation. Hence, consider this scan window
duration when calculating the advertising stop.

Relates to: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada af13d6d581 Bluetooth: controller: Fix soft latencies in periodic ticker
Fix, add the missing code for the removal of any accumulated
soft latencies or negative drift ticks when scheduling next
interval expiry with added laziness.

Typically a first interval would accumulate soft latencies
and this has to be removed if the interval is rescheduled
with any added laziness (scheduled to the next soft real
time interval).

Example, scan windows block any new scheduling until the end
of the window, adding latencies to any soft real time ticker
expiry which should try to execute as early as possible after
the scan window.

Fixes: #6083

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada 57e49b1f03 Bluetooth: controller: Refactor BT_CTLR_ADV_INDICATION feature
Refactor BT_CTLR_ADV_INDICATION feature by moving the
implementation closer to the implementation that is closing
the advertisement event so that in the future new members
can be added as necessary (example, advertised channels).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Vinayak Kariappa Chettimada baf05409f8 Bluetooth: controller: Fix BT_CTLR_XTAL_ADVANCED cond. compilation
Fix compile warnings when BT_CTLR_XTAL_ADVANCED Kconfig
option is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-12 12:13:38 +02:00
Johan Hedberg 5ded8d8d49 Bluetooth: Remove useless BT_L2CAP_TX_USER_DATA_SIZE Kconfig variable
No one was setting this to any other value than its default, which
happens to be the same as BT_BUF_USER_DATA_MIN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg c14c2692e2 net: buf: Set default user data size to 4
Since all in-tree users are good with 4 bytes of user data, reduce the
default to 4. Also fix the default and rage values where apparently
'0' and '8' had been swapped.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg 0ad6dbd80d Bluetooth: Move HCI command buffer user data into separate array
The HCI command buffers are the only ones with more than 4 bytes of
required user data. Move the user data into a separate array and do
the mapping with the help of net_buf_id(). After this, it will be
possible to reduce the default net_buf user data size from 8 to 4.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-12 09:48:32 +02:00
Johan Hedberg a7518ba30f Bluetooth: Mesh: Fix coverity warning with unchecked error return
This fixes Coverity CID 182769.

Fixes #6102

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 21:38:02 +02:00
Vinayak Kariappa Chettimada a152109eb1 Bluetooth: controller: Fix nRF52840 radio timings for Coded PHY
Fix incorrect radio timing for Tx chain delay for S2 and S8
coding. Regression introduced  in commit 55d3ce111c
("Bluetooth: controller: Refactoring nRF5 radio driver").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-11 20:33:02 +01:00
Johan Hedberg d5f27b70cc Bluetooth: Remove bogus return statements for BR/EDR connections
Having these in the beginning of a switch statement without any case
statement makes no sense.

Fixes #6135

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 18:29:57 +02:00
Johan Hedberg 7aeb1fa136 net: buf: Remove incorrect dependency for NET_BUF_POOL_USAGE
NET_BUF_POOL_USAGE was never supposed to depend on NET_BUF_LOG.

Fixes #6127

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 13:37:09 +02:00
Johan Hedberg 5008ec7a06 net: buf: Introduce variable data length allocators
Introduce two new "standard" data allocators to net_buf. There are now
three in total:

NET_BUF_POOL_FIXED_DEFINE: This is the closes to the old
implementation, i.e. fixed size chunks.  It's also what the old
NET_BUF_POOL_DEFINE macro maps to.

NET_BUF_POOL_HEAP_DEFINE: uses the OS heap

NET_BUF_POOL_VAR_DEFINE: defines a variable sized allocator using
k_mem_pool (this is all that there was in my first draft of this
feature)

Currently the variable length allocators (HEAP & VAR) support
reference counted data payloads, i.e. cheap cloning. The FIXED
allocator does not currentlty support this to allow for the simplest
possible implementation, but the support can be added later if
desired.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Vinayak Kariappa Chettimada 18f366ca07 Bluetooth: controller: Fix disabling of Coded PHY feature
Fix conditional compilation in nRF5 radio interface so that
when Coded PHY feature is not selected then it does not use
the PPIs required for supporting the feature.

This will allow pwm_nrf5_sw driver to use PPI channels 14 to
19 and support 3 PWM channels. Without the Coded PHY feature
disabled, only PPI 14, 15, 18 and 19 are available for PWM.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-09 14:41:44 +01:00
Ravi kumar Veeramally b22ab26b10 net: app: Add a new API to get net pkt based on dst
Added a new API to get net pkt based on dst address. Destination
address will be used to find correct net_context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally 09b361deed net: app: Fix get_server_ctx helper function
When net_app_ctx has multiple net_contexts, selecting net_context
based on dst address has some glitches.

E.g. One net_app_ctx and two net_contexts (net_ctx1, net_ctx2).
     Both net_contexts are mapped to net_app_ctx.
     When a caller looking for net_ctx (e.g. net_ctx2) with
     matching dst address. Loop goes through net_ctx1 and dst
     doesn't match. But another if condition checks does this
     net_context mapped to net_app_ctx, yes it matches.
     So return net_ctx1, which is wrong.

So first go through all elements in array of net_contexts for
matching dst address, if it fails to find then go for matching
net_app_ctx.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally 0055e007d0 net: if: Provide a Kconfig to select default network interface
Default network interface is the first interface if there are multiple
interfaces exist. But this creates an issue when different parts of
the network subsystem wants to choose particular default interface.
At-least with this Kconfig option user can select default network
interface.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:44:15 +02:00
Christopher Collins aa8850b42a subsys: storage: flash_map - Use correct macro
Prior to this commit, the old `FLASH_DRIVER_NAME` macro was being used
in the definition of the flash drivers array.  This caused the array to
have a size of 0.

This commit changes the code to use the newer `FLASH_DEV_NAME` macro,
causing the configured flash device to be present in the table.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-08 23:29:23 -05:00
Michael Scott 83978e6264 net: lwm2m: add max device power source config option
The code in the LwM2M "Device" object was checking for this max
power source config value, except that it was never added as a
Kconfig option.  Let's go ahead and add it so apps can set the
value appropriately.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:49:01 +02:00
Michael Scott c1e180b6ee net: lwm2m: return NOT_FOUND for unused multi-value resources
When attempting to read an unused multi-value resource such as
"Available Power Sources", lwm2m client return a successful coap packet
w/o any values.  This looks like a timeout to any lwm2m servers which
make sure a valid response is returned.

Let's fix this by returning the correct NOT_FOUND error code instead.

NOTE: To test this I commented out the portion of the lwm2m client
sample which initializes the LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT and
LWM2M_DEVICE_PWR_SRC_TYPE_USB values.  By default, the sample will
setup dummy values to be returned by the client.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-02-08 09:48:45 +02:00
Robert Chou 228bf05af6 net: lwm2m: update internal API select_writer() and select_reader()
As per review of PR #5893, this is a follow up patch to update
select_writer() API to match the behavior of select_reader() API.

Quote from OMA-TS-LightweightM2M-V1_0_1-20170704-A. 8.2.5
"An Object Instance or Resource is Read by sending a CoAP GET to the
 corresponding path. The response includes the value in the
 corresponding Plain Text, Opaque, TLV or JSON format according to
 the specified Content-Format (see section 6.4).The request MAY
 specify an Accept option containing the preferred Content-Format
 to receive. When the specified Content-Format is not supported by
 the LwM2M Client, the request MUST be rejected."

Therefore, we do not attempt to assign a content-format when the
requested one is not supported. Instead, we return an error code.

0 is returned when reader or writer has been successfully selected by
select_reader() or select_writer()

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-07 22:12:48 -05:00
Andrzej Puzdrowski b3614c0b17 subsys: fs: fcb: remove f_area_id from fcb structure
It is faster to operate directly on flash_area pointer instead
of fetch it all the time using the fcb flash area id.
Also as f_area_id was needed only for get appropriate flash_area
pointer, so it is better to pass it only while initialization
the fcb and not store it in fcb instance data at all.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-02-07 09:51:26 -05:00
Andrzej Puzdrowski 95a9dbc4b3 subsys: fs: fcb: rework fcb_walk and its callback
Previously flash_area structure was the parameter for the callback
function for transferring sector location info.
Now flash_sector is used so relevant flash_area is missing for
the callback.

This patch introduces structure fcb_entry_ctx which incorporates
entries' location and relevant flash area. It is used to pass complete
information to the callback. Additional  pointer to the flash_area fcb
speeds up operations.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-02-07 09:51:26 -05:00
Christopher Collins e3cd915d8f fs: Convert FCB to use sectors (not areas)
Prior to this commit: `struct fcb` contained a pointer to an array of
`struct flash_area`.  Each entry in the array represented a flash sector
that the fcb comprised.

After commit: `struct fcb` contains a pointer to an array of `struct
flash_sector`, not `struct flash_area`.

Rationale: The FCB needs to know which sectors it occupies for its
rotate operation.  However, the `flash_area` type is meant to represent
a collection of sectors, not a single sector.  `struct flash_area`
contains information that the fcb does not need (e.g., area ID and
device ID).  Furthermore, the flash_map API provides a means of
converting a flash area ID to an array of sectors
(`flash_area_get_sectors()`), but no way to convert to an array of
areas.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Christopher Collins ffc90dd496 subsys: storage: flash_map - Remove some code duplication
This patch cleans up flash_map code.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Christopher Collins ffef30d39a storage: flash_map - Fix typo
get_flah_dev_from_id --> get_flash_dev_from_id

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Ding Tao 75a3590d20 fs: Kconfig: Fix warning on undefined choice NO_FILE_SYSTEM
Fix this by replace "NO_FS" with "NO_FILE_SYSTEM".

Signed-off-by: Ding Tao <miyatsu@qq.com>
2018-02-07 08:35:29 -05:00
Vinayak Kariappa Chettimada f54f2ceb95 Bluetooth: controller: Rename a microsecond variable
Rename incorrectly named variable storing microseconds, from
ticks_slot to slot_us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 12:26:34 +01:00
Vinayak Kariappa Chettimada a02606cbf9 Bluetooth: controller: Fix missing ticks to us conversion
Fixed a missing ticks unit to microsecond unit conversion
potentially caused incorrect window offsets being used while
establishing connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada 978652e7b5 Bluetooth: controller: Remove redundant whitespace
Removed redundant whitespace when dereferencing struct
members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:57:26 +01:00
Vinayak Kariappa Chettimada bb84be2c5c Bluetooth: controller: Fix ticker to use u32_t ticks_slot
ticker timespace reservation can range up to 10.24 seconds,
needing 19-bits to represent in 32KHz clock units. Hence,
fix controller implementation to use u32_t to store ticks
slot values.

Without this fix, the controller is asserting in scan_adv
sample when using continuous scanning with 2 second interval
and window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:48:27 +01:00
Vinayak Kariappa Chettimada ad7c9d3d76 Bluetooth: controller: Improved continuous scanning
Refactored the high frequency clock preparation advanced
feature to improve radio utilization during continuous
scanning.

The inter-event timespace value now considers the reserved
timespace while determining if the high frequency clock
will be retained. This reduces the preparation time, hence
increased radio use inside scan window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:23:10 +01:00
Vinayak Kariappa Chettimada fa724b2bba Bluetooth: controller: Refactor invalid ctrl PDU handling
Refactor the invalid control PDU handling so as to reuse the
switch-case and hence, reduce code size and CPU time used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-07 11:20:48 +01:00
Erwan Gouriou c734c2972f flash: remove obsolete FLASH_DRIVER_NAME
Replace seldom occurrences of FLASH_DRIVER_NAME by equivalent
and commonly used FLASH_DEV_NAME.

Fixes #5919.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-02-06 11:48:53 -06:00
Vinayak Kariappa Chettimada 8f239cd363 Bluetooth: controller: Rename radio_*_is_enabled to ll_*_is_enabled
In preparation towards a refactored controller, rename the
old radio_*_is_enabled() function to ll_*_is_enabled().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-06 10:49:25 +01:00
Vinayak Kariappa Chettimada 122a644d03 Bluetooth: controller: Fix handling of invalid Ctrl PDU lengths
Fix the controller implementation to handle Control PDUs
with invalid lengths by responding with Unknown Response
PDU.

Fixes LL.TS.5.0.2 conformance tests:
LL/PAC/SLA/BI-01-C [Control PDUs with Invalid Length from
	Master]
LL/PAC/MAS/BI-01-C [Control PDUs with Invalid Length from
	Slave]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 2800a9cb27 Bluetooth: controller: Minor cleanup of macros
Removed redundant macro definitions and rearranged code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 947bcba3d3 Bluetooth: controller: Use shorter (void *) for typecasts
Refactor and clean up code to use (void *) typecasts
consistently.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 4cd9ba7813 Bluetooth: controller: Use anonymous structs and unions in PDUs
Take advantage to cleanup code by using anonymous struct and
union definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada b7819ccab6 Bluetooth: controller: Add missing PDU struct definitions
Add missing PDU struct definitions in pdu.h file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada b521d50adc Bluetooth: controller: Refactor pdu_adv_payload_* to pdu_adv_*
Refactor PDU type names pdu_adv_payload_* to a shorter
pdu_adv_* struct names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada c4ba30cb1a Bluetooth: controller: Cleanup radio_pdu_node_rx/tx variables
Cleanup the use of long radio_pdu_node_rx and
radio_pdu_node_tx variable to shorter node_rx and node_tx
names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada fe0cebedcf Bluetooth: controller: Refactor phy req/rsp PDU struct
Refactor the pdu_data_llctrl_phy_req_rsp struct into
pdu_data_llctrl_phy_req and pdu_data_llctrl_phy_req structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Vinayak Kariappa Chettimada 9abf8ce0a0 Bluetooth: controller: Refactor length req/rsp PDU struct
Refactor the pdu_data_llctrl_length_req_rsp struct into
pdu_data_llctrl_length_req and pdu_data_llctrl_length_req
structs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:48:37 +01:00
Ioannis Glaropoulos d09baafe64 Bluetooth: controller: inline implementation of radio-enable-on-tIFS
This commit implements a minor refactoring of the implementation
for enabling the Radio on TIFS expiration. It inlines a function
that is defined in the local radio_nrf5_ppi header file.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 2764084561 Bluetooth: controller: implement sw-switch with the event timer
This commit contributes the implementation of the sw-switch for
tIFS in nRF5 Radio using the EVENT_TIMER instead of a dedicated
TIMER instance. A Kconfig configuration is added so the user can
select whether to use the EVENT_TIMER for the tIFS switch or use
a dedicated TIMER instance.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 0ec1095dd6 Bluetooth: controller: sw-switch with the event timer (prepare commit)
This commit implements minor refactoring of radio.c and ctrl.c,
to prepare for adding the implementation of sw-switch based on
the event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 9c4dc04ba5 Bluetooth: controller: conditionally reuse CC for ISR profiling
This commit adds the option of conditionally reuse an existing
CC register of the event timer for timer sampling used in ISR
profiling, in case SW tIFS switching is implemented based on the
event timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Ioannis Glaropoulos 2a85dda206 Bluetooth: controller: symbolic name for CC used in ISR profiling
This commit adds a symbolic name for the event timer
CC offset that is used to sample the event timer during
ISR profiling.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Vinayak Kariappa Chettimada d4cc46c453 Bluetooth: controller: refactor radio_nrf5* headers
Refactor radio_nrf5* header files to group together
definitions and have less #if-#else-#endif.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-05 16:25:41 +01:00
Marti Bolivar e2c9be1a18 dfu: mcuboot: add boot_read_bank_header()
This is an accessor function for the MCUboot image header of an image
bank. The interface may seem a little cumbersome, but it is
future-proof against MCUboot feature and incompatible header version
changes.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar 01aa12bffd dfu: mcuboot: add boot_is_img_confirmed()
Applications chainloaded by MCUboot may want to change their behavior
based on whether or not they are confirmed.

Here are some examples:

  - performing a built-in self test (BIST) if the image is not yet
    confirmed, and marking it OK if it passes (this enables reverting
    to an older working image if the BIST fails, and allows future
    resets to skip the BIST if it passes to improve boot time)

  - interacting with persistent metadata related to image state on
    other flash partitions during test upgrades (these are required in
    cases when the update source provides runtime metadata, such as
    monotonic counters, related to an upgrade attempt which must be
    used to report results)

To enable these use cases, add boot_is_img_confirmed(), which reads
the "image OK" field for the current firmware image and returns true
if and only if it is set.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar 4877dd22ea dfu: mcuboot: delete misleading comment
There is more information in the trailer than indicated by this comment.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Marti Bolivar 389060fb00 dfu: mcuboot: don't use magic when confirming image
The current implementation of boot_write_img_confirmed() does not
write the image OK byte in flash bank 0 if the magic "request upgrade"
bytes in that bank are "good". This is not robust behavior.

The MCUboot design document has this to say about the image OK byte:

   Upgrading an old image with a new one by swapping can be a two-step
   process. In this process, mcuboot performs a "test" swap of image
   data in flash and boots the new image. The new image can then
   update the contents of flash at runtime to mark itself "OK", and
   mcuboot will then still choose to run it during the next boot.

   [...]

    4. Image OK: A single byte indicating whether the image in this
       slot has been confirmed as good by the user (0x01=confirmed;
       0xff=not confirmed).

This says nothing about the magic bytes, so it'd be better not to make
assumptions about their effect here.

Further, MCUboot itself does not use the magic field when marking the
only known-good image on flash "OK" after either reverting a failed
upgrade or refusing to boot an upgrade iamge with an invalid
signature: instead, it unconditionally ensures the Image OK byte is
set to 0x01.

For consistency with MCUboot's design and implementation, remove the
lines that look at the magic bytes from boot_write_img_confirmed().

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-02-05 06:42:15 -08:00
Johan Hedberg 2ff98636a5 Bluetooth: Mesh: Add support for OOB info and URI in provisioning data
Until now the OOB info and URI fields in unprovisioned beacons were
generally ignored by the implementation. Add fields for these to
bt_mesh_prov and make sure to take them into account when encoding
advertising data, both for PB-ADV and PB-GATT. For PB-ADV the URI goes
out in a separate beacon, whereas for PB-GATT it is placed in the scan
response data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-05 12:46:05 +02:00
Robert Chou 54d7207e09 net: lwm2m: check content-format and respond with error if not support
Currently, we always set the content-format as "plain/text" when
it is unrecognized. This is wrong for it's possible that payload
is actually something else.

For example, we don't support JSON as incoming format right now.
But if I send a PUT request to /1/0/1 (server objectinstance/lifetime
resource) with value 3200 in JSON format: {"e":[{"n":"","v":3200}]}.
The client will still handle the request and respond with changed (2.04)
except the lifetime resource is updated incorrectly due to parsing
error.

Correct the behavior by not setting a default format and respond with
content-format-not-support error code (4.15)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-02-05 09:05:00 +02:00
Alberto Escolar Piedras bfabdf1de5 shell: Added noprompt command
Added noprompt command to shell. It will disable printing
the prompt.
For the native port, when feeding commands from a file or
pipe the prompt reprinting after each command (without echoing)
just confuses the user.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Alberto Escolar Piedras e3f727cc6e native: added stdin handling for shell
Now the native console driver also handles stdin
so we can drive the shell from the command line,
a pipe or a file

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-02 07:48:46 -08:00
Ravi kumar Veeramally 9489fa54cc net: http: Fix http_prepare_and_send
net_pkt_append() has been changed. If payload reached max value
of 'data_len' in net packet, net_pkt_append will not append.
So the caller has to create new packet and append remaining payload.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally d6ca4decea net: Unlink the neighbor after unref
Unlinking of neighbor also needed after nbr_unref. Otherwise
neighbor id is still in use and can not be linked further.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 82f23bc276 net: rpl: Fix handling of DAO message
When a node receives DIO message from peer then node adds peer as
a neighbor (nbr with linklayer address). But when a node receives
DAO message from different peer (chances are peer selected
different route to reach this node), remove peer with previous
link layer address and add as a neighbor with new link layer address
with new route information. Now node can properly route packets to
peer from neighbor table or based on nexthop information from
routing table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 6245dd68d9 net: rpl: Ignore parents with lower rank
When a node joins in DAG network, it chooses neighbor (node or border
router) as its parent. But if it receives DIO message from another
peer, it can only act as a neighbor, not as a parent. If peer rank
is better than current preferred parent rank then node will select
new peer as it's best parent.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally cfc8749133 net: rpl: Fix debug information and alignment issues
RPL prints lot of debug information which is difficult to track.
Minimized debugs in timer specific information and parsing of
DIO and DAO options. Also fixed alignment issues (no changes in
functionality)

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally ebf56ed1a6 net: mgmt: Fix mgmt push event
Do not even consider the push event if CONFIG_NET_MGMT_EVENT_INFO
enabled and info length is more than NET_EVENT_INFO_MAX_SIZE.
Print error message and ignore the event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally ed2fcaeb8a net: rpl: Change default value for NET_RPL_INIT_LINK_METRIC
Current default value for NET_RPL_INIT_LINK_METRIC is 2, changing it
to 1.

e.g. NET_RPL_MIN_HOP_RANK_INC is 256 and NET_RPL_MC_ETX_DIVISOR is 256.
     Rank calculation for nodes is
     rank_increase = CONFIG_NET_RPL_INIT_LINK_METRIC *
                             NET_RPL_MC_ETX_DIVISOR;

     Which gives 768 for first set of child nodes. It would be good if
     CONFIG_NET_RPL_INIT_LINK_METRIC value is 1 and nodes ranks will be
     245, 512, 768 based on the path they choose.

User can absolutely change their configuration to maintain proper ranks.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally e567ca4f44 net: rpl: Do not run IPv6 DAD for global addresses
When CONFIG_NET_RPL enabled, do not run DAD (duplicate address
detection) for global addresses. In RPL mesh network global addresses
for nodes are determined by prefix from Border Router. DAD is not
necessary in this case.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 83bda0f037 net: Add IPv6 route add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the route, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 9010def93e net: Add IPv6 neighbor add and delete event with info
If CONFIG_NET_MGMT_EVENT_INFO is enabled then provide mgmt info
about the neighbor, which is added or deleted.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 5e65444d04 net: ipv6: Remove route information before deleting neighbor
Remove any routes with neighbor as a nexthop first and then remove
neighbor from neighbor table.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 49894b98e4 net: Improve net management event information
Provided separate event information structs based on events. This way
user will know what kind of information will be received to that
particular event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally ef36088608 net: Fix RPL header update
When net_ipv6_prepare_for_send() needs to route packets, it missed
updating of RPL header.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen 182b054a9f net: rpl: Setup DAG prefix into network interface
This is needed in routing if we are acting as border router.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen 6167f0f70c net: rpl: Do not do neighbor discovery for RPL network
Doing neighbor discovery in RPL network is not necessary and
that can be disabled in RPL nodes. Unfortunately the border
router needs to have ND enabled as it has also non-RPL network
interfaces in use. So in this case, mark RPL node as always
reachable.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen d4d0ddd4f7 net: ipv6: Add some extra debug when updating link address length
As this is very specialized info which is not normally needed,
do not print it by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen e5b9e4d6ad net: ipv6: Add routing support between interfaces
Introduce CONFIG_NET_ROUTING option that allows the IP stack
to route IPv6 packets between multiple network interfaces.
No support for IPv4 routing is implemented by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Juan Manuel Torres Palma ff7f1bf9db net: arp: remove shadowing variable
Removes variable shadowing another declared
previously but does not change anything
functionally.

Signed-off-by: Juan Manuel Torres Palma <j.m.torrespalma@gmail.com>
2018-02-02 16:48:53 +02:00
Vinayak Kariappa Chettimada 258c7ccff1 Bluetooth: controller: Fix HCI LE Set PHY invalid behavior check
Fix HCI LE Set PHY command for invalid behavior testing for
invalid parameters and unsupported features.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:41:46 +01:00
Vinayak Kariappa Chettimada a1f12eb238 Bluetooth: controller: Fix redundant length update event
Fix generation of redundant length update event when no
change in effective octets or time.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-73-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-74-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/MAS/BV-76-C [Master Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/MAS/BV-77-C [Master Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-77-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-78-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 1M PHY]
LL/CON/SLA/BV-80-C [Slave Data Length Update - Responding
	to Data Length Update Procedure; LE 2M PHY]
LL/CON/SLA/BV-81-C [Slave Data Length Update - Initiating
	Data Length Update Procedure; LE 2M PHY]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-02 10:40:52 +01:00
Johan Hedberg 0b7ac73eb6 Bluetooth: Mesh: fix BT_MESH_LPN_POLL_TIMEOUT description
The calculation was off by a factor of 10.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-01 12:37:09 -08:00
Vinayak Kariappa Chettimada 5c57027f53 Bluetooth: controller: Fix to use CPR preferred periodicity value
Fixed implementation to use Connection Parameter Request
Procedure Preferred Periodicity value in calculating the new
connection interval used by the master role in Connection
Update Indication.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-32-C [Accepting Connection Parameter Request –
	Preferred_Periodicity]
LL/CON/MAS/BV-33-C [Accepting Connection Parameter Request –
	Preferred_Periodicity and preferred anchor points]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-02-01 16:51:54 +01:00
Paul Sokolovsky fbaa3b1724 net: tcp: prepare_segment: Return detailed error codes.
prepare_segment() returned NULL in case of any error, which then
net_context_send() translated into -EINVAL. That's highly confusing
though, because a common case of failure for prepare_segment() is
being unable to allocate data fragment(s) (for TCP header, etc.)
So, return output pkt by reference, and detailed error status as
a return value.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-01 13:13:32 +01:00
Johan Hedberg d6b905910b Bluetooth: Mesh: Fix passing CID to model publication messages
The vendor variants of the model publication client messages were not
passing onward the CID, rather passing CID_NVAL which is clearly not
right.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 13:35:36 -08:00
Vinayak Kariappa Chettimada 9acfc7fb5c Bluetooth: controller: Fix to restrict addr set in initiator
Fix controller implementation to restrict HCI LE Set Random
Address command when advertising and/or active scanning
and/or initiator state is enable.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:54:26 -08:00
Vinayak Kariappa Chettimada 7af9c7108f Bluetooth: controller: Fix for CPR with/without Feature Exchange
Fix implementation to support Connection Parameter Request
Procedure initiation with and without use of Feature
Exchange Procedure being performed in a connection.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/MAS/BV-81-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/MAS/BV-82-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]
LL/CON/SLA/BV-85-C [Initiating Connection Parameter Request
	- Unsupported Without Feature Exchange]
LL/CON/SLA/BV-86-C [Initiating Connection Parameter Request
	- Unsupported With Feature Exchange]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 16:02:14 +01:00
Johan Hedberg 8fc4c99496 Bluetooth: Remove redundant AD parsing check
A few lines earlier the code bails out in case len is 0. Checking for
buf->len < 1 is the same as checking for buf->len == 0. Since len is
guaranteed to be > 0 here the check len > buf->len implicitly checks
for buf->len == 0, i.e. the second test can be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 07:01:10 -08:00
Johan Hedberg 7ae78c9928 Bluetooth: Mesh: Fix segment transmission timeout
The timeout was hard-coded to 400ms, but the spec actually states:

"This timer shall be set to a minimum of 200 + 50 * TTL milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg 1150858d8f Bluetooth: Mesh: Fix ack timeout calculation
The caculation was wrong since the value may be BT_MESH_TTL_DEFAULT,
i.e. 0xff, leading to much too large values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg fee8734874 Bluetooth: Mesh: Clear segment rx context when incomplete timer expires
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=10321

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg fde013b254 Bluetooth: Mesh: Take advantage of K_SECONDS macro
This makes the code slightly more readable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Johan Hedberg a0ab6086e3 Bluetooth: Mesh: Fix ignoring old SeqAuth values
Replay protection is not enforced at the Lower Transport Layer, so it
is possible to get an old replayed segment here. In such a case
cleanly discard it instead of causing a valid existing transaction
from being discarded.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-01-31 06:59:49 -08:00
Michael Hope cff16051bb disk: delete the GET_DISK_SIZE IOCTL.
The argument is a u32_t which limits the maximum disk size to 4 GiB.
Rather than fix this, delete the ioctl and switch the only use to
GET_SECTOR_COUNT instead.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-31 09:14:40 -05:00
Andrei Emeltchenko e8ccb16986 usb: hid: Add Human Interface Device (HID) class
Add support for Human Interface Device USB class.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 8f21a37861 usb: Clean up code to meet Zephyr standard
Add missing "{}" braces and remove unneeded "()" braces.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 60f8c6e272 usb: usbnet: Clean up code
Use common logging method and correct braces.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 17735e8a04 usb: netusb: Remove USB custom_handler()
Custom handler is not used, cleaning code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Andrei Emeltchenko 6e2e2dbb1b usb: msc: Clean up comment
Trivial cleaning

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-31 07:42:19 -05:00
Michael Scott afb9830441 net: lwm2m: fix retransmit_request() pending process / packet send
During the CoAP API change, slight changes were made the ref / unref
packet pending process.  Let's re-align with the coap-client sample
in how we apply the packet refs in retransmit_request() and also
replace the lwm2m_send_message() call with a direct call of
net_app_send_pkt().  This avoids a second processing of the pending
packets and keeps the ref/unref flow cleaner.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-31 12:20:41 +02:00
Michael Scott db09596b1d net: lwm2m: correct packet pending process in lwm2m_send_message()
During the CoAP API change, the way packets were ref'd and then
unref'd in order to stop the packet sending functions from releasing
the net_pkts was changed and never updated in the LwM2M library.

Let's use coap_pending_cycle() and coap_pending_clear() to do the
ref/unref the same way as the coap-client samples in order to
match the pending process with the current CoAP APIs.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-31 12:20:41 +02:00
Vinayak Kariappa Chettimada d03ad43dbb Bluetooth: controller: Fix to restrict addr set in active scan
Fix controller implementation to only restrict HCI LE Set
Random Address command when advertising and/or active
scanning is enable.

Continues to pass the following LL.TS.5.0.2 conformance
test:
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-31 10:16:47 +01:00
David B. Kinder baed5a59c7 doc: fix misspellings in Kconfig files
Fix misspellings in Kconfig files used for configuration docs.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-01-30 20:03:40 -05:00
Ramakrishna Pallala 5155e68105 subsys: disk: Kconfig: add prompt messages for config options
Add prompt messages for config options dependent on DISK_ACCESS_FLASH

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-01-30 11:32:02 -05:00
Robert Chou 6fbd86113d net: lwm2m: fix reporting attributes with negative fraction
Fraction could be stored with negative value.
The implementation was only considering the positive value case.
Therefore, we have to modify the code to take care of the case.

To test it
======================================================================
1. launch eclipse/wakaama lwm2m server
2. launch zephyr lwm2m client and wait for registration completed
3. Issue commands from server
   * attr 0 /1/0/1 -0.1 0.1
   * disc 0 /1/0

Current output
----------------------------------------------------------------------
Client #0 /1/0 : 2.05 (COAP_205_CONTENT)
105 bytes received of type application/link-format:
</1/0>,</1/0/0>,</1/0/1>;gt=0.1;lt=0/00000,</1/0/2>,</1/0/3>,</1/0/4>,
</1/0/5>,</1/0/6>,</1/0/7>,</1/0/8>

Expected output
----------------------------------------------------------------------
Client #0 /1/0 : 2.05 (COAP_205_CONTENT)
102 bytes received of type application/link-format:
</1/0>,</1/0/0>,</1/0/1>;gt=0.1;lt=-0.1,</1/0/2>,</1/0/3>,</1/0/4>,
</1/0/5>,</1/0/6>,</1/0/7>,</1/0/8>

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-29 23:30:44 -05:00
Jukka Rissanen d1675bf3e6 net: http: Remove the old legacy API
There are no internal users for old HTTP API so removing it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-01-29 22:44:45 -05:00
Kamil Sroka 95cb365fae subsys: net: ip: l2: Add OpenThread L2
Add OpenThread to Zephyrs net stack as data link layer.
OpenThread requires to call process function when an event occurs.
This process function is called from cooperative thread.

Packet conversion and dispaching is implemented in openthread.c
as well as addresses forwarding.

Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2018-01-29 22:42:03 -05:00
Kamil Sroka 83b2218ab5 subsys: net: lib: Add OpenThread platform
OpenThread requires platform definition with standarized API
so we have to add wrappers to make it compatible with Zephyr.
OpenThread is based on autoconf, this requires
more specific CMakeLists.txt which allows to clone specific
commit or point to local copy of openthread.

Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2018-01-29 22:42:03 -05:00
Vinayak Kariappa Chettimada f117505773 Bluetooth: controller: Fix to restrict addr set in active states
Fixed implementation to disallow setting Bluetooth device
address under active advertising or scanning states.

Fixes LL.TS.5.0.2 conformance tests:
LL/CON/INI/BV-01-C [Connection Initiation]
LL/SEC/ADV/BV-01-C [Advertising With Static Address]
LL/SEC/SCN/BV-01-C [Random Address Scanning]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 18:03:15 +01:00
Alberto Escolar Piedras ec7727077b native: nrf52 changes to HAL to support running on simulated HW
Conditionally compiled changes to the NRF52 HAL so it can
run on simulated HW on the native port.
(HW models are not included in this commit)

All changes are under ifdefs and therefore will not have any
effect on normal builds

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-01-29 16:02:29 +01:00
Vinayak Kariappa Chettimada 619bcf56c4 Bluetooth: controller: Refactor mayfly integration into hal
Refactor mayfly based execution context solution out into
the HAL folder. This opens up the possibility to use
tasklets (if and when kernel gets the support) style
execution contexts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-29 13:04:15 +01:00
Vinayak Kariappa Chettimada f5d64aafaa Bluetooth: controller: Fix CPR initiation while in Enc. setup
Fixes a bug where in Connection Parameter Request was
initiated by slave role while Encryption Setup had been
started by the peer master.

Fixes: #5823

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-26 11:35:17 +01:00
Johann Fischer daa83f8823 usb: mass_storage: rework and cleanup logging
This patch reworked logging so that the logging levels are more
finely graded and the locations with non-critical error handling
(below usb_ep_set_stall's) are logged with SYS_LOG_WRN.
Also cleanup, add log domain and fix indents.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-01-26 08:35:08 +05:30
Kumar Gala 26e4da52cf arm: nordic: flash: Use FLASH_DEV_NAME define
We want to move to use a common FLASH_DEV_NAME across the various flash
drivers. So samples, tests, or other code can be a bit more generic.  So
replace CONFIG_SOC_FLASH_NRF5_DEV_NAME with FLASH_DEV_NAME.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-01-25 15:23:00 -06:00
Vinayak Kariappa Chettimada 4d7d9de342 Bluetooth: controller: Refactor LL up and downstream interface
Rename some legacy upstream and downstream interfaces in
radio_* namespace to ll_* namespace for consistency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 22:09:17 +01:00
Vinayak Kariappa Chettimada 5b0cd2c69b Bluetooth: controller: Conditional compile BT_LL_SW variant
Refactor Kconfig and CMakelists.txt to be able to
conditionally compile in BT_LL_SW variant in the controller
subsystem. This is done to support future controller with
vendor specific variant implementations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:51:10 +01:00
Vinayak Kariappa Chettimada ae9f5b38d0 Bluetooth: controller: Add missing CPR and DLE cond. compilation
Add missing conditional compilation in controller's HCI
implementation, removing redundant code being compiled in.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 11:16:45 +01:00
Vinayak Kariappa Chettimada 5f4a7ea119 Bluetooth: shell: Support a non-connectable build
Add conditional compilation and move code to support
building a non-connectable Bluetooth shell application.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-25 10:51:54 +02:00
Vinayak Kariappa Chettimada be0aa2ac2c Bluetooth: controller: Remove redundant clear of NRF_RADIO events
Remove redundant code that clears NRF_RADIO->EVENT_*
registers that are only used in PPI context. Only EVENT_*
registers that are read back need to be cleared.

Relates to: #5753

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:07:06 +01:00
Ioannis Glaropoulos 9d1ca9c390 Bluetooth: controller: remove redundant PPI channel and TIMER CC
This commit implements the SW-based radio switch for TIFS for LE
Coded PHY S2 in nRF52840 with a single PPI channel and a single
TIMER CC register.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos adaef465e4 Bluetooth: controller: minor refactoring in nrf5 radio driver
This commit moves the radio enable on-tick functionality in
function hal_radio_enable_on_tick_ppi_config_and_enable() in
radio_nrf5_ppi.h.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Ioannis Glaropoulos 36ded0b516 Bluetooth: controller: adjust nRF52840 HW radio timings for Coded PHY
This commit adjust the nRF52840 HW Radio timings for LE Coded PHY.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-24 11:06:33 +01:00
Vinayak Kariappa Chettimada 13130dbe73 Bluetooth: controller: Fix BT_CTLR_DEBUG_PINS Kconfig help text
Help text for BT_CTLR_DEBUG_PINS incorrectly mentioned
specific GPIO pins being reserved for this feature, but in
reality the pins reserved vary on the SoC selected, hence
any specific mention of pin details is removed from help
text.

Fixes: #5499

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-24 11:05:51 +01:00
Paul Sokolovsky 996c6dd603 net: if: Handle new address type of NET_ADDR_OVERRIDABLE
The meaning of this address type is the same as NET_ADDR_MANUAL,
but with a provision that DHCP can override such an address.
It's intended for the usecase when there's a default static
configuration for when DHCP is not available, but DHCP should
override it.

Before going to add another address type, there was an attempt
to repurpose TENTATIVE address state, but it doesn't work as
expected, as indeed, all existing address types/states already
have clearly semantics, and it makes sense to just another
address type to avoid confusion and unexpected behavior.

Fixes: #5696

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-23 09:25:51 +02:00
Paul Sokolovsky c57abaa7c8 net: app: Allow to specify both static IP settings and DHCPv4.
The idea is that static config is used unless/until DHCP values
arrive. This allows to have the same network configuration values
for both a case of direct board - workstation connection (where
DHCP is usually not available), and a case where both a board and
workstation connect to a router (which serves DHCP).

The changes in this commit however take care of netmask and gateway
settings, but not about IP address itself. This is addressed in the
next patch.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-23 09:25:51 +02:00
Vinayak Kariappa Chettimada 5d4a32b70a Bluetooth: controller: Fix missing TIFS_HW cond. compilation
Fix a missing !CONFIG_BT_CTLR_TIFS_HW conditional
compilation when nRF52840 is configured to use hardware
Trx switching, that caused compile error.

Fixes: #5779
Fixes: #5761

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-01-22 15:33:15 -06:00
Anas Nashif e1d284f648 shell: rename get_mod_cmd
rename function and call out module in the name.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif d7777d3bd5 shell: support standalone commands
This will allow us to register commands directly without a need for a
module.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif 8d1931504a shell: rename module sections
Prepare for supporting stand-alone commands.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif 16424cf0bc shell: kernel: rename tasks -> threads
Rename tasks -> threads, task was the common name for threads before the
unified kernel was introduced.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Anas Nashif dd013691b2 shell: add a shell banner
Give details about running version and add a line about usage.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-19 12:01:08 -05:00
Mariusz Skamra 0572fe99ec Bluetooth: mesh: Check Heartbeat Pub count prior scheduling delayed work
This check is needed to not schedule the delayed work if current
message to be sent is the last heartbeat message.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-19 14:07:48 +02:00
Mariusz Skamra 37122d7205 Bluetooth: mesh: Reset Heartbeat Pub timer before sending message
The timer should be reset before sending to ensure correct
publication period.

This patch allows to pass MESH/NODE/CFG/HBP/BV-02-C.

This patch is ported from mynewt:
Commit: d4b84638df47e7ea21629e6919f547f5dcd47285

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-19 14:07:48 +02:00
John Andersen b0d8075709 net: ip: dhcpv4: Handle DHCPV4_OPTIONS_DNS_SERVER
Actually set Zephyr's default DNS server based on the corresponding
DHCP option received. This makes DHCP-based setup Zephyr complete:
now it's possible to connect Zephyr DHCP-enabled system to a typical
router, and it will fully auto-configure to access Internet.

This initial implementation uses just first DNS server address as
returned in DHCP message, it may need to be extended in the future
based on the need.

Signed-off-by: John Andersen <john.s.andersen@intel.com>
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-18 17:30:40 +02:00
Paul Sokolovsky d965598ee2 net: dns: Allow to initialize DNS servers from struct sockaddr[]
In some cases, we need to initialize DNS servers from a binary
addresses, e.g. in case of DHCP processing. With existing API,
such addresses would need to be converted to strings, just to
be converted back to struct sockaddr in dns_resolve_init().
This is not efficient, and with a number of addresses quite
cumbersome. So instead, allow to pass DNS server either as
strings, or as struct sockaddr's (or both).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-18 17:30:40 +02:00
Paul Sokolovsky a3231798ae net: lib: dns: dns_resolve_close: Mark context as unused
So it can be dns_resolve_init()ed again.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-18 17:30:40 +02:00
Ioannis Glaropoulos 55d3ce111c Bluetooth: controller: Refactoring nRF5 radio driver
This commit refactors the nRF5 radio driver of Bluetooth controller
to use symbolic names for PPIs. It also revisits the Radio hardware
timing constants to align with experimental measurements.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-01-18 10:58:04 +01:00
Andrei Emeltchenko ca9c3ad8f1 usb: rndis: Use offsetof macro to ease offset calculations
Use macro offsetof() for calculating offset inside structure.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko be1d865409 usb: Add RNDIS packet boundary check
Add check for rndis_set_handle() packet.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko cd4cea0527 usb: netusb: Add Networking logging debug level
Adding Networking USB Device Debug level allows to fine-tune
logging.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 6d61c2cf24 usb: rndis: Select USB_COMPOSITE_DEVICE for RNDIS
Windows works better with this option.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 2a1bdc2549 usb: Set Class Handler buffer size to 256 for RNDIS
Set default value for RNDIS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 33e9851254 usb: rndis: Add Remote NDIS protocol handling
Add implementation of Microsoft Remote NDIS USB Ethernet protocol.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 337601b42f usb: rndis: Add RNDIS device descriptors to the table
Add needed descriptors for USB Remote NDIS Ethernet Network.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko b4ae3ec32f usb: Add init() callback to network device functions
Add init() callback needed for RNDIS and maybe others functions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 2615658027 usb: Use standard SYS_LOG_USB_DEVICE_LEVEL for log level
Change hardcoded value to configuration defined.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 7e80f41162 usb: Rename SYS_LOG_USB to SYS_LOG_USB_DEVICE
At the moment CONFIG_SYS_LOG_USB_LEVEL name does not specify that this
is log level for the Device Stack. Make it clear renaming to the
proper name.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Andrei Emeltchenko 42d160a315 usb: netusb: Remove unneeded debug
Remove old unneeded debug statements.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-17 18:53:05 -05:00
Paul Sokolovsky 9e37dbeabe net: shell: Fix typo in description of "dns" command.
Was "is configure", should be "is configure*d*".

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-17 17:08:54 -05:00
Mariusz Skamra 385240ad0c Bluetooth: Fix BT_TESTING option dependency
This removes BT_DEBUG dependency on BT_TESTING flag.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-16 14:40:54 +02:00
Michael Hope ed35aa8c63 net: use UNALIGNED_ACCESS when accessing s_addr on received packets.
The offset of the IP header in a received packet depends on the L2
header size.  For Ethernet this is 14 bytes which puts the u32 IPv4
addresses on a non-u32 byte boundary.  This causes chips that don't
support unaligned access (like the Cortex-M0) to fault.

The fixes in this patch are enough to ping the board and run the
http_server sample.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-16 11:27:48 +02:00
Patrik Flykt 010fb40b95 subsys: usb: Set Zephyr project USB Vendor and Product IDs
Document USB Vendor and Product IDs and their intended usage.
Set the Vendor and Product IDs and define the USB bcdDevice
Device Descriptor Device Release Number to be the binary
coded decimal representation of the Zephyr major and minor
kernel version number.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-01-15 15:47:53 -05:00
Andrzej Puzdrowski f8a674b45e subsys: storage: flash_map: devices bindings fetch optimalization
Moved fetch of flash device bindings to early initialization of the
application.
Device bindings are constant while the application is running so
it is better to fetch it at startup, and not every time flash_map
procedures are called.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-01-15 15:46:37 -05:00
Andrzej Puzdrowski b7f1289847 subsys: fs: Add Flash Circular Buffer
Zephyr already supports NFFS as a storage layer, but it might
be a little bit too heavyweight for certain applications in
memory-restricted ICs.

This module is response for need of Lightweight flash storage
capability. FCB is ported form MyNewt as native zephyr module.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-01-15 15:46:37 -05:00
Andrzej Puzdrowski 25269fb0ed subsys: storage: Add flash_map abstraction module
Introduce flas_map module is abstraction over flash memory and its
driver for using flash memories along with description of
available flash areas.
Module provides simple API for write/read/erase and so one.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-01-15 15:46:37 -05:00
Tomasz Bursztyka 6eec2d2aa5 net/ieee802154: Normalize parameter on radio API helper
For some reason, ieee802154_verify_channel had a device parameter
instead of an iface like all the others.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka ebfa2df113 net/ieee802154: Use helpers to call radio API functions
Now the code is a bit cleaner.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 6f51ac7f2b net/ieee802154: Introduce helpers to call radio api function
Basically to make code nicer and more readable.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 208e7f2bf6 net/lib: 15.4 interface is set UP after channel is configured
Once it has - at least - set up the channel, it can request the iface to
be put up.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 9078378bed net/ieee802154: Do not set the device UP by default
It will be up to the user to configure a valid channel, through
net_mgmt, and call net_if_up() in order to get the device up.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 6fa3d0fa3e net/ieee802154: Verify in L2 the Sub-Ghz channel value
Depending on device's band, the upper channel limit can vary a lot in
Sub-Ghz. Thus verifying it directly in L2 before requesting it to the
device.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 9aa2f45d23 net/ieee802154: Add Sub-Ghz dedicated function on the radio API
Sub-Ghz bands have different limit of channels. 10, or more than a
thousand is actually possible. Thus the device needs to expose such
limit to the L2 which is unaware of frequency band logic. L2 will
then allow user to select a proper channel.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Paul Sokolovsky cb140154b0 net: tcp Remove recv_max_ack field from struct net_tcp
This field is set and maintained, but not actually used for anything.
The only purpose for it would be to validate ACK numbers from peer,
but such a validation is now implemented by using send_seq field
directly.

Fixes: #4653

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-15 15:08:22 +02:00
Paul Sokolovsky e36f67d1d9 net: tcp: Remove incorrect logging of "ACK errors"
Case #1: If ACK received and our retransmit (i.e. unacked) queue is
empty, it's error. It's incorrect because TCP requires ACK to set for
every packet of established connection. For example, if we didn't
send anything to peer, but it sends us new data, it will reuse the
older ack number. It doesn't acknowledge anything new on our side,
but it's not an error in any way.

Case #2: If retransmit queue is only partially acknowledged, it's an
error. Consider that we have 2 packets in the queue, with sequence
numbers (inclusive) 100-199 and 200-399. There's nothing wrong if
we receive ACK with number 200 - it just acknowledges first packet,
we can remove and finish processing. Second packet remains in the
queue to be acknowledged later.

Fixes: #5504

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-15 15:07:49 +02:00
Paul Sokolovsky ac7b1291da net: tcp: Validate incoming ACK number
Per RFC 793:

  A new acknowledgment (called an "acceptable ack"), is one for which
  the inequality below holds:

    SND.UNA < SEG.ACK =< SND.NXT

If acknowledgement is received for sequence number which wasn't yet
sent, log an error and ignore it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-15 15:07:49 +02:00
Robert Chou b7af740f3a net: lwm2m: update observe_node when attributes are written or cleared
As title, we should update the existing observe_node when new attributes
are written from server side. Add the implementation to handle that.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-12 20:57:34 -05:00
Robert Chou 2281f6fd7d net: lwm2m: get attributes from obj/obj_inst/res for observe_node
1. Read notification attributes set by server to setup the
   minimum/maximum notification period of a observation request.
2. Reordering to check observe_node duplication first
   (bailout earlier)
3. Simplify remove observe_node condition checking

NOTE: attributes are inheritable, priority: res > obj_inst > obj
Reference: LwM2M spec V1_0_1-20170704-A, section 5.1

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-12 20:57:34 -05:00
Robert Chou b0e7a039ee net: lwm2m: report attributes on discover op
Since we've added storing notification attributes written by server.
We can now append these attributes as part of link-format for discover
op.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-12 20:57:34 -05:00
Robert Chou 09fcd83b98 net: lwm2m: add write-attribute WRITE support
Implement write-attribute on obj/obj_inst/res according to LwM2M spec
20170704-A, sec 5.1.2. Support pmin/pmax/st/gt/lt parameters on WRITE
operation.

The basic idea is to add sys_slist_t to obj/obj_inst/res structure.
And attach struct lwm2m_attr to the list when attributes are written
from server side (implement lwm2m_write_attr_handler accordingly)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-12 20:57:34 -05:00
Jukka Rissanen ff22595c31 net: ip: shell: Fix ipv4 echo reply callback to unref packet
The ICMPv4 handler needs to unref the received echo reply packet
because we are returning NET_OK to caller. Similar change was done
for IPv6 earlier.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-01-12 20:51:32 -05:00
Andrei Emeltchenko af0bf06aa3 usb: Fix USB Device dependency
USB Device stack should depend on supported drivers not on menuconfig
option.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-12 07:46:28 -05:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Paul Sokolovsky 84e3d3e7e8 libc: Kconfig: Move STDOUT_CONSOLE from subsys/debug
This option is clearly not related to debugging, but affects libc
features.

Fixes: #5566

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-11 12:47:10 -05:00
Pedro Martucci df37588b6f net: ip: shell: Fix ipv6 echo reply callback to unref packet
When testing ping6 with net shell, it was noticed that after some
sucessive calls the applications stopped to handle rx packets.
Analyzing other icmpv6 register callbacks it was verified that is
necessary to unref packets before returning NET_OK.

Signed-off-by: Pedro Martucci <pedropaulomartucci@gmail.com>
2018-01-11 09:19:48 +02:00
Michael Scott a21563d1a8 net: lib: lwm2m: fix coap proxy resource option
commit 2a7546fb5a ("net: lwm2m: add support for coap2coap proxy")
erroneously changed the COAP_OPTION_* used to specify the coap2coap
or coap2http proxy resource used from COAP_OPTION_URI_PATH to
COAP_OPTION_PROXY_SCHEME.

Changing it back to COAP_OPTION_URI_PATH requires us to re-order how
the coap options are appended to the packet as the coap options must
be added in the order specified by the numbers in:
https://tools.ietf.org/html/rfc7252#section-12.2

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-11 09:18:45 +02:00
Robert Chou 33030721c4 net: lwm2m: increase packet reference to avoid packet being freed
CoAP packet w/ confirmation flag set is required to be retransmitted
before it got the ACK message from the peer.

However, the packet is usally unreference once it's sent to the network.
Although we set the timeout as no wait when calling function
net_app_send_pkt(), it's still possible that the packet is unreferenced
before we got a chance to increase the packet reference by calling
coap_pending_cycle().

Usually, the IP stack will generate an ARP packet first and then send
out the packet.  However, this is not the case when the remote is a
loopback address.

As issue #5101 described, when asking client to perform a firmware pull
on URL "coap://127.0.0.1:7783/large". The packet will be unreferenced
immediately after calling net_app_send_pkt(). Which then result in
client hang.

The solution to the issue is to increase the reference count on the
sending packet and decrease it after the process is finished.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2018-01-11 09:18:10 +02:00
Michael Scott 33ea1b5c89 net: skip TX max send calculation in net_pkt_append() for RX packets
We shouldn't limit the amount of data appended to RX packets based on
the max send size of TX packets.  Skip this check for packets in the
RX slab.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-10 21:48:20 -05:00
Michael Scott 6338ec0546 Revert "net: net_app: set packet data_len on incoming packets"
This reverts commit 3599d793c2.

Setting a packet's data_len here doesn't fix the fact that we shouldn't
be using it at all on RX packets.  Fix belongs in net_pkt_append().

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-10 21:48:20 -05:00
Michael Scott a75458131a net: lib: app: trigger TLS closure when connection is closed
When testing TLS connections on production web server, it was noticed
that the TLS mainloop was getting "hung" after a connection was made
via HTTPS and then closed by the server.  The TLS mainloop was never
being notified that the connection was closed and was stuck waiting
for more data.

The next time that connection was used, TLS would fail to start.

Let's force trigger a closure of the TLS process when the net-app layer
is notified of the connection closure.  This allows the connection to
be successfully reused later.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-10 21:47:46 -05:00
Mariusz Skamra 2f81942754 Bluetooth: mesh: Fix model subscription groups cleanup
Virtual address labels array entries were not updated on va deletion,
so that STATUS_INSUFF_RESOURCES error was returned after few
subsequent Config Model Subscription Virtual Address Add, Delete,
Overwrite commands, even if there shall be free space available.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-10 16:38:53 +02:00
Mariusz Skamra 4ba9543bdd Bluetooth: mesh: Fix LPN subsciption groups update on VA deletion
This fixes missing bt_mesh_lpn_group_del call in mod_sub_va_del.
If Config Model Subscription Virtual Address Delete was received
and successfully proceeded, subscription address shall be also
deleted from LPN Subscribe Groups.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-10 16:38:53 +02:00
Anas Nashif 4d2ad0a8a5 Bluetooth: remove unused BT_DEBUG_COLOR
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-09 10:59:41 -05:00
Paul Sokolovsky d9e886bc6e net: Kconfig: Don't select STDOUT_CONSOLE
The net code doesn't use libc stdio stdout in any way, so there's no
need tweak those options.

Fixes: #5565

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-05 10:00:26 -05:00
Mariusz Skamra 253e40ad0e Bluetooth: mesh: Do not set RFU bits in Heartbeat Publication Features
Features received in Config Heartbeat Publication Set message can have
Feature bits set to RFU values.
This patch fixes setting this RFU bits in Heartbeat Publication
Features, so that those are not indicated in Config Heartbeat
Publication Status message.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-05 09:31:50 +02:00
Paul Sokolovsky 7c7223982a net: shell: conn: Cross-ref TCP control block to owning context
Previously "conn" command dumped TCP control blocks without
referencing it to an owning context, making it hard to figure
out what happens. Now, dump context address.

Example before:

net> conn
     Context    Iface         Flags Local               Remote
[ 1] 0x00403360 0x0041fac0    6ST   [::]:4242   [::]:0
[ 2] 0x004033c8 0x0041fac0    4ST   0.0.0.0:4242        0.0.0.0:0
[ 3] 0x00403430 0x0041fac0    6DU   [::]:4242   [::]:0
[ 4] 0x00403498 0x0041fac0    4DU   0.0.0.0:4242        0.0.0.0:0
[ 5] 0x00403500 0x0041fac0    4ST   192.0.2.1:4242      192.0.2.2:55314

TCP        Src port  Dst port   Send-Seq   Send-Ack  MSS
0x00403c00     4242         0 2541690653          0  1440
0x00403cbc     4242         0 2797902539 3233948882  1460
0x00403d78     4242     55314 2797902539 3233948882  1460

Example after:

net> conn
     Context    Iface         Flags Local               Remote
[ 1] 0x00403360 0x0041fac0    6ST   [::]:4242   [::]:0
[ 2] 0x004033c8 0x0041fac0    4ST   0.0.0.0:4242        0.0.0.0:0
[ 3] 0x00403430 0x0041fac0    6DU   [::]:4242   [::]:0
[ 4] 0x00403498 0x0041fac0    4DU   0.0.0.0:4242        0.0.0.0:0
[ 5] 0x00403500 0x0041fac0    4ST   192.0.2.1:4242      192.0.2.2:55424

TCP        Context   Src port Dst port   Send-Seq   Send-Ack  MSS
0x00403c00 0x00403360    4242        0 1854382523          0  1440
0x00403cbc 0x004033c8    4242        0 1420360158 2064582979  1460
0x00403d78 0x00403500    4242    55424 1420360158 2064582979  1460

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-04 18:38:19 -05:00
Paul Sokolovsky 94995cbd0f net: ip: Optimize statements for setting packet lengths.
Use native C operators for converting a word to bytes.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-04 18:37:18 -05:00
Mariusz Skamra fdca8d8f54 Revert "Bluetooth: Mesh: Fix ignoring invalid Transport OpCode as LPN"
This reverts commit ada5771d7c.

MESH/NODE/FRND/LPN/BI-02-C in Mesh Test Specification 1.0.1
has been fixed according to TSE #9774.

IUT shall ignore the message with an RFU Transport Control Opcode
but another Friend Poll message shall be sent with an alternating
FSN value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-04 15:33:19 +01:00
Mariusz Skamra cc1a960730 Bluetooth: mesh: Fix status returned from mod_unbind
According to Mesh Specification v1.0 4.3.2.48 Config Model App Status:
"The Status Code shall be Success if the received request was redundant
(bind request of existing binding, or unbind of a non-existing binding),
with no further action taken."

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-04 15:08:43 +01:00
Michael Scott 3599d793c2 net: net_app: set packet data_len on incoming packets
This fixes a bug when calling net_pkt_append[_all] which uses
pkt->data_len as part of the maximum packet length calculation
when the net_context is set.

Without this change the maximum packet length is calculated as 0
(the value of pkt->data_len) and an ENOMEM error is returned.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-03 19:02:31 -05:00
Michael Scott e71f95b946 net: ip: net_pkt: set pkt context, iface and family in net_pkt_get()
Commit 753daa6 ("net: pkt: Compute TX payload data length")
removed the default packet setup on incoming packets when they
belong to the rx_pkt pool.

Let's restore this behavior, as MBEDTLS processing in net_app library
needs to use packet family to determine IP header length on
incoming packets.

NOTE: A future cleanup patch could set the IP header length based
on the context IP family.  However, there are many places in the code
where this is being set, so care should be taken.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-03 19:02:31 -05:00
Mariusz Skamra 813ec50838 Bluetooth: btp: Add event indicating expiration of incomp timer
This event indicates that segmented message incomplete timer
expired.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra 9977caefa1 Bluetooth: testing: Move bt_test_mesh_net_recv to internal API
This function is called only within mesh stack.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra 8274cbabf6 Bluetooth: btp: Add Mesh Clear Replay Protection List Cache command
This command is needed for Bluetooth Mesh testing against PTS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra a909aa3a0b Bluetooth: btp: Add LPN Subscribe/Unsubscribe commands
This adds commands to manage Friend node Subscription List.
Those will be used to add or remove and group/virtual address
from subscription list.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra 0bd3790d5b Bluetooth: btp: Add event indicating invalid provisioning BearerOpcode
This adds BTP event indicating reception of provisioning message
with invalid (RFU) BearerOpcode.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Mariusz Skamra 0d71cef1f2 Bluetooth: tester: Add BTP Mesh Model Send command implementation
This command will be used to test if model can properly send
segmented and unsegmented messages to a given destination address.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2018-01-03 10:48:13 +01:00
Jan Van Winkel 36e2efaf91 fs: nffs: Corrected types in OS specific functions
Corrected types in OS specific functions to be inline with NFFS
declarations.

Fixes #5467

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2018-01-02 13:34:02 -05:00
Anas Nashif 13b08296e1 net: remove zoap library
We now have coap, all dependencies have been removed, so cleanup for the
next release.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-02 09:41:24 -05:00
Ravi kumar Veeramally 1e277e0f20 net: app: Do not reset net_context information
Do not reset net_context information in net_app_close. In case of
TCP behind the curtains connection might wait for some timers to
expire and send some messages (e.g. ACK). If we set source port to
'0', unexpected behaviour might happen with peer connection.
Only reset net_app context related information on net_app_close.
Let net_context_put will take care of proper connection closure.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-12-31 11:58:27 -05:00
Ravi kumar Veeramally a0371ae92f net: tcp: Add initial support for TIMEWAIT timer
Right now in FIN_WAIT1 state, if we receive FIN+ACK message, then
tcp state changed to FIN_WAIT2 on ACK flag and immediately on FIN
flag state changed to TIME_WAIT. Then final ACK is prepared and sent
(in queue at-least) to peer. Again immediately state changed to
TCP_CLOSED, where context is freed. net_context_put frees context
and releases tcp connection. Final ACK packet which is in queue
is dropped.

As a side effect of freed ACK packet, peer device keep on sending
FIN+ACK messages (that's why we see a lot of "TCP spurious
retransimission" messages in wireshark). As a result
of context free (respective connection handler also removed), we see
lot of packets dropped at connection input handler and replying with
ICMP error messages (destination unreachable).

To fix this issue, timewait timer support is required. When tcp
connection state changed to TIMEWAIT state, it should wait until
TIMEWAIT_TIMETOUT before changing state to TCP_CLOSED. It's
appropriate to close the tcp connection after timewait timer expiry.

Note: Right now timeout value is constant (250ms). But it should
be 2 * MSL (Maximum segment lifetime).

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-12-31 11:58:27 -05:00
Ravi kumar Veeramally 124c067027 net: tcp: Cancel the fin_timer on FIN message in FIN_WAIT1 state
fin_timer will be started after sending FIN to peer. After successful
reception of FIN+ACK message in FIN_WAIT1 state, fin_timer should be
cancelled.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-12-31 11:58:27 -05:00
Manivannan Sadhasivam 045d146d9f subsys: bluetooth: host: mesh: shell: Fix IVIndex parsing
Fix the parsing of IVIndex value from shell command line for
cmd_provision

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
2017-12-30 08:28:00 +01:00
Paul Sokolovsky e25df54eae various: Update/fix some textual material and code comments.
Of these, only struct net_ipv6_nbr_data::send_ns is a descriptive
change:

send_ns is used for timing Neighbor Solicitations in general, not
just for DAD.

The rest are typo/grammar fixes.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-29 09:45:39 -05:00
Vinayak Kariappa Chettimada 891ba80087 Bluetooth: controller: Fix S2 coding Rx chain delay timing const
Fix the S2 coding Rx chain delay timing constant based on
manual observations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-29 10:31:44 +01:00
Vinayak Kariappa Chettimada d3585cd1d9 Bluetooth: controller: Add tIFS SW switching for Coded PHY
Add implementation to consider differing Rx chain delays for
S2 and S8 Coded PHY PDU reception. These changes are
required to meet tIFS timings for transmission after a
reception on S8 coding.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-29 10:31:44 +01:00
Vinayak Kariappa Chettimada e00282af6e Bluetooth: Fix build failure with -Wshadow CFLAGS
Fixes many instances of errors similar to below:
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5927:22:
    error: declaration of ‘s_link’ shadows a previous
        local [-Werror=shadow]
  static memq_link_t s_link;
                     ^~~~~~
zephyr/subsys/bluetooth/controller/ll_sw/ctrl.c:5905:21:
    note: shadowed declaration is here
  static memq_link_t s_link;
                     ^~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-20 12:29:52 -05:00
Mariusz Skamra a87840e8e2 Bluetooth: Expose Bluetooth Testing API
This moves Bluetooth testing header file to the include/bluetooth.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2017-12-18 12:43:23 +01:00
Anas Nashif e2122cbf89 lib: move ring_buffer from misc/ to lib/
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-15 20:02:01 -05:00
Michael Scott 2c208e99ad net: lwm2m: cleanup transfer_request error handling
Consolidate and standardize error handling throughout
lwm2m_obj_firmware_pull.c.  As well as handle previously
unhandled errors returned from transfer_request().

NOTE: in general, unhandled errors will now result in
RESULT_UPDATE_FAILED.  Previously, unhandled errors in
transfer_request() would result in RESULT_CONNECTION_LOST
which might or might not be over-written with another
result later.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 18:02:25 -05:00
Michael Scott 2fc554b8fc crypto: config: config-coap: add CONFIG for setting max content length
The CoAP samples use an MBEDTLS config "config-coap.h" which could be
re-used by the LwM2M sample, except that most servers use a larger
maximum content length setting of 1500 bytes.

Let's add a CONFIG to set this for users of the CoAP lib and set the
CONFIG value for the samples to the 256 size currently used.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 17:52:13 -05:00
Michael Scott 2a7546fb5a net: lwm2m: add support for coap2coap proxy
Currently, LwM2M firmware download only supports coap2http proxy.
Let's add support for coap2coap proxy as well.

This was tested running Californium demo app cf-proxy on the host
machine with the following setting changed in Californum.properties:
MAX_RESOURCE_BODY_SIZE=524288

Add the following to the samples/net/lwm2m_client/prj.conf:
CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_SUPPORT=y
CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_ADDR="coap://[2001:db8::2]:5682"

Build the sample for qemu_x86 as you would normally, but now
you can use a real world coap address to pull firmware using the 5/0/1
resource.  The host machine running cf-proxy will pull the remote
resource and then deliver it to the running qemu sample.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:47:30 -05:00
Michael Scott 6ddbd56853 net: lwm2m: add support for DTLS
- Add needed settings for DTLS support to the lwm2m_ctx structure.
- Add initialization of MBEDTLS to the LwM2M lib based on the
  user application settings in lwm2m_ctx.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:46:48 -05:00
Michael Scott 7111491be3 net: lwm2m: use correct remote address when DTLS is enabled
The default net_context remote address is scrambled when using a
connection via DTLS.  Instead let's use the dtls context remote.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:46:48 -05:00
Michael Scott 8f4b4db71f net: lwm2m: fix possible dereference in RD client
While looping through possible lwm2m_ctx matches, we're referencing
remote before checking that the context itself is valid.

Also, reduce indentation issues.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:46:48 -05:00
Michael Scott e0b8d172a9 net: lwm2m: setup LwM2M build as static library
Instead of building under the "app" context, let's build the
LwM2M library as a separate static library.  This will be helpful
later when adding support for DTLS as w/o this configuration,
the build breaks on MBEDTLS config includes.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:46:48 -05:00
Michael Hope 9dd4399edd fs: only select the disk subsystem if the filesystem needs it.
Of the filesystems under subsys/fs/, only the ELM FAT filesystem needs
the disk layer as others (like NFFS) talk directly to the flash API.

This removes the need to define CONFIG_DISK_ERASE_BLOCK_SIZE and
similar which are used by the disk subsystem but not by NFFS.

Signed-off-by: Michael Hope <mlhx@google.com>
2017-12-14 16:49:18 -06:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Mariusz Skamra 700328ac55 Bluetooth: Introduce Bluetooth Testing API
This introduces Bluetooth internal API intended to be used for
qualification purposes. Application may register callbacks to get
data that is not exposed by public API.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2017-12-13 11:26:32 +02:00
Tomasz Bursztyka 4a3afb8506 net/ieee802154: Do not expose l2 specific context in generic net_l2.h
This will avoid exposing IEEE 802.15.4 Zephyr's L2 private context data
to unrelevant places.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-12 09:29:48 -05:00
Tomasz Bursztyka c88000a051 net/ieee802154: Split the net mgmt part from the L2 specific header
L2 specific data and IEEE 802154 net mgmt interface are not related.
Plus, application may use the net mgmt part, not the L2 one. So let's
split the content in relevant headers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-12 09:29:48 -05:00
Robert Chou 685db067d5 net: lwm2m: separate write operation from write-attributes op
Content-format is used to determine the type of the PUT/POST
request. Therefore, it's incorrect to assign default when the
caller does not include one in the request.

Define LWM2M_FORMAT_NONE=65535 to indicate the format is missing.
The 65000~65535 is reserved for experiments and should be safe for
the purpose. Check content-type at PUT method to setup
write/write-attrs operation accordingly.

Also, add reporting write-attrs as not implemented to the caller.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-12-12 09:26:31 -05:00
Robert Chou e237ae7d35 net: lwm2m: reduce code size of coap_options_to_path()
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-12-12 09:26:31 -05:00
Robert Chou dfbe275c64 net: lwm2m: discover op does not depend on input format type
According to LwM2M specification V1_0_1-20170704-A, table 25,
incoming request is a discover op if it is method GET with
accept format as application/link-format

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-12-12 09:25:59 -05:00
Robert Chou 3062e76858 net: lwm2m: correct lwm2m discover operation behavior
According to LwM2M specification 20170208-A, there are two different
discover interfaces supported by the device.
(1) Bootstrap discover (sec 5.2.7.3) (To be implemented)
(2) Device management discover interface (Sec 5.4.2)
 - object ID is required (i.e. root directory discover is not allowed)
 - attributes should be responded accordingly when implemented

This patch correct the behavior according to the spec and summarized
as follow
(1) Still support CoAP ".well-known/core" but change to report only
    first level of the URI.
(2) Respond to caller only when object ID is provided unless it's
    bootstrap discover

Fixes #4941

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-12-12 09:25:59 -05:00
Robert Chou 7929aaf307 net: lwm2m: remove unused options variable
Remove it for we are not using it after calling the
coap_packet_parse().

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-12-12 09:25:59 -05:00
Paul Sokolovsky 2a795a19ff drivers: eth_mcux: Implement IPv6 multicast group joining/leaving
IPv6 mcast addr to MAC mcast conversion was factored out to
subsys/net/ip/l2/ethernet.c for reuse by other drivers.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-12 09:24:51 -05:00
Tomasz Bursztyka f8cf3b99d9 subsys/net/lib: Clear up CMakeLists.txt
Tiny cleanups to clarify, and 80 chars limit fix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-11 09:34:16 -05:00
Tomasz Bursztyka 8d2c0b4707 subsys/net/ip: Clear up content in CMakeLists.txt
Empty CMakeLists.txt in l2 and l2/ieee802154 deserved to get filled-in
relevantly, instead of centralizing everything in ip/ location.
Also making sure lines don't get over 80 chars.
Also, no need of linking against mbetls unless net shell is enabled.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-11 09:34:16 -05:00
Paul Sokolovsky f161633109 net: if: Join solicited-node multicast addr for each unicast addr
https://tools.ietf.org/html/rfc4862#section-5.4.2 :

"""
Before sending a Neighbor Solicitation, an interface MUST join the
all-nodes multicast address and the solicited-node multicast address
of the tentative address.
"""

So, joining should happen before sending DAD packets, and it should
happen for each unicast address added. This is achieved by joining
from net_if_ipv6_addr_add() call. Note that we already leave
solicited-node group from net_if_ipv6_addr_rm(). In particular, we
leave it if DAD fails (as that function is called in this case).

Fixes #5282.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-11 09:09:48 -05:00
Aska Wu fa934009cb subsys: console: Fix the buffer size checking
Fix the problem that no compiler error even the buffer size is not power
of 2.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-12-10 19:49:02 -05:00
Anas Nashif f46c0c2472 kconfig: remove deprecated DEBUG_TRACING_KERNEL_OBJECTS
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Anas Nashif a254359c1a kconfig: stack_usage: remove extra space
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Vinayak Kariappa Chettimada ec5a787da2 Bluetooth: controller: Fix multiple master role event scheduling
When the controller is connecting to multiple connectable
advertisers, the events are scheduled consecutively avoiding
overlapping events. Calculation of the window offset did not
consider the preparation time before the event, causing the
new master role connection event to overlap with previous
event. This is now fixed by including the preparation time
in the used window offset from the end of connect_ind PDU
transmitted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-09 09:24:37 +02:00
Michał Narajowski 06facdcad7 Bluetooth: Mesh: Fix typo in Kconfig help message
300 * 100 ms = 30000 ms = 30 s

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2017-12-07 17:15:47 +02:00
Vinayak Kariappa Chettimada ba13c99141 Bluetooth: controller: Fix conn param req initiation check
Fixed the check related to initiating connection parameter
request procedure. This will avoid sending invalid repeated
dispatch of connection parameter request PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 11:30:42 -06:00
Vinayak Kariappa Chettimada 73a493eae6 Bluetooth: controller: Fix missing CPR procedure reset
When connection parameter request procedure was responded
by master role with Unsupported Link Layer Parameter Value,
a missing reset of the connection parameter request
procedure state caused next connection parameter request to
be incorrectly responded with same procedure collision
extended reject ind PDU. This caused an eventual connection
disconnection with reason LMP response timeout. This is now
fixed by reseting the state correctly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-12-06 10:24:26 -06:00
Johan Hedberg 8b51b60634 Bluetooth: Mesh: Proxy: Don't try to advertise when it's not possible
If we have the maximum number of supported connections, then it
doesn't make sense to try to do connectable advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg e4cac812df Bluetooth: Mesh: Proxy: Fine-tune subnet advertising rotation
Create a slightly smarter algorithm for choosing how long to advertise
each subnet. This is particularly important for the mesh_shell app,
since it uses a 10 second NODE_ID_TIMEOUT, meaning starting Node ID
advertising through user interaction would only succeed in advertising
one subnet (due to this being configured to 10 seconds).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 6e89138823 Bluetooth: Mesh: Suppport multiple subnets for app-triggered Node ID
Mesh Profile Specification 1.0 section 7.2.2.2.3:

"When the server starts advertising as a result of user interaction,
the server shall interleave the advertising of each subnet it is a
member of"

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 174facc02a Bluetooth: Mesh: Prioritize subnets with Node ID
Node ID advertising is short lived, so it's important to make sure
that subnets that get it enabled are first in queue to start
advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 86ac86c6ca Bluetooth: Mesh: Add helpers for starting/stopping Node ID
We'll soon extend the start functionality with a bit more stuff
(prioritizing the started subnet), so in order to avoid excessive code
duplication, create helpers for these actions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 62777755f9 Bluetooth: Mesh: Add Proxy advertising support for multiple subnets
Until now the proxy server code would only advertise with the first
subnet. Introduce tracking of what the last advertised subnet was, and
give each subnet 10 seconds of advertising at a time.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 364ce8801f Bluetooth: Mesh: Add support for sending NetKey Add message
Add configuration client model support for NetKey Add message, as well
as a mesh shell command for calling the new API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Johan Hedberg 74e1f51350 Bluetooth: Mesh: Coding-style: Remove redundant whitespace
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 20:02:19 +02:00
Michael Scott 2386ce7af8 net: if: fix ND reachable calculation
The reachable calculation for ND is using fractions combined with
integers and getting rounded to very small results (1ms or 0ms).
Let's split up the fraction into it's numerator and denominator
and perform the math in a better way to get the correct results.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-05 07:51:59 -06:00
Johan Hedberg 22f3d36ba7 Bluetooth: Mesh: Fix relaying from GATT to Advertising
The logic for choosing to relay from the GATT bearer to the
advertising bearer was still buggy. This patch refactors the logic to
a separate helper function to make it clearer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-05 13:52:10 +02:00
Johan Hedberg 7d7121b1ee Bluetooth: Mesh: Fix copy-paste mistake in log message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg dd839d90ac Bluetooth: Mesh: shell: Fix AppKey Add command handler
The command handler already has support for decoding from hex, however
it was not using the decoded value when calling the client API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg 39298cf3c5 Bluetooth: Mesh: Fix format specifier for s32_t
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 13:36:31 +02:00
Johan Hedberg c0b5a91588 Bluetooth: Mesh: Fix using the correct transmit state
If relaying is not supported, or disabled, the Relay Transmit state
will normally be 0, which is not what we want to use when proxying out
packets from GATT clients. The bt_mesh_net_relay() function is also
used for sending out locally originated packets, in which case the
Relay Retransmit state is also the wrong one to use (the Network
Transmit state should be used instead).

This patch makes sure we only use the Relay Retransmit state for
packets originating from the advertising bearer, and for all other
packets use the Network Transmit state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg 4871d8567b Bluetooth: Mesh: Fix relaying conditions for Adv & GATT bearers
The bt_mesh_net_relay() function was missing several important checks
for whether a PDU should be relayed or not. In particular, it would
relay a packet from adv to adv even if the Relay state was set to
disabled, as long as GATT Proxy was set to enabled. The code would
also relay packets to the GATT Proxy bearer if the Relay state was set
to enabled but GATT Proxy was set to disabled. This patch addresses
both of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg ad6f9b15e6 Bluetooth: Mesh: Fix changing Relay state from Not Supported (0x02)
If the Relay state is set to Not Supported (0x02) the Config Relay Set
message should not change the state, rather just return its current
value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-04 11:13:31 +02:00
Johan Hedberg 967d8b5b59 Bluetooth: Mesh: Fix beacon cache handling
The beacon cache handling was severely broken in the way that the
cache_add() function was incorrectly mapping net_idx to array index,
which could have lead to array overflows.

To fix this, while also cleaning things up, move the cache to the
actual bt_mesh_subnet struct. This e.g. lets us avoid having to track
the net_idx twice.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg a3448aba9f Bluetooth: Mesh: Fix setting an upper limit on beacon interval
https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9807

"If the computed Beacon Interval is less than 10 seconds, it should be
set to 10 seconds. If the computed Beacon Interval is greater than 600
seconds, it should be set to 600 seconds."

The lower limit is already covered by how frequently the delayed work
callback gets called, so we just need enforce the 600 second maximum.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-12-01 12:28:56 +02:00
Johan Hedberg 77ca943fd5 Bluetooth: Mesh: Fix sending beacons to Friend Queue & GATT clients
Whenever there's a security change (Key Refresh or IV Update) we
should immediately send beacons to any Friend Queues or connected GATT
clients. Introduce a helper function to do this, and make sure it's
called from all places that change the Key Refresh or IV Update
states.

This fixes test case MESH/SR/PROX/PB-12-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg 8f2a7f2d46 Bluetooth: Mesh: Fix logging mesh addresses
Addresses are 16-bit and not 8-bit.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 19:29:15 +02:00
Johan Hedberg 1210258603 Bluetooth: Mesh: Clearly document the magic 18 byte minimum length
This makes it clear why 18 is a valid minimum network PDU length to
enforce. This is particularly important since as of writing this patch
there's at least one PTS test case which sends too small PDUs, which
could potentially lead to people thinking the implementation is at
fault (it's not).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-30 14:58:09 +02:00
Johan Hedberg 6078f8acc2 Bluetooth: Mesh: Introduce API for clearing the RPL
Some Transport Layer tests (MESH/NODE/TNPT/BV-13-C in particular)
require manual clearing of the RPL. Introduce an API for it as well as
a command to the mesh shell to call the API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg 3222662553 Bluetooth: Mesh: Fix Replay Protection List checking
If we the stored RPL entry was for an old IV Index, and the received
PDU is for a new IV Index we should not be comparing the sequence
number (as it's by definition always greater than the old one).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:49:45 +02:00
Johan Hedberg 859afbf39b Bluetooth: Mesh: Fix disconnecting clients when disabling GATT Proxy
Section 4.2.11 of the Mesh Profile Specification 1.0 states:

"Upon transition from GATT Proxy state 0x01 to GATT Proxy state 0x00
the GATT Bearer Server shall disconnect all GATT Bearer Clients."

This also makes test case MESH/SR/MPXS/BV-08-C pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 90ea44cc4b Bluetooth: Mesh: Fix initializing Node ID start time
The bt_mesh_proxy_identity_enable() function was missing a line to
properly initialize the start time for Node Identity advertising.
Without it this public function wouldn't work as intended.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 012e763311 Bluetooth: Mesh: Fix GATT Proxy Service CCC read permissions
Test case MESH/SR/MPXS/BV-04-C requires the Proxy Service CCC to have
read permissions in order to pass.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg ff7d5ca910 Bluetooth: Mesh: Fix GATT Proxy & Node Identity state binding
Section 4.2.11.1 of the Mesh Profile specification 1.0 states:

"When the GATT Proxy state is set to 0x00, the Node Identity state for
all subnets shall be set to 0x00 and shall not be changed."

When the proxy state has been changed we also need to wake up the
advertising module to make sure we do the right kind of advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg 84409d0161 Bluetooth: Mesh: Deliver TTL=1 PDUs only to the local net interface
Section 3.4.5.2 in the Mesh Profile Specification (1.0) states:

"The output filter of the interface connected to advertising or GATT
bearers shall drop all messages with TTL value set to 1."

Also: https://www.bluetooth.org/errata/errata_view.cfm?errata_id=9811

Note that this is specifically 1 and not 0, since e.g. Friend PDUs
always go out with TTL 0.

Another noteworthy thing is that the way this has to be implemented is
slightly contrary to how it's presented in the specification (both in
the text as well as the Message processing flow diagram in section
3.11. If this was implemented following the spec to its word, then any
PDU received over GATT or Advertising with TTL 2 would never be
relayed (since the TTL would be 1 when the PDU gets rerouted back to
the bearer). This would be both counterintuitive to the intended
purpose of the TTL, and would also be contrary to the test
specification (see Test Procedure step 1 in MESH/NODE/RLY/BV-01-C).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Johan Hedberg bed5472cab Bluetooth: Mesh: Remove unnecessary variable
Most places in bt_mesh_friend_req() used rx->sub (which is already
quite short in itself), so just remove the only remaining user and the
helper variable itself.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-29 13:05:34 +02:00
Vakul Garg 26f43950f2 net: pkt: Corrected data length appended in net_pkt_append()
The maximum data length that can be appended using net_pkt_append()
should be set to TCP send_mss only if it is smaller than allowed
payload length in net_pkt.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-28 12:30:01 -05:00
Vakul Garg 687bd0d710 net: pkt: Account for IP header length for allowable payload data
For calculating amount of payload data that can be added in a packet,
we need to subtract IPv6 or IPv4 header lengths from MTU.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-28 12:30:01 -05:00
Ding Tao 6caf6964cd net: pkt: Fix possible division by zero
When net debugging is enabled, the count variable is initialized to -1.
This may cause division by zero if there is only one fragment in pkt.
Solve this by setting the count to 0 and checking the value before the
print at the end of the function.

Successfully tested on STM32F407 SoC.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2017-11-28 12:28:10 -05:00
Johan Hedberg c393bfd8e3 Bluetooth: Mesh: Fix Friend messaging state tracking
There were several issues with the code:

 - queue_size wasn't properly kept up to date, leading to erroneous
   buffer discarding logic.

 - Poll timeout when there were buffers in the Friend Queue didn't
   work because we didn't track if there'd been a preceding request
   for messages or not (hence the added pending_req variable).

 - We would overwrite the recv_delay timer if there was another
   request while the previous one was still sending (a likely scenario
   if we send out multiple advertising events per packet).

 - We weren't canceling the sending of a buffer if the Friendship was
   suddenly cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 49c5e5546a Bluetooth: Mesh: Log information about the on-behalf-of flag
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg b123799ebe Bluetooth: Mesh: Reduce logging clutter for LPN lookups
The logs for looking up LPNs were spamming the console a bit too much.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg c65d04655d Bluetooth: Mesh: Fix looking up existing friendship contexts
When receiving Friend Offers we should also consider unestablished
contexts, and simply start from the beginning if that happens.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg a9a18cec7b Bluetooth: Mesh: Fix clearing Friend state upon reset
Not clearing the Friend state could risk invalid timers staying
active, etc.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 2d63f5e480 Bluetooth: Mesh: Fix & clean up Friendship Credential handling
Pass the subnet to some friend_cred_* APIs since it contains all
necessary information for choosing the right keys to generate them
from. Also shorten the API names to avoid awkward line splitting -
these are internal APIs so it's an acceptable compromise. One bug that
this fixes as part of the cleanup is using the right NetKey Index when
clearing Friendship: previously the code was always using the index of
the first subnet, regardless of which subnet the Friendship was based
on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg e7199060c6 Bluetooth: Mesh: Remove unnecessary logic for key selection
Key Refresh Phase 2 is analogous to the Key Refresh flag being set.
This means that the flag can directly be used as the index to the
new/old key two-element array.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 46f8c7fb44 Bluetooth: Mesh: Fix clearing network message cache
Since the stack supports runtime reset and reprovisioning, we need to
clear the network message cache whenever creating a new mesh network.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 48e6bfaaa7 Bluetooth: Mesh: Fix proxy advertising handling
Remove inconsistent and sometimes unreliable tracking of what
advertising parameters should be used and when the Node Identity
advertising started. The main change that facilitates this is to have
the Node ID start timestamp as part of the mesh subnet context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg bdcf8c3692 Bluetooth: Mesh: Use 32-bit math for Node ID duration
The Node Identity duration is at most 60 seconds, so it's safe to use
32-bit timestamps.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 7909c3d3fa Bluetooth: Mesh: Introduce option for Node ID timeout
Some PTS test cases only work when we're advertising using Network
Identity. Using the default timeout of 60 seconds for Node Identity
will cause this test cases to fail (i.e. the PTS gives up before
Zephyr transitions to advertising from Node Identity to Network
Identity).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 699a7c9e85 Bluetooth: Mesh: shell: Fix parsing "boolean" parameters
The shell was being inconsistent in its parsing of boolean parameters.
Some commands were documented as accepting "on" but were actually
parsing the parameter with strtoul() which would result in 0.
Introduce a new helper to convert a string to a u8_t which still
accepts "on" or "enable". This gives us full flexibility of having a
simple interface to the user, but still allowing non-boolean values to
be tested (since on-air the value is a full octet).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg f81b23a624 Bluetooth: Mesh: shell: Add command for setting the UUID
Instead of having a hard-coded UUID, introduce a command to change it.
This is particularly useful if there are many unprovisioned nodes
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Johan Hedberg 4c180d6fbf Bluetooth: Mesh: shell: Make Static OOB optional
Having the Static OOB value set up-front can be confusing to the user
since they will not know what the value is. Start off by having it
unset, but introduce a new command using which the user can either set
or clear it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-28 17:17:48 +02:00
Anas Nashif 1092a25978 kconfig: move GDB_INFO kconfig to subsys/debug
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-27 22:15:30 -05:00
Vinayak Kariappa Chettimada b022f72cf4 Bluetooth: shell: Fix compile error due to missing memq.h include
Fixes the following compile error when building
tests/bluetooth/shell application:

In file included from subsys/bluetooth/shell/ticker.c:16:0:
subsys/bluetooth/shell/../controller/util/mayfly.h:21:2:
error: unknown type name 'memq_link_t'
  memq_link_t *_link;
  ^~~~~~~~~~~

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-27 13:48:24 -08:00
Johan Hedberg f20afb7473 Bluetooth: Mesh: Restrict scope of variables in health_get_registered()
Don't declare the variables in a wider scope than what they're needed
for.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg c2fd67699d Bluetooth: Mesh: shell: Fix sending health publication
We need to send out a Health Fault Current Status (the Health Model's
publication message) when all faults are cleared. The logic for
calculating number of faults was also wrong after the updated model
publication API.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Johan Hedberg 8a13066a4e Bluetooth: Mesh: shell: Fix health publication message size
The Health Current Fault message size was being set too small to fit
any faults. Use a macro to make sure the size gets applied in both
places where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 12:10:49 +02:00
Vakul Garg d5134d9bf3 Bluetooth: Added missing checks for whether CONFIG_BT_PRIVACY is enabled
Fixes error encountered during connecting BLE endpoint.
[bt] [ERR] le_remote_feat_complete: Unable to lookup conn for handle 32

This is to work around a buggy controller that states support for
enhanced privacy, but misbehaves when it's enabled. This change
makes it possible to ensure the host doesn't try to enable the enhanced
event by simply disabling the privacy feature in Kconfig.

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
2017-11-27 11:30:00 +02:00
Johan Hedberg d0826f3392 Bluetooth: Mesh: Fix NetKey Update behavior in Phase 1
If we get a different key value in Phase 1 we should return the same
"Cannot Update" error as in phases 2 and 3. This fixes test case
MESH/NODE/KR/BI-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg 48aecd1513 Bluetooth: Mesh: Add IV Update test mode API
This makes it possible to pass all IV Update tests without having to
build a custom configuration for some of the tests. We also disable
the feature in all sample configurations, but leave it on in the
tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg a41449ef2a Bluetooth: Mesh: shell: Add iv-update command
This command is needed to pass some IV Update-related PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:54 +02:00
Johan Hedberg 6e2a3863ac Bluetooth: Mesh: Fix creating initial beacon data
There was a chance that initial beacons for subnets would be sent with
uninitialized data. Make sure we initialize the beacon data each time
when we create a new subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-27 10:17:42 +02:00
Johan Hedberg a48724fd0f Bluetooth: Mesh: shell: Fix & clean up command help
Use NULL instead of "", fix typos, and indicate app-key-add last
parameter as optional (to match the command implementation).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 35fd523b03 Bluetooth: Mesh: Add support for manipulating Label UUIDs
Add support for sending messages that add, delete or overwrite Label
UUIDs, and add commands for these to the shell. With the help of these
commands it's possible to pass Transport Layer PTS tests (in
particular TNPT/BV-05-C) by manually adding a Label UUID through
module subscription, since the test case itself does not do this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 23ffed0511 Bluetooth: Mesh: Improve logging related to Label UUID lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg e80881d0b9 Bluetooth: Mesh: shell: Add raw network PDU sending support
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg b0393caeb5 Bluetooth: Mesh: shell: Add support for decoding hex strings
Add helper to decode arbitrary-length hex strings. The first user is
the AppKeyAdd handler.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Johan Hedberg 561b458011 Bluetooth: Mesh: shell: Fix decoding vendor model IDs
The code was accessing the wrong parameter.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 17:12:20 +02:00
Aska Wu 8a20c4add7 net: context: Make sure contexts lock is released when error
Also, set the in-use flag after it is allocated successfully.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-24 08:30:00 -05:00
Patrik Flykt 753daa65f9 net: pkt: Compute TX payload data length
Compute the length of the TX payload that is transported in one
IPv4 or IPv6 datagram taking into account UDP, ICMP or TCP
headers in addition to any IPv6 extension headers added by RPL.
The TCP implementation in Zephyr is known to currently carry at
maximum 8 bytes of options. If the protocol is not known to the
stack, assume that the application handles any protocol headers
as well as the data. Also, if the net_pkt does not have a
context associated, length check on the data is omitted when
appending.

Although payload length is calculated also for TCP, the TCP MSS
value is used as before.

Define IPv4 minimum MTU as 576 octets, See RFC 791, Sections 3.1.
and 3.2.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-11-24 08:27:39 -05:00
Johan Hedberg 9097a66460 Bluetooth: Mesh: LPN: Fix clearing group status
When the Friendship is lost the group status tracking needs to be
cleared.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 9859146722 Bluetooth: Mesh: LPN: Fix clearing pending request
The code would unconditionally clear sent_req in update_timeout(),
which would e.g. cause us to switch to Friend Polls if the Friend
didn't respond to a Subscription List Add/Remove on the first attempt.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 4cc6a4fcbb Bluetooth: Mesh: Increase initial poll timeout
The purpose of using something less than the configured poll timeout
was to cover the case where the LPN establishes Friendship before the
provisioner has completely configured it. However, there's the "more
data" flag in the initial Friend Response, and we now also have a
public API to request for more messages. Both of these features
diminish the value of having a reduced initial timeout. Also, some LPN
test cases do not expect us to send frequent polls initially, causing
failures with the PTS.

Therefore, introduce a Kconfig option to set the initial timeout, and
make it default to the actual poll timeout.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 89030f0906 Bluetooth: Mesh: Introduce public LPN APIs for better control
Many apps, the mesh shell included (due to PTS test requirements)
benefit from exposing LPN state and polling outside of the stack.
Introduce new APIs for these, and add code to the mesh shell module to
take advantage of them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-24 11:37:09 +02:00
Johan Hedberg 46e0afdf82 Bluetooth: Mesh: Health: Fix requiring specific Company ID
The Health Fault Test & Test Unacknowledged messages are supposed to
be sent for more than the Node Composition Data Company ID. It's true
that some PTS tests require the message to be ignored for
non-composition data ID, however that's something that should be
covered by the application that's used for testing, and not the
generic Health Server Code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg d588850c0c Bluetooth: Mesh: Add support for Health Attention messages
Add support for sending Health Attention messages, as well as commands
to use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 30d6761396 Bluetooth: Mesh: Introduce helpers to wait for a status message
There was a lot of code duplicated in the Foundation Client Models for
waiting on a specific status message. Refactor this into helper
functions (one per client model).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 7e8f9afee5 Bluetooth: Mesh: Add support for Health Period messages
Add support for sending Health Period messages, as well as commands to
use these new APIs from the shell.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg ce10be3a2a Bluetooth: Mesh: Add support for Health Fault Test messages
Add support for sending Test and Test Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 987c68b7aa Bluetooth: Mesh: Add support for Health Fault Clear messages
Add support for sending Clear and Clear Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 9e3ebf19d9 Bluetooth: Mesh: shell: Add Health Fault support to the server
Add commands and callbacks to manage the Registered Fault state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 1699d045f8 Bluetooth: Mesh: shell: Use a valid Company ID
The Company ID 0xffff is treated as invalid in some contexts, so use a
valid one. Also, the Health tests require the Health Fault Company ID
to match that found in the Composition Data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 2eda34cf3f Bluetooth: Mesh: Add support for receiving Health Current Status
Add a callback to the Health Client Model context, so that the
application is able to receive Health Current Status messages that
some Health Server Model publishes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg b26231d770 Bluetooth: Mesh: Add support for sending Health Fault Get message
Add the needed Health Client API for sending Health Fault Get, and add
a command to the shell to utilize it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 7ef5e53e28 Bluetooth: Mesh: Add skeleton for Health Client model
Add a skeleton for the Health Client model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Johan Hedberg 2a6010f1b3 Bluetooth: Mesh: shell: Add appidx command for setting the AppIndex
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-23 14:49:55 +02:00
Vinayak Kariappa Chettimada f9cd9d4a7b Bluetooth: controller: Fix compile error when LE_ENC is disabled
Fixes the following compile error when CONFIG_BT_CTLR_LE_ENC
is disabled:
subsys/bluetooth/controller/ll_sw/ctrl.c: In function
'isr_rx_conn_pkt_ctrl':
subsys/bluetooth/controller/ll_sw/ctrl.c:2613:29: error:
'LLCP_ENCRYPTION' undeclared (first use in this function)
         (conn->llcp_type != LLCP_ENCRYPTION)) ||
                             ^~~~~~~~~~~~~~~
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:48:05 -05:00
Johan Hedberg ea68c3aa22 Bluetooth: Fix compiler warning when VS HCI is unset
Fixes:

subsys/bluetooth/host/hci_core.c: In function ‘set_static_addr’:
subsys/bluetooth/host/hci_core.c:4043:1: error: label ‘generate’ defined
but not used [-Werror=unused-label]
 generate:
 ^~~~~~~~

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 18:48:05 -05:00
Vinayak Kariappa Chettimada 9fd502f956 Bluetooth: controller: Use PPI indices 14/15 for PA/LNA
PA/LNA feature being not default enabled, keeping the PPI
indices used for this feature at the higher indices would
allow use of these PPI indices by other drivers, for
instance the nRF5 software PWM driver.

Software PWM driver provides 3 PWM pins/channels using upto
6 PPI channels. If BLE controler where to use 0-13, then
14-19 PPI indices can be used by the PWM driver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 18:46:20 -05:00
Jukka Rissanen 1789a9356b net: app: Honor MTU when sending TLS/DTLS data
Make sure we send all the data that is needed to be sent and in
proper MTU size chunks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-22 10:10:31 -05:00
Tomasz Bursztyka b52c0f24a6 net/ieee802154: Make RAW mode generic
- Renaming NET_L2_RAW_CHANNEL to NET_RAW_MODE
- Create a generic IEEE 802.15.4 raw mode for drivers
- Modify the IEEE 802.15.4 drivers so it passes the packet unmodified,
up to code using that mode to apply the necessary changes on the
received net_pkt according to their needs
- Modify wpanusb/wpan_serial relevantly

Fixes #5004

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-22 10:10:09 -05:00
Vinayak Kariappa Chettimada f44efd12fa Bluetooth: controller: Replace void * with memq_link_t
Replace use if void * declaration related to memq links with
more readable memq_link_t.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-22 15:28:49 +01:00
Johan Hedberg 6fda8b2b4d Bluetooth: Mesh: Friend: Fix poll timeout type
The Poll Timeout needs to be at least 24 bits, so u16_t doesn't
suffice and will potentially result in truncation. Use u32_t, thereby
also fixing a coverity warning.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 9b87e0f2cc Bluetooth: Mesh: Fix coverity warning of unchecked return
Most places check the return value of bt_mesh_model_send(), so check
for it in all places.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 2849662aa8 Bluetooth: Mesh: Fix dereferencing mod->pub too early
The bt_mesh_model_publish() is supposed to return a "not supported"
error if the publish context doesn't exist. Fixing the premature
dereferencing also fixes coverity warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 7c53d31ed2 Bluetooth: Mesh: remove redundant 32-bit wrap-around code
The separate checking for "now < reftime" is unnecessary, since the
integer over/under-flow for unsigned 32-bit values resulting from
subtraction will give the right delta even if 'now' is less than the
reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 15fe221f13 Bluetooth: Mesh: Fix accuracy of Publish Period
After the Publish Retransmit state was introduced the Publish Period
measurement would begin once the previous Publish message has finished
transmitting. This will however cause inaccurate periods, which is
particularly an issue with the PTS that expects accuracy of less than
0.5 seconds (apparently).

Since the publication timer is also used for the retransmissions we
can't simultaneously use if for the period as well. Therefore, we
introduce a new variable called period_start which makes a note of
when the period was supposed to start, and then once all
retransmissoins are done initializes the timer with the send duration
taken into account.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Johan Hedberg 8f1541184f Bluetooth: Mesh: Fix non-periodic Model Publication
The only generally available model supporting publication that's
convenient to be used for testing is the Health Server Model.
Unfortunately since this model supports period publication, the
non-periodic side got less attention and had some bugs.

The first thing that needs to be done is to verify that the period
returned by bt_mesh_model_pub_period_get() is positive. If it's zero
then no periodic publication should take place.

Another thing that this patch cleans up is the naming of the callback
used for periodic publishing. There's no need do require the callback
to call bt_mesh_model_publish() since this must happen no matter what,
so instead rename the callback from 'func' to 'update' and have the
access layer call bt_mesh_model_publish() if the callback was
successful.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-22 12:53:54 +02:00
Robert Chou b678895a6d net: lwm2m: POST with <obj>/<obj instance> is a WRITE op
Per LwM2M specification V1_0_1-20170704-A, table 25.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-21 09:28:12 -05:00
Johan Hedberg 03151fc8d7 Bluetooth: Mesh: Proxy: Downgrade advertising errors to warnings
When a small amount of supported connections is configured (especially
the default number of 1), connectable advertising may fail. This is
perfectly fine since as soon as a disconnection event happens the
advertising will be successfully restarted. To avoid causing
unnecessary user worries, downgrade the resulting errors to warnings.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Johan Hedberg 95bef3694e Bluetooth: Mesh: Fix node reset
There were some things that were working only when receiving a Node
Reset message from someone else, but not when the app called
bt_mesh_reset() directly. There was also some state cleanup missing
for the transport layer. This patch addresses all of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 15:02:25 +02:00
Paul Sokolovsky 21f31e90ec net: sockets: Handle EINTR return from k_poll()
In 90b471fe4, there was a change to make k_poll() return EINTR error
if it was cancelled with k_fifo_cancel_wait(). Handle this change, or
otherwise sockets EOF handling was broken.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-21 07:01:49 -05:00
Aska Wu 3689107b59 net: tcp: First check sequence number
Previously, the connection will be reset easily due to a forged TCP
reset with a random sequence number.

As described in RFC793 p.69, we should check if the sequence number
falls into the receiver window at first.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-21 07:00:20 -05:00
Johan Hedberg 3a072f07a1 Bluetooth: Mesh: shell: Declare mandatory dependency on BT_MESH_CFG_CLI
The Configuration Client is such a generally useful feature for the
shell that it makes sense to have it as a mandatory dependency (the
shell wasn't anyway compiling at the moment without it).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 13:32:53 +02:00
Johan Hedberg 5a3a9aed49 Bluetooth: Mesh: Update TODO file
Update the TODO file with the latest status.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-21 12:19:41 +02:00
Vinayak Kariappa Chettimada 25737d9963 Bluetooth: controller: Optimise memq interface
Optimised the parameter passing order of memq interface such
that the compiled code uses less space and execution time.

Having a parameter that gets returned as the first parameter
passed to a function avoids instructions required to have
the result in the return register.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-21 09:11:34 +02:00
Johan Hedberg 47756c8364 Bluetooth: Mesh: shell: Add mod-sub-del command
Add command to delete model subscriptions.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 324336167e Bluetooth: Mesh: Add Model Subscription Del & Overwrite support
The Del and Overwrite operations have the exact same parameters and
expected status response as the Add operation, so we can reuse most of
the code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg a5340e72a3 Bluetooth: Mesh: Fix ignoring all messages in LPN mode
Even though we have LPN enabled, we might still receive messages
through other network interfaces than the advertising one (e.g. the
local network interface).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg ec9aaaed23 Bluetooth: Mesh: Fix calling send start for multi-segmented messages
Using the start callback, especially with multi-segment messages, may
not be super useful for applications, but we should support if if they
do provide it. One application could e.g. be to calculate the duration
it takes for a multi-segment message to be completely received by the
remote end.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg e7bb76e2b6 Bluetooth: Mesh: Fix model publication
Model publication was broken in a couple of ways:

 - The Publish Retransmit State was not taken into account at all
 - Health Server used a single publish state for all elements

To implement Publish Retransmit properly, one has to use a callback to
track when the message has been sent. The problem with the transport
layer sending APIs was that giving a callback would cause the
transport layer to assume that segmentation (with acks) is desired,
which is not the case for Model Publication (unless the message itself
is too large, of course). Because of this, the message sending context
receives a new send_rel ("Send Reliable") boolean member that an app
can use to force reliable sending.

Another challenge with the Publish Retransmit state is that a buffer
is needed for storing the AppKey-encrypted SDU once it has been sent
out for the first time.To solve this, a new new net_buf_simple member
is added to the model publication context. The separate 'msg' input
parameter of the bt_mesh_model_publish() API is removed, since the
application is now expected to pre-fill pub->msg instead.

To help with the publishing API change, the Health Server model gets a
new helper macro for initializing the publishing context with a
right-sized publishing message.

The API for creating Health Server instances is also redesigned since
it was so far using a single model publishing state, which would
result in erratic behavior in case of multiple elements with the
Health Server Model. Now, the application needs to provide a unique
publishing context for each Health Server instance.

The changes are heavily intertwined, so it's not easily possible to
split them into multiple patches, hence the large(ish) patch.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg f9fad553ac Bluetooth: Mesh: Fix encoding/decoding Publish Retransmit value
The Model Publish Retransmit Interval is in units of 50ms and not 10ms
like the other transmit/retransmit states. Create dedicated macros for
the Publish Retransmit State and use them where appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 4bf045e282 Bluetooth: Mesh: Use a unified send callback also for public API
There's no need for callback exposed in the public API to be something
different than what's used internally. In fact this would just
complicate things. This patch exposes the internal callback under a
bt_mesh_adv_cb name and uses it throughout the mesh stack.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 224506c78c Bluetooth: Mesh: Fix notifying message send completion for GATT proxy
In case an outgoing message gets only delivered to the proxy interface
we should not forget to notify the send callbacks of this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg c3ad883872 Bluetooth: Mesh: Introduce a second advertising callback
Some places of the code are interested in when the first advertising
event goes out. Others, on the other hand, are interested when the
last advertising event goes out. Some are even interested in both of
these. Instead of providing a single callback, provide a struct with
two possible callbacks for sending advertising PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg 8beb6784d3 Bluetooth: Mesh: Introduce user data for the advertising callback
This simplifies the callback implementations since they no-longer need
to do their own look-ups of the needed context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Johan Hedberg ad7afa0c7c Bluetooth: Mesh: Move per-buffer mesh meta-data to external struct
We've so far been trying to keep the per-buffer mesh meta-data to
a maximum of 8 bytes in anticipation of upcoming net_buf refactoring
that'll have all net_bufs in the system with the same sized user data.

It's however slowly becoming unfeasible to do this - e.g. simply
adding user data to the sending callback would already fill up the
full 8 bytes.

To solve this issue, treat the net_buf user data as just a pointer to
the actual user data, and keep the actual user data in a separate
array. We still keep taking advantage of net_buf_id() however, so
buffers can cheaply be mapped to their meta-data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-20 15:00:29 +02:00
Aska Wu 718b3cd7d0 net: sockets: Support ipv6 wildcard and loopback address
Add in6addr_any and in6addr_loopback which are defined in RFC2553 Basic
Socket Interface Extensions for IPv6.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-20 13:42:38 +02:00
Aska Wu b6c8c2d749 net: tcp: Fix tcp passive close
Previously, if passive close is peformed, the net context is released
after FIN is received and FIN,ACK is sent. The following last ack from
the peer will be treated as an improper packet, RST is sent to the peer.

This patch refines tcp_established() by centralizing the tcp state
transition and releases the net context only if NET_TCP_CLOSED is
reached.

Besides, the logic that releases the net pkt without appdata (i.e. ACK
or FIN) is moved from packet_received() to tcp_established(). This makes
packet_received() less dependent on the protocol and make the usage of
net pkt more clear in tcp_established().

Fixes: #4901

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-20 13:42:10 +02:00
Vinayak Kariappa Chettimada 9746b2a75d Bluetooth: controller: Fix memq_dequeue function
When testing memq implementation used by controller, a
missing check on NULL pointer return could lead to NULL
pointer deferencing.

Current implementation of controller and mayfly do not
by design lead to NULL pointer dereferencing, this fix
is only for correct-ness and complete-ness.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-20 10:42:53 +02:00
Jukka Rissanen c0fc269edf net: app: Do not allow local unspecified address in client
Do not allow :: or ANY address in client when sending data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-18 08:52:40 -05:00
Johan Hedberg 6d7f171549 Bluetooth: Mesh: Fix clearing incomplete Friendship upon reset
When resetting there is no point trying to start clearing the
Friendship since there will not be any security material left to send
out PDUs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg 62f2475e3e Bluetooth: Mesh: Fix compiler warning for access.c
This fixes a warning for duplicate const declaration specifier.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 14:44:19 +02:00
Johan Hedberg 1edb69e4b6 Bluetooth: Mesh: Make AppKey binding implicit for Model Publication
The common interpretation (among other implementations) seems to be
that Model Publication for a given AppKey Index implies a binding for
that AppKey. This isn't currently explicitly stated in the spec, but
in order to improve interoperability go with this interpretation as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:24:30 +02:00
Johan Hedberg 1c825c825f Bluetooth: Mesh: Friend: Fix setting pending_buf variable
The variable for tracking that a buffer from the Friend Queue hasn't
been sent yet was not being properly set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-17 13:09:45 +02:00
Aska Wu 7e58c5609a net: sockets: Fix net pkt leak
If net_context_recv() returns a error, net pkt will not be released. For
example, net_context_recv() returns -EBADF because the TCP connection is
closed by the peer.

Handle the return value instead of using SET_ERRNO().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-17 12:58:32 +02:00
june li 486e156827 net: dhcpv4: Unref net_pkt if message sending fails
If we cannot send a DHCP message, then unref the net_pkt
in order to avoid a buffer leak. Earlier we tried to
unref NULL net_pkt which is not correct.

Signed-off-by: june li <junelizh@foxmail.com>
2017-11-17 11:16:04 +02:00
Johan Hedberg bd69b2127e Bluetooth: Mesh: Use dedicated struct for heartbeat subscription
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg d4365e16f9 Bluetooth: Mesh: Use dedicated struct for heartbeat publication
This simplifies the API since there is no-longer a need to pass a huge
number of function arguments around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg a18a22524f Bluetooth: Mesh: shell: Add mod-pub command
Add a command for getting and setting the model publication. We also
have to adjust the app's configuration, since both the Model
Publication Set and Status messages are segmented messages, meaning we
need two TX and RX segment contexts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg 05be6b8033 Bluetooth: Mesh: Add support for sending Model Publication messages
Add support for Model Publication Set/Get and their vendor model
variants.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Johan Hedberg 2e50ba9847 Bluetooth: Mesh: Use invalid CID instead of bool for non-vendor models
The value 0xffff is reserved, so we can use that to indicate whether
there's a vendor model in question or not. Simplifies things over the
previously used separate boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 15:35:10 +02:00
Robert Chou 9dcbbdb3e2 net: lwm2m: fix sending packet w/o token setup when error
Token is missing when we jump to the error and token is not yet setup.
To correct it, we grab the token from the input packet at the beginning
of the handle_request()

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-16 10:21:14 +02:00
Johan Hedberg bde9dcd3bc Bluetooth: Mesh: Fix enabling scanning after provisioning
There were some needed changes missing after the update to have manual
control of PB-ADV & PB-GATT provisioning bearers. E.g. the test for
CONFIG_BT_MESH_LOW_POWER in net.c was no-longer indicative of scanning
being on or not.

Do the scan enabling selection within the LPN module if LPN is
supported, or otherwise enable scanning unconditionally in
bt_mesh_provision().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-16 08:39:00 +02:00
Ramakrishna Pallala a895d21d63 subsys: random: Fix semaphore initial count of xoroshiro128
Semaphore state_sem initial count is set to 0 but k_sem_give()
is invoked first in sys_rand32_get() which will block the caller
forever.

Fix the issue by setting the initail count to count_limit.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2017-11-15 15:47:10 -06:00
Johan Hedberg 45f258686b shell: Fix looking up help for the current module
The code was not properly handling "help <cmd>" for the currently
selected module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 7318904ae1 shell: Use struct shell_module instead of integer to refer to modules
It's much more intuitive to read "if (module)" instead of
"if (module != -1)" when checking for a valid module. Update the code
to use struct shell_module pointers instead of integers for tracking
modules.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 22b5ff9b29 shell: Redesign internal command handling
Make the internal commands (exit, select & help) as any other
commands, so that e.g. "help help" works as expected. Also redesign
the way commands are looked up to avoid duplicate lookups.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 329a6628e4 shell: Remove unnecessary function
The print_cmd_unknown() is just a two-liner and only called from a
single place, so just do the printk calls inline.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg f9e30ed582 shell: Fix command lookup for non-default modules
The code was completely broken wrt command lookups when the command is
given in the format "<module> <cmd> <args...>". It would only work if
the default module is not set, which is almost never the case (as most
apps set it explicitly).

Refactor the command handling by moving more logic up to shell_exec(),
so that get_cb() does a lookup for a single module

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg fe20f55d03 shell: Remove redundant checking for argv[0]
The way get_command_and_module() is used it's impossible for it to be
given an argv where argv[0] is NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 74556b7abb shell: Fix unnecessary passing by reference of argc
The get_cb() function does not modify argc, so there's no point in
passing it by reference.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 39a733151d shell: Remove unnecessary first_string variable
This variable adds no value, and is in fact longer to spell out than
simply argv[0].

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 76fb522993 shell: Remove redundant checking for first parameter
The way the command line parsing works, argv[0] is always guaranteed
to be non-NULL as well as a non-empty string, so doing checks for this
in get_cb() is redundant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Johan Hedberg 04fbb80adb shell: Remove unnecessary initialization of err
All code paths in shell_exec() are guaranteed to set err before
returning it, so doing this (rather curious) initialization is
completely unnecessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 16:04:39 +02:00
Michael Scott 6a5da2c574 net: lwm2m: fix max measurement checks
Copy/paste error was checking minimum measurements where it
should have been checking maximum measurements.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00
Michael Scott 157115c7d8 net: lwm2m: temp_sensor: fix min/max measurement values
Initial values for the min/max measurements were 0 and this caused
issues with sensors maximums that weren't above 0 and minimums that
went below 0.  Let's update those to MAX_INT so the first sensor
value update will set those to correct values.

When resetting the measured values, let's use the current sensor
value not 0.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00
Michael Scott 806d8f3baa net: lwm2m: refactor min / max measurement update code
Split out update code to make it re-usable.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-11-15 15:31:45 +02:00
Johan Hedberg c8b51ded29 Bluetooth: Mesh: shell: Fix newline in incorrect place
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:38:54 +01:00
Johan Hedberg d4be608036 Bluetooth: Mesh: Allow changing cfg client message timeout
10 seconds is quite long for configuration messages, and way too much
currently since we only talk through the local networking interface.
Set the default timeout to 2 seconds, and provide APIs through which
the timeout may be changed at run-time (mainly useful for the shell).

Note: The timeout_set() API is normally assumed to be called just once
for an application, based on the expected size of the network (hops &
latency). Trying to change it e.g. in a multi-threaded environment for
every message may not yield the expected results.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 882ce59e97 Bluetooth: Mesh: shell: Convert hb-sub-set command to hb-sub
Convert the hb-ub-set command to a more generic hb-sub that can be
used both for getting and setting the Heartrate Subscription State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 7b27d96f96 Bluetooth: Mesh: Add support for sending Heartbeat Subscription Get
Add support for sending the Heartrate Subscription Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 135fd92492 Bluetooth: Mesh: shell: Convert hb-pub-set command to hb-pub
Convert the hb-pub-set command to a more generic hb-pub that can be
used both for getting and setting the Heartrate Publication State.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 9bf8af8507 Bluetooth: Mesh: Add support for sending Heartbeat Publication Get
Add support for sending the Heartrate Publication Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 8e9e039700 Bluetooth: Mesh: shell: Implicitly initialize Bluetooth support
Avoid having to go do "init" for the bt module before issuing "init"
for the mesh module. Instead perform Bluetooth init implicitly. The
bt_enable() API will cleanly fail with -EALREADY if it was previously
called.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg d35061357a Bluetooth: Mesh: shell: Add provision command for self-provisioning
This is for testing purposes, in case an external provisioner is not
available or not wanted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg e631d6d6cc Bluetooth: Mesh: shell: Add hb-pub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 5e3804b11d Bluetooth: Mesh: Add support for sending Heartbeat Publication Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 2d40c1673c Bluetooth: Mesh: Fix calling complete callback for bt_mesh_provision()
If the app does direct provisioning, it may still want to do common
handling through its provisioning complete callback (if it has one
registered). This also means that we always require a non-NULL
provisioning context provided to bt_enable(), and that it needs to
fail if NULL was given.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 255edcfde2 Bluetooth: Mesh: Provisioning: Add NetKeyIndex to complete callback
It may be useful for the app to know what the initial NetKeyIndex that
it was given during provisioning is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 0b53341d92 Bluetooth: Mesh: shell: Group global variables in a dedicated struct
This avoids conflicts with function-local variables being called the
same way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 70cbcef576 Bluetooth: Mesh: Rename health server code from health to health_srv
This is in anticipation of soon adding health client support, which
could then cause confusion due to the ambiguous API names.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 3b252ca2be Bluetooth: Mesh: Rename configuration server code from cfg to cfg_srv
Now that there's support for configuration client as well, rename cfg
to cfg_srv to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 0ef7c6e09a Bluetooth: Mesh: Add more flexible APIs for provisioning bearers
Add the ability to track the provisioning bearer through an extra
parameter to link_open/close. Also introduce new public functions to
enable/disable specific provisioning bearers. This also means that one
now needs to explicitly enable provisioning bearers after calling
bt_mesh_init().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg a81fa43a59 Bluetooth: Mesh: Use proper _t suffix for typedefs
To be consistent with the coding style, use a _t suffix for typedefs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
june li c6407659f3 net: tcp: Add the frag back to caller allocated net_pkt
The original fragment chain of incoming packet will be lost and leaked
in case of early error, add frag back to packet and
let the caller do unref.

Fixes #4323

Signed-off-by: june li <junelizh@foxmail.com>
2017-11-15 12:28:18 +02:00
Jukka Rissanen 8dab561689 net: loopback: Skip neighbor checks for local packets
No need to do any IPv6 neighbor checks if the packet is routed back
to us by loopback driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-15 12:27:14 +02:00
Jukka Rissanen d315b430d4 net: Let loopback driver handle lo if it is enabled
If there is loopback interface, then let it handle all local
traffic. Loopback interface is only needed for test applications.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-15 12:27:14 +02:00
Johan Hedberg 7f6070fb6c shell: Add optional command description
The command name and a shortened form of valid parameters is not
necessarily enough to understand its usage. Add the option of
providing a more lengthy description of the command usage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 07:51:02 +02:00
Jukka Rissanen 9663287bf0 net: context: Check if TCP header is found
If the packet is too short, the TCP header pointer might be
NULL. In this case we just need to bail out.

Coverity-CID: 178787
Fixes #4787

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 23:03:16 +02:00
Johan Hedberg c87ecf58de shell: Include the command help when listing all commands
Most commands provide a short string to describe the parameters it
takes. Provide this help text as part of the list of supported
commands for each module.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 21:32:20 +02:00
Johan Hedberg d235f9cc6f Bluetooth: Mesh: shell: Add hb-sub-set command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 63329b79d6 Bluetooth: Mesh: shell: Add mod-sub-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg c233ce4fdb Bluetooth: Mesh: shell: Add app-key-bind command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 5429f14a69 Bluetooth: Mesh: shell: Add app-key-add command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 6585347f78 Bluetooth: Mesh: shell: Add for relay and 1-byte state commands
Add commands for 1-byte states such as Default TTL, Friend and GATT
Proxy, as well as the 2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg cc54f8c84c Bluetooth: Mesh: shell: Add support for Beacon Get/Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 96934bd3d4 Bluetooth: Mesh: shell: Add "dst" & "netidx" commands
Add commands to modify the used destination address and NetIdx.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 7a1c0b979e Bluetooth: Mesh: shell: Add support for getting composition data
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg f50b99572f Bluetooth: Mesh: Add support for sending Heartbeat Subscription Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg b4688bdc84 Bluetooth: Mesh: Add support for sending Model Subscription Add
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e4db09e919 Bluetooth: Mesh: Add support for sending Model App Bind message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e1bc6a6141 Bluetooth: Mesh: Add support for sending AppKeyAdd message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg cbfea942f6 Bluetooth: Mesh: Add support for Relay and 1-byte state Get/Set
Add support to the Configuration Client Model for getting and setting
1-byte states (which can be nicely generalized in code) as well as the
2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 07305fd71d Bluetooth: Mesh: Add support for sending Beacon Get & Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 3d1ce43eb0 Bluetooth: Mesh: Add support for sending Get Composition Data
Add Get Composition Data support to the Configuration Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 588887c9b7 Bluetooth: Mesh: Add primary address to provisioning complete callback
It may be useful for the app to know that the local node's primary
address is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 2a1e16c2a3 Bluetooth: Mesh: Add skeleton for Configuration Client Model
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 17c9b3a105 Bluetooth: Mesh: Make TRANSMIT_COUNT & TRANSMIT_INT macros public
These are useful for apps who want to implement/use the Configuration
Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Grzegorz Kolodziejczyk 1ff3ab5f82 Bluetooth: Mesh: Add read callback for ccc in provisioning service
This patch adds read permission for client characteristic configuration
descriptor. This is required by MESH/NODE/MPS/BV-06-C,
MESH/NODE/MPS/BV-07-C PTS tests.

Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
2017-11-14 14:27:37 +02:00
Tomasz Bursztyka acd10bf7a0 net/ieee802154: Shell handles extended address in EUI-64 format
802.15.4, as other radio tech, works in little endian on network level.
To keeps things simple, the inner context per-interface, stores the
extended address that way. But it can be confusing in shell then, so
let's work handle these addreses through EUI-64 format there.

Fixes #4936

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-14 07:00:19 -05:00
Robert Chou 1d70a39d1b net: samples: replace tag zoap with coap
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-14 06:42:57 -05:00
Johan Hedberg 1c0ff01ac7 Bluetooth: Mesh: shell: Add command for Node Identity
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg a6af281f04 Bluetooth: Mesh: shell: Take advantage of link open/close callbacks
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg 75253195a4 Bluetooth: Mesh: shell: Add LPN toggling command
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Johan Hedberg e2e74f705b Bluetooth: Mesh: shell: Add basic skeleton
Add a basic shell skeleton for Mesh, containing basic command for
initialization, provisioning and reset.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 11:03:58 +02:00
Michael Scott e04a5412a1 net: http: client: remove payload send_chunk logic
Logic for sending chunks of data is incompatible with adding
Content-Length: header.

Per https://tools.ietf.org/html/rfc7230#section-3.3.1:
"A sender MUST NOT send a Content-Length header field in any
message that contains a Transfer-Encoding header field."

Going a bit further in my mind: also don't send Transfer-Encoded
chunked data either when the Content-Length header is present.

In general, there will be problems if the http client library
makes payload changes without the user code knowing about it.

This patch removes the use of http_send_chunk() from the new
HTTP client code and instead sends the payload directly to
http_prepare_and_send()

This fixes an issue where every available buffer would be allocated
with repeating payload data because the for loop in http_request()
wasn't ending until we ran out of memory.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Michael Scott 865d617772 net: http: honor CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT setting
We should not use the user suppied timeout setting in
http_client_send_req() for the connection timeout.  In the
previous API the call to tcp_connect() used
CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT as the timeout setting.

Let's do that here too.

This fixes -ETIMEDOUT error generation when using K_NO_WAIT
for http_client_send_req().

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Jukka Rissanen 7784518d37 net: http: Add error status string to HTTP server error
Add status error string when sending a error message from
HTTP server to client as described in RFC 2616 ch 6.1.
Previously only error code was sent except for 400 (Bad Request).

This also fixes uninitialized memory access in error message.

Coverity-CID: 178792
Fixes #4782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 09:52:46 +02:00
David Leach 09ce2e218f subsys/random: Add _ASSERT() test on returned device_get_binding
If there is a build setup problem where a device driver has not been
setup for the entropy driver then the call to device_get_binding()
will return a NULL value and the code will continue to use this NULL
value. The result is a hard fault later in code execution.

Note that CONFIG_ASSERT is by default off so one has to turn this
configuration on to catch this problem.

Signed-off-by: David Leach <david.leach@nxp.com>
2017-11-13 13:50:15 -08:00
Sebastian Bøe 578c91ae18 Bluetooth: storage: Fix linking with subsys__fs
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-13 15:10:20 +02:00
Johan Hedberg cc55e86cc8 Bluetooth: Mesh: Fix relaying packets
The restoring of the buffer parsing state was only correct for the
friend queue (which needs the app-layer data). Relaying on the other
hand requires the network layer data, i.e. it needs a different state
to be restored.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 02d98d0da0 Bluetooth: Mesh: Fix missing tracking of segment callback
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg e70f6dfc88 Bluetooth: Mesh: Take advantage of BT_MESH_TTL_MAX macro
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg a2a46e66e1 Bluetooth: Mesh: Export key packing helpers internally
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 9cbb979db7 Bluetooth: Mesh: Fix sending messages when not provisioned
The message sending APIs should fail cleanly if we are not yet
provisioned.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 514cebcfe8 Bluetooth: Mesh: Change local_queue from k_fifo to sys_slist_t
We never access the local network interface queue in a blocking
fashing, so it's unnecessary to have all the infrastructure that
k_fifo provides. Use the simpler sys_slist_t instead.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 092a28541a Bluetooth: Mesh: Provisioning: Introduce link open/close callbacks
It may be useful for the app to know when the provisioning link is
active and when it has been closed. This can be used e.g. to signal
the user the state of the device. Some PTS tests also require
verifying the link state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 25604f979d Bluetooth: Mesh: Provisioning: Fix encoding of OOB values into link.auth
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 32399a4cd2 Bluetooth: Mesh: Provisioning: Fix input OOB support
The code was missing the sending of the Input Complete PDU, and was
also setting the link.auth value too late.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 497fef85c3 Bluetooth: Mesh: Provisioning: Fix coding style (too long line)
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg ec6fd3575b Bluetooth: Mesh: Provisioning: Fix OOB string output
The OOB string was being generated in an incorrect way, resulting
essentially in garbage.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Jukka Rissanen 198d96cc9a net: shell: Ping command needs target host set
The ping command was not checking if the user gave target
host as a parameter. This would lead to NULL pointer access.

Fixes #4827

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-13 10:18:22 +02:00
Johan Hedberg d43a92b1c8 Bluetooth: Fix clearing advertising & scanning parameters
The parameter structs for advertising and scanning contain many
members that may not get explicitly set when enabling these states. Do
a memset to zero on them to make sure we don't operate on
uninitialized memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-12 21:48:03 +02:00
Johan Hedberg cb8470f3a0 Bluetooth: Mesh: Kconfig: Use a saner default ReceiveDelay
A value of 20ms means it's possible the LPN will end up doing
simultaneous advertising & scanning, which increases the risk of lost
packets. Use a default of 100ms to keep these separate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 50a656ff16 Bluetooth: Mesh: Implement handling of Friend Clear messages
Handling Friend Clear messages and sending the Friend Clear
Confirmation responses wasn't so far properly implemented. One of the
requirements is to keep sending the reponses even though we no-longer
have a friendship. This means that we need to keep the net_idx, frnd
and lpn_counter values valid, which in turn requires the introduction
of a separate "valid" boolean value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg cb89cc7fdc Bluetooth: Mesh: Kconfig: Set PTS-friendly Friendship values
The PTS tests for the Friend node expect a minimum of 16 queued
messages and the ability to have two LPNs. Set these as defaults.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg b644bad5c0 Bluetooth: Mesh: Use network transmit count and interval for Friend
When sending PDUs from Friend to LPN we should adhere to the
configured network transmit count & interval to get better
reliability for the PDUs to be received by the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg ed8ed9ea7d Bluetooth: Mesh: Implement the Friend Clear procedure
When a Friend Node receives a Friend Request with a unicast
PreviousAddress that's not an element on the Friend Node, it needs to
start the Friend Clear procedure. This procedure involves sending
periodic Friend Clear messages to the old Friend of the LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg eb23d688f2 Bluetooth: Mesh: Fix network credential selection
The only messages that should be encrypted using the friendship
credentials are those coming through the Friend Queue on the Friend
node, most request-response pairs between LPN & Friend (exceptions are
Friend Request - Friend Offer, and Friend Clear - Friend Clear
Confirm), as well as Model Publication messages when the Friendship
Credentials Flag has been enabled in the model publication.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg d43a23652c Bluetooth: Mesh: Introduce LPN-specific adv transmit properties
When the node is in LPN node, the LPN-Friend messages has its own
retries, so doing this on the advertising level (i.e. following the
network transmit state) is sub-optimal.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 01d3940cdb Bluetooth: Mesh: Allow passing adv transmit info in net_tx
This makes it possible (in a subsequent patch) to fine-tune some
special cases, like the LPN poll messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 1d86ef0955 Bluetooth: Mesh: Use more accurate timing for LPN functions
Update the advertising callback to include the exact duration that we
will be sending out the packet. This is useful since sometimes we want
to use the end point of the advertising as the reference time to count
when some other action should take place.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg e74f4a6c39 Bluetooth: Mesh: Fix clearing friendship
Lower the attempts and make sure we track the old Friend address for
subsequent Friend Requests, in case we never receive a Clear
Confirmation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 4d7757fab1 Bluetooth: Mesh: Fix sending Friend Clear messages indefinitely
We should give up after a small number of attempts.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg b95d70c3f0 Bluetooth: Mesh: Improve Low Power establishment procedure
Add some automated policies for starting LPN establishment and make it
possible to perform the establishment in a "low power" way, i.e.
switching to low duty-cycle already when starting to send Friend
Requests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Loic Poulain f38482a8fd usb: netusb: Use lower addresses for default endpoint config
Even if endpoint addresses are configurable by each platform,
it would be better to make the default configuration compatible
with a larger board range.

e.g. STM32 OTG FS device has only four endpoints (0x84 is out).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 13:10:00 -05:00
Loic Poulain 94c6e47667 usb: netusb: Fix CMakeLists
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-10 11:27:50 -05:00
Paul Sokolovsky 91e810f87a net: sockets: sendto: Remove adhoc handling of max pkt payload size
Now the check happens on the level of the core IP stack, in
net_pkt_append().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-10 16:30:42 +02:00
Paul Sokolovsky 4718dac560 net: net_pkt_append: Take into account MTU when adding data to a packet
If we were asked to add 10KB to a packet, adding it won't help -
such packet won't be even sent by hardware on our side, and if
it is, it will be dropped by receiving side. So, make sure we
never add more data than MTU as set for the owning interface.
This actually gets a bit tricky, because we need also to account
for protocol header space. Typically, when net_pkt_append() is
called, protocol headers aren't even added to packet yet (they
are added in net_context_send() currently), so we have little
choice than to assume the standard header length, without any
extensions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-10 16:30:42 +02:00
Johan Hedberg 1f76023ad4 Bluetooth: Mesh: Fix ignoring prohibited ReceiveWindow value
According to the Mesh Spec value 0x00 of ReceiveWindow parameter is
prohibited. This is needed to pass MESH/NODE/FRND/LPN/BI-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:35:15 +02:00
Johan Hedberg 85e7a3d47e Bluetooth: Mesh: Fix typo when iterating GATT clients
The intention of the code was to access client->conn and not
clients->conn (which would always access the first client struct).

Fixes #4738

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 15:13:01 +02:00
Johan Hedberg 9c8ce3d7c4 Bluetooth: Mesh: Fix Mesh feature description in Kconfig
Use the correct term for the feature, and reformulate the help text
for BT_MESH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 08:11:52 -05:00
Johan Hedberg e980d45c13 Bluetooth: Mesh: Fix net_find_and_decrypt() function
The function return type was declared incorrectly. Also, the magic
checking for i after exiting the loop could cause some false positive
compiler warnings. Instead, return directly from the loop (with the
downside of duplicating a few lines of code).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:52:23 +02:00
Johan Hedberg 25c5d36b91 Bluetooth: Mesh: Avoid using 64-bit storage & math for beacons
It's in practice impossible for the time between two beacons to be
more than 50 hours (the approximate wrap-around time for a 32-bit
millisecond timer), so we can use a 32-bit timestamp instead of a
64-bit one for the beacon tracking.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 14:33:03 +02:00
Johan Hedberg 68f6b59e2d Bluetooth: Fix deadlock-risky HCI command buffer allocation
The LE scanning and advertising implementations were allocating and
holding buffers (the scan & advertising parameters respectively) while
at the same time potentially sending other commands (such as setting
the local private address). If these APIs would end up being called
simultaneously from different contexts, this could lead to a deadlock
in trying to allocate HCI command buffers, especially considering that
the default HCI command buffer count is 2.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 10:42:38 +02:00
Paul Sokolovsky b86b079f32 net: tcp: net_tcp_parse_opts: Convert MSS value to host byte order
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-09 17:00:26 +02:00
Tomasz Bursztyka 58bc383cfd net/ieee802154: Properly check the sequence when handling ACK frames
When sending a packet with AR flag set, the ACK frame that should be
replied to it must holp the same sequence number, so let's verify this
properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-09 10:00:38 +02:00
Tomasz Bursztyka cf78219318 net/ieee802154: Make FC/Seq validation function public
There will be place where validating only this part of the frame will be
necessary. This will avoid to run the little bit heavier
ieee802154_validate_frame().

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-09 10:00:38 +02:00
Sebastian Bøe 5630ccfc23 cmake: Introduce a default VID and PID
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe dad876f837 cmake: Fixed subsys/net/lib/http
This fixes the CI failure of the sample lwm2m_client.

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrei Emeltchenko 6f52e2d911 usb: Allow to select Endpoint addresses for CDC ACM
Sometimes we need to select Endpoint addresses manually to get it
working with certain USB controllers having limit for endpoints. In
this case default values break endpoint limit check. The proper
solution would be automatic endpoint allocation.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-08 15:09:47 -05:00
David B. Kinder 7e3ed1465f doc: fix Kconfig misspellings
Kconfig files are processed to create configuration
option documentation.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-11-08 13:50:35 -05:00
Paul Sokolovsky cdea2bfab7 net: tcp: Add support for TCP options parsing
Add a generic function for TCP option parsing. So far we're
interested only in MSS option value, so that's what it handles.
Use it to parse MSS value in net_context incoming SYN packet
handler.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Paul Sokolovsky 3c652996ff net: tcp: Add NET_TCP_HDR_LEN(hdr) macro for reuse
Calculates full TCP header length (with options). Macro introduced
for reuse, to avoid "magic formula". (E.g., it would be needed to
parse TCP options).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Paul Sokolovsky bc88ad750b net: tcp: Handle storage of TCP send MSS
MSS is Maximum Segment Size (data payload) of TCP. In SYN packets,
each side of the connection shares an MSS it wants to use (receive)
via the corresponding TCP option. If the option is not available,
the RFC mandates use of the value 536.

This patch handles storage of the send MSS (in the TCP structure,
in TCP backlog), with follow up patch handling actual parsing it
from the SYN TCP options.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-08 16:19:57 +02:00
Johann Fischer 8ff9b6350f subsys: netusb: use usb_cdc.h header
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-11-07 15:31:02 -05:00
Andrei Emeltchenko 641f867adf usb: netusb: Allow to select Endpoint numbers
Add support for selecting Endpoint numbers and move it under USB
Device Networking menu.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-07 14:00:58 -05:00
Johan Hedberg 2a74be43ea Bluetooth: Mesh: Fix network decryption in case of multiple LPNs
If we are a Friend node with multiple LPNs, we need to iterate through
all available Friendship credentials to find the right keys.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 1ecb486f17 Bluetooth: Mesh: Simplify & fix net credentials selection
The Mesh spec expects us to fall back to master credentials if
friendship ones are not available. Also remove an unnecessary branch
with the help of a new 'idx' variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg d118fff232 Bluetooth: Mesh: Remove unnecessary per-buffer segment context
The friend_cred and new_key information is common for all segments of
a segmented transaction, so it makes sense to store them as part of
struct seg_tx instead of each buffer's user data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 9b2a6d4866 Bluetooth: Mesh: Fix friendship credential usage for segmented messages
The friend_cred hint needs to be set already at the point of
segmenting, i.e. doing it in bt_mesh_net_send() is too late. Move the
setting to bt_mesh_trans_send() and bt_mesh_ctl_send().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg ada5771d7c Bluetooth: Mesh: Fix ignoring invalid Transport OpCode as LPN
MESH/NODE/FRND/LPN/BI-02-C requires us to ignore unknown Transport
OpCodes instead of treating them as valid responses to a Friend Poll.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg f51797335d Bluetooth: Mesh: Fix retries when establishing Friendship as LPN
The Mesh Specification recommends retrying up to 6 times the Friend
Poll when establishing Friendship as LPN.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg b18f023e31 Bluetooth: Mesh: Improve debug logs for provisioning
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg f7e74dd5cb Bluetooth: Mesh: Fix provisioning with Key Refresh flag set
We should not have any valid key material in key slot 0 if the KR flag
is set, since then the new key/old key information will be incorrect
when network PDUs get decrypted.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 4492c5d072 Bluetooth: Mesh: Improve acknowledgement timer calculation
According to the Mesh Profile Specification: "The acknowledgment timer
shall be set to a minimum of 150 + 50 * TTL milliseconds".

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 8fe33607c6 Bluetooth: Mesh: Fix message replay protection
The Mesh Profile Specification states that replay protection must be
done for all control and access messages. Furthermore, the replay
protection list must be updated with the sequence from the last
segment of a segmented message (the code was only updating based on
SeqZero).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg cad1f4ce7b Bluetooth: Mesh: Fix transport layer heartbeat subscription matching
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 95d34e0583 Bluetooth: Mesh: Cfg: Implement Low Power Node PollTimeout Get fully
Now that Friend support is complete we can create a full
implementation of the LPN PollTimeout Get message.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 6abfab08d4 Bluetooth: Mesh: Fix not including RSSI into network RX context
The RSSI was supposed to be stored in the net_rx struct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Johan Hedberg 7248e4b7c3 Bluetooth: Mesh: Add complete Friend support
Add all the missing pieces of Friend node support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 18:59:06 +03:00
Jukka Rissanen 517caef5a4 net: pkt: Remove unnecessary error print in adjust_offset
The commit 971da9d0 ("net: pkt: adjust_offset: Simplify and optimize
code") changed the adjust_offset() function but left the error print
intact. This print is now invoked even if there is no error which
looks bad in debug prints.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-07 15:18:02 +02:00
Johan Hedberg 86c32aac1c Bluetooth: Kconfig: Introduce new BT_SCAN_WITH_IDENTITY option
Even with the privacy feature disabled, the stack has so far defaulted
to using an NRPA for active scanning, in order to protect privacy.
This is mainly because it is not always clear that scanning for other
devices may risk revealing the local identity.

There may however be use cases where such revealing is actively
desired, so introduce a new option for this (which defaults to
disabled).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-07 14:14:17 +03:00
Loic Poulain 35d0592a39 usb: netusb: Change 'conf' to 'configured'
conf member represents the configuration state of the device.
Change its type from u8 to bool and clean related functions.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3fc83fd180 usb: netusb: ecm: Make in_pkt static
This reassembly buffer is local.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 41891849c9 usb: netusb: remove ecm struct
Remove unused iface member and move out skip variable.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain c82d1446bd usb: netusb: Remove ecm_register_function
The only access to the function is now the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 5f1c6d0999 usb: netusb: Move endpoint specific config to function interface
netusb endpoint config is specific to the function (ECM, RNDIS, EEM..).
Move this config to the function interface.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3c47817a98 usb: netusb: Abstract netusb function specific methods
Move class_handler and send_pkt to netusb function interface.
This makes netusb 'function' agnostic.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 3870fc5928 usb: netusb: Remove multi-function array
Today, we support/use only one USB configuration descriptor.
Moreover I assume multi-config support should be managed at
usb core level and not by each class driver.
Let's track one netusb function per netusb instance for now.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 0188881599 usb: netusb: Add netusb_recv method
This method can be use by netusb functions on pkt reception.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Loic Poulain 53d8389a6c usb: netusb: Remove eth_emu
Move network device creation/mgmt to netusb.
Add iface reference to netusb instance.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-07 11:17:16 +02:00
Tomasz Bursztyka c968e102e6 net/ieee802154: Add a choice on which packet to print-out
All, RX only or TX only

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-06 21:01:35 +02:00
Tomasz Bursztyka b181dc6791 net/ieee802154: Isolate packet display debugging option
Let's enable packet hex dump display without requiring the whole 15.4
stack debug option.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-06 21:01:35 +02:00
Aska Wu 62e5f8d7a1 net: socket: Handle the value-result argument
The addrlen of accept() and recvfrom() is a value-result argument. It
should be updated to the actual size of the source address after
calling accept() and recvfrom().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 20:59:05 +02:00
Robert Chou 3ad6719fbf net: lwm2m: response to peer with correct error code when write fail
Update the firmware update_result accordingly by checking return
value of the firmware data write callback registered by application.
Also, set response code according.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-06 20:49:59 +02:00
Robert Chou d36b3251fa net: lwm2m: check engine context before accessing it
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-06 20:49:31 +02:00
Jukka Rissanen dd7b4bae28 net: tcp: Do not run expire function in ISR context
The expire function can call net_context_unref() which tries to
get a semaphore with K_FOREVER. This is not allowed in interrupt
context. To overcome this, run the expire functionality from
system work queue instead.

Fixes #4683

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 17:16:46 +02:00
Paul Sokolovsky 971da9d011 net: pkt: adjust_offset: Simplify and optimize code
An edge condition was handled in a special way, even though the main
condition covered it well. More code, more jumps == slower code,
bigger binaries.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-06 17:03:48 +02:00
Jukka Rissanen 2486694eb9 net: http: Create HTTP library that uses net-app
Create http library that uses net-app instead of net_context
directly. The old HTTP API is deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 09:33:00 -05:00
Johan Hedberg 018198cedc net: buf: Add slist helpers
Now that net_buf has "native" support for sys_slist_t in the form of
the sys_snode_t member, there's a danger people will forget to clear
out buf->frags when getting buffers from a list directly with
sys_slist_get(). This is analogous to the reason why we have
net_buf_get/put APIs instead of using k_fifo_get/put.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 14:20:40 +02:00
Aska Wu 1bdd80f8db net: context: Replace net pkt parsing by helper functions
The code parsing received net pkt to get source or destination
sockaddr repeats multiple times in net_context.c.

Eliminate the duplication by net_pkt_get_src_addr() and
net_pkt_get_dst_addr() which can handle different internet protocol
(i.e. ipv4 or ipv6) and transport protocol (i.e. tcp or udp)

Fixes: #4421

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 14:09:46 +02:00
Aska Wu 2d7ff75f60 net: pkt: Add net_pkt_get_dst_addr()
Rename net_pkt_get_src_addr() to net_pkt_get_addr() and make it able to
handle source or destination address.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 14:09:46 +02:00
Johan Hedberg e25d925242 Bluetooth: Defer RL update if there's an ongoing connection
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 56f79f817e Bluetooth: Add support for Link Layer Privacy
Add support for loading IRKs into the controller as well as the LE
Enhanced Connection Complete HCI event. To simplify things, the old LE
Connection Complete handler translates its event into the new enhanced
one which is then the single place of processing new connection
events.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg a74feaaf55 Bluetooth: Add missing HCI defines for LL privacy
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 7762578de4 Bluetooth: Simplify and clean up LE scan handling
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg 9a8316061d Bluetooth: Mesh: Fix HB Sub Status when disabling subscription
MESH/NODE/CFG/HBS/BV-02-C expects it to be possible to do a Set with
the existing src & dst addresses but with a zero period in order to
"cancel" the current subscription. In such a case the addresses should
remain set but the period be set to zero, similar to what would happen
if the period would expire.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg 33826b91bd Bluetooth: Mesh: Fix clearing HB state when disabling HB sub
The heartbeat subscription Count, MinHops & MaxHops should only be
reset when enabling heartbeat subscription. Any other actions should
keep it unchanged.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg bcc140dbe6 Bluetooth: Mesh: Fix sending heartbeat only when relay state changes
The heartbeat should only be sent in case the relay state actually
changes. This fixes MESH/NODE/CFG/HBP/BV-03-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg c44daebe97 Bluetooth: Mesh: Fix HB Pub Count Log calculation routine
"4.1.2 Log field transformation

In order to compress two-octet values into one-octet fields, the
following logarithmic transformation is used: any two-octet value is
mapped onto a one-octet field value representing the largest integer
n, where 2^(n-1) is less than or equal to the two-octet value."

Log field transformation table:

Log Field Value         2-octet Value
0x01                    0x0001
0x02                    0x0002 through 0x0003
0x03                    0x0004 through 0x0007
0x04                    0x0008 through 0x000F
0x05                    0x0010 through 0x001F
0x06                    0x0020 through 0x003F
0x07                    0x0040 through 0x007F
0x08                    0x0080 through 0x00FF
0x09                    0x0100 through 0x01FF
0x0A                    0x0200 through 0x03FF
0x0B                    0x0400 through 0x07FF
0x0C                    0x0800 through 0x0FFF
0x0D                    0x1000 through 0x1FFF
0x0E                    0x2000 through 0x3FFF
0x0F                    0x4000 through 0x7FFF
0x10                    0x8000 through 0xFFFF

"4.2.17.2 Heartbeat Publication Count Log

The Heartbeat Publication Count Log value between 0x01 and 0x11 shall
represent that smallest integer n where 2^(n-1) is greater than or
equal to the Heartbeat Publication Count value. For example, if the
Heartbeat Publication Count value is 0x0579, then the Heartbeat
Publication Count Log value would be 0x0C."

According to this definition 2^(n-1) is an upper bound for n log
value.

Proposed Publication Count Log transformation table:

Pub Count Log Value     2-octet Value
0x01                    0x0001
0x02                    0x0002
0x03                    0x0003 through 0x0004
0x04                    0x0005 through 0x0008
0x05                    0x0009 through 0x0010
0x06                    0x0011 through 0x0020
0x07                    0x0021 through 0x0040
0x08                    0x0041 through 0x0080
0x09                    0x0081 through 0x0100
0x0A                    0x0101 through 0x0200
0x0B                    0x0201 through 0x0400
0x0C                    0x0401 through 0x0800
0x0D                    0x0801 through 0x1000
0x0E                    0x1001 through 0x2000
0x0F                    0x2001 through 0x4000
0x10                    0x4001 through 0x8000
0x11                    0x8001 through 0x10000

According to Log field transformation table 0x0579 would be
transformed to 0x0B and should be to transformed to 0x0C.

This is required to pass MESH/NODE/CFG/HBP/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg ebf1a3c661 Bluetooth: Mesh: Fix ignoring all prohibited sub_dst in HB Sub Set
Section 4.2.18.2 in the Mesh Profile Specification states:

"The Heartbeat Subscription Destination shall be the unassigned address,
the primary unicast address of the node, or a group address, all other
values are Prohibited."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 23:53:50 +03:00
Johan Hedberg 6047ccd2a1 Bluetooth: Mesh: Extend advertising API with helpers for Friend support
These extensions prepare the way of implementing full Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 91e75985bd Bluetooth: Mesh: Fix and clean up IV Update procedure
This patch fixes issue when receiving iv index greater than current
index + 42 in update mode. According to Specification when node is in
update state it should only accept iv index equal to the current iv
index. When node is in normal mode it should ignore index that is
greater than current index + 42.

This allows to pass MESH/NODE/IVU/BI-02-C.

Also this patch cleans up the iv update procedure, to make it easier
to read.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg b0a43b9d3c Bluetooth: Mesh: Return change information from bt_mesh_iv_update()
This will soon be useful to the callers of bt_mesh_iv_update(), in
particular Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg e1b381c58f Bluetooth: Mesh: Export bt_mesh_friend_cred_get() for Friend usage
This function will soon be needed by the Friend support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 020425f61a Bluetooth: Mesh: Remove redundant assignment
This value is assigned again a few lines later.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg a6ce33d7ea Bluetooth: Mesh: Cfg: Only update friend state if supported
If Friend support is not available we should not modify the value of
cfg->frnd.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg ab84517b45 Bluetooth: Mesh: Export some transport layer helpers
These will soon be needed by the Friend code to compose messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg ae714e4028 Bluetooth: Mesh: Add bt_mesh_net_flags() helper function
This reduces code in various places needed to construct a flags value
for a given subnet.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg b8e2c9a40f Bluetooth: Mesh: Fix TX segment context lookups
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 2f9171c3ac Bluetooth: Mesh: Take advantage of BT_MESH_NET_HDR_LEN define
Avoid using hard-coded magic numbers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Johan Hedberg 799ee46b5c Bluetooth: Mesh: Keep received buffer intact until transport layer
The lower transport layer is responsible e.g. for the Friend Queue, so
we need to have the buffer in its original parsing state there.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-04 10:06:39 +03:00
Jukka Rissanen 61fbc4d57d net: app: server: Allow IPv4 connections if IPv6 is enabled
A regression by commit 9728179757 ("Allow net_context re-connect").
The code did not create IPv4 listener if IPv6 listener was successfully
created.

Fixes #4697

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-03 16:09:08 +02:00
Savinay Dharmappa 0106059ff0 subsys: logging: event_logger: Fix CPU fault
A CPU fault occurs when sys_k_event_logger_get_wait()
api invoked with config KERNEL_EVENT_LOGGER_THREAD
enabled.

sys_k_event_logger_get_wait() supposed to pend  on a
semaphore when all the events from kernel event logger
are read.But when sys_k_event_logger_get_wait() inovked
with config KERNEL_EVENT_LOGGER_THREAD(i.e captures thread
events) subsquent call inside this function will write to
kernel event log buffer to capture pend event.This will
release the semaphore on which sys_k_event_logger_get_wait()
was pending hence thread gets unpend before swap gets called.

Which in other words a thread which is invoking
sys_k_event_logger_get_wait()(i. e sem_count = 0) get pends
and unpends in single function flow when KERNEL_EVENT_LOGGER_THREAD
enabled.

This would cause overlapping of the stack address where
return address of "_pend_current_thread" stored with esp of
callee saved(i. e thread->callee_saved.esp). Thus return adrress
of "_pend_current_thread" would be overwitten with zero. Which
in turn causes CPU fault.

The thread invoking sys_k_event_logger_get_wait() supposed
to only read the events of the threads which logged to kernel event
logger buffer. But it should not write to kernel event logger
buffer. Otherwise it would cause the race condition explained above.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-11-02 22:22:54 -04:00
Szymon Janc 3b1cb4a309 Bluetooth: Mesh: Fail init on keys generation error
Fail on Mesh initialization if provisioning is enabled and keys were
not generated. This make it simpler to debug misconfigured devices.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-11-02 15:52:07 +02:00
Johan Hedberg 7166920a1d Bluetooth: Add option to use heuristics for VS HCI detection
On targets where non-Zephyr controllers are likely, such as qemu, it
may be harmful to try to issue any of the vendor HCI commands, since
non-Zephyr controllers may interpret them in completely different
ways.

Introduce a Kconfig option that, when enabled, uses some simple
heuristics (HCI version & lack of public address) to try to guess in
advance whether the Zephyr HCI vendor extensions are supported or not.
The new option is available for any host-only configuration and is
enabled by default for the qemu targets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-02 14:51:42 +02:00
Vinayak Kariappa Chettimada 6016ccffe8 Bluetooth: controller: Fix diff proc collision with enc proc
Fixes the following conformance test regression failure
introduced in commit 7dd5fbee26 ("Bluetooth: controller:
Fix MIC error due to parallel Enc Proc")

TP/CON/MAS/BV-28-C [Initiating Connection Parameter Request
different procedure collision encryption]

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-02 10:26:09 +01:00
Paul Sokolovsky 4641f88623 net: pkt: net_frag_read: Typo fix in comment
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-02 10:05:07 +02:00
Robert Chou 44995e2de0 net: lwm2m: replace coap_next_block() w/ coap_update_from_block()
We should call coap_update_from_block() which will determine the minimum
size of the BLOCK1 SIZE between server/client and update the current
offset and total size(if available) accordingly.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-02 10:02:45 +02:00
Robert Chou a37f049e6d net: lwm2m: break the opaque write loop early when fail
As title, check the return value from the write callback and break if
an error is returned

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-11-02 10:01:40 +02:00
Michael Scott 5876baa3be net: lwm2m: oma_tlv: fix typo in TLV length processing
This fixes writing to number / boolean values in LwM2M objects.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-02 10:01:05 +02:00
Michael Scott 77f18827d8 net: lwm2m: simplify oma_tlv get_bool()
Use existing get_number() function to reduce code size.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-02 10:01:05 +02:00
Vinayak Kariappa Chettimada 7dd5fbee26 Bluetooth: controller: Fix MIC error due to parallel Enc Proc
Fix to disallow initiating LE Start Encryption while another
procedure is in progress. Similarly, disallow initiating
another procedure while Encryption procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-11-01 16:35:29 +01:00
Leandro Pereira 5a272b027a subsys/random: Add Xoroshiro128+ PRNG
This adds an implementation of Xoroshiro128+ PRNG, based on the
original implementation at [1].  This pseudorandom number generator
will use the entropy driver to obtain the seed.

While it uses only 128 bits of state, it's pretty robust for non-crypto
safe applications.

[1] http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira 8b883a61a3 subsys/random: sys_rand32_get() implementation that uses entropy API
Instead of every hardware number generator driver providing an
implementation of this function, use the random device API to
centralize the implementation of this function.

This is a very simplistic function that can be seen as a stepping stone
to refactor the random number generation in Zephyr.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira da9b0ddf5b drivers: Rename random to entropy
This should clear up some of the confusion with random number
generators and drivers that obtain entropy from the hardware.  Also,
many hardware number generators have limited bandwidth, so it's natural
for their output to be only used for seeding a random number generator.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Leandro Pereira adce1d1888 subsys: Add random subsystem
Some "random" drivers are not drivers at all: they just implement the
function `sys_rand32_get()`.  Move those to a random subsystem in
preparation for a reorganization.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-01 08:26:29 -04:00
Johan Hedberg f801c1ca8e net: buf: Add net_buf_id() API
Add a net_buf_id() API which translates a buffer into a zero-based
index, based on its placement in the buffer pool. This can be useful
if you want to associate an external array of meta-data contexts with
the buffers of a pool.

The added value of this API is slightly limited at the moment, since
the net_buf API allows custom user-data sizes for each pool (i.e. the
user data can be used instead of a separately allocated meta-data
array). However, there's some refactoring coming soon which will unify
all net_buf structs to have the same fixed (and typically small)
amount of user data. In such cases it may be desirable to have
external user data in order not to inflate all buffers in the system
because of a single pool needing the extra memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-01 12:08:27 +02:00
Andrei Emeltchenko 35a263374e usb: netusb: Fix handling no data case
In a case we get packet without fragments return -ENODATA.
The bug was discovered by Coverity.

Fixes #4637
Coverity-CID: 178334

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-01 10:00:02 +02:00
Andrei Emeltchenko 90721238c7 net: tcp: Print retry count in retransmission attempts
Print also retry count when retransmitting packets.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-11-01 10:00:02 +02:00
Ricardo Salveti 03b801321b net: increase retransmission timeout (RTO) config range
Previous max range value for RTO was 2 seconds, increase to 60 seconds
as setting larger values can be useful when debugging retransmission
issues on slow networks.

Signed-off-by: Ricardo Salveti <ricardo@opensourcefoundries.com>
2017-11-01 09:54:29 +02:00
Paul Sokolovsky 6f76a19f77 net: sockets: Fix Coverity false positive
Due to parameters used, net_context_recv() call cannot fail (it just
installs a callback, no I/O performed).

Coverity-CID: 178247
Fixes: #4581

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-11-01 09:47:40 +02:00
Andrei Emeltchenko 86272907d8 net: Add initial retransmission timeout config option
Add option to set initial Retransmission Timeout value. The value is
different from NET_TCP_ACK_TIMEOUT since latter affects TCP states
timeout when waiting for ACK for example.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-31 13:09:30 +02:00
Jukka Rissanen d525c41360 net: app: Allow TLS thread to run to handle the received data
If we receive lot of data fragments, then yield after initial
processing so that TLS thread can start to work on these.
If we do not yield here, we pile up data buffers and might run
out of memory more easily.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen afc0cdf7e4 net: app: Check if underlying net_context is freed
It might happen in TCP client, that the TCP connection is terminated
in which case net_context is freed. Check this and mark corresponding
net_context inside net_app to NULL. This way there will be no issue
to access already freed net_context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 5cc4ef78d3 net: app: TLS client handling issue when server closes connection
The client TLS code did not handle server issued close properly.
Now the connection is terminated properly and TLS thread is left up to
wait more requests from the user.

This commits adds new boolean field to net_app context. Because there
are already multiple boolean flags there, convert them all to bitfields
to save space.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 882f476293 net: app: TLS handshake must be done before sending data
As the TLS handshake might take long time before connection is ready,
check this before trying to send user data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 4743d89c9a net: app: Clarify the debug print in TX and RX
Print information that we are sending plain data and receiving
encrypted data, the code claimed that we are sending encrypted
data which is not the case here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Jukka Rissanen 9728179757 net: app: client: Allow net_context re-connect
If user closes the client connection, then make sure that
user can just call net_app_connect() instead of calling the
client init. The client initializes everything in net_app but
for simple re-connect that is not necessary.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-31 09:54:39 +02:00
Michael Scott 353be4cd58 net: lwm2m: propagate errors from post_write callbacks
Now that objects and samples have their return values fixed, let's
propagate them back up to the user if there's an error.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 98d8c6a665 net: lwm2m: fix all return values from resource callbacks
Previously, post_write and execute callbacks returned 1 when handled
and 0 for error condition.  However, this wasn't detailed enough and
the engine can't propagate any sort of error back to users -- so it
doesn't even check the return values in many cases!

Let's adjust the resource callback functions of all objects and the
lwm2m_client sample to return 0 for success or a valid error code.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott ccbd696706 net: lwm2m: remove predefined firmware buffer from firmware_pull
Now that we can access resource data in the lwm2m subsys, let's use
the user provided firmware push buffer (5/0/0) to also store the
firmware pull data.

This way the size of the firmware pull buffer is completely up to the
application.

NOTE: This patch adds a 64 byte firmware buffer to the lwm2m_client
sample for this purpose.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott febcf5317b net: lwm2m: fix OPAQUE handling in LwM2M engine
With the change to support multi-fragement buffers in the LwM2M subsys,
the OPAQUE data type was direct write methods were broken.

Let's fix OPAQUE handling by using the newly introduced getter methods
which can use multiple user callbacks (depending on the size of the
user provided buffer).  Let's also add public methods for users to set
/ get OPAQUE data in resources for future use with DTLS key data.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott f32815a8d5 net: lwm2m: expose lwm2m_engine_get_resource() for lwm2m subsys
The lwm2m_engine_get_resource() function needs to be made available to
other portions of the lwm2m subsys in order for firmware resource data
to be used in the future.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 7fa099b67e net: lwm2m: remove unused len var from lwm2m_engine_get()
During conversion from the ZoAP to CoAP APIs the use for this variable
was removed, but the variable itself was left in place.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott 507bf72d10 net: lwm2m: consolidate URI_LEN define in firmware pull source
No need for 2 different defines to specify URI lengths in the source
for firmware pull method.  Let's combine them.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott dd95dbcd9e net: lwm2m: introduce getter/setter for OPAQUE data
Each content formatter should have a way of handling opaque data.

For instance TLV data will individually be able to specify a length
but plain text will take up the rest of the packet.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott b37a005d68 net: lwm2m: add multi fragment support to LwM2M library
The existing LwM2M framework expected contiguous buffers and this
was the reason for the 384 byte buffer sizes.  This was previously
a limitation of the ZoAP API. The new CoAP API doesn't have this
limitation and the LwM2M library has already been migrated to use
it.

Let's finish the process by replacing any contiguous buffer handling
with the correct net_pkt APIs to parse across multiple fragments.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Michael Scott dd364efc58 net: lwm2m: share BUF_ALLOC_TIMEOUT setting w/ other lwm2m components
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-31 09:41:27 +02:00
Robert Chou be825dca1e net: lwm2m: handle format application/octet-stream w/ plain_text
application/octet-stream is used to indicate opaque payload format.
Use plain text handler to handle the opaque format.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-31 09:32:07 +02:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
Andrew Boie 74446381d1 sensors: move userspace handlers location
Place driver handlers with the drivers, not somewhere separate under
subsys/

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-30 13:20:19 -07:00
Andrei Emeltchenko f69b85e05c usb: netusb: Select NET_L2_ETHERNET when choosing Device Networking
Select automatically NET_L2_ETHERNET.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-30 11:50:42 -04:00
Jukka Rissanen 0e7c8edc92 net: context: Make sure we honor timeout when waiting data
The call to net_context_recv() with timeout returned -ETIMEDOUT
even when data was returned properly and there was no timeout.

Fixes #4565

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-30 17:18:11 +02:00
Vinayak Kariappa Chettimada 8edcbade9a Bluetooth: controller: Fix to enable Asym PHY on nRF52 Series
Fix the controller Kconfig to enable use of fast radio ramp
up by default, hence enabling support for Asym PHY updates
by default on nRF52 Series SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-30 14:51:18 +01:00
Aska Wu 60a8e7843e net: context: Fix find_available_port()
In bind_default(), a local variable is passed to find_available_port().
However, the port number is unpredictable as it's not initialized and
will be used directly if not zero. This will lead to problems if the
port number is already used.

This patch makes find_available_port() always returns an available port
regardless of the port number in the sockaddr parameter.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-30 12:01:43 +02:00
Andrei Emeltchenko a226d58716 usb: Use RFC 7042 Documentation values for MAC strings
Use documentation defined values for virtual devices MAC addresses in
Zephyr and Host OS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko c93578e608 usb: netusb: Add composite device with ECM function
Add composite device skeleton with ECM function implemented.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 38e010136d usb: netusb: Add ethernet emulation device
Ethernet emulation device allows to use networking interface for
interaction with USB endpoints.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko bbd3b4d749 usb: Add CDC ECM composite configuration
Add USB device configuration for CDC ECM

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Andrei Emeltchenko 91a4397e16 usb: Add extra debug information
Add extra debug information to USB commands.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-28 14:38:19 -04:00
Tomasz Bursztyka 0d760d36e7 net/6lo: Enable it by default if IEEE 802.15.4 is enabled
This rework commit 77b8f5c1f6

Comparing it to BT IPSP is a the wrong comparison: BT IPSP does specify
6lo/ipv6 for it to work. Whereas 802.15.4 does not.

Instead of selecting 6lo from 802.15.4's Kconfig, let's do the reverse
way. If the user enabled 802.15.4 and IPv6 as well (to which 6lo
depends on), then 6lo is enabled by default as using IPv6 on 15.4
without it does not make much sense.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-28 14:28:02 -04:00
Sebastian Bøe b7eaeb9f0a cleanup: Use quote include instead of system include
When the header file is located in the same directory as the source
file it is better to use a relative quote-include, e.g.

than a system include like

Avoiding the use of system includes in these cases is beneficial
because;

* The source code will be easier to build because there will be fewer
system include paths.

* It is easier for a user to determine where a quote-include header
  file is located than where a system include is located.

* You are less likely to encounter aliasing issues if the list of
  system include paths is minimized.

Authors:
Anas Nashif
Sebastian Bøe

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-28 07:11:53 -04:00
Michael Scott 0bd961647a net: lib: http: fix check for invalid body_start pointer
Recent commit fb7f6cfa97 ("net: lib: http: Fix invalid pointer
body_start") introduced logic to reset the response body_start pointer
when the response buffer was reused.

This check needs to be fixed so that it doesn't arbitrarily change
body_start when not needed.

The problem with the current check can be demonstrated by not setting
a response callback for request which generates a large response
spanning multiple packets.

In this case body_start is still valid (not reusing the response buffer
because there is no callback set), but it will be changed when the 2nd
packet is received and the "at" marker is located at the head of the
new packet (!= response_buffer).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 17:42:01 -04:00
Michael Scott 7aa06558e0 net: lwm2m: remove auto select of COAP_EXTENDED_OPTIONS_LEN config
When moving to the new CoAP API, I thought we would need to parse
incoming option values longer than 12 characters.

This hasn't proven to be true, so let's remove the auto-selection of
this config.  If needed user can set this option later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 11:33:06 -04:00
Michael Scott 2567b9fb6a net: coap: Fix error handling for coap option length
Currently, we check the length of an option value in the
coap_packet_append_option() function.  This isn't required as
we're appending to a net_pkt and not using struct coap_option
where the limitation is imposed.

Instead, we should check the option value length in
parse_option() where we assign the value to a struct
coap_option.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 11:33:06 -04:00
Jukka Rissanen b68ee59335 net: app: Check that we could install recv_cb after connected
Inform user if we could not install receive callback after
a connection is created in net-app client.

Coverity-CID: 178246
Fixes #4582

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Jukka Rissanen 9a61384b86 net: http: Check that we could install recv_cb in accept
Inform user if we could not install receive callback after
a connection is accepted in http server.

Coverity-CID: 178244
Fixes #4584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Jukka Rissanen de36f39dd6 net: mdns: Check net_pkt before accessing it
If we run out of memory, then net_pkt might be null and we must
not access it.

Coverity-CID: 178235
Fixes #4593

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Robert Chou e2024128e1 net: coap: check null pointer before assign value
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-26 12:43:34 +02:00
Ding Tao fb7f6cfa97 net: lib: http: Fix invalid pointer body_start
The body_start field at http_client_ctx.rsp is used to check if this
fragment contains (a part of) headers or not.

If the device recived more than one fragment in one http response,
may cause re-use of the result buffer in function on_body().

Once the device re-use the result buffer, the body_start that point
to this buffer address will no longer be valid.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2017-10-26 09:40:05 +03:00
Paul Sokolovsky 87c4515f5c net: ieee802154_shell: get_pan_id: Print ID in hex too
Oftentimes, 15.4 PAN IDs are specified in hex. For example, that's
how Zephyr config specifies the default value. So, print them also
in hex, to avoid confusion.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-26 09:30:32 +03:00
Michael Scott f8ba4585c5 net: lwm2m: register the RD client with the engine periodic service
Remove the RD client's stack in favor of using the engine's periodic
service to trigger RD client events.  This saves 5K RAM of stack based
memory.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 1674a8c717 net: lwm2m: register device periodic service with engine
Remove the stack from the device object and instead make use of
the periodic engine service which will trigger the device service
when it's ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott a4ab36bcbd net: lwm2m: add periodic service registration to engine
Stacks cost a lot of RAM in Zephyr.  We have 3 total stacks in
the LwM2M lib.  We can remove 2 of these if add a service handler
into the main LwM2M engine.  Each service can register with this
handler so that they can be called based on their own periodic
timer.  The handler itself will search through these registered
services and call them when they become due otherwise sleep
until another is ready.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:29:42 +03:00
Michael Scott 25ff4f0e6a net: lwm2m: reduce LwM2M footprint via lower defaults in Kconfig
Let's use conservative defaults for the LwM2M library to enable
hardware with constrained resources.  Users can increase where
necessary.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:25:56 +03:00
Michael Scott 022d805cc2 net: lwm2m: replace instances of s*printf with snprintk
Let's use snprintk for simple formatting to allow for possible disabling
of printf and protect calls to sprintf from string overruns.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:23:19 +03:00
Michael Scott ebe3660308 net: lwm2m: fix Leshan discover OP
When using Leshan REST API to perform a discover OP on a client, only an
accept field is sent with "application/link-format".  Current logic uses
the content-type to determine when a discover OP is indicated.  Let's
handle this case as well.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-26 09:20:40 +03:00
Vinayak Kariappa Chettimada 0328ecf6fc Bluetooth: controller: Fix Ctrl PDU Tx starvation assert
Replace all controller asserts in control procedure responses
that checked for buffer availability with an implementation
that nacks request PDUs if there are no buffer to prepare
response PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 16:16:47 +02:00
Vinayak Kariappa Chettimada 482771c497 Bluetooth: controller: Remove assert on invalid LL id
Remove an assert on receiving invalid LL id, drop these
invalid PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-25 14:54:17 +02:00
Paul Sokolovsky c469b7fc9f net: tcp: Avoid spurious seqno decrements
There were decrements of TCP sequence numbers, inherited from FNET
stack implementation, as was used as an initial base. RFC793 does
not specify conditions for decrementing sequence numbers, so such
decrements are an artifact of FNET implementation. In Zephyr code,
we had to compensate for these decrements by extra increments
(including an increment-by-2). So, remove decrements and associated
extra increments to simplify the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-25 14:19:04 +03:00
Michael Scott 1d05ba75d1 net: lwm2m: fix CREATED response code
Handle LwM2M CREATE op correctly and remove comments.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott eb5ba43644 net: lwm2m: fix error handling in handle_request()
Let's reset the payload and return correct response error codes.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott 1bca60d732 net: lwm2m: make release in lwm2m_release_message() optional
Let's rename lwm2m_release_message() to lwm2m_reset_message()
and add a parameter to let the function know whether or not to
release the lwm2m_message resource back to the pool.

By adding the optional release parameter, we can keep the
lwm2m_message but reset the underlying net_pkt / net_buf resources.
This allows us to regenerate the net_pkt after determining
an error has occured.  In this case, we don't want the previously
added net_pkt contents but we do want to maintain the message id,
token, etc.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Michael Scott fb734acc73 net: lwm2m: move to using the new multi-packet CoAP API
This patch moves from the ZoAP API in subsys/net/lib/zoap to
the CoAP API in subsys/net/lib/coap which handles multiple
fragments for sending / receiving data.

NOTE: This patch moves the LwM2M library over to the CoAP APIs
but there will be a follow-up patch which re-writes the content
formatter reader / writers to use net_pkt APIs for parsing
across multiple net buffers. The current implementation assumes
all of the data will land in 1 buffer.

Samples using the library still need a fairly large NET_BUF_DATA_SIZE
setting. (Example: CONFIG_NET_BUF_DATA_SIZE=384)

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-25 13:39:55 +03:00
Robert Chou 7aa223174a net: coap: empty payload with payload marker is malformed
From RFC 7252, section 3
"The absence of the Payload Marker denotes a zero-length payload.
The presence of a marker followed by a zero-length payload MUST
be processed as a message format error."

Check empty payload when COAP_MARKER is found and add a test case to
cover it

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-25 13:21:53 +03:00
Ravi kumar Veeramally 630fad3bbf net: coap: Improve options parsing helper functions
Options parsing helpers functions unable to handle the malformed
packets and dropping it. Improved parsing functionality to handle
malformed packets. Also payload marker is not mandatory in CoAP
packets when there is no payload. Exit gracefully when CoAP
packet contains only options.

Fixes #4396.

Coverity-ID: 178060

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-25 10:54:25 +03:00
Jukka Rissanen 29dd25afb4 net: app: Calculate TLS application data pointer correctly
We need to skip protocol headers when setting pointer to
application data when receiving TLS data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 12:18:50 -07:00
Jukka Rissanen 5eb8936b05 net: app: Fix compilation error if debugging is enabled
If user has enabled CONFIG_NET_DEBUG_APP, then the debugging
version of _net_app_select_net_ctx() was not properly declared
and it caused compile error.

Fixes #4481

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 11:40:55 -07:00
Johan Hedberg c2f0dad29d Bluetooth: Mesh: Improve Network Message Cache behavior
The implementation of the Network Message Cache has so far been
suboptimal, since it has treated the same packet with different TTL
values as different packets. Since one of the purposes of this cache
is to prevent unnecessary relaying, it's important that we don't let
the TTL value influence the "hash" that's used for matching messages.

This patch changes the hash to consist of most of the IV Index (three
least significant bytes of it), the sequence number and the source
address, which should give fairly optimal matching behavior.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-24 18:23:36 +03:00
Jukka Rissanen 5da4639067 net: ipv6: Remove invalid assert when receiving NS
If we receive a neighbor solicitation which does not have any
options, then there is no need to assert this condition as that
is a perfectly valid use case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-24 11:30:41 +03:00
Jukka Rissanen 41f44ad8e0 net: ieee802154: Check reassembly return value properly
If IEEE 802.15.4 reassembly function ieee802154_reassemble() returns
anything other than NET_CONTINUE, then drop that packet. Earlier
it only dropped the packet if NET_DROP was returned but the reassembly
might also return NET_OK. In that case the pkt is freed already and
pkt->frags pointer is NULL. This caused NULL pointer access in L2 when
packet was received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-24 11:30:10 +03:00
Paul Sokolovsky 91ac13d87d net: shell: stacks: Print config option needed for full info
This is similar to how few commands already behave if they can
provide additional info to the user if particular config options
are enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-23 15:13:35 +03:00
Aska Wu 311c5ea56a net: pkt: Fix net_pkt_get_src_addr()
net_pkt_tcp_data() and net_pkt_udp_data() simply returns the start
address of the header. However the header may span over multiple
fragments, unexpected data or memory corruption might happen when
reading or writing to the pointer directly.

Use net_tcp_get_hdr() and net_udp_get_hdr() instead.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-23 15:04:59 +03:00
Jukka Rissanen 363ccaf663 net: Clarify UDP and TCP header getter and setter documentation
The net_tcp_get/set_hdr() and net_udp_get/set_hdr() documentation
was not clear in corresponding header file. Clarify how the return
value of the function is supposed to be used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-23 15:04:23 +03:00
Aska Wu 898036d892 net: udp: Remove subsys/net/ip/udp.h
udp.h is out-of-date as it accesses net buf directly. In 3604c391, it
has been replaced by net/udp.h and udp_internal.h

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-23 15:03:43 +03:00
Paul Sokolovsky 09b967366f net: pkt: Use standard macros to define system pkt slabs/pools
Previously net_pkt.h, defined macros NET_PKT_TX_SLAB_DEFINE,
NET_PKT_DATA_POOL_DEFINE, but advertised them as intended for
"user specified data". However, net_pkt.c effectively used the
same parameters for slabs/pools, but this wasn't obvious due
to extra config param redirection. So, make following changes:

1. Rename NET_PKT_TX_SLAB_DEFINE() to NET_PKT_SLAB_DEFINE()
as nothing in its definition is TX-specific.
2. Remove extra indirection for config params, and use
NET_PKT_SLAB_DEFINE and NET_PKT_DATA_POOL_DEFINE to define
system pools.
3. Update docstrings for NET_PKT_SLAB_DEFINE and
NET_PKT_DATA_POOL_DEFINE.

Overall, this change removes vail of magic in the definition of
system pkt slabs/pools, making obvious the fact that any packet
slabs/pools - whether default system or additional, custom - are
defined in exactly the same manner (and thus work in the same manner
too).

Fixes #4327

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-23 13:58:11 +03:00
Jukka Rissanen 4fe8d17bca net: ieee802154: Add more information when hexdumping the pkt
When hexdumping the packet, print also information if we
received / transmitted packet. Also print information if the
hexdump is before compression or not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-21 18:14:56 -04:00
Johan Hedberg afc9b5098b Bluetooth: Mesh: Update TODO with current status
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-20 17:53:31 +03:00
Jukka Rissanen 2fba7024af net: app: Fix compilation if TCP is not enabled
If building a server that does not support TCP, then the
get_server_ctx() is not needed and thus needs to be compiled out.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-20 10:11:46 -04:00
Paul Sokolovsky a3eb4fcd3e net: pkt: net_pkt_tcp/udp_data: Better document caveats
Explicitly note that while these functions return pointers to
headers, the headers themselves may be fragmented into different
data fragments. 1a2f24f920 is an example where this might have
been overlooked.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-20 11:01:48 +03:00
Michael Scott 545db8b482 net: lwm2m: remove unused last_value_len from lwm2m_input_context
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott fcd37eb79d net: lwm2m: use isdigit in JSON formatter
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 078288b2be net: lwm2m: move non-public data out of shared TLV include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 1fb61d21ac net: lwm2m: move non-public data out of shared JSON include
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 7f7e203334 net: lwm2m: remove unused JSON parser types
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 12072a378f net: lwm2m: cleanup function parameter naming
Don't use names like "strlen" for parameters.  Try and name buffer
parameters consistently.

NOTE: For several functions I removed "const" flag.  This is
intentional and will be needed in upcoming patches.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:40:55 +03:00
Michael Scott 9b643e2be7 net: lwm2m: cleanup TODOs in firmware obj.
Remove some left over TODOs and also fix a TODO where we need to return
the appropriate error code to generate a 4.05 response.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:39:00 +03:00
Michael Scott 9a8597399d net: coap: fix coap packet length calculation
This calculation reads the length portion of the COAP header to determine
the length of the coap packet.  However, when encrypted via DTLS this
value seems to be getting corrupted.  Let's change this calculation so
that it will work for when DTLS is both enabled and disabled.  Use the
total length of the fragment data and substract back out the headers
to get a correct value.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-20 10:37:55 +03:00
Ravi kumar Veeramally 13480f3992 net: 6lo: Fix 6lo uncompression issue
When source address is unspecified then SAC is 1 and SAM is 00.
Uncompression does not process because context based compression
is not enabled.
Special case (SAC:1 and SAM:00) should be handled without context
based compression support.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-20 10:33:28 +03:00
Jukka Rissanen 73b0d2d084 net: shell: Print system workqueue information
Add system workqueue information prints to "net stacks" command.
This helps debugging when figuring out which stack is running out
of space.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-20 10:31:33 +03:00
Jukka Rissanen a499d9ffd1 net: shell: Add multi connection net-app monitoring support
Enhance existing "net app" command so that it can be
used to show information about multiple connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 4befa1316d net: app: Print info if address family is not set properly
If the IP address family is not set to correct value, then print
information about it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9bff68fc2e net: app: Print more info for TLS MAC verification errors
If we get MAC verification error in handshake, it could be that
everything is fine but we ran out of heap memory in mbedtls.
In this happens, suggest the user to check amount of memory
in mbedtls as it might just fix the issue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 28d0dffab2 net: app: Add more debugging when selecting net_ctx
As we select net_ctx, it is useful to see who actually called
the _net_app_select_net_ctx() when debugging the call flow.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9051d462ca net: app: Select proper net_ctx when sending msg
Sometimes when sending network packet, the wrong net_context was
selected which prevented data to be sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 42808f4919 net: app: Print more info which interface we are using for pkt
Useful when debugging which network interface is used when sending
the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 9090bdfc10 net: app: Close TLS connection properly
We should not close the TLS connection immediately if the TLS
data is not yet sent. So if user calls net_app_close() and we
still have data pending, then send the TLS data and only after
that close the connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 1b1a3a6768 net: app: Close a specific network context
As there can be multiple listening network contexts, it should
be possible to close one of them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Jukka Rissanen 8c5f25d13b net: app: Add support for multiple listening connections
The server is able to listen and serve multiple incoming
connections. This commit does not add support for multiple
incoming TLS connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 22:21:25 -04:00
Andrei Emeltchenko 44a3cca2e2 usb: Remove default Vendor and Product ID
Vendor ID and Product ID should be assigned on build time by
respective process.

For sanity check we assign some random values which are only used for
build tests and should not be used for real products.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-10-19 09:30:58 -04:00
Robert Chou 19559ee41b net: lwm2m: increase rd client stack size when NET_LOG_GLOBAL=y
The stack of rd client is exhausted while running lwm2m client w/ IPv6
and network log global enabled. Increase the stack size to 1536 when
NET_LOG_GLOBAL is enabled.

Detail described at #4424

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:36:02 -04:00
Robert Chou 652cc727fe net: lwm2m: only method GET is allowed for .well-known/core
".well-known/core" is mainly used with method GET for performing the
resource discovery (RFC 6690). Since we are implementing a LwM2M client
and is not implement a resource directory which allow others to do the
resource registration (POST to .well-known/core). Only GET method is
allowed for the usage. Report 4.5 (Method Not Allowed) if other methods
are requested.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou cfa9990c41 net: lwm2m: return 4.04 when URI is not composed by digits
Modify zoap_options_to_path() to return error when URI contains
character other than digits and return 4.04 NOT FOUND to caller.

PATH such as "/1a/2/3" was treated as "/1/2/3" after parsring
which is incorrect.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou d5ab14697f net: lwm2m: fix empty path being treated as 0/0/0 issue
Return 4.05 Method Not Allowed when path is empty ('/') to the
caller for it's only use by bootstrap delete. This change also avoid the
empty path being treated as request targeted at 0/0/0.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Robert Chou ce5e0d7208 net: lwm2m: response nicely when obj not found or OP not handled
1) Respond NOT FOUND to caller when object doesn't exist
2) Report as internal server error when OP not handled

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-19 05:34:10 -04:00
Tomasz Bursztyka 8dd04742a0 ieee802154: Make packet display enablement via a Kconfig option
Such option should be use carefully. Printing out in/out packets is
extremely verbose.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Tomasz Bursztyka 70fb09548a net/ieee802154: Use common net_hexdump_frags instead of local function
Now that net_hexdump_frags can print out the link-layer reserve part,
let's use it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Tomasz Bursztyka 81b9c8fcf6 net/utils: Make net_hexdump_frags being able to print ll reserve
If requested only and with colors with right SYS_LOG Kconfig options.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-19 05:33:23 -04:00
Jukka Rissanen 4463035c45 net: 6lo: Drop pkt if it is too short
If the pkt is corrupted and the offset would be larger than
the actual packet length, then print information about that and
drop the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-19 11:17:22 +03:00
Carles Cufi 493852bac3 Bluetooth: controller: Fix flow control packet drop
The main purpose of recv_thread is to process incoming events from the
radio and also any buffered items waiting to be dispatched to the Host
and that are pending because of lack of Host buffers.
When an iteration of the recv_thread obtains a element from the radio it
needs to process it immediately, either sending it straight away to the
Host or appending it to the queue. This was not the case before this
patch, where the concurrency of a buffered packet with one coming from
the radio would cause the latter to be "dropped", causing missing
packets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-18 14:43:39 +02:00
Michael Scott 1965e5e9fc net: lwm2m: add RD client callbacks for app
Applications may want to be notified when various events
happen in the LwM2M rd client.  Let's implement an event
callback which sends: connect, disconnect and update events.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Ricardo Salveti 58d758bf90 net: lwm2m: firmware: add support for firmware pull over CoAP proxy
CoAP allows a proxy to be used when transferring data (CoAP-CoAP and/or
CoAP-HTTP) by creating request on a specific URI path and by using the
Proxy URI CoAP option. Create specific Kconfig options for the proxy
server address and port, until a parser gets implemented.

Code tested with Californium acting as CoAP proxy.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
[michael.scott@linaro.org: rebased on net_app + lwm2m_message
refactoring + firmware update changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 4a0986dc7a net: lwm2m: ignore duplicate/older block transfers
During firmware download via block-wise transfer, we can see
packets occaionally get re-transmitted (normal logic in the
pending / retry functions).  However, both of these packets
end up coming through the reply handler and we should ignore
any block-wise transfer that has a current value less than
where we expect to be.

NOTE: This fixes K64F ethernet transfers where we were getting
too many packets back in the handler.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ed100e9c6a net: lwm2m: add full block-wise retries for firmware download
UDP packets can be lost in heavy traffic.  Normally we can handle this
with pending packet processing for packets which have not been responded
to with an ACK.  However, due to the time it takes for firmware to
download via CoAP, an extra level of retries should be added.

The process works like this:

Normal pending packets will try to send 3 times fairly quickly.
If that fails, then the timeout callback is called for the firmware
download process.  A retry counter is incremented and the timeout
callback perform a new packet send of the block-wise transfer
packet that is missing, until the retry counter hits a limit (3)
and then the transfer is aborted.

This allows for a longer "outage" to happen during firmware transfer
and the process can still succeed.

NOTE: This patch does not fix a current bug where the pending process
is not re-sending the packets correctly, it only makes the process
more stable with a better chance to work.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 0b0fd5515d net: lwm2m: fix packet leak in timeout work
When a packet expires after the pending retries we call
lwm2m_release_message() to free up resources.  This includes
cleanup of the pending structure which calls net_pkt_unref on
the pending packet.  This would normally free up the packet
memory.  However, earlier in the pending processing we add a ref
to the packet so that normal send processing doesn't free up
the memory.   This meant we were leaking packet memory every
time we had an expiration due to timeout.

Let's do an unref prior to calling lwm2m_release_message() to
make sure the packet memory is freed correctly.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott c9a80de76b net: lwm2m: setup lwm2m ctx for firmware download
Previously, firmware support wasn't initializing the retransmit work
or the extra network packet pools.  Let's fix that.

NOTE: While this fixes the setup of retransmit work, the actual
attempts to re-send packets which are pending is failing.  Needs
another follow-up fix.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 788c013d5b net: lwm2m: split out lwm2m context initialization
Create an internal function lwm2m_engine_context_init() which sets
the extra packet pools and initializes retransmit work internal to
the LwM2M engine.

This function will be used by firmware pull support which establishes
a new LwM2M context for downloading firmware.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott f630857e69 net: lwm2m: fix message release for separate reply
In the case of a proxy server translating HTTP -> COAP (known in
the code as "separate reply"), we were leaking lwm2m_message structures.
This was due to pending objects being cleared out during the first ACK,
and no other way of finding a matching message when the follow up packet
was received.  Let's add a second match for reply to make sure we can
find our matching message resources.

NOTE: This change renames find_msg_from_pending() to find_msg() and
makes it a static function as it's only used by the lwm2m_engine.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott edc32f4619 net: lwm2m: change registraion update messages to INFO
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 61fe1e17c3 net: lwm2m: RD client start message should be INFO not DEBUG
This is a useful message announcing that the RD client state machine
is starting for a particular connection.  If the log level is set
low so that DBG messages are hidden, then this message goes away.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott 3f9c36301c net: lwm2m: fix compile w/o CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
Fix wrong check of DELIVERY_METHOD_PUSH to DELIVERY_METHOD_PUSH_ONLY

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou b93eb8dee1 net: lwm2m: add firmware push support
1. Add handling block1 option in handle_request(). The basic idea is
   to declare structure block_context at compiled time and use "token"
   as a key to pick up the on-going block cotext. It should be able to
   support multiple blockwise transfer concurrently
2. Use write callback implemented in lwm2m_obj_firmware to deal w/ the
   update state transition and than call the callback registered by the
   application
3. move default_block_size to lwm2m_engine.c to share between
   lwm2m_engine and lwm2m_obj_firmware_pull

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on LwM2M net_app changes.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Robert Chou f6188fbce3 net: lwm2m: setup data_ptr/len for OPAQUE resource when none given
OPAQUE resource type might/might not have data_ptr/data_len setup
depending on the implementation. This introduce an issue that when
OPAQUE resource is written from the server side, the ones w/ none
setup will not be able to get the data at post_write_cb()

Modify to setup data_ptr/data_len as incoming buffer and buffer size

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-10-17 19:40:04 -04:00
Robert Chou d9f5fe7455 net: lwm2m: add state machine for firmware pull update
1. Parse firmware pull URI
2. Add lwm2m_firmware_get/set_update_cb() for application to register
   callback. This is because we want to check the update_state before
   we pass to the application
3. Add lwm2m_firmware_get/set_update_result() and
   lwm2m_firmware_get/set_update_stat() to manage the state transition
   as well as the sanity check

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: rebased on net_app framework and
lwm2m_message refactoring.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Michael Scott ba20b3a884 net: lib: lwm2m: use stand-alone URL parser
With future patches we will need to parse URLs in the registration
client and firmware object.  Enable it by default when LWM2M is
enabled.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 19:40:04 -04:00
Johan Hedberg 328f80fa07 Bluetooth: Fix memory leak of command response buffer
There was a missing net_buf_unref() for the response to reading the
controller static addresses.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 17:40:00 -04:00
David B. Kinder ee71332b99 doc: fix doc misspellings
Found some spelling issues missed during regular PR review

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-17 14:31:52 -04:00
Jukka Rissanen 9d1801d987 net: app: Close context even if there is no connection
If there is no connection to server, then _net_app_select_net_ctx()
will return NULL. This is perfectly fine and we can just continue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 14:07:14 -04:00
Jukka Rissanen 2ab129fe8a net: app: Bind to correct address family
Use the remote address to determine what address family to bind.
This prevents extra context to be created. In order to avoid
parsing the peer address string multiple times, the client
init function is re-factored.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 14:07:14 -04:00
Andrew Boie c5c104f91e kernel: fix k_thread_stack_t definition
Currently this is defined as a k_thread_stack_t pointer.
However this isn't correct, stacks are defined as arrays. Extern
references to k_thread_stack_t doesn't work properly as the compiler
treats it as a pointer to the stack array and not the array itself.

Declaring as an unsized array of k_thread_stack_t doesn't work
well either. The least amount of confusion is to leave out the
pointer/array status completely, use pointers for function prototypes,
and define K_THREAD_STACK_EXTERN() to properly create an extern
reference.

The definitions for all functions and struct that use
k_thread_stack_t need to be updated, but code that uses them should
be unchanged.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 08:24:29 -07:00
Jukka Rissanen e2c5b07f90 net: ipv4: Accept multicast packets for processing
We dropped received IPv4 multicast packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00
Jukka Rissanen c72deba1fe net: dns: Fix dns_pack.h documentation of packing routines
Some doxygen directives were missing from dns_pack.h file.
Also make function header documentation look better.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00
Jukka Rissanen 0257ce3d31 net: mdns: Initial mDNS responder support
This creates mDNS responder and serves configured IP addresses
to the callers which want to resolve .local addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00
Jukka Rissanen 13e69512da net: shell: Print hostname information
When printing network interfaces, print also current hostname
if it has a valid value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00
Jukka Rissanen e3adbf845c net: Add hostname setting to Kconfig
User can configure hostname of the device in Kconfig. This can
be used by mDNS responder to answer <hostname>.local queries.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-17 08:36:39 -04:00
Aska Wu 632904117c net: sockets: Fix the error zsock_send() failed on the datagram socket
net_context_sendto() returns an error if dest address is NULL.

If dest address is available, net_conext_sendto() should be used.
Otherwise, net_context_send() should be used.

Fixes #4347

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-17 08:10:14 -04:00
Michael Scott 1d36225345 net: lib: http: split out URL parsing as a separate CONFIG
With the introduction of CoAP and other protocols, URL parsing is
be needed when HTTP_PARSER is not.  Let's split out the existing
functionality of URL parsing into it's own CONFIG and let
HTTP_PARSER use it by automatically selecting HTTP_PARSER_URL when
HTTP_PARSER is enabled.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 08:08:16 -04:00
Johan Hedberg aaeff3c165 Bluetooth: Add basic host-side support for HCI vendor extensions
Add skeleton for HCI vendor extenstions and convert the nRF5x-specific
static address setting to use the HCI VS commands instead.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 15:01:54 +03:00
Carles Cufi 5c49afc9ec Bluetooth: controller: Fix Controller to Host flow control leak
When a connection is disconnected with outstanding unacked packets, the
Host has no way to signal or acknowledge their processing to the
Controller, since it is illegal to send a Host Number of Completed
Packets command when the connection is not up. Instead, consider the
outstanding packets as acked in order not to affect the correct flow
control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-17 13:10:08 +02:00
Johan Hedberg 092ec23024 Bluetooth: Mesh: Fix missing feature bits
The feature bits for Proxy and Friend were missing in the composition
data and heart beat messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-17 13:18:39 +03:00
Michael Scott 03cd73067b net: app: fix MBEDTLS-related build break in net_app
When CONFIG_STDOUT_CONSOLE is not selected, there is no printk()
function.  An alternative (printf) must be used.

This fix was taken from tests/crypto/mbedtls/src/mbedtls.c

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 10:21:21 +03:00
Steve Brown db0ee4ea62 Bluetooth: Mesh: heartbeat fixes for message count
Both count and period must be non-zero for message publication
Stop publication when count becomes zero
Add count to debug message in hb_publish

Signed-off-by: Steve Brown <sbrown@cortland.com>
2017-10-17 08:35:18 +03:00
Leandro Pereira 6f99bdb02a kernel: Provide only one _SYSCALL_HANDLER() macro
Use some preprocessor trickery to automatically deduce the amount of
arguments for the various _SYSCALL_HANDLERn() macros.  Makes the grunt
work of converting a bunch of kernel APIs to system calls slightly
easier.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-10-16 13:42:15 -04:00
Jukka Rissanen 2b9e736f66 net: shell: Add command to flush ARP cache
The "net arp flush" can be used to remove all entries from
ARP cache.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-16 17:13:22 +03:00
Paul Sokolovsky f45c4e1c8e net: shell: mem: Use better config define and terminology
It's possible to get number of free pkts/buffers with just
CONFIG_NET_BUF_POOL_USAGE, whereas CONFIG_NET_DEBUG_NET_PKT
depends on CONFIG_NET_LOG and adds quite a bunch of other
overhead. Also, give a hint that this option should be enabled
to get free buffer numbers.

Additionally, use unambiguous "Total" wording to represend the
maximum capacity of data structures, instead of previous "Count".
"Count" (or at least counter) is intuitively something which can
change, so not seeing any other numbers, it's very easy to assume
that it's actually number of free buffers (because that's the
information a user may be interested in in many cases).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-16 11:00:11 +03:00
Luiz Augusto von Dentz 49c895815a Bluetooth: L2CAP: Increase disconnect timeout to 2 seconds
There have been situations where the remote stacks cannot responds
within a second, so increases it to 2 seconds. The timeout has to be
relatively short as the channel cannot be reused while disconnecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-15 15:50:38 +03:00
Luiz Augusto von Dentz 5115cb16cf Bluetooth: L2CAP: Fix sending MPS that cannot be fully used
MPS shall never be bigger than MTU + 2 as the remaining bytes cannot
be used since the SDU is limited to length + MTU.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-10-15 15:50:38 +03:00
Vinayak Kariappa Chettimada 52bc2b6cd1 Bluetooth: controller: Add Coded PHY packet tx time restrictions
Add implementation to support Coded PHY update procedure
with packet transmit time restrictions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:47:47 +02:00
Vinayak Kariappa Chettimada 77eb73b505 Bluetooth: controller: Add encrypted Coded PHY support
Add support for encrypted Coded PHY connections on nRF52840
SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:45:02 +02:00
Vinayak Kariappa Chettimada 559c0248d5 Bluetooth: controller: Fix PA/LNA for Coded PHY
Use S8 coding Rx chain delay timings to calculate the PA
pin assertions when in Coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada f5d744b998 Bluetooth: controller: Fix tIFS calc for Coded PHY
Always use S8 Rx Chain Delay instead of the actual Rx-ed
packet coding. I believe, as the packet always start with
S8, hence S8 timings when used the tIFS is near correct
value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada 3ab134de9e Bluetooth: controller: Fix Coded PHY supervision timeout
When calculating and setting up the header compelte timeout
use S8 coding Rx chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-15 12:43:45 +02:00
Vinayak Kariappa Chettimada 6a8f22eeab Bluetooth: controller: Fix connection update supervision timeout
In the commit dd52b8ea02 ("Bluetooth: controller: Fix
first connection interval timing"), instead of using just a
tick unit as workaround, microseconds corresponding to a
tick unit was used while calculating the window offset to be
used at the connection update instant. This introduced an
error in scheduling the first event with new connection
parameters, causing supervision timeout of connection update
procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-14 12:20:45 +02:00
Johan Hedberg fccdb28154 Bluetooth: Mesh: Fix mod sub status parameters upon failure
Mesh Profile Specification v1.0, 4.4.1.2.8:

"When an element receives a Config Model Subscription Add message
or a Config Model Subscription Virtual Address Add message that
is not successfully processed (i.e., it results in an error condition
listed in Table 4.113), it shall respond with the Config Model
Subscription Status message, setting its fields to the values
of the corresponding fields (i.e., the identically named fields)
of the incoming message and setting the Status field to a status code
(defined in Table 4.113), and setting all other fields to 0."

The same applies to other Model Subscription messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:24:31 -07:00
Johan Hedberg 02b2b8cf65 Bluetooth: Mesh: Fix potential access to uninitialized variable
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:24:31 -07:00
Johan Hedberg ee217d4051 Bluetooth: Fix freeing up conn->tx_notify upon disconnect
It's possible that tx_notify still contains items when a Disconnect
Complete happens. Since the normal path for processing tx_notify is
not taken when the connection is not in CONNECTED state, we must make
sure to process the list latest in conn_cleanup() that's called as one
last thing before the connection object is freed up.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-13 17:23:46 -07:00
Jukka Rissanen 059959c83e net: tcp: Do not unref caller allocated net_pkt
If the caller has passed net_pkt to prepare_segment(), then
it is caller responsibility to unref it in a case of error.

Fixes #4292

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-13 17:23:25 -07:00
Andrew Boie a49dd2160a sensors: fix build error if userspace enabled
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-13 12:56:14 -07:00
Johann Fischer f67f6b0fdb subsys: mass_storage: add composite device configuration
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer 6fd0afa027 subsys: cdc_acm: add composite device configuration
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer 9b0da3bc0a subsys: usb: add composite device support
This patch adds composite support for USB class drivers.
It acts as a relay between the usb_device stack and
class or function drivers.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 09:18:14 -04:00
Johann Fischer deeb61f97b subsys: mass_storage: rework to use MSC header and common descriptor
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer 2e78a8fd6a subsys: cdc_acm: rework to use CDC header and common descriptor
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer f0832da1e0 subsys: usb: add common device descriptor
Add common device descriptor for USB class devices.
The common descriptor allows easy configuration of Manufacturer,
Product, SerialNumber strings and PID/VID.
It also allows future support for composite devices.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer 74137432c0 subsys: usb: add endpoint configuration for USB MSC
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Johann Fischer ad4c89ca2e subsys: usb: add endpoint configuration for CDC ACM driver
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-10-13 08:32:37 -04:00
Tomasz Bursztyka 7f04af8f7a net/ieee802154: Add a hw capability for handling ACK request on TX
Some chips are smart enough to handle the ACK request flag on
transmitted frames, so it's unneccessary for the L2 to wait for it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 811db9ac6a net/ieee802154: Expose a function to test for AR flag in net_pkt
This is both required in L2's radio part as well as it might be useful
on some ieee802154 radio drivers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 07f5bde3ed net/ieee802154: Stop using old radio API's functions
These are now fully replaced by set_filter() thus removing their usage
by the L2 layer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka c65c2a1130 net/ieee802154: Apply hw filters when applicable
If the hw supports filtering, L2 will apply the ieee address, short
address or PAN ID filters.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka eee33cf888 net/ieee802154: Add support for hw driven CSMA
Using radio's get_capabilities, it is possible to know if the driver can
get CSMA work handed-over.

For now, up to device drivers to use
CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA_* parameters.

Let's see if it will be interesting at some point to enable runtime
modification of these parameters.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka aedece5240 net/ieee802154: Use lqi from net_pkt relevantly
This only affects beacon handling logic, not really used feature for
now.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Vinayak Kariappa Chettimada bebffd3dc6 Bluetooth: controller: Fix missing reset of FC feature
Fixed a missing reset of FC feature on HCI reset. This
feature provided a simple connection handle based event
exclusions, but this is no longer needed with the
support for controller to host flow control. This feature
should be removed in the future.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-13 09:23:54 +02:00
Johan Hedberg c136a2eb83 Bluetooth: Fix reporting packets for disconnected connections
A connection might have gotten disconnected by the time that an ACL
buffer is free up, in which case there is no need to send a HCI
command for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-12 22:02:14 -05:00
Andrew Boie 225e4c0e76 kernel: greatly simplify syscall handlers
We now have macros which should significantly reduce the amount of
boilerplate involved with defining system call handlers.

- Macros which define the proper prototype based on number of arguments
- "SIMPLE" variants which create handlers that don't need anything
  other than object verification

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-12 16:26:28 -05:00
Vinayak Kariappa Chettimada 278df482a9 Bluetooth: controller: Fix missing PHY update procedure reset
When a peer master performed a PHY update procedure with no
change, the state machine was not released. This blocked
any future local initiation of the procedure and also
leading to termination of connection with reason LMP
response timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-12 11:03:51 +02:00
Andrew Boie 37ff5a9bc5 kernel: system call handler cleanup
Use new _SYSCALL_OBJ/_SYSCALL_OBJ_INIT macros.

Use new _SYSCALL_MEMORY_READ/_SYSCALL_MEMORY_WRITE macros.

Some non-obvious checks changed to use _SYSCALL_VERIFY_MSG.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-11 17:54:47 -07:00
Vinayak Kariappa Chettimada 7cc796771b Bluetooth: controller: Fix NRF_AAR use
Fixed the usage of NRF_AAR peripheral for controller privacy
to clear events on configure and on every radio ISR entry.

Without this fix, there was spurious AAR matches leading to
controller asserts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 22:21:10 +02:00
Andrew Boie 756f907274 misc: userspace support for printk()
To avoid making a system call for every character emitted, there is now
a small line buffer if userspace is enabled. The interface to the kernel
is a new system call which takes a sized buffer of console data.

If userspace is not enabled this works like before.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-11 09:23:57 -07:00
Vinayak Kariappa Chettimada e454862600 Bluetooth: controller: Fix PHY Update response state transition
PHY Update procedure timeout was started without transition
to the state that waits for the procedure to complete. This
prevented the timeout from being reset on successful
completion of the procedure and eventually leading to a
connection termination with reason LMP Response Timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 14:07:33 +02:00
Vinayak Kariappa Chettimada f64cccfea9 Bluetooth: controller: Fix CPR procedure's Conn Upd initiation
Fix Connection Parameter Request Procedure's Connection
Update Procedure initiation to calculate the offset rather
than selecting offsets from an out-of-bound memory area.

The symptoms of the bug was noticed as a supervision timeout
due to use of incorrect offset communicated to peer and a
wrong offset used in scheduling the connection events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-11 09:57:36 +02:00
Jukka Rissanen cab505f0c2 net: tcp: Use real MTU size for MSS for IPv6
Instead of hard coded 1280 bytes MSS, use the MTU of the link
for MSS. The minimal MSS is still 1280 which is mandated by
IPv6 RFC.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-10 10:53:00 -04:00
Vinayak Kariappa Chettimada 8ab1a1112b Bluetooth: controller: Fix Conn Param Req response timeout
When the peer slave rejects a Connection Parameter Request
Procedure, the controller proceeds to perform a Connection
Update Procedure without clearing the procedure timer that
causes the connection to terminate eventually. This is
fixed by clearing the procedure timeout when the Connection
Update Procedure completes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:10:23 -04:00
Vinayak Kariappa Chettimada c707c82fc8 Bluetooth: controller: Fix slave from initiating conn upd ind
If a peer master role has support for Connection Parameter
Request Procedure set in its supported features but would
send an Extended Reject Ind as response to the procedure
then the controller incorrectly initiated a Connection
Update Procedure which is not permitted in a slave role.

This would lead to connection timeout after the used instant
in the invalid Connection Update Procedure.

This is fixed by initiating a Connection Update Procedure
only if in a master role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-10-10 10:09:49 -04:00
Johan Hedberg 44d4c06b70 Bluetooth: Mesh: Fix missing initialization of bt_mesh.local_queue
The local_queue was never being initialized.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-09 20:40:36 +03:00
Johan Hedberg d1dd19880d Bluetooth: Mesh: Fix revoking app keys
The needed code for taking updated app keys into use and revoking the
old ones was missing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-09 19:46:10 +03:00
Tomasz Bursztyka efab82232b net/mgmt: Cleanup a bit Kconfig
Remove "depends on" and replace with an if/endif.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-09 10:53:17 +03:00
Tomasz Bursztyka 8e25695937 net/mgmt: Make event notifiers able to pass info to listeners
Adding net_mgmt_event_notify_with_info() which lets the event notifier
to pass dedicated data along with the event. The size of data that can
be passed must be limited to the biggest data passed (which will be
currently IPv6 + prefix).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-09 10:53:17 +03:00
Tomasz Bursztyka 743e50751f net/ieee802154: Always set ACK flag to 0 on data broadcast
commit d02fe29616 did not manage this
case.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-08 16:38:32 +03:00
Andrew Boie 6d79fe54da sensors: implement system calls
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-07 10:45:15 -07:00
Marti Bolivar 313b20d648 dfu: replace FLASH_ALIGN with FLASH_WRITE_BLOCK_SIZE
Use the define generated by the DTS instead of using the FLASH_ALIGN
alias. The latter is an internal mcuboot name. We shouldn't need it in
Zephyr itself.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-06 22:12:23 -04:00
Ravi kumar Veeramally f4772519d6 net: coap: Add multi fragment support to CoAP library
Current coap library fails to parse or prepare if packet is more
than one fragment. Added support to handle multi fragment packet.
Also well-known/core api used to prepare coap packet and send it
through net context api immediately. This is goind to be problematic
if user doesn't enable net context. Also user can not encrypt coap
packets. Now api will return prepared coap packet to application.
Application will send it to peer.

Jira: ZEP-2210

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-06 22:07:37 -04:00
Ravi kumar Veeramally 42a91f4c07 net: coap: Rename ZOAP library
ZOAP library has certain limitations in parsing and preparation of
coap messages. It can handle only on single network fragment. If
network packet is split between multiple fragments it fails. This
patch is just copy and rename of 'zoap' to 'coap'.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-06 22:07:37 -04:00
Paul Sokolovsky 77b8f5c1f6 net: l2: ieee802154: Automatically select CONFIG_NET_6LO
802.15.4 IP-based networking requires 6LoWPAN layer and won't work
correctly without it. So, if NET_L2_IEEE802154 is select,
automatically select NET_6LO. This is similar to what BLE L2
does (NET_L2_BT causes selection of NET_6LO).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-06 18:26:51 +03:00
Paul Sokolovsky 12d52542a3 net: lib: app: If NET_LOG_GLOBAL is enabled, enable NET_DEBUG_APP
This is similar to the changes made previously to other network
components: if user selected NET_LOG_GLOBAL, they really mean
they want logging (first of all, error/warning logging) across
the entire network stack.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-05 13:41:52 +03:00
Johan Hedberg 3993814e94 Bluetooth: Add helper to iterate all key objects
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Johan Hedberg a2db217e15 Bluetooth: Clean up address-to-string usage & implementation
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Johan Hedberg 8d02ab52ad Bluetooth: Add command opcode to warning about unusual pool id
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Tomasz Bursztyka 02cf1ab390 net/ieee802154: Fixing a typo in ieee15_4 shell module
Obviously unset ACK requires NET_REQUEST_IEEE802154_UNSET_ACK request.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-05 11:13:08 +03:00
Michael Scott b7060cf611 net: lwm2m: set range for client lifetime config
Due to timeout checking the minimum lifetime must be 15 seconds,
and we're storing the lifetime as an unsigned short so set the
maximum to 65535.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott b3e58c7874 net: lwm2m: add timeout callbacks to registration client
Callbacks are setup for the following states:
- ENGINE_DO_BOOTSTRAP
- ENGINE_DO_REGISTRATION (first registration)
- ENGINE_REGISTRATION_DONE (subsequent client updates)
- ENGINE_DEREGISTER

In most cases, if a timeout occurs the registration engine goes back to
ENGINE_INIT.  The exception is a timeout during client update, which
forces the state machine back to ENGINE_DO_REGISTRATION (skipping a
boostrap).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott 897dbffe7c net: lwm2m: refactor engine to use lwm2m_message structure
Sending an lwm2m message is too difficult.  It requires pending / reply
and other structures to be configured and set by various portions of
the library.  There is also no way to know if a pending message ever
encounters a timeout.

Let's fix this by simplifying the internal LwM2M engine APIs for
handling lwm2m messages:

1. A user calls lwm2m_get_message(lwm2m_ctx) which returns the first
   available lwm2m message from an array of messages
   (total # of messages is set via CONFIG_LWM2M_ENGINE_MAX_MESSAGES).
2. Next the user sets all of the fields in the message that are
   required (type, code message id, token, etc)
3. Then the user calls lwm2m_init_message(msg).  This initializes the
   underlying zoap_packet, pending and reply structures.
4. Once initialized, the user creates their payload in msg->zpkt.
5. When the user is ready to send, the call lwm2m_send_message(msg).
6. And if for some reason an error occurs at any point, they can free
   up the entire set of structures with: lwm2m_release_message(msg).

Included in the refactoring is a timeout_cb field which can be set in
the LwM2M messages.  If a pending structure ever expires the engine
will call the timeout_cb passing in the msg structure before it's
automatically released.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Michael Scott 42f3eccb38 net: lwm2m: cleanup token / token length handling
Instead of using a magic reference to 8 for token length, let's
establish a define for MAX_TOKEN_LENGTH and then use it for both
variable definitions and to make sure tokens are valid.  Also,

Correct the handling of a special token length value (0xFF) which
lets lwm2m_init_message() know to skip token generation.  We were
using a -1 value here previously (on a u8_t variable).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03:00
Jukka Rissanen e9eb128895 net: shell: Use correct network interface instead of default one
When the net-shell needs to send something to network interface,
it will check if the target address is found in neighbor cache and
then use that network interface. If the address is not found in nbr
cache, then the default interface is used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-04 10:58:18 +03:00
David B. Kinder f00f58517b doc: replace UTF-8 chars
Some our Zephyr tools don't like seeing UTF-8 characters, as reported in
issue #4131) so a quick scan and replace for UTF-8 characters in .rst,
.h, and Kconfig files using "file --mime-encoding" (excluding the /ext
folders) finds these files to tweak.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-03 20:03:57 -04:00
Paul Sokolovsky 82a03936a4 net: sockets: Simplify if logic in sendto(), fix warning
send()/sendto() aren't "front facing" functions, so when user calls
them, context type hopefully should be already validated by other
functions. They are also on critical path of app/network performance,
so getting rid of extra check helps a little bit too. This also
fixes a warning of "err" possibly being used non-initialized.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-03 16:18:11 -04:00
Aska Wu f1e488a488 net: sntp: Implement SNTP client library
The implementation is based on net app API. It sends the request and
parses the server reply by following some suggestions mentioned in the
secion "SNTP Server Operations" of RFC 4330.

The system uptime is used as the transmit timestamp of client request
This lib can work on those devices without RTC.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-03 15:29:27 -04:00
Anas Nashif e5ffa66d84 dfu: fix includes
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Anas Nashif 71a927955e usb: move headers to include/usb/class
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Anas Nashif 18a33edd39 usb: fix local includes and add usb namespace
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Carles Cufi e0c1c0aa64 Bluetooth: controller: Common config for VS extensions
Since the Zephyr HCI VS extensions apply to both the Host (using them
for additional functionality) and the Controller (implement the commands
and events), it make sense to make this a common setting in order for it
to be configurable in a way that applies to both.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-03 17:57:49 +03:00
Anas Nashif c6a8014e1c subsys: fs: consolidate elm FAT kconfig options
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 08:43:50 -04:00
Anas Nashif 3580ba539e subsys: fs: consolidate nffs kconfig options
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 08:43:50 -04:00
Anas Nashif 6192555b35 kconfig: cleanup file system kconfig
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 08:43:50 -04:00
Aska Wu 9ec60774f8 net: sockets: Implement sendto() and recvfrom()
sendto() and recvfrom() are often used with datagram socket.

sendto() is based on net_context_sendto() and recvfrom() is based on
zsock_recv() with parsing source address from the packet header.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-03 14:40:05 +03:00
Aska Wu 379771e2eb net: context: Bind default address for UDP
This patch makes net_context_sendto() work independently without calling
net_context_connect() first. It will bind default address and port if
necessary.

Also, since receive callback should be provided before sending data in
order to receive the response, bind default address and port to prevent
providing an unbound address and port to net_conn_register().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-03 14:40:05 +03:00
Aska Wu 1a2f24f920 net: pkt: Add net_pkt_get_src_addr()
Introduce net_pkt_get_src_addr() as a helper function to get the source
address and port from the packet header.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-10-03 14:40:05 +03:00
Carles Cufi 09330fa7b0 Bluetooth: controller: Disable PA/LNA for nRF51x
The PA/LNA feature is not functional on nRF51x series due to added
interrupt latency. Disable this feature unconditionally for those ICs to
avoid unexpected behavior.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-10-02 12:04:43 +02:00
Michael Scott 6110965ece net: lib: net app: restore IP header length when DTLS is used.
Other parts of the networking subsystem may use net_pkt_ip_hdr_len() on
a packet that has been encrypted for use with DTLS.  Let's restore that
value here so those areas don't receive an erroneous 0 value.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-02 12:00:12 +03:00
Vinayak Kariappa Chettimada 6831351799 Bluetooth: shell: Add controller DTM commands
Add controller Direct Test Mode commands to bt shell module.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 20:56:11 +02:00
Vinayak Kariappa Chettimada e95fd2860d Bluetooth: controller: Fix HCI Reset hang
Issuing HCI reset command while having connections sometimes
hung the controller.

ll_reset supplied invalid stop ticker id to role_disable
when trying to stop all connections. Connection role does
not utilize stop ticker. The invalid ticker id supplied
referenced memory outside the pool of tickers and based on
what the content is in RAM there, the controller would hang
trying to stop connections.

Fixed by not calling the ticker_stop interface with invalid
ticker ids.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:47:36 +02:00
Vinayak Kariappa Chettimada b97b9c4fef Bluetooth: controller: GPIO PA/LNA feature
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
Carles Cufi 6cfac15c68 Bluetooth: controller: Add PA/LNA GPIO Kconfig option
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-29 15:38:31 +02:00
KaSroka 94c0d23691 net: Log drop reason when UDP or TCP checksum mismatch occurs
Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2017-09-29 15:10:35 +03:00
Jukka Rissanen fb32aebd78 net: ipv6: Fix IPv6 address parameters when sending NA
The IPv6 address parameters in net_ipv6_send_na() can be const
as the function will not modify them. This avoids compile warning
about parameter constness.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 15:09:10 +03:00
Jukka Rissanen 45a46fafaa net: ipv6: Return neighbors in foreach function by interface order
It is useful to return the neighbors in net_ipv6_nbr_foreach()
groupped by network interface. This way the caller has them
already in proper order and does not need to re-group them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 15:08:44 +03:00
Jukka Rissanen 274be20ae9 net: shell: Fix command outputs
Some of the net commands had wrong alignments and newlines were
missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 15:08:00 +03:00
KaSroka 4d423f1c80 net: app: Don't wait for DAD to finish when DAD is disabled
Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2017-09-29 15:07:29 +03:00
Johan Hedberg 029780a196 Bluetooth: Mesh: Fix dropping valid proxy configration messages
Proxy configuration messages are allowed (in fact required) to use
unassigned addresses, so they should be exempt from this check.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg a576c4a73b Bluetooth: Mesh: Don't send health status messages if a test fails
The test failure may be e.g. because of an unknown company id, and in
that case the spec expects us to ignore the message.

With this patch it should be possible to pass MESH/SR/HM/RFS/BI-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 8d0ef1eb85 Bluetooth: Mesh: Fix setting health period divider
A previous patch which moved dispatching the health publish callback
to a later moment introduced a regression where the period divider
does not get updated when it should. In fact, having the divider as
part of the Health Server context is redundant, since the same
information is already stored generically in the model publication
context. Switching to using the model publication context makes things
simpler and ensures that the value is always up-to-date.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 4d3a2c66d1 Bluetooth: Mesh: Fix Set LPNTimeout message handling
We should ignore invalid addresses (helps pass
MESH/NODE/CFG/LPNPT/BI-01-C). Also fix a copy-paste issue in an error
log.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 19c304086f Bluetooth: Mesh: Fix resetting heartbeat subscription expiry properly
Set the value clearly to 0 instead of letting the old expiry time stay
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg f1638e0a2b Bluetooth: Mesh: Fix zeroing heartbeat state
The values all need to be zeroed when heartbeat subscription is
disabled. This makes it possible to pass MESH/NODE/CFG/HBS/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg ea397170d3 Bluetooth: Mesh: Fix spelling of "heartbeat"
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 53d06a1653 Bluetooth: Mesh: Fix encoding fault count to Health Current Status
There was a missing adjustment to buf->len after fetching the faults
from the app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg a3a481deb1 Bluetooth: Mesh: Fix Health Period Set OpCode
This was a copy-paste mistake.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Jukka Rissanen d14919ce47 net: if: Add IPv4 multicast add, remove and lookup functions
There was no handler functions for adding, removing and looking up
IPv4 multicast addresses in the network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 11:34:06 +03:00
Jukka Rissanen 2c6e473c93 net: context: Bind did not check IPv4 multicast address
If the user tried to bind to IPv4 multicast address, then the
operation failed and returned error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 11:34:06 +03:00
Jukka Rissanen 604cdb6b6d net: shell: Do not print IPv4 information in some cases
If the network interface does not support IPv4 like IEEE 802.15.4
or Bluetooth, then do not print IPv4 information for those interfaces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 11:29:43 +03:00
Carles Cufi 3b2120f500 Bluetooth: controller: Implement Read Build Info cmd
Implement the Read Build Information VS command. This returns a UTF-8
encoded string, which is extendable by the user via a new Kconfig
option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Carles Cufi 573c1c9071 Bluetooth: controller: Implement Write BD_ADDR VS cmd
Implement the Zephyr VS command that allows a Host to write a public
Bluetooth Address to the Controller in order to allow Hosts to provide
their own public Bluetooth addresses.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-28 15:41:49 +02:00
Jukka Rissanen c798c8293a net: pkt: Allow inserting NULL data
If the data parameter in net_pkt_insert() is NULL, then just
insert amount of data but clear the area instead of copying.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-28 12:42:25 +03:00
Jukka Rissanen c50d555c1e net: Allow user to tweak IPv4 TTL per packet
User was able to tweak IPv6 hop-limit so introduce similar
feature for IPv4 Time-To-Live value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-28 12:39:54 +03:00
Jukka Rissanen eda6403850 net: http: HTTP client was not honoring timeout parameter
If the caller of http_client_send_req() sets the timeout to
K_NO_WAIT, then the function would still wait for a while before
returning to the caller.

Jira: ZEP-2624

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-27 22:11:21 +03:00
Johan Hedberg d712a4e1a3 Bluetooth: Mesh: Remove local network interface Kconfig option
From section 3.4.5.3 in the Mesh Profile Specification 1.0:

    "A node shall implement a Local Network Interface."

Removing the Kconfig option also helps clean up quite a lot of code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg 76fd02ee0c Bluetooth: Mesh: Allow TTL <= 1 for the local net interface
The bt_mesh_net_relay() function needs to allow TTL <= 1 for the local
network interface since that's the code path that locally originated
outgoing packets take.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg 418cdadeab Bluetooth: Mesh: Send ack for every message with matching FCS
Mesh Profile Specification v1.0, 5.3.3:

"On the PB-ADV bearer, when the receiver has received all segments of
a transaction, the receiver shall calculate the FCS for the received
Provisioning PDU, and if it matches the FCS field in the Transaction
Start PDU, it shall send a Transaction Acknowledgment PDU after
a random delay between 20 and 50 milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 7e779ba69b Bluetooth: Mesh: Always set company ID in health status message
The Mesh specification recommends defaulting to the company ID in the
composition data when no other ID is relevant (e.g. in error cases or
if the app has not provided a callback).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg ac5140891b Bluetooth: Mesh: Set timer for periodic publish before publishing
Encrypting and sending a message takes a considerable amount of time
which makes the publication period longer than expected.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C test.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg fc679c50f9 Bluetooth: Mesh: Fix encoding health status when app has no callback
The branch for handling the case when the app has not provided a
callback for health faults was encoding the payload in a wrong way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 6b966e4b96 Bluetooth: Mesh: Fix copy-paste mistake when assigning to cfg->frnd
The right value is BT_MESH_FRIEND_NOT_SUPPORTED.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 5363f6e765 Bluetooth: Mesh: Drop invalid destination addresses
This is required to pass certain PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 68b459ec41 tests: bluetooth/at: Fix string signedness issues
To avoid signedness issues with some compilers, like icx, use 'char *'
instead of 'unsigned char *' for the at_client buffer.

Fixes #3600

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:50 +03:00
Johan Hedberg c40dc580b0 Bluetooth: Mesh: Fix SDU length check
The code was passing the wrong first parameter to the sdu_len_is_ok()
function.

Fixes #3985
Fixes #3984

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Johan Hedberg 3341439f98 Bluetooth: Mesh: Fix string signedness issue
Some compilers (like icx) may complain about unsigned vs signed
strings.

Fixes #3985

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Jukka Rissanen 4dc2dd87ea net: nbr: Print network interface pointer when adding neighbor
Useful when debugging issues in neighbor management.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-26 11:31:57 +03:00
Jukka Rissanen bc4ce8bda8 net: rpl: Neighbor data corrupted when receiving DAO message
The code was accessing wrong neighbor data when it received DAO
message. This corrupted nbr->iface pointer which was clearly seen
by "net nbr" shell command. The corruption then caused random
crashes or hangs when network interface via that pointer was
accessed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-26 11:31:57 +03:00
Jukka Rissanen 9369538642 net: ethernet: Set dest MAC address for IPv4 mcast
If the ethernet packet destination MAC address is NULL when sending
IPv4 multicast or broadcast packet, then we must set it as otherwise
we might to access NULL pointer data.

Fixes #1544

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-26 09:36:56 +03:00
Luiz Augusto von Dentz 2e50126f55 net: nbr: Add NET_IPV6_NBR_STATE_STATIC
This adds a new state NET_IPV6_NBR_STATE_STATIC which never timeouts
which is required in case of RFC 7668 which doesn't allow publishing
the address:

https://tools.ietf.org/html/rfc7668#section-3.2.3

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-09-26 09:19:32 +03:00
Johan Hedberg bac7367b0a Bluetooth: SMP: Fix responding to Pairing Failed PDUs
It makes no sense to respond with Pairing Failed PDU to another
Pairing Failed PDU.

Jira: ZEP-2620

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-25 14:38:34 +03:00
Andrzej Kaczmarek 12e2dfd90a fs: shell: Add more shell functions
Add following commands to fs shell:
- rf <filename>
- read <filename> [<offset> [<length>]]
- write <filename> [-o <offset>] <byte1> [<byte2> ... [<byteN>]]
- trunc <filename> [<length>]

For writes without offset specified, new data is appended to file.
For truncaces without length specified, 0 is default value.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-09-22 06:54:48 -04:00
Andrzej Kaczmarek 7feacf26c2 fs: shell: Extract common path handling code to helper
This patch moves code to create absolute path of file/directory to
separate helper since the same code is used in few places.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-09-22 06:54:48 -04:00
Andrzej Kaczmarek 81da3ca295 fs: nffs: Add NFFS filesystem support
This patch adds filesystem interface implementation for NFFS.
Default configuration for mem slabs sizes are the same as in Mynewt.

Origin: Original
Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-09-22 06:54:48 -04:00
Vinayak Kariappa Chettimada f0274c9e52 Bluetooth: controller: Move tIFS s/w switch PPI index up by one
Move the use of tIFS software switching PPI index set up by
one position to make place for use of PA/LNA implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:43 +02:00
Vinayak Kariappa Chettimada 74cd8d852e Bluetooth: controller: Use single PPI channel for AA capture
Earlier design captured AA twice in the first Rx in a slave
connection event and retained one of the capture until end
of event to calculate drift.

Design updated to use single capture of AA and save the
first AA capture in a slave connection event in RAM instead.

This frees up a PPI channel in the controller design.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 16:14:27 +02:00
Vinayak Kariappa Chettimada 3cd37866cc Bluetooth: controller: Internal document purpose of end capture
Document internal the purposes of various Tx/Rx PDU end
capture setup.

Also, removed any redundant capture of packet end.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:37 +02:00
Vinayak Kariappa Chettimada 4cb7b949dc Bluetooth: controller: Minor refactor radio_tmr_start
Minor refactor of radio_tmr_start to reduced duplicate
assignments common in if-then-else control path.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-21 15:18:07 +02:00
Andrei Emeltchenko 4efaefba5c usb: Allow to select configuration for composite devices
Composite multifunction USB devices should be able to know about
configuration change, implement it through existing callback.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko d5486e2e73 usb: Add CDC Class specific request definitions
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko e4b62aec7f usb: cdc: Add Ethernet Networking Descriptor definitions
Add definitions for Ethernet Networking Functional Descriptor
implementation.

Change-Id: I5b6a28e844c1e765da6230b6e1a01b008251b549
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko 799e9e6594 usb: trivial: Clean up tabulation
Make code look consistent.

Change-Id: Ic10b2e0f3df09b225ad4e556a0b0860348f8d598
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Andrei Emeltchenko 36b4a5c64d usb: Handle SET_INTERFACE request
Handle SET_INTERFACE USB request making it possible to implement
complex devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:00:23 -04:00
Anas Nashif db4eba64da dfu: img_util: move flash defines to SoC
mcuboot_constraints.h had FLASH information related to the SoC that
should be maintained as part of the SoC and not in the subsystem. Also
fixed Makefiles to check for IMG_UTIL Kconfig and not MCUBOOT.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-09-21 06:46:27 -04:00
Andrei Emeltchenko c9a60b73a1 net: arp: Always report error for missing gateway
At the moment errors are not always reported depending on
CONFIG_NET_DEBUG_ARP.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:39:07 +03:00
Andrei Emeltchenko aedbb8c220 net: arp: Exit early on zero gateway provided
In a case gateway is not set drop packet early otherwise bogus
ARPs for 0.0.0.0 are sent.

...
[net/arp] [DBG] find_entry: (0xa8006720): dst 0.0.0.0
[net/arp] [DBG] find_entry: (0xa8006720): [0] iface 0xa800cd80 dst
0.0.0.0 ll 00:00:00:00:00:00 pending 0xa800a7c0
[net/arp] [DBG] find_entry: (0xa8006720): ARP already pending to
0.0.0.0 ll 00:00:00:00:00:00
[net/arp] [DBG] net_arp_prepare: (0xa8006720): Resending ARP
0xa800a380
...

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-21 09:39:07 +03:00
Jukka Rissanen 43aa12fe25 net: dns: Do not resolve IPv6 address if IPv6 is disabled
If IPv6 is disabled, then it is useless to try to resolve
IPv6 address because "struct sockaddr" does not have enough
space to store IPv6 address.

Fixes #1487

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-20 08:55:06 +03:00
Jukka Rissanen bfc583c53f net: pkt: Allow cloning just the net_pkt without any data
It is useful to clone just the net_pkt which does not have any
data fragments linked to it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-20 08:40:34 +03:00
Paul Sokolovsky d3c7152528 net: sockets: Implement getaddrinfo()
POSIX-compatible getaddrinfo() call, implemented on top of native
Zephyr DNS resolver.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-19 17:39:44 +03:00
Paul Sokolovsky c7da45f9e2 net: Enable logging in more modules if CONFIG_NET_LOG_GLOBAL defined
This is useful to enable error/warning logging across the net
codebase (less useful for debug level logging, but that's true
for CONFIG_NET_LOG_GLOBAL already).

Implementation-wise, instead of keeping adding to long list of
"select"'s in CONFIG_NET_LOG_GLOBAL and thus introduce component
inter-dependencies, add "default y if NET_LOG_GLOBAL" to
individual components' logging options.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-18 08:19:27 -04:00
Andrei Emeltchenko cc4d138438 net: l2: Correct debug message and avoid unneeded assignment
At the moment we print "Sending ARP packet" even if we found ARP entry
and send the packet directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-18 10:27:47 +03:00
Michael Scott 70372f1201 net: lwm2m: save lwm2m_ctx instead of net_app_ctx in observer
This is the first part of a large refactoring of LwM2M library
message functions and will simplify observer handling later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 10464e346c net: lwm2m: remove extra sockaddr values
All throughout the LwM2M library we use sockaddr values which are
basically the same as the net_app_ctx's remote addr.  There's no
reason to keep these extra sockaddr values around.  The net_app
framework client won't accept incoming requests on sockaddr other
than the one we're connected to.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 3840761265 net: lwm2m: remove registration client "registered" field
Replace with a check of the state machine's state instead.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 33c79033d0 net: lwm2m: move library internals to net_app APIs
This is the final stage of moving the LwM2M library internals to
the net_app APIs.  This means we can support DTLS and other
built-in features in the future.  All of the logic for
establishing the network connection is removed from the sample
app.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 53099eb501 net: lwm2m: add net_context parameters to functions
In preparation for the move to net_app APIs, we will need
to pass net_app_ctx structures around to the following
functions:
lwm2m_udp_sendto()
udp_request_handler()

Let's add the parameter as net_context for now so the
transition will be smoother later.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott aa3e52c261 net: lwm2m: remove net_context parameter from lwm2m_udp_receive()
This is part of lwm2m_ctx and is not needed.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 148b264255 net: lwm2m: add ZoAP pendings/replies to lwm2m_ctx
This allows use to associate easily the replies / pending operations
with a specific network connection.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott e6b2eeb6a6 net: lwm2m: move retransmit_work to lwm2m_ctx
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 82c2b70cb5 samples: lwm2m: initialize lwm2m_ctx prior to use
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Michael Scott 728ab4229a net: lwm2m: introduce lwm2m context structure
The LwM2M library does not use net_app APIs internally.  To help
this effort let's establish a user facing structure "lwm2m_ctx"
(similar to http_client_ctx and mqtt_ctx) and start it off by
wrappering the net_context structure.

Future patches will add user setup options to this structure and
eventually remove the net_context structure in favor of a net_app_ctx.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-18 10:26:41 +03:00
Paul Sokolovsky 416711a989 net: arp: Log error if no gateway is set
If no gateway is set, an ARP request for 0.0.0.0 will be sent out,
which is confusing, so log as an error. Of course, logging will
happen only if enabled.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-18 10:13:14 +03:00
Jukka Rissanen 91041f9e73 net: ethernet: Fix the multicast IPv4 to MAC address mapping
The IPv4 multicast address to MAC address mapping was missing
the 4th byte high bit clearing.

We also need to have some storage for the multicast MAC address.
This was missing which could cause NULL pointer access.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-17 18:02:18 -04:00
Jukka Rissanen 1865b91f97 net: mdns: Add multicast DNS client support
This implements mDNS client from RFC 6762. What this means that
caller is able to resolve "hostname.local" names using multicast DNS.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-17 18:02:18 -04:00
Ricardo Salveti 34278a3a56 net: net_pkt: clone pkt from the same slab
Fixes a tx_pkts slab leak since the cloned pkt was referencing the
original pkt slab but was not originated from it (net_pkt_unref uses
pkt->slab when releasing the pkt).

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-09-15 15:43:30 +03:00
Paul Sokolovsky 4881fa2a0c net: if: Lack of default interface is an error, not warning.
Because a next networking API call will lead to a crash. Given that
logging can be easily disabled (disabled by default so far!), don't
be shy and call by the name (i.e. error).

Jira: ZEP-2105

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-15 12:21:14 +03:00
Jukka Rissanen 7344d64965 net: Do not try to parse empty IP address string
If the IP address string is empty, then it is no use trying
to parse it. This was seen when handling DNS server strings when
user has made a mistake and defined the DNS server addresses
incorrectly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-15 12:20:32 +03:00
Vinayak Kariappa Chettimada 492d9d9a06 Bluetooth: controller: Map debug pins to P3 pin head on nRF5x DK
Updated debug pin mapping so that the outputs are on P3 pin
head on all nRF5x Development Kits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:25:55 +02:00
Vinayak Kariappa Chettimada 4d3a07b8be Bluetooth: controller: Add radio setup HAL interface
Added a new interface to perform setup of radio hardware.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada a952d47a31 Bluetooth: controller: Fix NRF_CCM config for 2M PHY
Fixed the configuration of NRF_CCM for 2M PHY connections.
Now faster 2M data rate mode will be used when a connection
is in 2M PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada ea431f5fce Bluetooth: controller: Use correct NRF_AAR enable define
Use correct NRF_AAR enable macro defines from Nordic MDK.
Old code funtionally worked fine even though not setting
the correct enable value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada 247488c038 Bluetooth: controller: Remove unreachable workaround code
A workaround code for nRF52840 under nRF51 conditional
compilation is removed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:43 +02:00
Vinayak Kariappa Chettimada 20c4db8197 Bluetooth: controller: Fix conn param req procedure timeout
Fixed a bug in the implementation of Connection Parameter
Request Procedure when initiated in master role caused the
connection to terminate with reason LL response timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-15 10:05:15 +02:00
Carles Cufi d627ae4802 Bluetooth: controller: Fix handling of Read Static Addrs cmd
The status in the Command Complete event was uninitialized, leading to
incorrect contents of the event parsed by the Host. Correctly initialize
the status to success.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-14 17:15:23 +02:00
Vinayak Kariappa Chettimada e17e495af8 Bluetooth: controller: Fix hang on directed adv timeout
During testing it was discovered that directed advertising
timeout is missing implementation to handle the timeout
happening while next event is already in preparation.
The consequence was that after the event ticker expired,
the counter is shutdown, stalling the setup PPI from
starting the erroneous advertising, leaving the controller
in an invalid hung state.

This has been fixed by correctly handling the cases, stop
between prepare and event, and stop inside radio advertising
event. The fix takes care of putting the radio active
callback and HF clock in the correct states.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-13 18:03:14 +03:00
Andrei Emeltchenko 681bf1f143 net: icmpv4: Fix ICMPv4 packet size calculation
Adjust length of the packet before setup_ipv4_header() which actually
might increase packet size if there is not enough space available.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-13 09:28:32 -04:00
Andrei Emeltchenko d55852e3cf net: icmpv4: Fix ICMPv4 checksum calculation
Make calculation after we adjust size.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-09-13 09:28:32 -04:00
Carles Cufi b77b8e615b Bluetooth: controller: Issue Data Buffer Overflow event
Whenever the HCI ACL flow control is violated by the Host, a Data Buffer
Overflow event is now issued by the Controller (if enabled) to notify
the Host of the buffer overrun.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-13 14:17:32 +02:00
Jukka Rissanen 93d2df6bf3 net: Introduce multicast group join/leave monitor
Create support for registering a callback that will be called
if the device leaves or joins IPv6 multicast group.

Jira: ZEP-1673

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-13 14:15:02 +03:00
Tomasz Bursztyka a86ae5f5ed net/arp: Fixing a leak when there is no pending entries left
Commit cd35742a2 missed one unref too many on pending packet which was
triggering a crash which commit 0b8434f08 tried to fix, but it generates
a leak when there is not pending entries left in arp core. Finally,
fixing what cd35742a2 should have done: removing the extra unecessary
unref after sending the pending packet.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-09-13 11:30:28 +03:00
Robert Chou c0a946ac3c net: lwm2m: propogate errors to the caller when using TLV writer
Errors has been ignored when using TLV writer to create/write object
instance/resources. Modify to propagate the error back to the caller.

To reproduce the issue, try to create IPSO light control object
instances twice. Since the default instance count is 1, the second one
should be rejected and responded w/ error. But the current
implementation will respond w/ 2.04.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou 70ee7e31af net: lwm2m: return 4.04 (not found) when obj/obj_inst/res not exist
We did not check the requested object/object instance/resource exists or
not before we adding an observer. Correct it by checking the existence
first.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou 627d199db3 net: lwm2m: clean up observer when object/object instance is removed
We should stop sending out notification to the peer when the
object/object instances requested to be observed is removed

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou b6a0cdfd64 net: lwm2m: fix obj/obj_inst/observer sys_slist_t corrupted when remove
We were using sys_slist_remove() to remove object, object instance and
observer w/o passing the previous sys_snode_t to it (NULL).
This will instruct the function to treat the node as the list head and
result in unexpected behavior after the removal.

Correct it by using sys_slist_find_and_remove() or passing the previous
node to the function.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Robert Chou dc0b838641 net: lwm2m: reset obj_inst/res_inst data structure when delete
When a request demands to create a new object instance, it will search
whether the request object instance exists or not. However, current
implementation does not reset the lwm2m_engine_obj_inst at the time it
is deleted. It only removes the object instance from the sys list.

Correct the behavior by resetting both object instance and resource
instances at the time it's deleted. Also, consolidate function
lwm2m_delete_handler() and lwm2m_delete_obj_inst().

To reproduce the issue, try to create light control object instance
(/3301), delete the created instance and create it again. You shall find
following error message dumped.
> [ipso_light_control] [ERR] light_control_create: Can not create
  instance - already existing: 0
> [lib/lwm2m_engine] [ERR] lwm2m_create_obj_inst: unable to create obj -
  3311 instance 0

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-09-12 20:40:29 +03:00
Michael Scott cff468217b net: lwm2m: select NET_APP_CLIENT automatically
No need for samples to make sure they have this configured in their
.conf files.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-09-12 20:37:48 +03:00
Jukka Rissanen 0b8434f08f net: ethernet: Do not unref pending ARP request
If the packet is put pending because ARP request need to be
done, then do not unref original packet.

Fixes #1416

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-12 17:40:36 +03:00
Jukka Rissanen 13a6acecc3 net: shell: Add ARP cache printing
Add a command "net arp" to net-shell. This new command will
print ARP cache contents if IPv4 and Ethernet are enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-12 17:39:29 +03:00
Jukka Rissanen 1aa1528fe2 net: app: Init static IPv6 address properly
The commit 725be227 ("net/mgmt/event: Commands must be > 0 so
masking them works") prevented IPv6 address setting when an
application was initialized. The check in subsys/net/lib/app/init.c
needs to be adjusted because of that change.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-12 16:58:24 +03:00
Jukka Rissanen e71a31e22f net: Wrong networking defines used in the code
There were bunch of config options in tests/net, net-shell and
wpan_serial sample, and those options had wrong name so they
were ignored by the code.

Fixes #1428

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-12 08:37:53 -04:00
Andrzej Puzdrowski 25c6610a65 DFU: add module for store the image
Store image in sequence of certain blocks.
Module is intended to be use by a higher-level
image management protocol module

Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-09-11 11:37:43 -04:00
Andrzej Puzdrowski 49fccdd2ea DFU: add module for interact with mcuboot
read, update status
trigger flashing
erase image bank
Module is intended to be use by a higher-level
image management protocol module.

Signed-off-by: Fabio Utzig <utzig@apache.org>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-09-11 11:37:43 -04:00
Jukka Rissanen 61abc49c45 net: conn: Print received IPv4 or IPv6 data size
Useful in debugging to match packets seen in wireshark.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-10 10:03:58 -04:00
Jukka Rissanen ce41d5f432 net: tcp: Set the TCP context properly when accepting
When new connection is accepted, the TCP context variables like
sequence number etc. were not properly set.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-10 10:03:58 -04:00
John Andersen b81b26d8c7 net: Added Ipv4 missing debugging
For IPv6 check_ip_addr in subsys/net/ip/net_core.c makes a
NET_DBG call to report when a net_pkt is missing a destination
address. An analogous NET_DBG call has been added to the IPv4
destination address checking.

Signed-off-by: John Andersen <john.s.andersen@intel.com>
2017-09-08 14:32:35 +03:00
Tomasz Bursztyka cd35742a2b net/ethernet/arp: Let ethernet L2 managing pkt's reference while sending
prepare_arp() was unreferencing original pkt (called pending there) in
case of error.

net_prepare_arp() was always unreferencing pkt, though it could have
been already unreferenced by prepare_arp() as seen previously which is
an extra bogus unref in this case.

And in case it returned NULL, ethernet_send() would return NET_DROP
which in turn would make net_if's tx code to unref again the pkt.

This patch ensures pkt is unrefed only once and at the right place.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-09-08 10:59:11 +03:00
Jukka Rissanen 7e3d30880b net: shell: Fix TCP state printing
The TCP state string is only printed if CONFIG_NET_DEBUG_TCP is
defined. If that is not the case, then the "net conn" command
should not print the "State" column name as the state will not
be printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-08 10:58:25 +03:00
Vinayak Kariappa Chettimada 29e9d14420 Bluetooth: controller: Add checks to detect radio ISR latency
Added missing asserts to catch high CPU use in radio ISR and
latencies, without which if radio packet pointer is not set
correctly, would cause spurious transmissions and invalid
behavior.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 934d512223 Bluetooth: controller: Optimize the loop in nRF5 hal rand get()
Optimised the get() function in nRF5 hal rand implementation
to reduce number of probable branching operations.

This is needed to reduce nRF51 platform's CPU use in radio
ISR when using the fast encryption setup implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 5164d4b189 Bluetooth: controller: Move RSSI sampling after pkt processing
Move the code to acquire the RSSI sample after critical
control path that processes PDUs.

This is needed to reduce the time taken to assign the next
packet ptr inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 2cc2be707a Bluetooth: controller: Inline the packet_rx_reserve_get() func
Simplify and inline the packet_rx_reserve_get() functions
used inside radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada ed3aa170f3 Bluetooth: controller: Remove redundant use of auto variable
Removed use of a redundant auto variable that was assigned
and referenced only once.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 09368217d4 Bluetooth: controller: Fast enc setup with ccflags -Ofast
To meet CPU time usage restricts inside radio ISR on nRF51
SoCs, use ccflags -Ofast when using fast encryption setup
implementation in the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Vinayak Kariappa Chettimada 9182de5f0b Bluetooth: controller: Disable DLE and PHY upd proc for nRF51
Default to n the support for Data Length Update and
PHY update procedures on nRF51 SoCs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 14:36:30 -05:00
Steve Brown dfebd40ce1 Bluetooth: Mesh: Avoid spurious "No matching AppKey" warning
Signed-off-by: Steve Brown <sbrown@cortland.com>
2017-09-07 14:26:45 -05:00
Vinayak Kariappa Chettimada f43e4e0637 Bluetooth: controller: Fix assert on peer unknown rsp
Fixed an assert when peer responded with unknown rsp to
slave feature request when an existing another control
procedure was in progress.

This assert happened with a BT v4.0 peer implementation that
was performing a channel map update and local controller
initiated a slave feature request, receiving an unknown
response.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-07 05:51:46 -05:00
Łukasz Rymanowski d3862d7b39 Bluetooth: mesh: Clear link TX when ACK arrived on it
Without this fix there is an issue when doing PB-ADV provisioning
with PTS. We keep retransmitting Public Key which is ACKed by PTS and
this leads to transaction timeout as PTS does not send confirm probably
because it keep receiving PK from us.

This patch also makes sure that transaction id is between 0x80 - 0xFF

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Łukasz Rymanowski dbb90a1a99 Bluetooth: mesh: Fix failed provisioning response
Needed for following PTS test cases:

MESH/NODE/PROV/UPD/BV-10-C
MESH/NODE/PROV/BI-02-C

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Vinayak Kariappa Chettimada 4f87ad2ec1 Bluetooth: controller: Fix a bug in ctrl and data management
Fix the control and data packet management implementation
discovered during conformance testing.

This fixes:
TP/SEC/MAS/BV-12 [Master Start Encryption: Overlapping
Procedure]
TP/SEC/MAS/BV-13 [Master Start Encryption: Overlapping
Procedure with LL_SLAVE_FEATURES_REQ]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-05 09:16:19 -05:00
Carles Cufi 93ca60b733 Bluetooth: controller: Require nRF52 for privacy
Privacy on nRF51 is not passing the conformance and qualification tests
due to the time it takes to execute the privacy code while in ISR. Until
we come up with a way of optimizing and/or deferring the work, do not
allow privacy on nRF51 targets.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-05 07:55:05 -04:00
Carles Cufi 3df18ff277 Bluetooth: controller: Fix Read Version Info VS cmd
Use the macros generated during the build and located in version.h to
fill in the version information in the Read Version Information VS
command. Additionally reply with the correct hardware identifiers when
running on Nordic hardware.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 14:46:13 -04:00
Carles Cufi 80e0f7939e Bluetooth: controller: Add DTM HCI commands
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Vinayak Kariappa Chettimada 37c7551120 Bluetooth: controller: Add Direct Test Mode support
Added controller implementation to support Direct Test Mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-04 06:08:09 -04:00
Carles Cufi b276eeabc7 Bluetooth: controller: Fix Coverity unreachable code
CID: 175182

Use #else to avoid Coverity warning about unreachable code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-04 06:06:29 -04:00
Vinayak Kariappa Chettimada 4225b7985e Bluetooth: controller: Fix pointless expression
Seems due to incorrect rebase in commit 07270e52ba
("Bluetooth: controller: Coding style and refactoring"),
commit 95d55a2bfc ("Bluetooth: controller: Do not skip
one-shot tickers with slot"), and
commit 4ba2bb0d1c ("Bluetooth: controller: Be fair when
pre-empting a ticker"), a pointless expression was
introduced, fixed it.

Coverity-CID: 171563

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-09-02 04:53:30 -04:00
Jukka Rissanen 025cf55e55 Revert "net: tcp: Queue FIN instead of sending it immediately"
This reverts commit 817245c564.

In certain cases the peer seems to discard the FIN packet we are
sending, which means that the TCP stream is not closed properly.
This needs more work so revert this for time being.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-02 04:52:34 -04:00
Łukasz Rymanowski c90e09aa88 Bluetooth: mesh: Fix for key size
For input method we should use input_size instead of output_size

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-01 09:31:41 -04:00
Paul Sokolovsky 958ff51da8 net: sock: zsock_close: Explicitly cast few calls to (void).
To make Coverity happy.

Coverity-CID: 173646
Jira: ZEP-2465

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-09-01 09:31:19 -04:00
Johan Hedberg f7654a787e Bluetooth: Mesh: Fix setting the right value for Static OOB type
The code was setting the wrong bit of the Static OOB Type when a
static value has been provided.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-01 09:30:54 -04:00
Paul Sokolovsky eb5d6fcef5 net: sockets: Be sure to initialize socket's queue on accept
When new socket context is created on accepting connection to a
listening socket, its recv_q FIFO should be initialized. Without
initialization, this worked by a chance when FIFO structure was
simple, but recent change to add dlist to it (which now needs
proper initialization) exposed this issue.

Jira: ZEP-2576

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-31 15:07:33 -04:00
Jukka Rissanen bd425e6857 net: dns: Do not resolve numeric IP address
If the query name is already in numeric format, there is no
need to send the query string to DNS server as we can just
convert it ourselves.

Jira: ZEP-2562

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-31 14:33:59 -04:00
Jukka Rissanen a71164ed50 net: dns: Use IP address parsing function in init
This commit removes IP address parsing from DNS init and
replaces it by call to net_ipaddr_parse().

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-31 14:33:59 -04:00
Jukka Rissanen 532cbacc27 net: Add function to parse IP address string
The net_ipaddr_parse() will take a string with optional port
number and convert its information into struct sockaddr.
The format of the IP string can be:
     192.0.2.1:80
     192.0.2.42
     [2001:db8::1]:8080
     [2001:db8::2]
     2001:db::42

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-31 14:33:59 -04:00
Vinayak Kariappa Chettimada 38b148023e Bluetooth: controller: Fix assert on connection establishment
Fixes an assert during connection establishment when the
initiator overflows the initiator window in time while
sending the CONNECT_IND PDU. The actual window is one low
frequency tick less, hence corrected the check that permits
the transmission of CONNECT_IND PDU inside the initiator
window.

Symptom was, stopping of the scanner's ticker succeeds on
connection establishment, but next interval prepare was
already run when continuous scanning was used, breaking the
design, hence there was an assert.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-31 14:31:55 -04:00
David B. Kinder 97033049e1 doc: fix Kconfig misspellings
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-31 14:22:11 -04:00
Jukka Rissanen 817245c564 net: tcp: Queue FIN instead of sending it immediately
If network context is closed, send FIN by placing it to the end
of send queue instead of sending it immediately. This way all
pending data is sent before the connection is closed.

Jira: ZEP-1853

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-31 11:58:24 -04:00
Carles Cufi 2874841576 Bluetooth: Controller: Add Read Key Hier. Roots VS cmd
Implement the Zephyr Read Key Hierarchy Roots command, returning the IR
and ER present in nRF5x ICs when compiling for those.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Carles Cufi b7a5fab4cf Bluetooth: controller: Add Read Static Addresses VS command
Implement the first Vendor-Specific Command of the Zephyr specification
other than the 3 mandatory ones already present in the codebase, along
with a Kconfig option to enable and disable the presence of the VS
commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-30 08:18:42 -04:00
Jukka Rissanen 098483d6dd net: app: Allow TLS and DTLS to be enabled separately
TLS and DTLS are not related to each other so allow DTLS to be
enabled even if TLS is disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen adb1df7f8f net: shell: Do not crash if DTLS is disabled in net app command
The "net app" command was accessing NULL pointer if TLS and UDP were
enabled but DTLS was not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 75de00225f net: tcp: Print more info if net_pkt was not sent
Useful in debugging if we get information why the TCP packet was
not sent.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen dcfbc00c51 net: ipv6: Fix fragmented IPv6 packet sending
Earlier we modified the original pkt chain when creating IPv6
fragments. This is not a proper way as the original chain might
still be used in TCP when re-sending a message. So when fragmenting
the packet, clone it first and leave original packet intact. This
occupies litle more memory but is now safe.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 4cbb4134a0 net: context: Do not call send callback if context is not set
This is unlikely but needed if context inside net_pkt is not set.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 5b29631623 net: tcp: Recover a situation if the first net_buf is too short
This is very unlikely to happen but the device will access null
pointer if we do not properly check the return value of header
check function.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 0abf5ccda9 net: pkt: Print info if IP header is too short
When trying to figure out where ICMP / TCP / UDP header is located
in net_buf, print more information about what we were doing if the
header cannot fit the first fragment. This is much needed infomation
in debugging weird issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen d2efe6027c net: tcp: Use packet clone function to copy the frags
Using memcpy() to copy net_pkt is not safe because there are
pointers inside. So use the new net_pkt_clone() to do that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 82119b1dbe net: pkt: Add function to clone net_pkt fragment chain
This is needed when one wants to copy the whole fragment chain
and its head pointer net_pkt.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Jukka Rissanen 4fea5b18ab net: app: Add IP header to packets received by TLS/DTLS tunnel
The IP header was stripped by _net_app_ssl_mux() when it received
IP packet. This is fine but if the application expects the get
the IP header, then there is a problem. Fix this by saving IP
header to ssl_context and then putting it back in front of the
packet when the data is passed to application.
Note that this IP header is not used by net_app when the packet
is sent because TLS/DTLS creates a tunnel for transferring packets
and user can only sent packets via this tunnel.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-30 08:12:10 -04:00
Luiz Augusto von Dentz 9147b53d76 net: Remove check for k_delayed_work_cancel
k_delayed_work_cancel now only fail if it hasn't been submitted which
means it is not in use anyway so it safe to reset its data regardless
of its return.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 15:34:40 -04:00
Carles Cufi 7924d16aef Bluetooth: controller: Fix broken switch statement
Add a missing break that was forgotten when we introduced the Read TX
Power command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 16:25:11 +02:00
Luiz Augusto von Dentz 7d01c5ecb7 poll: Enable multiple threads to use k_poll in the same object
This is necessary in order for k_queue_get to work properly since that
is used with buffer pools which might be used by multiple threads asking
for buffers.

Jira: ZEP-2553

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 09:00:46 -04:00
Vinayak Chettimada 2b2eb9bb07 Bluetooth: controller: Refactor Conn Param Req implementation
Refactor the Connection Parameter Request Procedure to be
separate from and not overlap the variables of the
Connection Update Procedure.

Also, added missing implementations to pass all Connection
Parameter Request Procedure related Conformance Tests.

Jira: ZEP-1918

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-25 12:51:01 +02:00
Carles Cufi f597c8120e Bluetooth: controller: Add LE Read Chan Map command
Implement the LE Read Channel Map HCI command, along with making the
reading of the multi-byte channel map value from the connection pointer
thread-safe in case the ISR triggers while we are reading the value.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi a5fcafa155 Bluetooth: controller: Add Read TX Power commands
Although the current BLE controller only supports a single TX power (0
dBm), the qualification tests require the 2 Read TX Power to be
present and supported in the controller, so implement them while
returning always 0 dBm.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi 7bfa0ef47b Bluetooth: controller: Implement Read RSSI command
When the CONFIG_BT_CTLR_CONN_RSSI option is set, the connection RSSI is
available in the controller, and can be reported to the Host via the
Read RSSI command. Implement the command, which is required for
qualification.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Michael Scott caa377943a net: http: fix avoiding timeout on HTTP requests w/o body
The original commit 8ebaf29927 ("net: http: dont timeout
on HTTP requests w/o body") was intended to handle a case
where an HTTP response had been retrieved from the server but
the HTTP parser couldn't meet the criteria for calling
"on_message_complete".  For example, a POST to a REST API
where the server doesn't return anything but an HTTP
status code.

It was a really bad idea to check a semaphore count.  There
is a lot of kernel logic built into semaphores and how the
count is adjusted.  The assumption that the value is 0
after the k_sem_give() is incorrect.  It's STILL 0 if
something is pending with a k_sem_take().  By the time
k_sem_give() is done executing the other thread has now
been kicked and the count is back to 0.

This caused the original check to always pass and in turn
breakage was noticed in the http_client sample.

Let's do this the right way by setting a flag when
on_message_complete is called and if that flag is not set
by the time we reach recv_cb, let's give back the semaphore
to avoid a timeout.

Jira: ZEP-2561

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-23 16:42:03 -04:00
Jukka Rissanen 3dfa1cef0a net: http: HTTP header field state was not reset
The HTTP header field pointers are saved for each HTTP request.
But the counter that saves the pointers was never reset to initial
value when the connection was dropped. This meant that the header
field values were only proper for first HTTP request.

Jira: ZEP-2463

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 16:38:05 -04:00
Jukka Rissanen c200de1b53 net: app: Introduce missing enable/disable functions for server
The server needs global enable/disable status instead of only being
able to enable or disable just the TLS server part.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 13:33:33 -04:00
Jukka Rissanen 6c278fae5b net: app: Use port when init server with both IPv4 and IPv6
If we have specified AF_UNSPEC when initializing application
server local address, then we try to bind to both IPv4 and IPv6
addresses. The old code did not honor the port number in this
case but used some random value for port.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 13:33:33 -04:00
Jukka Rissanen e56a6e7baa net: app: Do not bind IPv4 if user wants IPv6 only
If user has specified a specific local address, then honor that
and do not try to bind IPv4 context if only IPv6 is defined,
and vice versa for IPv6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 13:33:33 -04:00
Leandro Pereira 4e439653aa net: connection: Zero out connection struct when unregistering
Zeroing-out all bytes from a connection structure when it's
unregistered ensures all state from a previous connection is gone and
can't be mistakenly reused.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-08-22 09:53:19 -04:00
Leandro Pereira 86e0cce541 net: Fix out-of-bounds access when registering connections
If either a remote or a local address were supplied to the
net_conn_register() function, the IP stack would proceed to copy
sizeof(struct sockaddr) bytes from the respective remote_addr
or local_addr pointers, regardless of the actual size of the storage
these pointers point to.

Use the proper size depending on the socket address family.

Coverity-ID: 173630
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-08-22 09:53:19 -04:00
Carles Cufi 94bab6ca8c Bluetooth: controller: Fix Read Peer RPA Command
There are 2 possible interpretations regarding the address to return in
response to the Read Peer RPA HCI Command:

1) The RPA that the local controller generates to be used in certain
packets it sends
2) The RPA generated and used by the peer device in its packets

We used to return 1) but our interpretation turned out to be incorrect
when reading the HCI test specification, so this commit switches to
returning 2).

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-22 15:22:25 +02:00
Paul Sokolovsky e4957813eb net: shell: Fix build when NET_DEBUG_APP defined, but client/server not
If CONFIG_NET_DEBUG_APP was defined, but neither NET_APP_SERVER nor
NET_APP_CLIENT, build failed due to net_app_cb() haven't beeen
defined. So, define it to empty in this case.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-22 08:22:20 -04:00
Paul Sokolovsky bdb233fba5 net: app: init: Bail out early if no network interface available
This is a known cause of crash on startup.

Jira: ZEP-2105

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-22 08:21:14 -04:00
Carles Cufi 523a9dfe8a Bluetooth: controller: Fix RL index check
In the ll_rl_pdu_adv_update() function, the check to verify if we are
dealing with an item from the resolving list or else with a simple
standard non-privacy enabled device was left over from the previous
iteration, which used negative values. Replace that check with the
proper current one, using the size of the rl array as an indicator of
whether the index is valid.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 18:49:59 +02:00
Vinayak Kariappa Chettimada dd52b8ea02 Bluetooth: controller: Fix first connection interval timing
Due to varying remainder value, first interval will need to
consider the remainder value used in microsecond timing from
the start of the initiator window.

Also the tx chain delay and ready delay must be substract
after the window offset is calculated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 17:37:43 +02:00
Carles Cufi 558be2e02c Bluetooth: controller: Enable Read Remote Ver Info bit
The Read Remote Version Information command is supported on the BLE
controller, enable the bit in Read Local Supported Commands to reflect
this.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 08:42:24 -04:00
Vinayak Kariappa Chettimada 6a39ed084f Bluetooth: controller: Add Minimum Number of Used Channels Proc
Add implementation to support Bluetooth 5.0 Minimum Number
of Used Channels Procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 08:41:56 -04:00
Paul Sokolovsky 8ca4cd8405 net: app: Allow to set static IPv4 netmask and gateway
Setting just IPv4 address as was allowed before isn't enough for
real-world usage (e.g. accessing DNS and outside servers in general).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-21 08:39:02 -04:00
Michael Scott 8662b69685 net: lwm2m: return BAD_REQUEST when object create fails
Per LwM2M spec (7.3.2.4 Operation on Object):
"If the payload (New Value) conveys an Object Instance ID in conflict
with one already present in the LwM2M Client, the complete request
MUST be rejected and a "Bad Request" error code MUST be sent back."

Let's do that.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04:00
Robert Chou d42af5914e net: lwm2m: ignore optional resource when not implmeneted
Per LwM2M specification 7.3.2.4, "Optional Resources MAY be conveyed
in the "New Value" parameter as well; the LwM2M Client MAY ignore the
optional resources it doesn't support."

Update TLV/JSON writer to ignore error when object fields are not
found (treated as optional resource). This will allow the resources
supported being written.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
[michael.scott@linaro.org: re-worked patch post addition of CREATE
operation.]
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04:00
Michael Scott 22b11ba8fe net: lwm2m: define a CREATE operation
Prior to this patch, a CREATE operation was handled as a WRITE operation
after the object instance was created.  This becomes problematic when
handling of optional resources differs between these 2 operations.

Let's introduce an actual CREATE operation and use it later to create
these differences.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04:00
Michael Scott 75016c7b97 net: lwm2m: fix resource not found error code in format writers
We are returning EINVAL from content format write ops when an object
field definition is not found (an optional field which is not
implemented).  Instead, return ENOENT which lets the LwM2M engine
know to send ZOAP_RESPONSE_CODE_NOT_FOUND to the LwM2M server at the
end of handle_request().

NOTE: This behavior is not correct when we call the writer right after
a CREATE operation where the data is assigned to resources for the
first time.  This case will be handled in a follow-up patch once we're
able to distinguish between a WRITE and a CREATE in the write op
handler.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-21 08:38:17 -04:00
Paul Sokolovsky dcb80f7ab8 net: struct sockaddr should have field "sa_family"
POSIX requires struct sockaddr's field to be named "sa_family"
(not just "family"):
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

This change allows to port POSIX apps easier (including writing
portable apps using BSD Sockets compatible API).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Vinayak Kariappa Chettimada cb90fbe56a Bluetooth: controller: Fix controller assert at clock rollover
Fix controller assert due to a bug introduced in commit
07270e52ba ("Bluetooth: controller: Coding style and
refactoring").

This reverts implementation to original way it was and the
calculation of the ticker expiry will now not overflow the
range of the RTC peripheral, which is a 24 bit counter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-18 15:34:19 +02:00
Ricardo Salveti 2175f78385 net: lwm2m: add IPSO light control object
As defined by IPSO-Smart-Objects "Section: 16. IPSO Object: Light
Control".

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-18 10:53:25 +03:00
Ricardo Salveti d540b405de net: 6lo: always check for net_pkt_get_frag returned frag
net_pkt_get_reserve_data ignores the timeout parameter when in isr,
using K_NO_WAIT instead, which can lead to invalid fragment.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-18 09:37:39 +03:00
Robert Chou c1500fe9a4 net: lwm2m: report resource type / content type at registration
Per LwM2M specification 5.3.1 Register, report "ct=11543" when JSON is
supported. Also, report the resource type as rt="oma.lwm2m" when "ct="
presents.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
Robert Chou a64dcbb7bf net: lwm2m: do not report object when object instances available
Per LwM2M specification 5.3.1 Register. When object instances are
available, object ID can be ignored in registration message

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
Robert Chou c21372eeb8 net: lwm2m: do not expose security object
According to LwM2M specification 5.2.7.3 Bootstrap DISOCVER,
security object is only reported to the bootstrap server.

Correct the behavior to (1) report server object to the server
(2) do not report security object at registration time

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-17 21:52:24 +03:00
Ricardo Salveti 60a908c9c9 Bluetooth: Kconfig: fix default value and range for BT_RX_STACK_SIZE
Fix checks for BT_HCI_RAW and move default range after the other range
options, required by Kconfig to avoid overwriting other options.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-17 21:11:50 +03:00
Paul Sokolovsky d9af77bfd6 net: sockets: Consistently use "BSD Sockets compatible API" moniker
This is how it's called in the main docs, so use this same phrase in
Kconfig and samples too.

Also, added some articles to docs.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-17 12:02:55 -05:00
Andrzej Kaczmarek dedb70d864 Bluetooth: Fix formatting string for storage directory name
Precision specifier is not supported by printk(), let's use
zero padding instead.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-08-17 11:16:03 +03:00
Carles Cufi e0194750cf Bluetooth: controller: Fix RSSI sign
The RSSI value is an 8-bit signed integer. Since the Link Layer works
only with positive unsigned integers, translate into a negative number
at the HCI layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 10:02:07 +02:00
David B. Kinder 81f7c82625 doc: fix misspellings and missing EOF newlines
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-16 17:38:41 -05:00
Jukka Rissanen f673a701f9 net: pkt: Add CONFIG_NET_DEBUG_NET_PKT_ALL option
This option enables full debugging output for memory allocations.
As that can produce lot of output and slow down the device under test,
it is disabled by default.
The previous CONFIG_NET_DEBUG_NET_PKT will collect information about
memory allocations but will not print any output. Use "net mem" or
"net allocs" commands in net-shell to see the memory allocation status.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 6a496f87cf net: shell: Fix column alignment in net mem command
Because the name of the memory pool can be quite long, print
it last so that the columns get aligned nicely.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen b57e83514f net: shell: Print more TCP pending packet information
Print current list of pending packets if TCP debugging is
enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 0a978ea5ef net: tcp: Send data only in established state
If we are not in ESTABLISHED state, then there is no need to
try to resend any pending data packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen e08716001a net: tcp: Do not re-send already sent packets
If the expire send timer expires, then it sends the packet.
If that happens, then we must not try to send the same packet
again if we receive ACK etc. which can cause re-sends to happen.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 0674e03790 net: tcp: Remove unused variable
There was two pkt variables in net_tcp_ack_received() so removing
the extra one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen cdec73d21e net: tcp: Only do ref when resending if we could send the packet
If the packet sending is slow then we must NOT increment the ref
count when re-sending it. This is unlikely but can happen if there
are lot of debug prints etc. extra activities that prevent the driver
to actually send the packet fast enough.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen f8ea1a59ea net: tcp: Add more debugging to TCP code
Useful when investigating issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 5325c4b594 net: tcp: Set the TCP sent flag after really sending pkt
Make sure that the sent flag is only set after we have really
sent the packet and the driver has verified that.
If the net_pkt_set_sent() is called while still in tcp.c, then
depending on how fast the device is, it might happen that the
retry timer expires before the packet is actually sent. This was
seen in frdm-k64f with ethernet and various debug prints activated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 3fe4877123 net: tcp: Cleanup TCP backlog when releasing context
If there is a backlog entry when TCP context is released, then
cancel the ACK timer if one exists.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Jukka Rissanen 12017ce761 net: http: Yield after sending response in server
Make sure that a network packet is sent after calling
http_response_send_data(). Othwerwise the packets might be
piling up and not sent in timely manner.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Andrew Boie 951ce4d00e net_context: work around missing errno codes
Some older C libraries do not have errno for EPFNOSUPPORT.
Fixes issues with newlib in some versions of Xtensa XCC compiler.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-16 10:59:10 -07:00
Andrew Boie e165f591ce net: rpl: fix inline function declaration
The initial function prototype did not have 'inline' in it,
resulting in a compiler warning with XCC.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-16 10:59:10 -07:00
Andrew Boie 833ca35954 net: tcp.h: fix some function declarations
It's never a good idea to redefine functions as macros if intended
to be unused in some configuration

- "statement with no effect" warnings
- "unused argument" warnings
- No type checking done if the macros are used

These have been redefined as empty inline functions.
Fixes compiler warnings with XCC.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-16 10:59:10 -07:00
Andrew Boie 2e32e815ba net: fix net_tcp_state_str() declaration
The second 'const' is misguided, indicating that the returns pointer
value itself cannot be changed, but since pointers are passed by value
anyway this is not useful and was generating warnings with XCC.

The leading 'const' indicates that the memory pointed to is constant,
which is all we needed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-16 10:59:10 -07:00
Andrew Boie d4f116ffde tcp.h: fix definition of tcp_init_isn()
Inline functions declared in header files need to be declared
static. Fixes a compiler warning with XCC compiler.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-16 10:59:10 -07:00
Paul Sokolovsky cf43be1a2e Bluetooth: Increase CONFIG_BT_HCI_TX_STACK_SIZE for BT_SPI
Older value of 256 was introduced in 1.7 times. Testing on
BOARD=96b_carbon with 2 weeks old codebase however showed that TX
thread stack however can grow to 324 bytes. Finally, with the
latest master, following stacks are reported on BLE disconnect
(with CONFIG_INIT_STACKS enabled):

rx stack (real size 1024): unused 452 usage 572 / 1024 (55 %)
tx stack (real size 384):  unused 16  usage 368 / 384 (95 %)

Two outcomes:

1. TX stack needs increase.
2. Over time, the stack usage grows, plus variations in SPI
drivers should also be taken into account.

So, increase the stack size to 416 bytes, to leave some headroom
beyond the immediate values seen on 96b_carbon.

Jira: ZEP-2510

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-16 14:54:20 +03:00
Michael Scott fe84d4f7dd net: http: allow HTTP_NETWORK_TIMEOUT to be configured
Currently, the HTTP_NETWORK_TIMEOUT setting is hard-coded as 20 seconds.
Not every application may want to wait that long, so let's change this
to a CONFIG option: CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT

NOTE: This also removes HTTP_NETWORK_TIMEOUT from the public http.h
include file.  It was not being used externally to HTTP client sources.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-16 12:35:33 +03:00
Ricardo Salveti 8dbb388000 samples: Bluetooth: add HCI SPI raw handler sample
Add a sample application that allows a Zephyr-based Bluetooth
controller to interface with an HCI driver via SPI. This sample
implements the same BT SPI protocol already as Zephyr's HCI SPI
driver.

Currently, the sample only supports the legacy SPI API.

Provide a single configuration file, avoiding board-specific
files. Some board-specific configuration information must be provided
via other means:

- CONFIG_BT_CONTROLLER_TO_HOST_SPI_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_PIN

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-15 22:58:02 +03:00
Marti Bolivar 4e53f4e830 Bluetooth: Kconfig: delete stray double quote
Trivial fix.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Carles Cufi fc965e5554 Bluetooth: controller: Split Ext Scan Filter Policies out
Since Extended Scanner Filter Policies is an independent feature from
Controller-based Privacy, split it out so it can be built independently
and included without it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-15 22:55:15 +03:00
Michael Scott 8ebaf29927 net: http: dont timeout on HTTP requests w/o body
A TCP FIN message is passed on to user apps as a tcp_received_callback
with a NULL pkt parameter.  This means the connection is closing and
the app should do whatever cleanup it needs as there will be no further
callbacks for the current TCP connection.

Currently, if a HTTP client request doesn't receive a "body" which
the HTTP parser can use to trigger on_message_complete, then the request
will end up timing out and most apps will think an error has occurred.

Instead, let's handle the TCP FIN message and return the waiting
semaphore, leaving the app to deal with whatever has been set in the
current HTTP context response data (IE: http_status).

This fixes using HTTP client to send POST data to servers which
only respond with HTTP_OK status and no body.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-15 22:21:15 +03:00
Paul Sokolovsky 0592c0ce59 Bluetooth: shell: gatt_read: Reset offset to 0
Unless offset was specified, it should default to 0, whereas
previously, value from the last command was used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-15 21:16:40 +03:00
Paul Sokolovsky f9caab42cc net: sockets: Move under "Network Application Support" heading
"Network Application Support" itself is renamed from "Network
Applications" and also includes net_app API.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-15 09:20:27 -04:00
Anas Nashif cf9613deec kconfig: build code conditionally when possible
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-14 20:32:26 -04:00
Paul Sokolovsky c1a5573c85 net: sockets: Check return value of k_poll()
Mostly to make Coverity happy.

Coverity-CID: 173641

Jira: ZEP-2465

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-14 23:46:44 +03:00
Carles Cufi 03a75e17dd Bluetooth: controller: Enable Extended Scan Filter Policies bit
Whenever privacy is enabled, we support the Extended Scan Filter
Policies functionality, and therefore we must show it in the bitfield of
LE supported features for the controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 21:06:51 +02:00
Carles Cufi d5c13a7530 Bluetooth: controller: Rename Kconfig prefix
Rename the BT_CONTROLLER prefix used in all of the Kconfig variables
related to the Bluetooth controller to BT_CTLR.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 15:44:56 +03:00
Johan Hedberg 01df52c2b7 Bluetooth: Use higher RX_BUF_LEN when Mesh Proxy protocol is used
Avoiding segmentation in the GATT-based Mesh Proxy protocol requires
having an RX buffer length of at least 77. We could round it up to 80
since there's otherwise wasted space, however there's also
BT_HCI_RESERVE to consider, so to avoid pushing over the 4-byte
boundary for certain HCI drivers just leave the size at 77.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-14 13:01:39 +03:00
Jukka Rissanen d8e13c0c45 net: tcp: Make do_ref_if_needed() a macro
This is needed in order to get information which function is
doing the ref. With inline function this was not possible.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen ff5e46a32f net: pkt: Fix the log domain
Instead of printing [net/net_pkt], print [net/pkt] if debug log
is enabled for network packet allocator. The double net in earlier
print is redundant information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen f0012de4a1 net: rpl: Allow fine tuning of parent count
Instead of always have CONFIG_NET_IPV6_MAX_NEIGHBORS parents,
use CONFIG_NET_RPL_MAX_PARENTS when creating the parent table.
Default value for max parents is the max neighbors so no
functionality changes are introduced here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen 1aa8be3454 net: nbr: Use the real size of the neighbor pool
Instead of always having CONFIG_NET_IPV6_MAX_NEIGHBORS number
of items in neighbor pool, store the neighbor count in the pool
and use that value when traversing the neighbor table.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen 20b35adf51 net: rpl: Add Kconfig option for specifying used IPv6 prefix
This is only usable in the root node.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen 4f7f16ada6 net: rpl: Add default interface type setting to Kconfig.rpl
Allow user to define what kind of network the RPL should serve.
Currently options will be either ANY or IEEE802154. If there
is only one network interface in the system, then ANY will take
the default network interface and use that. If there are multiple
network interfaces, then one should not use ANY as the default
network interface might not be the expected one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen a10bbdbd43 net: rpl: Add more debug prints when sending messages
Print network interface where the DIO, DIS or DAO was sent. This is
useful if we have multiple network interfaces in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen 597eef6c80 net: shell: Fix RPL parent list output print
The parent output strings were incorrectly aligned.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen ab55b35bac net: shell: Print network interface type
When printing network interface specific data, print also
the type of the network interface (ethernet, bluetooth etc).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen f125672c9a net: app: Do not try to set ANY address to interface
If the user has not specified CONFIG_NET_APP_MY_IPV4_ADDR or
CONFIG_NET_APP_MY_IPV6_ADDR, the value is set to "" in this case.
This will be converted to ANY IP address which is not useful
to be set to the network interface. So check this and just
continue the init in this case without setting the IP address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
Jukka Rissanen 7886336593 net: app: Fix for net_app_get_net_buf()
The documentation says that the API will automatically append the
net_buf fragment to the end of network packet fragment chain.
This was not the case and current only user for this API in
echo-server sample appended the fragment itself. The fix is to
automatically append the fragment to the end of fragment chain.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 10:04:03 +03:00
Robert Chou 37e21a4152 net: lwm2m: fix registration content format and use plain/text
1. According to the specification 5.3.1, it's a MUST to specify
   (1) content format: app link format (2) supported lwm2m version.
   Also, we should use text/plain instead of LWM2M's (obsolete).
2. Use LWM2M_FORMAT_OMA_TLV as default accept format when accept option
   is not given from the caller for TLV is a MUST have in LwM2M spec and
   it can deals w/ multiple resources read

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-13 20:52:56 +03:00
Robert Chou 87ce5f1935 net: lwm2m: save accept format in observe_node_data
Save in observe_node_data so that later on we can select the correct
content format requested by the caller at the first time

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-11 09:53:47 +03:00
Robert Chou 84106f3cb3 net: lwm2m: fix erroneous TLV write
Function do_write_op_tlv() uses in->inbuf and in->insize as a looping
condition to iterate through items in TLV payload and call
do_write_op_tlv_item() to update the value.

However, do_write_op_tlv_item() will override the value before calling
for fitting the usage of lwm2m_write_handler() function without restore
them. (lwm2m_write_handler() is also called by plain text/json writer
and is expecting in->inbuf is the start of buffer and in->insize as the
length of the buffer)

This will result in errors in do_write_op_tlv().

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-11 09:49:45 +03:00
Michael Scott f18674a320 net: http: fix http client request "Host" header
RFC-7230 "HTTP/1.1 Message Syntax and Routing" Section 5.4
describes the "Host" header formatting.  If Zephyr user
specifies a host string as a part of the HTTP client request
structure, we end up sending an incorrect HTTP header due
to a missing "Host :" text.

Fix this by prepending "Host: " to the header data before
the user supplied host string.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-11 09:45:02 +03:00
Aska Wu eb8fd4aacf net: sockets: inet_pton() should return 1 on success
Add zsock_inet_pton() to convert the return value of net_addr_pton()
which returns 0 on success.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-10 17:41:47 +03:00
Anas Nashif a5661c3690 debug: openocd: build openocd symbols using obj-
openocd object was put in a library causing it to be stripped. We want
those symbols in the final ELF to allow debugging with openocd, building
those as objects like the rest of the kernel keeps the symbols in the
kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-10 09:13:06 -05:00
Ricardo Salveti cc3290afc8 net: lwm2m: build sprint_token only when debug is enabled
sprint_token is only used by SYS_LOG_DBG, so only build it when
CONFIG_SYS_LOG_LWM2M_LEVEL > 3.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 3896930be6 net: lwm2m: engine: add flag for separate response
Separate response can happen when handling block transfer for firmware
updates, and to avoid duplicating the lwm2m_udp_receive function, create
and additional flag to allow handling CoAP separate response messages.
This is required to avoid removing the reply callback, since a new
message (with a valid token) will be received later from the server.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 36fe07802a net: lwm2m: create common wrapper for net_context_sendto
Simplifly net_context_sendto calls and also allows to easily debug every
send/receive lwm2m call.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 2c759d180d net: lwm2m: engine: fix typo
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 17b33d3a58 net: lwm2m: rd_client: handle forbidden errors
Stop both bootstrap and registration process if they return forbidden.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Ricardo Salveti 61961cf737 net: lwm2m: firmware: add Kconfig option for CoAP block size
CoAP block size might be adjusted for a faster firmware download
process.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-10 12:42:40 +03:00
Carles Cufi 868aeeb126 Bluetooth: controller: LE Directed Advertising Report
Implement the 4.2 event LE Directed Advertising Report, used for
scanners in a privacy-enabled controller to report directed advertising
events whose TargetA cannot be resolved by the local controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-10 12:33:36 +03:00
Vinayak Kariappa Chettimada 882bdd57b4 Bluetooth: controller: Add packet transmit time restrictions
Add implementation to support PHY update procedure with
packet transmit time restrictions.

This fixes:
TP/CON/SLA/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/SLA/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
TP/CON/SLA/BV-52-C [Initiating PHY Update Procedure Packet
Time Restrictions, No Change]
TP/CON/SLA/BV-53-C [Responding to PHY Update Procedure
Packet Time Restrictions, No Change]
TP/CON/MAS/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/MAS/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-10 10:54:28 +03:00
Jukka Rissanen 55b8edc88e net: Fix LLVM compiler warnings
Jira: ZEP-2488
Jira: ZEP-2486
Jira: ZEP-2485
Jira: ZEP-2482
Jira: ZEP-2480

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:50:50 -04:00
Sebastian Bøe 2120beebf4 Kconfig: Move BT_WAIT_NOP into subsys/bluetooth/host
The CONFIG_BT_WAIT_NOP define is used only by
zephyr/subsys/bluetooth/host/hci_core.c.

It is also the only config in drivers/bluetooth that is in use when
BT_CONTROLLER is enabled. Moving it into the bluetooth subsystem
allows us to restructure the drivers/kconfig code such that the entire
Bluetooth driver menu option is omitted when the BT_CONTROLLER is
enabled.

Moving it will also mean that all configs in drivers/bluetooth will
now be related to configuring the source code in drivers/bluetooth.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Robert Chou cd56290dbe net: lwm2m: rename CONFIG_NET_L2_BLUETOOTH to CONFIG_NET_L2_BT
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-08-09 16:03:02 +03:00
Jukka Rissanen b6a5d51baf net: Fix indentation issues
Some earlier search/replace broke indentation.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 16:01:28 +03:00
Jukka Rissanen b57edf042e net: ieee802154: Use proper network interface in shell
If the device has multiple network interface, then we must not
blindly use the default one but get the IEEE 802.15.4 network
interface when setting radio parameters in the shell.

Jira: ZEP-2432

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 14:21:02 +03:00
Jukka Rissanen 77b44a5300 net: shell: Fix neighbor printing for IEEE 802.15.4 networks
The "net nbr" command was printing the heading of neighbor list
incorrectly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen e60b2df376 net: shell: Fix the output of route command
Print route information by groupping them for each network
interface like this:

IPv6 routes for interface 0xa8007140
====================================
IPv6 prefix : 2001:db8::212:4b00:0:3/128
        neighbor  : 0xa80065e0
        link addr : 00:12:4B:00:00:00:00:03
IPv6 prefix : 2001:db8::212:4b00:0:1/128
        neighbor  : 0xa8006660
        link addr : 00:12:4B:00:00:00:00:01

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen 5538f23b17 net: shell: Add command to return RPL information
Add "net rpl" command to net-shell which will return both static
RPL configuration from Kconfig, and dynamic run time configuration
of the nodes and parents.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen d3ed19aaf5 net: rpl: Add helper to return parent information
Create net_rpl_foreach_parent() function that will traverse
through all the parents and return their information via callback.
This is needed by net-shell in later commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen 75c1189ffb net: rpl: Send DAO-ACK if we are the root node
Instead of always forwarding the DAO, send DAO-ACK if we are
the root node.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen dc2ccc5af0 net: rpl: Fix unused variable warnings
If debug level was low but debugging was activated, then some
of the debug variables were left unused.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen 4d87fbc322 net: rpl: Repair root functions are made global
The net_rpl_repair_root() and net_rpl_set_root_with_version()
functions were static which prevented global repair when using
an instance id. Making those functions global allows RPL network
repairing from shell for example.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen a5b4cca94a net: rpl: DAO message was discarded too early
The commit b14586c3ca ("net: rpl: RPL route entry was fetched
too late") dropped the DAO packet too early which prevents the
RPL root node functionality. Rework the earlier commit so that
Coverity issues are fixed but the RPL DAO message is also properly
handled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:25:03 +03:00
Jukka Rissanen f6661512a4 net: if: Add helper to return interface of given type
The helper will return the first network interface of a desired
L2 type.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:24:34 +03:00
Johan Hedberg 2975ca0754 Bluetooth: Kconfig: Rename CONFIG_BLUETOOTH_* to CONFIG_BT_*
The API name space for Bluetooth is bt_* and BT_* so it makes sense to
align the Kconfig name space with this. The additional benefit is that
this also makes the names shorter. It is also in line with what Linux
uses for Bluetooth Kconfig entries.

Some Bluetooth-related Networking Kconfig defines are renamed as well
in order to be consistent, such as NET_L2_BLUETOOTH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 11:14:19 +03:00
Michael Scott ccd4f68da3 net: lwm2m: add SPX Apache-2.0 license tag w/ Linaro copyright
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott aef5ee4582 net: lwm2m: add IPSO support w/ temperature sensor object
IPSO Smart Objects are a set of template objects based on the LwM2M
object framework which are designed to represent standard hardware
such as temperature and humidity sensors or light controls.

Let's add a place for these objects to live as well as an initial
temperature sensor object.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott c46c206f8c net: lwm2m: initial library support for LWM2M
Origin: SICS-IoT / Contiki OS
URL: https://github.com/sics-iot/lwm2m-contiki/tree/lwm2m-standalone-dtls
commit: d07b0bcd77ec7e8b93787669507f3d86cfbea64a
Purpose: Introduction of LwM2M client library.
Maintained-by: Zephyr

Lightweight Machine-to-Machine (LwM2M) is a protocol stack extension
of the Constrained Application Protocol (CoAP) which uses UDP
transmission packets.

This library was based on source worked on by Joakim Eriksson,
Niclas Finne and Joel Hoglund which was adopted by Contiki and then
later revamped to work as a stand-alone library.

A VERY high level summary of the changes made:
- [ALL] sources were re-formatted to Zephyr coding standards
- [engine] The engine portion was re-written due to the heavy reliance
  on ER-CoAP APIs which are not compatible to the Zephyr CoAP APIs as
  well as other Zephyr specific needs.
- [engine] All LWM2M/IPSO object data is now abstracted into resource
  data which stores information like the data type, length, callbacks
  to help with read/write.  The engine modifies this data directly (or
  makes callbacks) instead of all of the logic for this living in each
  object's code. (This wasn't scaling well as I was implementing
  changes).
- [engine] Related to the above change, I also added a generic set of
  getter/setter functions that user applications can call to change
  the object data instead of having to add getter/setting methods in
  each object.
- [engine] The original sources shared the engine's context structure
  quite extensively causing a problem with portability. I broke up the
  context into it's individual parts: LWM2M path data, input data and
  output data and pass only the needed data into each set of APIs.
- [content format read/writer] sources were re-organized into single
  .c/h files per content formatter.
- [content format read/writer] sources were re-written where necessary
  to remove the sharing of the lwm2m engine's context and instead only
  requires the path and input or output data specific to it's
  function.
- [LwM2M objects] re-written using the new engine's abstractions

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott 911efb0e72 net: zoap: use message id for reply matching
In the 08 Feb 2017 V1.0 LwM2M specification page 80 mentions: in
response to a "Notify" operation for which it is not interested in
any more, the LwM2M Server can send a "Reset Message".

Leshan server sends this CoAP RST response and it does not contain
the originating message token (which is also how the packet flow looks
on page 81 of the LwM2M spec).  Using the current ZoAP sources, the
client has no way of matching back to observation which needs to be
cancelled.

Let's add a match for message ID of a reply where there is no token
to handle this case.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
[ricardo.salveti@linaro.org: Handle both piggybackend and separate
response (id doesn't need to match, only token).]
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-09 10:55:53 +03:00
Sebastian Bøe 197e6e2ba3 Kconfig: Move BLUETOOTH_HCI_RESERVE into subsys/bluetooth/host
There are two kinds of HCI implementations. Bluetooth drivers in
 drivers/bluetooth that implement HCI by using a wired serial
 transport layer to talk to an external controller chip. And a
 bluetooth controller in subsys/bluetooth/controller that directly
 talks to an internal on-chip controller node.

Currently, when the the subsys/bluetooth/controller is used there
still exists exposed to the user a bluetooth driver configuration
menu, even though no external bluetooth driver is in use. This is due
to a dependency on certain configs in driver/bluetooth that are needed
even though no external controller is used.

This patch moves one of these configs, BLUETOOTH_HCI_RESERVE, from
drivers/bluetooth/hci/Kconfig to subsys/bluetooth/host/Kconfig such
that eventually we can omit the entire Bluetooth driver menu option.

This re-organization does not change when the config can be enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-08 23:01:05 +03:00
Vinayak Kariappa Chettimada dc1dad34f3 Bluetooth: controller: Fix return type in hal/rand.c
Fix incorrect return data type, which causes controller to
hang generating random numbers.

Fixes bug introduced in commit d90095b556 ("Bluetooth:
controller: Use random numbers in adv and enc setup")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 18:11:07 +03:00
Carles Cufi 2fab706216 Bluetooth: controller: Check AdvA in Scan Response
The specification requires the scanner to verify that the AdvA present
in a scan response matches the AdvA that was sent in the original scan
request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-08 14:48:34 +02:00
Jukka Rissanen 64562e1af2 http: server: Add function to send a chunk of data
The http_response_send_data() can be used to send a chunk of data
to the peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-08 15:35:18 +03:00
Vinayak Kariappa Chettimada d90095b556 Bluetooth: controller: Use random numbers in adv and enc setup
Added implementation to get random numbers in ISR. And fixed
implementation to use random numbers in advertisement random
delay and encryption setup procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 15:29:55 +03:00
Paul Sokolovsky f80b2ac865 net: sockets: Fix race condition with accept() call
For an accepted socket, we should set our receive callback and start
to queue packets ASAP (in the accept callback itself). Otherwise,
(if done in accept() call like before) we may miss to queue some
packets.

This issue wasn't exposed with slow SLIP and with emulated QEMU, but
easily exposed with Ethernet on a real hardware.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-08 12:44:28 +03:00
Jukka Rissanen 509cdfefe2 net: Fix compile warnings
Some compile warnings were shown when using newlib.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-08 12:11:04 +03:00
Jukka Rissanen ddc71c139a new: app: Fix compile error if using newlib
We need to define __LINUX_ERRNO_EXTENSIONS__ if newlib is being
used otherwise there is a compile error about ESHUTDOWN errno
value missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-08 12:11:04 +03:00
Michael Scott 64ead4c6ee net: app: fix IPv6 init for late IP assigment
- Fix typo'd "&&" when checking bit value
- Don't use NET_EVENT_IPV6_ADDR_ADD for checking mask value
  due to combination of bits: _NET_EVENT_IPV6_BASE |
  NET_EVENT_IPV6_CMD_ADDR_ADD
  Instead use NET_EVENT_IPV6_CMD_ADDR_ADD so the check works
  when NET_EVENT_IPV6_ROUTER_ADD is enabled.

Tested fix with echo_server on x86 qemu where it was previously
broken.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-08 08:28:54 +03:00
Carles Cufi 505ebfbe36 Bluetooth: controller: Fix TargetA check as initiator
The existing check for the TargetA address in directed advertising
events was incorrect. In fact the specification states:

"An initiator that has been instructed by the Host to use
Resolvable Private Addresses shall not respond to directed connectable
advertising events that contain Public or Static addresses for the
target’s address (TargetA field)."

Hence, reject TargetA values that have not been successfully resolved
when the controller is generating its own RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 21:54:16 -04:00
Jukka Rissanen 7072876229 net: icmpv4: Calculate start of ICMPv4 echo-req properly
The end of ICMPv4 header was incorrectly calculated.

Coverity-CID: 173634

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 529a55b6ef net: rpl: Do not probe parent that is not our neighbor
Unlikely to happen but make sure parent neighbor exists when
probing it.

Coverity-CID: 173635

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen a1b6e5495d net: rpl: Make sure parent is found when processing DIO msg
If there is no parent found with a specific dag, then we have
to check this in order not to access NULL pointer.

Coverity-CID: 173637

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 3a438f159b net: rpl: Do not access NULL parent
If the parent is not found when adding DAG, then just return.
We must check the parent pointer as it can be NULL.

Coverity-CID: 173638

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 1584bbec48 net: trickle: Do clock wrap check properly
No need to complex overflow checks that are error prone.
Coverity complained that the original diff check was always
false.

Coverity-CID: 173639

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 4dc236b7dd net: rpl: Remove dead code when updating IPv6 HBHO
There was dead code when handling IPv6 Hop-by-hop option.
The extra option value check can be removed as it is useless.

Coverity-CID: 173642

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 238c51f6d0 net: sockets: Comment Coverity warning about unchecked values
Coverity complains about non-checked return values here. This is false
positive as the return values do not need checking in this special
case because we are closing the socket.

Coverity-CID: 173646

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen d86ff7255f net: rpl: Comment Coverity false positive when forwarding DAO
Coverity complains about reversed src and dst fields when sending
DAO ack back to originator. This is false positive.

Coverity-CID: 173650

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 14a87ea9c9 net: if: Check return value of k_poll() when sending data
Check the return value of k_poll() as instructed by Coverity.
If debugging is enabled we print error if this happens, otherwise
this error is ignored. In our case the return value should always
be 0.

Coverity-CID: 173652

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 8c02460a5e net: dns: Check address family when initializing
It is be possible that the local address was not properly
resolved in which case the local_addr variable could be NULL.
This will cause NULL pointer access if the variable is used.

Coverity-CID: 173656

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen b14586c3ca net: rpl: RPL route entry was fetched too late
The RPL route entry variable "extra" was resolved inside an
if-statement and the code was always returning from it.
This meant the the later code dealing with "extra" was never
executed. Fixed by moving the resolving of "extra" a bit
earlier so that the "extra" variable has always a proper value.

Coverity-CID: 173659
Coverity-CID: 173654

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Jukka Rissanen 7182620340 net: rpl: Status code was incorrectly checked in MRHOF link cb
The TX send function will return status < 0 if there is an error
when sending. This status value was incorrectly checked.

Coverity-CID: 173660

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-07 21:32:03 -04:00
Johan Hedberg bf8e504588 Bluetooth: Mesh: Fix duplicate const declarations
Remvoe duplicate const declarations which may cause compiler warnings.

Jira: ZEP-2442

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:18:02 +03:00
Johan Hedberg 01b684f82b Bluetooth: Mesh: Fix pointer signedness compiler warnings
Fix compiler warnings resulting from passing C string literals to
functions expecting an unsigned char pointer.

Jira: 2443

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:17:40 +03:00
Carles Cufi 264481116c Bluetooth: controller: Enable AAR for Scan Responses
To be able to get a hit on the AAR whenever a Scan Response is received,
enable it in the state transition.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 14:37:56 +03:00
Carles Cufi ba9d3ae6b5 Bluetooth: controller: Fix whitelist filter logic
Add missing checks for the logic that discriminates between whitelisting
and non-whitelisting filtering, so that we do not fall into an
unsuspected false positive.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 12:05:49 +02:00
Paul Sokolovsky b7e3739043 net: sockets: Manage TCP receive window
As we buffer incoming packets in receive callbacks, we must decrease
receive window to avoid situation that incoming stream for one socket
uses up all buffers in the system and causes deadlock. Once user app
consumes queued data using recv() call, we increase window again.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-05 11:40:50 +03:00
Paul Sokolovsky 19ff963693 net: tcp: Allow to explicitly manage TCP receive window
This fixes the existing situation that "if application buffers data,
it's the problem of application". It's actually the problem of the
stack, as it doesn't allow application to control receive window,
and without this control, any buffer will overflow, peer packets
will be dropped, peer won't receive acks for them, and will employ
exponential backoff, the connection will crawl to a halt.

This patch adds net_context_tcp_recved() function which an
application must explicitly call when it *processes* data, to
advance receive window.

Jira: ZEP-1999

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-05 11:40:50 +03:00
Anas Nashif 09bcd8ee74 Kconfig: make all syslog variables depend on SYS_LOG
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-04 14:34:54 -05:00
Luiz Augusto von Dentz c4f632bd09 net: bt: app: Add NET_APP_BLUETOOTH_NODE option
This enables IPSP node role which requires IPSS GATT service to be
registered.

Jira: ZEP-2451

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-04 18:18:40 +03:00
Luiz Augusto von Dentz cbc4a2b9b0 net: bt: Add advertise management command
This adds NET_REQUEST_BT_ADVERTISE which can be used to advertise
IPSS service so the remote devices can connect to it.

Jira: ZEP-2451

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-04 18:18:40 +03:00
Michael Scott 9b3f6362e6 net: app: allow IPv6 interface init to work with late IP assigment
Some network interfaces such as bluetooth 6lowpan can start without
an assigned IP address and then later once the connection is up a
router advertisement broadcast will assign the IP address.

The net_app framework will timeout out during network init if a value
cannot be parsed from CONFIG_NET_APP_MY_IPV6_ADDR.  Let's adjust
the framework to handle a missing value there and fill it in later
when the IPv6 address is added to the interface.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-04 17:57:58 +03:00
Paul Sokolovsky 8088e14c74 net: sockets: poll: Use prefixed POLL* constants.
Default examples build with native POSIX aliases enabled, so
unprefixed refs got thru.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-04 17:24:22 +03:00
Carles Cufi f6405dfd93 Bluetooth: controller: Avoid assignments in if statement
Rework the ctrl_lrpa_get() function so that it doesn't require an
assignment to be present inside the if statement, yielding smaller and
safer code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi f23aaeb7f4 Bluetooth: controller: Fix warning due to unused variable
With privacy disabled the lrpa pointers are not used, so exclude them
from the build.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 3a35859410 Bluetooth: controller: Translate addresses in adv reports
Advertising reports generated by a scanner require the controller to
look up the resolving list to supply the host with an ID address instead
of the RPA that has been sent over the air.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 66c619eb83 Bluetooth: controller: Fix typo in scan request address population
Use the actual scanner address to copy the generated RPA into, instead
of mistakenly copying it into the advertiser's address.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 6e42c2af3b Bluetooth: controller: Use RPA in scanner only if available
Whenever trying to generate a local RPA to send a scan request or a conn
ind, verify that it can be generated (i.e. no NULL IRK provided by the
Host) and fall back to using the public/random address if required.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 2c60df0786 Bluetooth: controller: Fix Set Privacy Mode command
Trivial fix for the return value in the processing of the Set Privacy
Mode HCI command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
Carles Cufi a87e8a08ee Bluetooth: controller: Use little-endian peer IRKs for generation
Since the hardware expects big-endian IRKs but the common generation
function expects it in little-endian, copy and reverse the peer IRK
before generating RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
David B. Kinder 62a0cd246d doc: fix uses of back quotes in documentation
ReST defines interpreted text roles where text enclosed by single quotes
can be "intrepreted", for example :ref:`some name` becomes a link to
a label anywhere in the doc set named "some name", :c:func:`funcname()`
becomes a link to the API documentation for "funcname", and
:option:`CONFIG_NAME` becomes a link to, in our case, the documentation
for the generated Kconfig option.

This patch fixes uses of `some name` (without a role) by either adding
an explicit role, or changing to ``some name``, which indicates inline
code block formatting (most likely what was intended).

This is a precursor to changing the default behavior of interpreted
text to treat `some name` as :any:`some name` (as configured in
doc/conf.py), which would attempt to create a link to any available
definition of "some name".

We may not change this default role behavior, but it becomes an option
after the fixes in this patch.  In any case, this patch fixes incorrect
uses of single-quoted text (possibly introduced because GitHub's
markdown language uses single-quoted text for inline code formatting).

Jira: ZEP-2414

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-03 11:08:23 -04:00
Carles Cufi b2a76be25b Bluetooth: controller: LE Enhanced Connection Complete
Implement the LE Enhanced Connection Complete HCI event, but include it
only when controller-based privacy is enabled, since it is only relevant
with it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Carles Cufi dce2f95e95 Bluetooth: controller: Increase conn count only on success
Since a connection attempt can fail and will still generate an LE
Connection Complete event, check the status from the LL control module
before incrementing the HCI connection count used for flow control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Johan Hedberg f8c338fde8 Bluetooth: Mesh: Health: Fix Current Status encoding
The Test ID was incorrectly being added as 4 bytes (size of a pointer)
instead of the intended 1 byte.

This fixes Coverity CID 173643.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 14:09:40 +03:00
Johan Hedberg d97be9e7a6 Bluetooth: Mesh: Provisioning: Always allow Failed PDU
In addition to the next expected PDU we should also process Failed in
all states.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 13:10:40 +03:00
Johan Hedberg 019b805275 Bluetooth: hci_ecc: Fine-tune thread stack size
The current 960 is at least too small under qemu_x86:

ecc stack (real size 1024): unused 36 usage 988 / 1024 (96 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 10:47:18 +03:00
Carles Cufi 4694fe6e8a Bluetooth: controller: nrf5: Fix AAR packet pointer
The nRF5 AAR requires the packet pointer to be placed exactly 3 bytes
before the beginning of the address. Since we don't use the S1 extra
length byte, substract one from the address of the radio packet pointer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi fc0c3a6c32 Bluetooth: controller: Fix IRK endianness
The currently supported hardware in the LL requires big-endian IRK
values to properly function. Reverse the order of the IRK bytes coming
from HCI to address this issue.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi ba2f0a1f1e Bluetooth: controller: nrf5: Fix AAR scratch pointer
The nRF5's AAR was being improperly configured, leading to a NULL
scratch pointer which made it not function at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Andrew Boie 507852a4ad kernel: introduce opaque data type for stacks
Historically, stacks were just character buffers and could be treated
as such if the user wanted to look inside the stack data, and also
declared as an array of the desired stack size.

This is no longer the case. Certain architectures will create a memory
region much larger to account for MPU/MMU guard pages. Unfortunately,
the kernel interfaces treat both the declared stack, and the valid
stack buffer within it as the same char * data type, even though these
absolutely cannot be used interchangeably.

We introduce an opaque k_thread_stack_t which gets instantiated by
K_THREAD_STACK_DECLARE(), this is no longer treated by the compiler
as a character pointer, even though it really is.

To access the real stack buffer within, the result of
K_THREAD_STACK_BUFFER() can be used, which will return a char * type.

This should catch a bunch of programming mistakes at build time:

- Declaring a character array outside of K_THREAD_STACK_DECLARE() and
  passing it to K_THREAD_CREATE
- Directly examining the stack created by K_THREAD_STACK_DECLARE()
  which is not actually the memory desired and may trigger a CPU
  exception

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-01 16:43:15 -07:00
Jukka Rissanen 6bb620e232 net: shell: Add command to get info about net-apps
A new net-shell command "net app" will print information about
network app users in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 21:09:59 +03:00
Jukka Rissanen 95d30430d7 net: app: Add debugging support to get net_app instances
Add API that allows net-shell to get net_app context information
that can be used to debug net_app connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 21:09:59 +03:00
Jukka Rissanen f3f32e872a net: app: Add DTLS support
Allow UDP connections to use DTLS to encrypt the user data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 21:09:59 +03:00
Johan Hedberg 2d57272f65 Bluetooth: hci_ecc: Convert to new uECC API
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-01 10:35:06 -04:00
Jukka Rissanen 994f5f2a4d net: shell: Remove net_shell_init() as it is not needed
The net_shell_init() is empty function and there is no use
for it so removing it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 14:45:06 +03:00
Carles Cufi 296b469c40 Bluetooth: controller: Thread-safe local RPA access
In order to make sure that the ISR never gets an incomplete or partial
local RPA, use pointers to share the local RPA between thread mode and
ISRs. Pointer updates are guaranteed to be atomic at least on ARM
Cortex-M.
Additionally add support for using local RPAs when initiating a
connection or sending a scan request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi a260d6face Bluetooth: controller: Resolve TargetA in software
Since the hardware is only able to resolve the first address in the
packet, use the existing functionality to resolve a potential TargetA
RPA in software to verify if it matches the local device.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi af93255aa5 Bluetooth: controller: Privacy filtering in scanner and initiator
This commit introduces controller-based privacy for both the scanner and
the initiator roles. All the features in the specification are
implemented except:

* RPA resolution for directed advertising (TargetA address)
* RPA generation for scan requests and conn ind packets

Follow-up patches will cover the 2 items of functionality still missing
from the basic implementation. Hosts not using controller-based privacy
should not be affected by this change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Luiz Augusto von Dentz cf913738c5 Bluetooth: GATT: Indicate service changes when reconnecting
If peer has previously configure to received service changes indications
any changes to the database during the time it has been disconnected
shall be indicated once it reconnects:

[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] sc_save: (0x004065b4) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] bt_gatt_connected: (0x00405240) conn 0x00405aa0
[bt] [DBG] gatt_ccc_changed: (0x00405240) ccc 0x00400b30 value 0x0002
[bt] [DBG] sc_ccc_cfg_changed: (0x00405240) value 0x0002
[bt] [DBG] sc_restore: (0x00405240) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] gatt_indicate: (0x004065b4) conn 0x00405aa0 handle 0x0008
[bt] [DBG] sc_indicate_rsp: (0x00405240) err 0x00

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz c6cb97f7c4 Bluetooth: GATT: Fix not setting SC_INDICATE_PENDING
bt_gatt_indicate return 0 in case of success, not true, so
SC_INDICATE_PENDING was flag was not set when it should.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz 737c50b50f Bluetooth: GATT: Improve notification code
Only checks if consolidated CCC value matches with data->type once.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Vinayak Kariappa Chettimada bc64c46e35 Bluetooth: controller: Fix control and data Tx queue management
Control and Data packet Tx queue management updated to be
optimal and defer control packet responses when Tx is paused
during encryption setup.

This fixes:
TP/SEC/MAS/BV-12 [Master Start Encryption: Overlapping
Procedure]
TP/SEC/MAS/BV-13 [Master Start Encryption: Overlapping
Procedure with LL_SLAVE_FEATURES_REQ]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 6b02fb6e93 Bluetooth: controller: Fix handling PHY upd diff proc collision
Fix handling of different procedure collision when receiving
a PHY update request and handling of reject extended
indication.

This fixes:
TP/CON/MAS/BV-47-C [Handling Protocol Collision – Different
Procedure – Channel Map],

TP/CON/SLA/BV-46-C [Handling Protocol Collision – Different
Procedure – Channel Map] and

TP/CON/SLA/BV-48-C [Handling Protocol Collision – Different
Procedure – Connection Update]

conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 08466d5021 Bluetooth: controller: Fix missing procedure timeout on PHY_RSP
Fix missing procedure timeout start on PHY_RSP response
enqueue.

This fixes TP/CON/SLA/BV-51-C [Protocol Timeout for PHY
Update Procedure – No Update Request] conformance test in
LL.TS.5.0.0,

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 4ceca0864d Bluetooth: controller: Fix a missing PHY Update event
Fix missing PHY update event generation on same procedure
collision,

This fixes TP/CON/SLA/BV-44-C [Handling Protocol Collision –
Same Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada c9a9d0f708 Bluetooth: controller: Fix PHY update with no change in PHY
Fix PHY update procedure intiation to use correct No Change
value in MtoS and StoM when there is no change to respective
PHYs. Also, added missing HCI event generation under this
case.

This fixes TP/CON/MAS/BV-41-C [Initiating PHY Update
Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 21935f7dd6 Bluetooth: controller: Fix asymmetric PHY by using correct tIFS
Fix asymmetric PHY connection by using correct tIFS,
considering previous PHY and next PHY chain delays while
calculating the Tx and Rx tIFS.

This fixes:
TP/CON/SLA/BV-40-C [Initiating PHY Update Procedure]
TP/CON/SLA/BV-42-C [Responding to PHY Update Procedure]
TP/CON/MAS/BV-41-C [Initiating PHY Update Procedure]
TP/CON/MAS/BV-43-C [Responding to PHY Update Procedure]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada df5deea218 Bluetooth: controller: Fix header complete timeout calculation
Fix header complete timeout calculation by using Rx PHY
chain delay instead of incorrectly used Tx PHY chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada a682554231 Bluetooth: controller: Fix slave drift compensation
As ticker can only drift in 32kHz units, the slave Rx
window should consider a +/- one 32kHz unit in addition to
+/- 16us jitter of the master. Hence, for the current
implementation the slave Rx window jitter is +/- 48us.
Future improvement can be done by using remainder of 32kHz
unit drift to reduce this jitter to +/- 16us.

With this fix 20ppm clock accuracy passes conformance TIM
tests (else 251-500ppm had to be used).

Problem was not seen in real life as master do not have a
+/- 16us jitter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 1ff96f2588 Bluetooth: controller: Fix terminate procedure timeout
Fix terminate procedure timeout when supervision timeout
equals connection interval. In this case, avoid timing out
in the first event of procedure initiation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada b0f3944e90 Bluetooth: controller: Fix slave sending reject_ext_ind
Fix slave implementation to initiate reject_ext_ind if peer
supports reject_ext_ind.

This fixes:
TP/SEC/SLA/BV-11-C [Slave Sending Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 0883915a1e Bluetooth: controller: Fix master rx-ing reject_ext_ind enc_req
Fix master receiving REJECT_EXT_IND for ENC_REQ PDU.

This fixes:
TP/SEC/MAS/BV-11-C [Master Receiving Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 8bf3d5d98f Bluetooth: controller: Fix for unexpected PDU during Enc setup
Fix for handling unexpected PDU during Encryption start.

This fixes:
TP/SEC/MAS/BV-14-C [Master Receiving unexpected PDU during
encryption start], and
TP/SEC/SLA/BI-05-C [Slave Receiving unexpected PDU during
encryption start]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada b187b1b949 Bluetooth: controller: Fix handling invalid control PDUs
Fix handling invalid control PDUs by generating
LL_UNKNOWN_RSP PDU.

This fixes:
TP/PAC/SLA/BV-01-C [Unknown Packet from Master]
TP/PAC/MAS/BV-01-C [Unknown Packet from Slave]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada f80344f0fe Bluetooth: controller: Fix access address generation
Fix access address generation to correctly have two
transitions in the six MS bits and add other missing checks.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada d6506c1f54 Bluetooth: controller: Minor cleanup of enc pause impl.
Minor cleanup of Encryption Restart Procedure; No need to
pause rx for slave role on reception of PAUSE_ENC_RSP PDU as
its already paused.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Jukka Rissanen 1c07ead104 net: http: Add context net_buf pool support to HTTP client
This commit adds http_client_set_net_pkt_pool() function that allows
caller to define net_buf pool that is used when sending a TCP packet.
This is needed for those technologies like Bluetooth or 802.15.4 which
compress the IPv6 header during send.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Jukka Rissanen ca7afdc774 net: tcp: Do not try to print TCP error for 6lo packet
For IPv6 header compressed packet, the IP header offsets will
be wrong. In this case there is no need to print error when
trying to print TCP packet information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Jukka Rissanen 93214086f9 net: http: Add context net_buf pool support to HTTP server
This commit adds http_server_set_net_pkt_pool() function that allows
caller to define net_buf pool that is used when sending a TCP packet.
This is needed for those technologies like Bluetooth or 802.15.4 which
compress the IPv6 header during send.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Luiz Augusto von Dentz 59e9d7ad1c Bluetooth: L2CAP: Store sent data in the correct buffer
The buf variable may have been unrefed by net_buf_frag_del thus it shall
not be used to store the sent data nor it should be in the
chan->tx_queue.

Jira: ZEP-2395

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-30 18:00:17 +03:00
Vinayak Kariappa Chettimada ca143612bf Bluetooth: controller: Fix assert on create connection
Fix assert in the controller on master connection creation
due to the CONNECT_IND PDU being transmitted beyond the
calculated scan window.

This is related to commit 80a796b493 ("Bluetooth:
controller: Fix scanner to use correct slot ticks")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-29 09:51:20 +03:00
Vinayak Kariappa Chettimada b380ab0251 Bluetooth: controller: Fix assert, reset ticker_id_prepare
Fix an assert in next role event preparation when a
connection terminated during the connection event being
aborted/pre-empted out by the next role event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-28 13:41:16 -07:00
Aska Wu c0b5e55e6d net/mqtt: Enable TLS support
CONFIG_MQTT_LIB_TLS is introduced to enable TLS support.

Also, prj_frdm_k64f_tls.conf is added to demostrate the whole idea.

jira:ZEP-2261

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-07-28 11:25:43 +03:00
Aska Wu fb79837862 net/mqtt: Convert mqtt lib to use net app API
Use net app API since we want to enable MQTT with TLS.
mqtt_connect() and mqtt_close() are added to build and close the
connection to the broker. The caller doesn't need to deal with
the net context anymore and the most of network setup code in
mqtt_publisher is removed.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-07-28 11:25:43 +03:00
Jukka Rissanen 6bb446ed8e net: slip: Clarify slip settings in Kconfig
As SLIP TAP is now the default after the commit ca0ad13a61
("net: enable SLIP only on QEMU targets"), clarify the comments
and settings in various Kconfig files that talk about slip.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-28 10:45:47 +03:00
Leandro Pereira 732424f065 drivers, net: Clean up semaphore initialization
Change the common "init with 0" + "give" idiom to "init with 1".  This
won't change the behavior or performance, but should decrease the size
ever so slightly.

This change has been performed mechanically with the following
Coccinelle script:

    @@
    expression SEM;
    expression LIMIT;
    expression TIMEOUT;
    @@

    - k_sem_init(SEM, 0, LIMIT);
    - k_sem_give(SEM);
    + k_sem_init(SEM, 1, LIMIT);

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-07-27 15:23:07 -04:00
Jukka Rissanen 77eddf68c4 net: if: Delay IPv6 DAD if network interface is down
If the network interface is down, then IPv6 DAD (Duplicate
Address Detection) cannot be done if new IPv6 address is added
to the network interface. This can happen in Bluetooth, where
network interface is taken up only after there is a BT connection.
The DAD is delayed and done later after the network interface is up.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-27 16:03:03 +03:00
Jukka Rissanen f8c5f69780 net: shell: Do not access NULL pointer if interface is down
Normally network interface is always UP, but Bluetooth
interfaces are down until connected. So if this is the case,
then check the interface status before trying to access variables
that are NULL. This was seen with "net iface" shell command when
BT was enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-27 15:19:53 +03:00
Luiz Augusto von Dentz 60e34d1032 net: Don't enable SLIP driver if Bluetooth is enabled
In case the application is using NET_L2_BLUETOOTH the SLIP drivr shall
not be selected as bus they cannot coexist since they use the same UART
port:

arch/x86/soc/ia32/Kconfig.defconfig:

config BLUETOOTH_UART_ON_DEV_NAME
        default "UART_1"

config UART_PIPE_ON_DEV_NAME
        default "UART_1"

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-27 14:08:44 +03:00
Johan Hedberg c878bbdf08 Bluetooth: Mesh: Fix advertising thread initialization
Recent thread API update patches failed to update the mesh advertising
thread initialization.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-27 11:38:01 +03:00
Ricardo Salveti 696bef58ba net: app: fix build when NET_DEBUG_APP is used with SYS_LOG_NET_LEVEL=1
hr_addr is only available when SYS_LOG_NET_LEVEL is > 1.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-07-27 10:19:13 +03:00
Anas Nashif ca0ad13a61 net: enable SLIP only on QEMU targets
In many networking tests we had to configure SLIP in the prj.conf
leaving those configurations Qemu specific. This change enables SLIP for
QEMU targets automatically and allows reuse of prj.conf for multiple
boards.

Additionally, the TUN options is removed. This option was not used
anywhere.

To enable self-contained networking tests that do not depend on SLIP, we
introduce the new option NET_TEST which disables TAP and allows testing
in QEMU without the need for a host interface.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-07-26 10:57:48 -04:00
Jukka Rissanen e75b71ff0a net: trickle: Misc changes
* Fix the indentation which was caused by uint32_t -> u8_t changes.
* Make sure there is no unused variable warning if debugging is
  enabled but debug level is low.
* Add assert that checks that Imax_abs is > 0 which it should be.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-26 07:56:51 -05:00
Jukka Rissanen 723a4a5583 net: route: Check null pointer for neighbors and routes
If there are no neighbors or there is no route to one specific
neighbor, then check the NULL pointer before accessing the route.
This issue was seen with "net route" shell command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-26 11:25:06 +03:00
Andrew Boie e8cede7940 net: fix references to stack buffers
The net_stack_analyze function wants to look at the stack buffer,
but it is making assumptions on where this data is that are no
longer valid. Change to use the proper APIs for referencing this.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-26 10:31:46 +03:00
Kumar Gala a45dac0bd1 dts: fix Kconfig enablment of BLUETOOTH_MONITOR_ON_DEV_NAME
Since we generate BLUETOOTH_MONITOR_ON_DEV_NAME based on dts we need a
!HAS_DTS check around it.  Otherwise we can get into odd build errors.
Its also possibly that we don't specify "zephyr,bt-mon-uart" and in that
case we default to CONFIG_UART_CONSOLE_ON_DEV_NAME (ie 'zephyr,console'
on DTS platforms).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-07-25 12:23:20 -05:00
Vinayak Kariappa Chettimada 255e5cc344 Bluetooth: controller: Implement Read/Write Auth Payload timeout
Added implementation to support HCI Read Authenticated
Payload Timeout Command and HCI Write Authenticated Payload
Timeout Command.

This fixes:
TP/SEC/SLA/BV-08-C [No response to LL_PING_REQ]
TP/SEC/SLA/BV-09-C [Modified Authentication Payload Timeout]
TP/SEC/MAS/BV-08-C [No response to LL_PING_REQ]
TP/SEC/MAS/BV-09-C [Modified Authentication Payload Timeout]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-22 11:55:35 +03:00
Jukka Rissanen 5e7765ba28 net: app: Setup IEEE 802.15.4 during init
If IEEE 802.15.4 is enabled, then setup the network settings
automatically so that the device is ready for IP configuration.
This is only done if CONFIG_NET_APP_AUTO_INIT is enabled, which
is currently the default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-20 17:09:27 +03:00
Johan Hedberg 0ec2630882 Bluetooth: Mesh: Add initial implementation
Add an initial implementation for the Bluetooth Mesh Profile
Specification. The main code resides in subsys/bluetooth/host/mesh and
the public API can be found in include/bluetooth/mesh.h. There are a
couple of samples provided as well under samples/bluetooth and
tests/bluetooth.

The implementation covers all layers of the Bluetooth Mesh stack and
most optional features as well. The following is a list of some of
these features and the c-files where the implementation can be found:

 - GATT & Advertising bearers (proxy.c & adv.c)
 - Network Layer (net.c)
 - Lower and Upper Transport Layers (transport.c)
 - Access Layer (access.c)
 - Foundation Models, Server role (health.c & cfg.c)
 - Both PB-ADV and PB-GATT based provisioning (prov.c)
 - Low Power Node support (lpn.c)
 - Relay support (net.c)
 - GATT Proxy (proxy.c)

Notable features that are *not* part of the implementation:

 - Friend support (initial bits are in place in friend.c)
 - Provisioner support (low-value for typical Zephyr devices)
 - GATT Client (low-value for typical Zephyr devices)

Jira: ZEP-2360

Change-Id: Ic773113dbfd84878ff8cee7fe2bb948f0ace19ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-20 09:30:44 +03:00
Jukka Rissanen 16837f954f net: if: Check in delete addr if delayed work needs cancelling
The address lifetime timer was cancelled always even if the address
timer was never installed.

Jira: ZEP-2397

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-19 10:16:54 -07:00
Paul Sokolovsky 2c2e8b26b4 net: sockets: Implement poll() operation.
poll() allows to (efficiently) wait for available data on sockets,
and is essential operation for working with non-blocking sockets.

This is initial, very basic implementation, effectively supporting
just POLLIN operation. (POLLOUT implementation is dummy - it's
assumed that socket is always writable, as there's currently no
reasonable way to test that.)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-18 21:46:06 +03:00
Paul Sokolovsky b1a3753669 net: http_server: Properly close network contexts.
Use net_context_put(), not net_context_unref(). This makes sure
that after sending response, connections are properly closed.

Jira: ZEP-2362

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-18 08:40:02 +03:00
Paul Sokolovsky 9ed716b9b2 net: context: connect: Make sure local end is bound before connecting
Introduce net_context_bind_default() to ensure that local address is
set for context if not yet (via explict bind() call). This fixes
dereferences of NULL pointer to local address which was exposed when
MMU was enabled for qemu_x86.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-17 21:12:03 +03:00
Carles Cufi 35b34c2e65 Bluetooth: controller: Only add active slots to hw filter
When populating the hardware filter, add only slots that are marked as
taken to avoid the hardware being confused by all-0 addresses. This
solves an EBQ issue with whitelist filtering.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Carles Cufi 77b0108afd Bluetooth: controller: Avoid warning with privacy disabled
To avoid warnings (seen on some machines) that a function reaches its
end without returning a value, conditionally compile the function in a
way that this cannot happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Vinayak Kariappa Chettimada 52ee6622c0 Bluetooth: controller: Fix master terminate procedure
Fix master terminate procedure so that if slave responded to
the ack from master for the LL_TERMINATE_IND then the master
correctly disconnected.

This fixes TP/CON/MAS/BV-09-C [Master Accepting Termination]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Vinayak Kariappa Chettimada 9fc4fefc47 Bluetooth: controller: Fix slave latency enable at conn setup
Fix implementation to maintain a connection in the slave
role not taking slave latency into use before receiving an
acknowledgement from the master.

This fixes TP/CON/ADV/BV-03-C [Master Missing Slave Packets]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Marcel Holtmann aefcf547ad Bluetooth: controller: Add skeleton for vendor HCI commands
Signed-off-by: Marcel Holtmann <marcel.holtmann@intel.com>
2017-07-14 14:54:52 +03:00
Carles Cufi a8173b9033 Bluetooth: controller: Fix privacy whitelist allocation
Fix copy-paste issues when allocating devices in the privacy-enabled
whitelist.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 13:07:41 +02:00
Robert Chou 33c54ee6fd net: zoap: advance block context by checking M bit from block option
According to RFC7959 page 30, "The end of a block-wise transfer is
governed by the M bits in the Block options, _not_ by exhausting the
size estimates exchanges."

Therefore, we should check the M bit instead of total size (which
is not always available, too)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-07-14 11:06:54 +03:00
Vinayak Kariappa Chettimada 88dba0dd35 Bluetooth: controller: Fix cond. mayfly priority check
When the controller is configured to have its worker and job
be run at different interrupt priority, check for mayfly
priority being equal was incorrect.

Fixed by conditionally compiling the correct check of mayfly
priority level.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 10:01:15 +02:00
Vinayak Kariappa Chettimada 9dc7975b76 Bluetooth: controller: Fix to use correct anchor for scanner
Fixed a defect wherein anchor for first scanner event was in
the past (when looking for a free timeslice to avoid
overlapping with master role events) when actually there
were no master roles active. This defect caused the scanner
role to assert, when started with other roles active (eg.
advertiser), when trying to catch-up to current tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada 449295eee3 Bluetooth: controller: Revert fix for assert due to stale tick
This reverts commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada de6ed122a8 Bluetooth: controller: Revert fix for scanner Rx window hang
This reverts commit b5235207d3 ("Bluetooth: controller:
Fix for scanner Rx window hang") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Jukka Rissanen 7474553543 net: Fix connectivity issues if only UDP or TCP is enabled
If either UDP or TCP is enabled but not both, then connectivity
fails. This was a side effect of commit 3604c391e ("net: udp:
Remove NET_UDP_HDR() macro and direct access to net_buf")

Jira: ZEP-2380

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-14 08:49:45 +03:00
Jukka Rissanen 266792af9c net: ipv6: Fragmentation was accessing NULL pointer
When IPv6 fragments were sent, the last IPv6 fragmented packet
was accessing NULL pointer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-13 15:45:35 +03:00
Vinayak Kariappa Chettimada b07e7f2b5a Bluetooth: controller: Fix T_Terminate and other timeout calc.
Fix calculation of T_Terminate and other procedure timers by
using ceil on calculated connection interval units.

This fixes TP/CON/MAS/BI-02-C [Master T_Terminate Timer] and
TP/CON/SLA/BI-02-C [Slave T_Terminate Timer] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 2800961fe1 Bluetooth: controller: Fix supervision timeout countdown
Add missing supervision timeout countdown initiation on CRC
error.

This fixes TP/CON/ADV/BI-01-C [Connection Supervision
Timeout during Fail Connection Setup] and TP/CON/INI/BI-02-C
[Slave Packets Invalid CRC] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 97bfb1d9f4 Bluetooth: controller: Fix slave conn. failed to be established
Fix implementation so that both slave and master behave same
during connection setup and generate disconnection complete
with reason 0x3e (connection failed to be established).

This fixes TP/CON/ADV/BV-02-C [Accepting Connections
Timeout] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Carles Cufi 6886f979cf Bluetooth: controller: Allow devices not in resolving list
Whenever not using the whitelist the resolving list is traversed to
verify that the device is allowed depending on its current privacy mode.
In the case where the device is not found by address in the resolving
list, allow the request to go through, since we are then dealing with an
unknown devices and the resolving list restrictions do not apply.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 14:07:27 +03:00
Carles Cufi 4666015323 Bluetooth: controller: Fix regression in WL filter population
Erroneous check conversion triggered a regression when populating the
whitelist filter.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 09:29:16 +02:00
Luiz Augusto von Dentz 16e6abbcfb Bluetooth: L2CAP: Don't reuse RX buffers to respond
This causes num of packets command handling to dead lock since it
is done on RX buffer destroy if used on TX it may not be destroyed
on time causing.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-12 17:37:45 +03:00
Carles Cufi c9bd30aa90 Bluetooth: controller: Check AdvA in scan requests
The specification states that the AdvA in a Scan Request packet should
be identical to the one sent in the original advertising packet, so
check this when processing a Scan Request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 486dad9e4c Bluetooth: controller: Fix RL permission check
When the initiator is using an RPA and we match it using the filtering,
we should return early and allow the device packet through instead of
going through the whole resolving list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 7b02b06b41 Bluetooth: controller: Fix directed adv filtering
The specification states that filter policies shall be ignored for
directed advertising, so reflect this behaviour in the code.
Additionally when the local device is using RPAs but the peer uses an
identity address, the resolving list index needs to be updated when
traversing the RL to reflect that there has indeed been a  device match
even though the IRK match did not happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 968e4089d1 Bluetooth: controller: Fix AdvA checks in advertiser
The AdvA in the CONN_IND packet must match the AdvA in the advertising
packet that triggered it regardless of the advertising type.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Vinayak Kariappa Chettimada 9a13a0c732 Bluetooth: Add BUILD_ASSERT to check Tx and Rx thread priorities
Added BUILD_ASSERT check for Tx and Rx thread priorities.

The Tx thread priority shall be higher than Rx thread
priority in order to correctly detect transaction violations
in ATT and SMP protocols. The Number of Completed Packets
for a connection shall be processed before any new data is
received and processed for that connection.

The Controller's priority receive thread priority shall be
higher than the Host's Tx and the Controller's Rx thread
priority.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-12 13:50:51 +03:00
Ravi kumar Veeramally f73221e5cb net: rpl: Fix invalid config name
Fixes #665

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-07-12 11:06:57 +03:00
Jukka Rissanen 72e73b2bd6 net: arp: Do not try to access NULL pointer
When the ARP message is received when the device is starting up,
the network interface might not yet have IPv4 address setup
correctly. In this case, the IP address pointer could be NULL
and we must not use it for anything.

Fixes #752

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 20:18:32 +03:00
Paul Sokolovsky 1abb89f640 net: sockets: Implement non-blocking mode.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-11 14:00:27 +03:00
Jukka Rissanen 98fb2bed63 net: Comment false positives reported by Coverity
Coverity reported false positives, add comment about these in
the code.

Jira: ZEP-2344
Jira: ZEP-2345

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 13:59:04 +03:00
Paul Sokolovsky 4334144caa net: context: Fix use of k_delayed_work_cancel with SYN backlog
This patch fixes a regression which the original patch introducing
this code (improving concurrent connection handling) had on
*sequential* connection handling. Without this patch, with the
default CONFIG_NET_TCP_BACKLOG_SIZE of 1, after each connection
request, there was 1s (ACK timeout) "dead time" during which new
connection wasn't ptocessed.

This is because k_delayed_work_remaining_get() was checked the
wrong way. But there's no need to use k_delayed_work_remaining_get()
at all, instead just call k_delayed_work_cancel() and dispatch on
its return code.

Note that there's still a problem of synchronizing access to
the global array tcp_backlog, as worker (which modifies it) may
preempt packet handling code (which also modifies it).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-11 11:21:42 +03:00
Jukka Rissanen ee989be286 net: tcp: Fix sequence number validator
The sequence number validator was checking the seq numbers
incorrectly. This caused some valid RST packets to be dropped
and the TCP stream to hang.

Added also a TCP test case that tests the seq validator.

Jira: ZEP-2289

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 10:35:19 +03:00
Jukka Rissanen ccb9c844b5 net: ipv6: Increase default multicast address count to 3
Usually it is not enough to have just one IPv6 multicast
address defined for the network interface. So allocate three
IPv6 multicast addresses for the network interface as IPv6
by default uses multicast a lot. This hopefully will avoid
some mysterious errors if the addresses run out.

Note that this will increase memory usage a bit so you might
need to lower the count in your conf file if memory is low.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 10:33:28 +03:00
Jukka Rissanen e663c5df51 net: tcp: Add FIN timer when doing active close
The commit 210c30805b ("net: context: Close connection fast
if TIME_WAIT support is off") was not a proper way of closing
the connection. So if Zephyr closes the connection (active close),
then send FIN and install a timer that makes sure that if the peer
FIN + ACK is lost, we close the connection properly after a timeout.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 10:30:44 +03:00
Jukka Rissanen ee633595aa net: tcp: Fix passive close ACK timer
The commit 00ac0487b0 ("net: context: Remove tcp struct SYN-ACK
timer handling") removed also the passive close ACK timer.
Adding that ACK timer back so that we can close the connection
properly even if the last ACK from peer is lost.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 10:30:44 +03:00
Luiz Augusto von Dentz a864436559 Bluetooth: Shell: Add second vendor service
This adds a second vendor service testing if service changed indications
works with more than one change in a row and as a bonus it implements
echo attribute which notifies any data that is written to it:

> ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Command (0x52) len 4
        Handle: 0x0013
          Data: 0000
< ACL Data RX: Handle 3585 flags 0x02 dlen 9
      ATT: Handle Value Notification (0x1b) len 4
        Handle: 0x0013
          Data: 0000

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Luiz Augusto von Dentz 17b340cc13 Bluetooth: Shell: Implement support for gatt-metrics off
With introduction of bt_gatt_service_unregister it is now possible to
unregister service at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Luiz Augusto von Dentz 42c2b2ea81 Bluetooth: GATT: Rework Service Changed indications
There could be situations where many services are changed in a row which
would cause k_sem_take to block on the second change, but if the calling
thread is actually the RX thread then this will deadlock since the RX
thread is the one processing the confirmations of indications and it is
blocked k_sem_give is never called.

To solve this the services changes are now offloaded to the system wq
and the code will attempt to consolidate the range being changed so only
one indication is send. If for some reason another changes is caused
while confirmation is pending we just reschedule it to run later to
avoid blocking the system wq in the same way.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Carles Cufi f6260d6adb Bluetooth: controller: Rename whitelist arrays
For consistency with the Resolving List, rename the whitelist filter to
match its type and the privacy-enabled version to align it with the
short name used in the RL.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02:00
Carles Cufi a99d1f8fe6 Bluetooth: controller: Fix resolving list error handling
To correctly handle the allocation and deallocation of resolving list
items, the ll_rl_find and wl_pees_find functions have been modified to
return an invalid index instead of a negative value in case of error.
This is to avoid the ambiguity when mixing indices and negative numbers,
which does not play well with the first index 0.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02:00
Andrew Boie 65a9d2a94a kernel: make K_.*_INITIALIZER private to kernel
Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Jukka Rissanen 10eea9bb9a net: Fix NULL pointer access
The networking code was accessing NULL pointer which it should
not do.

Jira: ZEP-2367

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-10 09:32:26 -07:00
Luiz Augusto von Dentz 2285f17bea net: bt: Check return of bt_conn_get_info
This fixes coverity CID 171565 which may be valid in case of the
connection is not properly setup, or its memory is corrupted, it
may cause use of invalid addresses to be set using
net_if_set_link_addr.

JIRA: ZEP-2344

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-10 13:53:01 +03:00
june li cdeee63fbf net: tcp: Recalculate the tcp checksum when changing tcp header.
If the TCP data packet needs to be re-sent after the packet is lost,
then the acknowledgment number will be changed. This then means that
the TCP checksum needs to be recalculated too.

Signed-off-by: june li <junelizh@foxmail.com>
2017-07-10 11:08:07 +03:00
Geoff Gustafson 1405627c37 net: context: Use K_NO_WAIT instead of 0 for timeout
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
2017-07-10 10:59:28 +03:00
Ravi kumar Veeramally 5f9cf752f4 net: rpl: Ignore consistent DIO messages
When a node receives consistent DIO messages with same data from
Border Router just ignore those messages. Need not to proceed
further.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-07-07 15:49:06 +03:00
Ravi kumar Veeramally ab2dbffc4f net: rpl: Fix invalid access of IPv6 nbr link metric
Link metric is part IPv6 neighbour data struct. But RPL code is
trying to access it from RPL parent table where link metric doesn't
exist. So provided an api to get IPv6 neighbour data from RPL parent
data.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-07-07 15:49:06 +03:00
Ravi kumar Veeramally d971d26f84 net: rpl: Fix byte order conversion while preparing message
DAG rank will be properly written with net_pkt_write_be16() in
network packet. API will take care of endianness. So need
not to convert it using htons().

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-07-07 15:49:06 +03:00
Ravi kumar Veeramally 0aaee54ff0 net: rpl: Fix byte order conversion of sender rank
Sender rank (16 bit uint) was properly read with net_frag_read_be16()
api and need not to convert it again using ntohs().

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-07-07 15:49:06 +03:00
Jukka Rissanen e58bc105dc net: Avoid printing non-error cases when parsing packet
We had various asserts when checking network packet length but
printed also error when there was none. Fix this by checking
do we really have a too short message.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 9c907fca43 net: tcp: Remove NET_TCP_HDR() macro and direct access to net_buf
Remove NET_TCP_HDR() macro as we cannot safely access TCP header
via it if the network packet header spans over multiple net_buf
fragments.

Fixed also the TCP unit tests so that they pass correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 3604c391e6 net: udp: Remove NET_UDP_HDR() macro and direct access to net_buf
Remove NET_UDP_HDR() macro as we cannot safely access UDP header
via it if the network packet header spans over multiple net_buf
fragments.

Fixed also the UDP unit tests so that they pass correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 8476da9d9b net: icmp: Remove NET_ICMP_HDR() macro and direct access to net_buf
Remove NET_ICMP_HDR() macro as we cannot safely access ICMP header
via it if the network packet header spans over multiple net_buf
fragments.

Jira: ZEP-2306

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 7e259e7526 net: ipv6: Handle PAD1 extension header properly
The IPv6 HBH option PAD1 ext header was not parsed properly
as the code read one extra byte from the ext header. The
PAD1 length is only 1 byte.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen a6e876ef5b net: utils: Helper to check if protocol header fits in fragment
Add utility function that helps to figure out if the
protocol headers can be directly accessed when they fit one
net_buf fragment, or if they need to accessed using various
net_pkt helpers that know about reading data from two
different net_buf's.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 2cf47d1778 net: utils: Rework the IP packet checksum calculation
Instead of directly setting pointer to where to start to calculate
the various IP related checksums, use the net_frag_skip() to first
find out what is the fragment where the calculation should start.

This needs to be like this so that if the IP header + possible
extension are so long that they do not fit the first fragment,
we need to be prepared to look into second fragment.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Vinayak Kariappa Chettimada be003be10a Bluetooth: Decrease Rx processing priority
The following error and warning is received when connecting
to certain central devices:
[bt] [ERR] hci_num_completed_packets: packets count mismatch
[bt] [WRN] bt_att_recv: Ignoring unexpected request

This could happen if Tx-ed packet is not added to pending
list before a num of completed packets event and/or new Rx
packet is received.

This is fixed by reducing the Rx thread priorities in the
Host and the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-07 10:33:55 +03:00
Robert Chou de3df603fa net: net_app: fix syntax error when accessing remote from default_ctx
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-07-07 09:42:07 +03:00
june li 054e5453b9 net: tcp: Reset context->tcp to NULL after net_tcp_release.
net_context_unref() is protocol agnostic, after being un-referenced,
the same context might end up being used then for UDP,
if context->tcp is not reset to NULL, calling net_context_unref()
after this UDP usage will again try to release this TCP pointer
which might lead to random error.

Signed-off-by: june li <junelizh@foxmail.com>
2017-07-06 22:35:51 +03:00
Johan Hedberg 58d87ff530 Bluetooth: conn: Fix notifying all pending tx packets in send_frag()
The code in send_frag() depends on being able to allocate a new
pending tx contexts with 100% certainty. We must therefore notify
*all* connections instead of the current one in order to ensure that
there are free contexts available in free_tx.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 20:46:25 +03:00
Jukka Rissanen f4cc1d10a7 net: route: Do not try to access null link layer address
In some cases the lladdr might not be set, currently this is
seen with RPL unit tests, in which case we must not access
the lladdr.

Jira: ZEP-2330

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-06 09:19:11 -07:00
Jukka Rissanen 94f7c4e586 net: route: Do not try to del null route
If there is no route to the neighbor, then do not try to delete
it because the route pointer is NULL.

Jira: ZEP-2329

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-06 09:18:41 -07:00
Anas Nashif da7cc84655 subsystem: cleanup misc and make cpp a subsystem
Move a way from misc/ and put in its own subsystem to allow enhancements
in the future and make it a core part of Zephyr, not just something
misc.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-07-06 09:13:46 -05:00
Johan Hedberg 4f62c07960 Bluetooth: Fix bogus decoding of 8-bit num_handles as 16-bit
The num_handles parameter of the Number Of Completed Packets event is
8-bits and not 16-bits, so no helper variable or byte order conversion
is needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 15:57:10 +03:00
Johan Hedberg baf4f0c912 Bluetooth: conn: Switch order of tx_notify & tx_queue
In case both conn->tx_notify and conn->tx_queue have data in them we
should first process the notify queue and only then new outgoing
packets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 14:58:35 +03:00
Vinayak Kariappa Chettimada b56768b626 Bluetooth: controller: Fix first interval to be within +/-16us
Due to the missing remainder support in the ticker_start
function for first interval, fix implementation so as to
round the first interval/offset during master connection
setup and connection update to within +/-16us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-06 14:48:32 +03:00
Patrik Flykt 00ac0487b0 net: context: Remove tcp struct SYN-ACK timer handling
The SYN-ACK timer is now handled by the TCP backlog functionality,
while the remaining ACKs for established connections use the tcp
struct ack timer. With this, code setting tcp struct SYN-ACK state
timers can now be removed.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-07-06 14:33:55 +03:00
Patrik Flykt 117771e633 net: context: Add TCP SYN-ACK timer handling
Add timer for sent TCP SYN-ACKs. If the timer is already
scheduled to run before canceling it is attempted, set
the cancelled flag and let the callback remove the
delayed work.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-07-06 14:33:55 +03:00
Patrik Flykt 864df870f8 net: tcp: Implement TCP backlog for incoming connections
Add an array of configurable size that holds TCP backlog entries.
The array is shared between all incoming TCP connections in order
to make it possible to get away with less memory consumed than
with a connection based approach.

The backlog entries are created when a SYN is received for a
listening TCP socket and removed once the corresponding ACK is
seen. With an incoming RST the corresponding backlog entry is
cleared, if any.

The size of the global backlog array is defined with the
CONFIG_NET_TCP_BACKLOG_SIZE Kconfig variable.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-07-06 14:33:55 +03:00
Patrik Flykt 9cc7431b9d net: tcp: Make initial sequence number calculation public
The initial TCP sequence number needs to be assigned when a SYN
is received in net_context.c.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-07-06 14:33:55 +03:00
Jukka Rissanen 7a31d4b8cb net: app: Fix dual IPv4 and IPv6 support
It was not possible to send IPv4 packets if IPv6 was also
enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-06 14:32:37 +03:00
Anas Nashif e32cfe5f09 kconfig: fix typo in Kconfig name: NET_RPL_MC_EXT
Should be NET_RPL_MC_ETX

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-07-05 12:43:13 -04:00
Anas Nashif c2e62f4618 net: kconfig: fix help message for SLIP
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-07-05 12:43:13 -04:00
Johan Hedberg 259701149b Bluetooth: Clean up struct bt_conn
Fix alignment of rx_len, and move err & state to a better location to
minimize padding.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-05 12:40:11 +03:00
Johan Hedberg 30beef9419 Bluetooth: GATT Introduce BT_GATT_CCC_MAX helper define
The worst-case maximum number of CCC entries we need is actually
MAX_CONN + MAX_PAIRED. Provide a helper define for it and use it
whenever appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-04 17:30:40 +03:00
Johan Hedberg cf1f3c26a5 Bluetooth: Kconfig: let MAX_PAIRED be 0 if SMP is not supported
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-04 17:30:40 +03:00
Carles Cufi d990079f15 Bluetooth: controller: Fix HCI remote version structure
The HCI Read Remote Version Information Complete event structure was
incorrect, leading to qualification test failures. This patch fixes the
structure and also the storing of the data in an endianness-agnostic
manner.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 13:43:48 +03:00
Carles Cufi 269a828cb1 Bluetooth: controller: Use RL indices in adv ISR
To avoid manipulation of the irkmatch_ok and irkmatch_id, rely instead
on Resolving List indices for all checks in the advertising ISR.
Although we do incur in a small overhead to look it up initially, the
overall gains are worth the change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 09:30:46 +03:00
Vinayak Kariappa Chettimada 2dd375ef45 Bluetooth: controller: Fix advertisement event lengths
The Controller reserved more than required time for
advertisement event length. Due to this, directed
advertisements did not meet the required <= 3.75ms
interval. It is now fixed by having event lengths based
on the advertisement PDU types.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Vinayak Kariappa Chettimada 879c49ce91 Bluetooth: controller: Rename chl_* to chan_*
Rename use of chl_* namespace to more commonly used chan_*.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Carles Cufi 389736277b Bluetooth: controller: Fix Event Mask Page 2 handling
Correct the default value (0x0) for the Event Mask Page 2 and add the
command to set it to the list of supported commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 08:15:52 +03:00
Erwin Rol a0fc5d8229 net: app: prevent setting semaphore limit to 0
When neither IPv4 nor IPv6 are selected the limit that is
passed to k_sem_init will end up being 0, which will trigger
the folowing assertion in k_sem_init;

__ASSERT(limit != 0, "limit cannot be zero");

Fixed by not passing count as initial and limit value but
only as initial value and use UINT_MAX as limit.

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2017-07-03 20:58:13 -04:00
Erwin Rol f541ba3ca1 net: app: fix typo
Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2017-07-03 20:58:13 -04:00
Carles Cufi fc14bfbe2f Bluetooth: controller: Filter Auth Payload timeout exp
Correctly filter out the Authenticated Payload Timeout Expired event
based on the bit present on page 2 of the Event Mask.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Carles Cufi 73378e1cad Bluetooth: controller: Add support for Event Mask Page 2
In order to be able to filter events present in Page 2 of the Event
Mask, this command allows the Host to set the Page 2 of the bitmask
through the corresponding command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Carles Cufi b97a4670a6 Bluetooth: controller: Reset filters correctly
Reset and initialize filters correctly based on whether privacy is
enabled in the controller. Particularly relevant in the case of the
whitelist, which is handled in a completely different way if privacy is
enabled. Additionally reset the peer IRK list in the resolving list
whenever the list itself is cleared.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Vinayak Kariappa Chettimada 3779fb626a Bluetooth: controller: Increase ticker operations in thread mode
When flashing in synchronous mode with BLE roles active,
ticker function calls will be deferred to avoid radio ISR
latencies. Increase the total operations supported by 1, to
accommodate flash driver's use of ticker operations.

It has been observed, without this increase, either the
flash driver returned -ECANCEL or the BLE Controller
asserted on data transmit as a slave (trying to force data
transmit on earliest connection event interval).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-01 13:21:38 +02:00
Johan Hedberg 2684775d0f Bluetooth: monitor: Remove interrupt locking from monitor_console_out()
Locking interrupts for a long duration is in general bad design, and
is particularly bad for the controller which depends on low latency
interrupts. Instead of using interrupt locking introduce a new flag to
track the shared buffer usage and simply drop characters if the flag
is set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-30 17:19:56 +03:00
Carles Cufi 803eab08ec Bluetooth: controller: Privacy filtering in advertiser
Implement privacy-enabled filtering in the advertiser role. This
includes all required checks when running address generation and
resolution so that the advertiser complies with the relevant
specification sections.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-30 17:19:30 +03:00
Vinayak Kariappa Chettimada 4362eda4aa Bluetooth: controller: Fix missing re-initialization of ret_cb
Fix missing re-initialization of ret_cb to
TICKER_STATUS_BUSY before every new call to ticker interface
functions' with operation's callback.

One issue was undirected advertisement disable to return
failure status in the scan_adv sample.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada b5235207d3 Bluetooth: controller: Fix for scanner Rx window hang
With the fix in commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") it is required that a
skipping event shall abort the previous role in order to
enable the ticker_job to resume and reschedule next ticker
expiry.

In the scan_adv sample, with continuous scanning, an
advertiser would pre-empt it, but if the advertiser skipped
its event without aborting the scanner, the scanner is hung
with its rx window without a timeout, and HCI command to
stop the advertiser will wait forever to complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada 80a796b493 Bluetooth: controller: Fix scanner to use correct slot ticks
The scanner was reserving a little less slot ticks which
caused other roles to overlap before scan window could
close.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Jukka Rissanen a1be6a8ba9 net: app: Create support for network application API
The network application API is a higher level API for creating
client and server type applications. Instead of applications
dealing with low level details, the network application API
provides services that most of the applications can use directly.

This commit removes the internal net_sample_*() API and converts
the existing users of it to use the new net_app API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-30 06:13:09 -04:00
Johan Hedberg c55870e885 Bluetooth: hci_ecc: Use ATOMIC_DEFINE() for the flags
This doesn't make much practical difference, however it should resolve
Coverity CIDs 170740 and 170748.

Jira: ZEP-2343

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-30 12:55:33 +03:00
Erwin Rol 6e80eb46c8 net: ipv4: fix icmp checksum calculation
If ICMP packets do not fit in 1 net_pkt fragment the checksum
will be calculated incorrectly.

The problem shows up when using ping with the -s option to
create large ping requests. Eventhough the ping command does
accept the reply without complaining, Wireshark warns that
the icmp checksum is incorrect.

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2017-06-30 11:33:17 +03:00
Vinayak Kariappa Chettimada 2f29d7904f Bluetooth: controller: Fix hardfault, out-of-range ticker access
With the ticker for flash driver added, the Controller was
corrupting memory outside its allocations by incorrectly
using the flash ticker instance to be a BLE role and
corrupting memory. This is now fixed by checking for the
ticker ids to be within the Controller's use before using
them.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-29 16:54:34 +03:00
Johan Hedberg a5ae267e92 Bluetooth: Introduce new BT_LE_ADV_OPT_ONE_TIME advertising option
In some cases applications may want better control of advertising
instead of the stack doing automated re-enablement. Introduce a new
option that can be used to do more "manual" advertising control.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-29 15:08:00 +03:00
Johan Hedberg 3cb4d295d0 Bluetooth: Fix KEEP_ADVERTISING flag treatment in bt_le_adv_stop()
The BT_DEV_ADVERTISING flag already does a suffient job with tracking
the actual advertising state, so there's no need for bt_le_adv_stop()
to return an error if KEEP_ADVERTISING is set. We still need to clear
KEEP_ADVERTISING, but it should not be considered an error if it was
not set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-29 15:08:00 +03:00
Vinayak Kariappa Chettimada ed85dea358 Bluetooth: shell: Fix compile warnings when CONFIG_DEBUG=y
Fixed uninitialised auto variables, that had caused compile
errors under CONFIG_DEBUG=y.

Jira: Zep-2334

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-29 07:43:54 +03:00
Johan Hedberg 4040610244 Bluetooth: shell: Fix incorrect #define
This should have been upper case and not lower case.

Fixes: ZEP-2322

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-28 09:52:26 -04:00
Paul Sokolovsky 49eaa2b722 net: sockets: Explicitly flush conn/pkt queue on close()
If a socket is closed without reading all data from peer or accepting
all pending connection, they will be leaked. So, flush queues
explicitly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 6055b6cd6b net: sockets: Implement recv() for DGRAM sockets
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 2b4a240859 net: sockets: Implement recv() for STREAM sockets
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 41e88ea40c net: sockets: Implement send()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 7567962f3a net: sockets: Implement bind(), connect(), listen(), accept()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 386c5bacd1 net: sockets: Add configurable option to provide raw POSIX API names
With CONFIG_NET_SOCKETS_POSIX_NAMES=y, "raw" POSIX names like
socket(), recv(), close() will be exposed (using macro defines).
The close() is the biggest culprit here, because in POSIX it
applies to any file descriptor, but in this implementation -
only to sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 3432ff4fca net: sockets: Bootstrap Sockets API implementation
This adds Kconfig and build infrastructure and implements
zsock_socket() and zsock_close() functions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Vinayak Kariappa Chettimada 040b85bfbc Bluetooth: controller: Temporarily disable scan req notification
Temporarily, disable scan request notification reports when
LE Advertising Extensions feature is enabled; as support for
enabling scan request notification is not yet added to the
Controller's Link Layer interface functions, yet.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-28 15:00:47 +02:00
Andrzej Puzdrowski 9f964ba8d3 bluetooth: shell: add module for testing NRF5x flash driver
Intention is to test flash driver along with BLE radio.
Added flash shell module with commands for erase, write-check, read and
co-operation with radio stress test.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-06-28 12:29:50 +02:00
Andrzej Puzdrowski 7e6b9fa841 Bluetooth: controller: support for code exe. in co-operation with radio
Extend radio ticker nodes for support in-timeslice execution
Added interface for abort the radio
Added interface for check whether the radio is idle

Added interface for get ticker IDs for timeslice ticker node
Added interface for check whether radio ticker is running
Added interface for check whether radio ticker is initialized

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-06-28 12:29:50 +02:00
Carles Cufi 386c524f93 Bluetooth: controller: Keep track of IRK to RL indices
In order to associate a hit on the hardware IRK filtering with an entry
of the resolving list, add an array of correspondance between the IRKs
and the resolving list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 59ff81ca28 Bluetooth: controller: Add wl bit in resolving list
In order for some of the required checks in the ISR to be performed, we
need to keep track of which of the items in the resolving list are in
the whitelist as well. Track them using a single bit in the resolving
list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 4a016db283 Bluetooth: controller: Add device match ID radio API
In order to obtain the ID (index) of the device matched in a hardware
filter, a new API call has been added along with the required
implementation for nRF5x devices.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 1a07179a3c Bluetooth: controller: Generate RPAs for scanning and initating
Start RPA generation when enabling the scanner either for observing or
for initiating.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Vinayak Kariappa Chettimada 4ba2bb0d1c Bluetooth: controller: Be fair when pre-empting a ticker
When force scheduling a ticker use the number of times the
tickers have already skipped their intervals to decide if
the forced ticker can pre-empt the colliding ticker. This
introduces a fairness amongst tickers contesting for the
overlapping time slice.

Flashing in co-operation with Radio needs to be fair in
order to avoid connection supervision timeouts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Vinayak Kariappa Chettimada 95d55a2bfc Bluetooth: controller: Do not skip one-shot tickers with slot
In preparation towards mesh advertise implementation, avoid
one-shot tickers with slots, that have been scheduled to
expire, from being removed by a forced start or update
operation on another ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Vinayak Kariappa Chettimada 07270e52ba Bluetooth: controller: Coding style and refactoring
Refactoring of ticker implementation to conform to Zephyr
coding style.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Jukka Rissanen 92fa7ac6ce net: http: Remove mbedtls heap setting from http library
The global mbedtls heap is set automatically now so no need to
set it individually in the http library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-27 16:42:59 +03:00
Johan Hedberg 8f9c305a15 Bluetooth: Move PRNG initialization a bit later in HCI init
Move the PRNG initialization after reading local supported commands,
so that we don't send HCI_LE_Rand if the controller doesn't support it
(we still need to fail the init however). The patch also removes a few
unnecessary #ifdefs related to crypto.h.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-27 13:16:16 +03:00
Carles Cufi 0f0c45ce7c Bluetooth: controller: Optimize RL addition
To avoid iterating twice through the list, have ll_rl_find() return the
first free empty slot on the list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 2c1dbd21f4 Bluetooth: controller: Handle Privacy Modes
Add handling of the LE Set Privacy Mode HCI Command along with the logic
required to take it into account when populating the hardware filters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi bd31ad11de Bluetooth: controller: Add RL filter
In order for privacy to work correctly with and without peer IRKs, an
additional hardware filter is required to help match the peer device in
the case address resolution is not possible for a peer since the Host
has not provided a peer IRK for it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 343a916d48 Bluetooth: controller: Properly remove peer IRKs from RL
When removing a device from the resolving list, if it contained a peer
IRK then it is necessary to update the indices that point to the peer
IRK list, since the list itself is contiguous in memory.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 540a209085 Bluetooth: controller: Add whitelist population with privacy
When using privacy, an additional cache of the actual privacy peers is
required to avoid additional processing in the ISR (since some of the
peers in the whitelist will be disabled by the corresponding privacy
settings). Add the cache and populate the actual whitelist just before
advertising, scanning or initiating a connection.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 7df0ab780d Bluetooth: controller: Fix supported cmds and states
Properly use the role and feature Kconfig variables to populate both the
supported commands and the supported states in the controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-25 14:26:08 +03:00
Carles Cufi cb8be12595 Bluetooth: Fortify role dependency
Since the peripheral role depends on the broadcaster one, and the
central role depends on the observer one, select them automatically
instead of using defaults.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-25 14:26:08 +03:00
Robert Chou 7087162385 net: zoap: add missing response code for zoap_header_get_code()
Three response codes are missed in zoap_header_get_code() which will
result in the response code returned from the function being set as
ZOAP_CODE_EMPTY. Check include/net/zoap.h for the missing code
definition.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-06-23 16:04:00 -04:00
Johan Hedberg 9b1653061a Bluetooth: conn: Add pending tx before calling bt_send()
It's possible that the controller will emit the number of completed
packets event before bt_send() returns, or possibly preempt
send_frag() before it manages to call add_pending_tx(). We have to
therefore add the pending TX entry before calling bt_send().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-23 18:02:08 +03:00
Vinayak Kariappa Chettimada 3c23c6f53d Bluetooth: controller: Fix assert due to stale tick count
Fixed assert due to stale tick count in role event
preparation. This happens when ticker timeout expiry is
delayed from the requested realtime anchor, due to thread
mode processing overheads and occurring interrupts therein,
if any, that added a delay between requested anchor tick
and actual scheduling for the requested ticker timeout.

The assert is reproduced in bt shell by starting advertising
and following it with continuous scanning (interval 2.5ms,
window 2.5ms), on nRF51x. If the overheads and/or a
advertiser event delayed the scheduling of scanner by over
2.5ms, then the preparation of scanner asserted.

The assert has been fixed by checking for stale tick count
at expiry in role event preparation and skip the event
gracefully.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-23 16:02:54 +03:00
Carles Cufi 3707096d86 Bluetooth: controller: Correct adv, scan and init state checks
For whitelist and resolving list handling, avoid trying to start the
advertiser and scanner roles when they are already running.
Additionally, and since simultaneous scanning and initiating is not
supported, correctly report this to the host both in the supported
states and in the HCI command via an error code, instead of silently
disabling scanning.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-23 11:53:40 +03:00
Kumar Gala b0cbf1d455 Bluetooth: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00
Kumar Gala 7572203f54 Bluetooth: Fix use of uint32_t in nRF5 radio timings abstractions
We have conflicting types between the decleration and implementation of
several radio functions.  We should be using u32_t everywhere.  This
shows up when we try and build with newlib enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 12:19:01 -05:00
Vinayak Kariappa Chettimada 46f9489704 Bluetooth: controller: Add radio fast ramp feature
Added implementation to use nRF radio's fast ramp up mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-22 18:48:15 +03:00
Vinayak Kariappa Chettimada cd1fd05778 Bluetooth: controller: nRF5 radio timings abstractions
Added HAL Radio abstractions to use SoC specific Radio Timings
as documented in SoC's electrical characteristics.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-22 18:48:15 +03:00
Patrik Flykt ac07550566 net: context: Go back to LISTEN state when receiving RST
In LISTEN state ignore a TCP RST. In SYN RCVD state, reset TCP
connection state to LISTEN when a valid RST segment is received. In all
other states close the connection - except that these other states will
not be handled in tcp_syn_rcvd() function.

Jira: ZEP-2279

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-06-22 13:17:27 +03:00
Carles Cufi 851b214af0 Bluetooth: controller: Fix OCF data size
An OCF is a 10-bit value as defined by HCI, and therefore requires a
16-bit integer to store it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-21 15:33:16 +02:00
Vinayak Kariappa Chettimada 997b72d8dc Bluetooth: controller: Fix directed adv timeout and disable
Fixed assert due to incorrect implementation of stopping of
advertiser role under directed advertisement timeout, and
also, fixed assert due to adv stop ticker not being stopped
on advertisement disable from thread mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:40 +03:00
Vinayak Kariappa Chettimada 6616065e95 Bluetooth: controller: Add connect ind PDU address fields check
Added checks for advertiser and initiator/target addresses
received in CONNECT_IND when performing directed
advertising.

This is required to pass TP/CON/ADV/BV-04-C [Directed
Advertising Connection].

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:23 +03:00
Vinayak Kariappa Chettimada 8b74c98ed5 Bluetooth: controller: Fix conn context leak under directed adv
When directed advertisements timed out, connection context
associated was not being released. Subsequent connectable
advertising or connection creation failed.
This is now fixed by releasing the connection context on
directed advertisement timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-21 11:27:10 +03:00
Jukka Rissanen 210c30805b net: context: Close connection fast if TIME_WAIT support is off
If the CONFIG_NET_TCP_TIME_WAIT support is disabled, then do not
start to wait for reply to sent FIN in active close, but unref
the corresponding net_context in order to close the connection
as soon as possible.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-21 10:51:52 +03:00
Carles Cufi 89af682e88 Bluetooth: controller: Refactor whitelist handling (v2)
Refactor whitelist handling into generic filter management in
preparation for future resolving list ID address filters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 21:37:22 +03:00
Luiz Augusto von Dentz a6b37b072b Bluetooth: GATT: Rename bt_gatt_unregister_service
Rename bt_gatt_unregister_service to bt_gatt_service_unregister to be
consistent with other APIs such as bt_gatt_service_register.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-20 15:32:16 +03:00
Carles Cufi 4053470f62 Bluetooth: controller: Add inital support for Controller-based privacy
This initial commit adds the following:

* Handling of privacy HCI commands
* New Link Layer filter module for both whitelist and resolving list
* Advertising RPA generation with timeouts

Follow-up commits will expand the functionality.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Carles Cufi 1506b24fb8 Bluetooth: Correctly select RPA and TINYCRYPT options
Enforce the logical dependency between SMP, RPA generation and privacy
in the Kconfig files for the Bluetooth subsysem.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Carles Cufi 4307505e2d Bluetooth: controller: Rename mem function that checks all-zero mem
For consistency with the return value and to conform with other naming
schemes, rename mem_is_zero() to mem_nz().

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Andrew Boie 0f669132a0 kernel: remove gdb_server
This is unmaintained and currently has no known users. It was
added to support a Wind River project. If in the future we need it
again, we should re-introduce it with an exception-based mechanism
for catching out-of-bounds memory queries from the debugger.

The mem_safe subsystem is also removed, it is only used by the
GDB server. If its functionality is needed in the future, it
shoudl be replaced with an exception-based mechanism.

The _image_{ram, rom, text}_{start, end} linker variables have
been left in place, they will be re-purposed and expanded to
support memory protection.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-19 14:29:40 -04:00
Anas Nashif 397d29db42 linker: move all linker headers to include/linker
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-06-18 09:24:04 -05:00
Vinayak Kariappa Chettimada f4242b0723 Bluetooth: controller: Use find_lsb_set instead of custom ffs
Use globally available find_lsb_set in Zephyr instead of a
custom find first set function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-16 09:40:41 -05:00
Johan Hedberg 9703927f84 net: buf: Move net_buf_pool objects to dedicated linker area
Moving the net_buf_pool objects to a dedicated area lets us access
them by array offset into this area instead of directly by pointer.
This helps reduce the size of net_buf objects by 4 bytes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-16 17:05:06 +03:00
Jukka Rissanen 72567677e7 net: pkt: Fix net_pkt_split()
The net_pkt_split() was incorrectly checking fragA pointer
even before it was allocated.

The unit test is fixed and converted to ztest.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-16 17:05:06 +03:00
Luiz Augusto von Dentz 272b3a5c99 Bluetooth: Shell: Add gatt-show-db command
gatt-show-db shows the current set of attributes available in the GATT
database:

bt> gatt-show-db
attr 0x0011ce80 handle 0x0001 uuid 2800 perm 0x01
attr 0x0011ce94 handle 0x0002 uuid 2803 perm 0x01
attr 0x0011cea8 handle 0x0003 uuid 2a00 perm 0x01
attr 0x0011cebc handle 0x0004 uuid 2803 perm 0x01
attr 0x0011ced0 handle 0x0005 uuid 2a01 perm 0x01
attr 0x0011cde0 handle 0x0006 uuid 2800 perm 0x01
attr 0x0011cdf4 handle 0x0007 uuid 2803 perm 0x01
attr 0x0011ce08 handle 0x0008 uuid 2a05 perm 0x00
attr 0x0011ce1c handle 0x0009 uuid 2902 perm 0x03
attr 0x0011c9a0 handle 0x000a uuid 2800 perm 0x01
attr 0x0011c9b4 handle 0x000b uuid 2803 perm 0x01

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 01eeb5ea0b Bluetooth: Shell: Add gatt-unregister-service command
gatt-unregister-service can be used to remove the test service at
runtime causing service changed to be indicated:

00:1b:dc:07:31:88 (public)> gatt-unregister-service
[bt] [DBG] gatt_indicate: (0x0011e100) conn 0x0011d880 handle 0x0008
[bt] [DBG] bt_att_req_send: (0x0011e100) conn 0x0011d880 req 0x0011db00
[bt] [DBG] att_send_req: (0x0011e100) req 0x0011db00
Unregistering test vendor service

< ACL Data TX: Handle 3585 flags 0x00 dlen 11
      ATT: Handle Value Indication (0x1d) len 6
        Handle: 0x0008
          Data: 0a001000
> ACL Data RX: Handle 3585 flags 0x02 dlen 5
      ATT: Handle Value Confirmation (0x1e) len 0

Jira: ZEP-2225
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 3602590b9c Bluetooth: GATT: Add bt_gatt_unregister_service
With the introduction of Service Changed support it is now possible to
unregister services at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 79af35991b Bluetooth: GATT: Add bt_gatt_register_service
This adds bt_gatt_register_service using bt_gatt_service which contains
the attribute array that is then added to the database saving a pointer
in each and every attribute declared.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 79a723b3fa Bluetooth: GATT: Indicate Service Changed when a service is added
If the database is changed indicate the range changed to all peers
subscribed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz aa5b47fc3f Bluetooth: GATT: Add GATT service by default
GATT is mandatory service and now that the db can only be build
dynamically there is no reason to keep the applications registering it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz d837a6ec4b Bluetooth: GATT: Add GAP service by default
GAP is mandatory service and now that the db can only be build
dynamically there is no reason to keep the applications registering it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 6058c699b4 Bluetooth: Kconfig: Add CONFIG_BLUETOOTH_DEVICE_APPEARANCE
This makes applications able to select the value used for the
GAP appearance attribute.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz b3cfabab63 Bluetooth: Remove CONFIG_BLUETOOTH_GATT_DYNAMIC_DB
Removes CONFIG_BLUETOOTH_GATT_DYNAMIC_DB in preparation to the
introduction of bt_gatt_unregister.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 3910056505 Bluetooth: ATT: Fix adding timeout for NULL request
In certain cases a response may happen even before number of complete
packets is generated by the controller:

[bt] [DBG] att_req_destroy: (0x0011cfe0) req 0x0011daa0
[bt] [DBG] att_process: (0x0011cfe0)
[bt] [DBG] att_req_sent: (0x0011d780) conn 0x0011d820 att 0x0011d9a0
 att->req 0x00000000

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 19:26:50 +03:00
Vinayak Kariappa Chettimada 1dd5462320 Bluetooth: controller: Move scan response data swap outside tIFS
In preparation towards Privacy 1.2, move implementation that
swapped scan response PDU double buffer to same place as
where adv data PDU double buffer is swapped. So that, change
in AdvA in adv data PDU can be reflected in scan response
PDU buffer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 16:23:28 +02:00
Vinayak Kariappa Chettimada 799757a81f Bluetooth: controller: Avoid adv data set on ADV_EXT_IND PDU
Added fix to avoid adv data set function call from
corrupting a ADV_EXT_IND PDU under LE Extended Advertising.
Also, avoid redundant code execution under directed
advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 15:54:24 +02:00
Vinayak Kariappa Chettimada 0a1efac161 Bluetooth: controller: Fix ChSel bit be not used in ADV_EXT_IND
Only ADV_IND, ADV_DIRECT_IND, and CONNECT_IND PDUs can have
ChSel bit set in Advertising channel.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 15:54:24 +02:00
Carles Cufi 7d075f527b Bluetooth: Enforce cooperative priorities in Bluetooth threads
The Bluetooth subsystem assumes execution of its system threads in
cooperative priority, including the system workqueue and the thread
that interact with the controller (i.e. calling bt_send). This commit
adds a compile-time check for the system workqueue priority and
documentation for the bt_send API call.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-15 16:37:49 +03:00
Vinayak Kariappa Chettimada 8877348aec Bluetooth: shell: Fix compile error with LL cmds included
Fixed compile error due to the missing header file
dependency on bluetooth/hci.h, for bt_addr_le_t, in the
Link Layer header file.

Merge of PR #475 introduced the new dependency that broke
compilation after merge of #474.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 22:12:40 +02:00
Vinayak Kariappa Chettimada 66d9e11f93 Bluetooth: controller: Add ll_adv_scan_state_cb callback
Added a callback function ll_adv_scan_state_cb from the
Controller that gets called on either an advertiser or a
scanner getting started as the Controller's first enabled
state. The callback is also called on the Controller's
last disabled advertising or scanning state.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 17:42:27 +02:00
Vinayak Kariappa Chettimada ffc74034fb Bluetooth: controller: Fix missing reset of direct adv state
Fix missing implementation to reset the advertiser state
when directed advertisements stop without a connection being
established.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 17:42:27 +02:00
Vinayak Kariappa Chettimada dc11c9c315 Bluetooth: shell: Add Extended Scan command
Add shell scanx command to start Extended Scanning on 1M or
Coded PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada bedbd7fdee Bluetooth: controller: Extended scan for nconn nscan w/o aux
Update scanner implementation to receive ADV_EXT_IND PDUs.

Jira: ZEP-2238

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 128a0613cd Bluetooth: shell: Add LE Adv. Ext. advx command
Add Bluetooth Link Layer LE Advertising Extensions commands
for manual testing the feature during development. First one
being advx command to start non-connectable non-scannable
extended advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 03942483ec Bluetooth: controller: LE Adv. Ext. non-conn non-scan w/o aux
Add implementation to set extended advertising parameters,
start advertising Non-Connectable and Non-Scannable
Undirected without auxiliary packet.

Jira: ZEP-2238

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 51d6bdb2ff Bluetooth: controller: LE Advertising Extensions PDU structs
Add Bluetooth v5.0 LE Advertising Extensions air interface
packet structures.

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Carles Cufi 3b703288ae Bluetooth: controller: Handle reset atomic properly
In order to reuse code, the reset() function is used both to handle the
reset HCI command but also to initialize the internal HCI variables when
bringing up the system. In the latter case, avoid setting the reset bit
in the state atomic and signalling the polling API, since that is not
required during initialization.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-13 12:23:58 -04:00
Carles Cufi d0832f92fd Bluetooth: controller: Refactor whitelisting
As a preparation for advanced filtering (Controller-based privacy) this
commit refactors whitelisting so that it becomes its own module and
actually correctly performs state tracking to avoid modifying the
whitelist when it's in use.

Additionally it also removes the duplicate separate entries for
advertising and scanning, since the specification only allows one single
global whitelist singleton.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-13 12:22:43 -04:00
Vinayak Kariappa Chettimada d4fe898fe2 Bluetooth: controller: Add functions to get active filter policy
Add internal functions to read advertiser and scanner filter
policy if the roles are enabled. This is required to
restrict updates to whitelist and resolving lists when
filter policy are being used by the roles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 12:34:51 +02:00
Vinayak Kariappa Chettimada 08f3c62916 Bluetooth: controller: Reduce ll_adv struct size
Remove ll_adv struct members whose contents are stored in
PDU buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada faaa82fa5d Bluetooth: controller: Remove scan_ prefixes in scanner struct
Remove scan_ prefixes in scanner struct member names.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada 8eb9c8cea0 Bluetooth: controller: Fix advertiser context corruption
Under invalid host behavior, trying to start advertising
while already active would corrupt the advertiser context.
This is fixed by having an explicit flag to check whether
advertiser is already running.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada d577d3c450 Bluetooth: controller: Fix scanner context corruption
Under invalid host behavior, trying to start scanning while
already active would corrupt the scanner context. This is
fixed by having an explicit flag to check whether scanner is
already running.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada 19bccdd434 Bluetooth: controller: Use the term scanner in place of observer
Rename the use of the term observer in the controller to
the term scanner.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Vinayak Kariappa Chettimada e28323aed1 Bluetooth: controller: Fix non-scannable advertising mode
Under non-scannable advertising do not start a Rx window.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-13 11:59:41 +02:00
Leandro Pereira 9e329c7997 net: tcp: Remove fin_queued flag from struct net_tcp
This flag was set but never used.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-06-13 10:33:41 +03:00
Paul Sokolovsky 515788648a net: ip: Make struct in_addr::s_addr compatible with POSIX definition
From
http://pubs.opengroup.org/onlinepubs/7908799/xns/netinetin.h.html:

in_addr_t
    An unsigned integral type of exactly 32 bits.

[] the in_addr structure [] includes at least the following member:

in_addr_t      s_addr

In other words, POSIX requires s_addr to be a single integer value,
whereas Zephyr defines it as an array, and then access as s_addr[0]
everywhere. Fix that by following POSIX definition, which helps to
port existing apps to Zephyr.

Jira: ZEP-2264

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-13 10:32:03 +03:00
David B. Kinder 9faa5f2033 doc: spelling fixes in Kconfig files
regular spelling check on Kconfig.* files

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-06-12 19:40:51 -04:00
Jukka Rissanen c0682a9dca net: context: Init context state after unref
When the context is freed, we must set the state to UNCONNECTED.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-12 10:23:19 +03:00
Jukka Rissanen 35d28fb567 net: http: Connection close fix if old connection is active
If we receive a HTTP request and if the earlier context is still
active and it is not the same as the new one, then close the earlier
one. Otherwise it is possible that the old context will be left into
TCP ESTABLISHED state and would never be released. Example of this
is that we had IPv4 connection active and then IPv6 connection is
established, in this case we will disconnect the IPv4 connection
after this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-12 10:23:19 +03:00
Leandro Pereira 87ccb79a7a net: lib: dns: Check return value of net_context_recv()
Given that K_NO_WAIT is passed as a timeout to net_context_recv(), it's
unlikely this function will return any error value.  It's cheap to
check, though, so do it.

Coverity-CID: 170580
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-06-12 10:21:38 +03:00
Luiz Augusto von Dentz a04d22c6d8 net: shell: Remove code adjust arguments
The shell takes care of removing the module name so it is no longer
necessary to have this adjustment.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Luiz Augusto von Dentz 81cc89189b shell: Adjust arguments when executing a command of different module
The command callback might not recognize commands if the input comes
with the module name as first parameter as both argc and argv will be
off by one.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Luiz Augusto von Dentz 417dc03aad shell: Return proper errors if the command fails
If the command cannot be execute code should return a proper since this
may not be a user input.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Luiz Augusto von Dentz 1a8cd31d64 shell: Add shell_exec
This adds shell_exec which can be used to execute commands directly
without the use of a console which is useful for both testing as well
as interfacing with applications/upper layer which would like to have
access to shell commands directly.

In addition to that this may be more trivial to interface with instead
of using fifos like uart_register_input and telnet_register_input do.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-09 18:54:27 -04:00
Andrew Boie 567c6c7683 misc: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Tomasz Bursztyka 3a025544a1 ieee802154: Realign structure bitfields
Unsigned integer name change messed up the alignement of the size in
bitfields.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-06-09 13:19:50 +03:00
Jukka Rissanen 286139e13b net: tcp: Check pkt before sending RESET
In certain TCP states we should not try to send RESET segment
to peer. So check this and do not try to use NULL pkt to send
a message.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:37 +03:00
Jukka Rissanen fc125e0e2c net: shell: Add HTTP server connection monitoring
The "net http monitor" command turns on HTTP monitoring,
which means that for each incoming HTTP or HTTPS request,
a information about source and destination address, and
the HTTP request URL is printed.
User can disable the monitoring by "net http" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:10 +03:00
Jukka Rissanen e3ba68881d net: shell: Show HTTP connection information
The "net http" command will print currently active HTTP
connections in the HTTP server.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:10 +03:00
Jukka Rissanen ab51f67e17 net: http: Collect HTTP server connection information
If CONFIG_NET_DEBUG_HTTP_CONN is enabled, then start to collect
currently active HTTP connections to HTTP server.

This is only useful for debugging the HTTP connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:10 +03:00
Vinayak Kariappa Chettimada d055252ea9 Bluetooth: controller: Restrict enc to 1M 27 bytes PDU on nRF51
Restrict encryption support on nRF51 series SoC to Bluetooth
LE 1M PHY and max. 27 bytes PDU. If 251 bytes PDU using Data
Length Update procedure is desired, then LE Encryption
procedure will not be supported (until a software CCM is
implemented in future).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Vinayak Kariappa Chettimada ebd94f06b5 Bluetooth: controller: Cond. compile LE Encryption
Add Kconfig option to be able to conditional compile the
Bluetooth v4.0 LE Encryption procedure.

This is needed in order to be able to not support encryption
on nRF51 series when using Data Length Update procedure with
upto 251 byte payloads until a software-based CCM support is
implemented.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Jukka Rissanen 447193c959 net: context: Print error code if sending fails
If we cannot send network data, then print the error code when
printing debug information about the issue. This is needed when
debugging the issue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 7812569e0f net: context: Add debug print when context is freed
This is useful info to have when debugging.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 1b82463dee net: http: Add HTTPS client support
Add HTTPS support into http-client library. The init of the
HTTPS client connection is different compared to HTTP client,
but the actual HTTP request sending is using the same API as
HTTP client.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 0d43bbfb77 net: http: Move heap init into net/lib/http/http.c
This is done so that both http_client and http_server functionality
can share the same heap.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Anas Nashif 3405607d9e license: add missing licenses and copyright
We were missing license boilerplate in many files, add them

Jira: ZEP-1464

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-06-08 10:41:56 -04:00
Ravi kumar Veeramally 7a01988c64 net: 6lo: Fix source address uncompression
When src and dst addresses are compressed based on context
information, uncompression method should verify CID bit,
SAC and DAC bits and context ID's. But it has missed some
cases which resulted in invalid uncompressed IPv6 header.

e.g. CID is set, SAC is 0 and DAC is 1 and context id's provided.
Uncompression method assumed that src address is compressed based
on context information but it is not.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-06-06 09:06:01 -04:00
Ravi kumar Veeramally 4a8a42f9dd net: rpl: Update RPL header
Empty RPL HBH header will be inserted while finalizing IPv6 packet
but updated after finding nexthop and sent the packet. In case of
Bluetooth or multicast dst address it was missed. Resulted in
empty RPL HBH header and packet dropped at peer node. It should
be updated in all circumstances.

Jira: ZEP-2088

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-06-06 09:06:01 -04:00
Jukka Rissanen 2e2ce3120a net: https: Allow mbedtls debugging for https-server
The mbedtls debugging function was set before the ssl config
struct was initialized. This meant that it was not possible
to activate mbedtls debug prints. This commit sets the debug
print option after the config struct has been initialized.

Fixed also the debug prints which print extra \n which looks
very bad in debugging outputs.

This commit does not enable mbedtls debugging, it just makes it
possible to output mbedtls debug prints. In order to get mbedlts
debug prints one needs to do this:
* set DEBUG_THRESHOLD to >0 in http_server.c
* enable CONFIG_NET_DEBUG_HTTP in project config file
* enable MBEDTLS_DEBUG_C in mbedtls config file (see file pointed
  by CONFIG_MBEDTLS_CFG_FILE option)
* in qemu, one needs to increase the size of the available RAM,
  this setting does the trick, CONFIG_RAM_SIZE=300

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-06 09:32:52 +03:00
Paul Sokolovsky 08a2c6019c net: context: Operations on unused context should lead to EBADF.
Semantics of ENOENT error as used previously is "named entity not
found", whereas for "I/O handle is not valid", there's EBADF. For
example, POSIX/SUSV2 doesn't even list ENOENT as a possible error
for accept(), connect(), recv(), etc. whereas it lists EBADF, e.g.:
http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-05 10:32:28 +03:00
Vinayak Kariappa Chettimada 0998cdfba1 Bluetooth: shell: gatt-write-without-response with repeat
Add a repeat param to gatt-write-without-response so that
it covers what gatt-write-without-response-repeated was
doing. gatt-write-without-response was removed in the
commit 26eae70da.

gatt-write-signed too will have repeat param with this
change.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-04 09:34:08 +03:00
Andrei Emeltchenko f1f5275779 bluetooth: Allow to specify Logging Domain
At the moment all bluetooth logs are prefixed with [bt] making it
difficult to understand where the logs belong to.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-06-02 21:52:17 +03:00
Jukka Rissanen 2b6ebc0876 net: tcp: Timeout memory allocations
Instead of waiting forever for a free net_buf, set a timeout to
the allocations (500 ms). This way the application will not be
blocked by memory exhaustion.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-02 12:43:52 +03:00
Jukka Rissanen bd7d1bda20 net: http: Avoid unnecessary net_pkt error print
In some cases the net_pkt can be null when freeing it,
this will print error from net_pkt library. Avoid this by
checking the value of net_pkt before calling net_pkt_unref().

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-02 12:43:52 +03:00
Jukka Rissanen c9e6ef5331 net: http: Use random source port when connecting
If we re-connect to same peer server, then we should select a new
source port. Noticed that if the same source port as before is
used for the new connection, the peer might drop the packet. This
was seen when connecting to Linux peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-02 12:43:52 +03:00
Leandro Pereira 985d6c3f4b net: tcp: Limit number of segment retransmissions
Defines a new tunable, CONFIG_NET_TCP_RETRY_COUNT, that determines the
number of segment retransmissions that the IP stack will attempt to
perform before resetting the connection.

The default value is 9 retransmissions, which amounts to 1:42 minutes,
as close as possible to the minimum recommended by RFC1122.

Jira: ZEP-1956, ZEP-1957

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-06-02 12:36:05 +03:00
Johan Hedberg 67faa3fe98 Bluetooth: L2CAP: Remove redundant checks for chan->ops
It's mandatory to set chan->ops so explicit checks for it are
redundant. What's worse, inconsistent checking for this triggers
static code analyzer warnings. This patch fixes Coverity CID 151984.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-01 15:09:16 +03:00
Jaganath Kanakkassery 7ac75784d1 Bluetooth: SDP: Fix possible out of bound memory access
buf->len should be validated before accessing it since remote can
send invalid frame_len which can result in out of bound memory
access.

This also fix the len check wrt cstate, since current check is
not considering the cstate length size and frame_len size.

Jira: ZEP-2110
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-06-01 12:36:09 +03:00
Vinayak Kariappa Chettimada a3cba8bb90 Bluetooth: shell: Add controller's ticker shell module
Added shell module for the Bluetooth Controller's ticker
interfaces.

For now, info command enumerates active tickers' details.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-01 12:32:47 +03:00
Ruslan Mstoi 39e37ab2ab net: ipv6: Skip unknown options in NA message
If we receive unknown option in neighbor advertisement message,
then skip those properly. Old code did not check the length of
the extension options which could cause infinite loop.

Jira: ZEP-2219

Signed-off-by: Ruslan Mstoi <ruslan.mstoi@intel.com>
2017-06-01 09:36:24 +03:00
Jukka Rissanen 010b892c8a net: http: Parsing state was not cleared
If we received a bad HTTP request, then subsequent good requests
were also returning 400 error code. The parsing state needs to
be initialized after each received HTTP request.

Jira: ZEP-2181

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-31 14:54:06 -04:00
Leandro Pereira 111244923c ieee802154_shell: Only accept channels within expected range
Fixes the following issue:
	"In expression 1UL << chan - 1U, left shifting by more than 31
	bits has undefined behavior.  The shift amount, chan - 1U, is
	4294967295."

Coverity-CID: 167140
Jira: ZEP-2131
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-05-31 13:17:14 -04:00
Siddharth Chandrasekaran faaf859a46 shell: Add 'exit' command to leave a module
In console shell, add explicit, 'exit' command to leave the current
module. Currently this is being achieved by overloading select command
(without an argument).

Signed-off-by: Siddharth Chandrasekaran <siddharth@embedjournal.com>
2017-05-30 20:45:55 -04:00
Luiz Augusto von Dentz da86ae0cb6 Bluetooth: Shell: Rework gatt-write-signed
This makes gatt-write-signed to reuse cmd_gatt_write_without_rsp since
it is quite similar and that adds the ability to send multiple octecs
instead of just a single byte.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz a5aa904f90 Bluetooth: Shell: Fix help of gatt-write-signed
gatt-write-signed does not have an offset parameter.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 26eae70da2 Bluetooth: Shell: Remove gatt-write-without-response-repeated
This removes gatt-write-without-response-repeated and makes
gatt-write-without-response similar to gatt-write which was the
intention of gatt-write-without-response-repeated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 6107f61d8c Bluetooth: Shell: Fix help of gatt-write-without-response
gatt-write-without-response does not have an offset parameter.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 6abccb6d40 Bluetooth: Shell: Split GATT command to its own file
This makes it simpler to organize the GATT command implementation.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 54d917f767 Bluetooth: Shell: Add shell subdir if CONFIG_BLUETOOTH_SHELL=y
All the files under shell subdir shall only be build if
CONFIG_BLUETOOTH_SHELL is selected.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 7b9013140d Bluetooth: GATT: Fix not queuing writes to CCC
In order to properly queue request there need to be a bt_att_req
storage but none of the calls to gatt_write_ccc were using the params
causing gatt_send to use bt_att_send and not bt_att_req_send.

To fix this now all the callers of gatt_write_ccc do set the params
properly but this means that bt_gatt_unsubscribe has to wait for it
to be completed before the application can reuse the
bt_gatt_subscribe_params.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 14:34:11 +03:00
Jukka Rissanen df38a21ad3 net: shell: Enhance IPv6 fragmentation debugging prints
Print also network buffers that are allocated by the IPv6
fragment handler. This is very useful in debugging.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Jukka Rissanen 150df7dc53 net: ipv6: Make max number of fragmented pkt configurable
If the user really wants, it is possible to increase the
maximum size of the fragmented packet. According to RFC 2460
chapter 5, we do not need to accept larger than 1500 byte IPv6
packets, so the max pkt limit is set to 2. But if really needed
the limit can be raised by defining NET_IPV6_FRAGMENTS_MAX_PKT
to some new value. Currently there is no Kconfig option for
doing this as it is unlikely that this is needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Jukka Rissanen 2872e15c72 net: ipv6: Fix fragmentation cancellation
The cancellation of reassembly did not work as expected because
K_WORK_INITIALIZER() did not setup the timeout function properly.
So do the timer initialization at runtime instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Jukka Rissanen 27d85e6cf7 net: ipv6: Fix the IPv6 packet fragmentation sending
The IPv6 fragmentation was not working properly when the large
IPv6 packet was being sent. There is unit tests in next commit
that will test the IPv6 fragmentation sending.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Jukka Rissanen cef53bff11 net: ipv6: Memory leak during fragment reassembly
If the fragmented IPv6 packet was very large, we could run out
of resources. When that happened, we leaked the memory for the
pending fragments that were waiting reassembly.

Jira: ZEP-2166

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Jukka Rissanen 329579f5b1 net: ipv6: Default reassembly timeout set to 5 sec
The previous default 60 seconds is way too long for our limited
amount of memory. It might be that the 5 sec is still too long
but that can be changed in the future.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-30 11:21:51 +03:00
Vinayak Kariappa Chettimada 5d91b2ffe9 Bluetooth: controller: Explicitly compare radio event registers
While returning 32-bit values from radio status interfaces,
explicitly compare radio h/w event registers to be non-zero,
dont just return the direct 32-bit h/w register content.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-30 11:13:30 +03:00
Vinayak Kariappa Chettimada 05ad68b353 Bluetooth: controller: Add extra assert checks
Added extra assert checks to detect controller failure if
a role event preparation function was not followed by the
role event start function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-30 11:03:05 +03:00
Luiz Augusto von Dentz fe168789cc net: shell: Remove extra help command
Shell itself already have a help command, so instead of creating a net
specific help just fill the help description of each command.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 09:18:33 +03:00
Luiz Augusto von Dentz 0c7bf93cc7 net: shell: Move SHELL_REGISTER out of net_shell_init
Shell modules are registered at link time thus it makes no sense to
leave it behind net_shell_init.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 09:18:33 +03:00
Jukka Rissanen eeaa29666b net: http: Handle HTTPS connection closing gracefully
If the HTTPS connection is closed, then properly handle call to
HTTP parser init in case of error and also remove any pending
data that belong to old connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-29 23:50:33 +03:00
Jukka Rissanen cb1873654c net: ipv6: Skip unknown options in NS message
If we receive unknown option in neighbor solicitation message,
then skip those properly. Old code did not check the length of
the extension options which could cause infinite loop.

Jira: ZEP-2174

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-29 23:48:53 +03:00
Jukka Rissanen 23676369f7 net: pkt: Handle out-of-mem case properly
If we could not split the packet properly, make sure that the
fragments that we managed to allocate are unreffed and marked
as NULL.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-29 23:48:25 +03:00
Jukka Rissanen 3084c889a1 net: Print characters in hexdump
Print also the character when hexdumping a memory area.
This is useful so that one does not need to convert hex
values to characters in head. Unprintable chars are printed
as '.'

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-29 23:47:30 +03:00
Johan Hedberg a7ebfa948b Bluetooth: ATT: Fix canceling ATT timeout upon response
For some write requests, such as CCC, the code doesn't use an ATT
request context but we still need to clear the request timeout when
the response comes. Move the k_delayed_work_cancel() call to the right
place and add some debug logs that helped pinpoint this issue.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-29 21:50:34 +03:00
Johan Hedberg 8068b9ad65 Bluetooth: ATT: Improve response logging
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-29 21:50:34 +03:00
Vinayak Kariappa Chettimada fe3aeebcfa Bluetooth: shell: Fix scan on to use active scanning
Both scan on and scan passive performed passive scanning,
fixed scan on command to use active scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 18:21:36 +03:00
Johan Hedberg 1e5cd1c69b Bluetooth: Add kernel call stack analysis upon disconnection
It's useful to see all stack usages and not just the Bluetooth
internal ones.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-29 17:31:30 +03:00
Vinayak Kariappa Chettimada c3e674071d Bluetooth: controller: Fix failing fast encryption setup feature
In commit c41d3edda when implementing the alternative
encryption setup implementation, the original fast
encryption setup implementation was broken. When host is
slow in responding to LTK request, the controller asserted
when fast encryption implementation is selected. This is
now fixed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 17:31:04 +03:00
Vinayak Kariappa Chettimada 3a2ff7b08c Bluetooth: controller: Fix CSA#2 assert
Fix the assert in the controller during connection setup
when peer does not support CSA#2 feature and free Rx buffer
queue does not have enough buffers to generate CSA event.

The assert was reproduced by turning on advertisement
indication and scan request notification features in the
controllers advanced features, and a peer that does not
support CSA#2 initiated a connection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 17:30:44 +03:00
Carles Cufi 5d38c99761 Bluetooth: Consolidate all role configuration
Since role support is fundamental to both the Host and the Controller,
move the role configuration options to the top-level file and rename
them to fit the GAP specification, avoiding confusion between GAP and LL
names.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Carles Cufi 3e3a47dfef Bluetooth: controller: Conditionally include conn-related options
Only include connection-related options when CONFIG_BLUETOOTH_CONN is
selected, since otherwise this can lead to inconsistencies between
features and supported commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Luiz Augusto von Dentz 737a9dc306 Shell: bt: Use SHELL_REGISTER_WITH_PROMPT
This replaces the use of shell_register_prompt_handler with
SHELL_REGISTER_WITH_PROMPT which doesn't overwrite other modules
prompt.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz 6213730154 Shell: Add SHELL_REGISTER_WITH_PROMPT
This enables modules to define its own prompt handler instead of always
using the default_module_prompt.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz 12d1b2aa32 Shell: bt: Fix build without CONFIG_BLUETOOTH_GATT_CLIENT
If CONFIG_BLUETOOTH_GATT_CLIENT is not defined disable command that
would depend on it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz a6f75bebc7 Shell: bt: Add command supported by btshell
This adds existing commands support by btshell test application to bt
module.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz 1c4561925c Shell: Add initial code for bt shell module
This adds the config option and files of the bt shell module.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Johan Hedberg 6597896f0a Bluetooth: Fix missing test for BLUETOOTH_CONN with DLE
There's no point in doing anything about DLE if connection support is
not enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-28 16:12:18 +03:00
Carles Cufi d6513eeda3 Bluetooth: controller: Increase RX prio stack size
Due to several changes in the way stacks are calculated, 320 bytes is no
longer enough for the controller-only build. After measuring usages of
up to 320 bytes (locally) and 376 (reported by Ricardo Salveti), the
stack size is increased by 128 bytes, up to 448 bytes.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-26 08:51:04 -07:00
Johan Hedberg a61cf369bf Bluetooth: AVDTP: Remove dead code
The msgtype value is created using 'hdr & 3' which means that the
resulting value can never be greater than 3. This fixes Coverity CID
166771.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-25 09:14:05 -07:00
Jukka Rissanen 4f68e32b8a net: zoap: Remove extra null checks
No need to check attr and path variables for null as they
cannot be null.

Coverity-CID: 157595
Coverity-CID: 157602

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-25 18:50:40 +03:00
Jukka Rissanen 3677caa37e tests: net: zoap: Add path uri matching tests
Test the match_path_uri() function that was fixed by previous
commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-25 18:49:56 +03:00
Jukka Rissanen 7bed585c42 net: zoap: Fix NULL pointer access
The code was setting pointer to null and then access it.

Coverity-CID: 157575

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-25 18:49:56 +03:00
Vinayak Kariappa Chettimada a730686b7d Bluetooth: Auto-update LE data length to max. supported
Added implementation to auto-update LE Data Length to max.
Tx octets supported by the local and peer controllers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada c6dd9d5ef6 Bluetooth: controller: Handle Rej Ext Ind for Length Req PDU
Added implementation to handle an incoming Reject Ext Ind PDU in
response to a sent Length Req PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada a2a364bac4 Bluetooth: controller: Fix DLE crossover assert
When initiating Data Length Change at the same instant the
crossover condition was not handled correctly causing the
controller to assert.

This fix will allow crossover of Data Length Update
procedure, and this collison is harmless as per Bluetooth
specification, and gracefully handled by the controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada dac861be99 Bluetooth: controller: Add HCI Tx buffer overflow return code
Return error codes for HCI Tx buffer overflow conditions are
missing which would lead to silent dropping of Tx packets if
host implementations do not follow number of completed packets
or use correct buffer counts as returned by HCI Read Buffer
Size command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:15:47 -07:00
Jukka Rissanen 31faeca511 net: http: Add timeout to HTTP server response
Allow the caller to delay the closing of the HTTP connection
for a number of milliseconds. The purpose for this is that
the client can send still some data back to us for a short
period of time.

This is needed for example for Basic authentication so that
server is able to receive authentication values back.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-23 18:01:04 +03:00
Paul Sokolovsky 6b5a7238b2 subsys: console: Fix signed vs unsigned char issues.
May lead to warnings/errors with pedantic compilers (like LLVM).

Jira: ZEP-2170

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-22 08:43:31 -05:00
Vinayak Kariappa Chettimada ed187ebccd Bluetooth: Fix auto PHY update on connection
Since the PHY update complete event can be generated due to the
procedure being initiated by the peer, use a flag to
differentiate between local auto update initiated on connection
complete versus peer initiated anytime in the connection. This
is necessary to avoid repeated initiation of auto-update
procedures intended only to be issued on connection complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-19 20:01:34 +03:00
Jukka Rissanen 6ed7fb05d0 net: dhcpv4: Properly register UDP handler
The address family of the UDP port listener was not set. This
caused weird debug prints in net-shell. Now the listener will
be registering IPv4 any address as it should.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-19 14:56:22 +03:00
Jukka Rissanen dea9b2b6c3 net: conn: Check connection address family properly
When a connection handler was registered, the checker function
introduced in commit 43b37cef ("Check duplicate UDP/TCP connection
handlers") did not check the address family (IPv4 or IPv6) of
the local end point properly. This caused duplicate connection
error to be returned to the caller.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-19 14:55:40 +03:00
Mateusz Hołenko 634f875e19 net: 6lo: Fix handling SAM_00 mode for packets with context
The uncompressed source address in packets was not handled properly if
NET_6LO_CONTEXT was enabled.

This implementation is identical to the contextless case.

Signed-off-by: Piotr Zierhoffer <pzierhoffer@antmicro.com>
2017-05-18 15:11:05 +03:00
Jukka Rissanen f3c47f29ff net: tcp: Fix comment when ACK timeouts
The comment describing ACK timeout in LAST_ACK state had
typos and was a bit unclear.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 15:08:12 +03:00
Jukka Rissanen 1725c1efab net: tcp: Print current state when ACK timeouts
For debugging purposes it is important to know what state we
are when ACK timeouts.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 15:08:12 +03:00
Jukka Rissanen 48f9dccc32 net: tcp: Allow ACK timeout to be configured
The timeout value when waiting ACK in various TCP states can
be configured via Kconfig.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 15:08:12 +03:00
Jukka Rissanen 27b5540118 net: tcp: Set timer for last ACK
If we do not receive last ACK when the connection is tore down,
then do not wait forever as that would eat all the resources in
the network stack. So when we enter the LAST_ACK state, we setup
a timer that will unref the connection if the last ACK is not
received.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:56:39 +03:00
Paul Sokolovsky d6b93b311f net: tcp: When sending FIN, make sure it goes with ACK and proper seq
Without change to add ACK to FIN, invalid TCP packet is generated,
where ack sequence number is non-zero. Without adjusting sequence
number as done, ACK which we send in response to peer's FIN/ACK is
not recognized by peer, and peer keeps retransmitting its FIN/ACK.

Jira: ZEP-2104

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-18 10:56:11 +03:00
Jukka Rissanen 6f25eb097e net: conn: Remove unregistered connection from cache
When connection handler was unregistered, we did not remove
it from cache. This caused invalid connection to be passed to
net_context after connection unregister if connection caching
was enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:55:17 +03:00
Jukka Rissanen 69b25c0788 net: conn: Check UDP and TCP checksum before accepting packet
We did not check UDP or TCP checksum to be valid after receiving
the packet. Fix this so that the checksum is validated when
packet is received in connection handler. As the checksum validation
can be resource intensive, do it after we have verified that
there is a connection handler for this connection.

The checksum calculation can be turned OFF if needed, but it is
ON by default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-18 10:53:39 +03:00
Jukka Rissanen 6c60603a9f net: context: Shorten too long line
The commit "net: tcp: Handle retransmitted packets from peer"
introduced over 80 character line that was missed in review.
Fixing it now.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 16:55:02 +03:00
Jukka Rissanen bddacf6a7f net: stats: IPv6 multicast listener daemon stats not printed
The MLD statistics were collected but never printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen e5257ae790 net: stats: Activate RPL and MLD stats if needed
If user has enabled RPL and STATISTICS, then enable RPL
statistics by default as that is probably what user want.
Same thing for MLD statistics.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen 9f1c7ffa5d net: stats: Add UDP checksum stats update function
A function updating UDP checksum failure statistics was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Jukka Rissanen e253dcbd3b net: tcp: Add TCP statistics support
We did not collect any TCP statistics before but this commit
changes that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Paul Sokolovsky 7a1a9a7946 net: tcp: Handle retransmitted packets from peer.
When we receive a packet with the sequence we already seen (and
processed), the most likely cause of it is that our ACK was lost,
and peer has to retransmit that packet. Then, we should just ACK
it, because otherwise peer will retransmit it again and again,
falling into exponential backoff and hosing the entire TCP
connection.

This makes changes to send_ack(), adding a flag to force sending
an ACK regardless of its cached status, and remove inline modifier,
as the function is big and called from many places.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-17 10:34:11 +03:00
Jukka Rissanen c6fcda19a3 net: tcp: Always set ACK bit in RST packet
Set the ACK bit in every RST packet as that seems to be expected
by Linux for example.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 09:36:02 +03:00
Jukka Rissanen 00b4081da3 net: tcp: Handle case when RST is received in any state
We must check if we receive RST in any of the TCP states.
If we do not do this, then the net_context might leak as it
would never be released in some of the states. Receiving RST
in any TCP state is not described in TCP state diagram but is
described in RFC 793 which says in chapter "Reset Processing"
that system "...aborts the connection and advises the user and
goes to the CLOSED state."

We need to also validate the received RST and accept only those
TCP reset packets that contain valid sequence number.

The validate_state_transitions() function is also changed to
accept CLOSED state transition from various other states.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 09:34:51 +03:00
Vinayak Kariappa Chettimada e858f8db05 Bluetooth: controller: Increase Rx & Tx buf cnt range in Kconfig
With the support for 2M PHY added, the controller can now Rx/Tx
upto 18/19 minimum sized L2CAP packets per 7.5ms connection
intervals.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-16 15:30:51 +03:00
Paul Sokolovsky e4a5e35b28 net: if: net_if_get_default: Return NULL if no interfaces configured
net_if_get_default() was documented as returning "Default interface
or NULL if no interfaces are configured.", but actually didn't
return NULL in the latter case. Instead, it effectively returned
a pointer to random area of memory, shared with other system
structures, so calling functions like net_if_ipv4_set_netmask(),
etc. could trash unrelated memory.

Jira: ZEP-2105

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-16 14:32:58 +03:00
Paul Sokolovsky 72a30f3843 net: tcp: Add TCP sequence number comparison compliant with RFC793.
RFC793, "Transmission Control Protocol", defines sequence numbers
just as 32-bit numbers without a sign. It doesn't specify any adhoc
rules for comparing them, so standard modular arithmetic should be
used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-16 14:29:17 +03:00
Paul Sokolovsky 3cb13b9687 subsys: console: Add buffered output support to console subsystem
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-15 15:56:56 -04:00
Carles Cufi 6d1ea67144 Bluetooth: hci_core: Log incoming LE Meta Event's subevents
To better debug the flow of events into the Host, log the subevent code
whenever processing an LE Meta Event.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-15 21:02:44 +03:00
Vinayak Kariappa Chettimada 14365080d2 Bluetooth: l2cap: Fix initial credit calculaton for MTU < MPS
When required Rx MTU is less than configured Rx MPS, the
resultant initial credits was 0 which prevented any L2CAP
packet to be received.

Fixed by ceiling the initial credits count in the credits
calculation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-14 09:57:13 +03:00
Andrew Boie 5dcb279df8 debug: add stack sentinel feature
This places a sentinel value at the lowest 4 bytes of a stack
memory region and checks it at various intervals, including when
servicing interrupts or context switching.

This is implemented on all arches except ARC, which supports stack
bounds checking directly in hardware.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-13 15:14:41 -04:00
Youvedeep Singh 1da0a9eebd cdc_acm : Restrict writing more than 4 bytes into TX USB Endpoint.
Sometime it is observed on the Arduino 101 that when we write more than
4 bytes into TX USB Endpoint, first 4 bytes are getting repeated
(frequency of occurrence ~1/3000).

This patch does following :-

1. In sample application "cdc_acm", it adds capability to
handle partial transfer data incase data is transferred partially
if exceeds maximum data transfer size.
2. It restricts write of more than  4 bytes into TX USB Endpoint.
This is work around to  avoid issue occarance.

Jira: ZEP-2074

Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-05-13 15:12:27 -04:00
Jukka Rissanen a174d2eba7 net: http: Add HTTP server library support
This commit creates a HTTP server library. So instead of creating
a complex HTTP server application for serving HTTP requests, the
developer can use the HTTP server API to create HTTP server
insteances. This commit also adds support for creating HTTPS servers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Jukka Rissanen 43b37cef31 net: conn: Check duplicate UDP/TCP connection handlers
When a new UDP or TCP connection handler is to be registered,
we need to check if identical handler has already been created.
If a duplicate is found, the registering call will return -EALREADY.

The earlier code did not check this but allowed two identical
handlers to be created. The latter handler was never called in
this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Jukka Rissanen c77460da53 net: pkt: Add function to linearize a network packet
This helper copies desired amount of data from network packet
buffer info a user provided linear buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Vinayak Kariappa Chettimada a891415d97 Bluetooth: Print PHY update complete with status
When HCI core debug is enabled, print PHY update complete
with status on console.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-13 15:27:24 +03:00
Vinayak Kariappa Chettimada dbdc8a24b0 Bluetooth: kconfig: Use menu instead of menuconfig
To be consistent with other subsystem menu, use menu for
Bluetooth support in Kconfig instead of menuconfig which
showed up as checkbox.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-13 09:01:47 +03:00
Carles Cufi ef2aecefda Bluetooth: Move hci_uart UART Kconfig to the top-level file
To allow for hci_uart builds that do not include the controller code,
move the UART Kconfig option used by the sample up one level so that it
is shared by all configurations using Bluetooth:

Jira: ZEP-2132

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 15:26:41 +03:00
Vinayak Kariappa Chettimada 3e0f72d7cc Bluetooth: controller: Fix missing PHY update cond. compilation
Added a missing conditional compilation #if-#endif that caused
compilation error when PHY update feature was deselected.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-12 13:55:39 +03:00
Carles Cufi 6c9e563c92 Bluetooth: Move common code to common/
Since more and more code is going to be reused by both the Host and the
Controller, this commit introduces a common/ folder that will contain
everything that is not tied to one of the two components but shared by
them.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 12:56:14 +03:00
Andrew Boie b4e3799831 usb: mass_storage: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Andrew Boie 77d1f1d232 shell: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Andrew Boie 7a0782d8ee net: use k_thread_create()
Common code in include/misc/stack.h is now used for analysis.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Andrew Boie 899cf94dbd bluetooth: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Vinayak Kariappa Chettimada 0187280aa8 Bluetooth: controller: Revert cleanup redundant ticker busy loop
This reverts commit 698de88916 ("Bluetooth: controller:
Cleanup redundant ticker busy loop")

Scan enable asserted in ctrl.c line 3756 due to the fact that a
role event was active and ticker job has hence been disabled.
Add back the busy loop so that scan enable can wait until the
active role event completes gracefully.

The ticker busy loop is mandatory in all ticker interface calls
if a blocking behavior is desired.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-11 11:53:53 +03:00
Michael Scott 774567ea14 Bluetooth: controller: remove dup code in packet_rx_reserve_get()
The calculation in packet_rx_reserve_get() was already handled by
packet_rx_acquired_count_get().  So, let's use that code instead
and remove the duplication.

Change-Id: Ic76f70f1e78bebc74f5bef36cd92a3c332e489e9
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Michael Scott 667a40a181 Bluetooth: controller: nix #ifdefs from packet_rx_acquired_count_get()
This calculation can be used in packet_rx_reserve_get() where currently
the code is duplicated from packet_rx_acquired_count_get().
Let's allow use of packet_rx_acquired_count_get() regardless of whether
CONFIG_BLUETOOTH_CONTROLLER_DATA_LENGTH is enabled.

Change-Id: I613bde0a407f3caccabb22f369098575965e98ad
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Michael Scott 5699af2af0 Bluetooth: controller: verify DLE req_rsp has valid values
During testing, lr->max_rx_octets and lr->max_tx_octets were
at times set to 0.  If we use these 0 values, we end up with
very erratic behavior.  Best, to check for a sane value and
if invalid, default to the value in _radio.conn_curr->max_*x_octets.

Change-Id: I57c0e3790d988f0de17993cebe5c5c2ab0fc07a6
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-05-10 23:03:11 +03:00
Carles Cufi ff2a85a587 Bluetooth: controller: Add flow control logging
When Controller to Host flow control is enabled, output informational
messages for certain operations to help tune and debug the feature.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +03:00
Carles Cufi 8a7eeeb7f1 Bluetooth: Move HCI driver debug to top-level Kconfig
Since the HCI driver debug option applies to both files in
drivers/bluetooth and subsys/bluetooth, the configuration option itself
now lives in the top-level Kconfig file for consistency.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +03:00
Vinayak Kariappa Chettimada c1041a89a0 Bluetooth: Add PHY auto-update to 2Mbps on connection
Added implementation to auto-update Bluetooth PHY to 2Mbps
if the local Controller supports it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Chettimada c3adc7b0c7 Bluetooth: controller: PHY Update Procedure
Added support for Bluetooth v5.0 PHY Update Procedure in the
Controller.

Asymmetric PHY connections do not work for now due to the
Radio mode not being setup in time in the ISR during tIFS
period and the Radio already ramping up in the cached
previous Radio mode to meet tIFS deadline.

Subsequent commits will add this feature, by either double
buffering the mode in software or using fast radio ramp up
which gives enough time in the ISR to change the mode.

Jira: ZEP-2086

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Chettimada f19a1a348e Bluetooth: controller: Allow multiple ctrl pkt enqueue
Scale the ctrl pkt enqueue implementation to allow multiple
ctrl packets to be enqueued. This will aid in the graceful
implementation of parallel control procedure collisions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Kariappa Chettimada 2a40bf6a87 Bluetooth: Add LE Features test macro
Added HCI macros to check LE Features. Also, added test
macros for 2M and Coded PHY support in HCI Controller.

Earlier a common test macro was used between BR/EDR and LE,
but since LE features do not use pages for feature, an
explicit macro for testing LE feature is added now.

Also, features field in LE device structure is now a single
dimension array of 8 octets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Kumar Gala 18e7769431 net: zoap: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-05-09 17:06:28 -04:00
Carles Cufi 6821df1ef0 Bluetooth: Fix hci_raw's RX buffer alloc
The APIs for allocating RX buffers were modified recently and hci_raw
had not reflected those changes properly.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-08 21:11:08 +03:00
xiaorui hu cffb79a4e1 net: context: set tcp app data len when sending packets
When we send TCP data segment, we need to set the length
of the application data by calling net_pkt_set_appdatalen().
This is done so that sequence number can be properly
advanced when we receive ACK to that pending packet.

Signed-off-by: xiaorui hu <xiaorui.hu@linaro.org>
2017-05-08 08:07:41 -04:00
David B. Kinder f930480e16 doc: misspellings in Kconfig files
fix misspelling in Kconfig files that would show up in configuration
documentation and screens.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-05-05 19:38:53 -04:00
Carles Cufi d34c10725b Bluetooth: Enable events based on features
The event mask population used to let the Controller know which events
are relevant to the Host needs to take into account the features
supported by the Controller itself, in order to only enable those that
are indeed valid.

Jira: ZEP-2050

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-05 16:10:48 +03:00
Vinayak Chettimada fc6d8d1bc4 Bluetooth: controller: Scan Request Notifications
Implement the framework for LE Scan Request Received Event.
The feature is available under the Controller's advanced
features and will be selected implcitly when Bluetooth v5.0
LE Advertising Extensions feature is implemented.

Jira: ZEP-2073

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 15:56:04 +03:00
Vinayak Kariappa Chettimada a9a72f7bea Bluetooth: controller: Remove unreferenced hci_evt_is_discardable
Remove unreferenced function hci_evt_is_discardable after
introduction of hci_get_class function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 15:56:04 +03:00
Vinayak Chettimada b031d76655 Bluetooth: controller: Cond. compile connection state HCI cmds
Conditionally compile connection state related HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada c30ba00fbc Bluetooth: controller: Conditionally compile slave role HCI cmds
Conditionally compile slave role related HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada d39d8224be Bluetooth: controller: Refactor LL Master role to ll_master.c
Move master role related implementation out into a separate
ll_master.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada 446923e4d5 Bluetooth: controller: Refactor LL Scan state to ll_scan.c file
Move scanning state related implementation out into a
separate ll_scan.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada 6117d1dda7 Bluetooth: controller: Refactor LL Adv state to ll_adv.c file
Move advertising state related implementation out into a
separate ll_adv.c file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Vinayak Chettimada d9d3f8e7c7 Bluetooth: controller: Add Kconfig options for states and roles
In preparation for refactoring the Controller implementation
into seperate state and role based source files, add Kconfig
options for states and roles in the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-05 13:33:11 +03:00
Carles Cufi cff44ea3f6 Bluetooth: controller: Use sys_le16_to_cpu on all commands
To guarantee code that is endianness-independent, the sys_le* macros
must be used everywhere when accessing multi-byte values from the
command parameters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-05 12:54:52 +03:00
Carles Cufi 47dedfc992 Bluetooth: controller: Fix overwriting of command parameters
In HCI, the response buffer to a command is the same as the one for the
command itself, requiring command parameters to be processed before the
response is formed on the same memory area.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-05 12:54:52 +03:00
Jukka Rissanen 70f334d9f2 http: client: Create a HTTP library
Instead of separate sample application that does everything
related to HTTP client connectivity, create a HTTP client library
that hides nasty details that are related to sending HTTP methods.
After this the sample HTTP client application is very simple and
only shows how to use the client HTTP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-04 15:58:45 -04:00
Carles Cufi a1ff1a0933 Bluetooth: Consolidate flow control Kconfig
Since Controller to Host flow control is a feature that affects both
sides equally, move it to the top-level Kconfig file and consolidate its
use in both Controller and Host.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 18:09:31 +03:00
Johan Hedberg b484c1eeed Bluetooth: (Re)introduce ACL host flow control
This feature was removed some time ago, but turns out it's important
to have it available for split host-controller setups.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-04 16:38:34 +03:00
Johan Hedberg 70e09b11ea Bluetooth: Introduce buffer type parameter to bt_buf_get_rx
This is preparation for re-introducing host flow control.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-04 16:38:34 +03:00
Carles Cufi ccd4d4f401 Bluetooth: controller: Controller to Host Flow Control bits
Enable the bits corresponding to the new 3 commands supported when
enabling Controller to Host Flow Control, in order for the Host to be
able to enable the feature.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 15:23:46 +03:00
Carles Cufi 689bd232f8 Bluetooth: Reshuffle Kconfig options
In order to achieve proper sharing of configuration options, everything
that is common to both the Host and the Controller should now be placed
in the top-level Kconfig file, and Controller-only options are in the
controller/ Kconfig one.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 11:27:04 +03:00
Vinayak Chettimada 75bff19541 Bluetooth: controller: Introduce s/w based TRX switching
Introduce alternative TRX switching using dedicated timers
and peripheral interconnect. This will enable the
possibility to independently configure the Tx and Rx
settings between the tIFS.

Note, this will also provide the opportunity to design a
soft realtime Radio ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-04 09:36:31 +03:00
Carles Cufi 7ebe7da736 Bluetooth: controller: Controller to Host flow control
The Bluetooth Specification allows for optional Controller to Host flow
control based on the same credit-based mechanism as the Host to
Controller one. This is particularly useful in 2-chip solutions where
the Host and the Controller are connected via a physical link (UART, SPI
or similar) where the Host is sometimes required to ask the Controller
to throttle its data traffic while still making sure that relevant
events get through the line.

This implementation is based on a simple queue of pending events and
data that is populated whenever the Controller detects that the Host is
out of buffers and then emptied whenever the Host notifies the
Controller that is ready to receive data again. Events relevant to the
connections are also queued to preserve the order of arrival.

At this point the Controller ignores the connection handle sent by the
Host and treats all connections equally, and it also queues events even
for connections that have no data pending in the queue. Both this items
can be improved if necessity arises.

Note that Number of Completed Packets will still flow freely from the
Controller to the Host regardless of the pending ACL data packets, which
might lead to inconsistencies in the sequential order of certain
operations that include bi-directional data transfer.

Jira: ZEP-1735

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-03 22:23:42 +03:00
Luiz Augusto von Dentz 08eb5fc428 net: bt: Fix not setting lladdr type
When adding link-local address to the cache the type needs to be
properly set as net_ipv6_addr_create_iid will attempt to use it
when generating the IPv6 address.

Jira: ZEP-2077
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-03 08:48:24 -04:00
Jukka Rissanen 6a52a30b7d net: tcp: Mark ACK timer as cancelled
This is related to commit "net: tcp: Make sure ACK timer is not
run if cancelled" which did not set the cancel flag when the timer
was cancelled from tcp.c.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-03 08:48:24 -04:00
Tomasz Bursztyka e0a643591d net/net_if: Do not start TX thread if there is no network interface
And print a warning if that happens.

This will also avoid to raise an ASSERT on net_if_tx_thread()'s k_poll
as this one will be called with no events to work with.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-05-03 08:41:57 -04:00
Luiz Augusto von Dentz 024de97473 Bluetooth: ATT: Respond with not support error for unknown PDUs
This ensures that an unknown request won't cause ATT to timeout since
no response is currently generated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-02 12:56:53 -04:00
Vinayak Chettimada b29b3e2fdb Bluetooth: controller: Rename ll_address_* to ll_addr_*
Rename ll_address_* to ll_addr_*. Also, update ll_addr_get
to return reference to stored public or random address.

Change-id: I22cb0135d2223f679c4d9321f4724f8b7de0aede
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Michael Scott c8cb20a5b8 bluetooth: host: fix compile break with CONFIG_ASSERT in gatt.c
Fix the attr->handler reference to attr->handle.

Change-Id: I4a6ccee7860abf800f51df404979eac18eb26e8e
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 3666fb81f5 Bluetooth: hci: Consistently use bt_hci_evt_*
Rename occurences of bt_hci_ev_* to more widely used
bt_hci_evt_* namespace.

Change-id: I742fb86f8f835a0f6072638e1e997ad08891d43d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 9fcd0827fd Bluetooth: controller: Explicit AC and DC packet configure
In the Controller's radio hal, explicitly differentiate
between Advertisement and Data channel packet
configuration.

Also, remove nRF5x specific extra overhead in Advertisement
PDU structure.

Change-id: I942b88a160af78f8900d7e49fb5f36c8aa493b97
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 56f8af92cf Bluetooth: controller: Low Duty Cycle Directed Advertising
Added Bluetooth v4.1 Low Duty Cycle Directed Advertising
feature.

Change-id: I6ca665e298b343200c65405739f3998bc78b84e7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 65e07099a7 Bluetooth: l2cap: Use global conn tx pool for segmentation
L2CAP Dynamic Channel feature uses the global connection Tx
pool for segmentation either when there is no free buffers
in the original application pool or when the original data
buffer has no headroom to add L2CAP headers.

This eliminates the need for a dedicated fallback pool for
Dynamic Channel segmentation.

Change-id: Ia5452c814169d17ef261ecef425a8fcf2e7e1e84
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Johan Hedberg 890bf82aff Bluetooth: conn: Remove shadow iterator variable
This function already has an 'i' variable on the top-level, so no need
to declare a second one that'd just shadow the original.

Change-Id: I5dfa4df2c4793be220a40ac642b19bf440e80220
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Johan Hedberg 512d2ac433 Bluetooth: L2CAP: Fix unnecessary NULL check
The segment allocation function can't fail (it eventually waits with
K_FOREVER for a buffer to become available), so there's no point in
checking its return value for NULL. Also, the connection state check
is because of this particular waiting and not the semaphore waiting
(which is done with K_NO_WAIT).

Change-Id: I9698760541de810869cffc1c60cf97c5f8f7df8d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 27bad8743f Bluetooth: l2cap: Decouple segmentation size
L2CAP Tx segmentation used BT_L2CAP_RX_MTU value which is
the value used by fixed channel protocols. Decoupling the
buffer size provides the opportunity to reduce RAM used per
connection.

Change-id: Id064f9b2e3f02073402815d09c3ea13a35df2a6c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 3807a9529d Bluetooth: l2cap: Dont use BT namespace in internal MPS/MTU macro
Remove BT_ prefix from BT_L2CAP_MAX_LE_MPS and
BT_L2CAP_MAX_LE_MTU as they are internal to l2cap.c file.

Change-id: I6abec0a1f07b8aef49940ab7abeaacbd19947e0b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Carles Cufi a6e157b61a Bluetooth: Controller: Fix alignment issues from new integer types
The switch from C99 integer types to u16_t, etc. caused misalignment
in structs and function definitions with multi-line parameter lists.

Change-Id: I1448b159ab1afe50ff88b7a6bd1b254c44858d4c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Johan Hedberg d1bb961bcf Bluetooth: Remove unnecessary bt_dev_esco struct
This information should be part of the main BR/EDR context struct,
rather than there being a separate member in struct bt_dev. If/when
the needed ESCO information grows we can consider having a separate
struct, but even then it should be part of the main BR/EDR struct
instead of sitting directly in bt_dev.

Change-Id: I3edf120606ea6c6974f515bba90de2b25fc6fac6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Johan Hedberg 97f0241c07 Bluetooth: Fix alignment issues resulting from new integer types
The switch from C99 integer types to u16_t, etc. caused misalignment
in structs and function definitions with multi-line parameter lists.

Change-Id: Ic0e33dc199f834ad7772417bca4c0b2d2f779d15
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Leandro Pereira 86b0260e97 kconfig: Move debugging-related options from misc/ to subsys/debug/
This should fix the grouping for debugging options appearing in the
main "menuconfig" menu.

Change-Id: I7ddf3a6f3d025bf82ba63099b30e47a40d7c3187
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-04-28 23:41:16 +00:00
Christer Weinigel cc93aceb83 usb: cdc_acm: Use 2 instead of 4 for IN BULK endpoint
The highest endpoint number supported by the STM32F4xx USB device
controller is 3.  Change the cdc_acm driver to use endpoint 2
instead of endpoint 4 so that it will work with this platform.

Change-Id: I4a3cd08f546a7fe01558528de0990156f642d93b
Signed-off-by: Christer Weinigel <christer@weinigel.se>
2017-04-28 18:48:58 +00:00
Michael Scott 438492843c net/mqtt: return error codes from net_context_send
Instead of returning EIO let's bubble the error from net_context_send
back up to the caller in the following functions:
mqtt_tx_connect()
mqtt_tx_disconnect()
mqtt_tx_pub_msgs()
mqtt_tx_publish()
mqtt_tx_pingreq()
mqtt_tx_subscribe()
mqtt_tx_unsubscribe()

Change-Id: I9bb4396b227b8902ac1195a97bc37eb1959b643e
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-28 15:01:12 +03:00
Michael Scott 7bce4af81f net/mqtt: cleanup TX function unref handling
With CONFIG_NET_DEBUG_NET_PKT enabled, the log messages are full of
errors regarding NULL parameters passed into net_pkt_unref in almost
every TX function for handling MQTT messages:
mqtt_tx_connect()
mqtt_tx_disconnect()
mqtt_tx_pub_msgs()
mqtt_tx_publish()
mqtt_tx_pingreq()
mqtt_tx_subscribe()
mqtt_tx_unsubscribe()
mqtt_parser()

Let's clean up the unref handling so that our debug log isn't quite
so full of error spam (as opposed to the normal amount of spam from
the net buf log).

Change-Id: Ib49d1192f51abe4329e6dc9da3c51a4a36290082
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-28 15:01:12 +03:00
Michael Scott fa5503fb44 net/mqtt: use rlen to calculate # of QoS items in SUBACK packet
The data->len of an inbound netbuf can be larger than a single
MQTT packet.  For instance when a PINGRESP is also included
in the same netbuf.  For this reason we should not be using
the data->len to determine how large the rest of the MQTT data is.

Specific Example: we've seen in testing that PINGRESP packets
can be included with a SUBACK packet in the same netbuf. Under
this case the current code uses the data->len incorrectly and
tries to find 3 QoS elements for the SUBACK packet when there
is only 1 (the rest of the data is for PINGRESP).

NOTE: A larger patch to iterate through the netbuf data parsing
individual MQTT packets will be needed to fix the MQTT subsys.
This patch only corrects the SUBACK parsing.

Change-Id: I7f6cebaaed9570b778d466de84331cf8c5060755
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-28 15:01:12 +03:00
Michael Scott e5f1112b07 net/mqtt: combine mqtt_parser for PUBLISHER and SUBSCRIBER
Currently, app type MQTT_APP_PUBLISHER_SUBSCRIBER is not supported.
mqtt_init() will return EINVAL because the context rcv function is
either mqtt_publisher_parser or mqtt_subscriber_parser (not both).

Let's combine these functions into mqtt_parser and remove the app
type check from mqtt_init().

Change-Id: I60460e011395864706e293c997e9f8a65681b368
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-28 15:01:12 +03:00
Marti Bolivar 5fab97c9d0 net/mqtt: fix race condition in mqtt_init()
We need to set the mqtt context recv function prior to calling
net_context_recv which installs the mqtt_recv callback.
If not, we risk a race condition where an unprotected reference
to mqtt->rcv(mqtt, buf) is made in mqtt_recv().

Change-Id: If90ee58f4ea6f7879ef7c12b969ba27647426acc
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-04-28 15:01:12 +03:00
Paul Sokolovsky ff3b019054 net: shell: Make shell commands non-static to allow reuse.
Some applications may want to reuse implementations of these
commands for debugging/diagnostics purpose even if they don't
use net shell per se, or implement an alternative shell.

Jira: ZEP-2064

Change-Id: I48cb66ccc41bd41a75a4eb8eb3c366316ec5a096
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:12 +03:00
Ravi kumar Veeramally ead481a041 net: rpl: Fix invalid usage of router addition api
net_if_ipv6_router_add() will return router pointer on success.
This information must be cached in RPL instance, otherwise RPL
instance doesn't know about default route.

Change-Id: Ic6d80ebfa95c9a64df9adf2621ae2631d9bdb990
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 5edf55f771 net: rpl: Fix router when it's timer expires
When router or default router timer expired, interface will remove
router from the list. In this case RPL does not know about this.
When RPL node receives DIO messages it only verifies whether parent
exists or not. This extra checks will verify whether router really
in "used" state or not.

Jira: ZEP-2080

Change-Id: I4b36b3a2d495e76a38caddd058451daff08fab0c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally d9bde9a5ab net: ipv6: Use correct API to remove router
net_if_ipv6_router_rm() is the correct API to remove IPv6 router
from the interface as it also cancels the timer and raises a mgmt
event. The net_if_router_rm() only sets router as unused and
nothing else.

Change-Id: I55114288c9ae748520b67b206edcd4f5e420b1af
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally d787ccb40a net: zoap: Add block wise support for well-known response
If the ./well-known/core response is bigger than L2 MTU then
response will be sent in multiple fragments. In mesh kind of networks
getting response from farthest node might loose packets. So better to
send response in a block wise fashion. Block size is configurable.

Change-Id: Id421c66597fe448c12a7215f04f63f4a284c14ab
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 0cdfd75c7f net: zoap: Remove unused struct definition
Change-Id: I1b57972386b0def02eb125b6ae4825f11268f6ce
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 9d0a484690 net: zoap: Minor comment style fixes
Change-Id: I8f63781a39263e110aec2e6f1e14d72650ce4e30
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 6740e691e8 net: zoap: Remove magic number
Value 0xFF represents End Of Options marker in CoAP message.
Use #define than magic numbers in code.

Change-Id: I3bef21ea827987f7c2e670447ee20574cb6288ae
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:11 +03:00
Ravi kumar Veeramally 38503f8c76 net: zoap: Add timeout while requesting packets
Add timeout for packet and buffer requests. If there are no
buffers available gracefully drop the request.

Change-Id: I56fe2b606556149c83751aadc1c5eee7828a84a8
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-28 15:01:10 +03:00
Luiz Augusto von Dentz 86a72e1ed4 net: bt: Fix leaking TX packets
Bluetooth only cares about the actual payload so net_pkt can be unref
as soon as the data fragments are detached.

Jira: ZEP-2070
Change-Id: Id528d5440f42903378883f5e696b3f663bbfa313
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-28 15:01:10 +03:00
Paul Sokolovsky 25307d5331 net: net_pkt_append: Refactor to return length of data actually added
For stream-based protocols (TCP), adding less data than requested
("short write") is generally not a problem - the rest of data can
be sent in the next packet. So, make net_pkt_append() return length
of written data instead of just bool flag, which makes it closer
to the behavior of POSIX send()/write() calls.

There're many users of older net_pkt_append() in the codebase
however, so net_pkt_append_all() convenience function is added which
keeps returning a boolean flag. All current users were converted to
this function, except for two:

samples/net/http_server/src/ssl_utils.c
samples/net/mbedtls_sslclient/src/tcp.c

Both are related to TLS and implement mbedTLS "tx callback", which
follows POSIX short-write semantics. Both cases also had a code to
workaround previous boolean-only behavior of net_pkt_append() - after
calling it, they measured length of the actual data added (but only
in case of successful return of net_pkt_append(), so that didn't
really help). So, these 2 cases are already improved.

Jira: ZEP-1984

Change-Id: Ibaf7c029b15e91b516d73dab3612eed190ee982b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:09 +03:00
Jukka Rissanen 3051fc2035 net: rpl: Do not crash if DIO message contains garbage
Instead of just plain assert, check that the packet we receive
is ok before passing it to processing function.

Jira: ZEP-2057

Change-Id: I5754c82d16e1522d8fcee561eea280eadeec31ee
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-28 15:01:09 +03:00
Jukka Rissanen 52d0589c1f net: tcp: Fix TCP trace value debug
The TCP trace values were not printed because of incorrect
config option used. Print also seq and ack values in decimal
in order to make it easier to correlate the values in other
prints in tcp.c.

Change-Id: I44d1535a84dcba8c6c937d348516ba801193ca23
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-28 15:01:09 +03:00
Andrei Emeltchenko 65c002b8ce net: security: Use sys_put_be32() relevantly
Use ready-made utility function which can take care of endianness

Change-Id: I1edd0b2ce1a086dd637e97308145f9b434e48a1f
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-04-28 15:01:09 +03:00
june li 3e4faffede net: l2: Clear arp cache when disable interface.
When connect to diffrent router with the same gateway ip address,
need to clear arp cache when disable interface,
or it will use the wrong gateway mac address.
Call net_arp_clear_cache function replace to set arp_table 0.

Change-Id: Ib403a0c0030832ba48824db4d2d3fcb8add63d16
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-28 15:01:08 +03:00
Kumar Gala 05196f0320 kernel: event_logger: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Change-Id: I9ccb7c01a7d8c4ad8b1e55a1b45622aad2a57e57
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-25 22:09:12 +00:00
Leandro Pereira ffe74b45fa kernel: Add thread events to kernel event logger
This adds a new event type to the kernel event logger that tracks
thread-related events: being added to the ready queue, pending a
thread, and exiting a thread.

It's the only event type that contains "subevents" and thus has a
non-void parameter in their respective _sys_k_event_logger_*()
function.  Luckily, as isn't the case with other events (such as IRQs
and thread switching), these functions are called from
platform-agnostic places, so there's no need to worry about changing
the assembly guts.

This is the first patch in a series adding support for better real-time
profiling of Zephyr applications.

Jira: ZEP-1463
Change-Id: I6d63607ba347f7a9cac3d016fef8f5a0a830e267
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-04-25 02:16:36 +00:00
David B. Kinder 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

Change-Id: I6eda081c7b6f38287ace8c0a741e65df92d6817b
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-22 01:04:56 +00:00
Kumar Gala 6da829690f subsys: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: Icbf9e542b23208890a3a32358447d44cdc274ef1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:36:22 -05:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Jukka Rissanen af1e3b9d32 net: shell: Fix compiler error when printing conn handlers
There was compiler error if CONFIG_NET_DEBUG_CONN was set.

Change-Id: Ibb6721c55dd2c56cd0097359a53563c6221859ea
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 15:44:22 +03:00
Jukka Rissanen d8dd91d7bf net: context: Connect callback was set too late
We need to set the connect_cb for the context before sending SYN packet.
This is required if we have a loopback connection in which case everything
is happening more or less synchronously and the connect_cb would not be
called in this case because its value would still be null.
For remote network connections this patch makes no difference.

Change-Id: Id7f837cd9e81cd79c4666c98cae84f6cb1a77af0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 15:44:22 +03:00
Jukka Rissanen 1bf14853aa net: tcp: Make sure ACK timer is not run if cancelled
We must not let ACK timer to run if we have already cancelled it.
So keep track that the timer is cancelled and refuse to run it
if it was indeed cancelled. The reason why the timer might be run
in this case is because the timer might be scheduled to be triggered
after which one cannot cancel it.

Change-Id: I1c8b8cee72bc7a644e02db154d9d009b8d98ade2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:52 +03:00
Jukka Rissanen 137e4e7256 net: context: Set the local port correctly in accept
The local port was set to 0 for IPv6 when registering
the connection handler. For IPv4, the code was not setting
the port in local_addr struct.

Change-Id: I82f0c08641a94d75d255ac306eca7bec6c332fba
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:52 +03:00
Jukka Rissanen a1c4f3fbd5 net: Print debug info if packet is loopback back to us
Without this info it is a bit difficult to notice what is going
on in loopback case.

Change-Id: I8f61330c01d025e41f00d663bd26947b8cafb5c0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen a71a9f9ad1 net: conn: Utility to print connection handlers
Add support to print connection handler information in net-shell.
There exists one connection handler for each UDP/TCP port that we
are listening. These prints are only available if CONFIG_NET_DEBUG_CONN
is enabled because the net_context has the same information. Thus the
connection handler info is only printed if debugging is active in order
to verify that handler information is proper.

Change-Id: I0be39a5adb89b2cdbd85524c5d943e4a562b0fde
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen f498a90b77 net: pkt: Make the debug print eye friendly
Print "pkt" instead of "Pkt" when printing network packet
pointer value.

Change-Id: Id4225be9c55807def3d892d372cdfc5c79c871fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Jukka Rissanen 52339cdf5a net: tcp: Avoid unused variable compiler warning
If TCP debugging is enabled but if the loglevel is set to lower
than 4, then compiler prints warning about unused flags variable
in net_tcp_trace().

Change-Id: I2e663644b50fe97b75088202e21b286aa010953e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka f3ff4f7bd3 net_pkt: Let's make all IPv6 related attributes prefixed with ipv6_
Only 2 attributes lacked this prefix, which makes sense to have, so
applying it accordingly and changing the helpers as well.

Change-Id: I095b2729f977f8fb1624eff8801a4a4e21416693
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka e5896906f6 net: Rename all *_BUF() macros to *_HDR()
Most of these macros are not exactly exposing a buffer, but a specific
header pointer (ipv6, ivp4, ethernet and so on), so it relevant to
rename them accordingly.

Change-Id: I66e32f7c3f2bc75994befb28d823e24299a53f5c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka c18016b69b net_pkt: Externalize ext_bitmap handling
IPv6 next headers are processed in a way so it is not required to store
which header has been already seen in the net_pkt, as the processing loop
can store internally which one it has seen already.

Change-Id: I266ba8a3a0081a162318cdafb474a0fc44a3185e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka 2e331de690 net_pkt: Removing legacy net_dir
This is actually useless as there is only 1 RX memory slab, and thus can
be removed to reduce net_pkt structure size.

Change-Id: I62d716515120e7356ee1e2d75bbe1ec32e22c35d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka db11fcd174 net/net_pkt: Fully separate struct net_pkt from struct net_buf
- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

Change-Id: Ibd5c17df4f75891dec79db723a4c9fc704eb843d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka bf964cdd4c net: Renaming net nbuf API to net pkt API
There have been long lasting confusion between net_buf and net_nbuf.
While the first is actually a buffer, the second one is not. It's a
network buffer descriptor. More precisely it provides meta data about a
network packet, and holds the chain of buffer fragments made of net_buf.

Thus renaming net_nbuf to net_pkt and all names around it as well
(function, Kconfig option, ..).

Though net_pkt if the new name, it still inherit its logic from net_buf.
'
This patch is the first of a serie that will separate completely net_pkt
from net_buf.

Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Andrei Emeltchenko 9bf3ea071a net: shell: Correct print format specifier
Fix warning using incorrect format specifier

Change-Id: Ib6800c40b2cd769612ae6f107e41a941926d8e66
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-04-21 14:19:50 +03:00
june li 504b273b85 net: tcp: Do buf ref when resending a segment
We need to check whether buf_sent was true when resending the TCP
segment, and do a buf ref if needed. If this is not done, the buf
will be unref after send, which will cause unpredictable results.

Change-Id: Ibd4490305de88ac6ffd04ec42bba196e57da5c10
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-21 14:19:50 +03:00
Jukka Rissanen 7ce82fea82 net: ipv6: Make sure not to access null pointer
While very unlikely it might happen that fragment pointer is NULL
when going through fragment list.

Coverity-CID: 167148

Change-Id: Ic3dbed7ee29c7b864d4830d726f65d7f62dcea84
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally 651a0cb269 net: zoap: Prepare and send error response separately
If error occurs while preparing response to .well-known/core request,
do not send partly filled payload by simply changing code part only.
It's better to unref the partly filled reponse and prepare a new error
response and send.

Change-Id: I28013a4e331cfc6f01de873e80af48f765e49494
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally a8ac7af37a net: zoap: Remove unused helper function
Commit "net: zoap: Fix memory overflow issue" fixed and implemented
./well-known/core response in a different way, so this api is not needed
anymore.

Change-Id: I8f945fb5842028be50ecfdef95cbe5da3189a538
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally 79ff5ed5fa net: zoap: Fix memory overflow issue
If CoAP .well-known/core services list is bigger than single fragment
then current helper functions overwrites beyond fragment space. Which
corrupted whole stack. Right now sending response in multiple fragments
but preferred way is send response in block by block. This should
overcome packet loss across mesh scenarios. Recommended feature will
be supported with later patches.

Change-Id: I30ca55bde2516d80b3583731241ad295799c6614
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally 09773f5a5f net: zoap: Refactor zoap utilities
Most of the zoap utilities deal with first fragment of buffer chain.
So accessing of buf->frags directly make less usage of stack than
delcaring another variable for frag and its data. Due to code
refactoring couple of lines removed and in between those lines
coverity complained two issues, which is not valid now.

Coverity-CID: 157597
Coverity-CID: 157598

Change-Id: I3035c0625a131d49a4f0250ff0052875d3382544
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Ravi kumar Veeramally 2f73c324aa net: rpl: Fix rpl header update
When net_ipv6_finalize_raw() inserts RPL(HBH) header after IPv6 header,
it updates IPv6 next header as HBH and HBH next header as original IPv6
next header.

Then net_ipv6_prepare_for_send() will update RPL HBH header if it exists.
But net_rpl_update_header() is comparing HBH option and IPv6 next header,
which is wrong. Wrong comparion does not update RPL instance id and
sender rank. Peer nodes drops all the packets due to invalid instance
ID and sender rank.

Change-Id: I91c1870a09c60f8e1ebc73e434dcc208caf6299a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Mitul Shah d27ca378b6 net: context: Fixing bug in net context put flow
Following flow does not work:
net_context_get
net_context_bind
..
..
net_context_put
net_context_get
net_context_bind

At instance of call to net_context_bind, conn_handler
is not NULL and returns with EISCONN.

This patch sets conn_handler to NULL in net_context_unref

Change-Id: I56a50839101b22161644b3cd7c5f510fa1abae3e
Signed-off-by: Mitul Shah <mitul.a.shah@intel.com>
2017-04-21 14:19:49 +03:00
Paul Sokolovsky 52e3e5c68d net: shell: conn: Dump local/remote ports for contexts.
Without port numbers, information printed by net shell's "conn" command
is unclear and non-differentiating. Also, improve handling of unknown
address families - don't abort early, still pring context address, iface
address, etc.

Example of "conn" output with these changes from echo_server sample:

net> conn
     Context   	Iface         Flags Local           	Remote
[ 1] 0x001126e0	0x001121a0    6DU   [::]:4242	[::]:0
[ 2] 0x00112738	0x001121a0    4DU   0.0.0.0:4242	0.0.0.0:0
[ 3] 0x00112790	0x001121a0    6ST   [::]:4242	[::]:0
[ 4] 0x001127e8	0x001121a0    4ST   0.0.0.0:4242	0.0.0.0:0

TCP        Src port  Dst port   Send-Seq   Send-Ack  MSS    State
0x00112b00     4242         0  497073352          0  1280
0x00112b98     4242         0  497543793          0  1460

Change-Id: I2f03efd933979b5571f608c28a7a7a4bd7f5346a
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-21 14:19:49 +03:00
Kumar Gala d0eb235510 Bluetooth: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I8f57a17f78e674aca5400f005db8975c9f9e150e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 13:25:23 -05:00
Kumar Gala 3c454017b4 Merge "Merge bluetooth branch into master" 2017-04-20 16:55:36 +00:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
Johan Hedberg 2ec180aef5 Bluetooth: ATT: Start response timer only after actual transmission
If there are many connections there may be some delay before an ATT
PDU really gets transmitted over the air. Use the TX callback to
start the response timer so that it doesn't expire too soon.

Change-Id: Ibdd5bc1029ae4034caf329bf03892ac2093a0c67
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:57 +00:00
Johan Hedberg d893d31c16 Bluetooth: Introduce flow control for outgoing ATT packets
In order to not overload the TX buffer pool and potentially run out of
them, enforce flow control for outgoing ATT packets so that the send
functions block until the PDU has actually been transmitted over the
air.

Change-Id: Ic065bb88aec8c2d0ac2def8ef62131a427f7051f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:40 +00:00
Johan Hedberg ea9a067a9a Bluetooth: ATT: Fix bogus CONTAINER_OF() usage
This CONTAINER_OF() worked by chance, but was actually wrong, since it
makes it look like bt_l2cap_le_chan is the parent container of bt_att.
Instead bt_l2cap_le_chan is simply a member of bt_att, i.e. we can
dereference it directly.

Change-Id: I7307517bae823e54b45db31f75462655ce6eb50d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:04 +00:00
Johan Hedberg e2eb446b7b Bluetooth: Introduce a timeout for synchronous HCI command sending
There is no command that should take more than a couple of seconds. If
it does there's something severely wrong with the system. Catch such
situations with a clear assert rather than silently blocking the
sending thread.

Change-Id: Ie981fddcc27059df3e4df586e86ceac2e348f509
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 14:23:15 +03:00
Johan Hedberg a20464727f Bluetooth: SMP: Track when last key distribution PDU has been sent
According to the SMP specification the pairing is only to be
considered complete once the last SMP PDU has been transmitted over
the air. Take advantage of the new TX callback to notify completion
only once the packet has really been transmitted.

Change-Id: Ic87e598cd0e040d99f38344b98e476f67e4d9762
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 12:59:56 +03:00
Johan Hedberg 4a57bf6e6c Bluetooth: ATT: Enforce flow for incoming requests & indications
It's not valid for a peer to send another request before getting the
response to a previous one, or to send another indication without
getting the confirmation to a previous one. Take advantage of the
recently introduced TX callback to track when it's ok to accept these
ATT PDUs again.

The HCI USB transport has a potential issue here since a race
condition can occur between the ACL data and HCI event endpoints,
leading to dropping data when in fact both peers were behaving
correctly. To avoid hitting this issue, disable the flow enforcement
by default on the qemu targets that commonly use a USB-based
controller on the host OS.

Change-Id: I2791aaec6f6c0f8fd78a9a809a25e3ce129106c7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 12:59:56 +03:00
Johan Hedberg 4be4c60ab6 Bluetooth: Add support for tracking transmitted packets
Protocols/profiles may want to know when exactly their PDU has been
transmitted over the air. To make this possible, introduce support for
a callback that will get called when the controller reports that a
packet has been transmitted (through the Number of Completed Packets
HCI event).

Change-Id: Ia3a19b93c5b2111f144bfabe5861187c41525f30
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 09:59:33 +00:00
Johan Hedberg ac9a2398d8 Bluetooth: hci_raw: Fix ECC support
When the ECC code was last time refactored hci_raw.c was forgotten
about. This fixes the issue so that ECC works again with hci_raw.

Change-Id: I1b1df66f1b2a311db611b9936ec074c88caf4143
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 11:29:08 +03:00
Luiz Augusto von Dentz fd09c4aacf Bluetooth: L2CAP: Reuse request buffer to respond
This reduces the pressure on TX pool which may constantly block in case
of heavy traffic causing the RX thread to block as well.

Change-Id: Icfdde32031715e882085b7fa371191f157954156
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Luiz Augusto von Dentz 1885edf424 net: buf: Add net_buf_reset
This adds net_buf_reset which can be used to reset the state of a buffer.

Change-Id: I4b7c89dfd1a23a2ec8dfa3c99d5b02b9bcbceef3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Luiz Augusto von Dentz 661c033124 Bluetooth: L2CAP: Try to allocate segment from the original pool
This makes the code attempt to allocate from the original buffer pool
before relying on le_data_pool which shall only be used as last resort
as it is configure with minimal possible buffers (1 per connection).

Change-Id: I85b581627f5c3b1bf1ee7c5fa69099c5aca13d4a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 392b5deacb Bluetooth: controller: Channel Selection Algorithm #2
Add Bluetooth 5.0 LE Channel Selection Algorithm #2 feature

Jira: ZEP-2033

Change-id: Ic1155b4399882b89cab33cac78b08b7b39ff6f9d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 11a32bf46d Bluetooth: controller: Support BT 5.0 feature set bit fields
Added support in the Controller for increased feature set
bit fields in Bluetooth 5.0. Cached feature set in the
connection context is increased to a uint32_t value to
accommodate 17 feature bits.

Change-id: I9ae15d6d90fa7a3de186905d3c68088ee22d2911
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada a6f6adbd6b Bluetooth: Fix missing LE conn param req bit in set LE evt mask
With the introduction of event mask implementation in the
Controller, it is discovered that peer centrals
initiating LE connection parameter requests timed out as
the Host did not get/enable the HCI LE connection parameter
request event in the set LE event mask command.

Fix by adding the LE connection parameter request event bit
mask while creating set LE event mask command.

Jira: ZEP-2027

Change-id: Ida7750f375addc8a91036fffc47325518a3d2ec0
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Carles Cufi 045f076e5e Bluetooth: Use event masks instead of bits in controller and host
To avoid having to define a BIT64() macro in a public namespace, use
instead masks directly instead of bits, and also refactor the host code
so that it uses those instead of the earlier byte array with hardcoded
indices and masks.

Change-id: Ief03db616a96df65349d24289b62566a268ffdd0
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 2f70a6bcca Bluetooth: controller: Rename channel/chnl to chan
Rename symbol names with channel/chnl to chan.

Change-id: I196ffea79e7e10b0253363949051fdf82be62cb4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Kumar Gala f52a0341ba Bluetooth: AT: Fix building with newlib
Since the type of int, uint32_t, etc change with newlib we get the
following error:

subsys/bluetooth/host/at.c: In function ‘cme_handle’:
subsys/bluetooth/host/at.c:272:25: error: passing argument 2 of ‘at_get_number’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (!at_get_number(at, &val) && val <= CME_ERROR_NETWORK_NOT_ALLOWED) {
                         ^
subsys/bluetooth/host/at.c:46:5: note: expected ‘uint32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int at_get_number(struct at_client *at, uint32_t *val)
     ^~~~~~~~~~~~~

We we can easily address by making val a uint32_t.

Change-Id: Ie6988368bd862afd4075baede7cb0a66c1628c18
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 08:58:09 +03:00
Kumar Gala 819d3ae9c9 Bluetooth: AT: use explicit unsigned char to avoid array subscript error
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Being explicit about the char being unsigned char deals with this.

Change-Id: I348189e1df11a1fcc58e5810b010b602fd2df33e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 08:58:09 +03:00
Carles Cufi 8f9776073f Bluetooth: HCI: Naming consistency tweaks
For consistency, "chan" and "param" are used wherever "channel" and
"parameters" are the words in the specification.

Change-Id: I778a8501ae6af991618c14cc6e395d765a9ae102
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03:00
David B. Kinder 0ffb648210 spell: fix doxygen comment typos: /subsys
Fix doxygen comment typos used to generate API docs

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
Bogdan Davidoaia 290e1d8451 net: use UNALIGNED_GET/PUT to access IP address
Use UNALIGNED_GET and UNALIGNED_PUT throughout the networking stack to
access fields from the IP address structure. These structures can be
mapped directly to buffers and the macros are required for correct
unaligned memory access.

Jira: ZEP-2012

Change-Id: I55f9da7b143a22fa869d5d215c661de988cd9b91
Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 987df43ba5 net/ieee802154: Add ieee15_4 shell module functions to set/get tx power
Change-Id: I1245686118daa1c81691694b4b4c1512847beca0
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 3a3636ff7f net/ieee802154/samples: Add a Kconfig option to tweak the TX power
This can be useful to override the default value, for testing.

Change-Id: I23b559152c71955ff5aa6fd3643f1f40f5594194
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 26b5f94a79 net/ieee802154: Add a Kconfig option to set a default tx power
Change-Id: Ife2af22c13954286d8e44c3e0b1f60962c617c52
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 951294f15e net/ieee802154: Expose TX power setting through net mgmt API
This permits to tweak the TX power in dbm.

Change-Id: Idadff397941a39010ce3c374d9ca74b777934626
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 63619b503f net/ieee802154: Fixing a typo in net_mgmt settings accessor
s/SET/GET obviously

Change-Id: Ibaad65f846fef8b1b7839616b2022fad6548612a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen f8c9439908 net: if: Reshuffle fields in net_if and related structs
This does not save any space but sets the fields in the
structs in more natural order. Move IPv6 related
fields in net_if into internal ipv6 struct so that all
IPv6 fields are located inside one struct. Same thing
is done for IPv4 fields which are now located inside
IPv4 internal struct in net_if.

There is no functionality changes by this commit.

Change-Id: I7d72ec0a28e2b88c79a4c294655d5ef6da6ccb25
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Tomasz Bursztyka 62b710384d net/ieee802154: aux sec header frame counter is in little endian
So manipulating it requires to be ready to swap it if the CPU is BE.

Change-Id: I8d657c31cecfc9f3fcd010efbb6d090bf021f5f5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 611ccaaf88 net: dns: Remove dns_client API and sample application
DNS resolving is better done with DNS resolve API so remove
the DNS client API which is quite hard to use.

Change-Id: Ide4973a5be674414ea6e04a35c938195cce40b6a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 57e128654b net: mgmt: Add IPv6 DAD succeed/failed event
We need a way to know when IPv6 address is successfully set
into network interface.

If IPv6 DAD (Duplicate Address Detection) succeeds or fails,
we send a management event for that. This can be used by
other components to detect when the network interface is in
usable state.

Change-Id: Ifb22415fe21f31f5dba4f55455d6e0f89b414d32
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 528a393470 net: ipv6: Fix the constness of function parameters
Some of the IPv6 utility functions were missing const in
one of the parameters that are not modified by the corresponding
function.

Change-Id: Ic9fe53daac288570c14423fd9410dcf15d1c5cfa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Luiz Augusto von Dentz 076ddacca5 net: ipv6: Rework net_ipv6_nbr_add
This makes net_ipv6_nbr_add able to update entries so it can be reused
when receiving RA or NS requests, so it now performs a lookup before
creating a new entry (using nbr_new to reuse more code) and in case it
finds a match attempts to update the lladdr.

Change-Id: I305a67a955e037cbbb862fef947a5fcfe131507c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:44 +03:00
Luiz Augusto von Dentz 8b23e3e984 net: ipv6: Fix not initializing delayed work
net_ipv6_nbr_add shall init the delayed work as nbr_new does, so this
unifies both codes into nbr_init which does take care of initializing
the fields properly.

Change-Id: I91746276d346a3dc3c36be20d49bcf1968245fc5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 07438ead0d net: shell: Fix printk format for multicast routes
Route lifetime was printed using wrong modifier.

Change-Id: Ib503d50b5817491984d51bbdaadf7457fdde178b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen d1ac3d6914 net: rpl: Fix compilation if MRHOF is enabled
Make sure the RPL is compiled ok if CONFIG_NET_RPL_MRHOF is
enabled in the configuration.

Change-Id: I51fc0e20f854164c7e0374fa6a1ebf1d4e4dbc5b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 43847e751d net: rpl: Fix compilation if CONFIG_NET_RPL_MOP3 is enabled
If multicast routing is set meaning that MOP3 (Mode of Operation)
is enabled, then the code was not compiling properly.

Change-Id: Ice8a9f7b705c781536d3c2c5ca6cc2bb77a7acc1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen c7102c77a2 net: route: Fix compilation error
Change-Id: Ib4ed6fffe637ac9cd67ce4685d540730c26c8339
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 4bcdf049bb net: dns: Add more debugging about configured servers
Print information about configured DNS servers when starting
in order to ease the debugging.

Change-Id: I3ba71e514e463db790b82913e4c66a67160366dc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen d31fa5b87c net: dns: Set the address family and address length correctly
We need to set the resolved IP address family and length
before calling the user callback so that callback does not
need to figure out these values itself.

Change-Id: I724909fc1707608ab8728231a0311795b6a313f3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen 42bd36ec77 net: ipv6: Allow user to tweak packet hop limit value
The default hop limit is defined in struct net_if. It is possible
that user might want to tweak it for each network packet. For this
purpose, a net_nbuf_set_ipv6_hop_limit(buf) function is created.

Change-Id: I7568330358f80f0f5007d6d3c411c120b043c04f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen 31d3406efa net: rpl: Fix the statistics collection
The Kconfig.rpl file was missing option to actually collect
RPL statistics. Unified the config option name to be
CONFIG_NET_STATISTICS_RPL as there was two conflicting settings
in the code and both of them were missing from Kconfig file.

Change-Id: I4ce4fcbaa317b36cac315ea3b3f710fa7a344b25
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
Jukka Rissanen dc9f8629b2 net: rpl: Add checks for probing timer
The probing_timer is only available if CONFIG_NET_RPL_PROBING
is defined.

Change-Id: I2835d17e6c3d616f815f8beefd87d2571a5ad94c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
june li 961d7fc8f4 net: tcp: Release buf after failing to send
After failing to send the buf we need to release it.
This is not done for Bluetooth or IEEE 802.15.4 links which
create a copy of the sent buf and the failure case is already
checked by net_tcp_send_buf().

Change-Id: Ia556376b58ad74f68accb64eb2221a78d59dc2ec
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-13 15:21:42 +03:00
Luiz Augusto von Dentz 9c0ea2b90b net: buf: Print pool name if available
In case CONFIG_NET_BUF_POOL_USAGE is defined use print pool->name
instead of the pointer.

Change-Id: I0be5fd8283a887145e61bdad02f721265453ce20
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:42 +03:00
Bogdan Davidoaia 8f97651d23 net: use UNALIGNED_GET in net_addr_ntop
Use UNALIGNED_GET in net_addr_ntop as the uint16_t pointer used in this
function can point to an unalined address.

Jira: ZEP-2012

Change-Id: Idfbfa8da4c8d4e10299c4ae4d6431b10466cc988
Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
2017-04-13 15:21:42 +03:00
Jukka Rissanen 70cdaba202 net: shell: Add IPv6 fragmentation info printing
If the IPv6 fragmentation support is enabled, then print current
status of the IPv6 packet reassembly in "net conn" command.

Change-Id: I384e35928b67dd39ac720c77683b1767e2a1ce88
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:42 +03:00
Jukka Rissanen d8feb0a0e4 net: ipv6: Add helper to get the last extension header
Figure out what is the last extension header in IPv6 packet
and return offset to it. This is needed by IPv6 fragmentation
when fragmentation header is added to the packet.

Change-Id: I925ab806a5de076a425ff354711730d4f4b3c52f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen ea17e9d321 net: ipv6: Support fragmented IPv6 packets
This commit adds support for IPv6 packet fragmentation when
receiving (IPv6 reassembly) and when sending larger than 1280 bytes
long IPv6 packet. See RFC 2460 chapter 4.5 for more details.

Jira: ZEP-1718

Change-Id: Ia31c147cce4d456ee48f39276cca99aa09ce81d6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 1b2c16a498 net: nbuf: Add function to split a data fragment
Add net_nbuf_split() function that can be used to split
an existing net_buf fragment into two arbitrary length pieces,
and return the two new fragments to the caller. The data from
the original fragment is copied into these two new fragments.

Existing fragment is not modified.

Change-Id: I463e675232c6e19c2a42929f480893a6d1265873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 9d74fd71b5 net: dns: Invalid memory access
Do not try to cancel query if the DNS query index is < 0.

Coverity-CID: 166770

Change-Id: I03c1f274453640d0ff80694628b8e8f18e8de900
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 7a07f23da7 net: tcp: Store MSS in tcp header correctly
Use UNALIGNED_PUT() to store the MSS value into network packet
because the memory location cannot be guaranteed to be properly
aligned.

Change-Id: I77fd7a70ef45eedb657cac29457b0239b0a1d4c2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Anas Nashif 50553dd700 debug: rename variable CONFIG_GDB_RAM_SIZE
CONFIG_* usually come from Kconfig, rename variables that are locally
defined to avoid confusion about where they are set.

Change-Id: I402713e6f852907e75be4bc2b916a7d15dd5649c
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-11 03:14:24 +00:00
Luiz Augusto von Dentz d8008533a9 Bluetooth: GATT: Fix wrong check for empty database
This fixes regression introduced by
87f2f7afec.

Change-Id: I4a1177ad42c7bb20fe66f8927cd00a30236152af
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-10 17:45:46 +00:00
Anas Nashif c574dde9a5 kconfig: fixed name of Kconfig option in comment
Change-Id: Iae95d06e3a01bee62ea2160b9640722d2bfc3c41
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-10 16:07:22 +00:00
Anas Nashif 919b3f0878 kconfig: fixed Kconfig name in comments
Change-Id: Ia22e9df4b9d836635aef1d4b59efec8ce58815d6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-10 16:07:09 +00:00
Johan Hedberg be7c9fabae Bluetooth: AVDTP: Remove unused define
This is not used anywhere.

Change-Id: I943a3f28f1bdd619360215633dc66368e4b193a4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 17:05:51 +03:00
Johan Hedberg 2ed8d83d4d Merge bluetooth branch into master
Controller:
	- Added duplicate filtering support
	- Added event mask support
	- Kconfig enhancements
	- Various cleanups

 Host:
	- IRQ locking fix to monitor protocol
	- Fixed potential deadlock in ECDH support
	- Fix to connection error reporting
	- Fix to GATT signing
	- Fix to LE CoC
	- AT command & HFP improvements

----------------------------------------------------------------
Carles Cufi (4):
      Bluetooth: controller: Implement scan duplicate filter
      Bluetooth: controller: Implement event masks
      Bluetooth: controller: Fix warning with no dup filter
      Bluetooth: test: Add "tiny" controller configuration

Johan Hedberg (11):
      Bluetooth: monitor: Drop data instead of holding IRQ lock for long
      Bluetooth: monitor: Add support for logging packet drops
      Bluetooth: HCI: Add define for success status
      Bluetooth: ECC: Fix command status emission from wrong thread
      Bluetooth: Controller: Introduce rate-limiting on stack analysis
      Bluetooth: Remove unnecessary controller-side buffers tracking
      Bluetooth: SMP: Remove redundant ';'
      Bluetooth: hci_ecc: Fix ECDH API usage
      Bluetooth: tests/shell: Limit BR/EDR configuration to Qemu for now
      Bluetooth: conn: Pass disconnect error properly to the conn struct
      Bluetooth: conn: Set initial responder address when connecting

Luiz Augusto von Dentz (4):
      Bluetooth: GATT: Fix using write command when signing was requested
      Bluetooth: GATT: Be consistent with error in case SMP is disabled
      Bluetooth: L2CAP: Fix accounting SDU header len as data
      Bluetooth: GATT: Use sys_slist_t to represent the database

Sathish Narasimman (5):
      Bluetooth: AT: Unit test application init
      Bluetooth: HFP HF: Lookup table for unsolicited commands
      Bluetooth: HFP HF: Add support for RING indication cb
      Bluetooth: HFP HF: Support to send hf AT command
      Bluetooth: AT: Fix - chance of missing UNSOLICITED state

Vinayak Chettimada (17):
      Bluetooth: controller: Kconfig for advanced event preparation
      Bluetooth: controller: Kconfig option for advanced scheduling
      Bluetooth: controller: Hide advance features in Kconfig
      Bluetooth: controller: Move comp id and subver to configuration
      Bluetooth: Kconfig: Move BLUETOOTH_CONTROLLER to Controller file
      Bluetooth: Kconfig: Group stack size related options
      Bluetooth: Kconfig: Group HCI_RAW related options
      Bluetooth: Kconfig: Move BLUETOOTH_MAX_SCO_CONN to BR/EDR
      Bluetooth: Compile BR/EDR independent of BLUETOOTH_CONN check
      Bluetooth: Permit connectionless host-controller combined build
      Bluetooth: controller: Cleanup redundant ticker busy loop
      Bluetooth: controller: Move nRF5 specific debug pins to hal/nrf5
      Bluetooth: controller: Remove util/config.h
      Bluetooth: controller: Make worker and job priority configurable
      Bluetooth: controller: Add BT 5.0 PDU structs
      Bluetooth: controller: Group dup filter Kconfig with buf options
      Bluetooth: controller: Use defined keyword in #if cond compiles

 include/bluetooth/gatt.h                      |   2 +-
 include/bluetooth/hci.h                       |  41 ++++++
 include/bluetooth/hfp_hf.h                    |  50 +++++++
 samples/bluetooth/handsfree/src/main.c        |   6 +
 subsys/bluetooth/Kconfig                      |  12 +-
 subsys/bluetooth/controller/Kconfig           | 120 ++++++++++++++-
 subsys/bluetooth/controller/hal/debug.h       | 199 +------------------------
 subsys/bluetooth/controller/hal/nrf5/debug.h  | 204 ++++++++++++++++++++++++++
 subsys/bluetooth/controller/hci/hci.c         | 132 ++++++++++++++++-
 subsys/bluetooth/controller/hci/hci_driver.c  |  24 ++-
 subsys/bluetooth/controller/ll_sw/ctrl.c      | 152 ++++++++-----------
 subsys/bluetooth/controller/ll_sw/ctrl.h      |  21 ++-
 subsys/bluetooth/controller/ll_sw/ll.c        |  14 +-
 subsys/bluetooth/controller/ll_sw/pdu.h       |  20 +++
 subsys/bluetooth/controller/ticker/ticker.c   | 127 +++++++---------
 subsys/bluetooth/controller/util/config.h     |  30 ----
 subsys/bluetooth/controller/util/mayfly.c     |   2 -
 subsys/bluetooth/controller/util/mayfly.h     |   7 +
 subsys/bluetooth/host/Kconfig                 | 120 +++++++--------
 subsys/bluetooth/host/Makefile                |  32 ++--
 subsys/bluetooth/host/at.c                    |  28 +++-
 subsys/bluetooth/host/at.h                    |   3 +-
 subsys/bluetooth/host/conn.c                  |  15 ++
 subsys/bluetooth/host/conn_internal.h         |  11 +-
 subsys/bluetooth/host/gatt.c                  |  66 ++++-----
 subsys/bluetooth/host/hci_core.c              |  11 +-
 subsys/bluetooth/host/hci_core.h              |   2 +
 subsys/bluetooth/host/hci_ecc.c               | 169 +++++++++++++--------
 subsys/bluetooth/host/hfp_hf.c                | 138 ++++++++++++++++-
 subsys/bluetooth/host/l2cap.c                 |   7 +-
 subsys/bluetooth/host/monitor.c               | 108 +++++++++++---
 subsys/bluetooth/host/monitor.h               |  13 +-
 subsys/bluetooth/host/smp.c                   |   2 +-
 tests/bluetooth/init/prj_controller.conf      |   4 +
 tests/bluetooth/init/prj_controller_4_0.conf  |   4 +
 tests/bluetooth/init/prj_controller_dbg.conf  |   4 +
 tests/bluetooth/init/prj_controller_tiny.conf |  21 +++
 tests/bluetooth/shell/src/main.c              |  39 ++++-
 tests/bluetooth/shell/testcase.ini            |   2 +-
 tests/unit/bluetooth/at/Makefile              |   4 +
 tests/unit/bluetooth/at/prj.conf              |   5 +
 tests/unit/bluetooth/at/src/Makefile          |   4 +
 tests/unit/bluetooth/at/src/main.c            |  76 ++++++++++
 tests/unit/bluetooth/at/testcase.ini          |   4 +
 44 files changed, 1408 insertions(+), 647 deletions(-)
 create mode 100644 subsys/bluetooth/controller/hal/nrf5/debug.h
 delete mode 100644 subsys/bluetooth/controller/util/config.h
 create mode 100644 tests/bluetooth/init/prj_controller_tiny.conf
 create mode 100644 tests/unit/bluetooth/at/Makefile
 create mode 100644 tests/unit/bluetooth/at/prj.conf
 create mode 100644 tests/unit/bluetooth/at/src/Makefile
 create mode 100644 tests/unit/bluetooth/at/src/main.c
 create mode 100644 tests/unit/bluetooth/at/testcase.ini

Change-Id: I3b0f10cdbc59bcaeaea0a1bd8f613e42c829b13f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 12:10:41 +03:00
Johan Hedberg 17efbba7b4 Bluetooth: conn: Set initial responder address when connecting
If the connection process fails the user may still need to do
bt_conn_get_info() in its connected callback, so this needs to give a
meaningful value for the remote address. Start off with the one that
was given to bt_conn_create_le().

Jira: ZEP-2005

Change-Id: I4e9a033dec7c55fa549f5b6746c3bd81c0ccade5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 09:09:26 +00:00
Luiz Augusto von Dentz 87f2f7afec Bluetooth: GATT: Use sys_slist_t to represent the database
This replaces custom made list manipulation with sys_slist_t which makes
the code more readable.

Change-Id: I9ee024ad83da3e28f2ecab74b001bf0e795fe489
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-10 09:08:52 +00:00
Vinayak Chettimada 7a10c35f6b Bluetooth: controller: Use defined keyword in #if cond compiles
Use #if defined(...) constructs while using conditional
compilations of advanced event preparation and advanced
scheduling implementations.

Change-id: I728c76d0e7dbbfa378e8978b726ec404d9e55a72
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:41 +00:00
Vinayak Chettimada 83b7d1b8b7 Bluetooth: controller: Group dup filter Kconfig with buf options
Move the scan duplicate filter length option and group it along
with rx/tx buffer size Kconfig options.

Change-id: I3df07e667029c7d2571270db442ecb7241a417c2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:34 +00:00
Johan Hedberg 71d0843c7d Bluetooth: conn: Pass disconnect error properly to the conn struct
The bt_conn_set_state() function will not notify the connected
callback of the connection error if conn->err isn't properly set.

Jira: ZEP-2005

Change-Id: Idc30e736f4d8ba00156bf5c0e37dcccdb151742f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 08:20:53 +00:00
Youvedeep Singh 724fcffbef debug: Remove dependency of unsetting X86_IAMCU for CONFIG_DEBUG_INFO.
CONFIG_DEBUG_INFO was disabled for IAMCU targets. As per Jira update forked
arch/code is gone. So it should not block enabling DEBUG_INFO for IAMCU.

Currently CONFIG_DEBUG_INFO depends on (x86 = y && !X86_IAMCU)
CONFIG_DEBUG_INFO can not be set for IAMCU. this patch removes dependency.

Jira: ZEP-601

Change-Id: Ib5635096f83f7b931c277b667a55c6d54f8e946a
Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
2017-04-09 14:52:28 +00:00
Carles Cufi 923c470f5d Bluetooth: controller: Fix warning with no dup filter
Conditionally declare the iterator variable to avoid a warning when
compiling the controller without any duplicate filter entries.

Change-Id: I69e23d4c594db18172dc57d45e7925243fe2da69
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:55 +03:00
Vinayak Chettimada 1a62acd00e Bluetooth: controller: Add BT 5.0 PDU structs
Add struct definitions for BT 5.0 PDUs, LL_PHY_REQ,
LL_PHY_RSP, LL_PHY_UPDATE_IND, and LL_MIN_USED_CHANNELS_IND.

Change-id: Ib54209cdf381ba53217eb425696c24d797fe0a30
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg d2ac4a263a Bluetooth: hci_ecc: Fix ECDH API usage
The main issue is that after the latest update to TinyCrypt the
ecc_make_key() API expects a twice as big random number. Fix this, but
also move the variables to the static context since we're limiting one
HCI command at a time. Also place the variables in a union based on
their temporal dependencies. Thanks to this, we can now further reduce
the ECC stack size by 40 bytes (on ARM this then reports 12 bytes of
unused stack after key-pair generation and DHKey calculation).

Change-Id: I1036e0ca15f7c08063cba9e568d7df99e65c9156
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Carles Cufi 9a9699ebdb Bluetooth: controller: Implement event masks
HCI event masking allows the host to choose which events are reported to
it to avoid interruption and excessive traffic. This patch implements
masking to drop any non-enabled events as specified by the host.

Jira: ZEP-1769

Change-Id: If09d4aa22b0da8f743fc42a3b0db3f369daaff96
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Carles Cufi 27e83660ff Bluetooth: controller: Implement scan duplicate filter
Implement the controller's ability to drop duplicate advertising reports
when instructed by the Host.

Jira: ZEP-1246

Change-Id: I2d1b7abf1ed950dde705e5df30a858c595f3834c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 7c22073195 Bluetooth: controller: Make worker and job priority configurable
Add Controller advanced Kconfig options to select IRQ
priorities of the Radio, Ticker's Worker and JOB IRQs.

This will provide an opportunity to have peripheral IRQ's
of higher level than Bluetooth Controller.

Change-id: Iaa128c1cd64a309a77d42d485fdefe68f31e4895
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 1277eea15e Bluetooth: controller: Remove util/config.h
Remove util/config.h and unnecessary redefinitions of
caller ids.

Change-id: I85bb9ae3ab7ff9fcce18c886cfa3e33c91ebb670
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 2de3cc95be Bluetooth: controller: Move nRF5 specific debug pins to hal/nrf5
Move the nRF5 specific GPIO debug pin macro definitions to
hal/nrf5/debug.h.

The Controller's hal folder contains prototypes and
hal/<soc> shall contain SoC specific implementation to
realize a software-based Link Layer.

Change-id: Ic7bf283f926bbc3069e7d15c047fe93a6daa894f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 698de88916 Bluetooth: controller: Cleanup redundant ticker busy loop
Cleanup redundant ticker busy loop that could hang if the
worker and job IRQ priority levels are misconfigured, and
job gets disabled before all users/mayfly functions using
job complete.

Change-id: I053ad75a4328c51cfe651b820a2fa961e42ae48f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada cced2aea30 Bluetooth: Permit connectionless host-controller combined build
In a host plus controller combined build, if no connection
is required, deselect CONFIG_BLUETOOTH_MAX_CONN. This will
reduce RAM and ROM usage in the controller.

Also, make BLUETOOTH_PERIPHERAL, BLUETOOTH_CENTRAL and
BLUETOOTH_CONN switches accessible by the controller kconfig
to select the right roles to enable.

Change-id: I164cf696ab2a6f4859086d2cb18f6d3f2b1399d3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 981f2d3fdb Bluetooth: Compile BR/EDR independent of BLUETOOTH_CONN check
BR/EDR sources that was compiled under BLUETOOTH_CONN
if-clause is moved out as independent conditional
compilation based on selected BR/EDR feature support.

Change-id: Iedfafc6056132654a9150ed235b245f8be62b4b1
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 563fdd784b Bluetooth: SMP: Remove redundant ';'
Change-Id: I889b1768c40b630e00c9856630001dbf7557abba
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 9d7552f8f6 Bluetooth: AT: Fix - chance of missing UNSOLICITED state
If during hfp_hf_send response callback is not filled with NULL
and you receive unsolicited callback. which will not be taken care.
This patch fixes this issue.

Change-Id: I04007059d62273b9cdddf29e2d4a9086b07a01e5
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 9319e441b8 Bluetooth: HFP HF: Support to send hf AT command
A initiation to send AT commands is given in the application
with prefered AT command as the argument.
This patch supports to send the command within the profile stack.

Change-Id: Id5caa3ce64070fc17e60f4ea61a8c83a961099ba
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz a91238aca6 Bluetooth: L2CAP: Fix accounting SDU header len as data
This cause packets that are up to 2 bytes off segment maximum length
to be considered transmitted when in fact that could be some bytes left
to be transmitted which cause any subsequent packet to trigger invalid
SDU on the remote end:

[ 3612.376068] l2cap_le_data_rcv:6757: SDU fragment. chan->sdu->len 66 skb->len 68 chan->sdu_len 67
[ 3612.376073] Bluetooth: Too much LE L2CAP data received

Change-Id: Id2f3469ce1c0b27bb87c4d5bc18e6ede9d93dbde
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 5f69bde72b Bluetooth: Kconfig: Move BLUETOOTH_MAX_SCO_CONN to BR/EDR
Move the Kconfig option BLUETOOTH_MAX_SCO_CONN to BR/EDR if
clause.

Change-id: Iead2bc5a70a9499125f9edf22e85ade4dda8f5ac
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 2d6b82d44d Bluetooth: Kconfig: Group HCI_RAW related options
Move the BLUETOOTH_UART_TO_HOST_DEV_NAME options to after
BLUETOOTH_HCI_RAW option to group it together in the
Kconfig while using menuconfig.

Change-id: I21da080a5ffa30a08b1a1aa148ce8116e63a3c18
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 74cddf9393 Bluetooth: Kconfig: Group stack size related options
Group the stack size related options together to represent a
better order when using menuconfig.

Change-id: Id2968607e5054e30029c42987b3e70cb8cbfc74d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada ddba873aae Bluetooth: Kconfig: Move BLUETOOTH_CONTROLLER to Controller file
Move the Kconfig BLUETOOTH_CONTROLLER switch from top-level
Bluetooth Kconfig to Bluetooth Controller Kconfig.

Change-id: Iead760c22a0fbbda11e4558c4943b3366ecc8769
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz 57a99f6b7a Bluetooth: GATT: Be consistent with error in case SMP is disabled
This makes the code consistent with respect of errors, so instead of
checking directly on bt_gatt_write_without_response let this up to
bt_smp_sign.

Change-Id: Iea8d0bd2020df427b7542e2878ce8d9fd8b94170
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg 757fd755a6 Bluetooth: Remove unnecessary controller-side buffers tracking
When there's no support for connections there's also no need to track
the controller side buffers.

Change-Id: I7eac3af486f139f1ab32efda8ccfa188ed8359eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz 3136aa2ced Bluetooth: GATT: Fix using write command when signing was requested
Checking both if signing has been requested _and_ conn->encrypt can
bypass signing leading to the caller to assume that a proper signature
was send in when fact it was not.

To fix now the code explicitly checks if SMP is enabled and in case it
is and signing was requested fails.

Change-Id: Ie17df4a4c2191f2da0172c687db7999395839a97
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg dd1ba28726 Bluetooth: Controller: Introduce rate-limiting on stack analysis
In case the controller is receiving PDUs very rapidly, prevent it from
spamming the logs by limiting its stack analysis to at most once every
5 seconds.

Change-Id: I31c70d28e8af62b27172a4a77bf6e614ea3e20eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada b593e44da6 Bluetooth: controller: Move comp id and subver to configuration
Move company id and subversion number Kconfig to the
Controller configuration section from the features section.

Change-id: Ic4deb8b24d84d9b1817ba542705eebd612f0e020
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 16bd3d48db Bluetooth: controller: Hide advance features in Kconfig
Added a explicit Kconfig option to show the Controller's
advanced feature configurations. These feature
configurations need specific in-depth Controller
implementation knowledge and should not overwhelm normal
users of the Controller.

Change-id: Iae764f2b266b199cf180936c51c7a4ea089ee510
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada f38d57cba3 Bluetooth: controller: Kconfig option for advanced scheduling
Add Kconfig option to enable advanced scheduling in the
controller.

Enable non-overlapping placement of observer, initiator and
master roles in timespace. Uses window offset in connection
updates and uses connection parameter request in slave role
to negotiate non-overlapping placement with active master
roles to avoid slave roles drifting into active master
roles in the local controller.

This feature maximizes the average data transmission amongst
active concurrent master and slave connections while other
observer, initiator, master or slave roles are active in the
local controller.

Disabling this feature will lead to overlapping role in
timespace leading to skipped events amongst active roles.

Change-id: I16e4e6c3ca99f93987ab86924af0cb9d76bdbc7e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 9028e8e75b Bluetooth: ECC: Fix command status emission from wrong thread
HCI drivers are obliged to send HCI Command Status/Complete events
from a separate context than all other data, however the ECC wrapper
was violating this rule (sending everything from the same ECC thread).
This could lead to a deadlock if e.g. the ECC API user decides to
generate a DHKey from the same callback that it got notified of local
key-pair generation.

The obvious solution is to emit the Command Status directly from the
send function, before passing the command to be processed by the ECC
therad (through a k_fifo). However, this is not quite so simple since
bt_buf_get_cmd_complete() reuses the original command buffer, meaning
we'd loose the original parameters after sending a Command Status.

To work around this limitation with bt_buf_get_cmd_complete() we stop
passing the command buffer to the thread and instead store the
parameters in static variables and do the thread communication using
flags and a semaphore. One side effect is that only one command can be
pending at a time, however that works out fine for all of the users of
ECC.

A nice side effect of moving some things to static variables is that
we end up reducing call stack usage in the ECC thread, allowing it to
be shrunk by 180 bytes (verified to be sufficient for both ARM and
x86 boards).

Change-Id: Ic41f0316d3fe4d14b64fd3d0a549b221d168411a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 646726518f Bluetooth: controller: Kconfig for advanced event preparation
Added Kconfig option to enable advanced event preparation
feature.

Enables advanced event preparation offset ahead of radio
tx/rx, taking into account predictive processing time
requirements in preparation to the event, like control
procedure handling and CPU execution speeds. Crystal
oscillator is retained between closely spaced consecutive
radio events to reduce the overall number of crystal
settling current consumptions.

This feature maximizes radio utilization in an average role
event timeslice when they are closely spaced by using a
reduced offset between preparation and radio event.

By disabling this feature, the controller will use a
constant offset between the preparation and radio event. The
controller will toggle crystal oscillator between two
closely spaced radio events leading to higher average
current due to increased number of crystal settling current
consumptions.

Change-id: I19e640f7395ac7938873ef4bfac38acf8d6f7e0e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 46e649c536 Bluetooth: monitor: Add support for logging packet drops
The monitor protocol provides support for logging packet drops with
the help of the extended monitor header. Implement support for this.

Change-Id: I7ef7894816cb8d1bd876842d0253ef0980471e69
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 1f5a809178 Bluetooth: HFP HF: Add support for RING indication cb
This patch adds support for incoming RING indication callback to
notify application.

> ACL Data RX: Handle 256 flags 0x02 dlen 16   [hci0] 167174.600312
      Channel: 65 len 12 [PSM 3 mode 0] {chan 1}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 8
         FCS: 0x9a
        0d 0a 52 49 4e 47 0d 0a 9a                       ..RING...

Change-Id: I0469590a77d619f2a842df647d84f4d56dbd4883
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg 19d740c162 Bluetooth: monitor: Drop data instead of holding IRQ lock for long
The IRQ lock should never be held for long periods of time. Instead of
using the IRQ lock to prevent monitor protocol corruption simply drop
the data. Follow-up patches will add additional drop count tracking so
that these get reported properly over the protocol.

Change-Id: If498125b29f1b58bed676c78ad2062e2aa206318
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 86d64b4f92 Bluetooth: HFP HF: Lookup table for unsolicited commands
Using lookup table to search for unsolicted command and its
handler function.

Change-Id: Id677dad3918d7187e0065ada2985ec12a97f8ed9
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Jukka Rissanen 749b439863 net: icmpv6: Print received packet type as string
This helps debugging as printable string of the ICMPv6 type is
printed when packet is received if debugging is active.

Change-Id: I22b84bb6b28db7fba030699af3e561a0775b53d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:19 +03:00
Tomasz Bursztyka 8bbe03f35b net/core: Fix wrong parameter usage for check_unknown_option()
It requires a net_nbuf, so the actual buf, and not a frag here.

Change-Id: I4fd888c9a91f5e3f3dd664ae5e3bf93f90a2f597
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-07 18:32:19 +03:00
Jukka Rissanen 3e99c2ea0c net: Move IPv4 packet handling from net_core.c to ipv4.c
This will refactor net_core.c and move IPv4 specific code
into ipv4.c which is a more logical place for it.

Change-Id: Ia60c5bfec488d2d1a664f113dc3df88e7d5badd1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:18 +03:00
Jukka Rissanen d43494d187 net: Move IPv6 packet handling from net_core.c to ipv6.c
This will refactor net_core.c and move IPv6 specific code
into ipv6.c which is a more logical place for it.

Change-Id: I5bbecbb760111326b9a6bbef5802c53d7f6efda9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-07 18:32:18 +03:00
Tomasz Bursztyka 1ab40390c9 net/arp: Return relevant verdict if the ARP packet was consumed
DROP is only on error case, here it should return NET_OK if it was a
proper ARP packet and it got properly handled.

Change-Id: If347e80a76b3a56a9455b70d11b735c1fd910117
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-07 18:32:18 +03:00
Luiz Augusto von Dentz 4d1115ab35 net: Enable context buffer pool in case TCP and 6LO are enabled
The context buffer pool was introduced to deal with TCP holding buffers
when 6LO may modify them, therefore it makes sense to have it enabled
by default when TCP and 6LO are enabled given that the code can deal
with NULL pool in case the application don't implement one.

Change-Id: I600ca31ab40c96ee27937c2e885e332b0cee4995
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 18:32:18 +03:00
Luiz Augusto von Dentz c53b43e4d5 net: ip: Increase RX stack size
RX stack overflow when dealing with TCP over Bluetooth/6lo setup:

RX [rx_stack] stack size 1200/1264 bytes unused 0 usage 1200/1200 (100 %)

Change-Id: I8d5e43faf93f675960e59d9340b97d1ce9fc082a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 13:33:55 +03:00
Luiz Augusto von Dentz 1f4f8f65cb net: buf: Add CONFIG_NET_BUF_WARN_ALLOC_INTERVAL
CONFIG_NET_BUF_WARN_ALLOC_INTERVAL can be used to configure the interval
used to print allocation warnings.

Change-Id: I914f2e0d43b3f00c201e49ff42a45fa950b2df94
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 13:33:55 +03:00
Ravi kumar Veeramally 8ce12d5fe8 net: shell: Fix crash when retrieving remaining reachable time
Shell crashes if you try to retrieve IPv6 nbr reachable time
when CONFIG_NET_IPV6_ND is disabled.

Change-Id: I3c5b3b5614abf80373b892943fa1ab936d235f3c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Ravi kumar Veeramally 7a6f976725 net: rpl: Return valid verdict
Return proper verdict on handling of DIS messages. Otherwise debug
prints will be confusing that packet dropped.

Change-Id: Ia4e18d6238868e3aed4b17e2c9ea11aa432869be
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Ravi kumar Veeramally 7ff7f58771 net: rpl: Refactor few rpl functions
No functionality changes, just refactored few rpl functions to
to align nicely.

Change-Id: I05c0397de7a8392cc781de2747802b2dd1bb8146
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:51 +03:00
Luiz Augusto von Dentz 22acec357e net: buf: Reduce verbosity of net_buf_get
Don't assume NULL returns are always errors.

Change-Id: I28d7a0fa6c848e338635010b1fdc9fc3e8440b27
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 12:35:51 +03:00
Luiz Augusto von Dentz 7cdb750539 net: buf: Generate periodic warnings for allocation that takes too long
This might indicate buffer leaks or deadlock is happening.

Change-Id: If91a65ccfe1be9497b210de21e80b533b6739367
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 12:35:51 +03:00
Paul Sokolovsky a745832dc4 net: Elaborate output of net_nbuf_print_frags() to be more useful.
Following changes are made:

1. Output using NET_INFO logging level. This function is not part of
automatic logging, and must be called explicitly by a user application.
But if it outputs using NET_DEBUG, then DEBUG level needs to be
enabled, and the output of this function will be drowned in logging
spam. So, let user to enable just INFO level.

2. Show entire structure of the fragment chain, *including* the head
net_buf which holds net_nbuf structure. It is numbered as -1 in the
output to preserve existing order (and not change existing size
calculations).

3. Show owning pool (and its properties, like buffer size/user_data
size) for each buffer.

4. Check for NULL pointer, e.g. for convenience of calling directly
from net_context receive callback (which will be called with NULL
on TCP peer closed connection event).

With these changes, a newcomer from one look at the output of this
function will be able to have a clear basic picture of network
buffer management in Zephyr, and recurring user will be able to
recall any details at once.

Change-Id: I8f9562748329d749f765cc6af7989a448256d7e0
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 2a00f418f0 net: rpl: Refactor net_rpl_update_header function
No functionality changes, just refactored net_rpl_update_header
function to align nicely.

Change-Id: I5b3e099593bb964245ca06c9fb2ec85859a0640c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 3e78d38f01 net: event: Add events for ROUTE ADD and DEL
Change-Id: I1d8cb1aebe8a6eb224f6103db0679000bb57c187
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally bcc53c6157 net: route: Update IPv6 packet routing mechanism
Search destination address in IPv6 neighbor table. If it doesn't
exist in IPv6 neighbor table then go for routing. Added sanitycheck
to verify destination ll address is not the source ll address of
original packet (that means we are re-routing back to original sender).

Change-Id: I24adace6a0d17fbd1d2a36a5d75c79320de0a883
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 6cec42d792 net: route: Fix retrieving route nexthop
net_ipv6_nbr_lookup_by_index() will always find first matching entry
in IPv6 nbr table with lladdr index. But there can be multiple neighbors
linked to same lladdr index. So find route nexthop with ipv6_nbr_data
from nbr(ipv6 nbr) data pointer.

Change-Id: I5081d40330f5bc1ef0d96def03f4add4808b2fe9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally 3ebe644dd5 net: if: Fix missing submission of router lifetime timer
Router lifetime timer initialized in router_init but not submitted.

Change-Id: If5a77f413832db52eff99e7191f82d2a8fc8f081
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally d07ca1d518 net: nbr: Fix miss calculation of nbr size
Extra data size was not considered in nbr size calculation.

Change-Id: Idc572abf55c8f9fd19940edb719f58e02e7f8ecd
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally e0bfa15f8d net: rpl: Move net_route_lookup to proper place
Route lookup is necessary only if life time is
NET_RPL_ZERO_LIFETIME, otherwise lookup not required.

Change-Id: I25fb85c53e2d43cfdce08411af385f3ae26384cc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Ravi kumar Veeramally f6af085a4b net: rpl: Add support for DAO retransmissions
If DAO message is routed through different nodes or sent directly
to a parent and ACK lost somewhere in noicy network. Node can not
join RPL mesh network properly. So try re-sending DAO message for
max number of trials (Kconfigurable).

Change-Id: I7f6a065deacd1e3942c89118ce8da4fbaa34af51
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
june li 86cc447f38 net: tcp: Start retry timer when queueing data
When sending TCP data, check if the retry timer needs
to be started.

Change-Id: Iea90716e918dec0b22e60bf32467b11c0d1a296f
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-07 12:35:49 +03:00
Paul Sokolovsky 4a928409e8 subsys/logging: sys_event_logger_get: Fix k_sem_take() success check.
k_sem_take() is documented as returning negative value for error and
0 for success. The old code didn't work.

Change-Id: I717b35d73fced476b50e3207410858f86c2ef9bc
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-06 21:14:22 +00:00
Johan Hedberg 253a7f7064 Revert "subsys/console: Yield on char availability."
This reverts commit 4e2eaec268.

It's invalid to call k_yield from ISR. In fact, it'll trigger an
__ASSERT.

Change-Id: Icc7b81c07c2e7df63fe7d5029fac446ac6fe508b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-06 14:56:23 +03:00
Paul Sokolovsky 4e2eaec268 subsys/console: Yield on char availability.
If this is not done, there is common pattern that on big input block
(e.g. from a clipboard paste), IRQ routine is called in a tight loop,
leading to circular buffer overflow.

Change-Id: I69a7aa78081b8d74652406f3b3a577ddaf4c5f6f
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-06 00:59:47 +00:00
Anas Nashif 7d5be2af73 Merge "Merge net branch into master" 2017-04-01 20:46:11 +00:00
Paul Sokolovsky 542c2b93d0 subsys: console: Add pull-style console API support.
This change introduces console_getchar() and console_getline() API
calls which can be used to get pending console input (either one
char or whole line), or block waiting for one. In this regard, they
are similar to well-known ANSI C function getchar/gets/fgets, and
are intended to ease porting of existing applications to Zephyr, and
indeed, these functions (shaped as an external module) are already
used by few applications.

The implementation of the functions is structured as a new "console"
subsystem. The intention is that further generic console code may be
pulled there instead of being in drivers/console/. Besides the
functions themselves, initialization code and sample applications
are included.

At this time, there're may limitations of how these functions can
be used. For example, console_getchar() and console_getline() are
mutually exclusive, and both are incompatible with callback
(push-style) console API (and e.g. with console shell subsystem
which uses this API). Again, the intention is to make a first step
towards refactoring console subsystem to allow more flexible
real-world usage, better reusability and composability.

Change-Id: I3f4015bb5b26e0656f82f428b11ba30e980d25a0
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-01 20:44:17 +00:00
Tomasz Bursztyka 8108a608ff net/mgmt: Mask vs event should be verified part by part
It needs to check if current event matches:

- cb's layer
- cb's layer code
- cb's command

If none match, it will not raise the event.

Fixing the unit test as layer must be always != 0.

Jira: ZEP-1940

Change-Id: Iadd63e751fa6e534a10e7da9cae0f5bb5a384461
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 12:15:29 +00:00
Tomasz Bursztyka dc7be7c54f net/ieee802154: Disable ACK reply handling by default
Most (if not all) 802.15.4 devices can handle ACK replies by
themselves.

Change-Id: I0319d59de767b20eb67c1592bacaa4a7b7015cad
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka e716b4dcb0 net/ieee802154: Use context instead of interface to reduce stack usage
Now that interface is not directly used in data and mac frame creation,
let's just pass context pointer.

Change-Id: If002e6790d044eeffc57cb5685ac9525fbd6e43c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 0948149b92 net/ieee802154: Use context's extended address when generating frame
Now that RFD is default, the extended address can be changed through net
mgmt API, and thus no longer be the same as device's generated mac address.

Change-Id: I07ee647615c2caa1994712147c6c8a2b4306900d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 0df2a2fdbe net/ieee802154: Simplify data FS settings function signature
There is no need of interface anymore.
After previous changes, it appears that net_if parameter is not used so
we can remove it.

Change-Id: Id3570f50865696818a9be2280172e2e25fc537f7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 5e3354dad5 net/ieee802154: We don't get the MFR from device drivers
commit id 7a11439020 changed this.
Hopefully that changed did not affect anything.

Reducing minimal frame length and applying the change everywhere where
relevant.

Change-Id: I5ae203751bfcf70cef833620106d2c2d0e33b7a5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka d2f8a5a27f net/samples: Add 802.15.4 link-layer security settings for the samples
And use them accordingly in the common code part.

Change-Id: Id91b76e5baea607c0d68eebcde6f84e4e35ca44c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka e3c0310d98 net/ieee802154: Remove ORFD choice altogether.
ORFD was a hack, from the beginning of the IEEE 802.15.4 Soft MAC stack,
but is now useless and can therefore be removed.

Change-Id: I74d5e1995993f4a0749b6d9d553406d5ae162bda
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 26a4df620f samples/net: Uses CONFIG_NET_APP_IEEE802154_* options relevantly
In order to simplify when 802.15.4 is selected on these samples, let's
setup the device through a common code.

For this to work, RFD is now the default.

Change-Id: I46590864442f77d83f681cc0e854c94344648856
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 35dd54d1d7 net/ieee802154: Rename <SET/GET>_CHAN to <SET/GET>_CHANNEL
It's more readable and along with other part of the system.

Change-Id: Ib4be787d74310d838f38b1f1d5624e7357da8969
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 1a647613a4 net: Add 802.15.4 useful Kconfig application settings
These should be used by samples to fix basic 15.4 settings.

Change-Id: I31ad1540008ac760b7aef720e520bf8e72d3a805
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka 0f18ce44f9 net: Rename Kconfig.samples and its main option for future changes
s/SAMPLES/APP for name shortening. Applying the change where relevant.

Not only IP addresse will be available as samples settings there but
also IEEE 802.15.4 channel, pan_id, and more for instance.

Change-Id: I05dd24989bd0c804d9588092d67044a3e063bc88
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:26 +02:00
Tomasz Bursztyka 98cace4a96 net/ieee802154: Expose auxiliary security header validation function
This will be needed for Thread/MLE.

Change-Id: Ib421da66cfc4da8111ff131f08cac74a11674928
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:33 +02:00
Tomasz Bursztyka e771f174e5 net/ieee802154: Add net mgmt requests to set/get security settings
These requests are used to set/get the key, the mode and the level of
the IEEE 802.15.4 link layer security.

Only implicit key mode is supported for now.

Change-Id: Ifbc9a5d08f9fbf0d51d6c3e4b650cfdce3d263db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:33 +02:00
Tomasz Bursztyka 165f8b4d29 net/ieee802154: Integrate link-layer security relevantly
Initialize the ciphers.

Once the header is parsed and validated, we get all the necessary info
to decrypt the frame properly.

Change-Id: I3142fa572c7566b40efe18cf9d4e3f2b4bce0612
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka aa24613347 net/ieee802154: Provide the means to decipher data frames
It's not only about decrypting and authentifying but also setting the
right frag's length after that.

Change-Id: Ifc766b212b37d4e3593c210f6646ee85dff2ab6d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 5e115ba935 net/ieee802154: Provide the means to create secured data frames
Take into account the current security context to compute the header
size.

Provide the function to fill-in the aux security header in a frame.

Finally, call the generic encryption function which will process the
frame relevantly according to the given security context.

For now, only implicit key mode is supported.

Change-Id: I5412c32179e70217c0946b1b54d9a752375d522f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 9d78dba0a1 net/ieee802154: Add generic support for link layer cipher operations
This provides the means to authentify with/without encryption or
decryption of a frame following a generic 15.4 security context.

Change-Id: Ia5dbb7f43936a8131112fe4b16c9780e30f904c1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka fb55449882 net/ieee802154: Normalize one parameter to make it clearer
Some call use a boolean for it, and since it's supposed to be 1 or 0
let's ask for a boolean always.

Change-Id: If4fbe5d58d5c25fb2a86719435c59af53ea02445
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka fb0e2d44ee net/ieee802154: Change function signature for future change
When applying security, there will be needs for accessing payload as
well, thus providing the whole frag directly instead of a data pointer
on the ll part.

Change-Id: Ia97a1f07f2a12fc5cdf085c3cc6350d50b419cae
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 1ee5f3b578 net/ieee802154: Parse and validate auxiliary security header
This will ensure basic auxiliary security header fields are relevantly
filled-in as well as moving the parsing buffer pointer to the right
position for further parsing.

Change-Id: Ib09e312add783b13bf8b59a81a2ffe64eb6f8dc2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka e089f14427 net/ieee802154: Add Auxiliary Security Header definitions
These will be used to parse and create 802.15.4 frames with security
enabled.

Change-Id: Icad214c8d7aa658b8483bf601b091b266e1b8d77
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Jukka Rissanen d593914b17 net: Check if sent packet is meant for us
If the destination IP address is one of our own address,
then reroute it back to us.

Jira: ZEP-1966

Change-Id: I8b93fc5425f3f18b0b9e85ca9a57cb122129c47f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 039e215233 net: shell: Fix the connection status output
The fields in "net conn" output were unaligned and looked
generally very ugly.

Change-Id: I56b29982d4f6b984405944d155bbb6c682383318
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 11305ec928 net: nbuf: Do not crash if context pools are not in use
It is possible that CONFIG_NET_CONTEXT_NBUF_POOL is set but
application has not defined any pools. In this case the tx and
data pool pointers will be NULL in net_context struct and we
must use the default pools instead.

Change-Id: I286f34c87d9182aace71e0a61f038945810e4916
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Jukka Rissanen 6df4ee9691 net: tcp: Allow tweaking of 2MSL timeout
The default timeout (4 min) is very long. Allow tweaking the
value via Kconfig option.

Change-Id: Iddfd48b96f3612b9bba7caa4d64357505df9644d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally e5183fcf97 net: rpl: Fix invalid nbr lookup
Match neighbour with link layer address. And get RPL parent with
matching ll address. DAG id different which is prefix based address
from the parent.

Change-Id: I75ecdfa7aa63da210676a3f44b8510d24c38d1d5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally e6fd75c507 net: rpl: Fix DAO ACK reply
Let intermediate node reply DAO ACK only if it can not forward original
DAO messages to it's parent. If DAO forwarding is success let the final
parent sends DAO ACK.

Change-Id: I14ff9b5b110a639cad6415741dde71c2cdd222ef
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally 8b6166e5c9 net: rpl: Fix invalid parsing of DIO message
DIO message suboptions can contain PAD1, PADN, Metric container,
Routing information, DODAG configuration and Prefix information.
Right now we are not skipping PADN and unknown options payload.

Change-Id: I43557962784f68a223ea209eae5ca0367a3d5410
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:17 +03:00
Ravi kumar Veeramally ea7d1e138c net: rpl: Fix invalid parsing of DAO message
DAO message suboptions can contain PAD1, PADN, Target, Transit
and Target descriptor. Right now we are not skipping PADN and
Target descriptor payload.

Change-Id: I89a9c3cb59de5397d1430f0fa5de95beee193880
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally b77ad7dd6c net: rpl: Add support for handling of DAO ACK
Parse DAO ACK from parent and analyze it.

Change-Id: I2394bd5e339ff00c87b9b4835dd5a21e2bafb2e5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally bfb781dd14 net: rpl: Align Kconfig options properly
Indentation is wrong for few options. And few options does not
properly aligned.

Change-Id: Ib4a8a90a17fd20ddd16ec6f29558eb937f035bb9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally 6280abe372 net: icmpv6: Remove unnecessary cache ptrs for src and dst
Earlier net_nbuf_copy() mangled the original buffer. So cacheing
src and dst address was necessary. Now original buffer does not
get affected by net_nbuf_copy() call. Cacheing is not required.

Change-Id: I25f60bc6db2a75612e562e56024d4459478d80b4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Ravi kumar Veeramally 29fb336ccd net: if: Fix triggering interface link call back
Do not call callback if destination ll address is not set. This
happens when dst is multicast or broadcast.

Change-Id: I34dda92799a987d9cff031dc97f4a01b94437561
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-31 10:58:16 +03:00
Anas Nashif 2c04055970 Merge "Merge bluetooth branch into master" 2017-03-25 11:25:43 +00:00
Vinayak Chettimada 611460b913 Bluetooth: controller: Fix race waiting for ticker job to complt
Same volatile status variable as return and being updated
in ISR would modify the variable in two context which
caused the variable to be set to a stale value.

This commit uses two different variables, one for return
value and the other to be updated by ISR.

Jira: ZEP-1941

Change-id: I19e3bdc85e15bda7891395f3f1f64c2ddbeee0c6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-24 17:06:59 +00:00
Vinayak Chettimada 2d644f2f42 Bluetooth: controller: Fix mayfly caller id for thread call path
role_disable initiated through HCI commands are initiated
in thread context and controller code was using the job
mayfly caller id instead of using the correct app caller
id.

Also the XTAL retain calls being called from two different
call context used the same worker caller id and same mayfly
instead of using the correct caller ids and independent
mayfly for each caller.

This potentially could cause mayfly enqueued list to be
corrupted and enqueued mayfly could be lost.

Change-id: Ia356419462d1fb4e38f4a20c720974143f12fdb6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-24 17:06:43 +00:00
Tomasz Bursztyka 178589fc31 net/net_if: When IPv6 DAD is disabled, added address gets final state
There is no transition from tentative state etc... It should directly go
to preferred.

This is fixing ND processing when DAD is disabled: source address was
never set, as tentative state is not a valid in
is_proper_ipv6_address().

Change-Id: I6f0a0fdd99dd13d28849f9749f89ec21fdd370d8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 53b9c45f11 net/ipv6: Fix a NULL dereferencing issue when debug is enabled
Change-Id: If62aa12acfc07d32ae29068537127d245f8af87e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen aa11cef227 net: shell: Add DNS query support
Add "net dns <hostname> [A | AAAA]" command support that can be
used to query IPv4 or IPv6 address for a given host name.

Change-Id: I86b2258efa994a67163f9b3b340f44d65767f11b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 8dc01261ea net: dns: Initialize DNS resolver if DNS servers are set
If the config file contains DNS server addresses, then
configure the DNS resolver to use them.

Change-Id: Ie7f2bdcf7ac4bb7ee0ecf7fb5b7bd2df3379cdc3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 79cd66f40c net: dns: Add resolve API
This commit introduces a generic DNS resolving API that can
be used by applications. Later commits will introduce a system
level DNS support which simplifies the DNS resolving so that
DNS server names can be given from config file.

Change-Id: I60fbc81e2a44928d2ca53d51e703b9cde222b382
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 850efc270c net/icmpv4: Normalize input function signature with ipv6 counter-part
Length parameter was always useless, only used in debugging, so that can
be removed.

Change-Id: If597f424840f37955202fa5fe827dd992e4cf776
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka e98f2e0b6a net/shell: Add ping reply handlers and a timeout
Thus the ping command is more user-friendly: at least user knows the
ping got a reply or not.

Change-Id: I740a2f77d288f6287ac04c908f3d517a49df57d2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:42 +02:00
Tomasz Bursztyka 19af4eee4f net/icpmv4: Add dynamically registered ICMPv4 handlers
As it is done for ICMPv6. This will prove to be useful for implementing
an echo reply handler in a ping for instance.

Change-Id: I969a1da60f2a4ea59eee5c9983eb6e340923e2ef
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 1d361b0507 net/shell: Simplify ping logic
net_addr_pton always returns -EINVAL in case of error, so let's play with
it to factorize the code.

net_icmpv<4/6>_send_echo_request always returns -EIO in case of error.

Change-Id: I89e5ccd4b936701f7dad194089dda845fab5d738
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 1e3dc0cbb4 net/ipv6: Renaming IPv6 neighbor state related macros and function
Refining the names around IPv6's neighbor states to differentiate them
easily from any net_nbr related names (which are not tighten to IPv6).

Change-Id: Ibc24df2a9485477a53fe5fe1c8f993f0fcd91635
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Tomasz Bursztyka 4991499cab net/ipv6: Regroup debugging routines relevantly
Probably some refactoring left-over.

Change-Id: I9715441a54b2e675135ce4072651dcead3216d3b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen b3e5de641d net: tcp: Invalid transition from FIN_WAIT_1 to CLOSE_WAIT
We incorrectly changed the state from FIN_WAIT_1 to CLOSE_WAIT.
This caused ACK be sent in CLOSE_WAIT state when the connection
was closed by peer. Sending ACK in this state is not allowed
according to RFC. The connection was still closed but slightly
wrong way.

Jira: ZEP-1961

Change-Id: Ie4aa6818128d4190230b679e26ac9630c7d45d69
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 4de6340fe9 net: shell: Add command for testing TCP connection
User can open a TCP connection (just one at a time) by
using "tcp connect <ip> port" command.
Data can be sent by "tcp send <data>" command.
Connection can be closed by "tcp close" command.

Change-Id: I75aedd873a30575a6f742926b716afb7dbbfb92b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 4d0c27209b net: tcp: Refactor net_tcp_trace()
No functionality changes, use separate variable so that we do
not need to do big-endian conversion multiple times.

Change-Id: I8874b427bd39dfa2d952034a2623c47544a644fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 2149ec599e net: ipv6: Adding router mgmt add/del events
If IPv6 router is added, then NET_EVENT_IPV6_ROUTER_ADD event
is generated. When router is removed, NET_EVENT_IPV6_ROUTER_DEL
is then generated. This is useful info if we want to have a generic
connectivity to outside of our local network.

Change-Id: Ia03958a071ceb998127894025c99ab72a8b648d5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Jukka Rissanen 8130208839 net: context: Set the bind port
If the bind port is set to 0, then return the real bind port and
show it in the debug print.

Change-Id: If75b52bdacfc916329222d0d9e8aa4669e7a7160
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:40 +02:00
Gil Pitney 657ad14234 net: offload: More decoupling of net_offload from l2 naming
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

- Rename struct net_l2_offload_ip to struct net_offload
- Rename struct field offload_ip to just offload
- Rename include/net/offload_ip.h -> include/net/net_offload.h

Change-Id: I3cd891c2b13e0e8f3ad1c66264f90b5031ae17c2
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Gil Pitney adb2e7ea2e net: offload: Rename Kconfig NET_L2_OFFLOAD_IP to NET_OFFLOAD
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

This patch simply renames the NET_L2_OFFLOAD_IP Kconfig variable
to NET_OFFLOAD.

Change-Id: Ic8b1d004cbac09b7c636475aaed75b0a31e4be1c
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 1fb8b4aa74 net: route: Fix when route not found with dst address
When route not found try with default router if it exists. Consider
default router as nexthop. If default router also does not exist
then drop the packet.

Change-Id: I56cc9e4a1432fc25687cbaea600bfe9cf5b1d51e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 192ca6c95e net: rpl: Fix verdict for handle_dao_ack
No memory leak but debug prints shows buffer dropped due to
NET_DROP verdict. Added TODO comments to support DAO ACK.

Change-Id: I32deb2e1d2eea98f19ef26ad429ba8d03ae13751
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 42994f37b2 net: rpl: Cache src and dst addresses for DAO ACK reply
When an intermediate node received DAO message, it should forward it
to its parent (if exists) and it ack to orignal DAO sender. But
dao_forward() function steals frag chain from original buffer. Src
and dst address pointers to original buffer are not valid to
continue in dao_ack_send. So cache them for DAO ACK.

Change-Id: I3a4df4837a133afe4e2badb183f729c37d267f63
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:40 +02:00
Ravi kumar Veeramally 97f4f69aee net: rpl: Fix setting metadata of forwarding buffer
When DAO message is required to be forwarding to a parent addr,
only frag chain and iface is considered. But for newly created Tx buf
other metadata also required. In this particular case setting
inet type, ip header length. Also update checksum as dst address
is changed.

Change-Id: If0e0a52e943db66be4aeecb6d0e3b9d7c3f04f58
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 948ec357c7 net: rpl: Fix invalid reading of RPL Transmit information
Path lifetime exists at 6 byte in RPL Transit information. So after
type and option length 3 bytes should be skipped to read lifetime.

Change-Id: Ic90c3bd75e3c7c63ffe9be27c0d206fc8fd58604
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 62116a9b72 net: rpl: Add missing Kconfig option
NET_RPL_DAO_ACK Kconfig option was missed. subsys/net/ip/rpl.c has
functionality of this option. By default it is disabled. Enable it
if you want to know the status of DAO message.

Change-Id: If5ed86c9c8c6c62991fc92d2f1e2a35331811356
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 3bf7eb5cde net: rpl: Handle verdict properly for forwarding_dao
If DAO message is not inteded to destination node then
intermediate node will forward original message with final
destination address. But verdict not passed properly.

Change-Id: If61c7b683b55b24b68f5235d0eee5ed60b611aef
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Ravi kumar Veeramally 72a758fcb6 net: zoap: Fix memory leak
Unref the buffer if net_context_sendto() fails to send.

Change-Id: Iaae81f3044ad7197974493018b873bb76b2c0760
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen 7ef7d305ce net: rpl: Fix printf modifiers for size_t variables
Two size_t variables were printed using %d which gave warning
if RPL debugging was enabled.

Change-Id: I6bc135c76a31da304e94af34ecd571163ddf2a0e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen c4751a7c6b net: Select IPv6 neighbor cache when RPL is enabled
Selecting RPL will need to enable NBR cache support,
it is not enough just to select IPv6.

Change-Id: I8162497111354d0fa9e44564fa5cc5ee46110b96
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Jukka Rissanen 1061ce302a net: route: Try to route IPv6 packet if we are not the recipient
Instead of simply dropping the packet if the destination IPv6
address is not ours, try to figure out if there is a route
to real destination and then re-route the IPv6 packet there.

Change-Id: I6b2a0d7096b3d7877b82b04f38e3a6e588587c11
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Luiz Augusto von Dentz 9f76ce6f88 Bluetooth: L2CAP: Use sys_slist_t for fixed channels
Change-Id: I1a244c3f7d7a9b48844179515e19e71814f2b782
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 17:47:43 +02:00
Luiz Augusto von Dentz 194c4b9af6 Bluetooth: L2CAP: Use sys_slist_t for server channels
Change-Id: I1de0ed8fe82426d9a2049ab5f8c476863f3ea591
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 17:42:14 +02:00
Luiz Augusto von Dentz 41a55893f7 Bluetooth: L2CAP: Use sys_slist_t for connection channels
This avoid having duplicated code for list manipulation in both LE and
BR channels.

Change-Id: I734635e8e51d4b826a3d45cda8551e1e509bd913
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 14:52:52 +02:00
Mariusz Skamra aa435c951f Bluetooth: L2CAP: Fix TX queueing for LE CoC
This fixes an issue found on automated testing. If IUT had no credits
to send data, the TX request was not queued, because -EAGAIN error was
not returned to bt_l2cap_chan_send (which was responsible for queueing).

Scenario:
1. IUT was out of credits
2. Tester requested to send some data
3. Credits was given
4. No data was sent

Fixes: ZEP-1896

Change-Id: Ie9d0945d1e6b628cd978ede8105b37b838a61f1a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2017-03-21 17:05:43 -07:00
Vinayak Chettimada 0efd38885a Bluetooth: controller: Cleanup makefiles
Cleanup controller's root makefile and add folder level
makefile to have better control over dependencies.

Also explicitly include folder paths in c files to clearly
depict the dependencies.

Change-id: Iac7b3a86eff11082111049ba48559c74f6c4d3fb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Vinayak Chettimada 9522b9a37f Bluetooth: controller: Move PDU macros from radio.h to pdu.h
Move the PDU related size definitions out of radio.h and
place it in pdu.h. This will remove hci's dependency on
radio.h.

Change-id: Idf9d7cdf7c60d74816ef2b093c4ae457df16e9a9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Johan Hedberg bb975d3af6 Bluetooth: ATT: Refactor PDU handling
Mark each PDU type explicitly instead of using BT_ATT_OP_CMD_FLAG for
this. For simple "error response or not" selection the command flag is
sufficient, but to prepare for support for enforcing both request and
indication flow control it's useful to easily look up the type of the
PDU.

Additionally, refactor the handler lookup to make the flow a bit more
streamlined.

Change-Id: I575848356934b6d636dcda8d10b7e7fde1095355
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:43 -07:00
Johan Hedberg 6a2d57d90e Bluetooth: ATT: Reorder handler struct for compactness
Move the uint8_t members together to save 4 bytes for each struct.

Change-Id: I522be86397c57fd062018e409b65835912c6e7bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada bd80affa3f Bluetooth: Support connection parameter update as central
bt_conn_le_param_update returns -EBUSY when used in central
role if peer did not support LE connection parameter
request.

This commit allows a central role to use either LE
connection parameter request, if local controller supports
it, else use LE connection update.

Jira: ZEP-1773

Change-id: I72b9c77440459672fd50216a74ffcbd59c5f38f6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada f2f50d8bff Bluetooth: Fix checks for changes in connection parameters
Added checks for latency and timeout changes requested in
bt_conn_le_param_update, to decide if connection parameter
update is needed.

Change-id: I9de9f566158c5ade808ed356cb90b27186aa0243
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 7ce85104b8 Bluetooth: Use specific pointer type for conn->channels
There's no need to be opaque about this. Use the right type and let
the compiler catch errors for incorrect assignments.

Change-Id: If745354f514cbecfe6c0d845ebeaf3b93208b9b8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 24c7397160 Bluetooth: Controller: Increase default TX buffer count
Only 1 TX buffer is sub-optimal for performance since the controller
would always have to wait for the host TX thread to give it another
buffer. Increase the value to 2 so the controller can keep
transmitting data without waiting for the host.

Change-Id: I4841a6c5010f294996d6fe0fe63260b848a6a437
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada f1aabd8ba2 Bluetooth: controller: Replace 0 for pointers with NULL keyword
Updated controller code to use NULL keyword instead of
using 0 for pointers.

Change-id: I5ebff53dfeeba670fb7afe4740596b2662eb0334
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 94831a7589 Bluetooth: Introduce public big-endian AES API
There may be use cases where input and output is in big-endian rather
than little-endian. Introduce a native big-endian API to avoid
excessive byte order reversals in these cases.

Change-Id: Ia7b3e01bb0a07c4560b23f60c2f615ec614eb431
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 6cb853fc04 Bluetooth: Controller: Introduce big-endian variant for ECB
There are some use cases where all parameters are in big-endian. To
avoid excessive byte order reversals introduce a native big-endian
API.

Change-Id: I58fe9156c8819a3a43d715e70b6ba358bd2f844b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 579551ed06 Bluetooth: Controller: Factor out ECB core code from ecb_encrypt()
Do this in preparation of a purely big-endian API (all three
parameters as big-endian).

Change-Id: I815f74549caffd5ac387b5bb84e5851aa96639b9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman f5383b07a2 Bluetooth: AT: Fix reset the state during error
1. Reset the state when error occurs
2. This patch avoids checking for the AT_STATE_UNSOLICITED_CMD state
as the loop exits with possix error. So check for at->state
AT_STATE_START is sufficient for loop termination.
3. Fix different sign warning.

Change-Id: I80a1ca582112f1783690ac8a4125036bb706705f
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman d33ea09968 Bluetooth: HFP HF: SCO Initiate Audio connection
This patch adds support to initiate audio connection from the stack.

< HCI Command: Setup Synchronous... (0x01|0x0028) plen 17  [hci0]
        Handle: 256
        Transmit bandwidth: 8000
        Receive bandwidth: 8000
        Max latency: 7
        Setting: 0x0060
          Input Coding: Linear
          Input Data Format: 2's complement
          Input Sample Size: 16-bit
          # of bits padding at MSB: 0
          Air Coding Format: CVSD
        Retransmission effort: Optimize for power consumption (0x01)
        Packet type: 0x003e
          HV2 may be used
          HV3 may be used
          EV3 may be used
          EV4 may be used
          EV5 may be used

Change-Id: I4f4c0788760c9bdaf75651825511ff6bcd06df59
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman dcf9a97b18 Bluetooth: HFP HF: SCO: Handle SCO Disconnect
This patch handles the SCO disconnection part also unref the connected
corresponding ACL conn.

Change-Id: Ic2de68560cfd7d847e6011578c4424e24800d2ac
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman e0363fd45b Bluetooth: SCO: Rename 'conn' to 'acl'
This patch renames the 'conn' variable to 'acl' which is reference
to ACL connection for SCO connection.

Change-Id: I5f0a60bc5d80de08fa5b963cf545c71552909401
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 495ff6730c Bluetooth: SDP: Server: Support ServiceSearchAttributeRequest
This change adds support for handling Service Search Attribute
Requests.

> ACL data: handle 256 flags 0x02 dlen 24
    L2CAP(d): cid 0x0040 len 20 [psm 1]
        SDP SSA Req: tid 0x0 len 0xf
          pat uuid-16 0x1002 (PubBrwsGrp)
          max 65535
          aid(s) 0x0000 - 0xffff
          cont 00
< ACL data: handle 256 flags 0x00 dlen 109
    L2CAP(d): cid 0x0040 len 105 [psm 1]
        SDP SSA Rsp: tid 0x0 len 0x64
          count 97
          record #0
              aid 0x0000 (SrvRecHndl)
                 uint 0x10000
              aid 0x0002 (SrvRecState)
                 uint 0x0
              aid 0x0006 (LangBaseAttrIDList)
                 < uint 0x656e uint 0x6a uint 0x100 >
              aid 0x0005 (BrwGrpList)
                 < uuid-16 0x1002 (PubBrwsGrp) >
              aid 0x0001 (SrvClassIDList)
                 < uuid-16 0x111f (Handsfree AG) uuid-16 0x1203 (Audio)
              aid 0x0004 (ProtocolDescList)
                 < < uuid-16 0x0100 (L2CAP) > <
                 uuid-16 0x0003 (RFCOMM) uint 0x3 > >
              aid 0x0100 (SrvName)
                 str "HFP AG Service"
              aid 0x0311 (SuppFeatures)
                 uint 0x0
          cont 00

Change-Id: Ib742b09b70271f79aa6462acce25f4c08a9e1a15
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada a91dd34830 Bluetooth: Make LE Encrypt helpers public
Expose LE Encrypt helpers to applications. If software-
based controller is compiled-in, then controller's AES
hardware will be used by the exposed helper interface.

Change-id: I2bac9dfa5ccb3dd50447079affb52d920ae5bd81
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>.
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 3994f4d5b7 Bluetooth: SDP: Server: Send ServiceAttributeResponse
Now that we have all the requested attributes of the service, form
the response packet and send it.

This also renames create_attrib_resp() to create_attrib_list() since
it is basically creating the list of attributes based on the filter.

> ACL Data RX: Handle 256 flags 0x02 dlen 21
      Channel: 64 len 17 [PSM 1 mode 0] {chan 0}
      SDP: Service Attribute Request (0x04) tid 28258 len 12
        Record handle: 0x10000
        Max attribute bytes: 4096
        Attribute list: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            Unsigned Integer (1) with 2 bytes [0 extra bits] len 3
              0x0004
        Continuation state: 0
< ACL Data TX: Handle 256 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 0}
      SDP: Service Attribute Response (0x05) tid 28258 len 23
        Attribute bytes: 20
          Attribute list: [len 17] {position 0}
            Attribute: Protocol Descriptor List (0x0004) [len 2]
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  L2CAP (0x0100)
              Sequence (6) with 5 bytes [8 extra bits] len 7
                UUID (3) with 2 bytes [0 extra bits] len 3
                  RFCOMM (0x0003)
                Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                  0x05
        Continuation state: 0

Change-Id: I54ba00f7700cbb72182dce745d61f5281f83437a
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 32f03a42c7 Bluetooth: controller: Move bt_rand into separate file
Move crypto related interface provided by the
software-based Controller bt_rand into separate file,
crypto.c.

Change-id: I9998a43fe45799b479969ca195f324199418b8c2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 5bf86ea209 Bluetooth: controller: Use explicit paths to internal headers
Use explicit path while including internal header files.

Change-id: Ide80eb23007574a7362850173ac227943bda21d5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 4b10d75fbe Bluetooth: controller: Move LL code from driver to ll_sw
The current hci_driver.c contained all the software Link Layer
initialization code. To decouple HCI from the actual LL, most of the
functionality that is actually part of the LL has been moved to the
ll_sw folder, opening the possibility for future hardware-based LL
implementations.

Change-Id: I1b54d655568a4ec02409da2f1a0addb4d64beed0
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 8dd0374214 Bluetooth: controller: Remove public address config option
Since this presents a risk of public Bluetooth address duplication in
the wild by compiling once with a particular address and then flashing
the same image to multiple devices, a decision has been taken to remove
that config option and replace it later with another mechanism.

Change-Id: I068db25b2996c2409630554b1819b6adc48226cd
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi a7f6656998 Bluetooth: controller: Move ll.h to an include folder
To present a common interface to both software and hardware Link Layers
the API in ll.h now lives in its own separate include/ folder.

Change-Id: I2b0ab0d11b47b9c35a5759bcc30f347e6c616648
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 5517893543 Bluetooth: Make bt_hci_driver instances link-time constants
Declaring these as const lets the linker generate more optimal code.
Some extra care is needed with hci_ecc.c since it was overwriting the
send callback. Now the choice of send() call is done directly in the
bt_send() function

Change-Id: Iac74f5ee9bee097bbb34c11bd13d1d886700f5cc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 61706ca021 Bluetooth: SDP: Server: Find the attributes in the record
Retrieves the record specified by the record handle, go over each
attribute in the record and check whether the attribute is there
in the list provided in the request.

Change-Id: I8f09e0fbb7811a20bb25dc0029cd7c79a9345c88
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Carles Cufi 841c5432cc Bluetooth: controller: Introduce BLUETOOTH_LL_SW
In preparation for future hardware implementations of the BLE
Link Layer, this patch introduces the BLUETOOTH_LL_SW
configuration option to specify that the default software
LL is to be built.

Change-Id: I8b9d5b5e0d2926d18f9e8c8f042a74326895bf95
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Sathish Narasimman befc6510f1 Bluetooth: HFP HF: SCO: Handle synchronous_conn_complete
Handle the synchronous connection complete event received from the
controller and update the event details received.

> HCI Event: Synchronous Connect Complete (0x2c) plen 17
        Status: Success (0x00)
        Handle: 266
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Link type: eSCO (0x02)
        Transmission interval: 0x06
        Retransmission window: 0x02
        RX packet length: 30
        TX packet length: 30
        Air mode: CVSD (0x02)

Change-Id: I4bcd0488f798b112af504245e80180a70b32a882
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 383bc7712d Bluetooth: SDP: Server: Handle ServiceAttributeRequest
Handles the ServiceAttributeRequest, populates the attributes to be
searched in the record specified by the record handle.

Change-Id: I3b702eaf05615f795d32aa30dbfaf91f5b2ce560
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-21 17:05:42 -07:00
Carles Cufi be060208e9 Bluetooth: controller: Rename downstream API calls
Rename all LL downstream API calls from radio_ to ll_ so that they
reflect the layer they are actually targeting. Additionally they have
been moved to ll.h so as to expose a proper interface.

Change-Id: I4fb3946597920c9fafaacb6d87d34d83d75e8f27
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Carles Cufi 7e0a900e05 Bluetooth: controller: Remove unused H:4 tag macros
Remove the H:4 packet type macros that were unused in this file.

Change-Id: If161ddbf2d3adb2871cadd76de0e6c3bb50a16db
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada e3d00bf338 Bluetooth: Controller: Version 5.0 and PDU type rename
Report as Bluetooth 5.0 compliant controller as there are
no mandatory features.

Rename PDU types as per the changes in Bluetooth 5.0
Specification.

Change-id: I1363e054eafd37c2bdca0f69b2638c7edb785787
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 00d8a902b7 Bluetooth: Controller: Add Kconfig range check for public address
Bluetooth device address is 48-bit, added Kconfig range
field to restrict input to 48-bit hexadecimal value.

Change-id: I650343eab5809535137e164e783c9dd4f3e2a6f2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Matthias Ringwald 34b6c53c46 Bluetooth: Controller: Kconfig company id and subversion number
Add Kconfig option to set the Controller's company id and
subversion number.

Change-id: I3508aba18bf0b79fd423c7b4142b6fc57eaf55d7
Signed-off-by: Matthias Ringwald <matthias@bluekitchen-gmbh.com>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 0d75faf02d Bluetooth: Controller: Add advertisement event indication feature
Add a Controller event that indicates everytime
advertisement event has been transmitted on air.

Change-id: I4722488bbfeca987e66983faf5b26467407a89c9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada d8f28bc96a Bluetooth: Controller: Fix RSSI feature conditional compilation
Add ARG_UNUSED on rssi_ready local variable when the RSSI
feature is compiled out.

Change-id: I04f8f11cbc3530f7b85ffa72f27373e213b6e35e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 4b534bc403 Bluetooth: SDP: Server: Send service search response
Now that we have all the records which has the uuids in the
service serach pattern, take the handle of each of those records,
prepare and send the service search response.

> ACL data: handle 256 flags 0x02 dlen 17
    L2CAP(d): cid 0x0040 len 13 [psm 1]
        SDP SS Req: tid 0x6b6f len 0x8
          pat uuid-16 0x0100 (L2CAP)
          max 256
          cont 00
< ACL data: handle 256 flags 0x00 dlen 26
    L2CAP(d): cid 0x0040 len 22 [psm 1]
        SDP SS Rsp: tid 0x6b6f len 0x11
          count 3
          handles 0x10000 0x10001 0x10002
          cont 00

Change-Id: I85ec8ee384d0bf8090265577ec3ef805e75d4766
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Luiz Augusto von Dentz 7aa5ae1feb net: rpl: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: Ib04b6689c59d03328687b0b579e80012dbd2f853
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 11:37:48 +02:00
Luiz Augusto von Dentz 64ccc1d5df net: ipv6: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: I454f40b63133bb7d6239dbe902858932bacfc454
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 11:37:48 +02:00
Jukka Rissanen 9337dd8c22 net: tcp: Print TCP trace in one line
Print TCP header information in one line as there is really no
need to use multiple lines. Also use debug level when printing
the header info so that it is only seen if debugging is activated.

Change-Id: I27f314ca060239545769dec07148897da3426436
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:45 +02:00
Luiz Augusto von Dentz 1b19e16d40 net: if: Make sure k_delayed_work_init is only called once
k_delayed_work_init shall only be called once per work and not every
time before as that can trash the workqueue list if the work is pending.

Change-Id: Ib6398a6a843dd4d820529487ad76a9dc9d9e152e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:45 +02:00
Michael Scott 081246737c net/http: let HTTP_SERVER, HTTP_CLIENT and HTTP_PARSER select HTTP
Due to commit 8308b9bd2d ("net/http: Add the HTTP/1.1 API")
every user of CONFIG_HTTP_PARSER would need to add CONFIG_HTTP to
their .conf files.  Which is fine for intree samples/tests as they
have been adjusted, but the rest of world working on Zephyr apps
will need to make this changes as well.

Instead, we should have each of the following select HTTP instead of
depend on it, which will make future use of these configs and their
dependencies more intuitive:
HTTP_SERVER
HTTP_CLIENT
HTTP_PARSER

NOTE: As cleanup, this commit also removes the CONFIG_HTTP added to
samples and test .conf files.

Change-Id: I81cfaa19e37333b1bf98778f8147814780e7f77c
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-17 10:34:45 +02:00
Luiz Augusto von Dentz 9f8d1c17d9 net: bt: Fix warnings when debug is enabled
This fixes warnings when using %u to print the result of sizeof.

Change-Id: I5391456c855ec2785af22467d9d0f355bbb1e577
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 430e271751 net: icmp: Fix return values of ICMP error send function
The return code from net_icmpv{4|6}_send_error() was not correct
if the error message could be sent. Now 0 is returned if sending
succeed, and <0 otherwise.

Change-Id: Iff67f097a9d9519c9f11d4cbc9cf428a7c74ec1b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 8ae7bb257f net: icmp: Update ICMP statistics for every ICMP packet
Update statistics for every sent, received and dropped
ICMPv{4|6} packet.

Change-Id: Ibe6f02e8222adb3db1f1dbd0cde1ed251710eb43
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen d233f91388 net: icmp: Gracefully timeout net_buf get in RX path
If we are replying ICMPv{4|6} message, then do not wait forever
for a free buffer. In a busy system, this might lead to non-progress
in RX path if we receive lot of packet from the network and never get
a free buffer.

Change-Id: Iaef92541b8745f872a07bc6e2052d0393d4d1e8b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Michael Scott d48ef44d25 net: 6lo: Fix typo in compress bit calculation
commit 2e3e93dccb ("net: 6lo: Fix compress bit calculation") adds
a bit shift to the compress bit calculation, however it's typo'd as
a greater than comparison causing get_6co_compress() to return a
boolean value rather than the shifted version of the calculation.

Change-Id: Idacac2c032a03f1f75a78c94bed4c70428b8c77a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 0a259d6bd0 net: ipv6: Prefix length was incorrectly set
The IPv6 prefix address length was incorrectly set in net_if
after RA was received from the network. The incorrect "len"
variable was used instead of correct "prefix_len" in the prefix
info struct.

Change-Id: Ifeaf150b9960414d2ad200053a3bd5290dc8d365
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 51dea40f80 net: ipv6: Cancel the prefix timer before setting it again
If the earlier prefix timeout is not cancelled before setting
it again, the system will hang.

Change-Id: I6e271294c8e5d43e3ceae4780b5d1c26bab2b296
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:44 +02:00
Tomasz Bursztyka 82545373ee net/mgmt: Remove the list node before unlocking the semaphore
The caller semaphore was released too early, this can cause the caller
to re-use the data and possibly corrupt the memory, if caller yields
and is run before this management thread. Solution is to first remove
the node from the list and then unlock the semaphore.

Change-Id: I02cef53559d776f32a5959380e6b7122cd5198c5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:44 +02:00
Jukka Rissanen 157c383260 net: ipv6: Make config options more fine grained
Add CONFIG_NET_IPV6_NBR_CACHE option that is the base for both
neighbor discovery (ND) and duplicate address detection (DAD).

Both ND and DAD can be disabled if needed. If NBR cache is
disabled, then ND and DAD are disabled too.

Note that it makes not much sense to disable DAD or NBR cache
as IPv6 will not work properly without them. It is possible
to disable ND but then the neighbor information needs to come
via other sources like RPL.

Change-Id: I57c8668ad828b3a153dfc58eea78bf5f7ac3938a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen a623209f62 net: Print error if buf or interface are NULL when receiving pkt
Although very unlikely, I saw crashes at startup that could
be because of the buf or iface were null.

Change-Id: I8649eeb4f24fcd7d9f2acaeefaba4e6593388e91
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 312a9cbb32 net: ipv6: Enhance debug print when handling pending packet
The fragment pointer is good to print here.

Change-Id: If09e684bbe0f9f5d3f961c4af8f86fb3ff364671
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen b18dd41b2d net: ipv6: Clear pending buf if NS cannot be sent
If for some reason the neighbor solicitation cannot be sent,
then we need to unref the pending packet as that would never
be freed otherwise.

Change-Id: Ied12a9b3a027a2aad3fafd0b5b36c56b5f042c28
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen ff6365c928 net: ipv6: Make sure there is data to be sent
If we are trying to send a IPv6 network packet and there
is no data, then print error.

Change-Id: Ia0e7bebae513f1bcf984e189566ae7e10a90bbfc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 13c1037885 net: ipv6: Use net_nbuf_unref() to get better debug prints
When going through fragments in update_ll_reserve(), use
net_nbuf_unref() in order to get better memory allocation
debug prints.

Change-Id: Ia7ee15b32800acdebeb28125465515132c55e179
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 185f36034f net: Ignore everything in RX if interface is not up
No need to receive anything if network interface is down.

Change-Id: I22d62aeaf4fbef54608818bf6c8073ec2e9a7c09
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Jukka Rissanen 318afc4519 net: Synchronize TX and RX threads startup
Make sure that both the TX and RX threads are running before
we turn the network interface up.

Change-Id: Ie7e5938403e90e1ae76047c221cf9fd2f5a1167b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:43 +02:00
Tomasz Bursztyka 1dfd399d77 net/mgmt: Remove a useless k_sem_init() and use K_SEM_DEFINE instead
Change-Id: I95ec89ad67f9d40df6773056d5af6a9df1332ca3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:43 +02:00
Tomasz Bursztyka d6d1b3a748 net/mgmt: Add a network interface based synchronous event listener
In case of callback based event listener, it is easy for the callback to
filter on the given interface. But in case of the synchronous call it's
not: it would need, after a failed comparison on the interface pointer
to loop by itself on the net_mgmt_event_wait() which is a little bit
heavy (reinstalling the event listener, with the semaphore and all) and
a bit of a burden for the caller itself.

Instead, net_mgmt provides a dedicated call
net_mgmt_event_wait_on_iface() which does it the right way, so the
callback and the related semaphore are destroyed if only the iface
matches the one given as parameter (besides the timeout obviously).

Change-Id: Iab05c3249586f4f4d0447eea42fdac72b8428f2e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Tomasz Bursztyka 35e5aa8865 net/mgmt: Add a function to wait on a event synchronously
Instead of creating a handler and a related callback structure on an
event_mask: net_mgmt_event_wait() can be used to wait synchronously on
such event_mask. The core mgmt part will seamlessly reuse the struct
net_mgmt_event_callback so the whole internal notification mechanism is
using the same code.

Change-Id: I426d782c770e75e5222aa3c5b703172b1f1f2e5e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Paul Sokolovsky c1ecd8c890 net: context: For bind debug logging, include context protocol.
It's not enough to know just network address and port number to
disambiguate an endpoint, protocol (TCP vs UDP, etc.) should be
known too. Without this patch, there is a confusing output from
e.g. echo_server if both TCP and UDP is enabled.

Jira: ZEP-1086

Change-Id: I247a2dfc87df634ceac3b8733d7349b1d6aca80c
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-17 10:34:42 +02:00
Paul Sokolovsky 80c2946c42 net: connection: Move proto2str() to utils.c, rename to net_proto2str()
This function is useful for logging in other parts of network stack,
so allow to reuse it. (Will be used for net_context logging in a
follow-up patch).

Change-Id: I8238874584f8f039c94e5d827265944d97d13f6b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-17 10:34:42 +02:00
Luiz Augusto von Dentz e46c8f27ed net: if: Don't check NET_IF_UP in net_if_prepare_events
NET_IF_UP may change during the lifetime of k_pool which means we would
have to reconfigure everytime the flag changes but NET_IF_UP is already
checked during net_if_send_data thus it should never reach the queue in
the first place making this check unnecessary.

Jira: ZEP-1888

Change-Id: Iaa8471bee886a6f7e701a1dd243fb199def26589
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 8cb97ae47d net: Modify IPv4/6 packet finalize API's
Current finalize api's takes buf as input parameter and returns
the finalized buf. But if there are any issue while finalizing,
it failed to throw an error.

Change-Id: I6db54b7453eec41a8051fab50d5c0dc937debd54
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 84a1c87d7f net: rpl: Add API to access default rpl instance
Change-Id: I1b0a3a9065f62d1fa757d93bd752c0f7c47fe821
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 12c98493b8 net: rpl: Fix compilation warnings about format specifier
Change-Id: I1887042586aa77cbb2642a64fba54a36e0bd7a20
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally eaa31ec530 net: context: Fix setting of appdata ptr and length
When IPv6 header contains extra header (e.g. HBH), extra header length
was not part of app data length calculation. Result applications get
invalid total length. Also simplified set_appdata_values().

Change-Id: I07438d62dfd0f9abc1452484deb8b5eacdc37cf1
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:42 +02:00
Ravi kumar Veeramally 593e73615b net: icmpv6: Add support for HBH and RPL option handling
Add support for adding IPv6 extra header (HBH) with RPL options
in ICMPv6 echo reply.

Change-Id: Ibd0b96362a7d5a5f668a18d6a33e6917d37dc51c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally ad855fc31d net: ipv6: Fix handling of RA 6CO options
As per RFC 6775 4.2, context length holds number of leading bits
in the Context Prefix field that are valid. Rest are not valid
for compression.

Change-Id: Id21cc2d7a5d42980cf9295f85e75c4869ff6cb99
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally 137aeb2809 net: rpl: Add RPL header revert utility
When a nodes receive a packet with RPL option in IPv6 HBH, it's need
to be reverted with node flags, instance id and sender rank.

Change-Id: Ic49c8e84c7846dc02728c120078506f6d7411e52
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Ravi kumar Veeramally 643d545cb3 net: core: Fix IPv6 RPL extension parsing
RPL extension header verify function takes input parameter as
metadata 'buf' and start reading from it. Instead it should start
reading from fragment (buf->frags). Also API should return
fragment and offset where caller can continue reading it.

Change-Id: I80612144aed55aa2dcf9eaab1f4408e10efdda31
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen a7133282ce net: shell: Pretty print the neighbor cache info
Make sure the neighbor cache is printed nicely in table
format with columns aligned.

Change-Id: I5323fdc644317ea08fd4694215f8cd44f8d7ff74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen 995ff35a93 net: shell: Add cmd to remove IPv6 neighbor from cache
Add "net nbr rm <ipv6 address>" command. This is useful when
debugging IPv6 neighbor discovery procedure.

Change-Id: Idf1d5628bcf01489ca28a77e9a2f84a8ed041c9a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Flavio Santes 87fc47e1fe net/dns: Fix DNS answer RR computation
- Remove a routine that erroneously computes an answer RR value:
  dns_answer_rdlength.

- Change: dns_unpack_answer_rdlength -> dns_answer_rdlength.

- Change: htonl -> ntohl in the dns_answer_ttl routine.

Change-Id: I8b5a16f63560d3e23dd38cb7339b6e232bb706ea
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-17 10:34:41 +02:00
Flavio Santes 86e6a5d00a net/dns: Fix wrong name in DNS answer type routine
Use dns_answer_type instead of dns_response_type to reflect that
the routine refers to the DNS answer RR.

Change-Id: I6d01add4a1b090b83a0708326a52b7bb945c8d23
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen f55e545376 net: utils: Byte to hex converter had wrong prototype
The net_byte_to_hex() prototype first parameter was uint8_t *,
but it should have been char *.

Jira: ZEP-1885

Change-Id: I6132a67bb9e8199de88451fb4e446081f401e8f6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:41 +02:00
Jukka Rissanen d9528ac7fa net: ipv6: Properly enter DELAY state in NUD
We did not handle NUD (Neighbor Unreachability Detection)
properly and did not go to DELAY state when neighbor
reachability was checked.

Change-Id: I127d25124aa806c44ff37c1355cc3db7fb25b2d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen cd85a5e924 net: ipv6: Add more debugging to reachability timer
Print timer information when creating and expiring the
reachability timer.

Change-Id: I5c8fee91de85fe7c9ea7c467f45dbb105250d5b1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 7848d6e0ff net: ipv6: Wrong timer was used when reachability timer expired
The send_ns timer was used instead of reachable timer when
the reachability timer was expired. This meant that the
reachability timer was never restarted after it expired once.

Change-Id: Iccbd6d019d1106adca60f7319bc4c547cdb1d924
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 49c0444f5c net: shell: Print more detailed neighbor information
Print the neighbor pointer address and remaining time when
viewing the neighbor cache in "net nbr" command.

Change-Id: I13840ccc16c31c99a803ec1b7afe69879bd639f2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen ac74637e54 net: ipv6: Return the prefix lifetime in seconds
Use the proper API to get the remaining time in prefix timer
and return the value in seconds as expected.

Change-Id: I055ce0ba6092c23ad60d6775ce75a0a67ad91d26
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 465ce5bac5 net: ipv6: Send NS when neighbor is added
In order to verify that the neighbor is reachable, send
neighbor solicitation message to neighbor which should then
send neighbor advertisement to us so that we can then mark
it reachable.

Change-Id: I2c45ee4a6982c698ef6c8fa1acccb995aadf8ee6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 2f5ee81c28 net: ipv6: Print IPv6 neighbor state changes
In order to be able to debug IPv6 neighbor state changes,
pretty print the state names when setting the new state.

Change-Id: I64e0b4173eaa63c9715c17420a008602759aa4fa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Jukka Rissanen 91e99ea7da net: ipv6: Add debug function to convert nbr state to string
To be used by net-shell and other files for debugging neighbor
state.

Change-Id: Ie9b09a54a05dcb066906a3697dfe38aeffc886e6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-17 10:34:40 +02:00
Tomasz Bursztyka f6987169d8 net/ieee802154: Fix net mgmt request to get core settings
Obviously s/SET/GET

Change-Id: Iab4fa82ee6c53cb53806bf131655605a21125c3b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:40 +02:00
Tomasz Bursztyka 00a3b880f6 net/ieee802154: Add missing line breaks in the shell module
Change-Id: Ib05922bd2799732107bea1bef218e558dd94f264
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:40 +02:00
Flavio Santes b8f8968f70 net/http: Move some statements to the right place
The "null terminator" for the chunked transfer encoding must be
added only if the payload is present.

Change-Id: Id325a660f060b3a3468bcca16a079def11b8c3ef
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-17 10:34:39 +02:00
Jukka Rissanen a060553666 net: if: Skip error print for already joined mcast group
No need to print error if we have already joined a pre-defined
multicast group.

Change-Id: I1237d5fbf0b63267ccb00432522513358c48d31d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:51 +02:00
Jukka Rissanen 011392dafd net: if: Fix compiler warning when printing TX stack size
Wrong type modifier %zu in debug print, should be %d.

Change-Id: I82feca91d9e083a03263477569c552acc7c9767f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:50 +02:00
Luiz Augusto von Dentz 50ec0864c6 net: bt: Fix memory corruption
Patch 235118245864491a592245f57e5244bf61711943 did not set the ll
addresses in the right buffer which causes 6lo to unref buffers
causing a double unref latter.

Jira: ZEP-1890

Change-Id: Id7591ef3c20c7ab62dcb04576406d70602baa129
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:50 +02:00
Tomasz Bursztyka b1d73aaa98 net/ieee802154: Use pre-filled link address as ll target
IPv6 fills in lladdr_dst properly according to nexthop. Thus it's
useless to lookup again for nbr when creating data frame etc... Let's
use this directly. It both optimizes the code path as well as implements
proper nexthop frame sending.

Jira: ZEP-1863

Change-Id: Ic17a1b14a0db0692d31419ea2f45a5f288a09fb5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:50 +02:00
Tomasz Bursztyka fac10f9b9a net/ieee802154: Display which channel is being scanned
Change-Id: I1917db4ac0ce5e65aff98a290401fa3caa896520
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:50 +02:00
Flavio Santes 8308b9bd2d net/http: Add the HTTP/1.1 API
This patch adds the HTTP/1.1 API for Zephyr. This API consists of client
and server context structures enabled via Kconfig variables.
HTTP parser support is enabled via the CONFIG_HTTP_PARSER configuration
variable.

Currently, this API only includes support for writing HTTP requests
(client mode) and HTTP responses (server mode). TLS support is not
considered in this iteration.

Supported HTTP methods:
	GET, HEAD, OPTIONS and POST.

Supported HTTP responses:
	400, 403 404. The http_response routine may be used to write
	any HTTP status code, for example 200 OK.

Jira: ZEP-1701

Change-Id: Ic9ccd4d4578d6d0f3a439976ea332b031644ca7d
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:49 +02:00
Tomasz Bursztyka e38a9e8b9c net: Switch from per-iface tx thread to a unique k_poll triggered one
Now that k_poll landed in the kernel, it's worth using it to save
memory and reduce the number of threads at runtime.

Such switch has been first done in bluetooth (see hci_core.c and conn.c
in subsys/bluetooth/host). Since network interfaces kind of follows the
same design for sending data, it was then easy to copy the same change as
in bluetooth.

Change-Id: I7f9734b88ac818284bbabaedc946b4765b905ebb
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:49 +02:00
Michael Scott 0453629078 net: ip: Fix 6lo buffer leak when sending ACK
Due to recent TCP fixes for 6lo, we are making a copy of buffers
sent to net_tcp_send_buf() so that TCP retransmit can send the original
(unmodified) buffer.  This original buffer is freed via the TCP
sent_list when the related ACK packet is received.

However, there are users of the net_tcp_send_buf() function which
will never get a corresponding ACK (and do not add the buffer to the
TCP sent_list).  An example is send_ack() in net_context.c.  In this
case, we leak the original buffer.

To fix this leak in the 6lo specific block of net_tcp_send_buf(),
let's check to see if the original buffer was added to the TCP sent_list
and if not, then avoid the buffer copy process entirely.

Change-Id: If99e0e5bf266d33dd3466dc5d74443eaa39d10a8
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:49 +02:00
Flavio Santes 1532013f53 net/dns: Fix style issues
Don't break lines after the static keyword.

Change-Id: I46e3a427d819f864c57b142f38b8956d93b6d428
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:49 +02:00
Flavio Santes f4890e2d87 net/dns: Add the static keyword to the dns_find_null routine
The static keyword is missing in the dns_find_null function definition.

Change-Id: I19c89ca61b6ff550bf7ccb2ca9065a957532ede1
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:49 +02:00
Flavio Santes e376a68bd1 net/dns: Fix style issues in the DNS high-level API
Don't break the line after the static keyword.

Change-Id: I51343124ae3b3a2f9b4916c5279ba09b8c08fd9a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen 6ff97e40c4 net: core: Use K_NO_WAIT when spawning RX and TX threads
Instead of magic constant (0) use the K_NO_WAIT when spawning
a thread.

Change-Id: Ib3a181fdfa246843d9c708592ccc754e54bc6005
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen 2e552b2b59 net: core: Mark RX and TX threads essential
As the networking cannot work without RX or TX threads, mark
them as essential.

Change-Id: Icb52c77fcdcef35d77c36e5ec855fed438a38407
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen df19a423b0 net: todo: Mark multicast join/leave support done
Jira: ZEP-828

Change-Id: I806a80cdc532ac02122f54fbb7df60fa0f3883a4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen aa95a93f38 net: iface: Print error if we cannot join mcast groups
If we cannot join pre-defined allnodes or solicit node multicast
groups, then print error. Typically this will happen if the number
of multicast IPv6 address records is too small in net_if struct.

Change-Id: I12211cff90ef4edc856f1432cab0c37aae9a1bd5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 29a6cc0add net: icmpv6: Add function to unregister ICMPv6 handler
This is only needed when doing unit tests.

Change-Id: Ifd4e5e8ea98e3ab2344ed0c19d92f2be7d8008f8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 75b550e81d net: ipv6: Collect MLD statistics
Collect number of received, sent or dropped multicast listener
reports and queries.

Change-Id: Ia5c08203155475763f96df23f44eceffa7569873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 8d8e3772e6 net: ipv6: Respond to MLD query
If we receive MLDv2 (Multicast Listener Discover) query,
we send out information about the multicast groups that
we have joined.

Change-Id: If4ea9fa685319b2ad900e1949a5cbe12e7696b43
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen ef2ee88af1 net: ipv6: Add router alert option to MLD msg
As dictated by RFC 3810 ch 5, we need to add Hop-by-Hop option
with Router Alert sub-option to the sent multicast listener
message.

Change-Id: I8e3ed58fff4736e9708276a3185f94e7f2b453a3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen c89270c670 net: if: Create support to flush the TX queue
If we are taking network interface down, then flush the TX for any
pending bufs that would be needed to be sent.

Change-Id: I229ecce8e07ec5847d4c6c6a1994de04bd9171e2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 82267e7bd4 net: ipv6: Allow joining to existing multicast address
If the multicast address already exists, then do not give
error but try to join it.

Change-Id: I32ffa6b3bf0798011d684a1a21e87e389f1f0380
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen f8467437e6 net: if: Leave all joined IPv6 multicast groups at net_if_down
When network interface is taken down, leave only those
IPv6 multicast groups that were joined.

Change-Id: I414556c093ba67be7c13e6c86e0451465c2203f3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen c3c76f35cc net: ipv6: Notify others if we join/leave IPv6 mcast group
Send management event if we joined or leaved IPv6 multicast
group.

Change-Id: Ieeb407ef88fb3bf4cd92d4fb4b69f03b260474e7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen ba5bb5a9df net: if: Join/leave pre-defined IPv6 multicast groups
When we setup the network interface, add predefined IPv6 multicast
groups into the network interface. When interface is taken down,
then leave all the multicast groups that joined.
See RFC 4291 ch 2.8 for details.

Change-Id: If17d3e8c75157a02aa93c92e2fb499619c1484cf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:47 +02:00
Jukka Rissanen 74e747a27f net: ipv6: Add support to join/leave multicast group
This and subsequent commits adds API to join or leave
an IPv6 multicast group.

Jira: ZEP-1673

Change-Id: I26dcfe16a4527dbf7886a30827a5d4ebfdeaac01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:47 +02:00
Marcus Shawcroft 0547f51408 net: shell: Fix missing return when IPv6 disabled
Change-Id: Ic7b94841da0966ae9022f26cf71db7912aa79880
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:47 +02:00
june li 07b8e4cb01 net: tcp: Add tcp options length
The tcphdr->offset was not set when tcp options were added.

Change-Id: I19fe97983ce81948a9a84893183e5c9000f12767
Signed-off-by: june li <junelizh@foxmail.com>
2017-03-09 20:33:47 +02:00
Michael Scott eddd598323 net: tcp: remove net_tcp_set_state() function
There are no users of net_tcp_set_state() left outside of
subsys/net/ip/tcp.c.

And the naming of this function is confusing -- it could easily
be mistaken for net_tcp_change_state() which contains additional
logic for certain tcp states.

Let's remove it entirely and fix the remaining uses to set
tcp->state directly.

Change-Id: I92855ad180e8682780fcff11e50af06adcbc177c
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:47 +02:00
Michael Scott a96fbc8167 net: tcp: fix NET_TCP_CLOSED state propagatation
In net_tcp_release() when a TCP connection is being closed, we
should call net_tcp_change_state instead of net_tcp_set_state.

net_tcp_change_state() will call into net_tcp_set_state() but
also contains logic specific to NET_TCP_CLOSED which unregisters
the context's conn_handler and sends an accept callback (if
present) with -ENETRESET error for user code to handle.

This fixes an EISCONN error returned by net_context_bind() when
a TCP-based net_context was reused.  Due to the conn_handler
not being cleaned up in the TCP code.

Change-Id: I8439a028a1c7ae5fd2a50d11caa9947a0ac6c7d4
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-09 20:33:47 +02:00
Jukka Rissanen 673da2fbc8 net: core: Fix IPv6 extension parsing
The parsing of IPv6 extension headers was skipping bytes
in certain cases.

Change-Id: I80612144aed55aa2dcf9eaab1f4408e10ef9ca31
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally 2e3e93dccb net: 6lo: Fix compress bit calculation
Compress bit calculation was wrong. It should be moved
to 4 bits left to cache it properly.

Change-Id: Ib011874881a69032795c2ecfd9a615b6cf559c69
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally dbec3b5838 net: 6lo: Fix invalid check on context id
Max 6lowpan contexts are 16 as per RFC 6775 4.2 6LoWPAN Context Option.
Range is 0 - F. So context id '0' is valid.

Change-Id: I8468a805e0145b64921139a587cdaeeb9d6871b8
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally eb6379dd94 net: 6lo: Fix tiny style and comments issues
Change-Id: I449473dbcc2cc0baa52607a94432c5c18befece5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally 9b9198562b net: 6lo: Fix invalid hoplimit uncompression
If hoplimit bit is unset then values are inlined as
per RFC 6282 3.1.1 HLIM: Hop Limit.

Change-Id: I5821fdf1a4a65b252362277cc604ae913203f80e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally 2b3a12be70 net: 6lo: Fix incorrect order of HLIM and NH compression
Hop limit compression should be after next header compression as
per RFC 6282 3.1.1.

Change-Id: I0eaf3428bf835fe73831a7fe6fb708b73c8f5d12
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Luiz Augusto von Dentz 79ea89624e net: bt: Place ll address type together with other assignments
Change-Id: I15867c9457daf7857ef8dfccbd38419ab8292e8d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:46 +02:00
Luiz Augusto von Dentz d7ed8d62d6 net: bt: Fix setting ll addresses to possible invalid pointers
net_nbuf_ll_src(buf)->addr and net_nbuf_ll_dst(buf)->addr should be
pointing to ctxt area not actual net_nbuf_ll region since the payload
over Bluetooth does not carry any ll addresses.

Change-Id: I87828d74abf2402fdf2a5e34aa8db93aa7c50d08
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally a6bc5cbb19 net: core: Fix IPv6 extra header options handling
If the packet contains IPv6 header + Extra header + ICMPv6 headers,
last header does not contain 'next header and length' fields. So
while parsing header we should first check next header and continue
parsing. Otherwise we parse 2 bytes extra and set invalid ext hdr len
and handover to other layers. So everything goes wrong after that.

Also simplified next header parsing to minimal.

Change-Id: I5d8235c5a57c8b77adf6a07eb8eb74350a3e4dc6
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally 89b7bbfcfd net: core: Remove duplicate calls
If the buffer contains IPv6 header, set header length only once.
Need not to set it in different scenarios.

Change-Id: I54ab9a4259851c9230db240f6091e3190d25b6cb
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:46 +02:00
Ravi kumar Veeramally 3fd8305d6a net: core: Do not handle RPL options if RPL not enabled
If RPL is not enabled do not handle RPL options in IPv6 extra header.
Issues will arise if we skip reading those bytes and continue further.

E.g. Upper layer protocol like ICMPv6 echo request does not prepare
proper echo reply if we skip like this. It doesn't know what options
need to be updated in reply header.

Change-Id: I250672a54d4c7f60727313f6e7f8fe902685d0c5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally 4c58593b79 net: core: Fix missing verdict assignment
Verdict not assgined to its proper value and return NULL in case
of read error. Also simplified error handling.

Change-Id: Idf4c5e242066dfd03e1519271dc1ba38ec43e6ce
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally 5a26d8dacd net: icmpv6: Return valid verdict in case of success
Verdict NET_DROP returned even though it handled properly.

Change-Id: I61e04b12f971b39585e983aa9a1007c63acd8b4e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally e17fe10673 net: icmpv6: Simplify debug calls
Debugging code snippet inside handle_echo_reply() does not look nice,
just provided inline functions and simplified it.

Change-Id: Idc3a9284153aaa04d0431a9dd705c4f1c51b817d
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally 992549ab40 net: icmpv6: Remove unnecessary cache pointers for src and dst
Earlier net_nbuf_copy_all() mangled the original buffer. So cacheing
src and dst address and other values was necessary. Now original
buffer does not get affected by net_nbuf_copy_all() call. Cacheing
is not required.

Change-Id: I8a8534f7ec299853b9b296d85e8aacecd3768c8e
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Ravi kumar Veeramally 476f46f61b net: icmpv6: Remove unused variable 'len' from input calls
Variable len is not used in net_icmpv6_input() and if required
it can be obtained from 'buf'.

Change-Id: I4b0710e1cf16cff9837173ad9d6908ec54ebafae
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:45 +02:00
Jesus Sanchez-Palencia 08f6f5507b net: todo: Remove TCP from TODO
TCP support is already implemented so it can be removed from
TODO file.

Change-Id: I27690120959ffa1e15891e3210bbcc38a3898359
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
2017-03-09 20:33:45 +02:00
Paul Sokolovsky 46eaa94ec5 net: context: Check if conn_handler exists when binding
If a UDP context had net_context_recv() called before
net_context_bind(), then it will have a stale connection handle
associated with initial (random) port number, while will be "bound"
to a new port as specified in net_context_bind(). So, it silently
won't behave as a user expects. net_context_bind() should really
update (or destroy/recreate) conn_handle in this case, but until
it's implemented, apply stopgap measure of at lease reporting error
back to user in this case.

Jira: ZEP-1644

Change-Id: I22ad55f94eaac487a4d5091ccbb24f973ec71553
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-03-09 20:33:45 +02:00
Jukka Rissanen 58d6e20493 net: nbuf: Print more info when trying double free net_buf
Print information who freed the net_buf last time if this
can be figured out. This info is not fully accurate if there
is lot of allocations going on but could give some indicatation
who was using the net_buf previously.

Change-Id: I3d4463c54a9b944847a532d951fb6d2303fc06cf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:45 +02:00
Jukka Rissanen a616aa1f58 net: 6lo: ieee802154: Memory leak when unfragmenting received data
If we could not allocate a buffer while unfragmenting, make sure
that all the created temporary net_buf artifacts are freed and
we do not have a memory leak.

Change-Id: Ib98ae32eb4a0f9b5f92c51e9713fd8e6d78b10da
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen ac7a05bbba net: 6lo: ieee802154: Do no try to unref NULL net_buf
It is possible that the cached buf is NULL so avoid nasty
error print by not trying to free NULL pointer.

Change-Id: Iec53164f6ffab4b830aba63a1f351ca2349a43ff
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen f8ae384dae net: nbuf: Print adjust value if we fail in read or write
If net_nbuf_read() or net_nbuf_write() offset adjustment fails,
print the offset value in order to make debugging easier.

Change-Id: I899998bdcbc91a25ed7d71a599a5052a6fa4ee36
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen f031c2be37 net: nbuf: Do not delete the fragments in net_nbuf_unref()
Show only what would be freed when debugging the allocations.
Let the net_buf_unref() to delete the individual fragments.

Change-Id: I1a39a553f12d73b78c4ba08be0e8e8252b666c8e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 93f7f9f3e6 net: shell: Show also ISR and main stack usage
The "net stacks" command will also print main and interrupt
handler stack sizes.

Change-Id: I1b867be81ac8b4f6d9446f484ebb8b1d852b98b0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen f8c60de061 net: nbuf: Create net_nbuf_frag_del() for tracking allocations
Create net_nbuf_frag_del() so that we can track net_buf frees.
If CONFIG_NET_DEBUG_NET_BUF is not defined, then this new function
will call net_buf_frag_del() directly, and if not, then it will
track memory usage.

Change-Id: I5f382436cebc71fdaf12baf7bf964fb63bee7aca
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 99097e53cb net: shell: Add cmd to see net_buf allocations
This commit adds "net allocs" command that can be used to
track net_buf allocations that are done by net_nbuf_get*()
and net_nbuf_unref().

Change-Id: If3dc2ecf5552f8008138ee9733458a19f9764c13
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 38d26d07e9 net: nbuf: Track memory allocations
User can track memory allocations and deallocations.
This is enabled by CONFIG_NET_DEBUG_NET_BUF option.

Change-Id: I9d83b9b63fb2b141c9a283887f1770bb4232f61c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 573eea0884 net: nbuf: Remove unnecessary buf init
No need to set the buf to NULL as it will get its value
from net_buf_alloc() call anyway.

Change-Id: Ib3a32b6e4cb4b446761b6a97a88c20fc52d3d683
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 038664ac6f net: if: Clarify the documentation in net_if_send_data()
Add description what happens if NET_DROP is returned from
L2 send function.

Change-Id: I371de725b710041bb26a141f9860c0062fb1ef5d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 5032bdc46d net: nbuf: Pass ll_reserve when creating TX buffer
Instead of always calling net_nbuf_get_reserve_tx() with zero
ll_reserve (first parameter) and then setting the link layer
reserve separately, pass the reserve to that function which can
then set the ll_reserve in buf itself.

Change-Id: I21c14cb7e2e6c36d170c09998bca0207ecf65c75
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 189ec2b6ad net: Remove link layer reserve param from IP packet creator
The ll_reserve parameter is useless in net_ipv{4|6}_create_raw()
function as the reserve information is already stored in buf.

Change-Id: I7815a78c001e3da532478c04b3dac9b37bbc723c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 5197266768 net: nbuf: Use net_nbuf_get_frag() to allocate a fragment
The code used net_nbuf_get_reserve_{rx|tx}_data() function to
allocate a fragment. Instead of that low level function, use
net_nbuf_get_frag() instead. There are few places this is not
possible or is too big change like in few test programs.

Change-Id: Ied7e2b7db352de998b200ffa6ff82471bfa5ebe3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 0fdee2ef5d net: nbuf: Print pool name instead of address in debug prints
The net_buf pool address is not very useful so print the
user friendly name of the pool instead.

Change-Id: I1c64621c816832d2459819490ec5609f5c39f9f1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 4111b994b7 net: shell: Fix the info prints for net_buf pools
The columns were not aligned properly.

Change-Id: I551d04182c2877a29bb02a9da5400d74a080a1c9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen d32503f57e net: nbuf: Split one global DATA pool to RX and TX DATA pools
If we receive lot of packets, it might happen that we exhaust
all the DATA buffers in the system. This would prevent from
us sending anything to the network.
Change this by splitting the DATA buffer pool into RX and TX
parts. This way RX flooding cannot consume all DATA buffers
that needs to be sent.

Change-Id: I8e8934c6d5fdd47b579ffa6268721b5eb3d64b6d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 2478dd250b net: context: TCP packets must be send via net_tcp_send_data()
Do not shortcut the sending side for TCP as we need to use
net_tcp_send_data() to send TCP data in order not to have
double unref in Bluetooth or IEEE 802.15.4 technologies which
has a special TCP packet sending logic.

Change-Id: I077db336c6335ccdbbafa4600f98388ecf33955f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 93533b37d8 net: tcp: Fix the issues with 6lo
When sending TCP data using 802.15.4 or Bluetooth technologies,
the 6lo code modified the original IPv6 header. This caused
issue when acknowledgment was waited to the sent packet as
the code could never match the sequence and ack numbers in
TCP header.

This commit changes this and the packet is cloned when sending
it so the 6lo code will modify a copy of the data and will not
touch the original packet.

JIRA: ZEP-1719

Change-Id: Iae51f35d5b5ada0d2543b58a29abbf10f146777e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen e18f76ce60 net: conn: Print UDP and TCP checksum after receiving pkt
Enhance the connection debugging and print the UDP and TCP
checksum when the packet is received.

Change-Id: I1ccf58a299178277fab0667b01d54ad7bac38663
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 30a3f5ce88 net: 6lo: Change how net_buf is allocated in RX side
If there is lot of network traffic, it is possible that all the
network packets are allocated by network driver. The device driver
places the received packets into RX queue. Then that queue is read
by 6lo code. During the uncompression, the 6lo code tries allocate
net_buf in order to place proper IPv6 header into it.
If all the data fragments are in use at this point, then 6lo cannot
continue and it blocks while waiting available net_buf. This leads
to deadlock in the stack.
The solution is to change the 6lo to allocate the net_buf using a
timeout which will cause the received packet to be dropped if it
cannot be uncompressed because of out-of-buf situation.

Change-Id: I137f02b05193e16c45da8804974d357c920c861d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 10979d8326 net: 6lo: Use dedicated buf pool if enabled
When doing 6lo compression or 802.15.4 fragmentation,
use the API that uses dedicated net_buf pool if that
support is enabled by the user.

Change-Id: Ic6651c393832c759eebb66a41db31c9067ebb4a9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 4bcc2a47d0 net: nbuf: Fix net_nbuf_copy() so that original nbuf is not modified
It makes no sense to modify the original net_buf so change the
copy function not to touch the original buffer.

Change-Id: I5d22445ce50cee62994c36567f0e995a500cb89d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 6a4372b0df net: nbuf: Fix the net_nbuf_copy() buf parameter
The first parameter of net_nbuf_copy() must be the head
of the buffer chain i.e., it must contain the user_data
part. If a fragment is given, then we do not know enough
information to allocate the data fragments.

Change-Id: I052b183d8c63d7326b320254f36f00b2fc48b0a0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen a5dbf31b3a net: shell: Print network buffer pool information
Print information about various network buffer pools in the
system. This is useful in debugging the buffer allocations.

Change-Id: I31123c6f1f6647f77503f32e268c174330762128
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 7719cee113 net: Add net_buf pool support to each context
User can configure its own pools for data that needs to
be transmitted out (TX). This helps to avoid deadlocking
the system if user space application uses all the buffers
in the system, and the core IP stack tries to get buffer
that needs to be sent out.

By default the net_buf pool support in net_context is turned
off as application developer needs to create the pools and
tie them to desired contexts.

Change-Id: Ida4a1771d34d6c250974e56fba4f0e0b2592cb29
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 9fce1626d7 net: nbuf: Remove unnecessary debugging code
As the pool contains now more accounting information, there is
no need to keep track of this data in nbuf.c.

Change-Id: I7fd44f9feda8fd9816356556d1e788ad56e6eedd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 7218d0d64b net: buf: Add more accounting info to net_buf pool
Adding this information to the pool:
* number of available (free) buffers in pool
* total size of the pool in bytes

This can be used when debugging net_buf pool allocations.

Change-Id: I4212fcddb1affdf53e0827c88473d3380e2a4929
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft 7c193b7f9f net/dhcpv4: Support REBINDING
Change-Id: I1e3809b3cde1dec29a001e750cb191cfac046dab
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft f8cc065d13 net/dhcpv4: Refactor t1 handler.
Rewrite the dhcpv4_t1_timeout() handler to explicitly handle all
states.

Change-Id: I6f9d6c8cfacd945e24eb66c6440bf305d528c521
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft b42a6b3192 net/dhcpv4: Remove !iface checks from timeout handlers.
The iface handle checks in the both timeout handlers are unnecessary.
Drop them.

Change-Id: Ie7c884b2ea648f700fbefa8382341036a4db063f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft b0df4bf260 net/dhcpv4: Fix the behaviour of ciaddr.
Correct the logic that determines when CIADDR is set and when it is
left as all zeros. RFC2131 requires that CIADDR is only set when the
client is in specific states.

Change-Id: I93a45e355fbef8d11dba5ac194570b87c594656e
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 045d317b9b net/dhcpv4: Use BROADCAST and UNICAST appropriately.
RFC2131 places explict requirements on a client w.r.t which messages
are broadcast and which are unicast directly to a server.  Notable
rules as they apply to the current dhcpv4 implementation are that
DISCOVER and a REQUEST in response to an OFFER are broadcast.  A
REQUEST in state RENEWAL is unicast.  There are further rules relevant
to the REBINDING state which is not yet implementated.

Adjust the current implementation that always uses broadcast to use
unicast as required by RFC2131

Change-Id: I6edef4241bcd74623a804a73415888cd679888d0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 4b24c18f5f net/dhcpv4: Use server identifier appropriately.
RFC2131 requries that a client MUST NOT include server identifier in
DHCPREQUEST from state RENEWING.

Change-Id: I0fba703f3a3b218af1ac03f4f1f0daa290bd428f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 53f0823113 net/dhcpv4: Call net_if_ipv4_addr_rm
The DHCPv4 client obtains resources from the server on a lease.  Once
a lease expires those resources must be relinquished.

Update the DHCPv4 client to explicitly remove leased resources from
the network stack once a lease has expired.

Change-Id: I5d3b7a02e463041cfdee1d104f5962498bdd6a30
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 3726bb98bd net/dhcpv4: Introduce start/stop API and disabled state.
Change-Id: Iae3b96dd91325ecf51b33b8c58f65aa5ec2b40c9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft c4f4cb17db net/dhcpv4: Rework initialization.
The existing dhcpv4 initialization code places all initialization in
the per iface dhcpv4_start() code.  The net_udp_register() setup needs
to happen once for the dhcpv4 instance rather than once per iface.
Subsequent patches in this series also need a place to perform one
time initialization, independent of iface.

Factor the one time setup code out of the existing net_dhcpv4_start()
into a dhcpv4_init() function.  Rather than use SYS_INIT() to run
dhcpv_init() we hook directly into net_init().

The prototype of dhcpv4_init() is shared within the net subsystem with
a new private header file deliberately to avoid exposing the function
via the public API in include/net/dhcpv4.h

Change-Id: I3502a53cc3bfe4db4e4cd22c02ae133c266fdf10
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 010102ae02 net/dhcpv4: Refactor REQUESTING state entry.
Factor out common code associated with entering the REQUESTING state.

Change-Id: I0fc038a49309625c24b874dfda0355794cd41da9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 653d614e1e net/dhcpv4: Refactor SELECTING state entry.
Factor out common code associated with entering the SELECTING state.

Change-Id: If34929e5f13dff7650388a2b491a01cbbf5dc100
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 5cfc917617 net/dhcpv4: Refactor send_discover
Refactor send_discover() to provide a clean separation between state
machine and action.

Change-Id: I96510cc6a7ab16216821fe65ea4289a78f6443aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 33bb4c0f21 net/dhcpv4: Refactor send_request state handling.
Refactor send_request() to provide a clean separation between state
machine and action.

Change-Id: If4c61c5789c919ab3ce6c1f914afc243176760d8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 9dd39e1553 net/dhcpv4: Implement NAK support.
Handle the NAK message.

Change-Id: Ia3686564b083b16bd409bbe39acc500404f90fe0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 57b24721b2 net/dhcpv4: Refactor handle_reply()
Split handle_reply into distinct state machine and actions.

Change-Id: Ib177c7a4007662f941f156acfa5791e1d27e3d73
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft b840664c11 net/dhcpv4: Adjust state names to reflect rfc2131
The dhcpv4 state machine implementation names differ from the names
used by the relevant rfc.  There is no good reason for them to be
different, so rename them.

Change-Id: I837f1bc4788c0ed4d2949b12eb6f5bfeef9a0be8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1f279e13b3 net/dhcpv4: Unify dhcpv4 state name printers
There are two implementations of dhcpv4 state name numbers to human
readable strings, unify the two.

Change-Id: I1d654918bb919108a0d8c5514b309b193c9c3f96
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 8df38dc55f net/dhcpv4: Move timers inside the net_if dhcpv4 context
The dhcpv4 state machine has a dedicated context within each net_if
structure.  For reasons unknown the timers used by the dhcpv4 state
machine have been placed in net_if outside of the dhcpv4 context area.
Relocate them into the dhcpv4 context.

Change-Id: I0531f493610dffda9ca9208993597a5665bde997
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 5dcc56ebed net/dhcpv4: Refactor dhcpv4 message type representation.
Change the message type representation from integer to enum, this will
help prevent re-occurrence of recent issues where states and events
are interchanged by making it more likely the compiler will see a type
mismatch.

Change-Id: Ia235afda428a9e5dfbd933e02beeae468b4c84a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 0d0cdc23a6 net/dhcpv4: Refactor packet construction
Refactor and simplify packet construction.  This resulting code is
simplier, easier to read and compiles a lot smaller.

Change-Id: I43c67d79fbb77f85af54355eca41f516054cbba3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1559a3b3e8 net/dhcpv4: Add missing const
Change-Id: I213b35936eb862d5abc4356a1a920cc2fef02f3f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Jesus Sanchez-Palencia b21cfc2404 net: context: Make packet_received() static
This function is used only within net_context.c, make the symbol static
then.

Change-Id: Ib2c00a21c25e8c6a1404d6345d4b8ae05b779525
Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
2017-03-09 20:33:40 +02:00
Vinicius Costa Gomes 8f409f28b4 lib/zoap: Fix warning about signedness conversion
'query->value' is a 'const uint8_t *' so it should be casted to a
char (signed) array before it is used in places where a 'char *'
is expected, strncmp() is an example.

Jira: ZEP-1810

Change-Id: I94cf780a40ad5fed29607d2302dc7a10387bb86f
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-03-09 20:33:40 +02:00
Leandro Pereira 4a0e008e8d net: tcp: ACK packet should not be forwarded to application
Since we try to match with POSIX behavior as much as possible, let's
not bother the user unless they need to be bothered.  The recv(2) POSIX
syscall won't return 0 on stream sockets unless the connection has been
closed by the peer; however, that was happening with the callback set
by net_context_recv().

Change it so that the callback is never called if operating on a stream
socket and appdatalen is set to 0.

This is similar to a previous patch sent by Michael Scott in [1], but
not relying on the actual TCP flags: only on the appdatalen and the
socket type.

[1] https://gerrit.zephyrproject.org/r/#/c/9949/

Jira: ZEP-1632

Change-Id: Ib0c214fc9269d305a03e8d85eb606f106c45b038
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-03-09 20:33:40 +02:00
Sathish Narasimman e51a19fdc2 Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask

> HCI Event: Connect Request (0x04) plen 10           [hci0] 126.198264
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Class: 0x7a020c
          Major class: Phone (cellular, cordless, payphone, modem)
          Minor class: Smart phone
          Networking (LAN, Ad hoc)
          Capturing (Scanner, Microphone)
          Object Transfer (v-Inbox, v-Folder)
          Audio (Speaker, Microphone, Headset)
          Telephony (Cordless telephony, Modem, Headset)
        Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Transmit bandwidth: 8000
        Receive bandwidth: 8000
        Max latency: 7
        Setting: 0x0060
          Input Coding: Linear
          Input Data Format: 2's complement
          Input Sample Size: 16-bit
          # of bits padding at MSB: 0
          Air Coding Format: CVSD
        Retransmission effort: Optimize for power consumption (0x01)
        Packet type: 0x0006
          HV2 may be used
          HV3 may be used
> HCI Event: Command Status (0x0f) plen 4           [hci0] 126.205171
      Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
        Status: Success (0x00)

Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:35:28 +00:00
Sathish Narasimman 5490c80383 Bluetooth: HFP HF: SCO: Add esco supported pkt type
From the response of read_local_supported_feaatures check if local
device supports eSCO packet type and update it to bt_dev.
Also added sco field in bt_dev

Change-Id: If85b3d24d327a6243318fad89a07375a8253f89b
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:35:06 +00:00
Sathish Narasimman 83bb08fbd9 Bluetooth: HFP HF: Handling AG Network error
This patch includes handling AG network error i.e +CME ERROR and
report the error number.

Change-Id: I19a3158e44568ad0ad21fb0dd790ac2f554c0625
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:34:31 +00:00
Sathish Narasimman 1d44e345be Bluetooth: AT: Fix 'signed' warning
Jira: ZEP-1857

Change-Id: Ie9647048544442a004f9b55e3ae889f472b08281
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:34:08 +00:00
Vinayak Chettimada 16608e9a51 Bluetooth: Controller: mayfly enable to supercede over disable
If mayfly enable is called before mayfly could be disabled,
then enable shall supercede disabling, the mayfly will
remain enabled. Any new mayfly enqueued by the caller that
tried to disable mayfly will be chain for deferred
executon under this condition.

The BLE Controller's connection update procedure broke when
mayfly implementation was updated to defer disabling until
all queued mayfly where completed. Mayfly is disabled
between ticker_stop and ticker_start calls to chain them
so that ticker does not power off counter h/w if the ticker
being stopped is last one.

This commit fixes the connection update procedure which
used the mayfly enable before mayfly disable could
complete.

Jira: ZEP-1839

Change-id: I07d34c90d193b5eca9762acd8b7272e8d7a78474
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-08 15:14:32 +00:00
Vinayak Chettimada ecc0f83d92 Bluetooth: Controller: Fix assert on role stop/abort
Call to ticker_stop/update can fail under the condition
where in a role is being stopped but at the same time it is
preempted by the role event that also uses ticker_stop/
update.

Also if a role closes graceful while it is being stopped,
the radio ISR will process the stop state with no active
role at that instance in time. In this case just reset the
state to none, the role has already been gracefully closed
before this ISR execution. The above applies to aborting a
role event too.

This commit adds code to detect these conditions and
deterministically recover from it.

This commit fixes the assert observed while stopping
advertiser in the Bluetooth sample scan_adv.

Jira: ZEP-1852

Change-id: I51c8d6e212ef43e3526a199cf7b666a79729c732
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-08 15:14:22 +00:00
Vinayak Chettimada 8747090426 Bluetooth: Controller: Kconfig option to set public address
Added Kconfig option to be able set public address. Seems
conformance testers look for valid public address.

Change-Id: I2c4f702117f99a42c9eef0133b46556a1c6d1496
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 14:51:54 +01:00
Luiz Augusto von Dentz a9655eee4b Bluetooth: L2CAP: Add TX queueing for LE CoC
This allows to queue buffer to sent later in case it runs out of
credits so it no longer blocks the caller thread.

Jira: ZEP-1776

Change-Id: Ifa9b412f98889b50c0b889655d910520d11a4718
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 13:24:58 +02:00
Luiz Augusto von Dentz 03ff07ea7f Bluetooth: L2CAP: Move functions in preparation for queuing
This moves necessary functions that will be needed for queuing packets
while waiting for more credits.

Jira: ZEP-1776

Change-Id: I030c696d432ec5be1b8e6b649e953da145929777
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada 966fbbcd04 Bluetooth: Controller: Run all enqueued mayfly before disable
Controller asserted in preparation of a role event due to
the previous (same or another) role event preparation being
not complete.

Mayfly callee was disabled in the previous event due to the
preparation time being short and previous start running
(higher natural priority) before all previous preparation
mayfly completed. The previous start disabled mayfly to
avoid Radio ISR latencies.

The current role event that asserted, preempted the
previous role (observer role with continuous scanning
window) which runs until preemption to maximise the Radio
h/w use (observer scanning until next interval). The
previous preparation mayfly is still disabled when the
current role preparation tries to use same mayfly instance
which should be free for a new enqueue.

This commit updates mayfly implementation so that mayfly
callee is disabled only after all enqueued mayfly instances
are run to completion.

Jira: ZEP-1839

Change-id: I3e0d31422db8e47b819189110b11ebd07dd09a7c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg 0ed68c7680 Bluetooth: Relax minimum advertising interval for 5.0 controllers
The 100ms limit is only valid for controllers before version 5.0. For
a 5.0 controller the minimum is 20ms (0x00a0) which is already checked
for later in the valid_adv_param() function.

Change-Id: I0566a38ff855800d2e46e1d2c0a5c7bc9bc610cd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi ff3e6e333f Bluetooth: controller: Report 5.0 compliant controller
Since there are no mandatory features in 5.0 when compared to a 4.2
compliant controller, report 5.0 as the current specification
implemented by the controller, to allow for features such as short
advertising intervals (< 100ms) which are already supported.

Change-Id: I1b138a86290a0422760a5e265cdd7b72d68f0048
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg f253f4e14c Bluetooth: Add support for Bluetooth 5.0 version specifier
Add support for detecting version 5.0, i.e. 0x09.

Change-Id: Ia2da513b65c420142fe97a4fa173bfa8045e9d75
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas f7a4d112ae Bluetooth: SDP: Server: Filter records based on requested uuids
Filters the service records by going through all the records and
removes the one which does not have the uuid. So finally, only
the records which has all the uuids in the service search pattern
will be present in matching recs.

Change-Id: I1daa7c1b645efae2af66962999cc4c541891eff7
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz 480cdbd6d3 Bluetooth: GATT: Add bt_gatt_get_mtu API
bt_gatt_get_mtu can be useful when GATT is used to transport another
protocol on top.

Change-Id: I328ef49138ccc4ce642b0019d08060f6022d5aa7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas e3705b2f60 Bluetooth: SDP: Server: Handle Service Search request
Handles the service search request from peer, parses the service
search pattern (which is a data elem seq of uuids to be searched)
and populate the uuids.

This also populates the registered records which will be filtered
based on the uuids in the pattern (which will be done in the subsequent
patch).

Change-Id: I9a232a7cfdd159325214ed13e98cc20be39a2e3b
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Jaganath Kanakkassery 85b2a7e056 Bluetooth: SDP: Server: Introduce private define for max services
This is mainly done to avoid VLAs for looking up the service to handle
service search requests so that we can make sure that RX stack size
is sufficient for the defined no of services.

Change-Id: Ia99072615d9094a35bd7605ed2901e8018c0ecb2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish d0c78ce6d4 Bluetooth: AVDTP: Rename of variables
Renaming the params in bt_avdtp_req.

Change-Id: Ibc84931d0fa1d3af0a017f25a9893e51fb06bd1b
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish 7f27599aba Bluetooth: AVDTP: Fix discover param struct
Changed bt_avdtp_req variable from pointer to variable

Change-Id: Ie1270b7da4f6130e89259c6b5c999407d56b33d8
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz a05cea3a22 Bluetooth: GATT: Use __ASSERT for invalid parameters
Instead of returning -EINVAL at runtime assert in case of invalid
parameters.

Change-Id: I40505f06a4c12445bfb1f1846ace1b592b6bc342
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas c25df73c5a Bluetooth: SDP: Server: Refactor data element structure header
Separate out data element structure header into type and size fields

Change-Id: I869ee1ea82db1f6d669bb905055135b7d63f3fa2
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas 690d455b78 Bluetooth: SDP: Server: Set security level to NONE
Change-Id: I67e18ba3060d0cbe703be9cd0b31e72e2b18d429
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas 6699f5a52f Bluetooth: SDP: Server: Fix MTU setting after l2cap connection
L2CAP TX and RX MTUs will be exchanged during configuration req/rsp.
It should not be modified after connection.

Change-Id: I1e291c9e093561f349bcdcbb75cd7ff22b4163a5
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi 3141dcf3b4 Bluetooth: controller: Introduce debug pins Kconfig option
A new Kconfig debug option now controls the usage of pin toggling to
debug the BLE controller.

Change-Id: I24c5c13ca71e3395e10f14e27ad4bca9f2e94687
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Carles Cufi 34e0c4b253 Bluetooth: controller: Set debug pins with macros
Use macros to identify the different debug pins used to monitor the
runtime behavior of the controller, for easier identification of the
lines.

Change-Id: Ia76d6298985b1d367b7ad193d8261f5403446371
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Piyush Itankar edb32b74d1 Bluetooth: A2DP: Stream End Point Registration
Added an API to allow addition of stream end points by the application.

Change-Id: I91b95fc5dc3b9b2950e8d55b5846e460e55f2453
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada c78601481d Bluetooth: Controller: Fix LE Ping PDU dispatch
It was observed that due to possible CRC errors, one
connection interval was not sufficient by the peer to
respond to LE Ping PDU which caused the Controller to
generate the Authenticated Payload Timeout event to host.

This fix advanced the dispatch of LE Ping PDU by 6
connection intervals that the peer would listen to before
the 30s timeout.

Change-id: I6c292c623047a05b4e771e70093d87228db62cce
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada 16ef73423e Bluetooth: Controller: Use direct ISR for Radio IRQ only
The new hard real-time (direct) interrupt support is used
only for Radio IRQ. Only Radio ISR has hard real-time
requirement of completing its execution inside the tIFS of
150us.

This commit reverts back RTC0 and SWI4 ISR to using the
normal IRQ_CONNECT.

Observed on nRF51, Radio ISR (open text, notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 44us and max. of 77us.

Observed on nRF51, Radio ISR (LESC, fast encrypted,
notifications):
Latencies: min. of 5us and max. of 10us.
CPU utilized: min. of 39us and max. of 112us.

Jira: ZEP-1038

Change-id: Id3d09df7bdbdfea090f21f6f58aaded8c5f1e10d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Arun Jagadish 4efe5eb5b1 Bluetooth: AVDTP: Add AVDTP Receive Function
Added AVDTP Receive function, to recieve L2CAP Data.
Handlers added to parse AVDTP Signal ID

Change-Id: Iedfc4b6883d6cf27615d90a0d37ed10869e47ff3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi 727987276e Bluetooth: controller: Use direct ISRs
The new hard real-time (direct) interrupt support in the kernel allows
ISRs to be run directly with no significant latency overhead.

Use this new mechanism to improve the latency of the 3 critical
interrupts in the controller: radio, RTC0 and SWI4.

Jira: ZEP-1038

Change-Id: Ief9dacbea4c4c2e8a1c77893a0d6175a91819ffb
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Szymon Janc 767cd577dc Bluetooth: GATT: Fix subscriptions removal
This fix not removing subscription if it was first element on the list.
In that case prev was NULL resulting in passing garbage node to
sys_slist_remove.

Change-Id: I9452af08409692f9a331afd514fbac8cc727d289
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc 8637c23e41 Bluetooth: GATT: Remove not needed variable
prev is not used.

Change-Id: I735be33a3a763fcdee316fdf6cacfaa26e216210
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc da9f9cc3f7 Bluetooth: Fix connection object leak
When canceling outgoing connection initial reference was not dropped.

btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) disconnected -> connect-scan
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
Connection pending
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> disconnect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) connect-scan -> disconnected
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
Connection failed
btshell>

Change-Id: I0c38bbed8d1712d07a579275355e7dcd8d6b0b38
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc 48b9c97b8f Bluetooth: SMP: Fix passkey entry for legacy pairing
This fix legacy pairing with passkey entry model when passkey
is fisr entered on local side. Replying with error in that case
is bogus as we should just wait for remote confirm.

Change-Id: I75480802928fd29d21617aa9250f90df647eb9a2
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Jithu Joseph fce0d9a865 subsys: gdb_server: Fix type mismatch
This was flagged by ISSM icx compiler.

JIRA: ZEP-1806

Change-Id: Iebd04febbdce9b92a4d0cae986ca7f84f4da58a0
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2017-03-01 14:26:16 +00:00
Anas Nashif c78a3485e2 Merge "Merge net branch into master" 2017-02-27 22:32:01 +00:00
Anas Nashif 69170173c8 kernel: use k_cycle_get_32 instead of sys_cycle_get_32
Jira: ZEP-1787
Change-Id: I948100e75697dc106a4ba12ce51401673d79fe68
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-02-27 21:10:32 +00:00
Flavio Santes 6383705e53 net/dns: Improve unaligned memory access
Improve unaligned memory access in some inline routines.

Change-Id: I8065b4ac399a5f9f03997b43d8f8f8d320778ec3
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-27 08:34:06 +00:00
Marcus Shawcroft 5028503d61 net/l2/ieeee802154: Fix typo in ieee802154_reserve name
Change-Id: I64112dfc04872d07b5dc4394d98b0ebd04222f53
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-27 08:30:02 +00:00
Jukka Rissanen 4852d6859b net: ipv6: Do not try to unref null pointer
If the DAD timeouts, then the pending pointer will be null
when we remove the neighbor. Fortunately this only prints
this error message and does not cause any issues in the code.

[net/nbuf] [DBG] net_nbuf_unref_debug: (0x00118350): *** ERROR *** \
  buf 0x00000000 (nbr_clear_ns_pending():175)

Change-Id: I3e11d4aa1d90f205df591b5d5cdcf2ee7bde6c01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:55 +02:00
Vinicius Costa Gomes 8e304ef2e6 iot/zoap: Fix requiring that the buffer is unchanged for retransmit
It is possible that the buffer waiting for retransmission is modified
after it is sent, for example, it can be compacted by 6lo, and our
assumption of where is the message ID is located in the buffer is no
longer valid.

As the message ID is the only information that is necessary for
keeping track of retransmissions, we keep a copy of it in the pending
struct, as well as the destination address of the retransmission.

Change-Id: Id33d54353404628673541225a1a05e27ee08765f
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen c27aced5bf net: if: Remove local address from IPv6 neighbor cache
When we do DAD (Duplicate Address Detection), the local IPv6
address gets added to the neighbor cache. This is useless so
remove it after DAD has finished.

Change-Id: I9625d367e96d8108a7d3d1d8b2e95f3c4ea11c45
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen f5477582bd net: ipv6: Add util to remove neighbor from cache
Add net_ipv6_nbr_rm() utility function that can be used to
remove an IPv6 neighbor from the cache.

Change-Id: I9794856a4f65c5e943656970648e5c5762b0338c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen ab740c00c7 net: shell: Print IPv6 neighbor information
Add "net nbr" command which prints IPv6 neighbor cache
contents.

Change-Id: I7c26ecb117e8b77e64e3be3c0164a94f0d1775bf
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen d29e073c62 net: ipv6: Add util to traverse neighbor cache entries
Add utility function to go through all the stored neighbors
in the IPv6 neighbor cache.

Change-Id: I42fe0ec48c000215403aef63629d0763189ebdbb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen c13753587f net: icmpv6: Echo-Reply seq and id fix
The sequence and identifier fields are 16-bit instead of 32-bit
long. This did not cause any issue in Echo-Reply but those two
fields should be set properly.

Change-Id: I5e4878f53d6bb37660d46d173159d27bbe0e94dc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:53 +02:00
Jukka Rissanen 02a06f6489 net: icmpv6: Add TCP header when sending ICMPv6 error
TCP header was not sent back to originator when ICMPv6
error message was prepared to be sent.

Change-Id: I171bd724c4260b83d7d1c37e0894f9ed8cddd2c9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:53 +02:00
Jukka Rissanen 75c48fcbf2 net: buf: net_buf_frag_del() had insufficient debugging
In order to see who is freeing the fragment, add function
and line information to net_buf_frag_del() when net_buf
debugging is activated.

Change-Id: I732f579fab2390cb16804cb35b83f46e65fca342
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:26 +02:00
Ravi kumar Veeramally 05d5dcf007 net: tcp: Retransmit buffers are not freed on tcp_release
TCP maintains 'sent_list' for retransmission if it doesn't get ACK for it.
Same list is not freed on net_tcp_release() call. This causes memory leak.

Change-Id: I2b2def1ea19487cc48ea4fbb6343ef0c773f288f
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-22 17:28:25 +02:00
Michael Scott f30a9e51c1 net: context: let tcp_established() handle more TCP states
Due to commit fece856959 ("net: tcp: Clean up FIN handling") the
tcp_established() callback now handles TCP connections which are
in various ending/closing states other than TCP_ESTABLISHED.

Currently, these states are generating the following error and not
being processed:
Context 0x123456778 in wrong state 6.
(Shown when TCP is in LAST_ACK state).

This commit also fixes a memory leak issue discribed in
Jira: ZEP-1658

Analysis of the memory leak issue is here:
When TCP connection is established, tcp context is in
NET_TCP_ESTABLISHED state. Once it receives FIN message from client
it goes to NET_TCP_CLOSE_WAIT and then it turns to NET_TCP_LAST_ACK
after connection closing request from server. Now server gets final
ack from client, but tcp_established() will reject it because current
state is not in NET_TCP_ESTABLISHED. Even if server receives proper
ack, it is not handled by server. Hence 'sent_list' is not freed.

Change-Id: I41c8af2e6851809f87a02c271a4290cf3d823ebb
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-22 17:28:25 +02:00
Ravi kumar Veeramally 4da61f7fc7 net: context: Fix invalid order of statements
NET_ASSERT(net_nbuf_iface(buf)) should be called before setting
it on context [net_context_set_iface(context, net_nbuf_iface(buf))].

Change-Id: I9a1da1214857e96e03784bc98a9aae5cf59ef0fc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-22 17:28:25 +02:00
Tomasz Bursztyka 46298d5a45 net/utils: Fix parameters type
Using char or uint8_t relevantly.

Jira: ZEP-1723

Change-Id: I512cb6ff4800cd23f6539e7a47c7f3c72dc94183
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen 4eb2020055 net: Set the network link address type when setting link address
The interface L2 address type is set at the same time as the
L2 address is set to the network interface. This is most
convinient place to set the address type.

Change-Id: I712d7357d075959eb79df3463141cfbc6d163a74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:25 +02:00
Flavio Santes 057f31e7e9 net/mqtt: Remove length computations for some msg fields
Currently, for the following MQTT msg fields:

- client_id
- will_topic
- user_name
- topic

their length is computed inside the routine that receives the MQTT msg.

Although this simplifies development, also imposes one restriction:
data must be null-terminated. Sometimes, data is received from other
sources and not generated by the application, so the null-terminated
constraint may be considered problematic for the user.

This patch removes the assumption that string fields are null-terminated.
Current data structures are already prepared to handle this case, so no
API change is required.

Change-Id: I5a147a5b21e0da49541cbe62baac363c8737cd3e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-15 12:20:08 +02:00
Flavio Santes 84403077d2 net/mqtt: Add payload size validation
Validate payload size before starting to decodify MQTT messages.

Change-Id: I02653b5e41f930ca75de8f0395b2a7df315e12c5
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-15 12:20:08 +02:00
Flavio Santes 9c8d2d9fb8 net/mqtt: Use uint32_t for Remaining Length encoding/decoding
This patch updates the Remaining Length field from uint16_t to
uint32_t. The MQTT std specifies that this field must be
unsigned 4 bytes length.

Change-Id: I319d0745c673faece4bbd4db29b1bafad78ac199
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-15 12:20:08 +02:00
Marcus Shawcroft 0296cdd728 net/dhcpv4: Ensure udp header checksum is computed correctly
The dhcpv4 client code builds ip and udp packets from scratch rather
than using the network stack to do the heavy lifting (why ?).

When it computes the udp checksum of each packet it builds it neglects
to clear any preexisting detritus from the checksum field.  The result
of this is that some packets will be built with correct checksums and
some will be built with incorrect checksums.

This is the underlying reason that the dhcp client often taken many
retransmissions and elapsed time before in order to acquire an IP
address.

Change-Id: Iebd1ed34e06f7f2e53d45f6d1555e22f48490287
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft ccd6d8c79f net/dhcpv4: Remove unused dhcpv4 offer state
The offer state is unused, remove it.

Change-Id: I9d6217dae291bb90c57c77ce439809bf7e9a9177
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Marcus Shawcroft 45e199c812 net/dhcpv4: Fix event/state mismatch
Fix long standing issue where a dhcpv4 message type is compared
against a dhcpv4 state machine state name rather than a message type.
The issue probably arizes due to the similarity in names between
messages and states.  By accident, the relevant message types and
states happen to share the same numbers, hence the implementation
works, but is ill defined.

Change-Id: I5c028de4336ff42f6696e28b3492c932c58b5a05
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Flavio Santes bed71d0a02 net/mqtt: Fix inline doc for MQTT
Fix inline documentation for the MQTT API.

Jira: ZEP-1669

Change-Id: I90702eae236a9189b58e0f2fb2a6c5a3eeaf959c
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-14 08:30:34 +02:00
Vinicius Costa Gomes d8d16e81f5 iot/zoap: Add missing const modifier to header file
Makes it cleared that zoap_update_from_block() doesn't modify the
packet.

Change-Id: I35429b153370c50eb5ae9c914b47a3144faf2f04
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-14 08:30:33 +02:00
Vinicius Costa Gomes e190ffe200 iot/zoap: Fix handling of 16-bytes block-wise transfers
This fixes the case that a request for block number (NUM) 0, using a
16 byte block was considered invalid.

This was because it is encoded as the value 0 (zero), which can be
expressed as the BLOCK1 option present but without any value
associated. The old code considered this the same as the option not
existing.

Change-Id: I0f3912803a88865e9f544a6d0078ed4231775a88
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-14 08:30:33 +02:00
Leandro Pereira 570634a259 kernel: Add OpenOCD support
In order for OpenOCD to have a high-level view of an RTOS, it uses the
GDB protocol to obtain symbols from the system.

The GDB protocol, however, does not allow obtaining fields from
structures directly, and hardcoding offsets is not only brittle (due to
possibly different architectures or changes in the code), it's also
infeasible considering Zephyr is highly-configurable and parts of key
structs can be compiled in or out.

Export an array with offsets for these key structs. Also add a version
element in that array to allow changes in those structs.

Change-Id: I83bcfa0a7bd57d85582e5ec6efe70e1cceb1fc51
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-02-11 03:57:19 +00:00
Luiz Augusto von Dentz b4b395845a Bluetooth: GATT: Fix compilation error
List container changes apparently were merged in the wrong order causing
leaving it with a compilation error.

Change-Id: Ib9d9502ddb39330c262e495a33592d0340713d83
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 20:54:34 +02:00
Anas Nashif 8c7aa9aa85 Merge "Merge bluetooth branch into master" 2017-02-10 16:37:56 +00:00
Luiz Augusto von Dentz a8ed185615 Bluetooth: Convert FOR_EACH macro instances to use CONTAINER
Change-Id: I02c31842db5df10dda3e15bff370d2e459cc909d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 16:16:15 +00:00
Luiz Augusto von Dentz 4ab09bdead net: Convert FOR_EACH macro instances to use CONTAINER
Change-Id: I2fbdc8128bef79eac74441c84fbb80e31f6bc261
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 16:16:15 +00:00
Johan Hedberg 01c821f56f Merge bluetooth branch into master
Some more Bluetooth fixes for 1.7.0-rc1.

----------------------------------------------------------------
Arun Jagadish (1):
      Bluetooth: AVDTP: Moving structures to headerfile

Johan Hedberg (1):
      Bluetooth: Fix missing connection cleanup in some scenarios

Luiz Augusto von Dentz (1):
      Bluetooth: GATT: Fix not updating previous node

Prasanna Karthik (1):
      Bluetooth: nble: Catch and handle non-zero fn_index

Szymon Janc (1):
      Bluetooth: Fix not clearing signaled flag for conn_change signal

 drivers/bluetooth/nble/rpc_deserialize.c |  3 +-
 subsys/bluetooth/host/avdtp.c            | 10 ----
 subsys/bluetooth/host/avdtp_internal.h   | 13 +++++
 subsys/bluetooth/host/conn.c             | 49 +++++++++++------
 subsys/bluetooth/host/conn_internal.h    |  1 +
 subsys/bluetooth/host/gatt.c             |  1 +
 6 files changed, 48 insertions(+), 29 deletions(-)

Change-Id: If1d53d9767d89080480ce5147156adeeb26565dc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-10 18:03:51 +02:00
Arun Jagadish 40f91b7105 Bluetooth: AVDTP: Moving structures to headerfile
Moving AVDTP structure - bt_avdtp_req,to header file.

Change-Id: I6e3bbc9e5b45ae7009cc5d94ae50a08b0490f4fa
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-10 10:37:05 +00:00
Marcus Shawcroft 4c08b15c63 net/dhcpv4: Ensure the retransmission attempts counter gets reset.
Change-Id: I4c7c478425ca6f602a397295c36573a4453346d3
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-10 11:25:26 +02:00
Jukka Rissanen c3b0f35f6f net: if: Change the iface param in net_if_ipv6_maddr_lookup
Change the handling of iface parameter in net_if_ipv6_maddr_lookup()
function:
  * If the *iface is set to NULL, then return the found
    interface to the caller.
  * If the *iface is not NULL, then use that interface
    when doing the lookup.

Change-Id: Ia1f0365170ea9f3e615d189231160614a80d241a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:26 +02:00
Jukka Rissanen 253030c654 net: context: Fix the multicast address lookup in bind
Because of the change in next commit "net: if: Change
the iface param in net_if_ipv6_maddr_lookup",
we must initialize the network interface to NULL.
Without this the multicast address lookup will fail.

Change-Id: I113b44ce23c5f2ecbbf1698972078f102995e891
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Jukka Rissanen c357349e44 net: if: Change the addr param type in net_if_ipv6_maddr_add/rm
Make the IP address parameter const because we are not
modifying the IP address in net_if_ipv6_maddr_add() or
net_if_ipv6_maddr_rm()

Change-Id: I98c19de132e58c386f661e8a76a349d562a82c71
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Jukka Rissanen c0f6a5ecd8 net: nbuf: Fix constness of data param in net_nbuf_append
As the function does not change the original data, make
the corresponding parameter const.

Change-Id: I1125a2f9205dc73de2f0aac0c30110591baace1e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Johan Hedberg 6c995a5053 Bluetooth: Fix missing connection cleanup in some scenarios
If the TX thread is not in k_poll() when conn->state gets set to
DISCONNECTED and a dummy buffer is pushed to conn->tx_queue the
bt_conn_prepare_events() function would have failed to add the
connection to the poll list for cleanup. To ensure the cleanup always
happens introduce a new flag that indicates that a cleanup must
happen. The extra benefit of the flag is that we no-longer need a
dummy buffer, but can simply use the conn_change signal to wake up the
TX thread.

Change-Id: I369584d305261ab3666b931c786daff9d131d228
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-10 10:09:10 +02:00
Szymon Janc fb3317b7a1 Bluetooth: Fix not clearing signaled flag for conn_change signal
From k_poll_signal_init() documentation:
The poll signal contains a 'signaled' field that, when set by
k_poll_signal(), stays set until the user sets it back to 0. It thus
has to be reset by the user before being passed again to k_poll() or
k_poll() will consider it being signaled, and will return immediately.

Change-Id: I55daac92dd6293ac653fd7fa0f907b0b7fd99d65
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-10 06:18:05 +00:00
Luiz Augusto von Dentz 92e8d91332 Bluetooth: GATT: Fix not updating previous node
When iterating to the subscriptions to be removed the code has to keep
a reference to the previous node but it case the subscription matches but
doesn't need to be removed it doesn't update the prev node which may
corrupt the list in case the next node end up being removed.

Change-Id: Ic5448f01bf78d293f93b9a7078a0147385ea1d23
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 08:16:41 +02:00
Marcus Shawcroft 878aa5f15c net/dhcpv4: Correct backoff and retransmit behaviour
Implement RFC2131 4.1.1 requirement that at dhcp implementation wait
for a random delay of 1 to 10s before sending the initial DISCOVER.

Implement RF2131 4.1 requirement that at dhcp implementation set the
initial retransmit timeout at 4 seconds and exponentially backoff on
each retransmit.

Change-Id: Id7029f3ed16a5f886dbd555fed87320aeffe31aa
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft d06ca47eb3 net/dhcpv4: Use unique XID on each request.
Rather than reuse XID's on retransmissions, always use a unique XID.

Either behaviour is permitted by rfc2131.  Debugging the dhcp client
in the presence of multiple dhcp servers with significant packet loss
in the network is much easier if we don't unnecessarily reuse request
identifiers.

Change-Id: I5c82cbdbf3dfc0ef88cae036aa863946844c144f
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:11 +00:00
Marcus Shawcroft 8cd2e089d6 net/dhcpv4: Add further diagnostics.
Change-Id: I13fed6b6102d7711082f16de3f782c606808b142
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:10 +00:00
Ravi kumar Veeramally b45c4c7353 net: tcp: Remove multiple times of nbuf_compact() call
finalize_segment() will call net_ipv4_finalize() or
net_ipv6_finalize(). Both the functions perform net_nbuf_compact().
But after finalize_segment(), net_nbuf_compact() called again, which
is unnecessary.

Change-Id: I9fab63bcc44eec87061a4b55edd5053cf6556a75
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Ravi kumar Veeramally d3ea2021f4 net: tcp: Remove multiple checks on nbuf protocol family
Protocol family is checked in prepare_segment() and in same function
it's again verified by finalize_segment(). So remove the double checking
in finalize_segment().

Change-Id: I17123ab8741d017d7e3ff1ef3fb07371b0d4aa66
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Ravi kumar Veeramally 369e906e31 net: Ref net_buf using net_nbuf_ref
Using net_buf_ref() technically works but debugging the network buffer
allocations is more difficult if done like that.

Change-Id: Iac81bd3ab95547741d49f32763baaa54e97b4877
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-09 09:43:06 +02:00
Anas Nashif 31f01f8ed6 Merge "Merge net branch into master" 2017-02-08 12:03:09 +00:00
Johan Hedberg 79883c9834 Merge bluetooth branch into master
- Use k_poll to consolidate all TX threads into a single one
 - Reuse HCI command buffers for storing their response
 - Improvements to SDP client support
 - New "volatile subscription" flag to GATT API
 - Various smaller fixes & cleanups here and there

----------------------------------------------------------------
Arkadiusz Lichwa (8):
      Bluetooth: SDP: Get ProtocolDescriptorList attribute internals
      Bluetooth: shell: Add SDP client support
      Bluetooth: uuid: Fix assigned UDP uuid value
      Bluetooth: SDP: Add API to get ProfileDescriptorList attribute
      Bluetooth: shell: Add getting ProfileDescriptorList attribute
      Bluetooth: SDP: Add API to get SupportedFeature attribute
      Bluetooth: shell: Use SupportedFeature attribute API
      Bluetooth: shell: Add support to retrieve A2SRC record

Arun Jagadish (2):
      Bluetooth: AVDTP: Remove buffer pool
      Bluetooth: AVDTP: Add AVDTP Discover Function Definition

Carles Cufi (1):
      Bluetooth: hci_core: Use nRF5x FICR address

Jaganath Kanakkassery (2):
      Bluetooth: RFCOMM: Fix session timer during acl disc
      Bluetooth: RFCOMM: Use common tx pool for control packets

Johan Hedberg (15):
      Bluetooth: Fix trivial coding style issue
      Bluetooth: Fix checking for invalid public address
      Bluetooth: Fix using correct variable type for interrupt mask
      Bluetooth: Fix buffer leak when HCI driver send() fails
      Bluetooth: drivers/h4: Add support for discarding certain events
      Bluetooth: Add convenience macros for common header sizes
      Bluetooth: Kconfig: Merge headroom reserve variables into a single one
      Bluetooth: Controller: Redesign response buffer allocation for commands
      Bluetooth: Reuse HCI command buffers for the command response
      Bluetooth: conn: Use delayed work for LE connection timeout
      Bluetooth: Merge bt_conn TX threads into a single one with k_poll
      Bluetooth: Merge HCI command and connection TX threads
      Bluetooth: samples: Add missing README.rst files
      Bluetooth: Controller: Use LL_ASSERT instead of BT_ASSERT
      Bluetooth: Fix incorrect checks for command buffer user data

Jonathan Gelie (3):
      Bluetooth: GATT: introduce volatile subscription flag
      Bluetooth: GATT: set subscribe value to zero for unsubscription
      Bluetooth: GATT: fixing unsubscription

Luiz Augusto von Dentz (1):
      Bluetooth: GATT: Fix not removing subscriptions safely

Sathish Narasimman (5):
      Bluetooth: HFP HF: Service level connection completed
      Bluetooth: HFP HF: Enable extended AG Error Result Code
      Bluetooth: HFP HF: Indicate disconnect to application
      Bluetooth: HFP HF: Disconnect rfcomm on SLC error
      Bluetooth: HFP HF: Remove unused variable 'buf'

Szymon Janc (5):
      Bluetooth: Use assert when getting net buf with K_FOREVER
      Bluetooth: Remove some dead code
      Bluetooth: L2CAP: Remove dead code
      Bluetooth: SDP: Make bt_sdp_create_pdu static
      Bluetooth: L2CAP: Make l2cap_br_send_conn_rsp return void

 drivers/bluetooth/hci/Kconfig                   |  13 +-
 drivers/bluetooth/hci/h4.c                      |  93 +++-
 drivers/bluetooth/hci/h5.c                      |  47 +-
 drivers/bluetooth/hci/spi.c                     |  13 +-
 drivers/bluetooth/nble/gatt.c                   |  76 +--
 include/bluetooth/buf.h                         |  13 +-
 include/bluetooth/gatt.h                        |  18 +-
 include/bluetooth/hci.h                         |   9 +-
 include/bluetooth/l2cap.h                       |  20 +-
 include/bluetooth/sdp.h                         |  51 ++-
 include/bluetooth/uuid.h                        |   2 +-
 samples/bluetooth/handsfree/README.rst          |  23 +
 samples/bluetooth/hci_uart/src/main.c           |  11 +-
 samples/bluetooth/hci_usb/src/main.c            |  11 +-
 samples/bluetooth/peripheral_sc_only/README.rst |  26 ++
 subsys/bluetooth/controller/hci/hci.c           | 153 ++++---
 subsys/bluetooth/controller/hci/hci_driver.c    |  23 +-
 subsys/bluetooth/controller/hci/hci_internal.h  |   2 +-
 subsys/bluetooth/controller/ll/ctrl.c           |   2 +-
 subsys/bluetooth/host/Kconfig                   |  10 +-
 subsys/bluetooth/host/at.c                      |   2 +-
 subsys/bluetooth/host/at.h                      |   3 +-
 subsys/bluetooth/host/avdtp.c                   |  81 +++-
 subsys/bluetooth/host/avdtp_internal.h          |   7 -
 subsys/bluetooth/host/conn.c                    | 178 ++++----
 subsys/bluetooth/host/conn_internal.h           |  15 +-
 subsys/bluetooth/host/gatt.c                    | 142 +++---
 subsys/bluetooth/host/hci_core.c                | 285 ++++++++----
 subsys/bluetooth/host/hci_core.h                |   6 +
 subsys/bluetooth/host/hci_ecc.c                 |   6 +-
 subsys/bluetooth/host/hci_raw.c                 |  12 +
 subsys/bluetooth/host/hfp_hf.c                  |  50 +-
 subsys/bluetooth/host/l2cap.c                   |  35 --
 subsys/bluetooth/host/l2cap_br.c                |  49 +-
 subsys/bluetooth/host/l2cap_internal.h          |   7 +-
 subsys/bluetooth/host/rfcomm.c                  |  31 +-
 subsys/bluetooth/host/rfcomm_internal.h         |   5 +-
 subsys/bluetooth/host/sdp.c                     | 584 +++++++++++++++++++++++-
 tests/bluetooth/shell/src/main.c                | 172 +++++++
 39 files changed, 1700 insertions(+), 586 deletions(-)
 create mode 100644 samples/bluetooth/handsfree/README.rst
 create mode 100644 samples/bluetooth/peripheral_sc_only/README.rst

Change-Id: I7589dbad8b97477c72d1b856121593bcf6d11339
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-08 13:03:20 +02:00
Arun Jagadish 93e28c75fe Bluetooth: AVDTP: Add AVDTP Discover Function Definition
Implementation of Send AVDTP_DISCOVER functionality

< ACL Data TX: Handle 256 flags 0x00 dlen 6
      Channel: 64 len 2 [PSM 25 mode 0] {chan 0}
      AVDTP: Discover (0x01) Command (0x00) type 0x00 label 0 nosp 0

Change-Id: Ieb6d1e5379d8933d57f3b1399f091378ce3c0756
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-08 11:02:09 +00:00
Jonathan Gelie 048a15bcc8 Bluetooth: GATT: fixing unsubscription
If subcription was found within the subscription list,
we have check if remains identical subscription
from the next node.
Otherwise none unsubscription is realized.

Change-Id: I38132d7c80575801885b8057902f3d4666b08aea
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-08 11:00:06 +00:00
Johan Hedberg ce2d74a58a Bluetooth: Fix incorrect checks for command buffer user data
If the buffer given to hci_cmd_done() is not from the command buffer
then using the cmd(buf) macro is not valid. Simply bail out from
hci_cmd_done() if this is an event that didn't have a matching command
buffer.

Change-Id: Id8357a23a307f4ef3a9214a4e1f7d853a18cb907
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-08 11:59:50 +02:00
Michael Scott a2e9dd1361 net: context: fix net context / net conn leak
If a net context is not connected or listening, we can go ahead and
call net_context_unref() to free it up instead of waiting for
FIN_ACK which will never happen.

Change-Id: Ice06f572df64f2edb5918c10c92087ce0b7b254a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:36 +02:00
Michael Scott 7acb7aceb3 net: ip: change some error messages to NET_ERR
Several error messages are currently being logged as NET_DBG which
requires the user to have CONFIG_SYS_LOG_NET_LEVEL=4.

Let's show these as errors so they are more visible.

Change-Id: I28c9a1aedb78787ef098a9bf565472a437373933
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally 58ba1d834e net: nbuf: Fix net_nbuf_compact() API
Current API description of net_nbuf_compact() is not very clear.
The first parameter needs to be the first net_buf in the chain.

The changes to this API are needed in order to clarify following
use cases:
1) User provides fragment that is not first of the chain and compact is
successfully done. In this case there is no free space in fragment list
after the input fragment. But there might be empty space in previous
fragments. So fragment chain is not completely compacted.

2) What if input fragment has been deleted and api returns the same
buf?

So this commit simplifies the API behavior. Now net_nbuf_compact()
expects the first parameter to be either TX or RX net_buf and then it
compacts it. It fails only if the input fragment is a data fragment.

Change-Id: I9e02dfcb6f3f2e2998826522a25ec207850a8056
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally 999338ea94 net: nbuf: Remove unused net_nbuf_push() API
The net_nbuf_push() API is not used by anyone. Semantics are not
clear and following patch requires changes to push api, so removing
this API for now. If needed this can be re-introduced later.

Change-Id: I1d669c861590aa9bc80cc1ccb08144bd6020dac5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Jukka Rissanen 32415396d8 net: arp: Fix the ethernet header location
The ethernet header location was incorrectly calculated
and the result pointer had some random value.

Change-Id: I6b2deee787a78444f3ee3be805d4b82ebb6c3664
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally d7e0531149 net: fragment: Fix the 802.15.4 fragmentation
Currently fragmentation introduces empty fragment in the
beginning of the list, and adds fragmentation header, and moves frags
data to previous fragments. This is done based on condition that max
data should be multiples of 8 bytes and offset is based on before
compression.

It will fail at scenario when current fragment has not enough space
to move from next fragment and next fragment has more than allowable
max bytes. This will cause memory overflow which is typically seen
as double-free error to the user.

This is solved more simple way by this commit. First detach frags list,
prepare new fragment and attach that to buffer. Then move data from
detached frag list and free the fragments in the old one.

Change-Id: I5e3693d47828ff3b92db4ba5f6c00c0b751daadc
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen dace99611a net: nbuf: Fix double free in net_nbuf_compact()
If we are in the end of the fragment chain, then we can just
bail out as there is nothing more to do. There will be a
double free if we continue as the last entry is already
removed at this point.

Change-Id: I0f9782b408244d283dc7e3e087359dd00bada7a9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen d15c836f6c net: nbuf: Remove dead code in net_nbuf_compact()
Change-Id: I8898ca20dd9d1764f52cd039baaa144faa7326f7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen 5294497dd5 net: nbuf: Add helper to print fragment chain
Change-Id: I33eb2cf88e1cdeb79034334331dd346fa31cec49
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen bd3908b2a9 net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h
by adding a timeout parameter. These function prototypes
are changed to accept a timeout parameter.
	net_nbuf_get_rx()
	net_nbuf_get_tx()
	net_nbuf_get_data()
	net_nbuf_get_reserve_rx()
	net_nbuf_get_reserve_tx()
	net_nbuf_get_reserve_data()
	net_nbuf_copy()
	net_nbuf_copy_all()
	net_nbuf_push()
	net_nbuf_append()
	net_nbuf_write()
	net_nbuf_insert()

Following convinience functions have not been changed
	net_nbuf_append_u8
	net_nbuf_append_be16
	net_nbuf_append_be32
	net_nbuf_insert_u8
	net_nbuf_insert_be16
	net_nbuf_insert_be32
	net_nbuf_write_u8
	net_nbuf_write_be16
	net_nbuf_write_be32
so they call the base function using K_FOREVER. Use the
base function if you want to have a timeout when net_buf
is allocated.

Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen 8c6e76fb37 net: todo: Add CAN support entry
Added a placeholder for CAN (Controller Area Network) support.

Change-Id: Ia6587df71a87f7439691768a04ba7ca07142e72f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Michael Scott 567cc4531f net: context: keep randomly assigned port for TCP bind() calls
Prior to commit df201a0e4b ("net: context: Assign a random port
number when context is created"), TCP clients were assigned a random
port number when the incoming sockaddr parameter's port value was 0.

After the above commit, this is now broken as it will bind to port 0.

If left this way, every TCP client would need to add a line of code
copying the context->local sockaddr_ptr's port value into the
src_sockaddr port prior to calling net_context_bin().

Instead, we can reinstate this behavior in net_context_bind(), by
making sure we only overwrite the randomly assigned port in the
context->local sockaddr if the incoming sockaddr parameter has a
port which is != 0.

Change-Id: I0f27f031f743d50c351ecf9ab55b5282a20ff292
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-08 10:12:35 +02:00
Jukka Rissanen 8db13f905b net: ipv6: Free received NA net_buf
If we receive a neighbor advertisement, we need to free its
net_buf because we are returning NET_OK to the caller. This
return code means that we consumed the net_buf but we did
not call net_nbuf_unref() in this case.

Change-Id: Ia6d8f1b440be87eff5d2b14a23336a37be6d6a04
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Jukka Rissanen f25d4768b2 net: ipv6: Fix pending buf leak when NA is received
The pending buf needs to be freed after it has been sent
to the network. We took the ref when pending buf was saved,
now we need to unref it when it is about to be sent.

Change-Id: I1e429969895700000a8aa124bd645db2d52d036c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:34 +02:00
Flavio Santes 362a12200a net/dns: Fix inline documentation
Fix inline documentation for the dns client API.

Jira: ZEP-1669

Change-Id: I9e6ae4e1301f1e4a125b75add1a8bc7331a818b0
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-07 22:33:47 +00:00
Johan Hedberg 5b80603dbd Bluetooth: Controller: Use LL_ASSERT instead of BT_ASSERT
The controller code should not use BT_ASSERT directly.

Change-Id: If0b7d8e21d2ab4569a564bd03e36e4eb9204c595
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-07 12:29:58 +00:00
Szymon Janc afab7e1c01 Bluetooth: L2CAP: Make l2cap_br_send_conn_rsp return void
This function cannot fail.

Change-Id: I6b3393e0cfe1c334536e26c2715d5aff44c6dfd8
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:46 +00:00
Szymon Janc 7ee83b6c62 Bluetooth: SDP: Make bt_sdp_create_pdu static
It is not used outside of sdp.c and has no declaration.

Change-Id: I420a6b98d1b46fedffa29d042267b9c606d04c46
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:35 +00:00
Szymon Janc 22ada7b063 Bluetooth: L2CAP: Remove dead code
l2cap_create_le_sig_pdu always returns valid pointer.

Change-Id: I1510dc9ae387b426d7280f213e9d22b9a6a8418a
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:24 +00:00
Szymon Janc 69a52d82c9 Bluetooth: Remove some dead code
bt_l2cap_create_pdu always returns valid pointer.

Change-Id: Id525d19c096407150a7370396ed557290fbc35c5
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:13 +00:00
Szymon Janc 295e8e575c Bluetooth: Use assert when getting net buf with K_FOREVER
net_buf_alloc called with K_FOREVER should always return valid pointer.
Returning NULL indicated kernel bug.

Change-Id: I6c317de2d98723d0c1a0618e91490a2128f69f06
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:01 +00:00
Sathish Narasimman 54eedffd58 Bluetooth: HFP HF: Remove unused variable 'buf'
'buf' variable of type struct net_buf was one of the arguments for
finish callback in response to each AT command sent. 'buf' variable
not used in that function. So removed 'buf' variables from the argument
list.

Change-Id: I7d6aa6082f524012ae13a04426915076130ddf69
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 18:19:31 +00:00
Jonathan Gelie a42e4f694f Bluetooth: GATT: set subscribe value to zero for unsubscription
Subscribe value is set to zero before calling notify callback,
to distinguish a subscription failure from an unsubscription
on disconnection (when flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE is set).

Change-Id: Ia91220492d82041b2c385bf88a15180387e7a483
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:44:01 +00:00
Sathish Narasimman ccecfaac6a Bluetooth: HFP HF: Disconnect rfcomm on SLC error
If found error during service level connection disconnect rfcomm.

Change-Id: Ida425375975b8d60ab1024d07a8ffe7745ae0b54
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 17:43:21 +00:00
Jonathan Gelie b3ac77becd Bluetooth: GATT: introduce volatile subscription flag
Some application protocol required non-persistente subscription
across connection even in bonded case.
Flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE specify if subscription
must be remove during disonnection.

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Sathish Narasimman 8fe69090e5 Bluetooth: HFP HF: Indicate disconnect to application
Invoke disconnected application callback when rfcomm is disconnected.

Change-Id: Icdefa8ee0b8f061f7db75a73e7f7ed4044817c5a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 13:01:07 +00:00
Luiz Augusto von Dentz 31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +00:00
Sathish Narasimman 7fe2a96fc2 Bluetooth: HFP HF: Enable extended AG Error Result Code
Send standard AT+CMEE command used to enable the use of result
code +CME ERROR.

< ACL Data TX: Handle 256 flags 0x00 dlen 18           [hci0] 23.101226
      Channel: 67 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 4d 45 45 3d 31 0d 40                 AT+CMEE=1.@
> ACL Data RX: Handle 256 flags 0x02 dlen 15           [hci0] 23.127140
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I246c25252440c9c973e1f90156dab44c48f02c3a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 10:32:24 +00:00
Sathish Narasimman ece5865b2e Bluetooth: HFP HF: Service level connection completed
Once the service level connection is done call the connected
callback.

Change-Id: I7541e221d4c03c939682ec70f1d9c093f87ceb09
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 09:36:54 +00:00
Johan Hedberg dc70415dc4 Bluetooth: Merge HCI command and connection TX threads
We can go further with taking advantage of k_poll and merge the
connection TX thread together with the HCI command thread, thereby
saving even more memory.

Change-Id: I1792056fd4621d62c7cd05929094033acca45c74
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 1fb0351f9a Bluetooth: Merge bt_conn TX threads into a single one with k_poll
Now that the k_poll API is available we can use it to have single
connection TX thread instead of multiple ones, which helps reduce the
per-connection memory overhead by a substantial amount.

Change-Id: Icb5d4da87cf0d660bba8da43186d1e76f41c825a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arun Jagadish aa16b02bb5 Bluetooth: AVDTP: Remove buffer pool
Removing the module specific buffer pool. If future, use common acl_tx_pool.

Change-Id: Ie1452f981ef43642715be395315845cc2d9bb285
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 192db7179c Bluetooth: conn: Use delayed work for LE connection timeout
Detaching the timeout from the tx_thread lets us prepare for merging
all TX threads into a single one with the help of k_poll(). There's no
need to define a new delayed work object since the existing connection
parameter update object and connection timeout will never need to run
in parallel. Additionally, but some CONFIG_BLUETOOTH_CENTRAL guards to
void pulling in unnecessary code when Central role is not enabled.

Change-Id: Ia1f222aa052edcecd484a924f2d9a63a3b8fd11f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 50678b03cb Bluetooth: Reuse HCI command buffers for the command response
Reduce the pressure on the common RX buffer pool by reusing HCI
command buffers also for the Command Status or Command Complete
response to them. This also implies removing the existing Kconfig
variable for the command buffer sizes since the size is also dependent
on maximum Command Complete event sizes. Instead, reuse the RX buffer
size also for HCI Command buffers.

Change-Id: I006b287d64a0c9ca40de741aa9a424a49a927385
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 6c0e9720e2 Bluetooth: Controller: Redesign response buffer allocation for commands
With an upcoming patch the HCI command buffers will be reused for the
Command Complete/Status HCI events. The controller HCI code needs some
refactoring to postpone the event buffer allocation so that the
parsing state of the HCI command buffer isn't touched.

Change-Id: I1f614fb9f02ed1886ca84198fbc8c64abc29e44f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 743379c21f Bluetooth: Kconfig: Merge headroom reserve variables into a single one
A subsequent patch will start reusing HCI command buffers for
receiving the response, so the distinction of received vs sent data
headroom would just make the code unnecessarily complex. Instead, just
merge these two variable into a single one.

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg be139268b3 Bluetooth: Add convenience macros for common header sizes
The C pre-processor doesn't allow using sizeof() in comparisons such
as "#if FOO < sizeof(bar)". To make it possible to use such
comparisons where the sizes of headers are involved, introduce helper
macros for the headers instead of always having to hard-code magic
numbers into the code.

Change-Id: Iaf654cb4aaa49e83360901f5b01225ba4b952854
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 800ed72293 Bluetooth: Fix buffer leak when HCI driver send() fails
If the driver send() fails we need to free up bt_dev.sent_cmd.

Change-Id: I41b6293dfe09f1d94d7f85663ddbebed40cf6e90
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa 178482fdb1 Bluetooth: SDP: Add API to get SupportedFeature attribute
Adds API to allow user get SupportedFeatures attribute ID.

Jira: ZEP-1112

Change-Id: I91a1bf548d99c5c7cc75682aed19e89390350533
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa a7e4eaafaa Bluetooth: SDP: Add API to get ProfileDescriptorList attribute
Adds API enabling retrieve remote profile version.

Jira: ZEP-1112

Change-Id: I9b1a9a15848d5c485ec3dd2b405a6d51ce9b020e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa 15520c5ce9 Bluetooth: SDP: Get ProtocolDescriptorList attribute internals
Adds API to get available specific information included in protocols UUID
tree during parsing Protocol Descriptor List attribute. Usually it's to
be remote Server Channel/PSM number operating on applicable protocol.
There're a few helper functions added to be able parse and retrieve such
information from raw record data.

Jira: ZEP-1112

Change-Id: I736a780b95ba54821d36e6011b739f5ff37cd64f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg e5305f1ab5 Bluetooth: Fix using correct variable type for interrupt mask
The irq_lock() API returnes unsigned int.

Change-Id: I12d2e980dca621d44ac9776e2961f504cb747c94
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 54e34f4431 Bluetooth: Fix checking for invalid public address
Both all-zeroes and all-ones addresses are invalid. Fix the check for
this so that we fall back to a static random identity address when
needed.

Change-Id: I17cf903e0f3ed321311d86d09bed19343c2c801a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery 43a5810793 Bluetooth: RFCOMM: Use common tx pool for control packets
This will reduce memory consumption by 23 bytes per session.

Change-Id: I1831b59881eaefb68f93c30e298b8f97d63c7428
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery c5bb728d66 Bluetooth: RFCOMM: Fix session timer during acl disc
Session idle timer should not be started in dlc destroy if
session is already disconnected (which can happen in scenarios
like acl disconnection where in dlc is detached from session and
destroy will be called from tx thread) otherwise timer function will
get invoked for a disconnected session.

This patch moves starting of idle timer from dlc destroy to
the point dlc disconnect is recieved from remote since idle
timer is to handle only that scenario.

Change-Id: I94501515a182ff0e2348ba4e2df63100f2f52209
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Carles Cufi 2093c1ccf0 Bluetooth: hci_core: Use nRF5x FICR address
The nRF5x come preprogrammed from manufacturing with either a public or
random static BLE address in the FICR register. Use the random static
one when present instead of generating one during Bluetooth
initialization.

Change-id: Ic733cb926e0414e56d6f8be65b033692e914b72a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-02-05 22:39:25 +02:00
Johan Hedberg f23acadffe Bluetooth: Fix trivial coding style issue
Change-Id: I8a50fb6fe46d7a7deb6538f6a23bf5e58db2d52d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Tomasz Bursztyka 93ed88a670 net/ipv6: Updating ll reserve should be done for all IPv6 packet.
Doing it only in net_context, prevented to do it once NS succesfully
finished. This generated an error in 15.4, where pending data had wrong
ll reserve size.

Change-Id: I0f917fb76171457e5dff2c29e44edb8f00662150
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:20 +02:00
Jukka Rissanen 1301d3f6d3 net: ipv6: Use the nexthop when sending the packet
We must use the nexthop instead of destination address
when sending the packet. The current code mixed destination
and nexthop addresses and ignored the nexthop when sending
neighbor solicitation message.

Change-Id: I53887c16ef6fcf8365f1f47ab5792cb208dd273e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Jukka Rissanen 6930f93fd3 net: stats: Collect bytes sent and received
Keep track of amount of bytes that are sent or received from
all network interfaces.

Change-Id: I706481aab1a7e0cf2bc78d032f2ef4ebbabe3184
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Ravi kumar Veeramally df201a0e4b net: context: Assign a random port number when context is created
Current behaviour has an issue when UDP context is created with local
port number 0, net_conn_input() happens to treat zero port as
a wildcard ("receive packets for all ports"). net_context_bind()
for a UDP context doesn't affect its existing connection in any way.

Proposed solution is, context should be created with a random free
port assigned and bind() updates connection information from context.

Jira: ZEP-1644

Change-Id: Idb3592b58c831d986763312077b0dcdd95850bc9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:20 +02:00
Ravi kumar Veeramally f6c8b0b89a net: context: Skip reserved ports
The port numbers in the range from 0 to 1023 are the well-known ports
or system ports. Do not allocate them for users.

Change-Id: I4d7b4e1314759e4d8b260669946b9880282642c0
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:20 +02:00
Tomasz Bursztyka 3aa6b21c07 net/ieee802154: Fixing active scan buffer reference counting
Commit-ID 83ed3a29be changed the way
fragments are managed after being sent, and this brought a bug in the
active scan logic. Up to active scan to keep the buffer referenced
relevantly now, which is simpler than it used to be.

Reported-by: Johann Fischer <j.fischer@phytec.de>

Change-Id: I23db4bab878328b1ca3cb313e737de819177c281
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:20 +02:00
Luiz Augusto von Dentz affcac5a2d net: bt: Add Kconfig to interoperate with Linux
This adds a NET_L2_BLUETOOTH_ZEP1656 which sets NET_IF_POINTOPOINT to
avoid using nbr cache with Linux peers as they send wrong link
addresses.

Jira: ZEP-1656

Change-Id: I842f4cbb99ae9d9c004494739c07189c191929fe
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:19 +02:00
Luiz Augusto von Dentz 2c1bef4d09 net: Introduce NET_IF_POINTOPOINT flag
This flag can be used by driver to indicate pointopoint links which should
not require destination link address to be resolved.

Jira: ZEP-1656

Change-Id: I58dd3bf48485d6203e75373497e00668317b9825
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:19 +02:00
Jukka Rissanen 16d8f59c83 net: nbuf: Do no use timeout if called from isr
The net_nbuf_get*() functions were calling net_buf_alloc()
with K_FOREVER. This can cause issue if called from isr
context. The fix is to check if we are in isr and then try
to alloc net_buf with K_NO_WAIT.

Change-Id: I809170f2cd059480d436763e19a35386d9bdf048
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:19 +02:00
Vinicius Costa Gomes 2d852f47d2 iot/zoap: Fix the return value of zoap_packet_get_payload()
The returning 'len' was always informing the remaining available space
in that net_buf fragment. This not the expected behaviour for
incoming packets, in this case, we really want the size for the
payload already present in the packet.

When this function is called with a packet without a payload, with
will return the available space in the packet, when the payload is
already set, it will return the size of that payload.

Change-Id: Ia4643b8c2a015ad2316bed037e457b186e420b19
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka 55751eed47 net/ieee802154/shell: Add commands to set/get radio network info
Channel, PAN-ID, short and extended address

Change-Id: Icdf94dff6f59cd155a072a609290197b37bd084c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka f2872e60ad net/ieee802154/mgmt: Add getters/setters for various radio network info
Channel, pan-id, short and extended addresses.

Change-Id: Ib63dadac37d649df3efc8fdd67f5312d3a7c8e20
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka 2e5de5b44c net/ieee802154: Setting short address is about local node
Fix setting short address through net mgmt API. It's not about
coordinator's short address, but local one.

Change-Id: I320143e40d336a1085bf12b17a88a2c35da83504
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka 8d7eb6ed2b net/ieee802154: Set IEEE extended address whatever runtime mode it is
ORFD or RFD does not matter: the extended address should be set
according to device's MAC address.

Change-Id: I39d09c3a953283eeaa30b908ea159638604bd72b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 32eb764959 net/mqtt: Remove redundant line
Delete redundant line and let the common exit point to release
the buffers.

Change-Id: I97e0ef79803083fabd841fb3d38d67c04ff31f7b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 02bd8411dc net/mqtt: Validate null or app level zero-length rx buffers
Don't try to process null or zero-length buffers generated by
the IP stack. Zero-length buffers are valid at the TCP layer but
contain no information for applications.

Change-Id: If66d301527f56ca8e8761789b7fd6931fc37b8e0
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 9e6a6f3bce net/mqtt: Add the "malformed" callback to the MQTT ctx structure
Add the malformed callback that will be executed when a message
is received and it does not follow the MQTT v3.1.1 spec.

There is another case when this callback may be executed: when
the IP stack reception buffer's size is not enough to hold an
MQTT message.

The publisher and subscriber parser routines are updated to make
use of this callback. Inline documentation is also updated.

Change-Id: Id1d34336c4322673ca85f2db0b8d432db3c9afa8
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 4a17932d6a net/mqtt: Simplify the MQTT high-level API
1) Remove some variables pointing to user-provided data.
2) Pass the context structure instead of those variables.
3) Homogenize the use of "ctx" for all the callbacks receiving the
   struct mqtt_ctx * pointer.

Now users must use the CONTAINER_OF macro to access data required
by the MQTT callbacks.

Change-Id: I871c0bd8601a67b39187683215579f9ed0087cf9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes db6fda8835 net/mqtt: Move upwards buffer size validation
Although the buffer size validation works as it is inside the
mqtt_linearize_buffer routine, let's move it before getting a
data buffer from the buffer poll.

Change-Id: Id80af8a1e188929769463b04deaef3956b63cd00
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Luiz Augusto von Dentz a94f179252 net: Add ll addresses on net_if_send_data
This makes sure ll addresses are properly set before sending reducing the
duplicated code on L2 drivers.

Change-Id: I5330c1d00a344e77555c6f31033ae42af20214bf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:17 +02:00
Julien Chevrier 6aae825a2d net: iface: Fix bad comparisons in net_if
Fix comparisons in net_if_get_by_index and net_if_get_by_iface:
__net_if_end is not a pointer to a net_if structure.

Change-Id: Ie8e3a457c3f0fa97c080b38b5b7d2b420c50252b
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2017-02-03 15:59:17 +02:00
Jukka Rissanen d6cc2c9a36 net: nbuf: Removing dead code from net_nbuf_compact()
There is dead code that is never executed so removing it.

Coverity-CID: 157585

Change-Id: I6926289b5735b78fcb99ad493d1b05198b9e36cc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:17 +02:00
Michael Scott 56afb1065a net: tcp: Only return -ETIMEDOUT if timeout!=0 in connect
Previous commit: 6e6281af96
"net: tcp: Only return -ETIMEDOUT if timeout>0 in connect"
missed that K_FOREVER needs a semaphore taken, but has a
value of -1.

Change the logic here to timeout!=0 to handle this case.

Change-Id: Iae6a784443810130a7de267226483426fbd4f0d4
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-03 15:59:17 +02:00
Andy Ross 3efe6b7ede net: tcp: Add optional TIME_WAIT support
The RFC requires we honor the 2MSL TIME_WAIT timeout, support for
which was just removed with the FIN cleanup.  Add it back, but make it
optional (proper sequence number and ephemeral port randomization
makes true collisions a birthday problem in a ~80 bit space!).

Change-Id: I176c6250f43bba0c914da1ee7f0136dcb1008046
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:15 +02:00
Andy Ross f3cce9082d net: net_context: Drop callbacks in net_context_put()
The context may live for a while after the user closes it (c.f. TCP),
and of course the documentation specifies that the user must not use
it after calling net_context_put().  Don't confuse them by invoking
their callbacks on the "closed" connection; it's likely that the user
has destroyed her own tracking data and the user_data pointers would
be garbage.

Change-Id: Iba9cc7025c6ea4a94cc4796903966f8d1b831996
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:15 +02:00
Andy Ross fece856959 net: tcp: Clean up FIN handling
The connection close paths were a little tangle. The use of separate
callbacks for "active" and "passive" close obscured the fundamentally
symmetric operation of those modes and made it hard to check sequence
numbers for validation (they didn't).  Similarly the use of the
official TCP states missed some details we need, like the distinction
between having "queued" a FIN packet for transmission and the state
reached when it's actually transmitted.

Remove the state-specific callbacks (which actually had very little to
do) and just rely on the existing packet queuing and generic sequence
number handling in tcp_established().  A few new state bits in the
net_tcp struct help us track current state in a way that doesn't fall
over the asymmetry of the TCP state diagram.  We can also junk the
FIN-specific timer and just use the same retransmit timer we do for
data packets (though long term we should investigate choosing
different timeouts by state).

Change-Id: I09951b848c63fefefce33962ee6cff6a09b4ca50
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:15 +02:00
Andy Ross f16886d419 net: tcp: Don't send active close FIN packets synchronously
A FIN packet generated by a net_context_put() must go into the normal
transmit queue and not be sent synchronously.  Previously sent data is
expected to be delivered and acknowledged before the connection is
terminated.

An advantage we get with this change is unified timeout and retry
handling for FIN packets.

Note that there remains a misfeature here where the queing of the FIN
results in a synchronous switching of the connection callback to
tcp_active_close(), which will prevent any further data received from
being provided to the user.

Change-Id: I2d41316549da9fee383b4f32af5e8b3adf4cb122
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:15 +02:00
Andy Ross 5d6e0d425b net: tcp: Clean up net_context lifecycle
The death of a network context was sort of a mess.  There was one
function, net_context_put(), which was used both by the user as a way
to "close" the connection and by the internals to delete it and to
"clean up" a TCP connection at the end of its life.

This has led to repeated gotchas where contexts die before you are
ready for them (one example: when a user callback decides the
transation is complete and calls net_context_put() underneath the
receive callback for the EOF, which then returns and tries to inspect
the now-freed memory inside the TCP internals).  I've now stepped into
this mess four times now, and it's time to fix the architecture:

Swap the solitary put() call for a more conventional reference
counting implementation.  The put() call now is a pure user API (and
maybe should be renamed "close" or "shutdown").  For compatibility,
it still calls unref() where appropriate (i.e. when the context can be
synchronously deleted) and the FIN processing will still do an unref()
when the FIN packets have been both transmitted and acked.  The
context will start with a refcount of 1, and all TCP callbacks made on
it will increment the refcount around the callback to prevent
premature deletion.

Note that this gives the user a "destroy" mechanism for an in-progress
connection that doesn't require a network round trip.  That might be
useful in some circumstances.

Change-Id: I44cb355e42941605913b2f84eb14d4eb3c134570
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:14 +02:00
Jukka Rissanen 1997a049fa net: Increasing the default number of network contexts
The old default 2 is too low especially if TCP is enabled.
So in order not to confuse the application developer,
increase the default number of network contexts to 6.

Change-Id: I263bb4b6f31354a11d921d94aa97214abd85ae24
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:14 +02:00
Jorge Ramirez-Ortiz 8b9212d57d net/mqtt: Check function return value
Change-Id: I4a4df19d50b9422f3e72d6386c0c726b6d9b82f2
Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
2017-02-03 15:59:14 +02:00
Ravi kumar Veeramally b13f44bcdd net: utils: Add net_addr_ntop() helper function
net_addr_ntop() will convert IPv4|6 address to string form.
Renamed existing net_sprint_ip_addr_buf() to net_addr_ntop()
and adjusted parameters as per API.

Jira: ZEP-1638

Change-Id: Ia497be6bf876ca63b120529acbadcfd9162a96e3
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:14 +02:00
Luiz Augusto von Dentz 3171610f8b net: bt: Fix failing to resolve link-local address
This make sure the link-local address of the destination is added to the
nbr cache as that is accessed when calling net_ipv6_prepare_for_send,
this is needed when following RFC 7668 since link-local addresses are
never registered using nbr discovery.

Change-Id: I2bc578d33d1061726d0cbf46e4464df74d79e992
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:14 +02:00
Kumar Gala 54c642caec net: ip: stat: fix typo in rpl.dio.sent stat
in net_print_statistics for RPL we had:

GET_STAT(rpl.dio..sent)

This wouldn't work or compile, so drop a dot.

Change-Id: Idd6b4dfd5fcae3b90bc977fe3ed301cd813ca87c
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-02-03 15:59:13 +02:00
Michael Scott ca6a686495 net: correct in*_addr parameter of net_addr_pton()
Currently, the function accepts a struct sockaddr * but the code
immediately type casts this to either in_addr or in6_addr.  This is
incorrect behavior as the first field in a sockaddr is sa_family_t
and not address data.

So without special knowledge, a developer will use a sockaddr structure
as the parameter and then wonder why the address information isn't being
set correctly.

Let's change this parameter to void * which makes this function similar
to inet_pton().

Jira: ZEP-1616

Change-Id: I1fc9368da999d90feb07c03fac55dcc749d4eba6
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-03 15:59:13 +02:00
Jukka Rissanen 6d50b47987 net: tcp: Call connect callback later
If the user supplied connect callback uses too much time, then
it is possible that the connect_wait semaphore will timeout
even if the TCP connection was established correctly. This issue
can be avoided if connect_cb is called after we have released
the connect_wait semaphore.

Change-Id: I175e80f2ad48de657d0d99a44340c5ee1a17364c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:13 +02:00
Kumar Gala 869a9fc050 fat: match type info expected by fat library for f_write
The fat library uses its own typedef for integer parms and expects a
UINT to be either 16 or 32-bits in length.  We potentially get into
trouble when we build with newlib if we use an uint32_t.  Lets just use
unsigned int which should cover all cases for us.

Change-Id: I3dbbf4871ab65dd12488d41cb06a06387c128339
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-30 12:01:50 +00:00
Anas Nashif 66417c0246 Merge "Merge net branch into master" 2017-01-29 04:31:39 +00:00
Kumar Gala edcb6ceb12 Bluetooth: hci_raw: Make bt_buf_get_rx args consistent
The hci_raw version of bt_buf_get_rx was expecting an int for timeout.
Let us int32_t instead so we match both the hci_core version and the
type that net_buf_alloc expects.

This addresses a possible build issue if/when int32_t differs from our
default (ie, newlib).

Change-Id: I69374c48da8f2b96fa2bd418ff505fbaacda11f0
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 4153b6ca1f Bluetooth: Kconfig: Make device name variable generic
Change BREDR_NAME to DEVICE_NAME so it can also be used as the LE
device name.

Change-Id: I9ef55d9dff098372d47d9d5754ad7a7163a65bc0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar 4a014f3e81 Bluetooth: A2DP: Stream End Point Structure
Added structure definition for stream end points
and the a2dp stream.

Change-Id: I6d0cc08611f5179397bea6200eb9244d7c1cc8d6
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman 730b4f89d2 Bluetooth: HFP HF: Handle +CIEV reponse
The +CIEV reponse received from the AG is handle and value is
updated to the application.

> ACL Data RX: Handle 256 flags 0x02 dlen 22         [hci0] 114.667753
      Channel: 64 len 18 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 14
         FCS: 0x9a
        0d 0a 2b 43 49 45 56 3a 20 32 2c 30 0d 0a 9a     ..+CIEV: 2,0...

Change-Id: I771cdb422d201293d356151fa33ec485083b2356
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Arun Jagadish 1806804ad8 Bluetooth: AVDTP: Add AVDTP Discover API Prototype
Added AVDTP Discover Request API Prototype.

Change-Id: I661331634b64099e352efe12cacc9af5d4c7ce16
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-28 08:43:41 +02:00
Luiz Augusto von Dentz 278bd910d5 Bluetooth: L2CAP: Only set state for dynamic channels
Fixed channels don't really use channels state as they don't need
connection setup.

Change-Id: Ie8b1327db0269a45e9ccb6049f8dda87aa445fb5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar 42a175f300 Bluetooth: A2DP: Adds accept state callback handlers
Adds state callback handler to allocate memory to AVDTP on an incoming
connection. Also, abstracts searching of free session as a function call.

Change-Id: Idee6b7a0507b0b75c0007717e351ca12de0cb5be
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery 91f9c9cf1c Bluetooth: RFCOMM: Implement MSC Flow Control
This is mainly for backward compatibility with 1.0b devices and for
spec compliance. CFC is mandatory post 1.0b spec where in MSC FC
shall not be used.

FC bit in MSC is used to manage the flow control. If FC is 1 then
the device is unable to accept frames.

Implementation is done by reusing "tx_credit" as a binary semaphore
wherein it will be blocked if MSC is recieved with FC bit 1 and
unblocked if FC bit is 0. Once tx thread is scheduled then semaphore
should be always available until all the buf in queue is sent.

Change-Id: I91181668ec0f46ff0b02905dd97e4503fc1fa7a7
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery 17ea79e733 Bluetooth: RFCOMM: Fix v24_signal in MSC response
v24_signal in MSC response should be the copy of it received
in the command.

Change-Id: I9723ba182bf5911025c7a57220cd70687ca785f3
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman d903b53e6b Bluetooth: AT: HFP HF: Handle unsolicited reponse
This implemnts the feature to handle the unsolicited response
received from the AG. In the hfp_hf.c file the unsolicited_cb function
process it.

Change-Id: I3ca6c8d4a1522d02f7160e2fe4ae1598cd93ce7e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Andrei Emeltchenko 6580644449 net: Fix leaving NET_MAX_6LO_CONTEXTS set when 6lowpan deselected
Make NET_MAX_6LO_CONTEXTS depends on NET_6LO_CONTEXT, otherwise at the
moment even deselecting 6lowpan leaves NET_MAX_6LO_CONTEXTS set.

Change-Id: Iaa34d324005817be05190e203f6899ab89f89e5d
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-01-27 11:59:31 +00:00
Tomasz Bursztyka 1e0fdd37ab net/shell: Fix format string
Change-Id: Id335466e68add23a5786257681dc1b4d5bf6846d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 11:49:42 +01:00
Andrei Emeltchenko a207459cee net: Make NET_IPV6_DAD depends on NET_IPV6_ND
Making NET_IPV6_DAD depends on NET_IPV6_ND instead of default fixes
issue when deselecting NET_IPV6_ND, NET_IPV6_DAD is still selected in
this case.

Change-Id: I633b1a71fb5fdcd7ecc75be80a737d8bda142b2e
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-01-27 12:35:54 +02:00
Andrei Emeltchenko 86cd8eaf56 net: Make NET_IPV6_ND configurable option
NET_IPV6_ND is always selected by NET_ROUTE which is always selected
for NET_IPV6.

Change-Id: I316838033cccd205b24add6626521bbab5a68715
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-01-27 12:35:54 +02:00
Ravi kumar Veeramally 0c39e6dc45 net: 6lo: Fix tiny style issues
Change-Id: I5cf65f4d428f17290642ce94d5e70d233f512213
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:54 +02:00
Ravi kumar Veeramally 313ee1d49b net: dhcpv4: Fix tiny style issues
Change-Id: I12e6763627d85912496e8c702cd97bf90ac4f741
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:54 +02:00
Tomasz Bursztyka 668d2abb07 net/6lo: Switch to NET_ERR/NET_WARN when relevant.
This permits to catch issues without the need to enable debug level.

Change-Id: Ic3c66a84be587e955d532cc321161a3ae7b5d69d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:54 +02:00
Tomasz Bursztyka fa35ccf9cf net/ieee802154: Raise an error when data frame cannot be created
Change-Id: I7405c4b3de194c09f7d8d8e1bb54602b6dba304b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:54 +02:00
Tomasz Bursztyka 83ed3a29be net/ieee802154: Modify radio TX function signature
The cause for this change is TCP. Until now, the radio strategy driver
(ALOHA or CSMA) was providing the actual nbuf, and not the buffer
fragment, counting on the fact that the loop was using
net_buf_frag_del() which made so, iteration after iteration, buffer
framgent to be always buf->frags. The problem with this logic is loosing
the fragments that might be still referenced by TCP, in case the whole
buffer did not make it so TCP can retry later and so on.

Instead, TX now takes the nbuf and the actual frag to send. It could
have been working with just a pointer on the data, and the whole length
of the frame. But it has been avoided due to possible future devices,
that will be smarter and run CSMA directly in the hw, thus it will
require to access the whole buffer list through the nbuf.

Change-Id: I8d77b1e13b648c0ec3645cb2d55d1910d00381ea
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Andrei Emeltchenko 5794d80c10 net: Remove CONFIG_NET_IPV6_NO_ND config option
The option is no longer used so it can be removed.
Use CONFIG_NET_IPV6_ND option instead.

Change-Id: Ibaa3d3deb52b8b176e85f8b9e1d8c80c1026aea1
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka f7b0e35c5f shell: If enabled, let's register telnet console as an input
Change-Id: I476ca0f7914b02d2523a341560023c7e334d8b1b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 587335c6cf shell: Make the command queue size configurable via Kconfig
Change-Id: I80551c76903118bfe831776c87135e89d32552da
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 2f1af492ee console/shell: Switch to generic console input
Let's use the generic console input type now. This will be useful for
other console input drivers such as telnet.

Change-Id: I787a1e9d86481d5f8c4803453726d9042a89dea4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka 1a52e6e91a shell: Fix tiny style issues
- identation alignment
- 80 chars length limit

Change-Id: Ieae83e0daa2c7ee7aff32a053db5692094488df7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Luiz Augusto von Dentz 2e9fd888bf net: bt: Fix not checking for valid ll addresses
ll addresses need to be set properly before sending as the stack is not
checking if they are NULL.

Change-Id: Ia4e96240f18b53b0e32e21649a8b571c94260731
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:52 +02:00
Ravi kumar Veeramally 02b104dae8 net: 6lo: Verify src and dst link layer addresses
If src and dst link layer addresses are not then 6lo fails
to compress the packet.

Change-Id: Ie2692def49f8a101194e3669dbaec00b557e14ce
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:52 +02:00
Malcolm Prinn 755c4a6f7a net: iface: Fix typo in net_if_down
Change-Id: I36a7292a3a176f32239332a7e91308e280da9cae
Signed-off-by: Malcolm Prinn <malcolm.prinn@intel.com>
2017-01-27 12:35:52 +02:00
Jukka Rissanen 6e6281af96 net: tcp: Only return -ETIMEDOUT if timeout>0 in connect
No need to set the status to -ETIMEDOUT in connect callback
if user did not want to have a timeout when doing a TCP connect.

Change-Id: I6d6e565a8d12bcefbcd9de751e789b5e43aad244
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-27 12:35:52 +02:00
Andy Ross 47d94648ed net: tcp: Issue connection callback on RST
A connection refused needs to be exposed to the user, otherwise the
connection will be stuck as a zombie forever.

This patch also adds a ENOTCONN check in net_context_recv() to match
the one that was already there in net_context_send().

Change-Id: I4f9ae46dd849f68ed97976add7da5daf1932cf55
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-27 12:35:52 +02:00
Andy Ross 7b27d4be0a net: tcp: Make the connect callback on success, not transmission
The net_context_connect() callback was being invoked synchronously
with the transmission of the SYN packet.  That's not very useful, as
it doesn't tell the user anything they can't already figure out from
the return code.  Move it to the receipt of the SYNACK instead, so the
app can know that it's time to start transmitting.  This matches the
Unix semantics more closely, where connect(2) is a blocking call that
wakes up only when the connection is live.

Change-Id: I11e3cca8572d51bee215274e82667e0917587a0f
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-27 12:35:52 +02:00
Luiz Augusto von Dentz 1fd9f4b846 net: bt: Fix warning when compiling without debug
With CONFIG_NET_DEBUG_L2_BLUETOOTH is disabled the code generate the
following warning:

subsys/net/ip/l2/bluetooth.c: In function 'eir_found':
subsys/net/ip/l2/bluetooth.c:301:16: warning: unused variable 'addr' [-Wunused-variable]
  bt_addr_le_t *addr = user_data;
                ^

Change-Id: I1a1ca20c4f2e4fa8aa2a551d2fffa1f86874760e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:51 +02:00
Luiz Augusto von Dentz 1c94ddd906 net: bt: Fix not checking channel state
When checking if the L2CAP channel is connected it is not enough to check
if the conn member is set since the connection may still be pending.

Change-Id: I93a2328943b0ca0e42cdb5c525b30c7cdddd1c18
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:51 +02:00
Ravi kumar Veeramally 4540a73b59 net: Use lighter printk() instead of printf()
Use printk(), snprintk() instead of printf() and snprintf().
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf()
will not output anything without it.

Change-Id: I9ad778e318fe999e79ec34182f2de8574e45b7d4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:51 +02:00
Ravi kumar Veeramally a28e2059e8 net: Fix 80 line character limit
Change-Id: Ic83a631db4ae76b1b2bb1bbd888d1329f065c18c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:51 +02:00
Paul Sokolovsky fe72df5292 net: Set default NET_NBUF_RX_COUNT to 4.
Older default value of 2 is too small for even simple uses, for
example enabling just CONFIG_NETWORKING, CONFIG_NET_IPV4,
CONFIG_NET_SLIP_TAP makes a Zephyr application hang on start up
(apparently, waiting to allocate more buffers). While value of 3
is enough to cover the above options, set new default to 4 to
accommodate configurations with IPv4/IPv6/UDP/TCP enabled.

While the new default slightly increases RAM footprint, it's
apparently better for users who are short of it to optimize it
explicitly, rather than potentially make every Zephyr beginner
wonder why enabling networking breaks applications in non-obvious
way.

Change-Id: I76e83517f0d914ce616a930c3c48ee5c52567b88
Jira: ZEP-1619
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-01-27 12:35:50 +02:00
Benjamin Walsh ed240f2796 kernel/arch: streamline thread user options
The K_<thread option> flags/options avaialble to users were hidden in
the kernel private header files: move them to include/kernel.h to
publicize them.

Also, to avoid any future confusion, rename the k_thread.execution_flags
field to user_options.

Change-Id: I65a6fd5e9e78d4ccf783f3304b607a1e6956aeac
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-24 13:34:50 +00:00
Kumar Gala 8d4c1787bf Bluetooth: Controller: Use CMSIS NVIC APIs directly
Convert driver to use the CMSIS NVIC APIs rather than the internal
ones so we can remove them in the future.

Change-Id: Ib9fe696e8d5e55f60865d3fd958a035135ce517a
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-23 15:15:55 -06:00
Tomasz Bursztyka 467c69d524 net: tcp: Fix TCP states swap when accepted an incoming connection
TCP states are swaped between "server" context and the new connection
context. But in any case the "server" context should loose the
information that makes it able to accept other new connections.

The swap was badly made, as the "server" context was loosing the
accept_cb (!) and the user data pointer. Instead the new connection
context was unrelevantly inheriting those.

Change-Id: Icc877449e1d4c4e59553dcbfd41718c5006edca0
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-20 16:23:21 +02:00
Jukka Rissanen 088289ec28 net: context: Add status to connect callback
It is useful that the user API can know whether the connection
was established properly or not. So this commit adds status
parameter to connect callback in net_context API.

The call to connect callback needs to be set properly in TCP
code. This commit does not fix the connect callback call which
is not properly done right now in net_context.c.

Change-Id: I284a60ddd658ceef9e65022e96591f467a936a09
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:21 +02:00
Jukka Rissanen 9a7ccf81f9 net: nbuf: Fix debug prints in memory pool init and unref
Wrong pool pointer was used when printing pool information during
the unref in nbuf.c. During nbuf init, wrong pool pointer was used
when printing memory pool sizes.

Change-Id: I9ed08cf7afa3c841c97ea981b97fff37aa40a984
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:20 +02:00
Michael Scott 72e013a7ba net: tcp: add timeout wait in net_context_connect
If the parameter "timeout" is set in net_context_connect(), the
assumption by the user is that the function would wait for SYNACK
to be received before returning to the caller.

Currently this is not the case.  The timeout parameter is handed
off to net_l2_offload_ip_connect() if CONFIG_NET_L2_OFFLOAD_IP is
defined but never handled in a normal call.

To implement the timeout, let's use a semaphore to wait for
tcp_synack_received() to get a SYNACK before returning from
net_context_connect().

Change-Id: I7565550ed5545e6410b2d99c429367c1fb539970
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott eb9055c019 net: tcp: move accept_cb from net_context to net_tcp
net_context is used for more than just TCP contexts.  However,
the accept_cb field is only used for TCP.  Let's move it from
the generic net_context structure to the TCP specific net_tcp
structure.

Change-Id: If923c7aba1355cf5f91c07a7e7e469d385c7c365
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott 2c3faa0de2 net: tcp: fix buffer leak in tcp_synack_received
When SYNACK is received we dont hand off the netbuf to anything
which will call net_nbuf_unref, so let's not mark it NET_OK.
Instead let the code path fall through to mark it NET_DROP.

Change-Id: I1f883e1a13c53c930bf50c07ff701e3db6f02d8a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott 87914610b0 net: tcp: if buffer is TCP_FIN increment send_ack by 1
Now that the TCP_FIN block is after a potential packet_received()
tcp->send_ack should be appropriately set to the last sequence
processed.

In the case of a TCP_FIN buffer, we should advance it by 1 or else
the destination will continue to retry to send the last block.

Change-Id: I9c97d35a87ad6cc1a50f928b237780bff4cd2877
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott c1f822222b net: tcp: don't assume TCP_FIN buffers are NET_DROP
Since we default to a return value of NET_DROP, we
can remove the automatic NET_DROP in the TCP_FIN block.

The return value will be set to NET_OK by packet_received()
if appropriate data is found which needs to be sent to
the callback.

Change-Id: Ib2634ba34440ca7053a4e98bf80f12cf6fbbd361
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott 29b7d9c644 net: tcp: handle TCP_FIN after processing any data in the buffer
Buffers marked TCP_FIN may still have data attached to them
which needs to be processed and handed back to the callback.

Let's move the TCP_FIN handling to after the data processing
section now that we have a copy of the TCP flags to do this.

Change-Id: I90f53b10e393024ebffebe1837b8866764b8a7ac
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott da7e00e3aa net: tcp: in tcp_establish save TCP flags for post-processing use
buffer TCP flags can be cleared during packet_received so let's
save a copy of them for later.

Change-Id: I401e99c1ed2723dac4e86da58635b548a5645c13
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Anas Nashif 8da8118e3c net: in newlib, ESHUTDOWN is considered an extension
Allow building the IP stack with newlib by enabling linux extensions.

Jira: ZEP-1592
Change-Id: I6714b73c7666a6f56c5203e2754ce1d7d94af0f1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-20 16:23:20 +02:00
Tomasz Bursztyka b7dd42879d net: shell: Use lighter printk() instead of printf()
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf() will not
output anything without it.

Change-Id: I8013e4efa5cb760215316e9413734281fb576f4d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes d27cc52f37 iot/zoap: Add a helper to find an observer by address
In some situations, for example, when the remote side sends a RESET
message indicating that it is no longer interested in observing a
resource, it is helpful to have a way to obtain the obverser
representation.

Change-Id: Ifbf627f9170be844fd525c557dda8cb722ac7aff
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes 13fc795b3e iot/zoap: Fix wrong byte-order when retrieving integer options
When retrieving options that represent an integer, the order of the
bytes being considered was inverted, resulting in invalid values being
returned.

Change-Id: I8ba84f77e3402066632c0ba650939266c87a8ea2
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes 4534046ad9 iot/zoap: Ignore non-request packets in zoap_handle_request
For example, when a RESET packet is passed to zoap_handle_request(),
there's nothing it can do, and it's not an error, so it returns
success silently.

Change-Id: I025bb44733521d6132999c219aaa292a3de302d7
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Michael Scott dbd7481274 net: tcp: remove unused semaphore tcp_lock
Change-Id: Ibcd89b063a8bd5f6f7400e0ed73eb6b6d8b86b26
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally 4f3a0ef595 net: dhcpv4: Remove dead code
When parser encouter DHCPV4_OPTIONS_END, it immediately returns NET_OK.
No need to maintain end variable here.

Coverity-CID: 157584

Change-Id: I4c8b91f37ae882845c280dab1a8204966aaac00a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally 0a3ebde216 net: 6lo: Fix dereferencing null pointer
Pointer udp will be NULL when (!(CIPHC[0] & NET_6LO_IPHC_NH_1))
condition is true.

Coverity-CID: 157588

Change-Id: I8aa1eb2e4d4aee8039631d76ad0ecc345247d6b5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally c6a006c60b net: 6lo: Handle destination address uncompression properly
When contex information provided and DAC bit is not set and vice versa
are invalid cases.

Coverity-CID: 157569

Change-Id: I1b798703cbbb6155a7bdf734d0fcde9ce48c409c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 1bb7b7e99c net: nbuf: Check possible null pointer access
In net_nbuf_get(), check that context pointer value is not
null before accessing data via it.

Coverity-CID: 157600

Change-Id: I7e7ea19a85f6fbef129e9ce699ea740d3be84cb8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen d3301aae88 net: ipv6: Check neighbor pointer in NS reply timeout
If neighbor is not found, then ignore the timeout.

Coverity-CID: 157583

Change-Id: Ia2199970bd862e43901f5717025271c11c74af5e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 66f5dfa04f net: tcp: Allocate space for TCP header
We need to allocate separate fragment to store the IP
protocol headers.

Coverity-CID: 157582

Change-Id: Ib0dd5d28cd6876a0cf2de3b063c030ef64da998c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen b5039aa80c net: icmpv6: Removing dead code
Callback cannot be null so no need to check its value.

Coverity-CID: 157572

Change-Id: I26e4b24c41d30aa9007b78895975035e6bf8807f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 2eb218c5b7 net: Fix possible null pointer dereference in nbuf
The context parameter might be NULL so we need to check
its value before accessing its content.

Coverity-CID: 157571

Change-Id: I7f75323d9d261a77421688f37a40bb44ff3ca2bd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 06d3ccce96 net: tcp: When retransmitting, hold an extra, temporary reference
The link layer dereferences a buffer right after it is transmitted.

If this extra reference is not held, the second time a buffer is
retransmitted, the reference that TCP holds when keeping the buffer in
the `sent_list` will be taken, and retransmission won't happen reliably
anymore.

As soon as the TCP fragment is acknowledged by the peer, the
`sent_list` reference is taken, and the buffer is freed.

Change-Id: Ie50f9acf02c1dff74248a5dfbec3785a91ff90f7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 46c0997e8b net: tcp: Reduce size of state member from 32 to 4 bits
No more than 4 bits are necessary to store the state of a TCP connection,
so better pack it using bitfields so that it uses only 4 bits instead of
32, by sharing space with `retry_timeout_shift` and `flags` fields.

There are 12 (or 14, if you count the 2 unused bits in the `flags`
field) bits remaining in the same dword, but I don't know what to to
stuff there yet.

This also changes all direct field access for the `state` field to
function calls.  These functions are provided as `static inline`
functions and they perform only casts, so there's no function call
overhead.

Change-Id: I0197462caa0b71b287c0773ec5cd2dd4101a4766
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 525b51594f net: tcp: Get rid of recv_mss field from TCP struct
This frees up some more memory as well, by computing the maximum segment
size whenever needed.  A flag is set in the TCP context to signal if
the value has been already computed.

Change-Id: Idb228d4682540f92b269e3878fcee45cbc28038a
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 9a558c2aaa net: tcp: Remove unused recv_ack field from TCP context
This value is never set (always zero), so it's safe to remove it from
the net_tcp struct.

Change-Id: Ie4c1d90204a9834f2223b09828af42ee101bd045
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 5de6d084a9 net: tcp: Use an uint8_t for retry timeout instead of an uin32_t
Rename the variable to `retry_timeout_shift`, and shift-right the value
each time there's a timeout.  This saves some memory in that structure
by using the holes left due to alignment.

Change-Id: I18f45d00ecc434a588758a8d331921db902f4419
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 1aee85be4c net: tcp: Ensure all timers are disposed of when releasing context
Cancel all delayed work timers: FIN, ACK, and retry timers.  Also, do
that unconditionally regardless of which state the machine is in, as
that's a no-op if the timer has not been started yet.

Change-Id: Ia36b97c6823943976447fbd6389ae04862c19ff9
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Andy Ross d4b9b6c1bf net: tcp: Destroy net_tcp struct at the same time as the context
The net_tcp struct was being cleaned up and destroyed when the
outbound FIN packet is sent on a connection that already received an
inbound FIN.  That's not right, per spec we need to wait for the ACK
(though this would be benign cheating).  And worse: there were code
paths which were themselves spec-compliant where the net_tcp struct
(now a NULL pointer) would be used after this spot leading to
occasional crazy behavior on socket close.

Don't do it this way.  Clean up the TCP struct at the same time we
destroy the net_context.  Much saner that way.

Change-Id: I4bc6b97eb0b71a7fa8faea02c1eb4c4d3bd3ae6d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-20 16:23:17 +02:00
Andy Ross 01ae35b58e net: tcp: Pass correct user_data pointers
The TCP stack inherited msot of the user_data management from UDP, but
it doesn't quite work.  It's not possible to have a single pointer in
the general case, as e.g. a net_context_send() call may happen
synchronously underneath a recv callback and clobber the pointer, even
though there will be much more data coming later on the active stream.

Put a recv_user_data field into the TCP struct and use that.  Long
term, it would be good to revisit this and come up with a unified
solution that works for both.  There is yet another "user_data"
pointer in net_connection that seem likely to overlap too.

Change-Id: Id3a8eca64fc680e0e80b74944c4d621d7810a8fe
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-20 16:23:17 +02:00
Michael Scott c78c7ac13c net: route: remove extra variable use in net_route_add()
Let's drop the lladdr variable and get the link address and
length from the net_linkaddr_storage variable instead.

Change-Id: I75a5d08527cda7df102db897ade9015d39f10caf
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott f3c66e5205 net: ipv6: fix NULL reference in handle_ra_neighbor
lladdr.addr doesn't point to any storage value when it's
handed off to the net_nbuf_read function.  This results
in a write to an undefined area of memory.

Fix this by pointing lladdr.addr to a net_linkaddr_storage
structure's byte storage array which can handle the maximum
specified length.

Change-Id: I05e0a0420b262ba1e5ac95cebe1f0d91f54878ce
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott 7b674cb287 net: linkaddr: introduce net_linkaddr_set function
The net_linkaddr_storage structure contains an array of bytes used
to store the link address.  This array can be different sizes
depending on the CONFIG options used when building.  To facilitate
consistency and error checking let's introduce a new helper function
to copy the addr and len values to this structure.

Also move all uses of memcpy related to net_link_storage structures to
the new helper function.

Change-Id: Ic547d86b07e62e5ac3bc330d4eaeb4508a143200
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott 4aad767328 net: linkaddr: calculate linkaddr storage addr size via config
- Introduce NET_LINK_ADDR_MAX_LENGTH which is either 6 or 8
  depending on whether CONFIG_NET_L2_IEEE802154 is used
- Instead of being a placeholder single index array of uint8_t,
  let's use NET_LINK_ADDR_MAX_LENGTH to assign the size of the
  "addr" array field in the net_linkaddr_storage structure.
- Now that the "addr" field of net_linkaddr_storage contains the
  true size of the link address, we can remove "storage" field
  which was hard coded to 8 bytes (2 uint32_t's).
- Fix 2 references to the "storage" field of the net_linkaddr_storage
  structure.

Change-Id: I2ea12058280b289f65085964eb7d503d4fd260c2
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Johan Hedberg 1f35d47204 Bluetooth: Don't select TinyCrypt RNG for combined builds
For combined builds with Controller+Host the Controller's HW RNG is
used instead of TinyCrypts PRNG.

Change-Id: I4dbe85e547c057cf57ae0934b10866f2bb9f610d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 17:03:44 +00:00
Luiz Augusto von Dentz bfc0c35387 Bluetooth: L2CAP: Fix always using RX_BUF_COUNT as initial credits
In case the channel provides its own MTU and allocator it should be
able to store as much data as set in the MTU, based on that the code
can give enough credits to fill the entire channel MTU.

Change-Id: I291cf1bb643f200bde191914e814f681f4f65c3e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 17:03:34 +00:00
Lee Jones e74a91ce5a Bluetooth: Kconfig: Specify stack size for Bluetooth SPI
This value was found using trial and error.

Change-Id: I8dc3ea0759244bd28b97542f67a037f074d7b871
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-01-18 12:24:52 +00:00
Arun Jagadish d5b5af07be Bluetooth: AVDTP: Added params to AVDTP Request structure
Added pointer to store the callback function
from the application in the Request structure.

Added userdata param, to be used to fill AVDTP resp.

Change-Id: I8f3289545fdbbd91e4ed7f9983f4f4331d9b59a6
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-18 12:10:37 +00:00
Luiz Augusto von Dentz 514c9fa55f Bluetooth: L2CAP: Make sure state is correctly updated
This makes l2cap_chan_add updates the state to CONNECT so it doesn't
have to be done manually for both incoming and outgoing code paths.

Change-Id: I7331e49c675c83c6c1b184eeecc49c75c446a1ff
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 11:58:24 +00:00
Johan Hedberg 6cc35a751e Bluetooth: SMP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I330769204914286bb98583dd89a3d849d4fcc128
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 11:57:23 +00:00
Johan Hedberg eb085514e3 Bluetooth: L2CAP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I77d2e53f7aa7f2832513f235a63ad2cf14e73cb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:33:12 +00:00
Johan Hedberg fcc1fada58 Bluetooth: conn: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I78a3ccc6fcb84b431198f1a6c46aa6d50e9e9cd1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:23:36 +00:00
Johan Hedberg f036dd9ae8 Bluetooth: hci_core: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I4da93076a27a33b15a9b9119cfe5a1ff68acba0b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:21:08 +00:00
Johan Hedberg 645f867444 Bluetooth: Take advantage of IS_ENABLED macro for BT_DBG
The new IS_ENABLED macro allows exposing conditionally enabled code
always to the compiler, even though it may not ultimately end up being
built. This is in particular useful for letting the compiler catch any
logging format string errors. Introduce a new BT_DBG_ENABLED macro
that c-files need to define before including <bluetooth/log.h> in
order to choose whether BT_DBG() logs are enabled or not.

When no Bluetooth logs are enabled the patch also modifies the log
macros to have the format strings checked with the help of the
__printf_like annotation and empty static inline functions.

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg 1adc58fd79 Bluetooth: Introduce a new connection parameter request callback
Introduce a new callback to bt_conn_cb that allows the application to
decide whether the accept or reject an incoming connection parameter
request. If the request is accepted the callback allows the
application to also adjust the values to what it thinks are more
appropriate.

The Zephyr Bluetooth API allows multiple registered connection
callbacks, so in principle there may be multiple le_param_req()
callbacks. It's recommended for an app to just use one (for clarity),
but if there are multiple the app is responsible for managing
potentially different requirements. In the case of multiple callbacks
each callback will receive the modified parameters in case a previous
callback modified them.

Jira: ZEP-1474

Change-Id: I098db5791aac521f1edfa9fefdf847db0a27e3a5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 68732ef9d5 Bluetooth: L2CAP: Remove RECV_RESERVE from BT_L2CAP_RX_MTU
The BT_L2CAP_RX_MTU is counted starting with the BLUETOOTH_RX_BUF_LEN
variable, which doesn't include the BLUETOOTH_HCI_RECV_RESERVE
contribution (this would only be valid if we started subtracting from
BT_BUF_RX_SIZE).

Change-Id: I1ab3eaf8907946c56c2a9fe16b2074f3a3027a0f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 6f114e0a62 Bluetooth: Remove ACL details from BT_BUF_RX_SIZE
BT_BUF_RX_SIZE is used for the RX buffer pool which is used for both
ACL data and HCI events. It should therefore not contain any
ACL-specific details. This patch removes the ACL header size from the
macro and instead makes taking it into account the responsibility to
the Kconfig option. Since buffer sizes are anyway rounded up to the
nearest multiple of 4 the default goes up from 70 to 76.

Change-Id: I41274d9131e7529d41c16bd66de95637fb150a29
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Luiz Augusto von Dentz 27fb0aab10 Bluetooth: L2CAP: Fix using CONFIG_BLUETOOTH_RX_BUF_LEN as MTU
CONFIG_BLUETOOTH_RX_BUF_LEN shall not be used as RX MTU since it doesn't
account for ACL and L2CAP headers.

Change-Id: Ic3ebb4bd13d86a39174840f0ab625b66e863018a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-17 08:44:21 +02:00
Jaganath Kanakkassery 461591728f Bluetooth: RFCOMM: Implement Aggregate Flow Control
This is mainly for backward compatibility with 1.0b devices and for
ICS & spec compliance. CFC is mandatory post 1.0b spec where in
Aggregate FC shall not be used.

Aggregate FC is managed using FCOFF and FCON messages. This is for
the entire session which means that all the dlcs in that session
will be affected.

Implementation is done using binary semaphore wherein it will be
blocked when FCOFF is recieved and unblocked in FCON.
Once tx thread is scheduled then semaphore should be always available
until all the buf in queue is sent.

Change-Id: Ibfd2c4d033cef64c238ead83474f9e171572de1e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-17 08:44:21 +02:00
Carles Cufi 93d7512215 bluetooth: hci_core: Fix conn params validity check
Bluetooth Core Specification v5.0, Vol 2, Part E, 7.8.12:

"The Supervision_Timeout parameter defines the link supervision timeout
for the connection. The Supervision_Timeout in milliseconds shall be larger
than (1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is
given in milliseconds."

Let's remember that:
conn_interval is given in units N * 1.25 ms
sup_timeout is given in units N * 10 ms

sup_timeout_ms > (1 + latency) * (conn_interval_ms * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 1.25 * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 2.5)
yields:
sup_timeout_n * 4 > (1 + latency) * (conn_interval_n)

Change-id: I30ac1d375a1baaa3e61f4c29b1165110599e1f7c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-17 08:44:21 +02:00
Johan Hedberg e564de0deb Bluetooth: Prefer struct bt_le_conn_param over individual values
This reduces stack pressure a little bit, and also paves the way for
introducing an application callback for accepting an incoming
connection parameter update request.

Change-Id: Ib02c14e27cbe34f85d663f36abd0597683ae1dc1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg a54292afc9 Bluetooth: GATT: Fix missing connection address comparison
When receiving notifications we should be properly matching against
the remote address of subscribed peers.

Change-Id: Ibcba1101aac418fd02f9068667f84e8294aade07
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 1dccc36428 Bluetooth: Remove unused bt_hci_driver_unregister() API
There are no users of this API and no (currently) envisioned use cases
for it. Remove it for now - it can always be brought back later if
there's a need for it.

Change-Id: I6530e096e3671c844a3f7dea8856147ffc716d71
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Sathish Narasimman 10bb3bbba5 Bluetooth: AT: Rename enum at_cmd_type elements
Rename the elements of 'enum at_cmd_type' in order to follow the
name spacing. Which should have prefix of 'AT_' for each elements.
This patch also involves the renaming, corresponding handler
function of 'enum at_cmd_type' with prefix 'at_' i.e 'cmd_start' as
'at_cmd_start'.

Change-Id: I722a25954163c06e131b94042c6a18e1e3458f6e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 815e15e3b2 Bluetooth: Controller: Rename hci_le_rand to bt_rand
Rename hci_le_rand to bt_rand and make its parameter types compatible.
This also includes updating rand_get() to use size_t instead of
uint32_t & uint8_t.

Change-Id: I4d434dfbbaf339b1bc7b451d358d07a291dd0375
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 4cd92c90c9 Bluetooth: Use the controller bt_rand() whenever possible
The controller bt_rand() ties into the hardware which uses less memory
and is more power-efficient than using the TinyCrypt PRNG.

Change-Id: I7570d18f3e84dae3d5c2d3322b5d37cd3e8f3b6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 767c92e176 Bluetooth: Consolidate most outgoing ACL TX buffers into a single pool
Having TX buffers split into numerous pools has the downside of
increased memory consumption. This patch takes the initial step to
consolidate these pools into a single one, saving about 248 bytes of
RAM for a basic configuration.

Change-Id: I449ba18b44a9a6af68e9a2c44f19a9286eb88b14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa 4880e717b1 Bluetooth: ATT: Fix redundant sys_slist call
Uses sys_slist_get function to get node and automatically, if valid,
remove one from the list.

Change-Id: I4cee6fbb064bf9644efdb7e6771e702b1f08678a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa 53fde44046 Bluetooth: UUID: Fix format specifier in 128-UUID
Fixes not supported now format specifier.

Change-Id: Ia01ea3fd18acfeed6f4a3899334911dac1b76643
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Johann Fischer 6b79ed0428 net: ieee802154: inform about unsupported frames
Be nice and inform user about unsupported and dropped frames.

Change-Id: Iaf0e7ed660a926c45dac9fc36b788c4c786eac11
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-01-13 14:38:59 +00:00
Luiz Augusto von Dentz 8b185ecc50 net: bt: Add disconnect shell command
Change-Id: Ibb3a6e580751549ab5330296d6cd9f9cae4903ab
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:42 +00:00
Luiz Augusto von Dentz e13a899280 net: bt: Add disconnect management command
This adds NET_REQUEST_BT_DISCONNECT which can be used to disconnect
IPSP in case it is connected.

Change-Id: I8da00b02ee08611bef5f4c0708936b2d31fd2a93
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:30 +00:00
Luiz Augusto von Dentz 1112c2d382 net: bt: Add scan shell command
Change-Id: Ieecf4e3ed91641582fe6a8e5512eb13fe3b8e76e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:13 +00:00
Luiz Augusto von Dentz 4eae48ee64 net: bt: Add scan management command
This adds NET_REQUEST_BT_SCAN which can be used to scan peripherals
advertising IPSS UUID.

Change-Id: I2463079d182b4da080e6ef94d883c7c1e24a454c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:04 +00:00
Luiz Augusto von Dentz 1bcd12d0d3 net: bt: Add shell support
This adds a shell module called "net_bt" that exposes Bluetooth L2
management commands.

Change-Id: Ia6da1d38cfd51502119758a8f6abbb6d1cd31743
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:42 +00:00
Luiz Augusto von Dentz b434d0f50b net: bt: Add connect management command
Connect command can be used to initiate a connection, which in IPSP
terminology refer to a router role.

Change-Id: I12b9428924c88a9c68d3adbfe9016a0dd690aade
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:26 +00:00
Luiz Augusto von Dentz 348f46bf6e net: bt: Fix not showing any logs
Including logging/sys_log.h before net_core.h prevents SYS_LOG_LEVEL,
etc, to be set properly.

Change-Id: Iaa7aa98110aa455162836be1d9560fbfc03569df
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:06 +00:00
Luiz Augusto von Dentz 331c29f96c net: mgmt: Decode event fields
This decodes the event layer, code and type when debugging is enabled.

Change-Id: I23c6fb200f3287a138e46df9f472c9982898675d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:34:51 +00:00
Johann Fischer 133f2c07d2 net: ieee802154: fix validate_mac_command_cfi_to_mhr
Change-Id: I4baa9e8e079531f1759584c22869c97b72ab2588
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-01-13 10:29:04 +01:00
Andy Ross fc35e649ff net: tcp: Don't leak net_conn_handles
net_context_put() forgot to release the conn_handler field causing
subsequent failures in net_conn_register() when they ran out.

Change-Id: I0d306b5035199422fa8788338ac9da8d1900d5f9
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-13 10:29:03 +01:00
Andy Ross 96294b79a7 net: tcp: Signal EOF with a NULL buffer in the callback
TCP didn't actually have a way to signal synchronous receipt of a FIN
packet.  Extend the recv_cb API to allow a NULL buf argument with
status==0 (by analogy to Unix's zero-length read) to signal EOF.

Update docs too, and also echo_server which wasn't prepared to handle
this situation.

Change-Id: I7dc08f9e262a81dcad9c670c6471898889f0b05d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-13 10:29:03 +01:00
li zj 9a87e403ac net: icmpv4 : calculate ipv4 header chksum
In icmpv4, after calling setup_ipv4_header() function,
only calculate ICMP chksum, not calculate ipv4 header chksum,
ipv4 header chksum still 0, the other side will drop this pack.

Change-Id: I1550a4c8c7ab63132d70ba6ce19a7caf78ad84e6
Signed-off-by: li zj <279939902@qq.com>
2017-01-13 10:29:03 +01:00
li zj 0fc1d808a3 net: dhcpv4 : set ciaddr 0.0.0.0 when send DHCPV4_MSG_TYPE_REQUEST
When router receive dhcpv4 request with ciaddr not 0.0.0.0,
some router reply NAK, dhcpv4 never successful.

Change-Id: I4b66b18f7d30ad5a1b638fdca0bb204ed078d551
Signed-off-by: li zj <279939902@qq.com>
2017-01-13 10:29:03 +01:00
Michael Scott a972d03ce7 net: ip: save TCP seq/ack values in tcp_synack_received
The tcp_synack_received() function ends with a call to send_ack().
However, if we don't update the sequence and ACK values, we'll send back
headers with 0 values and the destination will try resending over and
over.

Fix this by saving the seq and ack values when a TCP_SYN is flagged
in the header (which should be the case almost any time this function
is used as a callback).

Change-Id: I57f07ce719f2b6e2fb34c96c867d2e1c37f342ba
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:03 +01:00
Michael Scott f23ca0e5e1 net: ip: reword appdata debug message in packet_received
Trivial text tweak for clarity.

Change-Id: I470d54d86de7ddc4e83e3ad871448c244134c117
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:03 +01:00
Michael Scott 742b5e22ea net: ip: set context state to NET_CONTEXT_CONNECTED on synack success
Once SYNACK has been received for a TCP connection, we need to set the
net context state to NET_CONTEXT_CONNECTED or else calls to sendto()
will fail with -ENOTCONN.

Change-Id: Idd78e1dcdd5ac0bca5d3fba40b59ab8fde6b8729
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott c306844583 net: ip: set local address family during TCP connect
When calling net_context_connect, the local address family
is never set prior to calling net_tcp_register.  This generates
an error:
"Local address family not set." (-EINVAL)

Let's set the local address family prior to this call.

Change-Id: Ic5f2edf684d14f9bb77019c49c95e5524a406417
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott a2464d049f net: ip: on synack copy local/remote data prior to net_tcp_register
When TCP SYNACK is received we register the connection via the
net_tcp_register function.  During this call several errors are
generated concerning local and remote address information not
being set.

Let's copy the local and remote address data prior to this call.

Change-Id: I17cd83f7b4b7e65e45fec1810fb38f745653bdc7
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott ff1345dbaf net: tcp: replace seq/ack/wnd value shifts with system calls
In other portions of the code we use the sys_put_be* function
to shift the values from the current system endian to big
endian array of bytes.  Let's be consistent and do that in
the prepare_segment function as well.

Change-Id: I5a1a4c30ddf313c9e978be98fd969899f5de6190
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Kumar Gala 0f2ce02abe net: Remove NET_SLIP choice from Kconfig
The NET_SLIP Kconfig choice option doesn't really do anything for us,
plus we get warnings related to setting CONFIG_NET_SLIP=y in prj.conf
files.

Warnings like:

warning: override: reassigning to symbol NET_SLIP
warning: override: NET_SLIP_TAP changes choice state

So remove NET_SLIP choice and remove CONFIG_NET_SLIP=y in the prj.conf
files.

Change-Id: Ibccf9cf167f4c8a4df480ca0396bf83fcf60df1e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-13 10:29:02 +01:00
Anas Nashif f1d0c2b0ad shell: add stacks command
Change-Id: Ibefface37c38749043602bce29317a315d0b53fd
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 20:47:10 +00:00
Anas Nashif 36c5167b72 shell: add tasks command to kernel module
Change-Id: I67c497c04e3c92a7f55cc5d95d7d3cfea414b4d8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 20:47:09 +00:00
Anas Nashif 502f0c893c shell: rename command 'set_module' to 'select'
select is more intuitive and easy to remember, and it is shorter too :)

Change-Id: Icc79e5cb88163344c1e2fcf65e313c33c4afa2cc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-11 19:20:57 +00:00
Anas Nashif 7e18ab70f9 filesystem: add mkdir shell command
Change-Id: I84d8acd46ba3406eb3f4a73beaa98b7c132bea7f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-09 19:47:49 +00:00
Anas Nashif 6c1c4b7cd4 filesystem: fix dependency on shell
Change-Id: I7977753fa6897cbe480de83f6d49e3c7952144c0
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-09 15:07:51 +00:00
Jithu Joseph 89f4bf7c7e subsys: disk: Refactor disk_access stuff into a directory
Disk IO functions are used by both FS and USB Mass Storage.
This patch refactors those from FS directory to a separate one.
In addition existing, config options were modified to make
stuff meaningful.

Jira: ZEP-1276

Change-Id: Ia2a2e18f3dbbbdb964c3dc0427d8138ad86134cd
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2017-01-08 20:58:05 +00:00
Anas Nashif f6e039062a kernel: remove dependency on CONFIG_NANO_TIMERS/TIMEOUTS
Remove legacy option and use SYS_CLOCK_EXISTS where appropriate.

Change-Id: I3d524ea2776e638683f0196c0cc342359d5d810f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-08 18:09:52 +00:00
Michael Scott 249cfb682f net: l2: bluetooth: Fix build break in ipsp_disconnected
In commit bf4fb51f44, "net: if: Add NET_IF_UP flag"
a reference to ctxt->iface was added in the ipsp_disconnected function.

Let's add the ctxt variable definition to fix the build break.

Change-Id: Ib06047e333504f3db4fe175fb3ef1dce347e1916
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-06 22:08:13 +00:00
Leandro Pereira fb02efb1c9 net: tcp: Use appdatalen when acknowledging packets
If the length of all fragments is used instead, the TCP header is also
considered; sequence numbers do not consider the header.

Change-Id: I19e77ac0fe62ca619b0903dd0265f8ea4878cdf7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:48 +00:00
Leandro Pereira 162843f90a net: tcp: Store return value of net_buf_frags_len() on a size_t
The net_buf_frags_len() function returns a size_t, which is an unsigned
integer.  Store on an appropriate size_t variable instead.

Change-Id: I98aa4c0ddd7c464737436aa9ce13bdc86c11da2b
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:35 +00:00
Leandro Pereira 342f81b7e1 net: tcp: Remove unused retransmit_timer field from net_tcp
`retry_timer` is being used instead.

Change-Id: I53f8e724b48eca5e17bc9fec38f25c457b1492c9
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:25 +00:00
Leandro Pereira 84b68b8b21 net: tcp: Be more consistent with namespaces for private funcs
Change-Id: Ie2699e01c5cc19cd04eed8383d6c73769366a55e
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-06 14:27:13 +00:00
Andy Ross 3a8b73067d net: tcp: Precompute appdata properly
TCP packets need the computed packet length early so they can fill in
a correct sequence number in their generated ACKs.  Waiting for
packet_received() is too late.  Precompute it before needed, and skip
the evaluation later.

Change-Id: I25547009f88277e0042c74f2005a141819797886
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 14:25:58 +00:00
Andy Ross 02174b8e0f net: tcp: Swap tcp->context backpointers
On accepting a new connection, the stack does an odd "swap" trick
where it updates the struct net_tcp record on the *listening* context
with the values from the new connection, and then swaps it with the
empty one that got allocated for the *new* context.

Unfortunately this swap forgot to swap the net_tcp "context" field
backpointers, so the net_context retrieved at runtime was for the
wrong connection.  Surprisingly, this actually almost worked for a
long time, except that the destination address would be wrong in the
newer setup.

Change-Id: I0c1812ddb9f9ff3e7deb60d1fd67cafd9ba96997
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 13:56:02 +00:00
Andy Ross a5b694fbbc net: tcp: Select correct source address for SYNACK packets
The source address for a TCP SYNACK must (obviously) be the same as
the destination address of the SYN that produced it.  But the existing
IP packet creation routines would simply fill in a default address
from the net_context struct, which is correct for *established*
connections, but for the listening socket is generally INADDR_ANY
(i.e. all zeroes) and will result in an arbitrary choice for source
address (e.g. a link-local address on the same interface) which can
easily be wrong.

So we need to pass the correct address all the way down from the SYN
packet handler code through the net_ipv*_create() packet creation
functions.  This requires lots of API plumbing, but relatively little
logic change.

Change-Id: Ic368f8cef6689f8a27cbafd5933a4964d5cc457e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 08:21:15 -05:00
Tomasz Bursztyka 336e3f8721 net: ieee802154: Add a shell module named 'ieee15_4'
This one exposes IEEE 802.15.4 net mgmt requests through the shell. User
has then the ability to directly make relevant requests like raising a
scan, associating, etc...

For now, it assumes the 15.4 interface is the only one on the system and
thus will rely on net_if_get_default().

Change-Id: I8eb20565b8231e6cfcba6c1479179cc85ff1d8e5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 12:27:01 +01:00
Tomasz Bursztyka 6b41aecd99 net: ieee802154: Expose basic network parameters through net mgmt API
It is then possible to set the channel, pan_id and short address through
this API. Such features are mainly useful for testing purposes.

Change-Id: I41aeb397afdb231458a3b13638f3e13d3ac28a6c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 12:27:01 +01:00
Tomasz Bursztyka 415afe130e net: ieee802154: Fix logging primitive in mgmt part
Change-Id: I9a97acfc06b7836cce622e374e21efcecbd99bd5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 11:02:26 +01:00
Flavio Santes e86b6c23af net/dns: Introduce the qname_copy routine
When a CNAME is part of the DNS answer RR, sometimes a label with
a pointer is found. The CNAME must be reused to create a new DNS
query and that CNAME will become the new DNS Query QNAME. This new
QNAME must not include pointers.

This patch introduces the qname_copy routine that "linearizes" a
given QNAME (perhaps with pointers).

The dns_read routine is also updated to reflect these changes.

Change-Id: I8e8f64e85e2cbf494fd589e2b7a67d470d34604b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes e8eb62b87b net/mqtt: Allow an MQTT subscriber app to receive msgs
This patch adds the mqtt_subscriber_parser routine and modifies the
mqtt_init routine to allow an MQTT subscriber app to receive MQTT msgs.

Change-Id: Ie54ab892dacbc4386acab78a8991eba1850d8171
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes 76e479974a net/mqtt: Allow an MQTT publisher app to receive msgs
Changes applied by this patch:

- Add the mqtt_publisher_parser routine
- Add the MQTT_PACKET_TYPE macro to get the MQTT msg packet type
  (required by mqtt_publisher_parser)
- Add the mqtt_linearize_buffer (required by mqtt_publisher_parser)
- Add the mqtt_recv callback for reception
- Modify the mqtt_init routine to install the reception callback

The mqtt_publisher_parser routine is a callback used internally
to execute the appropriate mqtt_rx routine. Only the following
messages are handled by this routine:

MQTT_CONNACK, MQTT_PUBACK, MQTT_PUBREC, MQTT_PUBCOMP and MQTT_PINGRESP.

On error, it executes the ctx->malformed cb, if defined.

This commit also introduces the mqtt_linearize_buffer routine that
will be used to linearize an IP stack fragmented buffer. This patch
makes use of the net_nbuf_linear_copy routine to linearize the
incoming buffer. mqtt_rx_xxxx routines are also updated to handle
linear buffers (no fragmentation).

Currently, all the network protocol routines assume that the input
buffer is not fragmented. Future versions will remove that assumption
and the mqtt_linearize_buffer routine will be removed as well.

Public MQTT API is not affected by this patch.

Change-Id: I02fece67052ffbc7cb393d5ca545c503da463c4b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes 8619d9d625 net/mqtt: Improve error handling in mqtt_rx_connack routine
Avoid undesired behaviors by exiting once an error is detected.

Change-Id: Id8e6accd6cd096274fe1c40a615d290967f1d4b9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes e4e74be208 net/mqtt: Improve buffer error handling in mqtt_tx routines
This commit improves the buffer error handling in the mqtt_tx
routines.

Change-Id: Ic8e5761d927fe881b2376b6ac948a412e3b1168a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes d490ff27ad net/mqtt: Add the mqtt_rx_publish routine
The mqtt_rx_publish is used to process incoming MQTT PUBLISH
messages. This routine performes the following steps:

- take ownership of the rx buffer containing the MQTT PUBLISH msg,
- call the MQTT parser routine, and
- determine, based on the incoming message's MQTT QoS,
  the next action.

Change-Id: I3cc011cf0c280205161d0484f12a2cfa79fdf44a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes edfaeba73d net/mqtt: Use the right data type
Use the appropriate data type for some variables:

- const input arguments
- int32_t instead of uint32_t for timeout
- uint8_t instead of int for variables that take just a few
  possitive values.

Change-Id: Id7d762b400fa17e6751829ac401cd7c13aabb7b2
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes 4cfd7f7fe2 net/mqtt: Improve indentation
Replace tabs by spaces to improve code alignment in mqtt_pkt.c.

Change-Id: If586b91ba67b8075ddc7e0203dc538420e96b49a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes 51a48d2d07 net/mqtt: Make input arguments const
This commit changes some function signatures found at the private
MQTT Packet Lib. Input arguments representing arrays can be considered
'const', avoiding compiler warnings when passing "const arrays" in
MQTT applications.

Change-Id: I3ebaa9c7ff5fba74324bf79c55027cdd82669eaa
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes c015c0e2c8 net/nbuf: Introduce the net_nbuf_linear_copy routine
This commit adds one routine previously found at the DNS resolver
library. The net_nbuf_linear_copy routine allows to "linearize"
an IP stack network buffer. This routine is required by functions
that must jump between big chunks of data that in this case may
lie between many fragments. Tracking fragments may be a tedious
task, so getting a linear copy of the buffer will reduce code
complexity altough it increases memory consumption.

The DNS client library is updated to reflect these changes.

Change-Id: Iae321f99fa9b05fae7e722b6d41baac427d82d7e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes a46548ec31 net/protocols: Remove unnecessary assignement in Makefiles
Change-Id: Ifea85ebdaf5f1ac6b17abddc0311306c31c36b37
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka 5d0503fa30 net: ieee802154: Handle disassocation notification from PAN coordinator
PAN coordinator can decide to eject a client device from the PAN by
disassocating it.

Change-Id: Ia868554d40a7aceb4c75a0b426db45f56003fbb7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka 820713239a net: ieee802154: Add PAN disassociation request
If associated, this will request to disassociate from the PAN. That's
only client side, PAN coordinator can also disassociate a client, which
case is not handled here.

Change-Id: If308f51b62c5006b4a2db53d0c891e8192f3c198
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka d8b874b0c7 net: ieee80215: Add Active Scan request
Active scan differs from passive scan by sending a Beacon request (thus
the "active" part) and wait for beacons in reply to it.

Taking the opportunity to add debugging output to scanning logic.

Change-Id: I85001b1ea17f4ec4cd315dc39524c4d8f053cee2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka df4fa6557e net: ieee802154: Integrate MAC Command frames handling
Now we can handle incoming MAC command frames.
Association result ONLY for now.

Change-Id: Ib54b1757185ed079fe6914fa7939347020e006d9
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka b53e48de1b net: ieee802154: Add PAN association request
Such management request will enable association the 15.4 device to an
existing PAN.

Change-Id: I61ffd5e4d8192716e067c5225b3327f08944063b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka 8a2bc07af8 net: ieee802154: Integrate beacon frame handling
This is used only for scanning at this point. But will be needed to get
slots information and else in the future.

Change-Id: Ib917469134c6ba5a54485847c612d3755f62ed35
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka 88d4f1f543 net: ieee802154: Add grounds for passive scan
Currently, as only CC2520 device is supported: it will loop over the 16
channels present in 2.4Ghz spectrum. However, this will need refinement
as soon as other spectrums will be in use: L2 layer could request
capabilites from the device in order to know which range to use.

Scan result is done one at a time for now. It's unlikely going to fit
all production use case, so it's going to change in the future.

Change-Id: I2fafec49eb5cbfca1a4f04107ba3b6511d7d956d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka ef041c10b6 net: event: Notify on interface being put down or up
It can be thus used to track the status of network interfaces in order
to act accordingly (no need to try sending things on network if the
interface is down for instance).

Change-Id: Ie160ef0dfdad6679d531d05a7abada96ad1de7db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Luiz Augusto von Dentz 8a16c6681a net: l2: Add enable callback
This adds enable callback which can be used to notify the L2 driver about
changes of interface state, the L2 driver can then check if the new state
is allowed and reject otherwise.

Change-Id: I4bb6b1e32be2633f24694c0246585f803f8c645d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-06 09:11:42 +01:00
Luiz Augusto von Dentz bf4fb51f44 net: if: Add NET_IF_UP flag
This adds NET_IF_UP flag support indicating the interface is up,
currently this shall only be used internally by the driver, later on it
shall be possible to make it public by using dedicated functions.

Change-Id: I38090da4030395b2341733b846004789416d61c1
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-06 09:11:42 +01:00
Johan Hedberg 696b89da0f Bluetooth: Fix potential race condition in bt_pub_key_gen()
It's possible for the Public Key to be available by the time that the
bt_hci_cmd_send_sync() returns, so we need to make sure the flags have
the right values no matter what.

Change-Id: I053093b6611af360f52b14ddca50d409388f9475
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 14:48:01 +02:00
Arun Jagadish 231050a966 Bluetooth: AVDTP:Add Accept Incoming connection cb
Added Accept Incoming connection callbacks for the A2DP layer

Change-Id: I8aee32a97916ed9fc9c4050151e7395e288c404c
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-05 11:33:24 +00:00
Jaganath Kanakkassery c37b59b3bb Bluetooth: RFCOMM: Implement timer in session
As per the spec, the station which disconnects the last dlc
should disconnect session also. In case if remote does not
do it we need to disconnect otherwise rfcomm will be connected
without any dlc. So this starts an idle timer to handle the
above scenario.

This also starts a disconnect timer to handle in case remote
does not respond to session disconnect request.

Change-Id: I3b45aa5bf4c35fd81dc10974f2b0b6d4cfe4ea7d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 09:36:08 +00:00
Sathish Narasimman b5891d1ddf Bluetooth: HFP HF: Rename cind_status_handle_values
Rename cind_status_handle_values to ag_inidcator_handle_values.
Because the same function will be reused internally for +CIEV
Callbacks.

Change-Id: I875064de17700d72ea89dbbe0f5cb6554c813a5e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman 4b323cd72e Bluetooth: AT: Reset AT and CMD state
Reset AT and COMMAND state to process unsolicited response received
after processing result recieved for AT command sent to AG.

Change-Id: Id2a5827ce5b098336291696157027699479478cf
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman 166a8f762a Bluetooth: HFP HF: SLC Enable indicator status report
End of service level connection(call waiting or 3-way calling bit
and HF Indicators bit not set at present). AT+CMER is sent to
enable indicators status reporting in the AG side.

< ACL Data TX: Handle 256 flags 0x00 dlen 24                  [hci0] 102.898017
      Channel: 68 len 20 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 16
         FCS: 0x40
        41 54 2b 43 4d 45 52 3d 33 2c 30 2c 30 2c 31 0d  AT+CMER=3,0,0,1.
        40                                               @
> ACL Data RX: Handle 256 flags 0x02 dlen 15                  [hci0] 102.942198
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I1630bf40f0f84e6e037b405854eb0c1c4ea691c4
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Szymon Janc 46a7989a5d Bluetooth: hci_ecc: Verify LE Generate DHKey command parameters
Reply with Invalid Parameters Command Status if incomplete command
was received.

 HCI Command: LE Generate DHKey (0x08|0x0026) plen 60
        invalid packet size
        f6 0f 79 a0 3c 4f 3e 90 40 66 6b 1d 93 64 af ed  ..y.<O>.@fk..d..
        03 ec b4 5f 29 cf 6d 26 42 02 61 b9 29 9a bf 0b  ..._).m&B.a.)...
        5e da 86 8b 3a ef aa e8 13 3d 87 de a7 dc 36 57  ^...:....=....6W
        25 89 56 43 e8 2a 73 56 62 60 fa 81              %.VC.*sVb`..
> HCI Event: Command Status (0x0f) plen 4
      LE Generate DHKey (0x08|0x0026) ncmd 1
        Status: Invalid HCI Command Parameters (0x12)

Change-Id: I9c4e798096023f0807e8d353ac3318e3d13dc6f7
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-01-05 08:49:17 +02:00
Piyush Itankar 4b5e19d21c Bluetooth: A2DP: Removes confirmation callback registration
Confirmation callbacks needed not be registered with AVDTP
during A2DP initialization

Change-Id: I2cdf8c5a283775e49fa6e7e9404024e26d05a767
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery 665937a19f Bluetooth: RFCOMM: Implement timer in dlc
This basically implements timer for connection and disconnection.

Conn timer will be started when dlc is initialized and stopped
when it is connected. Authentication if any, will be also included
in this timer.

Disc timer will be started during disconnect initiation.

Change-Id: Ia4b74e478fefa42db21aef528e623a24c72ddf7f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery 3b397076ab Bluetooth: RFCOMM: Rearrange fns to avoid forward declaration
Moves rfcomm_send_disc() and rfcomm_session_disconnect() to call it
while doing timer implementation.

Change-Id: I5805d31fb45181193385f055716c8518d68cc4a1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa b11f30a246 Bluetooth: SDP: Update 'no records found' code comment
Adds more descriptive comment to the code responsible for handling no
resolved UUID case.

Jira: ZEP-1112

Change-Id: I1af07949e19246d51bab9df05504a90f5fb22bb2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa 7ec0c37ec3 Bluetooth: SDP: Add UUID reference to user callback
User may want to know when getting called user UUID callback handler
on what UUID the result data was retrieved from server.

Jira: ZEP-1112

Change-Id: Iabb2dbdf0f3cfdb24244e052f094c7549164b199
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Vinayak Chettimada 2d064eef89 Bluetooth: Controller: revert to event callback inside radio ISR
In order that host can continue a connection event by
enqueuing packets, the number of completed packets event
needs to be generated as soon it arrives on air. Hence, the
Controller now calls the radio_event_callback on every radio
Rx complete ISR.

The callback executes at the Radio ISR priority, take care
to only do as little as necessary in the callback, say, just
a semaphore give to wake up the hci_driver's thread.

Change-id: If48afd0f1390d450bc1e7ec66f1c9fd45208d9a4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Carles Cufi e979d656cc bluetooth: controller: Split events into normal and priority
For the host to be able to block on the recv_thread while waiting for a
number of completed packets HCI event, those are pulled from the radio
in a new, higher priority thread that also schedules the execution of
the lower priority event/ACL data recv_thread.

Change-id: I9d356bd297d0504cb16a032fb5fe5530693546e2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Luiz Augusto von Dentz ae6d92a4ef Bluetooth: ATT: Fix using k_fifo API with net_buf
net_buf shall not be used with k_fifo since net_buf_unref will assume
unused bytes in the beginning are actually fragments causing it to
unref them as well.

Jira: ZEP-1489

Change-Id: I5ce420de73b245dc20eb15ea4d8d0b6ba346e513
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg d64f47d956 Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in
which context to call it (based on e.g. bt_hci_evt_is_prio) it's
cleaner to have two separate APIs: bt_recv and bt_recv_prio.

Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 1094f00253 Bluetooth: Reduce the minimum RX buf count to 2
The recent redesign of the H:4 HCI driver means that the smallest
safest RX buffer count goes down to 2. Default is left at 3 however to
get a bit better performance.

Change-Id: I879c7bd3a769f973dfb9bd179d196ab91f9d2abe
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 2f191012c2 Bluetooth: Controller: Deprioritize adv report buffer allocation
Advertising reports are the only HCI events which we can drop if we
are low on buffers. Allocate them therefore with K_NO_WAIT rather than
K_FOREVER.

Change-Id: I0b7c92647f9be54b8746da837037725f8161a452
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 88b620550c Bluetooth: Controller: Switch to controller-side RX thread
Since the controller already uses a thread for receiving data it makes
sense to enable the BLUETOOTH_RECV_IS_RX_THREAD option.

Change-Id: I927b20c1a0afaea8d000df28cc220a69ae817d59
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 533d544d95 Bluetooth: Remove unused prio pool and buffer helpers
These are no longer used by anything.

Change-Id: Ic01467b4fbaae0af29ff5dc537f2e19744170a41
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg d79bdd74e9 Bluetooth: Controller: Use bt_buf_get_rx for buffer allocation
The controller uses K_FOREVER for the allocations so there's no
benefit in trying to use specialized pools (which exist to try to
guarantee availability of buffers for critical data).

Change-Id: I130f2c44a2f28af1284290e6a0b17dcba438862f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 38eef90d01 Bluetooth: hci_ecc: Delay event buffer allocation
Allocate the event buffers after the ECDH operations rather than
before them. This way we don't hold on to the buffer for potentially
multiple seconds while the buffer could be used for other things.

Change-Id: I0fcc34ec4bea2265b7df3c1de3587c2a850c974e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 8f766efc2f Bluetooth: Use bt_buf_get_rx in hci_ecc.c
There's no need to use the type-specific helpers since those anyway
map to the same pool.

Change-Id: I74750f545c989bb921abca58166fe591ed325856
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 53b1503ac8 Bluetooth: Kconfig: Fine tune options for RECV_IS_RX_THREAD
Give more sensible values when RECV_IS_RX_THREAD is configured.

Change-Id: I40b5bd88213d224cc29f63fccef6cecee5868f77
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 0174200cd0 Bluetooth: Add bt_buf_get_rx() helper API
The separate ACL & event pools will soon be removed, and it's already
now convenient to have a generic API when the exact type of the
incoming packet is not yet known.

Change-Id: I84cb65d17ea69ebeaeb21532fbf76689e4fb59a0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg bc8564bddc Bluetooth: Remove support for host flow control
The controller doesn't support this feature and the only driver that
was needing it (h4.c) will be converted not to rely on it in the next
patch.

Change-Id: Ia514b79b6d05aa128768c2355353b7797e8b8977
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 0a3a108762 Bluetooth: Introduce support for HCI driver-side RX thread
Add support for using the context bt_recv() is called in as the RX
thread, rather than having a separate host-side RX thread.

Change-Id: I256bfe5dece5272c816f2292e58747553189963d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg ea0dcd7587 Bluetooth: Refactor bt_recv() logic
Refactor the bt_recv() logic to make it easier to insert #ifdefs to
remove the RX queue and thread when the context calling bt_recv()
itself is sufficient enough.

Change-Id: Ie8c5a4dfe9533a4464a2e4909c94d3e1b185b55b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 57de98daf6 Bluetooth: Kconfig: Introduce BLUETOOTH_COMBINED_RX_BUF option
If the controller doesn't need ACL host flow control it may want to
optimize and use a single pool for incoming data.

Change-Id: Iec2a69bd2d7a127c7329d0423ab5ce6b73cb9904
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 6f429a38d8 Bluetooth: Kconfig Remove HOST_BUFFERS option
This option has not been used so far and will only contribute
unnecessary complexity in subsequent patches that introduce a concept
of combined RX buffers.

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 5d3d13f4a4 Bluetooth: SDP: Send resolved UUID data to user
After getting whole UUID response for SSA PDU request the user can be
informed about discovery results. Result data feeding the user is
splitted to logical record chunks if more than one record was found.
Every such portion represent unparsed SDP record prestripped from record
length. Each response record data passed to user starts from first raw
attributes data and the record response buffer's length tells exactly
about each record length. User UUID callback handler's return result
can drive delivery (dis)continuation of every such portion to the user.

Jira: ZEP-1112

Change-Id: Icec518ca7bab3c8dfef4a966d98e9d9004894bcc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 51e71ea0fd Bluetooth: RFCOMM: Increase dlc stack size to 256
This analyzes the dlc stack using stack_analyze() which is coming
as 188 with BLUETOOTH_DEBUG_LOG off.

dlc stack (real size 320):     unused 68       usage 188 / 256 (73 %)

So increase the stack size to 256.

Change-Id: Ie5d5f267f4f618747551f0bfd0e05ffb47e0bb91
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 164aa00f0f Bluetooth: SDP: Check room needed against user allocated
When getting very first SSA PDU response for given UUID we can extract
from it the counter telling us how much data will be delivered by server
to collect all complete response for given UUID. Let's use that
information to check if the room allocated by app is big enough for
collecting resolved data.

Jira: ZEP-1112

Change-Id: I91515da668d89e05755d64e427dee0936bf20323
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 7eacb0477c Bluetooth: HFP HF: SLC query indicators present value
Service level connection sending AT+CIND? and parse the response
to get the present value of the available indicators.
This patch also providing callback interface to application for
the indicators value received.

Also added doxygen comment for connected and disconnected callback.

< ACL Data TX: Handle 256 flags 0x00 dlen 17                   [hci0] 25.251358
      Channel: 67 len 13 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 9
         FCS: 0x40
        41 54 2b 43 49 4e 44 3f 0d 40                    AT+CIND?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 25.262012
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 33                   [hci0] 25.293028
      Channel: 64 len 29 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 24
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 30 2c 30 2c 31 2c 33  ..+CIND: 0,0,1,3
        2c 30 2c 33 2c 30 0d 0a 86                       ,0,3,0...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 25.295006
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I7b2a89487e2d481391c51201e32b3287808f82dc
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 7782ccbd76 Bluetooth: AT: Change API name skip_whitespace to skip_space
skip_whitespace() API name is changed to skip_space(). Where the
skip_space function is to skip only SPACE(ASCII Dec: 32).

Change-Id: Ib28ffa45295912505bc27a986803ed0ae2b0002c
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 128ef4dd99 Bluetooth: HFP HF: SLC Connection send/parse CIND
Part of service level connection initilization. Sending AT+CIND=?
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 18                   [hci0] 20.888273
      Channel: 76 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 49 4e 44 3d 3f 0d 40                 AT+CIND=?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.914998
        Num handles: 1
        Handle: 256
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.916863
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 142                  [hci0] 20.945835
      Channel: 64 len 138 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 1024
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 28 22 63 61 6c 6c 22  ..+CIND: ("call"
        2c 28 30 2c 31 29 29 2c 28 22 63 61 6c 6c 73 65  ,(0,1)),("callse
        74 75 70 22 2c 28 30 2d 33 29 29 2c 28 22 73 65  tup",(0-3)),("se
        72 76 69 63 65 22 2c 28 30 2d 31 29 29 2c 28 22  rvice",(0-1)),("
        73 69 67 6e 61 6c 22 2c 28 30 2d 35 29 29 2c 28  signal",(0-5)),(
        22 72 6f 61 6d 22 2c 28 30 2c 31 29 29 2c 28 22  "roam",(0,1)),("
        62 61 74 74 63 68 67 22 2c 28 30 2d 35 29 29 2c  battchg",(0-5)),
        28 22 63 61 6c 6c 68 65 6c 64 22 2c 28 30 2d 32  ("callheld",(0-2
        29 29 0d 0a 86                                   ))...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 20.947764
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I33126a19641b889f1749b642cbc5e63984d85b6d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman 39e7350a13 Bluetooth: AT: Rename API's which uses term 'stream'
Rename the API's with 'list' which uses the term 'stream'.
For example 'at_open_stream' is renamed to 'at_open_list' and
the same applies for other API's which uses 'stream' in it.

Change-Id: I62bed70de3d85cd4890b10e04eba27ae2de1907c
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada a69cdca529 Bluetooth: Controller: Remove advertiser struct use in observer
Change-id: I2c332047d80167cb5823f5af605cb5edbcb5e9fe
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 0565945a5c Bluetooth: Controller: fix DLE conditional compilations
Fix missing conditional compilation of Data Length Update
feature.

Change-id: I93aa1da2145a33095c220c863ed1457bb27a7aec
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Johan Hedberg 34cff06a72 Bluetooth: hci_ecc: Fix incorrect private_key size
The private_key parameter to generate_keys is supposed to be 32 bytes
in size, i.e. an array of 8 uint32_t variables.

Change-Id: Ia891fd68bfd8662983b898084e5a8524b7a9b8e2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa c97220c1d6 Bluetooth: SDP: Allocate user delivered memory for resolved data
Adds driven by user params buffer location to be populated by UUID
resolved data. Corresponding handlers responsible for connected and
disconnected states of L2CAP transport channel used by SDP PSM traffic
automatically allocates and unrefs such memory. Data receiving handler
performs buffer fill up.

Jira: ZEP-1112

Change-Id: I8aa97e6e69344dca0f241a4e9097acac75e14a7c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 3304cbc41b Bluetooth: SDP: Validate SSA response PDU
Adds two extra checks against invalid length of attribute payload
frame.

Jira: ZEP-1112

Change-Id: I089442a5b9631471f9f394860681f1483e021c43
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 7c6063c4ec Bluetooth: SDP: Enable resolve all user delivered UUIDs
Iterates all UUID params list delivered by user. When iteration finish
release SDP client L2CAP transport channel.

Jira: ZEP-1112

Change-Id: I0602e32a5296a05719ad1385b4aff537350b3e7d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada d5d473b0f8 Bluetooth: Controller: replace work with mayfly
This commit introduces a very light-weight and lock-less
scheduling of the Controller's deferred function calls
called the Mayfly.

Earlier work implementation used in the Controller had an
O(n) to schedule a function in a linked list that used IRQ
lock during modification of the linked list in the
Controller's ISR executions.

Mayfly is a compile time configurable matrix of queues
where an execution context-safe queue exists between two
execution context, one being the caller and the second
being the callee. Callee(s) are run in a software interrupt
but can also be run in an OS thread.

There are minor clean ups too in this commit related to
folder structure.

Change-id: I5ff44dcee6679d2f5ce9e8437d98d6c868782f3d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 8bd73aeba7 Bluetooth: Controller: add memq_peek interface
Change-id: I276eddd5e347a5930cff3158ee9aaec0cc7a1585
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 85cfff0d92 Bluetooth: Controller: Kconfig fast encryption setup feature
Enable connection encryption setup in 3 connection
intervals. Peripheral will respond to Encryption Request
with Encryption Response in the same connection interval,
and also, will respond with Start Encryption Response PDU in
the 3rd connection interval, hence completing encryption
setup in 3 connection intervals. Encrypted data would be
transmitted as fast as in 3rd connection interval from the
connection establishment. Maximum CPU time in Radio ISR will
increase if this feature is selected.

Change-id: I16f2863fc2aaed624826505739519d4de1ac44c5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 404e7662e0 Bluetooth: Controller: Kconfig Tx buffer size
Add Kconfig configuration to select Tx buffer size, this
value will be returned in the HCI LE Read Buffer Size
command response.
This configuration will allow lower Tx RAM usage when
larger PDU sizes are desired in Rx direction only.

Change-Id: I5106a448d78a0754c4b0f6fa61fd5dcacd87a67c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 27353bb655 Bluetooth: Controller: Kconfig connection RSSI measurement
Add Kconfig configuration and conditional compilation of
RSSI measurement during a connection.

Change-id: I5a2f23f76a7cbbd9569d53d31899a472bf39d3ee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 08fcc44b8a Bluetooth: Controller: Kconfig Data Length Update feature
Add Kconfig configuration to conditionally enable Data
Length Update procedure support in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I4515c0c7cf9aeb333a289397ae3c9bac04a08e4e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 4fb2947b61 Bluetooth: Controller: fix LE Ping conditional compilations
Add additional conditional compilation of code not needed
when LE Ping is disabled in Kconfig.

Change-id: Idab40b1371488e06a6f2009fb553f7655b7b86f3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa d333b3892b Bluetooth: SDP: Handle SSA PDU response
Adds initial handling of SDP Service Search Attribute response PDU.
Currently attributes data are not collected. Main focus was done on
proper handling PDU continuation state to be able receive whole
requested SDP record(s) if found for given UUID.

< ACL Data TX: Handle 74 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 1 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 1 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 2 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 2 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 3 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 19
      Channel: 64 len 15 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 3 len 10
        Attribute bytes: 7
        Continuation state: 0
        Combined attribute bytes: 103
          Attribute list: [len 99] {position 0}
            Attribute: Service Record Handle (0x0000) [len 2]
              0x00010001
            Attribute: Service Class ID List (0x0001) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                OBEX Object Push (0x1105)
            Attribute: Protocol Descriptor List (0x0004) [len 2]
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  L2CAP (0x0100)
              Sequence (6) with 5 bytes [8 extra bits] len 7
                UUID (3) with 2 bytes [0 extra bits] len 3
                  RFCOMM (0x0003)
                Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                  0x09
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX (0x0008)
            Attribute: Browse Group List (0x0005) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                Public Browse Root (0x1002)
            Attribute: Bluetooth Profile Descriptor List (0x0009) [len 2]
              Sequence (6) with 6 bytes [8 extra bits] len 8
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX Object Push (0x1105)
                Unsigned Integer (1) with 2 bytes [0 extra bits] len 3
                  0x0100
            Attribute: Unknown (0x0100) [len 2]
              OBEX Object Push [len 16]
            Attribute: Unknown (0x0303) [len 2]
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x01
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x02
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x03
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x04
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x05
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x06
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0xff

Jira: ZEP-1112

Change-Id: Ie282782fba6ef06c6826b3e624f83c8f4c94ebbe
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Carles Cufi 4b7cdd499f bluetooth: Tune stack sizes after measuring with hci_uart
The following readings were obtained after running the peripheral and
central_hr apps in qemu combined with the controller (hci_uart) on nRF51
and nRF52:

Main Stack 380
Idle Stack: 68
ISR stack: 532
Controller RX Stack: 388
HCI TX Stack: 516

The numbers set in this change provide a safety margin from the ones
measured empirically.

Change-id: Ice7ad7f081502e0ea1accf856a7937c0bf0783b2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa ce61122cdf Bluetooth: SDP: Introduce ContinuationState of PDU
Adds initial handling of PDU Continuation State. It has crutial role
to interact with SDP server when receiving partial SDP PDU responses.

< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I53ea9ae64c3f2685c9a12be3683dfc3a95aa8bf9
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 5f3ce62eed Bluetooth: Fix reserve param of bt_l2cap_create_pdu()
reserve parameter of bt_l2cap_create_pdu() is incorrectly passed
as timeout.

Change-Id: Ieed293f52c2e98f16f1e43c498140178703236db
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Carles Cufi 80f000ab43 Bluetooth: Rename SEND_STACK to TX_STACK_SIZE
For consistency with RX_STACK_SIZE and the rest of stack sizes, rename
to use the normal naming scheme.

Change-id: Ib8d484482466fa8d629e6329e07b927abdd6f598
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 714718a33d Bluetooth: SDP: Validate Transaction ID of PDU
Adds check on receiving side whether current SDP PDU response matches
correcponding SDP PDU request.

Jira: ZEP-1112

Change-Id: Ide8da54fe38f12d3bcb1e7d056050c038b7ec065
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada b37e285c03 Bluetooth: Controller: Kconfig LE Ping feature
Add Kconfig configuration to conditionally enable LE Ping
feature in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I5fbbdbe8f45ac01c9b0d7b11e002a0d1db4d272e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 7fc2a8a4e2 Bluetooth: SDP: Implement ServiceSearchAttribute request PDU
Initial implementation one of basic UUID resolving request PDU based on
Service Search Attribute PDU specification [Core 4.2 Vol 3 Part B 4.7.1]
The request applies approach to query using single only UUID pattern
and getting all attributes for given UUID. The initial PDU transaction
is requested on PSM SDP L2CAP channel connected state.

> ACL Data RX: Handle 77 flags 0x02 dlen 18
      L2CAP: Configure Response (0x05) ident 12 len 10
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 64
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I0ed1d989a5abe030f1c70d4d1f104d488eafb2b3
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Louis Caron 9055f57850 Bluetooth: fix write cmd handling
The data pointer and length was not updated before invoking the
write_rsp function therefore providing pointer to the handle.

Change-Id: I5c27ab7a793979dffb8f1f2c68def027c45f2376
Signed-off-by: Louis Caron <louis.caron@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg fce1938a24 Bluetooth: Fix another incorrect memcpy call
This should also have been net_buf_add_mem(). Otherwise the buffer
gets corrupted.

Change-Id: I4687584777f446d398182c3e8c2cde5946987da4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 1921b53484 Bluetooth: Controller: refactor ISR to reduce critical path code
Move code that can be executed after radio tx/rx packet ptr
has been assigned in the radio h/w.

Change-id: I9c5a34ee6bb74c1265d7871bcdf93894e3e7b190
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada a591205045 Bluetooth: Controller: Kconfig radio ISR profiling
Add Kconfig configuration and conditional compilation of
radio ISR profiling.

Change-id: Ia80d6bc54810156be99b2e6a25327c30d0714697
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 73236dbaa5 Bluetooth: Controller: BT_INFO the ISR profiling event
Change-id: Ic2e01f698c13d76fc462349fe67f1694639888cb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ecb649c2a1 Bluetooth: Controller: add radio ISR profiling event
Added code to profile radio ISR execution time and generate
an event, which can be used to populate a vendor HCI event.

This event and associated code is disabled, subsequent
patch will add kconfig to enable it.

Change-id: Ic3fa3e0f4e36829a22a25ffee039949eaae561a7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada 6996619399 Bluetooth: Controller: use BT_WARN to display unknown rsp
Use BT_WARN instead of BT_ASSERT to display unknown rsp in
HCI layer.

Change-id: I63c792468d9c4768f69df73395ee026a03521704
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada ced33653fa Bluetooth: Controller: internally handle unknown rsp for LE Ping
Peer controllers not supporting LE Ping feature will
respond with unknown response PDU, handle it internally in
the controller rather than exposing it to HCI layer.

Discovered that controller was passing the unknown rsp PDU
to HCI layer when LE Ping was send to Nexus 5.

Unknown response for slave feature request was forwarded to
HCI layer, during that implementation unknown rsp for LE
ping too was getting forwarded to HCI layer.

Change-id: I4396c482e5546d78239cf41d88728de996e48d7d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 41984c7577 Bluetooth: RFCOMM: Handle non supported message types
If peer sends any non supported message then it has to be
responded with NSC (Non Supported Command) response.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Unknown CMD (0x33)
           Length: 8
        01 22 34 55 67 88 9a bb 70

< ACL Data TX: Handle 256 flags 0x00 dlen 11
      Channel: 64 len 7 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 3
         FCS: 0xaa
         MCC Message type: Non Supported Command RSP (0x04)
           Length: 1
           cr 1, mcc_cmd_type 33

Change-Id: I7be3b64a9cf437276c10868d52e0b9c555018df0
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery fb07eb9022 Bluetooth: RFCOMM: Respond to Test command
Test command is to test the connection between two stations.
The pattern recieved should be sent back in the response.

> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x70
         MCC Message type: Test Command CMD (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

< ACL Data TX: Handle 256 flags 0x00 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0xaa
         MCC Message type: Test Command RSP (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

Change-Id: I16beb4cf857cc8bbc049514dbf840d84e13c8fb5
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 14472d757d Bluetooth: Fix incorrect call to memcpy()
This call was supposed to be net_buf_add_mem().

Change-Id: I5e4a718474905c433533fd1c1d7e8e0b7ff35739
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 63f71adc5f Bluetooth: Take advantage of new net_buf_add_mem() API
This helps simplify code that was previously combining net_buf_add()
with memcpy().

Change-Id: If44cf9cd651aba5e544e36567869f147468663eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Tomasz Bursztyka d43af0b4c8 net: shell: NET_SHELL is not NET_LOG dependent
And it's not really a debugging option either, one might want to use it
for the features it brings. Thus moving it out of Kconfig.debug.

Change-Id: Ie1e2d2bcba94ad4b8354d3cc56087227184039b6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:20 +01:00
Tomasz Bursztyka a1aa08c288 net: ip: Improve logging by adding a dedicated sys_log level
Let's make net stack having its own level of debugging through sys_log.
It replaces NET_DEBUG by NET_LOG_ENABLED, which is then semantically
better: someone wanting to log the errors might want that not only for
debugging.

Along with it, CONFIG_NET_LOG_GLOBAL option is added, in order to enable
all available logging in network stack. It is disabled by default but
might be found useful when warning/errors need to be logged, so it is
then unnecessary to selectively enable by hand all CONFIG_NET_DEBUG_*
options.

It is possible, locally, to override CONFIG_SYS_LOG_NET_LEVEL by setting
the level one want to NET_SYS_LOG_LEVEL. This can be useful on samples
or tests.

Change-Id: I56a8f052340bc3a932229963cc69b39912093b88
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:20 +01:00
Tomasz Bursztyka 2e95186eff net: nbuf: Let's remove inner type
It's possible to know from which pool the nbuf comes from so
let's reduce nbuf size by removing its internal type attribute which
becomes then useless.

When a data buffer is not coming from nbuf data buffer pool, let's call
it "EXTERNAL", just to make debugging handling a little simple in the
code.

Change-Id: I6931394c8c4f594137f6380be0a0ba5cea371040
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:19 +01:00
Flavio Santes ac7300611c net: Restructure network protocols
This commit restructures the network protocols. Changes applied are:

- Move lib/iot/ to subsys/net/lib
- Move network protocol headers to include/net
- Move lib/iot/zoap/link-format.h to include/net/zoap_link_format.h
  and link-format.c to zoap_link_format.c
- Move tests/iot/ to tests/net/lib/
- Adapt sample code
- Adapt build system
- Modify doxygen paths

Change-Id: I37085fa4cc76a8a8e19a499ecb4e87b451120349
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft dc862ec104 net/dhcpv4: Use net_if_ipv4_set_netmask()
Use the interface function rather than writing directly to the iface
structure.  Check for errors in nbuf read.

Change-Id: I75311755c2060b640325962ada28adea597cb914
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft defbc89358 net/dhcpv4: Use router option to set IPv4 GW.
Change-Id: I58f47c02665990dcb656f7e6f7802e1958b420a8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 065c84d5a6 dhcpv4: Add option parsing diagnostics.
Change-Id: I81a4fa5df561217bfae0d48eb458bf45cfe55d16
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 739278e09d ethernet/arp: Use gateway for non local ipv4 routing.
Detect non local IPv4 destination addresses earlier and route them via
the gw address. Ensure that the ARP table is populated with the GW
address rather than the final destination address.

Jira: ZEP-1473

Change-Id: I3b628584148b760340ef0fea4da4e8893702c832
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Tomasz Bursztyka 8ab2a90231 net: rpl: Fix a build issue
s/energy_est/estimation when using net_rpl_node_energy_object.

Change-Id: I4b326a0dbbca11d48de0c595dfe843495fe10e04
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka ff5954890a net: ethernet: IPv6 packet length should be relevantly handled
It's much different than IPv4 where it's possible to find the whole
packet length. Here it has to count also the ipv6 header size by itself.

Jira: ZEP-1422

Change-Id: I84b1602ac75ef81b9ceda7898ca9dedf2e54d633
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka a79f9bcbc4 net: statistics: Expose relevant information through net mgmt API
User application can request the information it wants via the generic
net_mgmt() call, following the NET_REQUEST_STATS_* codes.

Change-Id: Ia9e7d318cf11b7bf8bfaf1ad63c8c985be846cc1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka cbd1609bf6 net: statistics: Provide specific Kconfig options
This will help to track only what's wanted (ipv6, tpc, udp, else...) if
needed to.

Change-Id: I5c2e5e582db629b5d0e1cd98004f693c50f532a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka 06e2b421af net: statistics: Make statistics calculation fully private
Let's change from macros to inlined function to make things nicer.

Change-Id: Ie98e0667613961b03c84ca60bc551d0f473765f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka a533eb9b4f net: statistics: Move current statistics code to its own file
This file will own more statistics handling in a near future.

Change-Id: Ifaf86852f5c7166e6878b5dc8f4cd4c166dbee90
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka e3cca46a1b net: buf: Let's make use of func/line parameters when available
It clutters a bit the code with ifdefs but it's quite useful when
debugging.

Change-Id: I4f6899d052921b8ef8a7ec2f6e7df927a1bca2f1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 0a1617365f net: buf: Change NET_BUF_DEBUG to NET_BUF_LOG and add a level option
It will be thus possible to enable only the error logging, or the other
sys_log levels.

Change-Id: I0c0ed789f7cfbb4811320e8f8249151288274873
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 4308da9288 net: log: Do not select STDOUT_CONSOLE
printk is anyway the routine being selected for sys_log.

Change-Id: Id6b516aa6ab8d4d420b9afe22b5e6b832dd3e216
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 90ac0b5c20 net: buf: Fix a debug message missing a parameter
Change-Id: I25a199ba074fa9affaf0a249b6af842a3a477ed7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Marcus Shawcroft 39d5f26988 net/dhcpv4: Correct spellings in comments.
Change-Id: I2c08c35eb81233b14fdfc8ccdcbc84340bdfd6a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:16 +01:00
Anas Nashif 7297f5db88 shell: move shell to its own subsystem
This moves the shell component into its own subsys and groups all
related files and options into a single place.

Additionally, one Kconfig option will now be required to enable the
shell:

 CONFIG_CONSOLE_SHELL=y

The header files was also moved to include/shell/shell.h and can be now
referenced with

 #include <shell/shell.h>

instead of

 #include <misc/shell.h>

Updated documentation as well.

Change-Id: Iffbba4acfa05408055e9fd28dffa213451351f94
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 19:35:11 +00:00
Anas Nashif fad7e2dd8d logging: move event_logger to subsys/logging
Jira: ZEP-1337
Change-Id: If1690e19a882cf53caaa3418ccabeb49c783f63d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 14:34:43 -05:00
Anas Nashif c1347b4730 kernel: replace all remaining nanokernel occurances
replace include <nanokernel.h> with <kernel.h> everywhere and also fix
any remaining mentions of nanokernel.

Keep the legacy samples/tests as is.

Change-Id: Iac48447bd191e83f21a719c69dc26233216d08dc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 14:34:43 -05:00
Johan Hedberg db8a5d9b80 net: buf: Add net_buf_add_mem() API
A very common pattern in code goes something like the following:

	memcpy(net_buf_add(buf, len), data, len);

To avoid having to create this kind of complex constructions every
time, this patch adds a new API which simplifies the call:

	net_buf_add_mem(buf, data, len);

Change-Id: Ic1aeae4baf88b2295d139f672d5d265db2ddbe7b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 16:27:08 +00:00
Arkadiusz Lichwa 4de2bad817 Bluetooth: SDP: Check SDP error when receiving PDU response
Stops handle data if server responds with SDP Error PDU

Jira: ZEP-1112

Change-Id: Iaddb740f71fa86384753ab32956fc69b89faeea0
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa d460181eb0 Bluetooth: SDP: Start receiving response data on SDP PSM
Adds handler responsible for receiving SDP data on SDP client request.
For now simple validation are done on SDP response header data.

Jira: ZEP-1112

Change-Id: Ic6009030db34e26dfdbd57fa1b0a22f6e27b6a11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Szymon Janc fa8a27fc03 Bluetooth: L2CAP: Fix possible endless loop
cid is uint16_t and L2CAP_BR_CID_DYN_END is 0xffff so doing
"cid < L2CAP_BR_CID_DYN_END" comparisong is always true resulting
in for loop not being terminated as expected. Check against cid
overflow instead. Code comment is also added for clarity.

Change-Id: I15d6d838ed8b731824e602d089d765614c96c6c1
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa fe7d3392cd Bluetooth: SDP: Check params validness
Validates user driven bt_sdp_discover_params data.

Jira: ZEP-1112

Change-Id: I7d560f80df80708906d91e541385ddf804bfdeb6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa b04f3a2b17 Bluetooth: SDP: Reset context on disconnection
Resets SDP client session data on related L2CAP transport channel
disconnection state. Leave the channel itself reset to L2CAP layer.

Jira: ZEP-1112

Change-Id: I4d8a8f10908f5e599ba6506470b98508869cb21b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 6d89dd897e Bluetooth: SDP: Queue user UUID to be resolved
Makes possible to append user UUID to context to be able later iterate
it on subsequent resolving process.

Jira: ZEP-1112

Change-Id: I193ff1cee199045c9686dc4ca200adf19db377e4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 4aca00220b Bluetooth: SDP: Refactor bt_sdp_discover API
Renames and refactors helper get_client_session to sdp_client_get_session
to follow existing naming convention and adds second helper creating
new SDP client session. Then simplifies using them the API implementation.

Jira: ZEP-1112

Change-Id: I6b919f521e6665a7117fa06208b3fa2ae5f77fda
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery c7346c4c93 Bluetooth: RFCOMM: Respond to RPN command
Peer sends Remote Port Negotiation command to set port
communication settings. Currently we accept all the settings
sent by remote.

If there is only one value byte in the request then current
port settings has to be returned for which we returns the
default settings defined in ETSI.

Note that RPN may be sent even before a dlc is opened.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Remote Port Negotiation Command CMD (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: Remote Port Negotiation Command RSP (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

Change-Id: I73b7d8577e7e2bc3e436f4db86a91e12db440f1f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery 61f34fd966 Bluetooth: RFCOMM: Pass session instead of dlc in make_uih_msg()
rfcomm_make_uih_msg() only needs session to get the role while creating
msg. This is mainly done since some commands like Test and RPN may come
even before dlc is created.

Change-Id: Ifd5a2ceaf17c20db3f00604cd2b4f1759155123e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc ba2adb70b2 Bluetooth: L2CAP: Fix use of uninitializer pointer
l2cap_br_conn_req_reply expects valid bt_l2cap_chan pointer but this
is achieved only on accept() callback. Use l2cap_br_send_conn_rsp
instead for rejecting cases where no channel was accepted. This also
makes success path being 'primary' function path ie erros all always
handled inside if() statements.

Jira: ZEP-1405

Change-Id: I890b4fcf029afce65eba4f2ebae0b1094feb007f
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2016-12-24 08:42:15 +02:00
Johan Hedberg f3c632bf44 Bluetooth: Add timeout to event & ACL buffer allocation functions
Not all users are in an ISR context where we can't block, so give the
callers the freedom to choose if they want to block or not.

Jira: ZEP-1481

Change-Id: I19bd7e2df94c4eeb60886a17a78f872bd7bea887
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa 3cbce90936 Bluetooth: SDP: Attempt reuse existing SDP client session
Adds validation check when 'sdp discovery' API is to be called
by client, to reuse existing connection if valid or initiate new one
if posssible to set SDP L2CAP link to remote.

Change-Id: I47ce33cb5e95cf2616f9b23712641b912ce40f37
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish 71fdc901e3 Bluetooth: AVDTP: Add AVDTP_Timer & Handler
Added AVDTP_TIMER = 6secs for tracking sent
Singalling Request.
Timeout handler function added.

Change-Id: I76ddcdcfba2b5e9317f66f9815e0d9d3f4cc87e7
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish 129a844d63 Bluetooth: AVDTP: Add AVDTP Pending Request
Added a Pending Request structure, this will keep
a track of the last sent AVDTP Singnalling Message.
This will be used to verify the response from the remote device
Memory will be allocated by the application.

Change-Id: Ic31df154b52ce9013e5039ab195a9651d1811a7a
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa f2c44466a4 Bluetooth: SDP: Add connected and disconnected handlers
Adds for now stubs of handlers responsible for taking a connected and
disconnected state of SDP L2CAP channel.

Change-Id: I21b76b755168fb63f6cade5f6b0c0bab93d0a01f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa b71e34da81 Bluetooth: SDP: Initial implementation of bt_sdp_discover API
Adds basic functionality to be able to trigger establishing outgoing
L2CAP channel to remote using as PSM SDP channel. The number of such
outgoing connections is limited by configured pool of connections.

Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>

Change-Id: Ie5428e5b1b5f5c57f473ee0adfd4621cd9fe6e3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman 9abbc61e4a Bluetooth: AT: Command parsing for range of values
This patch contains API's which is used to parse range of values
eg. (0,3). This patch also parses the string, reads, process and
move the buffer accordingly.

Change-Id: I8dba5b7d630f65b87967c101557c5c7ffd297dd1
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc bddf039736 Bluetooth: Make BR/EDR discovery be limited only by time
If more inquiry results were received during discovery than fits in
storage results with lowest RSSI will be skipped. This is to improve
API usefulness in busy environments where results with low RSSI (likely
more far away than high RSSI) could consume provided result space,

Change-Id: I1e9ca901b693f608d58575916809e8bd8bfe710f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman 77446839ad Bluetooth: AT: Improve API() to work with buffer increment
at_get_number which converts the string into number now operates on
at_client to get the string buffer. This patch also improves API()
skip_whitespace to be operated on at_client. Also the the API's
get_cmd_value, get_response_string are updated to work with buf
increment.

Also in this patch the return type of the function str_has_prefix
is changed from 'int' to 'bool'.

Change-Id: Ia626e0d13212b84413cce0444349975f4abe1cf6
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-12-24 08:42:15 +02:00
Carles Cufi 167eac7df3 Bluetooth: controller: Move call to k_sem_give() out of the ISR
The execution time of k_sem_give() increased slightly recently, and
since it was being called from the radio ISR this had an impact in the
deadlines not being met.
This change moves the actual call to k_sem_give() to a lower-priority
job and thus out of the ISR to avoid its execution time affecting the
ISR's timing.

Change-id: I76c82df895c6daaffef52786b0c900ee15acb0aa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery 0b1e6fb231 Bluetooth: RFCOMM: Respond to RLS command
If remote sends RLS command then it should be responded with the
value received.

> ACL Data RX: Handle 256 flags 0x02 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0x70
         MCC Message type: Remote Line Status CMD (0x14)
           Length: 2
           dlci 10 error: 5

< ACL Data TX: Handle 256 flags 0x00 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0xaa
         MCC Message type: Remote Line Status RSP (0x14)
           Length: 2
           dlci 10 error: 5

Change-Id: Ib70e02aede2088bca748d1eb68bee9b1bc47a65d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery e03f2e249e Bluetooth: RFCOMM: Remove unneeded NULL checks
rfcomm_make_uih_msg() does not return NULL anymore.

Change-Id: I8f49b85df8924af1e0d382e699e655a1ffe70662
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg 2b410afac1 Bluetooth: Fix priority event buffer availability when ECC is used
The ECC emulation synthesizes its own HCI events so we may need up to
two available priority buffers at any point in time.

Change-Id: I88b37c7e9e9f64483d80cde9243470a7f0477321
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish a535880505 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

Change-Id: Ie105a12f613a1c179aa01eb39298df2ee51c2da3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Flavio Santes d8083e92ab arch/arc, usb, ztest: Add the ARG_UNUSED macro
Add the ARG_UNUSED macro to avoid compiler warnings.

Change-Id: Ie07f52e742bdb93fb35301bd50cce3865f229623
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:54 +00:00
Flavio Santes 17a589a486 net/utils: Use the right data-type
Use size_t instead of int to avoid compiler warnings.

Change-Id: I86f804010a7bd0387299648f8c2c0f880f19f580
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:50 +00:00
Flavio Santes 9216e6c47d net: Add ARG_UNUSED
This patch adds the ARG_UNUSED macros to some function arguments
to avoid compiler warnings.

Change-Id: Iae2cd3018c9442ffa9268fdfd33eb9a21f55087c
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:49 +00:00
Carles Cufi fc479e03e0 Bluetooth: controller: Use SERIES config instead of NRF52
In preparation for the new Nordic MDK and nRF52840 IC support we switch
to using the SERIES config instead of the old "NRF52" macro that will be
deprecated in the new MDK.

JIRA: ZEP-1418

Change-Id: I563f025c9db9b7497116c5af23814d95c720f836
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-20 09:14:47 -06:00
Marcus Shawcroft 531cb01c19 ieee802165: Device driver_api is const, honour it.
Change-Id: I6aebffb8abc52013c626e3c67c8c4f1f529932e0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-20 13:47:31 +00:00
Marcus Shawcroft af6095876c net: Device driver_api is const, honour it.
Change-Id: I3fffe80e1be884e2b58387dc7fccf2def9c5e139
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-20 13:47:30 +00:00
Anas Nashif 87133d5def debug: gdb: move to new kernel APIs
Change-Id: Ifed1fe7c60fa150ee3ef4fefabafeb95312bf8bc
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 14:59:35 -05:00
Anas Nashif d687a95611 kernel: move kernel code to kernel/ directly
Also remove mentions of unified kernel in various places in the kernel,
samples and documentation.

Change-Id: Ice43bc73badbe7e14bae40fd6f2a302f6528a77d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 14:59:35 -05:00
Anas Nashif e6b7ba40d1 debug: fixed style and align code
Change-Id: I75875680feb7b814ed1fdafeb42de6f2d7049a90
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:41 +00:00
Anas Nashif 569f0b4105 debug: move debug features from misc to subsys/debug
Change-Id: I446be0202325cf3cead7ce3024ca2047e3f7660d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:40 +00:00
Anas Nashif a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00
Tomasz Bursztyka 675277e28d net: nbuf: Initialize nbuf memory area after allocation
After commit 71c7c01819 about buf pool, we
started to get spurious behaviors on various places of the code on
different boards (a101, frdm...) BUT on qemu. Basically, outgoing ip/udp
packets were full of garbage. Or sometimes it was the abilitty to parse
incoming packet that was happening.

The difference between qemu and actualy boards is - afaik, at least, let
me know if I am wrong - that qemu provide initialized memory (full of
0s). Following this asssumption, this patch just reset the nbuf right
after it got allocated. And all started to work again as thought.

It's in fact a good thing to reset nbuf memory. Even before the above
commit: after being used more than once, a buffer would have ended up
with old content, and this could have been generating a bug. So let's be
on the safe side and always intialize nbuf content.

Change-Id: I50647d9e9b82a4ed340a5ceb0d69409b0194dddd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:56 +01:00
Tomasz Bursztyka f991b82209 net: buf: Use buf->pool instead of now removed buf->free
Tiny debug message fix.

Change-Id: I464ff28d55b946a2e9ba4a0f9d88fbedd7ccef57
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:56 +01:00
Tomasz Bursztyka cff19c17c4 net: l2: ethernet: Handle Ethernet II minimal frame size relevantly
Minimal frame size is 60 bytes, but IP frame might be smaller than this
size minus the ethernet header. In that case, Ethernet frames are padded
so it does reach this minimal size. In this case, ethernet L2 should
update the buffer list so it remove the padding length from the whole.

Change-Id: Id370cad09ad82bb54febeb60b05f7e430cc8f963
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:54 +01:00
Luiz Augusto von Dentz 73e76c2ce2 net: Remove unnecessary k_wakeup
net_buf_put already awakes the RX thread so k_wakeup is not necessary.

Change-Id: I18b5aef5d6e85a9461bc01c17f56c3d4d9a13824
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-16 19:14:53 +01:00
Flavio Santes a8b73aa287 tcp: Validate net_context_put return code
Validate the return code of net_context_put and add debug information
in case any error is detected.

This patch fixes the error reported by Coverity:

Error handling issues  (CHECKED_RETURN)
Calling "net_context_put" without checking return value
(as is done elsewhere 4 out of 5 times).

Coverity-CID: 157833

Change-Id: Ia4a87cc08094bee465c8828411d7c1311481695a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-16 19:14:52 +01:00
Tomasz Bursztyka 9acd710a2a net: Update TODO list on L2 and 15.4 tasks
Change-Id: I1c9e11b05cc8af337349d249d46f524c8a75a4fc
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:51 +01:00
Johan Hedberg 1c9da665c3 Bluetooth: Remove unnecessary runtime kernel object initialization
There are static initializer macros available for most kernel objects
which we should use whenever possible.

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc 83874836ac Bluetooth: SMP: Add support for CT2 auth bit
This allows to use H7 function for key derivation if both sides declare
support for it.

< ACL Data TX: Handle 77 flags 0x00 dlen 11
      SMP: Pairing Request (0x01) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: EncKey IdKey Sign LinkKey (0x0f)
        Responder key distribution: EncKey IdKey Sign LinkKey (0x0f)
> ACL Data RX: Handle 77 flags 0x02 dlen 11
      SMP: Pairing Response (0x02) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: IdKey Sign LinkKey (0x0e)
        Responder key distribution: IdKey Sign LinkKey (0x0e)

Jira: ZEP-1431

Change-Id: I74ecfdd38a69bada0927907a0ef9ed6d59212e47
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Szymon Janc a2d8cee2cf Bluetooth: SMP: Add H7 crypto implementation and unit tests
This adds H7 function implementation and test based on sample data
from Core Specification 5.0 Vol 3. Part H. Appendix D.8.

Jira: ZEP-1431

Change-Id: I49d44ee7a352d1092f6379829d747c7e0ec5e83c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada f0bd2805bc Bluetooth: Controller: tune the xtal and hard realtime radio start offsets
Reduce the time limit for active clock startup and increase
the CPU usage time limit before hard real-time radio
transmit/receive.

Due to isr_wrapper overhead in ARM architectures, more time
was used before hard real-time radio transmission or
reception which was detected by controller implementation
and the controller aborted the radio transactions.

This commit permits more CPU utilization by the controller
before hard real-time radio transactions start.

Change-Id: Id976add80c70cabc753c43dfac6f6603588458d9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada 6de7a808af Bluetooth: Controller: ctrl pdu processing based on available CPU time
On CPUs like nRF51 which run at 16MHz, certain BLE control
procedure PDU processing take more CPU time than permitted
inside tIFS (150us). Current implementation of Data Length
Update procedure does not span over multiple connection
interval (unlike Encryption Setup, which is another control
procedure processing that would consume more CPU time)
hence taking more CPU time inside tIFS on nRF51.

During the radio ISR, the active clock and packet timer are
active and it is used to profile the CPU time taken which
is used to decide on whether there is sufficient time in
the current radio event to process the control packet.

This commit also fixes a potential bug that would cause
disconnection due to MIC failure on encrypted connections
that performed Data Length Update. Controller used to NACK
the request/response PDU if it was not in a state to resize
the receive buffers but did not reset the CCM counter. This
is now fixed by the change done to NACK control PDU based
on available CPU time in radio ISR.

Change-id: Id58322ad76a0dbc284738cdd9a7c0437c9e8c423
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery c776791ed0 Bluetooth: RFCOMM: Rename tmp with next
"next" is more relevant since its used to save next pointer

Change-Id: Ic0a8d543944681ba4291c5aa06125f565ab6115c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery 3ec7df34c1 Bluetooth: RFCOMM: Handle DM from peer
Outgoing connection request would be rejected by peer because
of various reasons like server channel not registered etc.
This handles that by destroying the dlc and informing the same
to user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 4 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 5

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect Mode (DM) (0x0f)
         Address: 0x13 cr 1 dlci 0x04
         Control: 0x1f poll/final 1
         Length: 0
         FCS: 0xbc

Change-Id: I98288db045001bb73ecfd54e7677d88b2bda9c13
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery a95de4360c Bluetooth: RFCOMM: Disconnect session after last dlc disconnection
As per the spec the station which disconnects last dlc should initiate
session disconnection and then l2cap disconnection.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0xfd

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xb6

Change-Id: I2d1d7d284995529d5d1522e0ca6082097db19bc2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg bc8ec12977 Bluetooth: Remove unnecessary NULL check
Change-Id: I6ec661cdd64c3c22d85f84c6246e4dcd5db71815
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg 758e220cdc Bluetooth: Remove inline declaration from bt_le_conn_params_valid
The function is not particularly small, and is used from several
places, so remove the inline declaration. This also prepares the way
for the possibility of having an application callback for letting the
application choose whether it's fine with the proposed parameters, and
thereby influence the response we send to the remote device.

Change-Id: I5848b179318b6fb6ee37fcbd479a919204f559f1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc 8d759fcec4 Bluetooth: SMP: Fix key_id length in smp_h6_test
key_id is 4 bytes value.

Change-Id: I2550f3c2b5ab328562fa4375d215b04d2fc76e6f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Arun Jagadish 7f6a059a36 Bluetooth: AVDTP: Add AV-Stream data structure
AV-Stream Data structure added to AVDTP structure.

Change-Id: Icb6ae80e84b49e8a800c99e7f004b43a0fa6c043
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg 6ca9390e4d Bluetooth: Kconfig: Fix logging dependency on printk
Now that all logging methods use printk as a backend the respective
Kconfig options should declare the right dependencies.

Change-Id: I65c759db0ec7ba6333b76d8d20aea0e374fd4947
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Anas Nashif fe958df4dd libc: rework libc selection and reduce Kconfigs
Moved all libc Kconfigs to where the code is and remove the default
Kconfig for selecting the minimal libc. Minimal libc is now the default
if nothing else is configured in.

Removed the options for extended libc, this obviously was restricting
features in the minimal libc without a good reason, most of the
functions are available directly when using newlib, so there is no
reason why we need to restrict those in minimal libc.

Jira: ZEP-1440
Change-Id: If0a3adf4314e2ebdf0e139dee3eb4f47ce07aa89
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-15 22:31:28 +00:00
Anas Nashif 42738fdff4 net: multicast_eth_addr is use only with IPV6
Change-Id: Ia204a327ec7a85d1b0b0bf79778b4ebee8f294a6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-15 14:32:57 +00:00
Tomasz Bursztyka 353cd721a9 net: Fix incorrect logging format specifiers
Following commit fc21a76db6
Some more fixes are needed.

Change-Id: I19c2c979d44be5edfd76041d3cf4507860795c78
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-15 12:29:03 +00:00
Johan Hedberg 692771fbe9 net: buf: Switch from k_fifo to k_lifo for free buffers
Using a LIFO instead of a FIFO has the potential benefit that more
recently in-use buffers may be "cache-hot" and therefore accessed
faster than least recently used (which is what we get with a FIFO).

Change-Id: I59bb083ca2e00d0d404406540f7db216742a27cf
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 12:06:22 +02:00
Johan Hedberg d659bb020e net: buf: Remove redundant user_data_size from buffers
Since the user data size is now stored in the pool there's very little
value in storing it as well per-buffer.

Change-Id: I17a99123b232423c52a2179b4eccd813728d51b1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:17 +02:00
Johan Hedberg 71c7c01819 net: buf: Remove the need for net_buf_pool_init()
In order to keep the initialization process light-weight, remove
net_buf_pool_init() and instead perform the initialization of the pool
and buffers in a "lazy" manner. This means storing more information
in the pool, and removing any 'const' members from net_buf. Since
there are no more const members in net_buf the buffer array can be
declared with __noinit, which further reduces initialization overhead.

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg 45bc46d42e net: buf: Introduce net_buf_destroy() wrapper
This is only for use with custom destroy callbacks, so that the
application gets isolated away from the details of how exactly the
buffers are managed. This opens up the possibility of switching away
from k_fifo to potentially better solutions, such as k_lifo.

Change-Id: I0d8322fdec3500d8ae060ae471b9448aeaa4572a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 08:45:05 +02:00
Tomasz Bursztyka c8f8527d55 net: ieee802154: ACK reply needs to set all FCF attributes.
That bug never got caught because the buffer in unit test is always
clean and fully initialized to 0, and that part of the code being
tested is never used in real as the ACK reply is directly made by the
chip.

Change-Id: I88c4dd3767b4addf2250165b94f49fae29d322ea
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-15 08:45:05 +02:00
Marcus Shawcroft b42587e9cd net: Switch net dependency to CONFIG_RANDOM_GENERATOR
The CONFIG_TEST_RANDOM_GENERATOR parameter is not intended for
production use.  Switch to CONFIG_RANDOM_GENERATOR.

Change-Id: Id6ce986259270455223ce6a42d19a3d9c9b1e642
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-13 22:50:19 +00:00
Johan Hedberg c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

This patch removes the NET_BUF_POOL() macro and replaces it with a
NET_BUF_POOL_DEFINE() macro that internally expands into the buffer
array and new net_buf_pool struct with a given name:

	NET_BUF_POOL_DEFINE(pool_name, ...);

Having a dedicated context struct for the pool has the added benefit
that we can start moving there net_buf members that have the same
value for all buffers from the same pool. The first such member that
gets moved is the destroy callback, thus shrinking net_buf by four
bytes. Another potential candidate is the user_data_size, however
right not that's left out since it would just leave 2 bytes of padding
in net_buf (i.e. not influence its size). Another common value is
buf->size, however that one is also used by net_buf_simple and can
therefore not be moved.

This patch also splits getting buffers from a FIFO and allocating a
new buffer from a pool into two separate APIs: net_buf_get and
net_buf_alloc, thus simplifying the APIs and their usage. There is no
separate 'reserve_head' parameter anymore when allocating, rather the
user is expected to call net_buf_reserve() afterwards if something
else than 0 headroom is desired.

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Johan Hedberg 3fcb9c4ec2 Bluetooth: Use _vprintk() instead of _prf()
The Bluetooth thread stack sizes are optimized based on the assumption
that printk is used for logging and not printf. Using _prf() (the
printf backend) risks overflowing the stack, so use the recently
exposed _vprintk instead.

Change-Id: Ibcbe0af2994c83114d12aa27a8bc29c77bb8c4c8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-11 04:26:06 +00:00
Arkadiusz Lichwa 24b03e75f3 Bluetooth: Remove not needed header in uuid.c file
Now printk family from <misc/printk.h> already included should handle
BT_DBG() like expansion.

Change-Id: I5e03f786530e4bbbdb94a13a4cd77db580268c11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:34:59 +01:00
Arkadiusz Lichwa c4fa607499 Bluetooth: Fix format specifier in UUID DBG helpers
Replace precision formatter (.) in printk with padding flag like %04x
since for now precision is not handled properly in printk family.

Change-Id: Ib63198e407ef584c5650d6452518b1767047630f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:33:56 +01:00
Johan Hedberg 26056c8318 Bluetooth: Fix left-over printf usage
These should have been converted to using printk instead.

Change-Id: I62323704dad4fc51cc14ee4734acb6b325dcda14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 12:26:02 +00:00
Jaganath Kanakkassery 4349141935 Bluetooth: RFCOMM: Implement Disconnect API
This will be used by the user to disconnect or cancel connect dlc.
This also defines an internal close function which will take
appropriate action based on the dlc state.

In case of user initiated disconnection if some pending packets are
there in queue then it has to be sent before sending DISC packet.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x2b cr 1 dlci 0x0a
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0x6d

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x29 cr 0 dlci 0x0a
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x26

Change-Id: Ie4fa3bd8f6b279fee6fb56ddce198d82c5047849
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-09 06:52:56 +00:00
Arkadiusz Lichwa 5c0a502e9f Bluetooth: L2CAP: Fix uninitialized pointer
When PSM server doesn't have BR/EDR L2CAP resources to assign and handle
incoming request properly, local channel pointer may stay uninitialized.
This fixes such scenario. The fix refactors main connection request
reply handler to additional helper which can be used to send response
unconditionally for situation when local channel is not allocated
to setup L2CAP link between.

Jira: ZEP-1405

Change-Id: I5caedd63a59ad0d1704ac87fa51616a0770320bf
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg f53388dbb9 Bluetooth: L2CAP: Fix format specifier for hex uint16_t
Instead of %4.4x we need to use %04x which printk supports.

Change-Id: I0564be5531bb266b328f77231f5d00f43eabe1ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz 4a0c9e86f6 Bluetooth: GATT: Update CCC addresses
If connection destination address has been changed update the addresses
stored by the time it disconnects since in case of RPA it is no longer
mapping to the same device after it has been disconnected.

Change-Id: I0ce966928f605a885125179eaa7b9093989825ab
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz 624a170e8d Bluetooth: GATT: Fix using bt_addr_le_cmp with destination address
The connection destination address may change if the identity address
is resolved.

Change-Id: Id6f7b6494c24ff118043ba5f4ff54e254376eddf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz ae213a2ea8 Bluetooth: Fix bt_conn_lookup*
bt_conn_lookup shall work both with identity address or initial
destination address as bt_conn may change the destination address with
the identity address.

Change-Id: Ibdd19ec453c3307eb6db188196b7e57a2260b526
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg a4b6b2417d Bluetooth: Switch from printf to printk functions
There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 5ac059b6b9 Bluetooth: Extend advertising parameters with optional own address
Applications may want finer control of the NRPA used for
non-connectable beacons, and provide it up-front rather than letting
the stack generate one.

Change-Id: I84d459372cc85ed09a8f9cde16dbb9b98dec2a43
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg d883fcf814 Bluetooth: Make LE random address helpers public
Expose helpers in hci.h for setting and getting the LE random address
type.

Change-Id: I7c6437051f0b2d1f5f79e19b2616bb643ae6300b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Arun Jagadish ede69e5d19 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

Change-Id: Iafd6cfe7a2f85acd867d096515e1b803882875c2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 9aafa973df Bluetooth: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: I4d6f635a0ed61de698727028ea8767dc0ef28bb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:59 +00:00
Johan Hedberg fc21a76db6 net: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: Iab7cc6da110e9c98720211a6f773dcf055a3a411
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:58 +00:00
Anas Nashif 70f9244db7 Merge "Merge net branch into master" 2016-12-05 15:56:26 +00:00
Flavio Santes 7fae8989f5 fs/disk: Improve code readability
This commit improves source code readability by breaking long
expressions found at some if statements.

Some minor style issues are also fixed by this patch.

Change-Id: I0c8e42eaf0fca3a98490c54a0ccb941766c50fa3
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-05 02:46:52 +00:00
Johan Hedberg 299216b2f0 Bluetooth: Controller: Make use of min() convenience macro
Instead of having custom logic for determining the minimum of two
values, use the existing min() helper from misc/util.h.

Change-Id: I9809883d4a31126329373f293897dd49eb91e9ad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery e36d58e593 Bluetooth: RFCOMM: Remove send DM from drop()
rfcomm_dlc_drop() can be used from many places to unlink dlc
from session and destroy it. So it is better to send DM
explicitly from relevant places.

Change-Id: I9b6a31ce5bb65b90510aa483539d4a201ba12b60
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-03 17:09:38 +00:00
Vinayak Chettimada f0186d716d Bluetooth: Controller: Fix DLE to check supported rx length
When the Controller is configured to support less than 251
as the supported maximum data length, missing check caused
the Controller to incorrectly re-initialize its rx buffers
causing assert during the DLE procedure. This commit fixes
the procedure to correctly use the supported maximum length
if the peer requests a transmit length that exceeds the
supported receive length.

Change-id: I6ad7196e3db44b303ddf2ec06e0ae579bf2eb774
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Szymon Janc d1187302e0 Bluetooth: Make bt_send stack requirements a Kconfig option
This allows to fine tune TX stacks size depending on selected HCI
driver. If needed it can be used to tune for monitor too or other
logging mechanism used.

Change-Id: Ib501921da0b786e151083760d85ec58fe3c08b60
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc b00e747ddf Bluetooth: L2CAP: Fix set but not used variables
If debugs are disabled scid and dcid variables were never read.
This also fix mixed values of scid and dcid in le_disconn_req.

Change-Id: I3b435dd0640c5c65ab5fe68e33dd25e3c9e0026e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc efec1aa79d Bluetooth: Fix missing prototype config
subsys/bluetooth/host/hci_ecc.c: At top level:
subsys/bluetooth/host/hci_ecc.c:277:6: warning: no previous prototype
      for 'bt_hci_ecc_init' [-Wmissing-prototypes]
 void bt_hci_ecc_init(void)
      ^
  CC      subsys/bluetooth/host/conn.o

Change-Id: I920d8b6b66c82be932c579461310505c6d402c08
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Johan Hedberg cb84ad1ad6 Bluetooth: Fix coding style issues in LE address helper functions
Even one-line branches should have {}, and the last two return
statements can be simplified into a single one.

Change-Id: I0f65aeaba867240255eae8e1c461386700444ae6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Szymon Janc 70417f1fce Bluetooth: Simplify ncmd handling
With k_sem API it is possible to specify maximum sempahore value
so we no longer need to track semaphore count.

Change-Id: I86744ba63bd3207051ca3466d4f81b816d24f5ad
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc a081e0a57f Bluetooth: GATT: Fix primary service discovery response
Applications expect service end handle as attribute value in userdata
on discovery response callback.

Jira: ZEP-1354

Change-Id: I664da4a7e054a531ad1c2c8cbc74367cb679ff03
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery dd94c3b3eb Bluetooth: RFCOMM: Handle security for outgoing DLCs
Security needs to be elevated based on dlc required sec_level
before creating dlc. If L2CAP connection is not created then
setting dlc required sec_level to chan would do the job.

Change-Id: I21debd3559c9ccfb79011160d676932bc2a54604
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi d42987acf4 Bluetooth: Controller: Fix local LE supported features bitmap
Correct the local LE supported features bitmap to actually "or"
together all the bits that correspond to the set of features that
are implemented at this time.

Change-Id: I0c62ec566c775514250fcf062aeef6c9656719e3
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Arun Jagadish 6f3c4bf425 Bluetooth: AVDTP: SEP Definition
Added
SEP structure
SEP Registration function

Change-Id: Ib8c4a1753c85390009c154a50a1a1a2f2794e8a2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz 30838af5e9 Bluetooth: L2CAP: Fix possibly reading past the end of buffer
If the original buffer cannot be reused, either by no having enough
space for user data or if is fragmented, it can in fact be smaller than
both the segment buffer and MPS.

Change-Id: I59a537aff59c5d56b2883e9bd51f3a1a3932d348
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz 37b0e0ab2e Bluetooth: L2CAP: Fix segmentation
The segments need to be limited by the minimun of the segment buffer
tailroom and tx MPS not the original buf length.

Change-Id: I580a3bb61aa190ac0cdd3717bc06fd6e6e668304
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi 3b1baa88ef Bluetooth: Controller: Implement ECC commands
Implement the 2 HCI commands that provide ECC public key
and shared secret generation:

- LE Read Local P-256 Public Key
- LE Generate DHKey

Jira: ZEP-1246

Change-Id: I79388bfdb9f2e28b9377b4bb6ee2caca25f33f3e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Tomasz Bursztyka 562f9c1c2e net: ieee802154: Add support for big endian
Structures attribute need to be ordered according to endianness.

Change-Id: Ib3053728cbc49e54631057c779aba0f16aace283
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:20 +02:00
Jukka Rissanen 5ece8c26b5 net: tcp: Fixing the constness of TCP state debug string
Change-Id: I42a8271cf10efcd9ce67ef860a45fa54c0690387
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:20 +02:00
Jukka Rissanen 3eaec41ab8 net: Moved net/ to subsys/net
* Moved networking code into subsys/net.
* Renamed net/yaip to net/ip at the same time.
* Fixed the tests/net to compile
* Fixed the Makefiles and Kconfig files in subsys/net
  to use the new location of the IP stack

Change-Id: Ie45d9e8cb45a93fefdf969b20a81e3b1d3c16355
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:20 +02:00
Jithu Joseph 1dc41f515f usb :mass_storage: correct the license details
Certain structures and defines in this file are from
from mbed's implementation. The file header is updated
as per this.

Change-Id: I688917cdd17cfc8b27d5b78181ced90df73c9efd
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-12-02 02:11:34 +00:00
Baohong Liu 100e141a25 subsys: usb: use unified kernel API
Change-Id: I3eb70333cbfce17ccf1345a94f0f63148c9a3e7e
Signed-off-by: Baohong Liu <baohong.liu@intel.com>
2016-12-01 00:40:46 +00:00
Tomasz Bursztyka 44daf98e27 usb: cdc_acm: Various style fixes
- {} are always required on if/for/while
- no break line before an if, if condition is testing previous
  assignment
- parameters indentation etc...

Change-Id: I83f217c02733b9e63ef1e752f55937f3d7dc03e1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-11-30 15:23:42 +00:00
Tomasz Bursztyka b6e04720c8 usb: cdc_acm: Drop legacy API for unified one
s/nano_sem/k_sem + some necessary changes for the k_sem to work.

Change-Id: I96377083f5e17631b63d6da1a0546966ec95ff8b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-11-30 15:23:42 +00:00
Jaganath Kanakkassery 8166de77db Bluetooth: RFCOMM: Initiate DLC
This patch initiate a DLC when user calls connect. It first does
Parameter negotiation and then establish connection to the
dlci derived from channel given by user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 4

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: DLC Parameter Negotiation RSP (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 14 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 7

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x59

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x92

Change-Id: I62a19f624fc4bb89eb9a109a5352fa763c1241d2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Jaganath Kanakkassery d9eb0fb2a0 Bluetooth: RFCOMM: Refactor rfcomm_handle_pn()
Handle the scenarios like ignoring a response in non existing dlc,
correctly handle if received a command with invalid mtu etc.

Change-Id: Ib0bce9134bac3a0dead03798f859af54873a70c1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Luiz Augusto von Dentz 1bbb31e201 Bluetooth: L2CAP: Fix regression with move to k_sem API
k_sem_take return differ from nano_sem_take since it return 0 for
successful case instead of 1.

Change-Id: Ia39cd624d56dbc1c8e7f3558244bebf765da191d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 8217bb1ef6 Bluetooth: Kconfig: Remove deprecated dependency on NANO_TIMEOUT
This is no longer needed after switch to unified kernel.

Change-Id: Ie1f8dadb3f2e43ae6ccfbfaf1f754196f3237471
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 6cda540a4e Bluetooth: Kconfig: Remove deprecated dependency for ECC support
After switch to unified kernel this is no longer needed.

Change-Id: If9877d3fa038dd873011fb780c7e767e150647ae
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz 58a2b3df7c Bluetooth: GATT: Fix using out of scope variable
This fixes defect found by coverity: 152027 Pointer to local outside
scope.

Change-Id: I50f196a04363ffa6e6654b71a9a1d89034580413
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Carles Cufi c969e757bc Bluetooth: Controller: Implement missing DLE commands
Implement the 3 missing HCI commands required to support
Data Length Extensions:

- LE Read Suggested Default Data Length
- LE Write Suggested Default Data Length
- LE Read Maximum Data Length

Note: Only octets are actually used at this time, not time.

Jira: ZEP-1246

Change-Id: Id76d8fedb5ecaf0001c8429cf22f9a3e2c910a44
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada e9b818e763 Bluetooth: Controller: Fix suspicious use of sizeof
Fix Coverity, sizeof not portable, defect; by explicitly
using sizeof(void *).

suspicious_sizeof:
Passing argument mem_head of type void ** and argument 4U
/* sizeof (mem_head) */ to function memcpy is suspicious.
In this case, sizeof (void **) is equal to sizeof
(void *), but this is not a portable assumption.

Change-id: I4b4776466e16020876500feba0141985b8581017
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 26f6b71a8e Bluetooth: Controller: Fix incorrect irq priority check
External interrupts are indexed from value 16, wherein
0 to 15 are ARM cortex M exceptions. Fixed code in
_irq_is_priority_equal to fetch correct external
interrupt line ISR priority.

Change-id: I9cfd411480e78dfc9635e72d14df9d667a9d8400
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 27b1a24993 Bluetooth: Controller: Remove unused util functions
Change-id: I7b691d082d080239c35b63221e3c6c7aa93ed58e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 94a425429c Bluetooth: Controller: Fix incorrect auto variable init
Coverity analysis discovered NULL pointer being
dereferenced when passing a auto variable. The variable is
now correctly assigned with address of a valid default
value variable. As per design, the dereferencing will not
happen as the master role does not use the passed parameter
only slave role uses it to prepare the connection parameter
request PDU.

Change-id: I3f8519b23a83cb8c50c7fba81810eff7737ff74a
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 7b1c042b02 Bluetooth: Controller: Fix observer filter_policy field size
Coverity analysis discovered that observer filter policy
field was 1 bit, whereas valid range for extended scanner
filter policy feature implemented in controller is 0 to 3.
Increase the bit field size from 1 to 2.

Change-Id: Id4b2e354961dfb3b45f72fa4e0ab18de7425bbb5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Szymon Janc a2ee111aa0 Bluetooth: Fix address type use for passive scanning
This fix using incorrect address type for passive scanning with
privacy enabled. Controller was not reporting directed advertising
to RPA address due to public type being used for passive scan.

This was affecting TC_CONN_GCEP_BV_01_C, TC_CONN_ACEP_BV_01_C and
TC_CONN_DCEP_BV_01_C qualification test cases.

Jira: ZEP-1200

Change-Id: Icc316441fcac1a72d75f9ade27a99030efc846b9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz c0edc551b5 Bluetooth: GATT: Fix using att_ prefix
This might create confusions when debugging as usually the prefix is
associated with the file or layer.

Change-Id: Ibf45578c1f54a4bec896acd6042589c815216e1f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 243668dbc4 Bluetooth: Kconfig: Fix BR/EDR dependencies
BR/EDR code should have minimal impact on LE code so to keep it simple
just require peripheral and central to be enabled when selecting BR/EDR
support.

Fix following Kconfig warning:

warning: (NETWORKING_WITH_BT && BLUETOOTH_BREDR) selects
    BLUETOOTH_L2CAP_DYNAMIC_CHANNEL which has unmet direct dependencies
    (BLUETOOTH && BLUETOOTH_HCI && BLUETOOTH_HCI_HOST && BLUETOOTH_CONN
    && BLUETOOTH_SMP)

Change-Id: I7f7cb8794def0df6daaa4abfe4596df460f1a2b2
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc 9dde3e02fd Bluetooth: Fix use of deprecated PRIMARY init level
Fix following warning:

  CC      subsys/bluetooth/host/monitor.o
In file included from zephyr/include/drivers/loapic.h:58:0,
                 from zephyr/include/drivers/ioapic.h:22,
                 from zephyr/include/drivers/sysapic.h:20,
                 from zephyr/include/arch/x86/irq_controller.h:33,
                 from zephyr/include/arch/x86/arch.h:28,
                 from zephyr/include/arch/cpu.h:23,
                 from zephyr/include/kernel.h:2458,
                 from zephyr/include/zephyr.h:20,
                 from zephyr/subsys/bluetooth/host/monitor.c:24:
zephyr/subsys/bluetooth/host/monitor.c: In function
    '_deprecation_check_sys_init_bt_monitor_init0':
zephyr/include/device.h:130:16: warning: '_INIT_LEVEL_PRIMARY' is
    deprecated [-Wdeprecated-declarations]
  static struct device_config _CONCAT(__config_, dev_name) __used \
                ^
zephyr/include/device.h:245:2: note: in expansion of macro
    'DEVICE_AND_API_INIT'
  DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
  ^
zephyr/include/init.h:69:2: note: in expansion of macro 'DEVICE_INIT'
  DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
  ^
zephyr/subsys/bluetooth/host/monitor.c:193:1: note: in expansion of
    macro 'SYS_INIT'
 SYS_INIT(bt_monitor_init, PRIMARY, MONITOR_INIT_PRIORITY);
 ^
zephyr/include/device.h:48:31: note: declared here
 static __deprecated const int _INIT_LEVEL_PRIMARY = 1;

Change-Id: Ie903e3a075f6614b26018be5769be3651f0963be
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Vinayak Chettimada 11770b8bf4 Bluetooth: Controller: Fix HCI Reset Command implementation
Added implementation for HCI Reset Command. Implementation
gracefully disables any running advertiser, observer, and/
or connection roles, and it resets controller context members.
The HCI Reset Command is implemented in such a way that
driver instances shared with other sub-systems and
application is not disturbed and instance/references used
by Bluetooth Controller are gracefully returned back.

Jira: ZEP-1282

Change-id: Ifb9ae6807736b5ec2d9f346cf2a590322056bcee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Mariusz Skmara 2305196461 Bluetooth: Fix not sending L2CAP Connection Parameters Update Request
This fixes issue that L2CAP Connection Parameters Update Request was
not sent. There was check that used LE features of host controller
to determine if L2CAP procedure or LL shall be used. It was failing
with 4.2 controller. The check shall test if remote supports
LL Connection Parameters Request Procedure. If it's not supported,
then L2CAP Connection Parameters Update Procedure will be used.

Closes ZEP-1220

1/4   L2CAP   TC_LE_CPU_BV_01_C      PASS
2/4   GAP     TC_CONN_CPUP_BV_01_C   PASS
3/4   GAP     TC_CONN_CPUP_BV_02_C   PASS
4/4   GAP     TC_CONN_CPUP_BV_03_C   PASS

Change-Id: I61ad544d9568ca6306a845e05c1a2e28d1693ab4
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 2469bd6f87 Bluetooth: Use convenience macros for timeout durations
Using the K_* macros makes it easier to read what exactly the various
timeouts are.

Change-Id: Ia405d3760b8e600af7e33a7221ef6ec717708973
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 1e20e8dc04 Bluetooth: Fix left-over usage of TICKS_NONE and TICKS_UNLIMITED
Switch left-over usage of TICKS_NONE and TICKS_UNLIMITED to the new
unified kernel counterparts K_NO_WAIT and K_FOREVER.

Change-Id: I2f2a16360e816f9f8791eb216deb3c70b8cc87df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 19:27:34 +02:00
Jithu Joseph fca0add22b console : usb: USB UART console output support
Add support for console output via the USB UART.
Note that console input via the USB UART doesnt work.

Adds a simulated poll method for UART interface exposed by USB.

Jira : ZEP-775

Change-Id: I357827ea52c027eb000baed80225f422df1f3358
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-12 01:39:30 +00:00
Vinayak Chettimada 4812b2d40e Bluetooth: Controller: Fix device whitelist feature
During the initial integration of controller to Zephyr OS,
radio hardware access was abstracted out into hal/radio.c
file. Bug introduced in hal/radio.c has been fixed so that
whitelist feature works again.

Change-id: Ie5faf80b1a008ef326613548a5a28a4ba52e7ef7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 16:40:59 +00:00
Johan Hedberg c245b96249 Bluetooth: Kconfig: Fix order of default entries
The conditional defaults must come last in order to be properly
processed.

Change-Id: Id7a152ca1a1584935029e212d0dd8f37494d1cf4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 12:09:46 +00:00
Vinayak Chettimada 5629197b17 Bluetooth: Controller: Add HCI_LE_Remove_Device_From_White_List
Add implementation in HCI and Controller to support
HCI_LE_Remove_Device_From_White_List, as it is listed as
mandatory under BT Spec. v4.2, Part E, Section 3.19 LE
Controller Requirements.

Change-id: Icef88dffc85746f3cc7adb7fb692ae5578274ed2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 11:56:47 +00:00
Johan Hedberg a14680f7c0 Bluetooth: hci_ecc: Convert to new thread API
Convert from a private task to the thread API, also add stack usage
analysis and tune-down the stack size to avoid wasting memory:

On x86:
ecc stack (real size 1280):	unused 80	usage 1136 / 1216 (93 %)

On arm:
ecc stack (real size 1280):	unused 52	usage 1128 / 1180 (95 %)

Change-Id: Iba84a5a9cb5257c1456663adf4952c5c18650f97
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:52:02 +02:00
Johan Hedberg 81975637dc Bluetooth: Rename left-over mentions of "fiber" to "thread"
Rename left-over mentions in code comments of "fiber" to "thread".

Change-Id: I1af1baf99652434e90eb491c10238b94d26d341d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:06:05 +02:00
Johan Hedberg 916ed6cdd2 Bluetooth: Controller: Stop using deprecated APIs
Switch from fiber_start() to k_thread_spawn() and from NANOKERNEL to
POST_KERNEL init level.

Change-Id: I34fb11cbe20216c8646ebacb07be304a67e3cd0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:04:02 +02:00
Johan Hedberg 8b92cb2d78 Bluetooth: RFCOMM: Switch to using k_thread_spawn()
Use k_thread_spawn() instead of the deprecated fiber_start() API.

Change-Id: I42e798ef3a4276863659c8d97c85224a652be1fd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:55:27 +02:00
Johan Hedberg 500010d369 Bluetooth: Remove need for fiber offload
The bt_recv() function had protections for being called from a
preemptible task context, however nothing was protecting preemption by
ISR. A fairly simple fix is to protect the couple of critical regions
that can be reached from bt_recv() with the help of irq_lock().

Change-Id: Ifc29fd31205eb5425e1b7c862347d9420688df4e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 918a8e6bac Bluetooth: Use k_thread_spawn() instead of deprecated nano_fiber_start()
Switch to using the unified kernel k_thread_spawn() API instead of
nano_fiber_start().

Change-Id: I325cf467ae2a52c6aec8fc166397c323929e3013
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg b0f0742b6e Bluetooth: Use k_yield() instead of deprecated fiber_yield()
Use the unified kernel API k_yield() instead of fiber_yield().

Change-Id: I8f52031f52f7ac8783033a51751dc22decdfa59a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 80e04e4fd1 Bluetooth: Use k_uptime_get() instead of deprecated sys_tick_get_32()
Switch to using k_uptime_get() instead of the deprecated
sys_tick_get_32() API.

Change-Id: I737ef0153eff9d283bae840ff5177f8132396e1b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:38:24 +00:00
Szymon Janc 2b16287286 Bluetooth: Use proper timeout defines for net_buf_get_timeout
Use defines from k_fifo intead of legacy API.

Change-Id: Ib8cf0d88240ef145da550b8cf83d2580e7140521
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:28 +00:00
Szymon Janc 577fe910ae Bluetooth: Remove not needed nano_work.h includes
Those are lefovers from nano_delayed_work usage.

Change-Id: I3f17c7b89b1fa946495e160732457500e2f74f25
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 203897d04e Bluetooth: HCI: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in HCI layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: I953a82a6aa613bb1072a8ad4b01e0f94e5cd64bd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 5aef8dd1ad Bluetooth: conn: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in bt_conn layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ia8f34b475051515fd74000cce745ad226aa18aa5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz b96efa9efd Bluetooth: SMP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in SMP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ida58ff0f609dc2a8fd415692bc2cec91eb56a294
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz ec57d7cdb2 Bluetooth: ATT: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in ATT layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I14d8438c1537febcb7768ef2934042ce38682739
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz b3cece0af1 Bluetooth: L2CAP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in L2CAP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I1e3bd7857248865e34a313dd42862af5f4e3805b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc 47eaaf9f96 Bluetooth: Use unified k_fifo API for FIFOs
Change-Id: I6ddc24575e4bf3c3040945a2bdb62f153b15cdb3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg 3062516a1a Bluetooth: Controller: Improve default RX/TX buffer counts
Currently the ideal buffer counts for a controller-only build are 6 RX
buffers and 7 TX buffers: ATT_MTU of 158 bytes can be sent in one
connection interval of 6 tx/rx -es wherein connection interval is
7.5ms

Change-Id: I64b4620c5e8e7db8d7ed72fa1db82e266e121f27
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc 27cbd586cb Bluetooth: ATT: Fix non-ASCII characters in code comments
Change-Id: Ief28ffbab1f1751344184b35e40f32e1fc1d6ac9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Jaganath Kanakkassery 00457636f8 Bluetooth: RFCOMM: Initiate session connection
This patch introduces the Connect API which initiates session
connection first. If session is already there with the peer
then it has to reuse it and initiate DLC (which will be done
in the subsequent patch) since there can be only one session
per device.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x1c

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xd7

Change-Id: I9828e0f3b3ea43bb17df95f0536e15df86f1b4be
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg e4c5c96a16 Bluetooth: Fine-tune default incoming ACL buffer count
In some SMP + GATT scenarios it's possible we get up to 6 incoming ACL
packets. To handle these efficiently, and more importantly, to not
have to drop data if the controller lacks host flow control (as is the
case currently with Zephyr-based controllers), increase the default
from 5 to 6.

For a controller-build it makes sense to just match up with the
controller-side configured RX buffers.

Change-Id: Id44fa724597b88a51f9085dac009e8d84a439bfc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg b64e0d4c51 Bluetooth: Kconfig: Remove redundant 'default n' declarations
All boolean options default to 'n' without the need to explicitly
state this. It's only the cases where we want 'default y' where we
need to state this.

Change-Id: I47dbda62462ea437a2423b8508ea2cc640a22e41
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg c583a9f43b Bluetooth: Kconfig: Restructure for a more logical hierarchy
Restructure the Bluetooth options more logically.

- Both host and controller are now behind the same high level
  CONFIG_BLUETOOTH.

- Selecting controller support disables other HCI driver selection, so
  the controller isn't in the same list as HCI drivers any more.

- Under the top-level there's a "Custom stack" option, which when
  enabled opens up the option of choosing CONFIG_NBLE.

There are various other cleanups and simplifications in this patch as
well, since splitting these up would have been fairly tricky while
making sure all test cases still build.

Change-Id: I5bb715cb9d20201cb8b72fbd149c8a09a4b2d7d2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg 1c40b964a0 Bluetooth: Dump the content of unhandled events as hex
This should be particularly useful with the recently added controller
assert functionality that causes vendor events with debug information.

Change-Id: Ied0df2ff414e08c11a73cca0afba4dc04b0b8625
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Carles Cufi f7d313b154 Bluetooth: Controller: Add ASSERT info dump on HCI builds
When building Zephyr in the controller-only configuration,
assertions that happen in the Link Layer code are not visible
to the Host which is running on another HCI and connected via
UART or USB to it. This patch allows the Controller code
to output the assertion line number when in such a configuration,
allowing the Host to view the event to help debugging.

The event format used is temporary and will be replaced by a
standardized Vendor Specific specification to come at a later
time.

Change-Id: I013ca6783a3fdedc47b171132919dd4798c66285
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-11 07:59:15 +02:00
Johan Hedberg 50f03a8de5 Bluetooth: Controller: Kconfig: Clean up style issues
The right convention for help text is tab + 2 spaces.

Change-Id: I2722a8b33f5f74be110dc43fbcecc12841f0db84
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz 629ab2da6b Bluetooth: ATT: Fix not forwarding error properly
When retrying the request due to a security error that can fail but since
the original buffer was freed in the process the code can no longer verify
if the opcode matches thus it always fails BT_ATT_ERR_UNLIKELY instead of
using the response error, so this not longer cares about the opcode and
just use the response error always.

JIRA: ZEP-1195

Change-Id: I1149b993b97733ab5bb00f347e4f973647e0fdd4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Sergio Rodriguez 6044f05f8a usb: class: Using unified kernel thread spawn API
Change-Id: I1e46a3414b71493875cf7f3f05af4ba4750df7c6
Signed-off-by: Sergio Rodriguez <sergio.sf.rodriguez@intel.com>
2016-11-11 02:50:49 +00:00
Luiz Augusto von Dentz bc3af66a01 Bluetooth: L2CAP: Add helper function to create LE signalling PDUs
This consolidate code around LE signalling header handling which has been
duplicated in many places.

Change-Id: I0c2cd48c155b751e1bbbd26070965d075cdc2cc5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:43:43 +00:00
Carles Cufi 6ccfa64b5c Bluetooth: Controller: Handle LL_UNKNOWN_RSP PDU for remote features
When a peer controller does not recognize one of the LL control
PDUs received, it will issue an LL_UNKNOWN_RSP PDU to let the
peer know that it does not recognize the request.
The controller now handles this incoming PDU and completes the
procedure by issuing the appropriate HCI event in the case of
an LL_FEATURE_REQ and _RSP pair.

Jira: ZEP-1220

Change-Id: I7c04a346441f04deee41198daa6309c11ae1b571
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-09 08:57:52 +02:00
Johan Hedberg 195e1b89b1 Bluetooth: Fix usage of C++ reserved word
'private' is a C++ reserved word and will lead to compilation errors:

  C++     ble.o
In file included from ble.cpp:7:0:
 include/bluetooth/bluetooth.h:284:10: error: expected unqualified-id before 'private'
  uint8_t private[4];

Change-Id: I36aef5a84af4fc66e1c810bd0c56e5ab5f803294
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman c719bfb689 Bluetooth: HFP HF: SLC connection-Send/Parse BRSF
Service Level Connection(SLC) Initialization part. Sending AT+BRSF
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 20
      Channel: 75 len 16 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 12
         FCS: 0x40
        41 54 2b 42 52 53 46 3d 31 34 38 0d 40           AT+BRSF=20.

.
> ACL Data RX: Handle 256 flags 0x02 dlen 23
      Channel: 64 len 19 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 14
         FCS: 0x86
         Credits: 4
        0d 0a 2b 42 52 53 46 3a 20 38 37 31 0d 0a 86     ..+BRSF: 871.
> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I51581928d479ea4229b32a07cbea86c1f6fe09c8
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman b0d34d83c5 Bluetooth: AT handling error condition
In function at_get_number check for the value if gets computed.
If not return error. Also change the end state handling.

Change-Id: I193b04fa2880dfb44e7727b30b67c1ec2e051cc7
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg 8ed846285e Bluetooth: Implement bt_storage_clear()
Add an implementation for the bt_storage_clear() API.

Jira: ZEP-181

Change-Id: Iae01c571c161317ea0cc44513d108301c7b5a069
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg 77a8516dd2 Bluetooth: storage: Add basic support for internal storage
Add basic implementation of an internal storage handler that uses the
local file system. The root directory for all Bluetooth related data
is /bt. Each remote device has its own subdirectory and each key its
own file. This helps keep the implementation very simple, but does
come with the meta-data overhead for each file.

As an example, the value of a key 0x0001 for a device with a static
random address cc:11:22:33:44:55 would be stored in the following
file: /bt/cc11223344551/0001. Local values such as the identity
address are stored directly under /bt with a file name that matches
the key the same way as remote-device files.

For full functionality the implementation requires a file system that
can support file/directory names of up to 13 characters in length. If
the file system supports less than that (as is the case with FAT12)
then only local values can be stored (in /bt/abcd). Local values
include the identity address as well as the local IRK.

Jira: ZEP-181

Change-Id: I7dc696af6353a154cb00dcd01a5f4ac3d7127e6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc e18e3ed60a Bluetooth: Controller: Use unified k_sem API for semaphore
Change-Id: I02b4e5f4d0a2995cfae1b9a2edcbdf01d6ec631a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8f800a8bfe Bluetooth: Use unified k_sem API for semaphores
Change-Id: I0099c837cc8ad67b8f927b2debd771acfe626eea
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8944c25c90 Bluetooth: Controller: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ib72c4038637c303ee32e433706355299ae1b9a13
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 3808ad0a96 Bluetooth: L2CAP: Limit segments to TX MPS
le_data buffers are no longer limited to the minimun of 23 bytes, instead
it uses CONFIG_BLUETOOTH_L2CAP_IN_MTU which means it can be bigger than
the MPS thus causing invalid data to be sent:

> ACL Data RX: Handle 64 flags 0x02 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 672
        MPS: 23
        Credits: 65535
< ACL Data TX: Handle 64 flags 0x00 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 230
        MPS: 65
        Credits: 4
        Result: Connection successful (0x0000)
< ACL Data TX: Handle 64 flags 0x00 dlen 27
< ACL Data TX: Handle 64 flags 0x01 dlen 2
      Channel: 64 len 25 [PSM 128 mode 0] {chan 0}
        3c 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff  <...............
        ff ff ff ff ff ff ff ff ff

JIRA: ZEP-1219

Change-Id: Id67f1faac8766c66aa24c7421d44112434666a10
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 3317227437 Bluetooth: Remove workaround for Mynewt firmware bug
This is not needed for Zephyr controller build and should already
be fixed in Mynewt.

Change-Id: I39e81dc3e9b5fd5a3f5f823465527248625caf26
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Arun Jagadish 227b1d4643 Bluetooth: AVDTP: Set Profile Security Level to Medium
Setting AVDTP Profile Security to Medium

Change-Id: I93aa367ac5bfe4e8bfe08f25d0e7e9d65b891350
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 4f39b4ceb1 Bluetooth: L2CAP: Fix regression causing credits not to be restored
Patch 8c118f8673 causes the wrong semaphore
to checked so receiving credits are never restored which caused the
channel to get stuck after all the credits are consumed.

JIRA: ZEP-1199

Change-Id: I9cd5474b3bcaafcb19d15613939ce30d07befe0a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Jithu Joseph 63b4e2134f usb: class: Add USB mass storage class support.
This patch implements USB Mass Storage device Class,
which allows the  Zephyr target Board to appear
as a USB drive to a host.

This code would invoke disk_read() /disk_write()
hooks which are to be provided by the storage
layer.

The Mass Storage protocol state machine is based on
mbed's implementation. We augment it by adding Zephyr's
USB transport and Storage APIs, and offload disk ops
to a fiber context rather than in the USB irq context.

origin: https://developer.mbed.org/users/mbed_official/code/USBDevice/file/01321bd6ff89/USBMSD

Jira: ZEP-233

Change-Id: I8199598c76da20ab20012d81dac7615f6a366303
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-09 02:45:46 +00:00
Jithu Joseph 7eab305593 usb: Add end-point stall APIs and flow control APIS
USB class drivers may need to offload some work from
upcall interrupt context to a background fiber. This
requires some way to defer taking more data from host
till the offloaded work completes. Two APIs are added to
achieve this.

Further USB class drivers sometimes need to set STALL condition
on end-points to signal errors to host.These too are
added.

Change-Id: Ic973522c3394e23d7f9c4c67affc0cd050afc20f
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-09 02:45:46 +00:00
Jithu Joseph 2fe288b4aa fs: expose generic ramdisk/flash disk access functions
This patch removes "FAT" from  files names, config names and
symbol names so as to avoid confusion, when other modules use
them in a more generic way.

Also flash_disk_access.c and ram_disk_access.c now exports generic
disk_access symbols as defined in include/disk_access.h rather
than FAT specific ones in fs/fat_diskio.h. Thus modules like
USB which need to use disk_access interface is not dependent
on symbols from ELMChan FAT module. Also fat_diskio.h
is removed.

Further the shim between ELM chan and Zephyr is modified as
per these changes.

Change-Id: Ifd80f14a629e467ee9c7a9aaff8a4896eed11982
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-11-09 02:45:45 +00:00
Johan Hedberg 61cfaa1be1 fs: Add simple shell support
Add a simple shell that allows exploring the contents of the file
system.

Jira: ZEP-1235

Change-Id: Iaa49f0be18980dd740e9552ddf4761196a818884
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-08 14:22:33 +00:00
Vinayak Chettimada fb032efa90 Bluetooth: Controller: Use configured clock source
Remove hardcoded use of crystal as 32KHz clock source and
20 ppm accuracy; and use the values from config for sleep
clock source and sleep clock accuracy value in Bluetooth
Controller.

Change-id: I1c0d53ecf8ad158153d5186a6680b5eb03d1641b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-07 12:04:03 +00:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Johan Hedberg f26007d212 Bluetooth: Print full controller info upon init
Provide more detailed information about the controller address and
version upon init when debug is enabled.

Change-Id: I5fe9c7c91f95928cb3cc64b801137bb1466e4115
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:06:31 +02:00
Vinayak Chettimada d62426030c Bluetooth: Controller: Fix re-encryption procedure
During implementation of alternate encryption procedure
usable in nRF51, commited in
c41d3edda8, re-encryption
procedure was broken. This commit fixes the issue, and
now re-encryption should work on both nRF51 and nRF52.

Change-id: Ia41200f42b1d46e1f3f35ff44b582d4ffcc5f4fa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-04 22:06:31 +02:00
Mariusz Skamra 748c00b31e Bluetooth: GATT: Pass data buffer as NULL if length is 0
So that application could check data pointer to see if any
data have been received and if read operation is complete.

Change-Id: I36c3ff81baefbc535374d937e5297938445eafa6
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 1b7c219f8a Bluetooth: L2CAP: Make use of bt_l2cap_chan_set_state on BR/EDR
This makes use of the same code used by LE to print the state transitions.

Change-Id: I90a04f3c3f426fde1e0987acb572f7371c483c1c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 5fecf98c8e Bluetooth: L2CAP: Log state transitions
This adds a common function to log state transitions including the caller
function and line in case something goes wrong:

[bt] [DBG] bt_l2cap_chan_disconnect: (0x0011b14c) chan 0x001199c0 scid 0x0040 dcid 0x0040
[bt] [DBG] bt_l2cap_chan_set_state_debug: (0x0011b14c) chan 0x001199c0 psm 0x0080 connect -> disconnect
[bt] [WRN] bt_l2cap_chan_set_state_debug: bt_l2cap_chan_disconnect()1562: invalid transition

Change-Id: I246a9004a04d93a38b8c7f7633705f6c191698b2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 349230321f Bluetooth: L2CAP: Fix not updating CoC channel state
Channel state shall be updated properly otherwise it may cause unexpected
errors.

Change-Id: Ifd54d6bd3c5b44a40c315fd8a2946b30168aa65f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 88038d1782 Bluetooth: RFCOMM: Define macro for PF bit
This defines and clarifies PF bit macro for both UIH and
non UIH packets.

Change-Id: Ide7736c0fc8607708824766adbfccf1bd7bc48e9
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 70f1df22a4 Bluetooth: RFCOMM: Set sec_level to LOW during L2CAP register
Security will be elevated based on the DLC required level
during connection.

Change-Id: I0b63885582f34a5689f7bc8081c1f9f011b2325f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Sathish Narasimman 56392e5c2e Bluetooth: Fix initialization of variable
Initialize the variable to zero before computing.

Change-Id: Iccdf77a085667728dbb68779f001c8d940a7a89d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 807bd5fec8 Bluetooth: L2CAP: Handle LE connection response security errors
If there are security errors bump the security of the connection and
retry:

7C:7A:91:18:82:5F (public)> l2cap-connect 0x0080
[bt] [DBG] bt_l2cap_chan_connect: (0x0011ae8c) conn 0x0011b940 chan 0x00119700 psm 0x0080
[bt] [DBG] l2cap_chan_tx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] l2cap_chan_rx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] bt_l2cap_chan_add: (0x0011ae8c) conn 0x0011b940 chan 0x00119700
L2CAP connection pending
7C:7A:91:18:82:5F (public)> [bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 2 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0000 mtu 0 mps 0 credits 0 result 0x0005
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 7
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 7
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 65
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 65
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
Security changed: 7C:7A:91:18:82:5F (public) level 2
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 3 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0040 mtu 672 mps 230 credits 10 result 0x0000
Channel 0x00119700 connected

Change-Id: I2402fd86cc6bdf41a537053325e0a1973c23377a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Luiz Augusto von Dentz d1ae81eddd Bluetooth: L2CAP: Make CoC depend on SMP
This is necessary in order to properly handle security errors which are
part of the testing specification thus can influence qualification.

Change-Id: If444e753be9196f3d5bb36cea00e332a33aa249f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 5d40ea1d15 Bluetooth: RFCOMM: Introduce helper to initialize dlc
This is to avoid code duplication while implementing outgoing
connection.

Change-Id: I52f882b7be9180f29def59c8ac3ef0a4798b719d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery e3c258e286 Bluetooth: RFCOMM: Introduce helper to get session
This is to avoid code duplication while implementing outgoing
connection.

This also moves setting initiator flag while allocating, than
doing it when SABM is received.

Change-Id: I8e811c995bf0eaa0bd24715e2e96d8a578a79c5d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 2eba256fd2 Bluetooth: RFCOMM: Define enum and macros for role and CR
This replaces initiator flag of session and dlc to enum which has
two values INITIATOR and ACCEPTOR.

Also this defines macros for CRs in header. Basically there are
three types fo CRs. Frame header CR has different meaning for
UIH and non UIH packets. Also this renames the existing msg hdr
CR to make it consistent.

These changes are basically done to make it more readable

Change-Id: Ic15e93465b0afbd19d8805f27d7a43f34ef38689
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery f6f4acbced Bluetooth: RFCOMM: Remove extra tab
Change-Id: I2edafa32711cbac933d719a1ea0736e955bbb12c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

Change-Id: I3bc796f7e331fca0c485f3890d62b9c03e027b96
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Anas Nashif 4d090e09d6 usb: move usb subsystem to subsys/usb and cleanup header inclusion
Change-Id: I5bdfd2cf5fee62af2ca772d778477f4f378a6a55
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-31 19:21:42 +00:00
Johan Hedberg c9dcbe66dd fs: Kconfig: Remove bogus default value
FS_FAT_FLASH_DISK_W25QXXDV is a boolean so "" makes no sense.

Change-Id: Ic43529928d80bcd76c2876219990bcec86657d3d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-31 08:08:27 +02:00
Johan Hedberg 51390c39a2 fs: Kconfig: Clean up representation of mutually exclusive options
The flash and RAM disk options are mutually exclusive (evident e.g. in
both defining FS_VOLUME_SIZE and FS_BLOCK_SIZE variables), so they
should really be inside a choice-endchoice block. The duplicated
options can also taken care of with a single definition using
conditional default values.

Change-Id: I87733f0c342166a9e03aa0e1f34390d91107b137
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-31 08:08:27 +02:00
Johan Hedberg b108d02eba fs: Make API naming adhere to the appropriate namespace
The namespace allocated for the filesystem API is fs_* and FS_*. That
means all symbols and defines should adhere to it.

Jira: ZEP-1155

Change-Id: I422310448b7c7c347f621aea6d7b1d97ef25c94d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-31 08:08:10 +02:00
Ramesh Thomas e354ad2a36 fs: Move file system code to subsys/
Subsystems code will reside in subsys/ folder. This patch creates the
folder and moves FS code there.

Jira: ZEP-1120
Change-Id: If3b1bcb996c5fbd4056cd5d1920d41d29810d6b2
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2016-10-30 13:23:58 +00:00