Commit graph

1260 commits

Author SHA1 Message Date
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
Michael Scott caa377943a net: http: fix avoiding timeout on HTTP requests w/o body
The original commit 8ebaf29927 ("net: http: dont timeout
on HTTP requests w/o body") was intended to handle a case
where an HTTP response had been retrieved from the server but
the HTTP parser couldn't meet the criteria for calling
"on_message_complete".  For example, a POST to a REST API
where the server doesn't return anything but an HTTP
status code.

It was a really bad idea to check a semaphore count.  There
is a lot of kernel logic built into semaphores and how the
count is adjusted.  The assumption that the value is 0
after the k_sem_give() is incorrect.  It's STILL 0 if
something is pending with a k_sem_take().  By the time
k_sem_give() is done executing the other thread has now
been kicked and the count is back to 0.

This caused the original check to always pass and in turn
breakage was noticed in the http_client sample.

Let's do this the right way by setting a flag when
on_message_complete is called and if that flag is not set
by the time we reach recv_cb, let's give back the semaphore
to avoid a timeout.

Jira: ZEP-2561

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-23 16:42:03 -04:00
Jukka Rissanen c200de1b53 net: app: Introduce missing enable/disable functions for server
The server needs global enable/disable status instead of only being
able to enable or disable just the TLS server part.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 13:33:33 -04:00
Aska Wu 72c62976d0 net: ip: Prevent unaligned exception
s_addr is actually an unsigned integer and it's not guaranteed to be
aligned on 4-byte boundary. In net_ipv4_addr_cmp(), accessing s_addr
directly might cause an unaligned exception on some platform
like xtensa. Use UNALIGNED_GET() to prevent unalgined exception.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-22 08:23:56 -04:00
Paul Sokolovsky dcb80f7ab8 net: struct sockaddr should have field "sa_family"
POSIX requires struct sockaddr's field to be named "sa_family"
(not just "family"):
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

This change allows to port POSIX apps easier (including writing
portable apps using BSD Sockets compatible API).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Paul Sokolovsky 4520cfe1a1 net: Define struct sockaddr_storage
POSIX doesn't guarantee that "legacy" struct sockaddr is large enough
for all usages, e.g. IPv6 addresses, and instead requires use of
struct sockaddr_storage:
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

    ... shall define the sockaddr_storage structure. This structure
    shall be:

    Large enough to accommodate all supported protocol-specific
    address structures

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Ricardo Salveti 2175f78385 net: lwm2m: add IPSO light control object
As defined by IPSO-Smart-Objects "Section: 16. IPSO Object: Light
Control".

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-18 10:53:25 +03:00
Jukka Rissanen e08716001a net: tcp: Do not re-send already sent packets
If the expire send timer expires, then it sends the packet.
If that happens, then we must not try to send the same packet
again if we receive ACK etc. which can cause re-sends to happen.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-16 14:50:57 -04:00
Michael Scott fe84d4f7dd net: http: allow HTTP_NETWORK_TIMEOUT to be configured
Currently, the HTTP_NETWORK_TIMEOUT setting is hard-coded as 20 seconds.
Not every application may want to wait that long, so let's change this
to a CONFIG option: CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT

NOTE: This also removes HTTP_NETWORK_TIMEOUT from the public http.h
include file.  It was not being used externally to HTTP client sources.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-16 12:35:33 +03:00
Jukka Rissanen 0c20287004 net: l2: Declare Bluetooth and Offload L2 drivers public
This is needed so that we can get L2 information for example
in net-shell.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-14 11:06:34 +03:00
David B. Kinder 2c850d7547 doc: fix misspellings in include (API docs)
Fix misspellings in .h files missed during code reviews
and affecting generated API documentation

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-10 12:22:19 -04:00
Aska Wu eb8fd4aacf net: sockets: inet_pton() should return 1 on success
Add zsock_inet_pton() to convert the return value of net_addr_pton()
which returns 0 on success.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-10 17:41:47 +03:00
Jukka Rissanen b6a5d51baf net: Fix indentation issues
Some earlier search/replace broke indentation.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 16:01:28 +03:00
Jukka Rissanen 53928aae76 net: if: Helper to return first IEEE 802.15.4 interface
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:24:34 +03:00
Jukka Rissanen f6661512a4 net: if: Add helper to return interface of given type
The helper will return the first network interface of a desired
L2 type.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-09 12:24:34 +03:00
Johan Hedberg 2975ca0754 Bluetooth: Kconfig: Rename CONFIG_BLUETOOTH_* to CONFIG_BT_*
The API name space for Bluetooth is bt_* and BT_* so it makes sense to
align the Kconfig name space with this. The additional benefit is that
this also makes the names shorter. It is also in line with what Linux
uses for Bluetooth Kconfig entries.

Some Bluetooth-related Networking Kconfig defines are renamed as well
in order to be consistent, such as NET_L2_BLUETOOTH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 11:14:19 +03:00
Michael Scott aef5ee4582 net: lwm2m: add IPSO support w/ temperature sensor object
IPSO Smart Objects are a set of template objects based on the LwM2M
object framework which are designed to represent standard hardware
such as temperature and humidity sensors or light controls.

Let's add a place for these objects to live as well as an initial
temperature sensor object.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott c46c206f8c net: lwm2m: initial library support for LWM2M
Origin: SICS-IoT / Contiki OS
URL: https://github.com/sics-iot/lwm2m-contiki/tree/lwm2m-standalone-dtls
commit: d07b0bcd77ec7e8b93787669507f3d86cfbea64a
Purpose: Introduction of LwM2M client library.
Maintained-by: Zephyr

Lightweight Machine-to-Machine (LwM2M) is a protocol stack extension
of the Constrained Application Protocol (CoAP) which uses UDP
transmission packets.

This library was based on source worked on by Joakim Eriksson,
Niclas Finne and Joel Hoglund which was adopted by Contiki and then
later revamped to work as a stand-alone library.

A VERY high level summary of the changes made:
- [ALL] sources were re-formatted to Zephyr coding standards
- [engine] The engine portion was re-written due to the heavy reliance
  on ER-CoAP APIs which are not compatible to the Zephyr CoAP APIs as
  well as other Zephyr specific needs.
- [engine] All LWM2M/IPSO object data is now abstracted into resource
  data which stores information like the data type, length, callbacks
  to help with read/write.  The engine modifies this data directly (or
  makes callbacks) instead of all of the logic for this living in each
  object's code. (This wasn't scaling well as I was implementing
  changes).
- [engine] Related to the above change, I also added a generic set of
  getter/setter functions that user applications can call to change
  the object data instead of having to add getter/setting methods in
  each object.
- [engine] The original sources shared the engine's context structure
  quite extensively causing a problem with portability. I broke up the
  context into it's individual parts: LWM2M path data, input data and
  output data and pass only the needed data into each set of APIs.
- [content format read/writer] sources were re-organized into single
  .c/h files per content formatter.
- [content format read/writer] sources were re-written where necessary
  to remove the sharing of the lwm2m engine's context and instead only
  requires the path and input or output data specific to it's
  function.
- [LwM2M objects] re-written using the new engine's abstractions

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-09 10:55:53 +03:00
Michael Scott 911efb0e72 net: zoap: use message id for reply matching
In the 08 Feb 2017 V1.0 LwM2M specification page 80 mentions: in
response to a "Notify" operation for which it is not interested in
any more, the LwM2M Server can send a "Reset Message".

Leshan server sends this CoAP RST response and it does not contain
the originating message token (which is also how the packet flow looks
on page 81 of the LwM2M spec).  Using the current ZoAP sources, the
client has no way of matching back to observation which needs to be
cancelled.

Let's add a match for message ID of a reply where there is no token
to handle this case.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
[ricardo.salveti@linaro.org: Handle both piggybackend and separate
response (id doesn't need to match, only token).]
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-09 10:55:53 +03:00
Jukka Rissanen 64562e1af2 http: server: Add function to send a chunk of data
The http_response_send_data() can be used to send a chunk of data
to the peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-08 15:35:18 +03:00
Paul Sokolovsky 19ff963693 net: tcp: Allow to explicitly manage TCP receive window
This fixes the existing situation that "if application buffers data,
it's the problem of application". It's actually the problem of the
stack, as it doesn't allow application to control receive window,
and without this control, any buffer will overflow, peer packets
will be dropped, peer won't receive acks for them, and will employ
exponential backoff, the connection will crawl to a halt.

This patch adds net_context_tcp_recved() function which an
application must explicitly call when it *processes* data, to
advance receive window.

Jira: ZEP-1999

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-05 11:40:50 +03:00
Luiz Augusto von Dentz cbc4a2b9b0 net: bt: Add advertise management command
This adds NET_REQUEST_BT_ADVERTISE which can be used to advertise
IPSS service so the remote devices can connect to it.

Jira: ZEP-2451

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-04 18:18:40 +03:00
Aska Wu e7acafd967 net: sockets: Fix a link error if CONFIG_NET_TCP is not enabled
Always support net_pkt_sent() and net_pkt_set_sent().

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-04 16:50:37 +03:00
Paul Sokolovsky fbd593408f net: sockets: Add docs for BSD Sockets compatible API.
Includes updates to Zephyr networking API feature list (also minor
tweaks to it not dorectly related to sockets), overview of BSD
Sockets compatible API, and basic API reference section.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-01 22:09:52 -04:00
Andrew Boie 507852a4ad kernel: introduce opaque data type for stacks
Historically, stacks were just character buffers and could be treated
as such if the user wanted to look inside the stack data, and also
declared as an array of the desired stack size.

This is no longer the case. Certain architectures will create a memory
region much larger to account for MPU/MMU guard pages. Unfortunately,
the kernel interfaces treat both the declared stack, and the valid
stack buffer within it as the same char * data type, even though these
absolutely cannot be used interchangeably.

We introduce an opaque k_thread_stack_t which gets instantiated by
K_THREAD_STACK_DECLARE(), this is no longer treated by the compiler
as a character pointer, even though it really is.

To access the real stack buffer within, the result of
K_THREAD_STACK_BUFFER() can be used, which will return a char * type.

This should catch a bunch of programming mistakes at build time:

- Declaring a character array outside of K_THREAD_STACK_DECLARE() and
  passing it to K_THREAD_CREATE
- Directly examining the stack created by K_THREAD_STACK_DECLARE()
  which is not actually the memory desired and may trigger a CPU
  exception

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-01 16:43:15 -07:00
Jukka Rissanen 95d30430d7 net: app: Add debugging support to get net_app instances
Add API that allows net-shell to get net_app context information
that can be used to debug net_app connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 21:09:59 +03:00
Jukka Rissanen f3f32e872a net: app: Add DTLS support
Allow UDP connections to use DTLS to encrypt the user data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-01 21:09:59 +03:00
David B. Kinder 80a2f9476f net/mqtt: tweak doxygen comment for return value
mqtt_init's return value in the generated docs didn't format
correctly.  Needs to be a space after the 0, so just delete
the comma.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-07-31 19:32:24 -04:00
Jukka Rissanen 539b0c46ff net: doc: Add missing defgroups to network header files
Some of the networking header files in include/net/ directory were
missing @defgroup doxygen directives.

There was also duplicate @defgroup directives which are now changed
to @addtogroup directives.

Added also missing API links to doc/api/networking.rst file.

Added exceptions to .known-issues/doc/networking.conf file so that
doxygen does not complain.

Jira: ZEP-2308

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 20:59:09 +03:00
Jukka Rissanen 1c07ead104 net: http: Add context net_buf pool support to HTTP client
This commit adds http_client_set_net_pkt_pool() function that allows
caller to define net_buf pool that is used when sending a TCP packet.
This is needed for those technologies like Bluetooth or 802.15.4 which
compress the IPv6 header during send.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Jukka Rissanen 93214086f9 net: http: Add context net_buf pool support to HTTP server
This commit adds http_server_set_net_pkt_pool() function that allows
caller to define net_buf pool that is used when sending a TCP packet.
This is needed for those technologies like Bluetooth or 802.15.4 which
compress the IPv6 header during send.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Aska Wu c0b5e55e6d net/mqtt: Enable TLS support
CONFIG_MQTT_LIB_TLS is introduced to enable TLS support.

Also, prj_frdm_k64f_tls.conf is added to demostrate the whole idea.

jira:ZEP-2261

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-07-28 11:25:43 +03:00
Aska Wu fb79837862 net/mqtt: Convert mqtt lib to use net app API
Use net app API since we want to enable MQTT with TLS.
mqtt_connect() and mqtt_close() are added to build and close the
connection to the broker. The caller doesn't need to deal with
the net context anymore and the most of network setup code in
mqtt_publisher is removed.

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-07-28 11:25:43 +03:00
Jukka Rissanen f8c5f69780 net: shell: Do not access NULL pointer if interface is down
Normally network interface is always UP, but Bluetooth
interfaces are down until connected. So if this is the case,
then check the interface status before trying to access variables
that are NULL. This was seen with "net iface" shell command when
BT was enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-27 15:19:53 +03:00
Jukka Rissanen e75b71ff0a net: trickle: Misc changes
* Fix the indentation which was caused by uint32_t -> u8_t changes.
* Make sure there is no unused variable warning if debugging is
  enabled but debug level is low.
* Add assert that checks that Imax_abs is > 0 which it should be.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-26 07:56:51 -05:00
Jukka Rissanen 68ced8035d net: Add missing __cplusplus checks to includes
Some of the public networking include files did not had
__cplusplus checks.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-24 14:54:34 -04:00
Paul Sokolovsky 2c2e8b26b4 net: sockets: Implement poll() operation.
poll() allows to (efficiently) wait for available data on sockets,
and is essential operation for working with non-blocking sockets.

This is initial, very basic implementation, effectively supporting
just POLLIN operation. (POLLOUT implementation is dummy - it's
assumed that socket is always writable, as there's currently no
reasonable way to test that.)

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-18 21:46:06 +03:00
Jukka Rissanen 31b5b140e0 net: context: Clarify the callback API documentation
Document clearly how and in what context, the various callbacks
in net_context API are being called.

Jira: ZEP-2352

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-17 21:47:32 +03:00
Robert Chou 33c54ee6fd net: zoap: advance block context by checking M bit from block option
According to RFC7959 page 30, "The end of a block-wise transfer is
governed by the M bits in the Block options, _not_ by exhausting the
size estimates exchanges."

Therefore, we should check the M bit instead of total size (which
is not always available, too)

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-07-14 11:06:54 +03:00
Paul Sokolovsky 1abb89f640 net: sockets: Implement non-blocking mode.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-11 14:00:27 +03:00
Andrew Boie 65a9d2a94a kernel: make K_.*_INITIALIZER private to kernel
Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Jukka Rissanen 9c907fca43 net: tcp: Remove NET_TCP_HDR() macro and direct access to net_buf
Remove NET_TCP_HDR() macro as we cannot safely access TCP header
via it if the network packet header spans over multiple net_buf
fragments.

Fixed also the TCP unit tests so that they pass correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 3604c391e6 net: udp: Remove NET_UDP_HDR() macro and direct access to net_buf
Remove NET_UDP_HDR() macro as we cannot safely access UDP header
via it if the network packet header spans over multiple net_buf
fragments.

Fixed also the UDP unit tests so that they pass correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Jukka Rissanen 8476da9d9b net: icmp: Remove NET_ICMP_HDR() macro and direct access to net_buf
Remove NET_ICMP_HDR() macro as we cannot safely access ICMP header
via it if the network packet header spans over multiple net_buf
fragments.

Jira: ZEP-2306

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-07 15:24:00 +03:00
Anas Nashif 3ec3276163 kconfig: fixed stray Kconfig variables
Those were found using:

  ./scripts/checkconfig.py

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-07-06 10:34:41 -05:00
Jukka Rissanen 7a31d4b8cb net: app: Fix dual IPv4 and IPv6 support
It was not possible to send IPv4 packets if IPv6 was also
enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-06 14:32:37 +03:00
Jukka Rissanen 489ea9ba4f net: context: Remove useless asserts when setting net_buf pools
No need to print errors if assinging null values into net_buf
pools as this is a normal condition if those pools are not used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-06 14:27:55 +03:00
Jukka Rissanen a1be6a8ba9 net: app: Create support for network application API
The network application API is a higher level API for creating
client and server type applications. Instead of applications
dealing with low level details, the network application API
provides services that most of the applications can use directly.

This commit removes the internal net_sample_*() API and converts
the existing users of it to use the new net_app API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-30 06:13:09 -04:00
Paul Sokolovsky 2b4a240859 net: sockets: Implement recv() for STREAM sockets
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 41e88ea40c net: sockets: Implement send()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 9405887aa7 net: sockets: Add POSIX compat defines for inet_ntop, inet_pton
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 7567962f3a net: sockets: Implement bind(), connect(), listen(), accept()
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 4877d6556b net: context: Allow to put context into FIFO at expense of user_data
By moving user_data member at the beginning of structure. With
refcount at the beginning, reliable passsing of contexts via
FIFO was just impossible. (Queuing contexts to a FIFO is required
for BSD Sockets API).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 386c5bacd1 net: sockets: Add configurable option to provide raw POSIX API names
With CONFIG_NET_SOCKETS_POSIX_NAMES=y, "raw" POSIX names like
socket(), recv(), close() will be exposed (using macro defines).
The close() is the biggest culprit here, because in POSIX it
applies to any file descriptor, but in this implementation -
only to sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 041d38740d net: context, pkt: Changes for Sockets API
Two changes are required so far:

* There's unavoidable need to have a per-socket queue of packets
(for data sockets) or pending connections (for listening sockets).
These queues share the same space (as a C union).
* There's a need to track "EOF" status of connection, synchronized
with a queue of pending packets (i.e. EOF status should be processed
only when all pending packets are processed). A natural place to
store it per-packet then, and we had a "sent" bit which was used
only for outgoing packets, recast it as "eof" for incoming socket
packets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Paul Sokolovsky 3432ff4fca net: sockets: Bootstrap Sockets API implementation
This adds Kconfig and build infrastructure and implements
zsock_socket() and zsock_close() functions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-28 16:07:55 +03:00
Johan Hedberg 9703927f84 net: buf: Move net_buf_pool objects to dedicated linker area
Moving the net_buf_pool objects to a dedicated area lets us access
them by array offset into this area instead of directly by pointer.
This helps reduce the size of net_buf objects by 4 bytes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-16 17:05:06 +03:00
Robert Chou c1db42f52c net: zoap: correct description of zoap_response_received()
The original description seems copied from zoap_pending_received().
Correct the description to reflect what it does actually

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
2017-06-14 14:55:43 -04:00
Paul Sokolovsky 515788648a net: ip: Make struct in_addr::s_addr compatible with POSIX definition
From
http://pubs.opengroup.org/onlinepubs/7908799/xns/netinetin.h.html:

in_addr_t
    An unsigned integral type of exactly 32 bits.

[] the in_addr structure [] includes at least the following member:

in_addr_t      s_addr

In other words, POSIX requires s_addr to be a single integer value,
whereas Zephyr defines it as an array, and then access as s_addr[0]
everywhere. Fix that by following POSIX definition, which helps to
port existing apps to Zephyr.

Jira: ZEP-2264

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-06-13 10:32:03 +03:00
Andrew Boie 567c6c7683 misc: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Tomasz Bursztyka 3a025544a1 ieee802154: Realign structure bitfields
Unsigned integer name change messed up the alignement of the size in
bitfields.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-06-09 13:19:50 +03:00
Jukka Rissanen fc125e0e2c net: shell: Add HTTP server connection monitoring
The "net http monitor" command turns on HTTP monitoring,
which means that for each incoming HTTP or HTTPS request,
a information about source and destination address, and
the HTTP request URL is printed.
User can disable the monitoring by "net http" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:10 +03:00
Jukka Rissanen ab51f67e17 net: http: Collect HTTP server connection information
If CONFIG_NET_DEBUG_HTTP_CONN is enabled, then start to collect
currently active HTTP connections to HTTP server.

This is only useful for debugging the HTTP connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 13:09:10 +03:00
Jukka Rissanen 1b82463dee net: http: Add HTTPS client support
Add HTTPS support into http-client library. The init of the
HTTPS client connection is different compared to HTTP client,
but the actual HTTP request sending is using the same API as
HTTP client.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 0d43bbfb77 net: http: Move heap init into net/lib/http/http.c
This is done so that both http_client and http_server functionality
can share the same heap.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 7d13261bd9 samples: net: zperf: Fix llvm compiler warnings
Jira: ZEP-1884

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-01 10:30:21 -04:00
Jukka Rissanen 31faeca511 net: http: Add timeout to HTTP server response
Allow the caller to delay the closing of the HTTP connection
for a number of milliseconds. The purpose for this is that
the client can send still some data back to us for a short
period of time.

This is needed for example for Basic authentication so that
server is able to receive authentication values back.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-23 18:01:04 +03:00
Patrik Flykt 789721e9cc zoap: Include net/net_ip.h when sockaddr is used
Add include file net/net_ip.h as zoap header files use struct
sockaddr.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2017-05-23 10:29:41 +03:00
Jukka Rissanen e253dcbd3b net: tcp: Add TCP statistics support
We did not collect any TCP statistics before but this commit
changes that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-17 13:55:21 +03:00
Paul Sokolovsky 72a30f3843 net: tcp: Add TCP sequence number comparison compliant with RFC793.
RFC793, "Transmission Control Protocol", defines sequence numbers
just as 32-bit numbers without a sign. It doesn't specify any adhoc
rules for comparing them, so standard modular arithmetic should be
used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-16 14:29:17 +03:00
Jukka Rissanen a174d2eba7 net: http: Add HTTP server library support
This commit creates a HTTP server library. So instead of creating
a complex HTTP server application for serving HTTP requests, the
developer can use the HTTP server API to create HTTP server
insteances. This commit also adds support for creating HTTPS servers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Jukka Rissanen c77460da53 net: pkt: Add function to linearize a network packet
This helper copies desired amount of data from network packet
buffer info a user provided linear buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Paul Sokolovsky 29d9f957db net: if: Clean up docstrings in header file
A half of params were described as "pointer on" (pretty strange
sounding), another half - "pointer to". Use the latter consistently.
Also, minor wording and punctuation changes.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-12 11:14:04 -04:00
Andrew Boie 7a0782d8ee net: use k_thread_create()
Common code in include/misc/stack.h is now used for analysis.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Kumar Gala ed96de9f10 net: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-05-09 17:06:28 -04:00
Jukka Rissanen 70f334d9f2 http: client: Create a HTTP library
Instead of separate sample application that does everything
related to HTTP client connectivity, create a HTTP client library
that hides nasty details that are related to sending HTTP methods.
After this the sample HTTP client application is very simple and
only shows how to use the client HTTP API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-04 15:58:45 -04:00
David B. Kinder fc5f2b3832 doc: spelling check doxygen comments include/
fix misspellings found in doxygen comments used for API docs

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-05-02 22:21:37 -04:00
Paul Sokolovsky e813091f0a net: Switch to common values for SOCK_STREAM, SOCK_DGRAM
Many OSes use values SOCK_STREAM = 1, SOCK_DGRAM = 2, apparently
inherited from the original BSD Unix, which introduced Sockets API.
These values are exposed as numbers in many places, e.g. with a
debugger, when printing just as numbers, etc., so use the above
common values to avoid possible confusion.

Jira: ZEP-2066

Change-Id: I0477abc79e2b43ef83f9fb11a66092f2b41f75fa
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:10 +03:00
Jukka Rissanen 1f5d7bae9f dns: Remove unused fields from dns_addrinfo struct
The ai_flags, ai_socktype and ai_protocol fields are removed as there
is currently no use for them. These can be added back later if really
needed.
Reordering the fields at the same time which caused 4 bytes to be saved
in storage space.

Jira: ZEP-2065

Change-Id: Ida1dcfb6afed73733d3db9cf4d07e771d31ee314
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-28 15:01:10 +03:00
Paul Sokolovsky 25307d5331 net: net_pkt_append: Refactor to return length of data actually added
For stream-based protocols (TCP), adding less data than requested
("short write") is generally not a problem - the rest of data can
be sent in the next packet. So, make net_pkt_append() return length
of written data instead of just bool flag, which makes it closer
to the behavior of POSIX send()/write() calls.

There're many users of older net_pkt_append() in the codebase
however, so net_pkt_append_all() convenience function is added which
keeps returning a boolean flag. All current users were converted to
this function, except for two:

samples/net/http_server/src/ssl_utils.c
samples/net/mbedtls_sslclient/src/tcp.c

Both are related to TLS and implement mbedTLS "tx callback", which
follows POSIX short-write semantics. Both cases also had a code to
workaround previous boolean-only behavior of net_pkt_append() - after
calling it, they measured length of the actual data added (but only
in case of successful return of net_pkt_append(), so that didn't
really help). So, these 2 cases are already improved.

Jira: ZEP-1984

Change-Id: Ibaf7c029b15e91b516d73dab3612eed190ee982b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:09 +03:00
june li 3e4faffede net: l2: Clear arp cache when disable interface.
When connect to diffrent router with the same gateway ip address,
need to clear arp cache when disable interface,
or it will use the wrong gateway mac address.
Call net_arp_clear_cache function replace to set arp_table 0.

Change-Id: Ib403a0c0030832ba48824db4d2d3fcb8add63d16
Signed-off-by: june li <junelizh@foxmail.com>
2017-04-28 15:01:08 +03:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Tomasz Bursztyka f3ff4f7bd3 net_pkt: Let's make all IPv6 related attributes prefixed with ipv6_
Only 2 attributes lacked this prefix, which makes sense to have, so
applying it accordingly and changing the helpers as well.

Change-Id: I095b2729f977f8fb1624eff8801a4a4e21416693
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka e5896906f6 net: Rename all *_BUF() macros to *_HDR()
Most of these macros are not exactly exposing a buffer, but a specific
header pointer (ipv6, ivp4, ethernet and so on), so it relevant to
rename them accordingly.

Change-Id: I66e32f7c3f2bc75994befb28d823e24299a53f5c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka 02cb7e6e71 net_pkt: Reordering the attributes for better alignment
Instead of using a bool, let's just use a bit in a bifield, shared among
various attribute. This saves space.

Make ext_len attribute enabled only on IPv6 (ipv6, icmpv6 and rpl are
the only code setting it) and reordering the helpers functions
accordingly.

Change-Id: Ifd3295d778959308ead7db9b2a59396e50f8e18c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:51 +03:00
Tomasz Bursztyka c18016b69b net_pkt: Externalize ext_bitmap handling
IPv6 next headers are processed in a way so it is not required to store
which header has been already seen in the net_pkt, as the processing loop
can store internally which one it has seen already.

Change-Id: I266ba8a3a0081a162318cdafb474a0fc44a3185e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka 2e331de690 net_pkt: Removing legacy net_dir
This is actually useless as there is only 1 RX memory slab, and thus can
be removed to reduce net_pkt structure size.

Change-Id: I62d716515120e7356ee1e2d75bbe1ec32e22c35d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka db11fcd174 net/net_pkt: Fully separate struct net_pkt from struct net_buf
- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

Change-Id: Ibd5c17df4f75891dec79db723a4c9fc704eb843d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Tomasz Bursztyka bf964cdd4c net: Renaming net nbuf API to net pkt API
There have been long lasting confusion between net_buf and net_nbuf.
While the first is actually a buffer, the second one is not. It's a
network buffer descriptor. More precisely it provides meta data about a
network packet, and holds the chain of buffer fragments made of net_buf.

Thus renaming net_nbuf to net_pkt and all names around it as well
(function, Kconfig option, ..).

Though net_pkt if the new name, it still inherit its logic from net_buf.
'
This patch is the first of a serie that will separate completely net_pkt
from net_buf.

Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Ravi kumar Veeramally a8ac7af37a net: zoap: Remove unused helper function
Commit "net: zoap: Fix memory overflow issue" fixed and implemented
./well-known/core response in a different way, so this api is not needed
anymore.

Change-Id: I8f945fb5842028be50ecfdef95cbe5da3189a538
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-21 14:19:49 +03:00
Kumar Gala 3c454017b4 Merge "Merge bluetooth branch into master" 2017-04-20 16:55:36 +00:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
Luiz Augusto von Dentz 1885edf424 net: buf: Add net_buf_reset
This adds net_buf_reset which can be used to reset the state of a buffer.

Change-Id: I4b7c89dfd1a23a2ec8dfa3c99d5b02b9bcbceef3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Bogdan Davidoaia 290e1d8451 net: use UNALIGNED_GET/PUT to access IP address
Use UNALIGNED_GET and UNALIGNED_PUT throughout the networking stack to
access fields from the IP address structure. These structures can be
mapped directly to buffers and the macros are required for correct
unaligned memory access.

Jira: ZEP-2012

Change-Id: I55f9da7b143a22fa869d5d215c661de988cd9b91
Signed-off-by: Bogdan Davidoaia <bogdan.davidoaia@linaro.org>
2017-04-13 15:21:46 +03:00
Andrei Emeltchenko 01a9e4001d net: nbuf: Implement net_nbuf_append_le32 helper
net_nbuf_append_le32 helper appends le32 data to the packet, this is
needed in some Thread headers using LE data.

Change-Id: I04233ca064c2e23ec5c53979ac234adfe0ccb9dd
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 951294f15e net/ieee802154: Expose TX power setting through net mgmt API
This permits to tweak the TX power in dbm.

Change-Id: Idadff397941a39010ce3c374d9ca74b777934626
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:46 +03:00
Tomasz Bursztyka 192435ae2b net/nbuf: Add an attribute to store/get IEEE 802.15.4 RSSI on RX
This way, the driver will be able to pass the RSSI of the frame it just
received.

Change-Id: I08e7565e35b4fb087cf348bce01722ab25d59f0f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen f8c9439908 net: if: Reshuffle fields in net_if and related structs
This does not save any space but sets the fields in the
structs in more natural order. Move IPv6 related
fields in net_if into internal ipv6 struct so that all
IPv6 fields are located inside one struct. Same thing
is done for IPv4 fields which are now located inside
IPv4 internal struct in net_if.

There is no functionality changes by this commit.

Change-Id: I7d72ec0a28e2b88c79a4c294655d5ef6da6ccb25
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 8b8371f573 net: if: Repack net_if_addr struct to save space
Shuffle the fields to different order in net_if_addr struct.
This saves space in net_if struct. This saved 4.8% memory,
640 bytes in original versus 608 bytes after this commit, when
allocating net_if using minimal amount of address counts and
IPv4, DHCPv4 and IPv6 enabled.

Change-Id: I591543cded587178cf6f82189953bb2e99c2188a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 611ccaaf88 net: dns: Remove dns_client API and sample application
DNS resolving is better done with DNS resolve API so remove
the DNS client API which is quite hard to use.

Change-Id: Ide4973a5be674414ea6e04a35c938195cce40b6a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 57e128654b net: mgmt: Add IPv6 DAD succeed/failed event
We need a way to know when IPv6 address is successfully set
into network interface.

If IPv6 DAD (Duplicate Address Detection) succeeds or fails,
we send a management event for that. This can be used by
other components to detect when the network interface is in
usable state.

Change-Id: Ifb22415fe21f31f5dba4f55455d6e0f89b414d32
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:45 +03:00
Jukka Rissanen 528a393470 net: ipv6: Fix the constness of function parameters
Some of the IPv6 utility functions were missing const in
one of the parameters that are not modified by the corresponding
function.

Change-Id: Ic9fe53daac288570c14423fd9410dcf15d1c5cfa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:44 +03:00
Tomasz Bursztyka e896d18a63 net: Make sure IP layer events have fully differentiated layer code
Layer code should be made so that masking them don't overlap with
another one in net_event code logic. Earlier it was possible to get
an IP addr event for IPv6 even though code would be only listening
for IPv4 one.

Reported-by: Xiaorui Hu <xiaorui.hu@linaro.org>

Change-Id: I8341a91d55556033dd228f68f8ca64e196f52bec
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-13 15:21:44 +03:00
Jukka Rissanen 186939c43d net: dns: Fix the compilation even if DNS is disabled
Make sure that CONFIG_DNS_RESOLVER_MAX_SERVERS and
CONFIG_DNS_NUM_CONCUR_QUERIES are defined even if
CONFIG_DNS_RESOLVER is not enabled. This fixes compilation
error in this special case.

Change-Id: Icf1f247c138c379246ece57e78b04e70ae43cc1e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen 83822b932a net: dns: Fix the documentation errors in header file
Change-Id: I516d5634a0f4d66ec15324fb856f9b313bc6f9d8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen 42bd36ec77 net: ipv6: Allow user to tweak packet hop limit value
The default hop limit is defined in struct net_if. It is possible
that user might want to tweak it for each network packet. For this
purpose, a net_nbuf_set_ipv6_hop_limit(buf) function is created.

Change-Id: I7568330358f80f0f5007d6d3c411c120b043c04f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:43 +03:00
Jukka Rissanen ea17e9d321 net: ipv6: Support fragmented IPv6 packets
This commit adds support for IPv6 packet fragmentation when
receiving (IPv6 reassembly) and when sending larger than 1280 bytes
long IPv6 packet. See RFC 2460 chapter 4.5 for more details.

Jira: ZEP-1718

Change-Id: Ia31c147cce4d456ee48f39276cca99aa09ce81d6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Jukka Rissanen 1b2c16a498 net: nbuf: Add function to split a data fragment
Add net_nbuf_split() function that can be used to split
an existing net_buf fragment into two arbitrary length pieces,
and return the two new fragments to the caller. The data from
the original fragment is copied into these two new fragments.

Existing fragment is not modified.

Change-Id: I463e675232c6e19c2a42929f480893a6d1265873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-04-13 15:21:41 +03:00
Paul Sokolovsky ed42268ffb net: buf: Document that after data, structure may contain "user_data"
Document via a comment, as C doesn't allow to represent variable
length fields in a structure.

Change-Id: I7d0436eab434fc5f27a2b6e2c9a4a548ab20dbcb
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-07 12:35:51 +03:00
Ravi kumar Veeramally 3e78d38f01 net: event: Add events for ROUTE ADD and DEL
Change-Id: I1d8cb1aebe8a6eb224f6103db0679000bb57c187
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-04-07 12:35:50 +03:00
Tomasz Bursztyka 8292dc16d4 net/ieee802154: Remove useless __packed annotation
These structs are not mapped to network data, and allocated on stack.

Change-Id: Ib00e15c3d0cdb21fd124ef6f61ec010100bcc9bf
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:28 +02:00
Tomasz Bursztyka 35dd54d1d7 net/ieee802154: Rename <SET/GET>_CHAN to <SET/GET>_CHANNEL
It's more readable and along with other part of the system.

Change-Id: Ib4be787d74310d838f38b1f1d5624e7357da8969
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 11:24:27 +02:00
Tomasz Bursztyka e771f174e5 net/ieee802154: Add net mgmt requests to set/get security settings
These requests are used to set/get the key, the mode and the level of
the IEEE 802.15.4 link layer security.

Only implicit key mode is supported for now.

Change-Id: Ifbc9a5d08f9fbf0d51d6c3e4b650cfdce3d263db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:33 +02:00
Tomasz Bursztyka 5e115ba935 net/ieee802154: Provide the means to create secured data frames
Take into account the current security context to compute the header
size.

Provide the function to fill-in the aux security header in a frame.

Finally, call the generic encryption function which will process the
frame relevantly according to the given security context.

For now, only implicit key mode is supported.

Change-Id: I5412c32179e70217c0946b1b54d9a752375d522f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Tomasz Bursztyka 9d78dba0a1 net/ieee802154: Add generic support for link layer cipher operations
This provides the means to authentify with/without encryption or
decryption of a frame following a generic 15.4 security context.

Change-Id: Ia5dbb7f43936a8131112fe4b16c9780e30f904c1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-31 10:39:32 +02:00
Jukka Rissanen cbfce3a299 net: dns: Add functions to resolve using default context
Applications should normally use these functions as then the system
wide DNS server settings are used.

Change-Id: I2c1fc7c7c881081506d21c3d37628d5c3dcc6aaa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 8dc01261ea net: dns: Initialize DNS resolver if DNS servers are set
If the config file contains DNS server addresses, then
configure the DNS resolver to use them.

Change-Id: Ie7f2bdcf7ac4bb7ee0ecf7fb5b7bd2df3379cdc3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 79cd66f40c net: dns: Add resolve API
This commit introduces a generic DNS resolving API that can
be used by applications. Later commits will introduce a system
level DNS support which simplifies the DNS resolving so that
DNS server names can be given from config file.

Change-Id: I60fbc81e2a44928d2ca53d51e703b9cde222b382
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:42 +02:00
Jukka Rissanen 2149ec599e net: ipv6: Adding router mgmt add/del events
If IPv6 router is added, then NET_EVENT_IPV6_ROUTER_ADD event
is generated. When router is removed, NET_EVENT_IPV6_ROUTER_DEL
is then generated. This is useful info if we want to have a generic
connectivity to outside of our local network.

Change-Id: Ia03958a071ceb998127894025c99ab72a8b648d5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:41 +02:00
Gil Pitney 657ad14234 net: offload: More decoupling of net_offload from l2 naming
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

- Rename struct net_l2_offload_ip to struct net_offload
- Rename struct field offload_ip to just offload
- Rename include/net/offload_ip.h -> include/net/net_offload.h

Change-Id: I3cd891c2b13e0e8f3ad1c66264f90b5031ae17c2
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Gil Pitney 3209c22d79 net: offload: Move offload_ip field from net_l2 to net_if
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

This provides a more direct call stack from the net_context APIs
to the offload driver functions, versus going through the current
offload L2 (dummy) driver.

Change-Id: Ia5a677d87f7b62f54b2702ce8ecfaf026f6f7c26
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Gil Pitney adb2e7ea2e net: offload: Rename Kconfig NET_L2_OFFLOAD_IP to NET_OFFLOAD
This is part of a patch series to decouple TCP/IP offload, which
currently occurs at the transport layer (L4), from the data link
layer (L2).

This patch simply renames the NET_L2_OFFLOAD_IP Kconfig variable
to NET_OFFLOAD.

Change-Id: Ic8b1d004cbac09b7c636475aaed75b0a31e4be1c
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-03-24 17:31:40 +02:00
Jukka Rissanen 1061ce302a net: route: Try to route IPv6 packet if we are not the recipient
Instead of simply dropping the packet if the destination IPv6
address is not ours, try to figure out if there is a route
to real destination and then re-route the IPv6 packet there.

Change-Id: I6b2a0d7096b3d7877b82b04f38e3a6e588587c11
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-24 17:31:39 +02:00
Tomasz Bursztyka d6d1b3a748 net/mgmt: Add a network interface based synchronous event listener
In case of callback based event listener, it is easy for the callback to
filter on the given interface. But in case of the synchronous call it's
not: it would need, after a failed comparison on the interface pointer
to loop by itself on the net_mgmt_event_wait() which is a little bit
heavy (reinstalling the event listener, with the semaphore and all) and
a bit of a burden for the caller itself.

Instead, net_mgmt provides a dedicated call
net_mgmt_event_wait_on_iface() which does it the right way, so the
callback and the related semaphore are destroyed if only the iface
matches the one given as parameter (besides the timeout obviously).

Change-Id: Iab05c3249586f4f4d0447eea42fdac72b8428f2e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Tomasz Bursztyka 35e5aa8865 net/mgmt: Add a function to wait on a event synchronously
Instead of creating a handler and a related callback structure on an
event_mask: net_mgmt_event_wait() can be used to wait synchronously on
such event_mask. The core mgmt part will seamlessly reuse the struct
net_mgmt_event_callback so the whole internal notification mechanism is
using the same code.

Change-Id: I426d782c770e75e5222aa3c5b703172b1f1f2e5e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-17 10:34:42 +02:00
Flavio Santes 8308b9bd2d net/http: Add the HTTP/1.1 API
This patch adds the HTTP/1.1 API for Zephyr. This API consists of client
and server context structures enabled via Kconfig variables.
HTTP parser support is enabled via the CONFIG_HTTP_PARSER configuration
variable.

Currently, this API only includes support for writing HTTP requests
(client mode) and HTTP responses (server mode). TLS support is not
considered in this iteration.

Supported HTTP methods:
	GET, HEAD, OPTIONS and POST.

Supported HTTP responses:
	400, 403 404. The http_response routine may be used to write
	any HTTP status code, for example 200 OK.

Jira: ZEP-1701

Change-Id: Ic9ccd4d4578d6d0f3a439976ea332b031644ca7d
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-09 20:33:49 +02:00
Tomasz Bursztyka e38a9e8b9c net: Switch from per-iface tx thread to a unique k_poll triggered one
Now that k_poll landed in the kernel, it's worth using it to save
memory and reduce the number of threads at runtime.

Such switch has been first done in bluetooth (see hci_core.c and conn.c
in subsys/bluetooth/host). Since network interfaces kind of follows the
same design for sending data, it was then easy to copy the same change as
in bluetooth.

Change-Id: I7f9734b88ac818284bbabaedc946b4765b905ebb
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-03-09 20:33:49 +02:00
Jukka Rissanen 75b550e81d net: ipv6: Collect MLD statistics
Collect number of received, sent or dropped multicast listener
reports and queries.

Change-Id: Ia5c08203155475763f96df23f44eceffa7569873
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen 82267e7bd4 net: ipv6: Allow joining to existing multicast address
If the multicast address already exists, then do not give
error but try to join it.

Change-Id: I32ffa6b3bf0798011d684a1a21e87e389f1f0380
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen f8467437e6 net: if: Leave all joined IPv6 multicast groups at net_if_down
When network interface is taken down, leave only those
IPv6 multicast groups that were joined.

Change-Id: I414556c093ba67be7c13e6c86e0451465c2203f3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Jukka Rissanen c3c76f35cc net: ipv6: Notify others if we join/leave IPv6 mcast group
Send management event if we joined or leaved IPv6 multicast
group.

Change-Id: Ieeb407ef88fb3bf4cd92d4fb4b69f03b260474e7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:48 +02:00
Patrik Flykt 7380d25ffc net/trickle: Include net_core.h in order to define NET_ASSERT
net/net_core.h is not included by default in trickle.h, which can leave
NET_ASSERT undefined.

Change-Id: Ifadeacc745d6623f096e06c16bfb4dfa6a880a40
Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>
2017-03-09 20:33:47 +02:00
Jithu Joseph bf5263a552 net: ip: Address type mismatch warnings
These were flagged by icx compiler.

Jira: ZEP-1811 , ZEP-1809

Change-Id: I0dff800ce2bb440b39dceb08b145e085be4c8caf
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2017-03-09 20:33:46 +02:00
Jukka Rissanen f8c60de061 net: nbuf: Create net_nbuf_frag_del() for tracking allocations
Create net_nbuf_frag_del() so that we can track net_buf frees.
If CONFIG_NET_DEBUG_NET_BUF is not defined, then this new function
will call net_buf_frag_del() directly, and if not, then it will
track memory usage.

Change-Id: I5f382436cebc71fdaf12baf7bf964fb63bee7aca
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 38d26d07e9 net: nbuf: Track memory allocations
User can track memory allocations and deallocations.
This is enabled by CONFIG_NET_DEBUG_NET_BUF option.

Change-Id: I9d83b9b63fb2b141c9a283887f1770bb4232f61c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 57150538bd net: nbuf: Remove obsolete reserve variable from net_nbuf
There is no user for the reserve variable inside struct net_nbuf
so remove it.

Change-Id: I45750215cefa2227002eb2de57f080823e7013ce
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:44 +02:00
Jukka Rissanen 5197266768 net: nbuf: Use net_nbuf_get_frag() to allocate a fragment
The code used net_nbuf_get_reserve_{rx|tx}_data() function to
allocate a fragment. Instead of that low level function, use
net_nbuf_get_frag() instead. There are few places this is not
possible or is too big change like in few test programs.

Change-Id: Ied7e2b7db352de998b200ffa6ff82471bfa5ebe3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen d32503f57e net: nbuf: Split one global DATA pool to RX and TX DATA pools
If we receive lot of packets, it might happen that we exhaust
all the DATA buffers in the system. This would prevent from
us sending anything to the network.
Change this by splitting the DATA buffer pool into RX and TX
parts. This way RX flooding cannot consume all DATA buffers
that needs to be sent.

Change-Id: I8e8934c6d5fdd47b579ffa6268721b5eb3d64b6d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen eb35c8dcae net: nbuf: Add helper function to copy buf user_data
The function copies the net_buf user data (struct net_nbuf).

Change-Id: I2ea42823d58aea77ea7b710f6ce5fd5d1e3641b4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:43 +02:00
Jukka Rissanen 4bcc2a47d0 net: nbuf: Fix net_nbuf_copy() so that original nbuf is not modified
It makes no sense to modify the original net_buf so change the
copy function not to touch the original buffer.

Change-Id: I5d22445ce50cee62994c36567f0e995a500cb89d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 6a4372b0df net: nbuf: Fix the net_nbuf_copy() buf parameter
The first parameter of net_nbuf_copy() must be the head
of the buffer chain i.e., it must contain the user_data
part. If a fragment is given, then we do not know enough
information to allocate the data fragments.

Change-Id: I052b183d8c63d7326b320254f36f00b2fc48b0a0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen a5dbf31b3a net: shell: Print network buffer pool information
Print information about various network buffer pools in the
system. This is useful in debugging the buffer allocations.

Change-Id: I31123c6f1f6647f77503f32e268c174330762128
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 230de764a9 net: buf: Store name of the buffer pool
This is used to show the name of the pool during debugging.

Change-Id: I3a3c3c853e5fe13fd11f6ffd9e1feea4abf0c248
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 7719cee113 net: Add net_buf pool support to each context
User can configure its own pools for data that needs to
be transmitted out (TX). This helps to avoid deadlocking
the system if user space application uses all the buffers
in the system, and the core IP stack tries to get buffer
that needs to be sent out.

By default the net_buf pool support in net_context is turned
off as application developer needs to create the pools and
tie them to desired contexts.

Change-Id: Ida4a1771d34d6c250974e56fba4f0e0b2592cb29
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 7218d0d64b net: buf: Add more accounting info to net_buf pool
Adding this information to the pool:
* number of available (free) buffers in pool
* total size of the pool in bytes

This can be used when debugging net_buf pool allocations.

Change-Id: I4212fcddb1affdf53e0827c88473d3380e2a4929
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft 7c193b7f9f net/dhcpv4: Support REBINDING
Change-Id: I1e3809b3cde1dec29a001e750cb191cfac046dab
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:42 +02:00
Marcus Shawcroft 3726bb98bd net/dhcpv4: Introduce start/stop API and disabled state.
Change-Id: Iae3b96dd91325ecf51b33b8c58f65aa5ec2b40c9
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft 81c0d5fb3d net/dhcpv4: Explicitly initialize net_if dhcpv4 state.
Change-Id: I1ded49223f3b19ae26eb8cd346d00121bfb6721b
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:41 +02:00
Marcus Shawcroft b840664c11 net/dhcpv4: Adjust state names to reflect rfc2131
The dhcpv4 state machine implementation names differ from the names
used by the relevant rfc.  There is no good reason for them to be
different, so rename them.

Change-Id: I837f1bc4788c0ed4d2949b12eb6f5bfeef9a0be8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 1f279e13b3 net/dhcpv4: Unify dhcpv4 state name printers
There are two implementations of dhcpv4 state name numbers to human
readable strings, unify the two.

Change-Id: I1d654918bb919108a0d8c5514b309b193c9c3f96
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marcus Shawcroft 8df38dc55f net/dhcpv4: Move timers inside the net_if dhcpv4 context
The dhcpv4 state machine has a dedicated context within each net_if
structure.  For reasons unknown the timers used by the dhcpv4 state
machine have been placed in net_if outside of the dhcpv4 context area.
Relocate them into the dhcpv4 context.

Change-Id: I0531f493610dffda9ca9208993597a5665bde997
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-03-09 20:33:40 +02:00
Marti Bolivar 3dc31f61e8 net/buf.h: fix copy-paste Doxygen error
Fix Doxygen for net_buf_simple_push_be16().

Change-Id: Ief834565658f5b4b919dcc77b6fd9350c5e2835a
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-02-27 10:28:55 +02:00
Marcus Shawcroft f998077f4a net/if: Fix documentation comment marker.
Documentation comments should begin with /**

Change-Id: I59867e8aad340dac4d66f86e09f4f8ae9d3d75fb
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-27 10:28:55 +02:00
Marcus Shawcroft 4cab8fe154 net/nbuf: Fix spelling.
Change-Id: I821c796b2d5c9d6424be2d26509ad5f72dfe110b
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-27 10:28:55 +02:00
Jukka Rissanen b892c4c61b net: ipv6: Bluetooth address fix
If IPv6 address is generated from Bluetooth MAC address,
then the Universal/Local bit must not be toggled or touched
at all. See RFC 7668 ch 3.2.2 for details.

Because this change is not compatible with older Linux kernel
BT IPSP support, the old behavior can be enabled by setting
CONFIG_NET_L2_BLUETOOTH_ZEP1656 option.

Change-Id: I05d48723b70f1eb60fbd46107ef6a2a4e8f9154a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-27 10:28:55 +02:00
Vinicius Costa Gomes 8e304ef2e6 iot/zoap: Fix requiring that the buffer is unchanged for retransmit
It is possible that the buffer waiting for retransmission is modified
after it is sent, for example, it can be compacted by 6lo, and our
assumption of where is the message ID is located in the buffer is no
longer valid.

As the message ID is the only information that is necessary for
keeping track of retransmissions, we keep a copy of it in the pending
struct, as well as the destination address of the retransmission.

Change-Id: Id33d54353404628673541225a1a05e27ee08765f
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-27 10:28:54 +02:00
Jukka Rissanen 75c48fcbf2 net: buf: net_buf_frag_del() had insufficient debugging
In order to see who is freeing the fragment, add function
and line information to net_buf_frag_del() when net_buf
debugging is activated.

Change-Id: I732f579fab2390cb16804cb35b83f46e65fca342
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:26 +02:00
Tomasz Bursztyka 799ad12ec5 net: Fix stack type
s/unsigned char/char

Jira: ZEP-1723

Change-Id: I07b23b28fdb4d2f0f78dcdd314faaebec06471db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen a5605cedb0 net: ipv6: IEEE 802.15.4 short address fix
If IPv6 address is generated from IEEE 802.15.4 short address,
then the Universal/Local bit must be set to 0.

See RFC 6282 chapter 3.2.2 for details.

Change-Id: Ied38f40e807bdcd792570b331f6b99a6fcc7db1b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen b9c497ac49 net: nbuf: Set the link address type in nbuf
When we know the network interface where the packet is about
to be sent, then set the link address type too.

The link address type is used when working with IPv6 link
local and auto configured addresses.

Change-Id: If086c3c413c025809cffa64311f973bc7bdac7db
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen 4eb2020055 net: Set the network link address type when setting link address
The interface L2 address type is set at the same time as the
L2 address is set to the network interface. This is most
convinient place to set the address type.

Change-Id: I712d7357d075959eb79df3463141cfbc6d163a74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:25 +02:00
Jukka Rissanen 24b66f4670 net: Add network link technology type to linkaddr
In order to know what kind of address the L2 link address is,
add a type of the address into struct net_linkaddr.

Change-Id: Icd4cb0374219583689cf9ee204c0840cad8559e9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:24 +02:00
Tomasz Bursztyka a180deaaf5 net: Remove duplicate const specifier
Jira: ZEP-1723

Change-Id: I0b305f7104a7a6248852846542b6894c86bfc1d8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-15 12:20:08 +02:00
Flavio Santes 057f31e7e9 net/mqtt: Remove length computations for some msg fields
Currently, for the following MQTT msg fields:

- client_id
- will_topic
- user_name
- topic

their length is computed inside the routine that receives the MQTT msg.

Although this simplifies development, also imposes one restriction:
data must be null-terminated. Sometimes, data is received from other
sources and not generated by the application, so the null-terminated
constraint may be considered problematic for the user.

This patch removes the assumption that string fields are null-terminated.
Current data structures are already prepared to handle this case, so no
API change is required.

Change-Id: I5a147a5b21e0da49541cbe62baac363c8737cd3e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-15 12:20:08 +02:00
Tomasz Bursztyka f0f9be881f net: Fix a const specifier issue
Duplicate const specifier, it should be the pointed data that is const.

Jira: ZEP-1723

Change-Id: I194abb0fc9ad564c6d53e4727bd63c8099d4eb2e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-15 12:20:08 +02:00
Marcus Shawcroft ccd6d8c79f net/dhcpv4: Remove unused dhcpv4 offer state
The offer state is unused, remove it.

Change-Id: I9d6217dae291bb90c57c77ce439809bf7e9a9177
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-14 08:30:34 +02:00
Flavio Santes bed71d0a02 net/mqtt: Fix inline doc for MQTT
Fix inline documentation for the MQTT API.

Jira: ZEP-1669

Change-Id: I90702eae236a9189b58e0f2fb2a6c5a3eeaf959c
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-14 08:30:34 +02:00
Vinicius Costa Gomes d8d16e81f5 iot/zoap: Add missing const modifier to header file
Makes it cleared that zoap_update_from_block() doesn't modify the
packet.

Change-Id: I35429b153370c50eb5ae9c914b47a3144faf2f04
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-14 08:30:33 +02:00
Vinicius Costa Gomes b032f54f60 iot/zoap: Fix header indentation
Change-Id: Iea2dd0f2493e240caa33f81fa68e5be894f0de86
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-14 08:30:33 +02:00
Vinicius Costa Gomes 0c94d6a085 iot/zoap: Improve zoap.h documentation
Now types and functions have better explanations of their usage and
parameters associated.

Jira: ZEP-1657

Change-Id: I146688324080ac3cf0876f1db3c92c9514e1303d
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-14 08:30:33 +02:00
Jukka Rissanen c3b0f35f6f net: if: Change the iface param in net_if_ipv6_maddr_lookup
Change the handling of iface parameter in net_if_ipv6_maddr_lookup()
function:
  * If the *iface is set to NULL, then return the found
    interface to the caller.
  * If the *iface is not NULL, then use that interface
    when doing the lookup.

Change-Id: Ia1f0365170ea9f3e615d189231160614a80d241a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:26 +02:00
Jukka Rissanen c357349e44 net: if: Change the addr param type in net_if_ipv6_maddr_add/rm
Make the IP address parameter const because we are not
modifying the IP address in net_if_ipv6_maddr_add() or
net_if_ipv6_maddr_rm()

Change-Id: I98c19de132e58c386f661e8a76a349d562a82c71
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Jukka Rissanen c0f6a5ecd8 net: nbuf: Fix constness of data param in net_nbuf_append
As the function does not change the original data, make
the corresponding parameter const.

Change-Id: I1125a2f9205dc73de2f0aac0c30110591baace1e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-10 11:25:25 +02:00
Marcus Shawcroft 8cd2e089d6 net/dhcpv4: Add further diagnostics.
Change-Id: I13fed6b6102d7711082f16de3f782c606808b142
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-02-09 14:27:10 +00:00
Gil Pitney 8c143090ba net: offload_ip: Update net_context_accept_cb_t to net_tcp_accept_cb_t
This is required to allow an "IP Offload" driver to build,
once CONFIG_NET_L2_OFFLOAD_IP is enabled.

This fixes the offload_ip.h header following the change made by
commit eb9055c019
("net: tcp: move accept_cb from net_context to net_tcp")

Change-Id: I1a6010c2dbdfc5e74a2ae172aa0167783f4a0cfe
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
2017-02-09 09:43:06 +02:00
Ravi kumar Veeramally 58ba1d834e net: nbuf: Fix net_nbuf_compact() API
Current API description of net_nbuf_compact() is not very clear.
The first parameter needs to be the first net_buf in the chain.

The changes to this API are needed in order to clarify following
use cases:
1) User provides fragment that is not first of the chain and compact is
successfully done. In this case there is no free space in fragment list
after the input fragment. But there might be empty space in previous
fragments. So fragment chain is not completely compacted.

2) What if input fragment has been deleted and api returns the same
buf?

So this commit simplifies the API behavior. Now net_nbuf_compact()
expects the first parameter to be either TX or RX net_buf and then it
compacts it. It fails only if the input fragment is a data fragment.

Change-Id: I9e02dfcb6f3f2e2998826522a25ec207850a8056
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Ravi kumar Veeramally 999338ea94 net: nbuf: Remove unused net_nbuf_push() API
The net_nbuf_push() API is not used by anyone. Semantics are not
clear and following patch requires changes to push api, so removing
this API for now. If needed this can be re-introduced later.

Change-Id: I1d669c861590aa9bc80cc1ccb08144bd6020dac5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-08 10:12:36 +02:00
Jukka Rissanen bd3908b2a9 net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h
by adding a timeout parameter. These function prototypes
are changed to accept a timeout parameter.
	net_nbuf_get_rx()
	net_nbuf_get_tx()
	net_nbuf_get_data()
	net_nbuf_get_reserve_rx()
	net_nbuf_get_reserve_tx()
	net_nbuf_get_reserve_data()
	net_nbuf_copy()
	net_nbuf_copy_all()
	net_nbuf_push()
	net_nbuf_append()
	net_nbuf_write()
	net_nbuf_insert()

Following convinience functions have not been changed
	net_nbuf_append_u8
	net_nbuf_append_be16
	net_nbuf_append_be32
	net_nbuf_insert_u8
	net_nbuf_insert_be16
	net_nbuf_insert_be32
	net_nbuf_write_u8
	net_nbuf_write_be16
	net_nbuf_write_be32
so they call the base function using K_FOREVER. Use the
base function if you want to have a timeout when net_buf
is allocated.

Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-08 10:12:35 +02:00
Anas Nashif 6fa71b8302 net: nbuf: Fix style of doxygen comment
Change-Id: I791a2b585cc008bd9101957f1ca0540be1220833
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-02-08 10:12:34 +02:00
Flavio Santes 362a12200a net/dns: Fix inline documentation
Fix inline documentation for the dns client API.

Jira: ZEP-1669

Change-Id: I9e6ae4e1301f1e4a125b75add1a8bc7331a818b0
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-07 22:33:47 +00:00
Johan Hedberg dc42b2df43 net: buf: Fix timeout parameter documentation
The timeout given to APIs is in milliseconds and not ticks.

Change-Id: Iae198ca3aee326c19d0894a22f6e5cfca19ba131
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-03 15:24:07 +00:00
Jukka Rissanen 6930f93fd3 net: stats: Collect bytes sent and received
Keep track of amount of bytes that are sent or received from
all network interfaces.

Change-Id: I706481aab1a7e0cf2bc78d032f2ef4ebbabe3184
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-03 15:59:20 +02:00
Ravi kumar Veeramally df201a0e4b net: context: Assign a random port number when context is created
Current behaviour has an issue when UDP context is created with local
port number 0, net_conn_input() happens to treat zero port as
a wildcard ("receive packets for all ports"). net_context_bind()
for a UDP context doesn't affect its existing connection in any way.

Proposed solution is, context should be created with a random free
port assigned and bind() updates connection information from context.

Jira: ZEP-1644

Change-Id: Idb3592b58c831d986763312077b0dcdd95850bc9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:20 +02:00
Luiz Augusto von Dentz 2c1bef4d09 net: Introduce NET_IF_POINTOPOINT flag
This flag can be used by driver to indicate pointopoint links which should
not require destination link address to be resolved.

Jira: ZEP-1656

Change-Id: I58dd3bf48485d6203e75373497e00668317b9825
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-03 15:59:19 +02:00
Vinicius Costa Gomes 2d852f47d2 iot/zoap: Fix the return value of zoap_packet_get_payload()
The returning 'len' was always informing the remaining available space
in that net_buf fragment. This not the expected behaviour for
incoming packets, in this case, we really want the size for the
payload already present in the packet.

When this function is called with a packet without a payload, with
will return the available space in the packet, when the payload is
already set, it will return the size of that payload.

Change-Id: Ia4643b8c2a015ad2316bed037e457b186e420b19
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka f2872e60ad net/ieee802154/mgmt: Add getters/setters for various radio network info
Channel, pan-id, short and extended addresses.

Change-Id: Ib63dadac37d649df3efc8fdd67f5312d3a7c8e20
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:19 +02:00
Tomasz Bursztyka 8d7eb6ed2b net/ieee802154: Set IEEE extended address whatever runtime mode it is
ORFD or RFD does not matter: the extended address should be set
according to device's MAC address.

Change-Id: I39d09c3a953283eeaa30b908ea159638604bd72b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:18 +02:00
Tomasz Bursztyka 12a0f71711 doc/api/networking: Add existing network protocol libraries APIs
DHCPv4, MQTT, DNS client, ...

Change-Id: I5c5d7437bb53610678eba38d307c86694ac01da9
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 9e6a6f3bce net/mqtt: Add the "malformed" callback to the MQTT ctx structure
Add the malformed callback that will be executed when a message
is received and it does not follow the MQTT v3.1.1 spec.

There is another case when this callback may be executed: when
the IP stack reception buffer's size is not enough to hold an
MQTT message.

The publisher and subscriber parser routines are updated to make
use of this callback. Inline documentation is also updated.

Change-Id: Id1d34336c4322673ca85f2db0b8d432db3c9afa8
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Flavio Santes 4a17932d6a net/mqtt: Simplify the MQTT high-level API
1) Remove some variables pointing to user-provided data.
2) Pass the context structure instead of those variables.
3) Homogenize the use of "ctx" for all the callbacks receiving the
   struct mqtt_ctx * pointer.

Now users must use the CONTAINER_OF macro to access data required
by the MQTT callbacks.

Change-Id: I871c0bd8601a67b39187683215579f9ed0087cf9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-02-03 15:59:18 +02:00
Tomasz Bursztyka d8323e1a6c doc: Include main Network APIs doxygen documentation
Added missing dogygen definitions.

Jira: ZEP-1495

Change-Id: Ibc087f3f174b8af45b0726c0d82b77feff36d4e3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-02-03 15:59:17 +02:00
Andy Ross 5d6e0d425b net: tcp: Clean up net_context lifecycle
The death of a network context was sort of a mess.  There was one
function, net_context_put(), which was used both by the user as a way
to "close" the connection and by the internals to delete it and to
"clean up" a TCP connection at the end of its life.

This has led to repeated gotchas where contexts die before you are
ready for them (one example: when a user callback decides the
transation is complete and calls net_context_put() underneath the
receive callback for the EOF, which then returns and tries to inspect
the now-freed memory inside the TCP internals).  I've now stepped into
this mess four times now, and it's time to fix the architecture:

Swap the solitary put() call for a more conventional reference
counting implementation.  The put() call now is a pure user API (and
maybe should be renamed "close" or "shutdown").  For compatibility,
it still calls unref() where appropriate (i.e. when the context can be
synchronously deleted) and the FIN processing will still do an unref()
when the FIN packets have been both transmitted and acked.  The
context will start with a refcount of 1, and all TCP callbacks made on
it will increment the refcount around the callback to prevent
premature deletion.

Note that this gives the user a "destroy" mechanism for an in-progress
connection that doesn't require a network round trip.  That might be
useful in some circumstances.

Change-Id: I44cb355e42941605913b2f84eb14d4eb3c134570
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-02-03 15:59:14 +02:00
Ravi kumar Veeramally b13f44bcdd net: utils: Add net_addr_ntop() helper function
net_addr_ntop() will convert IPv4|6 address to string form.
Renamed existing net_sprint_ip_addr_buf() to net_addr_ntop()
and adjusted parameters as per API.

Jira: ZEP-1638

Change-Id: Ia497be6bf876ca63b120529acbadcfd9162a96e3
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-02-03 15:59:14 +02:00
Michael Scott ca6a686495 net: correct in*_addr parameter of net_addr_pton()
Currently, the function accepts a struct sockaddr * but the code
immediately type casts this to either in_addr or in6_addr.  This is
incorrect behavior as the first field in a sockaddr is sa_family_t
and not address data.

So without special knowledge, a developer will use a sockaddr structure
as the parameter and then wonder why the address information isn't being
set correctly.

Let's change this parameter to void * which makes this function similar
to inet_pton().

Jira: ZEP-1616

Change-Id: I1fc9368da999d90feb07c03fac55dcc749d4eba6
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-02-03 15:59:13 +02:00
Tomasz Bursztyka 83ed3a29be net/ieee802154: Modify radio TX function signature
The cause for this change is TCP. Until now, the radio strategy driver
(ALOHA or CSMA) was providing the actual nbuf, and not the buffer
fragment, counting on the fact that the loop was using
net_buf_frag_del() which made so, iteration after iteration, buffer
framgent to be always buf->frags. The problem with this logic is loosing
the fragments that might be still referenced by TCP, in case the whole
buffer did not make it so TCP can retry later and so on.

Instead, TX now takes the nbuf and the actual frag to send. It could
have been working with just a pointer on the data, and the whole length
of the frame. But it has been avoided due to possible future devices,
that will be smarter and run CSMA directly in the hw, thus it will
require to access the whole buffer list through the nbuf.

Change-Id: I8d77b1e13b648c0ec3645cb2d55d1910d00381ea
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:53 +02:00
Tomasz Bursztyka aa84d81f25 net: ip: Add a useful macro to staticaly initialize a struct in_addr
As for IN6ADDR_ANY_INIT, let's have an INADDR_ANY_INIT.

Change-Id: I07c9ec6d2bb20d3a228edaac2e3380942feac5fd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:52 +02:00
Ravi kumar Veeramally c34cb8236e net: ip: Check error conditions and return false
Check if input parameters are valid or not. It might lead to crash
NULL address input.

Change-Id: Ib446ab0467268bca01f478cca3ece868c7c9e49b
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:52 +02:00
Andy Ross 7b27d4be0a net: tcp: Make the connect callback on success, not transmission
The net_context_connect() callback was being invoked synchronously
with the transmission of the SYN packet.  That's not very useful, as
it doesn't tell the user anything they can't already figure out from
the return code.  Move it to the receipt of the SYNACK instead, so the
app can know that it's time to start transmitting.  This matches the
Unix semantics more closely, where connect(2) is a blocking call that
wakes up only when the connection is live.

Change-Id: I11e3cca8572d51bee215274e82667e0917587a0f
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-27 12:35:52 +02:00
Jukka Rissanen 088289ec28 net: context: Add status to connect callback
It is useful that the user API can know whether the connection
was established properly or not. So this commit adds status
parameter to connect callback in net_context API.

The call to connect callback needs to be set properly in TCP
code. This commit does not fix the connect callback call which
is not properly done right now in net_context.c.

Change-Id: I284a60ddd658ceef9e65022e96591f467a936a09
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:21 +02:00
Michael Scott 72e013a7ba net: tcp: add timeout wait in net_context_connect
If the parameter "timeout" is set in net_context_connect(), the
assumption by the user is that the function would wait for SYNACK
to be received before returning to the caller.

Currently this is not the case.  The timeout parameter is handed
off to net_l2_offload_ip_connect() if CONFIG_NET_L2_OFFLOAD_IP is
defined but never handled in a normal call.

To implement the timeout, let's use a semaphore to wait for
tcp_synack_received() to get a SYNACK before returning from
net_context_connect().

Change-Id: I7565550ed5545e6410b2d99c429367c1fb539970
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott eb9055c019 net: tcp: move accept_cb from net_context to net_tcp
net_context is used for more than just TCP contexts.  However,
the accept_cb field is only used for TCP.  Let's move it from
the generic net_context structure to the TCP specific net_tcp
structure.

Change-Id: If923c7aba1355cf5f91c07a7e7e469d385c7c365
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00