Commit graph

41120 commits

Author SHA1 Message Date
Jukka Rissanen
9148567dbd net: shell: Add command to view active network contexts
The "net conn" net-shell command will print out currently
active network contexts (sockets).

Change-Id: Iaf3ced1a4b7ab10291c0b87eecd9e9bedb486e06
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +02:00
Jukka Rissanen
928e7c4824 net: Local address family was not set in net_context
The address family of local endpoint address was not
set in net_context. This caused wierd issues as the
address family was always AF_UNSPEC.

Change-Id: Ibd05f9af86a8bdea3399ad20e3b84bd7d43a6415
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +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
07cd16388e net: Increase the default network connection count
For dual IPv6 and IPv4 stack, the limit of network connections needs
to be increased as the default value of 4 is too small in this case.

Change-Id: If031ae9ee1dd095d20ee6a677ef8c678055ecfb0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
1501cb1076 net: tcp: Check for NET_TCP_IS_SHUTDOWN flag when sending/receiving
Return -ESHUTDOWN when this flag is set.

Change-Id: Ia2f5d8890b70652c1c348f25d4879248540ac66e
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
35bf12c5ac net: tcp: Add more debugging messages when disposing connections
Change-Id: I4c6da19cd1b697be44072a15d6b1f2f5a6b3c5de
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
1209245bac util: Ensure ARRAY_SIZE() will only take arrays
This code is inspired by a similar feature found in ccan[1],
that enforces that the parameter passed to ARRAY_SIZE() is
always an array and not a generic pointer.  This is a slightly modified
version that will work if the macro is expanded outside of a function
body.

The check is performed by comparing if typeof(array) and
typeof(&array[0]) are of a different type.  Due to the way arrays
decays to pointers in C, if one passes a pointer, the types won't be
compatible and a compile time assertion will fail.

No bugs have been found with this change, but since there's no runtime
or size overheads, there's no reason to not enable it.

[1] https://github.com/rustyrussell/ccan/blob/master/ccan/array_size/\
    array_size.h

Change-Id: I6c321714d0024298e593176be43b2d0b5362cc0d
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
1223c2b674 net: tcp: Send FIN packet when transitioning to LAST_ACK
When preparing a non-data segment, the FIN flag was not set in the sent
segment. Do it now.

Also, set NET_TCP_IS_SHUTDOWN when transitioning to this state.  This
flag isn't currently used beyond sending data segments, but will be
checked before the application tries to send data, or when data is
received from the network.

Change-Id: I6fb4f8fc7aa2a433522075d49307e8615ec6f2c7
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Jukka Rissanen
2b2dce28cd net: rpl: Use unified kernel API
Dropping legacy API.

Change-Id: Iee4b868e0b23b4e656ef2241872d4cfc8b0fd0de
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
2a14a59162 net: Use PART_OF_ARRAY() macro
This cleans up some code, and fixes some wrong assertions. For
instance, the following code was present in net_context_bind():

	NET_ASSERT(context >= &context[0] || \
		   context <= &context[NET_MAX_CONTEXT]);

The intention was to see if the context (which is a pointer to a
net_context struct) was part of the "contexts" array, but instead did
something else entirely.

Change-Id: Iae8161990987ec0c3632ee493ff9248e789683dc
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Leandro Pereira
4f3be3951a util: Add PART_OF_ARRAY() to check if pointer points to array element
This macro does two things: first, it validates that the pointer is not
NULL.  Second, it validates if it's between the first and the last
element in the array.

This is useful for cases where a pool of structures are used, such as
in the network subsystem.

Change-Id: I9d815936e31d87a3b3ff80466eea97bc4ad954b5
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:16 +02:00
Juan Manuel Cruz
9e36897455 ethernet: enc28j60: fixes an issue caused during an internal rebase.
The original commit:

https://gerrit.zephyrproject.org/r/#/c/6256/

has changed because an internal rebase. Two lines adding an SPI
command are missing.
This commit adds back the missing lines.

Change-Id: I5cbeda73ef1eae5eb98dfa3b7f3086b7438da9a9
Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
b3077ab4e7 samples: net: Fix echo-server compilation error
My IPv4 address was missing because of complex set of #ifdef's.

Change-Id: I6768587d3e104a57c10756bc43267f26068aa3cb
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
412a4f32ff net: Fix menuconfig for setting up samples IP addresses
We need to have a menuconfig for setting up networking
sample application IP address. This way we can properly
use strtol() which is only available if the
CONFIG_MINIMAL_LIBC_EXTENDED is selected.

Change-Id: I749ea444584b3e15d4a6fee9cd9065aba22a7278
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
697f4098f2 net: tcp: While disposing connection, properly check net_tcp pointer
The net_tcp_release() function was checking if the passed pointer to a
net_tcp struct was valid by checking if the pointer was within the
range of the tcp_context array.

However, the check was inverted, and the function was returning -EINVAL
every time a pointer to any element of the tcp_context array was
passed.

Because of this, TCP connections were never properly disposed, TCP
context were most likely left in either active or passive close states,
and new connections could never be established again.

Change-Id: I2ed368157349f0ca5641f7d15a555c0035e1a9e2
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
572e3a1607 net: tcp: Calculate ack# correctly when receiving data
Use the appdatalen value calculated by packet_received().  This avoids
recalculating the acknowledgement delta by reusing the same value that
is provided to the application.

In particular, sending a 30-byte packet to a Zephyr server would
produce an ACK# that, instead of being 30 higher than the sequence
number, was 40 below that number, because -NET_IPV6H_LEN was being
considered in the calculation.

Wireshark seems happy with this value, with no retransmissions from the
Linux end to the Zephyr end.

Change-Id: I35507fc2b880b4bae97277951d6d1b74a83a88c2
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
564d8cda53 net: tcp: Revisit implementation of passive close
This change moves the handling of passive close to a callback function
that handles the {CLOSE_WAIT, LAST_ACK} states.  This cleans up the
callback that handles the established estate, leaving only the handling
for that specific state in the tcp_established() callback.

Also, send the correct acknowledge number and send only an ACK rather
than a FIN+ACK packet while transitioning from ESTABLISHED to
CLOSE_WAIT.

These changes makes Wireshark happy when the connection is closed.

Change-Id: Ieeced5dff845f53a6b61af973dcf0fe3b7b8601f
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
bab94301ff net: tcp: Print pointer to state when transitioning
This aids in debugging logs to know which state structure transitioned
to which state.

Change-Id: I5bb1f34431e162f422513fcb40a2178e24e6fd84
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
4ed6ed06d8 net: tcp: Be more careful before dereferencing pointer in accept()
The function net_context_accept() was dereferencing context->tcp
without asserting it's not NULL, even if the protocol was not TCP.
There's a check prior to that to ensure it's a SOCK_STREAM, but that
wasn't sufficient to ensure that the pointer wouldn't be dereferenced
even if invalid.

Change-Id: Ie4f6b9792f6ebb90198ba3a845bb1b83ac450c38
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
777cd0727c net: tcp: Fix state transitions during handshake
During handshake, a new network context is created. But, before that,
the master TCP state is reset to the LISTEN state. Although correct by
the state machine definition, the TCP state of the master socket is
swapped with the newly-created context for the client socket.

This allows the client to keep the sequence numbers and other critical
flags. So, after swapping the TCP states, we were transitioning between
the LISTEN and ESTABLISHED states, which is wrong, and the new state
would be kept in the default, CLOSED state, which would make it
impossible to connect to a port a second time.

Change-Id: I3a30c632be0da29960c632d1ee62d1c4ec9d7348
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
e66a257b7e net: tcp: Print all the reasons a RST segment is sent
One case was not covered by a NET_DBG call, so add it.

Change-Id: Ie2b1f5cf6cdf62d39a3d12d0533e57e126266451
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
95d23577d2 net: tcp: Handshake ACK timeout should transition to LISTEN
The timeout was transitioning the master socket to the CLOSED state,
which made the port unconnectable if a handshake failed to finish in
one second.

Also cancel the ACK timeout when transitioning to ESTABLISHED;
otherwise, the connection would be closed after a second.

As a bonus, print the timeout in miliseconds.

Change-Id: I8e2d93cf0bbd706397909a2bb97b1821964d25da
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Leandro Pereira
483c8e780f net: Remove duplicated return statement
Change-Id: I7dc42165d94add6d24dfcbf427f1fee3f44f6f5b
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:15 +02:00
Tomasz Bursztyka
f0c41205db wpanusb: Minimize debug output by default and set proper nbuf size
Nbuf data size needs to be set to 128 bytes, specifically for
wpan sample.

Debug output kills timing, and thus can generate spurious failures on
reception, so limiting it to errors by default.

Change-Id: Ia918361d07369dacbe577e26855d7ef6ed865f7b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
5165eb7e7e net: udp: Add util to create UDP packet
Create utility function that creates an UDP packet.
Use that function by net_udp_append().

Change-Id: I65b911a41910f812f8754ac1c787790ba63c637d
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:15 +02:00
Jukka Rissanen
a870dffa7f samples: net: echo apps can use IP address set in config file
The used IPv6 or IPv4 address can be set in the config file.
This way one does not need to edit the source file to setup
the desired IP address.

Change-Id: Ic900bd4694481b4b035026ad0ba7b9280eb84e4a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
9ee1f3f7d4 net: Add support for setting up sample apps IP addresses
User is able to setup sample net apps IP addresses
via config file.

Change-Id: I7fbbda30d474095da717ed300977761857f509b8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
876b7a9b10 samples: net: Bind to any IPv4 address by default
Let the echo-server listen any configured IPv4 address
by default.

Change-Id: Ib83c5e069ae1e26615c37fa980bc4009b5a5e40c
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
0cc43a62ac samples: net: Do not use static address in DHPCv4
If user has enabled DHCPv4 support, then do not try
to set static IPv4 address.

Change-Id: Ia359f578044d72b951f53c509c92c09d575207f0
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
06fd64d1a0 net: dhcpv4: Fix debug output
The xid was printed in network byte order when msg was received.
Added also expected xid vs received xid if the packet recv
failed.

Change-Id: I6311033600f8e61378a8a1fb126074e83f98f142
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
cdc56a0893 drivers: ieee802154: RX stack debug enhancements
Use the stack declaration macro from net_core.h which
allows user to see more information about stack usage
when using net shell.

Change-Id: Id3cc0fa49c5da79ba7d5573103864f1881e2f2e5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
59532902ff net: mgmt: Use macro to define the stack
This enables the management stack information to be shown
in the net shell.

Change-Id: I6cf1d8b9a0d2da1623ce99b7726ea72a9769f2d8
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
b20279dbfd net: rpl: Increase the RX stack usage
RPL requires 300 bytes more stack in RX path.

Change-Id: I7ebe5ec6470f6766997f8b5eb199fc55b059513a
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
888e6b997d net: Move stack related Kconfig options to Kconfig.stack
This way we see all the stack related Kconfig options in
one place.

Change-Id: I01dd566525823c96ee8c000435e27619fc8699c4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Jukka Rissanen
720be1a3b8 net: shell: Add command to print stack usage info
The "net stacks" command will print information about
stack usage in the networking sub-system.

Change-Id: I568445e99158972b13dc10a1bb720ba9650b7ab4
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +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
0f8be63d8e ethernet: ksdk: Use unified kernel API
Dropping legacy API.

Change-Id: Id3d0b3e4ac7834e78a4d70ee5c99c6998958921e
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-12-02 12:41:14 +02:00
Mahavir Jain
eefd912fed samples: net: Use unified kernel interface for sem/queue declaration
Change-Id: I2519a7a35f83d2542f333ca6791a6f22944a42c4
Signed-off-by: Mahavir Jain <mjain@marvell.com>
2016-12-02 12:41:14 +02:00
Vinicius Costa Gomes
8a11cf696d samples/leds-demo: Listen on the ANY address
If we want to receive packets to multiple addresses, the solution is to
listen on the ANY address, and add the address to the interface in
question (already done).

Change-Id: I383cc1401f1236ee05bdb010252a9f9909aa15bd
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2016-12-02 12:41:14 +02:00
Vinicius Costa Gomes
9cd6bd9961 samples/leds-demo: Fix not using the LED correctly
Before using the LED we must set the direction of the GPIO pin to
output, and the LED will turn on when that GPIO pin is 'low'. So, for
our purposes, the LED is active low.

Change-Id: If8e6ce05ff2f3ddb7b17a87b172a91f7276194a4
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2016-12-02 12:41:13 +02:00
Vinicius Costa Gomes
4723d29e32 samples/leds-demo: Fix missing include file
'board.h' includes the definition of LED0_GPIO_PORT and LED0_GPIO_PIN,
without this include the fallback was used, as if the board in question
didn't have any LEDs.

Change-Id: I78ebdb2e2ffc41dff5011dcf9e33e09d70950e81
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2016-12-02 12:41:13 +02:00
Vinicius Costa Gomes
e27c7c02b2 samples/leds_demo: Add config for using 802.15.4
This adds a configuration profile allowing this example to run on a
Quark SE C1000 devboard.

Change-Id: Ic04fd30a91ed0a1fc8c3a3b3a6e397f0722f50b1
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
2016-12-02 12:41:13 +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
Luiz Augusto von Dentz
1997b24e88 net: bt: Remove comments about nbuf extra references
This no longer apply as there is no longer a extra reference needed.

Change-Id: I84f50da7e15f31722cd99b906f9dd987a10ce2dd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-02 12:41:13 +02:00
Luiz Augusto von Dentz
d1588dccee net: bt: Print data length for both recv and send
Change-Id: Ibe5c0a17addaa0f7a839691f8eac6128fe95335f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-02 12:41:13 +02:00
Mahavir Jain
fa43abc100 net: shell: Fix warning in case CONFIG_NET_IPv6 is not enabled
Change-Id: Ie10aa043c222871c9f9ec8f6f311949b39f7c904
Signed-off-by: Mahavir Jain <mjain@marvell.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
d45a5330ee net: tcp: Validate state transitions for debugging purposes
If NET_DEBUG is enabled within tcp.c, all state transitions are checked
against the TCP state machine specification.  If an invalid state
transition is found, a debugging message is printed.

Change-Id: I8fe521a74da6c57e8aeee32e99b25c3d350fd4b0
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00
Leandro Pereira
db3bee8bdd net: tcp: No need to #if defined(TCP) inside TCP callback
The whole function is only built if TCP is also built.

Change-Id: I0ed71273fa8db52b3e4c18d4b7b1766593f15f5a
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2016-12-02 12:41:13 +02:00