Commit graph

125 commits

Author SHA1 Message Date
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Jukka Rissanen 4043909d69 net: http: Remove HTTP client and server APIs
The old legacy APIs use net-app library and as that is being
removed, then the dependencies need to be removed also.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Krzysztof Chruscinski 97345dbb1b logging: Fix errors in log usage
Couple of findings which were revealed after changing
LOG_MODULE_REGISTER macro:
- missing semicolons after LOG_MODULE_REGISTER()
- missing LOG_LEVEL defines
- other

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-10 12:38:29 -05:00
Jukka Rissanen 009e4dafa7 net: Make Kconfig template variables prettier
Adding spaces around "=" when definining Kconfig template so
that is more consistent with overall style of these template
variables.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-05 09:01:37 -04:00
Jukka Rissanen 57a8db7789 net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might
be overwritten must use log_strdup() which will create a copy
of the printable string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Jukka Rissanen 8ffb0fc968 net: lib: Convert http library to use log level
Use network log level in HTTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Jukka Rissanen 355d58b0d0 net: http: One extra byte was sent in last chunk
There was one extra byte sent in last chunk which caused
this error to be printed by curl

  * Illegal or missing hexadecimal sequence in chunked-encoding
  * stopped the pause stream!
  * Closing connection 0
  curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-08-15 12:59:13 +03:00
Ulf Magnusson ec3eff57e0 Kconfig: Use the first default with a satisfied condition
Up until now, Zephyr has patched Kconfig to use the last 'default' with
a satisfied condition, instead of the first one. I'm not sure why the
patch was added (it predates Kconfiglib), but I suspect it's related to
Kconfig.defconfig files.

There are at least three problems with the patch:

  1. It's inconsistent with how Kconfig works in other projects, which
     might confuse newcomers.

  2. Due to oversights, earlier 'range' properties are still preferred,
     as well as earlier 'default' properties on choices.

     In addition to being inconsistent, this makes it impossible to
     override 'range' properties and choice 'default' properties if the
     base definition of the symbol/choice already has 'range'/'default'
     properties.

     I've seen errors caused by the inconsistency, and I suspect there
     are more.

  3. A fork of Kconfiglib that adds the patch needs to be maintained.

Get rid of the patch and go back to standard Kconfig behavior, as
follows:

  1. Include the Kconfig.defconfig files first instead of last in
     Kconfig.zephyr.

  2. Include boards/Kconfig and arch/<arch>/Kconfig first instead of
     last in arch/Kconfig.

  3. Include arch/<arch>/soc/*/Kconfig first instead of last in
     arch/<arch>/Kconfig.

  4. Swap a few other 'source's to preserve behavior for some scattered
     symbols with multiple definitions.

     Swap 'source's in some no-op cases too, where it might match the
     intent.

  5. Reverse the defaults on symbol definitions that have more than one
     default.

     Skip defaults that are mutually exclusive, e.g. where each default
     has an 'if <some board>' condition. They are already safe.

  6. Remove the prefer-later-defaults patch from Kconfiglib.

Testing was done with a Python script that lists all Kconfig
symbols/choices with multiple defaults, along with a whitelist of fixed
symbols. The script also verifies that there are no "unreachable"
defaults hidden by defaults without conditions

As an additional test, zephyr/.config was generated before and after the
change for several samples and checked to be identical (after sorting).

This commit includes some default-related cleanups as well:

  - Simplify some symbol definitions, e.g. where a default has 'if FOO'
    when the symbol already has 'depends on FOO'.

  - Remove some redundant 'default ""' for string symbols. This is the
    implicit default.

Piggyback fixes for swapped ranges on BT_L2CAP_RX_MTU and
BT_L2CAP_TX_MTU (caused by confusing inconsistency).

Piggyback some fixes for style nits too, e.g. unindented help texts.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-10 12:38:28 -07:00
Ravi kumar Veeramally 3fafe4f9ad net: ipv6: Handle large IPv6 packets properly
Current implementation does not handle large extension headers
(e.g HBHO). Which resulted network stack crashes or due to
misinterpretation of lengths network packets are dropped. Also
caused issues while preparing IPv6 packet (e.g. large HBHO header
with IPv6 fragmentation support).

Issues fixed and provided more unit tests.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-07-23 15:01:09 +03:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Jukka Rissanen d70c7383de net: websocket: Initial support for server websocket
This commit creates a websocket library that can be used by
applications. The websocket library implements currently only
server role and it uses services provided by net-app API.
The library supports TLS if enabled in configuration file.

This also adds websocket calls to HTTP app server if websocket
connection is established.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:17:36 +02:00
Ravi kumar Veeramally ebc81bdf8d net: http: Provide destination address in http replies
net_app_ctx maintains multiple net contexts(net_ctx). But when http
api's wants to reply or send some data, its always choose the first
net_context in the array, which is not correct always.

net_app_get_net_pkt_with_dst() api will select proper context
based on destination address. So with the help of new api in
net_app, http can select proper context and send packets. To
achieve this, desination address is provided in http_recv_cb_t
and http_connect_cb_t callbacks. Also chaged relevant API's to
provide destination address in http message preparation methods.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-03-05 10:23:17 +01:00
Michael Scott e9c0d001fa net: http: client: remove payload send_chunk logic
Logic for sending chunks of data is incompatible with adding
Content-Length: header.

Per https://tools.ietf.org/html/rfc7230#section-3.3.1:
"A sender MUST NOT send a Content-Length header field in any
message that contains a Transfer-Encoding header field."

Going a bit further in my mind: also don't send Transfer-Encoded
chunked data either when the Content-Length header is present.

In general, there will be problems if the http client library
makes payload changes without the user code knowing about it.

This patch removes the use of http_send_chunk() from the new
HTTP client code and instead sends the payload directly to
http_prepare_and_send()

This fixes an issue where every available buffer would be allocated
with repeating payload data because the for loop in http_request()
wasn't ending until we ran out of memory.

NOTE: This patch was previously applied but was lost when
commit d1675bf3e6 ("net: http: Remove the old legacy API")
moved code around.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott 4fe2bcf13f net: http: fix flush in http_prepare_and_send()
In commit 9489fa54cc ("net: http: Fix http_prepare_and_send"),
the logic for when to call http_send_flush() was incorrect.  This
is causing a call to http_send_flush() every time
http_prepare_and_send() is called.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott fcb5e2b1ee net: http: honor CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT setting
We should not use the user suppied timeout setting in
http_client_send_req() for the connection timeout.  In the
previous API the call to tcp_connect() used
CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT as the timeout setting.

Let's do that here too.

This fixes -ETIMEDOUT error generation when using K_NO_WAIT
for http_client_send_req().

NOTE: This patch was previously applied but was lost when
commit d1675bf3e6 ("net: http: Remove the old legacy API")
moved code around.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Michael Scott a2dfaebafc net: http: client: handle empty body for PUT/POST request response
In previous version of the HTTP API, commit 8ebaf29927 ("net: http:
dont timeout on HTTP requests w/o body") fixed handling of HTTP
responses without body content.

For the new API, let's add a specific fix for when PUT/POST requests
are responded to with just the status code.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2018-03-02 16:51:22 +01:00
Leandro Pereira 517df4d73c subsys: net: http: Send "Internal Server Error" on unknown error code
Avoid using an uninitialized pointer when adding headers to the HTTP
context.

Coverity-CID: 178792
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-02-19 10:37:57 +02:00
Ravi kumar Veeramally 9489fa54cc net: http: Fix http_prepare_and_send
net_pkt_append() has been changed. If payload reached max value
of 'data_len' in net packet, net_pkt_append will not append.
So the caller has to create new packet and append remaining payload.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2018-02-02 16:50:07 +02:00
Jukka Rissanen d1675bf3e6 net: http: Remove the old legacy API
There are no internal users for old HTTP API so removing it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-01-29 22:44:45 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Tomasz Bursztyka f8cf3b99d9 subsys/net/lib: Clear up CMakeLists.txt
Tiny cleanups to clarify, and 80 chars limit fix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-12-11 09:34:16 -05:00
Michael Scott e04a5412a1 net: http: client: remove payload send_chunk logic
Logic for sending chunks of data is incompatible with adding
Content-Length: header.

Per https://tools.ietf.org/html/rfc7230#section-3.3.1:
"A sender MUST NOT send a Content-Length header field in any
message that contains a Transfer-Encoding header field."

Going a bit further in my mind: also don't send Transfer-Encoded
chunked data either when the Content-Length header is present.

In general, there will be problems if the http client library
makes payload changes without the user code knowing about it.

This patch removes the use of http_send_chunk() from the new
HTTP client code and instead sends the payload directly to
http_prepare_and_send()

This fixes an issue where every available buffer would be allocated
with repeating payload data because the for loop in http_request()
wasn't ending until we ran out of memory.

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Michael Scott 865d617772 net: http: honor CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT setting
We should not use the user suppied timeout setting in
http_client_send_req() for the connection timeout.  In the
previous API the call to tcp_connect() used
CONFIG_HTTP_CLIENT_NETWORK_TIMEOUT as the timeout setting.

Let's do that here too.

This fixes -ETIMEDOUT error generation when using K_NO_WAIT
for http_client_send_req().

Signed-off-by: Michael Scott <michael@opensourcefoundries.com>
2017-11-14 09:52:59 +02:00
Jukka Rissanen 7784518d37 net: http: Add error status string to HTTP server error
Add status error string when sending a error message from
HTTP server to client as described in RFC 2616 ch 6.1.
Previously only error code was sent except for 400 (Bad Request).

This also fixes uninitialized memory access in error message.

Coverity-CID: 178792
Fixes #4782

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-14 09:52:46 +02:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Jukka Rissanen 2486694eb9 net: http: Create HTTP library that uses net-app
Create http library that uses net-app instead of net_context
directly. The old HTTP API is deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-11-06 09:33:00 -05:00
Michael Scott 0bd961647a net: lib: http: fix check for invalid body_start pointer
Recent commit fb7f6cfa97 ("net: lib: http: Fix invalid pointer
body_start") introduced logic to reset the response body_start pointer
when the response buffer was reused.

This check needs to be fixed so that it doesn't arbitrarily change
body_start when not needed.

The problem with the current check can be demonstrated by not setting
a response callback for request which generates a large response
spanning multiple packets.

In this case body_start is still valid (not reusing the response buffer
because there is no callback set), but it will be changed when the 2nd
packet is received and the "at" marker is located at the head of the
new packet (!= response_buffer).

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-27 17:42:01 -04:00
Jukka Rissanen 9a61384b86 net: http: Check that we could install recv_cb in accept
Inform user if we could not install receive callback after
a connection is accepted in http server.

Coverity-CID: 178244
Fixes #4584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-10-27 15:35:59 +03:00
Ding Tao fb7f6cfa97 net: lib: http: Fix invalid pointer body_start
The body_start field at http_client_ctx.rsp is used to check if this
fragment contains (a part of) headers or not.

If the device recived more than one fragment in one http response,
may cause re-use of the result buffer in function on_body().

Once the device re-use the result buffer, the body_start that point
to this buffer address will no longer be valid.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2017-10-26 09:40:05 +03:00
Andrew Boie c5c104f91e kernel: fix k_thread_stack_t definition
Currently this is defined as a k_thread_stack_t pointer.
However this isn't correct, stacks are defined as arrays. Extern
references to k_thread_stack_t doesn't work properly as the compiler
treats it as a pointer to the stack array and not the array itself.

Declaring as an unsized array of k_thread_stack_t doesn't work
well either. The least amount of confusion is to leave out the
pointer/array status completely, use pointers for function prototypes,
and define K_THREAD_STACK_EXTERN() to properly create an extern
reference.

The definitions for all functions and struct that use
k_thread_stack_t need to be updated, but code that uses them should
be unchanged.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 08:24:29 -07:00
Michael Scott 1d36225345 net: lib: http: split out URL parsing as a separate CONFIG
With the introduction of CoAP and other protocols, URL parsing is
be needed when HTTP_PARSER is not.  Let's split out the existing
functionality of URL parsing into it's own CONFIG and let
HTTP_PARSER use it by automatically selecting HTTP_PARSER_URL when
HTTP_PARSER is enabled.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-10-17 08:08:16 -04:00
Jukka Rissanen eda6403850 net: http: HTTP client was not honoring timeout parameter
If the caller of http_client_send_req() sets the timeout to
K_NO_WAIT, then the function would still wait for a while before
returning to the caller.

Jira: ZEP-2624

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-09-27 22:11:21 +03:00
Luiz Augusto von Dentz 9147b53d76 net: Remove check for k_delayed_work_cancel
k_delayed_work_cancel now only fail if it hasn't been submitted which
means it is not in use anyway so it safe to reset its data regardless
of its return.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 15:34:40 -04:00
Michael Scott caa377943a net: http: fix avoiding timeout on HTTP requests w/o body
The original commit 8ebaf29927 ("net: http: dont timeout
on HTTP requests w/o body") was intended to handle a case
where an HTTP response had been retrieved from the server but
the HTTP parser couldn't meet the criteria for calling
"on_message_complete".  For example, a POST to a REST API
where the server doesn't return anything but an HTTP
status code.

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

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

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

Jira: ZEP-2561

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-23 16:42:03 -04:00
Jukka Rissanen 3dfa1cef0a net: http: HTTP header field state was not reset
The HTTP header field pointers are saved for each HTTP request.
But the counter that saves the pointers was never reset to initial
value when the connection was dropped. This meant that the header
field values were only proper for first HTTP request.

Jira: ZEP-2463

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-22 16:38:05 -04:00
Paul Sokolovsky dcb80f7ab8 net: struct sockaddr should have field "sa_family"
POSIX requires struct sockaddr's field to be named "sa_family"
(not just "family"):
http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html

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

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-18 16:34:51 -04:00
Jukka Rissanen 12017ce761 net: http: Yield after sending response in server
Make sure that a network packet is sent after calling
http_response_send_data(). Othwerwise the packets might be
piling up and not sent in timely manner.

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

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

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-16 12:35:33 +03:00
Michael Scott 8ebaf29927 net: http: dont timeout on HTTP requests w/o body
A TCP FIN message is passed on to user apps as a tcp_received_callback
with a NULL pkt parameter.  This means the connection is closing and
the app should do whatever cleanup it needs as there will be no further
callbacks for the current TCP connection.

Currently, if a HTTP client request doesn't receive a "body" which
the HTTP parser can use to trigger on_message_complete, then the request
will end up timing out and most apps will think an error has occurred.

Instead, let's handle the TCP FIN message and return the waiting
semaphore, leaving the app to deal with whatever has been set in the
current HTTP context response data (IE: http_status).

This fixes using HTTP client to send POST data to servers which
only respond with HTTP_OK status and no body.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-15 22:21:15 +03:00
Michael Scott f18674a320 net: http: fix http client request "Host" header
RFC-7230 "HTTP/1.1 Message Syntax and Routing" Section 5.4
describes the "Host" header formatting.  If Zephyr user
specifies a host string as a part of the HTTP client request
structure, we end up sending an incorrect HTTP header due
to a missing "Host :" text.

Fix this by prepending "Host: " to the header data before
the user supplied host string.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-11 09:45:02 +03:00
Jukka Rissanen 64562e1af2 http: server: Add function to send a chunk of data
The http_response_send_data() can be used to send a chunk of data
to the peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-08-08 15:35:18 +03:00
Andrew Boie 507852a4ad kernel: introduce opaque data type for stacks
Historically, stacks were just character buffers and could be treated
as such if the user wanted to look inside the stack data, and also
declared as an array of the desired stack size.

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

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

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

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

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

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-08-01 16:43:15 -07:00
Jukka Rissanen 1c07ead104 net: http: Add context net_buf pool support to HTTP client
This commit adds http_client_set_net_pkt_pool() function that allows
caller to define net_buf pool that is used when sending a TCP packet.
This is needed for those technologies like Bluetooth or 802.15.4 which
compress the IPv6 header during send.

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-31 11:50:25 +03:00
Paul Sokolovsky b1a3753669 net: http_server: Properly close network contexts.
Use net_context_put(), not net_context_unref(). This makes sure
that after sending response, connections are properly closed.

Jira: ZEP-2362

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-07-18 08:40:02 +03:00
Jukka Rissanen 98fb2bed63 net: Comment false positives reported by Coverity
Coverity reported false positives, add comment about these in
the code.

Jira: ZEP-2344
Jira: ZEP-2345

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-07-11 13:59:04 +03:00
Geoff Gustafson 1405627c37 net: context: Use K_NO_WAIT instead of 0 for timeout
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
2017-07-10 10:59:28 +03:00
Jukka Rissanen 92fa7ac6ce net: http: Remove mbedtls heap setting from http library
The global mbedtls heap is set automatically now so no need to
set it individually in the http library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-27 16:42:59 +03:00
Jukka Rissanen 35d28fb567 net: http: Connection close fix if old connection is active
If we receive a HTTP request and if the earlier context is still
active and it is not the same as the new one, then close the earlier
one. Otherwise it is possible that the old context will be left into
TCP ESTABLISHED state and would never be released. Example of this
is that we had IPv4 connection active and then IPv6 connection is
established, in this case we will disconnect the IPv4 connection
after this commit.

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

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

This is only useful for debugging the HTTP connections.

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

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-09 09:56:21 +03:00
Jukka Rissanen 2e2ce3120a net: https: Allow mbedtls debugging for https-server
The mbedtls debugging function was set before the ssl config
struct was initialized. This meant that it was not possible
to activate mbedtls debug prints. This commit sets the debug
print option after the config struct has been initialized.

Fixed also the debug prints which print extra \n which looks
very bad in debugging outputs.

This commit does not enable mbedtls debugging, it just makes it
possible to output mbedtls debug prints. In order to get mbedlts
debug prints one needs to do this:
* set DEBUG_THRESHOLD to >0 in http_server.c
* enable CONFIG_NET_DEBUG_HTTP in project config file
* enable MBEDTLS_DEBUG_C in mbedtls config file (see file pointed
  by CONFIG_MBEDTLS_CFG_FILE option)
* in qemu, one needs to increase the size of the available RAM,
  this setting does the trick, CONFIG_RAM_SIZE=300

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-06 09:32:52 +03:00
Jukka Rissanen bd7d1bda20 net: http: Avoid unnecessary net_pkt error print
In some cases the net_pkt can be null when freeing it,
this will print error from net_pkt library. Avoid this by
checking the value of net_pkt before calling net_pkt_unref().

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-02 12:43:52 +03:00
Jukka Rissanen c9e6ef5331 net: http: Use random source port when connecting
If we re-connect to same peer server, then we should select a new
source port. Noticed that if the same source port as before is
used for the new connection, the peer might drop the packet. This
was seen when connecting to Linux peer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-06-02 12:43:52 +03:00
Jukka Rissanen 010b892c8a net: http: Parsing state was not cleared
If we received a bad HTTP request, then subsequent good requests
were also returning 400 error code. The parsing state needs to
be initialized after each received HTTP request.

Jira: ZEP-2181

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-31 14:54:06 -04:00
Jukka Rissanen eeaa29666b net: http: Handle HTTPS connection closing gracefully
If the HTTPS connection is closed, then properly handle call to
HTTP parser init in case of error and also remove any pending
data that belong to old connection.

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

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

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-23 18:01:04 +03:00
Jukka Rissanen a174d2eba7 net: http: Add HTTP server library support
This commit creates a HTTP server library. So instead of creating
a complex HTTP server application for serving HTTP requests, the
developer can use the HTTP server API to create HTTP server
insteances. This commit also adds support for creating HTTPS servers.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-05-13 14:30:58 -04:00
Jukka Rissanen 70f334d9f2 http: client: Create a HTTP library
Instead of separate sample application that does everything
related to HTTP client connectivity, create a HTTP client library
that hides nasty details that are related to sending HTTP methods.
After this the sample HTTP client application is very simple and
only shows how to use the client HTTP API.

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

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

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

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

Jira: ZEP-1984

Change-Id: Ibaf7c029b15e91b516d73dab3612eed190ee982b
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-28 15:01:09 +03:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Tomasz Bursztyka db11fcd174 net/net_pkt: Fully separate struct net_pkt from struct net_buf
- net_pkt becomes a stand-alone structure with network packet meta
  information.
- network packet data is still managed through net_buf, mostly named
  'frag'.
- net_pkt memory management is done through k_mem_slab
- function got introduced or relevantly renamed to target eithe net_pkt
  or net_buf fragments.
- net_buf's sent_list ends up in net_pkt now, and thus helps to save
  memory when TCP is enabled.

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

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

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

Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-04-21 14:19:50 +03:00
Michael Scott 081246737c net/http: let HTTP_SERVER, HTTP_CLIENT and HTTP_PARSER select HTTP
Due to commit 8308b9bd2d ("net/http: Add the HTTP/1.1 API")
every user of CONFIG_HTTP_PARSER would need to add CONFIG_HTTP to
their .conf files.  Which is fine for intree samples/tests as they
have been adjusted, but the rest of world working on Zephyr apps
will need to make this changes as well.

Instead, we should have each of the following select HTTP instead of
depend on it, which will make future use of these configs and their
dependencies more intuitive:
HTTP_SERVER
HTTP_CLIENT
HTTP_PARSER

NOTE: As cleanup, this commit also removes the CONFIG_HTTP added to
samples and test .conf files.

Change-Id: I81cfaa19e37333b1bf98778f8147814780e7f77c
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-03-17 10:34:45 +02:00
Flavio Santes b8f8968f70 net/http: Move some statements to the right place
The "null terminator" for the chunked transfer encoding must be
added only if the payload is present.

Change-Id: Id325a660f060b3a3468bcca16a079def11b8c3ef
Signed-off-by: Flavio Santes <flavio.santes@intel.com>
2017-03-17 10:34:39 +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
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
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