Commit graph

57 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
Jukka Rissanen 8cd1dcc69c net: buf: Remove timeout variable from debug print
The timeout value cannot be printed anymore after k_timeout_t
changes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-04-09 16:07:03 +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
Joakim Andersson 662ee8eacf net: buf: Switch from net buf assert to system assert
Remove net bufs own assertion mechanism and use the system assert
instead. This changes the assertion messaged printed from printing
expression to printing the line and file name. This provides more
context as the same expression could be asserted upon multiple times and
would then not provide enough clarity in the message.

This removes the option to enable only net buf assertions.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-13 13:59:55 +01:00
Oleg Zhurakivskyy fe7d6e2eae net: buf: Add an assert in net_buf_alloc_len()
Add an assert in net_buf_alloc_len() for undersized alloc.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Oleg Zhurakivskyy 25d719c33a net: buf: Use __ASSERT() in NET_BUF_ASSERT()
NET_BUF_ASSERT() tranlates into nothing in presence
of CONFIG_ASSERT=y, which is misleading.

Use __ASSERT() in NET_BUF_ASSERT().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-01-08 14:10:21 +02:00
Joakim Andersson 8d2b9e6fef net: buf: Add push functions for supported bit-variants
Add push functions for bit-widths supported by add and pull functions.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-02 19:05:27 +01:00
Luiz Augusto von Dentz 8724f4a2ee net: buf: Add support for 64 bit data type
This enables pulling and pushing values in 64 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz e0a55796b2 net: buf: Add support for 48 bit data type
This enables pulling and pushing values in 48 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz 4c06a9f577 net: buf: Add support for 24 bit data type
This enables pulling and pushing values in 24 bit format.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Luiz Augusto von Dentz 53784479b3 net: buf: Add net_buf_simple_init_with_data
This adds net_bug_simple_init_with_data which can be used to initialize
a net_buf_simple pointer with an external data pointer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-10 09:55:30 +02:00
Martí Bolívar 6a4b069711 net: optimize net_buf_simple routines
Use sys_put_xyz() helpers instead of memcpy() whenever possible. This
brings in straight-line inline code for pushes and adds of known,
small sizes.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-10-25 10:37:40 +03:00
Trond Einar Snekvik 3d201b45f9 net: buf: Add net_buf_simple_clone
Provides a way to clone a net_buf_simple without altering the state of
the original buffer. The primary usage scenario is for manipulating a
previously allocated PDU inside a buffer without altering the length and
offset of the buffer.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2019-10-04 20:56:25 +03: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
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
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
Johan Hedberg 80dd9be4ca net: buf: Add net_buf_pull_mem() API
This is the same as net_buf_pull(), except that instead of returning
the new buf->data it returns the old buf->data. This was recently
discussed in github issue #12562.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +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
Paul Sokolovsky 71e2e31a76 net: buf: linearize: Never return -ENOMEM, just do what user asked to
Don't try to find "errors" in the values of dst_len and len params
passed to net_buf_linearize(). Instead, do what entails with the
common sense from the values passed in, specifically:

1. Never read more than dst_len (or it would lead to buffer
overflow).
2. It's absolutely ok to read than specified by "len" param, that's
why this function returns number of bytes read in the first place.

The motivation for this change is that it's not useful with its
current behavior. For example, a number of Ethernet drivers linearize
a packet to send, but each does it with its own duplicated adhoc
routine, because net_buf_linearize() would just return error for the
natural use of:

net_buf_linearize(buf, sizeof(buf), pkt->frags, 0, sizeof(buf));

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-01-08 11:06:56 +02:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Jukka Rissanen 9051068630 net: buf: Fix debug level setting
Some of the net_buf related tests failed if they enabled
CONFIG_NET_BUF_LOG setting.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-23 10:36:01 +03:00
Jukka Rissanen be092a607a net: buf: Remove remaining SYS_LOG usage
Remove the last SYS_LOG reference from buf.c as SYS_LOG is
being deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-22 11:11:35 +03:00
Jukka Rissanen 46bc51d8c1 net: buf: Convert to new logging system
This commit replaces syslog with new logging subsystem in buf.c

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-04 14:13:57 +03:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Luiz Augusto von Dentz 9f79862300 net: buf: Use net_buf_add_mem in net_buf_append_bytes
This ensures the memory copies are properly logged when debug is
enabled.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2018-09-24 12:51:11 +03:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

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

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Johan Hedberg b088a09235 net: buf: Use size_t instead of u16_t for lengths in public API
Even though the net_buf implementation may (and does currently)
internally use u16_t for lengths, keep the public facing API
consistent by using size_t.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Johan Hedberg c90549c474 net: buf: Use void * instead of u8_t * for arbitrary data
This makes the net_buf_append_bytes() API consistent with all other
net_buf APIs that take a pointer to arbitrary data.

Fixes #9283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-09-11 14:55:54 +03:00
Michael Scott db577f00b1 net: buf: add linearize, append_bytes and skip APIs to net_buf
This change moves the logic for linearize and append_bytes from
the net_pkt sources into the net_buf sources where it can be
made available to layers which to not depend on net_pkt.  It also,
adds a new net_buf_skip() function which can be used to iterated
through a list of net_buf (freeing the buffers as it goes).

For the append_bytes function to be generic in nature, a net_buf
allocator callback was created.  Callers of append_bytes pass in
the callback which determines where the resulting net_buf is
allocated from.

Also, the dst buffer in linearize is now cleared prior to copy
(this was an addition from the code moved from net_pkt).

In order to preserve existing callers, the original functions are
left in the net_pkt layer, but now merely act as wrappers.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-08-06 10:43:46 +03:00
Tomasz Bursztyka 47e45c52a1 net: buf: Support allocation of a net_buf pointing to external buffer
Difference being that the data is not, then, allocated from the pool.
Only the net_buf is.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-02-13 16:46:32 +02:00
Johan Hedberg 5008ec7a06 net: buf: Introduce variable data length allocators
Introduce two new "standard" data allocators to net_buf. There are now
three in total:

NET_BUF_POOL_FIXED_DEFINE: This is the closes to the old
implementation, i.e. fixed size chunks.  It's also what the old
NET_BUF_POOL_DEFINE macro maps to.

NET_BUF_POOL_HEAP_DEFINE: uses the OS heap

NET_BUF_POOL_VAR_DEFINE: defines a variable sized allocator using
k_mem_pool (this is all that there was in my first draft of this
feature)

Currently the variable length allocators (HEAP & VAR) support
reference counted data payloads, i.e. cheap cloning. The FIXED
allocator does not currentlty support this to allow for the simplest
possible implementation, but the support can be added later if
desired.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg dd09cbc1c4 net: buf: Redesigned API with split data and meta-data
Redesign of the net_buf_simple and net_buf structs, where the data
payload portion is split to a separately allocated chunk of memory. In
practice this means that buf->__buf becomes a pointer from having just
been a marker (empty array) for where the payload begins right after
the meta-data.

Fixes #3283

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-02-10 09:20:42 +02:00
Johan Hedberg 018198cedc net: buf: Add slist helpers
Now that net_buf has "native" support for sys_slist_t in the form of
the sys_snode_t member, there's a danger people will forget to clear
out buf->frags when getting buffers from a list directly with
sys_slist_get(). This is analogous to the reason why we have
net_buf_get/put APIs instead of using k_fifo_get/put.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 14:20:40 +02:00
Johan Hedberg f801c1ca8e net: buf: Add net_buf_id() API
Add a net_buf_id() API which translates a buffer into a zero-based
index, based on its placement in the buffer pool. This can be useful
if you want to associate an external array of meta-data contexts with
the buffers of a pool.

The added value of this API is slightly limited at the moment, since
the net_buf API allows custom user-data sizes for each pool (i.e. the
user data can be used instead of a separately allocated meta-data
array). However, there's some refactoring coming soon which will unify
all net_buf structs to have the same fixed (and typically small)
amount of user data. In such cases it may be desirable to have
external user data in order not to inflate all buffers in the system
because of a single pool needing the extra memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-01 12:08:27 +02:00
Johan Hedberg 9703927f84 net: buf: Move net_buf_pool objects to dedicated linker area
Moving the net_buf_pool objects to a dedicated area lets us access
them by array offset into this area instead of directly by pointer.
This helps reduce the size of net_buf objects by 4 bytes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-16 17:05:06 +03:00
Kumar Gala a509441210 net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:30:38 -05:00
Luiz Augusto von Dentz 1885edf424 net: buf: Add net_buf_reset
This adds net_buf_reset which can be used to reset the state of a buffer.

Change-Id: I4b7c89dfd1a23a2ec8dfa3c99d5b02b9bcbceef3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Luiz Augusto von Dentz 9c0ea2b90b net: buf: Print pool name if available
In case CONFIG_NET_BUF_POOL_USAGE is defined use print pool->name
instead of the pointer.

Change-Id: I0be5fd8283a887145e61bdad02f721265453ce20
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-13 15:21:42 +03:00
Luiz Augusto von Dentz 1f4f8f65cb net: buf: Add CONFIG_NET_BUF_WARN_ALLOC_INTERVAL
CONFIG_NET_BUF_WARN_ALLOC_INTERVAL can be used to configure the interval
used to print allocation warnings.

Change-Id: I914f2e0d43b3f00c201e49ff42a45fa950b2df94
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 13:33:55 +03:00
Luiz Augusto von Dentz 22acec357e net: buf: Reduce verbosity of net_buf_get
Don't assume NULL returns are always errors.

Change-Id: I28d7a0fa6c848e338635010b1fdc9fc3e8440b27
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 12:35:51 +03:00
Luiz Augusto von Dentz 7cdb750539 net: buf: Generate periodic warnings for allocation that takes too long
This might indicate buffer leaks or deadlock is happening.

Change-Id: If91a65ccfe1be9497b210de21e80b533b6739367
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-07 12:35:51 +03:00
Jukka Rissanen 7218d0d64b net: buf: Add more accounting info to net_buf pool
Adding this information to the pool:
* number of available (free) buffers in pool
* total size of the pool in bytes

This can be used when debugging net_buf pool allocations.

Change-Id: I4212fcddb1affdf53e0827c88473d3380e2a4929
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-03-09 20:33:42 +02:00
Jukka Rissanen 75c48fcbf2 net: buf: net_buf_frag_del() had insufficient debugging
In order to see who is freeing the fragment, add function
and line information to net_buf_frag_del() when net_buf
debugging is activated.

Change-Id: I732f579fab2390cb16804cb35b83f46e65fca342
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2017-02-22 17:28:26 +02:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Tomasz Bursztyka e3cca46a1b net: buf: Let's make use of func/line parameters when available
It clutters a bit the code with ifdefs but it's quite useful when
debugging.

Change-Id: I4f6899d052921b8ef8a7ec2f6e7df927a1bca2f1
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 0a1617365f net: buf: Change NET_BUF_DEBUG to NET_BUF_LOG and add a level option
It will be thus possible to enable only the error logging, or the other
sys_log levels.

Change-Id: I0c0ed789f7cfbb4811320e8f8249151288274873
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Tomasz Bursztyka 90ac0b5c20 net: buf: Fix a debug message missing a parameter
Change-Id: I25a199ba074fa9affaf0a249b6af842a3a477ed7
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-02 10:03:17 +01:00
Johan Hedberg db8a5d9b80 net: buf: Add net_buf_add_mem() API
A very common pattern in code goes something like the following:

	memcpy(net_buf_add(buf, len), data, len);

To avoid having to create this kind of complex constructions every
time, this patch adds a new API which simplifies the call:

	net_buf_add_mem(buf, data, len);

Change-Id: Ic1aeae4baf88b2295d139f672d5d265db2ddbe7b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 16:27:08 +00:00
Anas Nashif a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00
Tomasz Bursztyka f991b82209 net: buf: Use buf->pool instead of now removed buf->free
Tiny debug message fix.

Change-Id: I464ff28d55b946a2e9ba4a0f9d88fbedd7ccef57
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-12-16 19:14:56 +01:00