If we were asked to add 10KB to a packet, adding it won't help -
such packet won't be even sent by hardware on our side, and if
it is, it will be dropped by receiving side. So, make sure we
never add more data than MTU as set for the owning interface.
This actually gets a bit tricky, because we need also to account
for protocol header space. Typically, when net_pkt_append() is
called, protocol headers aren't even added to packet yet (they
are added in net_context_send() currently), so we have little
choice than to assume the standard header length, without any
extensions.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
When sending a packet with AR flag set, the ACK frame that should be
replied to it must holp the same sequence number, so let's verify this
properly.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
There will be place where validating only this part of the frame will be
necessary. This will avoid to run the little bit heavier
ieee802154_validate_frame().
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.
Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.
This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.
For users that just want to continue their work with minimal
disruption the following should suffice:
Install CMake 3.8.2+
Port any out-of-tree Makefiles to CMake.
Learn the absolute minimum about the new command line interface:
$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..
$ cd build
$ make
PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Add a generic function for TCP option parsing. So far we're
interested only in MSS option value, so that's what it handles.
Use it to parse MSS value in net_context incoming SYN packet
handler.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Calculates full TCP header length (with options). Macro introduced
for reuse, to avoid "magic formula". (E.g., it would be needed to
parse TCP options).
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
MSS is Maximum Segment Size (data payload) of TCP. In SYN packets,
each side of the connection shares an MSS it wants to use (receive)
via the corresponding TCP option. If the option is not available,
the RFC mandates use of the value 536.
This patch handles storage of the send MSS (in the TCP structure,
in TCP backlog), with follow up patch handling actual parsing it
from the SYN TCP options.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
The commit 971da9d0 ("net: pkt: adjust_offset: Simplify and optimize
code") changed the adjust_offset() function but left the error print
intact. This print is now invoked even if there is no error which
looks bad in debug prints.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
The addrlen of accept() and recvfrom() is a value-result argument. It
should be updated to the actual size of the source address after
calling accept() and recvfrom().
Signed-off-by: Aska Wu <aska.wu@linaro.org>
Update the firmware update_result accordingly by checking return
value of the firmware data write callback registered by application.
Also, set response code according.
Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
The expire function can call net_context_unref() which tries to
get a semaphore with K_FOREVER. This is not allowed in interrupt
context. To overcome this, run the expire functionality from
system work queue instead.
Fixes#4683
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
An edge condition was handled in a special way, even though the main
condition covered it well. More code, more jumps == slower code,
bigger binaries.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Create http library that uses net-app instead of net_context
directly. The old HTTP API is deprecated.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Now that net_buf has "native" support for sys_slist_t in the form of
the sys_snode_t member, there's a danger people will forget to clear
out buf->frags when getting buffers from a list directly with
sys_slist_get(). This is analogous to the reason why we have
net_buf_get/put APIs instead of using k_fifo_get/put.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The code parsing received net pkt to get source or destination
sockaddr repeats multiple times in net_context.c.
Eliminate the duplication by net_pkt_get_src_addr() and
net_pkt_get_dst_addr() which can handle different internet protocol
(i.e. ipv4 or ipv6) and transport protocol (i.e. tcp or udp)
Fixes: #4421
Signed-off-by: Aska Wu <aska.wu@linaro.org>
Rename net_pkt_get_src_addr() to net_pkt_get_addr() and make it able to
handle source or destination address.
Signed-off-by: Aska Wu <aska.wu@linaro.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>