Commit graph

1260 commits

Author SHA1 Message Date
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
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
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
Michael Scott
34b67374de net: net_context: correct description of recv_data_wait in net_context
The recv_data_wait field in struct net_context is described as a "Mutex"
when in fact it's a semaphore signal.

Change-Id: I3bef8d1a07ceb3da5894ae4cdc8f1fe3c61c5dbe
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Jukka Rissanen
700c313ce7 net: buf: Use TCP sent_list variable only if needed
If TCP is not enabled, then compile out the TCP retransmit
list variable that is part of net_buf struct.

Change-Id: I07e188454d9be76ac93fe96405f00a89b967668a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:20 +02:00
Vinicius Costa Gomes
d27cc52f37 iot/zoap: Add a helper to find an observer by address
In some situations, for example, when the remote side sends a RESET
message indicating that it is no longer interested in observing a
resource, it is helpful to have a way to obtain the obverser
representation.

Change-Id: Ifbf627f9170be844fd525c557dda8cb722ac7aff
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes
e49ae1c6e2 iot/zoap: Clarify the return value of zoap_register_observer()
Change-Id: Ib30a81d424d8db13399d57851622d75be5f7c010
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes
4c636eef6a iot/zoap: Add response code for Continue status
This status is used when a blockwise transfer should continue with the
next block.

Change-Id: If68c32aea8c0b63efcd929cdff57f0ff235b2792
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen
ba026941a1 net: ipv6: Fix IPv6 prefix comparision
If the prefix length % 8 is not 0, then the remaining
bit length was calculated incorrectly and the prefixes
were claimed to match even though they might not be the
same.

Adding a test cases for testing this properly.

Coverity-CID: 157591

Change-Id: I9cb5a73d5cc211ec183176400fa5e2dfd209e2da
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Michael Scott
7b674cb287 net: linkaddr: introduce net_linkaddr_set function
The net_linkaddr_storage structure contains an array of bytes used
to store the link address.  This array can be different sizes
depending on the CONFIG options used when building.  To facilitate
consistency and error checking let's introduce a new helper function
to copy the addr and len values to this structure.

Also move all uses of memcpy related to net_link_storage structures to
the new helper function.

Change-Id: Ic547d86b07e62e5ac3bc330d4eaeb4508a143200
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott
4aad767328 net: linkaddr: calculate linkaddr storage addr size via config
- Introduce NET_LINK_ADDR_MAX_LENGTH which is either 6 or 8
  depending on whether CONFIG_NET_L2_IEEE802154 is used
- Instead of being a placeholder single index array of uint8_t,
  let's use NET_LINK_ADDR_MAX_LENGTH to assign the size of the
  "addr" array field in the net_linkaddr_storage structure.
- Now that the "addr" field of net_linkaddr_storage contains the
  true size of the link address, we can remove "storage" field
  which was hard coded to 8 bytes (2 uint32_t's).
- Fix 2 references to the "storage" field of the net_linkaddr_storage
  structure.

Change-Id: I2ea12058280b289f65085964eb7d503d4fd260c2
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
David B. Kinder
ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Luiz Augusto von Dentz
e13a899280 net: bt: Add disconnect management command
This adds NET_REQUEST_BT_DISCONNECT which can be used to disconnect
IPSP in case it is connected.

Change-Id: I8da00b02ee08611bef5f4c0708936b2d31fd2a93
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:30 +00:00
Luiz Augusto von Dentz
4eae48ee64 net: bt: Add scan management command
This adds NET_REQUEST_BT_SCAN which can be used to scan peripherals
advertising IPSS UUID.

Change-Id: I2463079d182b4da080e6ef94d883c7c1e24a454c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:04 +00:00
Luiz Augusto von Dentz
b434d0f50b net: bt: Add connect management command
Connect command can be used to initiate a connection, which in IPSP
terminology refer to a router role.

Change-Id: I12b9428924c88a9c68d3adbfe9016a0dd690aade
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:26 +00:00
Luiz Augusto von Dentz
56261b21cc net: mgmt: Make NET_MGMT_GET_* macros return meaningful values
They should return the same value as in NET_MGMT_LAYER and
NET_MGMT_LAYER_CODE.

Change-Id: Ia95adcd3b6b6aaf0ed29f3260bc54784ca532d8f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:34:35 +00:00
Tomasz Bursztyka
55d653f52f net: mgmt: Silently ignore net_mgmt_event functions if not enabled
When CONFIG_NET_MGMT_EVENT is not set, it will still be able to compile
code using net_mgmt_event related functions.

Change-Id: I6824c57093636867ea4228338aa6c02913975510
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-13 11:35:41 +01:00
Andy Ross
96294b79a7 net: tcp: Signal EOF with a NULL buffer in the callback
TCP didn't actually have a way to signal synchronous receipt of a FIN
packet.  Extend the recv_cb API to allow a NULL buf argument with
status==0 (by analogy to Unix's zero-length read) to signal EOF.

Update docs too, and also echo_server which wasn't prepared to handle
this situation.

Change-Id: I7dc08f9e262a81dcad9c670c6471898889f0b05d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-13 10:29:03 +01:00
Michael Scott
22bd26cba7 net: net_context: state setting is a value not individual bits
The state of a net context is checked as a whole value (not individual
bits).  Currently, the net_context_set_state function is adding the
passed in flags to the existing value.  This is incorrect.

Change-Id: Ieba6b9dfc35537745b14c50a2ccb115c6976c001
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Tomasz Bursztyka
6b41aecd99 net: ieee802154: Expose basic network parameters through net mgmt API
It is then possible to set the channel, pan_id and short address through
this API. Such features are mainly useful for testing purposes.

Change-Id: I41aeb397afdb231458a3b13638f3e13d3ac28a6c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 12:27:01 +01:00
Flavio Santes
30225d5ef1 net/dns: Fix documentation issues
Fix some documentation issues found at the dns_client.h file.

Change-Id: I3c1138f55b182ad2507b2cc3a4a50dc874a0d730
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes
76e479974a net/mqtt: Allow an MQTT publisher app to receive msgs
Changes applied by this patch:

- Add the mqtt_publisher_parser routine
- Add the MQTT_PACKET_TYPE macro to get the MQTT msg packet type
  (required by mqtt_publisher_parser)
- Add the mqtt_linearize_buffer (required by mqtt_publisher_parser)
- Add the mqtt_recv callback for reception
- Modify the mqtt_init routine to install the reception callback

The mqtt_publisher_parser routine is a callback used internally
to execute the appropriate mqtt_rx routine. Only the following
messages are handled by this routine:

MQTT_CONNACK, MQTT_PUBACK, MQTT_PUBREC, MQTT_PUBCOMP and MQTT_PINGRESP.

On error, it executes the ctx->malformed cb, if defined.

This commit also introduces the mqtt_linearize_buffer routine that
will be used to linearize an IP stack fragmented buffer. This patch
makes use of the net_nbuf_linear_copy routine to linearize the
incoming buffer. mqtt_rx_xxxx routines are also updated to handle
linear buffers (no fragmentation).

Currently, all the network protocol routines assume that the input
buffer is not fragmented. Future versions will remove that assumption
and the mqtt_linearize_buffer routine will be removed as well.

Public MQTT API is not affected by this patch.

Change-Id: I02fece67052ffbc7cb393d5ca545c503da463c4b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes
bf88fe5118 net/mqtt: Add the reception callback
The reception cb: internal use only cb that will be set according to
the application profile: PUBLISHER, SUBSCRIBER, PUBLISHER & SUBSCRIBER
or SERVER.

Change-Id: Ib36b0686deb9220e507f9e468aae1b1191c35d31
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes
d490ff27ad net/mqtt: Add the mqtt_rx_publish routine
The mqtt_rx_publish is used to process incoming MQTT PUBLISH
messages. This routine performes the following steps:

- take ownership of the rx buffer containing the MQTT PUBLISH msg,
- call the MQTT parser routine, and
- determine, based on the incoming message's MQTT QoS,
  the next action.

Change-Id: I3cc011cf0c280205161d0484f12a2cfa79fdf44a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes
ab042f2997 net/mqtt: Add missing function prototypes
Some public function prototypes are missing, so this commit adds
them to the mqtt.h header.

Change-Id: I57a50ce346f086f55e499bfc8c815fd161a52f7b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes
edfaeba73d net/mqtt: Use the right data type
Use the appropriate data type for some variables:

- const input arguments
- int32_t instead of uint32_t for timeout
- uint8_t instead of int for variables that take just a few
  possitive values.

Change-Id: Id7d762b400fa17e6751829ac401cd7c13aabb7b2
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes
c015c0e2c8 net/nbuf: Introduce the net_nbuf_linear_copy routine
This commit adds one routine previously found at the DNS resolver
library. The net_nbuf_linear_copy routine allows to "linearize"
an IP stack network buffer. This routine is required by functions
that must jump between big chunks of data that in this case may
lie between many fragments. Tracking fragments may be a tedious
task, so getting a linear copy of the buffer will reduce code
complexity altough it increases memory consumption.

The DNS client library is updated to reflect these changes.

Change-Id: Iae321f99fa9b05fae7e722b6d41baac427d82d7e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka
820713239a net: ieee802154: Add PAN disassociation request
If associated, this will request to disassociate from the PAN. That's
only client side, PAN coordinator can also disassociate a client, which
case is not handled here.

Change-Id: If308f51b62c5006b4a2db53d0c891e8192f3c198
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka
d8b874b0c7 net: ieee80215: Add Active Scan request
Active scan differs from passive scan by sending a Beacon request (thus
the "active" part) and wait for beacons in reply to it.

Taking the opportunity to add debugging output to scanning logic.

Change-Id: I85001b1ea17f4ec4cd315dc39524c4d8f053cee2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka
b53e48de1b net: ieee802154: Add PAN association request
Such management request will enable association the 15.4 device to an
existing PAN.

Change-Id: I61ffd5e4d8192716e067c5225b3327f08944063b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka
88d4f1f543 net: ieee802154: Add grounds for passive scan
Currently, as only CC2520 device is supported: it will loop over the 16
channels present in 2.4Ghz spectrum. However, this will need refinement
as soon as other spectrums will be in use: L2 layer could request
capabilites from the device in order to know which range to use.

Scan result is done one at a time for now. It's unlikely going to fit
all production use case, so it's going to change in the future.

Change-Id: I2fafec49eb5cbfca1a4f04107ba3b6511d7d956d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka
ef041c10b6 net: event: Notify on interface being put down or up
It can be thus used to track the status of network interfaces in order
to act accordingly (no need to try sending things on network if the
interface is down for instance).

Change-Id: Ie160ef0dfdad6679d531d05a7abada96ad1de7db
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Tomasz Bursztyka
81bbfa1995 net: event: Fix misplaced comment
Change-Id: I6ab966461b98351d5207ec53054c62eebd6b44dc
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 09:11:43 +01:00
Luiz Augusto von Dentz
8a16c6681a net: l2: Add enable callback
This adds enable callback which can be used to notify the L2 driver about
changes of interface state, the L2 driver can then check if the new state
is allowed and reject otherwise.

Change-Id: I4bb6b1e32be2633f24694c0246585f803f8c645d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-06 09:11:42 +01:00
Luiz Augusto von Dentz
bf4fb51f44 net: if: Add NET_IF_UP flag
This adds NET_IF_UP flag support indicating the interface is up,
currently this shall only be used internally by the driver, later on it
shall be possible to make it public by using dedicated functions.

Change-Id: I38090da4030395b2341733b846004789416d61c1
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-06 09:11:42 +01:00
Tomasz Bursztyka
a1aa08c288 net: ip: Improve logging by adding a dedicated sys_log level
Let's make net stack having its own level of debugging through sys_log.
It replaces NET_DEBUG by NET_LOG_ENABLED, which is then semantically
better: someone wanting to log the errors might want that not only for
debugging.

Along with it, CONFIG_NET_LOG_GLOBAL option is added, in order to enable
all available logging in network stack. It is disabled by default but
might be found useful when warning/errors need to be logged, so it is
then unnecessary to selectively enable by hand all CONFIG_NET_DEBUG_*
options.

It is possible, locally, to override CONFIG_SYS_LOG_NET_LEVEL by setting
the level one want to NET_SYS_LOG_LEVEL. This can be useful on samples
or tests.

Change-Id: I56a8f052340bc3a932229963cc69b39912093b88
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:20 +01:00
Tomasz Bursztyka
2e95186eff net: nbuf: Let's remove inner type
It's possible to know from which pool the nbuf comes from so
let's reduce nbuf size by removing its internal type attribute which
becomes then useless.

When a data buffer is not coming from nbuf data buffer pool, let's call
it "EXTERNAL", just to make debugging handling a little simple in the
code.

Change-Id: I6931394c8c4f594137f6380be0a0ba5cea371040
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:19 +01:00
Flavio Santes
ac7300611c net: Restructure network protocols
This commit restructures the network protocols. Changes applied are:

- Move lib/iot/ to subsys/net/lib
- Move network protocol headers to include/net
- Move lib/iot/zoap/link-format.h to include/net/zoap_link_format.h
  and link-format.c to zoap_link_format.c
- Move tests/iot/ to tests/net/lib/
- Adapt sample code
- Adapt build system
- Modify doxygen paths

Change-Id: I37085fa4cc76a8a8e19a499ecb4e87b451120349
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-02 10:03:19 +01:00
Tomasz Bursztyka
a79f9bcbc4 net: statistics: Expose relevant information through net mgmt API
User application can request the information it wants via the generic
net_mgmt() call, following the NET_REQUEST_STATS_* codes.

Change-Id: Ia9e7d318cf11b7bf8bfaf1ad63c8c985be846cc1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka
88b99fa782 net: statistics: Have a dedicated struct for rpl data
This will be useful for net mgmt based API to grab statistics.

Change-Id: Id3904c48cfdd6c6fb01b6919948eb13af826ca1e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka
cbd1609bf6 net: statistics: Provide specific Kconfig options
This will help to track only what's wanted (ipv6, tpc, udp, else...) if
needed to.

Change-Id: I5c2e5e582db629b5d0e1cd98004f693c50f532a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka
06e2b421af net: statistics: Make statistics calculation fully private
Let's change from macros to inlined function to make things nicer.

Change-Id: Ie98e0667613961b03c84ca60bc551d0f473765f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka
2f9efd1a8e net: statistics: Fix comment length issue
Some were > 80 chars.

Change-Id: Ie7175c973b4e1ee4039380b0a233d88a60e6df4a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka
0a1617365f net: buf: Change NET_BUF_DEBUG to NET_BUF_LOG and add a level option
It will be thus possible to enable only the error logging, or the other
sys_log levels.

Change-Id: I0c0ed789f7cfbb4811320e8f8249151288274873
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Johan Hedberg
db8a5d9b80 net: buf: Add net_buf_add_mem() API
A very common pattern in code goes something like the following:

	memcpy(net_buf_add(buf, len), data, len);

To avoid having to create this kind of complex constructions every
time, this patch adds a new API which simplifies the call:

	net_buf_add_mem(buf, data, len);

Change-Id: Ic1aeae4baf88b2295d139f672d5d265db2ddbe7b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 16:27:08 +00:00
Flavio Santes
9216e6c47d net: Add ARG_UNUSED
This patch adds the ARG_UNUSED macros to some function arguments
to avoid compiler warnings.

Change-Id: Iae2cd3018c9442ffa9268fdfd33eb9a21f55087c
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:49 +00:00
Anas Nashif
a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00
Tomasz Bursztyka
cff19c17c4 net: l2: ethernet: Handle Ethernet II minimal frame size relevantly
Minimal frame size is 60 bytes, but IP frame might be smaller than this
size minus the ethernet header. In that case, Ethernet frames are padded
so it does reach this minimal size. In this case, ethernet L2 should
update the buffer list so it remove the padding length from the whole.

Change-Id: Id370cad09ad82bb54febeb60b05f7e430cc8f963
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:54 +01:00
Flavio Santes
e776658e1b net: Remove legacy tinydtls.h header
TinyDTLS is gone, so in this patch we are removing the tinydtls.h
header.

Change-Id: I7deddc554ac5c2fc952565a2df2e4c46e7cd2f6e
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-16 19:14:52 +01:00
Johan Hedberg
9609751909 net: buf: Fix incorrect reference to net_buf_get_debug
This is a left-over that should have been renamed to the new
net_buf_alloc_debug function name.

Change-Id: Iefcbd2eefab5614b1b80214cb0927f3db77d592e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 12:49:57 +00:00
Tomasz Bursztyka
353cd721a9 net: Fix incorrect logging format specifiers
Following commit fc21a76db6
Some more fixes are needed.

Change-Id: I19c2c979d44be5edfd76041d3cf4507860795c78
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-15 12:29:03 +00:00
Johan Hedberg
692771fbe9 net: buf: Switch from k_fifo to k_lifo for free buffers
Using a LIFO instead of a FIFO has the potential benefit that more
recently in-use buffers may be "cache-hot" and therefore accessed
faster than least recently used (which is what we get with a FIFO).

Change-Id: I59bb083ca2e00d0d404406540f7db216742a27cf
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 12:06:22 +02:00
Johan Hedberg
d659bb020e net: buf: Remove redundant user_data_size from buffers
Since the user data size is now stored in the pool there's very little
value in storing it as well per-buffer.

Change-Id: I17a99123b232423c52a2179b4eccd813728d51b1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:17 +02:00
Johan Hedberg
71c7c01819 net: buf: Remove the need for net_buf_pool_init()
In order to keep the initialization process light-weight, remove
net_buf_pool_init() and instead perform the initialization of the pool
and buffers in a "lazy" manner. This means storing more information
in the pool, and removing any 'const' members from net_buf. Since
there are no more const members in net_buf the buffer array can be
declared with __noinit, which further reduces initialization overhead.

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg
45bc46d42e net: buf: Introduce net_buf_destroy() wrapper
This is only for use with custom destroy callbacks, so that the
application gets isolated away from the details of how exactly the
buffers are managed. This opens up the possibility of switching away
from k_fifo to potentially better solutions, such as k_lifo.

Change-Id: I0d8322fdec3500d8ae060ae471b9448aeaa4572a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 08:45:05 +02:00
Johan Hedberg
c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

This patch removes the NET_BUF_POOL() macro and replaces it with a
NET_BUF_POOL_DEFINE() macro that internally expands into the buffer
array and new net_buf_pool struct with a given name:

	NET_BUF_POOL_DEFINE(pool_name, ...);

Having a dedicated context struct for the pool has the added benefit
that we can start moving there net_buf members that have the same
value for all buffers from the same pool. The first such member that
gets moved is the destroy callback, thus shrinking net_buf by four
bytes. Another potential candidate is the user_data_size, however
right not that's left out since it would just leave 2 bytes of padding
in net_buf (i.e. not influence its size). Another common value is
buf->size, however that one is also used by net_buf_simple and can
therefore not be moved.

This patch also splits getting buffers from a FIFO and allocating a
new buffer from a pool into two separate APIs: net_buf_get and
net_buf_alloc, thus simplifying the APIs and their usage. There is no
separate 'reserve_head' parameter anymore when allocating, rather the
user is expected to call net_buf_reserve() afterwards if something
else than 0 headroom is desired.

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Jukka Rissanen
481f67e266 net: nbuf: Provide metadata info for sent TCP buf
Create a variable in nbuf metadata area for storing TCP
buf_sent information.

Change-Id: I21a85c58183f1e4997d03d4a93546ddd9b32e977
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:19 +02:00
Andy Ross
094c65051c net: tcp: TCP transmission
Hook up TCP transmission through the net_context_send() API.  Queues
packets via a list in the net_buf header, but as of right now simply
transmits the queue synchronously, ignoring the need for retransmit
and the limits of the receive window on the other side.

Requires that the ACK transmission be moved ahead of the net_context
callback invokation.  This to work around a glitch in the way ACKs
work with queueing (they depend on current state, but packets are
assembled just once) that will be fixed in a coming patch.

Change-Id: I7490333e4b314e7734fcc03f2a63d76ae89d698a
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:19 +02:00
Jukka Rissanen
b4cba17408 net: Fix stack info collector in net shell
The cc2520 driver RX thread did not like the stack information
collection macros defined in net_core.h. Both the cc2520 TX and
RX got the same variable name which did not compile.
This is now changed so that the first parameter is added to
the variable name to create a unique variable.

Change-Id: Ia41d01a71afd73af2ef31aa5f7a890a3cf0385aa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:18 +02:00
Jukka Rissanen
68ea9377e6 net: Make native IP stack the default
As the native IP stack is now the default, there is no need
for corresponding Kconfig option.

Change-Id: I08e4992f540f928a2b7378e8803e634e38725348
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:17 +02:00
Jukka Rissanen
6b43821f20 net: Remove legacy Contiki based uIP stack
This commit removes the legacy Contiki based uIP stack.
The new native IP stack must be used after this commit.

The commit also removes following things:
- legacy cc2520 driver
- legacy ethernet drivers
- legacy IP stack samples

and changes these things:
- disabled tests that only work for legacy IP stack
- select new IP stack by default
- enable random number generator by default as it is needed
  by the new IP stack

Change-Id: I1229f9960a4c6654e9ccc6dac14a7efb9394e45d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:17 +02:00
Jukka Rissanen
1b9b1d46c3 net: Add util to loop all network contexts
This is to be used in net-shell to view currently
available network connections.

Change-Id: Iadb6555ed6db4e8fb0639e6d0dcf1eccd970acca
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +02:00
Jukka Rissanen
e765a5a2e2 net: Add initial IP stack offloading support
If IP stack offloading is enabled, then call corresponding
L2 driver when corresponding net_context API function is
called. The L2 driver can then do its magic to send/recv
IP packet or do what ever with it.

Change-Id: I26695cee6feb80a41923db0165f22d94477333be
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +02:00
Jukka Rissanen
8e84e36f14 net: Declare a macro to define stacks used by networking
The macro defines the stack as usual, but if user has
enabled net shell (CONFIG_NET_SHELL), then additional
information about the stack is stored in net_shell
linker section. The information in the net_shell linker
section is then used to print information about the
stacks in the networking sub-system.

Change-Id: Ic6e9f16a73a192b9a59d32a6d0070322382f98bd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
7502824598 net: Use alignment macros when copying IP address
The original version can fail in ARM like this

***** USAGE FAULT *****
  Executing thread ID (thread): 0x200027a8
  Faulting instruction address:  0x00008080
  Unaligned memory access
Fatal fault in thread 0x200027a8! Aborting.

so use UNALIGNED_PUT() and UNALIGNED_GET() instead.

This failure was seen when IPv6 address was
copied to neighbor cache in ipv6.c:nbr_new().

Change-Id: I638424b9a95c451e13314ca9182c39ab8aa71830
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:13 +02:00
Jukka Rissanen
40b91b05c4 net: Fix unknown func call when getting stack vars
If CONFIG_INIT_STACKS is not enabled but CONFIG_NET_SHELL is,
then net_analyze_stack_get_values() was not properly compiled
out which caused unknown function call.

Change-Id: I18de5ec0b5d6ab7876e801c83b82c9dd5bf22093
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:13 +02:00
Jukka Rissanen
209b0cdb1c net: Add IPv4 address string max length
Change-Id: I37a2ea9371c34353f259300452fd228a00b26aa8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
e69fbacc5a net: Add util to check if IPv4 address is unspecified
Change-Id: I373bc32481ad186a3c198ed29709f12ea40cf583
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
ba65d1ef1d net: Add util to check if IPv4 address is a loopback one
Change-Id: I55a6e07060993fc7274749706d063fc15953c38f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:10 +02:00
Jukka Rissanen
b650b758c9 net: Add util to remove an IPv6 router from the network interface
Change-Id: Ie9cc461187a25355819e685cec68b04d4eba8c87
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:08 +02:00
Jukka Rissanen
5092b3c555 net: Add util to update router lifetime
Change-Id: I38ecf574f2a0c69348ed73efb9b26aadab4344aa
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:08 +02:00
Jukka Rissanen
41e547673a net: Add util to update IPv6 address validity time
Change-Id: I951c9e781c74724c69fbd700ef738dd487ec15a7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:08 +02:00
Tomasz Bursztyka
54ddabc7e6 net: context: Instead of 0 as timeout, K_NO_WAIT is better.
Updating the API documentation to use K_NO_WAIT instead of 0.

Change-Id: I10ba31fe116210443f383b343993c3cca830a7c2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:07 +02:00
Tomasz Bursztyka
85a8f8e6fa net: trickle: Using unified kernel API
Dropping legacy API. This commit also contains updated
unit tests in order to pass the test.

Change-Id: Ibc7426837e2f4f23bb5f3ed3719635c5c3d0ed0f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:07 +02:00
Tomasz Bursztyka
1aaf5aaa93 net: l2: Using unified kernel API
Dropping legacy API.

Change-Id: Icf24ecef714a9d6ddbe16aff6422b4fcc6c428e2
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:06 +02:00
Tomasz Bursztyka
aa9a552012 net: if: Using unified kernel API
Dropping legacy API.

Change-Id: I46eb30f691f5e0a9e9156f8b4dab3c00e64ffb9b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:06 +02:00
Tomasz Bursztyka
ea13cf8575 net: context: Using unified kernel API
Dropping legacy API.

Change-Id: I2f98ec39906bd8c0a8979171904d244b6a82a5e7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:06 +02:00
Tomasz Bursztyka
f3cb3ff40e net: core: Using unified kernel API
Dropping legacy API.

Change-Id: I756e47855cc979aa130ad0de4fd527c4a79e8d71
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:06 +02:00
Piotr Mienkowski
93e46cc8d8 net: Definitions for IEEE 802.3, Section 2 MII compatible PHY transceivers
Origin: Original

Based on "IEEE Std 802.3-2008, Section 2" Chapter 22.2.4

Change-Id: I08516dd1c2f74c1324d00d665f221e01af25d7f1
Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2016-12-02 12:41:05 +02:00
Jukka Rissanen
89a00ada23 net: Replace deprecated kernel init level
Replace NANOKERNEL by POST_KERNEL in the net stack.

Change-Id: Iaad7cdbe849741bc1cf18b0ccf7264417a9495d6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:05 +02:00
Jukka Rissanen
1d86b236af net: nbuf: Fix UDP and TCP start of the packet calculation
The functions that return the start of the UDP and TCP buffers,
did not take the IP extension header length into account.

Change-Id: Ie3e2fbc49365de9176a788b54ab628e6ef37f5ee
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:04 +02:00
Jukka Rissanen
c5f8dc4748 net: ipv4: Move broadcast address getter to ipv4.c
More logical place for net_ipv4_broadcast_address() is in ipv4.c
instead of net_if.c.

Change-Id: I069f5030963bcb809df34e874054e2b7826ff868
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:04 +02:00
Jukka Rissanen
1b58d970ca net: ipv6: Move unspecified address getter to ipv6.c
More logical place for net_ipv6_unspecified_address() is in ipv6.c
instead of net_if.c. Removing the net_if_ipv6_unspecified_addr()
variant as it is no longer needed.

Change-Id: Ib5b4f6748030a8bf50fb848a87eef2968e2bcbc8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:04 +02:00
Jukka Rissanen
b30bb36216 net: Add util to return IPv4 ANY address
Add function that returns IPv4 any address (all bits are zero).

Change-Id: I8816f7f264ad3a98fced7089f0b94220603c2291
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:04 +02:00
Tomasz Bursztyka
bf33494e49 net: ieee802154: Let's ask LQI through driver API
Instead of appending the LQI into the buffer, which is an awkward usage.

Change-Id: I2f604cd61ef3b309cdfe304dac0ab1e7a2ca3f6a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:04 +02:00
Jukka Rissanen
76ddf5dcab net: Add util that checks if the IPv4 address is multicast one
Change-Id: I8c2bfccfbd25c5a034d546b334745bf739b70eae
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:03 +02:00
Jukka Rissanen
d41325edee net: Clarified the net_send_data() function return value
If net_send_data() returns 0, then the buffer was sent ok
and the sending device driver has already freed the buffer.

If net_send_data() returns <0, then the buffer sending failed
and the caller can either try to fix the issue and re-send the
buffer, or the caller can unref the buffer. Normally caller
should unref the buffer in this case as there is not much that
can be done here.

Change-Id: I39d7b22bbb78a9c16fd037f3a066797e455c31fd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:03 +02:00
Jukka Rissanen
75c86a37a3 net: Fix net_nbuf_write() documentation
The pos and len variables were in incorrect order.
The pos is first before the len variable.

Change-Id: I0b078ce2f08923c1673bd918fc03adb2ff09691a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:03 +02:00
Jukka Rissanen
7e0b45759f net: Add helper to return network buffer information
This is needed by net-shell module.

Change-Id: Ic93f806a5882592ff1769b4a14b6ed524ba14912
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:02 +02:00
Jukka Rissanen
60ecd5ecd6 net: Network stack analyzer re-factored
Separate the calculation of stack utilization variables and
printing the values from each other so that it is possible
to use separate printing function to print the values.

Change-Id: I3a5827c08edea5017e2a4bc1c5be2fe419cdfcb8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:02 +02:00
Jaakko Hannikainen
f9f0d895ea net: Add net_addr_pton()
This function converts a string into an IP address.

Change-Id: If57983a345fe4c18df01e58dbce7d9a50a27b82a
Signed-off-by: Jaakko Hannikainen <jaakko.hannikainen@intel.com>
2016-12-02 12:41:02 +02:00
Leandro Pereira
ad1a9d088d net: tcp: Add better type safety for connection handlers
This creates a `struct net_conn_handle` that's only used as an opaque
pointer.  The purpose is to avoid assigning a void* to a void** in
connection registering/unregistering functions, avoiding a
previously-caught bug by issuing an incompatible pointer types warning:

	warning: passing argument 7 of 'net_tcp_register' from
		incompatible pointer type [-Wincompatible-pointer-types]

Suggested by Andy Ross in 5beec6.  This particular commit didn't catch
any bugs, but the one caught in 5beec6 wouldn't exist if this were in
place at the time.

Change-Id: I5c13fb4c5826adce6397feb7b400d36e426c4a87
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:02 +02:00
Jukka Rissanen
750a93df40 net: Fix IPv6 address debug print
The allocated space for IPv6 string was too short by 10 chars
which meant that full IPv6 address was not printed correctly.

Change-Id: I9c7f3f118f486f88e769aaadf09d100a1d4fd6bc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:01 +02:00
Jukka Rissanen
5c79f01181 net: nbuf: Add function to add stuff to IPv6 extension map
Utility function that can add option bits to IPv6 option bitmap.

Change-Id: Ia10d27c201556fb960a736590788b791a7e3c018
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
98404b175c net: rpl: Initial commit
RPL implementation taken from net/ip/contiki/rpl and
ported to use the new stack.

Origin: Contiki

Change-Id: I479d9dd143b763f90cb7915806fd7e9faea0300c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
13dd72a593 net: Add helpers to get network interface IPv6 addresses
Add utilities to return network interface link local and
global IPv6 addresses.

Change-Id: I54d0ec28410b9ad4ad7068a887bfa6706453159c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
d4c910ec9f net: Add IPv6 extension header type values to net_ip.h
Change-Id: I1925d4a894675b503b033b78e7b717a8993ec331
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
fa801d5b19 net: Add helper to find default IPv6 router
Go through the router list and return the default router
where to send the network packet.

Change-Id: I87e5118b03352b7d11e1fde800d1530e5929ebab
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
865d82dfe1 net: Add helper to check if the IPv6 address is part out subnet
Helper checks if the IPv6 address belongs to one of the subnets
defined for network interfaces.

Change-Id: I0e88ebe5014a514404b589e32cc71590950a39c7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:00 +02:00
Jukka Rissanen
29e9621c50 net: Add utility to go through all network interfaces
Change-Id: I0a9dabf3585fb3813b806238f6e5049c2646890d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:59 +02:00
Jukka Rissanen
41fa0c02df net: Add func that checks if address is global multicast one
Change-Id: If40e8833f8b08c0b066650a2c680771ad0cdc252
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:59 +02:00
Jukka Rissanen
8aac3ed390 net: Add support for link cb in net_if
The other part of the stack can register a handler that is
called after the network packet has been sent. This callback
is used by RPL routing code.

Change-Id: I6b76c5f01d1f6706b0c0a56980ad50e1b85fc427
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:59 +02:00
Tomasz Bursztyka
d02fe29616 net: ieee802154: Add support for requesting ACK on packets
This is meant if only one needs reliability when sending non-TCP packets
(as TCP would make is redundant).

Change-Id: I7dc605094b422a750424c3498d18f32d809d23a8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:57 +02:00
Tomasz Bursztyka
7e4bba03b4 net: ieee802154: Optimize context structure usage
For future purpose, let's not occupy a full byte for a unique boolean.

Change-Id: I36f2824cca4806eb90640a71ed3cea37a353b276
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:55 +02:00
Tomasz Bursztyka
62ea188772 net: mgmt: Fix include recursion loop
Including net_if.h can makes things looping, as this one will include
net_l2.h, which one might include a technology that will in turn include
net_mgmt.h again.

Change-Id: I514720875937414167f0396edb9147ed29dd6d69
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:55 +02:00
Tomasz Bursztyka
efaa46594f net: mgmt: Define request handlers to avoid build warning
Up to the part declaring mgmt request to define such handler. This is
meant to avoid such warning:

warning: implicit declaration of function ...

Change-Id: Ide6e9abf886169c26d81fe6b5c7bc280e1ac4e4d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:55 +02:00
Ravi kumar Veeramally
f1986a1d1e net: Add IPv4 related events
Change-Id: Ieb26ab96b2b9aa6765ddba21628ab1530a2597ea
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:54 +02:00
Ravi kumar Veeramally
889b090ffb net: Implement net_nbuf_insert
Add support for inserting data into an arbitrary location in fragment.

Change-Id: Iaecdc4e980a73e0f66c208315d342e05762cd6f5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:53 +02:00
Ravi kumar Veeramally
9f308ac83c net: Implement net_nbuf_write
Add support for nbuf write to an arbitrary location in fragment.

Change-Id: I686c6d86feb8545603edd7c7a9ef6fde1c909a72
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:53 +02:00
Jukka Rissanen
ddda50c214 net: tcp: Initial TCP functionality
This creates initial TCP handling logic but does not yet
enable fully working TCP connection.

Some of the connection logic is taken from FNET TCP
implementation.

Origin: FNET 3.6.1
URL: https://github.com/butok/FNET/blob/master/fnet_stack/stack/fnet_tcp.c

Change-Id: I1e100d9fa9c91437562b933d94d0bd3db1a5885e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:51 +02:00
Ravi kumar Veeramally
ed3dbe1cbf net: Fix typos in nbuf apis
Change-Id: Id89d0d7f1d49a275de0f735a6457fdb6fdad31ea
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:51 +02:00
Jukka Rissanen
54a500a478 net: Add helpers to get sockaddr pointer
This way we avoid ugly casts in the calling code.

Change-Id: I9c949cf22ecd1603e9247a07240de5759bf85463
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:51 +02:00
Paul Sokolovsky
be96b7df62 net: Make net_context_get_ip_proto check correct flag.
Apparently, a copy-paste error: NET_CONTEXT_TYPE was used instead of
NET_CONTEXT_PROTO. The corresponding "set" function uses the latter,
so it for "get" too.

Change-Id: Ideb5bfaeb548222a6e64d53b782c9a111e3ef33b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2016-12-02 12:40:51 +02:00
Ravi kumar Veeramally
c689fd6f1a net: Rename net_nbuf_write to net_nbuf_append
Current net_nbuf_write() api just appends data to last fragment. And
doesn't write data based on offset. That's why renaming this api.

New net_nbuf_write() apis based on offset will be coming soon.

Change-Id: Ie8e13e5f6091a279b62b6d8b0b3928a5187e75b0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:51 +02:00
Luiz Augusto von Dentz
83c9da8af8 net: Add initial Bluetooth support using native IP stack
Initial Kconfig and L2 layer support.

Jira: ZEP-992

Change-Id: Ia60316566ea1e535d9cdb3f372c3c46630d0e9c0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-02 12:40:50 +02:00
Ravi kumar Veeramally
ead511ddae net: Fix net_nbuf_read corner cases
Valid case:
 1) If the offset is more than current fragment length, adjusts offset
    from next relevant fragment and starts reading or skipping.
 2) If the read or skip length is more than available data length,
    then throw an error.

In case of an error, frag is 'NULL' pos is '0xffff'. Rest of the cases
are successful read and skip.

Change-Id: I88c4b85e14e5821f681966b5148ba9519b91cca4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:49 +02:00
Jukka Rissanen
962400f9b1 net: uip: Fix the net_context.h content for legacy stack
The legacy stack has all the net_context API stuff in
net_socket.h so include it in net/net_context.h file.

This re-works the commit 627feb92d4 which added the
net_context_get_internal_connection() to net_context.h.
Now that function prototype is found in net_socket.h.

Change-Id: If22fa63357f4b2e9503f8c9850e69ffda39c61c7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:49 +02:00
Tomasz Bursztyka
1069d26eae net: Differentiate IPv6 event command and final event
Enum names are colliding with defines, which is bad.

Change-Id: Ia8c003983ddeb1ebed8a9210e682bcb21abfa687
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:48 +02:00
Jukka Rissanen
4bf941ee39 net: Re-order fields in net_nbuf struct
Re-ordering fields in struct net_nbuf in order to avoid
holes because of memory alignment.

Change-Id: I5a3ab31a0232003c161fd65848f70d83e07a75c9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:48 +02:00
Tomasz Bursztyka
805e475e9d net: events: Fix a mix up between code and command
Code is actually meant to identify the part in the layer from which the
events originates. Adding or removing an address is a command.

Change-Id: I42b4823d2585b15851c4fdd91802a13d2a5759c1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:47 +02:00
Tomasz Bursztyka
0bd597348c net: Add network management event code for IPv6
Currently, only address related changes are handled.

Change-Id: I2aa366518dae2725e58cbede4ccbe2ef19cd8b16
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:47 +02:00
Tomasz Bursztyka
1d64c3632d net: mgmt: Add some macro helpers for filling in the bit field
This will be useful when creating request and/or event codes.

Change-Id: Ibc117b476c52d72c77924a245e1f263f583061f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:47 +02:00
Juan Manuel Cruz
da5bc59d03 net: Fixes the network interface naming macro
The network interface naming macro is ignoring the
dev_name parameter. This can bring issues if having
more than one network interface in the system.

Change-Id: I7e975be61e82bd04bd865b0c4078607cbdef2230
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-12-02 12:40:46 +02:00
Jukka Rissanen
d46f37fe2d net: Add more nbuf read/write helpers
Add net_nbuf_write_u8(), net_nbuf_write_be16(),
net_nbuf_write_be32() and net_nbuf_read_u8() helpers.

Change-Id: I7129625dab85262885a4e130f6d312860c8d1b31
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:46 +02:00
Jukka Rissanen
76716480d8 net: IPv6 address should be const in net_if_get_ll_reserve
As the function does not modify the IPv6 address,
it can be const.

Change-Id: I2af58a4954d8b6f0d71bc7d0d14ddf0f62f8ca7c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:46 +02:00
Tomasz Bursztyka
af703e1106 net: Normalizing net_mgmt API names
While doing some documentation for it, I realized names were not all
good and it missed some stuff:

- what belongs to event should contain "event" in it
- we have a structur as callback so let's type the handler as a handler
- let's add the request handler signature

Change-Id: I18822cbcdc3c10e33600d6db38abab5ca73a228c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:46 +02:00
Andrei Emeltchenko
7889ebaf5e net: Add L2 RAW channel hidden option
L2 RAW channel allows to use some functions of IP stack for RAW access
of network drivers. It is hidden from user and is selected by 2520 raw
driver.

Change-Id: I91dd09803052072dfddb7989d9d67c3a5840f89e
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-12-02 12:40:46 +02:00
Tomasz Bursztyka
cce3a7e3d5 net: Add support for event handling on network management API
This adds the capability to raise an event, and for anybody to listen to
it.

Change-Id: I2287b43d678930c29391efa2ddf7b12652cc1bb6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:46 +02:00
Tomasz Bursztyka
a73b1c39d1 net: Add network management API
Define the ground mechanism to interact with the network stack.

Change-Id: Id2af76188967fa66e0f0d755a2c1dc8a85985540
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:45 +02:00
Jukka Rissanen
7a4cd852d4 net: Add be16 and be32 read helpers to nbuf.h
Two utility functions net_nbuf_read_be16() and net_nbuf_read_be32()
added which return either 16 or 32 bit big endian value.

Change-Id: I3401dde75669b429160c602a820359c800671afb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:45 +02:00
Flavio Santes
b29b0995d2 net: Improve net_context_connect documentation
This commit tries to improve inline documentation by refactoring
the original text. Missing information is also added, for example:
function return codes.

Change-Id: I940d4b6fa3e8079323e5e0ec1e5f63407505c9d9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-02 12:40:45 +02:00
Jukka Rissanen
61dc5be389 net: Íncorrectly named function in net_if.c
The net_ipv6_set_reachable_time() was incorrectly named, the
correct name is net_if_ipv6_set_reachable_time().
The _if_ prefix needs to be there as the function is located
in net_if.c file.

Change-Id: Ic841328bdff92fbb90f51a199ebbee82d7b1c9fd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:28 +02:00
Ravi kumar Veeramally
618879ac6a net: Add nbuf APIs to read/write across multiple fragments
Helper functions to read and write data across multiple fragments.

Write function always adds at the end of last fragment. If there is
no space in last fragment new data fragment will be created and added
to input buffer.

Read function start reading from offset of input fragment. If the
required data is located in mutliple fragments it reads from list
of fragments and returns position and fragment where read stopped.

Skip function start skipping from offset of input fragment. If the
required length is across multiple fragments it skip till length and
returns position and fragment where read stopped. This is useful
when reading with unwanted data (reserved or unhandled data).

These functions are quite useful when handling with multiple fragments.

Change-Id: I348b869108724602ae780a1cba4fe17d3af7ffc2
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:28 +02:00
Ravi kumar Veeramally
28c82144c2 net: Add DHCPv4 client support
Change-Id: I3a7a9074f68059d69c20c947882a3f6480ace23a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:26 +02:00
Jukka Rissanen
c427e9bbd6 net: Context accept cb needs to return failure code
If the connection establishment has an error, the accept
callback needs to be able to return that error to user space
so that the application can know about it.
This is especially important in TCP where application needs
to start to listen again if reset is sent during connection
establishment.

Change-Id: I55f36e4f101c7237c1288f09baf6e602b33da2b3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
73aa1cc72c net: Add TCP buffer access func to nbuf
So we can easily access TCP buffer that is stored
in net_buf.

Change-Id: I37ae728be45ded2fcc74735592d94897c945afbe
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
708579eb6b net: Add TCP protocol header definition
Change-Id: I17ab9f21ebbebdfc47e82a11540d8e071d7c46de
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
8d9ea90fba net: Add net_nbuf_pull function
This will remove given amount of data from the fragment list.

Change-Id: I17d809982af0b941f957205688ee61e5ac3c1f08
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
6ef5fa22b2 net: Align net_if struct to 32-byte boundary
This is needed because if there are more than one network
interfaces configured, then the second interface will point
to wrong address. Only solution to this issue is to align
the net_if to 32 byte boundary. The issue was seen in qemu
and it is not really known if the issue is present in real
hardware.

Change-Id: I2048c8a9a0aab51f84c15539159410b544f6c9b1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
70430795a9 net: Fix the statistics compilation
Make sure that the statisitics compilation can be done even
if some sub-statistics module is not compiled, like IPv6 or
IPv4 statistics.

Change-Id: I1a91acd70569f074d9bb3269f74ee9c6a0ea9cf7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Jukka Rissanen
96e629c877 net: Fix remaining debug option naming issues
Some of the DEBUG options for the new IP stack still used
the CONFIG_NETWORK_IP_STACK_DEBUG_ prefix.

Change-Id: I8f039ac5e303a7c571a870403ce17d758db540d5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:25 +02:00
Tomasz Bursztyka
7353cf4079 net: ieee802154: Add CSMA-CA non slotted radio protocol support
Implementing the primitives for non-slotted CSMA-CA radio protocol
according to section 5.1.1.4 in the 2011 version of the specification.

Slotted version will come when Beacon frame will be supported, thus
getting PAN coordinator info from its superframe.

Change-Id: I0545ed953a3c48e6b8e9cd4082db01ed66ad098b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:25 +02:00
Tomasz Bursztyka
becf74743b net: Split debug Kconfig options from legacy to new stack
- new stack options are renamed and placed in their respective menus
- new stack Kconfig gets normalized (tabs vs spaces, etc...)

Change-Id: Ia68f6589fed464bbdd76dc0812775684b2f94a58
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:24 +02:00
Tomasz Bursztyka
aaf5075372 net: Add a macro to create specific net if instances
This will be necessary for devices that require to instanciate more than
one network interface.

Change-Id: I01fd4eb220ed63a4fe073614fb2a132cd00c6bc8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:24 +02:00
Jukka Rissanen
58a7ada44c net: Add network address length to user API
Add socklen_t addrlen parameter to net_context_bind(),
net_context_sendto() and accept callback.

Currently the address length option is not really mandatory
as we can figure out the length from the address family.
But if we are going to support other protocol address families
it might be needed.

Change-Id: I59206465c3259050c469c5b2150221646a9a08d7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:24 +02:00
Johan Hedberg
35c24140f8 net: buf: Fix minor typo in documentation
Change-Id: I19869683c5dde8ef88ddfdfb1e0656a8b824ffdd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-02 12:40:23 +02:00
Jukka Rissanen
5b40f871ff net: Do not try to use net_if.h in legacy uIP stack
The net_if.h is only meant for new IP stack.

Change-Id: I133d576d7c070dd4a2291544bd0b0401bda942b5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:23 +02:00
Andrei Emeltchenko
295b68d90c net: Fix documentation errors in net_if header file
Change-Id: I66ae70040e7ea65b6b72b9736fe384db02f23581
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-12-02 12:40:23 +02:00
Jukka Rissanen
17d2ab05c8 net: Trickle algorithm implementation
See RFC 6206 for Trickle details.

Change-Id: I709d81eb182f068293cf4b1f1474b2911febc5d4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:21 +02:00
Jukka Rissanen
181adfdadb net: Add support for IPv6 prefix lifetime
If the received IPv6 router advertisement contains prefix
address options, set the validity of the prefix and expire
them when needed.

Change-Id: I7026d2101bd9eca1f90688c14d5c6aaa66e4af5e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:20 +02:00
Jukka Rissanen
27d9936bd3 net: Print buffer usage after receiving or sending data
Change-Id: Iae56937f8609b46778bc433ec88c193fe91e6cf4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:19 +02:00
Jukka Rissanen
dfc1e66780 net: Add ll address checker function
The net_linkaddr_cmp() will compare two link layer addresses
and return true if they are the same.

Change-Id: I13f5ee9e7976a4118e891aefdb6e7c08f098c0b6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:19 +02:00
Tomasz Bursztyka
0624199e1f net: Adding ALOHA radio protocol to IEEE 802.15.4 L2 driver
This is the simplest - if not the dumbest - radio protocol we can use
for IEEE 802.15.4 stack. It just transmsits right away (with optional
retry) without taking care of doing any CCA (Clear Channel Assesment).

See IEEE 802.15.4 specification document, part 4.5.4.2

Change-Id: I341ad197aa221bc8f9ec67d0fd523da294a0351b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:18 +02:00
Tomasz Bursztyka
df9b6f76af net: Add preliminary IEEE 802.15.4 L2 driver
It currently supports the basics for the Data MAC service. A radio
protocol is still necessary to send packets.

Change-Id: I78f974ad7440d258583a5c7c6c7160e904eb54f4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:18 +02:00
Tomasz Bursztyka
c3ce028d3b net: Add new IEEE 802.15.4 Radio API for device drivers
This new radio API will be provided by 802.15.4 device drivers in order
to fit in the new IEEE 802.15.4 stack within native IP stack.

Change-Id: Ib28e8dd3f25e5c802284568b88c2ea6d5cf58f89
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:18 +02:00
Tomasz Bursztyka
3560f58293 net: L2 might need private data per-interface
Allocate the right amount of space for L2's context.

Change-Id: Ia2f4f4162334e9e9c26dc95230abdfde5986e052
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:18 +02:00
Tomasz Bursztyka
f0003c3a25 net: Add a function to lookup for an iface from a device
One might need to find out the proper interface from a given struct
device pointer.

Change-Id: Id480d0a2bdf57f0b2d38379727ea1491dedf213e
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:18 +02:00
Tomasz Bursztyka
3501290245 net: Add documentation to net_l2 header file
Change-Id: Ib07406a6d988cd742d2077503b70de230197d390
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:17 +02:00
Tomasz Bursztyka
f7a9b07a84 net: l2 layer reserve size might need extra parameter
The dst_ip6 is a parameter, required for future 802.15.4 L2 layer.
At some point such parameter could be changed to a void pointer,
and a utility function would populate it depending on L2 layer,
if such parameter needs someday to be variable and complex (some
specific struct or else).

Also make sure we use ARG_UNUSED() relevantly, and using proper prefix
to functions.

Change-Id: I43297bb4fb48a8f1bb5075c216342db16261cbb8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:17 +02:00
Tomasz Bursztyka
72df406cb8 net: Add IPv6 ND statistics when relevant
CONFIG_NET_IPV6_ND enables ND packet processing, and we are thus
interested about the packet recv/sent/drop statistics.

Change-Id: Id281c924193bd2b1d71088bf40d47b1601daad5c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:17 +02:00
Jukka Rissanen
dd3b93d3f3 net: Update UDP sent packet statistics
Change-Id: Ia012f1b1d2cd9e975e3e1744a2f6fce09ccc0987
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:17 +02:00
Jukka Rissanen
1eb1c0f4f3 net: Call net_context send callback when packet is sent
The send callback in net_context is called after packet has been
successfully sent or dropped. The callback is not called if the
packet is pending and waiting for example IPv6 ND to finish.

Change-Id: I28e77c6333974705a0e31862bb913eedace0b3f9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:16 +02:00
Jukka Rissanen
e2908b1a6b net: Call send callback in net_context properly
The send callback should be called after the packet has been
sent so setup things allowing that.

Change-Id: Icb82f9896667dcb1e400376c0fca6df380509090
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:16 +02:00
Jukka Rissanen
e04fbc04e1 net: Add token to nbuf
The token is used by net_context.c when sending packet. User
can set the token and get it back when data has been sent.
This can be used to know what specific packet was sent if
there are multiple packets going at the same time.

Change-Id: Iaaf730faaa55a712ae22d903e612e44deb683b8f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:16 +02:00
Jukka Rissanen
11e111d494 net: Rename ip_protocol to net_ip_protocol
In order to be consistent with naming, this commit renames
ip_protocol enum that is found in net_ip.h to net_ip_protocol.

Change-Id: Ie6caf059279b819794a13494468de789450e2bd8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:16 +02:00
Jukka Rissanen
13733f7894 net: Add user space API to net_context
This API provides similar kind of functionality as BSD socket
API. This API does not provide BSD socket API.

Change-Id: I537d0ad2a5213f1d1e11fa7891dd4f4d0f3cc4bb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:15 +02:00
Jukka Rissanen
b055a05ae8 net: Add helpers for getting protocol specific sockaddr
Change-Id: Icdf9dec83856b35228f9e3be24c2beceb37c3178
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:15 +02:00
Jukka Rissanen
0dbe48eb46 net: Add sockaddr struct
These are need in future commits. The sockaddr struct will hold
the IP address and port number among other things.

Change-Id: I0971c39f0f1cb019aa8610977a245e24548c56ee
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:15 +02:00
Jukka Rissanen
6085ff518a net: Making IP address const in utility func
Changing the IP address type to const as the functions do not
modify the IP address.

Change-Id: I176d84af5f05843226a954f91b6bb3bba6596863
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:14 +02:00
Jukka Rissanen
20167bd472 net: Utility to get net_if according to index value
Using network interface index instead of net_if pointer can
save 3 bytes of memory. So these utilities help to convert
pointer to index and vice versa.

Change-Id: I8743a06e0935d48798b19526154058be385550af
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:14 +02:00
Jukka Rissanen
2658ac7a73 net: IP address lookup functions return interface
When checking the IP address from network interface, return
also the used network interface.

Change-Id: If7b8385193da4cb1b469f697e219cfae3b6477dd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:14 +02:00
Tomasz Bursztyka
a1fde2bff8 net: Fix dedicated IPv4 function for net_if
IPv4/6 functions follows this scheme: net_if_ipv<4/6>_<name>.
Applying that to net_if_set_gw/net_if_set_netmask which are IPv4
functions.

Change-Id: I2dcbb16ce81cfdffbfbb5cae24ad76ddf2b9919a
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:14 +02:00
Tomasz Bursztyka
92e592c80d net: Simplify IPV<4/6> config management in net_if
Reducing the amount of #if defined(CONFIG_NET_IPV<4/6>) for a clearer
code and to lower compiler's stress.

Change-Id: Iffbfbda4409c6cbf48a3057ea1b9e43309cd84e7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:14 +02:00
Ravi kumar Veeramally
3fdaf518da net: Add utility to verify given addr based on ll
Utility verifies given address is based on link layer address
or not.

Change-Id: I2b89e498fa2481051ec9a47ada8b4a5e8e38ad7a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:13 +02:00
Ravi kumar Veeramally
a4cb318333 net: Add support for 802.15.4 short address for iid creation
If the link layer address is short address, create interface ID based on
short address.

Change-Id: I49e150cc20a0bf973880d27f418762f68f2d9139
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:13 +02:00
Ravi kumar Veeramally
602f1b58bd net: Clear ipv6 addr parameter on create iid
While reusing buffers and passing those parameters might have
already some garbage. So just clear first and create iid.

Change-Id: I5774de157e0c39e7e7b1313a598557c58a4c63b0
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:13 +02:00
Tomasz Bursztyka
2c875eb171 net: Fix net_ip.h documentation
Change-Id: I86cd4b607e9d67665e4061b25a459ca8b1d9c2e1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:13 +02:00
Tomasz Bursztyka
97daa51c80 net: Cleanup net_if's documentation
Change-Id: Idd139ee5f56c8b55119db69582393fe2906eae74
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:13 +02:00
Tomasz Bursztyka
b8e3415264 net: Let's use inline function for type checking for net_nbuf
Using macros does not let the compiler verifying about the type we are
providing, which usually give an error easier to understand.
Also, this will let the compiler deciding how to actually optimize
(inline or not) the code.

Change-Id: Iba49590b620ef0a1bd0ed5621453524fcfea747c
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:13 +02:00
Tomasz Bursztyka
b70a4f501a net: Moving header files to include/net/yaip
This make sure we will found all relevant headers in the right location.

Change-Id: I37fe978ed2af09d921c48df6986a8df9041ddc3f
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:13 +02:00
Jukka Rissanen
92112c61aa net: Debugging function to print fragment chain information
Debug function that will print individual fragments and their sizes.

Change-Id: I84ce144230fb099bb44ed383075564ebf377998f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:13 +02:00
Jukka Rissanen
51f48ff377 net: Refactor nbuf.h and nbuf.c
No functionality changes.

Change-Id: I4dc36ee95c46a1311cfa1466e069697df6268854
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:13 +02:00
Jukka Rissanen
482d7c69cc net: Refactored IPv6 DAD and ND activation
The earlier Kconfig entries for IPv6 DAD and ND were confusing.
This commit will clarify this so DAD is activated by
CONFIG_NET_IPV6_DAD and ND is activated by CONFIG_NET_IPV6_ND.
These are settings are enabled by default.

Change-Id: If6245e3425489bc454a0d75113770c4f797a4017
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:12 +02:00
Jukka Rissanen
ac390213ff net: Utility that inserts free space to the fragment list
Provide an utility function that pushes data down in the fragment
chain which means that there would be some free space before the
first fragment.

Change-Id: I491ac4e8cbf633f86f2351cad48d683e829bda63
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:12 +02:00
Jukka Rissanen
47d71db2f8 net: Utility function to compact net_buf fragments
Provide a function that checks if there is any free space
in the individual fragment and remove such slack. If there
are fragments that would become empty, then those fragments
are removed from the fragment list and freed to the fragment
pool.

Change-Id: Ieb1c953a1458622c4552c23ef38e330873cd27c3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:12 +02:00
Jukka Rissanen
4c9c626129 net: Initial UDP support
Create a handler for catching UDP network traffic. This commit
is only providing infrastructure for UDP management.

Change-Id: Ia6f8de62773a85f7b637b73bfe3c89197cc2abb1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:12 +02:00
Jukka Rissanen
813fdf85ed net: Add IPv6 minimum MTU value
Added define for minimum IPv6 MTU value (1280 bytes)

Change-Id: Ia81d8b3df079a2bb9bfb0a05e297d94423ba0fc5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
c30f90a4c4 net: Make some IPv6 utility functions to use const addr
Changed the net_is_ipv6_addr_unspecified() and
net_is_ipv6_addr_solicited_node() to use const IPv6 address
as those function do not change the address.

Change-Id: I1222bf946c371433a8468fa71054b93346e2ae4e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
abf82f4150 net: Add TTL IPv4 option
User can set the initial value for time-to-live option in Kconfig.
The TTL option is only used in IPv4.

Change-Id: I57677e65a2adee4aa4dc16d1504f848d1218c6c1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
38a3253744 net: Add net_nbuf_copy() utility function
This function will copy desired amount of bytes from one
fragment list to another. Caller can specify amount of
bytes reserved in front of the new fragment list.

Change-Id: Ie3344b285a47c79f116fbcff500d383a99d28bf9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
57ab8e0899 net: Make IPv6 ND optional
It is possible to turn of IPv6 neighbor discovery if it is
not used in order to save some memory.

Change-Id: I20159dd452b7bac6962532a91e844c33f3da2dfb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
eca55e103e net: Initial router advertisement support
Change-Id: I842a5aeff870da71eeabdc29c8ea730c541eddd0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
66f87c9542 net: Initial router solicitation support
Change-Id: Ic3aee9999656ab435e0965456d94fd5540b4e220
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
9b3d8378e5 net: Initial IPv6 neighbor discovery support
Change-Id: I76dc7471c56085a61bbdd9f75ecb49aeb0874dbb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:11 +02:00
Jukka Rissanen
53caa13652 net: Refactored ARP packet header handling
The ARP packet header contained ethernet header. This is very
confusing so separate the link layer header. Fixed also the
unit tests to run properly.

Change-Id: I8b00bde280ad9f49494766370acb2a8e9cade033
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:10 +02:00
Jukka Rissanen
b4b296b888 net: Add utility func to return eth broadcast addr
As the broadcast address is needed in both arp.c and ethernet.c
it is useful to create a utility function for returning that.

Change-Id: I26e75e325f7ee6dcd703a92b3349bd8d388e157e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:10 +02:00
Jukka Rissanen
4352795436 net: Calling net_buf_put() instead of nano_fifo_put()
Because of commit 7720f6ed1c ("net: buf: Introduce support
for fragmentation") the net_buf should be placed into queue by
calling net_buf_put() when using fragmented data.

Change-Id: I5c3dae92596e9cb0d0ba166bc3de2da9f4fc24b7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:09 +02:00
Jukka Rissanen
79fc041407 net: Add link layer reserve information to l2 driver
Caller can figure out what is the link layer header size
for a given link layer. There is a callback that can return
a dynamic header size if needed.

Change-Id: I59ea2319eb6cb53a0ba5c6aa9e7eecc4b38c94d3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:09 +02:00
Jukka Rissanen
60752bd08d net: Set the l2 src/dst addresses in nbuf
We need to know where the L2 protocol source and destination
addresses are so save that information in nbuf.

Change-Id: I08677a0421effb0c997c6a68cfc02ccfa67e7e1e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:09 +02:00
Jukka Rissanen
068f0bf092 net: Add ethernet address helpers
Add helper to check Ethernet broadcast and multicast address.

Change-Id: Icfe5508a4d3ab2364209a50150a4f8fe239ebc93
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:09 +02:00
Ravi kumar Veeramally
5a15b9070c net: Add utility to remove ipv4 address from iface
Change-Id: Ic1366f575ac476b25a240be99df3b82594df2891
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:09 +02:00
Jukka Rissanen
c13ffd3433 net: Fix arp.h so that net_arp_init() is found
The net_arp_init() was not properly declared if IPv4 was
not active.

Change-Id: I479b93f67c4536bcf9a081c36a6bc82dc5605c4c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:08 +02:00
Jukka Rissanen
01423a8467 net: Network stack analyzer uses now the SYS_LOG sub-system
Use SYS_LOG instead of directly printing using printk()

Change-Id: I61cff11cf8424f726f24ea00b447f2f4827f2c9c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:08 +02:00