To avoid extra logic in code that creates net_buf fragment lists, make
it possible to pass a NULL pointer as the head net_buf when there are
no previous buffers. Before this change the code would look like this:
if (head) {
net_buf_frag_add(head, buf);
} else {
head = net_buf_ref(buf);
}
After the patch the code can simply do:
head = net_buf_frag_add(head, buf);
This will then do the right thing regardless if head is NULL or
non-NULL.
Change-Id: I300394242e2e243ed3839b25629ec816dd98c148
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Extend the net_buf_frag_del() API to be usable for deleting the head
of a fragment chain. This is useful when parsing a stream-based
protocol encoded into a fragment chain, making code such as the
following possible:
...parse data from 'head' buffer...
/* If current buffer is empty, move to the next one */
if (!head->len) {
head = net_buf_frag_del(NULL, head);
}
Change-Id: I65794bd7fab4e6dadfd2d6b2fa367f9424fd1bde
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Without this line break, when CONFIG_NET_BUF_DEBUG is enabled, the
output may get confusing.
Change-Id: Ic467511f1dbbd283710f51ef14f94e0269c7c0ea
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
The small typo in the debug printed variable prevents compiling when
using debug printing in the netbuf code.
Change-Id: I6cafa82e7f5629e9021d7ad1a2130f2945b4f661
Signed-off-by: Jaakko Hannikainen <jaakko.hannikainen@intel.com>
Add helper to add 32-bit big endian data to net_buf and
net_buf_simple.
Change-Id: Ib6359558abcbed824365928327277ad69aa51e99
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This just renames the existing net_buf helper APIs to corresponding
net_buf_simple APIs and then defines the old net_buf API names as
macros mapping to the new net_buf_simple helpers.
Change-Id: I3c2b35683c0fde66f5f697be2c34c01172af8e31
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
User can add fragments to the network packet if the data cannot
be placed in one buffer.
Change-Id: I060ef533cc4fdda0f38405fb7dc72015f5cac7fc
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This is similar to the other net_buf_*_u8() helpers that already
exist.
Change-Id: I63fc963877c1946964e675067dd98f748be7cbbc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Add helpers for big-endian 16-bit values, similar to the ones that
already exist for little-endian values.
Change-Id: I63bf4dd7df802669ea6657cd95d6da48e6176487
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This API allows initializing the buffer with a given headroom. This
prepares the way for eventually removing the 'reserve_head' parameter
from the net_buf_get APIs, but can already now be useful in some
scenarios where the headroom is desired to be different than some
higher level API sets it to be.
Change-Id: Iffbe5761fdf3d2ad8cb4b8437b1074cf42ea9c6c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This is the only safe way, especially when doing the call from a task.
Change-Id: Ic50b73e04c4b831ac481dd56596f9d36cf0e2ccc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Freeing the fragment list by recursively calling net_buf_unref() is
elegant but dangerous. Since we have fairly small stack sizes it'd be
possible to overflow the stack if the user creates a very long list of
fragments (empirical tests showed that some 21 fragments is enough to
kill a 2k stack). Instead, use a while-loop for freeing up the
fragments, thereby guaranteeing a fixed upper bound for net_buf_unref()
stack usage.
Change-Id: Ibfe794fa717d1cddc84365c7b7b9cff4024edbf6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Introduce support buffer fragment chains that are linked together.
This is done with the help of a flag while the buffer is inside a FIFO
(indicating that the next fragment follows it in the same FIFO) and
with the help of a "next" pointer while the buffer is outside of a
FIFO.
In order to do proper "marshaling" a new net_buf_put() API needs to be
always used when inserting a buffer into a FIFO. Respectively, the
net_buf_get() and net_buf_get_timeout() functions are extended to
support getting buffers from arbitrary FIFOs and reassemble the
fragment chain based on the flags that the received buffers contain.
The insertion of a fragment chain using net_buf_put() into a FIFO is
done atomically with the help of irq_lock/unlock since FIFOs support
multiple writers, however since there's ever only a single reader per
FIFO similar locking is not necessary there.
Change-Id: I0ec579f63ea8d063f50e3f1f4c2e80ec399622d7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
With this API it's possible for the caller to force specific behavior
when it comes to waiting (or not waiting) on the FIFO.
Change-Id: Ib66e2f767c26c82abf1ba3b80bd15aec2383542e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The function gets 32bit-wide data from net buffer and converts the
value from little endian to host order.
Change-Id: I2d2454951b3ac39686a25454678ce92d8a1a0f3d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
The function gets 32bits wide data, converts host order to little
endian and then puts the data on protocol stack to be send.
Change-Id: I29e4040b302a16b551a0922133c327ff694fec5d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
A helper for the (fairly common) task of decoding individual 8-bit
values.
Change-Id: Id7e97df152232d5dd9861cf1e107877f1b8febaa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
There are many situations when encoding data when we need to insert
single bytes to the buffer. With this helper the encoding code stays a
bit more readable.
Change-Id: Ibc0ce43af5ae25a1baa0f1adbc5816ae7c04e3bb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Changes the nanokernel FIFO API so that the timeout parameter must be
specified when invoking nano_isr_fifo_get(), nano_fiber_fifo_get(),
nano_task_fifo_get() and nano_fifo_get().
This obsoletes the following APIs:
nano_fiber_fifo_get_wait()
nano_fiber_fifo_get_wait_timeout()
nano_task_fifo_get_wait()
nano_task_fifo_get_wait_timeout()
nano_fifo_get_wait()
nano_fifo_get_wait_timeout()
Change-Id: Icbd2909292f1ced0bad8a70a075478536a141ef2
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
There could be cases where the destroy callback needs more
fine-grained control of step ordering than "1. destroy, 2. put back to
free FIFO". One case could be when the the pool needs to be protected
by a microkernel mutex or semaphore. In such a case the putting back
to the FIFO may need to happen before a custom action in the destroy
callback.
Making the destroy callback responsible for returning to the free FIFO
gives full flexibility regarding the order of the cleanup actions.
Change-Id: Ib9532d1dd70e0a2042af54ebd3e40a853dd42d33
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit fixes this compile error if network buffer debugging
is activated.
CC net/buf.o
net/buf.c: In function 'net_buf_unref':
net/buf.c:40:31: error: expected expression before 'if'
#define NET_BUF_ASSERT(cond) (if (!(cond)) { \
^
net/buf.c:81:2: note: in expansion of macro 'NET_BUF_ASSERT'
NET_BUF_ASSERT(buf->ref > 0);
^
Change-Id: Id4248806a5df571663e47eab581164a16df0cd1b
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
We need to have a generic buffer API in order to efficiently transfer
data between different subsystems. The first such case will be the
Networking and Bluetooth subsystems where 6LoWPAN data will be passed
back and forth.
The needed API needs to provide enough flexibility for different
buffer sizes as well as custom protocol-specific context data.
The implementation offered in this patch follows the general design of
the existing Networking and Bluetooth buffer implementations by using
a backing array of buffer which is fed into a "free buffers" FIFO for
management. The main difference is that the API allows specifying
variable sized buffers for each created pool, as well as a minimum
amount of "user data" that's allocated as part of each buffer.
There's also an optional destroy callback that's e.g. useful for HCI
flow control in Bluetooth (for notifying the controller of available
buffers).
Change-Id: I00b7007135a0ff35219f38f48658f31728fbb7ca
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>