net: nbuf: Add timeout to net_buf getters
This commit changes the net_buf getter functions in nbuf.h by adding a timeout parameter. These function prototypes are changed to accept a timeout parameter. net_nbuf_get_rx() net_nbuf_get_tx() net_nbuf_get_data() net_nbuf_get_reserve_rx() net_nbuf_get_reserve_tx() net_nbuf_get_reserve_data() net_nbuf_copy() net_nbuf_copy_all() net_nbuf_push() net_nbuf_append() net_nbuf_write() net_nbuf_insert() Following convinience functions have not been changed net_nbuf_append_u8 net_nbuf_append_be16 net_nbuf_append_be32 net_nbuf_insert_u8 net_nbuf_insert_be16 net_nbuf_insert_be32 net_nbuf_write_u8 net_nbuf_write_be16 net_nbuf_write_be32 so they call the base function using K_FOREVER. Use the base function if you want to have a timeout when net_buf is allocated. Change-Id: I20bb602ffb73069e5a02668fce60575141586c0f Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
8c6e76fb37
commit
bd3908b2a9
60 changed files with 564 additions and 419 deletions
|
@ -95,7 +95,7 @@ static struct net_buf *udp_recv(const char *name,
|
|||
NET_INFO("%s received %u bytes", name,
|
||||
net_nbuf_appdatalen(buf));
|
||||
|
||||
reply_buf = net_nbuf_get_tx(context);
|
||||
reply_buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
|
||||
NET_ASSERT(reply_buf);
|
||||
|
||||
|
@ -113,7 +113,7 @@ static struct net_buf *udp_recv(const char *name,
|
|||
net_buf_pull(tmp, header_len);
|
||||
|
||||
while (tmp) {
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
|
||||
memcpy(net_buf_add(frag, tmp->len), tmp->data, tmp->len);
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ static void telnet_end_client_connection(void)
|
|||
|
||||
static int telnet_setup_out_buf(struct net_context *client)
|
||||
{
|
||||
out_buf = net_nbuf_get_tx(client);
|
||||
out_buf = net_nbuf_get_tx(client, K_FOREVER);
|
||||
if (!out_buf) {
|
||||
/* Cannot happen atm, nbuf waits indefinitely */
|
||||
return -ENOBUFS;
|
||||
|
@ -234,7 +234,7 @@ static inline bool telnet_send(void)
|
|||
struct line_buf *lb = telnet_rb_get_line_out();
|
||||
|
||||
if (lb) {
|
||||
net_nbuf_append(out_buf, lb->len, lb->buf);
|
||||
net_nbuf_append(out_buf, lb->len, lb->buf, K_FOREVER);
|
||||
|
||||
/* We reinitialize the line buffer */
|
||||
lb->len = 0;
|
||||
|
@ -258,7 +258,7 @@ static int telnet_console_out_nothing(int c)
|
|||
|
||||
static inline void telnet_command_send_reply(uint8_t *msg, uint16_t len)
|
||||
{
|
||||
net_nbuf_append(out_buf, len, msg);
|
||||
net_nbuf_append(out_buf, len, msg, K_FOREVER);
|
||||
|
||||
net_context_send(out_buf, telnet_sent_cb,
|
||||
K_NO_WAIT, NULL, NULL);
|
||||
|
|
|
@ -551,7 +551,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
|||
lengthfr = frm_len;
|
||||
|
||||
/* Get the frame from the buffer */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
SYS_LOG_ERR("Could not allocate rx buffer");
|
||||
goto done;
|
||||
|
@ -565,7 +565,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
|||
size_t spi_frame_len;
|
||||
|
||||
/* Reserve a data frag to receive the frame */
|
||||
pkt_buf = net_nbuf_get_reserve_data(0);
|
||||
pkt_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!pkt_buf) {
|
||||
SYS_LOG_ERR("Could not allocate data buffer");
|
||||
net_buf_unref(buf);
|
||||
|
|
|
@ -145,7 +145,7 @@ static void eth_rx(struct device *iface)
|
|||
return;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
/* We failed to get a receive buffer. We don't add
|
||||
* any further logging here because the allocator
|
||||
|
@ -188,7 +188,7 @@ static void eth_rx(struct device *iface)
|
|||
struct net_buf *pkt_buf;
|
||||
size_t frag_len;
|
||||
|
||||
pkt_buf = net_nbuf_get_reserve_data(0);
|
||||
pkt_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!pkt_buf) {
|
||||
irq_unlock(imask);
|
||||
SYS_LOG_ERR("Failed to get fragment buf\n");
|
||||
|
|
|
@ -162,7 +162,7 @@ static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
|||
rx_nbuf_list->tail = 0;
|
||||
|
||||
for (int i = 0; i < rx_desc_list->len; i++) {
|
||||
rx_buf = net_nbuf_get_reserve_data(0);
|
||||
rx_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (rx_buf == NULL) {
|
||||
free_rx_bufs(rx_nbuf_list);
|
||||
SYS_LOG_ERR("Failed to reserve data net buffers");
|
||||
|
@ -470,7 +470,7 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
rx_frame = net_nbuf_get_reserve_rx(0);
|
||||
rx_frame = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
|
||||
/* Process a frame */
|
||||
prev_frag = rx_frame;
|
||||
|
@ -509,7 +509,7 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
|||
DCACHE_INVALIDATE(frag_data, frag_len);
|
||||
|
||||
/* Get a new data net buffer from the buffer pool */
|
||||
new_frag = net_nbuf_get_reserve_data(0);
|
||||
new_frag = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (new_frag == NULL) {
|
||||
queue->err_rx_frames_dropped++;
|
||||
net_buf_unref(rx_frame);
|
||||
|
|
|
@ -594,7 +594,7 @@ static void cc2520_rx(int arg)
|
|||
goto flush;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
SYS_LOG_ERR("No buf available");
|
||||
goto flush;
|
||||
|
@ -604,9 +604,9 @@ static void cc2520_rx(int arg)
|
|||
/**
|
||||
* Reserve 1 byte for length
|
||||
*/
|
||||
pkt_buf = net_nbuf_get_reserve_data(1);
|
||||
pkt_buf = net_nbuf_get_reserve_data(1, K_NO_WAIT);
|
||||
#else
|
||||
pkt_buf = net_nbuf_get_reserve_data(0);
|
||||
pkt_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
#endif
|
||||
if (!pkt_buf) {
|
||||
SYS_LOG_ERR("No pkt_buf available");
|
||||
|
|
|
@ -524,7 +524,7 @@ static inline void mcr20a_rx(struct mcr20a_context *mcr20a)
|
|||
pkt_len = read_reg_rx_frm_len(&mcr20a->spi);
|
||||
pkt_len -= MCR20A_FCS_LENGTH;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
SYS_LOG_ERR("No buf available");
|
||||
goto out;
|
||||
|
@ -535,9 +535,9 @@ static inline void mcr20a_rx(struct mcr20a_context *mcr20a)
|
|||
/**
|
||||
* Reserve 1 byte for length
|
||||
*/
|
||||
pkt_buf = net_nbuf_get_reserve_data(1);
|
||||
pkt_buf = net_nbuf_get_reserve_data(1, K_NO_WAIT);
|
||||
#else
|
||||
pkt_buf = net_nbuf_get_reserve_data(0);
|
||||
pkt_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
#endif
|
||||
if (!pkt_buf) {
|
||||
SYS_LOG_ERR("No pkt_buf available");
|
||||
|
|
|
@ -54,13 +54,13 @@ static uint8_t *upipe_rx(uint8_t *buf, size_t *off)
|
|||
upipe->rx_buf[upipe->rx_off++] = *buf;
|
||||
|
||||
if (upipe->rx_len == upipe->rx_off) {
|
||||
nbuf = net_nbuf_get_reserve_rx(0);
|
||||
nbuf = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!nbuf) {
|
||||
SYS_LOG_DBG("No buf available");
|
||||
goto flush;
|
||||
}
|
||||
|
||||
pkt_buf = net_nbuf_get_reserve_data(0);
|
||||
pkt_buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!pkt_buf) {
|
||||
SYS_LOG_DBG("No fragment available");
|
||||
goto out;
|
||||
|
|
|
@ -267,12 +267,12 @@ static inline int slip_input_byte(struct slip_context *slip,
|
|||
}
|
||||
|
||||
if (!slip->rx) {
|
||||
slip->rx = net_nbuf_get_reserve_rx(0);
|
||||
slip->rx = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!slip->rx) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
slip->last = net_nbuf_get_reserve_data(0);
|
||||
slip->last = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!slip->last) {
|
||||
net_nbuf_unref(slip->rx);
|
||||
slip->rx = NULL;
|
||||
|
@ -287,7 +287,7 @@ static inline int slip_input_byte(struct slip_context *slip,
|
|||
/* We need to allocate a new fragment */
|
||||
struct net_buf *frag;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!frag) {
|
||||
SYS_LOG_ERR("[%p] cannot allocate data fragment",
|
||||
slip);
|
||||
|
|
|
@ -311,34 +311,40 @@ static inline void net_nbuf_set_src_ipv6_addr(struct net_buf *buf)
|
|||
*/
|
||||
|
||||
struct net_buf *net_nbuf_get_rx_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_rx(context) \
|
||||
net_nbuf_get_rx_debug(context, __func__, __LINE__)
|
||||
#define net_nbuf_get_rx(context, timeout) \
|
||||
net_nbuf_get_rx_debug(context, timeout, __func__, __LINE__)
|
||||
|
||||
struct net_buf *net_nbuf_get_tx_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_tx(context) \
|
||||
net_nbuf_get_tx_debug(context, __func__, __LINE__)
|
||||
#define net_nbuf_get_tx(context, timeout) \
|
||||
net_nbuf_get_tx_debug(context, timeout, __func__, __LINE__)
|
||||
|
||||
struct net_buf *net_nbuf_get_data_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_data(context) \
|
||||
net_nbuf_get_data_debug(context, __func__, __LINE__)
|
||||
#define net_nbuf_get_data(context, timeout) \
|
||||
net_nbuf_get_data_debug(context, timeout, __func__, __LINE__)
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_rx_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_reserve_rx(res) \
|
||||
net_nbuf_get_reserve_rx_debug(res, __func__, __LINE__)
|
||||
#define net_nbuf_get_reserve_rx(res, timeout) \
|
||||
net_nbuf_get_reserve_rx_debug(res, timeout, __func__, __LINE__)
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_tx_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_reserve_tx(res) \
|
||||
net_nbuf_get_reserve_tx_debug(res, __func__, __LINE__)
|
||||
#define net_nbuf_get_reserve_tx(res, timeout) \
|
||||
net_nbuf_get_reserve_tx_debug(res, timeout, __func__, __LINE__)
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_data_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line);
|
||||
#define net_nbuf_get_reserve_data(res) \
|
||||
net_nbuf_get_reserve_data_debug(res, __func__, __LINE__)
|
||||
#define net_nbuf_get_reserve_data(res, timeout) \
|
||||
net_nbuf_get_reserve_data_debug(res, timeout, __func__, __LINE__)
|
||||
|
||||
void net_nbuf_unref_debug(struct net_buf *buf, const char *caller, int line);
|
||||
#define net_nbuf_unref(buf) net_nbuf_unref_debug(buf, __func__, __LINE__)
|
||||
|
@ -369,10 +375,15 @@ void net_nbuf_print_frags(struct net_buf *buf);
|
|||
*
|
||||
* @param context Network context that will be related to
|
||||
* this buffer.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_rx(struct net_context *context);
|
||||
struct net_buf *net_nbuf_get_rx(struct net_context *context,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get buffer from the TX buffers pool.
|
||||
|
@ -382,10 +393,15 @@ struct net_buf *net_nbuf_get_rx(struct net_context *context);
|
|||
*
|
||||
* @param context Network context that will be related to
|
||||
* this buffer.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_tx(struct net_context *context);
|
||||
struct net_buf *net_nbuf_get_tx(struct net_context *context,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get buffer from the DATA buffers pool.
|
||||
|
@ -395,10 +411,15 @@ struct net_buf *net_nbuf_get_tx(struct net_context *context);
|
|||
*
|
||||
* @param context Network context that will be related to
|
||||
* this buffer.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_data(struct net_context *context);
|
||||
struct net_buf *net_nbuf_get_data(struct net_context *context,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get RX buffer from pool but also reserve headroom for
|
||||
|
@ -408,10 +429,15 @@ struct net_buf *net_nbuf_get_data(struct net_context *context);
|
|||
* but is mainly used by network fragmentation code.
|
||||
*
|
||||
* @param reserve_head How many bytes to reserve for headroom.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head);
|
||||
struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get TX buffer from pool but also reserve headroom for
|
||||
|
@ -421,10 +447,15 @@ struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head);
|
|||
* but is mainly used by network fragmentation code.
|
||||
*
|
||||
* @param reserve_head How many bytes to reserve for headroom.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head);
|
||||
struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get DATA buffer from pool but also reserve headroom for
|
||||
|
@ -434,10 +465,15 @@ struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head);
|
|||
* but is mainly used by network fragmentation code.
|
||||
*
|
||||
* @param reserve_head How many bytes to reserve for headroom.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_get_reserve_data(uint16_t reserve_head);
|
||||
struct net_buf *net_nbuf_get_reserve_data(uint16_t reserve_head,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Place buffer back into the available buffers pool.
|
||||
|
@ -477,11 +513,15 @@ struct net_buf *net_nbuf_ref(struct net_buf *buf);
|
|||
* @param reserve Amount of extra data (this is not link layer header) in the
|
||||
* first data fragment that is returned. The function will copy the original
|
||||
* buffer right after the reserved bytes in the first destination fragment.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return New fragment list if successful, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount,
|
||||
size_t reserve);
|
||||
size_t reserve, int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Copy a buffer with fragments while reserving some extra space
|
||||
|
@ -492,13 +532,18 @@ struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount,
|
|||
* @param reserve Amount of extra data (this is not link layer header) in the
|
||||
* first data fragment that is returned. The function will copy the original
|
||||
* buffer right after the reserved bytes in the first destination fragment.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return New fragment list if successful, NULL otherwise.
|
||||
*/
|
||||
static inline struct net_buf *net_nbuf_copy_all(struct net_buf *buf,
|
||||
size_t reserve)
|
||||
size_t reserve,
|
||||
int32_t timeout)
|
||||
{
|
||||
return net_nbuf_copy(buf, net_buf_frags_len(buf), reserve);
|
||||
return net_nbuf_copy(buf, net_buf_frags_len(buf), reserve, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -554,11 +599,15 @@ bool net_nbuf_is_compact(struct net_buf *buf);
|
|||
* no parent, then set this parameter NULL.
|
||||
* @param buf Network buffer
|
||||
* @param amount Amount of data that is needed in front of the fragment list.
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Pointer to the start of the fragment list if ok, NULL otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_push(struct net_buf *parent, struct net_buf *buf,
|
||||
size_t amount);
|
||||
size_t amount, int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Remove given amount of data from the beginning of fragment list.
|
||||
|
@ -583,12 +632,17 @@ struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount);
|
|||
* @param buf Network buffer fragment list.
|
||||
* @param len Total length of input data
|
||||
* @param data Data to be added
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return True if all the data is placed at end of fragment list,
|
||||
* False otherwise (In-case of false buf might contain input
|
||||
* data in the process of placing into fragments).
|
||||
*/
|
||||
bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data);
|
||||
bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Append uint8_t data to last fragment in fragment list
|
||||
|
@ -606,7 +660,7 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data);
|
|||
*/
|
||||
static inline bool net_nbuf_append_u8(struct net_buf *buf, uint8_t data)
|
||||
{
|
||||
return net_nbuf_append(buf, 1, &data);
|
||||
return net_nbuf_append(buf, 1, &data, K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -627,7 +681,8 @@ static inline bool net_nbuf_append_be16(struct net_buf *buf, uint16_t data)
|
|||
{
|
||||
uint16_t value = sys_cpu_to_be16(data);
|
||||
|
||||
return net_nbuf_append(buf, sizeof(uint16_t), (uint8_t *)&value);
|
||||
return net_nbuf_append(buf, sizeof(uint16_t), (uint8_t *)&value,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -648,7 +703,8 @@ static inline bool net_nbuf_append_be32(struct net_buf *buf, uint32_t data)
|
|||
{
|
||||
uint32_t value = sys_cpu_to_be32(data);
|
||||
|
||||
return net_nbuf_append(buf, sizeof(uint32_t), (uint8_t *)&value);
|
||||
return net_nbuf_append(buf, sizeof(uint32_t), (uint8_t *)&value,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -770,23 +826,23 @@ struct net_buf *net_nbuf_read_be32(struct net_buf *buf, uint16_t offset,
|
|||
* e.g. Buf(Tx/Rx) - Frag1 - Frag2 - Frag3 - Frag4
|
||||
* (Assume FRAG DATA SIZE is 100 bytes after link layer header)
|
||||
*
|
||||
* 1) net_nbuf_write(buf, frag2, 20, &pos, 20, data)
|
||||
* 1) net_nbuf_write(buf, frag2, 20, &pos, 20, data, K_FOREVER)
|
||||
* In this case write starts from "frag2->data + 20",
|
||||
* returns frag2, pos = 40
|
||||
*
|
||||
* 2) net_nbuf_write(buf, frag1, 150, &pos, 60, data)
|
||||
* 2) net_nbuf_write(buf, frag1, 150, &pos, 60, data, K_FOREVER)
|
||||
* In this case write starts from "frag2->data + 50"
|
||||
* returns frag3, pos = 10
|
||||
*
|
||||
* 3) net_nbuf_write(buf, frag1, 350, &pos, 30, data)
|
||||
* 3) net_nbuf_write(buf, frag1, 350, &pos, 30, data, K_FOREVER)
|
||||
* In this case write starts from "frag4->data + 50"
|
||||
* returns frag4, pos = 80
|
||||
*
|
||||
* 4) net_nbuf_write(buf, frag2, 110, &pos, 90, data)
|
||||
* 4) net_nbuf_write(buf, frag2, 110, &pos, 90, data, K_FOREVER)
|
||||
* In this case write starts from "frag3->data + 10"
|
||||
* returns frag4, pos = 0
|
||||
*
|
||||
* 5) net_nbuf_write(buf, frag4, 110, &pos, 20, data)
|
||||
* 5) net_nbuf_write(buf, frag4, 110, &pos, 20, data, K_FOREVER)
|
||||
* In this case write creates new data fragment and starts from
|
||||
* "frag5->data + 10"
|
||||
* returns frag5, pos = 30
|
||||
|
@ -801,13 +857,17 @@ struct net_buf *net_nbuf_read_be32(struct net_buf *buf, uint16_t offset,
|
|||
* relative to return fragment)
|
||||
* @param len Length of the data to be written.
|
||||
* @param data Data to be written
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return Pointer to the fragment and position (*pos) where write ended,
|
||||
* NULL and pos is 0xffff otherwise.
|
||||
*/
|
||||
struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag,
|
||||
uint16_t offset, uint16_t *pos, uint16_t len,
|
||||
uint8_t *data);
|
||||
uint8_t *data, int32_t timeout);
|
||||
|
||||
/* Write uint8_t data to an arbitrary offset in fragment. */
|
||||
static inline struct net_buf *net_nbuf_write_u8(struct net_buf *buf,
|
||||
|
@ -816,7 +876,8 @@ static inline struct net_buf *net_nbuf_write_u8(struct net_buf *buf,
|
|||
uint16_t *pos,
|
||||
uint8_t data)
|
||||
{
|
||||
return net_nbuf_write(buf, frag, offset, pos, sizeof(uint8_t), &data);
|
||||
return net_nbuf_write(buf, frag, offset, pos, sizeof(uint8_t),
|
||||
&data, K_FOREVER);
|
||||
}
|
||||
|
||||
/* Write uint16_t big endian value to an arbitrary offset in fragment. */
|
||||
|
@ -829,7 +890,7 @@ static inline struct net_buf *net_nbuf_write_be16(struct net_buf *buf,
|
|||
uint16_t value = htons(data);
|
||||
|
||||
return net_nbuf_write(buf, frag, offset, pos, sizeof(uint16_t),
|
||||
(uint8_t *)&value);
|
||||
(uint8_t *)&value, K_FOREVER);
|
||||
}
|
||||
|
||||
/* Write uint32_t big endian value to an arbitrary offset in fragment. */
|
||||
|
@ -842,7 +903,7 @@ static inline struct net_buf *net_nbuf_write_be32(struct net_buf *buf,
|
|||
uint32_t value = htonl(data);
|
||||
|
||||
return net_nbuf_write(buf, frag, offset, pos, sizeof(uint32_t),
|
||||
(uint8_t *)&value);
|
||||
(uint8_t *)&value, K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -862,18 +923,26 @@ static inline struct net_buf *net_nbuf_write_be32(struct net_buf *buf,
|
|||
* @param offset Offset of fragment where insertion will start.
|
||||
* @param len Length of the data to be inserted.
|
||||
* @param data Data to be inserted
|
||||
* @param timeout Affects the action taken should the net buf pool be empty.
|
||||
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
|
||||
* wait as long as necessary. Otherwise, wait up to the specified
|
||||
* number of milliseconds before timing out.
|
||||
*
|
||||
* @return True on success,
|
||||
* False otherwise.
|
||||
*/
|
||||
bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag,
|
||||
uint16_t offset, uint16_t len, uint8_t *data);
|
||||
uint16_t offset, uint16_t len, uint8_t *data,
|
||||
int32_t timeout);
|
||||
|
||||
/* Insert uint8_t data at an arbitrary offset in a series of fragments. */
|
||||
static inline bool net_nbuf_insert_u8(struct net_buf *buf, struct net_buf *frag,
|
||||
uint16_t offset, uint8_t data)
|
||||
static inline bool net_nbuf_insert_u8(struct net_buf *buf,
|
||||
struct net_buf *frag,
|
||||
uint16_t offset,
|
||||
uint8_t data)
|
||||
{
|
||||
return net_nbuf_insert(buf, frag, offset, sizeof(uint8_t), &data);
|
||||
return net_nbuf_insert(buf, frag, offset, sizeof(uint8_t), &data,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/* Insert uint16_t big endian value at an arbitrary offset in a series of
|
||||
|
@ -881,12 +950,13 @@ static inline bool net_nbuf_insert_u8(struct net_buf *buf, struct net_buf *frag,
|
|||
*/
|
||||
static inline bool net_nbuf_insert_be16(struct net_buf *buf,
|
||||
struct net_buf *frag,
|
||||
uint16_t offset, uint16_t data)
|
||||
uint16_t offset,
|
||||
uint16_t data)
|
||||
{
|
||||
uint16_t value = htons(data);
|
||||
|
||||
return net_nbuf_insert(buf, frag, offset, sizeof(uint16_t),
|
||||
(uint8_t *)&value);
|
||||
(uint8_t *)&value, K_FOREVER);
|
||||
}
|
||||
|
||||
/* Insert uint32_t big endian value at an arbitrary offset in a series of
|
||||
|
@ -894,12 +964,13 @@ static inline bool net_nbuf_insert_be16(struct net_buf *buf,
|
|||
*/
|
||||
static inline bool net_nbuf_insert_be32(struct net_buf *buf,
|
||||
struct net_buf *frag,
|
||||
uint16_t offset, uint32_t data)
|
||||
uint16_t offset,
|
||||
uint32_t data)
|
||||
{
|
||||
uint32_t value = htonl(data);
|
||||
|
||||
return net_nbuf_insert(buf, frag, offset, sizeof(uint32_t),
|
||||
(uint8_t *)&value);
|
||||
(uint8_t *)&value, K_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -145,7 +145,7 @@ static struct net_buf *build_reply_buf(const char *name,
|
|||
printk("%s received %d bytes", name,
|
||||
net_nbuf_appdatalen(buf));
|
||||
|
||||
reply_buf = net_nbuf_get_tx(context);
|
||||
reply_buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
|
||||
recv_len = net_buf_frags_len(buf->frags);
|
||||
|
||||
|
|
|
@ -58,12 +58,12 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
|||
|
||||
udp_ctx = ctx->net_ctx;
|
||||
|
||||
send_buf = net_nbuf_get_tx(udp_ctx);
|
||||
send_buf = net_nbuf_get_tx(udp_ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
||||
if (!rc) {
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
|
|
@ -47,13 +47,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
|||
|
||||
net_ctx = ctx->net_ctx;
|
||||
|
||||
send_buf = net_nbuf_get_tx(net_ctx);
|
||||
send_buf = net_nbuf_get_tx(net_ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
printk("cannot create buf\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
||||
if (!rc) {
|
||||
printk("cannot write buf\n");
|
||||
return -EIO;
|
||||
|
|
|
@ -364,11 +364,12 @@ static struct net_buf *prepare_send_buf(const char *name,
|
|||
struct net_buf *send_buf;
|
||||
bool status;
|
||||
|
||||
send_buf = net_nbuf_get_tx(context);
|
||||
send_buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
|
||||
NET_ASSERT(send_buf);
|
||||
|
||||
status = net_nbuf_append(send_buf, expecting_len, lorem_ipsum);
|
||||
status = net_nbuf_append(send_buf, expecting_len, lorem_ipsum,
|
||||
K_FOREVER);
|
||||
if (!status) {
|
||||
NET_ERR("%s: cannot create send buf", name);
|
||||
return NULL;
|
||||
|
|
|
@ -271,7 +271,7 @@ static struct net_buf *build_reply_buf(const char *name,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
reply_buf = net_nbuf_get_tx(context);
|
||||
reply_buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
|
||||
NET_ASSERT(reply_buf);
|
||||
|
||||
|
@ -292,7 +292,7 @@ static struct net_buf *build_reply_buf(const char *name,
|
|||
net_buf_pull(tmp, header_len);
|
||||
|
||||
while (tmp) {
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
|
||||
if (!net_buf_headroom(tmp)) {
|
||||
/* If there is no link layer headers in the
|
||||
|
|
|
@ -54,25 +54,27 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
|
|||
struct net_buf *tx;
|
||||
int rc;
|
||||
|
||||
tx = net_nbuf_get_tx(http_ctx->tcp_ctx.net_ctx);
|
||||
tx = net_nbuf_get_tx(http_ctx->tcp_ctx.net_ctx, K_FOREVER);
|
||||
if (tx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(method), (uint8_t *)method)) {
|
||||
if (!net_nbuf_append(tx, strlen(method), (uint8_t *)method,
|
||||
K_FOREVER)) {
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(url), (uint8_t *)url)) {
|
||||
if (!net_nbuf_append(tx, strlen(url), (uint8_t *)url, K_FOREVER)) {
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(protocol), (uint8_t *)protocol)) {
|
||||
if (!net_nbuf_append(tx, strlen(protocol), (uint8_t *)protocol,
|
||||
K_FOREVER)) {
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(HEADER_FIELDS),
|
||||
(uint8_t *)HEADER_FIELDS)) {
|
||||
(uint8_t *)HEADER_FIELDS, K_FOREVER)) {
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
|
@ -80,13 +82,14 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
|
|||
char content_len_str[CON_LEN_SIZE];
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(content_type),
|
||||
(uint8_t *)content_type)) {
|
||||
(uint8_t *)content_type, K_FOREVER)) {
|
||||
rc = -ENOMEM;
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(content_type_value),
|
||||
(uint8_t *)content_type_value)) {
|
||||
(uint8_t *)content_type_value,
|
||||
K_FOREVER)) {
|
||||
rc = -ENOMEM;
|
||||
goto lb_exit;
|
||||
}
|
||||
|
@ -100,18 +103,20 @@ int http_send_request(struct http_client_ctx *http_ctx, const char *method,
|
|||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(content_len_str),
|
||||
(uint8_t *)content_len_str)) {
|
||||
(uint8_t *)content_len_str, K_FOREVER)) {
|
||||
rc = -ENOMEM;
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(tx, strlen(payload), (uint8_t *)payload)) {
|
||||
if (!net_nbuf_append(tx, strlen(payload), (uint8_t *)payload,
|
||||
K_FOREVER)) {
|
||||
rc = -ENOMEM;
|
||||
goto lb_exit;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!net_nbuf_append(tx, strlen(sep), (uint8_t *)sep)) {
|
||||
if (!net_nbuf_append(tx, strlen(sep), (uint8_t *)sep,
|
||||
K_FOREVER)) {
|
||||
rc = -ENOMEM;
|
||||
goto lb_exit;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ uint16_t http_strlen(const char *str)
|
|||
|
||||
int http_add_header(struct net_buf *tx, const char *str)
|
||||
{
|
||||
net_nbuf_append(tx, strlen(str), (uint8_t *)str);
|
||||
net_nbuf_append(tx, strlen(str), (uint8_t *)str, K_FOREVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ int http_add_chunk(struct net_buf *tx, const char *str)
|
|||
str_len = http_strlen(str);
|
||||
|
||||
snprintf(chunk_header, sizeof(chunk_header), "%x\r\n", str_len);
|
||||
net_nbuf_append(tx, strlen(chunk_header), chunk_header);
|
||||
net_nbuf_append(tx, strlen(chunk_header), chunk_header, K_FOREVER);
|
||||
|
||||
if (str_len) {
|
||||
net_nbuf_append(tx, str_len, (uint8_t *)str);
|
||||
net_nbuf_append(tx, str_len, (uint8_t *)str, K_FOREVER);
|
||||
}
|
||||
|
||||
net_nbuf_append(tx, strlen(rn), rn);
|
||||
net_nbuf_append(tx, strlen(rn), rn, K_FOREVER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ int http_write(struct http_server_ctx *ctx, const char *http_header,
|
|||
struct net_buf *tx;
|
||||
int rc = -EINVAL;
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, K_FOREVER);
|
||||
printf("[%s:%d] net_nbuf_get_tx, rc: %d <%s>\n",
|
||||
__func__, __LINE__, !tx, RC_STR(!tx));
|
||||
if (tx == NULL) {
|
||||
|
|
|
@ -146,12 +146,12 @@ transmit(struct net_context *ctx, char buffer[], size_t len)
|
|||
{
|
||||
struct net_buf *send_buf;
|
||||
|
||||
send_buf = net_nbuf_get_tx(ctx);
|
||||
send_buf = net_nbuf_get_tx(ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(send_buf, len, buffer)) {
|
||||
if (!net_nbuf_append(send_buf, len, buffer), K_FOREVER) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,12 +100,12 @@ static int led_get(struct zoap_resource *resource,
|
|||
|
||||
id = zoap_header_get_id(request);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -167,12 +167,12 @@ static int led_post(struct zoap_resource *resource,
|
|||
|
||||
id = zoap_header_get_id(request);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -245,12 +245,12 @@ static int led_put(struct zoap_resource *resource,
|
|||
|
||||
id = zoap_header_get_id(request);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -307,12 +307,12 @@ static int dummy_get(struct zoap_resource *resource,
|
|||
|
||||
id = zoap_header_get_id(request);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
|
@ -66,13 +66,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
|||
|
||||
udp_ctx = ctx->net_ctx;
|
||||
|
||||
send_buf = net_nbuf_get_tx(udp_ctx);
|
||||
send_buf = net_nbuf_get_tx(udp_ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
printk("cannot create buf\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
||||
if (!rc) {
|
||||
printk("cannot write buf\n");
|
||||
return -EIO;
|
||||
|
|
|
@ -60,13 +60,13 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
|||
|
||||
net_ctx = ctx->net_ctx;
|
||||
|
||||
send_buf = net_nbuf_get_tx(net_ctx);
|
||||
send_buf = net_nbuf_get_tx(net_ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
printk("cannot create buf\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
||||
if (!rc) {
|
||||
printk("cannot write buf\n");
|
||||
return -EIO;
|
||||
|
|
|
@ -54,13 +54,13 @@ int tcp_tx(void *context, const unsigned char *buf, size_t size)
|
|||
|
||||
tcp_ctx = ctx->net_ctx;
|
||||
|
||||
send_buf = net_nbuf_get_tx(tcp_ctx);
|
||||
send_buf = net_nbuf_get_tx(tcp_ctx, K_FOREVER);
|
||||
if (!send_buf) {
|
||||
printk("cannot create buf\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf);
|
||||
rc = net_nbuf_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
||||
if (!rc) {
|
||||
printk("cannot write buf\n");
|
||||
return -EIO;
|
||||
|
|
|
@ -143,12 +143,12 @@ static int slip_process_byte(unsigned char c)
|
|||
#endif
|
||||
|
||||
if (!pkt_curr) {
|
||||
pkt_curr = net_nbuf_get_reserve_rx(0);
|
||||
pkt_curr = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!pkt_curr) {
|
||||
SYS_LOG_ERR("No more buffers");
|
||||
return 0;
|
||||
}
|
||||
buf = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
SYS_LOG_ERR("No more buffers");
|
||||
net_nbuf_unref(pkt_curr);
|
||||
|
@ -220,13 +220,13 @@ static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
|
|||
{
|
||||
struct net_buf *buf, *pkt;
|
||||
|
||||
pkt = net_nbuf_get_reserve_rx(0);
|
||||
pkt = net_nbuf_get_reserve_rx(0, K_NO_WAIT);
|
||||
if (!pkt) {
|
||||
SYS_LOG_DBG("No buf available");
|
||||
return;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
SYS_LOG_DBG("No fragment available");
|
||||
net_nbuf_unref(pkt);
|
||||
|
|
|
@ -382,8 +382,17 @@ static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
|
|||
{
|
||||
struct net_buf *pkt, *buf;
|
||||
|
||||
pkt = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_data(0);
|
||||
pkt = net_nbuf_get_reserve_tx(0, K_NO_WAIT);
|
||||
if (!pkt) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_data(0, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
net_nbuf_unref(pkt);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
net_buf_frag_insert(pkt, buf);
|
||||
|
||||
net_buf_add_u8(buf, setup->bRequest);
|
||||
|
|
|
@ -173,13 +173,13 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
|
|||
|
||||
k_delayed_work_init(&retransmit_work, retransmit_request);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Unable to get TX buffer, not enough memory.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Unable to get DATA buffer, not enough memory.\n");
|
||||
return;
|
||||
|
|
|
@ -64,12 +64,12 @@ static int test_del(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -123,12 +123,12 @@ static int test_put(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -188,12 +188,12 @@ static int test_post(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -257,12 +257,12 @@ static int location_query_post(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -317,12 +317,12 @@ static int piggyback_get(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -419,12 +419,12 @@ static int query_get(struct zoap_resource *resource,
|
|||
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -494,12 +494,12 @@ static int separate_get(struct zoap_resource *resource,
|
|||
goto done;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -525,12 +525,12 @@ static int separate_get(struct zoap_resource *resource,
|
|||
}
|
||||
|
||||
done:
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -614,12 +614,12 @@ static int large_get(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -712,12 +712,12 @@ static int large_update_put(struct zoap_resource *resource,
|
|||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
||||
NET_INFO("*******\n");
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
|
@ -54,23 +54,24 @@ void zperf_tcp_upload(struct net_context *ctx,
|
|||
loop_time = k_cycle_get_32();
|
||||
last_loop_time = loop_time;
|
||||
|
||||
buf = net_nbuf_get_tx(ctx);
|
||||
buf = net_nbuf_get_tx(ctx, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk(TAG "ERROR! Failed to retrieve a buffer\n");
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(ctx);
|
||||
frag = net_nbuf_get_data(ctx, K_FOREVER);
|
||||
if (!frag) {
|
||||
net_nbuf_unref(buf);
|
||||
printk(TAG "ERROR! Failed to retrieve a fragment\n");
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
/* Fill in the TCP payload */
|
||||
st = net_nbuf_append(buf, sizeof(sample_packet),
|
||||
sample_packet);
|
||||
sample_packet, K_FOREVER);
|
||||
if (!st) {
|
||||
printk(TAG "ERROR! Failed to fill packet\n");
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ static inline struct net_buf *build_reply_buf(struct net_context *context,
|
|||
|
||||
printk(TAG "received %d bytes\n", net_nbuf_appdatalen(buf));
|
||||
|
||||
reply_buf = net_nbuf_get_tx(context);
|
||||
frag = net_nbuf_get_data(context);
|
||||
reply_buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(reply_buf, frag);
|
||||
|
||||
|
|
|
@ -86,13 +86,13 @@ static inline void zperf_upload_fin(struct net_context *context,
|
|||
struct net_buf *buf, *frag;
|
||||
bool status;
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk(TAG "ERROR! Failed to retrieve a buffer\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk(TAG "ERROR! Failed to retrieve a fragment\n");
|
||||
continue;
|
||||
|
@ -107,7 +107,7 @@ static inline void zperf_upload_fin(struct net_context *context,
|
|||
USEC_PER_SEC);
|
||||
|
||||
status = net_nbuf_append(buf, sizeof(datagram),
|
||||
(uint8_t *)&datagram);
|
||||
(uint8_t *)&datagram, K_FOREVER);
|
||||
if (!status) {
|
||||
printk(TAG "ERROR! Cannot append datagram data\n");
|
||||
break;
|
||||
|
@ -121,7 +121,8 @@ static inline void zperf_upload_fin(struct net_context *context,
|
|||
|
||||
frag = net_nbuf_write(buf, net_buf_frag_last(buf),
|
||||
sizeof(struct zperf_udp_datagram),
|
||||
&pos, size, sample_packet);
|
||||
&pos, size, sample_packet,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/* Send the packet */
|
||||
|
@ -229,13 +230,13 @@ void zperf_udp_upload(struct net_context *context,
|
|||
|
||||
last_loop_time = loop_time;
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk(TAG "ERROR! Failed to retrieve a buffer\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk(TAG "ERROR! Failed to retrieve a frag\n");
|
||||
continue;
|
||||
|
@ -250,7 +251,7 @@ void zperf_udp_upload(struct net_context *context,
|
|||
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
|
||||
|
||||
status = net_nbuf_append(buf, sizeof(datagram),
|
||||
(uint8_t *)&datagram);
|
||||
(uint8_t *)&datagram, K_FOREVER);
|
||||
if (!status) {
|
||||
printk(TAG "ERROR! Cannot append datagram data\n");
|
||||
break;
|
||||
|
@ -264,7 +265,8 @@ void zperf_udp_upload(struct net_context *context,
|
|||
|
||||
frag = net_nbuf_write(buf, net_buf_frag_last(buf),
|
||||
sizeof(struct zperf_udp_datagram),
|
||||
&pos, size, sample_packet);
|
||||
&pos, size, sample_packet,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/* Send the packet */
|
||||
|
|
|
@ -712,10 +712,7 @@ static inline bool compress_IPHC_header(struct net_buf *buf,
|
|||
return false;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
|
||||
IPHC[offset++] = NET_6LO_DISPATCH_IPHC;
|
||||
IPHC[offset++] = 0;
|
||||
|
@ -1287,10 +1284,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf)
|
|||
#endif
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
|
||||
ipv6 = (struct net_ipv6_hdr *)(frag->data);
|
||||
|
||||
|
@ -1406,10 +1400,7 @@ static inline bool compress_ipv6_header(struct net_buf *buf,
|
|||
{
|
||||
struct net_buf *frag;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
|
||||
frag->data[0] = NET_6LO_DISPATCH_IPV6;
|
||||
net_buf_add(frag, 1);
|
||||
|
|
|
@ -132,7 +132,8 @@ static inline void unset_dhcpv4_on_iface(struct net_if *iface)
|
|||
/* Add magic cookie to DCHPv4 messages */
|
||||
static inline bool add_cookie(struct net_buf *buf)
|
||||
{
|
||||
return net_nbuf_append(buf, sizeof(magic_cookie), magic_cookie);
|
||||
return net_nbuf_append(buf, sizeof(magic_cookie), magic_cookie,
|
||||
K_FOREVER);
|
||||
}
|
||||
|
||||
/* Add DHCPv4 message type */
|
||||
|
@ -140,7 +141,7 @@ static inline bool add_msg_type(struct net_buf *buf, uint8_t type)
|
|||
{
|
||||
uint8_t data[3] = { DHCPV4_OPTIONS_MSG_TYPE, 1, type };
|
||||
|
||||
return net_nbuf_append(buf, sizeof(data), data);
|
||||
return net_nbuf_append(buf, sizeof(data), data, K_FOREVER);
|
||||
}
|
||||
|
||||
/* Add DHCPv4 minimum required options for server to reply.
|
||||
|
@ -154,7 +155,7 @@ static inline bool add_req_options(struct net_buf *buf)
|
|||
DHCPV4_OPTIONS_ROUTER,
|
||||
DHCPV4_OPTIONS_DNS_SERVER };
|
||||
|
||||
return net_nbuf_append(buf, sizeof(data), data);
|
||||
return net_nbuf_append(buf, sizeof(data), data, K_FOREVER);
|
||||
}
|
||||
|
||||
static inline bool add_server_id(struct net_buf *buf)
|
||||
|
@ -163,16 +164,17 @@ static inline bool add_server_id(struct net_buf *buf)
|
|||
uint8_t data;
|
||||
|
||||
data = DHCPV4_OPTIONS_SERVER_ID;
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = 4;
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(buf, 4, iface->dhcpv4.server_id.s4_addr)) {
|
||||
if (!net_nbuf_append(buf, 4, iface->dhcpv4.server_id.s4_addr,
|
||||
K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -185,16 +187,17 @@ static inline bool add_req_ipaddr(struct net_buf *buf)
|
|||
uint8_t data;
|
||||
|
||||
data = DHCPV4_OPTIONS_REQ_IPADDR;
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = 4;
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(buf, 4, iface->dhcpv4.requested_ip.s4_addr)) {
|
||||
if (!net_nbuf_append(buf, 4, iface->dhcpv4.requested_ip.s4_addr,
|
||||
K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -206,7 +209,7 @@ static inline bool add_end(struct net_buf *buf)
|
|||
{
|
||||
uint8_t data = DHCPV4_OPTIONS_END;
|
||||
|
||||
return net_nbuf_append(buf, 1, &data);
|
||||
return net_nbuf_append(buf, 1, &data, K_FOREVER);
|
||||
}
|
||||
|
||||
/* File is empty ATM */
|
||||
|
@ -216,7 +219,7 @@ static inline bool add_file(struct net_buf *buf)
|
|||
uint8_t data = 0;
|
||||
|
||||
while (len-- > 0) {
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +234,7 @@ static inline bool add_sname(struct net_buf *buf)
|
|||
uint8_t data = 0;
|
||||
|
||||
while (len-- > 0) {
|
||||
if (!net_nbuf_append(buf, 1, &data)) {
|
||||
if (!net_nbuf_append(buf, 1, &data, K_FOREVER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -278,15 +281,10 @@ static struct net_buf *prepare_message(struct net_if *iface, uint8_t type)
|
|||
struct net_buf *frag;
|
||||
struct dhcp_msg *msg;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL));
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
}
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag));
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
|
|
@ -106,7 +106,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
|
|||
/* Take the first address of the network interface */
|
||||
src = &iface->ipv4.unicast[0].address.in_addr;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
/* We cast to IPv6 address but that should be ok in this case
|
||||
* as IPv4 cannot be used in 802.15.4 where it is the reserve
|
||||
|
@ -115,7 +115,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
|
|||
reserve = net_if_get_ll_reserve(iface,
|
||||
(const struct in6_addr *)dst);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
net_nbuf_set_family(buf, AF_INET);
|
||||
|
@ -192,7 +192,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
|
|||
|
||||
iface = net_nbuf_iface(orig);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
reserve = sizeof(struct net_ipv4_hdr) + sizeof(struct net_icmp_hdr) +
|
||||
NET_ICMPV4_UNUSED_LEN;
|
||||
|
@ -223,7 +223,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code)
|
|||
/* We only copy minimal IPv4 + next header from original message.
|
||||
* This is so that the memory pressure is minimized.
|
||||
*/
|
||||
frag = net_nbuf_copy(orig->frags, extra_len, reserve);
|
||||
frag = net_nbuf_copy(orig->frags, extra_len, reserve, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto drop;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
|
|||
|
||||
iface = net_nbuf_iface(orig);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
/* We need to remember the original location of source and destination
|
||||
* addresses as the net_nbuf_copy() will mangle the original buffer.
|
||||
|
@ -96,7 +96,7 @@ static enum net_verdict handle_echo_request(struct net_buf *orig)
|
|||
payload_len = sys_get_be16(NET_IPV6_BUF(orig)->len) -
|
||||
sizeof(NET_ICMPH_LEN) - NET_ICMPV6_UNUSED_LEN;
|
||||
|
||||
frag = net_nbuf_copy_all(orig->frags, 0);
|
||||
frag = net_nbuf_copy_all(orig->frags, 0, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto drop;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
|
|||
|
||||
iface = net_nbuf_iface(orig);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
/* We need to remember the original location of source and destination
|
||||
* addresses as the net_nbuf_copy() will mangle the original buffer.
|
||||
|
@ -215,7 +215,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code,
|
|||
/* We only copy minimal IPv6 + next header from original message.
|
||||
* This is so that the memory pressure is minimized.
|
||||
*/
|
||||
frag = net_nbuf_copy(orig->frags, extra_len, reserve);
|
||||
frag = net_nbuf_copy(orig->frags, extra_len, reserve, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto drop;
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
|
|||
|
||||
src = net_if_ipv6_select_src_addr(iface, dst);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
reserve = net_if_get_ll_reserve(iface, dst);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ struct net_buf *net_ipv4_create_raw(struct net_buf *buf,
|
|||
{
|
||||
struct net_buf *header;
|
||||
|
||||
header = net_nbuf_get_reserve_data(reserve);
|
||||
header = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_insert(buf, header);
|
||||
|
||||
|
|
|
@ -292,7 +292,7 @@ struct net_buf *net_ipv6_create_raw(struct net_buf *buf,
|
|||
{
|
||||
struct net_buf *header;
|
||||
|
||||
header = net_nbuf_get_reserve_data(reserve);
|
||||
header = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_insert(buf, header);
|
||||
|
||||
|
@ -520,7 +520,7 @@ static struct net_buf *update_ll_reserve(struct net_buf *buf,
|
|||
|
||||
while (orig_frag) {
|
||||
if (!room_len) {
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -874,11 +874,12 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src,
|
|||
struct net_buf *buf, *frag;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, dst));
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(frag, "Out of DATA buffers");
|
||||
|
||||
|
@ -1476,11 +1477,12 @@ int net_ipv6_send_ns(struct net_if *iface,
|
|||
struct net_nbr *nbr;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, dst));
|
||||
frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(frag, "Out of DATA buffers");
|
||||
|
||||
|
@ -1611,10 +1613,11 @@ int net_ipv6_send_rs(struct net_if *iface)
|
|||
bool unspec_src;
|
||||
uint8_t llao_len = 0;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(
|
||||
net_if_get_ll_reserve(iface, &NET_IPV6_BUF(buf)->dst));
|
||||
net_if_get_ll_reserve(iface, &NET_IPV6_BUF(buf)->dst),
|
||||
K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
|
|
@ -107,12 +107,13 @@ static inline struct net_buf *prepare_arp(struct net_if *iface,
|
|||
struct net_eth_hdr *eth;
|
||||
struct in_addr *my_addr;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -202,7 +203,8 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
|
|||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
header = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
header = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
|
||||
hdr = (struct net_eth_hdr *)net_nbuf_ll(header);
|
||||
hdr->type = htons(NET_ETH_PTYPE_IP);
|
||||
|
@ -371,12 +373,13 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr, *query;
|
||||
struct net_eth_hdr *eth, *eth_query;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ static void ipsp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
net_buf_frags_len(buf));
|
||||
|
||||
/* Get buffer for bearer / protocol related data */
|
||||
nbuf = net_nbuf_get_reserve_rx(0);
|
||||
nbuf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
|
||||
/* Set destination address */
|
||||
net_nbuf_ll_dst(nbuf)->addr = ctxt->src.val;
|
||||
|
@ -216,7 +216,7 @@ static struct net_buf *ipsp_alloc_buf(struct bt_l2cap_chan *chan)
|
|||
{
|
||||
NET_DBG("Channel %p requires buffer", chan);
|
||||
|
||||
return net_nbuf_get_reserve_data(0);
|
||||
return net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
}
|
||||
|
||||
static struct bt_l2cap_chan_ops ipsp_ops = {
|
||||
|
|
|
@ -92,12 +92,12 @@ static inline void ieee802154_acknowledge(struct net_if *iface,
|
|||
return;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(IEEE802154_ACK_PKT_LENGTH);
|
||||
frag = net_nbuf_get_reserve_data(IEEE802154_ACK_PKT_LENGTH, K_FOREVER);
|
||||
|
||||
net_buf_frag_insert(buf, frag);
|
||||
net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag));
|
||||
|
|
|
@ -212,7 +212,7 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff)
|
|||
/* Datagram_size: total length before compression */
|
||||
size = net_buf_frags_len(buf) + hdr_diff;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ static inline bool copy_frag(struct net_buf *buf,
|
|||
|
||||
while (input) {
|
||||
write = net_nbuf_write(buf, write, pos, &pos, input->len,
|
||||
input->data);
|
||||
input->data, K_FOREVER);
|
||||
if (!write && pos == 0xffff) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -635,12 +635,12 @@ ieee802154_create_mac_cmd_frame(struct net_if *iface,
|
|||
struct net_buf *buf, *frag;
|
||||
uint8_t *p_buf;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -311,11 +311,13 @@ void net_nbuf_print_frags(struct net_buf *buf)
|
|||
|
||||
static struct net_buf *net_nbuf_get_reserve_debug(struct net_buf_pool *pool,
|
||||
uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller,
|
||||
int line)
|
||||
#else /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
static struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool,
|
||||
uint16_t reserve_head)
|
||||
uint16_t reserve_head,
|
||||
int32_t timeout)
|
||||
#endif /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
{
|
||||
struct net_buf *buf = NULL;
|
||||
|
@ -327,11 +329,12 @@ static struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool,
|
|||
|
||||
if (k_is_in_isr()) {
|
||||
buf = net_buf_alloc(pool, K_NO_WAIT);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
buf = net_buf_alloc(pool, K_FOREVER);
|
||||
buf = net_buf_alloc(pool, timeout);
|
||||
}
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pool == &data_buffers) {
|
||||
|
@ -356,41 +359,47 @@ static struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool,
|
|||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_BUF)
|
||||
struct net_buf *net_nbuf_get_reserve_rx_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_reserve_debug(&rx_buffers, reserve_head,
|
||||
return net_nbuf_get_reserve_debug(&rx_buffers, reserve_head, timeout,
|
||||
caller, line);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_tx_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_reserve_debug(&tx_buffers, reserve_head,
|
||||
return net_nbuf_get_reserve_debug(&tx_buffers, reserve_head, timeout,
|
||||
caller, line);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_data_debug(uint16_t reserve_head,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_reserve_debug(&data_buffers, reserve_head,
|
||||
caller, line);
|
||||
timeout, caller, line);
|
||||
}
|
||||
|
||||
#else /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head)
|
||||
struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head,
|
||||
int32_t timeout)
|
||||
{
|
||||
return net_nbuf_get_reserve(&rx_buffers, reserve_head);
|
||||
return net_nbuf_get_reserve(&rx_buffers, reserve_head, timeout);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head)
|
||||
struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head,
|
||||
int32_t timeout)
|
||||
{
|
||||
return net_nbuf_get_reserve(&tx_buffers, reserve_head);
|
||||
return net_nbuf_get_reserve(&tx_buffers, reserve_head, timeout);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_reserve_data(uint16_t reserve_head)
|
||||
struct net_buf *net_nbuf_get_reserve_data(uint16_t reserve_head,
|
||||
int32_t timeout)
|
||||
{
|
||||
return net_nbuf_get_reserve(&data_buffers, reserve_head);
|
||||
return net_nbuf_get_reserve(&data_buffers, reserve_head, timeout);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
|
@ -399,10 +408,12 @@ struct net_buf *net_nbuf_get_reserve_data(uint16_t reserve_head)
|
|||
#if defined(CONFIG_NET_DEBUG_NET_BUF)
|
||||
static struct net_buf *net_nbuf_get_debug(struct net_buf_pool *pool,
|
||||
struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
#else
|
||||
static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
||||
struct net_context *context)
|
||||
struct net_context *context,
|
||||
int32_t timeout)
|
||||
#endif /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
{
|
||||
struct in6_addr *addr6 = NULL;
|
||||
|
@ -425,9 +436,9 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
|||
reserve = net_if_get_ll_reserve(iface, addr6);
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_BUF)
|
||||
buf = net_nbuf_get_reserve_debug(pool, reserve, caller, line);
|
||||
buf = net_nbuf_get_reserve_debug(pool, reserve, timeout, caller, line);
|
||||
#else
|
||||
buf = net_nbuf_get_reserve(pool, reserve);
|
||||
buf = net_nbuf_get_reserve(pool, reserve, timeout);
|
||||
#endif
|
||||
if (!buf) {
|
||||
return buf;
|
||||
|
@ -449,44 +460,48 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
|||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_BUF)
|
||||
struct net_buf *net_nbuf_get_rx_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_debug(&rx_buffers, context, caller, line);
|
||||
return net_nbuf_get_debug(&rx_buffers, context, timeout, caller, line);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_tx_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_debug(&tx_buffers, context, caller, line);
|
||||
return net_nbuf_get_debug(&tx_buffers, context, timeout, caller, line);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_data_debug(struct net_context *context,
|
||||
int32_t timeout,
|
||||
const char *caller, int line)
|
||||
{
|
||||
return net_nbuf_get_debug(&data_buffers, context, caller, line);
|
||||
return net_nbuf_get_debug(&data_buffers, context, timeout,
|
||||
caller, line);
|
||||
}
|
||||
|
||||
#else /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
|
||||
struct net_buf *net_nbuf_get_rx(struct net_context *context)
|
||||
struct net_buf *net_nbuf_get_rx(struct net_context *context, int32_t timeout)
|
||||
{
|
||||
NET_ASSERT_INFO(context, "RX context not set");
|
||||
|
||||
return net_nbuf_get(&rx_buffers, context);
|
||||
return net_nbuf_get(&rx_buffers, context, timeout);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_tx(struct net_context *context)
|
||||
struct net_buf *net_nbuf_get_tx(struct net_context *context, int32_t timeout)
|
||||
{
|
||||
NET_ASSERT_INFO(context, "TX context not set");
|
||||
|
||||
return net_nbuf_get(&tx_buffers, context);
|
||||
return net_nbuf_get(&tx_buffers, context, timeout);
|
||||
}
|
||||
|
||||
struct net_buf *net_nbuf_get_data(struct net_context *context)
|
||||
struct net_buf *net_nbuf_get_data(struct net_context *context, int32_t timeout)
|
||||
{
|
||||
NET_ASSERT_INFO(context, "Data context not set");
|
||||
|
||||
return net_nbuf_get(&data_buffers, context);
|
||||
return net_nbuf_get(&data_buffers, context, timeout);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_DEBUG_NET_BUF */
|
||||
|
@ -564,7 +579,7 @@ struct net_buf *net_nbuf_ref(struct net_buf *buf)
|
|||
}
|
||||
|
||||
struct net_buf *net_nbuf_copy(struct net_buf *orig, size_t amount,
|
||||
size_t reserve)
|
||||
size_t reserve, int32_t timeout)
|
||||
{
|
||||
uint16_t ll_reserve = net_buf_headroom(orig);
|
||||
struct net_buf *frag, *first;
|
||||
|
@ -574,7 +589,10 @@ struct net_buf *net_nbuf_copy(struct net_buf *orig, size_t amount,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve);
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve, timeout);
|
||||
if (!frag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reserve > net_buf_tailroom(frag)) {
|
||||
NET_ERR("Reserve %zu is too long, max is %zu",
|
||||
|
@ -622,7 +640,12 @@ struct net_buf *net_nbuf_copy(struct net_buf *orig, size_t amount,
|
|||
* We must allocate a new one.
|
||||
*/
|
||||
struct net_buf *new_frag =
|
||||
net_nbuf_get_reserve_data(ll_reserve);
|
||||
net_nbuf_get_reserve_data(ll_reserve,
|
||||
timeout);
|
||||
if (!new_frag) {
|
||||
net_nbuf_unref(first);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net_buf_frag_add(frag, new_frag);
|
||||
|
||||
|
@ -803,7 +826,8 @@ struct net_buf *net_nbuf_compact(struct net_buf *buf)
|
|||
|
||||
struct net_buf *net_nbuf_push(struct net_buf *parent,
|
||||
struct net_buf *buf,
|
||||
size_t amount)
|
||||
size_t amount,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct net_buf *frag;
|
||||
|
||||
|
@ -816,7 +840,10 @@ struct net_buf *net_nbuf_push(struct net_buf *parent,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_buf_headroom(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_buf_headroom(buf), timeout);
|
||||
if (!frag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net_buf_add(frag, amount);
|
||||
|
||||
|
@ -898,7 +925,7 @@ struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount)
|
|||
* the buffer. It assumes that the buffer has at least one fragment.
|
||||
*/
|
||||
static inline bool net_nbuf_append_bytes(struct net_buf *buf, uint8_t *value,
|
||||
uint16_t len)
|
||||
uint16_t len, int32_t timeout)
|
||||
{
|
||||
struct net_buf *frag = net_buf_frag_last(buf);
|
||||
uint16_t ll_reserve = net_nbuf_ll_reserve(buf);
|
||||
|
@ -915,7 +942,7 @@ static inline bool net_nbuf_append_bytes(struct net_buf *buf, uint8_t *value,
|
|||
return true;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve);
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve, timeout);
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
|
@ -926,7 +953,8 @@ static inline bool net_nbuf_append_bytes(struct net_buf *buf, uint8_t *value,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data)
|
||||
bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct net_buf *frag;
|
||||
|
||||
|
@ -944,7 +972,8 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data)
|
|||
}
|
||||
|
||||
if (!buf->frags) {
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf),
|
||||
timeout);
|
||||
if (!frag) {
|
||||
return false;
|
||||
}
|
||||
|
@ -952,7 +981,7 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, uint8_t *data)
|
|||
net_buf_frag_add(buf, frag);
|
||||
}
|
||||
|
||||
return net_nbuf_append_bytes(buf, data, len);
|
||||
return net_nbuf_append_bytes(buf, data, len, timeout);
|
||||
}
|
||||
|
||||
/* Helper routine to retrieve single byte from fragment and move
|
||||
|
@ -1069,7 +1098,8 @@ struct net_buf *net_nbuf_read_be32(struct net_buf *buf, uint16_t offset,
|
|||
}
|
||||
|
||||
static inline struct net_buf *check_and_create_data(struct net_buf *buf,
|
||||
struct net_buf *data)
|
||||
struct net_buf *data,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct net_buf *frag;
|
||||
|
||||
|
@ -1077,7 +1107,8 @@ static inline struct net_buf *check_and_create_data(struct net_buf *buf,
|
|||
return data;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf),
|
||||
timeout);
|
||||
if (!frag) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1090,12 +1121,13 @@ static inline struct net_buf *check_and_create_data(struct net_buf *buf,
|
|||
static inline struct net_buf *adjust_write_offset(struct net_buf *buf,
|
||||
struct net_buf *frag,
|
||||
uint16_t offset,
|
||||
uint16_t *pos)
|
||||
uint16_t *pos,
|
||||
int32_t timeout)
|
||||
{
|
||||
uint16_t tailroom;
|
||||
|
||||
do {
|
||||
frag = check_and_create_data(buf, frag);
|
||||
frag = check_and_create_data(buf, frag, timeout);
|
||||
if (!frag) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1122,7 +1154,8 @@ static inline struct net_buf *adjust_write_offset(struct net_buf *buf,
|
|||
|
||||
*pos = 0;
|
||||
|
||||
return check_and_create_data(buf, frag->frags);
|
||||
return check_and_create_data(buf, frag->frags,
|
||||
timeout);
|
||||
}
|
||||
|
||||
/* If the offset is more than current fragment length, remove
|
||||
|
@ -1150,7 +1183,9 @@ static inline struct net_buf *adjust_write_offset(struct net_buf *buf,
|
|||
|
||||
*pos = 0;
|
||||
|
||||
return check_and_create_data(buf, frag->frags);
|
||||
return check_and_create_data(buf,
|
||||
frag->frags,
|
||||
timeout);
|
||||
}
|
||||
|
||||
if (offset > tailroom) {
|
||||
|
@ -1158,7 +1193,9 @@ static inline struct net_buf *adjust_write_offset(struct net_buf *buf,
|
|||
net_buf_add(frag, tailroom);
|
||||
offset -= tailroom;
|
||||
|
||||
frag = check_and_create_data(buf, frag->frags);
|
||||
frag = check_and_create_data(buf,
|
||||
frag->frags,
|
||||
timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1169,7 +1206,8 @@ static inline struct net_buf *adjust_write_offset(struct net_buf *buf,
|
|||
|
||||
struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag,
|
||||
uint16_t offset, uint16_t *pos,
|
||||
uint16_t len, uint8_t *data)
|
||||
uint16_t len, uint8_t *data,
|
||||
int32_t timeout)
|
||||
{
|
||||
uint16_t ll_reserve;
|
||||
|
||||
|
@ -1180,7 +1218,7 @@ struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag,
|
|||
|
||||
ll_reserve = net_nbuf_ll_reserve(buf);
|
||||
|
||||
frag = adjust_write_offset(buf, frag, offset, &offset);
|
||||
frag = adjust_write_offset(buf, frag, offset, &offset, timeout);
|
||||
if (!frag) {
|
||||
NET_DBG("Failed to adjust offset");
|
||||
goto error;
|
||||
|
@ -1213,7 +1251,7 @@ struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag,
|
|||
frag = frag->frags;
|
||||
|
||||
if (!frag) {
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve);
|
||||
frag = net_nbuf_get_reserve_data(ll_reserve, timeout);
|
||||
if (!frag) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -1230,7 +1268,8 @@ error:
|
|||
|
||||
static inline bool insert_data(struct net_buf *buf, struct net_buf *frag,
|
||||
struct net_buf *temp, uint16_t offset,
|
||||
uint16_t len, uint8_t *data)
|
||||
uint16_t len, uint8_t *data,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct net_buf *insert;
|
||||
|
||||
|
@ -1262,7 +1301,8 @@ static inline bool insert_data(struct net_buf *buf, struct net_buf *frag,
|
|||
data += count;
|
||||
offset = 0;
|
||||
|
||||
insert = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
insert = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf),
|
||||
timeout);
|
||||
if (!insert) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1314,7 +1354,8 @@ static inline struct net_buf *adjust_insert_offset(struct net_buf *buf,
|
|||
}
|
||||
|
||||
bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag,
|
||||
uint16_t offset, uint16_t len, uint8_t *data)
|
||||
uint16_t offset, uint16_t len, uint8_t *data,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct net_buf *temp = NULL;
|
||||
uint16_t bytes;
|
||||
|
@ -1333,7 +1374,8 @@ bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag,
|
|||
*/
|
||||
bytes = frag->len - offset;
|
||||
if (bytes) {
|
||||
temp = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
temp = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf),
|
||||
timeout);
|
||||
if (!temp) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1344,7 +1386,7 @@ bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag,
|
|||
}
|
||||
|
||||
/* Insert data into current(frag) fragment from "offset". */
|
||||
return insert_data(buf, frag, temp, offset, len, data);
|
||||
return insert_data(buf, frag, temp, offset, len, data, timeout);
|
||||
}
|
||||
|
||||
void net_nbuf_get_info(size_t *tx_size, size_t *rx_size, size_t *data_size,
|
||||
|
|
|
@ -445,7 +445,7 @@ int net_rpl_dio_send(struct net_if *iface,
|
|||
uint16_t value;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -482,7 +482,8 @@ int net_rpl_dio_send(struct net_if *iface,
|
|||
/* Flags and reserved are set to 0 */
|
||||
net_nbuf_append_be16(buf, 0);
|
||||
|
||||
net_nbuf_append(buf, sizeof(struct in6_addr), dag->dag_id.s6_addr);
|
||||
net_nbuf_append(buf, sizeof(struct in6_addr), dag->dag_id.s6_addr,
|
||||
K_FOREVER);
|
||||
|
||||
if (instance->mc.type != NET_RPL_MC_NONE) {
|
||||
net_rpl_of_update_mc(instance);
|
||||
|
@ -542,7 +543,8 @@ int net_rpl_dio_send(struct net_if *iface,
|
|||
|
||||
net_nbuf_append_be32(buf, 0); /* reserved */
|
||||
net_nbuf_append(buf, sizeof(struct in6_addr),
|
||||
dag->prefix_info.prefix.s6_addr);
|
||||
dag->prefix_info.prefix.s6_addr,
|
||||
K_FOREVER);
|
||||
|
||||
NET_DBG("Sending prefix info in DIO for %s",
|
||||
net_sprint_ipv6_addr(&dag->prefix_info.prefix));
|
||||
|
@ -719,7 +721,7 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface)
|
|||
return 0;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -2964,7 +2966,7 @@ int net_rpl_dao_send(struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -2993,7 +2995,8 @@ int net_rpl_dao_send(struct net_if *iface,
|
|||
net_nbuf_append_u8(buf, rpl_dao_sequence);
|
||||
|
||||
#if defined(CONFIG_NET_RPL_DAO_SPECIFY_DAG)
|
||||
net_nbuf_append(buf, sizeof(dag->dag_id), dag->dag_id.s6_addr);
|
||||
net_nbuf_append(buf, sizeof(dag->dag_id), dag->dag_id.s6_addr,
|
||||
K_FOREVER);
|
||||
#endif
|
||||
|
||||
prefixlen = sizeof(*prefix) * CHAR_BIT;
|
||||
|
@ -3003,7 +3006,7 @@ int net_rpl_dao_send(struct net_if *iface,
|
|||
net_nbuf_append_u8(buf, 2 + prefix_bytes);
|
||||
net_nbuf_append_u8(buf, 0); /* reserved */
|
||||
net_nbuf_append_u8(buf, prefixlen);
|
||||
net_nbuf_append(buf, prefix_bytes, prefix->s6_addr);
|
||||
net_nbuf_append(buf, prefix_bytes, prefix->s6_addr, K_FOREVER);
|
||||
|
||||
net_nbuf_append_u8(buf, NET_RPL_OPTION_TRANSIT);
|
||||
net_nbuf_append_u8(buf, 4); /* length */
|
||||
|
@ -3051,7 +3054,7 @@ static inline int dao_forward(struct net_if *iface,
|
|||
struct net_buf *buf;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -3089,7 +3092,7 @@ static int dao_ack_send(struct net_buf *orig,
|
|||
NET_DBG("Sending a DAO ACK with sequence number %d to %s",
|
||||
sequence, net_sprint_ipv6_addr(dst));
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
|
@ -245,7 +245,7 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp,
|
|||
tail = buf->frags;
|
||||
buf->frags = NULL;
|
||||
} else {
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
|
@ -274,7 +274,7 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp,
|
|||
goto proto_err;
|
||||
}
|
||||
|
||||
header = net_nbuf_get_data(context);
|
||||
header = net_nbuf_get_data(context, K_FOREVER);
|
||||
net_buf_frag_add(buf, header);
|
||||
|
||||
tcphdr = (struct net_tcp_hdr *)net_buf_add(header, NET_TCPH_LEN);
|
||||
|
|
|
@ -162,13 +162,13 @@ int dns_write(struct dns_context *ctx, struct net_buf *dns_data,
|
|||
goto exit_write;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, K_FOREVER);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_write;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(tx, dns_data->len, dns_data->data);
|
||||
rc = net_nbuf_append(tx, dns_data->len, dns_data->data, K_FOREVER);
|
||||
if (rc != true) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_write;
|
||||
|
|
|
@ -43,7 +43,7 @@ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg)
|
|||
goto exit_connect;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_connect;
|
||||
|
@ -81,13 +81,13 @@ int mqtt_tx_disconnect(struct mqtt_ctx *ctx)
|
|||
goto exit_disconnect;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_disconnect;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(tx, len, msg);
|
||||
rc = net_nbuf_append(tx, len, msg, ctx->net_timeout);
|
||||
if (rc != true) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_disconnect;
|
||||
|
@ -154,13 +154,13 @@ int mqtt_tx_pub_msgs(struct mqtt_ctx *ctx, uint16_t id,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_send;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(tx, len, msg);
|
||||
rc = net_nbuf_append(tx, len, msg, ctx->net_timeout);
|
||||
if (rc != true) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_send;
|
||||
|
@ -218,7 +218,7 @@ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg)
|
|||
goto exit_publish;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_publish;
|
||||
|
@ -255,13 +255,13 @@ int mqtt_tx_pingreq(struct mqtt_ctx *ctx)
|
|||
goto exit_pingreq;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_pingreq;
|
||||
}
|
||||
|
||||
rc = net_nbuf_append(tx, len, msg);
|
||||
rc = net_nbuf_append(tx, len, msg, ctx->net_timeout);
|
||||
if (rc != true) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_pingreq;
|
||||
|
@ -302,7 +302,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
|
|||
goto exit_subs;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_subs;
|
||||
|
@ -346,7 +346,7 @@ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
|
|||
goto exit_unsub;
|
||||
}
|
||||
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx);
|
||||
tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout);
|
||||
if (tx == NULL) {
|
||||
rc = -ENOMEM;
|
||||
goto exit_unsub;
|
||||
|
|
|
@ -246,12 +246,12 @@ int _zoap_well_known_core_get(struct zoap_resource *resource,
|
|||
|
||||
context = net_nbuf_context(request->buf);
|
||||
|
||||
buf = net_nbuf_get_tx(context);
|
||||
buf = net_nbuf_get_tx(context, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_data(context);
|
||||
frag = net_nbuf_get_data(context, K_FOREVER);
|
||||
if (!frag) {
|
||||
net_nbuf_unref(buf);
|
||||
return -ENOMEM;
|
||||
|
|
|
@ -308,7 +308,7 @@ static struct net_buf *create_buf(struct net_6lo_data *data)
|
|||
uint16_t len;
|
||||
int remaining;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ static struct net_buf *create_buf(struct net_6lo_data *data)
|
|||
net_nbuf_ll_dst(buf)->addr = dst_mac;
|
||||
net_nbuf_ll_dst(buf)->len = 8;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
if (!frag) {
|
||||
net_nbuf_unref(buf);
|
||||
return NULL;
|
||||
|
@ -384,7 +384,7 @@ static struct net_buf *create_buf(struct net_6lo_data *data)
|
|||
net_buf_frag_add(buf, frag);
|
||||
|
||||
if (remaining > 0) {
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -169,12 +169,12 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr;
|
||||
struct net_eth_hdr *eth;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -223,12 +223,13 @@ static inline struct net_buf *prepare_arp_request(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr, *req_hdr;
|
||||
struct net_eth_hdr *eth, *eth_req;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -333,13 +334,14 @@ static bool run_tests(void)
|
|||
ifaddr->addr_state = NET_ADDR_PREFERRED;
|
||||
|
||||
/* Application data for testing */
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem TX\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA\n");
|
||||
return false;
|
||||
|
@ -559,14 +561,15 @@ static bool run_tests(void)
|
|||
/* The arp request packet is now verified, create an arp reply.
|
||||
* The previous value of buf is stored in arp table and is not lost.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem RX reply\n");
|
||||
return false;
|
||||
}
|
||||
printk("%d buf %p\n", __LINE__, buf);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA reply\n");
|
||||
return false;
|
||||
|
@ -615,13 +618,14 @@ static bool run_tests(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Then feed in ARP request */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem RX request\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA request\n");
|
||||
return false;
|
||||
|
|
|
@ -499,8 +499,8 @@ static bool net_ctx_send_v6(void)
|
|||
int ret, len;
|
||||
struct net_buf *buf, *frag;
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -527,8 +527,8 @@ static bool net_ctx_send_v4(void)
|
|||
int ret, len;
|
||||
struct net_buf *buf, *frag;
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -561,8 +561,8 @@ static bool net_ctx_sendto_v6(void)
|
|||
0, 0, 0, 0, 0, 0, 0, 0x2 } } },
|
||||
};
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -597,8 +597,8 @@ static bool net_ctx_sendto_v4(void)
|
|||
.sin_addr = { { { 192, 0, 2, 2 } } },
|
||||
};
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -695,8 +695,8 @@ static bool net_ctx_sendto_v6_wrong_src(void)
|
|||
0, 0, 0, 0, 0, 0, 0, 0x3 } } },
|
||||
};
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v6_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v6_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -752,8 +752,8 @@ static bool net_ctx_sendto_v4_wrong_src(void)
|
|||
.sin_addr = { { { 192, 0, 2, 3 } } },
|
||||
};
|
||||
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx);
|
||||
buf = net_nbuf_get_tx(udp_v4_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_v4_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
|
|
@ -206,7 +206,8 @@ static struct net_buf *nbuf_get_data(struct net_if *iface)
|
|||
struct net_buf *buf;
|
||||
struct net_eth_hdr *hdr;
|
||||
|
||||
buf = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -265,7 +266,7 @@ struct net_buf *prepare_dhcp_offer(struct net_if *iface, uint32_t xid)
|
|||
int bytes, remaining = sizeof(offer), pos = 0;
|
||||
uint16_t offset;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -334,7 +335,7 @@ struct net_buf *prepare_dhcp_ack(struct net_if *iface, uint32_t xid)
|
|||
int bytes, remaining = sizeof(ack), pos = 0;
|
||||
uint16_t offset;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ static struct net_buf *create_buf(struct net_fragment_data *data)
|
|||
uint16_t len;
|
||||
int remaining;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ static struct net_buf *create_buf(struct net_fragment_data *data)
|
|||
net_nbuf_set_iface(buf, net_if_get_default());
|
||||
net_nbuf_set_ip_hdr_len(buf, NET_IPV6H_LEN);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
if (!frag) {
|
||||
net_nbuf_unref(buf);
|
||||
return NULL;
|
||||
|
@ -271,7 +271,7 @@ static struct net_buf *create_buf(struct net_fragment_data *data)
|
|||
net_buf_frag_add(buf, frag);
|
||||
|
||||
if (remaining > 0) {
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,14 +446,14 @@ static int test_fragment(struct net_fragment_data *data)
|
|||
frag = buf->frags;
|
||||
|
||||
while (frag) {
|
||||
rxbuf = net_nbuf_get_reserve_rx(0);
|
||||
rxbuf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!rxbuf) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(rxbuf, 0);
|
||||
|
||||
dfrag = net_nbuf_get_reserve_data(0);
|
||||
dfrag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
if (!dfrag) {
|
||||
goto end;
|
||||
}
|
||||
|
|
|
@ -192,8 +192,8 @@ static inline int test_ack_reply(struct ieee802154_pkt_test *t)
|
|||
|
||||
TC_PRINT("- Sending ACK reply to a data packet\n");
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
|
||||
memcpy(frag->data, data_pkt, sizeof(data_pkt));
|
||||
frag->len = sizeof(data_pkt);
|
||||
|
@ -236,7 +236,7 @@ static inline int initialize_test_environment(void)
|
|||
|
||||
k_sem_init(&driver_lock, 0, UINT_MAX);
|
||||
|
||||
current_buf = net_nbuf_get_reserve_rx(0);
|
||||
current_buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
if (!current_buf) {
|
||||
TC_ERROR("*** No buffer to allocate\n");
|
||||
return TC_FAIL;
|
||||
|
|
|
@ -283,10 +283,10 @@ static bool send_iface(struct net_if *iface, int val, bool expect_fail)
|
|||
struct net_buf *buf;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
||||
net_nbuf_append(buf, sizeof(data), data);
|
||||
net_nbuf_append(buf, sizeof(data), data, K_FOREVER);
|
||||
|
||||
ret = net_send_data(buf);
|
||||
if (!expect_fail && ret < 0) {
|
||||
|
|
|
@ -168,7 +168,7 @@ static struct net_buf *prepare_ra_message(void)
|
|||
struct net_if *iface;
|
||||
uint16_t reserve;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of RX buffers");
|
||||
|
||||
|
@ -176,7 +176,7 @@ static struct net_buf *prepare_ra_message(void)
|
|||
|
||||
reserve = net_if_get_ll_reserve(iface, NULL);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -413,7 +413,7 @@ static bool net_test_send_ns_extra_options(void)
|
|||
struct net_if *iface;
|
||||
uint16_t reserve;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
|
@ -421,7 +421,7 @@ static bool net_test_send_ns_extra_options(void)
|
|||
|
||||
reserve = net_if_get_ll_reserve(iface, NULL);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -449,7 +449,7 @@ static bool net_test_send_ns_no_options(void)
|
|||
struct net_if *iface;
|
||||
uint16_t reserve;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
|
@ -457,7 +457,7 @@ static bool net_test_send_ns_no_options(void)
|
|||
|
||||
reserve = net_if_get_ll_reserve(iface, NULL);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -569,7 +569,7 @@ static bool net_test_hbho_message(void)
|
|||
struct net_if *iface;
|
||||
uint16_t reserve;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
|
@ -577,7 +577,7 @@ static bool net_test_hbho_message(void)
|
|||
|
||||
reserve = net_if_get_ll_reserve(iface, NULL);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -614,7 +614,7 @@ static bool net_test_change_ll_addr(void)
|
|||
|
||||
net_ipv6_addr_create(&dst, 0xff02, 0, 0, 0, 0, 0, 0, 1);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
|
@ -622,7 +622,7 @@ static bool net_test_change_ll_addr(void)
|
|||
|
||||
reserve = net_if_get_ll_reserve(iface, NULL);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(reserve);
|
||||
frag = net_nbuf_get_reserve_data(reserve, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ static int test_ipv6_multi_frags(void)
|
|||
int bytes, remaining = strlen(example_data), pos = 0;
|
||||
|
||||
/* Example of multi fragment scenario with IPv6 */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE, K_FOREVER);
|
||||
|
||||
/* Place the IP + UDP header in the first fragment */
|
||||
if (!net_buf_tailroom(frag)) {
|
||||
|
@ -91,7 +91,7 @@ static int test_ipv6_multi_frags(void)
|
|||
net_buf_frag_add(buf, frag);
|
||||
|
||||
/* Put some data to rest of the fragments */
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE, K_FOREVER);
|
||||
if (net_buf_tailroom(frag) -
|
||||
(CONFIG_NET_NBUF_DATA_SIZE - LL_RESERVE)) {
|
||||
printk("Invalid number of bytes available in the buf, "
|
||||
|
@ -130,7 +130,8 @@ static int test_ipv6_multi_frags(void)
|
|||
|
||||
net_buf_frag_add(buf, frag);
|
||||
if (remaining > 0) {
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE,
|
||||
K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,8 +185,8 @@ static int test_fragment_copy(void)
|
|||
size_t orig_len;
|
||||
int pos;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE, K_FOREVER);
|
||||
|
||||
/* Place the IP + UDP header in the first fragment */
|
||||
if (net_buf_tailroom(frag)) {
|
||||
|
@ -224,13 +225,13 @@ static int test_fragment_copy(void)
|
|||
|
||||
/* Then copy a fragment list to a new fragment list */
|
||||
new_frag = net_nbuf_copy_all(buf->frags, sizeof(struct ipv6_hdr) +
|
||||
sizeof(struct icmp_hdr));
|
||||
sizeof(struct icmp_hdr), K_FOREVER);
|
||||
if (!new_frag) {
|
||||
printk("Cannot copy fragment list.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
new_buf = net_nbuf_get_reserve_tx(0);
|
||||
new_buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
net_buf_frag_add(new_buf, new_frag);
|
||||
|
||||
printk("Total new data len %zd\n", net_buf_frags_len(new_buf));
|
||||
|
@ -311,11 +312,11 @@ static int test_fragment_push(void)
|
|||
uint8_t *ptr;
|
||||
int i, bytes;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = NULL;
|
||||
|
||||
for (i = 0; i < FRAG_COUNT; i++) {
|
||||
frags[i] = net_nbuf_get_reserve_data(12);
|
||||
frags[i] = net_nbuf_get_reserve_data(12, K_FOREVER);
|
||||
|
||||
if (frag) {
|
||||
net_buf_frag_add(frag, frags[i]);
|
||||
|
@ -367,7 +368,7 @@ static int test_fragment_push(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
buf = net_nbuf_push(buf, buf->frags, sizeof(empty_data));
|
||||
buf = net_nbuf_push(buf, buf->frags, sizeof(empty_data), K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("push test failed, even with fragment pointer\n");
|
||||
return -1;
|
||||
|
@ -462,11 +463,11 @@ static int test_fragment_pull(void)
|
|||
struct net_buf *buf, *newbuf, *frags[FRAG_COUNT], *frag;
|
||||
int i, bytes_before, bytes_after, amount = 10, bytes_before2;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
frag = NULL;
|
||||
|
||||
for (i = 0; i < FRAG_COUNT; i++) {
|
||||
frags[i] = net_nbuf_get_reserve_data(12);
|
||||
frags[i] = net_nbuf_get_reserve_data(12, K_FOREVER);
|
||||
|
||||
if (frag) {
|
||||
net_buf_frag_add(frag, frags[i]);
|
||||
|
@ -518,13 +519,13 @@ static int test_fragment_pull(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Trying without TX or RX buf as a first element */
|
||||
frags[0] = net_nbuf_get_reserve_data(12);
|
||||
frags[0] = net_nbuf_get_reserve_data(12, K_FOREVER);
|
||||
frag = frags[0];
|
||||
memcpy(net_buf_add(frags[0], sizeof(test_data)),
|
||||
test_data, sizeof(test_data));
|
||||
|
||||
for (i = 1; i < FRAG_COUNT; i++) {
|
||||
frags[i] = net_nbuf_get_reserve_data(12);
|
||||
frags[i] = net_nbuf_get_reserve_data(12, K_FOREVER);
|
||||
|
||||
if (frag) {
|
||||
net_buf_frag_add(frag, frags[i]);
|
||||
|
@ -621,8 +622,8 @@ static int test_nbuf_read_append(void)
|
|||
uint16_t fail_pos;
|
||||
|
||||
/* Example of multi fragment read, append and skip APS's */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE, K_FOREVER);
|
||||
|
||||
/* Place the IP + UDP header in the first fragment */
|
||||
if (!net_buf_tailroom(frag)) {
|
||||
|
@ -650,7 +651,7 @@ static int test_nbuf_read_append(void)
|
|||
net_buf_frag_add(buf, frag);
|
||||
|
||||
/* Put some data to rest of the fragments */
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE, K_FOREVER);
|
||||
if (net_buf_tailroom(frag) -
|
||||
(CONFIG_NET_NBUF_DATA_SIZE - LL_RESERVE)) {
|
||||
printk("Invalid number of bytes available in the buf, "
|
||||
|
@ -689,7 +690,8 @@ static int test_nbuf_read_append(void)
|
|||
|
||||
net_buf_frag_add(buf, frag);
|
||||
if (remaining > 0) {
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE);
|
||||
frag = net_nbuf_get_reserve_data(LL_RESERVE,
|
||||
K_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -765,12 +767,14 @@ static int test_nbuf_read_append(void)
|
|||
tfrag = net_buf_frag_last(buf->frags);
|
||||
off = tfrag->len;
|
||||
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_short), test_rw_short)) {
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_short), test_rw_short,
|
||||
K_FOREVER)) {
|
||||
printk("net_nbuf_append failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_short), test_rw_short)) {
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_short), test_rw_short,
|
||||
K_FOREVER)) {
|
||||
printk("net_nbuf_append failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -799,12 +803,14 @@ static int test_nbuf_read_append(void)
|
|||
tfrag = net_buf_frag_last(buf->frags);
|
||||
off = tfrag->len;
|
||||
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_long), test_rw_long)) {
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_long), test_rw_long,
|
||||
K_FOREVER)) {
|
||||
printk("net_nbuf_append failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_long), test_rw_long)) {
|
||||
if (!net_nbuf_append(buf, sizeof(test_rw_long), test_rw_long,
|
||||
K_FOREVER)) {
|
||||
printk("net_nbuf_append failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -812,7 +818,8 @@ static int test_nbuf_read_append(void)
|
|||
/* Try to pass fragment to net_nbuf_append(), this should fail
|
||||
* as we always need to pass the first buf into it.
|
||||
*/
|
||||
if (net_nbuf_append(buf->frags, sizeof(test_rw_short), test_rw_short)) {
|
||||
if (net_nbuf_append(buf->frags, sizeof(test_rw_short), test_rw_short,
|
||||
K_FOREVER)) {
|
||||
printk("net_nbuf_append succeed but should have failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -847,10 +854,10 @@ static int test_nbuf_read_write_insert(void)
|
|||
uint16_t pos;
|
||||
|
||||
/* Example of multi fragment read, append and skip APS's */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
/* 1) Offset is with in input fragment.
|
||||
|
@ -859,7 +866,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
* and write data).
|
||||
*/
|
||||
frag = net_nbuf_write(buf, frag, NET_IPV6UDPH_LEN, &pos, 10,
|
||||
(uint8_t *)sample_data);
|
||||
(uint8_t *)sample_data, K_FOREVER);
|
||||
if (!frag || pos != 58) {
|
||||
printk("Usecase 1: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -882,7 +889,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
* there shouldn't be any length change).
|
||||
*/
|
||||
frag = net_nbuf_write(buf, frag, 0, &pos, NET_IPV6UDPH_LEN,
|
||||
(uint8_t *)sample_data);
|
||||
(uint8_t *)sample_data, K_FOREVER);
|
||||
if (!frag || pos != 48) {
|
||||
printk("Usecase 2: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -903,7 +910,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
/* Unref */
|
||||
net_nbuf_unref(buf);
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
/* 3) Offset is in next to next fragment.
|
||||
|
@ -911,7 +918,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
* create empty fragments(space) till offset and write data).
|
||||
*/
|
||||
frag = net_nbuf_write(buf, buf->frags, 200, &pos, 10,
|
||||
(uint8_t *)sample_data + 10);
|
||||
(uint8_t *)sample_data + 10, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Usecase 3: Write failed");
|
||||
}
|
||||
|
@ -934,7 +941,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
* the existing data.
|
||||
*/
|
||||
frag = net_nbuf_write(buf, buf->frags, 190, &pos, 10,
|
||||
(uint8_t *)sample_data);
|
||||
(uint8_t *)sample_data, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Usecase 4: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -959,16 +966,17 @@ static int test_nbuf_read_write_insert(void)
|
|||
* API should overwrite on first 10 bytes and create extra 10 bytes
|
||||
* and write there.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
/* Create 10 bytes space. */
|
||||
net_buf_add(frag, 10);
|
||||
|
||||
frag = net_nbuf_write(buf, frag, 0, &pos, 20, (uint8_t *)sample_data);
|
||||
frag = net_nbuf_write(buf, frag, 0, &pos, 20, (uint8_t *)sample_data,
|
||||
K_FOREVER);
|
||||
if (!frag && pos != 20) {
|
||||
printk("Usecase 5: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -996,18 +1004,18 @@ static int test_nbuf_read_write_insert(void)
|
|||
* bytes and write data. Third fragment 5 bytes overwritten and space
|
||||
* for 5 bytes created.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
/* First fragment make it fully occupied. */
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
len = net_buf_tailroom(frag);
|
||||
net_buf_add(frag, len);
|
||||
|
||||
/* 2nd fragment last 10 bytes tailroom, rest occupied */
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
len = net_buf_tailroom(frag);
|
||||
|
@ -1017,12 +1025,12 @@ static int test_nbuf_read_write_insert(void)
|
|||
read_pos = frag->len - 10;
|
||||
|
||||
/* 3rd fragment, only 5 bytes occupied */
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
net_buf_add(frag, 5);
|
||||
|
||||
temp_frag = net_nbuf_write(buf, temp_frag, temp_frag->len - 10, &pos,
|
||||
30, (uint8_t *) sample_data);
|
||||
30, (uint8_t *) sample_data, K_FOREVER);
|
||||
if (!temp_frag) {
|
||||
printk("Use case 6: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -1050,15 +1058,15 @@ static int test_nbuf_read_write_insert(void)
|
|||
* before first set of app data.
|
||||
*/
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
/* First fragment make it fully occupied. */
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
frag = net_nbuf_write(buf, frag, NET_IPV6UDPH_LEN, &pos, 10,
|
||||
(uint8_t *)sample_data + 10);
|
||||
(uint8_t *)sample_data + 10, K_FOREVER);
|
||||
if (!frag || pos != 58) {
|
||||
printk("Usecase 7: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -1077,7 +1085,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
}
|
||||
|
||||
if (!net_nbuf_insert(buf, frag, NET_IPV6UDPH_LEN, 10,
|
||||
(uint8_t *)sample_data)) {
|
||||
(uint8_t *)sample_data, K_FOREVER)) {
|
||||
printk("Usecase 7: Insert failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -1095,7 +1103,8 @@ static int test_nbuf_read_write_insert(void)
|
|||
}
|
||||
|
||||
/* Insert data outside input fragment length, error case. */
|
||||
if (net_nbuf_insert(buf, frag, 70, 10, (uint8_t *)sample_data)) {
|
||||
if (net_nbuf_insert(buf, frag, 70, 10, (uint8_t *)sample_data,
|
||||
K_FOREVER)) {
|
||||
printk("Usecase 7: False insert failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -1110,15 +1119,15 @@ static int test_nbuf_read_write_insert(void)
|
|||
* before first set of app data. Insertion data is long which will
|
||||
* take two fragments.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
net_nbuf_set_ll_reserve(buf, LL_RESERVE);
|
||||
|
||||
/* First fragment make it fully occupied. */
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf));
|
||||
frag = net_nbuf_get_reserve_data(net_nbuf_ll_reserve(buf), K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
frag = net_nbuf_write(buf, frag, NET_IPV6UDPH_LEN, &pos, 10,
|
||||
(uint8_t *)sample_data + 60);
|
||||
(uint8_t *)sample_data + 60, K_FOREVER);
|
||||
if (!frag || pos != 58) {
|
||||
printk("Usecase 8: Write failed\n");
|
||||
return -EINVAL;
|
||||
|
@ -1137,7 +1146,7 @@ static int test_nbuf_read_write_insert(void)
|
|||
}
|
||||
|
||||
if (!net_nbuf_insert(buf, frag, NET_IPV6UDPH_LEN, 60,
|
||||
(uint8_t *)sample_data)) {
|
||||
(uint8_t *)sample_data, K_FOREVER)) {
|
||||
printk("Usecase 8: Insert failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -1177,11 +1186,11 @@ static int test_fragment_compact(void)
|
|||
struct net_buf *buf, *frags[FRAG_COUNT], *frag;
|
||||
int i, bytes, total, count;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = NULL;
|
||||
|
||||
for (i = 0, total = 0; i < FRAG_COUNT; i++) {
|
||||
frags[i] = net_nbuf_get_reserve_data(12);
|
||||
frags[i] = net_nbuf_get_reserve_data(12, K_FOREVER);
|
||||
|
||||
if (frag) {
|
||||
net_buf_frag_add(frag, frags[i]);
|
||||
|
@ -1246,7 +1255,7 @@ static int test_fragment_compact(void)
|
|||
/* Add empty fragment at the end and compact, the last fragment
|
||||
* should be removed.
|
||||
*/
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -1271,11 +1280,11 @@ static int test_fragment_compact(void)
|
|||
/* Add two empty fragments at the end and compact, the last two
|
||||
* fragment should be removed.
|
||||
*/
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
@ -1300,11 +1309,11 @@ static int test_fragment_compact(void)
|
|||
/* Add empty fragment at the beginning and at the end, and then
|
||||
* compact, the two fragment should be removed.
|
||||
*/
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
net_buf_frag_insert(buf, frag);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
|
|
@ -357,14 +357,14 @@ static bool net_test_send_na(struct net_if *iface,
|
|||
struct net_buf *buf, *frag;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
buf = net_ipv6_create_raw(buf, net_if_get_ll_reserve(iface, dst),
|
||||
addr, dst, iface, IPPROTO_ICMPV6);
|
||||
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(frag, "Out of DATA buffers");
|
||||
|
||||
|
|
|
@ -316,8 +316,8 @@ static bool test_dio_dummy_input(void)
|
|||
struct net_buf *buf, *frag;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_tx(udp_ctx);
|
||||
frag = net_nbuf_get_data(udp_ctx);
|
||||
buf = net_nbuf_get_tx(udp_ctx, K_FOREVER);
|
||||
frag = net_nbuf_get_data(udp_ctx, K_FOREVER);
|
||||
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
|
|
|
@ -325,8 +325,8 @@ static bool send_ipv6_tcp_msg(struct net_if *iface,
|
|||
struct net_buf *frag;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
@ -373,8 +373,8 @@ static bool send_ipv4_tcp_msg(struct net_if *iface,
|
|||
struct net_buf *frag;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
|
|
@ -242,8 +242,8 @@ static bool send_ipv6_udp_msg(struct net_if *iface,
|
|||
struct net_buf *frag;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
@ -290,8 +290,8 @@ static bool send_ipv4_udp_msg(struct net_if *iface,
|
|||
struct net_buf *frag;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0);
|
||||
frag = net_nbuf_get_reserve_data(0);
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(0, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
|
|
@ -154,8 +154,8 @@ static bool run_tests(void)
|
|||
int hdr_len, i, chunk, datalen, total = 0;
|
||||
|
||||
/* Packet fits to one fragment */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
memcpy(net_buf_add(frag, sizeof(pkt1)), pkt1, sizeof(pkt1));
|
||||
|
@ -184,8 +184,8 @@ static bool run_tests(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Then a case where there will be two fragments */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, sizeof(pkt2) / 2), pkt2, sizeof(pkt2) / 2);
|
||||
|
||||
|
@ -198,7 +198,7 @@ static bool run_tests(void)
|
|||
frag->data[hdr_len + 2] = 0;
|
||||
frag->data[hdr_len + 3] = 0;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, sizeof(pkt2) - sizeof(pkt2) / 2),
|
||||
pkt2 + sizeof(pkt2) / 2, sizeof(pkt2) - sizeof(pkt2) / 2);
|
||||
|
@ -212,8 +212,8 @@ static bool run_tests(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Then a case where there will be two fragments but odd data size */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, sizeof(pkt3) / 2), pkt3, sizeof(pkt3) / 2);
|
||||
printk("First fragment will have %zd bytes\n", sizeof(pkt3) / 2);
|
||||
|
@ -227,7 +227,7 @@ static bool run_tests(void)
|
|||
frag->data[hdr_len + 2] = 0;
|
||||
frag->data[hdr_len + 3] = 0;
|
||||
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, sizeof(pkt3) - sizeof(pkt3) / 2),
|
||||
pkt3 + sizeof(pkt3) / 2, sizeof(pkt3) - sizeof(pkt3) / 2);
|
||||
|
@ -243,8 +243,8 @@ static bool run_tests(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Then a case where there will be several fragments */
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, sizeof(struct net_ipv6_hdr)), pkt3,
|
||||
sizeof(struct net_ipv6_hdr));
|
||||
|
@ -259,7 +259,7 @@ static bool run_tests(void)
|
|||
|
||||
for (i = 0; i < datalen/chunk; i++) {
|
||||
/* Next fragments will contain the data in odd sizes */
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, chunk),
|
||||
pkt3 + sizeof(struct net_ipv6_hdr) + i * chunk, chunk);
|
||||
|
@ -278,7 +278,7 @@ static bool run_tests(void)
|
|||
}
|
||||
}
|
||||
if ((datalen - total) > 0) {
|
||||
frag = net_nbuf_get_reserve_data(10);
|
||||
frag = net_nbuf_get_reserve_data(10, K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
memcpy(net_buf_add(frag, datalen - total),
|
||||
pkt3 + sizeof(struct net_ipv6_hdr) + i * chunk,
|
||||
|
@ -309,8 +309,9 @@ static bool run_tests(void)
|
|||
/* Another packet that fits to one fragment.
|
||||
* This one has ethernet header before IPv4 data.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
@ -337,8 +338,9 @@ static bool run_tests(void)
|
|||
/* Another packet that fits to one fragment and which has correct
|
||||
* checksum. This one has ethernet header before IPv4 data.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0);
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr));
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
frag = net_nbuf_get_reserve_data(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
net_buf_frag_add(buf, frag);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue