Commit graph

1061 commits

Author SHA1 Message Date
Jun Qing Zou ca783d72a6 net: lwm2m: support client-initiated De-register
Add new RD Client API of lwm2m_rd_client_stop() for this
Fix issues of de-register and event reporting in RD Client

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2019-09-08 12:36:33 +02:00
Jun Qing Zou 9103403308 net: lwm2m: support NET_SOCKETS_OFFLOAD in peer parsing
The LwM2M implementation for DNS resolving has checks which
configure hints based on whether IPv4 or IPv6 are enabled.
Neither of them need enabled if using NET_SOCKETS_OFFLOAD,
which then causes an error to be returned to due to
"hints.ai_family" not being set.

Also the offload API need to know when to free the allocated
"struct addrinfo" instead of calling free() generically,
thus let's use the freeaddrinfo() API for sockets which will
call into the offload API if needed.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18765

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
2019-08-30 11:58:00 +02:00
Michael Scott 7841ebf312 net: lwm2m: firmware_pull: fix multiple last_block notifications
When the firmware_pull mechansim sends the callback to notify the
sample of a new firmware block, the user supplied buffer can be
smaller than the CoAP BLOCK_SIZE setting.  To handle this case,
we loop through the payload and fill the user supplied buffer with
smaller chunks.

Unfortunately, the last_block calculation is done outside this loop
which causes several callbacks (while in this loop) to have
last_block true.   Let's fix this by adding a small check to make
sure we're at the end of the current payload block before notifying
the user of a last_block.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16158

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-29 19:49:29 +02:00
Jukka Rissanen 3479010e7d net: dns: Check and parse received mDNS responses properly
The mDNS packet receive had issues:

* The DNS id needs to be 0 for both sending and receiving, we did
  not accepted 0 incoming id.
* The mDNS response does not have any questions in it so we just
  need to skip the question count checks in response.
* Skip the Cache-Flush bit in Class field so that we can properly
  parse CLASS_IN value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-29 19:47:07 +02:00
Jukka Rissanen 9fdd41be28 net: dns: Print info about the type of the DNS server
In DNS server init, print information whether the DNS server
is mDNS or LLMNR one. This way we do not need to remember what
IP addresses are used either of them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-29 19:47:07 +02:00
Jukka Rissanen f4c4d12062 net: mdns: Use 5353 source port when sending the query
The source UDP port in all Multicast DNS responses MUST be 5353
as described in RFC 6762 chapter 6.

Fixes #18732

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-29 19:47:07 +02:00
Jukka Rissanen ae5db66b8c net: conn_mgr: Check IPv4 events against command
Make sure we use the IPv4 event command when checking IPv4 address
add or delete instead of event mask.

Coverity-CID: 203483
Fixes #18400

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 14:58:28 +02:00
Michael Scott 098f1c9bfa net: lwm2m: tlv: fix float32/64 sign handling
When val1 is 0, we need to handle a negative val2 value so that we
generate correct TLV value.

Example: val1 = 0, val2 = -500000 is equivalent to -0.5 decimal.
Currently we generate: 0.5 (losing the sign).

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott d52b5843c7 net: lwm2m: json: use plain text formatter for float32/64
Current JSON formatting for float32/64 is broken in a similar way as
plain text.  Let's use the newly fixed logic for plain text to
generate the float32/64 values in the JSON string.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott 404a4b8556 net: lwm2m: plain text: expose put_float32/64 functions
We can use the plain text float32/64 formatter for JSON as well, so
let's expose the put_float32/64 functions.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott cdcb33b75f net: lwm2m: plain text: fix float formatting
Formatting a float32/64 value for plain text is broken.
Example for 32bit: val1=0 and val2=500000 is equivalent to 0.5

Current formatter was using %d.%d (%lld.%lld for 64bit) so
exported value was 0.500000 (or 0.5)

To fix this, for val2 use a zero-padded formatter for the maximum
length of each bit length (6 for 32bit and 9 for 64bit), and then
remove the zero characters at the end of the string.

Notes re: handling of val1/val2 signs:
- eliminate potential negative sign when converting val2 to avoid:
  a value like: 0.-5
- use negative val2 when val1 is 0 to fix small negative handling
  such as -0.5

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16154

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-28 10:58:11 +02:00
Michael Scott e743d89cdc net: lwm2m: add missing bootstrap-finish handling
When the bootstrap support was added, it looks like I somehow missed
the handling block in the engine.

Let's add it now to fix boostrap support.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18080

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Michael Scott 523123857c net: lwm2m: Kconfig: fixup default instance counts for bootstrap
- LWM2M_SECURITY_INSTANCE_COUNT wasn't following the standard of
  having the unconditional default in the last position
- LWM2M_SERVER_INSTANCE_COUNT needs another instance when
  bootstrap is enabled.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Michael Scott 1bc586da6f net: lwm2m: Kconfig: move RD_CLIENT settings above dependencies
LwM2M boostrap support is enabled via the config option:
LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP.  If enabled, this config sets
the default # of server and security instances.  However, this is
not working correctly because LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
is defined below it's uses in the Kconfig file.

Let's move the RD_CLIENT configs higher in the Kconfig to fix this
behavior.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-24 11:04:25 +02:00
Paul Sokolovsky 951b47fab9 net: dns: dns_pack: Revamp FQDN parsing in answers
Simplify algorithm to skip (aka calculate length) of encoded domain
name in a DNS answer. Now it's fully compliant to RFC 1035 regarding
handling of compressed FQDNs. Additionally, bounds checking is now
performed by the parsing code.

Fixes: #18334

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-20 13:39:23 +02:00
Paul Sokolovsky 0bafa7c5ec net: dns: dns_pack: Properly access type and class fields of an answer
These are 16-bit fields, previous code access just least significant
byte of their values.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-20 13:39:23 +02:00
Tomasz Bursztyka 9124bcccc8 net: socket_mgmt: Fix for coverity CID 203397
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()

Coverity-CID: 203397
Fixes #18419

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-19 16:27:23 +02:00
Tomasz Bursztyka 7f527f616e net: socket_mgmt: Fix for coverity CID 203468
Let's use IS_ENABLED() instead of the #ifdef to get clearer code. ret
variable is used only at one place, no need for the ARG_UNUSED()

Coverity-CID: 203468
Fixes #18420

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-19 16:27:23 +02:00
Ravi kumar Veeramally 942e9dcc90 net: mgmt: Fix IPv4 connection management
IPv4 connection management status is stored in wrong
variable. ip_state should hold the status and then
it should be stored in state variable.

Fixes #18253

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-14 12:31:30 +02:00
Michael Scott 07f9e8beea net: lwm2m: fix IP address max calc in conn mon obj
When checking for total IP address counts, don't check
CONFIG_NET_IF_MAX_IPV6_COUNT twice.  This was a typo for
CONFIG_NET_IF_MAX_IPV4_COUNT.

This was reported by IRC user: retfie

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-09 23:22:13 +03:00
Tomasz Bursztyka e55c7d7265 net/conn_mgr: Fix events handler
- Commands were not gathered with the right macro
- bus fault access due to wrong declaration of iface_states external
variable.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-08-08 13:27:21 +03:00
Alexander Wachter c8c5f3bbf3 net: canbus: Rename canbus to canbus_raw
Rename the socket_can implementation from CANBUS to CANBUS_RAW.
This is a preperation for 6LoCAN which is a CANBUS L2 for IPv6.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
2019-08-08 13:25:01 +03:00
Jukka Rissanen abdd58ce3c net: sockets: Do not call NULL socket callback function
Before calling socket callback function, make sure the callback
function exists so that we do not get NULL pointer reference.

Fixes #18021

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-06 19:27:48 +03:00
Ravi kumar Veeramally 8e70bd6f48 net: mqtt: Modify SOCKS5 based connections
Current SOCKS5 based connections in mqtt are only
TCP (nonsecure) based. To support TLS based SOCKS5
connections, new methods needs to be introduced.

Instead, removed CONFIG_MQTT_LIB_SOCKS based implementation.
And now mqtt provides an api to set proxy
(mqtt_client_set_proxy()) details. That's enough,
socket layer will take care of making connections through
proxy server.

Fixes: #17037

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Ravi kumar Veeramally 39ed77e438 net: socks: Make SOCKS5 implementation transparent
Current SOCKS5 implementation is above socket level and every
higher layer protocol or application level needs to have
SOCKS5 related changes. This solution is based on socket
setsockopt(). Application caller has to set proxy details
through setsockopt() and socket:connect() will take care
creating connection.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Ravi kumar Veeramally c8fa169294 net: Add support for SOCKS5 socket option
The SO_SOCKS5 socket option can be used by the application to
set the SOCKS5 proxy details. These details will be used when
connecting to peer.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-08-05 13:26:11 +03:00
Michael Scott e81332d4bd net: lwm2m: cleanup memset usage during init
Several problems with memset usage in the LwM2M subsystem were
identified:
- Every single object that can have multiple instances is using
  memset to initialize static resource data during init.  This data
  will already be set to 0 because it is static, so the memset
  statements are unneeded.
- Instead of using memset during object init which is only called
  one time during kernel startup, let's add a memset to the
  object create function to ensure the resource data is cleared out.
  It could have been used prior and then released via a DELETE op.
- the IPSO Timer object was setting a lot of data structure members
  to 0 in the create function.  Let's do 1 memset on the entire
  structure and then only the non-zero values afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 6af8fa692b net: lwm2m: add LwM2M path to engine_set errors
When presenting errors in lwm2m_engine_set() let's include the related
LwM2M path for easier debugging.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 3d3af7114e net: lwm2m: add IPSO Accelerometer object support
This IPSO object can be used to represent a 1-3 axis accelerometer.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 3e7d374cd2 net: lwm2m: add Location object support
This core LwM2M object provides a range of location telemetry related
information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 9dc5e293f0 net: lwm2m: add Connection Monitoring object support
This core LwM2M Object enables monitoring of parameters related to
network connectivity.

This is only the basic object structure.  More work will be needed
to set the various resources based on connectivity.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ca61a238af net: lwm2m: add IPSO Push Button object support
This Object is used to report the state of a momentary action push
button control and to count the number of times the control has
been operated since the last observation.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 2019d49bf0 net: lwm2m: add IPSO On/Off Switch object support
This object is used with an On/Off switch to report it's state.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 4bf343d5d1 net: lwm2m: add IPSO Buzzer object support
The IPSO Buzzer object is used to represent a buzzer, beeper or
vibrating alarm.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 8817d930a8 net: lwm2m: rework resource instance storage / access methods
LwM2M allows for multiple instance resources such the power source
resources in the device object.  These types of resources have
always been very hard to work with, and frankly were poorly
implemented.

This led to other issues where it was very hard to have
non-sequential resource instances, and each resource of this type
needed special getter / setter methods such as:
lwm2m_device_add_pwrsrc()
lwm2m_device_set_pwrsrc_voltage_mv()

Going forward, as more LwM2M objects are implemented this just
doesn't scale well.

To fix this:
- split the resource instance data out from the resource data.
  This includes the data pointer information and resource
  instance id.
- add resource id and resource instance id to the event callback
  functions so user's can see in more detail what resources and
  resource instances are being handled.
- allow generic functions like lwm2m_engine_get_*() and
  lwm2m_engine_set_*() to access resource instance data.
- adjust object resource initialization  macros to map resource
  instances to resources at the time of object instance
  creation.
- fix up the lwm2m_client as a reflection of all of these changes.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 6a2f362357 net: lwm2m: remove lwm2m_engine_obj from most handlers/formatter OPs
Due to work combining data into the lwm2m_message structure, we no
longer need to pass the lwm2m_engine_obj parameter between
formatters and most of the operation handlers.

So, let's remove it.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ca308ec479 net: lwm2m: remove unique lwm2m_engine_obj_delete_cb_t definition
Instead, let's use lwm2m_engine_user_cb_t which is used elsewhere and
matches the same signature.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 30f31fb4e1 net: lwm2m: remove unused multi_max_count field from obj_field
The multi_max_count is no longer used and can be removed from the
obj_field structure if we change all of the OBJ_FIELD() macros to
use OBJ_FIELD_DATA() instead.

Technically, OBJ_FIELD() and OBJ_FIELD_DATA() are now the same, but
we're keeping them both for the time being.  In the future, more
fields may be added to the obj_field structure and we can use the
OBJ_FIELD() macro again if that's the case.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott ad01c035b8 net: lwm2m: update function prototypes and descriptions
- Several of the functions use "path" as the parameter name for the
  string-based LwM2M path.  Let's clarify by using "pathstr".
- Recent updates to the LwM2M engine now support resource instances
  when parsing the LwM2M path.  Let's update descriptions accordingly.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott 9534bbd991 net: lwm2m: add missing application type to IPSO Light Control
Per IPSO Light Control definition from the OMA LwM2M registry:
http://www.openmobilealliance.org/tech/profiles/lwm2m/3311.xml

There is an optional "Application Type" string resource (5750) in the
Light Control object.  This was missed in the initial implementation.

NOTE: sample will assign reference if needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott a33a6f7754 net: lwm2m: remove data storage for IPSO Timer application type
We are pre-allocating a storage variable for the application type
resource in the IPSO Timer object.  This is an optional resource
which won't always be set by samples.

Let's leave out the pre-allocated variable and let the sample set
this reference if needed (it's optional).

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Michael Scott c0e313aae1 net: lwm2m: use server record to set default observe notify timing
Server records contain the default PMIN and PMAX settings for how
often we can send observe notifications.  We are currently using
arbitrary defaults which cannot be changed when compiled or
during runtime.

Let's add Kconfig settings for the default settings to use and
also lookup the current values in the active server record when
an observe is added.

The actual PMIN/PMAX values can still be set via WRITE_ATTRIBUTE
operation.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-08-02 12:00:35 +03:00
Pieterjan Camerlynck d0dd1fbf5c net: lwm2m: cancel pending retransmit work when closing context
Currently the retransmit_work is not cancelled when closing a context,
making it operate on an invalid context.

LwM2M RD client also closes the context and initializes it again when
registration with the server fails, overwriting the active timeout and
breaking the timeout dlist.

Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
2019-07-30 10:19:39 +03:00
Robert Lubos ddf2230f44 net: openthread: Use repository provided by west
Move CMake ExternalProject integration of OpenThread to the
CMakeLists.txt file within the OpenThread fork.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-07-25 11:52:48 +02:00
Jukka Rissanen 0435dce697 net: Add support for TXTIME socket option
The SO_TXTIME socket option can be used by the application to
tell the network device driver the exact moment when the
network packet should be sent.

This feature is also implemented in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen ec2e2f43d8 net: sockets: Add sendmsg() API
Add BSD socket sendmsg() API that can be used to send data to peer
and also pass ancillary data to lower level of the network stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-24 10:17:16 +03:00
Jukka Rissanen 1a9e09c85c net: socket: userspace: Copy user specified value in getsockopt()
User could have set something to optval in getsockopt() and we
need to copy the data to kernel optval so that the socket family
code can use the value for something.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-23 22:31:14 +03:00
Markus Becker 3178555878 net: openthread: Allow DHCP configuration of OpenThread in Zephyr
Certain Thread implementations (notably ARMs) require a DHCPv6
implementation.
Allow the usage of the relevant OpenThread configuration parameters in
Zephyr.

Signed-off-by: Markus Becker <markus.becker@tridonic.com>
2019-07-22 13:23:05 +03:00
Tomasz Bursztyka b2e71a2fa2 net: Add a connection manager preliminary logic
It currently only listens to relevant events about network interface to
decide whether raising connected or disconnected event.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-12 12:33:19 +03:00
Michael Scott e7155622a2 net: lwm2m: add custom TLS credential load function pointer
Current implementation of LwM2M engine doesn't allow users a way
of overriding TLS credential load with custom function.  This
would be needed by an offloaded TLS stack where we don't want
to use standard Zephyr functions.

Let's add a load_credential function pointer to the LwM2M client
context which will be called when it's available.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17408

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-11 11:08:05 +03:00
Michael Scott b5231d0b93 net: lwm2m: firmware: add log_strdup to remove logging errors
When performing OTA using the LwM2M subsys, several logging errors
regarding log_strdup were noted.  Let's fix these.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:09:22 +03:00
Michael Scott 13086ccda8 net: lwm2m: dont select MBEDTLS or set MBEDTLS options in subsys
If a sample wants to use the Zephyr implementation of mbedtls, it
enables CONFIG_MBEDTLS and sets any needed Zephyr-specific mbedtls
options.

Currently, the LwM2M subsystem selects MBEDTLS automatically when
LWM2M_DTLS_SUPPORT is enabled.  Let's remove this and let the
LwM2M client sample enable mbedtls and it's options.

This mimics the behavior of several other network-related samples
and removes conflicts when selecting alternate implementations of
MBEDTLS.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17399

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:47 +03:00
Michael Scott 82e889a2e2 net: lwm2m: fix error message in load_tls_credential()
Copy/paste issue was showing the wrong error message when a TLS
credential failed to be added.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:08:30 +03:00
Michael Scott 88642ef2eb net: lwm2m: remove IP CONFIG checks in lwm2m_parse_peerinfo()
CONFIG_NET_IPV* checks are not needed in lwm2m_parse_peerinfo().
The functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Michael Scott 05cc5ae92c net: lwm2m: remove IP CONFIG checks in lwm2m_sprint_ip_addr()
CONFIG_NET_IPV* checks are not needed in lwm2m_sprint_ip_addr().  The
functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

NOTE: Also fixes an issue where a NULL is returned when the IP address
is unknown.  This usually ends up with a crash/abort in the logging
code.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401

Signed-off-by: Michael Scott <mike@foundries.io>
2019-07-09 21:07:58 +03:00
Jukka Rissanen 8f92dc4634 net: dns: Send net-mgmt event for DNS server add and del
If DNS server(s) are added or removed e.g., as part of DHCP
processing, send newly defined net-mgmt events so that
a user application may get this information.

Fixes #16924

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 17:04:55 +03:00
Robert Lubos c37faaa56d net: lwm2m: Ignore close return value
Explicitly ignore return value from `close` call.

Coverity-CID: 198870

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-07-08 21:40:15 +03:00
Jukka Rissanen 57101e56f4 net: llmnr_responder: Fix debug prints after receiving query
The hostname needs to have log_strdup() when printing it.
Also it is useful to print information if the sending fails.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-08 16:02:38 +03:00
Tomasz Bursztyka 11a8b42d8b net/llmnr: Fix LLMNR answer creation
- answer offset was 1 byte off.
- request offset, when copied into the answer, was off as well.

Fixes #16142

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-07-08 16:02:38 +03:00
Nicolas Pitre d19a5f9119 net: socket: mgmt: use uintptr_t for the nm_pid field
This may contain a pointer so make sure it is sufficiently wide
on 64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-05 10:06:23 -04:00
Nicolas Pitre 66045b5db0 net/socket: use the iterable section object constructor/iterator
The handcrafted allocation falls victim of misaligned structures due to
toolchain padding which crashes the socket test code on 64-bit targets.
Let's move it to the iterable section utility where those issues are
already taken care of.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 11:36:52 +03:00
Jukka Rissanen 2f95f4afe7 net: sockets: Initialize IP socket addresses in getsockname()
Make sure the IPv4 and IPv6 socket addresses are initialized before
copying them. This avoids uninitialized memory access.

Coverity-CID: 199436
Fixes #17202

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 15:26:59 +03:00
Jukka Rissanen eef7625660 net: socket: Add SO_TIMESTAMPING socket option
This can be used to activate the network packet statistics
collection. Note that we do not have resources to calculate
each network packet transit times but we collect average times
instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-03 09:42:45 +03:00
Jukka Rissanen 7c65db4e31 net: socket: mgmt: Add setsockopt() and getsockopt() support
Currently only setting and getting of Ethernet Qav options are
supported via this interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen 6f32f17cda net: socket: Add userspace support to getsockopt()
Allow userspace application to call getsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen ee849826e3 net: socket: Add userspace support to setsockopt()
Allow userspace application to call setsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Jukka Rissanen c0d6831bc0 net: sockets: mgmt: Add AF_NET_MGMT address family support
Allow application to listen network management events using
BSD socket API. Application needs to create the socket using
AF_NET_MGMT address family. At this point we only support
receiving network management events that the network subsystem
is sending.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 13:50:08 -07:00
Pieterjan Camerlynck b7d4b0057e net: lwm2m: fix automatic notification frequency
This fixes the issue where observations are automatically reported using
the minimum period instead of the maximum. This causes notifications to
be sent more frequently than configured when the resource does not
change.

Signed-off-by: Pieterjan Camerlynck <pieterjan.camerlynck@gmail.com>
2019-07-01 10:36:33 +03:00
Ravi kumar Veeramally 84b191edd2 net: sockets: Add timeout to socket connect call
Current socket connect call implementation always takes
K_FOREVER timeout value, which blocks TCP connections
in case failure. TCP connections waits until it receives
SYN ACK. If there is no SYC ACK means, connect call is
blocked forever.

Added a Kconfig option to define timeout value. Default
value is 3000 milliseconds. User can modify it.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-07-01 10:34:15 +03:00
Jukka Rissanen ef10937553 net: dns: Make dns_unpack_answer() to check non-compressed answers
Modify dns_unpack_answer() function to check if the answer is
compressed or not, and return correct values regardless.

Fixes #16594

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-01 09:44:29 +03:00
Justin Brzozoski ffe25df82a mqtt: Allow client to override keepalive
This change will allow an MQTT client to override the compile-time
keepalive if desired.  The change is structured such that the
compile-time default will still be setup by calling mqtt_client_init,
but can be changed by the application before calling mqtt_connect if
desired.

Signed-off-by: Justin Brzozoski <justin.brzozoski@signal-fire.com>
2019-06-28 09:54:16 -04:00
Anas Nashif 5b0aa794b2 cleanup: include/: move misc/reboot.h to power/reboot.h
move misc/reboot.h to power/reboot.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6ecadb03ab cleanup: include/: move misc/math_extras.h to sys/math_extras.h
move misc/math_extras.h to sys/math_extras.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8be9f5de03 cleanup: include/: move misc/fdtable.h to sys/fdtable.h
move misc/fdtable.h to sys/fdtable.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 969f8f1c68 cleanup: include/: move entropy.h to drivers/entropy.h
move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Jukka Rissanen 70aa383018 net: sntp: Ignore return value from close
Return value from close() can be ignored in sntp_close()
as it is not returning value to caller anyway.

Coverity-CID: 198863
Fixes #16584

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-27 23:52:51 +03:00
Jukka Rissanen 19806a2c1b net: getaddrinfo: Query both IPv4 and IPv6 if family is AF_UNSPEC
We must query both IPv4 and IPv6 addresses if the hints parameter
is NULL i.e., user does not supply hints or if family is set to
AF_UNSPEC.

Fixes #16453

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-20 14:45:43 +03:00
Håkon Øye Amundsen 05cd3420ac net: mqtt: add mqtt_readall_publish_payload()
This function uses mqtt_read_publish_payload_blocking to perform a
blocking read of the specified number of bytes.

When reading out a payload, the normal use case is to read the
entire payload. This function facilitates that use case.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-06-20 13:06:08 +03:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Jukka Rissanen 06b500b6bd net: sockets: can: Close the socket cleanly
If the socket is closed, then do CAN detach if that is needed.
This way the CAN interrupts are not received if there are no
CAN sockets listening the data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Jukka Rissanen 6621491014 net: sockets: can: Add dispatcher
We need to dispatch the received CAN frame if there are multiple
sockets interested in the same CAN-IDs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-18 17:58:00 +03:00
Loic Poulain 3189da5cdc net: mdns_resolver: Fix malformed MDNS response
The query->len does not take 'Terminator' into account, shift over
one byte to prevent overwriting it with next field (Type).

This fixes mdns_resolver sample.

Fixes: 87eb552dd2 (net/dns: Switch mdns responder to new net_pkt API)

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-12 13:59:27 +03:00
Loic Poulain 4f4adae271 net: lib: Fix missing dns subdir include
The dns directory was not included when building with
MDNS_RESONDER or LLMR_RESPONDER configs.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-12 13:59:27 +03:00
Jukka Rissanen c3bb0a6af9 net: socket: Add SO_PRIORITY support to setsockopt
Allow user to set the socket priority using setsockopt() call.
The priority value is used to order the networking queues so
that packets with a higher priority may be processed first.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-09 12:54:05 +03:00
Jukka Rissanen a348c8c61c net: llmnr: Check that UDP header can be accessed
It is possible that UDP header cannot be accessed so we need
to check that we do not do null pointer dereference.

Coverity-CID: 198866
Fixes #16581

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-06-09 01:42:13 +08:00
Paul Sokolovsky 0fb8a917e6 net: sockets: Make NET_SOCKETS_POSIX_NAMES depend on !POSIX_API
These options are mutually exclusive, or more specifically,
CONFIG_POSIX_API has wider scope and supersedes
CONFIG_NET_SOCKETS_POSIX_NAMES. Implementation-wise, the two
options should not be defined at the same time, as that may
lead to declaration conflicts.

Fixes: #16141

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-06-05 07:51:01 -04:00
Robert Lubos 87462df3ef net: sockets: Remove TI conditional from offloaded fcntl implementation
Offloaded `fcntl` implementation should be available for all offloaded
implementations, not specific for TI. `socket_offload.c` is already
conditionally compiled based on `CONFIG_NET_SOCKETS_OFFLOAD` option, so
there should not be conflicts for non-offloaded interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-30 18:41:31 -04:00
Michael Scott a46db55d0a net: lwm2m: fix log_strdup missing errors
Due to commit a211afb0 ("logging: Add option to detect missed
transient string duplication"), the logs for LwM2M subsystem
is now spamming missing log_strdup() calls.

Let's add log_strdup() where needed.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-30 11:26:43 +08:00
Paul Sokolovsky 8b3db460aa net: getaddrinfo: Parse numeric IPv4 addresses
If a valid numeric IP address is provided as argument, it should
be resolved without contacting DNS server.

Also, implement handling of AI_NUMERICHOST.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-29 17:46:56 +08:00
Louis Dupont a8fffca40f net: lwm2m: Remove IPSO objects maximum number of instances limitation.
Fixes #16156 by removing kconfig maximum number of instances.

Signed-off-by: Louis Dupont <dupont.louis@ireq.ca>
2019-05-25 17:57:56 -04:00
Michael Scott a923c2f1be net: openthread: fix off-by-one error in settings offset calculation
OpenThread uses CONFIG_OT_PLAT_FLASH_PAGES_COUNT to calculate the # of
pages at the end of flash to use for storing OpenThread settings.

This calculation has an off-by-one error which sets the offset for
the storage area as 1 page of flash too low.

For example, on nRF52840:
- default setting for CONFIG_OT_PLAT_FLASH_PAGES_COUNT is 4
- flash size is 1MB (0x100000)
- flash page size is 4096 (0x1000)
- expected offset is 0xfc000

Using the current logic we get an offset of: 0xfb000

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/16339

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-23 10:47:20 +03:00
Tomasz Gorochowik c0b30355fb net: sockets: implement getsockname function
From POSIX.1-2017:

The getsockname() function shall retrieve the locally-bound name of the
specified socket, store this address in the sockaddr structure pointed
to by the address argument, and store the length of this address in the
object pointed to by the address_len argument.

The address_len argument points to a socklen_t object which on input
specifies the length of the supplied sockaddr structure, and on output
specifies the length of the stored address. If the actual length of the
address is greater than the length of the supplied sockaddr structure,
the stored address shall be truncated.

If the socket has not been bound to a local name, the value stored in
the object pointed to by address is unspecified.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-05-17 22:49:32 +03:00
Paul Sokolovsky a2fa8e9c1c net: getaddrinfo: Implement initial handling of host == NULL
If host is NULL and ai_flags are AI_PASSIVE in a call to
getaddrinfo(), need to return "any" address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-16 16:11:10 +03:00
Jakob Olesen c8708d9bf3 misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.

Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-05-14 19:53:30 -05:00
Sebastian Bøe c2c8c849b6 cmake: Don't have users call zephyr_link_interface on mbedTLS
Libraries that use mbedTLS have been invoking
zephyr_link_interface(mbedTLS). It is not clear what the intent of
this code has been, but it is redundant with the mbedTLS build
scripts, so it can be safely removed.

In addition to being redundant, it causes problems as it introduces an
ordering dependency, with this code mbedTLS must be declared before
users of mbedTLS are declared. Since this code is redundant, this
ordering dependency is also unnecessary.

This code is believed to have been added early on by accident and
copied through cargo-cult programming since.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-11 08:35:26 -04:00
Jukka Rissanen e082d98911 net: sockets: can: Register handler for AF_CAN
Use the automatic registration of AF_CAN type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen b3cd478a5f net: sockets: packet: Register handler for AF_PACKET
Use the automatic registration of AF_PACKET type sockets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 61f4597d64 net: sockets: tls: Register handler for TLS sockets
Use the automatic registration of TLS socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Jukka Rissanen 89bf1578d9 net: sockets: Add a way to register a socket family handler
Allow automatic handling of registered socket families.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-10 22:43:27 +03:00
Paul Sokolovsky 22f1a29185 net: sntp: Add convenience API for one-shot SNTP query
sntp_simple() function queries the server (passed as "addr[:port]"
string). It wraps calls to a number of other functions, and may be
useful to write simple, concise apps needing the absolute time.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-10 13:44:32 +03:00
Paul Sokolovsky 426f3fa1ac net: socketutils: Add utils to manipulate network address strings
Two utils to manipulate addresses in format "addr[:port]". I.e.,
network address (domain name or numeric), optionally followed by
port number:

* net_addr_str_find_port(), to return pointer to port number
substring (or NULL if not present).
* net_getaddrinfo_addr_str(), which is effectively getaddrinfo()
wrapper taking a "addr[:port]" string as a parameter.

The header file is named socketutils.h to emphasize that these
utility functions are implemented on top of BSD Sockets API
(and other POSIX/ANSI C functions), and thus portable to other
POSIX systems (e.g., Linux), so can be used in apps testing
POSIX compatibility. More utility functions (beyond address
manipulation) can be added later.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-10 13:44:32 +03:00
Robert Lubos b8494d9a51 net: lib: mqtt: Enable blocking PUBLISH payload readout
It is convenient to have a blocking version of
`mqtt_read_publish_payload` function, for cases when it is called from
the event handler. Therefore, extend the 'mqtt_read_publish_payload'
argument list with information whether the call should block or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-07 22:08:30 -04:00
Jukka Rissanen 9a6bbbfb69 net: Check device driver API pointer
It is possible that the device driver API pointer is null.
For example if the device driver returns an error, the device
code will make the API pointer NULL so that the API would not
be used. This can cause errors in networking code where we
typically do not check the NULL value.

Fixes #15003

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-05-07 15:41:15 +03:00
Robert Lubos 7eb4a68876 net: openthread: Fix utilsFlashErasePage function
Zephyr implementation of OpenThreads utilsFlashErasePage platform
function did not disable flash protection before calling `flash_erase`
function. This resulted in an error instead of actual flash erase on
platforms that properly implement flash write protection.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-07 08:35:34 -04:00
Robert Lubos 57629724c2 net: openthread: Implement frame pending API
Implement OpenThreads frame pending bit management on top of the Zephyrs
radio driver API. This allows for proper Sleepy End Devices handling
from the parent side.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-05-06 10:58:04 -04:00
Luiz Augusto von Dentz c42707c2d3 Bluetooth: Use BT_GATT_SERVICE_DEFINE whenever possible
This makes use of BT_GATT_SERVICE_DEFINE to statically define services
for services that are not required to be dynamically registered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-02 08:29:23 +03:00
Håkon Øye Amundsen 66431d213d cmake: helper function for importing library
When importing a pre compiled imported library it is currently
required to perform three steps.
This commit introduces a helper function which allows the
user to import a library with a single function call.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2019-04-30 10:18:02 -04:00
Paul Sokolovsky f65727a193 net: sntp: Add sntp_query() function with fractional precision
Existing sntp_request() function has a coarse integer seconds
precision,  discarding fractional part as returned by SNTP.
Deprecate it, and instead introduce sntp_query() function which
returns both integer and fractional seconds as a newly introduced
structure sntp_tstamp.

Fixes: #15596

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-04-24 12:53:09 +03:00
Paul Sokolovsky e8e814c631 net: sntp: Handle case of request timeout
Previously, a case when poll() call timed out wasn't handled, and
recv() was called unconditionally. In the case of timeout, recv()
itself would hang indefinitely.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-04-24 12:50:12 +03:00
Jukka Rissanen 1897896e97 net: sockets: Make sure that getaddrinfo() cannot hang forever
If for some reason the DNS resolver callback is not called properly
then make sure that semaphore will not block forever.

Fixes #15197

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-04-11 18:01:08 -04:00
Michael Scott cb2bfcb9c0 net: lwm2m: fix periodic services handling
This fixes an issue where if timestamp == service_due_timestamp,
we don't call the periodic service.  Then the following call to
engine_next_service_timeout_ms() returns 0 because the service
is still due and lwm2m_engine_service() is called again.
This process repeats several times until the value of
k_uptime_get() changes and then the work is finally handled.

Previously, the resolution of k_uptime_get() was in ms.  A recent
change to this API defaults Zephyr so that the resolution is
set via CONFIG_SYS_CLOCK_TICKS_PER_SEC (default 100).

This means the value of k_uptime_get() only changes every 10ms.

Reported-by: Github User pieterjanc
Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
Michael Scott 42abfc6532 net: lwm2m: dont use system workqueue for services
"It's a Trap!" -- Admiral Ackbar

When moving to the BSD-socket APIs, the original thread running LwM2M
periodic services such as observes and lifetime updates, was replaced
with a re-occuring workqueue job.  To save the overhead of creating a
new thread, I used the system workqueue for these jobs.

This was a mistake.  If these jobs hit a semaphore or wait for some
reason, it cannot be prempted due to the priority of the system work
queue.

Let's instead add this service handling to the thread that we already
use for polling sockets.  This also removes a configuration issue where
the system workqueue stack size needed to be increased.  This can now
be adjusted via the LWM2M_ENGINE_STACK_SIZE knob.

Directly fixes semaphore usage in the socket-based DNS code.
This was introduced as a bugfix for non-responsive DNS server hanging
the Zephyr device forever.  However, this probably fixes randomly
seeming hangs on the device.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-04-10 13:54:23 -04:00
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
Andrew Boie ce6b80470d net: add missing syscall for gethostname()
We need all the socket APIs to work from user mode.
tests/net/socket/misc now runs in userspace.

Fixes: #15227

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie 7e3a34f84f mqtt: use sys_mutex instead of k_mutex
Allows the mqtt_client data structure to exist in user memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -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
Tedd Ho-Jeong An f5c4e369ea net: sockets: Update setsockopt to handle IPV6_V6ONLY
This patch adds a routine that handles IPV6_V6ONLY option in setsockopt
function.

Fixes #14657

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
2019-03-26 13:23:49 -04:00
Vincent Wan 3609e261bb net: sockets: move fcntl back to socket_offload.c
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.

Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05:00
Tomasz Bursztyka cf322c44db net: Switch usage of net_pkt_get_reserve to net_pkt_alloc
Some places were still using the old allocator. Using the new one does
not change any behavior. This will help to remove the useless data_len
attribute in net_pkt which legacy allocator was still setting.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 03bfc5dd0f net/context: Remove token parameter from net_context_send/sendto
And also to the relevant callbacks.

That parameter is not used anywhere so it is useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka a25f054cbd net/pkt: Remove _new suffix to net_pkt_read functions
Suffix is now useless, as these functions are now the only ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka f8a091104e net/pkt: Remove _new suffix to net_pkt_get_data_new function
Now that legacy - and unrelated - function named net_pkt_get_data has
been removed, we can rename net_pkt_get_data_new relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 172fe5a87b net/context: Remove _new suffix on net_context_send/sendto functions
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Paul Sokolovsky 4e097b4d54 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Paul Sokolovsky 5499f38e7a net: socket: Increment TCP context refcount on socket(), accept()
TCP context is effectively owned by both application and the stack:
stack may detect that peer closed/aborted connection, but it must
not dispose of the context behind the application back. Likewise,
when application "closes" context, it's not disposed of immediately,
there's yet closing handshake for stack to perform.

This effectively means that TCP contexts have refcount of 2 when
they're created. Without this change, following situation is
possible: peer opens connection, an app get a context (or socket)
via accept, peer sends data, closes connection. An app still holds
a reference to connection, but stack may dispose of context, and
even reuse it for a new connection. Then application holds a reference
to either free, or completely different context.

This situation was very clearly and 100% reproducible when making
Zephyr port of open62541 library, which works in async manner using
select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-18 10:49:25 -05:00
Paul Sokolovsky 193d6c60df net: sockets: Implement gai_strerror()
To save binary size, currently just returns textual name of error
code, e.g. EAI_FAIL -> "EAI_FAIL". Based on real usecases, can be
replaced with user-friendly message later. (Current usecase is to
allow/help to elaborate sockets API by proof-of-concept porting
existing socket apps).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-15 07:13:15 -05:00
Michael Scott 8c615e7ce3 net: lwm2m: handle delay_work error in lwm2m_engine_init()
Let's handle errors during periodic service work submit.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 579e586fa1 net: lwm2m: fix write_handler sizes for float32/64
Normally, this bug wasn't apparent as the value is type-casted
to a float32/64 type.  However, once we start persisting these
values they need the correct length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 910506cfc1 net: lwm2m: guard obj_field parameter of LWM2M_HAS_PERM
Let's avoid future compile issues with this macro when passing
in a type-casted value that isn't surrounded by parenthesis.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott fcde4c42cc net: lwm2m: raise stack sizes
Occasionally we see a stack crash in LwM2M.  This may have been
due to the swap from net_app APIs to socket-based APIs.

Let's raise the default stack by 1k.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott d615ab0dc3 net: lwm2m: change resend packet to an INF message
To avoid missing important messages, let's change the resend
packet message from a DBG to an INF.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 144ff91670 net: lwm2m: cleanup observes when closing context
When a context is closed to a server, we should clean up any
existing observes along with it.  Otherwise these will try to fire
afterward.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 35eb7818a7 net: lwm2m: remove unnecessary check in sm_do_registration()
We are already in sm_do_registration(), there's no need to check
!sm_is_registered().  Either we are performing a full registration
or a registration update.  In both cases, sm_send_registration()
is called.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott a5a83675d4 net: lwm2m: correct status change on send_reg error
If an error is received during registration update, we need to reset
the status so that a full registration is performed.  This was
incorrectly being set to ENGINE_REGISTRATION_SENT.

The correct status should be: ENGINE_DO_REGISTRATION

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Michael Scott 2ab50cb676 net: lwm2m: Follow POSIX send() API
send() returns -1 upon error and sets errno appropriately.  Let's
not bother saving the return code and instead share errno back
to the user.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-15 06:57:50 -05:00
Kumar Gala 0033448f10 net: lwm2m: Fix minor bug with setting flags
Looks like we are setting some bit flags so we should use '|' not '||'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 16:28:58 -05:00
Jukka Rissanen 5a9fa72ef2 net: socket: can: Convert between can_frame and zcan_frame
The socket-can code expects to have "struct can_frame" from
application when it calls send(). We then have to convert to
"struct zcan_frame" as that is what the driver expects.

Same thing when receiving data. We just convert to
"struct can_frame" and pass that to application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -05:00
Jukka Rissanen fc36d56aca drivers: can: socket: Use proper filter when setsockopt is called
Check that the received filter is can_filter type when setsockopt()
is called.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-13 05:58:30 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Ulf Magnusson 214ef00db3 kconfig: subsys: net: Remove redundant dependencies
subsys/net/lib/lwm2m/Kconfig.ipso is 'source'd within an 'if LWM2M', in
subsys/net/lib/lwm2m/Kconfig, so the 'depends on LWM2M' is redundant.

The 'depends on NET_IPV4' and 'depends on NET_L2_OPENTHREAD' are within
corresponding 'if's in the same file.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:49:59 -05:00
Anas Nashif 4fcbb6bdf2 Revert "net: sockets: recv_stream: Check that the underlying net_context active"
This reverts commit 8cb5d083cb53627964ed72fb9fa3fb7a5219739f.

This was breaking tests on master due to missing dependency that is
still being reviewed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-06 17:40:52 -05:00
Paul Sokolovsky 41864915c2 net: sockets: recv_stream: Check that the underlying net_context active
It may be closed by the stack behind our back (something which needs
to be fixed).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-06 15:56:57 -05:00
Vincent Wan 55b3f05932 include: net: Move fcntl implementation into socket_offload.h
This is done to conform with how the rest of the socket APIs are
implemented during socket offload. Otherwise link error would
result due to the symbol being redefined in lib/os/fdtable.c.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-05 11:37:10 -05:00
Paul Sokolovsky a3cffb8e63 net: sockets: Trace socket/accept/close operations for debug logging
This is required to debug almost any issue with sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-05 08:28:25 -05:00
Paul Sokolovsky 5a44011e3b net: sockets: Add dummy impl for SO_REUSEADDR and TCP_NODELAY sockopts
These options are oftentimes used when implementing servers, and
thus required to port existing socket apps. These options are also
safe to just ignore, e.g. SO_REUSEADDR has effect only for repeated
recreation of server socket (not an expected usecase for a Zephyr
app), while TCP_NODELAY is effectively the default for Zephyr, as we
don't implement TCP buffering (aka Nagle algorithm).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-03-01 09:52:15 +01:00
Michael Scott 0482b66f0b net: lwm2m: fix json NULL deref / code flow in read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13867
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/13882

Signed-off-by: Michael Scott <mike@foundries.io>
2019-03-01 09:44:46 +01:00
Jukka Rissanen a6614a32c1 net: sntp: Remove useless comparison
The LI bits checks is useless as the bitshifted value cannot be
larger than SNTP_LI_MAX (3).

Coverity-CID: 190924
Fixes #13888

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-28 08:47:10 -06:00
Michael Scott cc1b6b024b net: lwm2m: fix json formatter putchar check
Found via Coverity CID 191001: Control flow issues  (NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true:
"put_char(out, '}') < 0U".

Let's fix this check to be less than 1 instead as it should have
been originally.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-27 08:36:12 -06:00
Ravi kumar Veeramally f940cec0d0 net: coap: Fix coverity issue
To get u8_t value, just right shift the operands are enough.

Fixes #12298
Coverity-CID: 190635

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-27 10:36:39 +01:00
Robert Lubos 10e43e12ed net: sockets: tls: Add missing poll descriptor increment
Poll descriptor was not incremented in poll update function in case it
was reported as not ready. In result, poll could end up processing the
same poll descriptor for every fd requested to monitor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Robert Lubos 6175d1bd8e net: sockets: tls: Detect EOF in poll prepare
Rework detection of EOF on a socket, so that it can be detected in a
poll prepare that socket is in in a EOF state and poll can return
immediately.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-26 02:07:11 +01:00
Tomasz Bursztyka 87eb552dd2 net/dns: Switch mdns responder to new net_pkt API
Unfortunately, most of the dns pack/unpack code is not factorized, and
mdns responder rewrites its own functions to write dns hdr, query,
answer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 7bc61c1366 net/dns: Switch llmnr responder to new net_pkt API
Unfortunately, most of the dns pack/unpack code is not factorized, and
llmnr responder rewrites its own functions to write dns hdr, query,
answer.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 675a5056ed net/dns: Switch to new net_context API
So instead of building the net_pkt by itself, dns will pass its message
buffer to net_context_sendto_new(), which in turn will build the net_pkt
relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka f72b113876 net/dns: Move function declaration after macros and local variables
dns_write was in the middle of this, let's just move it to a more
relevant place so we logically have macros, then local variables then
functions.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Tomasz Bursztyka 46cefe9155 net/dns: Move common macros in the relevant header
Some of dns_pack.c macros are also used in resolve.c, so let's just put
the macros in dns_pack.h

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-26 01:50:59 +01:00
Michael Scott f68d62bbdb net: lwm2m: fix float exponent after fraction assign
Once the fraction value has been assigned a value, we can't move
the exponent any more.

Fixes erroneous values the binary32/64 formats.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-26 01:45:51 +01:00
Robert Lubos f1920fff46 net: sockets: tls: Block DTLS client in poll until handshake is complete
When DTLS client was added to `poll` before/during the handshake, it
could throw errors and in some circumstances (when polling thread was
cooperative and had higher or equal priority to the handshake thread)
could lead to a deadlock in the application.

Prevent that, by blocking on handshake semaphore instead of fifo. Poll
will start using fifo for data poll only after handshake is complete.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Robert Lubos 64ca76f327 net: sockets: tls: Use semaphore to notify that handshake is complete
Instead of simple bool value, use a semaphore to notify that TLS
handshake is complete. This way, we can monitor this value with k_poll.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Robert Lubos f8502a9993 net: lwm2m: Remove misused errno check
Errno value is only significant when `recvfrom` function indicated an
error (by returning -1). We should not depend on it's value if no error
is notified.

As the return value of `recvfrom` is already checked, misused errno
verification can simply be removed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-23 07:42:38 -05:00
Paul Sokolovsky 87b5eb9fce net: sockets: Implement getnameinfo()
This function is the opposite of getaddrinfo(), i.e. converts
struct sockaddr into a textual address. Normally (or more
specifically, based on the flags) it would perform reverse DNS
lookup, but current implementation implements only subset of
functionality, by converting to numeric textual address.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:34:57 -05:00
Paul Sokolovsky f7169ec216 net: sockets: Fix logging message
A debug message told "Set EOF flag on pkt %p", but actually printed
net_context instead of net_pkt.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-19 17:33:44 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Michael Scott 844c2ad716 net: lwm2m: fix NULL deref in plain_text_read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12300
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12296

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott f6b221699c net: lwm2m: fix out-of-bounds access in put_s8()
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing
the data as an array of u8_t.  In put_bool() we get a singleton
pointer from the evaluation of: "value != 0 ? 1 : 0" which is
passed to put_s8() which in turn passes it to oma_tlv_put().

To avoid misinterpretation, let's create a temporary s8_t variable
to pass into oma_tlv_put instead.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12312

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott 95f21d59b7 net: lwm2m: remove checks for long int > MAX_INT
Per Coverity report, the evaluation of long int v > MAX_INT is
always false and considered a CONSTANT_EXPRESS_RESULT issue.

Removed these checks from:
atof32()
lwm2m_write_attr_handler()

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12317
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12320

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Paul Sokolovsky 3b73511153 net: sockets: Add dummy shutdown() implementation.
shutdown() itself is described as just marking RX or TX path of a
socket as not available. For the first approximation, we implement
it just as a dummy function, to allow build existing POSIX
applications which use it.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-13 07:00:51 -06:00
Michael Scott 91ef79539a net: lwm2m: fix rendering of zero value float32/64
Zero is a special value in the binary32/64 format.  It has all zero
bits (sign=0, exponent=0 and fraction=0).

Handle this special case explicitly instead of trying to encode
in binary format which results in an incorrect value of 0.5.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 07:00:33 -06:00
Michael Scott cf47c89971 net: lwm2m: add support for IPSO Timer object
Initial implementation of IPSO Timer object #3340
Based on: http://www.openmobilealliance.org/tech/profiles/lwm2m/3340.xml

"This IPSO object is used to time events and actions, using patterns
common to industrial timers. A POST to the trigger resource or On/Off
input state change starts the timing operation, and the timer
remaining time shows zero when the operation is complete. The
patterns supported are One-Shot (mode 1), On-Time or Interval
(mode 2), Time delay on pick-up or TDPU (tmode 3), and Time Delay
on Drop-Out or TDDO (mode 4). Mode 0 disables the timer, so the output
follows the input with no delay. A counter is provided to count
occurrences of the timer output changing from 0 to 1. Writing a value
of zero resets the counter. The Digital Input State resource reports
the state of the timer output."

NOTE: Only One-Shot Mode (mode 1) is implemented in this patch.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Michael Scott d53a0855a1 net: lwm2m: fix float32/64 handling
During the initial work on LwM2M, the float32/64 code was
basically stubbed out.  Float32 sent only whole values and
float64 was completely broken.

Let's clean up the OMA TLV formatting code by moving the float
processing code into a separate file: lwm2m_util.c.

Then using public definitions for binary32 and binary64, let's
fix the processing code to correctly fill the float32_value_t
and float64_value_t types.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-12 21:19:49 -05:00
Tomasz Bursztyka 34fe5545c9 net/socket: Use the new net_pkt API to read TCP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/TCP
headers.

Also, when reading the actual data, let's use net_pkt_read_new()
relevantly instead of going through the buffer by ourselves.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 6331f052b7 net/socket: Use the new net_pkt API to read UDP payload
There is no need for appdata pointer: net_pkt's cursor is already at the
right position, i.e. the beginning of the payload right after all IP/UDP
headers.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Tomasz Bursztyka 024a7e0502 net/sockets: Adapt net_pkt_get_src_addr to new net_pkt API
This function is only used in sockets, thus making it a private function
of socket library and renaming it relevantly.

Note that sockets should be reviewed at some point to avoid using such
function: zsock_received_cb() already get the ip header and the protocol
header, so it could grab the src addr/port from there. It would be way
more optimized to do so, since net_pkt_get_src_addr is costly as it
parses all over again the ip/protocol headers.

utils unit test is updated and the test of the former
net_pkt_get_src_addr/net_pkt_get_dst_addr are removed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-12 20:24:02 -05:00
Paul Sokolovsky a46aadeff2 net: sockets: Properly handle EOF condition for poll()
If a socket is in EOF, it's readable (so client can read() it, get 0
in return, figure it's in EOF, and close it). Without this change, we
had peer-closed sockets leaked (ignore) by poll() and select().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-12 09:45:04 -05:00
Kumar Gala abeed4ab74 net: lib: Remove CONFIG_HTTP reference
CONFIG_HTTP isn't a Kconfig symbol so remove reference to it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-11 22:29:58 -05:00
Kumar Gala 22253fcf6d openthread: Convert FLASH_ERASE_BLOCK_SIZE to DT_
Use DT_FLASH_ERASE_BLOCK_SIZE prefixed defined instead of
FLASH_ERASE_BLOCK_SIZE as the non-DT version is deprecated.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 22:39:07 -06:00
Jukka Rissanen 7f784153c1 net: socket: Dispatch all AF_CAN handling to sockets_can.c
The code was unnecessarily checking protocol for AF_CAN.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Jukka Rissanen c1d5cc26c1 net: sockets: Remove extra "default n" setting from config
No need to say "default n" as that is the implicit default.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-08 16:01:49 +02:00
Tomasz Gorochowik df0d7652df net: mqtt: Add SOCKS5 proxy support
This commits adds a new MQTT transport. The purpose is to be able to
connect to a MQTT broker through a SOCKS5 proxy.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-08 14:20:44 +02:00
Tomasz Gorochowik ead249f2f9 net: Add initial SOCKS5 support
This adds some very basic SOCKS5 proxy client support.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-08 14:20:44 +02:00
Andrei Gansari fea80ca5c1 net: subsys: fixed comments CONFIG_NET*
Fixed stranded comments:
CONFIG_NET_TLS_DEBUG removed
CONFIG_NET_LLDP_MSG_TX_INTERVAL -> CONFIG_NET_LLDP_TX_INTERVAL

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-02-08 13:57:55 +02:00
Paul Sokolovsky 5bb2c7022e net: sockets: Add gethostname() call
Implemented via Zephyr's net_hostname_get(). As support for that call
is configurable and by default off, while many POSIX applications
assume that hostname is always available, we need a default value
in case CONFIG_NET_HOSTNAME_ENABLE is "n". Initial version of this
patch added that on the level of gethostname() call, but of was
suggested to move that down to net_hostname_get() instead.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-08 10:39:30 +02:00
Jukka Rissanen df7162331f net: socket: can: Add getsockopt() and setsockopt() support
It is possible to set the filter in user application and that
information is passed to the CANBUS device driver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen f610db9453 net: l2: Add CANBUS L2 layer
This is basically a dummy layer that just passes data through.
It is needed so that we can create CANBUS type network interface
to the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Jukka Rissanen 49cea0a199 net: socket: can: Add socket CAN support
This allows user to create a CAN socket and to read/write data
from it. From the user point of view, the BSD socket CAN support
works same way as in Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-07 18:08:27 +02:00
Ravi kumar Veeramally a9a2b3ea91 net: sockets: Add socket api to support AF_PACKET
This commit adds packet socket support to socket api.
This version supports basic packet socket features.
Protocol family is AF_PACKET, type of socket is
SOCK_RAW and proto type is ETH_P_ALL. The user will
receive every packet (with L2 header) on the wire.
For TX, the subsystem expects that the user has set
all the protocol headers (L2 and L3) properly.

Networking subsystem doesn't verify or alter the headers while
sending or receiving the packets. This version supports packet
socket over Etherent only. Also combination of other family
and protocols doesn't work (i.e. Application can not open
packet-socket and non packet-socket together).

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-07 14:43:30 +02:00
Michael Scott 6cb768cb24 net: lwm2m: fix connection handling in RD client
A few cases were missed where we weren't cleaning up the existing
connection correctly.  This was easily missed because we try and
clean up the connection everywhere.

Instead, let's clean up any existing connection prior to starting
a new one in the do_bootstrap_reg() and do_registration()
functions.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Michael Scott 6b990ba9bf net: lwm2m: boostrap support cleanup
- Fix enum naming throughout
- Correct next_instance logic
- Move to registration server if no bootstrap server is found
- Fixes to logging

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-06 18:52:31 -05:00
Robert Lubos 418b9236fa net: lib: mqtt: Get rid of _sock suffix
As the legacy library has been removed, we no longer need to
differentiate betwen MQTT implementations. Therefore align the library
folder name with other libraries and remove the `_sock` suffix.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-02-05 11:05:26 -05:00
Ravi kumar Veeramally 1e47f26d1c net: coap: Remove legacy CoAP implementation
As we are removing net_app and net_pkt based libraries and
applications, CoAP legacy based libraries and apps are moved
to socket based implementations. So removing legacy CoAP.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-02-04 16:49:59 -05:00
Jukka Rissanen 6b3428c7e4 net: Remove net_app references from the code
Some net_app names were not removed by net_app API removal
commit so remove them here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 19:05:56 -05:00
Tomasz Bursztyka 4b78a251d7 net/context: Make recv_cb providing the ip and protocol headers
If status is 0, both ip_hdr and proto_hdr will own a pointer to the
relevant IP and Protocol headers. In order to know which of ipv4/ipv6
and udp/tcp one will need to use respectively net_pkt_family(pkt) and
net_context_get_ip_proto(context).

Having access to those headers directly, many callbacks will not need
to parse the packet again no get the src/dst addresses or the src/dst
ports. This will be change after this commit.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Tomasz Bursztyka 083470a14a net/sockets: Use the new send/sendto from net_context
It's now up to net_context to build the net_pkt and send it.
This will become the default.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-02-01 14:34:38 +02:00
Jukka Rissanen d1162600e9 net: app: Remove net-app API files
The net-app API is removed. Users should use the BSD socket API
for application development.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-02-01 12:29:21 +02:00
Michael Scott a79087cad1 net: lwm2m: add socket-based DNS support
Previously, the net_app layer handled DNS support as a part of
network initialization.  With the move to BSD-socket APIs,
we need to add support for DNS to the LwM2M library.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d1cb39e7ce net: lwm2m: migrate LwM2M library to BSD-sockets API
This commit removes the net_app layer from the LwM2M library and
replaces it with BSD-sockets APIs.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d7f20f63d8 net: lwm2m: fix firmware status after bad download attempts
This commit resets the firmware status to IDLE after a bad
download attempt.  Previously, the firmware object would stay
in an odd state and any further attempts to download firmware
would return an error.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 0abe96e4cf net: lwm2m: replace periodic service thread with work queue
We can save some resources by removing the periodic service thread
and replacing it by queuing the services to the work queue.

Before (reel_board using BT + DTLS)
Memory region         Used Size  Region Size  %age Used
           FLASH:      289464 B         1 MB     27.61%
            SRAM:       75620 B       256 KB     28.85%
        IDT_LIST:         136 B         2 KB      6.64%

After
Memory region         Used Size  Region Size  %age Used
           FLASH:      289576 B         1 MB     27.62%
            SRAM:       74596 B       256 KB     28.46%
        IDT_LIST:         136 B         2 KB      6.64%

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 180a365d2f net: lwm2m: support for LwM2M bootstrap
Now that the security data can be loaded into and used from the
security / server objects, we can add support for LwM2M bootstrap.

This is a mode where initially a connection can be made to a server
which can update several LwM2M (including security and server
data) and then trigger a "bootstrap complete".  Once this happens
the client will start it's connection process over but now with
the new information.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 54c10c04e5 net: lwm2m: use security data for connections
In order to support bootstrap mode, we need to store server data
in the security / server objects.  Once the connection to the
bootstrap server is made, it will clear these objects and add
new server connection data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3ef993c88e net: lwm2m: update security obj with DTLS data
For bootstrap support, we need to store connection credentials
in the security object.  This way the client can start a connection
at index 0 and after bootstrapping, move to the next connection.

Let's add the needed fields and a config item to set the key length.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 181544beec net: lwm2m: add JSON formatter for WRITE operations
Update the parsing functions for JSON used by the JSON data
formatter and enable it in the LwM2M engine.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 26599e30d4 net: lwm2m: introduce input formatter private data
The JSON formatter is currently not enabled for incoming WRITE
operations.  To update the code in the formatter and not litter
the input context with extra data, let's allow formatters to
store their own user data.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott a433af6e05 net: lwm2m: save remote address during setup
net_app contexts save the remote address and we use this during
observe notifications and pending handling.  If we move to another
network layer such as sockets, then the remote address becomes
harder to reference.  Let's save it as a part of the client
context.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott 3bfb7debb3 net: lwm2m: move to flat buffers
As part of the migration from net_app APIs to socket APIs, let's
stop referencing the net_pkt fragments throughout the LwM2M library.

Establish a msg_data flat buffer inside lwm2m_message and use that
instead.

NOTE: As a part of this change we remove the COAP_NET_PKT setting.
The COAP library reverts to COAP_SOCK behavior.

This doesn't mean we use sockets in LwM2M (yet), it only means we
use the socket-compatible COAP library which parses flat buffers
instead of net_pkt fragments.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Michael Scott d003910460 net: lwm2m: create DTLS config layer for LwM2M
Currently, this will select the needed configs for LwM2M and net_pkt.
During the migration to socket APIs, the net_pkt selections will change
to socket-based selects.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-31 23:02:56 -05:00
Aurelien Jarno 4394601524 net: sntp: get rid of the callback function
The original SNTP client library was designed for the net-app API, for
which it makes sense to have a callback function, which is called
asynchronously when an answer is received.

For the socket based interface, the callback is called just before
sntp_request() returns. It gets the status and the epoch_time in
parameter, however the status is already returned by sntp_request(). It
therefore make sense to replace the callback function by a pointer to
epoch_time.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-31 10:14:12 +02:00
Robert Lubos e0a44c388c net: openthread: Bump OpenThread commit to f9d757a1
This version has cli_console backend fixed, hence no longer crashes on
`ot ping` command.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-30 21:01:53 -05:00
Michael Scott 8a115ca556 net: lwm2m: remove some unnecessary includes
net/lwm2m.h is included by object.h

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 44e9b5ed44 net: lwm2m: refactor lwm2m_engine_context into lwm2m_message
The relationship between lwm2m_engine_context and lwm2m_message
has always been a tenuous one.  Let's merge the 2 structures
into lwm2m_message and remove all of the extra stack variables.

This change increases SRAM usage slightly due to the
addition of the context structures to the multiple lwm2m_messages.
However, the way lwm2m_engine_context was being used off the stack
was probably creating hard to debug issues in the longterm.

Also, having all of the structures in 1 place makes sharing them
much easier later.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 86728d849b net: lwm2m: fix unsigned check for <0 in LwM2M device obj
Reported by Github user himanshujha199640 using coccinelle:
subsys/net/lib/lwm2m/lwm2m_obj_device.c:172:5-16:
WARNING: Unsigned expression compared with zero.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/11135

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Michael Scott 0ee0773abd net: lwm2m: remove unused CONFIG_NET_CONTEXT_NET_PKT_POOL config
CONFIG_NET_CONTEXT_NET_PKT_POOL is used by Zephyr's TCP stack as
a way of keeping the original packet data when compression and
other l2 specific actions make the data unusable for retries.

LwM2M uses UDP and this option was never used.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-01-30 10:35:54 +02:00
Ravi kumar Veeramally f51cebeea2 net: sntp: Rework SNTP client library to use sockets
As networking libraries and protocols are moving to socket
based implementation, reworked SNTP client library to use sockets.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
2019-01-29 12:25:01 -05:00
Jukka Rissanen 581261334c net: mqtt: Remove legacy MQTT library
The old and deprecated net-app based MQTT library is removed.
See the BSD socket based MQTT library for a replacement.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-29 07:11:23 -05:00
Paul Sokolovsky 3e6d7d382a net: sockets_select: Fix build without CONFIG_NET_SOCKETS_POSIX_NAMES
The implementation code itself should not rely on plain POSIX names
and use zsock_ and ZSOCK_ prefixed versions of symbols.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-29 09:19:54 +02: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 1cba0161ed net: websocket: Remove the websocket as HTTP APIs are removed
Remove the experimental websocket code as it uses HTTP APIs
which are being removed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-01-25 11:21:20 -05:00
Paul Sokolovsky 9c91094ff7 net: sockets: select: Get rid of timeval in favor of zsock_timeval
struct timeval is per POSIX defined in sys/time.h, but that also
allowed to pull sys/select.h (and indeed, it does with native_posix),
which then starts to conflict with out select implementation (if
NET_SOCKETS_POSIX_NAMES is defined, and many samples/tests have it).

So, for now follow the existing route of duplicating all definitions
needed by our code in namespaced manner. Things like struct timeval
usage will need to be revisited later, when we'll want socket
subsystem to work with POSIX subsystem, but that's a separate deep
matter.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Paul Sokolovsky 3a0a9944c0 net: sockets: Implement select() call.
It's implemented on top of poll() anyway, and the current
implementation of fd_set uses array of fd's underlyingly, which
leads to O(n) complexity for FD_SET() and friends.

The purpose of select() implementation is to allow to perform
proof-of-concept port of 3rd-party code to Zephyr quickly. For
efficiency, poll() should be used instead.

Fixes: #11333

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-24 17:14:43 +02:00
Robert Lubos 0b93c68f79 net: sockets: Add fcntl to socket offloading API
Offload fcntl calls through socket offloading API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-01-18 17:25:01 +02:00
Paul Sokolovsky c885cb533e net: buf: linearize: Get rid of useless memset()
net_buf_linearize() used to clear the contents of output buffer,
just to fill it with data as the next step. The only effect that
would have is if less data was written to the output buffer. But
it's not reliable for a caller to rely on net_buf_linearize() for
that, instead callers should take care to handle any conditions
like that themselves. For example, a caller which wants to process
the data as zero-terminated string, must reserve a byte for it
in the output buffer explicitly (and set it to zero).

The only in-tree user which relied on clearing output buffer was
wncm14a2a.c. But either had buffer sizes calculated very precisely
to always accommodate extra trailing zero byte (without providing
code comments about this), or arguably could suffer from buffer
overruns (at least if data received from a modem was invalid and
filled up all destination buffer, leaving no space for trailing
zero).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-12 15:24:29 -06:00
Martin Schwan c5de716af4 net: mqtt: Fix typo "seg_tag_list"
Fix a typo in the mqtt_sec_config struct where it was "seg_tag_list"
instead of "sec_tag_list".

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
2019-01-10 11:30:33 +02:00
Paul Sokolovsky 3329eb2c4e net: pkt: net_frag_linearize: Make consistent with net_buf_linearize
net_frag_linearize() is just a wrapper for net_buf_linearize(). As
the latter was refactored to never return error, and instead just
return actual copied length, update the former and its usages too.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Aurelien Jarno e98e6a8a87 net: openthread: remove one subcommand level in shell
Currently OpenThread commands have to be prefixed in the shell by "ot
cmd", for example "ot cmd state". With the new shell, it is possible to
remove one subcommand level and change it to "ot state".

At the same time validate the number of arguments using
SHELL_CMD_ARG_REGISTER and improve the help message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Aurelien Jarno ac3ff65a91 net: openthread: improve shell output
Following the introduction of the new shell, the OpenThread shell
wrapper is not well integrated. It outputs the answer to a command using
printk(), which is not necessarily using the same device than the shell
if "zephyr,console" does not match "zephyr,shell-uart".

OpenThread calls the otConsoleOutputCallback() function to output the
answer to the shell. It can provide a callback argument, but defined
when OpenThread is initialized, not when the command is submitted.
Workaround that by taking a copy of the shell argument in a static
variable and use it for the call to shell_fprintf(). It is not perfect
if two or more shells issue concurrent commands, but is already an
improvement compared to printk().

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-07 11:19:24 +01:00
Aurelien Jarno d3b6c5a755 net: coap: return -EPERM for a resource without requested method
When walking through the coap resources in coap_handle_request, return
-EPERM if a resource exists but does not have the request method. This
allows the caller to catch the error and return a 4.05 message.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-01-02 13:04:46 +01:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Martin Turon 6410a16adb openthread: Update openthread version to latest upstream/master.
Update zephyr integration of openthread to latest api as of 2018-12-17:

2a75d30684

Both echo_server and echo_client compile and are operational.

Signed-off-by: Martin Turon <mturon@google.com>
2018-12-20 12:24:51 +01:00
Robert Lubos e8620e2cca ext: mbedtls: Unify mbedTLS Kconfig prefixes
Currently there is a mixed approach in prefixes from mbedTLS
configuration (MBEDTLS_ and TLS_). The latter was used in generic config
file and could bring up confusion that it can only be used with TLS
subsystem. Hence unify the approach to MBEDTLS_ prefix to avoid such
confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-17 11:27:02 +01:00
Tomasz Bursztyka e97a543e9b net/pkt: Remove parameters to "reserve" some headroom
Such parameter is not used anymore, it was defaulted to 0 previously.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-12-14 14:16:37 +01:00
Paul Sokolovsky 8a65f68a48 net: sockets_tls: Typo fix in comment
s/DLTS/DTLS.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 13b38ed686 lib: fdtable: Change ioctl vmethod signature to take va_list
As extend fdtable usage to more cases, there regularly arises a need
to forward ioctl/fcntl arguments to another ioctl vmethod, which is
complicated because it defined as taking variadic arguments. The only
portable solution is to convert variadic arguments to va_list at the
first point of entry from client code, and then pass va_list around.

To facilitate calling ioctl with variadic arguments from system code,
z_fdtable_call_ioctl() helper function is added.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 94007da116 net: sockets: Rework fcntl() dispatching to the underlying fd object
fcntl operations are implemented using ioctl vmethod.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Robert Lubos ee0b61fff8 net: sockets: Rework poll to support ioctl helper commands
This commit reworks socket poll implementation to support multiple
socket implementations.

To achieve that, two ioctl poll helper requests were added:
ZFD_IOCTL_POLL_PREPARE and ZFD_IOCTL_POLL_UPDATE. The poll
implementation calls ioctl with these requests for each socket
requested in the fds table.

The first request is responsible for preparing k_poll_event objects
for specific socket. It can request to skip waiting in k_poll by
returning EALREADY through errno.

The latter request is responsible for processing outcome of k_poll for
each socket. It can request to retry the k_poll by returning EAGAIN
through errno.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos 31ab8d061d net: sockets: tls: Implement vtable for TLS sockets
Implement extended socket vtable for TLS sockets, therefore allowing to
integrate the implementation with socket subsystem.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Robert Lubos df8693af64 net: sockets: Extend socket vtable
This commit extends socket vtable, allowing to redirect socket calls to
alternate implementations (e.g. TLS sockets).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02: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
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01: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
Jukka Rissanen 88d3a0a88f net: config: Enable syslog to network in init
Start to send syslog messages to net after we have a proper
IP address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Robert Lubos b5f9771252 net: mqtt: Fix NULL pointer dereference in logs
MQTT packet_length_encode function accepts NULL buf argument, therefore
it cannot be dereferenced without a check.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00
Robert Lubos a26db60b2f net: mqtt: Add missing mutex_unlock
mqtt_connect was not releasing mutex after successfull connection.
Reworked the code to have a single exit path with mutex unlock.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-11-28 13:09:46 -08:00