Commit graph

1260 commits

Author SHA1 Message Date
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
Jukka Rissanen
41f584ee51 net: Do not overwrite SYS_LOG_DOMAIN
The net_core.h accidentally overwrote SYS_LOG_DOMAIN with "net".
This must be done only for network related log domain.

Change-Id: I1050e430e8b649126e527f28c61d191ff34bbf2f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:08 +02:00
Jukka Rissanen
45afd1b0a7 net: The NET_DEBUG must not be set in header file
Setting NET_DEBUG in nbuf.h will confuse the net_core.h
so it should not be done here. The NET_DEBUG can only be
set in .c file.

Change-Id: Ia95996147bf119c4ddf9f45a9fd635f8d2b405cb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:08 +02:00
Jukka Rissanen
4f193e5baf net: Refactor various network init functions
There is no need to check if the sub-system is initialized
because net_init() is the only place that will call these
functions.

Change-Id: Icd54d2adf2924431cedd7c47124a3410842aeca3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:08 +02:00
Jukka Rissanen
7a88cee800 net: The IP protocol type needs to be set in L2 layer
The network L2 recv handler needs to set the initial value for
IP protocol type (IPv4 or IPv6). Otherwise the recv data check
in net_core.c:process_data() will not work properly if IPv4
is enabled.

Change-Id: I5684cd10e5d79e13a977406729ea68313e689c9b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
fa15fe3de6 net: Add IPv6 address network interface utils
Various utilities for IPv6 address manipulation in network
interface.

Change-Id: I270f0935288abd77d64c0f64f56b549fb6c4feb9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
e42774ce42 net: Add IPv6 utils for address manipulation
Change-Id: Iea5a0c81c5d35080b0206e33b4f279100fd0c80b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
ec689c32f9 net: Changing IPv4 address compare to a function
The IPv4 comparer was a macro but making it now a inline
function.

Change-Id: I315c52d812996e352e9b392627296ba229530ae0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
518eedf1a2 net: Use const for static and pre-defined IPv6 addresses
Change-Id: Ia1ed07e6bd93d2102c6c25ab8cb1ccdc9cf80d17
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
301feea5b4 net: Add struct to store link layer address
Adding a variant for net_linkaddr that can actually store
a link layer address. The normal net_linkaddr struct just
uses pointer to a ll address. The storage version is used
when we have a lladdr cache for neighbors.

Change-Id: I57421047f66090caf09595981c81d386144edce3
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:07 +02:00
Tomasz Bursztyka
b81ece31e4 net: Add comment explaining net_core's verdict values
It is then clear what logic to expect once such verdict has been given.

Change-Id: Id64ff00e65ffe2dad45673d1eca4eb76ae3ae1f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:07 +02:00
Jukka Rissanen
b6834c2467 net: Add NET_ASSERT() macro
Change-Id: Ie98da69fbd1cf277a5d517736217209c85180416
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
82a6e963f4 net: Removing capabilities from net_if api
As there is a L2 in the middle, there is no need for
net_if to provide such information.

Change-Id: I58a35d4d124cd8a67026f32e71713ef06f43b7c5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
4090b4c01f net: Add an L2 layer
Net core then does not know anything about l2 related logic.
For instance ARP is used in ethernet l2 API and nowhere else.
This will be helpful when adding different technologies altogether.

Currently, only SLIP driver is enabled to use relevant l2 layer.

Change-Id: I03c93326321028d04222733ca4083e3c6b785202
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
260d3b95d7 net: Make net_core.h include the least amount of necessary header
net_core.h is the ground brick of the IP stack, and thus should not
include other headers that might include net_core.h also: this would
create circular dependencies.

Change-Id: I70c17b736788528e4e0b4b5b2c478098b049c9b1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
d0b382c345 net: Add a helper to queue a buffer in a net_if instance
Makes code cleaner so it won't be necessary to access the net_if
internal queue directly.

Change-Id: I119a54e0639843093fa0da6f11e590e8990525d8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
249f889782 net: Shorten IPv4/6 config options
This is meant to stay in 80 chars line length limit.

Change-Id: Ib3b3b1cf5e05fec2407e470ae3600ff5a4c6a505
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Tomasz Bursztyka
8b6889ea25 net: Include toolchain related header for aliases
__packed is an alias for __attribute__(packed) and is declared in
toochain's headers.

Change-Id: Ib9d136a1a2dd401194988d6573bf7778f07dbfb6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:06 +02:00
Ravi kumar Veeramally
563835f7ed net: Use shorter alias for __packed attribute
Change-Id: I5bee3f1a9cf8629151734fc85b2c3e6097232cc0
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:05 +02:00
Ravi kumar Veeramally
3fe96a52e6 net: Add UDP header definition
Change-Id: I2f3bba1014cf598bed7606d5d43b3653052b1f7f
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:05 +02:00
Ravi kumar Veeramally
ada4f17711 net: Fix trivial comment errors in header files
Change-Id: I2f3bba1014cf598bed7606d5d43b3653052b1f88
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-12-02 12:40:05 +02:00
Jukka Rissanen
667d15de85 net: Add capabilities flag to net_if API
The network device driver can specify what kind of functionality
it supports. Currently there exists one flag that can be used
in ethernet devices that tells if ARP should be enabled or not.

Change-Id: Ieaaefcfc7cdd65f44190248f507ac3cb512a323e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
702ea43621 net: Add util to check if IPv4 address is part of a subnet
Change-Id: I6005861a4c4085b6c17ded03fda38a567a4e504a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
79fa53e17d net: Add utils to set IPv4 netmask and gateway to net_if
Change-Id: I52bcea3749aa5fb4e12b18fd9fd9a3907842bf01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
2593796d04 net: Add macro to compare two IPv4 addresses
Change-Id: I2af022d8a8df4c174e044d033a23d5912297e495
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
2b552fcc66 net: net_ipaddr_copy() macro was too fragile
Now making sure we are doing the IP address assignment correctly.

Change-Id: I8bf9233b932321a14df99ce49a39581f1343d004
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
af685962b6 net: Add utility function returning IPv4 broadcast address
Change-Id: Ibe4f5ad530f6a0f50137ef2cd8e64dbc9de6cba1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
94ba84426c net: Add utility function to return default network interface
Change-Id: Ia64d263831e2842883404d25b7ea429bea80ca1d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
b6a7648569 net: Process received ICMPv4 messages
Call ICMPv4 handler when receiving ICMP v4 packet.
Currently only echo-request msg is handled.

Change-Id: Ib59c65b38f13c484f1842485118dad32fb6a6f36
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:04 +02:00
Jukka Rissanen
402996e374 net: Network interface needs own TX fiber stack
Each network interface needs its own stack for TX fiber.

Change-Id: I9647c2b945a3d36bc77c00dad11badb0d5f851e5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:03 +02:00
Jukka Rissanen
d7e2897370 net: Add net_send_data() that sends data to network
This function is not meant to be used by applications as it
requires that the IP headers etc. are already in place.

Change-Id: I9099671111a029cdf630d131d7af09b147486f64
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:03 +02:00
Jukka Rissanen
5729d1c461 net: Renamed network data receive function
Renamed net_recv() to net_recv_data() so that the more generic
name can be used by applications. The net_recv_data() is only
meant to be used when L2 layer feeds data into L3 (IP) layer.

Change-Id: Iba155d51f81e3b99964fa916fe87a05a8bf8766a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:03 +02:00
Jukka Rissanen
6e803a9c6d net: Add ICMP protocol header struct
Add a macro to get and cast the ICMP protocol header.

Change-Id: Ief3f69d1b3dbe9dd55bc0a032b3506c8e0370563
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:03 +02:00
Jukka Rissanen
6e8fdd34fe net: Added API documentation to IP address check functions
Some API functions that check IP addresses were not documented
properly.

Change-Id: I0e7361447db55037888c62ada6b55e3cf5f410f7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:03 +02:00
Jukka Rissanen
d24f673248 net: Receive IPv4 packet
Check if we have received IPv4 packet and call a handler
function to process it.

Change-Id: I9f9e5f0888d2c3b91401c98f4925647ddce09962
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
93f129060d net: IPv6 address utility funcs for network interface
Added more functions to get proper IPv6 address from
a given network interface.

Change-Id: I5aecdb35eb549a0781949134ab4821dcb8ce9e7b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
cf5c1db262 net: Add IPv4 addresses to network interface
Allow user to assign IPv4 addresses to a network interface.

Change-Id: I77be4ed5eb0231eb12b4ad47cb6076c8f4238124
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
09d317ccd0 net: Utilities to set and lookup interface IPv6 addresses
The caller is able to add and lookup network interface IPv6
addresses.

Change-Id: I7f43e18bd1fa69c7dcd2f6b46ad33043c28b92e9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
f49de47f42 net: Add utility functions to check IPv6 addresses
IPv6 utility functions that check if a given IPv6 address
belongs to one of host network interfaces, and whether
the address is a given type.

Change-Id: If251534ae0af41963d45e305e7ba505a940d2fdc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
6646597a86 net: Add utility func to return IP address type as a string
This is only used in debugging.

Change-Id: Ie8b1d2540813527131ff489e49975a826b84311c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
cce1854b58 net: Drop received source mcast IPv6 packets
If the source address is multicast, then drop the IPv6 packet.

Change-Id: Ibe733161d67f047469a25a5955c41c335e472945
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
c44c229660 net: Receive IPv6 packet
Check if we have received IPv6 packet and call a handler
function to process it.

Change-Id: I1226729685ae2a805128b587e2a37e0016d53ecc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:02 +02:00
Jukka Rissanen
7047e00f85 net: Add net_context to compilation
Network context defines network endpoints a.k.a sockets.

Change-Id: Ib1fab03f0862b298a441a79a4f4173f18a8260cb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
8c8052497d net: Start to receive network packets
Currently all received packets are dropped as this is just
the initial patch enabling the receive support.

Change-Id: Ib06735f498a80edb8c9f7c5ec6f536a5ac1d362a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
f75d8a86bb net: Start to use logging macros from sys_log.h
Instead of directly calling printk/printf, the network printing
macros will use syslog macros defined in sys_log.h

Change-Id: I3f12f81557f50b24ca47a43f345162f9ffbd574c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
71f2a78316 net: Add send() to net_if API
The send() function is called from IP stack and it is used
when the network packet needs to be send via a specific
network interface.

Change-Id: Id6ce86b1748915fee73b62366dee13fcb7cf11a1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
b33d8d6591 net: Add net_if_get_by_link_addr() util function
This will return the network interface that has some specific
link address.

Change-Id: Iaebcf6e769d4f91f3cda6d3a0779324f89603b54
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
3e1aef117a net: Add net_analyze_stack() macro
This macro can be used to check stack usage. It should only
be used when debugging is activated.

Change-Id: I99fe6f9db1f3e955152a91f3a18d031126172cfd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
14cdced965 net: Fix compilation error in net_if.h
The NET_IF_INIT() macro used parameter pasting incorrectly.

Change-Id: I40a988ffb06ce135731cd69f18931b7507cd71cc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:01 +02:00
Jukka Rissanen
81298abfb4 net: Compile IPv6 and IPv4 address conditionally
Save 12 bytes per IP address if IPv4 is active and IPv6 is not.

Change-Id: Ia01d2feb83e6ba80b2775f9eed3065c956932632
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
920a5f5e38 net: Add function that feeds data to RX fifo
Network drivers should call this when new data has been
received from network.

Change-Id: Ife78fa0683b8c410c38358300a6a18e9325f0ef8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
e0e682eb66 net: Add TX fifo to network interface
Network packets to be sent are placed to correct fifo that
is allocated to certain network interface.

Change-Id: Idd5eded42758c5bed2c18769122c38d9d03dc419
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
510ebe255d net: Add IPv6 prefixes to network interface
Change-Id: I34c75eec6068abbd6af1eac2e178e42ce382b128
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
ad848dcfbf net: Add multicast address to network interface
Change-Id: Ifc09d2e1d3ac44ab0f5980ee17299119fbe2a867
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
ac479e19b8 net: Add network address information to interface
Change-Id: I14b9257362a1e6f4144900c7acde6a125ecf6a02
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Tomasz Bursztyka
2fa38c18f0 net: Add generic network interface header
This will be used by the new network stack to relate a device to actual
network context, and used in the different layers (mac, ip ...).

Change-Id: I30c08fa975314544c36b71636fd9653d562891b3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
b9289f176c net: Add ntohl() and related macros
Change-Id: Ia329a63644eab8ca1ce6debb8f7e7b97b8de711d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
9c5a6d17e2 net: Add defines for various IP protocol header lengths
Change-Id: I05dcb7a26f50cd0c8d544c5d829e1154ed3f8119
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:40:00 +02:00
Jukka Rissanen
a3b88f53c4 net: Initial commit for the new IP stack
This is a placeholder that compiles but does nothing else.

Change-Id: I9689fa26eb13bc23d29940938f7b3c11f32b2ff1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:39:59 +02:00
Luiz Augusto von Dentz
8062f6ea5a net: buf: Add extra logic when debug is enabled
In case of invalid behavior such as error or warnings print caller
function name and line number so it is easier to track back when there
there is a problem.

Change-Id: I3a5f4c7f63e0560fe0cf6f25936b079f127776a8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-28 14:57:44 +00:00
Benjamin Walsh
f6ca7de09c kernel/arch: consolidate tTCS and TNANO definitions
There was a lot of duplication between architectures for the definition
of threads and the "nanokernel" guts. These have been consolidated.

Now, a common file kernel/unified/include/kernel_structs.h holds the
common definitions. Architectures provide two files to complement it:
kernel_arch_data.h and kernel_arch_func.h. The first one contains at
least the struct _thread_arch and struct _kernel_arch data structures,
as well as the struct _callee_saved and struct _caller_saved register
layouts. The second file contains anything that needs what is provided
by the common stuff in kernel_structs.h. Those two files are only meant
to be included in kernel_structs.h in very specific locations.

The thread data structure has been separated into three major parts:
common struct _thread_base and struct k_thread, and arch-specific struct
_thread_arch. The first and third ones are included in the second.

The struct s_NANO data structure has been split into two: common struct
_kernel and arch-specific struct _kernel_arch. The latter is included in
the former.

Offsets files have also changed: nano_offsets.h has been renamed
kernel_offsets.h and is still included by the arch-specific offsets.c.
Also, since the thread and kernel data structures are now made of
sub-structures, offsets have to be added to make up the full offset.
Some of these additions have been consolidated in shorter symbols,
available from kernel/unified/include/offsets_short.h, which includes an
arch-specific offsets_arch_short.h. Most of the code include
offsets_short.h now instead of offsets.h.

Change-Id: I084645cb7e6db8db69aeaaf162963fe157045d5a
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-12 07:04:52 -05:00
Szymon Janc
2f45faba8c net: buf: Use unified k_fifo API for FIFOs
Only net_receive() is using non-special value for net_buf_get_timeout
so this change is included here. Other users are using special values
which are already correctly handling ticks vs ms change.

Change-Id: Ib12d34ac5a546b36fa7b35615f082c82a256bd07
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:17 +00:00
Szymon Janc
ccadd4b006 net: Use proper format for printing size_t
size_t should be printed with %zu. This also fix build error on
unified kernel due to ZEP-1133.

Change-Id: I9c5fc7f7de365e47bd0973913b94baa80f7907e3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-27 08:08:27 +00:00
Luiz Augusto von Dentz
76240677d9 net: buf: Make net_buf_frag_add take ownership of the buffer
This simplify buffer handling so that no extra references are needed.

Change-Id: Id99a0a75b39ca8db2216668f76c5a672713075ae
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-26 12:48:47 +00:00
Anas Nashif
45616f24e7 Revert "net: fetch valid conn. to determine MSS in data_is_sent_and_acked()"
This reverts commit 627feb92d4.

This patch breaks TCP/IPv4 support in echo_server.

Change-Id: Ia1e2cf8dfa94f845d3a8282c83bba40b36ee782c
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-14 07:12:06 +00:00
Rohit Grover
627feb92d4 net: fetch valid conn. to determine MSS in data_is_sent_and_acked()
Packets sent out through net_tx_fiber go through psock_send() where
they wait for data_is_sent_and_acked() to process them.
data_is_sent_and_acked() looks at the underlying connection's
MSS (maximum segment size) before putting them on the wire through
uip_send(). The trouble is that that linkage between the outgoing
buffer and the connection hasn't been established at the point
data_is_sent_and_acked() is called--this normally happens through
a call to uip_set_conn().
So data_is_sent_and_acked() fetches an invalid connection handle
and makes its choice using an arbitrary MSS. In my particular case,
this arbitrary value was 0, and so packets weren't being sent out.

Change-Id: I42e8ae104ac20f8df8780c8aee6964ed37113ba0
Signed-off-by: Rohit Grover <rohit.grover@arm.com>
2016-10-08 21:20:28 +00:00
Johan Hedberg
27fc467e74 net: buf: Allow NULL head pointer when inserting to frag list
To avoid extra logic in code that creates net_buf fragment lists, make
it possible to pass a NULL pointer as the head net_buf when there are
no previous buffers. Before this change the code would look like this:

	if (head) {
		net_buf_frag_add(head, buf);
	} else {
		head = net_buf_ref(buf);
	}

After the patch the code can simply do:

	head = net_buf_frag_add(head, buf);

This will then do the right thing regardless if head is NULL or
non-NULL.

Change-Id: I300394242e2e243ed3839b25629ec816dd98c148
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-30 15:07:32 +00:00
Johan Hedberg
8afb6fc229 net: buf: Allow head deletion with net_buf_frag_del()
Extend the net_buf_frag_del() API to be usable for deleting the head
of a fragment chain. This is useful when parsing a stream-based
protocol encoded into a fragment chain, making code such as the
following possible:

	...parse data from 'head' buffer...

	/* If current buffer is empty, move to the next one */
	if (!head->len) {
		head = net_buf_frag_del(NULL, head);
	}

Change-Id: I65794bd7fab4e6dadfd2d6b2fa367f9424fd1bde
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-30 15:07:32 +00:00
Ravi kumar Veeramally
69236fd49a net: Fix net_send return value documentation
If net_send() is success, do not unref the buffer. Free the buf
when it returns error.

Change-Id: Ic154879dfb583d52a0b12fd3e8bfc390a24efec9
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-09-12 02:19:57 +00:00
Inaky Perez-Gonzalez
3e63a74514 net/yaip: revert merge
Follow up to TSC decission for further discussion in the networking
WIG.

Change-Id: I148b484dfe308661573e47ed3e60cceed673bddf
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-07-22 04:43:09 +00:00
Johan Hedberg
e088b06e44 net: buf: Add API for saving & restoring parsing state
Occasionally it may be useful to pass a buffer to a subroutine and
have the routine do parsing of the buffer. However, since there isn't
necessarily a guarantee of how the subroutine performs the parsing it
may be necessary to restore to a well known state after the routine
returns.

This patch adds a simple struct for storing the parsing state as well
as two new functions to save and restore the state.

Change-Id: If9153ff9997021c76243ea9ebff13dfe94c45faa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-20 14:51:24 +03:00
Johan Hedberg
1de77488ae net: buf: Add net_buf_add_be32 helper
Add helper to add 32-bit big endian data to net_buf and
net_buf_simple.

Change-Id: Ib6359558abcbed824365928327277ad69aa51e99
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-19 11:13:08 +03:00
Johan Hedberg
94aa7e6cb0 net: buf: Minor cleanups & fixes to the API documentation
Rename left-over mentions of 'bt_buf' and ensure that all parameter
descriptions end with a period.

Change-Id: Ie63e63920a8bfea2d02806a65306421264c9f89b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-14 05:10:13 +00:00
Johan Hedberg
477fedcf1f net: buf: Add more big endian helpers
Change-Id: I3f8d9a2810359a0cc7b7ce2097f86e03fa35d3bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-13 14:11:37 +00:00
Johan Hedberg
77dfa93f47 net: buf: Add helpers to use net_buf_simple stack variables
Add a macro to easily define net_buf_simple stack variables, as well
as a helper to initialize them.

Change-Id: I3e4ffc172843a0946e8159618c8f84a87fc682bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-13 14:11:26 +00:00
Jukka Rissanen
d0daa97820 net: yaip: Moved ARP helper macro to arp.h
The helper macro NET_ARP_BUF() needs to be used from other
files so arp.h is proper place for it.

Change-Id: Ief7bbb385d9c180213ecd7cb08023f13999f5270
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:23 +00:00
Tomasz Bursztyka
56a747ead4 net: yaip: Add comment explaining net_core's verdict values
It is then clear what logic to expect once such verdict has been given.

Change-Id: Id64ff00e65ffe2dad45673d1eca4eb76ae3ae1f6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:23 +00:00
Jukka Rissanen
902912adbb net: yaip: Add NET_ASSERT() macro
Change-Id: Ie98da69fbd1cf277a5d517736217209c85180416
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:22 +00:00
Tomasz Bursztyka
5c64a078f4 net: yaip: Removing capabilities() from net_if api
As there is a L2 in the middle, there is no need for a net_if to provide
such information.

Change-Id: I58a35d4d124cd8a67026f32e71713ef06f43b7c5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:21 +00:00
Tomasz Bursztyka
d8f0b9ffed net: yaip: Add an L2 layer
Net core then does not know anything about l2 related logic.
For instance ARP is used in ethernet l2 API and nowhere else.
This will be helpful when adding different technologies altogether.

Currently, only SLIP driver is enabled to use relevant l2 layer.

Change-Id: I03c93326321028d04222733ca4083e3c6b785202
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:20 +00:00
Tomasz Bursztyka
bb1fe0c147 net: yaip: Make net_core.h include the least amount of necessary header
net_core.h is the ground brick of the IP stack, and thus should not
include other headers that might include net_core.h also: this would
create circular dependencies.

Change-Id: I70c17b736788528e4e0b4b5b2c478098b049c9b1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:19 +00:00
Tomasz Bursztyka
1f9f3e138b net: yaip: Add an helper to queue a buffer in a net_if instance
Makes code cleaner so it won't be necessary to access the net_if
internal queue directly.

Change-Id: I119a54e0639843093fa0da6f11e590e8990525d8
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:19 +00:00
Tomasz Bursztyka
bbf7d35001 net: yaip: Shorten IPv4/6 config options
This is meant to stay in 80 chars line length limit.

Change-Id: Ib3b3b1cf5e05fec2407e470ae3600ff5a4c6a505
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:18 +00:00
Tomasz Bursztyka
514f184350 net: yaip: Include toolchain related header for aliases
__packed is an alias for __attribute__(packed) and is declared in
toochain's headers.

Change-Id: Ib9d136a1a2dd401194988d6573bf7778f07dbfb6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-13 14:06:17 +00:00
Ravi kumar Veeramally
4450a41532 net: yaip: Fix __packed attribute, use shorter alias
Change-Id: I5bee3f1a9cf8629151734fc85b2c3e6097232cc0
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-07-13 14:06:15 +00:00
Ravi kumar Veeramally
7789df23d1 net: yaip: Add UDP header
Change-Id: I2f3bba1014cf598bed7606d5d43b3653052b1f7f
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-07-13 14:06:15 +00:00
Ravi kumar Veeramally
2cdbb932df net: yaip: Trivial comment fixes in header files
Change-Id: I2f3bba1014cf598bed7606d5d43b3653052b1f88
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-07-13 14:06:14 +00:00
Ravi kumar Veeramally
3ef38a6e05 net: yaip: Provide separate header file for ethernet
Change-Id: I2f3bba1014cf598cdd7606d5d43b3653052b1f7f
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-07-13 14:06:14 +00:00
Jukka Rissanen
6fd8c1750d net: yaip: Add helper to get pointer to link local header
Change-Id: I079fb35e26499797f14f233b69a152ab1c86f9d0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:10 +00:00
Jukka Rissanen
fabdce2899 net: yaip: Added IPv4 ARP support
Small IPv4 ARP cache that is used in Ethernet networks.

Change-Id: I9ab38ee14a799f8573f4d4e0eade1be107d42f1a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:07 +00:00
Jukka Rissanen
9de396cfb9 net: yaip: Add capabilities flag to net_if API
The network device driver can specify what kind of functionality
it supports. Currently there exists one flag that can be used
in ethernet devices that tells that ARP should be enabled.

Change-Id: Ieaaefcfc7cdd65f44190248f507ac3cb512a323e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:07 +00:00
Jukka Rissanen
892a76745f net: yaip: Add util to check if IPv4 address is part of subnet
Change-Id: I6005861a4c4085b6c17ded03fda38a567a4e504a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:06 +00:00
Jukka Rissanen
575ad92ffd net: yaip: Add utils to set IPv4 netmask and gateway in net_if
Change-Id: I52bcea3749aa5fb4e12b18fd9fd9a3907842bf01
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:06 +00:00
Jukka Rissanen
554c83f1de net: yaip: Macro to compare two IPv4 addresses
Change-Id: I2af022d8a8df4c174e044d033a23d5912297e495
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:05 +00:00
Jukka Rissanen
630339064c net: yaip: net_ipaddr_copy() macro was too fragile
Making sure we are doing the IP address assignment correctly.

Change-Id: I8bf9233b932321a14df99ce49a39581f1343d004
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:05 +00:00
Jukka Rissanen
b826212ed7 net: yaip: Add utility function returning IPv4 broadcast address
Change-Id: Ibe4f5ad530f6a0f50137ef2cd8e64dbc9de6cba1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-13 14:06:05 +00:00
Johan Hedberg
497268503e net: buf: Add complete net_buf_simple implementation
This just renames the existing net_buf helper APIs to corresponding
net_buf_simple APIs and then defines the old net_buf API names as
macros mapping to the new net_buf_simple helpers.

Change-Id: I3c2b35683c0fde66f5f697be2c34c01172af8e31
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-13 14:05:32 +03:00
Johan Hedberg
2d5bfe2f1f net: buf: Introduce net_buf_simple object
The object has the same layout as the last fields of the existing
net_buf. To maintain backwards compatibility net_buf receives a union
so that the old data, len and size members can be accessed as before,
however they are located in the same memory as the actual
net_buf_simple members.

Change-Id: I22d208faba30fe41c5ada17e6d13e641f528729a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-13 09:34:42 +00:00
Johan Hedberg
4e833a6522 net: buf: Group the data, size and len members at the end of net_buf
This is in preparation of introducing a new net_buf_simple object &
API.

Change-Id: I624b86e5d2c9f4e9d3647b2fe21ce8b89750256f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-13 09:34:22 +00:00
Jaakko Hannikainen
cf3fe37962 net: Add documentation about yielding
Now that net_send and net_reply yield, this behaviour should be
documented.

Jira: ZEP-469
Jira: ZEP-497

Change-Id: I8c3cf7bda009aa6e89f880447fd3b6a491f5d9ef
Signed-off-by: Jaakko Hannikainen <jaakko.hannikainen@intel.com>
2016-07-13 09:20:11 +00:00
Jukka Rissanen
ebfa17eebe net: yaip: Add utility function to return default network interface
Change-Id: Ia64d263831e2842883404d25b7ea429bea80ca1d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:58 +00:00
Jukka Rissanen
30b07ad70a net: yaip: Process received ICMPv4 messages
Call ICMPv4 handler when receiving such a network packet.
Currently only echo-request is handled.

Change-Id: Ib59c65b38f13c484f1842485118dad32fb6a6f36
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:57 +00:00
Jukka Rissanen
4eb4ee49f5 net: yaip: Network interface needs own TX fiber stack
Each network interface needs its own stack for TX fiber.

Change-Id: I9647c2b945a3d36bc77c00dad11badb0d5f851e5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:53 +00:00
Jukka Rissanen
cada55f5be net: yaip: Add net_send_data() that sends data to network
This function is not meant to be used by applications as it
requires that the IP headers etc. are already in place.

Change-Id: I9099671111a029cdf630d131d7af09b147486f64
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:53 +00:00
Jukka Rissanen
de67431a43 net: yaip: Renamed network data receive function
Renamed net_recv() to net_recv_data() so that the more generic
name can be used by applications. The net_recv_data() is only
meant to be used when L2 layer feeds data into L3 (IP) layer.

Change-Id: Iba155d51f81e3b99964fa916fe87a05a8bf8766a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:52 +00:00
Jukka Rissanen
cb2191652e net: yaip: Add ICMP protocol header struct
Add a macro to get and cast the ICMP protocol header.

Change-Id: Ief3f69d1b3dbe9dd55bc0a032b3506c8e0370563
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:51 +00:00
Jukka Rissanen
1b2069c61c net: yaip: Fixed the IP/UDP/ICMP getter macros
The nbuf macros for getting the pointer to start of IP, UDP
and ICMP buffer were incorrect.

Change-Id: I6309bd50cdf2cbf0c6c23b4b349c7c084cfe928d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:51 +00:00
Jukka Rissanen
7150b0035c net: yaip: Added API documentation to IP address check functions
Some API functions that check IP addresses were not documented
properly.

Change-Id: I0e7361447db55037888c62ada6b55e3cf5f410f7
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:50 +00:00
Jukka Rissanen
fbb940d9f0 net: yaip: Receive IPv4 packet
Check if we have received IPv4 packet and call a handler
function to process it.

Change-Id: I9f9e5f0888d2c3b91401c98f4925647ddce09962
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:50 +00:00
Jukka Rissanen
d85fa3fe2d net: yaip: IPv6 address utility funcs for network interface
Added more functions to get proper IPv6 address from
a given network interface.

Change-Id: I5aecdb35eb549a0781949134ab4821dcb8ce9e7b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:49 +00:00
Jukka Rissanen
272c8a62a1 net: yaip: Add IPv4 addresses to network interface
Allow user to assign IPv4 addresses to a network interface.

Change-Id: I77be4ed5eb0231eb12b4ad47cb6076c8f4238124
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:48 +00:00
Jukka Rissanen
208d558f68 net: yaip: Utilities to set and lookup interface IPv6 addresses
The caller is able to add and lookup network interface IPv6
addresses.

Change-Id: I7f43e18bd1fa69c7dcd2f6b46ad33043c28b92e9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:47 +00:00
Jukka Rissanen
a08376cc32 net: yaip: Add utility functions to check IPv6 addresses
IPv6 utility functions that check if a given IPv6 address
belongs to one of host network interfaces, and whether
the address is a given type.

Change-Id: If251534ae0af41963d45e305e7ba505a940d2fdc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:47 +00:00
Jukka Rissanen
644dc3ba81 net: yaip: Add utility func to return IP address type as a string
This is only used in debugging.

Change-Id: Ie8b1d2540813527131ff489e49975a826b84311c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:46 +00:00
Jukka Rissanen
3308e95b97 net: yaip: Add extension header and bitmap fields to nbuf
These are needed when parsing IPv6 packet.

Change-Id: I56ab93d45727c57f2d9db47baeb5b5a3725a0c46
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:46 +00:00
Jukka Rissanen
e54c565337 net: yaip: Drop received source mcast IPv6 packets
If the source address is multicast, then drop the IPv6 packet.

Change-Id: Ibe733161d67f047469a25a5955c41c335e472945
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:45 +00:00
Jukka Rissanen
d9c3552e00 net: yaip: Receive IPv6 packet
Check if we have received IPv6 packet and call a handler
function to process it.

Change-Id: I1226729685ae2a805128b587e2a37e0016d53ecc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:45 +00:00
Jukka Rissanen
27dcfc3efd net: yaip: Add statistics gathering support
Collect network statistics if CONFIG_NET_STATISTICS is
defined.

Change-Id: Id217daa3e19142c95396dc391ba2dc4123b18b22
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:43 +00:00
Jukka Rissanen
c43212d63c net: yaip: Add net_context to compilation
Network context defines network endpoints a.k.a sockets.

Change-Id: Ib1fab03f0862b298a441a79a4f4173f18a8260cb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:43 +00:00
Jukka Rissanen
5a3834915d net: yaip: Start to receive network packets
Currently all received packets are dropped as this is just
the initial patch enabling the receive support.

Change-Id: Ib06735f498a80edb8c9f7c5ec6f536a5ac1d362a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 19:20:42 +00:00
Johan Hedberg
ce88b0528f net: buf: Add basic documentation for net_buf struct
Change-Id: I93404bcafb72c174a216d3e441c5434a7302c128
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-12 11:39:23 +00:00
Johan Hedberg
40d83b28e6 net: buf: Fix documentation of fragment related API
Ensure that all parameters and return values are properly documented.

Change-Id: I04b19701355e994ba45cbc98167386c01d0f607b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-12 11:35:49 +00:00
Jukka Rissanen
6bd7430a34 net: yaip: Start to use logging macros from sys_log.h
Instead of directly calling printk/printf, the network printing
macros will use syslog macros defined in sys_log.h

Change-Id: I3f12f81557f50b24ca47a43f345162f9ffbd574c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:23:49 +00:00
Jukka Rissanen
b133b01d67 net: yaip: Add send() to net_if API
The send() function is called from IP stack and it is used
when the network packet needs to be send via a specific
network interface.

Change-Id: Id6ce86b1748915fee73b62366dee13fcb7cf11a1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:23:41 +00:00
Jukka Rissanen
17ddda8721 net: yaip: Add net_if_get_by_link_addr() util function
This will return the network interface that has some specific
link address.

Change-Id: Iaebcf6e769d4f91f3cda6d3a0779324f89603b54
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:23:24 +00:00
Jukka Rissanen
a8aabd8571 net: yaip: Add net_analyze_stack() macro
This macro can be used to check stack usage. It should only
be used when debugging is activated.

Change-Id: I99fe6f9db1f3e955152a91f3a18d031126172cfd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:22:48 +00:00
Jukka Rissanen
bc24ec86fe net: yaip: Fix compilation error in net_if.h
The NET_IF_INIT() macro used parameter pasting incorrectly.

Change-Id: I40a988ffb06ce135731cd69f18931b7507cd71cc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:22:40 +00:00
Jukka Rissanen
b7bc53ece9 net: yaip: Add nbuf buffer API
User should use the net_nbuf API that is supporting a concept
of RX, TX and DATA buffers, instead of using directly the net_buf
low level API.

Change-Id: I3b8f5f13cd37d42d2322a58b35573e117d520c54
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:22:24 +00:00
Jukka Rissanen
c630347683 net: yaip: Compile IPv6 and IPv4 address conditionally
Save 12 bytes per IP address if IPv4 is active and IPv6 is not.

Change-Id: Ia01d2feb83e6ba80b2775f9eed3065c956932632
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:22:14 +00:00
Jukka Rissanen
6c6a3856bc net: yaip: Add function that feeds data to RX fifo
Network drivers should call this when new data has been
received from network.

Change-Id: Ife78fa0683b8c410c38358300a6a18e9325f0ef8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:22:05 +00:00
Jukka Rissanen
5a90d28a72 net: yaip: Add TX fifo to network interface
Network packets to be sent are placed to correct fifo that
is allocated to certain network interface.

Change-Id: Idd5eded42758c5bed2c18769122c38d9d03dc419
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:21:47 +00:00
Jukka Rissanen
61aae6ab27 net: yaip: Add IPv6 prefixes to network interface
Change-Id: I34c75eec6068abbd6af1eac2e178e42ce382b128
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:21:30 +00:00
Jukka Rissanen
daf4871e36 net: yaip: Add multicast address to network interface
Change-Id: Ifc09d2e1d3ac44ab0f5980ee17299119fbe2a867
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:21:21 +00:00
Jukka Rissanen
d4e0025eb7 net: yaip: Add network address information to interface
Change-Id: I14b9257362a1e6f4144900c7acde6a125ecf6a02
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:21:12 +00:00
Tomasz Bursztyka
5f165e743f net: Add generic network interface header
This will be used by the new network stack to relate a device to actual
network context, and used in the different layers (mac, ip ...).

Change-Id: I30c08fa975314544c36b71636fd9653d562891b3
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-12 07:20:51 +00:00
Tomasz Bursztyka
257379d0ff net: Add header file for generic link address
It only describes the structure for now, but will then provide helpers.

Change-Id: I7ac7717a3289086dac50d90e25b2a1ce7d7abc91
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-07-12 07:20:40 +00:00
Jukka Rissanen
8e7007c26f net: yaip: Add ntohl() and related macros
Change-Id: Ia329a63644eab8ca1ce6debb8f7e7b97b8de711d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:19:51 +00:00
Jukka Rissanen
7db376cfec net: yaip: Add defines for various IP protocol header lengths
Change-Id: I05dcb7a26f50cd0c8d544c5d829e1154ed3f8119
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:18:45 +00:00
Jukka Rissanen
75ae39518c net: yaip: Initial commit for new IP stack
This is a placeholder that just compiles but does nothing else.

Change-Id: I9689fa26eb13bc23d29940938f7b3c11f32b2ff1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-12 07:18:06 +00:00
Jukka Rissanen
83707d5675 net: buf: Calculate amount of bytes in fragments
Utility function net_buf_frags_len() calculates amount of data
stored in the fragments.

Change-Id: I89ebc8dac4f216ff9e77b5c44002082398957f7b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-11 18:06:24 +00:00
Jukka Rissanen
4605a3771c net: buf: Add fragmentation API support
User can add fragments to the network packet if the data cannot
be placed in one buffer.

Change-Id: I060ef533cc4fdda0f38405fb7dc72015f5cac7fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-07-11 15:37:45 +00:00
Johan Hedberg
abc142bdc3 net: buf: Add net_buf_push_u8() helper API
This is similar to the other net_buf_*_u8() helpers that already
exist.

Change-Id: I63fc963877c1946964e675067dd98f748be7cbbc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-09 15:43:31 +03:00
Johan Hedberg
30cb395bbf net: buf: Add big-endian helpers
Add helpers for big-endian 16-bit values, similar to the ones that
already exist for little-endian values.

Change-Id: I63bf4dd7df802669ea6657cd95d6da48e6176487
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-09 15:43:31 +03:00
Johan Hedberg
727a2459b1 net: buf: Add net_buf_reserve() API
This API allows initializing the buffer with a given headroom. This
prepares the way for eventually removing the 'reserve_head' parameter
from the net_buf_get APIs, but can already now be useful in some
scenarios where the headroom is desired to be different than some
higher level API sets it to be.

Change-Id: Iffbe5761fdf3d2ad8cb4b8437b1074cf42ea9c6c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-09 15:43:31 +03:00
Johan Hedberg
e03151ee3e net: buf: Use precise buffer size given to NET_BUF_POOL
Until now, NET_BUF_POOL() would be opportunistic and allocate a few
more bytes extra for the buffer content if the given size wasn't a
multiple of 4. This is an issue however if the API user really wants
to have a precise size for the buffer so that e.g. net_buf_tailroom
gives meaningful and deterministic results.

This patch removes the opportunistic rounding up, basically leaving it
up to the application to decide if it wants to have unused padding in
the data structure or not.

The crucial thing here is to ensure that locating the user data
section (which is aligned to a 4-byte boundary) doesn't break, since
buf->size is used for that. However, the net_buf_user_data()
implementation already uses ROUND_UP() so the result will still be
the same even if buf->size is not a multiple of 4.

Change-Id: I4bc17139cda19a680180c2d326d417a41ad0d4cd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-09 15:43:31 +03:00
Tomasz Bursztyka
0e0509b67f net: Let's use inline function for type checking for net_buf
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: I17fb1f5a1c1854461fad101bbb40c9be33844c8b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-06-22 16:43:29 +00:00
Tomasz Bursztyka
06717d3196 net: Fix documentation of buf.h
Make sure all is documented, and the comments properly formated.

Change-Id: I7431535b0f3a409e63ac4b12c421be662098eed1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-06-22 13:34:46 +00:00
Johan Hedberg
7720f6ed1c net: buf: Introduce support for fragmentation
Introduce support buffer fragment chains that are linked together.
This is done with the help of a flag while the buffer is inside a FIFO
(indicating that the next fragment follows it in the same FIFO) and
with the help of a "next" pointer while the buffer is outside of a
FIFO.

In order to do proper "marshaling" a new net_buf_put() API needs to be
always used when inserting a buffer into a FIFO. Respectively, the
net_buf_get() and net_buf_get_timeout() functions are extended to
support getting buffers from arbitrary FIFOs and reassemble the
fragment chain based on the flags that the received buffers contain.

The insertion of a fragment chain using net_buf_put() into a FIFO is
done atomically with the help of irq_lock/unlock since FIFOs support
multiple writers, however since there's ever only a single reader per
FIFO similar locking is not necessary there.

Change-Id: I0ec579f63ea8d063f50e3f1f4c2e80ec399622d7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-06 08:17:24 +03:00
Johan Hedberg
6e4d2a9e0e net: Add net_buf_get_timeout() API
With this API it's possible for the caller to force specific behavior
when it comes to waiting (or not waiting) on the FIFO.

Change-Id: Ib66e2f767c26c82abf1ba3b80bd15aec2383542e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-02 10:32:20 +00:00
Ravi kumar Veeramally
5e99b14ad4 net: 6lowpan: Fix 6lowpan fragmentation
IP packet passing through 6lowpan compression and 802.15.4
fragmentation has an issue. (RFC 6282 and 4944) RFC4944, 5.3
says "fragment header's datagram_size and datagram_offset
values as the size and offset of the IPv6 datagram before
compression".

At the moment datagram size and offset values are after
compression. Due to multiple bearer (15.4 and bluetooth) support
and multiple incoming buffers support functionality is divided
to compression and fragmentation parts. And datagram size and
offset values for BT are after compression. Small packet (which
doesn't need fragmentation) doesn't go through this. So cacheing
compressed and uncompressed header lengths and with hdr difference
preparing fragments as per original buffer (total buf size and offset).

Change-Id: I9d3b0433e64964c68519d7c007cc06ec6035b573
Jira: ZEP-208
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2016-05-19 14:18:38 +00:00
Jukka Rissanen
3b7208db84 net: Do not wait forever when sending TCP data
If application calls net_send(), set the retry count to some
low number (currently 5) so that we do not wait forever but
eventually we try to send the data properly.

Change-Id: I8103246ac9227a0cf70b56aecab6ed8307877e19
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-05-17 09:57:28 +03:00
Jukka Rissanen
662ce340be net: Add functions to return connection status needed in TCP
These are internal functions needed when initiating a TCP
connection.

Change-Id: Ide5d59ac9854ec8bdea3baa97b3cde3ffa6a5e0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-05-17 09:57:28 +03:00
Arkadiusz Lichwa
e59773bb48 net: buf: Add net_buf_pull_le32() helper API
The function gets 32bit-wide data from net buffer and converts the
value from little endian to host order.

Change-Id: I2d2454951b3ac39686a25454678ce92d8a1a0f3d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-15 19:39:14 +00:00
Arkadiusz Lichwa
fcb6e03021 net: buf: Add net_buf_add_le32() helper API
The function gets 32bits wide data, converts host order to little
endian and then puts the data on protocol stack to be send.

Change-Id: I29e4040b302a16b551a0922133c327ff694fec5d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-13 07:55:39 +00:00
Jukka Rissanen
ad2e661569 net: Enable TCP support
User can enable TCP server (listening socket) support in the
IP stack. This commit does not yet have TCP client (connecting
socket) support.

Change-Id: I75dd02a81addc1d1e026463b53631d56378157df
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-04-25 09:40:32 +03:00
Jukka Rissanen
bf5d208f25 net: buf: Add helper for catching ref counting errors
Add ip_buf_ref() helper that helps to track the calls to
net_buf refcounting in IP stack.

Change-Id: Ie5f5a5d57b6ffcb20df4fbc9f25c6c73a99589df
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-04-18 12:07:20 +00:00
Vlad Lungu
0667c0fe0e net: contiki: move neighbor_list to struct l2_buf
When using the CSMA MAC driver, a new packet can be queued before
all the fragments of the previous one were sent. The transmit_packet_list()
function will start sending the old fragments with the new net_buf context.

Keep a per-context neighbor_list to avoid that

Change-Id: I9d41a923c48f597cc95a8f8c9f67884c5caac02c
Signed-off-by: Vlad Lungu <vlad.lungu@windriver.com>
2016-03-16 14:20:56 +00:00
Jukka Rissanen
cd8d4eb2b7 net: User must provide storage for local IP address
When user creates a socket using net_context_get(), the function
requires local endpoint IP address. This should not be a NULL
pointer because the storage for that IP address was statically
allocated inside the function. Because of this the user needs
to allocate the storage for this and pass that local IP address
to the function. The net_context_get() will fill that local
address to sane value if user passes ANY address (== all bytes
are zeroes) to it.

Change-Id: I88314957f07912d9ecbe517a2402822401d81bd9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-03-14 11:05:52 +00:00
Tomasz Bursztyka
050ec13556 net: ip: Make sure CONFIG_NETWORKING_WITH_LOGGING is properly handled
If the user unsets CONFIG_NETWORKING_WITH_LOGGING, it will mean he
really doesn't want to get any network stack logging output.

Change-Id: I0629a045adbf8916327a8a9ba69b6e6e9ee2e7d9
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-02-19 12:33:45 +00:00
Johan Hedberg
9d6aaa1cc7 net: buf: Add net_buf_pull_u8() helper API
A helper for the (fairly common) task of decoding individual 8-bit
values.

Change-Id: Id7e97df152232d5dd9861cf1e107877f1b8febaa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-12 15:10:20 +00:00
Peter Mitsis
61f7a13cfc net doc: Fix parameter names in documentation
Change-Id: I3a58e500d691254a09c922c248beaca0c5569e09
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 20:11:03 +00:00
Johan Hedberg
754248aedc net: buf: Add convenience API for adding 8-bit integers
There are many situations when encoding data when we need to insert
single bytes to the buffer. With this helper the encoding code stays a
bit more readable.

Change-Id: Ibc0ce43af5ae25a1baa0f1adbc5816ae7c04e3bb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-11 11:14:20 +02:00
Jukka Rissanen
6d2276e160 net: Print thread pointer in debug prints
This makes it easier to correlate the debug messages
to different fibers.

Change-Id: I6fb2d1265bb39fd27a1d1702e47eaf70e81ee98d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-10 19:13:00 -05:00
Jukka Rissanen
0cb73a1b9c net: Stack analyze function fixed
The stack analyzer works now same was as the one found in
Bluetooth sub-system.

Change-Id: I75e393882db6ba83f991d37aa2bf81d960b61231
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:25:32 -05:00
Szymon Janc
b5c7b1baca net: buf: Fix compilation with newlib libc
newlib is declaring __unused in cdef.h which was conflicting with
__unused member in struct net_buf. Use _unused name instead.

In file included from /work/Zephyr/project/zephyr-project/net/buf.c:27:0:
include/net/buf.h:38:14: error: declaration does not declare anything
    [-Werror]
           int __unused;
               ^
cc1: all warnings being treated as errors

Change-Id: I2df189a4d4aee0f982c2d28d24847052f6168d45
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:31 -05:00
Johan Hedberg
8d98247c8f net: buf: Add net_buf_push_le16 helper function
Change-Id: Icce051392d1523df8ebfeccf76477a6264d3d216
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:28 -05:00
Peter Mitsis
a0e4568760 c++: Add extern "C" { } block to header files
Adds extern "C" { } blocks to header files so that they can be
safely used by C++ source files.

Change-Id: Ia4db0c36a5dac5d3de351184a297d2af0df64532
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Jukka Rissanen
d0ac5c7cf0 net: buf: Enable IP and L2 buf debugging properly
The IP and L2 buffer debugging is now activated if one enables
CONFIG_NETWORKING_WITH_LOGGING option.

Change-Id: Idad4978cfd6bd705bdde6e21f1edcd3c7d280c75
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:24:59 -05:00
Jukka Rissanen
31e5fccf30 net: Enable L2 buffers only when 802.15.4 is enabled
Because the L2 buffers are only used by 802.15.4 sub-system,
we must not compile and link them to the kernel.

Change-Id: Iab0352582ac1c57e0dd8f54ca8e757e47e4df3be
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:24:46 -05:00
Jukka Rissanen
2272312b8d net: Refactor code to use new generic net_buf API
Change-Id: Id008bbf43062ca0641a76edaabef47c650287444
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:24:46 -05:00
Johan Hedberg
72050e2352 net: buf: Require destroy callbacks to handle returning to free FIFO
There could be cases where the destroy callback needs more
fine-grained control of step ordering than "1. destroy, 2. put back to
free FIFO". One case could be when the the pool needs to be protected
by a microkernel mutex or semaphore. In such a case the putting back
to the FIFO may need to happen before a custom action in the destroy
callback.

Making the destroy callback responsible for returning to the free FIFO
gives full flexibility regarding the order of the cleanup actions.

Change-Id: Ib9532d1dd70e0a2042af54ebd3e40a853dd42d33
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:44 -05:00
Johan Hedberg
c1f007687f net: Add initial generic buffer implementation
We need to have a generic buffer API in order to efficiently transfer
data between different subsystems. The first such case will be the
Networking and Bluetooth subsystems where 6LoWPAN data will be passed
back and forth.

The needed API needs to provide enough flexibility for different
buffer sizes as well as custom protocol-specific context data.

The implementation offered in this patch follows the general design of
the existing Networking and Bluetooth buffer implementations by using
a backing array of buffer which is fed into a "free buffers" FIFO for
management. The main difference is that the API allows specifying
variable sized buffers for each created pool, as well as a minimum
amount of "user data" that's allocated as part of each buffer.

There's also an optional destroy callback that's e.g. useful for HCI
flow control in Bluetooth (for notifying the controller of available
buffers).

Change-Id: I00b7007135a0ff35219f38f48658f31728fbb7ca
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:38 -05:00
Dan Kalowsky
2a57d02400 checkpatch: warning - spacing
Change-Id: Ia63d6c9d8d3c1bd9c540a039263cb8507af82b1e
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Dan Kalowsky
e8563c2f97 checkpatch: error - trailing_whitespace
Change-Id: I819d13f0d7a23e3a61dcda6a3ced18810b192158
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
d8a30896f4 checkpatch: converting from __FUNCTION__ to __func__
Change-Id: I2f28a4dd2b1b372905638cbccdf987396999d7ec
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
da67b29569 checkpatch: warning - block_comment_style
Change-Id: I6da43e41f9c6efee577b70513ec368ae3cce0144
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
39063598db checkpatch: error - spacing
Change-Id: Ie6e1c43581dd4b0734625b3a4e59a4ca79619e99
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Javier B Perez Hernandez
f7fffae8aa Change BSD-3 licenses to Apache 2
Change all the Intel and Wind River code license from BSD-3 to Apache 2.

Change-Id: Id8be2c1c161a06ea8a0b9f38e17660e11dbb384b
Signed-off-by: Javier B Perez Hernandez <javier.b.perez.hernandez@linux.intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:29 -05:00
Jukka Rissanen
4d745b70b0 net: Create separate net_buf pool for RX and TX use
Have a separate network buffer pool for received and transmitted
data. This way incoming packet flood cannot prevent from sending
IP packets out.

Change-Id: I2aae3bcb4ea63f36355f758de44532b167edfdb8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:39 -05:00
Jukka Rissanen
1abb0b5792 net: Enhance debugging of mac net buffer allocations
Print information who allocated or freed mac net buffer.

Change-Id: I106e1703b7f5c3e5363d53d63c599a12b65577cb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:38 -05:00
Jukka Rissanen
792bbbb6d8 net: Refactor the stack analyzer functions
Generalize the stack analyze functions so that they
can be used by other fibers.

Change-Id: If1fae51db45010b75f6ac58cd8d874b31ca336e2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:38 -05:00
Jukka Rissanen
c9599d9d9b net: Fix the uip_buf() macro
The macro was incorrectly set and caused in certain case
wrong expansion.

Change-Id: I5198906a5066882d178c0fcff8c6816a5461f37a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:38 -05:00
Jukka Rissanen
6fa1c89b38 net: tinydtls: Include file was missing
The tinydtls.h include file was missing from earlier tinydtls
commits.

Change-Id: I8b8398313c7f598daf81f4fb8c07fd138e22e22d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:24 -05:00
Jukka Rissanen
766eed3461 net: Document udp connection retrieval function as it is needed
Documenting the function that returns the used UDP connection
pointer. This function is needed for example in tinyDTLS
server implementation.

Change-Id: I08aae798dab0749912694d6338de91dcbd13df84
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:24 -05:00
Jukka Rissanen
0378a84fef net: Add macros to return IP and UDP info from net_buf
Add NET_BUF_IP() and NET_BUF_UDP() macros that return
correct struct containing either IP or UDP data.

Change-Id: I43b828ef78c1f13ccee41e6a60daa36145a35eba
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:23 -05:00
Jukka Rissanen
04dfda8927 net: Fix the documentation of net_release()
Fixed the description of what happens if there is a timeout.

Change-Id: Id19a791193b527a8ee086f069e103f42d2d9b0f4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:22 -05:00
Jukka Rissanen
e6d1925a96 net: Make sure Contiki will not remove received packet
We must not touch uip_len(buf) value as Contiki IP stack
will use it to determine what it should do with the
received packet. So after we have received the packet,
we update separate datalen variable in net_buf that will
store the correct length of the packet.

Change-Id: Iab79b741508e95e581d1727645e6b1d1eacded4c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:22 -05:00
Jukka Rissanen
e1359ab16b net: Add timeout to net_receive function
Allow caller to specify a timeout in ticks while waiting
network data. The timeout value has following meaning:
  TICKS_UNLIMITED  wait forever
  TICKS_NONE       do not wait
  value > 0        timeout value (only applicaple if
                   CONFIG_NANO_TIMEOUTS is defined)

Change-Id: Icbb33fa0eeb462659d4006dd9d948a04f39a87a9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:22 -05:00
Jukka Rissanen
20aa77ce6f net: Network buffers could be lost when sending packets
When sending data to network, make sure to check the return
code from network driver. The driver should return these codes:
 0 : If packet could not be sent. In this case buf should
     not be released.
 1 : If the packet was sent successfully. In this case the buf
     should be released by either the send() or some other
     lower layer function.
 <0: If there is an error, the buf should not be released by
     send() function.

Fixed the relevant part in Contiki code so that the tcpip_output()
return correct value
  0 = packet was not sent, caller needs to free it
  1 = packet was sent, network driver will free the net_buf
      after sending it to medium

Change-Id: I4380d7747985fc057f5ef73ca97b76f6e9888a55
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:22 -05:00
Jukka Rissanen
ea970e2ce1 net: Change the remaining doxygen comments to javadoc style
Change-Id: I942558ca9e4c140145de6e4a1bcebf8d9d16f3d2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:35 -05:00
Jukka Rissanen
3c9fd82c5b net: Add INADDR_ANY for IPv4 connectivity
Change-Id: I027ec85c9e15f0a4aae494f766414faab7f2012b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:35 -05:00
Jukka Rissanen
cc3afa6346 net: Add net_mbuf validation
Add infrastructure and checks to validate the net_mbuf during
its lifecycle.

Change-Id: Id4b638fff991325d2247b1f24152552038888915
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:34 -05:00
Jukka Rissanen
90ca5ff779 net: Validate that net_buf allocation is correct
Add macros that check that we are not trying to use already
freed net_buf and vice versa.

Change-Id: Ifdb6a7e24cd6d7a0de46fa7b991c358ea8828d6f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:34 -05:00
Jukka Rissanen
73fc66d86a net: Rework the includes so that they are inside include guard
Making sure we do not include anything unless they
are inside include guard.

Change-Id: Ie88cbc0ed6dbbf4033f3c8c310df7d084ab8b126
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:34 -05:00
Jukka Rissanen
54ab6fad20 net: Add net_reply() function
The net_reply() can be used if the application wants to reply
something to peer right after receiving the data. The function
will reverse the source and destination addresses and ports,
and set the uIP internal structures in such a way that the
reply is possible. Using this function saves the application
from allocating a separate net_buf for just sending simple
message back.

Change-Id: Ia960c83b77a8f300222159ee085fed99e2b007c2
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:34 -05:00
Anas Nashif
20764a2e8d doxygen: javadoc style
Change all occurances of /*! to /** to match javadoc
style.

Change-Id: I3a759d34e0e928216f61252682266e64c5b875f8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:32 -05:00
Ravi kumar Veeramally
89c83d0162 net: 6lowpan: Adapt compression functions to net_mbuf buffers
6lowpan HC06 and HC01 compression/uncompression functions are
adapted to net_mbuf buffers. HC06 compression and uncompression
works properly. HC01 adapted to net_mbuf but functionality is
failing due to inproper IPv6 link local addresses. buf pointers
from net_mbuf and couple of net_mbuf calls are removed (which
are not used at the moment and saves memory from net_mbuf).

Change-Id: I2711b71b1b8df2eaac67d69275baf4b62b03f9f6
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:30 -05:00
Jukka Rissanen
5d11691aa6 net: Add source mac address to net_buf
This is needed for enabling RPL and 6lowpan support.

Change-Id: I87f95a08db2cc874bbe841d9b1456803ab16d75d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:30 -05:00
Ravi kumar Veeramally
56ccfb3785 net: 15.4: Add 802.15.4 driver and 802.15.4 loopback radio driver
Enable 802.15.4 driver that receives the IPv6 packet, does header
compression on it and writes it to the 15.4 stack Tx FIFO.
The 15.4 Tx fiber will pick up the header compressed IPv6
6LoWPAN packet and fragment it into suitable chunks ready
to be sent to the 15.4 hw driver. The 15.4 stack Rx fiber picks
15.4 frames from 15.4 Rx FIFO (which are fed by 15.4 driver)
and reassembles the all fragmented packets and uncompress the
header and writes to the IP Rx FIFO.

The 15.4 loopback radio driver receives the 15.4 frames and
put it back to 15.4 Rx Fifo.

Change-Id: I68d1c7ff6de0e8770616e574206c2091c69a28e6
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:30 -05:00
Ravi kumar Veeramally
575c89eacb net: Update 802.15.4 stack with net_mbuf and split sicslowpan
Move packetbuf from net_buf to net_mbuf, update 802.15.4 stack
with net_mbuf (which is smaller in size, and mostly wrapper for
packetbuf) and split sicslowpan(ipv6/sicslowpan.c|h) functionality
to compression and fragmentataion. This patch contains
null_compression and null_fragmentation which is exactly what
uip_driver.c|h does.

Change-Id: Ifee359e20aa57a50fb00c9ce049d9476b2ac67e3
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:29 -05:00
Patrik Flykt
29a61aff9c net: Add function to receive an IP packet from the driver
After an IP packet has been (reassembled and) received, the driver
submits the IP packet to the IP stack.

Change-Id: Icbd1e7740ce59db16bc1d61002420e86ab101d2d
Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:29 -05:00
Jukka Rissanen
5d3685f85f net: Add separate buffers for MAC layer
We do not need large 1280 bytes long buffers in lower IP stack
layers. After long packet has been fragmented to smaller chunks
it depends on the radio technology how long buffers we need
to use. For 802.15.4 we can use 128 bytes long buffers.

Change-Id: I8cd6085944d78fa26a4aa1a93c58fc436856541b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:29 -05:00
Jukka Rissanen
2f5b1d1570 net: Add a way to see who is trying to alloc/dealloc a net_buf
Change-Id: Ib7813bc5809f85f27aa4fe06583b64461741466a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:29 -05:00
Jukka Rissanen
9099884162 net: Allow user application to get the packet data length
The uip_len(buf) cannot be used as the Contiki stack zeroes
the buffer len after sending and after processing received packet.

Thus the application can use uip_appdatalen(buf) macro to get
the application data length.

Change-Id: Iaaa508acb96c28919cfc0188ef46bb2b4a693090
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:28 -05:00
Jukka Rissanen
53fd129094 net: Add max length of the IPv6 address as a string
Change-Id: If7f5f3624cd34b5bff4ebb77c95ae7397e058430
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:24 -05:00
Jukka Rissanen
66fc2795e5 net: Add loopback and any IPv6 address definitions
Create IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT address
definitions for applications.

Change-Id: Ic864f559cae90a5f85e45ee90d73127b0ed8fde6
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:24 -05:00
Jukka Rissanen
6b3c739d7d net: Add helper function to set the link local address
Network driver should call this when it knows the device MAC or
EUI-64 address.

Change-Id: Ie03a80fcdb9a10cd1cb15f12037b3802da13bca9
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:24 -05:00
Jukka Rissanen
8ccc4b229a net: Make the union in net_addr anonymous
The network address union that holds IPv4 and IPv6 address
should be anonymous as there is no need to refer the union
separately.

Change-Id: I70bab6b91dcf49dfb5adb405eb2b9c602f932603
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:24 -05:00
Jukka Rissanen
251a45b602 net: Use our network buffers instead of global ones in Contiki
This mega patch changes how Contiki uses buffers. In standard
Contiki there is only couple of static and global buffers.
This makes the stack non-reentrant and only usable in one
thread. This patch replaces the global buffer with buffer
supplied by caller (net_buf.h). The Contiki stack is still not
fully re-entrant after this (packet reassembly needs more TLC)
but it is a good start.

Change-Id: I63abc230b36b14f33f687d3ef64cffb0f3a69f5d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:20 -05:00
Jukka Rissanen
da36c6371c net: Simple socket API introduced
The network context defines a network connection.

Change-Id: I29a186be6c9de9d824f10b6442fa1dfd3711d24d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:20 -05:00
Jukka Rissanen
4f5723a5d0 net: Network initialization and tx/rx functionality
Functions to receive data from apps and transmit it to network, and
receive from network and pass data to apps.

Change-Id: I1b1b8c041e6c5e20294081d2cd403636e9909cdc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:20 -05:00