Commit graph

2410 commits

Author SHA1 Message Date
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