Commit graph

5605 commits

Author SHA1 Message Date
Ravi kumar Veeramally 0c39e6dc45 net: 6lo: Fix tiny style issues
Change-Id: I5cf65f4d428f17290642ce94d5e70d233f512213
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:54 +02:00
Ravi kumar Veeramally 313ee1d49b net: dhcpv4: Fix tiny style issues
Change-Id: I12e6763627d85912496e8c702cd97bf90ac4f741
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:54 +02:00
Tomasz Bursztyka 668d2abb07 net/6lo: Switch to NET_ERR/NET_WARN when relevant.
This permits to catch issues without the need to enable debug level.

Change-Id: Ic3c66a84be587e955d532cc321161a3ae7b5d69d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:54 +02:00
Tomasz Bursztyka fa35ccf9cf net/ieee802154: Raise an error when data frame cannot be created
Change-Id: I7405c4b3de194c09f7d8d8e1bb54602b6dba304b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:54 +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
Andrei Emeltchenko 5794d80c10 net: Remove CONFIG_NET_IPV6_NO_ND config option
The option is no longer used so it can be removed.
Use CONFIG_NET_IPV6_ND option instead.

Change-Id: Ibaa3d3deb52b8b176e85f8b9e1d8c80c1026aea1
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-01-27 12:35:53 +02:00
Luiz Augusto von Dentz 2e9fd888bf net: bt: Fix not checking for valid ll addresses
ll addresses need to be set properly before sending as the stack is not
checking if they are NULL.

Change-Id: Ia4e96240f18b53b0e32e21649a8b571c94260731
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:52 +02:00
Ravi kumar Veeramally 02b104dae8 net: 6lo: Verify src and dst link layer addresses
If src and dst link layer addresses are not then 6lo fails
to compress the packet.

Change-Id: Ie2692def49f8a101194e3669dbaec00b557e14ce
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:52 +02:00
Malcolm Prinn 755c4a6f7a net: iface: Fix typo in net_if_down
Change-Id: I36a7292a3a176f32239332a7e91308e280da9cae
Signed-off-by: Malcolm Prinn <malcolm.prinn@intel.com>
2017-01-27 12:35:52 +02:00
Jukka Rissanen 6e6281af96 net: tcp: Only return -ETIMEDOUT if timeout>0 in connect
No need to set the status to -ETIMEDOUT in connect callback
if user did not want to have a timeout when doing a TCP connect.

Change-Id: I6d6e565a8d12bcefbcd9de751e789b5e43aad244
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-27 12:35:52 +02:00
Andy Ross 47d94648ed net: tcp: Issue connection callback on RST
A connection refused needs to be exposed to the user, otherwise the
connection will be stuck as a zombie forever.

This patch also adds a ENOTCONN check in net_context_recv() to match
the one that was already there in net_context_send().

Change-Id: I4f9ae46dd849f68ed97976add7da5daf1932cf55
Signed-off-by: Andy Ross <andrew.j.ross@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
Luiz Augusto von Dentz 1fd9f4b846 net: bt: Fix warning when compiling without debug
With CONFIG_NET_DEBUG_L2_BLUETOOTH is disabled the code generate the
following warning:

subsys/net/ip/l2/bluetooth.c: In function 'eir_found':
subsys/net/ip/l2/bluetooth.c:301:16: warning: unused variable 'addr' [-Wunused-variable]
  bt_addr_le_t *addr = user_data;
                ^

Change-Id: I1a1ca20c4f2e4fa8aa2a551d2fffa1f86874760e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:51 +02:00
Luiz Augusto von Dentz 1c94ddd906 net: bt: Fix not checking channel state
When checking if the L2CAP channel is connected it is not enough to check
if the conn member is set since the connection may still be pending.

Change-Id: I93a2328943b0ca0e42cdb5c525b30c7cdddd1c18
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-27 12:35:51 +02:00
Ravi kumar Veeramally 4540a73b59 net: Use lighter printk() instead of printf()
Use printk(), snprintk() instead of printf() and snprintf().
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf()
will not output anything without it.

Change-Id: I9ad778e318fe999e79ec34182f2de8574e45b7d4
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:51 +02:00
Ravi kumar Veeramally a28e2059e8 net: Fix 80 line character limit
Change-Id: Ic83a631db4ae76b1b2bb1bbd888d1329f065c18c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-27 12:35:51 +02:00
Paul Sokolovsky fe72df5292 net: Set default NET_NBUF_RX_COUNT to 4.
Older default value of 2 is too small for even simple uses, for
example enabling just CONFIG_NETWORKING, CONFIG_NET_IPV4,
CONFIG_NET_SLIP_TAP makes a Zephyr application hang on start up
(apparently, waiting to allocate more buffers). While value of 3
is enough to cover the above options, set new default to 4 to
accommodate configurations with IPv4/IPv6/UDP/TCP enabled.

While the new default slightly increases RAM footprint, it's
apparently better for users who are short of it to optimize it
explicitly, rather than potentially make every Zephyr beginner
wonder why enabling networking breaks applications in non-obvious
way.

Change-Id: I76e83517f0d914ce616a930c3c48ee5c52567b88
Jira: ZEP-1619
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-01-27 12:35:50 +02:00
Tomasz Bursztyka 467c69d524 net: tcp: Fix TCP states swap when accepted an incoming connection
TCP states are swaped between "server" context and the new connection
context. But in any case the "server" context should loose the
information that makes it able to accept other new connections.

The swap was badly made, as the "server" context was loosing the
accept_cb (!) and the user data pointer. Instead the new connection
context was unrelevantly inheriting those.

Change-Id: Icc877449e1d4c4e59553dcbfd41718c5006edca0
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-20 16:23:21 +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
Jukka Rissanen 9a7ccf81f9 net: nbuf: Fix debug prints in memory pool init and unref
Wrong pool pointer was used when printing pool information during
the unref in nbuf.c. During nbuf init, wrong pool pointer was used
when printing memory pool sizes.

Change-Id: I9ed08cf7afa3c841c97ea981b97fff37aa40a984
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:20 +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 2c3faa0de2 net: tcp: fix buffer leak in tcp_synack_received
When SYNACK is received we dont hand off the netbuf to anything
which will call net_nbuf_unref, so let's not mark it NET_OK.
Instead let the code path fall through to mark it NET_DROP.

Change-Id: I1f883e1a13c53c930bf50c07ff701e3db6f02d8a
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott 87914610b0 net: tcp: if buffer is TCP_FIN increment send_ack by 1
Now that the TCP_FIN block is after a potential packet_received()
tcp->send_ack should be appropriately set to the last sequence
processed.

In the case of a TCP_FIN buffer, we should advance it by 1 or else
the destination will continue to retry to send the last block.

Change-Id: I9c97d35a87ad6cc1a50f928b237780bff4cd2877
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott c1f822222b net: tcp: don't assume TCP_FIN buffers are NET_DROP
Since we default to a return value of NET_DROP, we
can remove the automatic NET_DROP in the TCP_FIN block.

The return value will be set to NET_OK by packet_received()
if appropriate data is found which needs to be sent to
the callback.

Change-Id: Ib2634ba34440ca7053a4e98bf80f12cf6fbbd361
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott 29b7d9c644 net: tcp: handle TCP_FIN after processing any data in the buffer
Buffers marked TCP_FIN may still have data attached to them
which needs to be processed and handed back to the callback.

Let's move the TCP_FIN handling to after the data processing
section now that we have a copy of the TCP flags to do this.

Change-Id: I90f53b10e393024ebffebe1837b8866764b8a7ac
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Michael Scott da7e00e3aa net: tcp: in tcp_establish save TCP flags for post-processing use
buffer TCP flags can be cleared during packet_received so let's
save a copy of them for later.

Change-Id: I401e99c1ed2723dac4e86da58635b548a5645c13
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:20 +02:00
Anas Nashif 8da8118e3c net: in newlib, ESHUTDOWN is considered an extension
Allow building the IP stack with newlib by enabling linux extensions.

Jira: ZEP-1592
Change-Id: I6714b73c7666a6f56c5203e2754ce1d7d94af0f1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-20 16:23:20 +02:00
Tomasz Bursztyka b7dd42879d net: shell: Use lighter printk() instead of printf()
CONFIG_STDOUT_CONSOLE is anyway disabled by default so printf() will not
output anything without it.

Change-Id: I8013e4efa5cb760215316e9413734281fb576f4d
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-20 16:23:19 +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 13fc795b3e iot/zoap: Fix wrong byte-order when retrieving integer options
When retrieving options that represent an integer, the order of the
bytes being considered was inverted, resulting in invalid values being
returned.

Change-Id: I8ba84f77e3402066632c0ba650939266c87a8ea2
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Vinicius Costa Gomes 4534046ad9 iot/zoap: Ignore non-request packets in zoap_handle_request
For example, when a RESET packet is passed to zoap_handle_request(),
there's nothing it can do, and it's not an error, so it returns
success silently.

Change-Id: I025bb44733521d6132999c219aaa292a3de302d7
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2017-01-20 16:23:19 +02:00
Michael Scott dbd7481274 net: tcp: remove unused semaphore tcp_lock
Change-Id: Ibcd89b063a8bd5f6f7400e0ed73eb6b6d8b86b26
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally 4f3a0ef595 net: dhcpv4: Remove dead code
When parser encouter DHCPV4_OPTIONS_END, it immediately returns NET_OK.
No need to maintain end variable here.

Coverity-CID: 157584

Change-Id: I4c8b91f37ae882845c280dab1a8204966aaac00a
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally 0a3ebde216 net: 6lo: Fix dereferencing null pointer
Pointer udp will be NULL when (!(CIPHC[0] & NET_6LO_IPHC_NH_1))
condition is true.

Coverity-CID: 157588

Change-Id: I8aa1eb2e4d4aee8039631d76ad0ecc345247d6b5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Ravi kumar Veeramally c6a006c60b net: 6lo: Handle destination address uncompression properly
When contex information provided and DAC bit is not set and vice versa
are invalid cases.

Coverity-CID: 157569

Change-Id: I1b798703cbbb6155a7bdf734d0fcde9ce48c409c
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 1bb7b7e99c net: nbuf: Check possible null pointer access
In net_nbuf_get(), check that context pointer value is not
null before accessing data via it.

Coverity-CID: 157600

Change-Id: I7e7ea19a85f6fbef129e9ce699ea740d3be84cb8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen d3301aae88 net: ipv6: Check neighbor pointer in NS reply timeout
If neighbor is not found, then ignore the timeout.

Coverity-CID: 157583

Change-Id: Ia2199970bd862e43901f5717025271c11c74af5e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 66f5dfa04f net: tcp: Allocate space for TCP header
We need to allocate separate fragment to store the IP
protocol headers.

Coverity-CID: 157582

Change-Id: Ib0dd5d28cd6876a0cf2de3b063c030ef64da998c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen b5039aa80c net: icmpv6: Removing dead code
Callback cannot be null so no need to check its value.

Coverity-CID: 157572

Change-Id: I26e4b24c41d30aa9007b78895975035e6bf8807f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:18 +02:00
Jukka Rissanen 2eb218c5b7 net: Fix possible null pointer dereference in nbuf
The context parameter might be NULL so we need to check
its value before accessing its content.

Coverity-CID: 157571

Change-Id: I7f75323d9d261a77421688f37a40bb44ff3ca2bd
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 06d3ccce96 net: tcp: When retransmitting, hold an extra, temporary reference
The link layer dereferences a buffer right after it is transmitted.

If this extra reference is not held, the second time a buffer is
retransmitted, the reference that TCP holds when keeping the buffer in
the `sent_list` will be taken, and retransmission won't happen reliably
anymore.

As soon as the TCP fragment is acknowledged by the peer, the
`sent_list` reference is taken, and the buffer is freed.

Change-Id: Ie50f9acf02c1dff74248a5dfbec3785a91ff90f7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 46c0997e8b net: tcp: Reduce size of state member from 32 to 4 bits
No more than 4 bits are necessary to store the state of a TCP connection,
so better pack it using bitfields so that it uses only 4 bits instead of
32, by sharing space with `retry_timeout_shift` and `flags` fields.

There are 12 (or 14, if you count the 2 unused bits in the `flags`
field) bits remaining in the same dword, but I don't know what to to
stuff there yet.

This also changes all direct field access for the `state` field to
function calls.  These functions are provided as `static inline`
functions and they perform only casts, so there's no function call
overhead.

Change-Id: I0197462caa0b71b287c0773ec5cd2dd4101a4766
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 525b51594f net: tcp: Get rid of recv_mss field from TCP struct
This frees up some more memory as well, by computing the maximum segment
size whenever needed.  A flag is set in the TCP context to signal if
the value has been already computed.

Change-Id: Idb228d4682540f92b269e3878fcee45cbc28038a
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 9a558c2aaa net: tcp: Remove unused recv_ack field from TCP context
This value is never set (always zero), so it's safe to remove it from
the net_tcp struct.

Change-Id: Ie4c1d90204a9834f2223b09828af42ee101bd045
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 5de6d084a9 net: tcp: Use an uint8_t for retry timeout instead of an uin32_t
Rename the variable to `retry_timeout_shift`, and shift-right the value
each time there's a timeout.  This saves some memory in that structure
by using the holes left due to alignment.

Change-Id: I18f45d00ecc434a588758a8d331921db902f4419
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Leandro Pereira 1aee85be4c net: tcp: Ensure all timers are disposed of when releasing context
Cancel all delayed work timers: FIN, ACK, and retry timers.  Also, do
that unconditionally regardless of which state the machine is in, as
that's a no-op if the timer has not been started yet.

Change-Id: Ia36b97c6823943976447fbd6389ae04862c19ff9
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-20 16:23:17 +02:00
Andy Ross d4b9b6c1bf net: tcp: Destroy net_tcp struct at the same time as the context
The net_tcp struct was being cleaned up and destroyed when the
outbound FIN packet is sent on a connection that already received an
inbound FIN.  That's not right, per spec we need to wait for the ACK
(though this would be benign cheating).  And worse: there were code
paths which were themselves spec-compliant where the net_tcp struct
(now a NULL pointer) would be used after this spot leading to
occasional crazy behavior on socket close.

Don't do it this way.  Clean up the TCP struct at the same time we
destroy the net_context.  Much saner that way.

Change-Id: I4bc6b97eb0b71a7fa8faea02c1eb4c4d3bd3ae6d
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-20 16:23:17 +02:00
Andy Ross 01ae35b58e net: tcp: Pass correct user_data pointers
The TCP stack inherited msot of the user_data management from UDP, but
it doesn't quite work.  It's not possible to have a single pointer in
the general case, as e.g. a net_context_send() call may happen
synchronously underneath a recv callback and clobber the pointer, even
though there will be much more data coming later on the active stream.

Put a recv_user_data field into the TCP struct and use that.  Long
term, it would be good to revisit this and come up with a unified
solution that works for both.  There is yet another "user_data"
pointer in net_connection that seem likely to overlap too.

Change-Id: Id3a8eca64fc680e0e80b74944c4d621d7810a8fe
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-20 16:23:17 +02:00
Michael Scott c78c7ac13c net: route: remove extra variable use in net_route_add()
Let's drop the lladdr variable and get the link address and
length from the net_linkaddr_storage variable instead.

Change-Id: I75a5d08527cda7df102db897ade9015d39f10caf
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +02:00
Michael Scott f3c66e5205 net: ipv6: fix NULL reference in handle_ra_neighbor
lladdr.addr doesn't point to any storage value when it's
handed off to the net_nbuf_read function.  This results
in a write to an undefined area of memory.

Fix this by pointing lladdr.addr to a net_linkaddr_storage
structure's byte storage array which can handle the maximum
specified length.

Change-Id: I05e0a0420b262ba1e5ac95cebe1f0d91f54878ce
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-20 16:23:16 +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
Johann Fischer 6b79ed0428 net: ieee802154: inform about unsupported frames
Be nice and inform user about unsupported and dropped frames.

Change-Id: Iaf0e7ed660a926c45dac9fc36b788c4c786eac11
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-01-13 14:38:59 +00:00
Luiz Augusto von Dentz 8b185ecc50 net: bt: Add disconnect shell command
Change-Id: Ibb3a6e580751549ab5330296d6cd9f9cae4903ab
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:42 +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 1112c2d382 net: bt: Add scan shell command
Change-Id: Ieecf4e3ed91641582fe6a8e5512eb13fe3b8e76e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:37:13 +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 1bcd12d0d3 net: bt: Add shell support
This adds a shell module called "net_bt" that exposes Bluetooth L2
management commands.

Change-Id: Ia6da1d38cfd51502119758a8f6abbb6d1cd31743
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:42 +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 348f46bf6e net: bt: Fix not showing any logs
Including logging/sys_log.h before net_core.h prevents SYS_LOG_LEVEL,
etc, to be set properly.

Change-Id: Iaa7aa98110aa455162836be1d9560fbfc03569df
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:36:06 +00:00
Luiz Augusto von Dentz 331c29f96c net: mgmt: Decode event fields
This decodes the event layer, code and type when debugging is enabled.

Change-Id: I23c6fb200f3287a138e46df9f472c9982898675d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-13 14:34:51 +00:00
Johann Fischer 133f2c07d2 net: ieee802154: fix validate_mac_command_cfi_to_mhr
Change-Id: I4baa9e8e079531f1759584c22869c97b72ab2588
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2017-01-13 10:29:04 +01:00
Andy Ross fc35e649ff net: tcp: Don't leak net_conn_handles
net_context_put() forgot to release the conn_handler field causing
subsequent failures in net_conn_register() when they ran out.

Change-Id: I0d306b5035199422fa8788338ac9da8d1900d5f9
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-13 10:29:03 +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
li zj 9a87e403ac net: icmpv4 : calculate ipv4 header chksum
In icmpv4, after calling setup_ipv4_header() function,
only calculate ICMP chksum, not calculate ipv4 header chksum,
ipv4 header chksum still 0, the other side will drop this pack.

Change-Id: I1550a4c8c7ab63132d70ba6ce19a7caf78ad84e6
Signed-off-by: li zj <279939902@qq.com>
2017-01-13 10:29:03 +01:00
li zj 0fc1d808a3 net: dhcpv4 : set ciaddr 0.0.0.0 when send DHCPV4_MSG_TYPE_REQUEST
When router receive dhcpv4 request with ciaddr not 0.0.0.0,
some router reply NAK, dhcpv4 never successful.

Change-Id: I4b66b18f7d30ad5a1b638fdca0bb204ed078d551
Signed-off-by: li zj <279939902@qq.com>
2017-01-13 10:29:03 +01:00
Michael Scott a972d03ce7 net: ip: save TCP seq/ack values in tcp_synack_received
The tcp_synack_received() function ends with a call to send_ack().
However, if we don't update the sequence and ACK values, we'll send back
headers with 0 values and the destination will try resending over and
over.

Fix this by saving the seq and ack values when a TCP_SYN is flagged
in the header (which should be the case almost any time this function
is used as a callback).

Change-Id: I57f07ce719f2b6e2fb34c96c867d2e1c37f342ba
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:03 +01:00
Michael Scott f23ca0e5e1 net: ip: reword appdata debug message in packet_received
Trivial text tweak for clarity.

Change-Id: I470d54d86de7ddc4e83e3ad871448c244134c117
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:03 +01:00
Michael Scott 742b5e22ea net: ip: set context state to NET_CONTEXT_CONNECTED on synack success
Once SYNACK has been received for a TCP connection, we need to set the
net context state to NET_CONTEXT_CONNECTED or else calls to sendto()
will fail with -ENOTCONN.

Change-Id: Idd78e1dcdd5ac0bca5d3fba40b59ab8fde6b8729
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott c306844583 net: ip: set local address family during TCP connect
When calling net_context_connect, the local address family
is never set prior to calling net_tcp_register.  This generates
an error:
"Local address family not set." (-EINVAL)

Let's set the local address family prior to this call.

Change-Id: Ic5f2edf684d14f9bb77019c49c95e5524a406417
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott a2464d049f net: ip: on synack copy local/remote data prior to net_tcp_register
When TCP SYNACK is received we register the connection via the
net_tcp_register function.  During this call several errors are
generated concerning local and remote address information not
being set.

Let's copy the local and remote address data prior to this call.

Change-Id: I17cd83f7b4b7e65e45fec1810fb38f745653bdc7
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Michael Scott ff1345dbaf net: tcp: replace seq/ack/wnd value shifts with system calls
In other portions of the code we use the sys_put_be* function
to shift the values from the current system endian to big
endian array of bytes.  Let's be consistent and do that in
the prepare_segment function as well.

Change-Id: I5a1a4c30ddf313c9e978be98fd969899f5de6190
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-13 10:29:02 +01:00
Kumar Gala 0f2ce02abe net: Remove NET_SLIP choice from Kconfig
The NET_SLIP Kconfig choice option doesn't really do anything for us,
plus we get warnings related to setting CONFIG_NET_SLIP=y in prj.conf
files.

Warnings like:

warning: override: reassigning to symbol NET_SLIP
warning: override: NET_SLIP_TAP changes choice state

So remove NET_SLIP choice and remove CONFIG_NET_SLIP=y in the prj.conf
files.

Change-Id: Ibccf9cf167f4c8a4df480ca0396bf83fcf60df1e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-13 10:29:02 +01:00
Anas Nashif f6e039062a kernel: remove dependency on CONFIG_NANO_TIMERS/TIMEOUTS
Remove legacy option and use SYS_CLOCK_EXISTS where appropriate.

Change-Id: I3d524ea2776e638683f0196c0cc342359d5d810f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-08 18:09:52 +00:00
Michael Scott 249cfb682f net: l2: bluetooth: Fix build break in ipsp_disconnected
In commit bf4fb51f44, "net: if: Add NET_IF_UP flag"
a reference to ctxt->iface was added in the ipsp_disconnected function.

Let's add the ctxt variable definition to fix the build break.

Change-Id: Ib06047e333504f3db4fe175fb3ef1dce347e1916
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-01-06 22:08:13 +00:00
Leandro Pereira fb02efb1c9 net: tcp: Use appdatalen when acknowledging packets
If the length of all fragments is used instead, the TCP header is also
considered; sequence numbers do not consider the header.

Change-Id: I19e77ac0fe62ca619b0903dd0265f8ea4878cdf7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:48 +00:00
Leandro Pereira 162843f90a net: tcp: Store return value of net_buf_frags_len() on a size_t
The net_buf_frags_len() function returns a size_t, which is an unsigned
integer.  Store on an appropriate size_t variable instead.

Change-Id: I98aa4c0ddd7c464737436aa9ce13bdc86c11da2b
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:35 +00:00
Leandro Pereira 342f81b7e1 net: tcp: Remove unused retransmit_timer field from net_tcp
`retry_timer` is being used instead.

Change-Id: I53f8e724b48eca5e17bc9fec38f25c457b1492c9
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-01-06 14:27:25 +00:00
Leandro Pereira 84b68b8b21 net: tcp: Be more consistent with namespaces for private funcs
Change-Id: Ie2699e01c5cc19cd04eed8383d6c73769366a55e
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-06 14:27:13 +00:00
Andy Ross 3a8b73067d net: tcp: Precompute appdata properly
TCP packets need the computed packet length early so they can fill in
a correct sequence number in their generated ACKs.  Waiting for
packet_received() is too late.  Precompute it before needed, and skip
the evaluation later.

Change-Id: I25547009f88277e0042c74f2005a141819797886
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 14:25:58 +00:00
Andy Ross 02174b8e0f net: tcp: Swap tcp->context backpointers
On accepting a new connection, the stack does an odd "swap" trick
where it updates the struct net_tcp record on the *listening* context
with the values from the new connection, and then swaps it with the
empty one that got allocated for the *new* context.

Unfortunately this swap forgot to swap the net_tcp "context" field
backpointers, so the net_context retrieved at runtime was for the
wrong connection.  Surprisingly, this actually almost worked for a
long time, except that the destination address would be wrong in the
newer setup.

Change-Id: I0c1812ddb9f9ff3e7deb60d1fd67cafd9ba96997
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 13:56:02 +00:00
Andy Ross a5b694fbbc net: tcp: Select correct source address for SYNACK packets
The source address for a TCP SYNACK must (obviously) be the same as
the destination address of the SYN that produced it.  But the existing
IP packet creation routines would simply fill in a default address
from the net_context struct, which is correct for *established*
connections, but for the listening socket is generally INADDR_ANY
(i.e. all zeroes) and will result in an arbitrary choice for source
address (e.g. a link-local address on the same interface) which can
easily be wrong.

So we need to pass the correct address all the way down from the SYN
packet handler code through the net_ipv*_create() packet creation
functions.  This requires lots of API plumbing, but relatively little
logic change.

Change-Id: Ic368f8cef6689f8a27cbafd5933a4964d5cc457e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-01-06 08:21:15 -05:00
Tomasz Bursztyka 336e3f8721 net: ieee802154: Add a shell module named 'ieee15_4'
This one exposes IEEE 802.15.4 net mgmt requests through the shell. User
has then the ability to directly make relevant requests like raising a
scan, associating, etc...

For now, it assumes the 15.4 interface is the only one on the system and
thus will rely on net_if_get_default().

Change-Id: I8eb20565b8231e6cfcba6c1479179cc85ff1d8e5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 12:27:01 +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
Tomasz Bursztyka 415afe130e net: ieee802154: Fix logging primitive in mgmt part
Change-Id: I9a97acfc06b7836cce622e374e21efcecbd99bd5
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-06 11:02:26 +01:00
Flavio Santes e86b6c23af net/dns: Introduce the qname_copy routine
When a CNAME is part of the DNS answer RR, sometimes a label with
a pointer is found. The CNAME must be reused to create a new DNS
query and that CNAME will become the new DNS Query QNAME. This new
QNAME must not include pointers.

This patch introduces the qname_copy routine that "linearizes" a
given QNAME (perhaps with pointers).

The dns_read routine is also updated to reflect these changes.

Change-Id: I8e8f64e85e2cbf494fd589e2b7a67d470d34604b
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes e8eb62b87b net/mqtt: Allow an MQTT subscriber app to receive msgs
This patch adds the mqtt_subscriber_parser routine and modifies the
mqtt_init routine to allow an MQTT subscriber app to receive MQTT msgs.

Change-Id: Ie54ab892dacbc4386acab78a8991eba1850d8171
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 8619d9d625 net/mqtt: Improve error handling in mqtt_rx_connack routine
Avoid undesired behaviors by exiting once an error is detected.

Change-Id: Id8e6accd6cd096274fe1c40a615d290967f1d4b9
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:45 +01:00
Flavio Santes e4e74be208 net/mqtt: Improve buffer error handling in mqtt_tx routines
This commit improves the buffer error handling in the mqtt_tx
routines.

Change-Id: Ic8e5761d927fe881b2376b6ac948a412e3b1168a
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 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 4cfd7f7fe2 net/mqtt: Improve indentation
Replace tabs by spaces to improve code alignment in mqtt_pkt.c.

Change-Id: If586b91ba67b8075ddc7e0203dc538420e96b49a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Flavio Santes 51a48d2d07 net/mqtt: Make input arguments const
This commit changes some function signatures found at the private
MQTT Packet Lib. Input arguments representing arrays can be considered
'const', avoiding compiler warnings when passing "const arrays" in
MQTT applications.

Change-Id: I3ebaa9c7ff5fba74324bf79c55027cdd82669eaa
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
Flavio Santes a46548ec31 net/protocols: Remove unnecessary assignement in Makefiles
Change-Id: Ifea85ebdaf5f1ac6b17abddc0311306c31c36b37
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-01-06 09:11:44 +01:00
Tomasz Bursztyka 5d0503fa30 net: ieee802154: Handle disassocation notification from PAN coordinator
PAN coordinator can decide to eject a client device from the PAN by
disassocating it.

Change-Id: Ia868554d40a7aceb4c75a0b426db45f56003fbb7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.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 df4fa6557e net: ieee802154: Integrate MAC Command frames handling
Now we can handle incoming MAC command frames.
Association result ONLY for now.

Change-Id: Ib54b1757185ed079fe6914fa7939347020e006d9
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 8a2bc07af8 net: ieee802154: Integrate beacon frame handling
This is used only for scanning at this point. But will be needed to get
slots information and else in the future.

Change-Id: Ib917469134c6ba5a54485847c612d3755f62ed35
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
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 d43af0b4c8 net: shell: NET_SHELL is not NET_LOG dependent
And it's not really a debugging option either, one might want to use it
for the features it brings. Thus moving it out of Kconfig.debug.

Change-Id: Ie1e2d2bcba94ad4b8354d3cc56087227184039b6
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:20 +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
Marcus Shawcroft dc862ec104 net/dhcpv4: Use net_if_ipv4_set_netmask()
Use the interface function rather than writing directly to the iface
structure.  Check for errors in nbuf read.

Change-Id: I75311755c2060b640325962ada28adea597cb914
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft defbc89358 net/dhcpv4: Use router option to set IPv4 GW.
Change-Id: I58f47c02665990dcb656f7e6f7802e1958b420a8
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 065c84d5a6 dhcpv4: Add option parsing diagnostics.
Change-Id: I81a4fa5df561217bfae0d48eb458bf45cfe55d16
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Marcus Shawcroft 739278e09d ethernet/arp: Use gateway for non local ipv4 routing.
Detect non local IPv4 destination addresses earlier and route them via
the gw address. Ensure that the ARP table is populated with the GW
address rather than the final destination address.

Jira: ZEP-1473

Change-Id: I3b628584148b760340ef0fea4da4e8893702c832
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:19 +01:00
Tomasz Bursztyka 8ab2a90231 net: rpl: Fix a build issue
s/energy_est/estimation when using net_rpl_node_energy_object.

Change-Id: I4b326a0dbbca11d48de0c595dfe843495fe10e04
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka ff5954890a net: ethernet: IPv6 packet length should be relevantly handled
It's much different than IPv4 where it's possible to find the whole
packet length. Here it has to count also the ipv6 header size by itself.

Jira: ZEP-1422

Change-Id: I84b1602ac75ef81b9ceda7898ca9dedf2e54d633
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +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 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 a533eb9b4f net: statistics: Move current statistics code to its own file
This file will own more statistics handling in a near future.

Change-Id: Ifaf86852f5c7166e6878b5dc8f4cd4c166dbee90
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:18 +01:00
Tomasz Bursztyka e3cca46a1b net: buf: Let's make use of func/line parameters when available
It clutters a bit the code with ifdefs but it's quite useful when
debugging.

Change-Id: I4f6899d052921b8ef8a7ec2f6e7df927a1bca2f1
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
Tomasz Bursztyka 4308da9288 net: log: Do not select STDOUT_CONSOLE
printk is anyway the routine being selected for sys_log.

Change-Id: Id6b516aa6ab8d4d420b9afe22b5e6b832dd3e216
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 90ac0b5c20 net: buf: Fix a debug message missing a parameter
Change-Id: I25a199ba074fa9affaf0a249b6af842a3a477ed7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Marcus Shawcroft 39d5f26988 net/dhcpv4: Correct spellings in comments.
Change-Id: I2c08c35eb81233b14fdfc8ccdcbc84340bdfd6a2
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2017-01-02 10:03:16 +01:00
Anas Nashif 7297f5db88 shell: move shell to its own subsystem
This moves the shell component into its own subsys and groups all
related files and options into a single place.

Additionally, one Kconfig option will now be required to enable the
shell:

 CONFIG_CONSOLE_SHELL=y

The header files was also moved to include/shell/shell.h and can be now
referenced with

 #include <shell/shell.h>

instead of

 #include <misc/shell.h>

Updated documentation as well.

Change-Id: Iffbba4acfa05408055e9fd28dffa213451351f94
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 19:35:11 +00: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 17a589a486 net/utils: Use the right data-type
Use size_t instead of int to avoid compiler warnings.

Change-Id: I86f804010a7bd0387299648f8c2c0f880f19f580
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-21 12:54:50 +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
Marcus Shawcroft 531cb01c19 ieee802165: Device driver_api is const, honour it.
Change-Id: I6aebffb8abc52013c626e3c67c8c4f1f529932e0
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-20 13:47:31 +00:00
Marcus Shawcroft af6095876c net: Device driver_api is const, honour it.
Change-Id: I3fffe80e1be884e2b58387dc7fccf2def9c5e139
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-20 13:47:30 +00:00
Anas Nashif d687a95611 kernel: move kernel code to kernel/ directly
Also remove mentions of unified kernel in various places in the kernel,
samples and documentation.

Change-Id: Ice43bc73badbe7e14bae40fd6f2a302f6528a77d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 14:59:35 -05: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 675277e28d net: nbuf: Initialize nbuf memory area after allocation
After commit 71c7c01819 about buf pool, we
started to get spurious behaviors on various places of the code on
different boards (a101, frdm...) BUT on qemu. Basically, outgoing ip/udp
packets were full of garbage. Or sometimes it was the abilitty to parse
incoming packet that was happening.

The difference between qemu and actualy boards is - afaik, at least, let
me know if I am wrong - that qemu provide initialized memory (full of
0s). Following this asssumption, this patch just reset the nbuf right
after it got allocated. And all started to work again as thought.

It's in fact a good thing to reset nbuf memory. Even before the above
commit: after being used more than once, a buffer would have ended up
with old content, and this could have been generating a bug. So let's be
on the safe side and always intialize nbuf content.

Change-Id: I50647d9e9b82a4ed340a5ceb0d69409b0194dddd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:56 +01:00
Tomasz Bursztyka f991b82209 net: buf: Use buf->pool instead of now removed buf->free
Tiny debug message fix.

Change-Id: I464ff28d55b946a2e9ba4a0f9d88fbedd7ccef57
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:56 +01: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
Luiz Augusto von Dentz 73e76c2ce2 net: Remove unnecessary k_wakeup
net_buf_put already awakes the RX thread so k_wakeup is not necessary.

Change-Id: I18b5aef5d6e85a9461bc01c17f56c3d4d9a13824
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-16 19:14:53 +01:00
Flavio Santes a8b73aa287 tcp: Validate net_context_put return code
Validate the return code of net_context_put and add debug information
in case any error is detected.

This patch fixes the error reported by Coverity:

Error handling issues  (CHECKED_RETURN)
Calling "net_context_put" without checking return value
(as is done elsewhere 4 out of 5 times).

Coverity-CID: 157833

Change-Id: Ia4a87cc08094bee465c8828411d7c1311481695a
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2016-12-16 19:14:52 +01:00
Tomasz Bursztyka 9acd710a2a net: Update TODO list on L2 and 15.4 tasks
Change-Id: I1c9e11b05cc8af337349d249d46f524c8a75a4fc
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:51 +01:00
Anas Nashif fe958df4dd libc: rework libc selection and reduce Kconfigs
Moved all libc Kconfigs to where the code is and remove the default
Kconfig for selecting the minimal libc. Minimal libc is now the default
if nothing else is configured in.

Removed the options for extended libc, this obviously was restricting
features in the minimal libc without a good reason, most of the
functions are available directly when using newlib, so there is no
reason why we need to restrict those in minimal libc.

Jira: ZEP-1440
Change-Id: If0a3adf4314e2ebdf0e139dee3eb4f47ce07aa89
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-15 22:31:28 +00:00
Anas Nashif 42738fdff4 net: multicast_eth_addr is use only with IPV6
Change-Id: Ia204a327ec7a85d1b0b0bf79778b4ebee8f294a6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-15 14:32: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
Tomasz Bursztyka c8f8527d55 net: ieee802154: ACK reply needs to set all FCF attributes.
That bug never got caught because the buffer in unit test is always
clean and fully initialized to 0, and that part of the code being
tested is never used in real as the ACK reply is directly made by the
chip.

Change-Id: I88c4dd3767b4addf2250165b94f49fae29d322ea
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-15 08:45:05 +02:00
Marcus Shawcroft b42587e9cd net: Switch net dependency to CONFIG_RANDOM_GENERATOR
The CONFIG_TEST_RANDOM_GENERATOR parameter is not intended for
production use.  Switch to CONFIG_RANDOM_GENERATOR.

Change-Id: Id6ce986259270455223ce6a42d19a3d9c9b1e642
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
2016-12-13 22:50:19 +00: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
Johan Hedberg fc21a76db6 net: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: Iab7cc6da110e9c98720211a6f773dcf055a3a411
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:58 +00:00
Tomasz Bursztyka 562f9c1c2e net: ieee802154: Add support for big endian
Structures attribute need to be ordered according to endianness.

Change-Id: Ib3053728cbc49e54631057c779aba0f16aace283
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:20 +02:00
Jukka Rissanen 5ece8c26b5 net: tcp: Fixing the constness of TCP state debug string
Change-Id: I42a8271cf10efcd9ce67ef860a45fa54c0690387
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:20 +02:00
Jukka Rissanen 3eaec41ab8 net: Moved net/ to subsys/net
* Moved networking code into subsys/net.
* Renamed net/yaip to net/ip at the same time.
* Fixed the tests/net to compile
* Fixed the Makefiles and Kconfig files in subsys/net
  to use the new location of the IP stack

Change-Id: Ie45d9e8cb45a93fefdf969b20a81e3b1d3c16355
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:20 +02:00