Commit graph

1260 commits

Author SHA1 Message Date
Jukka Rissanen 1134e8ee60 net: Add CAN protocol family type used in socket CAN support
This commit adds PF_CAN and AF_CAN protocol family identifiers
that are used by BSD socket CAN support code.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Vipin Anand <vipin.anand@intel.com>
2019-02-07 18:08:27 +02:00
Ravi kumar Veeramally 337b6f9a73 net: context: Add packet socket support
This commit adds basic packet socket support to net_context and
allows application to receive or send network packets in raw
format.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Jukka Rissanen 49e6abab26 net: ip: Add helpers for packet socket support
Various defines and helpers for supporting packet sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Jukka Rissanen ba99ef7c3e net: ethernet: Add more IEEE 802.3 protocol types
Add ETH_P_xxx protocol types if they are missing. After this
we can use the protocol types when working with BSD sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 14:43:30 +02:00
Anas Nashif 13f054075d doc: networking: move API reference to new section
Move text from under subsystems and put it under API reference where it
makes sense.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-05 07:04:40 -05:00
Anas Nashif 89256aa44d net: lwm2m: add doxygen group
Add missing doxygen group to get included in documentation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-05 07:04:40 -05:00
Ravi kumar Veeramally 1e47f26d1c net: coap: Remove legacy CoAP implementation
As we are removing net_app and net_pkt based libraries and
applications, CoAP legacy based libraries and apps are moved
to socket based implementations. So removing legacy CoAP.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-04 16:49:59 -05:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).

Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka e4ebe486b8 net/ip: Let's make public the 2 utility unions for ip/proto headers
Though these are currently used by the core only, it will be then used
by net_context as well. This one of the steps to get rid of net_pkt's
appdata/appdatalen attributes.

Also normalizing all ip/proto parameters name to ip_hdr and proto_hdr.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 40ad4b7e3e net/context: Expose new functions to create ipv4/6 packet from context
These will be specifically needed in TCP, as well as being used in
context internally.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka aa6af15946 net/pkt: Add a marker to identify LLDP message
This will be used by Ethernet L2 to set the right PTYPE in its header.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 6ea5a12f4c net/pkt: Use next_hdr field only for IPv6
Also, store the actual next_hdr value and not it's position.
This permits to reduce net_pkt from some bytes.

Such field was unused until now, but it will be soon.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 0d519f7bcf net/context: Create new send sendto functions using new net_pkt API
It's not anymore up to user to provide the pkt. Context will build the
packet according to its metadata and provided buffer and length.

It currently supports only IPv4 and UDP.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 06037c4d3f net/pkt: Add generic get/set data functions
These ones would support linearizing non-contiguous area, however
requiring a bit more complex type as an "accessor".

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka b039625745 net/pkt: Add an API to read/write into the buffer in a simpler way
Adding a cursor into net_pkt. This is used to read/write data in a much
simpler way, for pre-allocated buffers in net_pkt. This avoids API users
to deal with net_buf below directly.

However, to be used - as for the new allocators - it will require deep
net stack core and API changes.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 8eb9ff72f6 net/pkt: Add new allocators
These struct net_pkt allocators will give the possibility to allocate at
once the net_pkt and the buffer associated with, taking care of the
header space and MTU relevantly.

This enables to use the variable length allocator from net_buf. However,
it is not yet the default and is set as experimental.

As it is provided in parallel to existing allocators, it has to keep a
slab per-direction and thus a pointer in net_pkt, as well as appdata,
appdatalen etc... Resulting in "bloating" net_pkt. This will be solved
when, finally, former allocators will be removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 29ae6bd54c net/pkt: Add dummy getter/setters for IPv4/IPv6 attributes
All as static inline functions to let the compiler check the types
etc... And use ARG_UNUSED() always where relevant.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Jukka Rissanen d1162600e9 net: app: Remove net-app API files
The net-app API is removed. Users should use the BSD socket API
for application development.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 12:29:21 +02:00
Michael Scott d1cb39e7ce net: lwm2m: migrate LwM2M library to BSD-sockets API
This commit removes the net_app layer from the LwM2M library and
replaces it with BSD-sockets APIs.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 180a365d2f net: lwm2m: support for LwM2M bootstrap
Now that the security data can be loaded into and used from the
security / server objects, we can add support for LwM2M bootstrap.

This is a mode where initially a connection can be made to a server
which can update several LwM2M (including security and server
data) and then trigger a "bootstrap complete".  Once this happens
the client will start it's connection process over but now with
the new information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 54c10c04e5 net: lwm2m: use security data for connections
In order to support bootstrap mode, we need to store server data
in the security / server objects.  Once the connection to the
bootstrap server is made, it will clear these objects and add
new server connection data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott a433af6e05 net: lwm2m: save remote address during setup
net_app contexts save the remote address and we use this during
observe notifications and pending handling.  If we move to another
network layer such as sockets, then the remote address becomes
harder to reference.  Let's save it as a part of the client
context.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3bfb7debb3 net: lwm2m: move to flat buffers
As part of the migration from net_app APIs to socket APIs, let's
stop referencing the net_pkt fragments throughout the LwM2M library.

Establish a msg_data flat buffer inside lwm2m_message and use that
instead.

NOTE: As a part of this change we remove the COAP_NET_PKT setting.
The COAP library reverts to COAP_SOCK behavior.

This doesn't mean we use sockets in LwM2M (yet), it only means we
use the socket-compatible COAP library which parses flat buffers
instead of net_pkt fragments.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Jukka Rissanen 93e5181fbd net: context: Add locking for concurrent access
If the net_context functions are accessed from preemptive priority,
then we need to protect various internal resources.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-31 11:20:26 +02:00
Aurelien Jarno 4394601524 net: sntp: get rid of the callback function
The original SNTP client library was designed for the net-app API, for
which it makes sense to have a callback function, which is called
asynchronously when an answer is received.

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

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-31 10:14:12 +02:00
Jukka Rissanen cb1047351c net: mqtt: Remove legacy MQTT headers
Leftovers from legacy MQTT removal commit, now all traces of the
old MQTT implementation are gone.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-30 16:32:21 +02:00
Tomasz Bursztyka 12995b95c2 net/ip: Protocol family do not have to follow any other OS's value
It is the macro name that matters, not its value. Here, that will help
to save 1 bit in struct net_pkt later on.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-01-30 16:27:18 +02:00
Michael Scott 0ee0773abd net: lwm2m: remove unused CONFIG_NET_CONTEXT_NET_PKT_POOL config
CONFIG_NET_CONTEXT_NET_PKT_POOL is used by Zephyr's TCP stack as
a way of keeping the original packet data when compression and
other l2 specific actions make the data unusable for retries.

LwM2M uses UDP and this option was never used.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Ravi kumar Veeramally f51cebeea2 net: sntp: Rework SNTP client library to use sockets
As networking libraries and protocols are moving to socket
based implementation, reworked SNTP client library to use sockets.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-01-29 12:25:01 -05:00
Daniel Glöckner 5ef825fdf6 net: pkt: fix race condition in packet reference counting
It has been observed that some network drivers, f.ex. the SAM E70 GMAC,
call net_pkt_unref from inside the interrupt that signals the successful
transmission of a packet. This conflicts with the net_pkt_unref call
made by ethernet_send after the packet has been given to the driver.

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

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

Fixes #12708

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-01-29 09:22:14 +02:00
Robert Lubos 83b8abaf8a net: ip: Introduce mesh_local address flag
This commit introduces a concept of mesh-local IPv6 addresses. Such
addresses should only be used for mesh-local communication, therefore
should not be used to communicate with different subnets (i. e.
destinations outside the mesh).

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-28 21:24:26 -05:00
Johan Hedberg 80dd9be4ca net: buf: Add net_buf_pull_mem() API
This is the same as net_buf_pull(), except that instead of returning
the new buf->data it returns the old buf->data. This was recently
discussed in github issue #12562.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Jukka Rissanen 4043909d69 net: http: Remove HTTP client and server APIs
The old legacy APIs use net-app library and as that is being
removed, then the dependencies need to be removed also.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Paul Sokolovsky 9c91094ff7 net: sockets: select: Get rid of timeval in favor of zsock_timeval
struct timeval is per POSIX defined in sys/time.h, but that also
allowed to pull sys/select.h (and indeed, it does with native_posix),
which then starts to conflict with out select implementation (if
NET_SOCKETS_POSIX_NAMES is defined, and many samples/tests have it).

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

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

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

Fixes: #11333

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Loic Poulain 192733c096 net: wifi: Add Access Point mode interface
Add access point mode disable/enable to wifi mgmt/offload.

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Robert Lubos 635191ac8c net: ieee802154: Fix ack check
15.4 MHR is no longer set in net_buf pointed by net_pkt, but in a
separate net_buf, hence we need to check that net_buf now to
determine if we need to wait for ACK or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-17 11:16:26 +02:00
Vincent Wan 3fd89baca4 net: Fix inet_pton when offloading is enabled
When offloading is enabled, a call to inet_pton() results in a call to
zsock_inet_pton() based on its implementation in include/net/socket.h.
This eventually leads to a call to _impl_zsock_inet_pton(), which is
not defined when offloading is enabled.

In this commit, we have chosen to directly call net_addr_pton() in
inet_pton() in the offload case to be efficient, and keep the
implementation as it is when offload is not enabled.

Fixes #12441

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-01-15 10:39:52 +02:00
Jukka Rissanen a7afdc3512 net: rpl: Remove the deprecated code
The RPL was deprecated earlier so remove it by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-13 09:40:36 -05:00
Martin Schwan c5de716af4 net: mqtt: Fix typo "seg_tag_list"
Fix a typo in the mqtt_sec_config struct where it was "seg_tag_list"
instead of "sec_tag_list".

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
2019-01-10 11:30:33 +02:00
Paul Sokolovsky 3329eb2c4e net: pkt: net_frag_linearize: Make consistent with net_buf_linearize
net_frag_linearize() is just a wrapper for net_buf_linearize(). As
the latter was refactored to never return error, and instead just
return actual copied length, update the former and its usages too.

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

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

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

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

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
David B. Kinder c8ba6fe41d doc: add missing networking APIs
As mentioned in issue #12265, some networking APIs
aren't included in the generated
API docs because doxygengroup directives were missing.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-01-03 12:38:28 -05:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Martin Turon 6410a16adb openthread: Update openthread version to latest upstream/master.
Update zephyr integration of openthread to latest api as of 2018-12-17:

2a75d30684

Both echo_server and echo_client compile and are operational.

Signed-off-by: Martin Turon <mturon@google.com>
2018-12-20 12:24:51 +01:00
Tomasz Bursztyka 46c37c7692 net/pkt: Finally removing net_pkt_ll() and the relevant attribute
Removing net_pkt_set_ll() as well of course.

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

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

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 88da73b225 net/pkt: Introducing a new helper to get the start of the buffer
This is mostly meant to be used in drivers and/or L2.

net_pkt_ll() is going to be removed and is not semantically right.
Also, net_pkt_ip_data() is not semantically right as it is meant to
access IP data start.

So instead, adding a new function: net_pkt_data() which will get the
start of the buffer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka b105fc58f2 net/pkt: Rename net_pkt_ll_clear for better relevancy
Now it does not mangle with any ll reserver space, let's rename it to
net_pkt_lladdr_clear instead.

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

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 15f13880d6 net/pkt: Remove ll_reserve attribute and related functions
It's useless now.

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

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 01117e0d54 net/if: Remove function to get ll reserve
As it is unused now, it can be safely removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Tomasz Bursztyka 152924057d net/pkt: Add a pointer to link-layer data in the structure
This is one of the first steps to get rid of ll_reserve attribute and
the related L2 reserve() function.

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

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

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Anas Nashif 8ae5f16471 doc: put websocket library under networking
Group websocket APIs under networking.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-10 20:38:09 -05:00
Robert Lubos 31ab8d061d net: sockets: tls: Implement vtable for TLS sockets
Implement extended socket vtable for TLS sockets, therefore allowing to
integrate the implementation with socket subsystem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Jukka Rissanen ff0483c5af net: gptp: Get the gPTP header properly
If the link layer header is in the separate net_buf,
then skip that one.

Fixes #11827

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 16:18:24 +02:00
Jukka Rissanen a26a6ae6a7 net: core: Change NET_ASSERT*() to use zephyr standard assert
Avoid dependency to logging subsystem in NET_ASSERT*(), so
use standard Zephyr asserts instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jukka Rissanen 301d342571 net: Move net_analyze_stack() function to net_core.c
No need to this function be inlined so move it to .c file.

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

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

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Andrei Laperie 35a95a9b2f net: gptp: Replace calls to power function with pre-computed values
gPTP subsystem was calling pow(x,y) function with X and Y being
constants; these are replaced with the pre-computed values.

Signed-off-by: Andrei Laperie <andrei.laperie@intel.com>
2018-12-04 15:05:36 +02:00
Tomasz Bursztyka f964f3f8dc net/pkt: Add a gptp marker to know whether pkt is a gptp message or not
Like ARP, GPTP works on top of Ethernet but is considered as a layer 2
protocol, so we cannot set an AF_* family type. Instead let's have a bit
telling that current packet is a gptp message (family has to be
AF_UNSPEC).

The bit is unionized with a TCP related bit: TCP cannot be present on an
AF_UNSPEC packet so there will not be any collision.

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

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

Applying changes to Openthread L2 as well.

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

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

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

It will be:

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

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

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

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

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

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

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

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

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-30 11:12:13 -08:00
Ravi kumar Veeramally 19c598f081 net: coap: Deprecate net_pkt based CoAP library
Deprecating net_pkt based CoAP library due to Socket based
CoAP library.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-11-22 09:08:46 -05:00
Robert Lubos aa393809a4 doc: sockets: Make TLS option descriptions doxygen
Secure socket options descriptions were not doxygen comments,
therefore did not show up in the documentation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-21 12:25:57 -05:00
Robert Lubos d2a397bcf8 net: mqtt: Add TLS socket transport
Add TLS transport to socket MQTT implementation.

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

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

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

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-19 09:31:01 -05:00
Alexander Polleti fb4cb3a878 c++: convert implicit conversion to explicit ones in header files
c++ does not allow implicit conversions and setting -fpermissive just
causes a huge load of warnings to appear and hides real errors.

This commit converts those implicit conversions to c-style explicit
conversions.

Signed-off-by: Alexander Polleti <metapsycholo@gmail.com>
2018-11-16 15:18:36 -05:00
Tomasz Bursztyka 2a0669e501 net/ieee802154: Remove unnecessary __packed keyword on API struct
It is useless first, and for some reason now generate a bug on kw41z.

Fixes #11301

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-15 09:14:56 -05:00
Jukka Rissanen aa5f219bd1 net: if: Allow calling IPv4 specific functions
Make sure that IPv4 specific functions are callable even if
IPv4 is not enabled. This allows use of IS_ENABLED() macro
in other parts of the system.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-08 15:23:05 +02:00
Tomasz Bursztyka 3200914ed9 net/ethernet: Remove as many ifdef for CONFIG_NET_VLAN as possible
Most of vlan functions have dummy aliases when it's not enabled, so
let's use this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-11-06 12:42:06 +02:00
Paul Sokolovsky de659240e6 net: if: net_if_set_link_addr: Mention lifetime for address buffer
This function just stores the buffer pointer passed, so explicitly
mention that the buffer must remain valid while netif itself is
valid. For example, it can't be stored on stack.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-06 10:25:25 +02:00
Paul Sokolovsky c2702ba76e include: socket: Define ZSOCK_POLLHUP, ZSOCK_POLLNVAL
So that client apps can refer to them, and then can be implemented on
Zephyr side as needed.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
David B. Kinder 402ea4969f doc: fix misspellings in doxygen comments
Scan and fix misspellings in header files in /include missed during
regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-11-02 17:58:29 -04:00
Jukka Rissanen cf063fe85b net: Rename net_is_xxx...() functions to net_xxx_is...()
Unify the function naming for various network checking functions.

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

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

Fixes #10961

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

Fixes #10960

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

Fixes #10959

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-11-02 15:10:48 +02:00
Ravi kumar Veeramally c8954d3544 net: coap: CoAP library support over sockets
CoAP library is migrated to support over socket based
applications or other higher layer protocols. Most of the
API's and functionality is kept as it is except few changes.

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

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

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-10-31 19:44:25 -04:00
Jukka Rissanen 7d83543379 net: Properly handle pkt IPv4 broadcast destination address
If we receive an IPv4 that has broadcast destination address, then
properly handle it.
This means that for
  * ICMPv4, if CONFIG_NET_ICMPV4_ACCEPT_BROADCAST is set (this is the
    default value) and we receive echo-request then accept the packet.
    Drop other ICMPv4 packets.
  * TCP, drop the packet
  * UDP, accept the packet if the destination address is the broadcast
    address 255.255.255.255 or the subnet broadcast address.
    Drop the packet if the packets broadcast address is not in our
    configured subnet.

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

Fixes #10780

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

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

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

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

Fixes #10853

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-26 14:08:43 +03:00
Jukka Rissanen 6973c6a026 net: logging: Remove function name from NET_DBG if needed
The logger will add the function name automatically if
CONFIG_LOG_FUNCTION_NAME is set, so no need to do it here in that case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-19 13:54:50 +03:00
Gil Pitney 5a42292a9e net: socket.h: Add more BSD defines for getaddrinfo()
Add EAI_MEMORY and EAI_SERVICE definitions.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-10-12 13:06:53 +03:00
Jukka Rissanen fd25c8b59b net: wifi: Allow mgmt interface to compile if not offloaded
Even if we do not have wifi network offloading enabled, allow the
application to be compiled just fine. This allows easier
testing of the application even if the board does not support
wifi offloading.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-11 16:28:55 +03:00
Jukka Rissanen 3ab1f90822 net: lib: Convert net_app to use log level
Use network log level in net_app library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen a76814bfb6 net: Convert core IP stack to use log levels
Instead of one global log level option and one on/off boolean
config option / module, this commit creates one log level option
for each module. This simplifies the logging as it is now possible
to enable different level of debugging output for each network
module individually.

The commit also converts the code to use the new logger
instead of the old sys_log.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Joakim Andre Tønnesen d6e0fdca8c net: sockets: Add getaddrinfo and freeaddrinfo to socket offloading
Adds getaddrinfo and freeaddrinfo to the offloaded API.

Signed-off-by: Joakim Andre Tønnesen <joakim.tonnesen@nordicsemi.no>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-10-02 11:11:15 +03:00
Tomasz Gorochowik 0888da4dfe net: gptp: Add clock accuracy selection
This commits adds a possibility to select PTP clock accuracy through
KConfig.

The chosen accuracy should reflect the capabilities of the used
hardware.

See IEEE 1588-2008, chapter 7.6.2.5 for more details.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 68127a3100 net: gptp: Initial GrandMaster capability support
Implements GMCAP-1, GMCAP-2, and GMCAP-3 and their dependencies from
802.1AS-2011. See Annex A.10 for more details.

The Grand Master Capability can be turned on and off through KConfig.

Note: the correction field in FUP packets is not yet properly
calculated. There is a TODO left in the code, near which some parameters
are zeroed to make the correction field be set to 0. This mimics the
behavior of openAvnu (a Linux gPTP client). For full compliance the
field should be calculated and set properly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Tomasz Gorochowik 792dfd4a04 net: gptp: Convert SyncReceiptTime to ExtendedTimestamp
SyncReceiptTime should use an ExtendedTimestamp (with fractional
nanoseconds precision). Add a struct with the definition of the needed
type and convert that variable.

The struct representing the ExtendedTimestamp is named
net_ptp_extended_time to keep consistency with the existing net_ptp_time
which is used for regular PTP timestamps.

See 802.1AS-2011 chapters 10.2.3.4 and 6.3.3.5 for more reference.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-10-01 14:48:53 +03:00
Flavio Ceolin 6fdc56d286 kernel: Using boolean types for boolean constants
Make boolean expressions use boolean types.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-28 06:28:41 +05:30
Robert Lubos 8592501828 net: Remove s_addr/s6_addr defines from in_addr/in6_addr
Replace #defines for s_addr/s6_addr etc. in in_addr/in6_addr structures
within net_ip.h with fixed fileds inside an anonymous union. This
prevents intrusive behaviour of net_ip.h, which expands every occurence
of s_addr/s6_addr with it's own define, even in other, non-related
structures.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-27 21:46:04 +03:00
Robert Lubos 2cd1e4183b net: sockets: Add missing POLLERR definition
ZSOCK_POLLERR was missing it's posix name, so this commit adds one.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-09-26 18:11:45 +03:00
Flavio Ceolin 67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Gil Pitney c21b0fb357 net: sockets: Add a socket offload module
This patch enables BSD socket offload to a dedicated
TCP/IP offload engine.

This provides a simpler, more direct mechanism than going
through NET_OFFLOAD (zsock -> net_context -> socket conversions)
for those devices which provide complete TCP/IP offload at the
BSD socket level, and whose use cases do not require
IP routing between multiple network interfaces.

To use, configure CONFIG_NET_SOCKETS_OFFLOAD=y, and register
socket_offload_ops with this module.

Fixes #3706

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-09-11 18:42:34 +03:00
Tomasz Bursztyka b6468999e4 net/pkt: Rename link layer address accessors relevantly
*_ll_src/*_ll_dst/*_ll_swap/*_ll_if were not self explanatory, ll
meaning "link layer" it's ambiguous what the names meant.
Changing to:
*_lladdr_src/*_lladdr_dst/*_lladdr_swap/*_lladdr_if to fix this.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-09-11 16:06:13 +03:00
Johan Hedberg b088a09235 net: buf: Use size_t instead of u16_t for lengths in public API
Even though the net_buf implementation may (and does currently)
internally use u16_t for lengths, keep the public facing API
consistent by using size_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Johan Hedberg c90549c474 net: buf: Use void * instead of u8_t * for arbitrary data
This makes the net_buf_append_bytes() API consistent with all other
net_buf APIs that take a pointer to arbitrary data.

Fixes #9283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Andrei Emeltchenko e1757277ae net: lldp: Implement LLDP RX API
Add RX API to LLDP. Caller should register callback which is called
from ethernet_recv().

Fixes #9407

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-11 10:55:01 +03:00
Jukka Rissanen 3f4d468059 net: if: Add utility function to return IPv6 prefix info
The net_if_ipv6_prefix_get() function will return the proper prefix
for a given IPv6 address and network interface. This is used when
checking which source address should be returned to the caller.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen 09390e5b3f net: if: Support long lifetime IPv6 prefixes
Enable IPv6 prefix to have long lifetime (> 25 days)

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Jukka Rissanen c4cc8a5f3e net: if: Refactor IPv6 address lifetime timer
Refactor IPv6 address lifetime timer setting in net_if_addr to support
longer lifetime than 24 days.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-09-11 10:53:30 +03:00
Paul Sokolovsky 5f8d24baca net: Add INET_ADDRSTRLEN POSIX define
POSIX defines INET_ADDRSTRLEN and INET6_ADDRSTRLEN as max sizes of
textual form of IP addresses (including terminating NUL):
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html

We already define INET6_ADDRSTRLEN, so it makes sense to define
INET_ADDRSTRLEN too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-11 10:44:30 +03:00
Paul Sokolovsky 8a5b0b77f5 net: net_addr_ntop: Clarify docstring
The string returned is definitely NUL terminated, previously was
apaprently a typo.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-06 11:35:04 -04:00
Alexander Polleti f7d32d483f net: fix return type of net_addr_type2str
As we return stuff that is probably in the flash the return type should
be const char * and not char * as the user better doesn't try to change
them!

Signed-off-by: Alexander Polleti <metapsycholo@gmail.com>
2018-09-05 18:39:53 -04:00
David B. Kinder 7b548c42ee doc: fix misspellings in API documentation
Fix misspellings in doxygen API comments missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-28 13:58:22 -04:00
Michael Scott 3b80998ff2 net: lwm2m: correct Copyright to Foundries.io
Due to a change in the company name, the LwM2M copyrights need
to be changed from "Open Source Foundries Limited" ->
"Foundries.io".

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-27 19:29:16 -04:00
Jukka Rissanen 57a41a2330 net: if: Remove IPv6 auto addresses if the prefix is removed
The autoconfigured IPv6 addresses that are related to removed
prefix, need also removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 17:02:21 +03:00
Robert Lubos d529aef9f2 net: tls: Apply DTLS review fixes
This commit contains several fixes for DTLS implementation, proposed in
a post-merge review of #9338.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-17 15:10:00 +03:00
Jukka Rissanen eeabc2ba3d net: if: Lower ram usage for IP address lifetime handling
Instead of having one delayed_work struct / IP address, use
only one delayed_work struct for lifetime timer. This saves
over 20 bytes / allocated address struct.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-17 13:36:59 +03:00
Daniel Egger 5d3bc8b3d8 net: pkt: Added new function net_pkt_append_memset() to prefill packet
Some locations like DHCPv4 client create a prefilled packet by appending
new fragments in a loop with one byte each via net_pkt_append_u8() which
is wasteful and noisy. This patch adds the new functions
net_pkt_append_memset() which creates fragments as needed in the desired
size and initialises it to the specified value.

This change also adds a unittest for the new function.

Prerequisite for #9287

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2018-08-16 10:35:01 +03:00
Jukka Rissanen 7e3eaaa027 net: Use packed enums when applicable
Make several enums, that are used inside structs, to be packed so
that they use only needed amount of memory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 07:16:54 -07:00
Jukka Rissanen 7c7cfdda50 net: core: Always have a timeout when allocating a net_buf
Instead of waiting forever for a network buffer, have a timeout
when allocating net_buf. This way we cannot left hanging for a
long time waiting for a buffer and possibly deadlock the system.
This commit only adds checks to core IP stack in subsys/net/ip

Fixes #7571

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 12:17:00 +03:00
Jukka Rissanen 4b9d980980 net: if: Lower memory usage for IPv6 address, prefix and router info
Use bitfields for boolean values instead of full bytes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-14 09:06:01 +03:00
Andrew Boie 18cec245ba net: introduce system calls for zsock socket APIs
Add system calls for the zsock implementations of socket,
close, bind, connect, listen, accept, sendto, recvfrom,
fcntl, poll, inet_pton, and getaddrinfo.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-13 07:19:39 -07:00
Robert Lubos ae41ec1f35 net: tls: Make TLS poll implementation check mbedTLS data
Make TLS poll function verify if decrypted data is available after
socket has notified activity with POLLIN flag. This prevents from giving
false notifications in case data was received on socket but was consumed
by mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos b03a388d73 net: tls: Add socket option to set DTLS role
Add write-only socket option to set role for DTLS connection. This
option is irrelevant for TLS connections.

This options accepts and integer with a TLS role, compatible with
mbedTLS values:
0 - client,
1 - server.

By default, DTLS will assume client role.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Robert Lubos 85db974ec3 net: tls: Add DTLS protocol types
Define DTLS protocol types and and Kconfig option to enable DTLS
support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-08-13 15:24:34 +03:00
Oleg Zhurakivskyy ac92a01f5a net: ipv6: Refactor IPv6 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-13 13:53:14 +03:00
Jukka Rissanen 31f89b0303 net: eth: Add start and stop L2 functions
If the driver has created start() and stop() functions, then those
are called when ethernet L2 is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-10 12:36:19 +03:00
Oleg Zhurakivskyy fbac80bb94 net: ipv4: Refactor IPv4 header length handling
Change the length to uint16_t and work with it
through standard htons/ntohs() macros.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2018-08-09 16:25:17 +03:00
Jukka Rissanen d003d0e6a6 net: ipv4: Corrupted ARP pkt was sent instead of real IPv4 pkt
The ethernet sending routine sent a corrupted ARP packet instead
of the actual IPv4 packet.

Fixes #9348

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-09 11:56:44 +03:00
Jukka Rissanen f39ff76ced net: if: Do not inline net_if_ipv6_addr_lookup_by_iface()
No need to inline the net_if_ipv6_addr_lookup_by_iface() function
as it is used multiple times in ipv6.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen d0205693ae net: if: Add net_if_select_src_iface() function
Add a function which returns proper network interface to send either
IPv4 or IPv6 network packet to corresponding destination address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen b8fdf3c67a net: if: Add net_if_ipv6_select_src_iface() function
Add a function that will return the network interface that would
be used when sending a IPv6 network packet to specific IPv6 destination
address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 14:54:27 +03:00
Jukka Rissanen 1f855095b4 net: l2: Add promiscuous mode to L2 flags when applicable
This allows more bearers than just ethernet to have promiscuous
mode support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen 66244a0e67 net: if: No need to always join solicit node mcast group
For example for Bluetooth IPSP, it is not needed to join solicited
node multicast group address.

From https://tools.ietf.org/html/rfc7668#section-3.2.2 :

"""
There is no need for 6LN to join the solicited-node multicast address,
since 6LBR will know device addresses and hence link-local addresses
of all connected 6LNs.
"""

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jukka Rissanen ccfcdabaf6 net: l2: Add flags to tell if L2 supports multicast
If multicast is not supported, then we do not need to join
multicast group.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 11:02:30 +03:00
Jesus Sanchez-Palencia 598276262c net: l2: Add support for Link Layer Discovery Protocol (LLDP)
The LLDP protocol defines 2 separate agents, the Transmitters and
the Receivers. For the context of Zephyr, we are only interested in
the Tx agent, thus we drop any LLDP frames received by Zephyr.

LLDP frames are basically composed by an ethernet header followed by
the LLDP Protocol Data Unit (LLDPDU). The LLDPDU is composed by several
TLVs, some of them being mandatory and some optional.

Our approach here is having TLVs fully configured from Kconfig, thus
having the entire LLDPDU constructed on build time.

The commit adds NET_ETH_PTYPE_LLDP definition and related handling.

If CONFIG_NET_LLDP is enabled then ethernet_context has a pointer to
the struct net_lldpdu that belongs to that ethernet interface. Also
when CONFIG_NET_LLDP is enabled, the LLDP state machine will start to
send packets when network interface is coming up.

Currently the LLDP state machine is just a k_delayed_work() sending the
LLDPDU at a given period (defined by CONFIG_NET_LLDP_TX_INTERVAL).

Fixes #3233

Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-08 09:53:24 +03:00
Michael Scott db577f00b1 net: buf: add linearize, append_bytes and skip APIs to net_buf
This change moves the logic for linearize and append_bytes from
the net_pkt sources into the net_buf sources where it can be
made available to layers which to not depend on net_pkt.  It also,
adds a new net_buf_skip() function which can be used to iterated
through a list of net_buf (freeing the buffers as it goes).

For the append_bytes function to be generic in nature, a net_buf
allocator callback was created.  Callers of append_bytes pass in
the callback which determines where the resulting net_buf is
allocated from.

Also, the dst buffer in linearize is now cleared prior to copy
(this was an addition from the code moved from net_pkt).

In order to preserve existing callers, the original functions are
left in the net_pkt layer, but now merely act as wrappers.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-06 10:43:46 +03:00
Tomasz Gorochowik b6852e5a3a net: eth: mgmt: Add remaining 802.1Qav parameter types
This are all the parameters defined by the standard (12.21.1).

Additionally the parameters that are read-only are validated in the
ethernet_set_config callback.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:37:09 +03:00
Tomasz Gorochowik aed075ef50 net: ip: Fix net priorities definitions
Best Effort is the default priority with the assigned value of 0, but
Background is the lowest priority with the assigned value of 1.

Ref: IEEE 802.1Q, Chapter I.4, Table I-2.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-06 10:23:57 +03:00
Jonathan Yong dd88711a69 net: eth: Vendor specific statistics
Allows ethernet drivers to provide vendor specific statistics
and details in the form of key-value pairs with the name of
the staticstic and its value.

The new string tables will be behind a new config:
	NET_STATISTICS_ETHERNET_VENDOR

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-08-02 12:42:27 +03:00
Tomasz Gorochowik 805e2f2c79 net: eth: mgmt: Merge 802.1Qav related mgmt requests
There are too many individual requests for Qav related parameters. There
are more Qav parameters that need to be supported (and will be supported
soon - both on the GET and SET side). Handling it the way it was handled
so far would render the eth mgmt API dominated by Qav parameters. That
would make the file hard to read and understand.

Instead of that - use a single GET and SET requests for all Qav
parameters. This works by adding a separate enum with Qav request type
to the ethernet_qav_param struct.

Additionally this approach makes it much easier to document it all since
we now have just a single request and documentation comments in the
ethernet_qav_param struct.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-08-01 15:58:05 +03:00
Tomasz Gorochowik f568be48d0 net: eth: mgmt: Add Qav status hooks
Add calls responsible for getting and setting on/off status of Qav on
capable priority queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-31 17:54:24 +03:00
Jukka Rissanen 00e37cbb5b net: IPv4 link local support
Add basic IPv4 Link Local support as described in RFC 3927.

Signed-off-by: Matthias Boesl <matthias.boesl@gmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-31 16:34:28 +03:00
Tomasz Bursztyka 2c1863ff4c net/ethernet: Add a way to configure MAC address filters into devices
Some Ethernet devices can filter out incoming packets through a list of
valid MAC addresses, so let's add a way to expose this capability, using
it through the ethernet device API.

Fixes #7596

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-30 08:28:38 -04:00
Tomasz Gorochowik 3cd1425b58 net: eth: mgmt: Extend the management interface with a getter
This makes use of the get_config callback added to the Ethernet API.

For now the only parameter to get is the number of available priority
queues.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-27 20:27:59 +03:00
Tomasz Gorochowik a10a1c2601 net: eth: Add API callback to get hw configuration
This callback will be used to get HW specific configuration that cannot
be accessed through L2 directly.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-27 20:27:59 +03:00
Tomasz Gorochowik e487fc7887 net: eth: mgmt: Minor formatting fix
Line too long. Make it match other defines.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-27 20:27:59 +03:00
Tomasz Bursztyka 2ba28dd78c net/dhcpv4: Unify timeout management in a unique k_delayed_work
This reduces memory overhead on net_if_dhcpv4: 16 bytes vs 120 bytes
before. This might proove to be beneficial when there are many network
interface.

dhcpv4 ROM consumption is now 2132 bytes vs 4224 (many switches removed)

Fixes #8727

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-27 13:00:01 +03:00
Robert Lubos 7826228def net: tls: Add socket option to set peer verification level
Add write only TLS secure option to set peer verification level for
TLS connection.

This option accepts an integer with a peer verification
level, compatible with mbedtls values (0 - none, 1 - optional, 2 -
required.

By default, socket mimics mebdTLS behavior - (none for server, required
for client).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 3d560e14ac net: tls: Add socket option to read chosen ciphersuite
Add TLS secure socket option to read a ciphersuite chosen during TLS
handshake. Might be useful during development.

This is a read-only option that returns an integer containing an
IANA assigned ciphersuite identifier of chosen ciphersuite.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11c24c855d net: tls: Add socket option to select ciphersuites
Add TLS secure socket option that enables to narrow list of ciphersuites
available for TLS connection.

This option accepts an array of integers with IANA assigned ciphersuite
identifiers and returns such.

By default, every statically configured ciphersuite is available for a
socket and getsockopt returns an array of these.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 915317724c net: tls: Add socket option to set TLS hostname
Add write-only TLS secure socket option to set hostname.

This option accepts a string containing the hostname. May be NULL, to
disable hostname verification.

By default, an empty string is set as a hostname for TLS clients,
to enforce hostname verification in mbedTLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 48e055577b net: tls: Add socket option to select TLS credentials
Add TLS secure socket option to select TLS credentials to use.

This option accepts and returns an array of sec_tag_t that indicate
which TLS credentials should be used with specific socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos f959b5c164 net: tls: Add TLS socket options placeholder
Add TLS secure sockets wrapper for getsockopt/setsockopt functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos 11f7abcefd net: socket: Define getsockopt() and setsockopt()
Define socket option functions and make them return ENOPROTOOPT.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Robert Lubos d09cbcaf6f net: tls: Add credential management subsystem
Add TLS credential management subsystem that enables to register TLS
credentials in the system. Once specific credentials are registered in
the system, they will be available for TLS secure sockets to use.

To use a TLS credential with a socket, the following steps have to be
taken:
1. TLS credential has to be registered in a system-wide pool, using the
API provided in "net/tls_credentials.h" header file.
2. TLS credential (and other TLS parameters) should be set on a socket
using setsockopt().

Note, that there is no need to repeat step 1 for different sockets using
the same credentials. Once TLS credential is registered in the system,
it can be used with mulitple sockets, as long as it's not deleted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-26 12:13:15 -04:00
Tomasz Bursztyka 5ebc86bdc6 net/ethernet: A device driver api uses struct device *dev
Always use struct device *dev as first parameter for a device driver
API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-26 13:55:38 +03:00
Jukka Rissanen 9b8c83f44a net: Avoid holes in structs
Move struct members around in networking code so that we avoid
unnecessary holes inside structs. No functionality changes by
this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-25 15:20:34 +03:00
David B. Kinder 5c086deccd doc: fix doxygen error in ethernet.h
Doxygen comments for net_eth_promisc_mode parameters were incorrect

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-07-24 16:24:10 -04:00
Jukka Rissanen 3f9c7bd159 net: Add promiscuous mode support
Allow user to set the network interface into promiscuous mode
and then receive all the network packets that are received by
that interface.

Fixes #7595

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen bf9bae58d1 net: eth: Add generic promiscuous mode support
Allow ethernet L2 driver to set / unset the device driver
promiscuous mode flag.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Jukka Rissanen b19cb207cb net: if: Add promiscuous mode set / unset functionality
User is able to set the network interface to promiscuous mode
and query the promisc mode status.

Note that currently this is only supported for ethernet bearer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-24 15:12:37 +03:00
Andrew Boie 8e8dc1c528 net: relax net_ip.h check
This allows network stack headers to be included even if
no L3 networking support is enabled in Kconfig.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-24 11:43:46 +03:00
Ravi kumar Veeramally 3fafe4f9ad net: ipv6: Handle large IPv6 packets properly
Current implementation does not handle large extension headers
(e.g HBHO). Which resulted network stack crashes or due to
misinterpretation of lengths network packets are dropped. Also
caused issues while preparing IPv6 packet (e.g. large HBHO header
with IPv6 fragmentation support).

Issues fixed and provided more unit tests.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-07-23 15:01:09 +03:00
Andrew Boie a74137f665 net: getaddrinfo: use memory allocation for res
We no longer use a global array for what is supposed to be
a memory allocation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 08:56:21 -07:00
Jonathan Yong 40f743669b net: eth: Convert to use callbacks to query stats
The advantage to this approach allows drivers for
devices that already keep statistics data on hardware
registers to use those instead, rather than try to
replicate it the same counters again within the driver
itself.

The eth_native_posix.c driver though do not benefit
from this, is modified to use the new callback system.

Suggested-by: Jukka Rissanen <jukka.rissanen@intel.com>
Signed-off-by: Jonathan Yong <jonathan.yong@intel.com>
2018-07-19 13:46:13 +03:00
Gil Pitney 42f51ef08d drivers: wifi: winc1500: Use offload_context instead of user_data.
The wifi_winc1500 driver's socket id is stored in
net_context->user_data, which may be overwritten later at
the socket layer, which also uses the net_context->user_data
field to store socket flags.

This patch introduces a dedicated offload_context field
for use by offload drivers, and updates the wifi_winc1500 offload
driver to use this field instead of user_data.

Fixes #8820

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-07-18 07:47:45 -04:00
Michael Scott 538d3418fd net: lwm2m: introduce user-code callbacks for obj create/delete
LwM2M engine now supports optional resources that may need to be
setup or torn down in user-based code during object instance
creation / deletion.

Let's provide callbacks that can be used for this purpose.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Michael Scott 56e240e528 net: lwm2m: make lwm2m_engine_exec_cb_t more generic
Let's rename lwm2m_engine_exec_cb_t to lwm2m_engine_user_cb_t so that
future user-code callbacks can make use of the same definition.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-07-17 13:03:18 +03:00
Robert Lubos a7c698d936 net: tls: Add TLS context allocation/deallocation
Add tls_context structure that stored data required by TLS socket
implementation. This structure is allocated from global pool during
socket creation and freed during socket closure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Robert Lubos 00a69bf9bb net: socket: Add switch to enable TLS socket option support
Add switch to a socket layer that will enable switching socket API to
TLS secure sockets. At this point there is no secure sockets
implementation, so secure socket calls redirect to regular socket calls.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-07-13 15:03:45 -04:00
Tomasz Gorochowik 226fa97304 net: ethernet: Add 802.1Qav settings to eth mgmt api
This commit adds a possibility to use Qav (credit-based shaping) in the
ethernet drivers.

There are two parameters exposed through the mgmt api: deltaBandwidth
and idleSlope.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:27:34 -04:00
Tomasz Gorochowik 2ca3b1e3c4 net: if: Fix TX timestamp callbacks invocation
The problem is that net_if_call_timestamp_cb only checked if the
callback was registered for the PORT which invoked the whole action.

There is a possibility, that the callback will be registered, and packet
A will be passed to eth driver. Before the driver is finished with
packet A, network layer will start handling another packet (B) - so it
will unregister the callback for packet A and register it for B. After
that the network driver will finish processing packet A and invoke the
timestamp callback. The mechanism would then only check if a callback is
registered for the port of the driver and invoke the callback for the
packet that was registered earlier (so A instead of B).

This commit fixes that by storing info not only about the port but about
the packet too.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-07-04 16:26:35 -04:00
Jukka Rissanen 65b15c3226 net: eth: Add helper to return VLAN info for an interface
A small helper function will return information whether
a given network interface has VLAN enabled or not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen 3fd2d53e56 net: mgmt: Add VLAN enabled / disabled event support
Send network management event if VLAN tag is enabled or disabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-03 20:26:31 +03:00
Jukka Rissanen cf272e6667 net: gptp: Use the ptp clock instead of zephyr uptime
As the PTP clock should return the correct time, use that
instead of zephyr uptime for time as that has only ms accuracy.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-02 16:52:49 +03:00
Paul Sokolovsky c89a06dbc1 net: config: Introduce a dedicated header for the library
Split out definition of net_app_init() and its parameter flags from
net_app.h header to new net_config.h header. As we do this, rename
the function to net_config_init() and flags to NET_CONFIG_NEED_*.
This is a second step in splitting out network configuration API
out of net_app API, started in the c60df1311 commit.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-07-02 12:36:35 +03:00
Tomasz Bursztyka d309c870c7 net/ipv6: Properly separate what belongs to ipv6 from the rest
Context part should be in context. Then, rename ipv6 function for
clarity.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-02 12:34:12 +03:00
Tomasz Bursztyka 68f7e96916 net/ipv4: Properly separate what belongs to ipv4 from the rest
Context part should be in context. Then, rename ipv4 function for
clarity.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-07-02 12:34:12 +03:00
Anas Nashif a8d4b32412 net: fix header guard
Add missing _ to match guard name.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:23 +02:00
Jukka Rissanen 837ed14a0d net: llmnr: Add link-local mcast name resolution client support
This implements LLMNR client from RFC 4795. This means that caller
is able to resolve DNS resource records using multicast DNS.
The LLMNR is used in Windows networks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-29 13:11:18 +03:00
Tomasz Bursztyka 89eeba4250 net/arp: No need to expose publicly arp header
ARP is something internal to ethernet L2, let's just hide its header
file.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-29 12:57:45 +03:00
Jukka Rissanen 45b06a252f net: gptp: Initial core IEEE 802.1AS support
Core IEEE 802.1AS-2011 (gPTP) support and application interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-28 16:50:50 +03:00
Johan Hedberg 982385277b net: buf: Make net_buf_user_data() parameter const
This API doesn't modify the input buffer in anyway, so declare it as
const.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-28 10:49:52 +03:00
Tomasz Bursztyka 099fe7b98f net/ethernet: Let's use the same parameter names everywhere
s/eth_dev/dev

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-27 16:37:13 +03:00
Jukka Rissanen ed25a16a3b driver: ptp_clock: PTP clock driver definition
Defines a PTP clock driver that can be implemented in those network
interface drivers that provide gPTP support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-26 12:37:28 +03:00
Tomasz Gorochowik 23526e4f93 net: if: vlan: Implement packet priority to PCP conversion
This is actually the same as #7229 in which we missed this side of
conversion (only PCP to packet priority was implemented).

The conversion is actually the same both ways, thus it uses the map
added earlier.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-06-26 09:56:57 +03:00
Jukka Rissanen 580596c30a net: if: Add TX timestamp callback support
Allow creation of TX timestamp thread which will collect TX timestamp
information from device drivers. If the callback is registered, then
it will pass that timestamp information to the relevant party for
further processing. This support will be used by gPTP code in
subsequent commits.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Julien Chevrier <julien.chevrier@intel.com>
2018-06-22 12:31:32 -04:00
Paul Sokolovsky e62972bb8e net: ethernet: net_eth_fill_header: Remove superfluous "frag" param
Ethernet header is always filled in the first fragment of a packet,
so passing it as a separate function paramter is supefluous.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-13 08:44:51 -04:00
Jukka Rissanen 4ae875f9c1 net: arp: Timeout too long ARP request
There was no proper support to timeout an ARP requests which meant
that trying to resolve non-existent IP address left network packet
pending on ARP cache.

Fixes #8019

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-12 20:26:36 -04:00
Jukka Rissanen b93d29df56 net: ethernet: Add carrier detection to L2
Add net_eth_carrier_on() and net_eth_carrier_off() functions that
can be called by ethernet device driver when it detects that carrier
is lost or found.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Jukka Rissanen 3122112aa8 net: ethernet: Provide stubs for ethernet carrier functions
If CONFIG_NET_L2_ETHERNET_MGMT is not enabled, then provide
stubs for ethernet_mgmt_raise_carrier_on_event() and
ethernet_mgmt_raise_carrier_off_event() functions so that those
functions can be called always.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-06-11 17:27:29 -04:00
Tomasz Bursztyka d4e0a6872e net/pkt: Simplify a tiny bit how TC priority is set
Let's set it by default when allocating net_pkt. A macro will avoid
ifdefs as well

CONFIG_NET_TX_DEFAULT_PRIORITY is always defined.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 17:21:12 -04:00
Tomasz Bursztyka 97699537f3 net/arp: Clear cache per-iface when relevant
When disabling an ethernet interface, only its cache entries need to be
cleared up and not the whole cache. This is meaninful in case there is
2+ ethernet interface instances.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-11 14:35:29 -04:00
Tomasz Bursztyka 9ab9a83596 net/ethernet: Fix ethernet net mgmt interface layer code
Layer code mask is 0x7FF so obviously 0x802 is not valid (as it will
always set the synchronous bit).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-06-04 11:56:19 -04:00
David B. Kinder fcbd8fb631 doc: fix misspellings in API doxygen comments
Found some misspellings missed during normal code reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-05-23 15:28:01 -05:00
Tomasz Bursztyka 69e69b7f93 ieee802154: Add support for energy detection scan on driver API
This will be useful for OpenThread, drivers will need to implement that
fonction to be able to proceed with ED.

Fixes #5714

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-05-17 16:18:53 +03:00
Tomasz Bursztyka 49bd1e9c6f ieee802154: Add support for filtering source short/ieee addresses
L2 could take advantage of such hardware capability, when supported by
the device. This is also required for OpenThread.

Fixes #5714

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-05-17 16:18:53 +03:00
Michael Scott 0d67f6a78d net: lwm2m: introduce FLAG_OPTIONAL to denote optional resources
This patch introduces several changes to support OPTIONAL resources.

The primary indicator for this behavior is to assign FLAG_OPTIONAL
to the object field's permission flags.

These resources are not setup by the LwM2M object code.  They are
left up to the user-based code for initialization via the following
functions:
lwm2m_engine_set_res_data()
lwm2m_engine_get_res_data()

When assigning const-based data as a data buffer, user-based code can
also specify the following data flag: LWM2M_RES_DATA_FLAG_RO

The FLAG_OPTIONAL flag also affects the LwM2M engine in the following
ways:
- CREATE operations won't generate an error if optional resources are
  not included.
- Object instance READ operations won't complain about missing
  optional resources.
- In the future, BOOTSTRAP operations can have different handling
  based on optional resources.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 0db9af5a28 net: lwm2m: return error from lwm2m_engine_get_* functions
In the future, we will have optional resources that may or may
not be assigned a buffer for data storage.  When these resources
are queried we need to be able to return an error code if the
buffer isn't set.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-16 10:56:07 +03:00
Michael Scott 2c987298f2 net: tcp: expose some TCP helper functions
Similar to UDP, some drivers can make use of the following functions:
net_tcp_get_hdr()
net_tcp_set_hdr()

Let's expose them as <net/tcp.h> and change all internal references
to "tcp_internal.h".

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-05-15 18:07:47 +03:00
Leandro Pereira 9681f3d081 net: Update bit size of _unused member in struct net_pkt
This should reduce the struct size by 1 byte.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-09 09:53:34 -04:00
Jukka Rissanen 128557896c net: if: Add functions to get correct IPv4 address
Add functions that will return correct source IPv4 address
according to given destination address. This is done similar
way as for IPv6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-05-03 12:47:52 +03:00
Tomasz Gorochowik 3da4d37003 net: Implement VLAN priority to packet priority conversion
According to IEEE 802.1Q the VLAN priority (PCP) is not directly mapped
to the network packet priority. The Best Effort priority has a PCP value
of 0. The lowest priority (Background) has a PCP value of 1.

All the values are mapped according to the following table:

  +-----+-----+---------+
  | PCP | PRI | Acronym |
  +-----+-----+---------+
  |  1  |  0  |    BK   |
  |  0  |  1  |    BE   |
  |  2  |  2  |    EE   |
  |  3  |  3  |    CA   |
  |  4  |  4  |    VI   |
  |  5  |  5  |    VO   |
  |  6  |  6  |    IC   |
  |  7  |  7  |    NC   |
  +-----+-----+---------+

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2018-05-02 13:40:32 +03:00
Jukka Rissanen 8c561994f2 net: http: Fix client compilation if HTTPS is enabled
The http.h used HTTP server defines when compiling HTTP client.
This causes compilation error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-26 12:35:05 +03:00
Jukka Rissanen da8af39302 net: if: Add helper to select src interface for a IPv4 dst addr
If we have multiple network interfaces and we want to send
a IPv4 network packet to certain destination, then this new
helper can be used to figure out what network interface to use.

Note that this commit only adds support to select the correct network
interface according to destination IPv4 address. This does not enable
any automatic routing to happen.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
Tomasz Bursztyka eab3f168fd net/mgmt/wifi: Add dedicated net mgmt hooks for WiFi offload devices
Exposing connect, disconnect and scan for now.

In case the iface is an instance of a WiFi offload device, the way it
manages scanning, connecting and disconnecting will be specific to that
device (not the mgmt interface obviously). In such case the device will
have to export relevantly a dedicated bunch of function to serve the
mgmt interface in a generic way.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Gil Pitney 17b923ae3c net: wifi: Add a wifi.h to hold WiFi definitions
Placeholder to hold generic WiFi definitions.

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-04-12 09:56:07 -04:00
Patrik Flykt 7bde51d86a net/mgmt: Add initial WiFi management API definitions
Add empty WiFi network management functions that only return -ENETDOWN.
Define management handlers for scan, connect and disconnect requests,
again without any implementation nor parameters defined.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Tomasz Bursztyka 93ac7ce655 net/mgmt: Move NET_EVENT_INFO_MAX_SIZE into net core's private header
First because nobody needs to know that besides net_mgmt core and
secondary to avoid possible circular dependancy on
net_mgmt.h/net_event.h.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Dario Pennisi 6d387ec98f net: Remove the need for an l2 on offloaded drivers
Drivers will be directly contacted via net_if's offload attribute. No
need for a an extra layer as an L2.

Signed-off-by: Dario Pennisi <dario@iptronix.com>
Signed-off-by: Massimiliano Agneni <massimiliano.agneni@iptronix.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-12 09:56:07 -04:00
Jukka Rissanen c1e7fd76ef net: stats: Add infrastructure for collecting ethernet stats
Make sure we are able to collect ethernet statistics and query
it via net management API.

Fixes #6899

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-11 16:49:48 +03:00
Tomasz Bursztyka 8d558fb5ea net/ethernet: Add a management interface
This will permit to tweak ethernet L2 and devices settings at runtime.
Currently, only devices settings are tweaked through this interface.

Fixes #6640

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka f3d8012655 net/ethernet: Add function driver API to change some hw configuration
Depending on what's supported by the device, it could be possible to
configure these at runtime such as auto-negociation, link speed, etc...

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka 4bf1a9bd60 net/ethernet: All types are prefixed with ethernet_
Aligning eth_hw_caps to the right prefix, so ethernet_hw_caps.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka e9d77b60de net/ethernet: No need to expose vlan_setup if vlan is not enabled
Function should be exposed if only vlan is enabled.

Also, changing vlan_setup's signature to stay consistent with device
driver API.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Tomasz Bursztyka e996b37c0a net/ethernet: Add capabilities exposed by device drivers
Curently only link speed is exposed.
Opportunity taken to remove any post-fix enumerating the iface init
and/or the api: these must be generic and used by all the instances.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-10 14:45:37 +03:00
Jukka Rissanen 1443ff0f5e net: stats: Make statistics collection per network interface
Instead of one global statistics, collect statistics information
separately for each network interface. This per interface statistics
collection is optional but turned on by default. It can be turned
off if needed, in which case only global statistics are collected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-10 13:29:39 +03:00
Jukka Rissanen 85d65b20c9 net: stats: Fix the net_mgmt statistics collection
Make sure that we return proper network statistics data if
someone asks it via network management interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-10 13:29:39 +03:00
Jukka Rissanen 444dfa742f net: l2: Remove l2_data section start and end pointers
As the l2_data section might contain different size context elements
like "struct ethernet_context" for Ethernet and "void *" for
Dummy L2, remove the __net_l2_start and __net_l2_end variables so
that user does not accidentally try to use them as that would not work.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-06 06:33:46 -04:00
David B. Kinder 3314c3675f doc: misspellings in public API doxygen comments
occasional spelling-check pass found some misspellings

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-04-05 19:16:24 -04:00
Jukka Rissanen 687c3339b7 net: if: Use DEVICE_NAME_GET() instead of fixed string
The DEVICE_NAME_GET() macro should be used instead of fixed
string when creating a device pointer in net_if_dev structure.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 09:39:20 -04:00
Jukka Rissanen ad5bbefda3 net: Add function to convert VLAN priority to packet priority
Currently the VLAN priority is the same as packet priority but
if such conversion is needed, then this function can be used
for such conversion.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen de13e979fc net: if: vlan: Add virtual lan support
This allows creation of virtual lan (VLAN) networks. VLAN support is
only available for ethernet network technology.

Fixes #3234

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-05 08:54:19 -04:00
Jukka Rissanen adb05df4ca net: if: Bring back __net_if_align
The __net_if_align was removed in earlier commits but it needs
to come back as in some arch the alignment of net_if section
will be wrong.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-28 17:52:31 +03:00
Michael Hope 91ff634d32 ethernet: fix an unaligned access fault by removing __packed.
__packed allows the struct to be linked at a non-word size boundrary
which causes an unaligned access fault on the Cortex-M0+.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-28 09:37:37 +03:00
Jukka Rissanen f947439fa1 net: Align the stack infos in net_stack linker section
There can be lot of traffic class threads and each will have
their own stacks. This can trigger issue when traversing the
stacks list in "net stacks" shell command. To overcome this issue,
we need to align each net_stack_info struct by 32 bytes. This is
the same issue that happened with net_if earlier.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 99e93db6b2 net: stats: Add traffic class statistics
Add statistics for number of packets and bytes to each traffic
class. Print this information in net-shell.

Also make sure that we do not calculate total packet length many
times. So calculate network packet total length once and then use
that value instead of calculating it many times in a row.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 6049207a29 net: Add initial TX and RX traffic class support
With this commit it is possible to add priority to sent or received
network packets. So user is able to send or receive higher priority
packets faster than lower level packets.
The traffic class support is activated by CONFIG_NET_TC_COUNT option.
The TC support uses work queues to separate the traffic. The
priority of the work queue thread specifies the ordering of the
network traffic. Each work queue thread handles traffic to one specific
work queue. Note that you should not enable traffic classes unless
you really need them by your application. Each TC thread needs
stack so this feature requires more memory.

It is possible to disable transmit traffic class support and keep the
receive traffic class support, or vice versa. If both RX and TX traffic
classes are enabled, then both will use the same number of queues
defined by CONFIG_NET_TC_COUNT option.

Fixes #6588

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 159aaf1740 net: core: Add array support to stack info helpers
Allow caller to create array of thread stacks using
NET_STACK_ARRAY_DEFINE() macro. This allows more debug information
to be printed by "net stacks" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 81d8d5219c net: context: Add PRIORITY option support
Add context option support and implement PRIORITY option that
can be used to classify the network traffic to different trafic
classes according to said priority value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen ca8b00a3cc net: if: Make interface IP configuration more flexible
Instead of always allocating both IPv6 and IPv4 address information
to every network interface, allow more fine grained address
configuration. So it is possible to have IPv6 or IPv4 only network
interfaces.

This commit introduces two new config options:
CONFIG_NET_IF_MAX_IPV4_COUNT and CONFIG_NET_IF_MAX_IPV6_COUNT
which tell how many IP address information structs are allocated
statically. At runtime when network interface is setup, it is then
possible to attach this IP address info struct to a specific
network interface. This can save considerable amount of memory
as the IP address information struct can be quite large (depends
on how many IP addresses user configures in the system).

Note that the value of CONFIG_NET_IF_MAX_IPV4_COUNT and
CONFIG_NET_IF_MAX_IPV6_COUNT should reflect the estimated number of
network interfaces in the system. So if if CONFIG_NET_IF_MAX_IPV6_COUNT
is set to 1 and there are two network interfaces that need IPv6
addresses, then the system will not be able to setup IPv6 addresses to
the second network interface in this case. This scenario might be
just fine if the second network interface is IPv4 only. The net_if.c
will print a warning during startup if mismatch about the counts and
the actual number of network interface is detected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 47dafffb67 net: if: Separate IP address configuration from net_if
Move IP address settings from net_if to separate structs.
This is needed for VLAN support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Jukka Rissanen 85a2459edb net: Support network packet checksum calc offloading
Create infrastructure that allows ethernet device driver to tell
if it supports network packet checksum offloading. This applies only
to IPv4, UDP or TCP checksums. The driver can enable/disable checksum
offloading separately for Tx and Rx network packets.

If the device (ethernet in this case) can calculate the network
packet checksum for IPv4, UDP or TCP, then do not calculate the
corresponding checksum by the stack itself.

Fixes #2987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-23 08:37:01 +02:00
Stig Bjørlykke c8732d93d0 net: sockets: Add freeaddrinfo()
Add freeaddrinfo() to complement getaddrinfo().

Existing applications using getaddrinfo() will usually free
allocated memory using freeaddrinfo(). Even if nothing is allocated
the function should exist to avoid having to change the application
when porting.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-21 10:00:05 +02:00
Anas Nashif 639f8ed344 doc: http: add HTTP APIs to net group
Make http APIs be part of the overall networking group in doxygen.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-20 14:01:30 -04:00
Anas Nashif 11828bf66b doc: do not show undocumented members
Avoid listing internal function in the public API documentation. After
enabling those doxygen configs, we go lots of errors and bad refs that
were fixed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-20 14:01:30 -04:00
Jukka Rissanen ebb7845937 net: pkt: net_pkt_get_reserve_data() was aliased incorrectly
If CONFIG_NET_DEBUG_NET_PKT was enabled, then a call to
net_pkt_get_reserve_data() was calling wrong debug function
which caused compile error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-20 15:58:16 +02:00
Stig Bjørlykke 7c9c825138 net: sockets: Support MSG_PEEK flag in zsock_recvfrom
Add support for MSG_PEEK flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-20 15:55:04 +02:00
Jukka Rissanen b047f816f4 net: Create helper to convert MAC strings to array of bytes
As following commits need this functionality, create a function
which converts "01:02:ab:fe:34:dd" type hex strings to array of
bytes. Change the SLIP driver to use this new function.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-18 20:47:36 -04:00
Stig Bjørlykke 158adc684f net: sockets: Support MSG_DONTWAIT flag in zsock_recvfrom
Add support for MSG_DONTWAIT flag in recv and recvfrom.

This flag is needed when using non-zephyr embedded applications with
Zephyr's socket API.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
2018-03-18 17:06:38 -04:00
Tomasz Bursztyka c49d176c35 ieee802154: Make AR flag check generic and not tight to L2
Since this function is used on some drivers, and knowing these drivers
can be built for OpenThread, let's make it generic and out of the
802.15.4 L2 stack.

Fixes #5942

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-16 13:57:55 -07:00
Jukka Rissanen ead9cd409c net: websocket: Add console support
Add console driver that allows console session to be transferred
over a websocket connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Jukka Rissanen d70c7383de net: websocket: Initial support for server websocket
This commit creates a websocket library that can be used by
applications. The websocket library implements currently only
server role and it uses services provided by net-app API.
The library supports TLS if enabled in configuration file.

This also adds websocket calls to HTTP app server if websocket
connection is established.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Ravi kumar Veeramally ebc81bdf8d net: http: Provide destination address in http replies
net_app_ctx maintains multiple net contexts(net_ctx). But when http
api's wants to reply or send some data, its always choose the first
net_context in the array, which is not correct always.

net_app_get_net_pkt_with_dst() api will select proper context
based on destination address. So with the help of new api in
net_app, http can select proper context and send packets. To
achieve this, desination address is provided in http_recv_cb_t
and http_connect_cb_t callbacks. Also chaged relevant API's to
provide destination address in http message preparation methods.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-03-05 10:23:17 +01:00
Michael Scott 311d0ac66c net: http: dont add CRLF to protocol in http_client_send_get_req()
It's added in subsys/net/lib/http/http_client.c:http_request():95
after adding the protocol header.  If we add 2 CRLF it ends the
header block and causes an HTTP error.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Tomasz Bursztyka 7255d7bbfb net/mgmt: Fix how event_mask is handled on layer and layer code part
Exact match is the rule here.

Fixes #6413

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-03-02 16:50:21 +01:00
Johan Hedberg 67e14d3916 net: buf: Use __noinit where possible
Static variables that don't strictly need to be initialized at
boottime should be declared with __noinit. This makes a considerable
difference especially for large buffers.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-14 15:44:04 +02:00
Tomasz Bursztyka 47e45c52a1 net: buf: Support allocation of a net_buf pointing to external buffer
Difference being that the data is not, then, allocated from the pool.
Only the net_buf is.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-02-13 16:46:32 +02:00
Johan Hedberg 9da02caff2 net: buf: Make net_buf_simple_init() forward compatible
Make it safe to call net_buf_simple_init() even if the buffer was
created using the new macros. This is possible to detect since with
the new macros buf->__buf will be non-NULL and with the old
NET_BUF_SIMPLE() macro it will be NULL.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-11 10:40:57 +02:00
Johan Hedberg 5008ec7a06 net: buf: Introduce variable data length allocators
Introduce two new "standard" data allocators to net_buf. There are now
three in total:

NET_BUF_POOL_FIXED_DEFINE: This is the closes to the old
implementation, i.e. fixed size chunks.  It's also what the old
NET_BUF_POOL_DEFINE macro maps to.

NET_BUF_POOL_HEAP_DEFINE: uses the OS heap

NET_BUF_POOL_VAR_DEFINE: defines a variable sized allocator using
k_mem_pool (this is all that there was in my first draft of this
feature)

Currently the variable length allocators (HEAP & VAR) support
reference counted data payloads, i.e. cheap cloning. The FIXED
allocator does not currentlty support this to allow for the simplest
possible implementation, but the support can be added later if
desired.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Ravi kumar Veeramally b22ab26b10 net: app: Add a new API to get net pkt based on dst
Added a new API to get net pkt based on dst address. Destination
address will be used to find correct net_context.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-09 14:45:53 +02:00
Ravi kumar Veeramally 49894b98e4 net: Improve net management event information
Provided separate event information structs based on events. This way
user will know what kind of information will be received to that
particular event.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally b4036f9609 net: Add neighbor ADD/DEL events
Add event defintions for IPv6 NBR ADD/DEL events.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Ravi kumar Veeramally 13f6ffa221 net: Fix compilation error
Fix compilation error about net_mgmt_event_notify_with_info().

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen e5b9e4d6ad net: ipv6: Add routing support between interfaces
Introduce CONFIG_NET_ROUTING option that allows the IP stack
to route IPv6 packets between multiple network interfaces.
No support for IPv4 routing is implemented by this commit.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-02-02 16:50:07 +02:00
Gil Pitney f4e08b003c net: sockets: Define POSIX function symbols as inline functions
Previously, POSIX function names were aliased to zsock_ function
names using, for example:

	#define connect zsock_connect

This caused the C preprocessor to replace any symbol named 'connect',
whether a function or not, in all source code which included socket.h,
with 'zsock_connect'.  This generated unintended code where the symbol
'connect' was used as the name of a structure field (as in mqtt.h).

This new inline definition is applied to all the POSIX function symbols,
with the exception of fcntl, a redefinition of which would conflict
with the definiton in the toolchain's fcntl.h.

Fixes #5817

Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2018-01-29 23:08:44 -05:00
Jukka Rissanen d1675bf3e6 net: http: Remove the old legacy API
There are no internal users for old HTTP API so removing it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-01-29 22:44:45 -05:00
Kamil Sroka bdfaf7f994 include: net: net_l2: Add OpenThread L2
Add OpenThread L2 to L2 list.

Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2018-01-29 22:42:03 -05:00
Kamil Sroka fad1c66761 include: net: net_pkt: Use IEEE802154 instead of NET_L2_IEEE802154
Use CONFIG_IEEE802154 instead of CONFIG_NET_L2_IEEE802154
and CONFIG_IEEE802154_RAW_MODE when adding RSSI and LQI
members to net_pkt. CONFIG_IEEE802154 is selected when
at least one 15.4 device is selected (L2 or RAW).

Signed-off-by: Kamil Sroka <kamil.sroka@nordicsemi.no>
2018-01-29 22:42:03 -05:00
Paul Sokolovsky 996c6dd603 net: if: Handle new address type of NET_ADDR_OVERRIDABLE
The meaning of this address type is the same as NET_ADDR_MANUAL,
but with a provision that DHCP can override such an address.
It's intended for the usecase when there's a default static
configuration for when DHCP is not available, but DHCP should
override it.

Before going to add another address type, there was an attempt
to repurpose TENTATIVE address state, but it doesn't work as
expected, as indeed, all existing address types/states already
have clearly semantics, and it makes sense to just another
address type to avoid confusion and unexpected behavior.

Fixes: #5696

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-23 09:25:51 +02:00
Paul Sokolovsky d965598ee2 net: dns: Allow to initialize DNS servers from struct sockaddr[]
In some cases, we need to initialize DNS servers from a binary
addresses, e.g. in case of DHCP processing. With existing API,
such addresses would need to be converted to strings, just to
be converted back to struct sockaddr in dns_resolve_init().
This is not efficient, and with a number of addresses quite
cumbersome. So instead, allow to pass DNS server either as
strings, or as struct sockaddr's (or both).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-18 17:30:40 +02:00
Michael Hope ed35aa8c63 net: use UNALIGNED_ACCESS when accessing s_addr on received packets.
The offset of the IP header in a received packet depends on the L2
header size.  For Ethernet this is 14 bytes which puts the u32 IPv4
addresses on a non-u32 byte boundary.  This causes chips that don't
support unaligned access (like the Cortex-M0) to fault.

The fixes in this patch are enough to ping the board and run the
http_server sample.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-16 11:27:48 +02:00
Tomasz Bursztyka 9078378bed net/ieee802154: Do not set the device UP by default
It will be up to the user to configure a valid channel, through
net_mgmt, and call net_if_up() in order to get the device up.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Tomasz Bursztyka 9aa2f45d23 net/ieee802154: Add Sub-Ghz dedicated function on the radio API
Sub-Ghz bands have different limit of channels. 10, or more than a
thousand is actually possible. Thus the device needs to expose such
limit to the L2 which is unaware of frequency band logic. L2 will
then allow user to select a proper channel.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-15 15:15:38 +02:00
Michael Scott b4d12f5280 net: lib: http: fix CONFIG_HTTPS for client use
Fix build break when enabling CONFIG_HTTPS w/o CONFIG_NET_APP_SERVER

This error can be seen when building sample/net/http_client like so:
$ cd samples/net/http_client
$ mkdir build && cd build
$ cmake -DBOARD=qemu_x86 -DCONF_FILE=prj_tls.conf ..
$ make run

In file included from
             /home/<user>/zephyr/include/net/http.h:11:0,
        from /home/<user>/zephyr/samples/net/http_client/src/main.c:19:
/home/<user>/zephyr/include/net/http_app.h:643:11: error: unknown type
name ‘net_app_cert_cb_t’
           net_app_cert_cb_t cert_cb,
           ^~~~~~~~~~~~~~~~~
CMakeFiles/app.dir/build.make:302: recipe for target
'CMakeFiles/app.dir/src/main.c.obj' failed

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-01-09 11:42:22 -05:00
Anas Nashif 13b08296e1 net: remove zoap library
We now have coap, all dependencies have been removed, so cleanup for the
next release.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-02 09:41:24 -05:00
Paul Sokolovsky e25df54eae various: Update/fix some textual material and code comments.
Of these, only struct net_ipv6_nbr_data::send_ns is a descriptive
change:

send_ns is used for timing Neighbor Solicitations in general, not
just for DAD.

The rest are typo/grammar fixes.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-29 09:45:39 -05:00
Michael Scott 6ddbd56853 net: lwm2m: add support for DTLS
- Add needed settings for DTLS support to the lwm2m_ctx structure.
- Add initialization of MBEDTLS to the LwM2M lib based on the
  user application settings in lwm2m_ctx.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-12-15 16:46:48 -05:00
Tomasz Bursztyka 4a3afb8506 net/ieee802154: Do not expose l2 specific context in generic net_l2.h
This will avoid exposing IEEE 802.15.4 Zephyr's L2 private context data
to unrelevant places.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-12 09:29:48 -05:00
Tomasz Bursztyka c88000a051 net/ieee802154: Split the net mgmt part from the L2 specific header
L2 specific data and IEEE 802154 net mgmt interface are not related.
Plus, application may use the net mgmt part, not the L2 one. So let's
split the content in relevant headers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-12 09:29:48 -05:00
Paul Sokolovsky 2a795a19ff drivers: eth_mcux: Implement IPv6 multicast group joining/leaving
IPv6 mcast addr to MAC mcast conversion was factored out to
subsys/net/ip/l2/ethernet.c for reuse by other drivers.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-12-12 09:24:51 -05:00
Anas Nashif abbaac9189 cleanup: remove nanokernel/nano leftovers
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-05 09:44:23 -06:00
David B. Kinder 834f7de229 doc: fix doxygen API comments for http_app.h
@detail command should be @details (plural)

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-12-04 15:58:57 -06:00
Patrik Flykt 753daa65f9 net: pkt: Compute TX payload data length
Compute the length of the TX payload that is transported in one
IPv4 or IPv6 datagram taking into account UDP, ICMP or TCP
headers in addition to any IPv6 extension headers added by RPL.
The TCP implementation in Zephyr is known to currently carry at
maximum 8 bytes of options. If the protocol is not known to the
stack, assume that the application handles any protocol headers
as well as the data. Also, if the net_pkt does not have a
context associated, length check on the data is omitted when
appending.

Although payload length is calculated also for TCP, the TCP MSS
value is used as before.

Define IPv4 minimum MTU as 576 octets, See RFC 791, Sections 3.1.
and 3.2.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-11-24 08:27:39 -05:00
Tomasz Bursztyka b52c0f24a6 net/ieee802154: Make RAW mode generic
- Renaming NET_L2_RAW_CHANNEL to NET_RAW_MODE
- Create a generic IEEE 802.15.4 raw mode for drivers
- Modify the IEEE 802.15.4 drivers so it passes the packet unmodified,
up to code using that mode to apply the necessary changes on the
received net_pkt according to their needs
- Modify wpanusb/wpan_serial relevantly

Fixes #5004

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-22 10:10:09 -05:00
Aska Wu 718b3cd7d0 net: sockets: Support ipv6 wildcard and loopback address
Add in6addr_any and in6addr_loopback which are defined in RFC2553 Basic
Socket Interface Extensions for IPv6.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-20 13:42:38 +02:00
Anas Nashif ca9285d1bb doc: net: group all networking APIs in doxygen
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-17 17:14:18 -05:00
Michael Scott 92cf80e9b2 net: http: dont add CRLF to protocol
In http_request() a CRLF is added to the header information after
the protocol is added.  2 CRLF in a row means the header information
is done, so following header information will be ignored.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Jukka Rissanen 7784518d37 net: http: Add error status string to HTTP server error
Add status error string when sending a error message from
HTTP server to client as described in RFC 2616 ch 6.1.
Previously only error code was sent except for 400 (Bad Request).

This also fixes uninitialized memory access in error message.

Coverity-CID: 178792
Fixes #4782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 09:52:46 +02:00
Tomasz Bursztyka 58bc383cfd net/ieee802154: Properly check the sequence when handling ACK frames
When sending a packet with AR flag set, the ACK frame that should be
replied to it must holp the same sequence number, so let's verify this
properly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-11-09 10:00:38 +02:00
David B. Kinder 483f7671c7 doc: fix misspellings in doxygen API comments
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-11-08 13:51:02 -05:00
Jukka Rissanen 0a9ed4e12b net: http: Deprecate old HTTP library
The old HTTP server and client library code is deprecated. The
new HTTP library will be based on net-app API code which requires
changes to function names and parameters that are not compatible
with old library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 09:33:00 -05:00
Jukka Rissanen 2486694eb9 net: http: Create HTTP library that uses net-app
Create http library that uses net-app instead of net_context
directly. The old HTTP API is deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 09:33:00 -05:00
Johan Hedberg 018198cedc net: buf: Add slist helpers
Now that net_buf has "native" support for sys_slist_t in the form of
the sys_snode_t member, there's a danger people will forget to clear
out buf->frags when getting buffers from a list directly with
sys_slist_get(). This is analogous to the reason why we have
net_buf_get/put APIs instead of using k_fifo_get/put.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 14:20:40 +02:00
Aska Wu 2d7ff75f60 net: pkt: Add net_pkt_get_dst_addr()
Rename net_pkt_get_src_addr() to net_pkt_get_addr() and make it able to
handle source or destination address.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-11-06 14:09:46 +02:00
Johan Hedberg 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
Johan Hedberg 553af7cd52 net: buf: Add sys_snode_t member for convenience
This makes it easy to use net_buf objects in sys_slist_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-01 12:08:27 +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
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 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
Paul Sokolovsky 3e2444d78a net: context: net_context_setup_pools: Elaborate docs
Describe details and usecase for using this function. This follows
earlier updates for macros used to define buffers used by this
function (in 09b967366).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-10-28 14:20:57 -04: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
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
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 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
David B. Kinder 4600c37ff1 doc: Fix misspellings in header/doxygen comments
Occasional scan for misspellings missed during PR reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-17 19:40:29 -04: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
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 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
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 88c0ccd681 net: ethernet: Check multicast IPv4 MAC address
Make sure the multicast MAC address checker checks also
IPv4 multicast MAC address and accepts it.

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
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
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 e4cb0e67ee net/ieee802154: Removing now useless functions from radio API
Finally removing set_ieee_addr, set_short_addr and set_pan_id which have
been replaced by set_filter.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 3d63a3411d net/ieee802154: Add a filter function to radio API
This will replace the current mandatory set_ieee_addr, set_short_addr
and set_pan_id functions, which are only valid if the hardware is
supporting filtering. Which is not the case on some chips.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 9c4605583e net/ieee802154: Add a way to retrieve hw capabilities from the devices
This will be useful to know various generic hardware aspects that can be
used relevantly by the L2 layer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 7be649ea6f net/ieee802154: Remove get_lqi from radio API
Now that lqi and rssi are embedded into net_pkt, there is no need for
that function.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +03:00
Tomasz Bursztyka 296cd0ab6d net/pkt: Add 802.15.4 lqi and rssi into net_pkt metadata structure
Instead of having dedicated function on the radio api level for 15.4,
let's just add the relevant values to the net_pkt structure (if only
IEEE802154 is enabled). It's simpler and make the values relevantly
tied to the received packet.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-13 13:48:32 +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
Ravi kumar Veeramally ba0359102e net: Deprecate ZOAP library
Added deprecated statements to ZOAP library api, structs and enums.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-10-06 22:07:37 -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
Michael Scott 260a061018 net: lwm2m: Fix up lwm2m.h for doc generation
Add documentation tags for future addition to doc gen.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-05 10:48:57 +03: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
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 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
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 6edb0e3d18 net: ip: Check IPv4 multicast address using big-endian
The IPv4 address in struct in_addr is in big endian so check
the multicast address value correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-29 11:34:06 +03: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
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
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 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 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
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
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
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
Tomasz Bursztyka 725be22771 net/mgmt/event: Commands must be > 0 so masking them works
If an event cmd is 0, NET_MGMT_GET_COMMAND() will return 0. That breaks
mgmt event core logic.

Jira: ZEP-2594

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-09-08 12:49:26 +03: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
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 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
Ricardo Salveti d0df530a50 net: udp: replace net_udp_get/set_hdr macros with static inline
Replace net_udp_get_hdr and net_udp_set_hdr macros with static inline
function definitions to avoid unused variable build warnings when
NET_UDP is not defined.

This fixes the following warning:

subsys/net/ip/6lo.c: In function 'compress_IPHC_header':
subsys/net/ip/6lo.c:759:22: warning: unused variable 'hdr' [-Wunused-variable]
   struct net_udp_hdr hdr, *udp;
                      ^~~

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-25 15:35:53 -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