Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
475 changes: 444 additions & 31 deletions include/net/http.h

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions include/net/net_pkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,23 @@ static inline struct net_buf *net_pkt_copy_all(struct net_pkt *pkt,
int net_frag_linear_copy(struct net_buf *dst, struct net_buf *src,
u16_t offset, u16_t len);

/**
* @brief Copy len bytes from src starting from offset to dst buffer
*
* This routine assumes that dst is large enough to store @a len bytes
* starting from offset at src.
*
* @param dst Destination buffer
* @param dst_len Destination buffer max length
* @param src Source buffer that may be fragmented
* @param offset Starting point to copy from
* @param len Number of bytes to copy
* @return number of bytes copied if everything is ok
* @return -ENOMEM on error
*/
int net_frag_linearize(u8_t *dst, size_t dst_len,
struct net_pkt *src, u16_t offset, u16_t len);

/**
* @brief Compact the fragment list of a packet.
*
Expand Down
4 changes: 2 additions & 2 deletions samples/net/common/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Common routines used in net samples

ifeq ($(CONFIG_NET_L2_BLUETOOTH), y)
CFLAGS +=-I${ZEPHYR_BASE}/samples/bluetooth/
obj-y += ../bluetooth/gatt/ipss.o
ccflags-y += -I${ZEPHYR_BASE}/samples/bluetooth/
obj-y += ../../../bluetooth/gatt/ipss.o
endif

ifeq ($(CONFIG_NET_L2_IEEE802154), y)
Expand Down
2 changes: 2 additions & 0 deletions samples/net/common/net_sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extern "C" {

/* What kind of functionality is needed by the application. */
#define NET_SAMPLE_NEED_ROUTER 0x00000001
#define NET_SAMPLE_NEED_IPV6 0x00000002
#define NET_SAMPLE_NEED_IPV4 0x00000004

int net_sample_app_init(const char *app_info, u32_t flags, s32_t timeout);

Expand Down
48 changes: 40 additions & 8 deletions samples/net/common/sample_app_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include <ieee802154_settings.h>
#endif

struct k_sem waiter = K_SEM_INITIALIZER(waiter, 0, 1);
static struct k_sem waiter = K_SEM_INITIALIZER(waiter, 0, 1);
static struct k_sem counter;

#if defined(CONFIG_NET_DHCPV4)
static struct net_mgmt_event_callback mgmt4_cb;
Expand Down Expand Up @@ -67,6 +68,7 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
break;
}

k_sem_take(&counter, K_NO_WAIT);
k_sem_give(&waiter);
}

Expand All @@ -93,8 +95,8 @@ static void setup_dhcpv4(struct net_if *iface)

static void setup_ipv4(struct net_if *iface)
{
char hr_addr[NET_IPV4_ADDR_LEN];
struct in_addr addr;
int ret;

if (net_addr_pton(AF_INET, CONFIG_NET_APP_MY_IPV4_ADDR, &addr)) {
NET_ERR("Invalid address: %s", CONFIG_NET_APP_MY_IPV4_ADDR);
Expand All @@ -106,6 +108,7 @@ static void setup_ipv4(struct net_if *iface)
NET_INFO("IPv4 address: %s",
net_addr_ntop(AF_INET, &addr, hr_addr, NET_IPV4_ADDR_LEN));

k_sem_take(&counter, K_NO_WAIT);
k_sem_give(&waiter);
}

Expand All @@ -121,10 +124,6 @@ static void setup_ipv4(struct net_if *iface)
static struct net_mgmt_event_callback mgmt6_cb;
static struct in6_addr laddr;

/* DNS query will most probably fail if we do not have a default
* router configured because typically the DNS server is outside of local
* network. So wait for that before continuing.
*/
static void ipv6_event_handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, struct net_if *iface)
{
Expand All @@ -144,10 +143,12 @@ static void ipv6_event_handler(struct net_mgmt_event_callback *cb,
net_addr_ntop(AF_INET6, &laddr, hr_addr,
NET_IPV6_ADDR_LEN));

k_sem_take(&counter, K_NO_WAIT);
k_sem_give(&waiter);
}

if (mgmt_event == NET_EVENT_IPV6_ROUTER_ADD) {
k_sem_take(&counter, K_NO_WAIT);
k_sem_give(&waiter);
}
}
Expand Down Expand Up @@ -183,7 +184,10 @@ static void setup_ipv6(struct net_if *iface, u32_t flags)

int net_sample_app_init(const char *app_info, u32_t flags, s32_t timeout)
{
#define LOOP_DEVIDER 10
struct net_if *iface = net_if_get_default();
int loop = timeout / LOOP_DEVIDER;
int count = 0;

if (app_info) {
NET_INFO("%s", app_info);
Expand All @@ -206,14 +210,42 @@ int net_sample_app_init(const char *app_info, u32_t flags, s32_t timeout)
}
#endif

if (flags & NET_SAMPLE_NEED_IPV6) {
count++;
}

if (flags & NET_SAMPLE_NEED_IPV4) {
count++;
}

k_sem_init(&counter, count, count);

setup_ipv4(iface);

setup_dhcpv4(iface);

setup_ipv6(iface, flags);

/* Wait until we are ready to continue */
if (k_sem_take(&waiter, timeout)) {
if (timeout < 0) {
count = -1;
} else if (timeout == 0) {
count = 0;
} else {
count = timeout / 1000 + 1;
}

/* Loop here until until we are ready to continue. As we might need
* to wait multiple events, sleep smaller amounts of data.
*/
while (count--) {
if (k_sem_take(&waiter, loop)) {
if (!k_sem_count_get(&counter)) {
break;
}
}
}

if (!count && timeout) {
NET_ERR("Timeout while waiting setup");
return -ETIMEDOUT;
}
Expand Down
6 changes: 2 additions & 4 deletions samples/net/http_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

BOARD ?= frdm_k64f
BOARD ?= qemu_x86
CONF_FILE ?= prj_$(BOARD).conf

include $(ZEPHYR_BASE)/Makefile.inc
ifeq ($(BOARD), qemu_x86)
include $(ZEPHYR_BASE)/samples/net/common/Makefile.ipstack
endif
include $(ZEPHYR_BASE)/samples/net/common/Makefile.ipstack
Loading