Commit graph

1260 commits

Author SHA1 Message Date
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Andrew Boie 04bba6772b net: sockets: add API to fetch an fd's ctx object
Zephyr running on MPU devices have a different memory model than
process-oriented OSes like Linux and require a method to set
kernel object permissions on a file descriptor's underlying
context object. Add this, and a test to show that it is working.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie fed960b94a net: tag net socket objects
Used for permission validation when accessing the associated file
descriptors from user mode.

There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Tomasz Bursztyka 549cfff6c9 device: Rephrase data parameter documentation
This parameter points to the driver instance private data, and not to
its configuration data, which one is set via cfg_info parameter.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-29 10:42:07 +02:00
Christopher Friedt 09f957c47a net: socket: syscall for socketpair(2)
Working:

* non-blocking reads / writes
* blocking reads / writes
* send(2) / recv(2) / sendto(2) / recvfrom(2) / sendmsg(2)
* select(2)
* poll(2)

Fixes #24366

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-10 17:46:43 +02:00
Alexander Wachter 464f135ce6 canbus: Convert canbus driver and subsys to new timeout API
Convert all canbus related API/samples/tests/subsys
to the new timeout API with k_timeout_t.

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2020-05-06 10:19:13 +02:00
Lukasz Maciejonczyk ae68354428 net: l2: openthread: Add function for getting openthread default instance
The new function simplifies use of OpenThread API in Zephyr.

Signed-off-by: Lukasz Maciejonczyk <Lukasz.Maciejonczyk@nordicsemi.no>
2020-05-05 16:30:20 +03:00
Jukka Rissanen 65a1bebe85 net: Replace NET_WAIT_FOREVER by SYS_FOREVER_MS
As we now have SYS_FOREVER_MS, use that instead of network
specific NET_WAIT_FOREVER.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-05 16:29:23 +03:00
Jukka Rissanen 8160385b57 net: pkt: Fix removal of empty buffers in net_pkt_pull()
If we have removed first net_buf, then we must not restore the
original cursor as that will point to wrong head net_buf.
Add also unit test to check that the packets are removed
properly.
Clarify the documentation that we are removing data from
beginning of the function, also document that the cursor
is reset after this call.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-05 13:39:45 +03:00
Peter Bigot 842c42d7f0 documentation: fix wrong recommendation for millisecond timeouts
API documentation for parameters that accept a duration specified in
milliseconds is updated to replace references to K_NO_WAIT with 0, and
K_FOREVER with SYS_FOREVER_MS.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-30 18:26:26 +02:00
Bilal Wasim 220b664617 net: tftp: Adding support for TFTP Client.
Adding RFC1350 compliant support for TFTP Client in Zephyr. The
current implementation is minimal and only supports the ability
to get a file from the server.

Things for the future include support for putting files to
server and adding support for RFC2347.

Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
2020-04-30 14:19:46 +03:00
Kiril Petrov 7305e7b4a2 net: coap: add coap_pendings_clear and coap_replies_clear
Clears whole stack of pendins and replies.

Signed-off-by: Kiril Petrov <retfie@gmail.com>
2020-04-28 20:46:35 +03:00
Robert Lubos df152ab59f net: coap: Add initial tx time to coap_pending structure
So far, coap_pending structure kept track only of the timeout interval
between two consecutive retransmissions. Calculations inside
`coap_pending_next_to_expire` relied only on this value. This approach
gives incorrect results though, in case multiple messages are pending
for retransmission.

For instance, assuming initial retransmission timeout is set to 2
seconds. If some message had been retransmitted already, its timeout
would be increased to 4 seconds. Any new message added to the pending
list would have a retransmission timeout set to 2 seconds, and will be
returned as a first message to expire, no matter how long the initial
message was already on the list.

To resolve this, add a `t0` field to the coap_pending structure. This
field is initialized to the initial transmission time, and is increased
on each retransmission by the retransmission timeout.
`coap_pending_next_to_expire` uses this value to calculate absolute
time, when the next retransmission should take place, and based on this
information returns correctly first pending message to expire.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-28 09:50:45 +03:00
Anas Nashif 45a1d8aca9 kernel: rename initializers to be internal
Rename internal macros to use Z_ prefix instead of _K..

Those macros were missed when we did the global renaming activities.

Fixes #24645

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-24 22:27:08 +02:00
Arvin Farahmand 6d5f3debaa net: http_client: Fix payload issue on HTTP upload
Bug fix and improved `payload` handling in `http_client_req`.

Changes to `http_client_req` behaviour:

If the user provides `payload_len` it is used to generate the
`Content-Length` header. This is done even if `payload_cb` is used to
provide the actual data. If no `payload_len` is specified then no
`Content-Length` is generated.

If `payload_cb` is provided it is called to send the payload data.
Otherwise `payload` is used as the payload buffer and sent. If
`payload_len` is not zero, it is used as the size of `payload`.
Otherwise `payload` is assumed to be a string and `strlen` is used to
determine its size. This is to maintain current behaviour and not break
existing samples.

Fixes #24431

Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
2020-04-21 00:05:04 +03:00
Jukka Rissanen 3d6f05ed44 net: pkt: Move TCP 1st sent flag out of union
The TCP flag was conflicting with PPP flag in the same union.
This prevented TCP from working properly with PPP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-17 12:44:49 +03:00
Robert Lubos 04ddf6f957 net: ieee802154_radio: Extend frame pending bit handling configuration
Thread and Zigbee differ in how do they handle Frame Pending Bit field
in their frames. Introduce a new enum, `ieee802154_fpb_mode`, which
allows to configure the radio driver in an appropriate mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-17 09:17:38 +03:00
Robert Lubos 00d1f6e772 net: pkt: Add ACK Frame Pending Bit information for ieee802154
OpenThread expects information, whether Frame Pending Bit was set in the
ACK response sent by the radio driver. Carry this information in the
net_pkt structure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-17 09:17:38 +03:00
Robert Lubos 073ec8d4aa net: mqtt: Refactor because of timeout overhaul
Align MQTT with timeout API changes.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-09 21:58:42 +03:00
Kyle Sun a9b926414c net: lwm2m: Publicize firmware block context
This change is to allow access to the firmware block context in order to
give the firmware update callback implementation an indication of when
to reset the flash context. Additionally, it allows for a validity check
between the total expected size downloaded and the actual size
downloaded. A simple implementation can check if the block context's
current downloaded blocks is equal to the expected block size in order
to determine if the flash context needs to be reset. This approach
seemed the simplest, and knowing the firmware block context can have
other purposes. This has been tested by accessing the block context
during the update in the block received callback and confirming that the
callback had information regarding the current downloaded bytes.

Fixes #16122

Signed-off-by: Kyle Sun <yaomon18@yahoo.com>
2020-04-09 16:48:45 +02:00
Jukka Rissanen b9cbf8a5ed net: pkt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 406bdb1fc6 net: promisc: Refactor because of timeout overhaul
Convert minimal parts to support k_timeout_t values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 38dd9bc299 net: mgmt: Refactor because of timeout overhaul
Convert to use k_timeout_t

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen e56fa75ade net: context: Refactor because of timeout overhaul
The net_context API will change, the s32_t timeout parameter
will be changed to k_timeout_t. All the Zephyr users of this API will
be changed in subsequent commits. This is internal Zephyr API only,
so the API is not deprecated etc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen ab5aba4f8f net: ppp: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 5cf75fe091 net: websocket: Refactor because of timeout overhaul
Mention in websocket API documentation that the timeout value
is in milliseconds. Check timeout values properly using K_TIMEOUT_EQ()
macro.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen 1b04d44247 net: http: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.
Clarify the documentation of the timeout parameter that it is
in milliseconds.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen a49741ff66 net: dns: Refactor because of timeout overhaul
Use k_timeout_t internally, no change to user API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Jukka Rissanen e4224651bf net: Add NET_WAIT_FOREVER symbol to be used as timeout in network APIs
If a network API expects a millisecond timeout, then NET_WAIT_FOREVER
symbol can be used to indicate that the timeout should last forever.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +03:00
Marek Porwisz bca112f073 net: ieee802154: Allow event callback configuration
Implement a way to pass handler for various events from
radio driver

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-04-07 14:24:10 +03:00
Johan Hedberg 54ca1c118b net: buf: Convert net_buf to use k_timeout_t where appropriate
This patch updates the net_buf API to use k_timeout_t in essentially
all places where "s32_t timeout" was previously used. For the most
part the conversion is trivial, except for the places where
intermediate decrements of remaining timeout is needed. For this the
z_timeout_end_calc() API is used.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-04-03 23:17:53 +03:00
Robert Lubos 1fb418df4c net: ieee802154_radio: Allow to specify TX mode
Even though radio driver can report in its capabilities that it does
support CSMA CA, there's no way in the driver to select how the frame
should be transmitted (with CSMA or without). As layers above radio
driver (Thread, Zigbee) can expect that both TX modes are available, we
need to extend the API to allow either of these modes.

This commits extends the API `tx` function with an extra parameter,
`ieee802154_tx_mode`, which informs the driver how the packet should be
transmitted. Currently, the following modes are specified:
* direct (regular tx, no cca, just how it worked so far),
* CCA before transmission,
* CSMA CA before transmission,
* delayed TX,
* delayed TX with CCA

Assume that radios that reported CSMA CA capability transmit in CSMA CA
mode by default, all others will support direct mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-03 14:07:41 +03:00
Tomasz Bursztyka 00926e3899 net/iface: Add PM suspend state statistics
Counting how many times it went suspended, for how long on the last one
and on overage.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-04-02 11:07:45 +03:00
Robert Lubos 111313581d net: ieee802154_radio: Enable ed_scan unconditionally
Energy scan procedure, while introduced specifically for OpenThread in
Zephyr, may also be used by other upper layers (like Zigbee).
Therefore, disable conditional inclusion of the `ed_scan` API.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-04-01 15:41:31 +03:00
Tomasz Bursztyka 4322c66e4b net: Expose a way to know if the network interface is suspended or not
And use it in the shell to display such information then.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 80917ec16f net: Add preliminaly support for suspending/resuming a net interface
Such state needs to be set _from_ the PM API functions and not the other
way round. So if a network device driver does not support such API, it
will not be able to set the core net_if on PM state, obviously.

Currently, these functions only set/unset NET_IF_SUSPENDED flag.

More logic will be added later, to decide whether the net_if can be
actually set to suspend mode or not and also to take care of all timers
related to the interface.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Jukka Rissanen dee07c9e0a net: if: Add function to check any pending TX packets
This function can be used for example by network power management
to check if the network interface can be suspended or not.
If there are network packets in transmit queue, then the network
interface cannot be suspended yet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-27 14:48:30 +02:00
Tomasz Bursztyka 4ae72db135 net: Enable PM settings on network devices
By changing the various *NET_DEVICE* macros. It is up to the device
drivers to either set a proper PM function or, if not supported or PM
disabled, to use device_pm_control_nop relevantly.

All existing macro calls are updated. Since no PM support was added so
far, device_pm_control_nop is used as the default everywhere.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-03-27 14:48:30 +02:00
Robert Lubos ca5489d99f net: ieee802154: Add config to enable PAN coordinator mode
Add config to the radio API to enable/disable PAN coordinator mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-26 17:42:40 +02:00
Robert Lubos 5f67e4d9df net: ieee802154: Add config to enable promiscous mode
Add config to the radio API to enable/disable promiscuous mode.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-26 17:42:40 +02:00
Jukka Rissanen 78234833a7 net: pkt: Add flag for telling if this is 1st TCP packet
TCP code needs to know whether the pkt is sent the first time
or is it a resent one. This information is used when deciding
if the pkt ref count needs to be increased or not. The packet
does not need to increase ref count when sent first time, as
the ref count is already 1 when the pkt is created. But for the
2nd time the packet is sent, we will need to increase the ref
count in order to avoid buffer leak.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-17 13:13:58 +02:00
Andrew Boie 760644041c net: purge NET_STACK and other stack APIs
The current design of the network-specific stack dumping APIs
is fundamentally unsafe. You cannot properly dump stack data
without information which is only available in the thread object.

In addition, this infrastructure is unnecessary. There is already
a core shell command which dumps stack information for all
active threads.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Marcin Niestroj accef325a2 net: mqtt: add MQTT_UTF8_LITERAL() helper macro
This macro allows to easily initialize utf8 strings (struct mqtt_utf8)
from C literals, as it automatically calculates string length.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-03-13 10:06:18 +02:00
PK Chan 9f9e00a62d net: mqtt: Added event for MQTT ping response.
There are scenarios where there is a NAT firewall in between MQTT
client and server. In such case, the NAT TCP timeout may be shorter
than MQTT keepalive timeout and TCP timeout. The the MQTT ping
request message is dropped by the NAT firewall, so that it cannot be
received by the server, resulting in void MQTT ping response message.
There is no TCP FIN or RST at all. The application looks hang-up
until TCP timeout happens on the client side, which may take too
long.

Therefore, the event MQTT_EVT_PINGRESP is added to inform the
application that the route between client and server is still valid.

Signed-off-by: PK Chan <pak.kee.chan@nordicsemi.no>
2020-03-12 11:07:14 +02:00
Marek Porwisz 5c57f382de net: ieee802154: Extend radio api to support energy scan feature
Add the Energy Scan capability to the possible capabilities list.
Create new energy scan callback function type to make its usage
more readable.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-03-10 14:59:10 +02:00
Robert Lubos d2e7a7d0c7 net: lwm2m: Notify when it's safe to turn RX off
According to LWM2M specification, when Queue Mode is used, the LWM2M
client should keep the reciever on for specified time after sending A
CoAP message. This commit adds a new LWM2M event,
`LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF`, to facilitate the process by
notifying the application when it's safe to turn the receiver off.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-03-10 14:57:29 +02:00
Göran Weinholt 091f630014 net: ppp: ipcp: negotiate DNS servers and optionally use them
We now negotiate DNS servers in the IPCP configuration. This has been
observed to speed up the connection setup. The received DNS servers
are used by the DNS resolver library, but we leave it optional since
the static server list might be preferable.

Increase MAX_IPCP_OPTIONS to 4 so that we can nack all RFC 1877
options.

Signed-off-by: Göran Weinholt <goran.weinholt@endian.se>
2020-03-10 14:09:10 +02:00
Robert Lubos bea1093e62 net: sockets: Remove socket offloading interface
Instead of using a custom offloading interface, users can use
`NET_SOCKET_REGISTER` macro to register custom socket API provider. This
solution removes a limitation, that only one offloaded interface can be
registered and that it cannot be used together with native IP stack.

The only exception remainig are DNS releated operations -
`getaddrinfo`/`freeaddrinfo`, which, when offloaded, have to be
registered specifically.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2020-01-31 11:36:02 -05:00
Kim Bøndergaard dea0511659 net: mqtt: struct mqtt_sec_config: Declare hostname with const
The hostname member of struct mqtt_sec_config is used as optval
argument to ztls_sesockopt_ctx().
optval is declared as const void* so no need to limit hostname
to not allow const variables

Signed-off-by: Kim Bøndergaard <kibo@prevas.dk>
2020-01-30 14:19:55 -05:00
Peter Bigot 0a81465554 treewide: use full path to can.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00